
function update_shipping(ID, ids) {
	
	$.ajax({
	   type: "POST",
	   cache: false,
	   url: "/blingshopen-utveckling/index.php/ajax/updateshipping/",
	   data: "id="+ID,
	   success: function(msg){
		 splHTML = msg.split("|");
		 document.getElementById("fraktavgift").innerHTML = splHTML[0];
		 document.getElementById("input_fraktavgift").value = splHTML[1];
		 
		 reset_choose_boxes(ids, "delivery");
		 
		 document.getElementById("delivery_"+ID).className = "choose_box_marked";
		 document.getElementById("delivery").value = splHTML[2];
		 calc_total_sum();
	   }
	 });
	
	

}

function update_payment(ID, ids) {
	$.ajax({
	   type: "POST",
	   cache: false,
	   url: "/blingshopen-utveckling/index.php/ajax/updatepaymentinfo/",
	   data: "id="+ID,
	   success: function(msg){
		 
		 var splHTML = msg.split("|");
		 document.getElementById("betalavgift").innerHTML = splHTML[0];
		 document.getElementById("input_betalavgift").value = splHTML[1];
		 reset_choose_boxes(ids, "payment");
		 
		 document.getElementById("payment_"+ID).className = "choose_box_marked";
		 document.getElementById("payment").value = splHTML[2];
		 calc_total_sum();
	   }
	 });

}

function reset_choose_boxes(boxes, type) {

	var splBox = boxes.split("|");

	for (i=0;i<splBox.length;i++) {
		
		if (splBox[i] != "") {

			document.getElementById(type+"_"+splBox[i]).className = "choose_box";
			
		}
		
	}
	
}



function add_to_cart(id,qty) {
	$.ajax({
	   	type: "POST",
		cache: false,
	   	url: "/blingshopen-utveckling/index.php/cart/add/",
	   	data: "id="+id+"&qty="+qty, 
	   	success: function(msg){
		 document.getElementById("mini_cart").innerHTML = msg;
	   }
	 });
}

function clear_mini_cart() {
	$.ajax({
	   	type: "POST",
		cache: false,
	   	url: "/blingshopen-utveckling/index.php/cart/clearminicart/",
	   	success: function(msg){
		 document.getElementById("mini_cart").innerHTML = msg;
	   }
	 });
}

function find_username() {
	$.ajax({
	   	type: "POST",
		cache: false,
	   	url: "/blingshopen-utveckling/index.php/user/findusername/",
		data: "user="+document.getElementById("checkout_username").value, 
	   	success: function(msg){
		if(msg == "TRUE"){
			document.getElementById("password").style.display='table-row';
			document.getElementById("login_next").style.display='none';
			document.getElementById("login_submit").style.display='block';
		}else if(msg == "VALID"){
			location.href='/blingshopen-utveckling/index.php/checkout/order'
		}else{
			alert("Inte giltig");	
		}
	   }
	 });
}

function checkout_login(){
	$.ajax({
	   	type: "POST",
		cache: false,
	   	url: "/blingshopen-utveckling/index.php/user/login/",
		data: "user="+document.getElementById("checkout_username").value+"&password="+document.getElementById("checkout_pwd").value, 
	   	success: function(msg){
		if(msg != "FALSE"){
			location.href='/blingshopen-utveckling/index.php/checkout/order';
		}else{
			alert("Fel användarnamn eller lösenord.");	
		}
	   }
	 });
}

function login(){
	$.ajax({
	   	type: "POST",
		cache: false,
	   	url: "/blingshopen-utveckling/index.php/user/login/",
		data: "user="+document.getElementById("username").value+"&password="+document.getElementById("pwd").value, 
	   	success: function(msg){
		if(msg != "FALSE"){
			 document.getElementById("login_div").innerHTML = msg; 
		}else{
			alert("Fel användarnamn eller lösenord.");	
		}
	   }
	 });
}

function logout(){
	$.ajax({
	   	type: "POST",
		cache: false,
	   	url: "/blingshopen-utveckling/index.php/user/logout/",
	   	success: function(msg){
		if(msg == "TRUE"){
			location.href="http://db1.scancopy.se/blingshopen-utveckling/";
			//document.getElementById("login_div").innerHTML = "<br/><br/><div class='heading-right'><h2>Logga in</h2></div><form action='/shop/index.php/user/login/' method='post' style='clear:both;'>E-post: <input type='text' name='username' id='username' /><br />L&ouml;senord: <input type='password' name='pwd' id='pwd' /><p/><input type='button' value='Logga in' onclick='javascript:login()' /></form>";
		}
	   }
	 });
}

