//////////////////////////////////////////////////////////////////////////////
function get_counties(){
	var x=document.getElementById("state_sel");
	var state_sel=x.value;
	//var state_name=x.options[x.selectedIndex].text;
	var url="http://seniorsoftheworld.com/cgi-bin/state_fn.pl?action=get_counties&state_sel=" + state_sel;

	var x=document.getElementById("country_sel");
	var country=x.value;
     	document.getElementById('country').value=country;

     	document.getElementById('county_lbl').style.visibility='visible';
     	document.getElementById('state').value=state_sel;
	loadXMLDoc(url,'get_counties')
	}
//////////////////////////////////////////////////////////////////////////////
function get_county(){
	var x=document.getElementById("county_sel");
	var county_sel=x.value;
     	document.getElementById('county').value=county_sel;
	}
//////////////////////////////////////////////////////////////////////////////
function dynamic_content(action_ctr){
if(action_ctr == 0){
	loadXMLDoc('http://seniorsoftheworld.com/cgi-bin/homepage.pl?action=hp_copy','get_welcome')
	}
if(action_ctr == 1){
	loadXMLDoc('http://seniorsoftheworld.com/cgi-bin/article.pl?action=get_featured_articles','get_articles')
	}
if(action_ctr == 2){
	loadXMLDoc('http://seniorsoftheworld.com/cgi-bin/quote_of_the_day2.pl?action=hp_copy','get_quote')
	}
if(action_ctr == 3){
	loadXMLDoc('http://seniorsoftheworld.com/cgi-bin/thought_of_the_day.pl?action=hp_copy','get_thought')
	}
if(action_ctr == 4){
	loadXMLDoc('http://seniorsoftheworld.com/cgi-bin/author.pl?action=get_author&authid=LagmanG','get_author')
	}
}
//////////////////////////////////////////////////////////////////////////////
function loadXMLDoc(url,tid){
//alert(url);
vtid=tid;
var xmlHttp;
try{xmlHttp=new XMLHttpRequest();}
    catch (e){
	    try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
    	catch (e){
		try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
		catch (e){alert("Your browser does not support AJAX!");
        	return false;
			}
		}
	}
xmlHttp.onreadystatechange=function(){
    readyState=xmlHttp.readyState;
    if(readyState==4){
        if(vtid == "get_welcome"){
        	document.getElementById('welcome_copy').innerHTML=xmlHttp.responseText;
            if(readyState==4){dynamic_content(1);}
            }
        if(vtid == "get_articles"){
        	document.getElementById('featured_articles').innerHTML=xmlHttp.responseText;
            if(readyState==4){dynamic_content(2);}
            }
        if(vtid == "get_quote"){
		    document.getElementById('quote_of_the_day').innerHTML=xmlHttp.responseText;
            if(readyState==4){dynamic_content(3);}
            }
        if(vtid == "get_thought"){
		    document.getElementById('thought_of_the_day').innerHTML=xmlHttp.responseText;
            if(readyState==4){dynamic_content(4);}
            }
        if(vtid == "get_author"){
        	document.getElementById('featured_writers').innerHTML=xmlHttp.responseText;
            }

        if(vtid == "get_article_home"){
        	document.getElementById('articles').innerHTML=xmlHttp.responseText;
            }
        if(vtid == "get_events_home"){
        	document.getElementById('events').innerHTML=xmlHttp.responseText;
            }

        if(vtid == "get_counties"){
        	document.getElementById('county_copy').innerHTML=xmlHttp.responseText;
            }

        if(vtid == "get_event_communities"){
        	document.getElementById('events').innerHTML=xmlHttp.responseText;
            }

        }
    }
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
//////////////////////////////////////////////////////////////////////////////
function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}
//////////////////////////////////////////////////////////////////////////////
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    }
  }
return ""
}
////////////////////////////////////////////////////////////////////////////////////////////
function toggle_visibility(id,onoff) {
var e = document.getElementById(id);
if(onoff=='off')
    e.style.display = 'none';
    else
    e.style.display = 'block';
    }


////////////////////////////////////////////////////////////////////////////////////////////
function validateZip(zipcode){
var valid=false;
var isNumber=IsNumeric(zipcode);
if(isNumber && zipcode.length > 4){
    valid=true;
    }

if(!valid){
    document.getElementById('error_message').innerHTML="Invalid Zip Code";
    toggle_visibility('newsletterSubmit','off');
    }else{
    document.getElementById('error_message').innerHTML="";
    toggle_visibility('newsletterSubmit','on');
    }

}
////////////////////////////////////////////////////////////////////////////////////////////
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   }

