// AJAX Testing...
function processGetPost(){
var myajax=ajaxpack.ajaxobj;
var myfiletype=ajaxpack.filetype;
if (myajax.readyState == 4){
	if (myajax.status==200 || window.location.href.indexOf("http")==-1){
		if (myfiletype=="txt"){
			var retText = escape(myajax.responseText);
//			var ansiChars = '';
//			for(var i=0;i<retText.length;i++){
//				ansiChars += ansiChars + '';
//			}
			alert('"'+retText+'"');
		}else{
			alert(myajax.responseXML);
		}
	}
}
}
var vbIsOn = false;
function checkLoadVBScript(){
if(!vbIsOn&&ieOn){
	var src = '../JavaScript/msgAsk.vbs';
	loadjscssfile(src, "VBScript");
}
}

var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName  = navigator.appName;
var fullVersion  = ''+parseFloat(navigator.appVersion); 
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;
var ieOn = false;
// In MSIE, the true version is after "MSIE" in userAgent
if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
 browserName = "Microsoft Internet Explorer";
 fullVersion = nAgt.substring(verOffset+5);
 ieOn = true;
 window.setTimeout("checkLoadVBScript()",300);
}
// In Opera, the true version is after "Opera"
else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
 browserName = "Opera";
 fullVersion = nAgt.substring(verOffset+6);
}
// In Chrome, the true version is after "Chrome"
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
 browserName = "Chrome";
 fullVersion = nAgt.substring(verOffset+7);
}
// In Safari, the true version is after "Safari"
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
 browserName = "Safari";
 fullVersion = nAgt.substring(verOffset+7);
}
// In Firefox, the true version is after "Firefox"
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
 browserName = "Firefox";
 fullVersion = nAgt.substring(verOffset+8);
}
// In most other browsers, "name/version" is at the end of userAgent
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) 
{
 browserName = nAgt.substring(nameOffset,verOffset);
 fullVersion = nAgt.substring(verOffset+1);
 if (browserName.toLowerCase()==browserName.toUpperCase()) {
  browserName = navigator.appName;
 }
}
// trim the fullVersion string at semicolon/space if present
if ((ix=fullVersion.indexOf(";"))!=-1) fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1) fullVersion=fullVersion.substring(0,ix);

majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
 fullVersion  = ''+parseFloat(navigator.appVersion); 
 majorVersion = parseInt(navigator.appVersion,10);
}

function closeAICC(){
	window.parent.parent.close();
}

var processingDiv;
var focusOnLoadPage = '';
var interVeilDiv;

function noDeleteMsg(msg){
errMsg(msg);
}

function pageLoaded(){
processingDiv = document.getElementById('processing');
interVeilDiv = document.getElementById('interVeil');
initalizeToolTip();
initInputHighlightScript();
window.setTimeout("thisPageLoaded()",100);
if(focusOnLoadPage){
	var focusInput = document.getElementById(focusOnLoadPage);
	if (focusInput) focusInput = focusInput.focus();
}
}

function thisPageLoaded(){};

function winResized(){
if (processingDiv.style.visibility == 'visible') setCenterObj(processingDiv);
if (interVeilDiv && interVeilDiv.style.display=="block"){
	showVeil(); //readjust veil
}
}

function winScrolled(){
if (processingDiv && processingDiv.style.visibility == 'visible') setCenterObj(processingDiv);
}

function showProcessing(){
processingDiv.style.visibility = 'visible';
setCenterObj(processingDiv);
showVeil();
hideSelectObjs();
}

function hideProcessing(){
hideVeil();
processingDiv.style.visibility = 'hidden';
showSelectObjs();
}

var selectObjList;
function hideSelectObjs(){
if (!ieOn) return;
var selObjs = document.getElementsByTagName('select');
selectObjList = new Array();
for(var i=0;i<selObjs.length;i++){
	if (selObjs[i].style.visibility != 'hidden'){
		selectObjList[selectObjList.length] = selObjs[i];
		selObjs[i].style.visibility = 'hidden';
	}
}
}

function showSelectObjs(){
if (!ieOn) return;
if (selectObjList){
	for(var i=0;i<selectObjList.length;i++){
		selectObjList[i].style.visibility = 'visible';
	}
	selectObjList=null;
}
}

function showVeil(){
getDocViewPoint();
var docheightcomplete=(docStandardBody.offsetHeight>docStandardBody.scrollHeight)? docStandardBody.offsetHeight : docStandardBody.scrollHeight;
interVeilDiv.style.width=docWidth+"px"; //set up veil over page
interVeilDiv.style.height=docheightcomplete+"px"; //set up veil over page
interVeilDiv.style.left=0; //Position veil over page
interVeilDiv.style.top=0; //Position veil over page
interVeilDiv.style.visibility="visible"; //Show veil over page
interVeilDiv.style.display="block"; //Show veil over page
}

function hideVeil(){
interVeilDiv.style.display="none";
}

function setCenterObj(obj){
getDocViewPoint();
var pLeft = parseInt((docWidth - obj.offsetWidth)/2)-docScrollLeft;
var pTop = parseInt((docHeight - obj.offsetHeight)/2)+docScrollTop;
obj.style.left = pLeft+'px';
obj.style.top = pTop+'px';
}

var docWidth, docHeight, docScrollTop, docScrollLeft, docStandardBody;
function getDocViewPoint(){
//get window viewpoint numbers
var ie=document.all && !window.opera
var domclientWidth=document.documentElement && parseInt(document.documentElement.clientWidth) || 100000 //Preliminary doc width in non IE browsers
docStandardBody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
docScrollTop=(ie)? docStandardBody.scrollTop : window.pageYOffset
docScrollLeft=(ie)? docStandardBody.scrollLeft : window.pageXOffset
docWidth=(ie)? docStandardBody.clientWidth : (/Safari/i.test(navigator.userAgent))? window.innerWidth : Math.min(domclientWidth, window.innerWidth-16)
docHeight=(ie)? docStandardBody.clientHeight: window.innerHeight
}

function listObjData(obj){
if (obj){
	var listData = ''
	var i;
	for(i in obj){
		listData += i +'  '+ typeof(obj[i]) +'  '+ obj[i] +'\n'
//		alert(i +'  '+ typeof(obj[i]) +'  '+ obj[i])
//		if (typeof(obj[i])=='object') listObjData(obj);
	}
	alert(listData);
}
}

function resizePopup(){
var top_table_obj = document.getElementById("top_table")
if (!top_table_obj) return;
var popupW = parseInt(top_table_obj.offsetWidth) + 20;
var popupH = parseInt(top_table_obj.offsetHeight) + 20;
var winBounds = getWinBounds('', '', popupW, popupH)
if (winBnds.height<250) winBnds.height = 250;
innerResizeWindow(winBnds.width, winBnds.height)
}

function innerResizeWindow(innerWidth, innerHeight) {
if (self.innerWidth) {
myInnerWidth = self.innerWidth;
myInnerHeight = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientWidth) {
myInnerWidth = document.documentElement.clientWidth;
myInnerHeight = document.documentElement.clientHeight;
}
else if (document.body) {
myInnerWidth = document.body.clientWidth;
myInnerHeight = document.body.clientHeight;
}
else {
return;
}
adjustWidth = innerWidth - myInnerWidth;
adjustHeight = innerHeight - myInnerHeight;
window.resizeBy(adjustWidth, adjustHeight);
}

// AJAX
function createAjaxObj(){
var httprequest=false
if (window.XMLHttpRequest){ // if Mozilla, Safari etc
httprequest=new XMLHttpRequest()
if (httprequest.overrideMimeType)
httprequest.overrideMimeType('text/xml')
}
else if (window.ActiveXObject){ // if IE
try {
httprequest=new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e){
try{
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
return httprequest
}

var ajaxpack=new Object();
ajaxpack.basedomain="http://"+window.location.hostname;
ajaxpack.ajaxobj=createAjaxObj();
ajaxpack.filetype="txt";
ajaxpack.addrandomnumber=0; //Set to 1 or 0. See documentation in ajaxroutine.js.
ajaxpack.asynchronous=true;

ajaxpack.getAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj(); //recreate ajax object to defeat cache problem in IE
if (ajaxpack.addrandomnumber==1); //Further defeat caching problem in IE?
var parameters=parameters+"&ajaxcachebust="+new Date().getTime();
if (this.ajaxobj){
	this.filetype=filetype;
	if (callbackfunc!='') this.ajaxobj.onreadystatechange=callbackfunc;
	this.ajaxobj.open('GET', url+"?"+parameters, ajaxpack.asynchronous);
	this.ajaxobj.send(null);
}
}

ajaxpack.postAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj(); //recreate ajax object to defeat cache problem in IE
if (this.ajaxobj){
	this.filetype=filetype;
	if (callbackfunc!='') this.ajaxobj.onreadystatechange = callbackfunc;
	this.ajaxobj.open('POST', url, true);
	this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	this.ajaxobj.setRequestHeader("Content-length", parameters.length);
	this.ajaxobj.setRequestHeader("Connection", "close");
	this.ajaxobj.send(parameters);
}
}

function errMsg(msg){
var cap = 'Error: ' + page_title;
messageBox(msg, cap, 'stop', 'ok')
}

// Better message box
function messageBox(message, caption, icon, buttons){
	var msg = convertBRtoCRLF(message);
	var _icon = icon.toLowerCase();
	var _buttons = buttons.toLowerCase();
	if(!ieOn){
		return alertOrConfirm(msg, caption, _icon, _buttons);
	}
// Convert icon:
	switch (_icon)
	{
		case "stop":
			_icon = 1; break;
		case "hand":
			_icon = 1; break;
		case "question":
			_icon = 2; break;
		case "exclamation":
			_icon = 3; break;
		case "warning":
			_icon = 3; break;
		case "information":
			_icon = 4; break;
		case "asterisk":
			_icon = 4; break;
		default:
			_icon = 1;
	}
// Convert buttons:
	switch (_buttons)
	{
		case "ok":
			_buttons = 0; break;
		case "okcancel":
			_buttons = 1; break;
		case "abortretryignore":
			_buttons = 2; break;
		case "yesnocancel":
			_buttons = 3; break;
		case "yesno":
			_buttons = 4; break;
		case "retrycancel":
			_buttons = 5; break;
		default:
			_buttons = 0;
	}
	var deffButt = 0;
	var mods = 0;
	var retVal = vb_MsgBox(msg, caption, _icon, _buttons, deffButt, mods);
	var retArray = new Array("ok","cancel","abort","retry","ignore","yes","no");
	var retString = retArray[retVal-1];
	return retString;
}

function ask(caption, message, defInput){
	var inputVal = "";
	msg = convertBRtoCRLF(message);
	if(!ieOn){
		msg = caption + '\n\n' + msg;
		inputVal = prompt(msg,defInput);
	}else{
		inputVal = vb_InputBox(msg, caption, defInput);
	}
	return inputVal;
}

function alertOrConfirm(message, title, icon, buttons){
	var msg = title + '\n\n' + message;
	var alertOn = false;
	switch (buttons)
	{
		case "ok":
			alertOn = true; break;
		case "okcancel":
			break;
		case "abortretryignore":
			break;
		case "yesnocancel":
			break;
		case "yesno":
			break;
		case "retrycancel":
			break;
		default:
			alertOn = true; break;
	}
	var retVal = 'ok';
	if (alertOn){
		alert(msg);
	}else{
		retVal = confirm(msg);
		switch (buttons)
		{
			case "abortretryignore":
				retVal = (retVal==true) ? 'abort' : 'retry'; break;
			case "yesnocancel":
				retVal = (retVal==true) ? 'yes' : 'no'; break;
			case "yesno":
				retVal = (retVal==true) ? 'yes' : 'no'; break;
			case "retrycancel":
				retVal = (retVal==true) ? 'retry' : 'cancel';
			default:
				retVal = (retVal==true) ? 'ok' : 'cancel';
		}
	}
	return retVal;
}

function convertBRtoCRLF(passText){
	var msg = passText;
	if (typeof(msg)!='string') msg = passText.toString();
	while (msg.indexOf('<br>')!=-1){
		msg = msg.replace('<br>','\n');
	}
	return msg;
}

var winBnds = new Array();
function getWinBounds(winLeft, winTop, winWidth, winHeight){
	if (!winLeft){
		if (!winWidth){
			winLeft=0;
			winWidth=screen.width-10;
		}else{
			winLeft=(screen.width-winWidth-10)/2;
		}
	}
	if (!winTop){
		if (!winHeight){
			winTop=0;
			winHeight=screen.height-37;
		}else{
			winTop=(screen.height-winHeight-37)/2;
		}
	}
	if (!winWidth) winWidth = screen.width-(winLeft*2)-10;
	if (!winHeight) winHeight = screen.height-(winTop*2)-37;
	winLeft = parseInt(winLeft);
	winTop = parseInt(winTop);
	winWidth = parseInt(winWidth);
	winHeight = parseInt(winHeight);
	var winBounds = 'left=' + winLeft + ',top=' + winTop + ',width=' + winWidth + ',height=' + winHeight;
	winBnds.left = winLeft;
	winBnds.top = winTop;
	winBnds.width = winWidth;
	winBnds.height = winHeight;
	return winBounds;
}

function fourdigits(number){
	return (number < 1000) ? number + 1900 : number;
}

var now = new Date();
var datetoday = now;
var timenow = datetoday.getTime();
datetoday.setTime(timenow);
var thehour = datetoday.getHours();
if (thehour > 18) display = "Evening";
else if (thehour >11) display = "Afternoon";
else display = "Morning";
var greeting = ("Good " + display + "!");
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var date = ((now.getDate()<10) ? "" : "")+ now.getDate();
today = months[now.getMonth()] + " " + date + ", " + fourdigits(now.getYear());

// see http://javascript.internet.com/forms/ultimate-form-validator.html
// for good validation code
var submitcount=0;
// Mandatory fields
var requiredFields;
// Field description to appear in the dialog box
var requiredFieldsDesc;
var preErrMsg;
function validateForm(formobj){
	if (submitcount>=1){
		var errmsg = 'This form has already been submitted, please wait thanks.';
		messageBox(errmsg, 'Error: Submit more than once.', "stop", "ok");
		return false;
	}
	if (!requiredFields){
		submitcount+=1;
		showProcessing();
		return true;
	}
	var errmsg = validateFormMsg + '\n';
	var l_Msg = errmsg.length;
	if (preErrMsg) errmsg += preErrMsg;
	for (var i = 0; i < requiredFields.length; i++){
		var obj = formobj.elements[requiredFields[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == "" || obj.options[obj.selectedIndex].text.toLowerCase() == "choose"){
					errmsg += " - " + requiredFieldsDesc[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					errmsg += " - " + requiredFieldsDesc[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					errmsg += " - " + requiredFieldsDesc[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					errmsg += " - " + requiredFieldsDesc[i] + "\n";
				}
			}
		}
	}

	if (errmsg.length == l_Msg){
		submitcount+=1;
		showProcessing();
		return true;
	}else{
		messageBox(errmsg, validateFormCaption, "stop", "ok");
		return false;
	}
}

function checkIsThere(file_name, file_index, look_for, corp_id){
var params = 'file_name='+ file_name + '&file_index=' + file_index + '&look_for=' + look_for + '&corp_id=' + corp_id;
var url = '../scripts/is_there_db.mvc';
ajaxpack.asynchronous=false;
ajaxpack.getAjaxRequest(url, params, '', 'txt');
return (ajaxpack.ajaxobj.responseText=='yes');
}

function file_exists(file_name, file_path, location){
var params = 'file_name='+ file_name + '&file_path=' + file_path + '&location=' + location;
var url = '../scripts/file_exists.mvc';
ajaxpack.asynchronous=false;
ajaxpack.getAjaxRequest(url, params, '', 'txt');
return (ajaxpack.ajaxobj.responseText==1);
}

function checkNoSpaces(fieldValue){
return (fieldValue.split(' ').length==1);
}

function checkDecimals(fieldValue, decallowed){
if (isNaN(fieldValue) || fieldValue == ""){
	return 'is not a valid number.';
}else{
	if (fieldValue.indexOf('.') == -1) fieldValue += ".";
	dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);
	if (dectext.length > decallowed){
		return 'enter a number with up to ' + decallowed + ' decimal places.';
	}
}
return true;
}

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
	var errmsg = "Please enter a valid email address.";
	var cap = "Error: Invalid data";
	messageBox(errmsg, cap, "stop", "ok");
	e.select()
}
return returnval
}

function checkdate(objName) {
var datefield = objName;
if (chkdate(objName) == false) {
	datefield.select();
	var msg = 'That date is invalid.  Please try again.';
	var cap = 'Date Error';
	messageBox(msg, cap, 'stop', 'ok')
	datefield.focus();
	return false;
}else {
	return true;
}
}

function formatCurrency(num) {
// Need to make a change to optionaly return just the number - no formating ($ and ,)
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
//<input type=text name=input2 size=10 value="1000434.23" onBlur="this.value=formatCurrency(this.value);">

function checkCapsLock( e ) {
	var myKeyCode=0;
	var myShiftKey=false;
	var myMsg='Caps Lock is On.\n\nTo prevent entering your password incorrectly,\nyou should press Caps Lock to turn it off.';

	// Internet Explorer 4+
	if ( document.all ) {
		myKeyCode=e.keyCode;
		myShiftKey=e.shiftKey;
	// Netscape 4
	} else if ( document.layers ) {
		myKeyCode=e.which;
		myShiftKey=( myKeyCode == 16 ) ? true : false;
	// Netscape 6
	} else if ( document.getElementById ) {
		myKeyCode=e.which;
		myShiftKey=( myKeyCode == 16 ) ? true : false;
	}
	// Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
	if ( ( myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey ) {
		messageBox(myMsg, 'CapsLock', 'warning', 'ok');
	// Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
	} else if ( ( myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey ) {
		messageBox(myMsg, 'CapsLock', 'warning', 'ok');
	}
}
//<input type="Password" name="Password" size="16" maxlength="16" onkeypress="checkCapsLock( event )">

function checkPassword(passwordText){
var lgth = passwordText.length;
if (lgth<4||lgth>10){
	return 'The password must be a minimum of 4 and a maximum of 10 alphanumeric characters.';
}else{
	if (!checkChars(passwordText)){
		return 'Please re-enter the password as it contains invalid characters!';
	}
}
return '';
}

function checkChars(passText){
	var goodkeys = 'abcdefghijklmnopqrstuvwxyz0123456789';
	var checkText = passText.toLowerCase();
	for (var i=0;i < checkText.length;i++){
		var kchar = checkText.substring(i,i+1);
		if (goodkeys.indexOf(kchar) == -1) return false;
	}
	return true;
}

function chkdate(objName) {
var strDatestyle = "US"; //United States date style
//var strDatestyle = "EU";  //European date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
strDate = datefield.value;
if (strDate.length < 1) {
return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
if (strYear.length == 2) {
strYear = '20' + strYear;
}
// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}
if (strDatestyle == "US") {
datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
}
else {
datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
}
return true;
}
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}
//From date <input type=text name=from onBlur="checkdate(this)" size=11 maxlength=11>
//To date   <input type=text name=to   onBlur="checkdate(this)" size=11 maxlength=11>

function disableEnter(field, event){
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if (keyCode == 13){
	var i;
	for (i = 0; i < field.form.elements.length; i++)
		if (field == field.form.elements[i])
			break;
	i = (i + 1) % field.form.elements.length;
	field.form.elements[i].focus();
	return false;
} 
else
return true;
}
function download_dbf(pass_db_name, pass_db_path){
	showProcessing();
	db_name = '?db_name=' + escape(pass_db_name);
	db_path = '&db_path=' + escape(pass_db_path);
	var winBounds = getWinBounds('', '', 390, 265)
	var d = new Date();
	var unique = d.getTime() + '' + Math.floor(1000 * Math.random());
	var download_URL = scripts_dir + 'download_dbf.mvc' + db_name + db_path + '&u=' + unique;
	var opts = 'center:yes; dialogheight:' + winBnds.height + 'px; dialogwidth:' + winBnds.width + 'px; dialogtop:' + winBnds.top + 'px; dialogleft:' + winBnds.left + 'px; resizable:off; scroll:off';
	var rv = window.showModalDialog(download_URL,null,opts);
	hideProcessing();
}

function find_learner(){
	showProcessing();
	var d = new Date();
	var unique = d.getTime() + '' + Math.floor(1000 * Math.random());
	var find_learner_URL = 'find_learner.mvc?' + sess + '&corp_id=' + corp_id + '&u=' + unique;
	var winBounds = getWinBounds('', '', 500, 410)
	if (ieOn){
		var opts = 'center:yes; dialogHeight:' + winBnds.height + 'px; dialogWidth:' + winBnds.width + 'px;resizable:off;scroll:off';
	}else{
		var opts = 'center:yes; dialogheight:' + winBnds.height + 'px; dialogwidth:' + winBnds.width + 'px; dialogtop:' + winBnds.top + 'px; dialogleft:' + winBnds.left + 'px;resizable:off;scroll:off';
	}
	var args = '';
	var retValue = window.showModalDialog(find_learner_URL, args, opts);
	if (retValue){
		var formObj = document.forms['search'];
		if (formObj){
			formObj.elements[0].value = retValue;
			formObj.submit();
		}
	}else{
		hideProcessing();
	}
}

function cc_avail_courses(){
var d = new Date();
var unique = d.getTime() + '' + Math.floor(1000 * Math.random());
var avail_courses_URL = 'avail_courses.mvc?isPopup=true&corp_id=' + corp_id +'&cc_id=' + cc_id + '&u=' + unique;
var top_table_obj = document.getElementById("top_table")
if (top_table_obj){
	var popupW = parseInt(top_table_obj.width) + 30;
}else{
	var popupW = 780;
}
var winBounds = getWinBounds('', '', popupW, 420)
if (ieOn){
	var opts = 'center:yes; dialogHeight:' + winBnds.height + 'px;dialogWidth:' + winBnds.width + 'px;resizable:on;scroll:on';
}else{
	var opts = 'dialogHeight:' + winBnds.height + 'px;dialogWidth:' + winBnds.width + 'px;dialogTop:' + winBnds.top + 'px;dialogLeft:' + winBnds.left + 'px;resizable:on;scroll:on';
}
var args = '';
var retValue = window.showModalDialog(avail_courses_URL, args, opts);
}

function delCourse(courseName, cc_cnt){
	if (!coursesClicked[courseName]) coursesClicked[courseName] = false;
	if (coursesClicked[courseName]){
		coursesClicked[courseName] = false;
	}else{
		coursesClicked[courseName] = true;
		if (cc_cnt==0){
			var Msg = 'Note that this ' + course_lbl + ' is not assigned to any ' + div_lbl + 's.\nIt is OK to remove the ' + course_lbl + '.';
		}else{
			if(typeof(cc_cnt)=='undefined'){
				var Msg = 'WARNING! This ' + course_lbl + ' is assigned to this ' + div_lbl + '.\n';
//				Msg += 'Removing this ' + course_lbl + ' will remove access to the ' + course_lbl + ' from ALL ' + emp_lbl + 's in this ' + div_lbl + '.\n';
			}else{
				if (cc_cnt==1){
					var Msg = 'WARNING! This ' + course_lbl + ' is assigned to a ' + div_lbl + '.\n';
				}else{
					var Msg = 'WARNING! This ' + course_lbl + ' is assigned to ' + cc_cnt + ' ' + div_lbl + 's.\n';
				}
				Msg += 'Removing this ' + course_lbl + ' here will remove the ' + course_lbl + ' from ALL ' + div_lbl + 's.\n';
				Msg += 'Also, removing this ' + course_lbl + ' will remove access to the ' + course_lbl + ' from ALL ' + emp_lbl + 's.\n';
			}
			Msg += 'If this is not what you want, uncheck the ' + course_lbl + '.';
		}
		messageBox(Msg, 'Error: Corporate Assign Courses', "warning", "ok");
	}
}

var coursesClicked = new Array();
function corp_avail_courses(){
var d = new Date();
var unique = d.getTime() + '' + Math.floor(1000 * Math.random());
var avail_courses_URL = 'avail_courses.mvc?isPopup=true&corp_id=' + corp_id + '&u=' + unique;
var top_table_obj = document.getElementById("top_table")
if (top_table_obj){
	var popupW = parseInt(top_table_obj.width) + 30;
}else{
	var popupW = 780;
}
var winBounds = getWinBounds('', '', popupW, 420)
if (ieOn){
	var opts = 'center:yes; dialogHeight:' + winBnds.height + 'px;dialogWidth:' + winBnds.width + 'px;resizable:on;scroll:on';
}else{
	var opts = 'dialogHeight:' + winBnds.height + 'px;dialogWidth:' + winBnds.width + 'px;dialogTop:' + winBnds.top + 'px;dialogLeft:' + winBnds.left + 'px;resizable:on;scroll:on';
}
var args = '';
var retValue = window.showModalDialog(avail_courses_URL, args, opts);
}

var popup_loaded=false;
function load_popup(){
var src = '../JavaScript/popups/dhtmlwindow.css';
loadjscssfile(src, "css");
var src = '../JavaScript/popups/dhtmlwindow.js';
loadjscssfile(src, "js");
popup_loaded=true;
}

//loadjscssfile("myscript.js", "js") //dynamically load and add this .js file
//loadjscssfile("javascript.php", "js") //dynamically load "javascript.php" as a JavaScript file
//loadjscssfile("mystyle.css", "css") ////dynamically load and add this .css file

function loadjscssfile(filename, filetype){
var fileref=createjscssfile(filename, filetype)
if (typeof fileref!="undefined") document.getElementsByTagName("head")[0].appendChild(fileref)
}

//replacejscssfile("oldscript.js", "newscript.js", "js") //Replace all occurences of "oldscript.js" with "newscript.js"
//replacejscssfile("oldstyle.css", "newstyle", "css") //Replace all occurences "oldstyle.css" with "newstyle.css"

function replacejscssfile(oldfilename, newfilename, filetype){
var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist using
var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
var allsuspects=document.getElementsByTagName(targetelement)
for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
	if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(oldfilename)!=-1){
		var newelement=createjscssfile(newfilename, filetype)
		allsuspects[i].parentNode.replaceChild(newelement, allsuspects[i])
	}
}
}

function createjscssfile(filename, filetype){
if (filetype=="js"){ //if filename is a external JavaScript file
	var fileref=document.createElement('script')
	fileref.setAttribute("type","text/javascript")
	fileref.setAttribute("src", filename)
}
else if (filetype=="VBScript"){ //if filename is an external VBScript file
	var fileref=document.createElement('script')
	fileref.setAttribute("type","text/vbscript")
	fileref.setAttribute("src", filename)
}
else if (filetype=="css"){ //if filename is an external CSS file
	var fileref=document.createElement("link")
	fileref.setAttribute("rel", "stylesheet")
	fileref.setAttribute("type", "text/css")
	fileref.setAttribute("href", filename)
}
return fileref
}

function findObjPosition(obj){
var curleft = curtop = 0;
if (obj.offsetParent){
	do{
		curleft += obj.offsetLeft;
		curtop += obj.offsetTop;
	}
	while (obj = obj.offsetParent);
}
return [curleft,curtop];
}

function cleanMivaText(pass_text){
var clean_text = pass_text.replace('\n','<br>');
var clean_text = pass_text.replace('\r','<br>');
var clean_text = pass_text.replace('"','\"');
return clean_text;
}

var pub_msg='';
function detectPopupBlocker(){
	var test = window.open(null,"","width=100,height=100");
	try {
		test.close();
		pub_msg = 'Pop-ups not blocked.';
	}catch (e){
		pub_msg = 'Pop-ups blocked.';
	}
}

// Start ToolTip code
var toolTipHideDelay=250  //tooltip disappear delay (in miliseconds)
var toolTipShowDelay=500  //tooltip appear delay (in miliseconds)
var toolTipVertOffset=10 //vertical offset of tooltip from anchor link, if any
var toolTipEnableArrow=false //to disable or enable the arrow image, set if arrow found
var toolTipArrowImg=["../images/tooltip_arrowdown.gif", "../images/tooltip_arrowup.gif"] //path to down and up arrow images
var toolTipArrowHeight=11 //height of arrow image (amount to reveal)
var tooltiptext_array = new Array();
var toolTipLoadingObj;
var toolTipObj;
//<img src="../images/tooltip.gif" border="0" tooltip="true" tooltip_type="ajax" db_dir="{admin_dbdir}" db_name="courses" db_index="courses_id" db_lookup="{this_course_id}" db_field="c_desc"/>
//<img src=".../images/tooltip.gif" border="0" tooltip="true" tooltip_type="array" tooltip_indx_name="{this_course_id}" />
// or the following will become a tooltip_type="array"
//<span class="tooltip_trigger" tt_name="company"></span>

function initalizeToolTip(){
var all_spans=document.getElementsByTagName("span");
for (var i=0; i<all_spans.length; i++){
	if(all_spans[i].className && all_spans[i].className=='tooltip_trigger'){
		var ttTextID = all_spans[i].getAttribute("tt_name");
		if (typeof(tooltiptext_array[ttTextID])=='undefined') continue;
		var htm = '<img src="../images/tooltip.gif" border="0" tooltip="true" tooltip_type="array" tooltip_indx_name="' + ttTextID + '" />';
		all_spans[i].innerHTML = htm;
	}
}
var all_imgs=document.getElementsByTagName("img");
for (var i=0; i<all_imgs.length; i++){
	if (all_imgs[i].id=='tooltip_arrow'){
		tiparrow = all_imgs[i];
		toolTipEnableArrow = true;
	}
	if (isToolTip(all_imgs[i])){
		all_imgs[i].onmouseover=function(e){
			var evtobj=window.event? window.event : e;
			displayToolTip(this, evtobj);
		}
		all_imgs[i].onmouseout=setToolTipHideTimer;
	}
}
toolTipObj=document.getElementById("tooltip_popup");
toolTipLoadingObj=document.getElementById("tooltip_loading");
}

function getToolTipPosOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
	totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
	parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function toolTipClearBrowserEdge(obj, whichedge){
if (whichedge=="rightedge"){
	edgeoffsetx=0;
	var windowedge=ieOn && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
	toolTipObj.contentmeasure=toolTipObj.offsetWidth;
	if (windowedge-toolTipObj.x < toolTipObj.contentmeasure){
		edgeoffsetx=toolTipObj.contentmeasure-obj.offsetWidth;
	}
	return edgeoffsetx;
}else{
	edgeoffsety=0;
	var topedge=ieOn && !window.opera? iecompattest().scrollTop : window.pageYOffset;
	var windowedge=ieOn && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
	toolTipObj.contentmeasure=toolTipObj.offsetHeight;
//move up?
	if (windowedge-toolTipObj.y < toolTipObj.contentmeasure){
		edgeoffsety=toolTipObj.contentmeasure+obj.offsetHeight+(toolTipVertOffset*2);
	}
	return edgeoffsety;
}
}

function displayToolTip(obj, e){
if (window.event){
	event.cancelBubble=true;
}else{
	if (e.stopPropagation) e.stopPropagation();
}
if (typeof(toolTipObj)!="undefined") toolTipObj.style.visibility="hidden";
clearToolTipHideTimer();
clearToolTipShowTimer();
toolTipObj.triggerObj = obj;
delayShowToolTip=setTimeout("showToolTip()",toolTipShowDelay);
}

function showToolTip(){
toolTipObj.innerHTML = '';
setToolTipPosition();
var obj=toolTipObj.triggerObj;
var ttType = obj.getAttribute("tooltip_type");
switch (ttType){
	case "ajax":
		showBeforeAjaxToolTipText();
		return;
	case "text":
		ttText = obj.getAttribute("tooltip_text");
		if (ttText==''||ttText==null){
			ttText = 'No text in this ToolTip';
		}
		break;
	case "array":
		ttTextID = obj.getAttribute("tooltip_indx_name");
		if (typeof(tooltiptext_array[ttTextID])=='undefined'){
			ttText = 'Invalid ToolTip array index: '+ ttTextID;
		}else{
			ttText = tooltiptext_array[ttTextID];
			if (ttText==''||ttText==null){
				ttText = 'No text in this ToolTip';
			}
		}
		break;
	default:
		ttText = 'Invalid ToolTip type: '+ ttType;
}
toolTipObj.innerHTML = ttText;
setToolTipPosition();
toolTipObj.style.visibility="visible";
if (ieOn) hideSelectObjs();
}

function setToolTipPosition(){
var toolTipWidth = Math.floor((toolTipObj.offsetWidth + toolTipObj.offsetHeight) / 5 * 3);
toolTipObj.style.width=toolTipWidth + 'px';
var obj=toolTipObj.triggerObj;
toolTipObj.x=getToolTipPosOffset(obj, "left");
toolTipObj.y=getToolTipPosOffset(obj, "top")+toolTipVertOffset;
toolTipObj.style.left=toolTipObj.x-toolTipClearBrowserEdge(obj, "rightedge")+"px";
toolTipObj.style.top=toolTipObj.y-toolTipClearBrowserEdge(obj, "bottomedge")+obj.offsetHeight+"px";
if (toolTipEnableArrow) displayToolTipArrow();
}

function showBeforeAjaxToolTipText(){
toolTipLoadingObj.style.left=parseInt(toolTipObj.style.left) + 5 + "px";
toolTipLoadingObj.style.top=parseInt(toolTipObj.style.top) + 4 + "px";
toolTipObj.style.visibility="visible";
toolTipLoadingObj.style.visibility="visible";
// The following just allows the browser to show the TT Loading before doing the AJAX stuff.
setTimeout("getAjaxToolTipText()",10);
}

function getAjaxToolTipText(){
var obj=toolTipObj.triggerObj;
var db_dir = obj.getAttribute("db_dir")
var db_name = obj.getAttribute("db_name")
var db_index = obj.getAttribute("db_index")
var lookup = obj.getAttribute("db_lookup")
var db_field = obj.getAttribute("db_field")
ajaxpack.asynchronous=true;
var params = 'dbdir=' + db_dir + '&db_name=' + db_name + '&db_index=' + db_index + '&lookup=' + lookup + '&db_field=' + db_field;
var url = '../scripts/get_db_data.mvc';
ajaxpack.getAjaxRequest(url, params, ajaxLoadToolTipText, 'txt');
}

function ajaxLoadToolTipText(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){
	if (myajax.status==200 || window.location.href.indexOf("http")==-1){
		toolTipLoadingObj.style.visibility="hidden"
		if (myfiletype=="txt"){
			var retText = myajax.responseText;
		}else{
			var retText = myajax.responseXML;
		}
		toolTipObj.innerHTML = retText;
		setToolTipPosition();
	}
}
}

//function to display optional arrow image associated with tooltip
function displayToolTipArrow(){
tiparrow=document.getElementById("tooltip_arrow")
tiparrow.src=(edgeoffsety!=0)? toolTipArrowImg[0] : toolTipArrowImg[1]
var ieshadowwidth=(toolTipObj.filters && toolTipObj.filters[0])? toolTipObj.filters[0].Strength-1 : 0
//modify "left" value depending on whether there's no room on right edge of browser to display it, respectively
tiparrow.style.left=(edgeoffsetx!=0)? parseInt(toolTipObj.style.left)+toolTipObj.offsetWidth-tiparrow.offsetWidth-10+"px" : toolTipObj.style.left
//modify "top" value depending on whether there's no room on right edge of browser to display it, respectively
tiparrow.style.top=(edgeoffsety!=0)? parseInt(toolTipObj.style.top)+toolTipObj.offsetHeight-tiparrow.offsetHeight-ieshadowwidth+toolTipArrowHeight+"px" : parseInt(toolTipObj.style.top)-toolTipArrowHeight+"px"
tiparrow.style.visibility="visible"
}

function setToolTipHideTimer(){
clearToolTipShowTimer();
delayHideToolTip=setTimeout("hideToolTip()",toolTipHideDelay);
}

function clearToolTipHideTimer(){
if (typeof(delayHideToolTip)!="undefined"){
	clearTimeout(delayHideToolTip);
	hideToolTip();
}
}

function clearToolTipShowTimer(){
if (typeof(delayShowToolTip)!="undefined") clearTimeout(delayShowToolTip);
}

function hideToolTip(){
toolTipObj.style.visibility='hidden';
toolTipLoadingObj.style.visibility="hidden";
toolTipObj.style.left=0;
if (toolTipEnableArrow) tiparrow.style.visibility='hidden';
if (ieOn) showSelectObjs();
}
function isToolTip(pass_obj){
var isTT = pass_obj.getAttribute("tooltip");
return isTT=="true" ? true : false;
}
// End ToolTip code

var currentlyActiveInputRef = false;
var currentlyActiveInputClassName = false;

function highlightActiveInput() {
if(currentlyActiveInputRef) {
	currentlyActiveInputRef.className = currentlyActiveInputClassName;
}
currentlyActiveInputClassName = this.className;
this.className = 'inputHighlighted';
currentlyActiveInputRef = this;
}

function blurActiveInput() {
this.className = currentlyActiveInputClassName;
}

function initInputHighlightScript() {
var tags = ['INPUT','TEXTAREA'];
for(tagCounter=0;tagCounter<tags.length;tagCounter++){
	var inputs = document.getElementsByTagName(tags[tagCounter]);
	for(var no=0;no<inputs.length;no++){
		if(inputs[no].className && inputs[no].className=='doNotHighlightThisInput')continue;
		if(inputs[no].tagName.toLowerCase()=='textarea' || (inputs[no].tagName.toLowerCase()=='input' && (inputs[no].type.toLowerCase()=='text'||inputs[no].type.toLowerCase()=='file'))){
			inputs[no].onfocus = highlightActiveInput;
			inputs[no].onblur = blurActiveInput;
		}
	}
}
}

function ASYM_Trim(source){
	var returnValue = ''+source;
	if (returnValue=='') return returnValue;
	var invalidCars = '\r\f\n\t ';
	for (i=0;i<returnValue.length;i++){
		var currChar = returnValue.charAt(0);
		if (invalidCars.indexOf(currChar)==-1){
			break;
		}else{
			returnValue = returnValue.substring(1,returnValue.length);
		}
	}
	for (i=returnValue.length-1;i>=0;i--){
		var currChar = returnValue.charAt(i);
		if (invalidCars.indexOf(currChar)==-1){
			break;
		}else{
			returnValue = returnValue.substring(0,i);
		}
	}
	return returnValue;
}

