var checkmail_msg = "Invalid E-mail address! Please enter your correct email address.";
var password_msg = "Please enter your Password.";
var name_msg = "Please enter your Full Name.";
var company_name_msg = "Please enter your Company Name.";
var designation_msg = "Please enter Designation";
var address_msg = "Please enter your Address.";
var phone_msg = "Please enter your Telephone Number.";
var fax_msg = "Please enter Fax";
var email_msg = "Please enter your E-mail address.";
var profile_msg = 'Please enter your Profile.';
var comment_msg = "Please enter General Enquriry/Comments";
var phone_numeric_msg = 'Please enter Telephone only in numericals';
var fax_numeric_msg = 'Please enter Fax only in numericals';
var quantity_msg = 'Please enter Quantity';
var quantity_numeric_msg = 'Please enter Quantity only in numericals';
var quantity_proper_msg = 'Please enter Proper';
var  other_profile_msg ='You have chosen "other" under profile and left the information unfilled. Please fill in your profile details.';
var shopping_cart_empty_msg = 'There are no items present in your Shopping Cart';
//email format validation
function checkEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
		return (true)
	}
		alert(checkmail_msg)
		return (false)
}

//check the paramter is int ot not
function isInteger(s)
{   var i;
	for (i = 0; i < s.length; i++)
	{   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}
//this function use to trim the spaces in text field
function trimspace(str)
{		
	
	var len = str.length;

	if (len != 0)
	{
		for (var i=0;i<len;i++)
		{	
			if(str.indexOf(" ")==0)
				str=str.substring(1,len);
		}
		var strtrim = str;
		
		return strtrim;
	}
	else
	{
		return str;
	}
}

//this function use for add the product from shopping cart
function addShoppingCart(pID) {

	window.location = "imageinfo.php?pId="+pID+"&cartPID="+pID+"&add=1";
}

//this function use to remove the product from shopping cart

function removeShoppingCart(pID) {
	window.location = "imageinfo.php?pId="+pID+"&removePId="+pID+"&remove=1";
}

//this function use to checkout(going to shopping cart)
function checkout(pID) {
	
	//window.opener.document.location.reload()
	window.opener.document.location = "../cart/index.php?pId="+pID;
	self.close();	
}
//this function use to close the winddow
function closeWindow() {
	//window.opener.document.formName.hdnAction.value = str;
	window.close()
}
//this function use for update the checkout function
function updateQuantity(pid) {
	var id;
	id = document.getElementById("update"+pid).value;
	if(id == '') {
		alert(quantity_msg);
		document.getElementById("update"+pid).focus();
		return false;
	}
	if(id == '0' || id == '00') {
		alert(quantity_proper_msg);
		document.getElementById("update"+pid).focus();
		return false;
	}
	if(!isInteger(id)){
		alert(quantity_numeric_msg);
		document.getElementById("update"+pid).focus();
		return false;
	}

	formName.hiddenProductId.value = pid;
	formName.action = "index.php?update=1";
	formName.submit();	
}

//remove the product form shopping cart
function removeProductCheckOut(pID) {
	window.location = "index.php?RpId="+pID+"&removePId="+pID+"&removechekout=1";
}

//this function use for hide/show 
function show_hide_div(id) {
	var id_var = ""+id;
	if(id_var != 'undefined') {
		el = document.getElementById(id_var);
			if(id == 'packaging_file') {
				if (el.style.display == 'none')
				{
					el.style.display = '';
				} else {
					el.style.display = 'none';
				}
			} else {
				if (el.style.display == 'none')
				{
					el.style.display = '';
				}
			}
	}
}
function hide_div(id) {
	el = document.getElementById(id);
		if (el.style.display == '')
		{
			el.style.display = 'none';
		}
}

// this function use to validate the users order form
function contactOrderForm(actionParameter) {
	contactDetails.fullName.value = trimspace(contactDetails.fullName.value);
	if(contactDetails.fullName.value == '') {
		alert(name_msg);
		contactDetails.fullName.focus();
		return false;
	}
	contactDetails.companyName.value = trimspace(contactDetails.companyName.value);
	if(contactDetails.companyName.value == '') {
		alert(company_name_msg);
		contactDetails.companyName.focus();
		return false;
	}
	
	contactDetails.address.value = trimspace(contactDetails.address.value);
	if(contactDetails.address.value == '') {
		alert(address_msg);
		contactDetails.address.focus();
		return false;
	}
	contactDetails.telePhone.value = trimspace(contactDetails.telePhone.value);
	if(contactDetails.telePhone.value == '') {
		alert(phone_msg);
		contactDetails.telePhone.focus();
		return false;
	}
	
	contactDetails.email.value = trimspace(contactDetails.email.value);
	if(contactDetails.email.value == '') {
		alert(email_msg);
		contactDetails.email.focus();
		return false;
	}
	
	if(!checkEmail(contactDetails.email.value)) {
		contactDetails.email.focus();
		return false;
	}

	el = document.getElementById('other');

	if(el.style.display == '') {
		if(document.getElementById("other_id").value == '') {
			alert(other_profile_msg);
			document.getElementById("other_id").focus();
			return false;
			
		}
	}

	contactDetails.action = "index.php?actionParameter="+actionParameter; 
	contactDetails.submit();	
}

//this function use to contact order form
function orderDetailsForms() {
	document.getElementById('orderQuantity').value = trimspace(document.getElementById('orderQuantity').value);
	if(document.getElementById('orderQuantity').value == '') {
		alert("Please enter the required order quantity.");
		document.getElementById('orderQuantity').focus();
		return false;
	}
	document.getElementById('cardsPerSet').value = trimspace(document.getElementById('cardsPerSet').value);
	if(document.getElementById('cardsPerSet').value == '') {
		alert("Please enter the required amount of cards per set.");
		document.getElementById('cardsPerSet').focus();
		return false;
	}
		
	orderFormDetails.action = "index.php?actionParameter=orderDetails"; 
	orderFormDetails.submit();	
	//window.location = "index.php?actionParameter=orderDetails";
}

//this function use dor card details 
function cardDetailsForm() {

		
	/*if(document.getElementById('hiddenBackImage').value != 1) {
		if(cardsDetailsForm.number_of_colors_backs.value == '') {
		alert("You have upload Custom Backs file(s). Please enter Custom Backs Number of Colors.");
		cardsDetailsForm.number_of_colors_backs.focus();
		return false;
		}
	}*/
	cardsDetailsForm.number_of_colors_backs.value = trimspace(cardsDetailsForm.number_of_colors_backs.value);
	if(cardsDetailsForm.number_of_colors_backs.value != '') {
		if(!isInteger(cardsDetailsForm.number_of_colors_backs.value)) {
		alert("Please enter Custom Backs Number of Colors only in numericals");
		cardsDetailsForm.number_of_colors_backs.focus();
		return false;
		}
	}
	
	cardsDetailsForm.number_of_colors_fonts.value = trimspace(cardsDetailsForm.number_of_colors_fonts.value);
	if(cardsDetailsForm.number_of_colors_fonts.value != '') {
		if(!isInteger(cardsDetailsForm.number_of_colors_fonts.value)) {
		alert("Please enter Custom Fronts Number of Colors only in numericals");
		cardsDetailsForm.number_of_colors_fonts.focus();
		return false;
		}
	}

	if(cardsDetailsForm.coating.value == '') {
		alert("Please select the kind of coating required.");
		cardsDetailsForm.coating.focus();
		return false;
	}
	
	cardsDetailsForm.action = "index.php?actionParameter=cardDetails"; 
	cardsDetailsForm.submit();
//window.location = "index.php?actionParameter=cardDetails";
}

//this function use for the packaging details validations
function packaingDetailsFormfun() {
	

	if(packagingDetailsForm.number_of_colors_packaging.value != '') {
		if(!isInteger(packagingDetailsForm.number_of_colors_packaging.value)) {
		alert("Please enter Custom Designs on Packaging Number of Colors only in numericals");
		packagingDetailsForm.number_of_colors_packaging.focus();
		return false;
		}
	}

	packagingDetailsForm.action = "index.php?actionParameter=packagingdetails"; 
	packagingDetailsForm.submit();

}
function preview() {
	var checkFlag = false;
	var conatctAlert = document.getElementById('contactDetails').value;
	var orderAlert = document.getElementById('oderDetails').value;
	var cardAlert = document.getElementById('cardDetails').value;
	if(conatctAlert == '' && orderAlert == '' && cardAlert== '') {
		alert('Please fill in your "Contact Details", "Order Details" & "Card Details"');
		checkFlag = false;
		return false;
	} else if(conatctAlert != '' && orderAlert == '' && cardAlert == '') {
		alert('Please fill in your "Order Details" & "Card Details"');
		checkFlag = false;
		return false;
	}else if(conatctAlert == '' && orderAlert != '' && cardAlert == '') {
		alert('Please fill in your "Contact Details" & "Card Details"');
		checkFlag = false;
		return false;
	}else if(conatctAlert == '' && orderAlert == '' && cardAlert != '') {
		alert('Please fill in your "Contact Details" & "Order Details"');
		checkFlag = false;
		return false;
	}
	if(document.getElementById('contactDetails').value == '') {
		alert(' Please fill in your contact details by clicking on "Contact Details".');
		checkFlag = false;
		return false;
	} else {
		checkFlag = true;
		//return true;
	}
	if(document.getElementById('oderDetails').value == '') {
		alert(' Please fill in your order details by clicking on "Order Details".');
		checkFlag = false;
		return false;
	} else {
		checkFlag = true;
		//return true;
	}
	if(document.getElementById('cardDetails').value == '') {
		alert(' Please fill in your card details by clicking on "Card Details".');
		checkFlag = false;
		return false;
	} else {
		checkFlag = true;
		//return true;
	}
	/*if(document.getElementById('packagingDetails').value == '') {
		alert(' Please fill in your packaging details by clicking on "4. Packaging Details".');
		checkFlag = false;
		return false;
	} else {
		checkFlag = true;
		//return true;
	}
	*/
	if(checkFlag == true) {
		window.location = "index.php?actionParameter=preivew";
	}
}

//this function use to upload the file
function uploadfile(actionPrameter,backtoFile,msg_para) {

/*if(document.getElementById('contactDetails').value == '') {
		alert('Please enter a Contact Details first and then Upload file');
		return false;
	} //else {
*/
		if(msg_para == 'back') {
			if(cardsDetailsForm.designfilebacks_1.value == '') {
				alert("Please Browse Upload file");
				cardsDetailsForm.designfilebacks_1.focus();
				return false;
			}
			
			if(cardsDetailsForm.designfilebacks_1.value != '') {
			var words = cardsDetailsForm.designfilebacks_1.value;
		
			//var words = theForm.meeting_upload.value;
			var start = words.length-3;
		
			outp = words.substring(start,words.length) 
			outp = outp.toLowerCase();
			if((outp == "tif") || (outp == "eps") || (outp == "jpg") || (outp == "gif") || (outp == "pdf") || (outp == "ai") || (outp == "dcs2")) {
				//return true;
			} else {
				alert('Please browse TIF, EPS, JPEG/JPG, GIF, CDR, PDF, AI, DCS2, Post Scripts Composite, Post Script Re-Separated format only');
				cardsDetailsForm.designfilebacks_1.focus();
				return false;
			}
			
		}

		}

		if(msg_para == 'fronts') {
			
			if(cardsDetailsForm.designfilefronts_1.value == '') {
				alert("Please Browse Upload file");
				cardsDetailsForm.designfilefronts_1.focus();
				return false;
			}

			if(cardsDetailsForm.designfilefronts_1.value != '') {
				var words = cardsDetailsForm.designfilefronts_1.value;
			
				//var words = theForm.meeting_upload.value;
				var start = words.length-3;
			
				outp = words.substring(start,words.length) 
				outp = outp.toLowerCase();   
				if((outp == "tif") || (outp == "eps") || (outp == "jpg") || (outp == "gif") || (outp == "pdf") || (outp == "ai") || (outp == "dcs2")) {
				//return true;
				} else {
					alert('Please browse TIF, EPS, JPEG/JPG, GIF, CDR, PDF, AI, DCS2, Post Scripts Composite, Post Script Re-Separated format only');
					cardsDetailsForm.designfilefronts_1.focus();
					return false;
				} 
				
				}
		}

		//window.location = "index.php?actionParameter="+actionPrameter;
		cardsDetailsForm.action = "index.php?actionParameter="+actionPrameter+"&backTofile"+backtoFile+"&fileAddPara="+msg_para; 
		cardsDetailsForm.submit();
	//}
}
// this function use for upload file in Packaging deisgn cards
function uploadfilePackaging(actionPrameter,backtoFile,msg_para) {
	
	var chkflag = false;
	/*if(document.getElementById('contactDetails').value == '') {
		alert('Please enter a Contact Details first and then Upload file');
		return false;
	} else {
*/
			if(packagingDetailsForm.packagingdesignfile_1.value == '') {
				alert("Please Browse Upload file");
				packagingDetailsForm.packagingdesignfile_1.focus();
				chkflag = true;
				return false;
			} 

			
		if(packagingDetailsForm.packagingdesignfile_1.value  != '') {
			var words = packagingDetailsForm.packagingdesignfile_1.value ;
		
			//var words = theForm.meeting_upload.value;
			var start = words.length-3;
		
			outp = words.substring(start,words.length) 
			outp = outp.toLowerCase();
			if((outp == "tif") || (outp == "eps") || (outp == "jpg") || (outp == "gif") || (outp == "pdf") || (outp == "ai") || (outp == "dcs2")) {
				//return true;
			} else {
				alert('Please browse TIF, EPS, JPEG/JPG, GIF, CDR, PDF, AI, DCS2, Post Scripts Composite, Post Script Re-Separated format only');
				packagingDetailsForm.packagingdesignfile_1.focus();
				return false;
			} 
			 chkflag = true;
		}

		if( chkflag == true) {
			packagingDetailsForm.action = "index.php?actionParameter="+actionPrameter+"&backTofile"+backtoFile+"&fileAddPara="+msg_para; 
			packagingDetailsForm.submit();
		}
	//}
}

function resetVal(resetValue) {
	if(resetValue == 'contact') {
		window.document.contactDetails.reset();  
	} else if(resetValue == 'order') {
		window.document.orderFormDetails.reset(); 
	}else if(resetValue == 'card') {
		window.document.cardsDetailsForm.reset(); 
	}else if(resetValue == 'packaging') {
		window.document.packagingDetailsForm.reset(); 
	}
}

