// JavaScript Document
$(document).ready(function(){
						   
$("#postage").change(function(){  
	  $.ajax({
  		url: "ajaxs.php",
		data: "postage_id="+this.value,
  		cache: false,
  		success: function(html1){
    	$("#shiping").html(html1);
		$("#shiping_hide").val(html1);
		var tot_amt= $("#subtotal_hide").val();
  		var g_total = eval(tot_amt)+eval(html1);
		g_total = formatNumber(g_total,2);
		$("#total_amt").html(g_total);
		$("#total_hide").val(g_total);
		}
	});
	  
  });


$("#edit1").click(function(e){
	var height = $(window).height();
    var width = $(document).width();
	var d_height = $(document).height();
    $("#div_overlay").css("height",d_height);
	var pop_width = $("#div_ooverlay").width();
	var pop_height = $("#div_ooverlay").height();
	var left_d = eval(width/2) - eval(pop_width/2);
	var top_d = eval(height/2) - eval(pop_height/2);
	  $("#div_overlay").css("visibility","visible");
	  $("#div_ooverlay").css("visibility","visible");
	  $("#div_ooverlay").css("left",left_d);
	  $("#div_ooverlay").css("top",top_d);
	  
}); 

$("#edit2").click(function(e){
    var height = $(window).height();
	var width = $(document).width();
	var d_height = $(document).height();
    $("#div_overlay").css("height",d_height);
	var pop_width = $("#div_ooverlay").width();
	var pop_height = $("#div_ooverlay").height();
	var left_d = eval(width/2) - eval(pop_width/2);
	var top_d = eval(height/2) - eval(pop_height/2);  
	  $("#div_overlay").css("visibility","visible");
	  $("#div_ooverlay").css("visibility","visible");
	  $("#div_ooverlay").css("left",left_d);
	  $("#div_ooverlay").css("top",top_d);
}); 

$("#add_address").click(function(e){
    var height = $(window).height();
    var width = $(document).width();
	var d_height = $(document).height();
    $("#div_overlay").css("height",d_height);
	var pop_width = $("#div_ooverlay").width();
	var pop_height = $("#div_ooverlay").height();
	var left_d = eval(width/2) - eval(pop_width/2);
	var top_d = eval(height/2) - eval(pop_height/2);
	  $("#div_overlay").css("visibility","visible");
	  $("#div_ooverlay").css("visibility","visible");
	  $("#div_ooverlay").css("left",left_d);
	  $("#div_ooverlay").css("top",top_d);
}); 

$("#add_address1").click(function(e){
    var height = $(window).height();
	var d_height = $(document).height();
	var width = $(document).width();
	var pop_width = $("#div_ooverlay1").width();
	var pop_height = $("#div_ooverlay1").height();
	var left_d = eval(width/2) - eval(pop_width/2);
	var top_d = eval(height/2) - eval(pop_height/2);
	  $("#div_overlay1").css("visibility","visible");
	  $("#div_ooverlay1").css("visibility","visible");
	  $("#div_ooverlay1").css("left",left_d);
	  $("#div_overlay1").css("height",d_height);
	  $("#div_ooverlay1").css("top",top_d);
	  $("#div_ooverlay1").css("z:index",15);
}); 


$("#close_popup").click(function(e){
	  $("#div_overlay").css("visibility","hidden");
	  $("#div_ooverlay").css("visibility","hidden");
	  window.location.href='addressbook.asp';
}); 

$(".close_popup1").click(function(e){
	  $("#div_overlay1").css("visibility","hidden");
	  $("#div_ooverlay1").css("visibility","hidden");
}); 

$(".close_popup").click(function(e){
	  $("#div_overlay").css("visibility","hidden");
	  $("#div_ooverlay").css("visibility","hidden");
}); 


$("#checkout_go").click(function(){
	var height = $(window).height();
    var width = $(document).width();
	var d_height = $(document).height();
    $("#postage_div_overlay").css("height",d_height);
	var pop_width = $("#postage_div_ooverlay").width();
	var pop_height = $("#postage_div_ooverlay").height();
	var left_d = eval(width/2) - eval(pop_width/2);
	var top_d = eval(height/2) - eval(pop_height/2);
	  $("#postage_div_overlay").css("visibility","visible");
	  $("#postage_div_ooverlay").css("visibility","visible");
	  $("#postage_div_ooverlay").css("left",left_d);
	  $("#postage_div_ooverlay").css("top",top_d);	
});

$(".select_post").click(function(){
	$.ajax({
  		url: "ajax.php",
		data: "postage_id1="+this.id,
  		cache: false,
		success: function(){window.location.href='login.asp?act=checkout'}
  		
	});
	
});

$(".wishlink").click(function(){
	if($("#strength_val"+this.name).length>0){
		var url1 = "&strength="+$("#strength_val"+this.name).val();
	}else{
		var url1='';
	}
	if(this.title=='plasma'){
		var url1=url1+'&plasma=Yes';
	}
	$.ajax({
  		url: "ajax.php",
		data: "wish_id="+this.name+url1,
  		cache: false,
		success: function(){window.location.href='mywishlist.asp'}
		   
	});
	
});

$(".wishlink1").click(function(){
	if($("#strength_val"+this.name).length>0){
		var url1 = "&strength="+$("#strength_val"+this.name).val();
	}else{
		var url1='';
	}
	if(this.title=='plasma'){
		var url1=url1+'&plasma=Yes';
	}
	$.ajax({
  		url: "../ajax.php",
		data: "wish_id="+this.name+url1,
  		cache: false,
		success: function(){window.location.href='../mywishlist.asp'}
		   
	});
	
});


});

function update_cart_ajax(cart_id,qty_id,price,amt){

	var total = document.getElementById('total_hide').value;
	var qty = document.getElementById(qty_id).value;
	//alert(cart_id+" - "+qty+" - "+price+" - "+amt+" - "+total);

	$.ajax({
		type: "POST",
		url: "ajax_cart.php",
		data: "cart_id="+cart_id+"&qty="+qty+"&price="+price+"&amt="+amt+"&total="+total+"&update_cart=1",
		dataType: 'JSON',
		success: function(msg, status){
			//alert(msg);
			obj = eval('('+msg+')');
			//alert(obj.amt);
			//alert(obj.total);
			document.getElementById('total_hide').value = obj.total;
			document.getElementById('total_amt').innerHTML = obj.total;
			document.getElementById('total_amt_h').innerHTML = obj.total;
			document.getElementById(qty_id+'tot').innerHTML = obj.amt;
			
			//document.getElementById(qty_id).setAttribute("onblur","update_cart_ajax('"+cart_id+"','"+qty_id+"','"+price+"','"+obj.amt+"')");
			var temp = document.getElementById(qty_id);
			temp.onblur = new Function("update_cart_ajax('"+cart_id+"','"+qty_id+"','"+price+"','"+obj.amt+"')");
			//alert(temp.onblur);
			/*document.getElementById('destination_zip_code').value = obj.zip_code;
			document.getElementById('loadaddress').style.display="none";*/
		}
	});
}
