var bolInternalPg=true;
var usrMessage;
var browserLevel;
var strUserAgent;
var bolMobileDevice=false;
var arrMobileBrowsers = new Array("iPhone", "BlackBerry", "MOT", "portalmmm", "Ninitendo Wii","Nokia","Smartphone", "SymbianOS", "Tablet browser", "Opera Mini","Samsung", "SGH", "-SCH", "ReqwirelessWeb","Sharp", "Siemens", "SIE-", "SonyEricsson", "Playstation", "Sprint");

if(navigator.appName=="Microsoft Internet Explorer"){
	browserLevel="up";
}
else{
	browserLevel="down";
}
function pgInit(){
	strUserAgent=navigator.userAgent;
	strAppName=navigator.appName;
	strBrowser="MS";
	RegExSupport=false;
	strVersion=navigator.appVersion.substring(0,1);
   if(strUserAgent.indexOf("AOL") != -1){
		strBrowser="AOL";
		RegExSupport=false;
	}	
   else if(strAppName=="Netscape"){
		strBrowser="NS";	
		RegExSupport=true;
	}
   else if(strAppName=="Microsoft Internet Explorer"){
		strBrowser="MS";
		RegExSupport=true;
   }
	if(document.forms[0].frmBrowserUA){
		document.forms[0].frmBrowserUA.value=strUserAgent;
	}
	//Rule out mobile users


}

function chkMobile(){
	for(iRows=0;iRows < arrMobileBrowsers.length;iRows++){
		if(strUserAgent.indexOf(arrMobileBrowsers[iRows]) > -1){
			bolMobileDevice=true;
		}
	}
	
	if(bolMobileDevice){
		alert("Caution: Mobile devices are not \n supported by this website.");
	}

}

function chkSpaces(){
	var e=window.event;
	var thisKey=e.keyCode;
	//alert(thisKey);
	if (e.shiftKey) {	
		switch(thisKey){
			case 222 :
			case 190 :
			case 191 :
			case 192 :
			case 189 :
			case 188 :
			case 187 :
			case 50 :
			case 51 :
			case 52 :
			case 53 :
			case 54 :
			case 55 :
			case 56 :
			case 57 :
			case 48 :
			case 49 :
				userName = e.srcElement.value;
				userName = userName.substr(0,userName.length-1);
				alert("special characters Not Allowed");
				e.srcElement.value=userName;
				bolInvalid=true;
				break;
			default :
				break;
		}
	}
	else {
		switch(thisKey){
			case 190 :
			case 188 :
			case 187 :
			case 192 :
			case 219 :
			case 221 :
			case 222 :
				userName = e.srcElement.value;
				userName = userName.substr(0,userName.length-1);
				alert("special characters Not Allowed");
				e.srcElement.value=userName;
				bolInvalid=true;
				break;
			case 32 : 
				userName = e.srcElement.value;
				userName = userName.substr(0,userName.length-1);
				alert("Spaces Not Allowed");
				e.srcElement.value=userName;
			}	
	}
	return;
}


function NewWindow(mypage,myname,w,h,pos,infocus){
	if(pos=="random"){
		myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=="center"){
		myleft=(screen.width)?(screen.width-w)/2:100;
		mytop=(screen.height)?(screen.height-h)/2:100;
		}
	else 
		if((pos!='center' && pos!="random") || pos==null){
			myleft=0;mytop=20
		}
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	win=window.open(mypage,myname,settings);
	win.focus();
}
function popUp(url) {
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin";
}
function testEmail(src) {
	emailReg = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	var regex = new RegExp(emailReg);
	return regex.test(src);	
}
function opensavedsearches(){
	theTop=screen.height-10;
	myleft=(screen.width)?(screen.width-470)/2:100;
	mytop=(screen.height)?(screen.height-theTop)/2:100;
	window.open("wfrmSavedSearches.aspx", "_blank", "width=490,height=800,top=" + mytop + ",left=" + myleft + ",scrollbars=yes")
}
function opensavesearch(){
	theTop = screen.height-500;
	myleft=(screen.width)?(screen.width-310)/2:100;
	mytop=(screen.height)?(screen.height-theTop)/2:100;	
	window.open("wfrmSaveSearch.aspx", "_blank", "width=330,height=400,top=" + mytop + ",left=" + myleft + ",scrollbars=yes" + ",resize=yes")
}
function opensearchpreferences(){
	theTop = screen.height-450;
	myleft=(screen.width)?(screen.width-310)/2:100;
	mytop=(screen.height)?(screen.height-theTop)/2:100;	
	window.open("wfrmPreferences.aspx", "_blank", "width=310,height=450,top=" + mytop + ",left=" + myleft + ",scrollbars=No")
}
function anArray(n) {
	this.length = n;
	for (var i = 0; i < n; i++)
		this[i] = 0;
	return this
}

var textMonth = new anArray(12);
	textMonth[0] = "Jan", textMonth[1] = "Feb", textMonth[2] = "Mar"
	textMonth[3] = "Apr", textMonth[4] = "May", textMonth[5] = "Jun"
	textMonth[6] = "Jul", textMonth[7] = "Aug", textMonth[8] = "Sep"
	textMonth[9] = "Oct", textMonth[10] = "Nov", textMonth[11] = "Dec"

 var modDate = new Date(document.lastModified);
 var modDay = modDate.getDate();
 var modMonth = modDate.getMonth();
 var modYear = modDate.getFullYear();
 var copyDate = new Date();
 var copyYear = copyDate.getFullYear();

function defineword(txt) {
    window.status = txt;
    setTimeout("blankit()",5000); 
}

function blankit() {
     window.status="";
}
function winStatus(thisStatus){
	window.status=thisStatus;

}

function printWindow(){
	var newWindow,currText;
	newWindow = window.open("printDoc.aspx");
}

function getPrevious() {
	return(document.referrer);
}




function optUscCfrTopic_CheckChanged(srcElement){
	var gObjXML;
	gObjXML = new ActiveXObject("MSXML.DOMDocument");	//xml source object
	gObjXML.async=false;
	gObjXML.validateOnParse = true;
	gObjXML.load("..\\Library\\topicText.xml");							//Load DataIsland object
	if (gObjXML.parseError.errorCode != 0) 
		//tgtResults.innerHTML = showError(gobjXML);
		alert(showError(gObjXML));
	//alert("docLoaded");
	//alert(srcElement);
	var xmlQuery = "topics/topic[@id='" + srcElement + "']";
	var nodeList=gObjXML.selectNodes(xmlQuery);
	//alert(nodeList.item(0).firstChild.nodeValue);
	var topicTitle = nodeList.item(0).firstChild.nodeValue;
	//alert(topicTitle);
	//pnlUscTopicSearch.style.display='none';
}

function showError(objDocument) {
  // create the error message
  var strError = new String;
  strError = 'Invalid XML file !<BR />'
           + 'File URL: ' + objDocument.parseError.url + '<BR/>'
           + 'Line No.: ' + objDocument.parseError.line + '<BR/>'
           + 'Character: ' + objDocument.parseError.linepos + '<BR/>'
           + 'File Position: ' + objDocument.parseError.filepos + '<BR/>'
           + 'Source Text: ' + objDocument.parseError.srcText + '<BR/>'
           + 'Error Code: ' + objDocument.parseError.errorCode + '<BR/>'
           + 'Description: ' + objDocument.parseError.reason
  return strError;
}
function validateUSDate(strValue) {
	var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
	var bolValidDate=false;
	//check to see if in correct format
	if(!objRegExp.test(strValue)){
	  bolValidDate=false; //doesn't match pattern, bad date
	  usrMessage="Wrong Format use mm/dd/yyyy.";
	}
	else{
	  var strSeparator = strValue.substring(2,3); //find date separator
	  var arrayDate = strValue.split(strSeparator); //split date into month, day, year
	  //create a lookup for months not equal to Feb.
	  var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,'08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31};
	  var intDay = parseInt(arrayDate[1]);
	  var intYear = parseInt(arrayDate[2]);
	  var intMonth = parseInt(arrayDate[0]);

		//check if month value and day value agree
		if(arrayLookup[arrayDate[0]] != null) {
			if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0){
				bolValidDate=true;
				//Check for February and toggle bolValidDate back to false if bad February Date
				if(intMonth==1){
					if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0){
						bolValidDate=true;
					}
					else{
						bolValidDate=false;
						usrMessage="Wrong day for the month of February.";
					}
				}
			}
			else{
				usrMessage="Wrong day for the month.";
			}
		}
	}
  return(bolValidDate); 
}
//form.url.value = document.referrer

       


function setCookie (name, value) {
//usage::: setCookie("your_name", form.your_name.value);
        document.cookie = name + "=" + escape(value)
}
function getValue() {
    form = document.email_friend
    if (form.your_name.value.length == 0)
        form.your_name.value = getCookie("your_name")
    if (form.your_email.value.length == 0)
        form.your_email.value = getCookie("your_email")
}

function getCookie(Name) {
    var search = Name + "="
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) {
            offset += search.length
            end = document.cookie.indexOf(";", offset)
            if (end == -1)
                end = document.cookie.length
            return unescape(document.cookie.substring(offset, end))
        }
                return ""
    } else {
        return ""
    }
} 
function chkValidEmail(source,arguments){
	//alert("utils.js chkValidEmail");
	
	var strEmail=document.forms[0].txtEmail.value;
	var iDexAt=strEmail.indexOf("@",0);
	var iDexPer=strEmail.indexOf(".",iDexAt);
	var iDexIllegal = strEmail.indexOf("..",0);
	
	if(iDexIllegal > -1){
			alert("2 periods .. in the email address for the domain is illegal.");
			document.forms[0].txtEmail.focus();
			arguments.IsValid=false;
			return;
	}	
	if(iDexAt<=0){
			alert("Email address missing the @ symbol.");
			document.forms[0].txtEmail.focus();
			arguments.IsValid=false;
			return;
	}	
	if(strEmail.indexOf(",",0)>-1){
		alert("Commas are not valid in email addresses.");
		document.forms[0].txtEmail.focus();
		arguments.IsValid=false;
		return;
	}
	if(iDexPer==-1){
		alert("The email address is incomplete missing mail domain.");
		document.forms[0].txtEmail.focus();
		return(false);
	}
	if(iDexPer==strEmail.length-1){
		alert("The email address is incomplete, please enter a valid email address.");
		document.forms[0].txtEmail.focus();
		return(false);
	}

}

function chkAllStates(currEl,groupName,totalChkBoxes){
	//Frameworks 1.0 doesn't pass attribs to function 
	var thisElement="";
	if(currEl.checked){
		for(var iRows=0;iRows<totalChkBoxes+1;iRows++){
			thisElement=groupName + "_" + iRows;
			if(eval(thisElement + ".checked")){
				eval(thisElement + ".checked=false");
			}
		}
	}
}

