function popupConvert(cur)
{
        if(cur=="USD")
        {
                cur = "&To=USD";
        } else if(cur=="EUR")
        {
                cur = "&To=EUR";
        } else {
                cur = "";
        }

    priceToConvert = document.basket.grandtotal.value;
    if(priceToConvert == 0)
    {
                priceToConvert = 1;
        }
        CurrencyWindow = window.open ('http://www.xe.net/ecc/input.cgi?Template=sw&Amount=' + priceToConvert + '&From=GBP'+cur, 'CurrencyWindow', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,height=170,width=600');
        CurrencyWindow.focus();
}

function printpage(siteURL, pageTitle, theWidth, theHeight) {
  theWidth  = theWidth  == 0 ? 100 : theWidth;
  theHeight = theHeight == 0 ? 100 : theHeight;
  myPopup = window.open(siteURL + '/print/' + pageTitle,'InterviewNotes','width=' + theWidth + ',height=' + theHeight + ',resizable=no,scrollbars=yes,status=no');
}

function isset(  ) {
    var a=arguments; var l=a.length; var i=0;
    
    if (l==0) { 
        throw new Error('Empty isset'); 
    }
    
    while (i!=l) {
        if (typeof(a[i])=='undefined' || a[i]===null) { 
            return false; 
        } else { 
            i++; 
        }
    }
    return true;
}


function actionCart(pid,formno,action) {
	
	cid = document.forms['store'+formno].color.options[document.forms['store'+formno].color.selectedIndex].value;
	sid = document.forms['store'+formno].size.options[document.forms['store'+formno].size.selectedIndex].value;
	quantity = document.forms['store'+formno].quantity.value;

	personalisation = "";

	//personalisation += "Embroidery: " + document.forms['store'+formno].personalisation_embroidery.options[document.forms['store'+formno].personalisation_embroidery.selectedIndex].value + ":::";

	if(isset(document.forms['store'+formno].personalisation_shawl1))
	{
		personalisation += "Shawl corner 1: " + document.forms['store'+formno].personalisation_shawl1.value + ":::";
	}
	if(isset(document.forms['store'+formno].personalisation_shawl2))
	{
		personalisation += "Shawl corner 2: " + document.forms['store'+formno].personalisation_shawl2.value + ":::";
	}
	if(isset(document.forms['store'+formno].personalisation_shawl3))
	{
		personalisation += "Shawl corner 3: " + document.forms['store'+formno].personalisation_shawl3.value + ":::";
	}
	if(isset(document.forms['store'+formno].personalisation_shawl4))
	{
		personalisation += "Shawl corner 4: " + document.forms['store'+formno].personalisation_shawl4.value + ":::";
	}

	if(isset(document.forms['store'+formno].personalisation_name))
	{
		personalisation += "Child name: " + document.forms['store'+formno].personalisation_name.value + ":::";
	}
	if(isset(document.forms['store'+formno].personalisation_date))
	{
		personalisation += "Christening date: " + document.forms['store'+formno].personalisation_date.value + ":::";
	}
	if(isset(document.forms['store'+formno].personalisation_church))
	{
		personalisation += "Church: " + document.forms['store'+formno].personalisation_church.value + ":::";
	}
	if(isset(document.forms['store'+formno].personalisation_place))
	{
		personalisation += "Location: " + document.forms['store'+formno].personalisation_place.value + ":::";
	}
url = "update_cart.php?action="+action+"&pid="+pid+"&cid="+cid+"&sid="+sid+"&quantity="+quantity+"&personalisation="+personalisation;

//	alert(''+pid+','+cid+','+sid+''+quantity);

//	r = document.getElementById("update_cart");
	window.open( url,"_self");
//  window.prompt("", "?action="+action+"&pid="+pid+"&cid="+cid+"&sid="+sid+"&quantity="+quantity+"&personalisation="+personalisation)	
	
	
//	alert("item is added to the basket");
//	window.location.reload ( true );

//	history.go(0);
}

function deleteCart(pid,cid,sid) {
	r = document.getElementById("update_cart");
	r.src = "update_cart.php?action=remove&pid="+pid+"&cid="+cid+"&sid="+sid;
}

function updateCart(pid,cid,sid,quantity) {
	r = document.getElementById("update_cart");
	r.src = "update_cart.php?action=update&pid="+pid+"&cid="+cid+"&sid="+sid+"&quantity="+quantity;
}

function removeAllFromCart() {
	r = document.getElementById("update_cart");
	r.src = "update_cart.php?action=removeall";
}
