// MENU IE HACK
sfHover = function() {
	var sfEls = document.getElementById("best_sellers").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/* thank you dan popa for this: http://www.mister-pixel.com/ */
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

show_hide_forgot_pass=function(aRef,action){
  divRef=document.getElementById('forgot_password');
  if(action=='close'){
    Effect.BlindUp(divRef,{duration:1});
    aRef.onclick=function(){show_hide_forgot_pass(this,'open');};
  }
  if(action=='open'){
    Effect.BlindDown(divRef,{duration:1});
    aRef.onclick=function(){show_hide_forgot_pass(this,'close');};
  }
}


billingSameShipping=function(checkboxRef){

    var formRef=document.getElementById('formStep3');

    if(checkboxRef.checked){
      formRef.b_address1.value=formRef.s_address1.value;
      formRef.b_address2.value=formRef.s_address2.value;
      formRef.b_city.value=formRef.s_city.value;
      formRef.b_state.value=formRef.s_state.value;
      formRef.b_postal_code.value=formRef.s_postal_code.value;
      formRef.b_county.value=formRef.s_county.value;
    }
}


function show_div(divIdShow,divIdHide){
    document.getElementById(divIdShow).style.display='block';
    document.getElementById(divIdHide).style.display='none';
    
}


function popup(content, width, height){
    popup=window.open("", "newwin", "width="+width+", height="+height+", toolbar=no,menubar=yes, scrollbars=yes");
    popup.document.write("<title>Your Invoice<\/title>");
    popup.document.write('<link type="text/css" rel="stylesheet" href="content.css" />');
    popup.document.write('<body style="margin:10px;padding:0px;font:11px Arial,Helvetica, sans-serif;">');
    popup.document.write(content);
    popup.document.write("<\/body>");
    popup.document.write("<\/html>");
}


function recalculate_charge(selectRef, shippingCharge, vatCharge,prodCharge){
    var surcharge=selectRef.value;
    
    /*alert(shippingCharge);
    alert(vatCharge);
    alert(prodCharge);*/
    
    //add surcharge to shippingCharge and totalCharge: +10   
    if(surcharge.split('+')[1]!=undefined){
        var newShippingCharge=parseFloat(shippingCharge)+parseFloat(surcharge.split('+')[1]);        
        document.getElementById('delivery_speed_harrow_middlesex').style.display='none';
    }
    //shippingCharge is the surchage: 5
    else{
        var newShippingCharge=parseFloat(surcharge);       
        document.getElementById('delivery_speed_harrow_middlesex').style.display='block';
    }
    
    //alert(newShippingCharge);
    
    var newVAT=(newShippingCharge+parseFloat(prodCharge))*(parseFloat(vatCharge)-1); 
    var newProdCharge=parseFloat(prodCharge)+newShippingCharge;
    var newTotalCharge=(parseFloat(prodCharge)+newShippingCharge)*vatCharge;
    
    newShippingCharge=Math.round(newShippingCharge*100)/100;    
    newVAT=Math.round(newVAT*100)/100;  
    newTotalCharge=Math.round(newTotalCharge*100)/100;  
    newProdCharge=Math.round(newProdCharge*100)/100; 
    
    document.getElementById('shipping_charge').firstChild.nodeValue='£'+newShippingCharge;
    document.getElementById('subtotal').firstChild.nodeValue='£'+newProdCharge;
    document.getElementById('vat').firstChild.nodeValue='£'+newVAT;
    document.getElementById('total_charge').firstChild.nodeValue='£'+newTotalCharge;
}

