var alpha_array = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
var alphanum_array = new Array('#','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');

var IE4 = (document.all) ? true : false;
var NS4 = (document.layers) ? true : false;
var NS6 = (document.getElementById && !document.all) ? true : false;

var input_param  = document.location.search.substring(1,255);
var params_ary = input_param.split("&");
var param = new Array();
  
if (params_ary.length == 0) {
  	history.go(-1);
}

for (ii = 0; ii < params_ary.length; ii++) {
    cleaned = params_ary[ii].split("=");
    param[cleaned[0]] = unescape(cleaned[1]);
}


function writelayer(lay,txt) {


	if (IE4) {
		document.all[lay].innerHTML = txt;
	}

	if (NS4) {
		
		document.layers[lay].document.write(txt);
		document.layers[lay].document.close();
	}

	if (NS6) {
	
		var elm = document.getElementById([lay]);
		elm.setAttribute('innerHTML',''); 
		elm.setAttribute('innerHTML',txt); 
		
	
		//elm.setAttribute('nodeValue',txt);
		var range = document.createRange();
		range.setStartBefore(elm);
		var domfrag = range.createContextualFragment(txt);
		//alert(domfrag);
		while (elm.hasChildNodes()) {
			elm.removeChild(elm.lastChild);
		}
		elm.appendChild(domfrag);
		
   	}
}


function validate_contact_frm() {

	var errorMsg = '';
	
	if (document.frmcontact.first_name.value == '') {
		errorMsg = errorMsg + "First Name\n";
	}	
	
	if (document.frmcontact.last_name.value == '') {
		errorMsg = errorMsg + "Last Name\n";
	}
	
	if (document.frmcontact.contact_pref[0].checked && document.frmcontact.contact_pref[0].value == 'email_address') {
		if (document.frmcontact["email_address"].value == "") {
		   errorMsg = errorMsg + "Email Address\n";
		}   
	} else if (document.frmcontact.contact_pref[1].checked && document.frmcontact.contact_pref[1].value == 'phone') {
		if (document.frmcontact["phone"].value == "") {
		   errorMsg = errorMsg + "Phone Number\n";
		}	
	}	
	
	if (errorMsg != '') {
		alert("The following fields must be completed so that we may properly contact you.\n" + errorMsg);
	} else {
		document.frmcontact.submit();
	}

}

function validate_register() {

	var errMessage = "";

	if (document.frm.username.value == "" || document.frm.username.value == null) {
		errMessage = errMessage + "Username\n";
	}
	
	errMessage = IsEmailValid('frm','username');

	if (document.frm.password.value == "" || document.frm.password.value == null) {
		errMessage = errMessage + "Password\n";
	}
	
	if (document.frm.confirm_password.value == "" || document.frm.confirm_password.value == null) {
		errMessage = errMessage + "Confirming Password\n";
	}

	if (document.frm.first_name.value == "" || document.frm.first_name.value == null) {
		errMessage = errMessage + "First Name\n";
	}
	
	if (document.frm.last_name.value == "" || document.frm.last_name.value == null) {
		errMessage = errMessage + "Last Name\n";
	}
	
	if (errMessage == "") {
		document.frm.submit();
	} else {
		alert("The following fields need to be completed before your registration is accepted\n" + errMessage);
		return false;
	}

}

function remote_window(URLpage,URLtitle,Wheight,Wwidth,Wmenu){
	
	LeftPosition = (screen.width) ? (screen.width-Wwidth)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-Wheight)/2 : 0;
	settings = 'width='+Wwidth+',height='+Wheight+',top='+TopPosition+',left='+LeftPosition+',scrollbars,resizable';
 	
	if (Wmenu) {
		settings  = settings+',menubar';
 	}
  
  	remote_win = window.open(URLpage,URLtitle,settings)
}


function submitme(PageVal){
	document.dataform.intPageOffset.value=PageVal;
	document.dataform.submit();
}

function vaidate(PageVal){
	document.dataform.pgview.value=PageVal;
	document.dataform.submit();
}


function validate(){
	//if (document.dataform.query.value == ""){
		// alert("Please enter the first criteria you would like to search for.");
		// return false;
	//} else {
  		document.dataform.submit();
  		return true;
 	//}
} 

function reset_search(){

	var frm = document.dataform;
	
	frm["query[]"][0].value="";
	frm["query[]"][1].value="";
	frm["query[]"][2].value="";
	
	frm["where[]"][0].selectedIndex = 0;
	frm["where[]"][1].selectedIndex = 0;
	frm["where[]"][2].selectedIndex = 0;
	
	frm["andornot[]"][0].selectedIndex = 0;
	frm["andornot[]"][1].selectedIndex = 0;
	
	frm["intMaxHits"].selectedIndex = 0;
}



function IsEmailValid(FormName,ElemName) {

	var EmailOk  = true
	var Temp     = document.forms[FormName].elements[ElemName]
	var AtSym    = Temp.value.indexOf('@')
	var Period   = Temp.value.lastIndexOf('.')
	var Space    = Temp.value.indexOf(' ')
	var Length   = Temp.value.length - 1   // Array is from 0 to length-1
	var Invalid  = "Your e-mail address does not appear to be valid. Please make sure that your address contains the '@' symbol, that there are no spaces in your address, and that you have entered only one email address."

	// How many '@' signs are there
	var numOfAts = 0
	
	for(i = 0; i < Temp.value.length; i++){
    		theChar = Temp.value.charAt(i);
    		if(theChar == '@'){
        		numOfAts = numOfAts + 1
    		}
	}
 	
   	
   	if ((AtSym < 1) ||                     // '@' cannot be in first position
    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
    (Period == Length ) ||             // Must be atleast one valid char after '.'
    (Space  != -1) ||                  // No empty spaces permitted
    (numOfAts > 1))                    // No more than one '@' sign
   {
      EmailOk = false
      alert(Invalid)
      Temp.focus()
   }
return EmailOk
}



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}



