  // ************************************************************************************************	
  //'	Author:			Yssa Laude																												'
  //'	Filename:		protectedproduct.js																										'
  //'	Description:  										'
  // ************************************************************************************************ 
  
  var xmlDocument;
  var xmlObj;
  
  function whatbrowser()
  {
        if(document.layers)
        {
            thisbrowser="NN4";
        }
        if(document.all)
        {
             thisbrowser="ie"
        }
        
        if(!document.all && document.getElementById)
        {
             thisbrowser="NN6";
        }
        
        return(thisbrowser);
  }
			
  function _displayUserZipCode_textbox()
	{
		document.getElementById("divZipCodeLabel").style.visibility = "visible";  	
		document.getElementById("divZipCodeTextBox").style.visibility = "visible";  	
	}
			 
  function verify_if_product_available()
  {
	var userZipCode = document.all.item("txtZipCode").value;
	if (TrimString(userZipCode) != 0)
		{
			var blnIsValid = validateZIP(userZipCode);				   
			if (blnIsValid == false)
			  {
				document.getElementById("divNotValid").innerHTML = "<B>Please enter a valid zip code.</B>";
				document.getElementById("divNotValid").style.visibility = "visible";
				return(false);
			  }	
			else
			  {
				searchXML_for_userZipCode(userZipCode);
			  } 
		}
		else
		{
			document.getElementById("divNotValid").innerHTML = "<B>Please enter your 5 digit zip code.</B>";
			document.getElementById("divNotValid").style.visibility = "visible";
			return(false);
		 }  		
	 }
			 
	function searchXML_for_userZipCode(iUserZipCode)
	  {			
	    if (TrimString(iUserZipCode) != 0)
	    {					
			xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
			xmlDocument.async = "false";
			xmlDocument.onreadystatechange= _verify_onreadystatechange;
			xmlDocument.load('javascript/eastcoast_zipcodes.xml');						
			var objTotalItems = xmlDocument.selectNodes('//row');	
			var totalcount = objTotalItems.length;
			if (totalcount > 0)
			 {			  
			   //var objNode = xmlDocument.selectSingleNode("//row/F1[.  ='36868']"); 
			   var objNode = xmlDocument.selectSingleNode("//row/F1[.  ='" + iUserZipCode + "']"); 
			   if (objNode != null)
			     {
			        //window.open("WebForm1.aspx"); 			        
			        var winparam="scrollbars=yes, resizable=yes, status=no, toolbar=yes, directories=no, location=yes,";	
					w = "700";
					h = "500";
					var winwidth="width=" + w;
					var winheight=", height=" + h;
					var winvalues=winparam+winwidth+winheight;		
					var newWindow = window.open('protected_product.html', '_blank', winvalues);
			     }
			   else
				{
					document.getElementById("divNotValid").innerHTML = "<B>Sorry, but the product is currently not available in your area.</B>";
					document.getElementById("divNotValid").style.visibility = "visible";
					return(false);
				}  
			 }
		}	
	  }
	  
	function _verify_onreadystatechange() 
	{  	
		if (xmlDocument.readyState!=4) 
			{return false; }
		else
			{return true};		
	}
			 
	function validateZIP(fieldValue) 
	 {
		var valid = "0123456789-";
		var hyphencount = 0;
		var field = fieldValue;

		if (field.length!=5 && field.length!=10) 
		//if (field.length < 4) 
			{
				//alert("Please enter your 5 digit or 5 digit+4 zip code.");
				return false;	
			}

			for (var i=0; i < field.length; i++) 
				{
					temp = "" + field.substring(i, i+1);
					if (temp == "-") 
						hyphencount++;
						if (valid.indexOf(temp) == "-1") 
						 {
							//alert("Invalid characters in your zip code.  Please try again.");
							return false;
						}

					if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) 
						{
							//alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
							return false;
						}
					}
			return true;
		}
				
		function TrimString(s) 
		{
			// Remove leading spaces and carriage returns  
			while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
				{
					s = s.substring(1,s.length);
				}

			// Remove trailing spaces and carriage returns
			while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
				{
					s = s.substring(0,s.length-1);
				}
				return s;
	   }