
/*//This sets and gets cookies and will be on every page ///*/ 
function createCookie(name,value,days) {
    if (days) {
	    var date = new Date();
	    date.setTime(date.getTime()+(days*24*60*60*1000));
	    var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}

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;
}

// "Internal" function to return the decoded value of a cookie
//
function _getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
/*// This sets the cookie for the menu state//*/
        function menuState(){
            //This is to maintain the state in which it was open by setting a cookie
            //if(GetCookie ('menuState') != null)window.accordion_jso.runAccordion(GetCookie ('menuState'), true);
            if(GetCookie ('menuState') == null)return;
            if(GetCookie ('menuState') == 1)document.getElementById('Menu' + GetCookie ('menuState') + 'Content').style.height = '220px';
            if(GetCookie ('menuState') == 2)document.getElementById('Menu' + GetCookie ('menuState') + 'Content').style.height = '200px';
            if(GetCookie ('menuState') == 3)document.getElementById('Menu' + GetCookie ('menuState') + 'Content').style.height = '110px';
            if(GetCookie ('menuState') == 4)document.getElementById('Menu' + GetCookie ('menuState') + 'Content').style.height = '90px';
            if(GetCookie ('menuState') == 5)document.getElementById('Menu' + GetCookie ('menuState') + 'Content').style.height = '70px';
			if(GetCookie ('menuState') == 6)document.getElementById('Menu' + GetCookie ('menuState') + 'Content').style.height = '50px';
            if(GetCookie ('menuState') == 7)document.getElementById('Menu' + GetCookie ('menuState') + 'Content').style.height = '140px';
            document.getElementById('Menu' + GetCookie ('menuState') + 'Content').style.display = 'block';
            window.accordion_jso.lastClicked = document.getElementById("menu"+GetCookie ('menuState'));
            window.accordion_jso.openAccordion = 'Menu' + GetCookie ('menuState') + 'Content';
            window.accordion_jso.setImage(document.getElementById("menu"+GetCookie ('menuState')));
            
        }
        
/*This is to make the main menu animate open/*/
window.accordion_jso = {
    //ContentHeight: 200,
    TimeToSlide: 250.0,
    openAccordion: '',
    lastClicked: null,

    runAccordion: function(index, animate)
    
    {
			//if you change the height value change it in the menuState Function above as well
			if(index == 1)window.accordion_jso.ContentHeight=220;
			if(index == 2)window.accordion_jso.ContentHeight=200;
			if(index == 3)window.accordion_jso.ContentHeight=110;
			if(index == 4)window.accordion_jso.ContentHeight=90;
			if(index == 5)window.accordion_jso.ContentHeight=70;
			if(index == 6)window.accordion_jso.ContentHeight=50;
			if(index == 7)window.accordion_jso.ContentHeight=140;
         
			var nID = "Menu" + index + "Content";
         
			if(animate == false)window.accordion_jso.TimeToSlide=35.0;
			
			
         
          if(window.accordion_jso.openAccordion == nID)
            nID = '';
           
          setTimeout("window.accordion_jso.animate("
              + new Date().getTime() + "," + window.accordion_jso.TimeToSlide + ",'"
              + window.accordion_jso.openAccordion + "','" + nID + "')", 22);
         
          window.accordion_jso.openAccordion = nID;
          
          var d = document.getElementById("menu"+index);
          if(window.accordion_jso.lastClicked != null && d != window.accordion_jso.lastClicked) 
                window.accordion_jso.setImage(window.accordion_jso.lastClicked, 1);
         
          window.accordion_jso.setImage(d);
          window.accordion_jso.lastClicked = d;
		 
		 createCookie('menuState',index,0) ;

		window.accordion_jso.TimeToSlide=250.0;
        },

        animate: function(lastTick, timeLeft, closingId, openingId)
        { 
          var curTick = new Date().getTime();
          var elapsedTicks = curTick - lastTick;
         
          var opening = (openingId == '') ?
              null : document.getElementById(openingId);
          var closing = (closingId == '') ?
              null : document.getElementById(closingId);
         
          if(timeLeft <= elapsedTicks)
          {
            if(opening != null)
              opening.style.height = window.accordion_jso.ContentHeight + 'px';
           
            if(closing != null)
            {
              closing.style.display = 'none';
              closing.style.height = '0px';
            }
            return;
          }
         
          timeLeft -= elapsedTicks;
          var newClosedHeight =
              Math.round((timeLeft/window.accordion_jso.TimeToSlide) * window.accordion_jso.ContentHeight);

          if(opening != null)
          {
            if(opening.style.display != 'block')
              opening.style.display = 'block';
            opening.style.height =
                (window.accordion_jso.ContentHeight - newClosedHeight) + 'px';
          }
         
          if(closing != null)
            closing.style.height = newClosedHeight + 'px';

          setTimeout("window.accordion_jso.animate(" + curTick + "," + timeLeft + ",'"
              + closingId + "','" + openingId + "')", 22);
        },
        
        setImage: function (o, force){
         if(o.getAttribute("Xstate") == "opened" || force == 1){

                o.src=o.src.replace(/_open\.gif/,'_closed.gif');
                o.setAttribute("Xstate","closed");
               }
          else{
               o.src=o.src.replace(/_closed\.gif/,'_open.gif');
               o.setAttribute("Xstate","opened");
              }
         }


}
/*//this switches to the subsub menu for the third tier/*/
function switchMenu(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != "block" ) {
		el.style.display = 'block';
	}
	else {
		el.style.display = '';
	}
	}

/*This is for the pop up divs//*/
	
	window.productDetails_jso={
	    showPopup: function(o, e, s){
	        var d=document.getElementById(s);
	        d.style.visibility='visible';
	    },
	    
	    hidePopup: function(o, e, s){
	        var d=document.getElementById(s);
	        d.style.visibility='hidden';
	    },
	    
	    'end':'end'
	};

function clear_searchBox(who)
	{
		if(who=='cs'){
			if (document.searchForm.SearchFor.value == "Product Search"){
				document.searchForm.SearchFor.value = "";
			}
		}else{
			if(document.ErrorSearchForm.ErrorSearchFor.value == "Product Search"){
				document.ErrorSearchForm.ErrorSearchFor.value = "";
			}
		}
	}  
//This is to validate the users Email Address GET UPDATES in the preferences page

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.emailForm.EMAIL
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email Address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

/* This is for the pop new windows/*/
function nogo() { ; }

function openWindow( url )
{
//var w = window.open (url, "win", "height=200,width=500,location,menubar,resizable,scrollbars,status,toolbar");
var w = window.open (url, "win", "height=100,width=575");
}

function OpenWindowSRC(url, name, width, height, scroll) {
			popupWin = window.open(url, name, 'status=no,menubar=no,toolbar=no,scrollbars=' + scroll +',resizable=no,width=' + width +',height=' + height + ',screenX=0,screenY=0,top=0,left=0')
}
function OpenWindowHoliday(url, name, width, height, scroll) {
		popupWin = window.open(url, name, 'status=no,menubar=no,toolbar=no,scrollbars=' + scroll +',resizable=no,width=' + width +',height=' + height + ',screenX=0,screenY=0,top=0,left=0')
	}

/*This is for switching Class Names//*/
function changeClass(idElement,myClass){
    document.getElementById(idElement).setAttribute('className', myClass);
    document.getElementById(idElement).setAttribute('class', myClass);
}