// JavaScript Document

function enter_clicks_go() {
  if(window.event && window.event.keyCode == 13) {
    process_zip_code();
    return false;
  }
  return true;
}

function get_cookie ( cookie_name ) {
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );
  if ( results )
    return ( unescape ( results[1] ) );
  else
      get_zip_code('<font color="black">For Product Availability, please enter 5 digit zip code</font>',"")
}

function get_zip_code(top_text, the_status) {
  the_form = '';
  the_form = the_form + ('<form name="zipcode_form">');
  the_form = the_form + ('<input type="text" size="6" name="textzipcode" onkeypress="return enter_clicks_go()"  value="'  +  the_status +  '" />');
  the_form = the_form + ('&nbsp;&nbsp;<a herf="" style="cursor:hand" onClick="process_zip_code();"><img src="/images/go_button.jpg" alt ="local Zip Code" width="65" height="25" align="absbottom"></a>');
  the_form = the_form + ('  </form>');
  document.getElementById("get_zip").innerHTML=  '<table border="1" cellpadding="20" bgcolor="#FF0000"><tr><td>' + top_text + the_form + '</td></tr></table>';
}

function process_zip_code() {
  zip =  document.zipcode_form.textzipcode.value;
  if (zip == "") {
   get_zip_code('<font color="red">Enter zip code</font>',' invalid');
	 return(0);
  }
  if(zip.substring(0,3)=="967" || zip.substring(0,3)=="968") {
   get_zip_code('<font color="black">Sorry, we do not ship to Hawaii</font>','');
	 return(0);
  }
  if(zip.substring(0,3)=="995" || zip.substring(0,3)=="996" || zip.substring(0,3)=="997" || zip.substring(0,3)=="998" || zip.substring(0,3)=="999") {
   get_zip_code('<font color="black">Sorry, we do not ship to Alaska</font>','');
	 return(0);
  }
  if (zip.length == 3) {
    zip = '00' + zip;
  }
  if (zip.length == 4) {
    zip = '0' + zip;
  }					
  zip = zip.substring(0, 3);    // 1st 3 chars of zip
	document.cookie = "ziponfile=" + escape(zip) + "; path=/" ;  // escape converts zip number to string
document.getElementById("get_zip").innerHTML= '';
location.reload(true);

}

var rof = document.cookie.match ( "referreronfile" + '=(.*?)(;|$)' );
if (rof == null) {
    document.cookie = "referreronfile=" + (document.referrer) + "; path=/" ; 
}
