var browserName=navigator.userAgent;
var leftOffset = 0;
function showdeadcenterdiv(Xwidth,Yheight,divid) { 
    leftOffset = 0;
    // First, determine how much the visitor has scrolled 
    var scrolledX, scrolledY; 
    if( self.pageYOffset ) { 
        scrolledX = self.pageXOffset; 
        scrolledY = self.pageYOffset; 
    } else if( document.documentElement && document.documentElement.scrollTop ) { 
        scrolledX = document.documentElement.scrollLeft; 
        scrolledY = document.documentElement.scrollTop; 
    } else if( document.body ) { 
        scrolledX = document.body.scrollLeft; 
        scrolledY = document.body.scrollTop; 
    } 

    // Next, determine the coordinates of the center of browser's window 
    var centerX, centerY; 
    if( self.innerHeight ) { 
        centerX = self.innerWidth; 
        centerY = self.innerHeight; 
    } else if( document.documentElement && document.documentElement.clientHeight ) { 
        centerX = document.documentElement.clientWidth; 
        centerY = document.documentElement.clientHeight; 
    } else if( document.body ) { 
        centerX = document.body.clientWidth; 
        centerY = document.body.clientHeight; 
    } 

    // Xwidth is the width of the div, Yheight is the height of the 
    // div passed as arguments to the function: 
    leftOffset = scrolledX + (centerX - Xwidth) / 2; 
    if (browserName.indexOf("Firefox")==-1) {
        if (leftOffset > 0) {
            leftOffset = 0;
        } 
    } else {
        if (leftOffset > 90) {
            leftOffset = 0;
        }     
    }
    ///////var topOffset = scrolledY + (centerY - Yheight) / 2; 
    var topOffset = 0;
    // The initial width and height of the div can be set in the 
    // style sheet with display:none; divid is passed as an argument to // the function 
    var o=document.getElementById('divMain'); 
    var r=o.style; 
    r.position='absolute'; 
    r.top = topOffset + 'px'; 
    r.left = leftOffset + 'px'; 
    r.display = "block"; 
}

//window.onresize = doResize;
//window.onload = doResize;
function doResize(sz) {
    if (window.innerWidth) {
        showdeadcenterdiv(sz,0,'divMain');
    }
}

var curleft = 0;
var curtop = 0;
function findPos(obj) {
    curleft = 0;
    curtop = 0;
    if (obj.offsetParent) {
        do {
			curleft += obj.offsetLeft;
			//curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    curleft -= leftOffset;
    //return [curleft,curtop];
}

function OpenUp(elOpen, elClosed) {
	document.getElementById(elClosed).style.visibility="hidden"
	document.getElementById(elClosed).style.position="absolute"
	document.getElementById(elOpen).style.visibility="visible"
	document.getElementById(elOpen).style.position="static"
}
function CloseUp(elOpen, elClosed) {
	document.getElementById(elOpen).style.position="absolute"
	document.getElementById(elOpen).style.visibility="hidden"
	document.getElementById(elClosed).style.position="static"
	document.getElementById(elClosed).style.visibility="visible"
}

function PopOpen(elOpen) {
    document.getElementById(elOpen).style.visibility='visible';
    //document.getElementById(elOpen).style.left=((w/2) + 270)
    document.getElementById(elOpen).style.left=curleft;
}    
function PopClose(elClose) {
    document.getElementById(elClose).style.visibility='hidden'
}    

function ModalWindow(sURL,vArgs,w,h,scroll,resize){
	if (w=='') {w = screen.width};
	if (h=='') {h = screen.height};
	sFeatures='dialogHeight:'+h+'px;dialogWidth:'+w+'px;scroll:'+scroll+';help:no;status:no;resizable:'+resize+';'
	return showModalDialog(sURL,vArgs,sFeatures)
}

var winPop= null;
function NewWindow(mypage,myname,w,h,scroll,resizable){
	if (w=='') {w = screen.width};
	if (h=='') {h = screen.height};
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',toolbar=no,location=no,status=no,menubar=no,resizable='+resizable+',dependent=no'
	winPop=window.open(mypage,myname,settings)
    	//window.open(mypage,myname,settings)
	//if(parseInt(navigator.appVersion) >= 4){winPop.window.focus();}
}

function ClickCellButtonDeleteOnCol0(gridName, itemName){
	var cellinfo = itemName.split("_");	//cellinfo[2]=Row Index; cellinfo[3]=Column Index;	
	var row = igtbl_getRowById(itemName);

	if (cellinfo[3] == 0) { //Delete Column
		var confirmDelete = window.confirm("Are you sure you want to Delete the current record?\n\nClick 'OK' to continue or 'Cancel' to change your mind...");
		if (!confirmDelete) {
			igtbl_cancelPostBack(gridName);
		} else {
			igtbl_needPostBack(gridName);
		}
	}
}

function ClickCell (gridName, itemName, button) { 
	cellinfo = itemName.split("_");	//cellinfo[2]=Row Index; cellinfo[3]=Column Index;
	if (button == 0) { // 0=Left Mouse Button; 2=Right Mouse Button 
		var chkCookie = cookieVal("lastRowClickID")
		var lastGrid = chkCookie.substring(0,chkCookie.indexOf("_")-1)
		
		//if (lastGrid == gridName) {
			try{
				obj = eval(chkCookie);
				obj.style.backgroundColor = "White";
			} 
			catch(e){ 
			}	
		//}

		obj = eval(gridName + "_r_" + cellinfo[2]);
		obj.style.backgroundColor = "Beige";
		
		var lastRowClickID = gridName + "_r_" + cellinfo[2];
		ExpDate = new Date
		ExpDate.setDate(ExpDate.getDate()+1)
		document.cookie = "lastRowClickID="+lastRowClickID+";expires="+ExpDate.toGMTString()
	
	} 
}

function cookieVal(cookieName) {
	thisCookie = document.cookie.split("; ");
	for (i=0; i<thisCookie.length; i++) {
		if (cookieName == thisCookie[i].split("=")[0]) {
			return thisCookie[i].split("=")[1];
		}
	}
	return "";
}

function CheckAll(chkBox, gridName, columnKey) {

	var myGrid = igtbl_getGridById(gridName);

	for (i = 0; i < myGrid.Rows.length; i++) {
		myGrid.Rows.getRow(i).getCellFromKey(columnKey).setValue(chkBox.checked);
	}

}

function trim(inputStringTrim) {
	fixedTrim = "";
	lastCh = " ";
	for (x=0; x < inputStringTrim.length; x++) {
		ch = inputStringTrim.charAt(x);
		if ((ch != " ") || (lastCh != " ")) { fixedTrim += ch; }
		lastCh = ch;
	}
	if (fixedTrim.charAt(fixedTrim.length - 1) == " ") {
		fixedTrim = fixedTrim.substring(0, fixedTrim.length - 1); 
	}
	return fixedTrim;
}
			
function ChkListDelete(Element,Text){
	ElementStr = "document.forms[0]." + Element + ".selectedIndex"
	IDNum = eval(ElementStr)
	if (IDNum >= 0){
		var ConfirmDelete = window.confirm("Are you Sure you want to Delete this " + Text + "? \nNOTE: THIS CANNOT BE UNDONE! \n\nClick 'OK' to Confirm... \nClick 'Cancel' to Change your Mind...")
		if (ConfirmDelete) {return true}
		else {return false}
	}
	else {
		alert("A " + Text + " was not selected.")
		return false;
	}
}

function ChkDelete(Text){
	var ConfirmDelete = window.confirm("Are you Sure you want to Delete this " + Text + "? \nNOTE: THIS CANNOT BE UNDONE! \n\nClick 'OK' to Confirm... \nClick 'Cancel' to Change your Mind...")
		if (ConfirmDelete) {return true}
		else {return false}
}

function GTZero(oSrc, args){
   args.IsValid = (args.Value > 0);
}
function PhoneLen(oSrc, args){
   args.IsValid = (args.Value.length == 10);
}
function PWLen(oSrc, args){
    var Pass = args.Value;
    var PassLen = Pass.length;
    args.IsValid = (PassLen >= 6 && PassLen <= 15);
}
function PWChr(oSrc, args) {
    var GoodChar = false;
	for (x=0; x < args.Value.length; x++) {
		ch = args.Value.charAt(x);
		if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) || ((ch >= '0') && (ch <= '9')) || (ch == '_') || (ch == '!') || (ch == '@') || (ch == '$')) { 
	        GoodChar = true;
		}
		else {
		    GoodChar = false;
		    x = args.Value.length;
		}
	}
	args.IsValid = (GoodChar == true);
}

function ValidateSearchTerm(ctl) {
    var ctlName = ctl
    var val = document.getElementById(ctlName).value;
    if (trim(val) == "") {
        alert("A Search Term was not Entered.");
        document.getElementById(ctlName).value = "";
        document.getElementById(ctlName).focus();
        return false;
    } else {
        return true;
    }
}

function SubmitSearch(ctlSchBtn) {
    if (window.event.keyCode==13) {
        document.getElementById(ctlSchBtn).click();
        return false;
    }
}

function IsSamePage(PageLocation, PageToCompare) {
    var loc = PageLocation;
    var chr = "";
    var slashPos = 0;
    for (i=0; i<loc.length; i++) {
        chr = loc.substring(i,i+1);
        if (chr == "/") {slashPos = i}
    }
    var CurrPage = loc.substring(slashPos+1,loc.length);
    try{
        CurrPage = CurrPage.toLowerCase();
        PageToCompare = PageToCompare.toLowerCase();
    }
    catch(e){}	
    return CurrPage == PageToCompare;
}

/*
var xMousePos = 0; // Horizontal position of the mouse on the screen
var yMousePos = 0; // Vertical position of the mouse on the screen
var xMousePosMax = 0; // Width of the page
var yMousePosMax = 0; // Height of the page

function mousePositions() {
    if (document.layers) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }  
}
*/