// JavaScript Document
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_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_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}
function AdRotationLong(images,urls,iparams)
{
/* si: start index 
** i: current index
** ei: end index
** cc: current count
*/
 imageSet = new Array();
 urlSet = new Array();
 si = 0; 
 ci=0;
 cc=0;
 ei = images.length;
  for (i=1;i<ei;i++) {
    if (images.charAt(i) == ' ' || images.charAt(i) == ',') {
      imageSet[cc] = images.substring(si,i);
      cc++;
      si=i+1;
      }
    }
  ind = Math.floor(Math.random() *cc);
 si = 0; 
 ci=0;
 cc=0;
 ei = urls.length;
  for (i=1;i<ei && cc <=ind ;i++) {
    if (urls.charAt(i) == ' ' || urls.charAt(i) == ',') {
      urlSet[cc] = urls.substring(si,i);
      cc++;
      si=i+1;
      }
    }

  document.writeln("<img "+iparams+" src="+imageSet[ind]+" alt=\""+imageSet[ind]+"\">");
  //document.writeln("<img "+iparams+" src="+imageSet[ind]+" alt=\""+imageSet[ind]+"\">");
}

function AdRotation(images,urls)
{
  AdRotationLong(images,urls,"border=0");
}
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_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_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function photoWin(part) {
	partWindow=window.open(part, "SamcoHoseKit", "height=375, left=0, top=0, menubar=no, status=no, location=no, toolbar=no, resizable=yes");
	partWindow.focus()

}
// this function will change the color of a form element. //
//  arguments are "e" - element and "c" color to change to //
// example : <input type="text" name="test" onfocus="ChangeColor(this, 'f00');" onblur="ChangeColor(this, 'fff');" /> //

function ChangeColor(e, c) {
  e.style.backgroundColor = "#" + c;
}

// this function is for form validation.  it will loop through all fields in a given form.
//  if the element's name starts with "op_" (for optional field), it will skip validation.
//  Otherwise, it will check for null values, and alert the field's name if it is empty.
// if the field is named "email" or "phone", it uses regular expressions to make sure
// that the user's input matches the rules for phone #s & email addresses.
//  to call : <form name="whatever" methd="post" action="/cgi-bin/mailform?whatever" onsubmit="return Validate(this);">  
// if you want to be sure someone selects something from a select box, be sure to create an <option> with a value of default
// so the script can check to see that something other than default is selected

function Validate(f) {
  var e = "";
  for(i=0;i<f.length;i++) {
    if(!f[i].name.substring(0,3).match(/op_/)) {
        if(f[i].name.match(/email/)) {
          var RegEx = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
          if(!RegEx.test(f[i].value)) {
            e += "Null or invalid entry for email address.\n";
            ChangeColor(f[i], 'ffff00');
          }
        } else if(f[i].name.match(/phone/)) {
            e += IntelliPhone(f[i]);
        } else {
          if(f[i].value == "" || f[i].value == "default") {
            e += "Please fill out the required field \"" + f[i].name + "\".\n";
            ChangeColor(f[i], 'ffff00');
          } 
        }
    }
  }
  if(e.length > 0) {
    alert(e);
    return false;
  } else {          
    return true;
  }
}

// this function is the phone number validator.
// it automatically formats the users input : (###) ###-####
// If the user did not enter area code + valid phone #, it will error out
// This function is called from the Validate() function, but I usually call it like this also :
// <input type="text" name="phone" onblur="IntelliPhone(this);" />
// As that way, it will format the phone number right in the text box, as soon as the user 
// moves on to the next one.
function IntelliPhone(f) {
    var e = "";
    if(f.value.length < 10 || f.value.length > 14) {
        e += "Invalid entry for phone number.\n";
        ChangeColor(f, 'f00');
        return e;
    }  
    var SpecialChars = /\(|\)|\-|\\|\/|\.|\s+|\D/g;
    if(SpecialChars.test(f.value)) {
        var RemoveSpecialChars = f.value.replace(SpecialChars, "");
        f.value = RemoveSpecialChars;
    }
    if(f.value.length != 10) {
        e += "Please enter phone number, with area code.\n";
        ChangeColor(f, 'f00');
        return e;
    } else {
      var FormattedPhone = "(" + f.value.substring(0,3) + ") " + f.value.substring(3,6) + "-" + f.value.substring(6,10);
      f.value = FormattedPhone;
    }
    // var RexExpPhone = /\(\d{3}\)\s\d{3}-\d{4}/;
    var RexExpPhone = /\(\d{3}\)\s\d{3}-\d{4}/;
    if(!FormattedPhone.match(RexExpPhone)) {
      e += "Invalid entry for phone number.\n";
      ChangeColor(f, 'f00');
      return e;
    } else {
      return "";
    }
}
