var specialcase = ((navigator.userAgent.indexOf('Mac') != -1) || document.all)
var flag = 0;

var x,y,x1,y1,copyAttempt;
		var imgOn = new Array()
                for (var i=0; i < 10; i++) 
                {
		 imgOn[i] = new Image();
		 imgOn[i].src = "Images/en_home_nav_blank_on.gif";
                }

	
		var imgOff = new Array()
                for (var i=0; i < 10; i++) 
                {
		 imgOff[i] = new Image();
		 imgOff[i].src = "Images/en_home_nav_blank.gif";
                }

		var t;
		
		function clearMenuTimeout() {
			if (t){
				window.clearTimeout(t);
			}
		}
	
		function toggleMenu (id,cnt) {
			clearMenus(false,cnt);
			if (document.layers) {
				document.layers[id].visibility = "show";
			} else if (document.getElementById) {
				document.getElementById(id).style.visibility = "visible";
			} else if (document.all) {
				document.all[id].style.visibility = "visible";
			}
		}
	
		function clearMenus (wait,cnt) {
			if (wait) {
				clearMenuTimeout();
                                var wStr = "clearMenus(false," + cnt.toString() + ")";
				t = window.setTimeout(wStr, 1200);
				return true;
			}
			clearMenuTimeout();
			for (var i=0; i < cnt; i++) {
				if (document.layers) {
					document.layers["Product" + i].visibility = "hide";
				} else if (document.getElementById) {
					document.getElementById("Product" + i).style.visibility = "hidden";
				} else if (document.all) {
					document.all["Product" + i].style.visibility = "hidden";
				}
			}
		}
		function goProducts() {
			document.location.href = document.frmProdDrop.ProdDrop.options[document.frmProdDrop.ProdDrop.selectedIndex].value;
		}
//Blink tab
window.onerror = null;
 var bName = navigator.appName;
 var bVer = parseInt(navigator.appVersion);
 var NS4 = (bName == "Netscape" && bVer >= 4);
 var IE4 = (bName == "Microsoft Internet Explorer" 
 && bVer >= 4);
 var NS3 = (bName == "Netscape" && bVer < 4);
 var IE3 = (bName == "Microsoft Internet Explorer" 
 && bVer < 4);
 var blink_speed=100;
 var i=0;
 
if (NS4 || IE4) {
 if (navigator.appName == "Netscape") {
 layerStyleRef="layer.";
 layerRef="document.layers";
 styleSwitch="";
 }else{
 layerStyleRef="layer.style.";
 layerRef="document.all";
 styleSwitch=".style";
 }
}
function openJPN_Page()
{
  var popup = window.open(document.forms['sysvar'].jpnurl.value);
}

function PollOpen(id)
  {    
    var popup = window.open('en/pollsEN.asp?PollName='+id,'popup',config='height=400,width =400,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no');
  }

function replaceChar(field,str1,str2) {
out = str1; // replace this
add = str2; // with this
temp = "" + field; // temporary holder

while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add + 
temp.substring((pos + out.length), temp.length));
}
 return temp;
}

function getCounty(stateid)
{
 var  id = stateid

 document.forms['frmStates'].STATE.value = id.toUpperCase(); 
 document.forms['frmStates'].submit();
}

function getCounty1(stateid)
{
 var  id = stateid

 document.forms['frmStates1'].STATE.value = id.toUpperCase(); 
 document.forms['frmStates1'].submit();
}

function updateEmail(theform)
{
theform.elements['dist_sentto'].value = document.forms['sysvar'].distributors_sentto.value;		
}

function validateAmount(theform,thefield)
{
 if (thefield.value != "")
 {  
  if(isNaN(thefield.value) || (thefield.value <= 0))
  {
   thefield.value = "";
   alert ("Please enter a valid number.");
  }
 }
 caculateTotal1(theform);
}


function caculateTotal(theform)
{

 theform.elements['Order_SentTo'].value = 			document.forms['sysvar'].orders_sentto.value;

 if(isNaN(theform.elements['Quantity_Ordered'].value) || 	      	(theform.elements['Quantity_Ordered'].value <= 0))
 {
   theform.elements['Quantity_Ordered'].value = "";
   alert ("Please enter a valid number for Quantity Ordered.");
   return false;
 }

 if(isNaN(theform.elements['Ext_Cost'].value) || 	      	(theform.elements['Ext_Cost'].value <= 0))
 {
  theform.elements['Ext_Cost'].value = "";
   alert ("Please enter a valid number for Ext. Cost.");
   return false;
 }

 var fld1, fld2, fld3, fld4;

 for (var i=2;i<6;i++)
 { 
   fld1 = eval("theform.elements['Product_Cd"+ i +"']");
   fld2 = eval("theform.elements['Qty_Ordered"+ i +"']");
   fld4 = eval("theform.elements['EC"+ i +"']");

   if ((fld1.value != "") || (fld2.value != "") || (fld4.value != ""))
   {

     if (fld1.value == "") 
     {
        alert ("Please enter a Product Code for line item " + i  + ".");
        return false;
     }

     if (fld2.value == "") 
     {
        alert ("Please enter Quantity Ordered for line item " + i  + ".");
        return false;
     }
     else
     {
	if (isNaN(fld2.value) ||(fld2.value <= 0))
        {
          fld2.value = "";
          alert ("Please enter a valid number for Quantity Ordered for line item 			" + i  + ".");
          return false;
         } 
      }


     if (fld4.value == "") 
     {
        alert ("Please enter Ext. Cost for line item " + i  + ".");
        return false;
     }
     else
     {
	if (isNaN(fld4.value) ||(fld4.value <= 0))
        {
          fld4.value = "";
          alert ("Please enter a valid number for Ext. Cost for line item " + i  			+ ".");
          return false;
         } 
      }

   }
 }

 caculateTotal1(theform);
 return true;
}

function caculateTotal1(theform)
{
 var total = 0;
 var pototal = 0;
 var field;

  field = theform.elements['Quantity_Ordered'];
  if(isNaN(field.value) ||(field.value <= 0))
  {
     field.value = "";
  }
  else total = total + parseFloat(field.value);

  field = theform.elements['Ext_Cost'];
  if(isNaN(field.value) ||(field.value <= 0))
  {
     field.value = "";
  }
  else pototal = pototal + parseFloat(field.value);

 // other line items
 for (var i=2;i<6;i++)
 {
   field = eval("theform.elements['Qty_Ordered"+ i +"']");
   if(isNaN(field.value) ||(field.value <= 0))
   {
     field.value = "";
   }
   else total = total + parseFloat(field.value);

   field = eval("theform.elements['EC"+ i +"']");
   if(isNaN(field.value) ||(field.value <= 0))
   {
     field.value = "";
   }
   else pototal = pototal + parseFloat(field.value);

 }

 if (total.toString().indexOf(".") > -1)
 {
  theform.elements['Total_Qty_Ordered'].value 	=  	total.toString().substring(0,total.toString().indexOf(".")+3);

 }
 else theform.elements['Total_Qty_Ordered'].value = total;

 if (pototal.toString().indexOf(".") > -1)
 {
   theform.elements['Total_PO_Cost'].value 	=  	   (pototal.toString()+"0").substring(0,pototal.toString().indexOf(".")+3);

 }
 else theform.elements['Total_PO_Cost'].value = pototal + ".00";

}

//Setting cookies
function getCookieVal (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 getCookieVal (j); 
i = document.cookie.indexOf(" ", i) + 1; 
if (i == 0) break; } 
return null; } 

function SetCookie (name, value) { 
var argv = SetCookie.arguments; 
var argc = SetCookie.arguments.length; 
var expires = (argc > 2) ? argv[2] : null; 
var path = (argc > 3) ? argv[3] : null; 
var domain = (argc > 4) ? argv[4] : null; 
var secure = (argc > 5) ? argv[5] : false; 
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) + 
((domain == null) ? "" : ("; domain=" + domain)) + 
((secure == true) ? "; secure" : ""); } 

//BLINKING
function Blink(layerName,menuName){

 if (NS4 || IE4) { 
  if(i%2==0)
  {
   eval(layerRef+'["'+layerName+'"]'+
   styleSwitch+'.visibility="visible"');
   }
 else
 {
  eval(layerRef+'["'+layerName+'"]'+
  styleSwitch+'.visibility="hidden"');
 }
 } 
 if(i<1)
 {
  i++;
  } 
  else
  {
   i--
  }

 setTimeout("Blink('"+layerName+"','" + menuName + "')",blink_speed);
 
}

//set cookie
function writeCookie(layerName,menuName){

 var expdate = new Date (); 
 expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 31 * 9)); 

 if (layerName.indexOf("lnk") > -1)
 {
   SetCookie('lnkName',"'"+menuName+"'", expdate); 
 }
 else SetCookie('tabName',"'"+menuName+"'", expdate); 
}
//
function download_click() {

 var msg = window.document.forms['sysvar'].imgmsg.value;

 if ((window.event.srcElement.background != undefined) ||  
    (window.event.srcElement.type == 'image'))
 {
  if (window.event.button == 2) 
  {
   alert(msg);
   return false;
  }
 }
 return true;
}

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function validateField(theform, thefield, thefieldname)
{

   if (thefield.type == "text")
      {
        if (thefield.type == "textarea") alert(thefield.value);

        txtval = thefield.value;
        while (''+txtval.charAt(0)==' ')
        { 
         txtval = txtval.substring(1,txtval.length);
        }
        if (txtval == "")
        {
          alert("Enter a value for " + thefieldname); 
          return false;
        }
   
        if ((thefieldname.indexOf("E-Mail") > -1) || (thefieldname.indexOf("email") > -1))
        { 
          if (isEmail(thefield.value) == false)
          {
            alert("Please enter a proper email address.");
            return false;
          }
        }
      }
   else if (thefield.type == "select-one")
      {
        if ((thefield.selectedIndex < 0) || (thefield.value == ""))
        {
         alert("Please select " + thefieldname);  
         return false; 
        }
      }
   else if (thefield.type == "checkbox")
      {
       var chkfield, chk, oth;
       chkfield = eval("theform.elements['"+thefield.name+"']");
       chk = "";
       oth = "";

       for (var j=0;j<chkfield.length;j++)
       {
        if (chkfield[j].checked == true)
        {
          chk = "1";
          if (chkfield[j].value == "Other")
          {
            oth = "1";
            break;
          }
        }
       }
       
       if (chk == "")
       {
         alert("Please select " + thefieldname);  
         return false; 
       }
       
       // check if other option has been selected
     
       if (oth == "1")
       {
        txtval = theform.explain_other.value;
        while (''+txtval.charAt(0)==' ')
        { 
         txtval = txtval.substring(1,txtval.length);
        }
        if (txtval == "")
        {
          alert("You chose 'Other'. Please explain."); 
          return false;
        }
       }
       else theform.explain_other.value = "";
       
     } 
     else if (thefield.type == "textarea")
     {
      txtval = thefield.value;
        while (''+txtval.charAt(0)==' ')
        { 
         txtval = txtval.substring(1,txtval.length);
        }
        if (txtval == "")
        {
          alert("Enter a value for " + thefieldname); 
          return false;
        }
     }

}

function validateForm(theform, notreqstr) 
{

    var field, fieldname, txtval;

    for (var i=0;i<theform.elements.length;i++)
    {
      field=theform.elements[i];

      if (notreqstr.indexOf(field.name) < 0)
      {
       fieldname = replaceChar(field.name,"_"," ");

       if (validateField(theform,field,fieldname) == false) return false;       
      }
    }
    return true;
}

function loadValues(theform, thefield) 
{
 
  if (thefield.checked == true)
    {
      theform.elements['Shipping_Account_No'].value = 		theform.elements['Billing_Account_No'].value;

      theform.elements['Shipping_Company_Name'].value = 				theform.elements['Billing_Company_Name'].value;

      theform.elements['Shipping_Address'].value = 		theform.elements['Billing_Address'].value;

      theform.elements['Shipping_City'].value = 		theform.elements['Billing_City'].value;

      theform.elements['Shipping_State'].selectedIndex = 		theform.elements['Billing_State'].selectedIndex;

      theform.elements['Shipping_Zip'].value = 		theform.elements['Billing_Zip'].value;

      theform.elements['Shipping_Country'].value = 		theform.elements['Billing_Country'].value;

    }
 
}

function init()
{

	if (!(document.getElementById || document.all || document.layers)) return;
	if (specialcase && document.layers)
	{
 	        document.captureEvents(Event.MOUSEMOVE || Event.MOUSEDOWN);
		document.onmousemove = special;
	}
	for (i=0;i<document.images.length;i++)
	{

         if (document.images[i].src.indexOf("img/USAMap.gif") < 0)
         {
		document.images[i].onmousedown = checkIt;
		document.images[i].onmouseup = function() {return false};
		if (specialcase)
		{
			document.images[i].onmousemove = special;
			document.images[i].onclick = clearIt;
		}
         }
	}
}

function checkIt(e)
{
  var msg = window.document.forms['sysvar'].imgmsg.value;

	copyAttempt = 0;
	if (window.Event)
	{
		x = e.screenX;
		y = e.screenY;
		theButt = (e.which == 3);
	}
	else
	{
		x = window.event.clientX;
		y = window.event.clientY;
		theButt = (window.event.button == 2);
	}
	if (theButt)
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false; // NN4 only
	}
	if (specialcase) flag = 1;
	return false;
}

function special(e)
{
   var msg = window.document.forms["sysvar"].imgmsg.value;

	theObj = '';
	if (window.Event)
	{
		x1 = e.screenX;
		y1 = e.screenY;
		if (e.target.parentNode) theObj = e.target.parentNode.tagName;
	}
	else
	{
		x1 = window.event.clientX;
		y1 = window.event.clientY;
		theObj = window.event.srcElement.parentElement.tagName;
	}
        
	var isLink = (theObj == 'A');
	if (flag && (!isLink || ((Math.abs(x-x1) > 10) || (Math.abs(y-y1) > 10))))
	{
		copyAttempt = 1;
		flag = 0;
		alert(msg);
		return false;
	}
}

function clearIt()
{
	flag = 0;
	if (copyAttempt)
	{
		copyAttempt = 0;
		return false;
	}
}