   
var xmlHttp

//dara 30August2007     
function trim(sString) {
    while (sString.substring(0,1) == ' ')
        sString = sString.substring(1, sString.length);
    while (sString.substring(sString.length-1, sString.length) == ' ')
        sString = sString.substring(0,sString.length-1);
    return sString;
}

//dara 24October2007 used in affiliates/form_signup.php   
function getCounties(state_id)  
{           
    if (state_id > 0) { 
	    xmlHttp=GetXmlHttpObject()
	    
	    if (xmlHttp==null)
	      {
	      alert ("Your browser does not support AJAX!");
	      return;
	      } 
          
	    xmlHttp.onreadystatechange = getCounties_x;
	    xmlHttp.open("GET", "choose_county.php?stateid=" + state_id, true);    
	    xmlHttp.send(null);   
    } //end if
    else document.getElementById('county_area').style.display = 'none'; 
} 

//dara 24October2007 used in affiliates/form_signup.php, called by function getCounties() 
function getCounties_x() 
{       
	if (xmlHttp.readyState==4)
	{ 
        document.getElementById('county_area').style.display = ''; 
        document.getElementById('county').innerHTML = xmlHttp.responseText; 
	}                                                                         
}

//dara 24October2007 used in affiliates/form_signup.php   
function computePrice(county_id, county, is_selected)  
{          
    xmlHttp=GetXmlHttpObject()
    
    if (xmlHttp==null)
      {
      alert ("Your browser does not support AJAX!");
      return;
      } 

    xmlHttp.onreadystatechange = computePrice_x;
    xmlHttp.open("GET", "compute_price.php?countyid=" + county_id + "&county=" + county + "&selected=" + is_selected, true);
    xmlHttp.send(null);
   
} 

//dara 24October2007 used in affiliates/form_signup.php, called by function computePrice() 
function computePrice_x() 
{       
    if (xmlHttp.readyState==4)
    {    
        var pos = xmlHttp.responseText.indexOf('##') + 2;   
        var echo = xmlHttp.responseText.substring(pos, pos + 1);  
        var len = xmlHttp.responseText.length;
        
        if (echo == "1") { 
            document.getElementById('wishlist_area').style.display = ''; 
            document.getElementById('secure_button').style.display = ''; 
            document.getElementById('pricing_area').style.display = ''; 
            document.getElementById('pricing').innerHTML = xmlHttp.responseText.substring(pos + 1, len); 
            getWishList();
        }
        else {
            document.getElementById('wishlist_area').style.display = 'none'; 
            document.getElementById('pricing_area').style.display = 'none'; 
            document.getElementById('secure_button').style.display = 'none';
        }
    }                                                                        
}

//dara 24October2007 used in affiliates/form_signup.php   
function getWishList()  
{                
    xmlHttp=GetXmlHttpObject()
    
    if (xmlHttp==null)
      {
      alert ("Your browser does not support AJAX!");
      return;
      } 

    xmlHttp.onreadystatechange = getWishList_x;
    xmlHttp.open("GET", "county_wishlist.php", true);
    xmlHttp.send(null);
} 

//dara 24October2007 used in affiliates/form_signup.php, called by function getWishList() 
function getWishList_x() 
{       
    if (xmlHttp.readyState==4)
    {    
        document.getElementById('wishlist_area').style.display = ''; 
        document.getElementById('wishlist').innerHTML = xmlHttp.responseText;
    }                                                                        
}

//dara 25October2007 used in affiliates/form_signup.php   
function validateSignup(thisForm)  
{   
    var count = thisForm.length;
    var post = ''; 
    
    if (thisForm.length > 0) post = post + '?';
    
    for (i=0; i<count; i++) {
        if ( trim(thisForm[i].value) != "" ) 
            post = post + thisForm[i].name + '=' + thisForm[i].value + '&'; 
    }

    url = "ajax/validate_signup.php" + post;
      
    xmlHttp=GetXmlHttpObject()
    
    if (xmlHttp==null)
      {
      alert ("Your browser does not support AJAX!");
      return;
      } 
                  
    xmlHttp.onreadystatechange = validateSignup_x; 
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null); 
} 

//dara 24October2007 used in affiliates/form_signup.php, called by function validateSignup() 
function validateSignup_x() 
{     
    if (xmlHttp.readyState==4)
    {    
        var pos = xmlHttp.responseText.indexOf('##') + 2;   
        var status = xmlHttp.responseText.substring(pos, pos + 1);  
        var len = xmlHttp.responseText.length;  
        
        if (status == "1") document.getElementById('form_signup').submit();        
        else if (status == "0") { //if error
            document.getElementById('signup_error').style.display = ''; 
            document.getElementById('signup_error').innerHTML = xmlHttp.responseText.substring(pos + 1, len); 
        }        
    } //end if readyState                                                         
}

//dara 02November2007 used in affiliates/form_signup.php   
function validateEmail()  
{  
    post = "?email=" + document.getElementById('email').value;
    url = "ajax/validate_email.php" + post;
      
    xmlHttp=GetXmlHttpObject()
    
    if (xmlHttp==null)
      {
      alert ("Your browser does not support AJAX!");
      return;
      } 
                  
    xmlHttp.onreadystatechange = validateEmail_x; 
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null); 
} 

//dara 02November2007 used in affiliates/form_signup.php, called by function validateSignup() 
function validateEmail_x() 
{     
    if (xmlHttp.readyState==4)
    {    
        var pos = xmlHttp.responseText.indexOf('##') + 2;   
        var status = xmlHttp.responseText.substring(pos, pos + 1);  
        var len = xmlHttp.responseText.length;  
        
        if (status == "1") document.getElementById('cc_form').submit();        
        else if (status == "0") { //if error
            document.getElementById('err_msg').style.display = ''; 
            document.getElementById('err_msg').innerHTML = xmlHttp.responseText.substring(pos + 1, len); 
        }        
    } //end if readyState                                                         
}   

//dara 06November2007 used in affiliates/form_login.php   
function validateLogin()  
{  
    post = "?username=" + document.getElementById('username').value;
    post = post + "&password=" + document.getElementById('password').value;;
    url = "ajax/validate_login.php" + post;
      
    xmlHttp=GetXmlHttpObject()
    
    if (xmlHttp==null)
      {
      alert ("Your browser does not support AJAX!");
      return;
      } 
                  
    xmlHttp.onreadystatechange = validateLogin_x; 
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null); 
} 

//dara 06November2007 used in affiliates/form_login.php, called by function validateLogin() 
function validateLogin_x() 
{     
    if (xmlHttp.readyState==4)
    {    
        var pos = xmlHttp.responseText.indexOf('##') + 2;   
        var status = xmlHttp.responseText.substring(pos, pos + 1);  
        var len = xmlHttp.responseText.length;  
        
        if (status == "1") document.getElementById('form_login').submit();        
        else if (status == "0") { //if error
            document.getElementById('login_error').style.display = ''; 
            document.getElementById('login_error').innerHTML = xmlHttp.responseText.substring(pos + 1, len); 
        }        
    } //end if readyState                                                         
}                               

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
	    {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  catch (e)
	    {
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	  }
	return xmlHttp;
}