// JavaScript Document

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function dispsprod(str)
{
	window.location.href="sval.php?action=sc&id="+str;
}

function dispsproddet(str)
{
	window.location.href="sval.php?action=sp&id="+str;
}

//Calculate total amount, based on selected fields and display in product detail page.
function fnajaxcart(fprodid)
{ 
	var Count = 0;
	var txtprodid 	= "txtprodid"+fprodid;
	var chketch		= "chketch"+fprodid;
	var chketchlast	= "chketchlast"+fprodid;	
	var chkvinyl	= "chkvinyl"+fprodid;	
	var chkwamt		= "chkwamt"+fprodid;
	var chkwtamt	= "chkwtamt"+fprodid;
	var txtprodqty	= "txtprodqty"+fprodid;
	var chkwtcolor1	= "chkwtcolor1"+fprodid;
	var chkwtcolor2	= "chkwtcolor2"+fprodid;
	var chkwtcolor3	= "chkwtcolor3"+fprodid;
	var chkcustomclr= "chkcustomclr"+fprodid;
	var etch		= "etch"+fprodid;
	var podqtyerrmsg = "podqtyerrmsg"+fprodid;
	var divtotalamt	 = "divtotalamt"+fprodid;
	
	var prodid 	= $("#"+txtprodid).val();
	var etch 	= $("#"+chketch).is(":checked"); 
	var etchlast= $("#"+chketchlast).is(":checked"); 
	var vinyl 	= $("#"+chkvinyl).is(":checked"); 	
	var wood 	= $("#"+chkwamt).is(":checked");
	var woodtop = $("#"+chkwtamt).is(":checked");
	var prodqty = $("#"+txtprodqty).val();
	var gcolor  = $("#"+chkwtcolor1).is(":checked");
	var wcolor  = $("#"+chkwtcolor2).is(":checked");
	var bcolor  = $("#"+chkwtcolor3).is(":checked");	
	var custcolor = $("#"+chkcustomclr).is(":checked");

	if (prodqty == "" || prodqty <= 0)
	{
		$("#"+podqtyerrmsg).html("Please enter the Quantity");
		$("#"+podqtyerrmsg).css("color","red");
		Count = 1;
	}
	else if (prodqty > 0)
	{
		$("#"+podqtyerrmsg).html("");
	}
	
	if (etch == true)
	{
		etch = 1;	
	}
	else if (etch == false)
	{
		etch = 0;
	}
	
	if (etchlast == true)
	{
		etchlast = 1;	
	}
	else if (etchlast == false)
	{
		etchlast = 0;
	}
	
	if (vinyl == true)
	{
		vinyl = 1;	
	}
	else if (vinyl == false)
	{
		vinyl = 0;
	}

	if (wood == true)
	{
		wood = 1;
		if (gcolor == true)
			gcolor = "Golden Oak";
		else if (gcolor == false)
			gcolor = "";
			
		if (wcolor == true)
			wcolor = "Walnut";
		else if (wcolor == false)
			wcolor = "";

		if (bcolor == true)
			bcolor = "Black Cherry";
		else if (bcolor == false)
			bcolor = "";
		
		if (custcolor == true)
			custcolor = "Custom Color";
		else if (custcolor == false)
			custcolor = "";
		
	}
	else if (wood == false)
	{
		wood = 0;
		if (gcolor == false)
			gcolor = "";
			
		if (wcolor == false)
			wcolor = "";

		if (bcolor == false)
			bcolor = "";
		
		if (custcolor == false)
			custcolor = "";
	}
	
	if (woodtop == true)
	{
		woodtop = 1;
	}
	else if (woodtop == false)
	{
		woodtop = 0;
	}
	
	if (Count == 0)
	{
		$.ajax({
		type: "POST",
		url: "mod_cart.php",
		data: "action=ajaxcart&prodid="+prodid+"&etch="+etch+"&etchlast="+etchlast+"&vinyl="+vinyl+"&wood="+wood+"&woodtop="+woodtop+"&gcolor="+gcolor+"&wcolor="+wcolor+"&bcolor="+bcolor+"&custcolor="+custcolor+"&prodqty="+prodqty,
		success:function(msg)
		{
			//alert (msg);
			if (msg == 0)
			{
				$("#"+podqtyerrmsg).html("Could not add into Cart.");
				$("#"+podqtyerrmsg).css("color","red");
			}
			else // if (msg == 1)
			{
				$("#"+divtotalamt).html("Total Amount : $ "+msg);
			}
		}
		});
		return true;	
	}
	else
	{
		return false;	
	}
}


function fncart(fprodid)
{
	var Count = 0;
	var txtprodid 	= "txtprodid"+fprodid;
	var chketch		= "chketch"+fprodid;
	var chketchlast	= "chketchlast"+fprodid;	
	var chkvinyl	= "chkvinyl"+fprodid;	
	var chkwamt		= "chkwamt"+fprodid;
	var chkwtamt	= "chkwtamt"+fprodid;
	var txtprodqty	= "txtprodqty"+fprodid;
	var chkwtcolor1	= "chkwtcolor1"+fprodid;
	var chkwtcolor2	= "chkwtcolor2"+fprodid;
	var chkwtcolor3	= "chkwtcolor3"+fprodid;
	var chkcustomclr= "chkcustomclr"+fprodid;
	var etch		= "etch"+fprodid;
	var podqtyerrmsg = "podqtyerrmsg"+fprodid;
	
	var prodid 	= $("#"+txtprodid).val();
	var etch 	= $("#"+chketch).is(":checked"); 
	var etchlast= $("#"+chketchlast).is(":checked"); 
	var vinyl 	= $("#"+chkvinyl).is(":checked"); 	
	var wood 	= $("#"+chkwamt).is(":checked");
	var woodtop = $("#"+chkwtamt).is(":checked");
	var prodqty = $("#"+txtprodqty).val();
	var gcolor  = $("#"+chkwtcolor1).is(":checked");
	var wcolor  = $("#"+chkwtcolor2).is(":checked");
	var bcolor  = $("#"+chkwtcolor3).is(":checked");	
	var custcolor = $("#"+chkcustomclr).is(":checked");

	if (prodqty == "" || prodqty <= 0)
	{
		$("#"+podqtyerrmsg).html("Please enter the Quantity");
		$("#"+podqtyerrmsg).css("color","red");
		Count = 1;
	}
	else if (prodqty > 0)
	{
		$("#"+podqtyerrmsg).html("");
	}
	
	if (etch == true)
	{
		etch = 1;	
	}
	else if (etch == false)
	{
		etch = 0;
	}
	
	if (etchlast == true)
	{
		etchlast = 1;	
	}
	else if (etchlast == false)
	{
		etchlast = 0;
	}
	
	if (vinyl == true)
	{
		vinyl = 1;	
	}
	else if (vinyl == false)
	{
		vinyl = 0;
	}


	if (wood == true)
	{
		wood = 1;
		if (gcolor == true)
			gcolor = "Golden Oak";
		else if (gcolor == false)
			gcolor = "";
			
		if (wcolor == true)
			wcolor = "Walnut";
		else if (wcolor == false)
			wcolor = "";

		if (bcolor == true)
			bcolor = "Black Cherry";
		else if (bcolor == false)
			bcolor = "";
		
		if (custcolor == true)
			custcolor = "Custom Color";
		else if (custcolor == false)
			custcolor = "";
		
	}
	else if (wood == false)
	{
		wood = 0;
		if (gcolor == false)
			gcolor = "";
			
		if (wcolor == false)
			wcolor = "";

		if (bcolor == false)
			bcolor = "";
		
		if (custcolor == false)
			custcolor = "";
	}
	
	if (woodtop == true)
	{
		woodtop = 1;
	}
	else if (woodtop == false)
	{
		woodtop = 0;
	}
	
	if (Count == 0)
	{
		$.ajax({
		type: "POST",
		url: "mod_cart.php",
		data: "action=addcart&prodid="+prodid+"&etch="+etch+"&etchlast="+etchlast+"&vinyl="+vinyl+"&wood="+wood+"&woodtop="+woodtop+"&gcolor="+gcolor+"&wcolor="+wcolor+"&bcolor="+bcolor+"&custcolor="+custcolor+"&prodqty="+prodqty,
		success:function(msg)
		{
			//alert (msg);
			if (msg == 0)
			{
				$("#"+podqtyerrmsg).html("Could not add into Cart.");
				$("#"+podqtyerrmsg).css("color","red");
			}
			else // if (msg == 1)
			{
				$("#"+podqtyerrmsg).html("Cart has been updated.");
				$("#"+podqtyerrmsg).css("color","green");
				$("#"+txtprodqty).val("");
				$("#"+chketch).removeAttr("checked");
				$("#"+chkwamt).removeAttr("checked");
				$("#"+chkwtamt).removeAttr("checked");
				$("#divcart").html(msg);
				//$("#divviewcart").html(msg);
			}
		}
		});
		
		
		return true;	
	}
	else
	{
		return false;	
	}
}


//Remove products from Cart
function fnremovecart(cartid)
{
		$.ajax({
		type: "POST",
		url: "mod_cart.php",
		data: "action=delcart&cartid="+cartid,
		success:function(msg)
		{
			$("#cartmsg").html("Cart has been updated.");
			$("#cartmsg").css("color","green");
			$("#divcart").html(msg);
		}
		});
	return true;
}

//Checkout
function fncheckout()
{
	window.location.href="checkout.php";	
}


//Customer Login validation
function LoginValidation(from)
{	
	var username = jQuery.trim($("#username").val());
	var pwd		 = jQuery.trim($("#password").val());
	
	$("#generrmsg").html("");
	$("#usererrmsg").html("");
	
	if (username != "" && pwd != "") 
	{	
		$('#btnlogin').attr('disabled', true);					
		$("#statusmsg").html("Loading...");
		$("#statusmsg").css("color","white");
		$.ajax({
		type: "POST",
		url: "mod_custreg.php",
		data: "action=checkCustLogin&log="+username+"&pwd="+pwd,
		success: function(msg)
			{ 
				//alert (msg);
				if (msg == 0) 
				{
					$("#statusmsg").html("");
					$("#usererrmsg").html("");
					$("#pwderrmsg").html("");
					$("#generrmsg").html("Account does not exists!.");
					$("#generrmsg").css("color", "red");
					$('#btnlogin').attr('disabled', false);
				} 
				else 
				{
					$("#statusmsg").html("");
					//window.location.href = window.location.href;
					window.location.href = 'viewcart.php';
					$('#btnlogin').attr('disabled', false);										
				}
			}
		});
		
	} 
			
	if(username == "" && pwd == "") 
	{
		$("#usererrmsg").html("Please enter the E-Mail Address");
		$("#usererrmsg").css("color", "red");
		$("#pwderrmsg").html("Please enter the Password");
		$("#pwderrmsg").css("color", "red");
		$("#generrmsg").html("");
	}
	if(username == "" && pwd != "") 
	{
		$("#usererrmsg").html("Please enter the E-Mail Address");
		$("#usererrmsg").css("color", "red");
		$("#pwderrmsg").html('');
		$("#generrmsg").html("");
	}
	if(username != "" && pwd == "") 
	{
		$("#pwderrmsg").html("Please enter the Password");
		$("#pwderrmsg").css("color", "red");
		$("#usererrmsg").html('');
		$("#generrmsg").html("");		
	}
} /* Eof - LoginValidation*/


//Customer Login validation
function CustRegValidation(from)
{	
	var Count = 0;
	var firstname 	= jQuery.trim($("#firstname").val());
	var lastname 	= jQuery.trim($("#lastname").val());	
	var cemail 		= jQuery.trim($("#cemail").val());	
	var pwd		 	= jQuery.trim($("#cpassword").val());
	var terms 		= $("#chkterms").is(":checked");


	if(firstname == "") 
	{
		$("#fnameerrmsg").html("Please enter the First Name");
		$("#fnameerrmsg").css("color", "red");
		Count = 1;
	}
	else
	{
		$("#fnameerrmsg").html("");		
	}
	if(lastname == "") 
	{
		$("#lnameerrmsg").html("Please enter the Last Name");
		$("#lnameerrmsg").css("color", "red");
		Count = 1;
	}
	else
	{
		$("#lnameerrmsg").html("");
	}
	var validemail = isEmail(cemail);

	if(cemail == "" || validemail == false) 
	{
		$("#cusererrmsg").html("Please enter the Valid E-Mail Address");
		$("#cusererrmsg").css("color", "red");
		Count = 1;
	}
	else
	{
		$("#cusererrmsg").html("");
	}
	
	if(pwd == "") 
	{
		$("#cpwderrmsg").html("Please enter the Password");
		$("#cpwderrmsg").css("color", "red");
		Count = 1;
	}
	else
	{
		$("#cpwderrmsg").html("");		
	}
	
	if(terms == false) 
	{
		$("#termserrmsg").html("Please accept the terms and conditions.");
		$("#termserrmsg").css("color", "red");
		Count = 1;
	}
	else
	{
		$("#termserrmsg").html("");		
	}
	
	if (Count == 0 && from == 'submit') 
	{		
		$.ajax({
		type: "POST",
		url: "mod_custreg.php",
		data: "action=checkCustReg&firstname="+firstname+"&lastname="+lastname+"&cemail="+cemail+"&pwd="+pwd,
		success: function(msg)
			{ 
				//alert (msg);
				if (msg == "Exists0") 
				{
					$("#cgenerrmsg").html("Account already exists!.");
					$("#cgenerrmsg").css("color", "red");
				} 
				else if (msg == "cartempty0")
				{
					$("#firstname").val("");
					$("#lastname").val("");
					$("#cemail").val("");
					$("#cpassword").val("");
					$("#chkterms").removeAttr("checked");
					$("#cgenerrmsg").html("Account has been created.");
					$("#cgenerrmsg").css("color", "green");
					
					setTimeout(function() { 
					window.location.href="index.php";
					},2000);
					
				}
				else if (msg == "cart0")
				{
					$("#firstname").val("");
					$("#lastname").val("");
					$("#cemail").val("");
					$("#cpassword").val("");
					$("#chkterms").removeAttr("checked");
					$("#cgenerrmsg").html("Account has been created.");
					$("#cgenerrmsg").css("color", "green");
					
					setTimeout(function() { 
					window.location.href="viewcart.php";
					},2000);
					
				}

			}
		});
		
	} 

	
}

//Customer Login validation
function CustUpdValidation(from)
{	
	var Count = 0;
	var firstname 	= jQuery.trim($("#firstname").val());
	var lastname 	= jQuery.trim($("#lastname").val());	
	var pwd		 	= jQuery.trim($("#cpassword").val());

	if(firstname == "") 
	{
		$("#fnameerrmsg").html("Please enter the First Name");
		$("#fnameerrmsg").css("color", "red");
		Count = 1;
	}
	else
	{
		$("#fnameerrmsg").html("");		
	}
	if(lastname == "") 
	{
		$("#lnameerrmsg").html("Please enter the Last Name");
		$("#lnameerrmsg").css("color", "red");
		Count = 1;
	}
	else
	{
		$("#lnameerrmsg").html("");
	}
	
/*	if(pwd == "") 
	{
		$("#cpwderrmsg").html("Please enter the Password");
		$("#cpwderrmsg").css("color", "red");
		Count = 1;
	}
	else
	{
		$("#cpwderrmsg").html("");		
	}*/
	
	if (Count == 0 && from == 'submit') 
	{		
		$.ajax({
		type: "POST",
		url: "mod_custreg.php",
		data: "action=checkCustUpd&firstname="+firstname+"&lastname="+lastname+"&pwd="+pwd,
		success: function(msg)
			{ 
				//alert (msg);
				$("#firstname").val("");
				$("#lastname").val("");
				$("#cpassword").val("");
				$("#chkterms").removeAttr("checked");
				$("#cgenerrmsg").html("Profile has been updated.");
				$("#cgenerrmsg").css("color", "green");
				
				setTimeout(function() {
					  window.location.href = "index.php";
					}, 1000);
				
			}
		});
		
	} 

	
}

//Checkout validation
function checkout_valid(from)
{
	var Count = 0;
	var s_name		= jQuery.trim($("#txtc_name").val());
	var s_cpname	= jQuery.trim($("#txtc_cpyname").val());
	var s_stradd	= jQuery.trim($("#txtc_stradd").val());
	var s_city		= jQuery.trim($("#txtc_city").val());
	var s_state		= jQuery.trim($("#txtc_state").val());
	var s_zip		= jQuery.trim($("#txtc_zip").val());
	var s_ctry		= jQuery.trim($("#txtc_ctry").val());
	var s_email		= jQuery.trim($("#txtc_email").val());
	var s_pho		= jQuery.trim($("#txtc_phone").val());
	var s_fax		= jQuery.trim($("#txtc_fax").val());
	var b_name		= jQuery.trim($("#txtb_name").val());
	var b_cpname	= jQuery.trim($("#txtb_cpyname").val());
	var b_stradd	= jQuery.trim($("#txtb_stradd").val());
	var b_city		= jQuery.trim($("#txtb_city").val());
	var b_state		= jQuery.trim($("#txtb_state").val());
	var b_zip		= jQuery.trim($("#txtb_zip").val());
	var b_ctry		= jQuery.trim($("#txtb_ctry").val());
	var b_email		= jQuery.trim($("#txtb_email").val());	
	var b_pho		= jQuery.trim($("#txtb_phone").val());
	var b_fax		= jQuery.trim($("#txtb_fax").val());
	var paycheck 	= $("#radpay1").is(":checked");
	var paypon 		= $("#radpay2").is(":checked");
	var paycc 		= $("#radpay3").is(":checked");	
	var western		= $("#radpay4").is(":checked");		
	var payponum	= $("#txtponum").val();
	var ccardtype	= $("#selcardtype option:selected").val();
	var ccname		= jQuery.trim($("#txtcholdername").val());
	var ccnumber	= jQuery.trim($("#txtccnumber").val());
	var ccmonth		= $("#selmonth option:selected").val();
	var ccyear		= $("#selyear option:selected").val();
	var cccode 		= jQuery.trim($("#txtccseccode").val());
	var splins		= jQuery.trim($("#txtasplins").val());

	if (s_name == "")
	{
		$("#scnameerrmsg").html("Please enter the Name");
		$("#scnameerrmsg").css("color","red");
		Count = 1;
	}
	else
	{
		$("#scnameerrmsg").html("");	
	}
	
	if (s_cpname == "")
	{
		$("#scmpnameerrmsg").html("Please enter the Company Name");
		$("#scmpnameerrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#scmpnameerrmsg").html("");	
	}

	if (s_stradd == "")
	{
		$("#saddrerrmsg").html("Please enter the Street Address");
		$("#saddrerrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#saddrerrmsg").html("");	
	}
	
	if (s_city == "")
	{
		$("#scityerrmsg").html("Please enter the City");
		$("#scityerrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#scityerrmsg").html("");	
	}	

	if (s_state == "")
	{
		$("#sstateerrmsg").html("Please enter the State");
		$("#sstateerrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#sstateerrmsg").html("");	
	}	

	if (s_zip == "")
	{
		$("#sziperrmsg").html("Please enter the Zipcode");
		$("#sziperrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#sziperrmsg").html("");	
	}	
	
	if (s_ctry == "")
	{
		$("#sctryerrmsg").html("Please enter the Country");
		$("#sctryerrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#sctryerrmsg").html("");	
	}

	var svalidemail = isEmail(s_email);

	if(s_email == "" || svalidemail == false) 
	{
		$("#semailerrmsg").html("Please enter the valid E-Mail Address");
		$("#semailerrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#semailerrmsg").html("");	
	}
	
	if (s_pho == "")
	{
		$("#sphoerrmsg").html("Please enter the Phone");
		$("#sphoerrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#sphoerrmsg").html("");	
	}


//Billing Information
	if (b_name == "")
	{
		$("#bcnameerrmsg").html("Please enter the Name");
		$("#bcnameerrmsg").css("color","red");
		Count = 1;
	}
	else
	{
		$("#bcnameerrmsg").html("");	
	}
	
	if (b_cpname == "")
	{
		$("#bcmpnameerrmsg").html("Please enter the Company Name");
		$("#bcmpnameerrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#bcmpnameerrmsg").html("");	
	}

	if (b_stradd == "")
	{
		$("#baddrerrmsg").html("Please enter the Street Address");
		$("#baddrerrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#baddrerrmsg").html("");	
	}
	
	if (b_city == "")
	{
		$("#bcityerrmsg").html("Please enter the City");
		$("#bcityerrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#bcityerrmsg").html("");	
	}	

	if (b_state == "")
	{
		$("#bstateerrmsg").html("Please enter the State");
		$("#bstateerrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#bstateerrmsg").html("");	
	}	

	if (b_zip == "")
	{
		$("#bziperrmsg").html("Please enter the Zipcode");
		$("#bziperrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#bziperrmsg").html("");	
	}	
	
	if (b_ctry == "")
	{
		$("#bctryerrmsg").html("Please enter the Country");
		$("#bctryerrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#bctryerrmsg").html("");	
	}

	var bvalidemail = isEmail(b_email);

	if(b_email == "" || bvalidemail == false) 
	{
		$("#bemailerrmsg").html("Please enter the valid E-Mail Address");
		$("#bemailerrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#bemailerrmsg").html("");	
	}
	
	if (b_pho == "")
	{
		$("#bphoerrmsg").html("Please enter the Phone");
		$("#bphoerrmsg").css("color","red");
		Count = 1;		
	}
	else
	{
		$("#bphoerrmsg").html("");	
	}
	


	$('#btncheckout').attr('disabled', true);
	//$("#loading").html("<img src='images/loading.gif' />");
	$("#loading").html("Please wait....");
	
	if (paycheck == false && paypon == false && paycc == false && western == false)
	{
		$("#payerrmsg").html("Please select any one of payment mode.");
		$("#payerrmsg").css("color","red");
		Count = 1;
	}
	else
	{
		$("#payerrmsg").html("");
	}

	if (paycheck == false)
		paycheck = 0;
	else if (paycheck == true)
		paycheck = 1;

	if (western == false)
		western = 0;
	else if (western == true)
		western = 1;
		
	if (paypon == false)
	{
		paypon = 0;
		payponum = "";
	}
	else if (paypon == true)
	{	paypon = 1;		}
	
	if (paycc == false)
	{
		paycc 		= 0;
		ccname 		= "";
		ccholder 	= "";
		ccmonth 	= "";
		ccyear 		= "";
		cccode 		= "";
	}
	else if (paycc == true)
	{
		paycc = 1;
	}

	if (paycc == 1)
	{
		//Checking the credit card type
		if (ccardtype == "")
		{
			$("#ccarderrmsg").html("Please select Credit Card Type.");
			$("#ccarderrmsg").css("color","red");
			Count = 1;	
		}
		else
		{
			$("#ccarderrmsg").html("");		
		}
		
		if (ccname == "")
		{
			$("#ccnameerrmsg").html("Please enter Valid Credit Card Name.");
			$("#ccnameerrmsg").css("color","red");
			Count = 1;	
		}
		else
		{
			$("#ccnameerrmsg").html("");		
		}
		
		if (ccnumber == "")
		{
			$("#ccnumerrmsg").html("Please enter Valid Credit Card Number.");
			$("#ccnumerrmsg").css("color","red");
			Count = 1;	
		}
		else
		{
			$("#ccnumerrmsg").html("");		
		}

		if (ccmonth == "" || ccyear == "")
		{
			$("#ccexpdateerrmsg").html("Please select valid Month and Year.");
			$("#ccexpdateerrmsg").css("color","red");
			Count = 1;	
		}
		else
		{
			$("#ccexpdateerrmsg").html("");		
		}

		if (cccode == "")
		{
			$("#ccseccodeerrmsg").html("Please etner valid Security Code.");
			$("#ccseccodeerrmsg").css("color","red");
			Count = 1;	
		}
		else
		{
			$("#ccseccodeerrmsg").html("");		
		}
		
	}

	if (Count == 0)
	{
		$.ajax({
		type: "POST",
		url: "mod_checkout.php",
		data: "action=checkout&s_name="+s_name+"&s_cpname="+s_cpname+"&s_stradd="+s_stradd+"&s_city="+s_city+"&s_state="+s_state+"&s_zip="+s_zip+"&s_ctry="+s_ctry+"&s_email="+s_email+"&s_pho="+s_pho+"&s_fax="+s_fax+"&b_name="+b_name+"&b_cpname="+b_cpname+"&b_stradd="+b_stradd+"&b_city="+b_city+"&b_state="+b_state+"&b_zip="+b_zip+"&b_ctry="+b_ctry+"&b_email="+b_email+"&b_pho="+b_pho+"&b_fax="+b_fax+"&ccardtype="+ccardtype+"&paycheck="+paycheck+"&western="+western+"&paypon="+paypon+"&payponum="+payponum+"&paycc="+paycc+"&ccname="+ccname+"&ccnumber="+ccnumber+"&ccmonth="+ccmonth+"&ccyear="+ccyear+"&cccode="+cccode+"&splins="+splins,

		success: function(msg)
			{ 
				//alert(msg);
				if (msg == 0) 
				{
					$("#loading").html("");
					$("#generrmsg").html("Could not confirm an Order!.");
					$("#generrmsg").css("color", "red");
					$('#btncheckout').attr('disabled', false);					
				}
				else if (msg == 2) 
				{
					$("#loading").html("");
					$("#generrmsg").html("Shopping cart is empty!.");
					$("#generrmsg").css("color", "red");
					$('#btncheckout').attr('disabled', false);
				}
				else 
				{
					$("#loading").html("");
					$("#generrmsg").html("Order has been confirmed.");
					$("#generrmsg").css("color", "green");
					window.location.href="sval.php?action=ty&ack="+msg;
					//window.location.href = "thankyou.php?ack="+msg;
				}
			}
		});

	}
	else
	{
		$('#loading').html("");
		$('#btncheckout').attr('disabled', false);
	}

}



function isEmail(email)
  {
    invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";
    for (i=0; i<invalidChars.length; i++) {
        badChar = invalidChars.charAt(i);
        if (email.indexOf(badChar,0) > -1) {
            return false;
        }
    }
    lengthOfEmail = email.length;
    if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) {
        return false;
    }
    Pos = email.indexOf("@",1);
    if (email.charAt(Pos + 1) == ".") {
        return false;
    }
    while ((Pos < lengthOfEmail) && ( Pos != -1)) {
        Pos = email.indexOf(".",Pos);
        if (email.charAt(Pos + 1) == ".") {
            return false;
        }
        if (Pos != -1) {
            Pos++;
        }
    }
    atPos = email.indexOf("@",1);
    if (atPos == -1) {
        return false;
    }
    if (email.indexOf("@",atPos+1) != -1) {
        return false;
    }
    periodPos = email.indexOf(".",atPos);
    if (periodPos == -1) {
        return false;
    }
    if (periodPos+3 > email.length) {
        return false;
    }
    return true;
	}


//Customer Forgot Password
function forgotpass(from)
{	
	var cemail = jQuery.trim($("#username").val());

	if (cemail != "") 
	{	
		$('#btnforgot').attr('disabled', true);
		$("#cgenerrmsg").html("Please wait...");
		$("#cgenerrmsg").css("color", "white");
					
		$.ajax({
		type: "POST",
		url: "mod_custreg.php",
		data: "action=checkCustForgot&cemail="+cemail,
		success: function(msg)
			{ 
				//alert (msg);
				if (msg == 00) 
				{
					$("#usererrmsg").html("");
					$("#cgenerrmsg").html("");
					$("#generrmsg").html("Account does not exists!.");
					$("#generrmsg").css("color", "red");
					$('#btnforgot').attr('disabled', false);
				} 
				else if (msg == 01) 
				{
					//window.location.href = 'index.php';
					$("#username").val("");
					$("#cgenerrmsg").html("");					
					$("#usererrmsg").html("");
					$("#generrmsg").html("Reset Password link sent to your mail.");
					$("#generrmsg").css("color", "green");
					$('#btnforgot').attr('disabled', false);					
				}
			}
		});
		
	} 
			
	if(cemail == "") 
	{
		$("#usererrmsg").html("Please enter the Valid E-Mail Address");
		$("#usererrmsg").css("color", "red");
		$("#generrmsg").html("");
	}
} /* Eof - Forgot Password*/
	
	
//Customer Reset Password
function resetpass(from)
{	
	var Count = 0;
	var id = jQuery.trim($("#txtid").val());
	var pwd = jQuery.trim($("#password").val());	

	if(pwd == "") 
	{
		$("#usererrmsg").html("Please enter the Valid Password");
		$("#usererrmsg").css("color", "red");
		$("#generrmsg").html("");
		Count = 1;
	}

	if (pwd != "" && id != "" && Count == 0) 
	{	
		$.ajax({
		type: "POST",
		url: "mod_custreg.php",
		data: "action=checkCustResetPwd&id="+id+"&pwd="+pwd,
		success: function(msg)
			{ 
				//alert (msg);
				if (msg == 00) 
				{
					$("#usererrmsg").html("");
					$("#cgenerrmsg").html("");
					$("#generrmsg").html("Could not reset!.");
					$("#generrmsg").css("color", "red");
				} 
				else if (msg == 01) 
				{
					//window.location.href = 'index.php';
					$("#txtid").val("");
					$("#password").val("");					
					$("#cgenerrmsg").html("");					
					$("#usererrmsg").html("");
					$("#generrmsg").html("Password has updated.");
					$("#generrmsg").css("color", "green");

					setTimeout(function() {
					window.location.href="login.php";										
					},2000);
				}
			}
		});
		
	} 
			

} /* Eof - Reset Password*/
	
	
