function swapImage(image) {
  document.getElementById('language').src = image;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

curProduct = 1;
curCurb = 1;
oldFormValues = new Array();
oldFormNames = new Array();

function CaptureForm() {
  for (i = 0; i < document.forms["OrderForm"].elements.length; ++i) {
    oldFormValues[i] = document.forms["OrderForm"].elements[i].value;
    oldFormNames[i] = document.forms["OrderForm"].elements[i].name;
  }
}

function ReFillForm() {
  for (i = 0; i < oldFormValues.length; ++i) {
    if (document.forms["OrderForm"].elements[oldFormNames[i]].value != oldFormValues[i]) {
    document.forms["OrderForm"].elements[oldFormNames[i]].value = oldFormValues[i];
    }
  }
}

function AddAnotherProduct() {
  if (document.all) {
    divProd = document.all["AnotherProduct"];
  } else {
    divProd = document.getElementById("AnotherProduct");
  }
  curProduct++;
  CaptureForm();
  divProd.innerHTML += '<hr size="0" noshade><br /><table width="100%" border="0" cellspacing="0" cellpadding="3"> <tr> <td width="115" bgcolor="#D6D6D6"> <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr class="body"> <td width="40"><strong>QTY:</strong></td> <td><input name="qty1" size="3" value=""></td> </tr> </table> </td> <td width="15">&nbsp;</td> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="95" class="body">Description:</td> <td> <select name="product1"> <option value="Straight Pipe Jacks 10&quot; Tall">Straight Pipe Jacks 10&quot; Tall</option> <option value="RVO-38 Vent Boot">RVO-38 Vent Boot</option> <option value="Outside Corner">Outside Corner</option> <option value="Inside Corner">Inside Corner</option> <option value="Tapered Pipe Boot (Cones)">Tapered Pipe Boot (Cones)</option> <option value="Drain Boots">Drain Boots</option> <option value="Angle Boot 30 degree">Angle Boot 30 degree</option> <option value="Angle Boot 45 degree">Angle Boot 45 degree</option> <option value="Custom Item: (Describe Below)">Custom Item: (Describe Below)</option> <option value="CJ 2-way vent">CJ 2-way vent</option> <option value="Curb Wraps">Curb Wraps</option> </select> </td> </tr> </table> <br> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr class="body"> <td width="95">Jack Diameter:</td> <td width="80"> <select name="diam1"> <option value="" selected>-</option> <option value="1&quot;">1&quot;</option> <option value="2&quot;">2&quot;</option> <option value="3&quot;">3&quot;</option> <option value="4&quot;">4&quot;</option> <option value="5&quot;">5&quot;</option> <option value="6&quot;">6&quot;</option> <option value="7&quot;">7&quot;</option> <option value="8&quot;">8&quot;</option> <option value="9&quot;">9&quot;</option> <option value="10&quot;">10&quot;</option> <option value="11&quot;">11&quot;</option> <option value="12&quot;">12&quot;</option> <option value="13&quot;">13&quot;</option> <option value="14&quot;">14&quot;</option> <option value="15&quot;">15&quot;</option> <option value="16&quot;">16&quot;</option> <option value="17&quot;">17&quot;</option> <option value="18&quot;">18&quot;</option> <option value="19&quot;">19&quot;</option> <option value="20&quot;">20&quot;</option> </select> </td> <td width="90">Cone Range:</td> <td width="140"> <select name="conerange1"> <option value="" selected>-</option> <option value=".25 - 2&quot; (SA)">.25 - 2&quot; (SA)</option> <option value=".25 - 3&quot; (SA+)">.25 - 3&quot; (SA+)</option> <option value="1 - 3&quot; (A)">1 - 3&quot; (A)</option> <option value="1 - 4&quot; (A+)">1 - 4&quot; (A+)</option> <option value="2 - 4&quot; (B)">2 - 4&quot; (B)</option> <option value="3 - 6&quot; (B+)">3 - 6&quot; (B+)</option> <option value="4 - 7&quot; (C)">4 - 7&quot; (C)</option> <option value="7 - 11&quot; (D)">7 - 11&quot; (D)</option> <option value="10 - 14&quot; (E)">10 - 14&quot; (E)</option> </select> </td> <td width="90">Open/Closed:</td> <td> <select name="openclose1"> <option value="Open">Open</option> <option value="Closed" selected>Closed</option> </select> </td> </tr> </table> </td> </tr> </table>';
  ReFillForm();
}

function AddAnotherCurb() {
  if (document.all) {
    divCurb = document.all["AnotherCurb"];
  } else {
    divCurb = document.getElementById("AnotherCurb");
  }
  curCurb++;
  CaptureForm();
  divCurb.innerHTML += '<table width="90%" border="0" cellpadding="3" cellspacing="1" bgcolor="#A6A6A6"> <tr class="body"> <td bgcolor="#D6D6D6"><div align="center" class="body"><strong>QTY</strong></div></td> <td bgcolor="#FFFFFF"><div align="center">Length</div></td> <td bgcolor="#FFFFFF"><div align="center">Width</div></td> <td bgcolor="#FFFFFF"><div align="center">Height</div></td> </tr> <tr class="body"> <td bgcolor="#D6D6D6"><div align="center"><input name="curbqty1" type="text" size="3"></div></td> <td bgcolor="#FFFFFF"><div align="center"><input name="curblength1" type="text" size="3"></div></td> <td bgcolor="#FFFFFF"><div align="center"><input name="curbwidth1" type="text" size="3"></div></td> <td bgcolor="#FFFFFF"> <div align="center"><input name="curbheight1" type="text" size="3"></div></td> </tr> </table>';
  ReFillForm();
}

function confirmFields(formName) {
  var errorMessage = "";
  for (var i = 0; i < document.forms[formName].elements.length; i++) {
    if (document.forms[formName].elements[i].value == "" && document.forms[formName].elements[i].attributes["required"] != null ) {
      errorMessage += "*   " + document.forms[formName].elements[i].attributes["required"].value + "\n";
    }
  }
  if (errorMessage != "") {
    alert ("Please fill in the following fields:\n\n" + errorMessage);
    return false;
  } else {
    return true;
  }
}

function popMessage() {
  alert('Thank you! Your order has been successfully submitted. A representative will contact you soon.')
}

function errorMessage() {
  alert('Error! You must enter a valid email address before submitting an order.');
}
