var rnd = Math.random();
var popupWindow;

function updateStatDate(statdate) {
	var d =new Date();
	var statd = document.getElementById(statdate); 
	statd.value = (d.getMonth() + 1) + '/' + d.getDate() + '/' + d.getYear();
}

function UpdateAction(frm,actionvalue){
	var x=document.getElementById(frm);
	for (var i=0;i<x.length;i++){
		//alert(x.elements[i].name + " this is a test " + actionvalue);	
		if (x.elements[i].name == "action") {
			x.elements[i].value = actionvalue;
			break;
		}
	}
}	

function updatechkbox(thisctrl){
	if (thisctrl.checked) thisctrl.value="1";
	if (!thisctrl.checked) thisctrl.value ="0";
	//alert(thisctrl.value);
}

function checkuncheckbox(thisctrl){
	if (thisctrl.checked) {
		thisctrl.checked =false; 
	}else {thisctrl.checked =true;}
}

function checkOther(controlName, otherControlName) {
	var DropDown = document.getElementById(controlName);
	var OtherText = document.getElementById(otherControlName);
    for (var i = 0; i < DropDown.length; i++) {
        if (DropDown.options[i].selected) {
			if  (DropDown.options[i].value == '') { 			 
                OtherText.value = "";
                OtherText.disabled=false;
                OtherText.focus();
             }
             else {
				OtherText.value = "";
				OtherText.disabled=true;			 
             }
        }
    }
}
function lockUnlock(divid,myvalue,tmpvalue) {
	//alert("this is a test " & tmpvalue);
	if (tmpvalue == myvalue){
		document.getElementById(divid).style.display = 'block';
	}else {document.getElementById(divid).style.display = 'none';}
}

function changeZipCntyReg(ctrlCity,ctrlState, ctrlZip,ctrlCnty,ctrlReg) {
	var DropDown = document.getElementById(ctrlCity + "temp");
	var city = document.getElementById(ctrlCity);	
	var zip = document.getElementById(ctrlZip);
	var state = document.getElementById(ctrlState);
	var cnty = document.getElementById(ctrlCnty);
	var reg = document.getElementById(ctrlReg);		
    for (var i = 0; i < DropDown.length; i++) {
        if (DropDown.options[i].selected) {
             if (DropDown.options[i].value != ''){
			 	myArray = DropDown.options[i].value;
				var myArray=myArray.split("|");
				//reset city field's value
				city.value = myArray[0];
				//truncate and set state value from city value
				state.value = myArray[1];//mycity.substring(p+1);				
				//truncate and set zip value from city value
				zip.value = myArray[2]; //mycity.substring(p+2);
				//truncate and set cnty value from city value
				cnty.value = myArray[3]; //mycity.substring(p+2);
				//truncate and set reg value from city value
				reg.value = myArray[4]; //mycity.substring(p+2);											 
             }else {zip.value = '';state.value = 'AZ';}
        }
    }
}


//this section is being used for eApplication

function changeZip(ctrlCity,ctrlState, ctrlZip,ctrlCounty) {
	var DropDown = document.getElementById(ctrlCity + "temp");
	var city = document.getElementById(ctrlCity);	
	var zip = document.getElementById(ctrlZip);
	var state = document.getElementById(ctrlState);
	var county = document.getElementById(ctrlCounty);
    for (var i = 0; i < DropDown.length; i++) {
        if (DropDown.options[i].selected) {
             if (DropDown.options[i].value != ''){
			 	
			 	myArray = DropDown.options[i].value;
				var myArray=myArray.split("|");
				//reset city field's value
				city.value = myArray[0];
				//truncate and set state value from city value
				state.value = myArray[1];//mycity.substring(p+1);				
				//truncate and set zip value from city value
				zip.value = myArray[2]; //mycity.substring(p+2);
				//truncate and set temp county value from city value
				var cnty = myArray[3]; //mycity.substring(p+2);
				for (var c = 0; c < county.length; c++) {
					if (county.options[c].value == cnty) {
						county.options[c].selected = true;
						break;
					}
				}							 
             }else {zip.value = '';state.value = 'AZ';}
        }
    }
}

function chkNumbValue(numbname,datatype){
var errors='';
	with (numbname)
	{
	//validate ein
		if (value != "") {
			var mynumb = value.replace(/,/gi, "")
			var isnumeric = "True";
			if (isNaN(mynumb)) {
				alert("Please enter valid numbers. You may use a comma to separate the values.\n(e.g. 1,200,000 for 1.2 million)");
				if (datatype == "money") value="0.0";
				if (datatype == "int") value="0";
				focus();
				select();				
				isnumeric="False";
			}else {
				if (name == "wifadesign" ||  name == "wifaconstruction") {
					document.all("EstRequestedFromWIFA").value = parseInt(document.all("wifadesign").value.replace(/,/gi, "")) + parseInt(document.all("wifaconstruction").value.replace(/,/gi, ""));
					if (name.indexOf("design") >= 0 && parseInt(value) > 0) {
						document.all("design").checked = true; 
						document.all("design").value=1;
					}
					if (name.indexOf("construction") >= 0 && parseInt(value) > 0) {
						document.all("construction").checked = true;
						document.all("construction").value = 1;
					}	
				}
			}
		}else{
			if (datatype == "money") value="0.0";
			if (datatype == "int") value="0";		
		} 
	}
	return isnumeric;
}

function saveScore(frm,objscore,objtemp,mystr){
	var x = document.getElementById(frm);
	var score = document.getElementById(objscore);
	var temp = document.getElementById(objtemp);
	score.value = 0; 
	temp.value ="";
	for (var i = 0; i < x.length - 2; i++) {
		if (x.elements[i].name.indexOf(mystr) == 0) {
			if (x.elements[i].checked == true){
				//alert(x.elements[i].value.split("|")[1]);
				score.value  = parseInt(score.value) + parseInt(x.elements[i].value.split("|")[1]);
				if (temp.value != '') temp.value += ';';
				temp.value += x.elements[i].value
			}
		}
	}
}
function saveScore1(oScore,oTemp,myStr){
	this.inputs = document.getElementsByTagName("input");
	for (var i = 0; i < this.inputs.length; i++){
	    if (this.inputs[i].id.indexOf(oScore) >= 0){
	        var score = this.inputs[i];
	    }
	    if (this.inputs[i].id.indexOf(oTemp) >= 0){
	        var temp = this.inputs[i];
	    }
	}
	if (score) {
	   score.value = 0;
	}
	if (temp) {
	   temp.value = "";
	}
	for (var i = 0; i < this.inputs.length; i++){
	    if (this.inputs[i].id.indexOf(myStr) == 0){
	        if (this.inputs[i].checked == true){
	            //alert(this.inputs[i].value.split("|")[1]);
	            score.value = parseInt(score.value)+parseInt(this.inputs[i].value.split("|")[1]);
	            if (temp.value != '') temp.value += ';';
	            temp.value += this.inputs[i].value;
	        }
	    }
	}
			//alert(inputs[i].id);
}
function chkScore(frm,objscore,objtemp,mystr){
	var x = document.getElementById(frm);
	var score = document.getElementById(objscore);
	var temp = document.getElementById(objtemp);
	for (var i = 0; i < x.length; i++) {
		if (x.elements[i].name.indexOf(mystr) == 0) {
			if (temp.value.indexOf(x.elements[i].value) >= 0) x.elements[i].checked = true;
		}
	}
}
function chkScore1(oScore,oTemp,myStr){
	this.inputs = document.getElementsByTagName("input");
	for (var i = 0; i < this.inputs.length; i++){
	    if (this.inputs[i].id.indexOf(oScore) >= 0){
	        var score = this.inputs[i];
	    }
	    if (this.inputs[i].id.indexOf(oTemp) >= 0){
	        var temp = this.inputs[i];
	    }
	}
	for (var i = 0; i < this.inputs.length; i++) {
		if (this.inputs[i].id.indexOf(myStr) == 0) {
			if (temp.value.indexOf(this.inputs[i].value) >= 0) this.inputs[i].checked = true;
		}
	}
}

function saveCatBen(frm,obj,mystr){
	var x = document.getElementById(frm);
	var score = document.getElementById(obj);
	score.value = ''; 
	for (var i = 0; i < x.length - 2; i++) {
		if (x.elements[i].name.indexOf(mystr) == 0) {
			if (x.elements[i].checked == true){
				if (score.value  != '') score.value  += ',';
				score.value += x.elements[i].value
			}
		}
		/*removed by jmm 09/15/07, also was removed from cwapplication.asp
		if (x.elements[i].id == "beneOther" && x.elements[i].value != "") {
			if (score.value  != '') score.value  += ',';
			score.value += x.elements[i].value + 'beneOther';
		}*/	
	}
}
function saveCatBen1(Obj,myStr){
	this.inputs = document.getElementsByTagName("input");
    for (var i = 0; i < this.inputs.length; i++){
	    if (this.inputs[i].id.indexOf(Obj) >= 0){
	        var tObj = this.inputs[i];
	        break;
	    }
	}
	if (tObj) {
	   tObj.value = "";
	}
	for (var i = 0; i < this.inputs.length; i++){
	    if (this.inputs[i].id.indexOf(myStr) == 0){
	        if (this.inputs[i].checked == true){
	            if (tObj.value != '') tObj.value += ',';
	            tObj.value += this.inputs[i].value;
	        }
	    }
	}
}
function chkCatBen(frm,obj,mystr){
	var x = document.getElementById(frm); 
	var score = document.getElementById(obj);
	for (var i = 0; i < x.length; i++) {
		if (x.elements[i].name.indexOf(mystr) == 0) { 
			//alert(score.value);
			if (score.value.indexOf(x.elements[i].value) >=0) x.elements[i].checked = true;
		}	
	}
}
function chkCatBen1(Obj,myStr){
	this.inputs = document.getElementsByTagName("input");
	for (var i = 0; i < this.inputs.length; i++){
	    if (this.inputs[i].id.indexOf(Obj) >= 0){
	        var tObj= this.inputs[i];
	    }
	}
	for (var i = 0; i < this.inputs.length; i++) {
		if (this.inputs[i].id.indexOf(myStr) == 0) {
			if (tObj.value.indexOf(this.inputs[i].value) >= 0) this.inputs[i].checked = true;
		}
	}
}
function sumRPScore() {
	var das = parseInt(document.all("DebtAuthorizationScore").value);
	var psc = parseInt(document.all("ProjectPlansSpecScore").value);
	var aps = parseInt(document.all("ApplicablePermitsScore").value);
	var pbs = parseInt(document.all("ProjectBidsScore").value);
	document.all("RPScoreTemp").value = das + psc + aps + pbs;
}
function saveRPScore(obj,myvalue){
	document.getElementById(obj.name + 'Score').value = 0 ; 
	if (obj.checked == true && parseInt(myvalue) != 0)	document.getElementById(obj.name + 'Score').value  = parseInt(myvalue);
	if (obj.checked == true && parseInt(myvalue) == 0) {
		document.getElementById(obj.name + 'Date').disabled = false;
		document.getElementById(obj.name + 'Date').focus();
	}else if (document.getElementById(obj.name + 'Date').value == '') document.getElementById(obj.name + 'Date').disabled = true;
	if (document.all("RPScoreTemp")) sumRPScore();
}
function chkRPScore(frm,obj){
	var x = document.getElementById(frm);
	var temp = document.getElementById(obj + "Temp");
	var mydate = document.getElementById(obj + "Date");
	var myscore = document.getElementById(obj + "Score");
	for (var i = 0; i < x.length; i++) {
		if (x.elements[i].name.indexOf(obj) == 0) {
			if (temp.value == x.elements[i].value) {
				x.elements[i].checked = true;
				if (mydate.value =='' && myscore.value > 0) {
					mydate.disabled=true;
				}else mydate.disabled=false;
				//alert(mydate.name + " " + mydate.value + " " + x.elements[i].value);
			}
		}
	}
}
function chkOptRadio(frm,obj){
	var x = document.getElementById(frm);
	var temp = document.getElementById(obj + "Temp");
	for (var i = 0; i < x.length; i++) {
		if (x.elements[i].name.indexOf(obj) == 0) {
			if (temp.value == x.elements[i].value) {
				x.elements[i].checked = true;
				//alert(temp.value);
			}
		}
	}
}function disableSubmitButtons(tobj){
	this.x = document.getElementsByTagName('input');
    if (typeof tobj!="undefined" && tobj!=""){
        //disable specific element
	    for (var i = 0; i < this.x.length; i++) {
		    if (this.x[i].id.indexOf(tobj)>= 0 && this.x[i].type == "submit"){
		       this.x[i].style.display = 'none';
		    }
	    }    
    }else{
        //disable all submits,buttons
	    for (var i = 0; i < this.x.length; i++) {
		    if (this.x[i].type == "submit" || (this.x[i].type == "button" && this.x[i].id != "btnSearchList") || (this.x[i].type == "image" && this.x[i].src.indexOf("icon_edit.gif") < 0 && this.x[i].src.indexOf("icon_escape.gif") < 0)){
		       this.x[i].style.display = 'none';
		       //alert(this.x[i].type + " " + this.x[i].value);
		    }
	    }
    }	  
}
function disableAll(){
	this.x = document.getElementsByTagName('input');
	for (var i = 0; i < this.x.length; i++) {
		if (this.x[i].className != "cssHide"){
		    this.x[i].disabled = true; 
		}else this.x[i].style.display = 'none';
	}
}
function disableButtons(){
	this.x = document.getElementsByTagName('input');
	for (var i = 0; i < this.x.length; i++) {
		if (this.x[i].className == "cssButton"){
		    //this.x[i].disabled = true; 
		    this.x[i].style.display = 'none';
		}
	}
}
function hideTempElements(){
	this.x = document.getElementsByTagName('input');
	for (var i = 0; i < this.x.length; i++) {
		if (this.x[i].className != "cssHide"){
		    //this.x[i].disabled = true; 
		}else this.x[i].style.display = 'none';
	}
}
function chkPYF(frm,obj){
	var x = document.getElementById(frm);
	var temp = document.getElementById(obj + "Temp");
	for (var i = 0; i < x.length; i++) {
		if (x.elements[i].name.indexOf(obj) == 0) {
			if (temp.value == x.elements[i].value) {
				x.elements[i].checked = true;
				//alert(temp.value + " " + x.elements[i].value);
			}
		}
	}
}
function SysIDNumb(elmnt){
var error='';
	with (elmnt)
	{
		if (value != '') {
			value = value.replace(/[-!`)]/gi,"");
			var sysids = value.split(',');
			var sysidlist = document.getElementById("sysidlist");
			if (!sysidlist) sysidlist = getElementByTag("sysidlist","input")
			for (var i = 0; i < sysids.length; i++) {
				if (sysids[i].length < 5){
					for (var a = sysids[i].length; a < 5;a++) {
						sysids[i] = '0' + sysids[i];
					}
					sysids[i] = 'AZ04' + sysids[i];
					if (sysidlist.value.indexOf(sysids[i]) < 0) {
						alert("System ID: " + sysids[i] + " was not found in ADEQ 2008 Master Priority List. \n\n Please check the id and try again.");
						sysids[i]='';
					}
				}else if (sysids[i].length == 5) {
					sysids[i] = 'AZ04' + sysids[i];
					if (sysidlist.value.indexOf(sysids[i]) < 0) {
						alert("System ID: " + sysids[i] + " was not found in ADEQ 2008 Master Priority List. \n\n Please check the id and try again.");
						sysids[i]='';
					}
				}else if (sysids[i].length > 9) {
					alert("The System Id must be 9 characters in length. Please try again.");
					error ="True";
					value = "";
					focus();
				}else if ((sysidlist.value.indexOf(sysids[i]) < 0) || (sysids[i].length != 9)) {
					alert("System ID: " + sysids[i] + " was not found in ADEQ 2008 Master Priority List. \n\n Please check the id and try again.");
					sysids[i]='';
				}
			}
			if (!error) value = sysids.join(",");			
		}
	}
}
function getElementByTag(id,tagname){
	this.inputs = document.getElementsByTagName(tagname);
	for (var i = 0; i < this.inputs.length; i++){
	    if (this.inputs[i].id.indexOf(id) >= 0){
	        //alert(this.inputs[i].value);
	        return this.inputs[i];
	    }
	}
	return null;
}
function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
}

//***************************************************************************************
//        Browser Window Functions
//		  
//***************************************************************************************
function go() 
{
	if (document.getElementById("applicant").value!='') {
	    window.location=document.getElementById("applicant").value;
	}else alert("not found");
}
function reloadOpener(url)
{
	alert("this is a test");
	opener.window.location = url;
}
function CloseWindow()
{
    var browser=navigator.appName;
    var b_version=navigator.appVersion;
    if (browser.indexOf("Microsoft") == 0)
    {
        window.opener  = 'x'; // does not work in firefox browser
    }
    window.close();
}
function printpage()
{
	window.print()
	/*@cc_on @*/ 
	/*@if (@_win32 && @_jscript_version>=5)
	
	function window.confirm(str)
	{
		execScript('n = msgbox("'+str+'","4132","RWIC Website")', "vbscript");
		return(n == 6);
	}
	
	@end @*/
}

//***************************************************************************************
//        Pop-up window Functions
//		  
//***************************************************************************************
function printMyApp(myurl){
    if (myurl){
	    //alert("this is a");
	    appWindow=window.open(myurl,'printApp','width=650,height=400,resizable=1,toolbar=0,scrollbars=1,status=0,menubar=0,location=0,channelmode=0','replace=true')
	    appWindow.focus();
    }
}
function previewApp(myurl){
    if (myurl){
	    //alert("this is a");
	    previewWindow=window.open(myurl,'previewApp','width=650,height=400,resizable=1,toolbar=0,scrollbars=1,status=0,menubar=0,location=0,channelmode=0','replace=true')
	    previewWindow.focus();
    }
}
function editMyApp(myurl){
    if (myurl){
	    //alert("this is a");
	    popupWindow=window.open(myurl,'editMyApp','fullscreen=1,status=1,resizable=1,scrollbars=1,location=1,channelmode=0','replace=true')
	    popupWindow.focus();
    }
}
function openwindow(myurl){
	appWindow=window.open(myurl,'winApplication','width=650,height=400,resizable=1,toolbar=0,scrollbars=1,status=0,menubar=0,location=0,channelmode=0','replace=true')
	appWindow.focus()
}
function openLGTSUpdate(myurl){
	appWindow=window.open(myurl,'LGTSPopup','width=150,height=100,resizable=1,toolbar=0,scrollbars=1,status=0,menubar=0,location=0,channelmode=0','replace=true')
	appWindow.focus()
}
function previewNotes(myurl){
    if (myurl){
	    //alert("this is a");
	    previewWindow=window.open(myurl,'previewNotes','width=650,height=400,resizable=0,toolbar=0,scrollbars=1,status=0,menubar=0,location=0,channelmode=0','replace=true')
	    previewWindow.focus();
    }
}
function openDocs(myurl){
    if (myurl){	
		rnd++; 
		myurl = myurl + '&session=' + rnd;
	    //alert("this is a");
	    previewWindow=window.open(myurl,'openDocs','width=550,height=300,resizable=0,toolbar=0,scrollbars=1,status=0,menubar=0,location=0,channelmode=0,fullscreen=0,directories=0,titlebar=0','replace=true')
	    previewWindow.focus();
    }
}
function viewImg(imgPath,width,height){
    if (imgPath){	
		rnd++; 
		imgPath = imgPath + '?session=' + rnd;
	    //alert("this is a");
	    imgWindow=window.open(imgPath,'viewImg','width='+width+',height='+height+',resizable=0,toolbar=0,scrollbars=1,status=0,menubar=0,location=0,channelmode=0,fullscreen=0,directories=0,titlebar=0','replace=true')
	    imgWindow.focus();
    }
}
function checkPopupBlocker(){
	if(popupWindow){
		var popUpsBlocked = false;
	}else{
		var popUpsBlocked = true;  
	} 
	var msg = "Your browser\'s pop-up blocking software is enabled. You may not be able to display the intended webpage.\n"
		msg += "Please allow pop-ups from WIFA website by adding the site below.\n\n";
		msg += "eapps.azwifa.gov\n\n";
		msg += "If you need further technical assistance, please contact our Systems Administrator at\n";
		msg += "(602) 364-1338.";
		
	if(popUpsBlocked)
		alert( msg );
	else window.location='http://www.azwifa.gov/';										
}
//***************************************************************************************
//        Action-Confirmation Functions
//		  
//***************************************************************************************
//confirm prior to delete record
function ConfirmDel(itemstr)
{
	/*@cc_on @*/
	/*@if (@_win32 && @_jscript_version>=5)
	
	function window.confirm(str)
	{
		execScript('n = msgbox("'+str+'","4132","RWIC Website")', "vbscript");
		return(n == 6);
	}
	
	@end @*/
	var del=confirm('Are you sure you want to delete this ' + itemstr + '?')
    	return del;
}
//confirm prior to score and to rank application record
function ConfirmScoreRank(msg)
{
	/*@cc_on @*/
	/*@if (@_win32 && @_jscript_version>=5)
	function window.confirm(str)
	{
		execScript('n = msgbox("'+str+'","4132","RWIC Website")', "vbscript");
		return(n == 6);
	}
	@end @*/
	var cal=confirm('Are you sure you want ' + msg)
    	return cal;
}
//confirm prior to export application record
function ConfirmExportApp(msg)
{
	/*@cc_on @*/
	/*@if (@_win32 && @_jscript_version>=5)
	function window.confirm(str)
	{
		execScript('n = msgbox("'+str+'","4132","RWIC Website")', "vbscript");
		return(n == 6);
	}
	@end @*/
	var myvalue = ' New Under Review Duplicate Application';
	if (myvalue.indexOf(document.getElementById("appStat").value) > 0) {
		alert("Invalid Application Status: please change status and try again");
		document.getElementById("fra_appstat").focus;
		return false;
	}else {
		var cal=confirm('Are you sure you want ' + msg)	
			return cal;	
	}	
}
//confirm prior to submit application
function ConfirmSubmit()
{
	/*@cc_on @*/
	/*@if (@_win32 && @_jscript_version>=5)
	function window.confirm(str)
	{
		execScript('n = msgbox("'+str+'","4132","RWIC Website")', "vbscript");
		return(n == 6);
	}	
	@end @*/
	var del=confirm('Are you sure you are ready to submit this application?')
    	return del;
}
//confirm prior to submit application
function ConfirmB4Email()
{
	/*@cc_on @*/
	/*@if (@_win32 && @_jscript_version>=5)
	function window.confirm(str)
	{
		execScript('n = msgbox("'+str+'","4132","RWIC Website")', "vbscript");
		return(n == 6);
	}	
	@end @*/
	var del=confirm('Are you sure you want to send this email?')
    	return del;
}
//confirm prior to update record in LGTS
function ConfirmUpdateInLGTS()
{
	/*@cc_on @*/
	/*@if (@_win32 && @_jscript_version>=5)
	function window.confirm(str)
	{
		execScript('n = msgbox("'+str+'","4132","RWIC Website")', "vbscript");
		return(n == 6);
	}	
	@end @*/
	var del=confirm('Would you like to update record in LGTS?')
    	return del;
}
//confirm prior to remove record from the list
function ConfirmRem()
{
	/*@cc_on @*/
	/*@if (@_win32 && @_jscript_version>=5)
	
	function window.confirm(str)
	{
		execScript('n = msgbox("'+str+'","4132","RWIC Website")', "vbscript");
		return(n == 6);
	}
	
	@end @*/
	var del=confirm('Are you sure you want to remove this record?')
    	return del;
}
//confirm prior to save record
function ConfirmSave()
{
	/*@cc_on @*/
	/*@if (@_win32 && @_jscript_version>=5)
	
	function window.confirm(str)
	{
		execScript('n = msgbox("'+str+'","4132","RWIC Website")', "vbscript");
		return(n == 6);
	}
	
	@end @*/
	var del=confirm('Are you sure you want to remove this record?')
    	return del;
}
//confirm prior to merge records
function ConfirmMerge()
{
	/*@cc_on @*/
	/*@if (@_win32 && @_jscript_version>=5)
	
	function window.confirm(str)
	{
		execScript('n = msgbox("'+str+'","4132","RWIC Website")', "vbscript");
		return(n == 6);
	}
	
	@end @*/
	var del=confirm('Are you sure you want to merge names?')
    	return del;
}

//***************************************************************************************
//        Forms Validation Functions
//		  
//***************************************************************************************
function validateStaffInfo(thisform){
var errors='';
	with (thisform)
	{
	//validate required fields
		if (fname.value == "") errors += '- First name is required.\n'; 
		if (lname.value == "") errors += '- Last name is required.\n'; 		
		errors += validateEmail(email.value);
		if (agency.value == "") errors += '- Agency is required.\n'; 						
		errors += validateUsername(username.value);
		errors += validatePassword(password.value);
	}
	if (errors) alert('The following error(s) occurred:\n'+errors);
	return (errors == '');	
}
//***************************************************************************************
//        Fields Validation Functions
//		  email, username, passaword, and date
//***************************************************************************************
function validateDate(fld){
var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
var errors = 'Please enter valid date as month, day, and four digit year.\nYou may use a slash, hyphen, or period to separate the values.\nThe date must be a real date. 2-30-2007 would not be accepted.\nFormat mm/dd/yyyy.';
//alert(fld.value.match(RegExPattern));
	if (!(fld.value.match(RegExPattern)) || (fld.value=='')) {
		alert(errors);
		fld.value='';
		fld.focus();
		fld.select();
	} 
}
function validateEmail(strng){
	var error = "";
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) { 
		error = "- Please enter a valid email address.\n";
	}
	// forbidden characters are ( ) < > [ ] , ; : \ / "
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (strng.match(illegalChars)) {
	   error = "- The email address contains illegal characters.\n";
	}
	return error;	
}
function validateUsername(strng){
	var error = "";
	var uctr = 0
	if (strng == "") {
		error = "- You didn't enter a username.\n";
	}
	if ((strng.length < 4) || (strng.length > 15)) {
		error = "- The username is the wrong length.\n";
	}
	var illegalChars = /\W/;
  	// allow only letters, numbers, and underscores
    if (illegalChars.test(strng)) {
       error = "- The username contains illegal characters.\n";
    } 	
	// check to if username is not already exist
	this.frms = document.getElementsByTagName("form");
	for (var i = 0; i < this.frms.length; i++)
	{	
		this.inputs = this.frms[i].getElementsByTagName("input");
		for (var t = 0; t < this.inputs.length; t++)
		{
			if (this.inputs[t].id.indexOf("username") == 0){
				if (this.inputs[t].value == strng) uctr++;
			}
		}
	}	
	if (uctr > 1) {
		error = "- The username is already in use. \n"; 
	}
	return error;
}
function validatePassword (strng) {
	var error = "";
	if (strng == "") {
		error = "- You didn't enter a password.\n";
	}
    if ((strng.length < 6) || (strng.length > 12)) {
       error = "- The password is the wrong length.\n";
    }
    var illegalChars = /[\W_]/; // allow only letters and numbers
   // if (illegalChars.test(strng)) {
   //   error = "- The password contains illegal characters.\n";
   // } (strng.search(/[A-Z]+/) > -1) &&
	if (!((strng.search(/[~!@#$%^&\*()\-+]+/) > -1) && (strng.search(/[a-z]+/) > -1) &&  (strng.search(/[0-9]+/) > -1))) {
		error = "- The password must contain at least:\n";
		error += "      1. One lowercase letter\n";
		error += "      2. One special character: ~!@#$%^&*()-+\n";
		error += "      3. And one numeral.\n";
	}
	return error;
}

//***************************************************************************************
//        set Application Expand/Collapse inset window and save it to cookie
//		  
//***************************************************************************************
var divShowHide;
function showHideDivHolder(tobj,obj,hide){

    var tspan = document.getElementById(tobj.replace(/div/i, "span"))	
	divShowHide=tspan.title=="Expand"? "block":"none";
	
    if (typeof hide!="undefined" && hide!="") divShowHide='block';	
    showDivHolder(tobj,divShowHide);
}
function showDivHolder(tobj,showhide){
    divShowHide = showhide;
    var tspan = document.getElementById(tobj.replace(/div/i, "span"))
    if (divShowHide == 'none') {
        tspan.innerHTML = tspan.innerHTML.replace(/icon_up/i,"icon_down");
        tspan.innerHTML = tspan.innerHTML.replace(/HIDE /i,"VIEW ");
        tspan.title = "Expand"
    }else{
        tspan.innerHTML = tspan.innerHTML.replace(/icon_down/i,"icon_up");
        tspan.innerHTML = tspan.innerHTML.replace(/VIEW /i,"HIDE ");
        tspan.title = "Collapse"
    }
    
    //alert(tspan.innerHTML);
    var target = document.getElementById(tobj)? document.getElementById(tobj):getElementByTag(tobj,"div");
    if (!target) return;
    target.style.display=divShowHide;
    var expireDate = new Date;
    var cookiePath = window.location.href.indexOf('/recipients/')>0? "/recipients/":"/admins/";    
    // set cookie to expire in 12 months
    expireDate.setMonth(expireDate.getMonth()+12)
    //set cookie
    document.cookie = "showHide"+tobj+"="+divShowHide+";expires=" + expireDate.toGMTString()+cookiePath;
}
function initshowHideDivHolder(tobj){
    //alert(obj);
    var showHide="none|block";
    if (showHide.indexOf(readCookie("showHide"+tobj)) >= 0){
        showDivHolder(tobj,readCookie("showHide"+tobj));
    }else showDivHolder(tobj,"none")
}
function readCookie(cookiename){
    var cookievalue = Number.NaN;
    // read through cookies and find the variable
    if (document.cookie != ''){
        var thisCookie = document.cookie.split(";");
        for (c=0; c<thisCookie.length;c++){
           if (thisCookie[c].split("=")[0].indexOf(cookiename) >= 0) {
                // set variable to cookie
                cookievalue  = thisCookie[c].split("=")[1];
            }        
        }
    }
    return cookievalue;
}
//***************************************************************************************
//  following functions are used to print an external webpage with no need of opening it
//		  
//***************************************************************************************

function printWebpage(){
 bV = parseInt(navigator.appVersion)
 if (bV >= 4) window.print()
}
function setPrintedPage(altdoc) {
var prt = getElementByTag("printWebpage","link");
prt.setAttribute("href", altdoc);
printWebpage();
}

//***************************************************************************************
//        following functions are used in multiple functions such as dropdowlist.js,calendar.js
//		  
//***************************************************************************************

function getPosition(obj)
{	
	var curleft = curtop = 0;
    //find out where an element is on the page
    if (obj.offsetParent) {
        //The loop continues until the object currently being 
        //investigated does not have an offsetParent any more. 
        //While the offsetParent is still there, it still adds 
        //the offsetLeft of the object to curleft, and the offsetTop to curtop
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
        return [curleft,curtop];
    }else return [30,30];     
}
function getElementByTag(id,tagname){
	this.inputs = document.getElementsByTagName(tagname);
	for (var i = 0; i < this.inputs.length; i++){
	    if (this.inputs[i].id.indexOf(id) >= 0){
	        //alert(this.inputs[i].value);
	        return this.inputs[i];
	    }
	}
	return null;
}
function readCookie(cookiename){
    var cookievalue = Number.NaN;
    // read through cookies and find the variable
    if (document.cookie != ''){
        var thisCookie = document.cookie.split(";");
        for (c=0; c<thisCookie.length;c++){
           if (thisCookie[c].split("=")[0].indexOf(cookiename) >= 0) {
                // set variable to cookie
                cookievalue  = thisCookie[c].split("=")[1];
            }        
        }
    }
    return cookievalue;
}

function trim(str){
    // trim off leading spaces
    while (str.charAt(0) == ' ') {
        str = str.substring(1);
    }
    // trim of trailing spaces 
    while (str.charAt(str.length-1) == ' '){
        str = str.substring(0,str.length-1);
    }
    return str;
}
