/*@cc_on @*/
function getChecked(name){
/*	getChecked(name): return a comma seperated value (value1,value2,value3...)for all checkbox with same name
name	: name of the checkbox
need to create array of check box with same name like:
<input type=checkbox name='name' value=value1>
<input type=checkbox name='name' value=value2>
<input type=checkbox name='name' value=value3>
*/
	var o=document.getElementsByName(name);
	var i,s,v;
	for(i=0,s='';i < o.length; ++i){
		v=o.item(i);
		if(v.type == "checkbox"){
			if(v.checked) s += ',' + String(v.value);
		}
	}
	return s.substr(1);//remove leading ,
}
//////////////////////
function getIdValuesPair(name){
/*	getIdValuesPair(name): return a comma seperated (id1=value1,id2=value2...) for all input with same name
name	: name of input
need to create array of input with same name like:
<input type=text name='name' id='id1' value=value1>
<input type=text name='name' id='id2' value=value2>
<input type=text name='name' id='id3' value=value3>
*/
	var o=document.getElementsByName(name);
	var s='';
	for(i=0;i<o.length;++i){
		v=String(o.item(i).value);
		if(v != '') s += ',' + o.item(i).id + '=' + v;
	}
	return s.substr(1);
}
//////////////////////
function checkAll(name){
/*	checkAll(name):	mark as checked all checkbox with same name
name	: name of the checkbox
*/
	var o=document.getElementsByName(name);
	var i;
	for(i=0;i < o.length; o.item(i).checked=true, ++i);
}
////////////////////////
function setAll(name,state){
/*	setAll(name,state):	mark all checkbox with same name to the specified state
name	: name of the checkbox
state	: true/false status
*/
	var o=document.getElementsByName(name);
	var i;
	for(i=0;i < o.length; o.item(i).checked=state, ++i);
}

////////////////////////
function clearAll(name){
/*	clearAll(name):	uncheck all checkbox with same name
name	: name of the checkbox
*/
	var o=document.getElementsByName(name);
	var i;
	for(i=0;i < o.length; o.item(i).checked=false, ++i);
}
/////////////
////////////////////////
function resetAllName(name){
/*	resetAllName(name):	set name to empty string to exclude from submitting
name	: name of the checkbox
*/
	var o=document.getElementsByName(name);
	var i;
	for(i=0;i < o.length; o.item(i).name='', ++i);
}
/////////////
function urlgo(page,q){
/*	urlgo(page,q,[<name1,value1>[,..n]][,'-',<namex>[,...n]])
	tell browser to goto specified location
page:	page name to goto
q	:	query string
<name1,value1>:	append parameter name=value to query string q
namex	: chop this parameter from query string q
*/
	var c=arguments.length;
	var re=new RegExp;
	for(i = 2; (argv=String(arguments[i])) != '-' && i < c; ++i){
		re.compile("(?:\\&|^)" + argv + "=[^\\&]*(?=\\&|$)","ig");
		q=q.replace(re,"&");//append to url
		q += "&" + argv + "=" + String(arguments[++i]);
	}
	for(++i; i < c; ++i){ //ignore -, denote a start of chopping parameters)
		argv=String(arguments[i]);
		re.compile("(?:\\&|^)" + argv + "=[^\\&]*(?=\\&|$)","ig");
		q=q.replace(re,"&"); //chop from url
	}
	q=q.replace(/\&{2,}/ig,"&").replace(/(?:^\&|\&$)/ig,"");
	window.location.href=page + "?" + q;
}
///////////////
function urlchop(q){
/*	urlchop(q,[name][,...n])
	chop name from query string q
q	: original query string
name: chop this parameter from q
*/
	var c=arguments.length;
	var re=new RegExp;
	for(i=1; i < c; ++i){ //ignore -, denote a start of chopping parameters)
		argv=String(arguments[i]);
		re.compile("(?:\\&|^)" + argv + "=[^\\&]*(?=\\&|$)","ig");
		q=q.replace(re,"&"); //chop from url
	}
	return q.replace(/\&{2,}/ig,"&").replace(/(?:^\&|\&$)/ig,"");
}
////////////////
function urlformat(q){
/*	urlgo(q,[<name1,value1>[,..n]][,'-',<namex>[,...n]])
	append or chop specified parameters from query string
q				: original query string
<name1,value1>	: append parameter name1=value1 to query string q
namex			: chop this parameter from q
*/
	var c=arguments.length;
	var re=new RegExp;
	for(i = 1; (argv=String(arguments[i])) != '-' && i < c; ++i){
		re.compile("(?:\\&|^)" + argv + "=[^\\&]*(?=\\&|$)","ig");
		q=q.replace(re,"&");//append to url
		q += "&" + argv + "=" + String(arguments[++i]);
	}
	for(++i; i < c; ++i){ //ignore -, denote a start of chopping parameters)
		argv=String(arguments[i]);
		re.compile("(?:\\&|^)" + argv + "=[^\\&]*(?=\\&|$)","ig");
		q=q.replace(re,"&"); //chop from url
	}
	return q.replace(/\&{2,}/ig,"&").replace(/(?:^\&|\&$)/ig,"");
}
/*created by DungHM*/
function hideButton(){
//An button tren thanh cong cu voi doi so la id cua td chua nut	
	argLen = arguments.length;
	for(i=0;i<argLen;i++){
		arg = String(arguments[i]);
		with(parent.banner){
			document.getElementById(arg).style.display="none";
		}
	}
}
function showButton(){	
//Hien button tren thanh cong cu voi doi so la id cua td chua nut	
	argLen = arguments.length;
	for(i=0;i<argLen;i++){
		arg = String(arguments[i]);
		with(parent.banner){
			document.getElementById(arg).style.display="";
		}
	}
}
function oversort(id){
	document.getElementById(id).style.backgroundImage="url(../images/over.gif)";	
}
function outsort(id){
	document.getElementById(id).style.backgroundImage="url(../images/bg-product.gif)";	
}
function contextmenu(id){	
	document.getElementById(id).style.visibility = "visible";
}
function contextout(id){
	document.getElementById(id).style.visibility = "hidden";
}
function checknumber(val){
	if (isNaN(val)){
		alert("Day khong phai la mot so!");
		return false;
	}
	if (val == null || val ==""){
		alert("Ban khong duoc bo trong truong nay!");
		return false;
	}
	return true;
}
var __tested__ = false;
function storeCaret (textEl) {
	__tested__=true;
	if (textEl.createTextRange) {
		textEl.caretPos = document.selection.createRange().duplicate();
	}
}
function insertAtCaret (textEl, text) {
	if(!__tested__) return;
	if (textEl.createTextRange && textEl.caretPos) {
		var caretPos = textEl.caretPos;
		caretPos.text =
		caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?	text + ' ' : text;
		textEl.focus();
	}
	else textEl.value = text;
}
function EnterToBr(){
	if(window.event.keyCode == 13 && ! window.event.shiftKey){
		insertAtCaret(window.event.srcElement,"<br>");
	}
}

//Gui cho nguoi than
function showpopup(url){
	if (url=="") return;
	var content = "<form id='sendform' action='sendto.php' method='post' onSubmit='return checkform(this);'>";
	content += "<table width='100%' style='font-size:11px' bgcolor='#EFEBDE'><tr><td colspan='2' class='boxTitle'><input type='hidden' name='url' value='"+url+"'>G&#7917;i cho b&#7841;n b&#232;</td></tr>";
	content += "<tr><td class='text'>Ng&#432;&#7901;i g&#7917;i:&nbsp;</td><td><input name='sendername' class='inputbox' type='text' style='font-size:11px;width:250px;' value=''></td></tr>";
	content += "<tr><td class='text'>Email ng&#432;&#7901;i g&#7917;i:&nbsp;</td><td><input class='inputbox' name='senderemail' type='text' style='font-size:11px;width:250px;'  value=''></td></tr>";
	content += "<tr><td class='text'>Ng&#432;&#7901;i nh&#7853;n:&nbsp;</td><td><input type='text' class='inputbox' name='receivername' style='font-size:11px;width:250px;'  value=''></td></tr>";
	content += "<tr><td class='text'>Email ng&#432;&#7901;i g&#7917;i:&nbsp;</td><td><input type='text' class='inputbox' name='receiveremail' style='font-size:11px;width:250px;'  value=''></td></tr>";
	content += "<tr><td class='text'>Ghi ch&#250;:&nbsp;</td><td><textarea style='overflow:auto' class='inputbox' name='sendernote' style='font-size:11px;width:250px;height:100px'></textarea></td></tr>";
	content += "<tr><td class='text' colspan='2' style='text-align:center'><input type='submit' value='G&#7917;i &#273;i' style='font-family:tahoma;font-size:11px;border:1px solid #000000'>&nbsp;<input type='button' value='B&#7887; qua' style='font-family:tahoma;font-size:11px;border:1px solid #000000' onClick=\"javascript:closebox('sendtofriend');\"></td></tr></table>";
	content += "</form>";
	if ($('sendtofriend')) document.body.removeChild($('sendtofriend'));
	oDiv = document.createElement('DIV');	
	oDiv.id="sendtofriend";
	oDiv.style.fontSize="11px";
	oDiv.style.border="1pt solid #0A2C6F";
	oDiv.style.padding="0px";
	oDiv.style.position="absolute";
	oDiv.style.textAlign="justify";
	oDiv.style.width="380px";
	oDiv.style.height="150px";
	oDiv.style.top="200px";
	oDiv.style.left="320px";
	oDiv.style.backgroundColor="#FFFFFF";
    oDiv.innerHTML = content;
	oSelect = document.getElementsByTagName("select");
	for(var i=0;i<oSelect.length;i++){
		oSelect[i].style.visibility="hidden";	
	}
	document.body.appendChild(oDiv);	
}

function showImage(imgsrc,o){
	if (imgsrc=="") return;
	if ($('picturebox')) document.body.removeChild($('picturebox'));
	if ($('banner_top')) $('banner_top').style.visibility="hidden";
	oDiv = document.createElement('DIV');
	oDiv.id = "picturebox";
	oDiv.style.zIndex = "1";
	oDiv.innerHTML = '<div style="display:block;height:20px;text-transform:uppercase;font-weight:bold; float:left;"><strong style="cursor:pointer;padding:7px;font-size:14px;" onClick="javascript:closebox(\'picturebox\');" title="Click chu&#7897;t l&#234;n &#7843;nh &#273;&#7875; &#273;&#243;ng">[X]</strong><div>';
	oDiv.innerHTML += "<img src='"+imgsrc+"' style='cursor:pointer;display:block;' title='Click chu&#7897;t l&#234;n &#7843;nh &#273;&#7875; &#273;&#243;ng' onClick=\"javascript:closebox('picturebox');\">";
	oDiv.style.border="1px solid #CCCCCC";
	oDiv.style.padding="0px";
	oDiv.style.position="absolute";
	oDiv.style.width=o.offsetWidth+10;
	oDiv.style.height=o.offsetHeight+50+"px";
	oDiv.style.top= (posY(o)-80) + 'px';	
	oDiv.style.left= (posX(o)-100) + 'px';
	oDiv.style.backgroundColor="#FFFFFF";	
	document.body.appendChild(oDiv);
	oDiv.style.visibility ="hidden";
	fade(oDiv,"visible");
}

function closebox(id){
	oDiv = $(id);	
	if ($('banner_top')) $('banner_top').style.visibility="visible";
	document.body.removeChild(oDiv);	
	oSelect = document.getElementsByTagName("select");
	for(var i=0;i<oSelect.length;i++){
		oSelect[i].style.visibility="visible";	
	}
}

function fade(obj,type) {
	try{
    obj.style.filter="blendTrans(duration=2)";
    // Make sure the filter is not playing.
    if (obj.filters.blendTrans.status != 2) {
        obj.filters.blendTrans.apply();
        obj.style.visibility=type;
        obj.filters.blendTrans.play();
    }
	}catch(e){
		obj.style.visibility="visible";
	};
}

function checkform(oForm){
	var regex = /^(([\-\w]+)\.?)+@(([\-\w]+)\.?)+\.[a-zA-Z]{2,4}$/;
	var sender=oForm.senderemail.value;
	var receiver=oForm.receiveremail.value;
	for (var i=0;i<oForm.elements.length-2;i++){
		if (oForm.elements[i].value==""){
			alert("Ban khong duoc de trong truong nay");
			return false;
		}
	}
	if (!regex.test(sender) || !regex.test(receiver)){
		alert("Email khong dung dinh dang");
		return false
	}
	return true;
}	
function loadingbox(){
	this.loading = function (content,width,height){
		if (document.getElementById("loading")){
			document.body.removeChild(document.getElementById("loading"));
		}
		var div = document.createElement("DIV");
		div.setAttribute("id","loading");
		div.innerHTML = content;
		div.style.position = "absolute";
/*@if(1)
		div.style.left =(posX(document.getElementById("contentpanel")) -50)+"px";
		div.style.top = (posY(document.getElementById("contentpanel"))-100)+"px";
/*@else@*/
		div.style.left = posX(document.getElementById("contentpanel"))+"px";
		div.style.top = posY(document.getElementById("contentpanel"))+"px";
/*@end@*/
		div.style.width = width+"px";
		div.style.height = height+"px";
		div.style.textAlign = "center";
		div.style.verticalAlign = "middle";		
		div.style.padding = "0px";
		div.style.zIndex = 1;
		div.onclick = function (){
			document.body.removeChild(div);
		}
		document.body.appendChild(div);
	}
	this.draw = function (content,width,height){
		if (document.getElementById("loading")){
			document.body.removeChild(document.getElementById("loading"));
		}
		var div = document.createElement("DIV");
		div.setAttribute("id","loading");
		div.innerHTML = content;
		div.style.position = "absolute";
/*@if(1)
		div.style.left =(posX(document.getElementById("contentpanel")) +10)+"px";
		div.style.top = (posY(document.getElementById("contentpanel"))+15)+"px";
/*@else@*/
		div.style.left = posX(document.getElementById("contentpanel"))+"px";
		div.style.top = posY(document.getElementById("contentpanel"))+"px";
/*@end@*/
		div.style.width = width+"px";
		div.style.height = height+"px";
		div.style.textAlign = "center";
		div.style.verticalAlign = "middle";
		div.style.border = "2px solid #333333";
		div.style.fontColor = "#FFFF00";
		div.style.padding = "0px";
		div.style.zIndex = 1;
		div.style.backgroundColor = "#FFFFCC";
		div.onclick = function (){
			document.body.removeChild(div);
		}
		document.body.appendChild(div);
	}
	this.messagebox = function (content,width,height){
		if (document.getElementById("messagebox")){
			document.body.removeChild(document.getElementById("messagebox"));
		}
		var div = document.createElement("DIV");
		content = content + "<input type = 'button' value = '&nbsp;&nbsp;&nbsp;&#272;&oacute;ng&nbsp;&nbsp;&nbsp;' onClick = \"document.body.removeChild($('messagebox'));\" style='border:1px solid #CCCCCC;'><br/><a href='index.php' style='color:blue;'>http://www.dienthoaitrungtin.com</a><br/>";
		div.setAttribute("id","messagebox");
		div.innerHTML = content;
		div.style.position = "absolute";
/*@if(1)
		div.style.left =(posX(document.getElementById("contentpanel")) -5)+"px";
		div.style.top = (posY(document.getElementById("contentpanel"))-10)+"px";
/*@else@*/
		div.style.left = posX(document.getElementById("contentpanel"))+"px";
		div.style.top = posY(document.getElementById("contentpanel"))+"px";
/*@end@*/
		div.style.width = width+"px";
		div.style.height = height+"px";
		div.style.textAlign = "center";
		div.style.verticalAlign = "middle";
		div.style.border = "2px solid #333333";
		div.style.fontColor = "#FFFF00";
		div.style.padding = "2px 0px 0px 0px";
		div.style.zIndex = 1;
		div.style.backgroundColor = "#FFFFCC";
		//div.onclick = function (){
			//document.body.removeChild(div);
		//}
		document.body.appendChild(div);
	}
	this.clear = function (){
		var div = document.getElementById("loading");
		if (div){
			document.body.removeChild(div);
		}else{
			return;
		}
		
	}
}
function mediaPreview(url){
	window.open("trial.php?url="+url,null,"height=200,width=200,status=no,toolbar=no,menubar=no,location=no");
}

function checkEmail(form,input){
	var regex = /^(([\-\w]+)\.?)+@(([\-\w]+)\.?)+\.[a-zA-Z]{2,4}$/;
	if (!regex.test(input)){
		alert("Email khong dung dinh dang");
		return;
	}
	submitTextForm(form,'text','cust-process.php?act=resetpass');
	return true;
}

function vote(f){
	var v = '';
	for(i=0;i < f.elements.length;++i)
		if(f.elements[i].type == 'checkbox' || f.elements[i].type == 'radio'){
			if(f.elements[i].checked)
				v += '&' + f.elements[i].name + '=' + encodeURI(f.elements[i].value);
		}else{
			v += '&' + f.elements[i].name + '=' + encodeURI(f.elements[i].value);
		}
	v = v.substr(1);//exclude leading &
	var sParams = "status=no,scrollbars=yes,toolbar=no,menubar=no,resizable=yes,location=no,height=300,width=500,top=100,left=200";
	var wname = "pollwindow";
	var dest = "poll.php?"+v;
	window.open(dest,wname,sParams);
	return false;
}
function isEmpty(obj){
	var value = obj.value;
	if (value=="" || value == null){
		return false;
	}
	return true;
}

function isEmail(obj){
	var str = obj.value;
	var emailPattern = /^(([\-\w]+)\.?)+@(([\-\w]+)\.?)+\.[a-zA-Z]{2,4}$/;
	if (isEmpty(obj)){
		if (!emailPattern.test(str)){
			return false;
		}
	}	
	return true;
}
function showMenuNode(o){
	var u,v,w,i=0,j=0,k=0;
	v = o.nextSibling;
/*	if(u=v){
		w=u.previousSibling;
		while(w && i<20){
			w.nextSibling.style.display='none';
			w=w.previousSibling;
			++i;
		}
		w=u.nextSibling;
		while(w && i<20){
			w.nextSibling.style.display='none';
			w=w.nextSibling;
			++i;
		}
	}*/
	if(v.style.display=='list-item') v.style.display='none';
	else v.style.display  ='list-item';
	return false;
}
function posX(obj){
	var vX=0;
	if(obj.x) vX=obj.x;
	else if(obj.offsetParent)
		while(obj.offsetParent){
			vX+=obj.offsetLeft;
			obj=obj.offsetParent;
		}
	return vX;
}
function posY(obj){
	var vX=0;
	if(obj.y) vX=obj.y;
	else if(obj.offsetParent)
		while(obj.offsetParent){
			vX+=obj.offsetTop;
			obj=obj.offsetParent;
		}
	return vX;
}
function setCurrency(cid){
	document.cookie='cy='+cid;
}
function setLanguage(lid){
	document.cookie='l='+lid;
}
/*---end---*/
/*@cc_on
function setMaxSpecialImgSize(o){
	if(o.width > 80) o.width=80;
}
@*/