﻿// Add2Cart.js

function Set_sc(sTHIS) {
pcode=document.getElementById("ccode").innerHTML;
cid=String(GetCookie("cid"));
pcart=GetCart(cid);
var s=s_gi('vrpprod');
s.linkTrackVars='events,products';
s.linkTrackEvents=pcart==""?"scAdd,scOpen":"scAdd";
s.events=pcart==""?"scAdd,scOpen":"scAdd";
s.products=';'+pcode;
s.tl(sTHIS,'o','Add To Cart');
}
function GetCart( crtID ) {
return PostGet("GETCART",crtID,'','','','','','','','','');
}

function a2cBN(onoff,pcode,pname,pseq,pqty) {
    if( GotAj()=="Y" ) {
	//a_a2cqty=document.getElementById("a2c"+pseq+"qty").value;
	a_a2cqty=pqty;
	if(onoff==0) {
		document.getElementById('vrpMsg').style.border="";
		document.getElementById('vrpMsg').style.width="1px";
		document.getElementById('vrpMsg').style.height="1px";
		document.getElementById('vrpMsg').innerHTML= " ";
		return;
	}
    var a_cid=String("");
    var a_aid=String("");
    a_cid=String(GetCookie("cid"));
    a_aid=String(GetCookie("aid"));
    if(a_cid=="") {
        alert("This website uses cookies.\r\nPlease set your browser to allow use\r\n of temporary cookies.\r\n\r\nThank You.");
        return;
    }
    a_ccode=pcode;
    a_cname=pname;
    if(Number(a_a2cqty)<0) { a_a2cqty="1"; }
    _SendResults=PostGet("ADD2CART",a_cid,a_ccode,a_a2cqty,'','','','','','','');
    if( Trim(_SendResults)==Trim("INSERTED") || Trim(_SendResults)==Trim("UPDATED") || Trim(_SendResults)==Trim("ADDED") ) {
        msgData ="<form action='/add2cart.aspx?cid="+a_cid+"&aid="+a_aid+"'><center><br />"
        msgData+="The following item was ";
        msgData+=Trim(_SendResults)==Trim("UPDATED")?"updated in":"added to";
        msgData+=" your cart.<br />"
        msgData+="<table border='0' cellpadding='0' cellspacing='0'>";
        msgData+="<tr bgcolor='#c0c0c0'><th>Code #</th><th>Product</th><th>Qty.</th></tr>";
        msgData+="<tr><th>"+a_ccode+"</th><th>"+a_cname+"</th><th>"+a_a2cqty+"</th></tr>";
        msgData+="<tr><td colspan='3'>&nbsp;</td></tr>";
        msgData+="<tr><td colspan='3' align='center'><input type='button' value='Checkout' onclick=\"document.location='"+https+"checkout.aspx?cid="+a_cid+"&aid="+a_aid+"';\">&nbsp;&nbsp;&nbsp;<input type='button' value='Continue Shopping' onclick=\"a2c(0,'','','');\"></td></tr>";
        msgData+= "</table></center></form>";
        msgData+="<iframe id='vrp_iframe' frameborder='0' src='/BNCartGuide.aspx?id=";
        msgData+=a_ccode;
        msgData+="' valign='bottom'></iframe>"
    } else {
        msgData ="<br /><form><center>ERROR<br />"
        msgData+=_SendResults;
        msgData+= "</center></form>";
    }    
    msgPos=0;
	oPage = "";
	//msgHeight=150;
	msgHeight=460;
	//msgWidth=400;
	msgWidth=500;
	if(msgPos==1) {
	    // 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.
            mouseY=mouseY+sTOP;
            boxTop= (  mouseY - (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.left=Trim(boxLeft)+"px";
	    document.getElementById('vrpMsg').style.left=(GetWidth()/2)-(msgWidth/2)+"px";
	    document.getElementById('vrpMsg').style.top=Trim(boxTop)+"px";
	} else {
	    // Show centered on screen.
	    document.getElementById('vrpMsg').style.left=(GetWidth()/2)-(msgWidth/2)+"px";
	    document.getElementById('vrpMsg').style.top=(GetHeight()/2)-(msgHeight/2)+"px";
	}
	document.getElementById('vrpMsg').style.width=(msgWidth+12)+"px";
	document.getElementById('vrpMsg').style.height=(msgHeight+12)+"px";
	if(!document.all) {   // Firefox
	    oPage += "<div id='vrp_cart_shadow'></div>";
    	oPage += "<div id='vrp_cart_container'>";
   	} else {      // IE
	    oPage += "<div id='vrp_cart_shadow'></div>";
    	oPage += "<div id='vrp_cart_container'>";
   	}
	oPage += "<table id='vrp_cart_displaytable'>";
	oPage += "<tr style='background-image:url(/images/bg_bluestrip_22b.jpg); background-repeat:repeat-x;' ><td align='center' style='color:white;'><b>Add To Cart</b></td>";
	oPage += "<td align='right'>";
	oPage += "<a href='' onClick=\"a2c(0,'','',''); return false;\"><img src='/images/red-x.gif' border='0'></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;
    if(GetCookie("CartOn")=="1") {
        ShowCart(); // toggle off
        ShowCart(); // toggle back on
    }   
    return false; 
    } else {
        a_cid=String(GetCookie("cid"));
        a_aid=String(GetCookie("aid"));
        if(a_cid=="") {
            alert("This website uses cookies.\r\nPlease set your browser to allow use\r\n of temporary cookies.\r\n\r\nThank You.");
            return;
        }
        a_ccode=pcode;
        a_cname=pname;
        a_a2cqty=document.getElementById("a2c"+pseq+"qty").value;
        if(Number(a_a2cqty)<0) { a_a2cqty="1"; }
        document.getElementById("pformqty").value=a_a2cqty;
        document.getElementById("pform").Submit;
        return true;
    }
}
function a2c(onoff,pcode,pname,pseq) {
    if( GotAj()=="Y" ) {
	if(onoff==0) {
		document.getElementById('vrpMsg').style.border="";
		document.getElementById('vrpMsg').style.width="1px";
		document.getElementById('vrpMsg').style.height="1px";
		document.getElementById('vrpMsg').innerHTML= " ";
		return;
	}
    var a_cid=String("");
    var a_aid=String("");
    a_cid=String(GetCookie("cid"));
    a_aid=String(GetCookie("aid"));
    if(a_cid=="") {
        alert("This website uses cookies.\r\nPlease set your browser to allow use\r\n of temporary cookies.\r\n\r\nThank You.");
        return;
    }
    a_ccode=pcode;
    a_cname=pname;
    a_a2cqty=document.getElementById("a2c"+pseq+"qty").value;
    if(Number(a_a2cqty)<0) { a_a2cqty="1"; }
    _SendResults=PostGet("ADD2CART",a_cid,a_ccode,a_a2cqty,'','','','','','','');
    if( Trim(_SendResults)==Trim("INSERTED") || Trim(_SendResults)==Trim("UPDATED") || Trim(_SendResults)==Trim("ADDED") ) {
        msgData ="<form action='/add2cart.aspx?cid="+a_cid+"&aid="+a_aid+"'><center><br />"
        msgData+="<b>The following item was ";
        msgData+=Trim(_SendResults)==Trim("UPDATED")?"updated in":"added to";
        msgData+=" your cart.</b><br />"
        msgData+="<table border='0' cellpadding='0' cellspacing='0'>";
        msgData+="<tr bgcolor='#c0c0c0'><th>Code #</th><th>Product</th><th>Qty.</th></tr>";
        msgData+="<tr><th>"+a_ccode+"</th><th>"+a_cname+"</th><th>"+a_a2cqty+"</th></tr>";
        msgData+="<tr><td colspan='3'>&nbsp;</td></tr>";
        msgData+="<tr><td colspan='3' align='center'><input type='button' value='Checkout' onclick=\"document.location='"+https+"checkout.aspx?cid="+a_cid+"&aid="+a_aid+"';\">&nbsp;&nbsp;&nbsp;<input type='button' value='Continue Shopping' onclick=\"a2c(0,'','','');\"></td></tr>";
        msgData+= "</table></center></form>";
        msgData+="<iframe id='vrp_iframe' frameborder='0' src='/BNCartGuide.aspx?id=";
        msgData+=a_ccode;
        msgData+="' valign='bottom'></iframe>"
    } else {
        msgData ="<br /><form><center>ERROR<br />"
        msgData+=_SendResults;
        msgData+= "</center></form>";
    }    
    msgPos=0;
	oPage = "";
	//msgHeight=150;
	msgHeight=460;
	//msgWidth=400;
	msgWidth=500;
	if(msgPos==1) {
	    // 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.
            mouseY=mouseY+sTOP;
            boxTop= (  mouseY - (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.left=Trim(boxLeft)+"px";
	    document.getElementById('vrpMsg').style.left=(GetWidth()/2)-(msgWidth/2)+"px";
	    document.getElementById('vrpMsg').style.top=Trim(boxTop)+"px";
	} else {
	    // Show centered on screen.
	    document.getElementById('vrpMsg').style.left=(GetWidth()/2)-(msgWidth/2)+"px";
	    //document.getElementById('vrpMsg').style.top=(GetHeight()/2)-(msgHeight/2)+"px";
	    document.getElementById('vrpMsg').style.top=(screen.availHeight/2)-(msgHeight/2)+"px";
	    //viewimageWin.moveTo(screen.availWidth/2-(w/2),screen.availHeight/2-(h/2));


	}
	document.getElementById('vrpMsg').style.width=(msgWidth+12)+"px";
	document.getElementById('vrpMsg').style.height=(msgHeight+12)+"px";
	if(!document.all) {   // Firefox
	    oPage += "<div id='vrp_cart_shadow'></div>";
    	oPage += "<div id='vrp_cart_container'>";
   	} else {      // IE
	    oPage += "<div id='vrp_cart_shadow'></div>";
    	oPage += "<div id='vrp_cart_container'>";
	}
	oPage += "<table id='vrp_cart_displaytable'>";
	oPage += "<tr style='background-image:url(/images/bg_bluestrip_22b.jpg); background-repeat:repeat-x;' ><td align='center' style='color:white;'><b>Add To Cart</b></td>";
	oPage += "<td align='right'>";
	oPage += "<a href='' onClick=\"a2c(0,'','',''); return false;\"><img src='/images/red-x.gif' border='0'></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;
    if(GetCookie("CartOn")=="1") {
        ShowCart(); // toggle off
        ShowCart(); // toggle back on
    }   
    return false; 
    } else {
        a_cid=String(GetCookie("cid"));
        a_aid=String(GetCookie("aid"));
        if(a_cid=="") {
            alert("This website uses cookies.\r\nPlease set your browser to allow use\r\n of temporary cookies.\r\n\r\nThank You.");
            return;
        }
        a_ccode=pcode;
        a_cname=pname;
        a_a2cqty=document.getElementById("a2c"+pseq+"qty").value;
        if(Number(a_a2cqty)<0) { a_a2cqty="1"; }
        document.getElementById("pformqty").value=a_a2cqty;
        document.getElementById("pform").Submit;
        return true;
    }
}

