var _gPageChange=0;

function _gPageChanged(){
	_gPageChange=1;
}

function _gIsPageChanged(){
	if(_gPageChange)
	    return true;
	return false;
}

function _gPageNotChanged(){
    _gPageChange=0;
}

function pageChangeOk(){
	if(_gPageChange)
	{
		var chk = window.confirm("To save changes click 'Cancel' and click 'Save'.\nTo discard any changes click 'OK'.");
		if(chk){
		    _gPageNotChanged();
			return true;
		}
	}
	else
		return true;
}
	
function HTMLfind()
{
    var x = new ActiveXObject("WScript.Shell")
    x.SendKeys("^f");
}

function openHTMLfind(windowObj)
{
    showModelessDialog('../inc/find.html', windowObj,'dialogWidth:385px; dialogHeight:100px; scroll:no; status:no; help:no;');
}

function searchtype(){
	var retval = 0;
	var matchcase = 0;
	var matchword = 0;
	retval = matchcase + matchword;
	return(retval);
}

// find the text I want
function findtext(startAgain){
	if (document.all.strSearch.value.length < 1) {
		//alert("Please enter text in the \"Find what:\" field.");
	}
	else {
		var searchval = document.all.strSearch.value;
		if(startAgain){ 
		    rng.expand("textedit");
		    rng.collapse();
		}
		else rng.collapse(false);
		if (rng.findText(searchval, 1000000000, searchtype())) {
			rng.select();
		}
		else {
			var startfromtop = confirm("Your word was not found.\nWould you like to start again from the top?");
			if (startfromtop) {
				rng.expand("textedit"); // selects everything
				rng.collapse(); // collapse at the beginning
				rng.select(); // create the selection
				findtext(); // start again
			}
		}
	}
}

function openCenterWindow(url,name,width,height)
{
	var hg=height;
	var w=width;
	var l = (screen.availWidth - w) / 2;
	var t = (screen.availHeight - hg) / 2;

//	var features = "width="+w+",height="+hg+",left="+l+",top="+t;
//	features += ",screenX="+l+",screenY="+t;
//	features += ",scrollbars=1,resizable=1,location=0";
//	features += ",menubar=0,toolbar=0,status=1,dependent=1";
//	var h = window.open(url,'',features);
//	h.focus();	
	
	var features = "dialogwidth:"+w+"px;dialogheight:"+hg+"px;scroll:yes;resizable:yes;status:yes;";
	var h = showModalDialog(url,null,features);	
	if(h){
	    var t = h.split("~");
	    if(t.length>1){
	        var d = t[1];
	        for(i=2;i<t.length;i++)
	            d += "~" + t[i];
	        window.returnValue = d;	        
	    }
	    var t1 = t[0].split("$!$");
	    if(t1.length>1)
	        window.open(t1[0], t1[1]);                   	    
	    else
	        window.location = t[0];
	}	
}

function openReportWindow(url)
{
	var h=600;
	var w=800;
	var l = (screen.availWidth - w) / 2;
	var t = (screen.availHeight - h) / 2;

	var features = "width="+w+",height="+h+",left="+l+",top="+t;
	features += ",screenX="+l+",screenY="+t;
	features += ",scrollbars=0,resizable=1,location=0";
	features += ",menubar=0,toolbar=0,status=1";
	var h = window.open(url,'',features);
	h.focus();	
}

function toolBarOver(e)
{
	if (!e)
	var e=window.event;
	var S=e.srcElement;
	while (S.tagName!="TD")
	{S=S.parentElement;}
	S.className="toolbarTDO";
}

function toolBarOut(e)
{
	if (!e)
	var e=window.event;
	var S=e.srcElement;
	while (S.tagName!="TD")
	{S=S.parentElement;}
	S.className="toolbarTD";
}

function toolbarCancel()
{
	window.history.back();
}

function submitForm(formObj){		
	var check= validateForm(formObj);
	if(check==false)
		return check;
	formObj.submit();
}	

function confirmDelete(){
	return confirm("Are you sure you want to delete record?");
}

function confirmChildDelete(){
	return confirm("Are you sure you want to delete record?\n\nNOTE:This will delete all the child records refers to this record.");
}

function goBack(){
	history.back();
}

var prevRow;
var prevRowClassName;
function RowClicked(obj,clickedLocation,childGeneration)
{
    if(obj.className=="boxrowclicked")//same row clicked
        return false;
        
    if(childGeneration==1)
    {
        if(!window.parent.frames[0].pageChangeOk()) return false;
        window.parent.frames[0]._gPageNotChanged();
    }
    else if(childGeneration==2)
    {     
        if(!window.parent.parent.frames[0].pageChangeOk()) return false;
        window.parent.parent.frames[0]._gPageNotChanged();
    }
    
	if(prevRow)
		prevRow.className = prevRowClassName;

	prevRow = obj;
	prevRowClassName = obj.className;

	obj.className = "boxrowclicked";
	
	if(clickedLocation!="")
	{
	    if(childGeneration==1)
            window.parent.frames.right.location = clickedLocation; 
        else if(childGeneration==2)
            window.parent.parent.frames.right.location = clickedLocation; 
	}
}

function RowClickedPopup(obj,clickedLocation,childGeneration,width,height)
{
    //if(obj.className=="boxrowclicked")//same row clicked
    //    return false;
        
    if(childGeneration==1)
    {
        if(!window.parent.frames[0].pageChangeOk()) return false;
        window.parent.frames[0]._gPageNotChanged();
    }
    else if(childGeneration==2)
    {     
        if(!window.opener.parent.frames[0].pageChangeOk()) return false;
        window.opener.parent.frames[0]._gPageNotChanged();
    }
    else if(childGeneration==3)
    {     
        if(!window.opener.opener.parent.frames[0].pageChangeOk()) return false;
        window.opener.opener.parent.frames[0]._gPageNotChanged();
    }
    
	//if(prevRow)
	//	prevRow.className = prevRowClassName;
	//prevRow = obj;
	//prevRowClassName = obj.className;
	//obj.className = "boxrowclicked";
	
	if(clickedLocation!="")
	{
	    openCenterWindow(clickedLocation,childGeneration,width,height);
	}
}

function RowClickedPopup2(obj,clickedLocation,childGeneration,width,height)
{
  
	if(clickedLocation!="")
	{
	    openCenterWindow(clickedLocation,childGeneration,width,height);
	}
}

function FromTreeFramePageChangeOK(){
    if(!FromFramePageChangeOK()){
        window.parent.frames.right.focus();
        return false;
    }
    FromFramePageNotChanged(); 
    return true;
}

function LeftFrameRefresh(url){
    window.parent.frames.left.location = url;
}

function FromFramePageChangeOK()
{
    return window.parent.frames.toolbar.pageChangeOk();
}

function FromFramePageNotChanged()
{
    window.parent.frames.toolbar._gPageNotChanged();
}

function FromFramePageChanged()
{
    window.parent.frames.toolbar._gPageChanged();
}

function GridLineChanged(hidObj)
{
    hidObj.value=1;
}

function SelectAllClicked(obj,type)
{   
    var frm = document.forms[0];    
    var checkString="";
    if(type==1){
        checkString="_PER_READ1";
        frm._READWRITESELECTALL.checked = false;
        frm._NOACCESSSELECTALL.checked = false;
    }
    else if(type==2){
        checkString="_PER_READWRITE1";
        frm._READSELECTALL.checked = false;
        frm._NOACCESSSELECTALL.checked = false;
    }
    else if(type==3){
        checkString="_PER_NO_ACCESS1";
        frm._READWRITESELECTALL.checked = false;
        frm._READSELECTALL.checked = false;
    }
     
    for (var i=0; i<frm.elements.length; i++){
        if(frm[i].id.indexOf(checkString)>0){
            frm[i].checked = obj.checked;
        }
    }    
}

function RecordSavedMessage(){
    //alert('Record(s) Saved.');
}

function RecordDeletedMessage(){
    //alert('Record(s) Deleted.');
}
	function setPointer() {
	    if (document.all)
	        for (var i=0;i < document.all.length; i++)
	             document.all(i).style.cursor = 'wait';
	             
	}

	function resetPointer() {
	    if (document.all)
	        for (var i=0;i < document.all.length; i++)
	             document.all(i).style.cursor = 'default';
	}

	function flipImage(url)
	{
	    if (window.event.srcElement.tagName == "IMG" ) {
	        window.event.srcElement.src = url;
	    }
	}
	function mergePNG(id, path, width, height) {
		tclass = "";
		talt = "Click to view";
		if ((browser.isIE55 || browser.isIE6x) && browser.isWin32) {
			var pngAlpha = true;
		} else { 
			var pngAlpha = false;
		}
		
		if (pngAlpha)
			document.write('<div style="height:'+height+'px; width:'+width+'px;  filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+path+'\', sizingMethod=\'scale\')" class="'+tclass+'"	id="'+id+'"></div>');
		else
			document.write('<img src="'+path+'" width="'+width+'" height="'+height+'" name="'+id+'" border="0" class="'+tclass+'" alt="'+talt+'" />');
	}
	 function ReplaceComma(inputString){
		var InputString = new String(inputString);
		var CommaPos;
		if (InputString!="")
		{
			CommaPos=InputString.indexOf(',');
			while (CommaPos > 0) {
				InputString=InputString.replace(',','');	
				CommaPos=InputString.indexOf(',');
			}
		}
		return InputString;
	 }
	function ReplaceAmpersand(InputString){
		var InputString = new String(inputString);
		var CommaPos;
		if (InputString!="")
		{
			CommaPos=InputString.indexOf('&');
			while (CommaPos > 0) {
				InputString=InputString.replace('&','*');	
				CommaPos=InputString.indexOf('&');
			}
		}
		return InputString;
	 } 
	 
	  