function login(){
	var	username	=document.form_login.username.value;
	var	password	=document.form_login.password.value;
	var	url_load	="/member/login.php";

	var	errMsg		="";
	

	if (password ==""){
			errMsg = "กรุณาระบุ password";
			setfocus = "password";
	}

	if (username ==""){
			errMsg = "กรุณาระบุ username";
			setfocus = "username";
	}

	if (errMsg != ""){
		alert(errMsg);
		eval("document.form_login." + setfocus + ".focus()");
	}else{

		$("#loading_process").fadeIn(300);
		$.post(url_load, "username="+username+"&password="+password, function(data){
				if (data =="OK")
				{
					window.location.reload();
				}else{
					document.form_login.username.value="";
					document.form_login.password.value="";
					$("#loading_process").fadeOut(600);
					alert("Login ผิดพลาดชื่อผู้ใช้หรือรหัสผ่านผิดพลาดกรุณาตรวจสอบอีกครั้ง");	
				}
		});

	}

}
function forgetpassword(){
	var	username	=document.form_forget_password.username.value;
	var	url_load	="/member/forgetpassword.php";

	var	errMsg		="";

	if (username ==""){
			errMsg = "กรุณาระบุ username หรือ email";
			setfocus = "username";
	}

	if (errMsg != ""){
		alert(errMsg);
		eval("document.form_forget_password." + setfocus + ".focus()");
	}else{

		$("#loading_process").fadeIn(300);
		$.post(url_load, "username="+username, function(data){
				if (data =="ERROR")
				{
					document.form_forget_password.username.value="";
					$("#loading_process").fadeOut(600);
					alert("ข้อมูล username หรือ email ผิดพลาดกรุณาตรวจสอบอีกครั้ง");	
				}else{
					$("#loading_process").fadeOut(600);
					$("#profile_login").html(data);
				}
		});

	}


}


function openmsn(){
	document.getElementById("msndisplay").innerHTML="<iframe src=\"http://settings.messenger.live.com/Conversation/IMMe.aspx?invitee=92b17e19140de387@apps.messenger.live.com&mkt=th-TH\" width=\"300\" height=\"400\" style=\"border: solid 1px black; width: 300px; height: 400px;\" frameborder=\"0\"></iframe>";
	document.getElementById("msnblock").innerHTML="<a href=\"javascript:closemsn();\" class=\"linkorange\">ปิดหน้าต่างพูดคุย</a>";
	display("msndisplay");
}
function closemsn(){
	document.getElementById("msndisplay").innerHTML="";
	document.getElementById("msnblock").innerHTML="<a href=\"javascript:openmsn();\" class=\"linkorange\" title=\"พูดคุยกับทีมงานได้ทันทีมีทีมงานคอนตอบคำถามอยู่ครับ\">คุยกับเด็กหน้าร้าน KreeBay.com</a>";
	hide("msndisplay");
}


function display(sID) {
	oObj = document.getElementById(sID);
	if (oObj) {
		oObj.style.display='inline';
	} 
}

function hide(sID) {
	oObj = document.getElementById(sID);
	if (oObj) {
		oObj.style.display='none';
	}
}


function loginform(){
	var	url_load	="/member/login.php";

	$("#loading_process").fadeIn(300);

	$.get(url_load, "", function(data){
		$("#loading_process").fadeOut(600);
		$("#profile_login").html(data);
	});
}

function forgetpasswordform(){

	var	url_load	="/member/forgetpassword.php";

	$("#loading_process").fadeIn(300);

	$.get(url_load, "", function(data){
		$("#loading_process").fadeOut(600);
		$("#profile_login").html(data);
	});
}


function cartupdate(){

	var	url_load	="/cart/cartupdate.php";

	$("#loading_cart").fadeIn(100);

	$.get(url_load, "", function(data){
		$("#loading_cart").fadeOut(100);
		$("#widget_cart").html(data);
	});

}


function cartdelete(id){

	var	url_load	="/cart/cartdelete.php";

	$("#loading_cart").fadeIn(100);

	$.get(url_load, "id="+id, function(data){
		$("#loading_cart").fadeOut(1000);
		$("#widget_cart").html(data);
	});

}


function itemdelete(){


	var	url_load		="/cart/itemdelete.php";
	var file_del		="";
	var item_id			="";
	var i				="";

//	if (window.confirm("ยืนยันการลบอีกครั้ง ?")) {

		if (document.form_item.item_id.length !=undefined)
		{


			for (i=0; i<=document.form_item.item_id.length-1; i++){
					if (document.form_item.item_id[i].checked)
					{

						file_del = document.form_item.item_id[i].value;

						if (file_del !="" && file_del != null){
								item_id =item_id+"&id"+i+"="+file_del;
						}
					}
			}
			item_id =item_id+"&count="+i+"&p=1";

/**/
		}else{

	if (document.form_item.item_id.checked==true){
					file_del = document.form_item.item_id.value;
						if (file_del !="" && file_del != null){
								item_id =item_id+"&id0="+file_del;
						}
				}
			item_id =item_id+"&count=1&p=1";
/**/
		}


		if (item_id !=""){
			$("#loading_item").fadeIn(300);
			$.get(url_load, item_id, function(data){
				$("#loading_item").fadeOut(1000);
				$("#itemhtml").html(data);
			});
		}

	}

//}


function itemupdateup(id){


	var	url_load		="/cart/itemupdateup.php";

			$("#loading_item").fadeIn(300);
			$.get(url_load, "id="+id, function(data){
				$("#loading_item").fadeOut(1000);
				$("#itemhtml").html(data);
			});

}


function itemupdatedown(id){


	var	url_load		="/cart/itemupdatedown.php";

			$("#loading_item").fadeIn(300);
			$.get(url_load, "id="+id, function(data){
				$("#loading_item").fadeOut(1000);
				$("#itemhtml").html(data);
			});

}


function checkAgree(){
		if (document.getElementById('form_register').agree.checked == true){
			document.getElementById('form_register').button1.disabled=false;
		}else{
			document.getElementById('form_register').button1.disabled=true;						
		}
}