function subscribe(){
	window.location="subscribe-update.html?email="+$("#e_mail").val();
	//	alert($("#e_mail").val());
}
//$.post("test.php", { action: "getNameAndTime" },
//	function(data){
//		alert(data.name); // John
//		console.log(data.time); //  2pm
//	}, "json");

function justtest(){
	
	$.post("lib/ajax_callback_actions.php", { action:"test_" },
	function(data){
		
		alert(data); // John
		
	});
//	alert('test');
}

function sponsor_me_now(_id){
//	alert(_id);
	show_ajax_preloader('total_qty');
	$.post("lib/ajax_callback_actions.php", { action:"sponsor_me_now" , id:_id},
	function(data){
		
		if(parseInt(data) == 0){
			get_total_quan();
			alert('Benefeciary already selected!');	
		}else{
			$("#total_qty").html('('+data+')');	
			window.location = "shopping-cart.html";
		}
		
	});
}

function sponsor_school(_id){
//	alert(_id);
	show_ajax_preloader('total_qty');
	$.post("lib/ajax_callback_actions.php", { action:"sponsor_school" , id:_id},
	function(data){
		
		if(parseInt(data) == 0){
			get_total_quan();
			alert('School already selected!');	
		}else{
			$("#total_qty").html('('+data+')');	
			window.location = "shopping-cart.html";
		}
		
	});
}

function show_this_gift(_id){
	window.location="gifts.html?id="+_id;
//	alert(_id);
}

function add_to_cart(_id, min_qty,name,index){
	//alert(_id+" --- "+min_qty+" ---  "+name+" ---  "+index);
	show_ajax_preloader('total_qty');
	$.post("lib/ajax_callback_actions.php", { action:"add_to_cart" , id:_id, qty:min_qty, name:name, index:index},
	function(data){
		
		$("#total_qty").html('('+data+')');
		window.location = "shopping-cart.html";
		
	});
}

function _add_to_cart(_id,_index,min_quan){
//	alert('this');
	var min_qty = $("#"+_index).val();
	if(!greater_than_min(min_quan,min_qty)){
		exe_update_cart_qunatity_(_id, min_qty,'gifts','gifts_id');	
	}else{
		alert("The min quantity of this Item is "+min_quan);
	}
	
}

function exe_update_cart_qunatity_(_id,min_qty,name,index){
	show_ajax_preloader('total_qty');
	$.post("lib/ajax_callback_actions.php", { action:"upadate_cart_qty" , id:_id, qty:min_qty, name:name, index:index },
	function(data){
		$("#total_qty").html('('+data+')');
		calc_total_paymet();
		window.location = "shopping-cart.html";
	});
}

function greater_than_min(min,quan){
	var ret = true;
	var a = parseInt(min);
	var b = parseInt(quan);
	if(a <= b){
		ret = false
	}
	return ret;
}

function remove_to_cart(_id,type){
	$("#col_"+_id).remove();
	show_ajax_preloader('total_qty');
	$.post("lib/ajax_callback_actions.php", { action:"remove_to_cart" , id:_id, type:type},
	function(data){
		calc_total_paymet();
		$("#total_qty").html('('+data+')');
		
	});
}

function upadate_cart_qty(_id,id_,min_quan,a,b){
	//alert(_id+" --- "+id_+" --- "+min_quan);
	if(greater_than_min(min_quan,id_.value)){
		alert("The min quantity of this Item is "+min_quan);
		id_.value = min_quan;
	}
	exe_update_cart_qunatity(_id,id_.value,'gifts','gifts_id');
}

function exe_update_cart_qunatity(_id,min_qty,name,index){
	show_ajax_preloader('total_qty');
	$.post("lib/ajax_callback_actions.php", { action:"upadate_cart_qty" , id:_id, qty:min_qty, name:name, index:index },
	function(data){
		$("#total_qty").html('('+data+')');
		calc_total_paymet();
	});
}

function show_ajax_preloader(_id){
	var ht = '<img src="images/35.gif"/ style="display:block;">';
	$("#"+_id).html(ht);
}

function calc_total_paymet(){
	show_ajax_preloader('total_payment');
	$.post("lib/ajax_callback_actions.php", { action:"calc_total_paymet" },
	function(data){
//		alert(data);
		$("#total_payment").html(data);
		
	});
}

function add_email_to_cotact_list(){
	show_ajax_preloader('preload');
	$.post("lib/ajax_callback_actions.php", { action:"add_email_to_cotact_list", email:$("#_email").val() },
	function(data){
		if(parseInt(data) == 0){
			alert("Error: Invalid Email Address!");
		}else if(parseInt(data) == 2){
			alert("Error: Dupplicate Email Address!");	
		}else{
			$("#contact_list_table").append(data);
		}
		$("#preload").html("");
	});			
}

//set_all_contact_status_0

function select_all_(){
	show_ajax_preloader('preload');
	$.post("lib/ajax_callback_actions.php", { action:"set_all_contact_status_1"},
	function(data){
		$("#preload").html("");
	});	
}

function deselect_all_(){
	show_ajax_preloader('preload');
	$.post("lib/ajax_callback_actions.php", { action:"set_all_contact_status_0"},
	function(data){
		$("#preload").html("");
	});	
}

function select_all(_id){
	select_all_();
	$.each($('input[name="'+_id+'[]"]'), function(){
		$(this).attr('checked', 'checked');
	});
}
function deselect_all(_id){
	deselect_all_();
	$.each($('input[name="'+_id+'[]"]'), function(){
		$(this).attr('checked', '');
	});
}

function contact_action(index,id){
	if(id.checked == true){
		set_contact_status('1',index);
	}else if(id.checked == false){
		set_contact_status('0',index);
	}
}

function set_contact_status(status,index){
	show_ajax_preloader('preload');
	$.post("lib/ajax_callback_actions.php", { action:"set_contact_status", status:status, index:index},
	function(data){
		$("#preload").html("");
	});	
}

function get_total_quan(){
	show_ajax_preloader('total_qty');
	$.post("lib/ajax_callback_actions.php", { action:"get_total_quan"},
	function(data){
		
		$("#total_qty").html('('+data+')');	
		
	});
}