/*
 * Never Use $get( anyid ) function in this file, as this file is shared by homepage and AJAX is not loaded on Home Page for optimization purposes
 * Instead use document.getElementById() function. 
 */ 
function CreateTransparentControl(DivID, CLSID, ObjectID, WIDTH, HEIGHT, URL, FLASHVARS, AUTOSTART)
{
  var d = document.getElementById(DivID);
  var objectTag = '<object classid=' + CLSID + ' id=' + ObjectID + ' width=' + WIDTH + ' height=' + HEIGHT +' codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
  objectTag = objectTag + '<param name="allowScriptAccess" value="sameDomain">';
  objectTag = objectTag + '<param name="movie" value=' + URL + '>'
  objectTag = objectTag + '<param name="FlashVars" value=' + FLASHVARS + '>';
  objectTag = objectTag + '<param name="quality" value="high">'  
  objectTag = objectTag + '<param name="autoStart" value=' + AUTOSTART + '/>';
  
  objectTag = objectTag + '<param name="wmode" value="transparent" />'
				
  objectTag = objectTag + '<embed wmode="transparent" src="' + URL + '" flashVars="' + FLASHVARS + '" quality="high" bgcolor="#000000" width="' + WIDTH + '" height="' + HEIGHT +'" name="main" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
  objectTag = objectTag + "</object>";
  d.innerHTML = objectTag;
}
function SetLogin(loginname)
{
    var mf = GetMainFormName();
    if (mf==null) return;
    var login = GetElementName("hidden_login",mf)
    if (login!= null)
        document.forms[mf].elements[login].value = loginname;
}

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 MM_showHideMenuLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideMenuLayers.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 isEnter(e)
{
    if (e.keyCode == 13)
    {		
	    gosearch();
    }	
    return true;
}

function gosearch()
{	
    var mf = GetMainFormName();		
    if (mf==null) return;
	
    var searchWord = document.getElementById("SearchKeywords").value;
    searchWord = searchWord.toLowerCase();
    if (searchWord != 'search')
    {
        document.forms[mf].action="/_us/_en/search/index.aspx?SearchKeywords=" + searchWord;
        document.forms[mf].submit();
    }
}

function DoAlternate(imgObj,objToShowHideStr,status){
    var objToShowHide = document.getElementById(objToShowHideStr);
    if ( typeof(status) != 'undefined' ){
        if ( status == 'show' ){
            imgObj.src = '/img/ICN_Mns.gif';
            objToShowHide.style.display = 'block';
        } else if ( status == 'hide' ){
            imgObj.src = '/img/ICN_Pls.gif';
            objToShowHide.style.display = 'none';
        }
    }
    else {    
        if ( imgObj.src.indexOf('/img/ICN_Pls.gif') != -1 )
            imgObj.src = '/img/ICN_Mns.gif';
        else
            imgObj.src = '/img/ICN_Pls.gif';
        
        if ( objToShowHide.style.display == 'block' )
            objToShowHide.style.display = 'none';
        else
            objToShowHide.style.display = 'block';
    }        
}

 function AdjustHeights(){
    var leftCont = document.getElementById('LeftNavContainer'); 
    var rightCont = document.getElementById('RightContainer');
    var maxHeight = 0;
    if (  leftCont != null && rightCont != null ) {
        if(leftCont.offsetHeight){
           maxHeight = Math.max(leftCont.offsetHeight,rightCont.offsetHeight); 					
        } else if(leftCont.style.pixelHeight){ 
          maxHeight = Math.max(leftCont.style.pixelHeight,rightCont.style.pixelHeight);				 
        } 
        leftCont.style.height=maxHeight + "px";
        rightCont.style.height=maxHeight + "px";
    }
}
function ResetHeights(){
    var leftCont = document.getElementById('LeftNavContainer'); 
    var rightCont = document.getElementById('RightContainer');
    var maxHeight = 0;
    if (  leftCont != null && rightCont != null ) {
         leftCont.style.height='';
         rightCont.style.height='';
    }
}
/*
 * This Update was provided by magic zoom team as a fix to the flickering problem of the Top Menu in IE
 * Please do no change any thing below this code, it is very important JS update/hack 
 **/

if(window.attachEvent /* only for IE */) {
    window['MM_showHideMenuLayers'] = function() {
        args = MM_showHideMenuLayers.arguments;
        for (i=0; i<(args.length-2); i+=3) {
            with (document) {
                if (getElementById && getElementById(args[i])) {
                    MM_showHideMenuLayers_callback(args[i], args[i+1], args[i+2]);
                }
            }
        }
    }
    
    function MM_showHideMenuLayers_callback(id, unknow_argument, mode, second) {
        second = second || false;
        el = document.getElementById(id);
        over = mode == 'show' ? true : false;
        if(!second && !over) {
            setTimeout(function(){MM_showHideMenuLayers_callback(id, unknow_argument, 'hide', true);}, 100);
            el.setAttribute('sameAttribute', 1);
            return;
        } else if(!over && el.getAttribute('sameAttribute') == 0) {
            return;
        }
        el.setAttribute('sameAttribute', 0);
        if(el.style) {
            el.style.visibility = (mode=='show')?'visible':(mode=='hide')?'hidden':mode;
            if (AJAX_IsIE6()) {
                // the logic is oposite for hiding the dropdown for IE6
                var val = (mode=='show')?'hidden':'visible'; 
                ToggleDropDowns( val ); 
                //alert(val);              
            }
        }
       
    }
    
    window['MM_swapImage'] = function() {
        args = MM_swapImage.arguments;
        var j=0;
        document.MM_sr = new Array;
        for (var i=0; i<(args.length-2); i+=3) {
            if (MM_findObj(args[i])) {                
                MM_swapImage_callback(args[i], args[i+1], args[i+2]);
                document.MM_sr.push(MM_findObj(args[i]));
            }
        }
    }
    
    function MM_swapImage_callback(id, unknow_argument, img/*,second*/) {
        el = MM_findObj(id);
        el.setAttribute('sameAttributeSwap', 0);
        if(!el.oSrc) {
           // alert('First Time :: oSrc : ' + el.oSrc);alert('Src : '+ el.oSrc);
            el.oSrc=el.src;
            el.src=img;
        }
        else{
          // TM : Added the else statement to solve the image swap issue
          // el.oSrc=el.src;
           el.src=img; 
        }
    }
    
    window['MM_swapImgRestore'] = function() {
        var i, x, a=document.MM_sr;
        for(i=0; a&&i<a.length&&(x=a[i])&&x.oSrc; i++) {
            MM_swapImgRestore_callback(x);
        }
    }
    
    function MM_swapImgRestore_callback(el, second) {
        second = second || false;
        if(!second) {
            setTimeout(function(){MM_swapImgRestore_callback(el, true);}, 100);
            el.setAttribute('sameAttributeSwap', 1);
            return;
        } else if(el.getAttribute('sameAttributeSwap') == 0) {
            return;
        }
        el.setAttribute('sameAttributeSwap', 0);
        el.src = el.oSrc;
    }
}

function AJAX_IsIE6() {
  if (navigator.appName=='Microsoft Internet Explorer') {
       
      if (navigator.appVersion.indexOf('MSIE 6.0')!=-1) {        
         return true;
      }
  }
  return false;

}
function ToggleDropDowns(state) {
    //alert(state);
    var mf = GetMainFormName();
    var variantDD = document.getElementById('varlist')
    if ( variantDD != null )
        variantDD.style.visibility = state;
    
     var quantityDDID =  GetElementID("QtyList",mf);
     var objquantityDD=document.getElementById(quantityDDID);
     if (objquantityDD!=null) {
           objquantityDD.style.visibility = state;
     }

 }

 function CheckZipCode(zipCtrl, errorMsgCtrl, tblCell) {
     var mf = GetMainFormName();

     var zipname = zipCtrl + "$" + "address_zip";

     var zipCode = GetElementByName(zipname, mf);

     var divZipError = document.getElementById(errorMsgCtrl);

     var tblcellZip = document.getElementById(tblCell);

     /*Check if the object exists before manipulating the values */
     if (divZipError != null) {
         divZipError.style.display = "none";
     
         //If zip code is not entered, then let the webbox validation methods capture that error. 
         //This will enable the validation to work when "ship to billing" address checkbox is checked.
         if (zipCode != null && zipCode.value.length == 0) {     
             return true;
         }
         else {
             var allValid = true;

             var objRegExp = /(^\d{5}$)|(^\d{5}-\d{4}$)/

             if (objRegExp.exec(zipCode.value) == null) allValid = false;

             if (!allValid) {
                 if (tblcellZip != null) tblcellZip.style.color = "#FF0000";
                 divZipError.style.display = "block";
                 window.scrollTo(500, 200);
                 return false;
             }
             else {
                 return true;
             }
         }
     }
     else {
         return false;
     }
 }