/************************************************************************************/
/*  							Public Site  validations 							*/
/************************************************************************************/
function ApplyPromoCode() {
	if(document.frmcheckout.promocode_code.value == "Promotional Code"){
			document.frmcheckout.promocode_code.value = "";
	}
	if(TextValidate(document.frmcheckout.promocode_code,'Promotional Code')==false){ return false };
	document.frmcheckout.action="checkout.php";
	document.frmcheckout.submit();
}

function addtocart(productid,url)
{	
	var name 	 ='quantity_'+productid;
	var value 	 = document.getElementById(name).value;
	/**** Mandatory check Validation ***********/
	
	if(value=="") {
		alert('Please enter product quantity');
 		document.getElementById(name).focus();
 	}
	else if(value<=0) {
		alert('Product quantity should be greater than zero');
 		document.getElementById(name).focus();
	}
	else if(isNaN(value)) {
		alert('Please enter numeric integer values for product quantity');
		document.getElementById(name).value='';
 		document.getElementById(name).focus();
 	}else if(parseInt(value)!=value) {
	   alert('Please enter integer values for product quantity');
 	   document.getElementById(name).focus();
 	}else {
		
		
		document.frmCart.addproduct.value = 1;	
		document.frmCart.continue_url.value = url;
		document.frmCart.product_id.value = productid;
		document.frmCart.product_quantity.value = document.getElementById(name).value;	
		
	/*****************  Quantity Check *********************/
	
		//Ajax Code comes here
		var xmlhttp;
		var req;
		req = false;
		if(window.XMLHttpRequest){
				//Intiate the object
				xmlhttp = new XMLHttpRequest();				
		}
		// If the user is using IE
		else if (window.ActiveXObject) { 
				//Intiate the object
			try{
				  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch(e){}
		}
		var url = 'quantity_status.php?productid='+productid+'&quantity='+value;	
		xmlhttp.open('GET', url, true);
		//Check that the PHP script has finished sending us the result
		xmlhttp.onreadystatechange = function() {
				if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					//Replace the content of the "result" DIV with the result returned by the PHP script
					var response     = xmlhttp.responseText;
					if(response!=""){
						alert(response);
					} 
					
					document.frmCart.action ='addtocartprocess.php';
					document.frmCart.submit();	
 				}
		}
	xmlhttp.send(null);	
	
	/*************** 		Ends	**********************/
	
	}
}
function addtocartOther(productid)
{
	/**** Mandatory check Validation ***********/

		var value =1;
		document.frmCartOther.addproduct.value = 1;	
		document.frmCartOther.product_id.value = productid;
		document.frmCartOther.product_quantity.value = 1;	
		
	/*****************  Quantity Check *********************/
	
		//Ajax Code comes here
		var xmlhttp;
		var req;
		req = false;
		if(window.XMLHttpRequest){
				//Intiate the object
				xmlhttp = new XMLHttpRequest();				
		}
		// If the user is using IE
		else if (window.ActiveXObject) { 
				//Intiate the object
			try{
				  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch(e){}
		}
		var url = 'quantity_status.php?productid='+productid+'&quantity='+value;	
		xmlhttp.open('GET', url, true);
		//Check that the PHP script has finished sending us the result
		xmlhttp.onreadystatechange = function() {
				if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					//Replace the content of the "result" DIV with the result returned by the PHP script
					var response     = xmlhttp.responseText;
					if(response!=""){
						alert(response);
					} 
					document.frmCartOther.action ='addtocartprocess.php';
					document.frmCartOther.submit();	
					 
				}
		}
	xmlhttp.send(null);	
	
	/*************** 		Ends	**********************/
	
	
}
function addtocartOther1(productid)
{
	/**** Mandatory check Validation ***********/

		var value =1;
		document.frmCartOther1.addproduct.value = 1;	
		document.frmCartOther1.product_id.value = productid;
		document.frmCartOther1.product_quantity.value = 1;	
		
	/*****************  Quantity Check *********************/
	
		//Ajax Code comes here
		var xmlhttp;
		var req;
		req = false;
		if(window.XMLHttpRequest){
				//Intiate the object
				xmlhttp = new XMLHttpRequest();				
		}
		// If the user is using IE
		else if (window.ActiveXObject) { 
				//Intiate the object
			try{
				  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch(e){}
		}
		var url = 'quantity_status.php?productid='+productid+'&quantity='+value;	
		xmlhttp.open('GET', url, true);
		//Check that the PHP script has finished sending us the result
		xmlhttp.onreadystatechange = function() {
				if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					//Replace the content of the "result" DIV with the result returned by the PHP script
					var response     = xmlhttp.responseText;
					if(response!=""){
						alert(response);
					} 
					document.frmCartOther1.action ='addtocartprocess.php';
					document.frmCartOther1.submit();	
 				}
		}
	xmlhttp.send(null);	
	
	/*************** 		Ends	**********************/
	
	
}

function addtowishlist(productid) {
	
	//Ajax Code comes here
		var xmlhttp;
		var req;
		var productid=productid;
		req = false;
		if(window.XMLHttpRequest){
				//Intiate the object
				xmlhttp = new XMLHttpRequest();				
		}
		// If the user is using IE
		else if (window.ActiveXObject) { 
				//Intiate the object
				  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		var url = 'product_wishlist_add.php?productid='+productid;	
		xmlhttp.open('GET', url, true);
		//Check that the PHP script has finished sending us the result
		xmlhttp.onreadystatechange = function() {
				if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					//Replace the content of the "result" DIV with the result returned by the PHP script
					var response     = xmlhttp.responseText;
					if(response!=""){
						alert(response);
					}
				}
		}
	xmlhttp.send(null);	
	
}



function wishlistDelete(id){
			if(confirm("Are you sure you want to delete the Item from your wishlist ? ")){
				document.form2.action = 'product_wishlist.php?action=wishlistDel&wishdel_product_ID='+id;
 				document.form2.submit();			
			}
}

function sendtoFriend(pid){
	//Ajax Code comes here
		
		if(document.getElementById("txt_name").value==""){
			alert("Please enter your name");
			document.getElementById("txt_name").focus();
			return false;
		}
		if(document.getElementById("txt_email").value==""){
			alert("Please enter your email");
			document.getElementById("txt_email").focus();
			return false;
		}
		if(document.getElementById("txt_friendname1").value==""){
			alert("Please enter your friend name");
			document.getElementById("txt_friendname1").focus();
			return false;
		}
		if(document.getElementById("txt_friendemail1").value==""){
			alert("Please enter your friend email");
			document.getElementById("txt_friendemail1").focus();
			return false;
		}
		
		
		if(document.getElementById("txt_email").value!=""){
			if(EmailValidate(document.getElementById("txt_email"),"email")==false) { return false;}
		}
		if(document.getElementById("txt_friendemail1").value!=""){
			if(EmailValidate(document.getElementById("txt_friendemail1"),"email")==false) { return false;}
		}
		if(document.getElementById("txt_friendemail2").value!=""){
			if(EmailValidate(document.getElementById("txt_friendemail2"),"email")==false) { return false;}
		}
		
		document.getElementById("emailtofriend").style.display = "none";
		document.getElementById("loadingemailtofriend").style.display = "block";
		
		var xmlhttp;
		var req;
		var pid=pid;
		var name=document.getElementById("txt_name").value;
		var email=document.getElementById("txt_email").value;
		var friendname1=document.getElementById("txt_friendname1").value;
		var friendemail1=document.getElementById("txt_friendemail1").value;
		if(document.getElementById("txt_friendname2").value){
		var friendname2=document.getElementById("txt_friendname2").value;
		}else{
		var friendname2="";	
		}
		if(document.getElementById("txt_friendemail2").value){
		var friendemail2=document.getElementById("txt_friendemail2").value;
		}else{
		var friendemail2="";	
		}
		
		req = false;
		if(window.XMLHttpRequest){
				//Intiate the object
				xmlhttp = new XMLHttpRequest();				
		}
		// If the user is using IE
		else if (window.ActiveXObject) { 
				//Intiate the object
				  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		var url = 'sendtofriend.php?pid='+pid+'&name='+name+'&email='+email+'&friendname1='+friendname1+'&friendemail1='+friendemail1+'&friendname2='+friendname2+'&friendemail2='+friendemail2;	
		//alert(url);
		
		xmlhttp.open('GET', url, true);
		//Check that the PHP script has finished sending us the result
		xmlhttp.onreadystatechange = function() {
				if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					//Replace the content of the "result" DIV with the result returned by the PHP script
					var response     = xmlhttp.responseText;
					if(response!=""){
						//alert(response);
						document.getElementById("emailtofriend").style.display = "none";
						document.getElementById("loadingemailtofriend").style.display = "none";
						document.getElementById("successemailtofriend").style.display = "";
					}
				}
		}
	xmlhttp.send(null);	
}

function contactus(){
		if(document.getElementById("txt_name").value==""){
			alert("Please enter your name");
			document.getElementById("txt_name").focus();
			return false;
		}
		if(document.getElementById("txt_email").value==""){
			alert("Please enter your email");
			document.getElementById("txt_email").focus();
			return false;
		}
		if(document.getElementById("txt_email").value!=""){
			if(EmailValidate(document.getElementById("txt_email"),"email")==false) { return false;}
		}
		
		document.frmcontactus.action="contactUs.php";
		document.frmcontactus.submit();
}

function customerForgotValidate() {
	if(TextValidate(document.frmforgotpass.txt_email," Email")==false) { return false;	}
	if(EmailValidate(document.frmforgotpass.txt_email," Email")==false) { return false; }
	
		
	document.frmforgotpass.action = "forgot-password.php?status=phint";
	document.frmforgotpass.submit();
}

function updateBasket(page,args) {
			
			var url = page+"?action=update";
			if(args) { url += "&"+args}
			document.form2.action = url;
  			document.form2.submit();
}
function cartDelete(id){
			if(confirm("Are you sure you want to delete the Item from your shopping basket ? ")){
				document.form2.action = 'shoppingBasket.php?action=cartDel&del_product_ID='+id;
 				document.form2.submit();			
			}
}
function updateQuantityminus(id) {
		if(document.frmList.product_Quantity[id]){
			var qtyvalue = document.frmList.product_Quantity[id].value;
			if(qtyvalue > 1){
				document.frmList.product_Quantity[id].value = parseInt(qtyvalue)-1;
			}
		} else {
			var qtyvalue = document.getElementById("product_Quantity").value;
			if(qtyvalue > 1){
				document.getElementById("product_Quantity").value = parseInt(qtyvalue)-1;
			}
		}
}
function updateQuantityplus(id) {
 		if(document.frmList.product_Quantity[id]){
			var qtyvalue = document.frmList.product_Quantity[id].value;
			document.frmList.product_Quantity[id].value = parseInt(qtyvalue)+1;
		} else {
			var qtyvalue = document.getElementById("product_Quantity").value;
			document.getElementById("product_Quantity").value = parseInt(qtyvalue)+1;
		}
		
}
function updateQuantityminus1(id) {
		var qtyvalue = document.frmList.quantity.value;
		if(qtyvalue > 1){
			document.frmList.quantity.value = parseInt(qtyvalue)-1;
		}
}
function updateQuantityplus1(id) {

		var qtyvalue = document.frmList.quantity.value;
		document.frmList.quantity.value = parseInt(qtyvalue)+1;
		
}
function deleteBasket(page,args) {
	var count =0;
	if(document.form2.check.checked) {
		var check = new Array(document.form2.check.value);
		count = 1;
	}else {	var check=document.form2.check; }
	for (var i=0;i<check.length;i++){
		if(check[i].checked == true) count++;
	}
	if(count <= 0) {
		alert("Please select the product to delete");
	}else {
		if(confirm("Are you sure to delete the selected product?")) {
			document.form2.action = page+"?action=delete&"+args;
			var url = page+"?action=delete";
			if(args) { url += "&"+args}
			document.form2.submit();
		}
	}
}
function validateEmpty(){

	var answer = confirm("Are you sure to empty the basket?")
	if (answer)
	{
	window.location='basket.php?action=newbasket';
	}
}

function Checkout() {
		document.form2.action = "checkout.php";
		document.form2.submit();;
}

function Confirm() {
		document.frmcheckout.action = "https://select-test.wp3.rbsworldpay.com/wcc/purchase";
		document.frmcheckout.submit();;
}



window.name = "wndMain"; 
function popUp(strPage, intWidth, intHeight){
	// central calcs
	intScreenWidth = screen.width;
	intScreenHeight = screen.height;
	intPopupLeft = (intScreenWidth/2) - (intWidth/2);
	intPopupTop = (intScreenHeight/2) - (intHeight/2);	
	// exec popUp
	pagePopup = window.open(strPage,"pagePopup",'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,menubar=nocopyhistory=no,width='+intWidth+',height='+intHeight+',left='+intPopupLeft+',top='+intPopupTop);
}



function PrescriptionQuantityminus(id,price) {
		var ctrl = "quantity_"+id;
		var qtyvalue = document.getElementById(ctrl).value;
		if(qtyvalue > 1){
			document.getElementById(ctrl).value = parseInt(qtyvalue)-1;
		}
		
		var totalprice = document.getElementById(ctrl).value * price;
		document.getElementById("total"+id).innerHTML = "&pound;"+totalprice;
 		
}
function PrescriptionQuantityplus(id,price) {
 		var ctrl = "quantity_"+id;
		var qtyvalue = document.getElementById(ctrl).value;
		document.getElementById(ctrl).value = parseInt(qtyvalue)+1;
		
		var totalprice = document.getElementById(ctrl).value * price;
		document.getElementById("total"+id).innerHTML = "&pound;"+totalprice.toFixed(2);
}

function ShowExemptions(id){
		if(id ==1){ // show exemption list box
			document.getElementById("exemption").style.display = "";
			document.getElementById("numberofitems").style.display = "none";
		} else if (id ==2){ // show number of items list box
			document.getElementById("exemption").style.display = "none";
			document.getElementById("numberofitems").style.display = "";
		}
}
 
function filltextbox(selectedvalue){
		if(selectedvalue == "more"){
				document.getElementById("txt_nhs_numberofitems").style.display = "";
				document.getElementById("sel_nhs_numberofitems").style.display = "none";
		} 
}

function NHSPrescriptions() {
		if(document.frmnhs.nhs_ispaid[0].checked == true){
			 if(SelectValidate(document.frmnhs.nhs_exemption,'your payment exemption status')==false){ return false }; 
			 
		} else if(document.frmnhs.nhs_ispaid[1].checked == true){
			if(document.getElementById("txt_nhs_numberofitems").style.display==""){
 					if(isNum(document.getElementById("txt_nhs_numberofitems").value) == false ){
							alert("Enter numeric value");
							document.getElementById("txt_nhs_numberofitems").focus();
							return false;
					} 					
					document.getElementById("nhs_numberofitems").value = document.getElementById("txt_nhs_numberofitems").value;
 			} else {
 					document.getElementById("nhs_numberofitems").value = document.getElementById("sel_nhs_numberofitems").options[document.getElementById("sel_nhs_numberofitems").selectedIndex].value;
			}
		}
 		return true;
}

function ValidateDelivery(){
		if(document.frmdelivery.terms.checked==false){
				alert("Please check the Terms and Conditions");
				document.frmdelivery.terms.focus();
				return false;				
		}
		
		document.frmdelivery.submit();
		
}


function register(){
		if(document.getElementById("regname").value==""){
			alert("Please enter your name");
			document.getElementById("regname").focus();
			return false;
		}
		if(document.getElementById("regemail").value==""){
			alert("Please enter your email");
			document.getElementById("regemail").focus();
			return false;
		}
		if(document.getElementById("regemail").value!=""){
			if(EmailValidate(document.getElementById("regemail"),"email")==false) { return false;}
		}
		
		document.frmregister.action="partnershipProgramme.php";
		document.frmregister.submit();
}

function askpharma(){
		if(document.getElementById("askname").value==""){
			alert("Please enter your name");
			document.getElementById("askname").focus();
			return false;
		}
		if(document.getElementById("askemail").value==""){
			alert("Please enter your email");
			document.getElementById("askemail").focus();
			return false;
		}
		if(document.getElementById("askemail").value!=""){
			if(EmailValidate(document.getElementById("askemail"),"email")==false) { return false;}
		}
		
		document.frmaskpharma.action="askPharmacy.php";
		document.frmaskpharma.submit();
}



function makeObject(){
	var x;
	if (window.ActiveXObject) {
		x = new ActiveXObject("Microsoft.XMLHTTP");
	}else if (window.XMLHttpRequest) {
		x = new XMLHttpRequest();
	}
	return x;
}
var request = makeObject();

function newssubscribe(actionval,newsletter_ID,member_ID){
		//document.getElementById("particular").innerHTML = '<table width="659"  border="0" cellspacing="0" cellpadding="0"><tr><td><img src="http://www.arcadiaonline.co.uk/arcadia-images/spacer.gif" height="15"></td></tr><tr><td  valign="top" align="center"><img src="http://www.arcadiaonline.co.uk/arcadia-images/loading.gif" border="0"><br/><span class="paragraph2">Loading...</span></td></tr></table>';	
		
		//alert(document.getElementById("sub").checked);
		
		//var statusval = document.getElementById("sub").checked;
		
		//var action = "newslettersprocess.php?action="+actionval+"&newsletter_ID="+newsletter_ID+"&member_ID="+member_ID+"&statusvalue="+statusval;
		var action = "newslettersprocess.php?action="+actionval+"&newsletter_ID="+newsletter_ID+"&member_ID="+member_ID;
		/*alert(action);
		var browserName = navigator.appName;
		request.open("GET", action, true);
		request.onreadystatechange = function() {	
			if(request.readyState == 4 && request.status == 200) {
				
				var answer = request.responseText; 
				alert(answer);
					
			}
		}
		request.send(null);
	return false;*/
	
		document.formsubscribe.action="newsletters.php?action="+actionval+"&newsletter_ID="+newsletter_ID+"&member_ID="+member_ID;
		document.formsubscribe.submit();
}

