var timeoutID = 0;
var prevID = '';
menu_status = new Array();

function showHide(theid){
    if (document.getElementById) {
    var switch_id = document.getElementById(theid);

        if(menu_status[theid] != 'show') {
           switch_id.className = 'show';
           menu_status[theid] = 'show';
		   if(timeoutID != 0){
		   	clearTimeout(timeoutID);
			timeoutID = 0;
		   }
		   if(prevID != ''){
		   	document.getElementById(prevID).className = 'hide';
           	menu_status[prevID] = 'hide';
			prevID = '';
		   }
		   timeoutID = setTimeout("showHide('" + theid + "')", 7000 );
		   prevID = theid;
        }else{
           switch_id.className = 'hide';
           menu_status[theid] = 'hide';
		   if(timeoutID != 0){
		   	clearTimeout(timeoutID);
			timeoutID = 0;
		   }
		   prevID = '';
        }
    }
}

function openProdWin(strLink) {
  var win = window.open('', 'prodWin', 'height=500,width=500,resizable=0,toolbar=0,scrollbars=0,status=0,menubar=0,location=0,directories=0');
  win.focus();
  if (strLink.indexOf('Install\.html') > -1) {
    strLink = strLink.replace('Install\.html', 'Install\_1\.html');
    strLink = 'installPhotos/' + strLink;
  }
  win.document.location.href = strLink;
}

function openDataFile(strLink) {
  var win = window.open('', 'dataFileWin', 'height=420,width=750,resizable=yes,toolbar=yes,scrollbars=yes,status=yes,menubar=yes,location=yes,directories=no');
  win.focus();
  win.document.location.href = 'data_files/index.html#id' + strLink;
}

function openInstructionFile(strLink) {
  var win = window.open('', 'instructionFileWin', 'height=420,width=750,resizable=yes,toolbar=yes,scrollbars=yes,status=yes,menubar=yes,location=yes,directories=no');
  win.focus();
  win.document.location.href = 'instruction_sheet.html#id' + strLink;
}

function openSpecificationFile(strLink) {
  var win = window.open('', 'instructionFileWin', 'height=420,width=750,resizable=yes,toolbar=yes,scrollbars=yes,status=yes,menubar=yes,location=yes,directories=no');
  win.focus();
  win.document.location.href = 'specification_sheet.html#id' + strLink;
}

function openBrochure(strFile) { openPDFWin('Brochure', strFile); };
function openSpecSheet(strFile) { openPDFWin('SpecSheet', strFile); };
function openInstSheet(strFile) { openPDFWin('InstSheet', strFile); };

function openPDFWin(strLink, strFile) {
  var win = window.open('', 'pdfWin', 'height=550,width=500,resizable=yes,toolbar=no,scrollbars=yes,status=no,menubar=no,location=no,directories=no');
  win.focus();
  var file = 'asp/index.asp?file=' + escape(strLink + '_' + strFile + '.pdf');
  win.document.location.href = file;
}

function openNewsWin(strLink) {
  var win = window.open('', 'prodWin', 'height=600,width=380,resizable=yes,toolbar=no,scrollbars=yes,status=no,menubar=no,location=no,directories=no');
  win.focus();
  win.document.location.href = strLink;
}

function sendPage(strLink) {
  var strPath = 'asp/';
  if (document.location.href.indexOf('.asp?') >= 0) strPath = '../asp/'; 
  var win = window.open(strPath + 'emailLink.asp?send=' + escape(strLink), 'sendWin', 'width=300,height=330,resizable=no,toolbar=no,scrollbars=no,status=no,menubar=no,location=no,directories=no');
  win.focus();
}

function swapImgOver(strImg) {
  var oImg = document.images[strImg];
  if (oImg == null) return;
  oImg.src = oImg.src.replace('_out\.', '_over\.');
}
function swapImgOut(strImg) {
  var oImg = document.images[strImg];
  if (oImg == null) return;
  oImg.src = oImg.src.replace('_over\.', '_out\.');
}
//*********************
var o1stBadFld = null;

function validateField(oFld, strName, iMinLen, iMaxLen) {
  var strErr = '';
  if (oFld == null) { alert(strName + ' field could not be found!'); return ''; }
  if (oFld.value != null && oFld.type == 'text') oFld.value = trim(oFld.value);
  if (oFld[0] != null && oFld[0].checked != null) {
    for (var i = 0; i < oFld.length; i++) {
      if (oFld[i].checked == true) return '';
    }
    if (o1stBadFld == null) o1stBadFld = oFld[0];
    if (oFld[0].type == 'checkbox') {
      strErr += 'Please select at least one of the "' + strName + '" options.\n';
    } else {
      strErr += 'Please select one of the "' + strName + '" options.\n';
    }
  } else if (oFld.selectedIndex != null && oFld.selectedIndex == 0) {
    strErr += 'Please select one of the "' + strName + '" options.\n';
  } else if (oFld.value == '' && iMinLen > 0) {
    strErr += 'Please enter a value for the "' + strName + '" field.\n';
  } else if (oFld.value.length < iMinLen) {
    strErr += 'Please enter at least ' + iMinLen + ' characters in the "' + strName + '" field.\n';
  } else if (oFld.value.length > iMaxLen) {
    strErr += 'Please enter at most ' + iMaxLen + ' characters in the "' + strName + '" field.\n';
  } 
  if (o1stBadFld == null && strErr != '') o1stBadFld = oFld;
  return strErr;
}

function bIsValidEmail(strEmail) {
  if (trim(strEmail) == '') return true;
  var strRe = "(\\w+([\\.\\-]\\w+)*)(@)(\\w+([\\.\\-]\\w+)+)";
  var re = new RegExp(strRe,"ig");
  var arr = re.exec(strEmail);
  if (arr == null || arr[0] != strEmail) return false;
  return true;
}

function trim(strValue) {
  var nbsp = String.fromCharCode(160), chr = null;
  if (strValue == null) strValue = "";
  strValue = "" + strValue;
  do {
    chr = strValue.charAt(0);
    if (chr == ' ' || chr == nbsp) {
      strValue = strValue.substr(1);
    }
  } while (chr == ' ' || chr == nbsp);
  do {
    chr = strValue.charAt(strValue.length - 1);
    if (chr == ' ' || chr == nbsp) {
      strValue = strValue.substr(0, strValue.length - 1);
    }
  } while (chr == ' ' || chr == nbsp);
  return strValue;
}

//*********************
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='Please enter a valid email address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += 'Please enter a valid '+nm+' address.\n'; }
  } if (errors) document.getElementById('validation').innerHTML =(errors);
  document.MM_returnValue = (errors == '');
}
