// JavaScript Document



function hideshow(which)

{

if (!document.getElementById|document.all)

	{

	return

	}

else

	{

	if (document.getElementById)

		{

		oWhich = eval ("document.getElementById('" + which + "')")

		}

	else

		{

		oWhich = eval ("document.all." + which)

		}

	}

 

	window.focus()

 

	if (oWhich.style.display=="none")

		{

		oWhich.style.display=""

		}

	else

		{

		oWhich.style.display="none"

		}

}

//end IE 4+ And NS6 dHTML Outlines

function initoutlineExpandible()

{

hideshow('caseChild1')

hideshow('caseChild2')

hideshow('caseChild3')

hideshow('caseChild4')

hideshow('caseChild5')

hideshow('caseChild6')

hideshow('caseChild7')

hideshow('caseChild8')

hideshow('caseChild9')

hideshow('caseChild10')



}
  

 function updateCart(cid, mid,ctype){
	 $.ajax({
		 	   url: 'cart-functions.php',
			   type: 'post',
			   data: {action: "changeQty", mid: mid, cid: cid, ctype: ctype, qty: $("#"+cid).val()},
			   error: function() {
      		   	alert('有錯誤產生，請連絡MIS@kmcc.org.tw');
    		   }
					});
			   

	 $("#mycart").load("cart-functions.php", {action: 'freshcart'});

 }

 function modifyOrder(action,mid,cid,ctype){

	 switch(action){

		case 'delOrder': 

			 var sure = window.confirm('確定要刪除此訂單？');

			 if (!sure)	return;
			 $.ajax({
		 	   url: 'cart-functions.php',
			   type: 'post',
			   data: {action: "deleteOrder", mid: mid},
			   error: function() {
      		   	alert('有錯誤產生，請連絡MIS@kmcc.org.tw');
    		   }
					});
			  $("#mycart").load("cart-functions.php", {action: 'freshcart'});

		break;

		case "delCase":

			 var sure = window.confirm('確定要移除此個案？');

			 if (!sure)	return;

			 $.ajax({
		 	   url: 'cart-functions.php',
			   type: 'post',
			   data: {action: "deleteCase", mid: mid, ctype: ctype, cid: cid},
			   error: function() {
      		   	alert('有錯誤產生，請連絡MIS@kmcc.org.tw');
    		   }
					});
			   
			  $("#mycart").load("cart-functions.php", {action: 'freshcart'});

		break;

	 }

	$("#mycart").load("cart-functions.php", {action: 'freshcart'});

 }
 
 function insertCart(id,ctype) {
  $.ajax({
    url: 'cart-functions.php',
	type: 'post',
	data: {action: 'check'},
    error: function(xhr) {
      alert('Ajax request 發生錯誤');
    },
    success: function(response) {
		if(!response){
			alert("請先登入會員!");
	   }else{
		   $.ajax({
				  url: 'cart-functions.php',
				  type: 'post',
				  data: {action: 'add',pid: id, ctype: ctype},
				  error: function(xhr) {
     				 alert('Ajax request 發生錯誤');
    			  },
				  success: function(response) {
					   if(response == "此個案已在您購物車裡了!"){
					   	alert(response);
			  			}
					   $.post("cart-functions.php", { action: 'freshcart'},
   						function(data){
						$('#mycart').html(data);
   						});				
				  }
		});
	  }
	}
  });
}
/*
 function insertCart(id){

	 new Ajax.Request('cart-functions.php', {

	parameters: 'action=check' ,

    onSuccess: function(transport){

      var response = transport.responseText;

	   if(!response){

      		alert("請先登入會員!");

	   }else{

			new Ajax.Request('cart-functions.php', {

			parameters: 'action=add&pid=' + id ,

			onSuccess: function(transport){

			  var response = transport.responseText;

			  if(response == "此個案已在您購物車裡了!"){

				alert(response);

			  }

			},

			onFailure: function(){ alert('有錯誤產生，請連絡MIS@kmcc.org.tw') }

		

				 });

			new Ajax.Updater('mycart', 'cart-functions.php', {parameters: {action: 'freshcart'}});

		  }

    },

    onFailure: function(){ alert('有錯誤產生，請連絡MIS@kmcc.org.tw') }



		 });

 	

 }*/