var arrIFRPB = new Array(999);
var sGlobalCommentType = "";
var iMaxIFRPB = 0;
var ESC_DOWN   = false;
var SHIFT_DOWN = false;
var CTRL_DOWN  = false;
var A_DOWN     = false;
var E_DOWN     = false;
var bIsPosting = false;
var bShowXML = false;
var bShowIFrame = false;
document.onkeydown = function(evt) {
	try{
		evt = (evt) ? evt : window.event
		var keyCode = evt.keyCode;
		if(keyCode==17)SHIFT_DOWN=true;
		if(keyCode==16)CTRL_DOWN=true;
		if(keyCode==65)A_DOWN=true;
		if(keyCode==69)E_DOWN=true;
		if(keyCode==27)ESC_DOWN=true;
		if(SHIFT_DOWN & CTRL_DOWN & A_DOWN && !bShowXML) {	
			bShowXML = true;
			var xml = new ActiveXObject('MSXML2.FreeThreadedDOMDocument');
			xml.loadXML(parent.document.all.header_iptSession.value);
			bShowXML = false;
			SHIFT_DOWN = false;
			CTRL_DOWN = false;
			A_DOWN = false;
			ESC_DOWN = false;
			alert(xml.xml);
		}
		if(ESC_DOWN) {
			
		}
	} catch(e){}
}

function timeSplit(sTime) {
	if(sTime.charAt(0) > '1') {
	    sTime = '0' + sTime;
	}
	var arr = new Array();
	arr.push(sTime.substr(0,2));
	arr.push(sTime.substr(3,2));
	if(sTime.length > 8) { // We have Hour,Min,Secs, AM/PM
		arr.push(sTime.substr(9,2));
	} else {
		arr.push(sTime.substr(6,2));
	}
	
	return arr;
}

function timeAddMinutes(sTime, sMinutes) {
	var arr = new Array();
	var arr = timeSplit(sTime);
	var d = new Date();
	if(arr[2] == 'PM') {
		var milHour = Number(arr[0]) + Number(12);
		d.setHours(milHour);
	} else {
		d.setHours(arr[0]);
	}
	d.setMinutes(arr[1]);
	d.setSeconds(0);
	var mins = Number(d.getMinutes()) + Number(sMinutes);
	d.setMinutes(mins);
	
	return d.toLocaleTimeString();
}

function checkScrolled()
{
	frmObj.top=eval(scrolled)+ltop+'px';
	setTimeout('checkScrolled()',scrollSpeed);
}

function addRoundCorner(el)
{
 el.runtimeStyle.behavior="none";
 var c = "<div style='clear:both'></div>";
 el.insertAdjacentHTML("AfterBegin", "<div class=rch>"+ c +"<div class=rc_l></div><div class=rc_r></div>"+ c +"</div>");
 el.insertAdjacentHTML("BeforeEnd","<div class=rcf>"+ c +"<div class=rc_l></div><div class=rc_r></div>"+ c +"</div>");
}

function tdHov(tdObj,cls)
{
	tdObj.className=cls;
}

function getBitFromBool(bVal)
{
	if(bVal)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

var srcElem;
var intMouseX = 0;
var intMouseY = 0;
var mx=0;
var my=0;

document.onmousemove = getMouseXY;
var bIsPosting=false;


function escapeXML(sXML)
{
	
	return sXML.replace(/&/g,'&amp;');
}


function IFReturn(sSub,iIFRID)
{
	document.getElementById('ifr_'+sSub).contentWindow.document.all.args.value=arrIFRPB[iIFRID] ;
	document.getElementById('ifr_'+sSub).contentWindow.cmdDoPostBack();
}

function popHelp()
{
	var popH = screen.height-20;
	var popW = screen.width-20;
	var winleft = (screen.width - popW) / 2;
	var winUp = (screen.height - popH) / 2;
	winProp = 'width='+popW+
				',height='+popH+
				',left='+winleft+
				',top='+winUp+
				',scrollbars=1,menubar=1,resizable=1,toolbar=1'
	Win = window.open('http://www.appointmate.com/help/', 'popMap', winProp);
	Win.window.focus();
}

function getMap(iCustomerID, iResourceID, iApptID)
{
	var sArgs ='CustomerID=='+iCustomerID+'||ResourceID=='+iResourceID+'||ApptID=='+iApptID;
	IFRPB2('getMap',sArgs,'getMapProcess()');
}

function getMapProcess()
{
	var sMapPath = document.all.ifr_getMap.contentWindow.document.all.xmlReturn.innerHTML;
	popMap(sMapPath);
}

function popMap(URL)
{
	var popH = screen.height-20;
	var popW = screen.width-20;
	var winleft = (screen.width - popW) / 2;
	var winUp = (screen.height - popH) / 2;
	winProp = 'width='+popW+
				',height='+popH+
				',left='+winleft+
				',top='+winUp+
				',scrollbars=1,menubar=1,resizable=1,toolbar=1'
	Win = window.open(URL, 'popMap', winProp);
	Win.window.focus();
}


function IFRPB2(sSub,sArgs,sOnLoad)
{
	if (sArgs.length==0){sArgs='args=none';}
	if(eval('document.all.ifr_'+sSub)!=null)
	{
		arrIFRPB[iMaxIFRPB] = sArgs;
		eval('document.all.ifr_'+sSub).src = 'IFRPB.aspx?sSub='+sSub+'&IFRID='+iMaxIFRPB+'&OnLoad='+sOnLoad;
		iMaxIFRPB+=1;
	}
	else
	{
		arrIFRPB[iMaxIFRPB] = sArgs;
		sIFR = '<iframe id="ifr_'+sSub+'" runat="server" frameborder="0" src="IFRPB.aspx?sSub='+sSub+'&IFRID='+iMaxIFRPB+'&OnLoad='+sOnLoad+'" style="HEIGHT:0px;WIDTH:0px;VISIBILITY:hidden;DISPLAY:none;"></iframe>';
		//alert(sArgs);
		iMaxIFRPB+=1;
		document.body.insertAdjacentHTML('beforeEnd', sIFR);
	}
	
}

function IFRPB(sSub,sArgs,sOnLoad)
{
	if (sArgs.length==0){sArgs='args=none';}
	if(!bIsPosting)
	{	
		bIsPosting = true;
		try{
		document.getElementById("header_ifrPB").contentWindow.document.all.args.value=sArgs;
		document.getElementById("header_ifrPB").contentWindow.document.all.sSub.value=sSub;
		document.getElementById("header_ifrPB").contentWindow.document.all.onLoad.value=sOnLoad;
		document.getElementById("header_ifrPB").contentWindow.cmdDoPostBack();
		}
		catch(e)
		{
			try{
				document.getElementById("ifrPB").contentWindow.document.all.args.value=sArgs;
				document.getElementById("ifrPB").contentWindow.document.all.sSub.value=sSub;
				document.getElementById("ifrPB").contentWindow.document.all.onLoad.value=sOnLoad;
				document.getElementById("ifrPB").contentWindow.cmdDoPostBack();
			}
			catch(e){}
		}
	}
}

function moveListItem( srcList, destList, moveAll ) 
{
	// Do nothing if nothing is selected
	if ( ( srcList.selectedIndex == -1 ) && ( moveAll == false ) ) { return; }
	
	newDestList = new Array( destList.options.length );
	var len = 0;
	for( len = 0; len < destList.options.length; len++ ) {
			if ( destList.options[ len ] != null ) {
			newDestList[ len ] = new Option( 
				destList.options[ len ].text, 
				destList.options[ len ].value, 
				destList.options[ len ].defaultSelected, 
				destList.options[ len ].selected );
		}
	}

	for( var i = 0; i < srcList.options.length; i++ ) {
	//alert(0);//alert(srcList.options[i].value); 
		if ( srcList.options[i] != null && srcList.options[i].value!=-1 && ( srcList.options[i].selected == true || moveAll ) ) {
			newDestList[ len ] = new Option( 
				srcList.options[i].text.replace('-----','*'), 
				srcList.options[i].value, 
				srcList.options[i].defaultSelected, 
				srcList.options[i].selected );
			len++;
		}
	}
	//newDestList.sort( compareOptionValues );   // BY VALUES
	//newDestList.sort( compareOptionText );   // BY TEXT

	// Populate the destination with the items from the new array
	for ( var j = 0; j < newDestList.length; j++ ) {
		if ( newDestList[ j ] != null )	{
			destList.options[ j ] = newDestList[ j ];
		}
	}
	// Erase source list selected elements
	for( var i = srcList.options.length - 1; i >= 0; i-- ) { 
		if ( srcList.options[i] != null && srcList.options[i].value!=-1 && ( srcList.options[i].selected == true || moveAll ) )	{
			//srcList.options[i].value = "";
			//srcList.options[i].text  = "";
			srcList.options[i]       = null;
		}
	}
}


function bOvr(obj)
{
	obj.className ='btnOvr';
	//obj.style.color = 'red';
	//obj.style.textDecoration = 'underline';
}

function bOut(obj)
{
	obj.className ='btnOut';
	//obj.style.color = 'blue';
	//obj.style.textDecoration = 'none';
}


function swpImg(obj)
{
	if (obj.src.indexOf('_sel')==-1)
	{
		obj.src = obj.src.replace('.gif','_sel.gif');
	}
	else
	{
		obj.src = obj.src.replace('_sel.gif','.gif');
	}
	return true;
}

function mOvr(obj)
{
	obj.style.color = 'red';
	obj.style.textDecoration = 'underline';
}

function mOut(obj)
{
	obj.style.color = 'blue';
	obj.style.textDecoration = 'none';
}

function mOvrI(obj)
{
	obj.style.border = 'GhostWhite thin solid';
	obj.style.borderRight = 'silver thin ridge';
	obj.style.borderBottom = 'silver thin ridge';
}

function mOutI(obj)
{
	obj.style.border = '';
	
	obj.style.borderRight = '';
	obj.style.borderBottom = '';
	obj.style.borderLeft = '';
	obj.style.borderTop = '';
}

function dayOver(obj)
{
	obj.style.border='#ffff99 double';
}

function dayOut(obj)
{
	obj.style.border='';
}

function showErr(linkObj,baseObj,xmlObjName)
{
	var popupObj = window.createPopup();
	var popupBodyObj = popupObj.document.body;
	
	var menuID = document.all.tblMemo;
	document.all.divMemo.style.visibility='visible';
	document.all.divMemo.style.display='block';
	document.all.spnMemo.innerHTML = eval('document.all.spnErr'+baseObj+getRecord(linkObj.recordNumber,xmlObjName)).innerHTML;
	
	popupBodyObj.innerHTML = menuID.outerHTML;
	popupObj.show(0, eval(linkObj.offsetHeight +10), menuID.offsetWidth, menuID.offsetHeight, linkObj);
}

function showHelp(linkObj,baseObj)
{
	var popupObj = window.createPopup();
	var popupBodyObj = popupObj.document.body;
	
	var menuID = document.all.tblMemo;
	document.all.divMemo.style.visibility='visible';
	document.all.divMemo.style.display='block';
	document.all.spnMemo.innerHTML = eval('document.all.spnHelp'+baseObj).innerHTML;
	
	popupBodyObj.innerHTML = menuID.outerHTML;
	popupObj.show(0, eval(linkObj.offsetHeight +10), menuID.offsetWidth, menuID.offsetHeight, linkObj);
}

function showWindow(strLoc)
{
	options = 'toolbar=1,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=';
	options += screen.width/1.2;
	options += ',height=';
	options += screen.height/2;
	options += ',left =';
	options += screen.width/12;
	options += ',top ='
	options += screen.height/4;

	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open('../'+strLoc, '" + id + "', options);");
}

function getIntFromBool(bVal)
{
	if(bVal)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}


function getBoolFromInt(iVal)
{
	if(iVal==0)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function isDate(dateStr) {

  var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
  var matchArray = dateStr.match(datePat); // is format OK?

  if (matchArray == null) {
    //alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
    return false;
  }

  // parse date into variables
  month = matchArray[1];
  day = matchArray[3];
  year = matchArray[5];

  if (month < 1 || month > 12) { // check month range
    //alert("Month must be between 1 and 12.");
    return false;
  }

  if (day < 1 || day > 31) {
    //alert("Day must be between 1 and 31.");
    return false;
  }

  if ((month==4 || month==6 || month==9 || month==11) && day==31) {
    //alert("Month " + month + " doesn't have 31 days!")
    return false;
  }

  if (month == 2) { // check for february 29th
    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
    if (day > 29 || (day==29 && !isleap)) {
      //alert("February " + year + " doesn't have " + day + " days!");
      return false;
    }
  }
  return true;  // date is valid
}

function showReport(strLoc)
{
	options = 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=';
	options += screen.width/1.1;
	options += ',height=';
	options += screen.height/1.25;
	options += ',left =';
	options += screen.width/20;
	options += ',top ='
	options += screen.height/20;

	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(strLoc, '" + id + "', options);");
}
function getDate()
{
	var d = new Date()
	return eval(d.getMonth()+ 1)+'/'+d.getDate()+'/'+d.getFullYear()
}

function dateAdd( start, interval, number ) {
	
	//alert(start);
	//alert(interval);
	//alert(number);
    // Create 3 error messages, 1 for each argument. 
    var startMsg = "Sorry the start parameter of the dateAdd function\n"
        startMsg += "must be a valid date format.\n\n"
        startMsg += "Please try again." ;
		
    var intervalMsg = "Sorry the dateAdd function only accepts\n"
        intervalMsg += "d, h, m OR s intervals.\n\n"
        intervalMsg += "Please try again." ;

    var numberMsg = "Sorry the number parameter of the dateAdd function\n"
        numberMsg += "must be numeric.\n\n"
        numberMsg += "Please try again." ;
		
    // get the milliseconds for this Date object. 
    var buffer = Date.parse( start ) ;
	
    // check that the start parameter is a valid Date. 
    if ( isNaN (buffer) ) {
        alert( startMsg ) ;
        return null ;
    }
	
    // check that an interval parameter was not numeric. 
    if ( interval.charAt == 'undefined' ) {
        // the user specified an incorrect interval, handle the error. 
        alert( intervalMsg ) ;
        return null ;
    }

    // check that the number parameter is numeric. 
    if ( isNaN ( number ) )	{
        alert( numberMsg ) ;
        return null ;
    }

    // so far, so good...
    //
    // what kind of add to do? 
    switch (interval.charAt(0))
    {
        case 'd': case 'D': 
            number *= 24 ; // days to hours
            // fall through! 
        case 'h': case 'H':
            number *= 60 ; // hours to minutes
            // fall through! 
        case 'm': case 'M':
            number *= 60 ; // minutes to seconds
            // fall through! 
        case 's': case 'S':
            number *= 1000 ; // seconds to milliseconds
            break ;
        default:
        // If we get to here then the interval parameter
        // didn't meet the d,h,m,s criteria.  Handle
        // the error. 		
        alert(intervalMsg) ;
        return null ;
    }
    return new Date( buffer + number ) ;
}

function DateAdd_old(startDate, numDays, numMonths, numYears)
{
	var returnDate = new Date(Date.parse( startDate ));
	var yearsToAdd = numYears;
	
	var month = returnDate.getMonth()	+ numMonths;
	if (month > 11)
	{
		yearsToAdd = Math.floor((month+1)/12);
		month -= 12*yearsToAdd;
		yearsToAdd += numYears;
	}
	returnDate.setMonth(month);
	returnDate.setFullYear(returnDate.getFullYear()	+ yearsToAdd);
	
	returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);
	
	return returnDate;

}

function YearAdd(startDate, numYears)
{
		return DateAdd(startDate,0,0,numYears);
}

function MonthAdd(startDate, numMonths)
{
		return DateAdd_old(startDate,0,numMonths,0);
}

function DayAdd(startDate, numDays)
{
		return DateAdd(startDate,numDays,0,0);
}

function addZero(vNumber){ 
	return ((vNumber < 10) ? "" : "") + vNumber 
} 
    
function formatDate(vDate, vFormat){ 
	var vDay                      = addZero(vDate.getDate()); 
	var vMonth            = addZero(vDate.getMonth()+1); 
	var vYearLong         = addZero(vDate.getFullYear()); 
	var vYearShort        = addZero(vDate.getFullYear().toString().substring(3,4)); 
	var vYear             = (vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort) 
	var vHour             = addZero(vDate.getHours()); 
	var vMinute           = addZero(vDate.getMinutes()); 
	var vSecond           = addZero(vDate.getSeconds()); 
	var vDateString       = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear) 
	vDateString           = vDateString.replace(/hh/g, vHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond) 
	return vDateString 
} 

function editField(strObj,intNumber,strGroup)
{
	try{
		if(eval('document.all.ipt'+strGroup+strObj+getRecord(intNumber,strGroup)).type='checkbox')
		{
			eval('arr'+strGroup)[eval('arr'+strGroup).length]=eval('document.all.ipt'+strGroup+strObj+getRecord(intNumber,strGroup)).checked;
		}
		else
		{
			eval('arr'+strGroup)[eval('arr'+strGroup).length] = eval('document.all.ipt'+strGroup+strObj+getRecord(intNumber,strGroup)).value;
		}
	}
	catch(e)
	{
		eval('arr'+strGroup)[eval('arr'+strGroup).length] = eval('document.all.ipt'+strGroup+strObj+getRecord(intNumber,strGroup)).value;
	}
	
	eval('document.all.spn'+strGroup+strObj+getRecord(intNumber,strGroup)).style.visibility ='hidden';
	eval('document.all.spn'+strGroup+strObj+getRecord(intNumber,strGroup)).style.display ='none';
	eval('document.all.spnEdit'+strGroup+strObj+getRecord(intNumber,strGroup)).style.visibility ='visible';
	eval('document.all.spnEdit'+strGroup+strObj+getRecord(intNumber,strGroup)).style.display ='block';
}

function updateField(strObj,intNumber,strGroup)
{
	eval('document.all.spn'+strGroup+strObj+getRecord(intNumber,strGroup)).style.visibility ='visible';
	eval('document.all.spn'+strGroup+strObj+getRecord(intNumber,strGroup)).style.display ='block';
	eval('document.all.spnEdit'+strGroup+strObj+getRecord(intNumber,strGroup)).style.visibility ='hidden';
	eval('document.all.spnEdit'+strGroup+strObj+getRecord(intNumber,strGroup)).style.display ='none';
}

function cancelField(strObj,intNumber,strGroup,intObjCount)
{	
	//alert(eval('arr'+strGroup)[intObjCount]);
	if(eval('arr'+strGroup)[intObjCount]=='on'){eval('document.all.ipt'+strGroup+strObj+getRecord(intNumber,strGroup)).checked = 'checked';}
	if(eval('arr'+strGroup)[intObjCount]=='off'){eval('document.all.ipt'+strGroup+strObj+getRecord(intNumber,strGroup)).checked = '';}
	
	//eval('document.all.ipt'+strGroup+strObj+getRecord(intNumber,strGroup)).value = eval('arr'+strGroup)[intObjCount];
	eval('document.all.ipt'+strGroup+strObj+getRecord(intNumber,strGroup)).value = eval('arr'+strGroup)[intObjCount];
	eval('document.all.spn'+strGroup+strObj+getRecord(intNumber,strGroup)).style.visibility ='visible';
	eval('document.all.spn'+strGroup+strObj+getRecord(intNumber,strGroup)).style.display ='block';
	eval('document.all.spnEdit'+strGroup+strObj+getRecord(intNumber,strGroup)).style.visibility ='hidden';
	eval('document.all.spnEdit'+strGroup+strObj+getRecord(intNumber,strGroup)).style.display ='none';
}

function editClick(strGroup,intRow)
{
	eval('document.all.Edit'+strGroup+getRecord(intRow,strGroup)).style.visibility = 'hidden';
	eval('document.all.Edit'+strGroup+getRecord(intRow,strGroup)).style.display = 'none';
	eval('document.all.Delete'+strGroup+getRecord(intRow,strGroup)).style.display = 'none';
	eval('document.all.Update'+strGroup+getRecord(intRow,strGroup)).style.visibility = 'visible';
	eval('document.all.Update'+strGroup+getRecord(intRow,strGroup)).style.display = 'block';
	eval('document.all.Cancel'+strGroup+getRecord(intRow,strGroup)).style.visibility = 'visible';
	eval('document.all.Cancel'+strGroup+getRecord(intRow,strGroup)).style.display = 'block';
	
}

function updateCancelClick(strGroup,intRow)
{
	eval('document.all.Edit'+strGroup+getRecord(intRow,strGroup)).style.visibility = 'visible';
	eval('document.all.Edit'+strGroup+getRecord(intRow,strGroup)).style.display = '';
	eval('document.all.Delete'+strGroup+getRecord(intRow,strGroup)).style.visibility = 'visible';
	eval('document.all.Delete'+strGroup+getRecord(intRow,strGroup)).style.display = '';
	eval('document.all.Update'+strGroup+getRecord(intRow,strGroup)).style.visibility = 'hidden';
	eval('document.all.Update'+strGroup+getRecord(intRow,strGroup)).style.display = 'none';
	eval('document.all.Cancel'+strGroup+getRecord(intRow,strGroup)).style.visibility = 'hidden';
	eval('document.all.Cancel'+strGroup+getRecord(intRow,strGroup)).style.display = 'none';
}

function checkLocation(obj)
{
	if(obj.value >=990)
	{
		document.all.fntLocation.color = 'black';
		document.all.txtLocationNumber.disabled = true;
		document.all.txtLocationNumber.value = '[N/A]';
	}
	else
	{
		document.all.fntLocation.color = 'red';
		document.all.txtLocationNumber.disabled = false;
		document.all.txtLocationNumber.value = '';
	}
}

function checkRecords(strGroup)
{
	
	try{
		if (eval('xml'+strGroup).xml.length <= 25)
		{	eval('document.all.div'+strGroup).style.visibility = 'hidden';
			eval('document.all.div'+strGroup).style.display = 'none';
			eval('document.all.spn'+strGroup+'NoRecords').style.visibility = 'visible';
			eval('document.all.spn'+strGroup+'NoRecords').style.display = 'block';
			try{if(!bolSave){eval('document.all.xml'+strGroup+'New').value = '';}}catch(e){}
			return false;
		}
		else
		{	eval('document.all.div'+strGroup).style.visibility = 'visible';
			eval('document.all.div'+strGroup).style.display = 'block';
			eval('document.all.spn'+strGroup+'NoRecords').style.visibility = 'hidden';
			eval('document.all.spn'+strGroup+'NoRecords').style.display = 'none';
			try{if(!bolSave){eval('document.all.xml'+strGroup+'New').value = '';}}catch(e){}
			return true;
		}
	}
	catch(e)
	{
		eval('document.all.div'+strGroup).style.visibility = 'hidden';
		eval('document.all.div'+strGroup).style.display = 'none';
		eval('document.all.spn'+strGroup+'NoRecords').style.visibility = 'visible';
		eval('document.all.spn'+strGroup+'NoRecords').style.display = 'block';
			try{if(!bolSave){eval('document.all.xml'+strGroup+'New').value = '';}}catch(e){}
		return false;
	}
}

function syncChanges(strObj)
{
 	var xmlDoc = new ActiveXObject('MSXML2.FreeThreadedDOMDocument');
	xmlDoc.async = false;
	xmlDoc.loadXML(eval('xml'+strObj).xml);
	
	eval('document.all.xml'+strObj+'New').value = xmlDoc.xml;
	//prompt(xmlDoc.xml,xmlDoc.xml,xmlDoc.xml);
	//showDeleted(strObj);
	//window.setTimeout('showDeleted("'+strObj+'");',2000);
	return true;
}
/*
function showDeleted(strGroup)
{
	for (var j = 0; j < eval('xml'+strGroup).recordset.RecordCount; j++)
	{
		if( eval('xml'+strGroup).firstChild.childNodes[j].getElementsByTagName('Updated')[0].text=='2')
		{
			eval('tr'+strGroup+getRecord(j+1,strGroup)).className ='DataCol_del';
		}
		else
		{
			eval('tr'+strGroup+getRecord(j+1,strGroup)).className ='DataCol';
		}
	}
}
*/
function syncChanges2(objXMLIsland,objXMLDocElem)
{
	objXMLIsland.loadXML(objXMLDocElem.xml);
}

function SyncNodes(xmlIsland, xmlInput) {
	// save to xml island...
	eval(xmlIsland).loadXML(xmlInput);
	// copy to hidden input for postback...
	try {
		eval('document.all.ipt' + xmlIsland).value = xmlInput;
	}
	catch (er) {}
}

function getElem(Obj)
{
	if(eval('xml'+Obj).recordset.RecordCount > 1)
	{
		eval('xml'+Obj).recordset.AbsolutePosition = srcElem.recordNumber;
		return '('+ eval(srcElem.recordNumber - 1)+')';
	}
	else
	{
		eval('xml'+Obj).recordset.AbsolutePosition = srcElem.recordNumber;
		return '';
	}
}

function getRecord(intNumber, Obj)
{
	if (intNumber == -1)
	{
		return '';
	}
	
	if(eval('xml'+Obj).recordset.RecordCount > 1)
	{
		return '('+(intNumber-1)+')';
	}
	else
	{
		return '';
	}
}


function getMouseXY(e)
{
    intMouseX = event.CustomerX + document.body.scrollLeft;
    intMouseY = event.CustomerY + document.body.scrollTop;
}


function Len(str)
{
	return String(str).length;
}

function Mid(str, start, len)
{
	// Make sure start and len are within proper bounds
	if (start < 0 || len <= 0) return '';

	var iEnd, iLen = String(str).length;
	if (start + len > iLen)
		iEnd = iLen;
	else
		iEnd = start + len;
	return String(str).substring(start,iEnd);
}

function InStr(strSearch, charSearchFor)
{
	for (i=0; i < Len(strSearch); i++)
	{
		if (charSearchFor == Mid(strSearch, i, String(charSearchFor).length))
		{
			return i;
		}
	}
	return -1;
}
	
function Right(str, n) 
{
	if (n <= 0)     // Invalid bound, return blank string
		return '';
    else
    {				// Valid bound, return appropriate substring
		var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}

function Left(str, n) 
{
	if (n <= 0)		// Invalid bound, return blank string
		return '';
	else if (n > String(str).length) // Invalid bound, return
		return str;						// entire string
	else				// Valid bound, return appropriate substring
		return String(str).substring(0,n);
}

function RTrim(str) 
{
        var whitespace = new String(" \t\n\r");
        var s = new String(str);
        if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
            var i = s.length - 1;       // Get length of string
            while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                i--;
            s = s.substring(0, i+1);
        }
        return s;
}

function buildXMLNodeFromList(objList, nodeRoot, nodeChild, bAllItems) 
{
	var bSelected = false;
	var strXMLNode = '';
	
	if ( bAllItems == false )
	{
		for (var i=0; i <= eval('document.all.'+objList).length - 1 ; i++)
		{
			if ( eval('document.all.'+objList+'['+i+']').selected ) {
				strXMLNode = strXMLNode + '<' + nodeRoot + '>'
										+ '<' + nodeChild + '>'
										+ eval('document.all.'+objList+'['+i+']').value
										+ '</' + nodeChild + '>'
										+ '</' + nodeRoot + '>';
				bSelected = true;
			}
		}
	}
	if ( bSelected == false || bAllItems == true )
	{
		strXMLNode = '';
		for (var i=0; i <= eval('document.all.'+objList).length - 1 ; i++)
		{
			strXMLNode = strXMLNode + '<' + nodeRoot + '>'
									+ '<' + nodeChild + '>'
									+ eval('document.all.'+objList+'['+i+']').value
									+ '</' + nodeChild + '>'
									+ '</' + nodeRoot + '>';
		}
	}
	return strXMLNode;
}

function compareOptionValues(a, b) 
{ 
	// Radix 10: for numeric values, Radix 36: for alphanumeric values
	var sA = parseInt( a.value, 36 );  
	var sB = parseInt( b.value, 36 );  
	return sA - sB;
}
function compareOptionText(a, b) 
{ 
	
	//a = replaceChars(a);
	//b = replaceChars(b);
	// Radix 10: for numeric values, Radix 36: for alphanumeric values
	var sA = parseInt( a.text, 36 );  
	var sB = parseInt( b.text, 36 );  
	return sA - sB;
}

function replaceChars(entry,out,add) {
	//out = '\s'; // replace this
	//add = ''; // with this
	temp = '' + entry; // temporary holder

	while (temp.indexOf(out)>-1)
	{
		pos= temp.indexOf(out);
		temp = '' + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}
	return temp;
}

function showMessage(linkObj,intNumber,Obj) 
{
	var sHTML = "";
	try{sHTML = eval('document.all.spnErr'+ Right(linkObj.id,Len(linkObj.id)-3)+getRecord(intNumber, Obj)).innerHTML;}
	catch(e){}
	try{sHTML = eval('document.all.spn'+ Right(linkObj.id,Len(linkObj.id)-3)+getRecord(intNumber, Obj)).innerHTML;}
	catch(e){}
	Obj.onMouseOut = "hideddrivetip()";
	ddrivetip(sHTML, '#DFDFFF',250);
}

function resizeTA(TA) 
{
  var winW, winH;
  var usingIE = 0;

  // these paramaters have to match the font you specify with your
  // style tag on the textarea.
  var fontMetricWidth = 7;
  var fontMetricHeight = 14;

  // you don't want this smaller than 1,1
  var minWidthInCols = 20;
  var minHeightInRows = 7;

  // offset fudge factors. 
  // Making these bigger makes the textarea smaller.
  var leftOffsetFudge = 55;
  var topOffsetFudge = 25;


  if (parseInt(navigator.appVersion)>3) {
    if (navigator.appName=="Netscape") {
      winW = window.innerWidth;
      winH = window.innerHeight; 
    }
    if (navigator.appName.indexOf("Microsoft")!=-1) {
      winW = document.body.offsetWidth;
      winH = document.body.offsetHeight;
      usingIE = 1;
    }
  }

  if (! usingIE ) {
    return; // this javascript below does not work for netscape
  }

  // this code computes the upper-left corner offset
  // by walking all the elements in the html page  
  toffset = 0;
  loffset = 0;
  offsetobj = TA;
  while (offsetobj) {
    toffset += offsetobj.offsetTop + offsetobj.CustomerTop;
    loffset += offsetobj.offsetLeft + offsetobj.CustomerLeft;
    offsetobj = offsetobj.offsetParent;
  }

  // compute and set the width
  var overhead = loffset + leftOffsetFudge;
  var ta_width = ((winW - overhead))  / fontMetricWidth;
  if (ta_width < minWidthInCols) {
    ta_width = minWidthInCols;
  }
  TA.cols = ta_width;

/*
  // compute and set the height
  var overhead = toffset + topOffsetFudge;
  var ta_height = (winH - overhead) / fontMetricHeight;
  if (ta_height < minHeightInRows) {
    ta_height = minHeightInRows;
  }
  TA.rows = ta_height;
  */
}

function resizeTAFull(TA) 
{
  var winW, winH;
  var usingIE = 0;

  // these paramaters have to match the font you specify with your
  // style tag on the textarea.
  var fontMetricWidth = 7;
  var fontMetricHeight = 14;

  // you don't want this smaller than 1,1
  var minWidthInCols = 20;
  var minHeightInRows = 7;

  // offset fudge factors. 
  // Making these bigger makes the textarea smaller.
  var leftOffsetFudge = 60;
  var topOffsetFudge = 30;


  if (parseInt(navigator.appVersion)>3) {
    if (navigator.appName=="Netscape") {
      winW = window.innerWidth;
      winH = window.innerHeight; 
    }
    if (navigator.appName.indexOf("Microsoft")!=-1) {
      winW = document.body.offsetWidth;
      winH = document.body.offsetHeight;
      usingIE = 1;
    }
  }

  if (! usingIE ) {
    return; // this javascript below does not work for netscape
  }

  // this code computes the upper-left corner offset
  // by walking all the elements in the html page  
  toffset = 0;
  loffset = 0;
  offsetobj = TA;
  while (offsetobj) {
    toffset += offsetobj.offsetTop + offsetobj.CustomerTop;
    loffset += offsetobj.offsetLeft + offsetobj.CustomerLeft;
    offsetobj = offsetobj.offsetParent;
  }

  // compute and set the width
  var overhead = loffset + leftOffsetFudge;
  var ta_width = ((winW - overhead))  / fontMetricWidth;
  if (ta_width < minWidthInCols) {
    ta_width = minWidthInCols;
  }
  TA.cols = ta_width;


  // compute and set the height
  var overhead = toffset + topOffsetFudge;
  var ta_height = (winH - overhead) / fontMetricHeight;
  if (ta_height < minHeightInRows) {
    ta_height = minHeightInRows;
  }
  TA.rows = ta_height;
}

function getObject(objectId) {
	if (document.all && !document.getElementById) {
		return document.all(objectId)
	} else {
		return document.getElementById(objectId)
	}
}

//Telephone Mask Function

function ValidatePhone(p1)
{
var p = '' + p1.value;
var p2 = '';

for (var i=0; i < p.length+1; i++)
{
	if (!isNaN(p.substring(i-1,i)))
	{
		p2 = p2 + p.substring(i-1,i);
	}
}
p = p2;

if(p.length==1)
{
	pp=p;
	d4=p.indexOf('(')
	pp='('+pp;
	//p1.value=pp;
}

if(p.length==3)
{
	pp=p;
	d4=p.indexOf('(')
	d5=p.indexOf(')')
	if(d4==-1)
	{
		pp="("+pp;
	}
	if(d5==-1)
	{
		pp=pp+") ";
	}
	//p1.value="";
	//p1.value=pp;
}

if(p.length>3)
{
	d1=p.indexOf('(')
	d2=p.indexOf(')')
	if (d2==-1)
	{
		l30=p.length;
		p30=p.substring(0,5);
		p30=p30+") " 
		p31=p.substring(5,l30);
		pp=p30+p31;
		//p1.value="";
		//p1.value=pp;
	}
}
if(p.length>4){
	p11=p.substring(d1+1,d2);
	if(p11.length>3)
	{
		p12=p11;
		l12=p12.length;
		l15=p.length
		p13=p11.substring(0,3);
		p14=p11.substring(3,l12);
		p15=p.substring(d2+1,l15);
		p1.value="";
		pp="("+p13+") "+p14+p15;
		//p1.value=pp;
	}
	l16=p.length;
	p16=p.substring(d2+1,l16);
	l17=p16.length;
	if(l17>3&&p16.indexOf('-')==-1)
	{
		p17=p.substring(d2+1,d2+5);
		p18=p.substring(d2+5,l16);
		p19=p.substring(0,d2+1);
		pp=p19+p17+"-"+p18;
		//p1.value="";
		//p1.value=pp;
	}
	p1.value=pp;
}
}

function valTel(key,m)
{
	var bolVal = true;
	if ( ((key>47&&key<58)||(key>95&&key<106)))
	{
		if(m.value.length > 13){return false;}
		else{return MaskFilter(key, m, '(###) ###-####');}
		
	}
	else if ((key==16) || (key==8) || (key==9) || (key==46) || (key==37) || (key==38) || (key==39) || (key==40))
		{return true;}
	else if (key==13) 
		{MaskFilter(key,m,'(###) ###-####');
		return true;}
	else
	{
		return false;
	}
}
//End Telephone Mask Function

//Zipcode Mask Function
var n;
var p;
var p1;
function ValidateZip(){
p=p1.value

	if(p.length>4 && p.indexOf('-')>=0)
	{
		pa=p.substring(0,5);
		pb=p.substring(6,p.length);
		p1.value = pa+'-'+pb;
	}

	else if(p.length>4 && p.indexOf('-')==-1)
	{
		pa=p.substring(0,5);
		pb=p.substring(5,p.length);
		p1.value = pa+'-'+pb;
	}
	//setTimeout(ValidateZip,100)
}

function valZip(key,m)
{
	var bolVal = true;
	n=m.name;
	p1=m;

	if ( ((key>47&&key<58)||(key>95&&key<106)))
	{
		ValidateZip();
		if(m.value.length > 9){m.value = Left(m.value,Len(m.value) - 1);}
	}
	else if ((key==13) || (key==8) || (key==9) || (key==46) || (key==37) || (key==38) || (key==39) || (key==40)){return true;}
	else
	{
		return false;
	}
}
//End Zipcode Mask Function

//Number Validation
function valNum(key)
{
	if ((key>47&&key<58) || (key>95&&key<106) || (key==16) || (key==13) || (key==8) || (key==9) || (key==46) || (key==37) || (key==38) || (key==39) || (key==40)){return true;}
	else
	{
		alert('This field accepts only numeric values.');
		return false;
	}
}

function valDate(key)
{
	if ((key>47&&key<58) || (key>95&&key<106) || (key>36&&key<41) || (key==13) || (key==191) || (key==111) || (key==8) || (key==9) || (key==46) ){return true;}
	else
	{
		alert('Please enter a valid date in the MM/DD/YYYY format.');
		return false;
	}
}

function valPage(key)
{
	if ((key>47&&key<58) || (key>95&&key<106) || (key>36&&key<41) || (key==8) || (key==9) || (key==46) )
	{
		return true;
	}
	else if(event.keyCode=='13')
	{
		__doPostBack('cmdPage','');
		return false;
	}
	else
	{
		return false;
	}
}

function valDec(key)
{
	if ((key>47&&key<58) || (key==16) || (key>95&&key<106) || (key==110) || (key==190) || (key==13) || (key==8) || (key==9) || (key==46) || (key==37) || (key==38) || (key==39) || (key==40)){return true;}
	else
	{
		alert('This field accepts only numeric (decimal) values.');
		return false;
	}
}

function validateSSN(ssn) {
	var matchArr = ssn.match(/^(\d{3})-?\d{2}-?\d{4}$/);
	if (matchArr == null || parseInt(matchArr[1],10)==0) {
		return false;
	} else {
		return true;
	}
}

function validateCreditCard(type, ccnum) {
   if (type == "Visa") {
      // Visa: length 16, prefix 4, dashes optional.
      var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
   } else if (type == "MC") {
      // Mastercard: length 16, prefix 51-55, dashes optional.
      var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
   } else if (type == "Disc") {
      // Discover: length 16, prefix 6011, dashes optional.
      var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
   } else if (type == "AmEx") {
      // American Express: length 15, prefix 34 or 37.
      var re = /^3[4,7]\d{13}$/;
   } else if (type == "Diners") {
      // Diners: length 14, prefix 30, 36, or 38.
      var re = /^3[0,6,8]\d{12}$/;
   }
   if (!re.test(ccnum)) return false;
   // Remove all dashes for the checksum checks to eliminate negative numbers
   ccnum = ccnum.split("-").join("");
   // Checksum ("Mod 10")
   // Add even digits in even length strings or odd digits in odd length strings.
   var checksum = 0;
   for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) {
      checksum += parseInt(ccnum.charAt(i-1));
   }
   // Analyze odd digits in even length strings or even digits in odd length strings.
   for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) {
      var digit = parseInt(ccnum.charAt(i-1)) * 2;
      if (digit < 10) { checksum += digit; } else { checksum += (digit-9); }
   }
   if ((checksum % 10) == 0) return true; else return false;
}

function validateDate(DateValue)
{
	var checkstr = '0123456789';
	var seperator = '/';
	var sepCount = 0
	var day = '';
	var month = '';
	var year = '';
	var leap = 0;
	var err = 0;
	var i;

	err = 0;
	/* Delete all chars except 0..9 */
	for (i = 0; i < DateValue.length; i++) { 
		if (seperator.indexOf(DateValue.substr(i,1)) >= 0) { sepCount++; }
		if (sepCount > 2) { sepCount = 2; }
		if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) 
		{
			switch ( sepCount ) 
			{
				case 0: month = month + DateValue.substr(i,1); break;
				case 1: day = day + DateValue.substr(i,1); break;
				case 2: year = year + DateValue.substr(i,1); break;
			}
		}
	}
	/* if year is entered as 2-digit / always assume 20xx */
	if (year.length != 4) { year = '20' + year; }
	/* Validation of year */
	year = eval(year);
	if ((year < 1901) || (year > 9999)) { err = 20; }
	/* Validation of month*/
	month = eval(month);
	if ((month < 1) || (month > 12)) { err = 21; }
	/* Validation of day*/
	day = eval(day);
	if (day < 1) { err = 22; }
	/* Validation leap-year / february / day */
	if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) { leap = 1; }
	if ((month == 2) && (leap == 1) && (day > 29)) { err = 23; }
	if ((month == 2) && (leap != 1) && (day > 28)) { err = 24; }
	/* Validation of other months */
	if ((day > 31) && (
			(month == "01") || 
			(month == "03") || 
			(month == "05") || 
			(month == "07") || 
			(month == "08") || 
			(month == "10") || 
			(month == "12"))	) { err = 25; }
	if ((day > 30) && (
			(month == "04") || 
			(month == "06") || 
			(month == "09") || 
			(month == "11"))	) { err = 26; }

	if (err == 0) {
		return true;
	}
	else {
		return false;
	}
}

function confirmLink ()
{
	try
	{
		if ( document.all.iptWizardActive.value == 'True' )
		{
			return confirm('This customer has an Affiliation but no Enrollment in the new program (Only enrolled programs are reported). \nSelect OK to leave this page without enrolling the customer, or Cancel to remain on this page add the Enrollment.');
			//Warning: You have not yet enrolled this new customer into the selected program. Do you wish to continue with this selection?
		}
		else
		{	return true; }
	}
	catch (e)
	{ return true; }
}

var dFilterStep

function dFilterStrip (dFilterTemp, dFilterMask)
{
    dFilterMask = replace(dFilterMask,'#','');
    for (dFilterStep = 0; dFilterStep < dFilterMask.length++; dFilterStep++)
	{
		dFilterTemp = replace(dFilterTemp,dFilterMask.substring(dFilterStep,dFilterStep+1),'');
	}
	return dFilterTemp;
}

function dFilterMax (dFilterMask)
{
 	dFilterTemp = dFilterMask;
	for (dFilterStep = 0; dFilterStep < (dFilterMask.length+1); dFilterStep++)
	{
		if (dFilterMask.charAt(dFilterStep)!='#')
		{
		dFilterTemp = replace(dFilterTemp,dFilterMask.charAt(dFilterStep),'');
		}
	}
	return dFilterTemp.length;
}

function MaskFilter (key, textbox, dFilterMask)
{
	if (key==9){return true;}
	
	textbox.value = FilterByMask(key, textbox.value, dFilterMask);
    return false;
}

function FilterByMask(key, theValue, theMask)
{
	dFilterNum = dFilterStrip(theValue, theMask);

	if (key==8&&dFilterNum.length!=0)
	{
		dFilterNum = dFilterNum.substring(0,dFilterNum.length-1);
	}
 	else if ( (key>47&&key<58) && dFilterNum.length<dFilterMax(theMask) )
	{	//valid number and within the mask...
		dFilterNum=dFilterNum+String.fromCharCode(key);
	}
	else if ( (key>95&&key<106) && dFilterNum.length<dFilterMax(theMask) )
	{	//valid keypad number and within the mask...
		dFilterNum=dFilterNum+String.fromCharCode(key-48);
	}
	
	var dMaskOnly = '';
	for (dFilterStep = 0; dFilterStep < theMask.length; dFilterStep++)
	{	if (theMask.charAt(dFilterStep)!='#'){
			dMaskOnly = dMaskOnly + theMask.charAt(dFilterStep);}
	}

	var dFilterFinal='';
	for (dFilterStep = 0; dFilterStep < theMask.length; dFilterStep++)
	{
		if (theMask.charAt(dFilterStep)=='#')
			{
				if (dFilterNum.length!=0)
				{
					dFilterFinal = dFilterFinal + dFilterNum.charAt(0);
					dFilterNum = dFilterNum.substring(1,dFilterNum.length);
				}
				else
				{
					dFilterFinal = dFilterFinal + '';
				}
			}
		 	else if (theMask.charAt(dFilterStep)!='#')
			{
				dFilterFinal = dFilterFinal + theMask.charAt(dFilterStep); 			
			}
	}
	if(dMaskOnly==dFilterFinal){return '';}
	else{return dFilterFinal;}
}

function replace(fullString,text,by) {
// Replaces text with by in string
    var strLength = fullString.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return fullString;

    var i = fullString.indexOf(text);
    if ((!i) && (text != fullString.substring(0,txtLength))) return fullString;
    if (i == -1) return fullString;

    var newstr = fullString.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(fullString.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function ghideElement( elmID, overDiv )
{
   
    for( i = 0; i < document.all.tags( elmID ).length; i++ )
    {
        obj = document.all.tags( elmID )[i];
        if( !obj || !obj.offsetParent )
        {
        continue;
        }
        // Find the element's offsetTop and offsetLeft relative to the BODY tag.
        objLeft   = obj.offsetLeft;
        objTop    = obj.offsetTop;
        objParent = obj.offsetParent;

        while( objParent.tagName.toUpperCase() != "BODY" )
        {
        objLeft  += objParent.offsetLeft;
        objTop   += objParent.offsetTop;
        objParent = objParent.offsetParent;
        }
    
        objHeight = obj.offsetHeight;
        objWidth = obj.offsetWidth;

        if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
        else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
        else if( overDiv.offsetTop >= ( objTop + objHeight ));
        else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
        else
        {
        obj.style.visibility = "hidden";
        }
    }
}
    
    
function hideSelects()
{
   
    for( i = 0; i < document.all.tags( "Select" ).length; i++ )
    {
        obj = document.all.tags( "select" )[i];       
        obj.style.visibility = "hidden";

    }
    
    for( i = 0; i < document.all.tags( "select" ).length; i++ )
    {
        obj = document.all.tags( "select" )[i];       
        obj.style.visibility = "hidden";

    }
}

function showSelects()
{
   
    for( i = 0; i < document.all.tags( "Select" ).length; i++ )
    {
        obj = document.all.tags( "select" )[i];       
        obj.style.visibility = "visible";

    }
    
    for( i = 0; i < document.all.tags( "select" ).length; i++ )
    {
        obj = document.all.tags( "select" )[i];       
        obj.style.visibility = "visible";

    }
}

function hideSelectsInArea(overDiv )
{
	var doc = document;
    for( i = 0; i < doc.all.tags( 'SELECT' ).length; i++ )
    {
      obj = doc.all.tags( 'SELECT' )[i];
      if( !obj || !obj.offsetParent )
      {
        continue;
      }

      // Find the element's offsetTop and offsetLeft relative to the BODY tag.
      
      objLeft   = obj.offsetLeft;
      objTop    = obj.offsetTop;
      objParent = obj.offsetParent;

      while( objParent.tagName.toUpperCase() != "BODY" )
      {
        objLeft  += objParent.offsetLeft;
        objTop   += objParent.offsetTop;
        objParent = objParent.offsetParent;
      }

      objHeight = obj.offsetHeight;
      objWidth = obj.offsetWidth;
      if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft )
		obj.style.visibility = "";
      else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop )
		obj.style.visibility = "";
      else if( overDiv.offsetTop >= ( objTop + objHeight ))
		obj.style.visibility = "";
      else if( overDiv.offsetLeft >= ( objLeft + objWidth ))
		obj.style.visibility = "";
      else
      {
        obj.style.visibility = "hidden";
      }
    }
}


/*
* unhides <select> and <applet> objects (for IE only)
*/
function gshowElement( elmID )
{
    for( i = 0; i < document.all.tags( elmID ).length; i++ )
    {
        obj = document.all.tags( elmID )[i];
        
        if( !obj || !obj.offsetParent )
        {
        continue;
        }
    
        obj.style.visibility = "";
    }
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 
}

//Date format function
// Copyright 2001, 2003 InterAKT Online. All rights reserved.
function editDatePre(obj, mask, event) {
	var keyCode = event.keyCode;
	if (keyCode == 0) {
		keyCode=event.charCode;
	}
	
	if(keyCode == 9) {
		return;
	}

	// if the user pressed "." we autocomplete with the current date
	if ((keyCode == 190 || keyCode == 110 || keyCode == 46) && (obj.value.length == 0)) {
		date = new Date();
		y = date.getFullYear();
		m = date.getMonth()+1;
		d = date.getDate();
		if (m<10) m = "0"+m;
		if (d<10) d = "0"+d;

		tmp = mask;
		tmp = tmp.replace(/D+/i, d);
		tmp = tmp.replace(/M+/i, m);
		tmp = tmp.replace(/Y+/i, y);
		obj.value = tmp;
		hndlr_utilStopEvent(event);
		return false;
	}

	var diff = 0;

	if (keyCode == 187 || keyCode == 107 || keyCode == 61 || keyCode == 43) {
		diff = 1;
	} else if (keyCode == 189 || keyCode==109 || keyCode == 45) {
		diff = -1;
	}

	if (diff != 0) {
		var date = getInputDate(obj.value, mask);

		y = date.getFullYear();
		m = date.getMonth()+1;
		d = date.getDate();
		if (d.toString() == 'NaN') {
			d = '01';
		}
		d += diff;


		//compute date at 12:00PM to avoid time saving problems
		date = new Date(y, m-1, d, 12 , 1 ,1);
		y = date.getFullYear();
		m = date.getMonth()+1;
		d = date.getDate();

		//format the all the entries with yyyy mm and dd (4-2-2 digits)
		if (m<10) m = "0"+m;
		if (d<10) d = "0"+d;

		while (y.length < 4) {
			y = "0" + y;
		}

		tmp = mask;
		tmp = tmp.replace(/D+/i, d);
		tmp = tmp.replace(/M+/i, m);
		tmp = tmp.replace(/Y+/i, y);
		if (obj.value != tmp) {
			obj.value = tmp;
		}
		hndlr_utilStopEvent(event);
		return false;
	}
	
	//obj.exValue = obj.value;
	return true;
}

function hndlr_utilStopEvent(ev) {
	if(ev.preventDefault) {
		ev.preventDefault();
		ev.stopPropagation();
	} else {
		ev.cancelBubble = true;
	}
}


function toregexp2(txt) {
	txt = txt.replace(/([-\/\[\]()\*\+])/g, '\\$1');
	txt = txt.replace(/[MDY]/ig, '\\d');
	txt = txt.replace(/\?/g, '.');
	txt = txt.replace(/\./g, '\\\.');
	return txt;
}

function editDateBlur(obj, mask) {
	var flag = true;
	if (obj.value.length != 10 && obj.value.length > 0) {
		date = getInputDate(obj.value, mask);
		y = date.getFullYear();
		m = date.getMonth()+1;
		d = date.getDate();
		if (m<10) m = "0"+m;
		if (d<10) d = "0"+d;

		tmp = mask;
		tmp = tmp.replace(/D+/i, d);
		tmp = tmp.replace(/M+/i, m);
		tmp = tmp.replace(/Y+/i, y);
		obj.value = tmp;
	}
}

function editDate(obj, mask, event) {
	var keyCode = event.keyCode;
	if (keyCode == 0) {
		keyCode=event.charCode;
	}

	// correct the input size
	var size = obj.value.length;
	if (size > mask.length) {
		obj.value = obj.value.substr(0, mask.length);
		size = obj.value.length;
	}

	// validsate the input value with the masks' regexp
	var re = new RegExp('^' + toregexp2(mask.substr(0, size)) + '$');
	if (!obj.value.match(re)) { 
		if (obj.lastMatched) {
			obj.value = obj.lastMatched;
		} else {
			obj.value = ''; // obj.exValue;
		}
	} else {
		obj.lastMatched = obj.value;
	}

	// re-get the text size
	size = obj.value.length;

	//if we have entered 10 chars that means we have entered a potential date
	//check this date and convert it eventually to a valid date
	if (size == 10) {

		var date = getInputDate(obj.value, mask);

		y = date.getFullYear();
		m = date.getMonth()+1;
		d = date.getDate();

		if (m<10) m = "0"+m;
		if (d<10) d = "0"+d;

		while (y.length < 4) {
			y = "0" + y;
		}

		tmp = mask;
		tmp = tmp.replace(/D+/i, d);
		tmp = tmp.replace(/M+/i, m);
		tmp = tmp.replace(/Y+/i, y);
		if (obj.value != tmp) {
			obj.value = tmp;
		}
	} else {
		if (event.keyCode!=8) {
			completeSmartDate(obj,mask);
		}
	}
}

function getInputDate(value, mask) {
	value = value.substr(0,10);
	if(value.length == 0) {
		return new Date();
	}

	var d=0;
	var m=0;
	var y=0;
	if (mask.match(/D+.M+.Y+/i)) {
		d = value.substr(0,2);
		m = value.substr(3,2);
		y = value.substr(6,10);
	} else if (mask.match(/M+.D+.Y+/i)){
		m = value.substr(0,2);
		d = value.substr(3,2);
		y = value.substr(6,10);
	} else if (mask.match(/Y+.M+.D+/i)){
		y = value.substr(0,4);
		m = value.substr(5,2);
		d = value.substr(8,10);
	}

	if (y.length == 2) {
		if (y<50) {
			y = "20" + y;
		} else {
			y = "19" + y;
		}
	}

	m--;

	//compute date at 12:00 PM  to avoid time saving problems
	date = new Date(y, m, d, 12 , 1 ,1);

	return date;
}


/**
	complete the current typing text with the next char from the mask
	@param
		obj - SmartDate DOM Object
		mask - the Mask
	
**/
function completeSmartDate(obj, mask) {
	var size = obj.value.length;
	var sw=true;
	while (sw) {
		if (mask.length<=size) {
			break;
		}
		switch (mask.charAt(size)) {
			case 'M':
			case 'D':
			case 'Y':
				sw = false;
				return;
			default:
				obj.value += mask.charAt(size);
		}
		size++;
	}
	obj.lastMatched = obj.value;
}

function addNewGlobalComment(sType)
{
	sGlobalCommentType = sType;
	hideSelects();
	eval('document.all.'+sType+'CommentName').style.visibility ='visible';
	eval('document.all.'+sType+'CommentName').style.display ='block';
	eval('document.all.'+sType+'CommentDDL').style.visibility ='visible';
	eval('document.all.'+sType+'CommentDDL').style.display ='block';
	
	document.all.header_ddlGlobalCommentTypeAdd.style.visibility = 'visible';
	document.all.header_ddlGlobalCommentResource.style.visibility = 'visible';
	document.all.header_ddlGlobalCommentCustomer.style.visibility = 'visible';

	document.all.iptGlobalCommentID.value = '-1';
	document.all.header_ddlGlobalCommentTypeAdd.value = '-1';
	document.all.txtGlobalCommentAdd.value = '';
	
	var sHTML  = document.all.spnGlobalCommentAdd.innerHTML;
	document.all.iptGlobalCommentID.value = '-1';
	document.all.spnGlobalCommentAdd.innerHTML='';
	popModal(sHTML);
}

function cancelNewGlobalComment()
{
	eval('document.all.'+sGlobalCommentType+'CommentName').style.visibility ='hidden';
	eval('document.all.'+sGlobalCommentType+'CommentName').style.display ='none';
	eval('document.all.'+sGlobalCommentType+'CommentDDL').style.visibility ='hidden';
	eval('document.all.'+sGlobalCommentType+'CommentDDL').style.display ='none';
	
	showSelects();
	var sHTML = document.all.spnModalInner.innerHTML;
	document.all.spnGlobalCommentAdd.innerHTML=sHTML;
	hideModal();
	document.body.scroll='yes';	
}

function saveNewGlobalComment()
{
	if (!document.all.txtGlobalCommentAdd.value.length ==0)
	{
		if(sGlobalCommentType=='res')
		{
			sArgs ='CommentID==-1||ResourceID=='+document.all.header_ddlGlobalCommentResource.options(document.all.header_ddlGlobalCommentResource.selectedIndex).value+'||CommentTypeID=='+
			document.all.header_ddlGlobalCommentTypeAdd.options(document.all.header_ddlGlobalCommentTypeAdd.selectedIndex).value+
			'||CommentText=='+document.all.txtGlobalCommentAdd.value;
			
			IFRPB2('setResourceComment',sArgs,'setGlobalCommentProcess()');	
		}
		else if(sGlobalCommentType=='cust')
		{
			sArgs ='CommentID==-1||CustomerID=='+document.all.header_ddlGlobalCommentCustomer.options(document.all.header_ddlGlobalCommentCustomer.selectedIndex).value+'||CommentTypeID=='+
			document.all.header_ddlGlobalCommentTypeAdd.options(document.all.header_ddlGlobalCommentTypeAdd.selectedIndex).value+
			'||CommentText=='+document.all.txtGlobalCommentAdd.value;
			
			IFRPB2('setCustomerComment',sArgs,'setGlobalCommentProcess()');	
		}
	}
	else
	{
		alert('Please enter a comment');
	}
}

function setGlobalCommentProcess()
{
	 cancelNewGlobalComment();
}

function updateXmlIslandKey(islandName, iRec, key, value) {
    var island = eval('document.all.' + islandName);
    var xml = new ActiveXObject('MSXML2.FreeThreadedDOMDocument');
    xml.loadXML(island.innerHTML);
    xml.firstChild.childNodes[iRec-1].getElementsByTagName(key)[0].text = value; // We set the key's value
    xml.firstChild.childNodes[iRec-1].getElementsByTagName('Updated')[0].text = '1'; // We set the updated flag
    island.innerHTML = xml.xml;
}

function deleteXmlIslandKey(islandName, iRec) {
    var island = eval('document.all.' + islandName);
    var xml = new ActiveXObject('MSXML2.FreeThreadedDOMDocument');
    xml.loadXML(island.innerHTML);
    xml.firstChild.childNodes[iRec-1].getElementsByTagName('Updated')[0].text = '2'; // We set the updated flag as deleted
    island.innerHTML = xml.xml;
}

function doBreadCrum(sLocation) {
    switch(sLocation) {
        case 'Trainer':
            document.all.spnBreadCrumb.innerHTML = 'Trainer Selection';
            document.all.hdnBreadCrum.value = 'Trainer';
            break;
        case 'Schedule':
            document.all.spnBreadCrumb.innerHTML = 'Trainer Selection > Schedule Selection';
            document.all.hdnBreadCrum.value = 'Schedule';
            break;
        case 'Session':
            document.all.spnBreadCrumb.innerHTML = 'Trainer Selection > Schedule Selection > Session Selection';
            document.all.hdnBreadCrum.value = 'Session';
            break;
        case 'Complete':
            document.all.spnBreadCrumb.innerHTML = 'Trainer Selection > Schedule Selection > Session Selection > Complete';
            document.all.hdnBreadCrum.value = 'Complete';
            break;  
    }          
}

function dayofWeek(day)
{
    switch( day ) {
    case 0: s = "Sunday"; break;
    case 1: s = "Monday"; break;
    case 2: s = "Tuesday"; break;
    case 3: s = "Wednesday"; break;
    case 4: s = "Thursday"; break;
    case 5: s = "Friday"; break;
    case 6: s = "Saturday"; break;
    default: s = "Unknownday"
    }
return s;
}
function monthofYear(mon)
{
    switch( mon ) {
    case 0: s = "January"; break;
    case 1: s = "February"; break;
    case 2: s = "March"; break;
    case 3: s = "April"; break;
    case 4: s = "May"; break;
    case 5: s = "June"; break;
    case 6: s = "July"; break;
    case 7: s = "August"; break;
    case 8: s = "September"; break;
    case 9: s = "October"; break;
    case 10: s = "November"; break;
    case 11: s = "December"; break;
    default: s = "Unknownmonth"
    }
return s;
}

function daysInMonth(iMonth, iYear)
{
	return 32 - new Date(iYear, iMonth, 32).getDate();
}

function minMaxWorkflow(obj, oWrapper, oContainer)
{
	if (swapMinMaxImg(obj))
	{
		document.all.divLower.style.zIndex='1';
		document.all.divLower.style.height='100px';
		document.all.divLower.style.width='100%';
		document.all.divLower.style.position='static';
		document.all.divLower.style.top='0';
		document.all.divLower.style.left='0';
		//document.all.divCustomerComment.style.height='100px';
		eval('document.all.' + oWrapper).style.height='100px';
		eval('document.all.' + oContainer).style.height='100px';
		
		document.all.divUpper.style.display='block';
		document.all.divUpper.style.visibility='visible';
		document.all.divRight.style.display='block';
		document.all.divRight.style.visibility='visible';
			
		document.all.imgMinMaxWorkflow.title = 'Click here to maximize';
		
		var iCommentHeight = (document.body.offsetHeight-document.all.accLower.offsetTop)-80;
		if(iCommentHeight<100){iCommentHeight = 100;}
		//document.all.divCommentWrapper.style.height = iCommentHeight;
		eval('document.all.' + oWrapper).style.height = iCommentHeight;
	}
	else
	{
		document.all.divLower.style.zIndex='100';
		document.all.divLower.style.height='100px';
		document.all.divLower.style.width=document.body.offsetWidth - 20;
		//document.all.divCustomerComment.style.height=document.body.offsetHeight - 200;
		eval('document.all.' + oWrapper).style.height=document.body.offsetHeight - 200;
		eval('document.all.' + oContainer).style.height=document.body.offsetHeight - 200;
		
		
		document.all.divLower.style.position='absolute';
		document.all.divLower.style.top='100px';
		document.all.divLower.style.left='10px';
		
		document.all.divUpper.style.display='none';
		document.all.divUpper.style.visibility='hidden';
		document.all.divRight.style.display='none';
		document.all.divRight.style.visibility='hidden';
		
		document.all.imgMinMaxWorkflow.title = 'Click here to minimize';
		
		var iCommentHeight = (document.body.offsetHeight-document.all.accLower.offsetTop)-80 -100;
		if(iCommentHeight<100){iCommentHeight = 100;}
		//document.all.divCommentWrapper.style.height = iCommentHeight;
		eval('document.all.' + oWrapper).style.height = iCommentHeight;
	}
	
}
swapControlClass = function(oCtrl, sClassName) {
	oCtrl.className = sClassName;
}

function swapMinMaxImg(obj)
{
	if (obj.src.indexOf('minIcon')>0)
	{
		obj.src = obj.src.replace('minIcon','maxIcon');
		return true;
	}
	else
	{
		obj.src = obj.src.replace('maxIcon','minIcon');
		return false;
	}
}
/*
	PAGE OR URL FUNCTIONS
*/

function PageQuery(q) {
	if(q.length > 1) { 
		this.q = q.substring(1, q.length);
	} else { 
		this.q = null;
	}
	
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s) {
				return this.keyValuePairs[j].split("=")[1];
			}
		}
		return false;
	}
	
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	
	this.getLength = function() { 
		return this.keyValuePairs.length; 
	} 
}

function queryString(key){
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}

function PageName() {
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	return sPage;
}


function flashSave(bFlashOn) {
	if(bFlashOn) {
		document.all.btnSave.className = 'btnFlash';
	} else {
		document.all.btnSave.className = 'btnOut';
	}
	bFlashOn = !bFlashOn;
	window.setTimeout('flashSave('+bFlashOn+');',1000);
}