function setcookie(cookieName,cookieValue){	
	document.cookie = cookieName+"=" + cookieValue;
	window.alert('Use putvalue/getvalue instead of cookie');
}
function getcookie(cookieName){
	cookies = String(document.cookie) + ";";
	var pos = cookies.indexOf(cookieName + "=");
	if (pos!=-1){
		var start = pos + (cookieName + "=").length;
		var end = cookies.indexOf(";",start);
		var value = cookies.substring(start, end); 
		return value;
	}
	else return 0;
	window.alert('Use putvalue/getvalue instead of cookie');
}
function putvalue(cookieName,cookieValue){	
	document.cookie = cookieName+"=" + cookieValue;
}
function getvalue(cookieName){
	cookies = String(document.cookie) + ";";
	var pos = cookies.indexOf(cookieName + "=");
	if (pos!=-1){
		var start = pos + (cookieName + "=").length;
		var end = cookies.indexOf(";",start);
		var value = cookies.substring(start, end); 
		return value;
	}
	else return 0;
}

function swapmenu(cookieName){
	window.alert('deprecated');
	try{		
		var value = getcookie(cookieName);
		var m1 =document.getElementById('support_title1');
		var m2 =document.getElementById('support_title2');
		var c1 =document.getElementById('support_en');
		var c2 =document.getElementById('support_vn');
		switch(value){
			case 'support_title1': 
				//var m1 = document.getElementById(value);
				m1.firstChild.style.color="#ff0000";				
				m2.firstChild.style.color="#666666";				
				c1.style.display = "";
				c2.style.display = "none";
			break;
			case 'support_title2':				
				//m2.style.backgroundColor="#ff0000";
				m2.firstChild.style.color="#ff0000";
				m1.firstChild.style.color="#666666";				
				c1.style.display = "none";
				c2.style.display = "block";
			break;	
		}
	}catch(e){}
}
function TabControl(tab_bar,active_tab,key_store){
	this.switchTab=function(tab_id,tab_head){
		this.active_tab.className=this.active_tab.className.replace(/\s+[\w]+/,'');
		this.active_tab=document.getElementById(tab_id);
		this.active_tab.className += ' ' + this.active_tab.className + '_active';
		this.active_head.className = this.active_head.className.replace(/\s+[\w]+/,'');
		this.active_head = tab_head;
		this.active_head.className += ' ' + this.active_head.className + '_active';
		if(this.key_store) putvalue(this.key_store,tab_id);
	}
	this.setActive = function(active_tab){
		this.active_tab = active_tab;
		this.active_head = active_tab.firstChild;
		this.active_tab.className += ' ' + this.active_tab.className + '_active';
		this.active_head.className += ' ' + this.active_head.className + '_active';
	}
	this.addTab = function(tab_page){
		this.bar.appendChild(tab_page.firstChild);
	}
	this.bar = tab_bar;
	if(arguments.length == 3) this.key_store=key_store;
	else this.key_store=null;
	this.setActive(active_tab);
}
function rateProduct(o_event,PDid,goto){
	if(o_event.value == -1) return;
	self.location.href = URL_ROOT + 'product-process.php?act=rate&rate=' + o_event.value + '&ID='+PDid + '&go=' + encodeURIComponent(self.location.href);
	
}
function showReviewBox(o_event,o){
	if(o.style.display == 'none' || o.style.display==null || o.style.display=='') o.style.display='block';
	else o.style.display = 'none';
}
function fail(msg,o){
	window.alert(msg);
	o.focus();
	o.select();
	return false;
}
function popup(title,content,css){
	if(typeof(css) != 'undefined' && css) cssModify = '_' + css;else cssModify='';
	var b1 = document.createElement('DIV');
	b1.style.top='200px';
	b1.style.left='250px';
	b1.className="pop pop" + cssModify;
	var b2 = document.createElement('DIV');
	b2.className="pop_title_left pop_title_left" + cssModify;
	b1.appendChild(b2);
	var b3 = document.createElement('DIV');
	b3.className="pop_title_right pop_title_right" + cssModify;
	b2.appendChild(b3);
	var b4 = document.createElement('DIV');
	b4.className="pop_title pop_title" + cssModify;
	b3.appendChild(b4);
	var b5 = document.createElement('STRONG');
	b5.className="pop_title pop_title" + cssModify;
	b4.appendChild(b5);
	b5.innerHTML = title;
	b6= document.createElement('DIV');
	b6.className="btn_close";
	b6.onclick=function(){document.body.removeChild(this.parentNode.parentNode.parentNode.parentNode);}
	b4.appendChild(b6);
	var c1 = document.createElement('DIV');
	c1.className="pop_content pop_content" + cssModify;
	c1.innerHTML = content;
	b1.appendChild(c1);

	var f1 = document.createElement('DIV');
	f1.className="pop_end_left pop_end_left" + cssModify;
	b1.appendChild(f1);
	var f2 = document.createElement('DIV');
	f2.className="pop_end_right pop_end_right" + cssModify;
	f1.appendChild(f2);
	var f3 = document.createElement('DIV');
	f3.className="pop_end pop_end" + cssModify;
	f2.appendChild(f3);
	document.body.appendChild(b1);
	Drag.init(b4,b1);
	return b1;
}
function TabSet(tab_bar_id,tab_page_class,active_tab_id,key_store){
	this.bar = document.getElementById(tab_bar_id);
	this.addTab=function(tab_page_id){
		var tab_page = document.getElementById(tab_page_id);
		if(!tab_page || typeof(tab_page._head_idx) != 'undefined') return;//no add if already added
		var tab_head = tab_page.firstChild;
		var tab_bar = this.bar;
		tab_head._tab_page_id = tab_page_id;
		tab_head.onclick=function(){
			var tab_bar = this.parentNode;//here this means tab_head, now become child node of tab_bar
			var active_tab = document.getElementById(tab_bar._active_tab_id);
			var active_head = tab_bar.childNodes.item(tab_bar._active_head_idx);
			
			active_tab.className = active_tab.className.replace(/\s+[\w]+/,'');//last active tab becomes inactive (normal)
			active_tab.style.display='none';
			active_head.className = active_head.className.replace(/\s+[\w]+/,'');//last active head becomes inactive (normal)
			
			active_tab = document.getElementById(this._tab_page_id);
			active_tab.className += ' ' + active_tab.className + '_active';
			active_tab.style.display='block';
			this.className += ' ' + this.className + '_active';
			
			tab_bar._active_tab_id = this._tab_page_id;//hold last tab id
			tab_bar._active_head_idx = active_tab._head_idx;//hold last head id
			if(typeof(tab_bar._key_store) != 'undefined') putvalue(tab_bar._key_store,tab_page_id);
		}//function onclick
		tab_bar.appendChild(tab_head);
		tab_page._head_idx = tab_bar.childNodes.length-1;//_head_idx holds the index of the head child node in the bar
		tab_page.style.display='none';
	}//function addTab
	this.setActive = function(tab_page_id){
		var tab_page = document.getElementById(tab_page_id);
		tab_page.className += ' ' + tab_page.className + '_active';
		tab_page.style.display='block';
		var tab_head = this.bar.childNodes.item(tab_page._head_idx);
		tab_head.className += ' ' + tab_head.className + '_active';
		this.bar._active_tab_id = tab_page_id;//hold last
		this.bar._active_head_idx = tab_page._head_idx;//hold last
	}
	var tab_page=this.bar;
	var i;
	for(i=0;i < 1000 && (tab_page=tab_page.nextSibling);++i){
		if(tab_page.nodeType == 1 && tab_page.className.indexOf(tab_page_class) >=0 ){ this.addTab(tab_page.id);}
	}
	if(typeof(active_tab_id) != 'undefined' && active_tab_id){
		this.addTab(active_tab_id);
		this.setActive(active_tab_id);
	}
	if(typeof(key_store) != 'undefined' && key_store) this.bar._key_store = key_store;
}