﻿var states=new Array;
onload=function(){//alert(document.location);
	if(document.getElementById('btnContinueCheckout')!=null && document.getElementById('miniCartButton')!=null){
        var btn=document.getElementById('miniCartButton');
        btn.onclick=document.getElementById('btnContinueCheckout').onclick;
        btn.style.display="inline";
    }
    if(document.getElementById('btnContinueCheckOut1')!=null && document.getElementById('miniCartButton')!=null){
        var btn=document.getElementById('miniCartButton');
        btn.onclick=function(){document.getElementById('btnContinueCheckout1').form.submit();};
        btn.style.display="inline";
    }
	if(document.getElementById('discountLink')!=null){
	    var discountLink=document.getElementById('discountLink');
	    var discountLyr=document.getElementById('discount');
	    discountLyr.style.display="none";
	    discountLink.onmouseover=function(){
		    discountLyr.style.display="block";
	    }
	    discountLink.onmouseout=function(){
		    discountLyr.style.display="none";
	    }
	    discountLink.onclick=function(){
		    return false;
	    }
	}
    if(document.getElementById('militaryInstruction')!=null){
        var ml=document.getElementById('militaryInstruction');
        ml.style.display="none";
        var mLink=document.getElementById('militaryLink');
        if(mLink!=null){
            mLink.onclick=function(){
                ml.style.display=ml.style.display=="none" ? "block" : "none" ;
                return false;
            }
        }

        
    }

    if(document.getElementById('pnlBillingInfo')!=null){
        var country="";
        for(var i=0;i<document.forms[0].ShippingState.length;i++){
            var c=document.forms[0].ShippingState[i].text;
            states[i]=new Array(3);
            states[i][0]=c.substring(0,c.indexOf(":"));
            states[i][1]=c.substring(c.indexOf(":")+1,c.length);
            states[i][2]=document.forms[0].ShippingState[i].value;
        }
        initStates(document.forms[0].ShippingCountry,"shipping");
        //initStates(document.forms[0].BillingCountry,"billing");
    }
    var pp = document.getElementById('privacyPolicy');
    //alert(pp);
    if(pp){
        pp.style.display="none";
        var ps=document.getElementById('privacySwitch');
        if(ps){
            ps.onclick=function(){
                pp.style.display=pp.style.display=="none" ? "block" : "none" ;
                return false;
            }
        }
    }

}
function initStates(obj,stateList){
    var country=obj.value;
    if(stateList=="shipping"){
        stateList=document.forms[0].ShippingState;
    }else{
        stateList=document.forms[0].BillingState;
    }
    var state=stateList.value;
    var selected=0;
    stateList.length=0;
    for(var i=0;i<states.length;i++){
        if(country==states[i][0]){
            if(stateList.length==0){stateList[0]=new Option("--","");}
            stateList[stateList.length]=new Option(states[i][1],states[i][2]);
            if(state==states[i][2]){
                selected=stateList.length-1;
            }
        }
    }
    stateList.selectedIndex=selected;
    if(document.getElementById("shipStateTextBox")!=null){
      if(stateList.length>0){
        if(stateList.id=="ShippingState"){
            document.forms[0].ShippingStateTxt.value="Not on list";
            document.getElementById("shipStateTextBox").style.display="none";
            document.getElementById("shipStateDropDown").style.display="block";
        }else{
            document.forms[0].BillingStateTxt.value="Not on list";
            document.getElementById("billStateTextBox").style.display="none";
            document.getElementById("billStateDropDown").style.display="block";
        }
      }else{
        if(stateList.id=="ShippingState"){
            if(document.forms[0].ShippingStateTxt.value=="Not on list"){
                document.forms[0].ShippingStateTxt.value="";  
            }
            document.getElementById("shipStateTextBox").style.display="block";
            document.getElementById("shipStateDropDown").style.display="none";
        }else{
            if(document.forms[0].BillingStateTxt.value=="Not on list"){
                document.forms[0].BillingStateTxt.value="";  
            }
            document.getElementById("billStateTextBox").style.display="block";
            document.getElementById("billStateDropDown").style.display="none";
        }
      }
    }
    //if(document.forms[0].ShippingEqualsBilling.checked && stateList.id=="ShippingState"){
        //synchList(obj,obj.form);
    //}
}
	
if(!document.getElementById)document.getElementById=function(){return null;}



