function getFail(sel,fld,checkit){
 
  if (checkit == "Y"){ //first option is not selected
     fld.style.display = "inline"; //show the field
     //fld.value = sel.options[sel.selectedIndex].text + ": "; //add the option text to field
     fld.focus(); //set focus to field
  }
  else{ //first option is selected
     fld.style.display = "none"; //hide the field
  }
}



function addtocart(title,quantity,unid,price,custom) 
{		
				 //alert('adding to cart.....');
				 if (quantity == "" ) {
				 		quantity="1";
				}

				else if (isNaN(quantity)=="true") {
				 		alert('Please enter a valid number for the quantity');				
				}

				 else {
				 			addtocart="&t=" + title + "&q=" + quantity + "&u=" + unid + "&p=" + price + "&c=" + custom;
				 		  self.location='index.php?page=applications&do=additem' + addtocart;
					}		

}

function removecart(cartunid) 
{

				var addtocart="cartunid=" + cartunid + "&quantity=0";
				self.location='index.php?page=applications&do=updateitem&' + addtocart;
}


function changedelivery(changeval) 
{
				var urlredir = "index.php?page=applications&do=changedelivery&delivery=" + changeval;
        self.location=urlredir;
}

function changequantity(changeval) 
{
				var urlredir = self.location + "&do=changequantity&quantity=" + changeval;
				self.location=urlredir;
}

function changequantitycart(changeval,changeunid) 
{
				var urlredir = self.location + "&do=updateitem&quantity=" + changeval + "&cartunid=" + changeunid;
				self.location=urlredir;
}


function changeoption(changeval) 
{
				var urlredir = self.location + "&do=changeoption&opt=" + changeval;
				self.location=urlredir;
}

function changecustref(changeval) 
{
				var urlredir = "index.php?page=applications&do=changecustref&custref=" + changeval;
        self.location=urlredir;
}

function submitAddress(newaddress)
{
 				var urlredir = "index.php?page=applications&do=changeaddress&addr=" + newaddress;
        self.location=urlredir;
}

function changeAddress(changeval)
{
				var urlredir = "index.php?page=applications&do=updateaddress&addr=" + changeval;
        self.location=urlredir;
}

function changeWrapping(changeval)
{
				var urlredir = "index.php?page=applications&do=updatewrapping&wrapcost=" + changeval;
        self.location=urlredir;
}

function Validate()
{
        var quantity = document.getElementById("quantity").selectedIndex;
		
				if (quantity == "" | quantity == "0") {
					alert('You must enter a quantity to purchase before proceeding.');
					return false;
				}
		
		var options = document.getElementById("sizes").selectedIndex;
				
				if (options == "" | options == "0") {
					alert('You must select a size/lid to purchase before proceeding.');
					return false;
				}
		
		var colours = document.getElementById("colourspick").selectedIndex;
				
				if (colours == "" | colours == "0") {
					alert('You must select a colour to purchase before proceeding.');
					return false;
				}
				
        return true;
}

function getSize($referer)
{
	var sel = document.getElementById("colourspick");
	var filter = sel.options[sel.selectedIndex].value;

	fullURL = parent.document.URL
	xxx = fullURL.substring(fullURL.indexOf('&c')+3, fullURL.length)
	yyy = '&c' + xxx
	fullLength = fullURL.length
	stripLength = yyy.length + 1
	if(stripLength >7) {
		newloc = fullURL
	}
	else {
		newloc = fullURL.substr(0,fullLength - stripLength)
	}
	self.location= newloc +"&c=" + filter;
}
