﻿function init_search_text(_frm, _show, _hide){
	var show, hide, text;
	show = $('#'+_show);
	hide = $('#'+_hide);
	text = show.val();
	
	if(hide.val()!='')
		show.val(hide.val());
	
	$('#'+_frm).submit(function(){
		if(show.val()!=text)
			hide.val(show.val());
	});
	show.keyup(function(){
		hide.val(show.val());
	});
	show.blur(function(){
		hide.val(show.val());
		if(show.val()=='') show.val(text);
	});
	show.focus(function(){
		$(this).val(hide.val());
	});
}
function changeLang(_lang){
	try{
		var getStr = "type=language&lang=" + _lang + "&rd=" + Math.random(); 
		var actionURL = "ajax/actions.aspx";				
		
		$.ajax({
			type: "POST",
			url: actionURL,
			data: getStr,
			success: function(msg){
				if (msg.indexOf('err=')!=0) {
					//window.location.reload();
					window.location = 'default.aspx';
				}
			}
		});
		return;
	}catch(ex){}
}
function init_search_text_top(_frm, _show, _hide){
	var show, hide, text;
	show = $('#'+_show);
	hide = $('#'+_hide);
	text = show.val();
	
	if(hide.val()!='')
		show.val(hide.val());
	
	$('#'+_frm).submit(function(){
		if(show.val()!=text)
			hide.val(show.val());
	});
	show.keyup(function(){
		hide.val(show.val());
	});
	show.blur(function(){
		hide.val(show.val());
		if(show.val()=='') show.val(text);
	});
	show.focus(function(){
		$(this).val(hide.val());
	});
}
function process_enter(_frm){
	try{
		$('#'+_frm+' :input').each(function(i){
			$(this).keydown(function(event){
				if (event.keyCode == 13){
					if(_btn==''||!_btn)
						$('#'+_frm).submit();
					else
						$("#"+_btn).click();
				}
			});
		});
	}catch(ex){}
}
function process_enter_top(_frm){
	try{
		$('#'+_frm+' :input').each(function(i){
			$(this).keydown(function(event){
				if (event.keyCode == 13){
					if(_btn==''||!_btn)
						$('#'+_frm).submit();					
				}
			});
		});
	}catch(ex){}
}
function sendmail(_title, _body){
	window.location = "mailto:manhgioi@iboss.com.vn?subject=" + encodeURIComponent(_title) + '&body=' + window.encodeURIComponent(_body);
}
function ChuyenTVKhongDau(strVietNamese)  
{  
	if(!strVietNamese) return '';
	//processing Vietnamese
	var FindText="áàảãạâấầẩẫậăắằẳẵặđéèẻẽẹêếềểễệíìỉĩịóòỏõọôốồổỗộơớờởỡợúùủũụưứừửữựýỳỷỹỵÁÀẢÃẠÂẤẦẨẪẬĂẮẰẲẴẶĐÉÈẺẼẸÊẾỀỂỄỆÍÌỈĨỊÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢÚÙỦŨỤƯỨỪỬỮỰÝỲỶỸỴqwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM";  
	var ReplText="aaaaaaaaaaaaaaaaadeeeeeeeeeeeiiiiiooooooooooooooooouuuuuuuuuuuyyyyyAAAAAAAAAAAAAAAAADEEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOOOUUUUUUUUUUUYYYYYqwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM";  
	var index=-1;  
	var tmp = strVietNamese.split("");
	var length = tmp.length;
	for(var i=0;i<length;i++){
		if(i>=tmp.length) break;
		index=FindText.indexOf(tmp[i]);
		if(index>=0){
			tmp[i]=ReplText.substr(index,1);}
		else{
			tmp[i]="_";}
	}
    return tmp.join("");  
}
// Specific functions
function viewTab(_oid,_site,_curTab){
	try{
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')||(_curTab==null)){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "/ajax/actions.aspx?type=" + _curTab + "&site=" +_site+ "&rd=" + Math.random();
		
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
					obj.innerHTML = HttpRequest.responseText;	
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){alert(ex.tostring);}
}
function viewnews_search(_oid, _key, _page){
	try{
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=news_search&keyword=" + window.encodeURIComponent(_key) + "&page=" + window.encodeURIComponent(_page) + "&rd=" + Math.random();
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
					obj.innerHTML = HttpRequest.responseText;
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function viewnews(_oid, _cid, _page){
	try{	    
	
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		
		var actionURL = "ajax/actions.aspx?type=news&cat=" + window.encodeURIComponent(_cid) + "&page=" + window.encodeURIComponent(_page) + "&rd=" + Math.random();
        
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
					obj.innerHTML = HttpRequest.responseText;
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function viewdesign(_oid, _cid, _page){
	try{
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		
		var actionURL = "ajax/actions.aspx?type=viewdesign&cat=" + window.encodeURIComponent(_cid) + "&page=" + window.encodeURIComponent(_page) + "&rd=" + Math.random();
        
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
					obj.innerHTML = HttpRequest.responseText;
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function viewalldesigns(_oid, _cid){
	try{
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		
		var actionURL = "ajax/actions.aspx?type=viewalldesigns&cat=" + window.encodeURIComponent(_cid) + "&rd=" + Math.random();
        
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
					obj.innerHTML = HttpRequest.responseText;
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function newsType(_oid, _cid, _page){
	try{
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=newslist&newstype=" + window.encodeURIComponent(_cid) + "&page=" + window.encodeURIComponent(_page) + "&rd=" + Math.random();
		
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
					obj.innerHTML = HttpRequest.responseText;
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function viewOtherWeb(_oid,_site,_page,_type){
try {
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		if(obj!=null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=productothersite&site=" + window.encodeURIComponent(_site) + "&page=" + window.encodeURIComponent(_page) + "&rd=" + Math.random();
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
				       obj.innerHTML = HttpRequest.responseText;		
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function newsOtherWeb(_oid,_site,_page,_type){
try {
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		if(obj!=null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=newsfromothersite&site=" + window.encodeURIComponent(_site) + "&page=" + window.encodeURIComponent(_page) + "&rd=" + Math.random();

		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
				       obj.innerHTML = HttpRequest.responseText;					  
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function print_page(_type,_cid,_id,_page,_search){
	try{
		if(rewrite) {
			$('#print').after("<form action='"+baseURL+"print/"+(!_type?"print":_type)+"/"+(!_cid?"0":_cid)+"/"+(!_id?"0":_id)+"/"+(!_page?"1":_page)+"/"+(!_search?"print":ChuyenTVKhongDau(_search))+".html' id='print_form' method='post'><input type='hidden' name='keyword' value='"+_search+"' /></form>");
		}else{
			$('#print').after("<form action='"+baseURL+"print.aspx' id='print_form' method='post'></form>");
			$('#print_form').append("<input type='hidden' name='type' value='"+ _type+"' />");
			$('#print_form').append("<input type='hidden' name='cat' value='"+ _cid+"' />");
			$('#print_form').append("<input type='hidden' name='nid' value='"+ _id+"' />");
			$('#print_form').append("<input type='hidden' name='page' value='"+ _page+"' />");
			$('#print_form').append("<input type='hidden' name='keyword' value='"+_search+"' />");
		}
		$('#print_form').submit();
	}catch(ex){/*alert(ex.message)*/}	
}
function email_page(_title,_body){
	try{
		if(!_body){_body=window.location.toString();}
		if(!_title){_title=document.title;}
		window.location = "mailto:your-friend@email.com?subject=" + encodeURIComponent(_title) + '&body=' + window.encodeURIComponent(_body);
	}catch(ex){}
}
function bookmark_page(_title){
	try{
		var title=_title;var url=window.location.toString();
		if(!title) title=document.title;
		if (window.sidebar) // firefox
			window.sidebar.addPanel(title, url, "");
		else if(window.opera && window.print){ // opera
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
		} else if(document.all)// ie
			window.external.AddFavorite(url, title);
	}catch(ex){}
}
function url_anchor(){
	return unescape(self.document.location.hash.substring(1));
}
function setHomepage(url){
  try{
	if (document.all){
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(url);
	} else if (window.sidebar){
		if(window.netscape){
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage',url);
	}
  }catch(ex){bookmark_page(document.title,url)}
} 
function viewGoldRate(_oid,_loai){
	try {
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		if(obj!=null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=loadgoldratesite&loai=" + window.encodeURIComponent(_loai) + "&rd=" + Math.random();

		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
				       obj.innerHTML = HttpRequest.responseText;					  
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
function loadWeather(_oid){
	try {
		var HttpRequest = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		if (!HttpRequest) return;
		if((_oid==null)||(_oid=='')){return;}
		var obj = document.getElementById(_oid);
		if(!obj){return;}
		if(obj!=null) obj.innerHTML = '<img src="/images/assets/indicator.gif" />';
		var actionURL = "ajax/actions.aspx?type=loadweather" + "&rd=" + Math.random();
                
		var indicator = document.getElementById('processDiv');
		if(indicator!=null){
			indicator.style.display = 'block';
		}
		HttpRequest.open("GET",actionURL);
		HttpRequest.onreadystatechange = function()
		{
		   if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
		   {
			   if(HttpRequest.responseText.indexOf('err=')!=0){
				       obj.innerHTML = HttpRequest.responseText;					  
			   }
			   if(indicator!=null){indicator.style.display = 'none';}
		   }
		}
		HttpRequest.send(null);
		return;
	}catch(ex){}
}
// footer
function initFooter(nid3,seq3) {
	nav3 = document.getElementById(nid3);
	nav3.menu3 = new Array();
	nav3.current = null;
	nav3.menuseq3 = 0;
	navLen3 = nav3.childNodes.length;
	
	allA3 = nav3.getElementsByTagName("a")
	for(q = 0; q < allA3.length; q++) {
		allA3.item(q).onmouseover = allA3.item(q).onfocus = function () {
			nav3.isOver = true;
		}
		allA3.item(q).onmouseout = allA3.item(q).onblur = function () {
			nav3.isOver = false;
			setTimeout(function () {
				if (nav3.isOver == false) {
					if (nav3.menu3[seq3])
						nav3.menu3[seq3].onmouseover();
					else if(nav3.current) {
						if (nav3.current.submenu)
							nav3.current.submenu.style.display = "none";
						nav3.current = null;
					}
				}
			}, 500);
		}
	}

	for (r = 0; r < navLen3; r++) {
		navItem3 = nav3.childNodes.item(r);
		if (navItem3.tagName != "LI")
			continue;

		navAnchor3 = navItem3.getElementsByTagName("a").item(0);
		navAnchor3.submenu = navItem3.getElementsByTagName("ul").item(0);
		
		navAnchor3.onmouseover = navAnchor3.onfocus = function () {
			if (nav3.current) {
				if (nav3.current.submenu)
					nav3.current.submenu.style.display = "none";
				nav3.current = null;
			}
			if (nav3.current != this) {
				if (this.submenu)
					this.submenu.style.display = "block";
				nav3.current = this;
			}
			nav3.isOver = true;
		}
		nav3.menuseq3++;
		nav3.menu3[nav3.menuseq3] = navAnchor3;
	}
	if (nav3.menu3[seq3])
		nav3.menu3[seq3].onmouseover();
}
