// -- Bookmarking

function bookmark() {
 url = "http://www.911restorationinc.com";
 caption = "911 Restoration - Water Damage & Emergency Restoration Services";
 if (window.sidebar) 
   window.sidebar.addPanel(caption,url,0);
 else if (document.all)
   window.external.AddFavorite(url,caption);
}

// -- change country scripts --

function to_canada() {
   doChangeCountry('ca')
}
function to_states() {
   doChangeCountry('us')
}

function doChangeCountry(country) {
   formname = 'd_setloc';   
   formobj = addHtmlForm(formname,location.href);
   addHiddenInputField(formobj,'country',country);
   formobj.submit();
}
/*
   Adds an html form (dynamically created) to the HTML body element (assuming it exists.).
   @param actionValue action string
   @return the newly created HTML form element.
*/
function addHtmlForm(formname,actionValue) {
   var formElement = document.createElement("form");
   formElement.setAttribute('name',formname); 
   formElement.method = "POST";
   formElement.action = actionValue;
   var body = document.getElementsByTagName("body")[0];
   body.appendChild(formElement);
   return formElement;
}
/*
   Adds an html hidden input field (dynamically created) to the given HTML form element.
   @param formElement the given HTML form element
   @param fieldName the name of the hidden input field
   @param fieldValue the (string) value of the hidden input field
*/
function addHiddenInputField(formElement, fieldName, fieldValue) {
    var inputElement = document.createElement("input");
    inputElement.setAttributeNode(createHtmlAttribute("type", "hidden"));
    inputElement.setAttributeNode(createHtmlAttribute("name", fieldName));
    inputElement.setAttributeNode(createHtmlAttribute("value", fieldValue));
    formElement.appendChild(inputElement);
    return inputElement;
}

/*
   Creates an html attribute.
   @param name the name of the attribute.
   @param value the (string) value of the attribute.
   @return the newly created html attribute
*/
function createHtmlAttribute(name, value) {
    var attribute = document.createAttribute(name);
    attribute.nodeValue = value;
    return attribute;
}

// -- form validation scripts --

function check1()
{
 err = '';
 form = document.form1;
 name = form.nm.value;
 if (name=='' || name.length<3) err += '* Please enter your name\n';
 p1 = form.p1.value;
 p2 = form.p2.value;
 p3 = form.p3.value;
 if ( (isNaN(p1) || isNaN(p2) || isNaN(p3)) ||
      (p1.length<3 || p2.length<3 || p3.length<4) ) 
       err += '* Please enter valid phone number\n     example: 1(XXX)XXX-XXXX [digits for Xs]\n';
 else
      form.ph.value='1('+p1+')'+p2+'-'+p3;
 state = form.st.value;
 zip = form.zp.value;
 if (form.country.value=='us') { // testing zip & state for united states 
   if (state=='' && zip=='') err += '* Please enter zip code or state';
   if (zip!='' && ( isNaN(zip) || zip.length!=5 ) ) err += '* Please enter valid 5 digits zip code';
 }
 else { // testing postal code & province for canada
   if (state=='' && zip=='') err += '* Please enter postal code or province';
   re = /^([a-z]\d){3}$/i ;
   if (zip!='' && !(re.test(zip))) err += '* Please enter valid postal code\n     example: oXoXoX [o=letter, X=digit, no space required]';
 }
 if (err) alert(err)
 else {
   form.from1.value='1';
   form.submit();
 }
}
function check0()
{
 err = '';
 form = document.form2;
 name = form.nm.value;
 if (name=='' || name.length<3) err += '* Please enter your name\n';
 p1 = form.p1.value;
 p2 = form.p2.value;
 p3 = form.p3.value;
 if ( (isNaN(p1) || isNaN(p2) || isNaN(p3)) ||
      (p1.length<3 || p2.length<3 || p3.length<4) ) 
       err += '* Please enter valid phone number 1(XXX)XXX-XXXX [digits for Xs]\n';
 else
      form.ph.value='1('+p1+')'+p2+'-'+p3;
 state = form.st.value;
 zip = form.zp.value;
 if (form.country.value=='us') { // testing zip & state for united states 
   if (state=='' && zip=='') err += '* Please enter zip code or state';
   if (zip!='' && ( isNaN(zip) || zip.length!=5 ) ) err += '* Please enter valid 5 digits zip code';
 }
 else { // testing postal code & province for canada
   if (state=='' && zip=='') err += '* Please enter postal code or province';
   re = /^([a-z]\d){3}$/i ;
   if (zip!='' && !(re.test(zip))) err += '* Please enter valid postal code\n     example: oXoXoX [o=letter, X=digit, no space required]';
 }
 if (err) alert(err)
 else {
   form.from2.value='2';
    form.submit();
 }
}
function scrolltotop()
{
  window.scroll(0,0);
}


      
