
function AddToCart(isbnNumber, Quantity){
    if (Quantity == null) Quantity = 1;
//    alert("Buying " + Quantity + " of " + isbnNumber);
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+7);
    document.cookie="isbn" + isbnNumber + "=" + Quantity + ";expires="+exdate;
//	alert("isbn" + isbnNumber + " = " + getCookie("isbn" + isbnNumber));
//    alert(document.cookie);
	return true;
}

function RemoveFromCart(isbnNumber,reload){
//  alert("Removing: " + isbnNumber);
    var exdate=new Date();
    exdate.setDate(exdate.getDate()-1);
    document.cookie="isbn" + isbnNumber + "=0;expires="+exdate;
    if (reload) location.reload();
  return true;
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return null;
}

function UpdateCart(QtyControl){
//    alert("Looking for " + QtyControl);

    var Qtyctrl=QtyControl;
    var intbookidpos;
//    alert("Control = " + Qtyctrl.value );
    var Qty = QtyControl.value;
//    alert("Qty = " + QtyControl.value);
//    alert("id = " + QtyControl.id);
//    alert("name = " + QtyControl.name);
    var isbn = QtyControl.id;
    intbookidpos = isbn.indexOf("qty_");
    isbn = isbn.substring(0,intbookidpos);
//    alert(isbn);
    isbn = isbn.replace("isbn", "");
//    alert(isbn);
    isbn = isbn.replace("qty", "");
//    alert(isbn);
//    alert("New quantity for " + isbn + " is " + Qty);
    AddToCart(isbn, Qty);
    location.reload();

}

function NewPopUpWindowForContent(p_URL,p_Height,p_Width)
{
	window.open(p_URL, "ContentPopup", "height=" + p_Height + "," + "width=" + p_Width + "," + "top=200,left=200,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no");

}
function gotoPage(URL,Scheme)
{
	//URL	: Determines path and page we want to go to
	//Scheme: Determines the protocol to use.
    var targetpage;
	if(URL)
	{
		var sLocalSubWeb = "";
		if(URL.length>1)
		{
//            alert(document.location.host);
			if ( document.location.host == 'localhost') {
				sLocalSubWeb = "/creativehomeowner/public";
//				alert(document.location.host);
			} else if (document.location.host == 'crtmartini') {
				sLocalSubWeb = "/creativehomeowner/public";
//				alert(document.location.host);
			}
			
            targetpage = Scheme + "://" +document.location.host + sLocalSubWeb + "/" + URL;
   			if ( document.location.host == 'localhost') {  alert(targetpage);}

		}
	}

	window.open(targetpage,"_self");
}
