var jsFieldLength, jsUserPass, jsFirstName, jsLastName, jsZipCode, errorMessage, jsAdditionalComments, jsProductName, jsProductSize, jsEmail, jsShoppingMethod
function checkFieldLength(myForm, myField, myLength, myErrMsg)
{ 
document.getElementById(myErrMsg).childNodes[0].nodeValue = "";	
  valueTest = eval("document." + myForm + "." + myField + "." + "value;");
  valueTest2 = valueTest.split(' ').join('');
    if(valueTest2.length >= myLength){
      switch(myField)
      {   
        case "txtFirstNameID":
             jsFirstName = "";
        break;
        case "txtLastNameID":
             jsLastName = "";
        break;
        case "taAdditionalCommentsID":
             jsAdditionalComments = "";
        break;
        case "txtProductNameID":
			  jsProductName = "";
        break;
        case "txtProductSizeID":
			  jsProductSize = "";
        break;
        default:			  
      }		
	}else{	
		document.getElementById(myErrMsg).childNodes[0].nodeValue = "You need at least " + myLength + " characters.";		
      switch(myField)
      {
        case "txtFirstNameID":
			  jsFirstName = "First Name\n";
        break;
        case "txtLastNameID":
			  jsLastName = "Last Name\n";
        break;
        case "taAdditionalCommentsID":
			  jsAdditionalComments = "Comment\n";
        break;
        case "txtProductNameID":
			  jsProductName = "Product Name\n";
        break;
        case "txtProductSizeID":
			  jsProductSize = "Product Size\n";
        break;
        default:
       }
    }	
}
function focusField(x,z){

	var z=document.getElementById(z);
	if(z != null){
		z.focus();
	}
}
function trim11 (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}
function zeroPad(num,count)
{ 
  var numZeropad = num + '';
    while(numZeropad.length < count) {
      numZeropad = "0" + numZeropad; 
    }
    return numZeropad;
}


function showLoading(which){	
var flashPreloader = document.getElementById("displayLoadingCirlce");
	if(which == "hide"){		
		flashPreloader.childNodes[0].nodeValue = "";
		flashPreloader.innerHTML="";
	}else{
	    flashPreloader.childNodes[0].nodeValue = "<img src='images/preloadCircle.gif' />";
		flashPreloader.innerHTML = "<img src='images/preloadCircle.gif' />";
	}
}

function cleanDataJS(strTemp) { 
    strTemp = strTemp.replace(/\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-/g,""); 
    return strTemp;
} 

function encodeIt(x){
	return escape(x);
}
function URLencode(sStr) {
    return escape(sStr).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
  }


function selStoreFunc(){
  var storeINFO, storeDrop, address, city, state, zip, cityStateZipINFO, cityStateZipINFO2, finalINFO, test, newZip
  storeDrop = document.getElementById("selStoreID");	
  storeINFO = storeDrop.options[storeDrop.selectedIndex].text;
  address = document.getElementById("txtStoreAddressID");
  city = document.getElementById("txtStoreCityID");
  state = document.getElementById("txtStoreStateID");
  zip = document.getElementById("txtStoreZipID");  

  if(storeINFO != "Select a Store"){
   finalINFO = storeINFO.split(" - ");  
   address.value = trim11(finalINFO[2]);	
   city.value = finalINFO[1];
   state.value = finalINFO[0];
   test = finalINFO[3];
   newZip = test.slice(0,5);
   zip.value = newZip;
  }else{
   address.value = "";	    
   city.value = "";
   state.value = "";
   zip.value = "";
  }
}
function checkComments(){
	checkFieldLength("contactUs", "taAdditionalCommentsID", 10, "commentsMsg");
}
function checkEmail()
{
var patternReg=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|COM|net|NET|org|ORG|edu|EDU|int|INT|mil|MIL|gov|GOV|arpa|biz|aero|name|coop|info|pro|museum|tv|ca))$/;

    if(patternReg.test(trim11(document.contactUs.txtEmail.value))){ 		
		document.getElementById('eMailMsg').childNodes[0].nodeValue = " ";	
		jsEmail = "";
	} else {
		document.getElementById('eMailMsg').childNodes[0].nodeValue = "Please enter a valid email address.";	
		jsEmail = "Email Address\n";	
	}
}
String.prototype.toCapitalCase = function() {
	var re = /\s/;
	var words = this.split(re);
	re = /(\S)(\S+)/;
	for (i = words.length - 1; i >= 0; i--) {
	re.exec(words[i]);
	words[i] = RegExp.$1.toUpperCase()
	+ RegExp.$2.toLowerCase();
	}
return words.join(' ');
} 
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
function upperCaseField(){
var thisValue=document.getElementById("txtFirstNameID");
	if(thisValue == "object"){
	document.contactUs.txtFirstName.value = document.contactUs.txtFirstName.value.toCapitalCase();
	document.contactUs.txtLastName.value = document.contactUs.txtLastName.value.toCapitalCase();
	}
}
function number(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;
else if ((("0123456789\"'").indexOf(keychar) > -1))
   return true;
else
   return false;
}
function letter(e)
{
var key;
var keychar;
if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27))
   return true;
else if ((("abcdefghijklmnopqrstuvwxyz \"'").indexOf(keychar) > -1))
   return true;
else
   return false;
}
function specialChars(e) // * | , \ " : < > [ ] { } ` \ ' ; ( ) @ & $ # % + -
{
/*var key;
var keychar;
if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27))
   return true;
else if ((("abcdefghijklmnopqrstuvwxyz0123456789.,' ").indexOf(keychar) > -1))
   return true;
else
   return false;*/
   return true;
}
function specialCharsComments(e) // * | , \ " : < > [ ] { } ` \ ' ; ( ) @ & $ # % + -
{
/*var key;
var keychar;
if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27))
   return true;
else if ((("abcdefghijklmnopqrstuvwxyz0123456789!:;.\"?,' ").indexOf(keychar) > -1))
   return true;
else
   return false;*/
   return true;
}
function checkSpecialsChars(formname,fieldnameID){
   var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
   var thisValue = document.getElementById(""+fieldnameID+"");	
  for (var i = 0; i < thisValue.value.length; i++) {
  	if (iChars.indexOf(thisValue.value.charAt(i)) != -1) {
	  thisValue.select();
  	  alert ("The highlighted field has special characters that are not allowed.\n Please remove them and try again.");
  	return false;
  	}
  }
}
function shoppingMethodFunc(){
  var methodINFO, methodDrop
  methodDrop = document.getElementById("shoppingMethod");	
  methodINFO = methodDrop.options[methodDrop.selectedIndex].text; 

  if(methodINFO != "Select One"){
	  jsShoppingMethod = "";
  }else{	
     jsShoppingMethod = "Shopping Method\n";
  }
}
function validateFormContactUs(){
  var onlineShopping = document.getElementById("shoppingMethod");
  if(onlineShopping != null){
	shoppingMethodFunc();
  }else{
    jsShoppingMethod = "";
  }
  
  selStoreFunc();
  checkFieldLength("contactUs", "txtFirstNameID", 2, "fNameMsg");
  checkFieldLength("contactUs", "txtLastNameID", 2, "lNameMsg");
  checkFieldLength("contactUs", "taAdditionalCommentsID", 10, "commentsMsg");
  checkEmail();
 
  var validUpdate;
  validUpdate = jsShoppingMethod + jsFirstName + jsLastName + jsEmail + jsAdditionalComments;
  var errorMsgHeader = "Please double check\nthe following field(s):\n-------------------------\n";
  
  var btn=document.getElementById("submitID");
  if(validUpdate == ""){
    btn.disabled=true;
	showLoading("show");
    return true;
  }else{   
    btn.disabled=false;
	showLoading("hide");
    alert(errorMsgHeader + validUpdate);
    return false;	
  }
}
function validateFormPrivateLabel(){ 
 selStoreFunc();
 checkFieldLength("contactUs", "txtFirstNameID", 2, "fNameMsg");
 checkFieldLength("contactUs", "txtLastNameID", 2, "lNameMsg"); 
 checkEmail();
 checkFieldLength("contactUs", "taAdditionalCommentsID", 10, "commentsMsg");
 checkFieldLength('contactUs', 'txtProductNameID', 2, 'productNameMsg');
 checkFieldLength('contactUs', 'txtProductSizeID', 2, 'productSizeMsg');
  
  var validUpdate;
  validUpdate = jsFirstName + jsLastName + jsEmail + jsAdditionalComments + jsProductName + jsProductSize;
  var errorMsgHeader = "Please double check\nthe following field(s):\n-------------------------\n";
  
  var btn=document.getElementById("submitID");
  if(validUpdate == ""){
    btn.disabled=true;
	showLoading("show");
    return true;
  }else{
    btn.disabled=false;
	showLoading("hide");
    alert(errorMsgHeader + validUpdate);
    return false;	
  }
}
function validateFormTechnical(){ 
  var onlineShopping = document.getElementById("shoppingMethod");
  if(onlineShopping != null){
	shoppingMethodFunc();
  }else{
    jsShoppingMethod = "";
  }
  
 checkFieldLength("contactUs", "txtFirstNameID", 2, "fNameMsg");
 checkFieldLength("contactUs", "txtLastNameID", 2, "lNameMsg"); 
 checkEmail();
 checkFieldLength("contactUs", "taAdditionalCommentsID", 10, "commentsMsg");
  
  var validUpdate;
  validUpdate = jsShoppingMethod + jsFirstName + jsLastName + jsEmail + jsAdditionalComments;
  var errorMsgHeader = "Please double check\nthe following field(s):\n-------------------------\n";
  
  var btn=document.getElementById("submitID");
  if(validUpdate == ""){
    btn.disabled=true;
	showLoading("show");
    return true;
  }else{
    btn.disabled=false;
	showLoading("hide");
    alert(errorMsgHeader + validUpdate);
    return false;	
  }
}
function cookieEnabled() {    
cookieEnabled=(navigator.cookieEnabled)? true : false;    
	if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
	document.cookie="testcookie"
	cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false
} 
 if (cookieEnabled) return "YES"; 
 return "NO"
  }
  
 function isJavaEnabled() { 
  return (navigator.javaEnabled() ? "YES" : "NO"); 
 }  
 function flshEnabled() { 
   var MSDetect = "false"; 
   var k = new Array ("UNKNOWN","NO","YES");
   if (navigator.plugins && navigator.plugins.length)
   {
          x = navigator.plugins["Shockwave Flash"];
          if (x)
          {
              flashinstalled = 2;
              if (x.description)
              {
               y = x.description;
               flashversion = y.charAt(y.indexOf('.')-1);
              }
        }
       else{
              flashinstalled = 1;
        }
       if (navigator.plugins["Shockwave Flash 2.0"])
       {
              flashinstalled = 2;
              flashversion = 2;
       }
   }
   else if (navigator.mimeTypes && navigator.mimeTypes.length)
   {
          x = navigator.mimeTypes['application/x-shockwave-flash'];
          if (x && x.enabledPlugin)  flashinstalled = 2;
          else  flashinstalled = 1;
   }
   else{         
         MSDetect = "true";   
}    
   if (MSDetect == "true") {    
             var verIE = flahsInstalledIE();    
             if (verIE == 0) flashinstalled = 1;    
    else{     
            flashinstalled=2;     
            flashversion = verIE
           }
   }    
   var outStr = k[flashinstalled];   
   if (flashinstalled==2) outStr = k[flashinstalled] + "&nbsp; &nbsp; [Version: " + flashversion + "]";
   return outStr;
 } 
function flahsInstalledIE() { 
  for (var i=10; i>0; i--) {
            flashVersion = 0;
            try{
                var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
                return i;
               }
            catch(e){}
       }      
  return 0;
}  
function appName() { 
         if (navigator.appName.toLowerCase()=="netscape"){   
         var ver1 = navigator.appVersion;
         if (ver1.toLowerCase().indexOf("safari")>-1) return "Safari";   
         if (ver1.toLowerCase().indexOf("firefox")>-1) return "FireFox";
         }  
  else{ return navigator.appName; }
 } 
function appVersion(){
        return navigator.appVersion;
} 

  //alert("First Name: " + jsFirstName + "\n" + "Last Name: " + jsLastName + "\n" + "emaile: " + jsEmail + "\n" + "comments: " + jsAdditionalComments + "\n" + "Product Name: " + jsProductName + "\n" + "Product Size: " + jsProductSize + "\n");