// CartOnScreen.js
//myhome="http://vrp3dev.netaura.com/";
myhome="http://www.vrp.com/";
//myhttps="http://secure.netaura.com/";
myhttps="http://secure.vrp.com/";

CartOn="0";
zwin="";
function ShowCart()  {
    if( CartOn=="0" ) {
        if(GotAj()=="Y") {
        _SendResults="";
        ctyp=String(GetCookie("CTYPE"));
        if( ctyp=="" ) { ctyp="C"; }
        promo=""
        shipzip=String(GetCookie("shiptozip"));
        shipcountry=String(GetCookie("shiptocountry"));
        shipmethod=String(GetCookie("shiptomethod"));
        shipoutside=String(GetCookie("shiptooutside"));
        _SendResults=PostGet("MKCART","1",String(GetCookie("cid")),ctyp,promo,shipzip,shipcountry,shipmethod,shipoutside,"","");
        document.getElementById("SCART").style.visibility="visible";
        document.getElementById("SCART").style.height="";
        //alert(_SendResults);
        document.getElementById("SCART").innerHTML=_SendResults;
        CartOn="1";
        } else {
        document.getElementById("SCART").style.visibility="visible";
        document.getElementById("SCART").style.height="";
        CartOn="1";
        }
    } else {
        document.getElementById("SCART").style.height="0px";
        document.getElementById("SCART").style.visibility="hidden";
        CartOn="0";
    }
    SetCookie("CartOn",CartOn);
    //if( _SendResults.indexOf("Shipping</a>:&nbsp;&nbsp;&nbsp;$999.99")>=0 ) {
    if( _SendResults.indexOf("$999.99")>=0 ) {
        if(shipcountry=="034") {
            alert("The weight of the products is over the carriers limit.\r\nPlease select another shipping method.");
        }
    }
}
function GetShipAmt(tMODE) {
    aMSG="";
    aMSG2="";
    sWEIGHT=document.getElementById("shiptoweight").value;
    sZIP=document.getElementById("shiptozip").value;
    sCOUNTRY=document.getElementById("shiptocountry").value;
    sOUTSIDE=document.getElementById("shiptooutside").value;
    sMETHOD=document.getElementById("shipmethod").value;
    document.getElementById("shipmethod").style.visibility="visible";
    sSUBTOTAL=document.getElementById("subtotal").value;
    sSUBTOTAL=sSUBTOTAL.replace(/,/gi,"");
    document.getElementById("subtotal").value=sSUBTOTAL;
    sAMOUNT = PostGet("GETSHIPCOST",sCOUNTRY,sZIP,sWEIGHT,sMETHOD,sSUBTOTAL,sOUTSIDE,"","","","");
    sAMOUNT=sAMOUNT.replace(/\$\$/gi,"$");
    if(sZIP.substr(0,3)=="008" || sZIP.substr(0,3)=="009" ||sZIP.substr(0,3)=="995" ||sZIP.substr(0,3)=="996" ||sZIP.substr(0,3)=="997" ||sZIP.substr(0,3)=="998" ||sZIP.substr(0,3)=="999" || sZIP.substr(0,3)=="967" || sZIP.substr(0,3)=="968") { 
        sOUTSIDE="true";
    }
    if(sZIP.substr(0,3)=="008" || sZIP.substr(0,3)=="009") { 
        sOUTSIDE2="true";
    } else {
        sOUTSIDE2="false"
    }
//alert(sOUTSIDE);
//alert(sOUTSIDE2);
    sAMOUNT=sAMOUNT.replace(/\$\$/gi,"$");
    sAMOUNT=sAMOUNT.replace(/\,/gi,"");
    if(sAMOUNT=="$9999.99" || sAMOUNT=="9999.99") {
        if(sCOUNTRY=="001") {
          if(sOUTSIDE=="true") {
            if(sOUTSIDE2=="true") {
                sMETHOD="POP";
                aMSG2="Post Office";
                document.getElementById("shipmethod").value=sMETHOD;
            } else {
                sMETHOD="FEX";
                aMSG2="FedEx Two Day";
                document.getElementById("shipmethod").value=sMETHOD;
            }
          } else {
            sMETHOD="FLT";
            aMSG2="Flat Rate";
            document.getElementById("shipmethod").value=sMETHOD;
          }
        } else {
            sMETHOD="EMI";
            aMSG2="International Express Mail";
            document.getElementById("shipmethod").value=sMETHOD;
        }
        sAMOUNT = PostGet("GETSHIPCOST",sCOUNTRY,sZIP,sWEIGHT,sMETHOD,sSUBTOTAL,sOUTSIDE,"","","","");
        sAMOUNT=sAMOUNT.replace(/\$\$/gi,"$");
        sAMOUNT=sAMOUNT.replace(/\,/gi,"$");
        aMSG += "The ZIP code provided is not recognized by, or not applicable to this shipping carrier.\r\n";
        aMSG += "Please correct the ZIP code, or choose another shipping method. Meanwhile, we are \r\n"
        aMSG += "switching the shipping method to "+aMSG2+" Shipping."
    }

        if(sAMOUNT.indexOf("$0 ->The Ship To")!=-1) {
            if(sCOUNTRY=="001") {
              if(sOUTSIDE=="true") {
                    sMETHOD="POP";
                    aMSG2="Post Office";
                    document.getElementById("shipmethod").value=sMETHOD;
              } else {
                    sMETHOD="FLT";
                    aMSG2="Flat Rate";
                    document.getElementById("shipmethod").value=sMETHOD;
              }
            } else {
                if(sCOUNTRY=="034") {
                    sMETHOD="CPM";
                    aMSG2="Priority Mail International";
                    document.getElementById("shipmethod").value=sMETHOD;
                } else{
                    sMETHOD="EMI";
                    aMSG2="International Express Mail";
                    document.getElementById("shipmethod").value=sMETHOD;
                }
            }
            sAMOUNT = PostGet("GETSHIPCOST",sCOUNTRY,sZIP,sWEIGHT,sMETHOD,sSUBTOTAL,sOUTSIDE,"","","","");
            sAMOUNT=sAMOUNT.replace(/\$\$/gi,"$");
            sAMOUNT=sAMOUNT.replace(/\,/gi,"$");
            aMSG += "The ZIP code provided is not recognized by, or not applicable to this shipping carrier.\r\n";
            aMSG += "Please correct the ZIP code, or choose another shipping method. Meanwhile, we are \r\n";
            aMSG += "switching the shipping method to "+aMSG2+" Shipping.";
        }



    if(sAMOUNT=="$999.99" || sAMOUNT=="999.99") {
        if(sCOUNTRY=="001") {
          if(sOUTSIDE=="true") {
            sMETHOD="FEX";
            aMSG2="FedEx Two Day";
            document.getElementById("shipmethod").value=sMETHOD;
          } else {
            sMETHOD="FLT";
            aMSG2="Flat Rate";
            document.getElementById("shipmethod").value=sMETHOD;
          }
        }
    
        if(sCOUNTRY=="034") {
            sMETHOD="CPM";
            aMSG2="Priority Mail International";
            document.getElementById("shipmethod").value="CPM";
            sAMOUNT = PostGet("GETSHIPCOST",sCOUNTRY,sZIP,sWEIGHT,sMETHOD,sSUBTOTAL,sOUTSIDE,"","","","");
            sAMOUNT=sAMOUNT.replace(/\$\$/gi,"$");
            sAMOUNT=sAMOUNT.replace(/\,/gi,"$");
            aMSG += "The weight is over this carriers limit.\r\n";
            aMSG += "We are switching the shipping method to "+aMSG2+" Shipping."
        }
    }

    
    document.getElementById("shcost").innerHTML="<strong>Cost:</strong>&nbsp;"+sAMOUNT;
    SetCookie("shiptomethod",sMETHOD);
    ShowCart();
    ShowCart();
    if(aMSG!="") { alert(aMSG); }
}
function ResetPrice() {
    document.getElementById('shcost').innerHTML="<strong>Cost:</strong>&nbsp;(not calculated)";
    GetShipAmt(1);
}
function GetShipShippers(tMODE) {
    if( tMODE==0 ) {
//        //try {
//		// dw
//		curloc=String(window.location);
//		curloc=curloc.toLowerCase();
//		szip=document.getElementById("shiptozip").value;
//        scountry=document.getElementById("shiptocountry").value;
//        soutside=document.getElementById("shiptooutside").value;
//        smethod=document.getElementById("shipmethod").value;
//        // Set cookies in current domain
//        SetCookie("shiptozip",document.getElementById("shiptozip").value);
//        SetCookie("shiptocountry",document.getElementById("shiptocountry").value);
//        SetCookie("shiptooutside",document.getElementById("shiptooutside").value);
//        SetCookie("shiptomethod",document.getElementById("shipmethod").value);
//        cURL=String(window.location);
//        cURL=cURL.replace(/&/g,"|");
//        // Set cookies in other domain
//        setck="setc.aspx?d=0&z=";
//        setck+=szip;
//        setck+="&c=";
//        setck+=scountry;
//        setck+="&m=";
//        setck+=smethod;
//        setck+="&o=";
//        setck+=soutside;
//        setck+="&r=";
//        setck+=cURL;
//		if( curloc.indexOf("home.aspx")>1 ) {
//		    window.location=myhome+setck;
//		} else {
//            window.location=myhttps+setck;		
//		}
//		// dw
//		//}
//		//catch(dwerror) {
//		//
//		//}
		document.getElementById('vrpMsg').style.border="";
		document.getElementById('vrpMsg').style.width="1px";
		document.getElementById('vrpMsg').style.height="1px";
		document.getElementById('vrpMsg').innerHTML= " ";
		return;
    }
    //
    if(document.getElementById("shiptozip").value=="") return;
    if(document.getElementById("scountry").value=="") return;
    SetCookie("shiptozip",document.getElementById("shiptozip").value);
    SetCookie("shiptocountry",document.getElementById("scountry").value);
    SetCookie("shiptooutside",document.getElementById("shiptooutside").checked);
	oPage = "";
	msgWidth=350;
	msgHeight=300;
    msgData ="<form action=\"/GetShipData.aspx\" method=\"post\" >";
    msgData+="<input type='hidden' id='shiptozip' value='"+document.getElementById("shiptozip").value+"'>";
    msgData+="<input type='hidden' id='shiptocountry' value='"+document.getElementById("scountry").value+"'>";
    msgData+="<input type='hidden' id='shiptooutside' value='"+document.getElementById("shiptooutside").checked+"'>";
    msgData+="<br /><table border='0' cellpadding='0' cellspacing='0' align='center'>";
    msgData+="<tr><td colspan='2' align='center'>";
    msgData+="<strong>Please select a shipping method:</strong>&nbsp;";
    msgData+="</td></tr>";
    msgData+="<tr><td colspan='2' align='center'>";
    msgData+=PostGet("GETMETHODS",document.getElementById("scountry").value,document.getElementById("shiptozip").value,"","","","","","","","");
    msgData+="</td></tr>";
    msgData+="<tr><td colspan='2' align='center'>";
    msgData+="<div id='shcost'><strong>Cost:</strong>&nbsp;(not calculated)</div>";
    msgData+="<tr><td colspan='2' align='center'><br />";
    msgData+="<strong>After selecting the shipping method best<br />for you, click the select button.</strong><br />";
    msgData+="<input type='button' onclick='GetShipShippers(0);' value='Select' />";
    msgData+="</td></tr>";
    msgData+="</table>";
	msgData+="</form>";
    // Show centered on screen.
    document.getElementById('vrpMsg').style.top="5px";
    document.getElementById('vrpMsg').style.left=(GetWidth()/2)-(msgWidth/2)+"px";
    // Show just left of cursor.
    var sTOP = 0;
    var sDOWN = 0;
    var sHEIGHT = 0;
    if (document.documentElement && !document.documentElement.scrollTop) {
        sTOP=document.documentElement.scrollTop;
        sHEIGHT=document.documentElement.clientHeight;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
        sTOP=document.documentElement.scrollTop;
        sHEIGHT=document.documentElement.clientHeight;
    }
    else if (document.body && document.body.scrollTop) {
        sTOP=document.body.scrollTop;
        sHEIGHT=document.body.clientHeight;
    }
    sDOWN=sTOP;
    var boxLeft = 0;
    var boxTop = 0;
    boxLeft= (  mouseX -(msgWidth+40)  );
    //        
    if(!document.all) {   // FIREFOX
        boxTop= (  mouseY - (msgHeight/2) );
    } else {                  // I.E.
        mouseY2=5+sTOP;
        boxTop= (  mouseY2 - (msgHeight/2) );
    }
    xtop=Number(boxTop);
    xheight=Number(msgHeight);
    xvalue=xtop+xheight;
    ytop=Number(sTOP);
    yheight=Number(sHEIGHT);
    yvalue=ytop+yheight;
    zvalue=yvalue-xheight;
    if( xtop < ytop ) {
    boxTop=ytop+40;
    } else {
        if( xvalue > yvalue ) {
            boxTop = zvalue-40;
        }
    }
	document.getElementById('vrpMsg').style.top=Trim(boxTop)+"px";
	document.getElementById('vrpMsg').style.width=(msgWidth)+"px";
	document.getElementById('vrpMsg').style.height=(msgHeight)+"px";
	if(!document.all) {   // Firefox
	    oPage += "<div style='position: absolute; left: 10px; top: 10px; width: "+Trim(msgWidth)+"px; height: "+Trim(msgHeight)+"px;";
	    oPage += " background-color: black; filter: alpha(opacity=30); opacity: 0.30;'></div>";
    	oPage += "<div style='position: relative; height: "+Trim(msgHeight)+"px; width: "+Trim(msgWidth)+"px; border: solid 1px black;'>";
	} else {      // IE
	    oPage += "<div style='position: absolute; left: 10px; top: 10px; width: "+Trim(msgWidth)+"px; height: "+Trim(msgHeight)+"px;";
	    oPage += " background-color: black; filter: alpha(opacity=40); opacity: 0.40;'></div>";
    	oPage += "<div style='position: relative; height: "+Trim(msgHeight)+"px; width: "+Trim(msgWidth)+"px; border: solid 1px black;'>";
	}
	
	if(!document.all) {   // Firefox
	    oPage += "<table border='0' cellpadding='3' cellspacing='0' width='"+Trim(msgWidth)+"'";
	    oPage += " style='width:"+Trim(msgWidth)+"px; height:"+Trim(msgHeight)+"px;";
	} else {
	    oPage += "<table border='0' cellpadding='3' cellspacing='0' width='"+Trim(msgWidth)+"'";
	    oPage += " style='width:"+Trim(msgWidth)+"px; height:"+Trim(msgHeight-23)+"px;";
	}
	oPage += " background-color: white; filter: alpha(opacity=96); opacity: 0.96;'>";
	oPage += "<tr style='background-image:url(/images/bg_bluestrip_22b.jpg); background-repeat:repeat-x;' ><td align='center' style='color:white;'><b>Calculate Shipping Cost</b></td>";
	oPage += "<td align='right'>";
	oPage += "<a href='' onClick=\"GetShipShippers(0); return false;\"><img src='/images/red-x.gif' border='0' title='Close' alt='Close'></a>";
	oPage += "</td></tr>";
	oPage += "<tr height='98%'><td height='98%' valign='top' colspan='2'><p align='justify'>";
	oPage += msgData;
	oPage += "</p></td></tr>";
	oPage += "</table>";
	oPage += "</div>";
	document.getElementById('vrpMsg').innerHTML= oPage;
	GetShipAmt(1);
}
function ChkCntry() {
    if(document.getElementById("scountry").value=="001") {
        document.getElementById("divchk").style.visibility="visible";
    } else {
        document.getElementById("divchk").style.visibility="hidden";
    }
}
function CloseMe() {
SetCookie("shiptozip",document.getElementById("shiptozip").value);
SetCookie("shiptocountry",document.getElementById("shiptocountry").value);
SetCookie("shiptomethod",document.getElementById("shipmethod").value);
SetCookie("shiptooutside",document.getElementById("shiptooutside").value);
window.opener.document.pform.submit();
window.close();
}
function GetShipData(tMODE) {
    if( GotAj()=="N") {
        wt=document.getElementById("shiptoweight").value;
        st=document.getElementById("subtotal").value
        zwin=window.open("/GetShipData.aspx?w="+wt+"&s="+st,"Shipping","location=0,status=0,scrollbars=1,resizable=1,width=460,height=400");
        //zwin.moveTo(0,0);
    } else {
    if( tMODE==0 ) {
		document.getElementById('vrpMsg').style.border="";
		document.getElementById('vrpMsg').style.width="1px";
		document.getElementById('vrpMsg').style.height="1px";
		document.getElementById('vrpMsg').innerHTML= " ";
		return;
    }
    shiptozip=String(GetCookie("shiptozip"));
    shiptocountry=String(GetCookie("shiptocountry"));
	oPage = "";
	msgWidth=350;
	msgHeight=300;
	msgData ="<form action=\"/GetShipData.aspx\" method=\"post\">";
	msgData+="<br /><table border='0' cellpadding='0' cellspacing='0'align='center'>";
	msgData+="<tr><td colspan='2' align='center'>";
    msgData+="<strong>Please enter the ship-to postal code<br />and select the appropriate ship-to country.</strong><br /><br />";
    msgData+="</td><tr>";
    msgData+="<tr><td align='right'><strong>Postal Code:</strong>&nbsp;</td><td align='left'>"
    msgData+="<input type='text' id='shiptozip' name='shiptozip' size='10' maxlength='10' value='"+shiptozip+"' />";
    msgData+="</td></tr>";
    msgData+="<tr><td align='right'><strong>Country:</strong>&nbsp;</td><td>";
    msgData+=PostGet("GETCOUNTRIES",shiptocountry,"","","","","","","","","");
    msgData+="</td></tr>";
    msgData+="<tr><td colspan='2' align='center'><div id='divchk' style='visibility:hidden;'>";
    msgData+="<input type='checkbox' id='shiptooutside' name='shiptooutside'>";
    msgData+="Check if the address is outside<br />the contiguous US (AK, HI, PR, VI)</div>";
    msgData+="</td></tr>";
    msgData+="<tr><td colspan='2' align='center'><br /><br />";
    msgData+="<input type='button' onclick='GetShipShippers(1);' value='Continue' />";
    msgData+="</td></tr>";
    msgData+="</table>";
	msgData+="</form>";
    // Show centered on screen.
    document.getElementById('vrpMsg').style.top="5px";
    document.getElementById('vrpMsg').style.left=(GetWidth()/2)-(msgWidth/2)+"px";
    // Show just left of cursor.
    var sTOP = 0;
    var sDOWN = 0;
    var sHEIGHT = 0;
    if (document.documentElement && !document.documentElement.scrollTop) {
        sTOP=document.documentElement.scrollTop;
        sHEIGHT=document.documentElement.clientHeight;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
        sTOP=document.documentElement.scrollTop;
        sHEIGHT=document.documentElement.clientHeight;
    }
    else if (document.body && document.body.scrollTop) {
        sTOP=document.body.scrollTop;
        sHEIGHT=document.body.clientHeight;
    }
    sDOWN=sTOP;
    var boxLeft = 0;
    var boxTop = 0;
    boxLeft= (  mouseX -(msgWidth+40)  );
    //        
    if(!document.all) {   // FIREFOX
        boxTop= (  mouseY - (msgHeight/2) );
    } else {                  // I.E.
        mouseY2=5+sTOP;
        boxTop= (  mouseY2 - (msgHeight/2) );
    }
    xtop=Number(boxTop);
    xheight=Number(msgHeight);
    xvalue=xtop+xheight;
    ytop=Number(sTOP);
    yheight=Number(sHEIGHT);
    yvalue=ytop+yheight;
    zvalue=yvalue-xheight;
    if( xtop < ytop ) {
        boxTop=ytop+40;
    } else {
        if( xvalue > yvalue ) {
            boxTop = zvalue-40;
        }
    }
	document.getElementById('vrpMsg').style.top=Trim(boxTop)+"px";
	document.getElementById('vrpMsg').style.width=(msgWidth)+"px";
	document.getElementById('vrpMsg').style.height=(msgHeight)+"px";
	if(!document.all) {   // Firefox
	    oPage += "<div style='position: absolute; left: 10px; top: 10px; width: "+Trim(msgWidth)+"px; height: "+Trim(msgHeight)+"px;";
	    oPage += " background-color: black; filter: alpha(opacity=30); opacity: 0.30;'></div>";
    	oPage += "<div style='position: relative; height: "+Trim(msgHeight)+"px; width: "+Trim(msgWidth)+"px; border: solid 1px black;'>";
	} else {      // IE
	    oPage += "<div style='position: absolute; left: 10px; top: 10px; width: "+Trim(msgWidth)+"px; height: "+Trim(msgHeight)+"px;";
	    oPage += " background-color: black; filter: alpha(opacity=40); opacity: 0.40;'></div>";
    	oPage += "<div style='position: relative; height: "+Trim(msgHeight)+"px; width: "+Trim(msgWidth)+"px; border: solid 1px black;'>";
	}
	if(!document.all) {   // Firefox
	    oPage += "<table border='0' cellpadding='3' cellspacing='0' width='"+Trim(msgWidth)+"'";
	    oPage += " style='width:"+Trim(msgWidth)+"px; height:"+Trim(msgHeight)+"px;";
	} else {
	    oPage += "<table border='0' cellpadding='3' cellspacing='0' width='"+Trim(msgWidth)+"'";
	    oPage += " style='width:"+Trim(msgWidth)+"px; height:"+Trim(msgHeight-23)+"px;";
	}
	oPage += " background-color: white; filter: alpha(opacity=96); opacity: 0.96;'>";
	oPage += "<tr style='background-image:url(/images/bg_bluestrip_22b.jpg); background-repeat:repeat-x;' ><td align='center' style='color:white;'><b>Calculate Shipping Cost</b></td>";
	oPage += "<td align='right'>";
	oPage += "<a href='' onClick=\"GetShipData(0); return false;\"><img src='/images/red-x.gif' border='0' title='Close' alt='Close'></a>";
	oPage += "</td></tr>";
	oPage += "<tr height='98%'><td height='98%' valign='top' colspan='2'><p align='justify'>";
	oPage += msgData;
	oPage += "</p></td></tr>";
	oPage += "</table>";
	oPage += "</div>";
	document.getElementById('vrpMsg').innerHTML= oPage;
	}
}



