function checkBrowserEnableCookie(){var cookieEnabled=(navigator.cookieEnabled)?true:false
if(typeof navigator.cookieEnabled=="undefined"&&!cookieEnabled){document.cookie="testcookie"
cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)?true:false}
if(cookieEnabled)return true;else return false;}
function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();}
else var expires="";document.cookie=name+"="+value+expires+"; path=/";}
function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);}
return null;}
function eraseCookie(name){createCookie(name,"",-1);}
function countShoppingCart(name){if(readCookie(name)==null){createCookie(name,'-',1);document.getElementById('count_shopping_cart').innerHTML=0;}else{var current_cart=readCookie(name);var ca=current_cart.split(',');number_product=ca.length;document.getElementById('count_shopping_cart').innerHTML=number_product-1;}}
function emptyShoppingCart(name){createCookie(name,'-',1);}
function addToShoppingCart(sellid,quantity){if(readCookie('shopping_cart')==null){createCookie('shopping_cart',',',1);}
var current_cart=readCookie('shopping_cart');if(current_cart.search(','+sellid+'-')==-1){var new_cart=current_cart+','+sellid+'-'+quantity;createCookie('shopping_cart',new_cart,1);countShoppingCart('shopping_cart');document.getElementById('item_'+sellid).innerHTML='Đã thêm vào giỏ hàng';}else{alert('Sản phẩm đã có trong giỏ hàng!');}}
function checkItemInCart(sellid){var current_cart=readCookie('shopping_cart');if(current_cart != null && current_cart.search(','+sellid+'-')!=-1){$('span#item_'+sellid).html('[Trong giỏ hàng]');}else{}}
function deleteShoppingCartItem(sellid,quantity){if(confirm('Bạn muốn xóa bỏ sản phẩm này khỏi giỏ hàng ? ')){var current_cart=readCookie('shopping_cart');new_cart=current_cart.replace(","+sellid+'-'+quantity,"");createCookie('shopping_cart',new_cart,1);countShoppingCart('shopping_cart');window.location.href='?option=cart';}}//minified

//show menu
function showSub(groupId){
	var check = document.getElementById(groupId).style.display;	
	var curren_open = document.getElementById('menu_open').value;
	
	if(check =="none"){
		$("#"+groupId).slideDown("slow");
	}else{
		$("#"+groupId).slideUp("slow");
	}
}
 
 
function showDateTime(showDate, dateFormat, showTime, showAsGMT)
{
	var days = new Array("Ch&#7911; nh&#7853;t","Th&#7913; hai","Th&#7913; ba","Th&#7913; t&#432;","Th&#7913; n&#259;m","Th&#7913; s&#225;u","Th&#7913; b&#7843;y");
	var months = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
	var datetime = getDateTime(showDate, dateFormat, showTime, showAsGMT, days, months, "/", "/");
	document.write("<nobr>&nbsp;" + datetime + "&nbsp;</nobr>");
}

function getDateTime(showDate, dateFormat, showTime, showAsGMT)
{
	var days = arguments[4]||new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var months = arguments[5]||new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var monthSeperate = arguments[6]||"-";
	var yearSeperate = arguments[7]||"-";
	var now = new Date();
	var month = "";
	var day = "";
	var time = "";
	var first_date_num ="";
	var result = "";

  // show date
	if(showDate)
	{
		// long date
		if(dateFormat!="0")
			day = days[now.getDay()] + ", ";
		month = months[now.getMonth()];
		if (now.getDate() < 10)
			first_date_num = "0";
		result += day + first_date_num + now.getDate() + monthSeperate + month + yearSeperate + now.getFullYear();
	}
	
	// show time
	if(showTime)
	{
		var symbol = "AM";
		if(showAsGMT)
			time = new String(now.getUTCHours());
		else
			time = new String(now.getHours());
		if(time>=12)
		{
			time = time - 12;
			symbol = "PM";
		}
		if (time.length < 2)
			time = "0" + time;
		var minute = new String(now.getMinutes());
		if (minute.length < 2)
			minute = "0"+ minute;
		time = time  + ":" + minute + "&nbsp;" + symbol;
		if(showAsGMT)
			time += " (GMT)";
		if(result!="")
			result += "&nbsp;&nbsp;";
		result += time;
	}
	
	return result;
}

function createPriceSearch(min_max){
	var price_array = min_max.split(",");
	var max_price = price_array[1];
	var min_price = price_array[0];
	document.getElementById('max_price').value = max_price;
	document.getElementById('min_price').value = min_price;
}

function show(elementId){
	var checked = document.getElementById(elementId).style.display;	
	if(checked == "none"){
		 document.getElementById(elementId).style.display = "block";
	}else{
		document.getElementById(elementId).style.display = "none";
	}
}

function chooseShippingOption(method_id){
    document.getElementById('selectShippingMethod').value = method_id;
}

function choosePaymentOption(option) {
     var checked = document.getElementById(option).checked;
     var instId = document.getElementById(option).value;
     if (checked) {
         document.getElementById("selectPaymentMethod").value = instId;
         
        //Hide other options
         for (var i in paymentOptionList) {
             if (option != paymentOptionList[i]) {
                 document.getElementById("pay_" + paymentOptionList[i]).style.display = "none";
                 document.getElementById(paymentOptionList[i]).checked = false;
             }
         }
         //show the instruction
         document.getElementById("block_" + instId).style.display = "block";
     } else {
        document.getElementById("selectPaymentMethod").value = "0";
        //Uncheck, show other options again
        for (var i in paymentOptionList) {
             document.getElementById("pay_" + paymentOptionList[i]).style.display = "block";
             document.getElementById(paymentOptionList[i]).checked = false;
             var elt = document.getElementById(paymentOptionList[i]).value;
             document.getElementById("block_"+elt).style.display = "none";
         }
     }
 }

