function getLongDate() {
    now = new Date()
    dayName = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
    monthName = new Array("January","February","March","April","May","June","July","August","September","October","November","December")
    var LongDate = dayName[now.getDay()] + ", " + monthName[now.getMonth()] + " " + now.getDate() + ", " + chkYear(now.getYear())
    return LongDate
}
function chkYear(Y){
    if (Y < 2000) {return 1900 + Y}
    else {return Y}
}

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 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)
}
function getModalWin(appPath, page, vArgs, w, h, scroll, resize) {
	var win = ModalWindow(appPath + '/iframe.aspx?src=' + page, vArgs, w, h, scroll, resize);
}

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)
	//if(parseInt(navigator.appVersion) >= 4){winPop.window.focus();}
}
function getNonModalWin(page, name, w, h, scroll, resize) {
	var win = NewWindow('iframe.aspx?src=' + page, name, w, h, scroll, resize);
}
function NewWindowToolBar(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=yes,location=no,status=no,menubar=yes,resizable='+resizable+',dependent=no'
	winPop=window.open(mypage,myname,settings)
	//if(parseInt(navigator.appVersion) >= 4){winPop.window.focus();}
}

var rc="";
function chkIE() {if (document.all) {(rc);return false;}}
function chkNS(e) {if (document.layers ||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(rc);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=chkNS;}
else{document.onmouseup=chkNS;document.oncontextmenu=chkIE;}
document.oncontextmenu=new Function("return false")

function Exchange(aSel, uSel, Opt) {
	var Dup;
	var SelectMode = document.forms[0].hidClientSelectMode.value;
	var SelectedClients = document.forms[0].listClientsB.options.length;
	
	if ((SelectMode == 's') && (SelectedClients >= 1) && (aSel.name == 'listClientsB')) {
		alert("This Report can only be run for one Client at a time.");
		return false;
	}

    for (i=0;i<uSel.options.length;i++) {
	    uSelValArray = uSel.options[i].value.split("!");
	    uSelVal = uSelValArray[0];
		Dup = false;
        if (uSel.options[i].selected) {
			for (x=0;x<aSel.options.length;x++) {
				aSelValArray = aSel.options[x].value.split("!");
				aSelVal = aSelValArray[0];
				if (aSelVal == uSelVal) {
					Dup = true;
				}
			}
			if (Dup == false) {
	            aSel.options[aSel.options.length] = new Option(uSel.options[i].text, uSel.options[i].value);
	            if (Opt != "K") {
					uSel.options[i--] = null;
				}
				else {
				    uSel.options[i].selected = false
				}
			}
			else if (Opt == "R") {
	           uSel.options[i--] = null;
			}
        }
    }
    if (document.layers && !document.getElementById){history.go(0);}
}

function SelectContacts(aSel, uSel, Opt) {
    for (i=0;i<uSel.options.length;i++) {
	    uSel.options[i].selected = true
    }
    Exchange(aSel, uSel, Opt)
    for (i=0;i<uSel.options.length;i++) {
	    uSel.options[i].selected = false
    }
}

function ClickCellButtonDeleteOnCol0(gridName, itemName){
	var cellinfo = itemName.split("_"); //  cellinfo[0]=gridName;   cellinfo[1]='rc';
	                                    //  cellinfo[2]=ParentRow Row Index (if on Parent or Child row);   
	                                    //  cellinfo[3]=ParentRow Column Index if on ParentRow... or
	                                    //              ChildRow Row Index if on ChildRow
	                                    //  cellinfo[4]='undefined' (if on ParentRow)... or
	                                    //               ChildRow Column Index if on ChildRow
	var row = igtbl_getRowById(itemName);
	
	var delParamIndex;
	if (cellinfo[4]>=0) {
	    delParamIndex = 4;
	} else {
	    delParamIndex = 3;
	}
	
	if (cellinfo[delParamIndex] == 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 switchDisplay(cbId,objId,validatorId) {
//cbId = CheckBox ID; objId = ID of Object to be Hidden/Shown; validatorId= the Vam Validator ID
    try{
	    if (!document.getElementById(cbId).checked) {
    	    document.getElementById(objId).style.display = "none";
    	} else {
    	    document.getElementById(objId).style.display = "block";
        }

	    if (validatorId != '') {
    	    VAMEnabled('_ctl0__ctl0_InnerContentPlaceHolder_InnerContentPlaceHolder_ucSMSDevices_validDeviceChecks', document.getElementById(cbId).checked);
        }        	    

    } 
        catch(e){ 
    }
}

function VAMEnabled(pClientID, pEnabled) {
    var vAO = VAM_FindAOById(pClientID);
    if (vAO != null){
        VAM_SetEnabled(vAO, pEnabled);
    }
}

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 ExpandAll(gridName, openIt) {
	var myGrid = igtbl_getGridById(gridName);
    var hasChild;
    
    if (openIt == 'true'){
        Expand = true;
    }else{
        Expand = false;
    }
	        
	for (i = 0; i < myGrid.Rows.length; i++) {
	    hasChild = myGrid.Rows.getRow(i).getExpanded()
	    if (hasChild != null) {
	        igtbl_toggleRow(gridName,myGrid.Rows.getRow(i).Id, Expand);
        }
	}

}

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);
}

// Handle Non-Tab Stop Capability
function rememberFocus(elemID) {
//alert(elemID)
	ExpDate = new Date
	ExpDate.setDate(ExpDate.getDate()+1)
	document.cookie = "lastFocusID="+elemID+";expires="+ExpDate.toGMTString()
}
function tabNext(prevElemID,nextElemID) {
	try{
        var chkCookie = cookieVal("lastFocusID")
//alert(chkCookie)        
//alert("Prev: " + prevElemID)        
//alert("Next: " + nextElemID)
	    if (chkCookie == prevElemID) {
	        document.getElementById(nextElemID).focus();
	    } else if(chkCookie == nextElemID) {
	        document.getElementById(prevElemID).focus();
	    }
	} 
    catch(e){ 
	}
} 

function txtRequired(ElemID, Label) {
    var val = trim(document.getElementById(ElemID).value)
    if (val == "") {
        alert(Label + " is required");
        document.getElementById(ElemID).focus();
        return false;
    } else {
        return true;
    }
}

function UltraWebGrid_EditKeyDownHandler(gridName, cellId, key){
    
    //Get the cell being edited    
    var cell = igtbl_getCellById(cellId);
    
    //Get the row of the cell being edited
    var row = cell.getRow();

    //Key Codes Down = 40, Up = 38, Right = 39, Left = 37
    
    switch(key)
    {
        //If Down Key
        case 40:
            
            //Check to see if there is a next row
            var nextRow = row.getNextRow();
            if(nextRow != null)
            {
                //End editing of the current cell
                cell.endEdit(true); 
                
                //Active and begin edit on the cell below it
                nextRow.getCell(cell.Index).activate();
                nextRow.getCell(cell.Index).beginEdit();
            }
            break;
        //If up key
        case 38:
            //Check to see if there is a previous row
            var prevRow = row.getPrevRow();
            if(prevRow != null)
            {
                //End editing of the current cell
                cell.endEdit(true);
                
                //Active and begin edit on the cell above it
                prevRow.getCell(cell.Index).activate();
                prevRow.getCell(cell.Index).beginEdit();
            }
            break;
        //If right key
        case 39:
            //Check to see if there is a next cell in the row
            var nextCell = cell.getNextCell();
            if(nextCell != null)
            {
                //End editing of the current cell
                cell.endEdit(true);
                
                //Active and begin edit on the cell to the right
                nextCell.activate();
                nextCell.beginEdit();
            }
            break;
        //If left key
        case 37:
            //Check to see if there is a previous cell in the row
            var prevCell = cell.getPrevCell();
            if(prevCell != null)
            {
                //End editing of the current cell
                cell.endEdit(true);
                
                //Active and begin edit on the cell to the left
                prevCell.activate();
                prevCell.beginEdit();
            }
            break;
    }
}
                          
function MaxLen(elemID, maxLimit) {
    if (document.getElementById(elemID).value.length > maxLimit) {
        document.getElementById(elemID).value = document.getElementById(elemID).value.substring(0, maxLimit);
    }
}

function formatNumber (anynum, decimal) {
    //decimal  - the number of decimals after the digit from 0 to 3
    //-- Returns the passed number as a string in the xxx,xxx.xx format.
   //anynum=eval(obj.value);
   
   divider =10;
   switch(decimal){
		case 0:
			divider =1;
			break;
		case 1:
			divider =10;
			break;
		case 2:
			divider =100;
			break;
		default:  	 //for 3 decimal places
			divider =1000;
	}

   workNum=Math.abs((Math.round(anynum*divider)/divider));

   workStr=""+workNum

   if (workStr.indexOf(".")==-1){workStr+="."}

   dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
   pStr=workStr.substr(workStr.indexOf("."))

   while (pStr.length-1< decimal){pStr+="0"}

   if(pStr =='.') pStr ='';

   //--- Adds a comma in the thousands place.    
   if (dNum>=1000) {
	  dLen=dStr.length
	  dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
   }

   //-- Adds a comma in the millions place.
   if (dNum>=1000000) {
	  dLen=dStr.length
	  dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
   }
   retval = dStr + pStr
   
   //   //-- Put numbers in parentheses if negative.
   //   if (anynum<0) {retval="("+retval+")";}
   //-- Put "-" in front of number if negative.
   if (anynum<0) {retval="-"+retval;}

  
//You could include a dollar sign in the return value.
  //retval =  "$"+retval
  
  //obj.value = retval;
  return retval
}                    
