function update_Quantity()
{
//alert($('#quantity').val())	
//for($i=0;$i<$('#sessionCartId').lenght;$i++){
	var dataString="sessionCartId="+$('#sessionCartId').val()+"&quantity="+$('#quantity').val()+"&actions=update";
//}
//alert(dataString);

	$.ajax({ 
	 	
	  type: "POST",  
	  url: "updateQuantity.php",
	  data: dataString ,
	  success: function(response)
	  { 
			if(response=='success')
	  		{
			$("#quantityUpdated").html("Quantity Updated");
			$("#quantityUpdated").fadeOut(4000);
			}
	  }
	  	}); 
	return false;
}


/***********************************************************************************/
/*function orderSave1()
{

	var event_checked = $("#terms:checked").length; 
	
	if (event_checked == 0) 
	{ 
		alert("please check the terms and conditions")
		return false ;
	} 
	else if (event_checked == 1) 
		{ 
			orderSave1();
			
		}
	return false
}*/
/****************************************** validation for order **************************************************************/
function orderSave()
{



	//alert($("#terms").val())
$(".message1").hide();
 /*var newa=0;
 if($("#terms:checked").val()!=null)
	{
	   var newa=$("#terms:checked").val();
	
	 }*/

	 if($("#newaddress").val()=='2')
	{
			
		bothAddress();
		
	}
	else if($("#newaddress").val()=='1')
		{
		shippingAddress();
		
		//alert(email_check);
		}
		
		if($("#ssn").val()!='' && $("#city").val()!='' && $("#fname").val()!='' && $("#lname").val()!='' && $("#address").val()!='' && $("#postcode").val()!='' && $("#email").val()!='' && $("#phone").val()!='' && (emailchk($("#email").val()) == true) && (IsNumeric($("#phone").val()) == true) && (IsNumeric($("#ssn").val())==true))
		{
			//alert('dsfds');
	var event_checked = $("#terms:checked").length; 
	
	if(event_checked == 0) { 
	
	$('#formvalidation5').modal({
		close:false,
		position: ["30%",],
		overlayId:'confirmModalOverlay',
		containerId:'confirmModalContainer', 
		onShow: function (dialog) {
		$("#confirmModalContainer").height(150);
		
		$("#emptyternms").show();
		
		$('.yes').click(function () {
		$.modal.close();
	});
	
	}//
	});
		return false;
	
	} else
	{
		var rs='yes';
		//alert(rs);
		}
		
		
		}
		else
		{
			var rs='no';
			//alert(rs);
		}
		if($("#newaddress").val()=='2')
		{
		if($("#city1").val()!='' && $("#fname1").val()!='' && $("#lname1").val()!='' && $("#address1").val()!='' && $("#postcode1").val()!='')
		{
			
	var event_checked = $("#terms:checked").length; 
	
	if (event_checked == 0) 
	{ 
	
	$('#formvalidation5').modal({
	close:false,
	position: ["30%",],
	overlayId:'confirmModalOverlay',
	containerId:'confirmModalContainer', 
	onShow: function (dialog) {
	$("#confirmModalContainer").height(100);
	
	$("#emptyternms").show();
	
	$('.yes').click(function () {
	$.modal.close();
	});
	
	}//
	});
	return false;
	
	} else
	{
			var rs2='yes';
			}
			
		}
		else
		{
			var rs2='no';
			
		}
		}else if($("#newaddress").val()=='1')
		{
			if($("#ssn").val()!='' && $("#city").val()!='' && $("#fname").val()!='' && $("#lname").val()!='' && $("#address").val()!='' && $("#postcode").val()!='' && $("#email").val()!='' && $("#phone").val()!='' && (emailchk($("#email").val()) == true) && (IsNumeric($("#phone").val()) == true) && (IsNumeric($("#ssn").val())==true))
		{
			var rs='yes';
			var rs2='yes';
		}
		}
		if(rs=='yes' && rs2=='yes')
		{
			
			return true;
		}
	
return false;
}
/***********************************    Shippin And Billing Address Validation ********************************/
function bothAddress(){
	
	if( $("#ssn").val()=='' || $("#city").val()=='' || $("#fname").val()=='' || $("#lname").val()=='' || $("#address").val()=='' || $("#postcode").val()=='' || $("#email").val()=='' || $("#phone").val()=='' ||  $("#city1").val()=='' || $("#fname1").val()=='' || $("#lname1").val()=='' || $("#address1").val()=='' || $("#postcode1").val()=='') 
	{
	$('#formvalidation1').modal({
	close:false,
	position: ["30%",],
	overlayId:'confirmModalOverlay',
	containerId:'confirmModalContainer', 
	onShow: function (dialog) {
	$("#confirmModalContainer").height(380);
	/* shipping*/	
	if($("#fname").val()=='')
	{
	$("#emptyfname").show();
	}
	
	if($("#lname").val()=='')
	{
	$("#emptylname").show();
	}
	
	if($("#address").val()=='')
	{
	$("#emptyaddress").show();
	}
	
	if($("#ssn").val()=='')
	{
	$("#emptyssn").show();
	}
	
	if($("#ssn").val()!=""){
	
	var ssnvalid2=IsNumeric($("#ssn").val());
	if(ssnvalid2==false)
	{
	$("#validssn").show();
	}
	}
	
	if($("#postcode").val()=='')
	{
	$("#emptypostcode").show();
	}
	if($("#email").val()=='')
	{
	$("#emptyemail").show();
	}
	
	if($("#city").val()=='')
	{
	$("#emptycity").show();
	}
	
	
	
	if($("#email").val()!=""){
	
	var evalid1=emailchk($("#email").val());
	if(evalid1==false)
	{
	$("#validemail").show();
	}
	}
	
	if($('input[name=cartType]:checked').val()=="invoice") {
	if($("#phone").val()=='')
	{
	$("#emptyphone").show();
	}
	}
	else
	{
		//$("#phone").val('0');
		
	}
	if($("#phone").val()!=""){
	
	var pervalid2=IsNumeric($("#phone").val());
	if(pervalid2==false)
	{
	$("#validphone").show();
	}
	}
		
	/* billing*/	
		
	
	if($("#fname1").val()=='')
	{
	$("#emptyfname1").show();
	}
	
	
	if($("#lname1").val()=='')
	{
	$("#emptylname1").show();
	}
	
	if($("#address1").val()=='')
	{
	$("#emptyaddress1").show();
	}
	
	/*if($("#ssn1").val()=='')
	{
	$("#emptyssn1").show();
	}
	
	
	if($("#ssn1").val()!=""){
	
	var ssn1valid4=IsNumeric($("#ssn1").val());
	if(ssn1valid4==false)
	{
	$("#validssn1").show();
	}
	}
	
	
	if($("#email1").val()=='')
	{
	$("#emptyemail1").show();
	}*/
	
	if($("#postcode1").val()=='')
	{
	$("#emptypostcode1").show();
	}
	if($("#city1").val()=='')
	{
	$("#emptycity1").show();
	}
	
	
	
	/*if($("#email1").val()!=""){
	
	var evalid3=emailchk($("#email1").val());
	if(evalid3==false)
	{
	$("#validemail1").show();
	}
	}
	
	
	if($("#phone1").val()=='')
	{
	$("#emptyphone1").show();
	}
	
if($("#phone1").val()!=""){
	
	var pervalid4=IsNumeric($("#phone1").val());
	if(pervalid4==false)
	{
	$("#validphone1").show();
	}
	}*/
	
	
	$('.yes').click(function () {
		$.modal.close();
			});
	
			}//
	});
				

}
else if($("#ssn").val()!='' && $("#city").val()!='' && $("#fname").val()!='' && $("#lname").val()!='' && $("#address").val()!='' && $("#postcode").val()!='' && $("#email").val()!='' && $("#phone").val()!='' && $("#city1").val()!='' && $("#fname1").val()!='' && $("#lname1").val()!='' && $("#address1").val()!='' && $("#postcode1").val()!='')
	{
if($("#ssn").val()!=""){
	if($("#ssn").val().length<10)
	{
		var ssnvalid6=false;
	}
	else
	{
	var ssnvalid6=IsNumeric($("#ssn").val());
	}
	
	/*if(ssnvalid6==false)
	{
	$("#shipingssn2").show();
	}*/
	}
	if($("#phone").val()!=""){
	
	var phvalid6=IsNumeric($("#phone").val());
	//if(phvalid6==false)
	//{
	//$("#shipingphone2").show();
	//}
	}
	if($("#email").val()!='')
	{
		var evalid5=emailchk($("#email").val());
		//if(evalid5==false)
		//{
		//$("#shipingemail2").show();
		//}
		
	}
	if(ssnvalid6==false && phvalid6==false && evalid5==false)
	{
		$('#formvalidation2').modal({
	close:false,
	position: ["30%",],
	overlayId:'confirmModalOverlay',
	containerId:'confirmModalContainer', 
	onShow: function (dialog) {
		$("#shipingssn2").show();
		$("#shipingemail2").show();
		$("#shipingphone2").show();
		$('.yes').click(function () {
		$.modal.close();
			});
	}
									});
		return false;
	}
	
	else if(ssnvalid6==false)
	{
		$('#formvalidation2').modal({
	close:false,
	position: ["30%",],
	overlayId:'confirmModalOverlay',
	containerId:'confirmModalContainer', 
	onShow: function (dialog) {
		$("#shipingssn2").show();
		//$("#shipingemail2").show();
		//$("#shipingphone2").show();
		$('.yes').click(function () {
		$.modal.close();
			});
	}
									});
		return false;
	}
	else if(phvalid6==false)
	{
		$('#formvalidation2').modal({
	close:false,
	position: ["30%",],
	overlayId:'confirmModalOverlay',
	containerId:'confirmModalContainer', 
	onShow: function (dialog) {
		//$("#shipingssn2").show();
		//$("#shipingemail2").show();
		$("#shipingphone2").show();
		$('.yes').click(function () {
		$.modal.close();
			});
	}
									});
		return false;
	}
	else if(evalid5==false)
	{
		$('#formvalidation2').modal({
	close:false,
	position: ["30%",],
	overlayId:'confirmModalOverlay',
	containerId:'confirmModalContainer', 
	onShow: function (dialog) {
		//$("#shipingssn2").show();
		$("#shipingemail2").show();
		//$("#shipingphone2").show();
		$('.yes').click(function () {
		$.modal.close();
			});
	}});
		return false;
	}
	///
	
	
	
	if(ssnvalid6==true && phvalid6==true && evalid5==true)
	{
		
		return true;
		
		
		
	}
	//
return false;
	
}

	}
/*************************************************   shipping Address Validation ********************************/

function shippingAddress(){



	if($("#ssn").val()=='' || $("#city").val()=='' || $("#fname").val()=='' || $("#lname").val()=='' || $("#address").val()=='' || $("#postcode").val()=='' || $("#email").val()=='' || $("#phone").val()=='')
	{
		
	$('#formvalidation2').modal({
	close:false,
	position: ["30%",],
	overlayId:'confirmModalOverlay',
	containerId:'confirmModalContainer', 
	onShow: function (dialog) {
			
	$("#confirmModalContainer").height(230);
	
	if($("#fname").val()=='')
	{
	$("#shipingfname").show();
	}
	
	if($("#lname").val()=='')
	{
	$("#shipinglname").show();
	}
	
	if($("#address").val()=='')
	{
	$("#shipingaddress").show();
	}
	if($("#postcode").val()=='')
	{
	$("#shipingpostcode").show();
	}
	
	
	
	if($("#postcode").val()!=""){
	
	var postcodevalid6=IsNumeric($("#postcode").val());
	if(postcodevalid6==false)
	{
	$("#shipingpostcode2").show();
	}
	}
	
	
	if($("#city").val()=='')
	{
	$("#shipingcity").show();
	}
	
	if($("#ssn").val()=='')
	{
	$("#shipingssn").show();
	}
	
	if($("#ssn").val()!=""){
	
	var ssnvalid6=IsNumeric($("#ssn").val());
	
	if(ssnvalid6==false)
	{
	$("#shipingssn2").show();
	}
	}
	
	
	
	if($("#email").val()=='')
	{
	$("#shipingemail").show();
	}
	
	if($("#email").val()!='')
	{
		var evalid5=emailchk($("#email").val());
		if(evalid5==false)
		{
		$("#shipingemail2").show();
		}
	}
	
	if($('input[name=cartType]:checked').val()=="invoice") {
	
		if($("#phone").val()=='')
		{
		$("#shipingphone").show();
		}
		
		if($("#phone").val()!=""){
		
		var phvalid6=IsNumeric($("#phone").val());
		if(phvalid6==false)
		{
		$("#shipingphone2").show();
		}
		}/*
	*/
	
	}
	else
	{
		
		$("#phone").val('0');
	}
	
	$('.yes').click(function () {
		$.modal.close();
			});
	}
		//
	});
					
return false;
}
else if($("#ssn").val()!='' && $("#city").val()!='' && $("#fname").val()!='' && $("#lname").val()!='' && $("#address").val()!='' && $("#postcode").val()!='' && $("#email").val()!='' && $("#phone").val()!='')
{
	
	if($("#ssn").val()!=""){
	if($("#ssn").val().length<10)
	{
		var ssnvalid6=false;
	}
	else
	{
	var ssnvalid6=IsNumeric($("#ssn").val());
	}
	
	/*if(ssnvalid6==false)
	{
	$("#shipingssn2").show();
	}*/
	}
	if($("#phone").val()!=""){
	
	var phvalid6=IsNumeric($("#phone").val());
	//if(phvalid6==false)
	//{
	//$("#shipingphone2").show();
	//}
	}
	if($("#email").val()!='')
	{
		var evalid5=emailchk($("#email").val());
		//if(evalid5==false)
		//{
		//$("#shipingemail2").show();
		//}
		
	}
	if(ssnvalid6==false && phvalid6==false && evalid5==false)
	{
		$('#formvalidation2').modal({
	close:false,
	position: ["30%",],
	overlayId:'confirmModalOverlay',
	containerId:'confirmModalContainer', 
	onShow: function (dialog) {
		$("#shipingssn2").show();
		$("#shipingemail2").show();
		$("#shipingphone2").show();
		$('.yes').click(function () {
		$.modal.close();
			});
	}
									});
		return false;
	}
	else if(ssnvalid6==false)
	{
		$('#formvalidation2').modal({
	close:false,
	position: ["30%",],
	overlayId:'confirmModalOverlay',
	containerId:'confirmModalContainer', 
	onShow: function (dialog) {
		$("#shipingssn2").show();
		//$("#shipingemail2").show();
		//$("#shipingphone2").show();
		$('.yes').click(function () {
		$.modal.close();
			});
	}
									});
		return false;
	}
	else if(phvalid6==false)
	{
		$('#formvalidation2').modal({
	close:false,
	position: ["30%",],
	overlayId:'confirmModalOverlay',
	containerId:'confirmModalContainer', 
	onShow: function (dialog) {
		//$("#shipingssn2").show();
		//$("#shipingemail2").show();
		$("#shipingphone2").show();
		$('.yes').click(function () {
		$.modal.close();
			});
	}
									});
		return false;
	}
	else if(evalid5==false)
	{
		$('#formvalidation2').modal({
	close:false,
	position: ["30%",],
	overlayId:'confirmModalOverlay',
	containerId:'confirmModalContainer', 
	onShow: function (dialog) {
		//$("#shipingssn2").show();
		$("#shipingemail2").show();
		//$("#shipingphone2").show();
		$('.yes').click(function () {
		$.modal.close();
			});
	}
});
		return false;
	}
	if(ssnvalid6==true && phvalid6==true && evalid5==true)
	{
		
		return true;
	}
	return false;
}

}



	/******************************email validation start here*******************************************/

function emailchk(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		  
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		 
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   
		    return false
		 }

 		 return true					
	}

/******************************email validation end here*******************************************/
function IsNumeric(sText)

{
   var stripped = sText.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {
   	return false;
   
	}
	else
	{
		
		//return true;
 return true;
   }
 
}
