/***********************************************************************
*
* Common Functions
*
************************************************************************/
var httpURL = "http://www.andytucker-soccercamps.co.uk/";
var httpsURL = "https://www.andytucker-soccercamps.co.uk/";

function showDetailWindow(pType, pID)
{
	sUrl = httpURL+ "shop-detail-window.asp?id=" + pID + "&type=" + pType
	if(pType == "shop")
	{
		nWidth = 400;
		nHeight = 350;
	}
	else
	{
		nWidth = 550;
		nHeight = 400;
	}
	
	window.open(sUrl, 'ActPopup', 'width=' + nWidth + ',height=' + nHeight + ',scrollbars, resizable');
}

function showbasket(pvalue)
{
	if (pvalue == "True" || pvalue == "true")
		alert("You can not goto checkout. Your basket is empty!!");
	else
		window.location = httpsURL + "shop-checkout.asp";
	
}

function addproduct(paction, ptype, ppid, pextra)
{
	var doc = document.frmShop;
	var doc1 = document.frmTemp;
	var ltype, eurl;
	var boolSelected = false;
	var lExtra = "";
	
	doc.item_id.value = ppid;
	doc.item_action.value = paction;
	doc.type.value = ptype;
	
	if (paction == "empty")
	{
		if(confirm("Do you wish to empty your shopping basket?"))
		{
			doc.action = httpURL + "shop-basket-view.asp"
			doc.submit();
		}
	}
	else
	{
	
		if (pextra == "true")
		{
			
			var option = document.frmTemp(ppid + '_rdType');
			var option2 = document.frmTemp(ppid + '_rdType');
			var option3 = document.frmTemp(ppid + '_rdType');
			
			if (option[0].checked == true)
			{
				lExtra = option[0].value;
				boolSelected = true;
			}
			
			if (option[1].checked == true)
			{
				lExtra = option[1].value;
				boolSelected = true;
			}
			
			if (option[2].checked == true)
			{
				lExtra = option[2].value;
				boolSelected = true;
			}
		}
		else
			boolSelected = true;
			
		if (pextra != "" && pextra != "false" && pextra != "true")
		{
			boolSelected = true;
			lExtra = pextra;
		}
		
		if (boolSelected == false)
		{
			alert("Please select atleast one value from the list.");
		}
		else
		{
			if (lExtra != "true")
				doc.item_extra.value = lExtra;
				
			doc.action = httpURL + "shop-basket-view.asp"
			doc.submit();
		}
	}
}


function IsEmail(str) 
{
 		 	// are regular expressions supported?
		  	var supported = 0;
		  	if (window.RegExp) 
			{
	   			var tempStr = "a";
    			var tempReg = new RegExp(tempStr);
		    	if (tempReg.test(tempStr)) supported = 1;
		  	}
		  	if (!supported) 
    			return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
			  	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
			  	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
			  	return (!r1.test(str) && r2.test(str));
}


function confirmorder()
{
	var doc = document.frmcheckout;
	var founderror = false;
	
	
		if(doc.txtname.value == "")
		{
			alert("Please enter name.");
			founderror = true;
			doc.txtname.focus();
		}
		
		if(doc.txtadd.value == "" && founderror == false)
		{
			alert("Please enter invoice address.");
			founderror = true;
			doc.txtadd.focus();
		}
		
		if(doc.txttown.value == "" && founderror == false)
		{
			alert("Please enter town.");
			founderror = true;
			doc.txttown.focus();
		}
		
		if(doc.txtpcode.value == "" && founderror == false)
		{
			alert("Please enter postcode.");
			founderror = true;
			doc.txtpcode.focus();
		}
		
		if(doc.txthome.value == "" && founderror == false)
		{
			alert("Please enter a valid contact number.");
			founderror = true;
			doc.txthome.focus();
		}
		
		
		if(doc.txtemail.value == "" && founderror == false)
		{
			alert("Please enter a vaild email.");
			founderror = true;
			doc.txtemail.focus();
		}
		
		if (!IsEmail(doc.txtemail.value) && founderror == false)
		{
			alert ('Please check that the email address is valid.');
			founderror = true;
			doc.txtemail.focus();
		}
		
		
		if(doc.chkAgree.checked == false && founderror == false)
		{
			alert("Please agree with your Terms & Conditions.");
			founderror = true;
			doc.chkAgree.focus();
		}
		
		if (founderror == false)
		{
			if(doc.ordertypes.value == 2 || doc.ordertypes.value == 3)
			{
				doc.action = httpsURL + "shop-childform.asp";
				doc.submit();
			}
			else
			{
				doc.action = httpsURL + "shop-confirm.asp";
				doc.submit();
			}
		}
}


function confirmchildform()
{
	var doc = document.frmconfirm;
	var founderror = false;
	
	// if course is selected then child form needs to fill in
	for(i=0; i< doc.length; i++)
	{
		fieldRequired = doc[i].getAttribute("required");
		fieldMsg = doc[i].getAttribute("msg");
		
		fieldValue = doc[i].value; 
		fieldType = doc[i].type;
		
		fieldValue = fieldValue.replace(/^\s+|\s+$/g, '') ;
		
		if (fieldRequired == "true")
		{
			if (fieldValue == "")
			{
				blnAllFieldsOk = false;
				alert("Error: Please enter child details for course [" + fieldMsg + "]");
				doc[i].value = "";
				
				founderror = true;
				break;
			}
		}
	}
	
	if (founderror == false)
	{
		doc.action = httpsURL + "shop-confirm.asp";
		doc.submit();
	}
}

function cancelorder()
{
	if(confirm("Do you wish to cancel the order?"))
	{
			document.frmconfirm.action = httpsURL + "shop-confirm.asp?paction=cancel";
			document.frmconfirm.submit();
	}
}

function goback(pSection)
{
	if(pSection == '2.5')
		document.frmconfirm.action = httpsURL + "shop-checkout.asp";
	
	if(pSection == '3')
		document.frmconfirm.action = httpsURL + "shop-childform.asp";

			
	document.frmconfirm.submit();
}

function payorder(pPage)
{
	if(confirm("Are you sure to confirm your order?"))
	{
			alert("You will now be redirected to Protx payment system.....");
			document.frmconfirm.action = pPage;
			document.frmconfirm.submit();
		}
}
	
	
function addChildDeails(pOrderID, pProductID, pProductName, pQuantity, pFrom)
{
	if (pOrderID != "" && pProductID != "")
	{
		sUrl = httpsURL + "childform-edit.asp?oid=" + pOrderID + "&pid=" + pProductID + "&pname=" + pProductName + "&qty=" + pQuantity + "&from=" + pFrom
		var nWidth = "400";
		var nHeight = "500";
		
		window.open(sUrl, 'ActPopup', 'width=' + nWidth + ',height=' + nHeight + ',scrollbars, resizable=no');
	}
}