var ns4 = (document.layers) ? true:false
var ie4 = (document.all) ? true:false
var ie5up = document.getElementById&&document.all;
var ns6up = document.getElementById&&!document.all;
bgColor1= "#eee8aa"

/*-----This function used in detailresult page to display instruction window--------*/
function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus(); 
	}
}

/* Show and Hide Layers */
function show(id) {
	if (ie5up || ns6up){
		document.getElementById(id).style.visibility="visible";
	} else {
		if (ns4){ 
			document.layers[id].visibility = "show"
		} else { 
			if (ie4) document.all[id].style.visibility = "visible" 
		}
	}
}

/* Show and Hide Layers */
function hide(id) {
	if(ie5up || ns6up)
		document.getElementById(id).style.visibility="hidden";
	else 
	if (ns4)
		 document.layers[id].visibility = "hide"
	else 
		if (ie4) document.all[id].visibility = "hidden"
}

/* Color Change for text boxes */
function change(color){
	if (event.srcElement.tagName=="INPUT")
		event.srcElement.style.backgroundColor=color
}

function getCounties(options)
{
	for(var i=0; i<options.length; i++)
	  options[i].selected = true;

	alert("All counties are selected");
}

function LoginVal() {
	if ((document.frmLogin.userid.length > 25)) {
		alert("The Member ID must be less than 25 characters!")
		document.frmLogin.userid.focus();
		return false	
	}else if((document.frmLogin.userid.value == "" || document.frmLogin.password.value == "")) {
		alert("You must enter Member ID and Password to login.  Thank you try again.")
		document.frmLogin.userid.focus();
		return false
	}
	return true;
} 


/* Validate search forms */
function ValidateForm() {
	var objForm = document.searchform;
	if ((objForm.lastname.value == "") || (objForm.lastname.length < 3) ) {	
		alert("Please enter a Name.");
		objForm.lastname.focus(); 
		return false;
	}else{
		if ( objForm.lastname.value != "")
		{
			objForm.name.value = objForm.lastname.value;
		}else{
			objForm.name.value = objForm.lastname.value;
		}
	}	
	hide('namesearch');
	show('message');
	return true;
}

function ValidateForm2() {
	if ((document.searchform.volume.value == "" ))  {
		alert("Please enter Volume Number.");
		layerName = "namesearch"
		hideLayer = "message"
		document.getElementById(layerName).style.visibility="visible"
		document.getElementById(hideLayer).style.visibility="hidden"
		document.searchform.volume.focus(); 
		return false;
	} else{		
		if ( document.searchform.isSubscriptionActive.value == "true")
		{		
		var x = confirm('All exempted users (Town) logging in for the 1st time after 03/31/04 need to update account information. All other users must register again.  (This can be done by clicking "Account Information" Tab on the "Top menu bar" after login.)\n\nYou are about to be charged $0.50. Would you like to continue?\n\nNOTE: If you have done this same search before you will not be charged.');
			if (x) {
				hide('namesearch'); show('message');
			}
			return x;
		}
		return true;
	}
}

function ValidateForm3() {
	if ((document.searchform.instrumentnumber.value == "" ))  {
		alert("Please enter Instrument Number.");
		layerName = "namesearch"
		hideLayer = "message"
		document.getElementById(layerName).style.visibility="visible"
		document.getElementById(hideLayer).style.visibility="hidden"
		document.searchform.instrumentnumber.focus(); 
		return false;
	} else{
		if ( document.searchform.isSubscriptionActive.value == "true")
		{		
		var x = confirm('All exempted users (Town) logging in for the 1st time after 03/31/04 need to update account information. All other users must register again.  (This can be done by clicking "Account Information" Tab on the "Top menu bar" after login.)\n\nYou are about to be charged $0.50. Would you like to continue?\n\nNOTE: If you have done this same search before you will not be charged.');
			if (x) {
				hide('namesearch'); show('message');
			}
			return x;
		}
		return true;
	}
}


function ValidateForm4() {
	var objForm = document.searchform;
	if ((objForm.trustnumber.value == "") || (objForm.trustnumber.length < 3) ) {	
		alert("Please enter a Trust Number.");
		objForm.lastname.focus(); 
		return false;
	}		
	hide('namesearch');
	show('message');
	return true;
}


function ValidateSubscription() {
var s = document.subscription.cardNumber.value;
	if (document.subscription.firstname.value == "") {
		alert("Please enter First Name.")
		document.subscription.firstname.focus(); 
		return false
	}else if(document.subscription.lastname.value == ""){
		alert("Please enter Last Name.")
		document.subscription.lastname.focus(); 
		return false
	}else if(document.subscription.email.value == ""){
		alert("Please enter your Email Address.")
		document.subscription.email.focus(); 
		return false
	}else if (!checkCC(s)){
      	alert("INVALID CREDIT CARD NUMBER");
  		return false
	}else if(document.subscription.CreditCardOwnerName.value == ""){
		alert("Please enter the Name as shown on your Credit Card.")
		document.subscription.CreditCardOwnerName.focus(); 
		return false
	}else if(document.subscription.cardType.value == ""){
		alert("Please select a Credit Card Type.")
		document.subscription.cardType.focus(); 
		return false
	}else if(document.subscription.expirationMonth.value == ""){
		alert("Please select the month your card expires.")
		document.subscription.expirationMonth.focus(); 
		return false
	}else if(document.subscription.expirationYear.value == ""){
		alert("Please select the year your card expires.")
		document.subscription.expirationYear.focus(); 
		return false		
	} else if((document.subscription.userid.value == "") || (!isAlphanumeric(subscription.userid.value))) {
		alert("Please enter your Login Name containing only alphanumeric characters.")
		document.subscription.userid.focus(); 
		return false
	}else if(document.subscription.password.value == ""){
		alert("Please enter your Password.")
		document.subscription.password.focus(); 
		return false
	}else if (document.subscription.password.value != '' && document.subscription.verPassword.value != '' && document.subscription.password.value ==
		document.subscription.verPassword.value ){
		}else {
   		alert('Passwords do not match');
   		document.subscription.password.focus();
		return false		
	}
	return true;
}

function isAlphanumeric(string, ignoreWhiteSpace) {
	if (string.search) {
		if ((ignoreWhiteSpace && string.search(/[^\w\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\W/) != -1)) 

return false;
	}
	return true;
}


function checkCC(s) {
  var i, n, c, r, t;

  // First, reverse the string and remove any non-numeric characters.
  r = "";
  for (i = 0; i < s.length; i++) {
    c = parseInt(s.charAt(i), 10);
    if (c >= 0 && c <= 9)
      r = c + r;
  }

  // Check for a bad string.
  if (r.length <= 1)
    return false;

  // Now run through each single digit to create a new string. Even digits
  // are multiplied by two, odd digits are left alone.
  t = "";
  for (i = 0; i < r.length; i++) {
    c = parseInt(r.charAt(i), 10);
    if (i % 2 != 0)
      c *= 2;
    t = t + c;
  }

  // Finally, add up all the single digits in this string.
  n = 0;
  for (i = 0; i < t.length; i++) {
    c = parseInt(t.charAt(i), 10);
    n = n + c;
  }

  // If the resulting sum is an even multiple of ten (but not zero), the
  // card number is good.
  if (n != 0 && n % 10 == 0)
    return true;
  else
    return false;
}

function ValidateCCforMetro(userCategory){
	var s = document.credsubscription.cardNumber.value;

	if (!checkCC(s)){
      	alert("INVALID CREDIT CARD NUMBER");
  		return false
	}else if(document.credsubscription.CreditCardOwnerName.value == ""){
		alert("Please enter the Name as shown on your Credit Card.")
		document.credsubscription.CreditCardOwnerName.focus(); 
		return false
	}else if(document.credsubscription.cardType.value == ""){
		alert("Please select a Credit Card Type.")
		document.credsubscription.cardType.focus(); 
		return false
	}else if(document.credsubscription.expirationMonth.value == ""){
		alert("Please select the month your card expires.")
		document.credsubscription.expirationMonth.focus(); 
		return false
	}else if(document.credsubscription.expirationYear.value == ""){
		alert("Please select the year your card expires.")
		document.credsubscription.expirationYear.focus(); 
		return false	

	}
	
	if(userCategory != null && userCategory != "9"){	
		if(document.credsubscription.userid.value == ""){
			alert("Please enter your Email Address.")
			document.credsubscription.userid.focus(); 
			return false
		}else if(document.credsubscription.password.value == ""){
			alert("Please enter your Password.")
			document.credsubscription.password.focus(); 
			return false
		}else if(!(document.credsubscription.password.value != '' && document.credsubscription.verPassword.value != 			'' && document.credsubscription.password.value == document.credsubscription.verPassword.value)){
			alert('Passwords do not match');
	   		document.credsubscription.password.focus();
			return false
		}
	}

	return true;
}


/*---------This is used in the TXLR Edit Account----------*/

function deleteOption(object,index) {
    object.options[index] = null;
}

function addOption(object,text,value) {
    var defaultSelected = true;
    var selected = true;
    var optionName = new Option(text, value, defaultSelected, selected)
    object.options[object.length] = optionName;
}

function copySelected(fromObject,toObject) {
    for (var i=0, l=fromObject.options.length;i<l;i++) {
        if (fromObject.options[i].selected)
            addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
    }
    for (var i=fromObject.options.length-1;i>-1;i--) {
        if (fromObject.options[i].selected)
            deleteOption(fromObject,i);
    }
}

function copyAll(fromObject,toObject) {
    for (var i=0, l=fromObject.options.length;i<l;i++) {
        addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
    }
    for (var i=fromObject.options.length-1;i>-1;i--) {
        deleteOption(fromObject,i);
    }
}

function getCounties(options)
{
	for(var i=0; i<options.length; i++)
	  options[i].selected = true;
}


function getSessionImage( conVal ,targetVal) {
	document.frmdetail.convtype.value = conVal;
	document.frmdetail.submit();   
}

function autoSubmit() {
        if (document.getElementById('autoSubmitForm') != null)
        {
                document.autoSubmitForm.submit();
        }
}

/* used for selection of county in counties.jsp*/
function clickCounty(countycode) {	
	document.countyform.countycode.value=countycode; 
	document.countyform.submit();
}

/* Get the clicked page */
function clickProcess (refer)
{	
	if ( refer == "login" || refer == "subscription" || refer == "loginhelp")	
  	{
		document.commonForm.optflag.value="MenuCommand";
		document.commonForm.commandflag.value = "secure/" + refer + ".jsp";
		document.commonForm.countypage.value = "false";
    	document.commonForm.submit();
  	} 
  	else if ( refer == "account_details" )
	{
		document.commonForm.optflag.value="UserSubscriptionCommand";
		document.commonForm.commandflag.value="getUserSubscription";
		document.commonForm.submit();
	}
	else if ( refer == "logout")
	{
		document.commonForm.optflag.value="ShoppingCartLogoutCommand";
		document.commonForm.commandflag.value="logout";
		document.commonForm.submit();
	}
	else if ( refer == "current_charges")
	{
		document.commonForm.optflag.value="ViewCurrentChargesCommand";
		document.commonForm.commandflag.value="viewCurrentCharges";
		document.commonForm.submit();
	}
	else if ( refer == "feedback" ||  refer == "help")
	{
		document.commonForm.optflag.value="MenuCommand";
		document.commonForm.commandflag.value = refer + ".jsp";
		document.commonForm.countypage.value = "false";
    	document.commonForm.submit();
	}		
	else if ( refer == "contact" || refer == "index" || refer == "home")
	{
		document.commonForm.optflag.value="MenuCommand";
		document.commonForm.commandflag.value = refer + ".jsp";
		document.commonForm.countypage.value = "true";
    	document.commonForm.submit();
	}
  else if ( refer == "forms")
	{
		document.commonForm.optflag.value="MenuCommand";
		document.commonForm.commandflag.value = "forms/" + refer + ".jsp";
		document.commonForm.countypage.value = "true";
    	document.commonForm.submit();
	}
		else if ( refer == "biography" || refer == "fees" || refer == "account")
	{
		document.commonForm.optflag.value="MenuCommand";
		document.commonForm.commandflag.value = refer + ".jsp";
		document.commonForm.countypage.value = "true";
    	document.commonForm.submit();
	}
		else if ( refer == "remote_form")
	{
		document.commonForm.optflag.value="MenuCommand";
		document.commonForm.commandflag.value = refer + ".jsp";
		document.commonForm.countypage.value = "true";
    	document.commonForm.submit();
	}
	else if ( refer == "links" || refer == "whatsnew")
	{
		document.commonForm.optflag.value="MenuCommand";
		document.commonForm.commandflag.value = refer + ".jsp";
		document.commonForm.countypage.value = "true";
    	document.commonForm.submit();
	}
	else if ( refer == "locations" || refer == "bridgeview" || refer == "downtown"|| refer == "markham"|| refer == "maywood"|| refer == "rollingmeadows" || refer == "skokie")
	{
		document.commonForm.optflag.value="MenuCommand";
			document.commonForm.commandflag.value = "locations/" + refer + ".jsp";
		document.commonForm.countypage.value = "true";
    	document.commonForm.submit();
	}
	else if ( refer == "faq"|| refer == "formsQA" || refer == "OtherDocsQA"|| refer == "recordingQA"|| refer == "researchQA")
	{
		document.commonForm.optflag.value="MenuCommand";
			document.commonForm.commandflag.value = "faq/" + refer + ".jsp";
		document.commonForm.countypage.value = "true";
    	document.commonForm.submit();
	}
	else if(refer == "addDocument" )
	{
		alert("Hello");
		var i = 0;
		for(i in document.commonForm.elements.length)
			window.prompt(elements[i]);
	}
	else if ( refer == "ViewPurchasedDocs")	
  	{
		document.commonForm.optflag.value="MenuCommand";
		document.commonForm.commandflag.value = "secure/" + refer + ".jsp";
		document.commonForm.countypage.value = "false";
    	document.commonForm.submit();
  	} 
  	else 	
  	{
  		document.commonForm.optflag.value="MenuCommand";
		document.commonForm.commandflag.value = refer + ".jsp";
		document.commonForm.countypage.value = "false";
    	document.commonForm.submit();
  	}
	return true;
}


/* Get the default tab page */
function clickTab (tabNo)
{	
  var searchPage = "page_dispatcher.jsp?pagetype=search.page&tab=";
  document.commonForm.optflag.value = "MenuCommand";
  document.commonForm.countypage.value = "false";
  document.commonForm.commandflag.value = searchPage + tabNo;
  document.commonForm.submit();  
  return true;
}

function HandleOnClose() {
	if (event.clientY < 0) {
    	//event.returnValue = 'Are you sure you want to leave the page?';
		document.commonForm.optflag.value="ShoppingCartLogoutCommand";
		document.commonForm.commandflag.value="logout";
		document.commonForm.submit();
   }
}


function maximizeWin() {
  if (window.screen) {
    var aw = screen.availWidth;
    var ah = screen.availHeight;
    window.moveTo(0, 0);
    window.resizeTo(aw, ah);
  }
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}


function NumberValidation(value){
var value;
if (isNaN(value)) {
     alert("Value is not a number: " + value);
     return false;
     }
}


function ValidatePIN() {
	if((document.searchform.PIN_1.value == "") || (NumberValidation(searchform.PIN_1.value))) {
		alert("Please enter a PIN number containing only numeric characters1.")
		document.searchform.PIN_1.focus(); 
		return false
	}else if((document.searchform.PIN_2.value == "") || (NumberValidation(searchform.PIN_2.value))) {
		alert("Please enter a PIN number containing only numeric characters2.")
		document.searchform.PIN_2.focus(); 
		return false
	}else if((document.searchform.PIN_3.value == "") || (NumberValidation(searchform.PIN_3.value))) {
		alert("Please enter a PIN number containing only numeric characters3.")
		document.searchform.PIN_3.focus(); 
		return false
	}else if((document.searchform.PIN_4.value == "") || (NumberValidation(searchform.PIN_4.value))) {
		alert("Please enter a PIN number containing only numeric characters4.")
		document.searchform.PIN_4.focus(); 
		return false	

	} else if( (document.searchform.SEARCH_SELECTED[0].checked ) && (document.searchform.SUBDIV_SHORT_NAME.value == "") ){
				alert("Please enter a Subdivision Short Name.")
				document.searchform.SUBDIV_SHORT_NAME.focus(); 
				return false;	
			
	
		 
	}else if((document.searchform.SEARCH_SELECTED[1].checked) && (document.searchform.DECL_OF_CONDO_NUM.value == "")) {
			alert("Please enter a Condominium Number.")
			document.searchform.DECL_OF_CONDO_NUM.focus(); 
			return false;
	
		

		
	}

	return true;
}

function ValidateSub() {
	if((document.searchform.SECTION.value == "") && (document.searchform.SUBDIV_SHORT_NAME.value == "")) {
		alert("Please enter a Subdivision Name and/or the Section/Township/Range");
		document.searchform.SECTION.focus(); 
		return false;


	}else if((document.searchform.SECTION.value != "") || (document.searchform.TOWNSHIP.value  != "") || (document.searchform.RANGE.value  != "")) {

	if((document.searchform.SECTION.value >= "37") || (NumberValidation(searchform.SECTION.value))) {
		alert("Please enter a SECTION between 1-36");
		document.searchform.SECTION.focus(); 
		return false;
	}else if((document.searchform.TOWNSHIP.value  <= "34") || (document.searchform.TOWNSHIP.value  >= "43") || (NumberValidation(searchform.TOWNSHIP.value))) {
		alert("Please enter a TOWNSHIP number between 35-42");
		document.searchform.TOWNSHIP.focus(); 
		return false;
	}else if((document.searchform.RANGE.value >= "16")  || (document.searchform.RANGE.value <= "08")  || (NumberValidation(searchform.RANGE.value))) {
		if((document.searchform.RANGE.value != "9")){
			alert("Please enter a RANGE number between 9-15 "+ document.searchform.RANGE.value);
			document.searchform.RANGE.focus(); 
			return false;
		}

	}
	
	}else if(document.searchform.SUBDIV_SHORT_NAME.value == "") {
		alert("Please enter a Subdivision Short Name.")
		document.searchform.SUBDIV_SHORT_NAME.focus(); 
		return false;	
	}
	
	return true;
}
function ValidateLegal() {
	if((document.searchform.SECTION.value >= "37") || (NumberValidation(searchform.SECTION.value))) {
		alert("Please enter a SECTION between 1-36")
		document.searchform.SECTION.focus(); 
		return false
	}else if((document.searchform.TOWNSHIP.value  <= "34") || (document.searchform.TOWNSHIP.value  >= "43") || 

(NumberValidation(searchform.TOWNSHIP.value))) {
		alert("Please enter a TOWNSHIP number between 35-42")
		document.searchform.TOWNSHIP.focus(); 
		return false
	}else if((document.searchform.RANGE.value <= "8") || (document.searchform.RANGE.value >= "16") || 

(NumberValidation(searchform.RANGE.value))) {
		alert("Please enter a RANGE number between 9-15")
		document.searchform.RANGE.focus(); 
		return false
	

	} else if( (document.searchform.SEARCH_SELECTED[0].checked ) && (document.searchform.SUBDIV_SHORT_NAME.value == "") 

){
				alert("Please enter a Subdivision Short Name.")
				document.searchform.SUBDIV_SHORT_NAME.focus(); 
				return false;	
			
	
		 
	}else if((document.searchform.SEARCH_SELECTED[1].checked) && (document.searchform.DECL_OF_CONDO_NUM.value == "")) {
			alert("Please enter a Condominium Number.")
			document.searchform.DECL_OF_CONDO_NUM.focus(); 
			return false;
	
		

		
	}

	return true;
}

function ValidateAddress(){
	
 if(document.creditCardInfoForm.RECIPIENT_NAME.value == ""){
		alert("Please enter your name.")
		document.creditCardInfoForm.RECIPIENT_NAME.focus(); 
		return false
	}else if(document.creditCardInfoForm.ADDRESS1.value == ""){
		alert("Please enter your address.")
		document.creditCardInfoForm.ADDRESS1.focus(); 
		return false	
	}else if(document.creditCardInfoForm.CITY.value == ""){
		alert("Please enter a city.")
		document.creditCardInfoForm.CITY.focus(); 
		return false
	}else if(document.creditCardInfoForm.STATE.value == ""){
		alert("Please select a state.")
		document.creditCardInfoForm.STATE.focus(); 
		return false
	}else if(document.creditCardInfoForm.ZIP.value == ""){
		alert("Please enter a 5 digit zip code.")
		document.creditCardInfoForm.ZIP.focus(); 
		return false		
	}

	return true;
}


function ValidateLogin(){
	
 if(document.loginform.account_number.value == ""){
		alert("Please enter your account number.")
		document.loginform.account_number.focus(); 
		return false
	}else if(document.loginform.userid.value == ""){
		alert("Please enter your userid.")
		document.loginform.userid.focus(); 
		return false	
	}else if(document.loginform.password.value == ""){
		alert("Please enter your password.")
		document.loginform.password.focus(); 
		return false	
	}

	return true;
}