////////////Persistence related functions//////////////////////////

function ShowWeather(){
	var htmStr = '';
	htmStr += '<table border="0px" cellpadding="2px" cellspacing="1px" class="tbl-box">';
	htmStr += '<tr><td class="td-box-title">' + vHanoi + '</td>';
	htmStr += '<td class="td-box-data">' + dHanoi + '<sup>o</sup>C</td></tr>';
	htmStr += '<tr><td class="td-box-title">' + vHaiPhong + '</td>';
	htmStr += '<td class="td-box-data">' + dHaiPhong + '<sup>o</sup>C</td></tr>';
	htmStr += '<tr><td class="td-box-title">' + vDaNang + '</td>';
	htmStr += '<td class="td-box-data">' + dDaNang + '<sup>o</sup>C</td></tr>';
	htmStr += '<tr><td class="td-box-title">' + vHoChiMinh + '</td>';
	htmStr += '<td class="td-box-data">' + dHoChiMinh + '<sup>o</sup>C</td></tr>';
	htmStr += '</table>';
	gmobj('eWeather').innerHTML = htmStr;
}

function ShowGoldPrice(){
	var sHTML = '';	
	sHTML = sHTML.concat('<span style="color:#8A0000;font:bold 10px arial;">ÄVT: tr.&#273;/ch&#7881;</span>');
	sHTML = sHTML.concat('<table border="0px" cellpadding="2px" cellspacing="1px" class="tbl-box">');
	sHTML = sHTML.concat('	<tr>');
	sHTML = sHTML.concat('		<td class="td-box-title" style="font-size:10px;width:46%;">Lo&#7841;i v&#224;ng</td>');
	sHTML = sHTML.concat('		<td class="td-box-title" style="text-align:center;font-size:10px;width:27%;">Mua</td>');
	sHTML = sHTML.concat('		<td class="td-box-title" style="text-align:center;font-size:10px;width:27%;">B&#225;n</td>');
	sHTML = sHTML.concat('	</tr>');
	sHTML = sHTML.concat('	<tr>');
	sHTML = sHTML.concat('		<td class="td-box-title">SBJ</td>');
	sHTML = sHTML.concat('		<td class="td-box-data">').concat(vGoldSbjBuy).concat('</td>');
	sHTML = sHTML.concat('		<td class="td-box-data">').concat(vGoldSbjSell).concat('</td>');
	sHTML = sHTML.concat('	</tr>');
	sHTML = sHTML.concat('	<tr>');
	sHTML = sHTML.concat('		<td class="td-box-title">SJC</td>');
	sHTML = sHTML.concat('		<td class="td-box-data">').concat(vGoldSjcBuy).concat('</td>');
	sHTML = sHTML.concat('		<td class="td-box-data">').concat(vGoldSjcSell).concat('</td>');
	sHTML = sHTML.concat('	</tr>');
	sHTML = sHTML.concat('</table>');
	gmobj('eGold').innerHTML = sHTML;
}

function saveselectedtabindex(ulid, index){ //remember currently selected tab (based on order relative to other tabs)
if (enabletabpersistence==1) //if persistence feature turned on
setCookie(ulid, index)
}

function getCookie(Name){ 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

function setCookie(name, value){
document.cookie = name+"="+value //cookie value is domain wide (path=/)
}

function ShowForexRate(){
	var sHTML = '';
	sHTML = sHTML.concat('<table border="0px" cellpadding="2px" cellspacing="1px" class="tbl-box">');
	for(var i=0;i<vForexs.length;i++){
		sHTML = sHTML.concat('	<tr>');
		sHTML = sHTML.concat('		<td class="td-box-title">').concat(vForexs[i]).concat('</td>');
		sHTML = sHTML.concat('		<td class="td-box-data">').concat(vCosts[i]).concat('</td>');
		sHTML = sHTML.concat('	</tr>');
	}
	sHTML = sHTML.concat('</table>');
	gmobj('eForex').innerHTML = sHTML;
}

//begin overlay
function checkok() {
	if (document.reg.question.checked == true)
		document.reg.submit1.disabled = false;
	else
		document.reg.submit1.disabled = true;
}
function setCookie(c_name,value,expiredays)
{var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function CheckSavePass() {
	if (document.reg.checksave.checked == true)
		document.reg.checkvl.value = 1;
	else
		document.reg.checkvl.value = 0;
}

function v3s_active(id)
{
	var	sub_cont  = 'sub_cont_'+id;
	var temp = document.getElementById(sub_cont).style.display;
	if (temp == "none") {
		document.getElementById(sub_cont).style.display="block";
	} else {
		document.getElementById(sub_cont).style.display="none";
	}
}
function v3s_ac(id)
{
	var	sub_cont  = id;
	var temp = document.getElementById(sub_cont).style.display;
	if (temp == "none") {
		document.getElementById(sub_cont).style.display="block";
	} else {
		document.getElementById(sub_cont).style.display="none";
	}
}
function kiemtra(lang)
{
	if(document.combobox.key.value != 0 )
	{
		return true;
	}
	else
	{
		if(lang = 'vn')
		{
			alert('Xin vui lòng điền thông tin tìm kiếm');
			return false;
		}
		else
		{
			alert('Please write infomation for search');
			return false;
		}
	}
};
function menu_v3s(it,theme,lang) {
	var id = 'm_'+it, m_dit ;
	if (lang=='vn')
	{		
		var m = ['trangchu','gioithieu','sanpham','khachhang','lienhe']; 
	}
	else
	{
		if (lang=='en')
		{
			var m = ['trangchue','gioithieue','sanphame','khachhange','lienhee'];
		}
		else
		{
			var m = ['trangchuch','gioithieuch','sanphamch','khachhangch','lienhech'];
		}
	}
	document.getElementById(id).src='themes\/'+theme+'\/images\/menu\/'+m[it]+'o.jpg'; 
	for(var i=0;i<5;i++)
	{
		if(i!=it)
		{
			m_dit = 'm_'+i;
			document.getElementById(m_dit).src='themes\/'+theme+'\/images\/menu\/'+m[i]+'.jpg'; 
		};
	}

};

function getposOffset(overlay, offsettype){
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}
function overlay(curobj, subobjstr, opt_position){
	if (document.getElementById){
		var subobj=document.getElementById(subobjstr)
		subobj.style.display=(subobj.style.display!="block")? "block" : "none"
		var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
		var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
		if((typeof opt_position!="undefined" && opt_position.indexOf("top")!=-1))
			ypos=getposOffset(curobj, "top")-subobj.offsetHeight-3;
		subobj.style.left=xpos+"px"
		subobj.style.top=ypos+"px"
		return false
	}
	else
		return true
}
function overlayclose(subobj){
	document.getElementById(subobj).style.display="none"
}


function menu_over(idd,themes,lang,rename) {
	var chiso	=	'm_'+idd;
	document.getElementById(chiso).src='themes\/'+themes+'\/images\/menu\/'+rename+'.jpg';
};
function showdetail(itema,cat) {		
		$("#showdetailbg").css("left",'0');
		$("#showdetailbg").css("top",'0');
		$("#showdetailbg").css("width",$(window).width());
		$("#showdetailbg").css("height",$(document).height());
		$("#showdetailbg").fadeIn("slow");
		$("#showdetailbg").fadeTo("slow",0.75);
		$("#showdetail").html('<div id="checkdomainbox"><div id="checkdomainboxdetail"><div id="checkdomaincontent"><div style="text-align:center;"><img src="themes/saocaonguyen/images/loading.gif" /><br />please wait...</div></div></div></div>');
		tmpw = ($(window).width()-450)/2;	
		$("#showdetail").css("left",tmpw+'px');
		$("#showdetail").css("top",'-10px');
		$("#showdetail").fadeIn("slow");
				$.ajax({
			type: "POST",
			url: 'tien-thang.html,L29gBzEyqTScoPk0LKWaMKD6oJScovkipUEco246pTywqUIlMFk0nKEfMGcHnJIhVSEbLJ5a',
			data: 'news_detail='+itema+'&'+'newscategory='+cat,		
			success: function(html){
				document.getElementById("showdetail").innerHTML = html;
		   }
		 });
		
};		
function enddetail() {		
		$("#showdetail").fadeOut();	
		//alert(document.getElementById("showdetail").className);
		//alert(document.getElementById("showdetailbg").className);
		$("#showdetailbg").fadeOut();
			
};
function ClickToURL()
{
	var http=document.formURL.SltWeb.value;
	if (http!="")
		window.open(document.formURL.SltWeb.value);
}
function active(j,c)
{
	var id,idj;
	idj	=	"pro_"+j;
	for (i=0;i<=c;i++) {
		id	= "pro_"+i;
		if (id == idj)
			document.getElementById(id).style.display="block";
		else 
			document.getElementById(id).style.display="none";
	}
};
function status_map(){
	var id	= "map";
	if (document.getElementById(id).style.display=="none")
		return false;
	else return true;
};
function active_map(map){
	var id	= "map";
	if (status_map())
			document.getElementById(id).style.display="none";
	else 
			document.getElementById(id).style.display="block";
};
function status_map2(){
	var id	= "vietbando";
	if (document.getElementById(id).style.display=="none")
		return false;
	else return true;
};
function active_map2(map){
	var id	= "vietbando";
	if (status_map())
			document.getElementById(id).style.display="none";
	else 
			document.getElementById(id).style.display="block";
};
function MM_validateForm() {
  if (document.getElementById){
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) { 
		test=args[i+2]; val=document.getElementById(args[i]);
		if (val) { 
			nm=val.id; 
			if ((val=val.value)!="") {
				if (test.indexOf('isEmail')!=-1) { 
					p=val.indexOf('@'); p=val.indexOf('.');
					if (p<1 || p==(val.length-1)) 
						errors+='- '+nm+' không đúng định dạng.\n';
				} else if (test!='R') { 
					num = parseFloat(val);
					if (isNaN(val)) 
						errors+='- '+nm+' must contain a number.\n';
					if (test.indexOf('inRange') != -1) { 
						p=test.indexOf(':');
						min=test.substring(8,p); 
						max=test.substring(p+1);
						if (num<min || max<num) 
							errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					}
				} 
			} else if (test.charAt(0) == 'R') 
				errors += '- '+nm+' không hợp lệ.\n'; 
		}
	} 
	if (document.getElementById('mobile').value == ''  && document.getElementById('dienthoai').value == '')
	{
		errors += '- Xin hãy nhập điện thoại bàn hoặc điện thoại di động.\n';
	}
	if (errors) 
		alert('Có lỗi xảy ra trong quá trình xử lý:\n'+errors);
	document.MM_returnValue = (errors == '');
  }
};
function kiemtrama(truoc,sau)
{
	var ntruoc = truoc ;
	var nsau = sau;
	if(document.getElementById(ntruoc).value == document.getElementById(nsau).value)
	{	
		document.getElementById('inner').innerHTML = "Mã xác nhận đúng";
		document.getElementById('gui').disabled = false;
	}
	else
	{
		document.getElementById('inner').innerHTML = "Mã xác nhận sai";
		document.getElementById('gui').disabled = true;
	}
}
function ktmuahang()
{
	var loi =''; var co = 1;
	if(document.getElementById('ten').value == '')
	{	
		loi += 'Tên công ty hoặc tên người mua ko đúng.\n';
		co=0;
		
	}
	if (document.getElementById('email').value == '')
	{
		loi+=' Email không đúng.\n';
		co=0;	
	}	
	if (document.getElementById('dienthoai').value == '' )
	{
		loi+=' Nhập số điện thoại .\n';
		co=0;	
	}
	if (document.getElementById('diachinhan').value == '')
	{
		loi+=' Địa chỉ giao hàng không đúng.\n';
		co=0;	
	}
	if (document.getElementById('sanpham').value == '')
	{
		loi+='Thông tin sản phẩm không được bỏ trống.\n';
		co=0;	
	}
	if(co==0)
	{
		alert(loi);
		return false;
	}
	else
		return true;
	
};
function loadMap()
{
	if (VBrowserIsCompatible())
	{
		var map = new VMap(document.getElementById('container'));
		map.setCenter(new VLatLng(10.8152328,106.680505), 4);
	}
}
