function popupPrintReceipt(url) {
  window.open(url,'popupPrintReceipt','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=750')
}


var req; 
function loadXMLDoc(key) {
   var url="state_dropdown.php?CLCid=<?php echo tep_session_id();?>&country="+key;
   getObject("states").innerHTML = '&nbsp;<img style="vertical-align:middle" src="images/loading.gif">Please wait...';
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); } 
   catch(e) { 
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); } 
      catch(oc) { req = null; } 
   } 
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); } 
   if (req != null) {
      req.onreadystatechange = processChange; 
      req.open("GET", url, true); 
      req.send(null); 
   } 
} 
function processChange() { 
   if (req.readyState == 4 && req.status == 200) { 
      getObject("states").innerHTML = req.responseText;
      document.create_account.state.focus();
   } 
} 
function getObject(name) { 
   var ns4 = (document.layers) ? true : false; 
   var w3c = (document.getElementById) ? true : false; 
   var ie4 = (document.all) ? true : false; 

   if (ns4) return eval('document.' + name); 
   if (w3c) return document.getElementById(name); 
   if (ie4) return eval('document.all.' + name); 
   return false; 
}


function apop(){
   window.open ('https://www.pricegrabber.com/rating_merchrevpop.php?retid=3262', 'codes', config='height=480, width=166, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
}



function ups(){
   window.open ('https://www.speedwaysales.com/ups_time.html', 'UPS', config='height=600, width=600, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
}





function raiseTab(n)
  {
  // cycle through the three tabs/panels
  for(i=0;i<3;i++)
    {
    // create variables to represent the page elements being examined
    var curPanel = window.document.getElementById("panel"+i);
    var curTab = window.document.getElementById("tab"+i);
    if(i==n) 
      {
      // if the current panel/tab being examined is the one clicked on
      // raise it to the top
      curPanel.style.zIndex = 2;
      curTab.style.zIndex = 2;
      }
    else
      {
      // otherwise, stick it at the bottom
      curPanel.style.zIndex = 0;
      curTab.style.zIndex = 0;
      }
    }
  }


var ShipName = "";
var ShipAddress = "";
var ShipCity = "";
var ShipState = "";
var ShipZip = "";
var ShipCountry = "";

function InitSaveVariables(form) {
ShipName = form.sname.value;
ShipAddress = form.saddress.value;
ShipCity = form.scity.value;
ShipZip = form.szipcode.value;
ShipState = form.sstate.value;
//ShipCountry = form.scountry.value;
ShipCountryIndex = form.scountry.selectedIndex;
ShipCountry = form.scountry[ShipCountryIndex].value;

}

function ShipToBillPerson(form) {
if (form.copy.checked) {
InitSaveVariables(form);
form.sname.value = form.bname.value;
form.saddress.value = form.baddress.value;
form.scity.value = form.bcity.value;
form.szipcode.value = form.bzipcode.value;
form.sstate.value = form.bstate.value;
//form.scountry.value = form.bcountry.value;
form.scountry.selectedIndex = form.bcountry.selectedIndex;

}
else {

form.sname.value = ShipName;
form.saddress.value = ShipAddress;
form.scity.value = ShipCity;
form.szipcode.value = ShipZip;       
form.sstate.value = ShipState;
form.scountry.selectedIndex = ShipCountry;
   }
}


function startCalc(){
  interval = setInterval("calc()",1);
}
function calc(){
  one = document.form.itemprice.value;
  two = document.form.shippingcharge.value;
  three = document.form.quantity.value;
  if (document.form.sstate.value == 'WI' || document.form.sstate.value == 'Wisconsin' || document.form.sstate.value == 'wi' || document.form.sstate.value == 'wisconsin') {
  
  four = 1.056 * ((two * three) + (one * three));
  }
  else {
   four = (two * three) + (one * three);
  }
  
  document.form.total.value = four;
}

function stopCalc(){
  clearInterval(interval);
}


function addRow(r){
var root = r.parentNode;//the root
var allRows = root.getElementsByTagName('tr');//the rows' collection
var cRow = allRows[0].cloneNode(true)//the clone of the 1st row
var cInp = cRow.getElementsByTagName('input');//the inputs' collection of the 1st row
for(var i=0;i<cInp.length;i++){//changes the inputs' names (indexes the names)
//cInp[i].setAttribute('name',cInp[i].getAttribute('name')+'['+(allRows.length+1)+']')
cInp[i].setAttribute('name',cInp[i].getAttribute('name'))
}
var cSel = cRow.getElementsByTagName('select')[0];
//cSel.setAttribute('name',cSel.getAttribute('name')+'['+(allRows.length+1)+']');//change the selecet's name
cSel.setAttribute('name',cSel.getAttribute('name'));//change the selecet's name
root.appendChild(cRow);//appends the cloned row as a new row
}


function shownames(){
var allInp=document.getElementsByTagName('input');
for(var i=0;i<allInp.length;i++){
alert(allInp[i].name)
}
}


function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=500,height=780,screenX=150,screenY=150,top=150,left=150')
}

function check_agree(TheForm) {
  if (TheForm.agree.checked) {
    return true;
  } else {
    alert(unescape('Please read and accept our terms and conditions to continue.'));
    return false;
  }
}

function popupWindow2(url) {
  window.open(url,'popupWindow2','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=500,height=500,screenX=50,screenY=50,top=50,left=50')
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=400,left = 300,top = 110');");
}


function focused(obj) {
	if (obj.value == obj.defaultValue) {
		obj.value = "";
	}
}
function blurred(obj) {
	if (obj.value == "") {
		obj.value = obj.defaultValue;
	}
}

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_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_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 popuprebate () {
  window.open("https://www.speedwaysales.com/rebate_links.html", "Rebate", "top=155, left=740, width=270,height=380,scrollbars=yes");
 }
 
 function popuphusqy () {
  window.open("http://www.speedwaysales.com/husqy0.html", "Husqvarna Chain Saws", "top=100, left=740, width=750,height=550,scrollbars=yes");
 }
 
 
 function popupdtype () {
  window.open("https://www.speedwaysales.com/d_type.html", "Delivery Type", "top=155, left=740, width=320,height=480,scrollbars=yes");
 }
 
 function popupcloseout () {
  window.open("closeouts_small.html", "Closeout", "top=140, left=730, width=280,height=380,scrollbars=yes");
 }