





	

function chkbuyerlogin()

{

	str = $("#loginform").serialize();

	$.ajax(

		{

			type:'post',

			url:'http://www.bajrayogini.com.np/buyers/chkbuyerslogin',

			async: true,

			data: str,

			dataType:'json',

			success:function(response)

			{

				if(response.status == 1)

				{

					top.location.href = 'http://www.bajrayogini.com.np/';

				}

				else

				{

					//$.facebox(seller_login_failure);

					return false;

				}

			}

		});

}



function updatebillingadd()

{

	if(confirm('are you sure you want to save the current address ?'))

	{

		str = $("#regstep1").serialize();

		$.ajax(

	  	{

	   		type:'post',

	   		url:'http://www.bajrayogini.com.np/buyers/updateBillingAdd',

	   		async: true,

	   		data: str,

	   		success:function(response)

	      	{

	    		if(response.status == 1)

				{

					top.location.href = 'http://www.bajrayogini.com.np/checkout/step1';

				}

				else

				{

					return false;

				}

	      	}

		});

	}

	else{

		return false;

	}

}





function resetCardDetails()

{

	$( "form" )[ 1 ].reset();

}



function saveCardDetails()

{

	str = $("#buyerscard").serialize();

	$.ajax(

		{

			type:'post',

			url:base_url+'buyers/savecard',

			async: true,

			data: str,

			dataType:'json',

			beforeSend:function()

			{

				if(!$("#buyerscard").valid())

				{

					return false;

				}

			},

			success:function(response)

			{

				if(response.latestInfo)

				{

					addOption(document.buyerscard.buyers_cards,response.card_number,response.card_id);

				}

			}

		});

}



function updatebuyersinfo()

{

	str = $("#accountoverview").serialize();

	$.ajax(

		{

			type:'post',

			url:'http://www.bajrayogini.com.np/buyers/savebuyerinfo',

			async: true,

			data: str,

			dataType:'json',

			success:function(response)

			{

				alert("Information successfully saved.");

			}

		});

}





function attachDatePicker()

{

	$.datepicker.setDefaults({

	showOn: 'both',

	buttonImageOnly: true,

	buttonImage: base_url+'/assets/shared/icons/calendar.gif',

	buttonText: 'Calendar' });

	$('#act_card_expiry').datepicker({yearRange: '1960:'+'2020',dateFormat: 'yy-mm-dd'});

}



function addOption(selectbox,text,value )

{

	var optn = document.createElement("OPTION");

	optn.text = text;

	optn.value = value;

	optn.id = value;

	optn.selected = "selected";

	selectbox.options.add(optn);

}



function fillCardInfo(cardId)

{

	$.ajax(

			{

				type:'post',

				url:base_url+'buyers/getcarddetails',

				async: true,

				data:{"cardId":cardId},

				dataType:'json',

				beforeSend:function()

				{

					if(cardId == 0)

					{

						$( "form" )[ 1 ].reset();

						return false;

					}

				},

				success:function(response)

				{

					$("#act_card_details").val(response.card_details);

					$("#act_card_type").val(response.card_type);

					$("#act_card_number").val(response.card_number);

					$("#act_card_expiry").val(response.card_expiry_date);

					$("#act_cvs_code").val(response.card_cvv_code);

					$("#act_issuer_bank_country").val(response.issuerbank_country);

					$("#act_card_id").val(response.card_id);

				}

			});

}



function delCard()

{

	if(confirm('are you sure you want to delete'))

	{

		str = $("#buyerscard").serialize();

		$.ajax(

				{

					url:base_url+'buyers/delcard',

					type:'post',

					data:str,

					async:true,

					success: function(response)

					{

						$('#buyers_cards option:selected').remove();

						$( "form" )[ 1 ].reset();

						alert("The selected card information was successfully deleted");

					}

				}

		);

	}

	else

	{

		alert ("cancelled deletion");

	}

}



function fillShippingInfo(shipping_address)

{

	$.ajax(

			{

				type:'post',

				url:'http://www.bajrayogini.com.np/checkout/getShippingDetails',

				async: true,

				data:{"shipping_address":shipping_address},

				dataType:'json',

				beforeSend:function()

				{

					if(shipping_address == 0)

					{

						$( "form" )[ 0 ].reset();

						$("#sameasbilling").attr("disabled",false);

						return false;

					}

				},

				success:function(response)

				{

					$("#sameasbilling").attr("disabled", true);

					$("#samebilling").val("0");

					$("#shipping_full_name").val(response.shipping_add_full_name);

					$("#shipping_full_add").val(response.shipping_add_fulladd);

					$("#shipping_city").val(response.shipping_add_city);

					$("#shipping_state").val(response.shipping_add_state);

					$("#shipping_country").val(response.shipping_add_country);

					$("#shipping_zip_code").val(response.shipping_add_zip_code);

					$("#shipping_phone").val(response.shipping_add_phone);

					$("#shipping_email").val(response.shipping_add_email);

				}

			});

}





function delShipping(){

	

 if(confirm('are you sure you want to delete')){

  var shipping_id = $("#shipping_address option:selected").attr("value");

  $.ajax(

    {

     url:'http://www.bajrayogini.com.np/checkout/delShipping',

     type:'post',

     data:{"shipping_id":shipping_id},

     async:true,

     dataType:"json", // We are expecting for json string response from server script

     success: function(response)

     {

    	 shippingIdExist =  response.shippingIdExist // access variable from json string

    	 msg = response.msg; // accessing msg variable from json string object resposne

    	 if(shippingIdExist){

    		 alert(msg);

    	 }else{

    		 $('#shipping_address option:selected').remove();

    	     $( "form" )[ 0 ].reset();

    	     alert(msg);

    	 }

     }

    });

 }

 else

 {

  alert ("cancelled deletion");

 }

}



function deleteOrder(order)

{

	if (confirm("Are you sure you want to delete")) {

    document.location = delUrl;

  }

  else{

	alert("cancelled deletion");

}

}



function removeItems()

{

	if(confirm('Are you sure you wish to remove selected items from the cart?'))

	{

		

		var itemSelected = $("input#cartItem:checked").length;

		

		if(itemSelected > 0)

		{

			

			str = $("#cartItems").serialize();

			$.ajax(

		  	{

		   		type:'post',

		   		url:'http://www.bajrayogini.com.np/cart/remove',

		   		async: true,

		   		data: str,

		   		success:function(response)

		      	{

					top.location.href = 'http://www.bajrayogini.com.np/cart/';

					alert('Selected Items are removed successfully from the cart');					

		      	}

			});

		}

		else

		{

			alert("No Item is selected to remove");

			return false;

		}		

	}

	else

	{

		alert ("remove cancelled");

	}

}



function checkout(items)

{

	if(items <= 0){

		alert("No items present on cart");

		return false;

	}

	else{

		top.location='http://www.bajrayogini.com.np/checkout/step1';

	}

	

}




