// JavaScript Document

var userAgent=navigator.userAgent;
if ((userAgent.indexOf('Firefox') != -1) || (userAgent.indexOf('Netscape') != -1) || (userAgent.indexOf('Safari') != -1) || (userAgent.indexOf('Opera') != -1)) {
  	document.write('<link href="TW_assets/styles/mozilla.css" rel="stylesheet" type="text/css">');
}

if ((userAgent.indexOf('MSIE 7') != -1) || (userAgent.indexOf('MSIE 8') != -1))  { //IE 7
	document.write('<link href="TW_assets/styles/ie7up.css" rel="stylesheet" type="text/css">');
}

if (userAgent.indexOf('Netscape/7') != -1) { // Netscape 7
	document.write('<link href="TW_assets/styles/netscape7.css" rel="stylesheet" type="text/css">');
}

function TW_ChangeTableWidth(thisTable,x)
{
  document.getElementById(thisTable).width=x;
}

function TW_changeStyle(id, newClass) {

	identity=document.getElementById(id);
	identity.className=newClass;

}

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function TW_processSearch(thisForm) {
	// v2.0
	// Read which search we are doing and populate the appopriate variable (hidden).
	var errors = '';
	var term = thisForm.SearchTerm.value;
	var length = term.length;
	var methods = thisForm.method;
	var x = methods.length;
	
	for (i=0; i<x; i++){
		if(methods[i].checked) { var thisMethod = methods[i].value; }
	}
	
	if (thisMethod == 'number') {
		if ((length > 23) || (length < 1) || (term == 'Search Catalog')) { errors = 'Please enter between 1 and 23 characters for the item number.\n'; } 
		else { thisForm.txtino.value = term; }
		}
		
	if (thisMethod == 'keyword') {
		if ((length > 20) || (length < 1) || (term == 'Search Catalog')) { errors = 'Please enter between 1 and 20 characters for the keyword.\n'; }
		else { thisForm.txtkey.value = term; }
		}

	if (errors) { alert('The following error(s) occurred:\n'+errors); }
	document.MM_returnValue = (errors == '');
	
}

function TW_CheckOrderUpdate(form) {
	// version 1.0
	// Checks data entered into order summary pane before allowing submission.
	var i, j;
	
	for (i = 0; i < form.elements.length; i++)
	{
		if (form.elements[i].id.substring(0,3) == "qty")
		{
			if (form.elements[i].value.length > 4)
			{
				alert("Field cannot be longer than 4 characters!");
				form.elements[i].select();
				form.elements[i].focus();
				return false;
				
			}
			
			for (j = 0; j < form.elements[i].value.length; j++)
			{
				if (form.elements[i].value.charAt(j) < "0" || form.elements[i].value.charAt(j) > "9")
				{
					alert("Field must contain only whole numbers 0-9!");
					form.elements[i].select();
					form.elements[i].focus();
					return false;
					
				}
			}
		}
	}
	
	return true;
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function WA_deleteCookie(cookieobj, cookiename, cookiecheck)     {
  if (cookiecheck)     {
    cookieobj.setValue(cookiename, "");
    cookieobj.expire(cookiename);
  }
}

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 chkform(theForm)
{
    
    if (theForm.txtmbrid.value === "")
    {
        alert("You must enter a user ID");
        theForm.txtmbrid.focus();
        return (false);
    }
    
    if (theForm.txtmbrid.value.length < 1)
    {
        alert("You must enter a user ID.");
        theForm.txtmbrid.focus();
        return (false);
    }
    
    if (theForm.txtmbrid.value.length > 64)
    {
        alert("User ID cannot be more than 64 characters.");
        theForm.txtmbrid.focus();
        return (false);
    }
    if (theForm.txtmbrpassword.value === "")
    {
        alert("You must enter a password.");
        theForm.txtmbrpassword.focus();
        return (false);
    }
    
    if (theForm.txtmbrpassword.value.length < 1)
    {
        alert("You must enter a password.");
        theForm.txtmbrpassword.focus();
        return (false);
    }
    
    if (theForm.txtmbrpassword.value.length > 64)
    {
        alert("Password cannot be more than 64 characters.");
        theForm.txtmbrpassword.focus();
        return (false);
    }
    
    // Disable the login button
    //theForm.cmdLogin.value = "Logging In...";
    //theForm.cmdLogin.disabled = true;
    
    // Return clean
    return (true);
}

function CookieDef(expires,path,domain,secure)
{
  this.secure = secure;
  this.path = path;
  this.domain = domain;
  this.getValue = getCookie;
  this.setValue = setCookie;
  this.expire = deleteCookie;
  if (expires == 0) {
    this.expires = "";
  } else {
    var today_date = new Date();
	 var expire_seconds = today_date.getTime() + (expires * 24 * 60 * 60  * 1000);
    today_date.setTime(expire_seconds);
    this.expires = today_date.toGMTString();
  }
}
function getCV(offset) {
  var endstr = document.cookie.indexOf(";", offset);
  if (endstr == -1) endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
function getCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCV(j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return "";
}
function setCookie(name,value)
{
  document.cookie = name + "=" + escape(value) +
    ((this.expires == "") ? "" : ("; expires=" + this.expires)) +
    ((this.path == "") ? "" : ("; path=" + this.path)) +
    ((this.domain == "") ? "" : ("; domain=" + this.domain)) +
    ((this.secure == true) ? "; secure" : "");
}
function deleteCookie(name) {
  document.cookie = name + "=" + "" + "; expires=Thu,01-Jan-70 00:00:01 GMT";
}

function WA_setCookie(cookieobj, cookiename, cookievalue, cookiecheck, settype)     {
  var theValue = "";
  if (settype == 1)     {
    for (var n=0; n<cookievalue.length; n++)    {
      if (cookievalue[n].checked)     {
        theValue = cookievalue[n].value;
      }
    }
  }
  else if (settype == 2)     {
    for (var n=0; n<cookievalue.options.length; n++)    {
      if (cookievalue.options[n].selected)     {
        if (theValue != "")
          theValue += ", ";
        theValue += cookievalue.options[n].value;
      }
    }
  }
  else      {
    theValue = cookievalue
  }

  if (cookiecheck)     {
    cookieobj.setValue(cookiename, theValue);
  }
}

function WA_deleteCookie(cookieobj, cookiename, cookiecheck)     {
  if (cookiecheck)     {
    cookieobj.setValue(cookiename, "");
    cookieobj.expire(cookiename);
  }
}

function WA_decodeCookieSelectVal(theVal)     {
  theVal = theVal.replace(/\|WACS\|/g, ", ");
  return theVal;
}

function WA_checkCookieSelectOption(theList, theOption, theVal)     {
  var testVal = "";
  if (theList.options[theOption].value)     {
    testVal = theList.options[theOption].value;
  }
  else      {
    testVal = theList.options[theOption].text;
  }
  if (testVal == WA_decodeCookieSelectVal(theVal))     {
    theList.options[theOption].selected = true;
    return true;
  }
  return false;
}

function WA_getCookie(cookieobj, cookiename, cookieset, settype)     { // TW Updated
  var theValue = cookieobj.getValue(cookiename);
  if (theValue != '') {
	  if (settype == 1)     {
		cookieset.value = theValue;
	  }
	  else if (settype == 2)     {
		cookieset.checked = (String(theValue)!="" && String(theValue).toUpperCase() !="FALSE");
	  }
	  else if (settype == 3)     {
		for (var n=0; n< cookieset.length; n++)     {
		  if (cookieset[n].value == theValue)     {
			cookieset[n].checked = true;
			break;
		  }
		}
	  }
	  else if (settype == 4)     {
		var setArr = theValue.split(", ");
		for (var m=0; m<setArr.length; m++)     {
		  for (var n=0; n<cookieset.options.length; n++)     {
			if (n+m < cookieset.options.length && cookieset.options[n+m])     {
			  if (WA_checkCookieSelectOption(cookieset, n+m, setArr[m]))     {
				break;
			  }
			}
			if (n!=0 && n-m >= 0 && cookieset.options[n-m])     {
			  if (WA_checkCookieSelectOption(cookieset, n-m, setArr[m]))     {
				break;
			  }
			}
			if (n-m < 0 && n+m >= cookieset.options.length)     {
			  break;
			}
		  }
		}
	  }
  }
}


function WAAddError(formElement,errorMsg,focusIt,stopIt)  {
  if (document.WAFV_Error)  {
	  document.WAFV_Error += "\n" + errorMsg;
  }
  else  {
    document.WAFV_Error = errorMsg;
  }
  if (!document.WAFV_InvalidArray)  {
    document.WAFV_InvalidArray = new Array();
  }
  document.WAFV_InvalidArray[document.WAFV_InvalidArray.length] = formElement;
  if (focusIt && !document.WAFV_Focus)  {
	document.WAFV_Focus = focusIt;
  }

  if (stopIt == 1)  {
	document.WAFV_Stop = true;
  }
  else if (stopIt == 2)  {
	formElement.WAFV_Continue = true;
  }
  else if (stopIt == 3)  {
	formElement.WAFV_Stop = true;
	formElement.WAFV_Continue = false;
  }
}

function WAValidateNM(formElement,errorMsg,minLength,maxLength,allowDecimals,roundDecimals,reformatDecimals,punctuationMarks,focusIt,stopIt,required)  {
  var isValid = true;
  var theThousand = punctuationMarks.charAt(0);
  var theDecimal = punctuationMarks.charAt(1);
  var theCheck = 11/10;
  var trueDecimal = (String(theCheck).charAt(1));
  var value = formElement.value;
  var decimalIndex = value.length;
  if (punctuationMarks.indexOf(trueDecimal)<0 && value.indexOf(trueDecimal)>=0)  {
    isValid = false;
  }
  if (value.lastIndexOf(theDecimal)>=0) {
    decimalIndex = value.lastIndexOf(theDecimal);
  }
  while (value.indexOf(theThousand)>=0)  {
    decimalIndex = value.length;
    if (value.lastIndexOf(theDecimal)>=0) {
      decimalIndex = value.lastIndexOf(theDecimal);
    }
    if ((decimalIndex-(value.lastIndexOf(theThousand)+1))%3 != 0)
	  isValid = false;
    value = value.substring(0,value.lastIndexOf(theThousand)) + value.substring(value.lastIndexOf(theThousand)+1);
  }
  if (trueDecimal != theDecimal)  {
    while (value.indexOf(theDecimal)>=0)  {
      value = value.substring(0,value.indexOf(theDecimal)) + trueDecimal + value.substring(value.indexOf(theDecimal)+1);
    }
  }
  if ((!document.WAFV_Stop && !formElement.WAFV_Stop) && !(!required && value==""))  {
    for (var x=0; x<value.length; x++)  {
	  if  ((value.charAt(x)<0 || value.charAt(x) > 9) && (value.charAt(x) != " " && value.charAt(x) != "," && value.charAt(x) != "."))  {
        isValid = false;
      }
	}
    if (value == "")  {
	  isValid = false;
	}
	var oldVal = String(value);
	if (oldVal.indexOf(trueDecimal)>=0)  {
	  while (oldVal.charAt(oldVal.length-1)=="0" || oldVal.charAt(oldVal.length-1) == trueDecimal)
	    oldVal = oldVal.substring(0,oldVal.length-1);
	  if (oldVal.indexOf(trueDecimal)==0)
	    oldVal = "0" + oldVal;
	}
    if (String(allowDecimals) !="" )  {
	  if (String(value).indexOf(".") > 0 && ((String(value).indexOf(".") + allowDecimals + 2 <= String(value).length) || allowDecimals == 0))  {
	    isValid = false;
	  }
	}
	value = parseFloat(value);
	if (isNaN(value))  {
	  isValid = false;
	}
	else if (String(value).length!=String(oldVal).length) {
	  isValid = false;
	}
	else if ((minLength != "" && minLength > value) || (maxLength != "" && maxLength < value)) {
	  isValid = false;
	}
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
  else  {
    if (value != "")  {
	  if (roundDecimals != "")  {
	    value = Math.round(value*roundDecimals)/roundDecimals;
	  }
	  if (reformatDecimals != "")  {
	    value = String(value);
		if (value.indexOf(trueDecimal)<0)
		  value += trueDecimal;
		if (value.indexOf(trueDecimal) < value.length - reformatDecimals)  {
		  value = value.substring(0,value.indexOf(trueDecimal) + reformatDecimals + 1);
		}
		else  {
		  while (value.indexOf(trueDecimal) > value.length - reformatDecimals - 1)  {
		     value += "0";
		  }
		}
	  }
	}
    if (trueDecimal != theDecimal)  {
	  value = String(value);
      while (value.indexOf(trueDecimal)>=0)  {
        value = value.substring(0,value.indexOf(trueDecimal)) + theDecimal + value.substring(value.indexOf(trueDecimal)+1);
      }
    }
	if (roundDecimals != "" || reformatDecimals != "")
	  formElement.value = value;
  }
}

function WAAlertErrors(errorHead,errorFoot,setFocus,submitForm)  { 
  if (!document.WAFV_StopAlert)  { 
	  document.WAFV_StopAlert = true;
	  if (document.WAFV_InvalidArray)  {  
	    document.WAFV_Stop = true;
        var errorMsg = document.WAFV_Error;
	    if (errorHead!="")
		  errorMsg = errorHead + "\n" + errorMsg;
		if (errorFoot!="")
		  errorMsg += "\n" + errorFoot;
		document.MM_returnValue = false;
		if (document.WAFV_Error!="")
		  alert(errorMsg.replace(/&quot;/g,'"'));
		else if (submitForm)
		  submitForm.submit();
	    if (setFocus && document.WAFV_Focus)  {
		  document.tempFocus = document.WAFV_Focus;
          setTimeout("document.tempFocus.focus();setTimeout('document.WAFV_Stop = false;document.WAFV_StopAlert = false;',1)",1); 
        }
        else {
          document.WAFV_Stop = false;
          document.WAFV_StopAlert = false;
        }
        for (var x=0; x<document.WAFV_InvalidArray.length; x++)  {
	      document.WAFV_InvalidArray[x].WAFV_Stop = false;
	    }
	  }
	  else  {
        document.WAFV_Stop = false;
        document.WAFV_StopAlert = false;
	    if (submitForm)  {
	      submitForm.submit();
	    }
	    document.MM_returnValue = true;
	  }
      document.WAFV_Focus = false;
	  document.WAFV_Error = false;
	  document.WAFV_InvalidArray = false;
  }
}

function WAValidateAN(formElement,value,errorMsg,allowUpper,allowLower,allowNumbers,allowSpace,extraChars,focusIt,stopIt,required)  {
  var isValid = true;
  extraChars = extraChars.replace(/&quot;/g,'"');
  if ((!document.WAFV_Stop && !formElement.WAFV_Stop) || formElement.WAFV_Continue)  {
    for (var x=0; x<value.length; x++)  {
	  var charGood = false;
	  var nextChar = value.charAt(x);
	  var charCode = value.charCodeAt(x);
	  if (allowLower)  {
	    if (charCode >= 97 && charCode <= 122)  {
		  charGood = true;
		}
	  }
	  if (allowUpper)  {
	    if (charCode >= 65 && charCode <= 90)  {
		  charGood = true;
		}
	  }
	  if (allowNumbers)  {
	    if (charCode >= 48 && charCode <= 57)  {
		  charGood = true;
		}
	  }
	  if (allowSpace)  {
	    if (nextChar == " ")  {
		  charGood = true;
		}
	  }
	  if (extraChars)  {
	    if (unescape(extraChars).indexOf(nextChar) >= 0)  {
		  charGood = true;
		}
	  }
	  if (!charGood)  {
	    isValid = false;
		x = value.length;
	  }
	}
	if (required && value=="")
	  isValid = false;
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
}