// JavaScript Document	
function echeck(str)
	{
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID");
		   return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		    return false;
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		    return false;
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
 		 return true;					
	}
	
function changeImg(indexedImage)
	{
		document.getElementById("BigImg").src=indexedImage;
	}
	
function checkQty_details()
	{
	var frm = document.buy;
	var qty
	qty = "qty"+frm.product.value;
	if (eval("document.buy."+qty+".value") == "")
	{
		alert("Please enter Qty.");
		eval("document.buy."+qty+".focus()");
		return false;
	}
	
	if (isNaN(eval("document.buy."+qty+".value")))
	{
		alert("Please enter numeric value as Qty.");
		eval("document.buy."+qty+".focus()");
		return false;
	}	
	return true;	
}
	
	
function checkQty_cart(z) {
	var x=document.cartItem;
	qty=z*2;
	//alert(x.elements[qty].value);
	if(x.elements[qty].value=="") {
		alert("Quantity cannot be left blank");
		x.elements[qty].focus();
		x.elements[qty].value=1;
		//x.elements[qty].select();
		return;
	}
	if(isNaN(x.elements[qty].value)) {
		alert("Quantity entered is invalid.");
		x.elements[qty].value=1;
		x.elements[qty].focus();
		//x.elements[qty].select();
		return;
	}
	if(x.elements[qty].value<1) {
		alert("Quantity ordered cannot be less than 1.");
		x.elements[qty].value=1;
		x.elements[qty].focus();
		//x.elements[qty].select();
		return;
	}
	return;
}

 function submitForm(str) {
		var x=document.cartItem;
		if(str=="back") {			
			window.location.href="index.asp"
			return;
		}
		if(str=="up") {
			x.inEnd.value="update";
		}
		if(str=="ord") {		
			x.action = "view-cart.asp"
			x.inEnd.value="order";
		}
		x.submit();
	}
function checkQty(frm_,qty_)
	  {
		if (eval("document."+frm_+"."+qty_+".value") <= 0)
		{
			alert("Quantity ordered cannot be less than 1.");
			eval("document."+frm_+"."+qty_+".focus()");
			return false;
		}
		if (isNaN(eval("document."+frm_+"."+qty_+".value")))
		{
			alert("Please enter numeric value as Qty.");
			eval("document."+frm_+"."+qty_+".focus()");
			return false;
		}
		eval("document."+frm_+".submit()");
	 }
function formValidate() {
		var x=document.form1;
		if(x.email.value == "")
		{
			alert("Please enter your Email address.");
			x.email.focus();
			return false;
		}
		if ((x.email.value.length<5) || ((x.email.value.indexOf("@")==-1) ||(x.email.value.indexOf(".")==-1)))
		{
			alert ("Please enter a vaild Email address.");
			x.email.focus();
			return false;
		}
		//if(x.actionpage[0].checked) {
		//	x.action="shopRegform_n.asp";
		//}
		//else if(x.actionpage[1].checked) {
		//	x.action="shopLogin_n.asp";
		//}

		if(x.pass.value == "" && x.actionpage[1].checked)
		{
			alert("Please enter Password.");
			x.pass.focus();
			return false;
		}
		//return false;
		return true;
	}
	function isName() {
			var x=document.register;
			if(x.fname.value == "") {
				alert("Please enter your First Name.");
				x.fname.focus();
				return false;
			}
			if(x.lname.value == "") {
				alert("Please enter your Last Name.");
				x.lname.focus();
				return false;
			}
			return true;
		}
		
		function isPass() {
			var x=document.register;
			if(x.pass.value == "") {
				alert("Please enter Password.");
				x.pass.focus();
				return false;
			}
			if(x.pass.value.length<4) {
				alert("Password should not be less than 4 characters.");
				x.pass.focus();
				return false;
			}
			if(x.pass1.value=="") {
				alert("Please Retype Password.");
				x.pass1.focus();
				return false;
			}
			if((x.pass.value)!=(x.pass1.value)) {
				alert("Passwords typed do not match, please re-enter your passwords.");
				x.pass.value="";
				x.pass1.value="";
				x.pass.focus();
				return false;
			}
			return true;
		}//isPass()
	function RegformValidate() {
			//if ( !isName() || !isValidEmail() || !isPass() || !otherValidate()) {
			if ( !isName() || !isPass() || !otherValidate()) {
				return false;
			}
			return true;
		}
		
		function isEmail() {
			var x=document.register;
			var emailID=document.register.email;
			if ((emailID.value==null)||(emailID.value==""))
			{
			alert("Please Enter Email ID");
			emailID.focus();
			return false;
			}
			if (echeck(emailID.value)==false){
				emailID.value="";
				emailID.focus();
				return false;
			}
		
			return true;
		}
function otherValidate() {
			var x=document.register;
			if(x.address.value == "") {
				alert("Address field cannot be left blank.");
				x.address.focus();
				return false;
			}
			if(x.city.value == "") {
				alert("City field cannot be left blank.");
				x.city.focus();
				return false;
			}
			if(x.state.value == "") {
				alert("State/Province field cannot be left blank.");
				x.state.focus();
				return false;
			}
			if(x.zip.value == "") {
				alert("Zip code field cannot be left blank.");
				x.zip.focus();
				return false;
			}
			if(x.phone.value == "") {
				alert("Phone field cannot be left blank.");
				x.phone.focus();
				return false;
			}
			return true;
		}

function Regform_Validate() {
			//if ( !isName() || !isValidEmail() || !isPass() || !otherValidate()) {
			if ( !isName() || !isEmail() || !isPass() || !otherValidate()) {
				return false;
			}
			return true;
		}
		
		function isName_ship() {
			var x=document.register;
			if(x.fname.value == "") {
				alert("Please enter your First Name.");
				x.fname.focus();
				return false;
			}
			if(x.lname.value == "") {
				alert("Please enter your Last Name.");
				x.lname.focus();
				return false;
			}
			return true;
		}

		function otherValidate_ship() {
			var x=document.register;
			if(x.address.value == "") {
				alert("Address field cannot be left blank.");
				x.address.focus();
				return false;
			}
			if(x.city.value == "") {
				alert("City field cannot be left blank.");
				x.city.focus();
				return false;
			}
			if(x.state.value == "") {
				alert("State/Province field cannot be left blank.");
				x.state.focus();
				return false;
			}
			if(x.zip.value == "") {
				alert("State/Province field cannot be left blank.");
				x.zip.focus();
				return false;
			}
			if(x.phone.value == "") {
				alert("Phone field cannot be left blank.");
				x.phone.focus();
				return false;
			}
			return true;
		}

		function formValidate_ship() {
			if ( !isName_ship() || !otherValidate_ship()) {
				return false;
			}
			return true;
		}//formValidate()

		function shipValidate(val1) {
			var x=document.shipAddress
			x.custShipNum.value=val1
			x.mode.value="";
			x.submit();
		}//shipValidate()

		function shipDelete(val1) {
			var x=document.shipAddress
			x.custShipNum.value=val1;
			x.mode.value="delete";
			x.submit();
		}//shipValidate()
	
	function validate_search()
	{
		var x=document.xsearch;
		if(x.searchkeyword.value == "")
		{
			alert("Please enter keyword to search cards.");
			x.searchkeyword.focus();
			return false;
		}
		x.submit();
	}
