function Home_shoppingcart(id,iMaND)
{
    ProductsDefault.Home_SaveItem(iMaND,Callback_Home_shoppingcart);   
    document.getElementById(id).innerHTML='<img src="../Images/save_OK.gif" border="0" >';    
}
function Callback_Home_shoppingcart(res)
{    
    document.getElementById('lblShoppingCard').innerHTML=res.value;    
}
//RemoveItem From shopping card
function Home_RemoveItem(iMaND)
{    
    ProductsDefault.RemoveItem(iMaND,Callback_Home_shoppingcart);    
}
//BrandProducts
function Brand_shoppingcart(id,iMaND)
{
    BrandProducts.Brand_SaveItem(iMaND,Callback_Brand_shoppingcart);   
    document.getElementById(id).innerHTML='<img src="../Images/save_OK.gif" border="0" >';    
}
function Callback_Brand_shoppingcart(res)
{    
    document.getElementById('lblShoppingCard').innerHTML=res.value;    
}
function Brand_RemoveItem(iMaND)
{    
    BrandProducts.RemoveItem(iMaND,Callback_Brand_shoppingcart);    
}
//Products_ProductDetail
function Detail_shoppingcart(id,iMaND)
{
    Products_ProductDetail.Detail_SaveItem(iMaND,Callback_Detail_shoppingcart);   
    document.getElementById(id).innerHTML='<img src="../Images/shopping_cart.gif" border="0" >';    
}
function Callback_Detail_shoppingcart(res)
{    
    document.getElementById('lblShoppingCard').innerHTML=res.value;    
}
function Detail_RemoveItem(iMaND)
{    
    Products_ProductDetail.RemoveItem(iMaND,Callback_Detail_shoppingcart);    
}

function SaveItem(iMaND)
{
    ProductsDefault.SaveItem(iMaND); 
    alert("Đã lưu vào bộ nhớ Favorite Mã SP#:"+iMaND);
}

function SaveItemDetail(iMaND)
{
    Products_ProductDetail.SaveItem(iMaND); 
    alert("Đã lưu vào bộ nhớ Favorite Mã SP#:"+iMaND);
}
function SaveItemHot(iMaND)
{
    HOTProducts.SaveItem(iMaND); 
    alert("Đã lưu vào bộ nhớ Favorite Mã SP#:"+iMaND);
}
function SaveItemBrand(iMaND)
{
    BrandProducts.SaveItem(iMaND); 
    alert("Đã lưu vào bộ nhớ Favorite Mã SP#:"+iMaND);
}
function SaveItemGroup(iMaND)
{
    GroupProducts.SaveItem(iMaND); 
    alert("Đã lưu vào bộ nhớ Favorite Mã SP#:"+iMaND);
}


/* ','=44 '-'=45 '.'=46 */
function NumberOnly() {
	if (event.keyCode < 48 || event.keyCode > 57)	
		event.returnValue = false;
}

function PositiveNumber() {
	if ((event.keyCode < 48 || event.keyCode > 57) &&  event.keyCode != 44 &&  event.keyCode != 46)
		event.returnValue = false;
}

function SignedNumberOnly() {
	if ((event.keyCode < 48 || event.keyCode > 57) &&  event.keyCode != 44 &&  event.keyCode != 46 && event.keyCode != 45)
		event.returnValue = false;	
}

var fieldDate;
function OpenCalendar(FD) {
	fieldDate = FD;
	var pathname = (window.location.pathname.toLowerCase());
	var stFeature = 'width=200,height=270';
	var toppx = (screen.height-270)/2;
	var leftpx = (screen.width-200)/2;

	stFeature += ',top='+toppx.toString()+'px,left='+leftpx.toString()+'px';
	top.newWin = window.open('/ft/cal.html','Calendar',stFeature); 
	
}

function OpenWindow(url, title, width, height, feature) {
	var iTop = (screen.height-height)/2;
	var iLeft = (screen.width-width)/2;

	var sFeature = 'scrollbars=yes,top=' + iTop.toString() + ',left=' + iLeft.toString() + ',width=' + width.toString() + ',height=' + height.toString();
	if (feature) sFeature += "," + feature;
	window.open(url, title, sFeature);
}

// Change input text to Upper Char
function UpperCase() {
	if (event.keyCode >= 97 && event.keyCode <= 122)
		event.keyCode -= 32;
}

// Check Date data type
function IsValidDate(value, datefmt) {
	if (value == '') return false;
	var arr = value.split("/");
	if (arr.length != 3) return false;

	var year, month, day;
	if (datefmt == 'dmy') {
		if (arr[2].length != 4) return false;
		year = parseInt(arr[2]);
		month = parseInt(arr[1]);
		day = parseInt(arr[0]);
		alert("origin: " + day + "/" + month + "/" + year);
	}
	else if (datefmt == 'mdy') {
		if (arr[2].length != 4) return false;
		year = parseInt(arr[2]);
		month = parseInt(arr[0]);
		day = parseInt(arr[1]);
		alert(day + "/" + month + "/" + year);
	}
	else
		return false;

	var date = new Date(year,month,day);
	alert(date.getDate() + "/" + date.getMonth() + "/" + date.getFullYear());
	if (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate())
		return true;
	else
		return false;
}

// Resize IFrame to content height
function getDocHeight(doc) {
	var docHt = 0, sh, oh;
	if (doc.height) docHt = doc.height;
	else if (doc.body) {
		if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
		if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
		if (sh && oh) docHt = Math.max(sh, oh);
	}
	return docHt;
}
function setIframeHeight(iframeId) {
	var iframeWin = window.frames[iframeId];
	var iframeEl = document.getElementById? document.getElementById(iframeId): document.all? document.all[iframeId]: null;
	if ( iframeEl && iframeWin ) {
		iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
		var docHt = getDocHeight(iframeWin.document);
		// need to add to height to be sure it will all show
		if (docHt) iframeEl.style.height = docHt + 30 + "px";
	}
}
function resizeiframe(iframeId) {
	var iframe = document.getElementById(iframeId);		
	if (iframe)
		iframe.document.onload=setIframeHeight(iframeId);		
}	