//------------------function isnumber(x)--------------------------------------
function isnumber (formname, formfield) {

var obid = eval("document.forms."+ formname + "." + formfield);
//alert(document.forms.resdb.zipcode.value);


if (obid.value.length > 5 || obid.value.length < 5)
	{alert("The ZIPcode is invalid.\n\nPlease enter 5 numbers only."); 
	obid.focus();
    return (false);}
    


if (isNaN(obid.value)) 
	{
		obid.focus();
		obid.select();
		alert("The ZIPcode is invalid.\n\nPlease enter a standard five digit ZIPcode\nusing numbers only.");
		return (false);
	}
else;
  return (true);
  }

//------------------function empty(x)--------------------------------------
function empty(x) { if (x.length > 0) return false; else return true; }


//------------------function makeWin(url)-------------------------------------
function makeWin(url) {

agent = navigator.userAgent;
windowName = "_blank";

params  = "";
params += "toolbar=0,";
params += "location=0,";
params += "directories=0,";
params += "status=0,";
params += "menubar=0,";
params += "scrollbars=1,";
params += "resizable=0,";
params += "width=495,";
params += "height=600,";

window.open(url, windowName , params);




}

//------------------function displayDiv()--------------------------------------
	
function displayDiv(item, node){ 
	var itm=document.getElementById(item);
	var nde=document.getElementById(node);

	if (itm.style.display == 'none') {
		nde.src='../images/minus.gif'
		itm.style.display ='block'}
	else {
		nde.src='../images/plus.gif'
		itm.style.display ='none'}
}	



//------------------ Cookie functions --------------------------------------

function chkcookie(){
	
	var chkd=ReadCookie('sar');
	if (chkd) {
		window.location.href='home.asp';
		}
}

function isCookieEnabled() {
 
    WriteCookie('temp','temp');
    var temp = ReadCookie('temp');
    if (!temp) {
      alert("It appears that your browser does not have cookie support enabled.\nTo experience the full functionality of this site please enable cookie support and try again");
      return false;
    }
    else return true;
}


var CookieDomain = ".savearanch.org";
var thisHost = location.hostname.toLowerCase();
if (thisHost.indexOf(".savearanch") > 0){
	CookieDomain = thisHost.substring(thisHost.indexOf(".savearanch"));
}

var pageName = "index";
var server = "location.hostname.toLowerCase()";
var channel = "sar";




function ReadCookie(name){
	var allCookie, cookieVal, length, start, end;
	cookieVal="";
	name=name+"=";
	allCookie=document.cookie;
	length=allCookie.length;
	if (length>0){
		start=allCookie.indexOf(name, 0);
		if (start!=-1){
			start+=name.length;
			end=allCookie.indexOf(";",start);
			if (end==-1) {
				end=length;
			}
			cookieVal=unescape(allCookie.substring(start,end));
		}
	}
	return(cookieVal);
}
function WriteCookie(name,value,domain,path,expires,secure){ 
	
	var d = new Date();
    d.setDate(d.getDate() + 10);
	expires=d;

	var CookieVal, CookError;
	CookieVal=CookError="";
	if (name){
		CookieVal=CookieVal+escape(name)+"=";
	}
	if (value){
		CookieVal=CookieVal+escape(value);
	}
	if (domain){
		CookieVal=CookieVal+"; domain="+domain;
	}
	if (path){
		CookieVal=CookieVal+"; path="+path;
	}
	if (expires){
		CookieVal=CookieVal+"; expires="+expires.toGMTString();
	}
	if (secure){
		CookieVal=CookieVal+"; secure="+secure;
	}
	else{
		//CookError=CookError+"Write failure";
		//alert("It appears that your browser does not have cookie support enabled.\nThis site functions with cookies.\nPlease enable cookie support and try again");
	}
	document.cookie=CookieVal;  // sets the cookie
}


var CookieDomain = ".savearanch.org";
var thisHost = location.hostname.toLowerCase();
if (thisHost.indexOf(".savearanch") > 0){
	CookieDomain = thisHost.substring(thisHost.indexOf(".savearanch"));
	
}
function setExpirationDate(y){
	var expires = new Date();
	var curyear = expires.getYear();
	if (curyear < 1900) {
		curyear = curyear + 1900;
	}
	expires.setYear(curyear + y);
	return expires;
}


function DeleteCookie(name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = ReadCookie(name);
document.cookie = name + "=pro; expires=" + exp.toGMTString();
}
//" + cval + "
var expDays = 60;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));





// --------------- format Date --------------------------
function formatDate (date,warn,formid) {

	if (warn=="")
		warn=false;
		
	if (date.length==0)
		return "";

	// check to see if anything but numbers are in date string
	var checkOK = "0123456789";
	var numsonly=true;
	var isnumber;

	for (i = 0;  i < date.length;  i++)
	{
	  ch = date.charAt(i);
	  isnumber=false;
	  for (j = 0;  j < 10;  j++)
	    if (ch == checkOK.charAt(j))
	      {isnumber=true; break;}
	      
	if (!isnumber)
		{numsonly=false; break;}
	 } //for i=0
	
	if (!numsonly) // check for proper date structure: 00/00/0000
	{
	  var checkOK = "0123456789";
	  var checkStr = "";
	  var count=0;
	  var addchar="";
	  var eop=false;
	  
	  for (i = 0;  i < date.length;  i++)
	  {
	    ch = date.charAt(i);
	    isnumber=false;
	    
	    for (j = 0;  j < 11;  j++)
	      if (ch == checkOK.charAt(j))
	        {isnumber=true;break;}
		
		if (isnumber) // number found, add it to addchar
			{addchar=addchar+ch;count++;}
		  else // no number found, must be separator, precede it with a zero
			if (count==1)
				{addchar="0"+addchar;eop=true;}
			else
				if (count > 1)
					{eop=true;}

		//alert('addchar='+addchar+'\n\ncount='+count+'\n\neop='+eop+'\n\ncheckStr.length='+checkStr.length);
		
		if (eop || count==4) // if end of part, add it to checkStr
			{checkStr=checkStr+addchar; addchar=""; eop=false; count=0;}
		
		//alert('checkStr='+checkStr);
	   } // for
	 var checkdate=checkStr;
	  //alert('checkdate='+checkdate);
	 } 
	 else
	 var checkdate=date;
	// !numsonly

	 
	// if other characters exist, make all months, days contain two digits
	// example: month of 1 (jan.) should read 01   i.e. 01/22/1980	not 1/22/1980
	
	if (checkdate.length < 8)
		allValid=false;
	else
		allValid=true;

	if (!allValid && warn)
		{
		alert('Date is invalid!\n\nPlease re-enter the Date before submitting the form.\n\nDate fields MUST be in the format: MM/DD/YYYY');
		//var obid=eval("document.Personalform." + formid);
		this.focus();
		}

	checkdate=checkdate.substring(0,2)+"/"+checkdate.substring(2,4)+"/"+checkdate.substring(4,8);
		
	return checkdate;
	//	return date;
	
} //func formatDate



//----------------------------- detect browser --------------------------------------------------
    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is.ie5up to detect IE5.
    // var is_major = parseInt(navigator.appVersion);
    // var is_minor = parseFloat(navigator.appVersion);

     var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
              && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
              && (agt.indexOf('webtv')==-1));
       
	// detect browser version
	var ns4 = (document.layers) ? true : false;
	var ns6 = (document.getElementById) ? true : false;
	var ie4 = (document.all) ? true : false;
    
    //alert(window.name);
 
 if (ns4 && window.name=='index'){
    location.href = 'indexns4.htm';
    window.name="";
    }
    
    
//--------------------------- set submit action for google search ------------------------------//

function setaction(frm){

	var swhat=document.getElementById("ss")
	var theform=frm
	
	for (i=0;i<theform.sitesearch.length;i++) 
	{ 
	      if (theform.sitesearch[i].checked) 
	      { 
	            var swhat = theform.sitesearch[i].value; 
	      } 
	} 

	if (swhat=="") {
		theform.action="http://www.google.com/custom";
		theform.submit();
	}	
	else {
		theform.action="../tax/ctcsearch.asp";
		theform.submit();
	}
}

//--------------------------- Functions to print out email addresses ------------------------------//
function  sendmail(n,d){
	document.location.href='mailto:' + n + '@' + d;
}

function printmail(n,d,m){
	var id;
	if(m == ""){
		m = n + ' at ' + d;
	}	 
	document.write("<a href=\"JavaScript:sendmail('" + n + "','" + d + "'); \" onMouseOver=\"self.status='" + m + "'; return true;\" onMouseOut=\"self.status=''; return true;\"" + id + ">" + m + "</a>");
	return true;
}	