

/* JavaScript Document */
function getQueryVariable(variable) {
	try{
		var query = new String(window.location.search);
		if (query.charCodeAt(0) == 63) {query = "&" + query.substring(1,query.length);}

		var vars = query.split("&");
		for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if (pair[0] == variable) {
				var sVal = pair[1];
				sVal = sVal.replace(/\+/gi," ");
				return unescape(sVal);
			}
		} 
		return "";
	}catch(ex){return "";}
}
function redirect(){
	if(location.protocol == "https:"){
		window.location = "http://" + location.host + location.pathname + location.search + location.hash;
	}
}
function decode(str) {
	return unescape(str.replace(/\+/g, " "));
}
function trim(str){str = clean(str); var nIndex = 0;for (var i=0; i<str.length; i++){if (str.charCodeAt(i)!=32){nIndex=i;break;}}str = str.substring(nIndex,str.length);nIndex = str.length;for (var i=str.length-1; i>=0; i--){if (str.charCodeAt(i)!=32){nIndex=i;break;} if (i==0){nIndex=0;}}str = str.substring(0,nIndex+1); if (str==" ") return ""; else return str;}
function clean(str){ if (null==str) return "";  strNew = "";for (var i=0; i<str.length; i++){if (str.charCodeAt(i)==13||str.charCodeAt(i)==10||str.charCodeAt(i)==9){}else{strNew += str.charAt(i);}} return strNew;}

function getFileContent(filename){
	var objXMLHttp = null;
	if (window.XMLHttpRequest){
		objXMLHttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject){
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP")
	}

	objXMLHttp.open("GET", filename, false);
	objXMLHttp.send(null);

	var strDoc = objXMLHttp.responseText;
	return strDoc;
}
function resize(){if (document.getElementById('expand')!=null){document.getElementById('expand').height = getHeight()-132;};}
function showHide(method,section){if (eval("document.all."+section)!=null){if (method == "open" ){eval( section + ".style.display = 'inline'" );}else if (method == "close"){eval( section + ".style.display = 'none'" );}}}
function showContent(content,target){
	showContentObj=eval("document.all."+target);
	if (null!=showContentObj&&showContentObj.innerHTML!=null){
		if(showContentObj.innerHTML!=content){
			showContentObj.innerHTML=content;
		}else{
			showContentObj.innerHTML="";
		}
	}
}
function createTableOpen(){document.write("<TABLE cellspacing='0' cellpadding='0' border='0' align='center'><TR><TD colspan='2' height='7' rowspan='2'><IMG height='7' src='/images/corner1.gif' width='7'></TD><TD style='border-top: 1px solid #BBBBBB;'><IMG height='1' src='/images/clearpixel.gif' width='1' border='0'></TD><TD colspan='2' height='7' rowspan='2'><IMG height='7' src='/images/corner2.gif' width='7'></TD></TR><TR valign='top'><TD><IMG height='5' src='/images/clearpixel.gif' width='1' border='0'></TD></TR><TR valign='top'><TD width='1' style='border-left: 1px solid #BBBBBB;'><IMG height='1' src='/images/clearpixel.gif' width='1' border='0'></TD><TD width='5'><IMG height='1' src='/images/clearpixel.gif' width='5' border='0'></TD><TD bgcolor='#FFFFFF' valign='top'>");}
function createTableClose(){document.write("</TD><TD width='5'><IMG height='1' src='/images/clearpixel.gif' width='5' border='0'></TD><TD width='1' style='border-right: 1px solid #BBBBBB;'><IMG height='1' src='/images/clearpixel.gif' width='1' border='0'></TD></TR><TR valign='bottom'><TD colspan='2' height='7' rowspan='2'><IMG height='7' src='/images/corner3.gif' width='7'></TD><TD style='border-bottom: 1px solid #BBBBBB;'><IMG height='1' src='/images/clearpixel.gif' width='1' border='0'></TD><TD colspan='2' height='7' rowspan='2'><IMG height='7' src='/images/corner4.gif' width='7'></TD></TR></TABLE>");}
function getHeight(){if (window.innerWidth){w = window.innerWidth; h= window.innerHeight;}else if (document.all){w = document.body.clientWidth; h = document.body.clientHeight;}return h;}
function getWidth(){if (window.innerWidth){w = window.innerWidth; h= window.innerHeight;}else if (document.all){w = document.body.clientWidth; h = document.body.clientHeight;}return w;}
function RorC(){ var top=self.screenTop;if (top>9000){/*logout();*/}else {}} 
function logout(){location.replace(urljspprog+'&action=logout');}
function getCookie(name){
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}
function setCookie(name,value){
	document.cookie = name + "=" + escape(value) + ";expires=Thu, 01-Jan-2010 00:00:01 GMT;";
}
function loginStatus(db_cgi_url,where){
   if (where=="bar"){
      if (getCookie('VietnamesePortal_Sesssion')==null)
         document.write("<a class='headermenutop' href='"+db_cgi_url+"/user.cgi'><b>Sign In</b></a><br> <font style='font:10px tahoma'>New User?</font> <a class='headermenutop' href='/cgi-bin/user/community.cgi?do=user_signup'>Sign Up</a>");
      else
         document.write("Welcome,&nbsp;<i><b>"+getCookie('VietnamesePortal_Name')+"</b></i><br>[&nbsp;<a class='headermenutop' href='"+db_cgi_url+"/user.cgi?logout=1'>Sign Out</a>, <a class='headermenutop' href='/cgi-bin/user/community.cgi?do=user_profile'>Profile</a>&nbsp;]");
   }
}
function displayDate(){
    var mydate=new Date();
    var year=mydate.getYear();
    if (year < 1000)
		year+=1900
    var day=mydate.getDay();
    var month=mydate.getMonth();
    var daym=mydate.getDate();
    if (daym<10)
		daym="0"+daym
    var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
    document.write("<font color='#bbbbbb'>"+dayarray[day]+', '+montharray[month]+' '+daym+', '+year+"</font>");
}
function openWindow(url) {
	popupWin = window.open(url,'new_page','width=400,height=400,scrollbars=yes')
}
function diplayOtherFavorite(tpl){
	var sOutput = "::&nbsp;&nbsp;&nbsp;";
	var arrApp = new Array("business","lyric","novel","poem","recipe","singer");
	for (var i=0; i<arrApp.length; i++){
		var sApp = new String(arrApp[i]);
		if (tpl!=sApp)
			sOutput += "<A class='sub_cat_link' href='/cgi-bin/"+sApp+"/mylinks.cgi'>"+sApp.toUpperCase()+"</A>&nbsp;&nbsp;&nbsp;::&nbsp;&nbsp;&nbsp;";
	}
	document.write(sOutput);
}
var base_url = "http://www.vietnameseportal.com/d";
var text = "";
var dictionaries = "ev";
function calldict(word, dict ){
	window.open(base_url+'?word='+word+'&db='+dict,'VNDictionary','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,titlebar=no,width=620,height=400')
}
function ctrlrightclick() {
	if (!window.event.ctrlKey) return true
	var x=document.body.createTextRange();
	x.moveToPoint(window.event.x, window.event.y);
	x.expand("word");
	if (x.text)
	{
		calldict(x.text, dictionaries);
	}
	return false
}
function detectKey() 
{
	if(event.type == 'keydown' && ( (event.keyCode == "A".charCodeAt(0)) || (event.keyCode == "a".charCodeAt(0)) ) )
	{
		if ( (event.ctrlKey) && (event.shiftKey) )
			{
				text = (document.all) ? document.selection.createRange().text : document.getSelection();
				calldict(text, dictionaries);
			}
	}
	return true
}
document.oncontextmenu = ctrlrightclick;
document.onkeydown = detectKey;
function showHits(){
	try{
		var sUrl = location.href;
		var arrUrl = sUrl.split("/");
		if (arrUrl.length>3){
			var sApp = (arrUrl[3]);
			if ("cgi-bin" == sApp)
				sApp = (arrUrl[4]);
			if (null!=sApp && sApp.length>3){
				var id = "0";
				var nEnd = sUrl.indexOf(".html");
				if (sUrl.indexOf(".php")!=-1)
					nEnd = sUrl.indexOf(".php");
				var sTempUrl = sUrl.substring(0,nEnd);
				var nStart = sTempUrl.lastIndexOf("_");
				if (nStart<nEnd)
					id = sUrl.substring(nStart+1,nEnd);
 				var urlcontent = "/cgi-bin/"+sApp+"/info.cgi?ty=hits&ID="+id+"&"+new Date().getTime();
				var sContent = getFileContent(urlcontent);
				if (sContent!="0")
					showContent(sContent,"HitsCount");
			}		
		}
	}catch(ex){}
}
function showMostViews(){
	if (null!==document.all.MostViews){
		var sUrl = location.href;
		if (sUrl.indexOf("/recipe/")!=-1){
			var sContent = getFileContent("/cgi-bin/recipe/info.cgi?ty=most&"+new Date().getTime());
			showContent(sContent,"MostViews");
		}
	}
}
function showLeastViews(){
	try{
		var sUrl = location.href;
		var arrUrl = sUrl.split("/");
		if (arrUrl.length>3){
			var sApp = (arrUrl[3]);
			if ("cgi-bin" == sApp)
				sApp = (arrUrl[4]);
			if (null!=sApp && sApp.length>3){
				var id = "0";
				var nEnd = sUrl.indexOf(".html");
				if (sUrl.indexOf(".php")!=-1)
					nEnd = sUrl.indexOf(".php");
				var sTempUrl = sUrl.substring(0,nEnd);
				var nStart = sTempUrl.lastIndexOf("_");
				if (nStart<nEnd)
					id = sUrl.substring(nStart+1,nEnd);
 				var urlcontent = "/cgi-bin/"+sApp+"/info.cgi?ty=least&ID="+id+"&"+new Date().getTime();
				var sContent = getFileContent(urlcontent );
				showContent(sContent,"LeastViews");
			}		
		}
	}catch(ex){}
}
function showTopSearches(){
	if (null!==document.all.TopSearches){
		var sUrl = location.href;
		if (sUrl.indexOf("/recipe/")!=-1){
			var sContent = getFileContent("/cgi-bin/recipe/info.cgi?ty=searches&"+new Date().getTime());
			showContent(sContent,"TopSearches");
		}
	}
}
function showAll(){
	try{
		var sUrl = location.href;
		var arrUrl = sUrl.split("/");
		if (arrUrl.length>3){
			var sApp = (arrUrl[3]);
			if ("cgi-bin" == sApp)
				sApp = (arrUrl[4]);
			if (null!=sApp && sApp.length>3){
				var id = "0";
				var nEnd = sUrl.indexOf(".html");
				if (sUrl.indexOf(".php")!=-1)
					nEnd = sUrl.indexOf(".php");
				var sTempUrl = sUrl.substring(0,nEnd);
				var nStart = sTempUrl.lastIndexOf("_");
				if (nStart<nEnd)
					id = sUrl.substring(nStart+1,nEnd);
 				var urlcontent = "/cgi-bin/"+sApp+"/info.cgi?ty=all&ID="+id+"&"+new Date().getTime();
				var sContent = getFileContent(urlcontent );
				var arrContent = sContent.split("|");
				if (arrContent.length == 4){
					var count = arrContent[0];
					if (count!="0")
						showContent(count,"HitsCount");
					showContent(arrContent[1],"MostViews");
					showContent(arrContent[2],"LeastViews");
					showContent(arrContent[3],"TopSearches");
				}
			}		
		}
	}catch(ex){}
}
function executeScript(){
	showHits();
	//showMostViews();
	//showLeastViews();
	//showTopSearches();

	//showAll();
}

function displayRSSContent(url){
	try{
		var sendUrl = "/nl/ac?do=@rs&url="+unescape(url)+"&"+new Date().getTime();
		var content  = getFileContent(sendUrl);
		document.write(content);
		var header = document.getElementById("rss_header_div").innerHTML;
		showHide("close","rss_header_div");
		showContent(header,"rss_header");
	}catch(ex){}
}

function viewRSSContent(url){
	try{
		var sUrl = unescape(url);
		if(sUrl.indexOf("yahoo.com")!=-1){ sUrl = "/cgi-bin/geturl.pl?url="+ sUrl.substring(sUrl.indexOf("*")+1,sUrl.length) + "?printer=1";}

		rsswindow=dhtmlmodal.open('RSSBox', 'IFRAME', sUrl , "RSS Content" , 'width=880px,height=550px,center=1,resize=1,scrolling=1');
		document.body.style.overflow = "hidden";
		if (!document.all)
			rsswindow.moveTo("middle",40);
		rsswindow.onclose = function(){ document.body.style.overflow = "scroll"; return true;}
		

	}catch (e) {alert("An exception occurred in the script - (viewRSSContent). \nError name: " + e.name + "\nError message: " + e.message); }	
}

function _includeLeftAds(){
	var sendUrl = "/html/ads_left.html?&"+new Date().getTime();
	var content  = getFileContent(sendUrl);
	document.write(content);
}
function _includeHorizontalAdsText(){
	var sendUrl = "/html/ads_horizontal_text.html?&"+new Date().getTime();
	var content  = getFileContent(sendUrl);
	document.write(content);
}
function _includeHorizontalAdsImage(){
	var sendUrl = "/html/ads_horizontal_image.html?&"+new Date().getTime();
	var content  = getFileContent(sendUrl);
	document.write(content);
}
function _includeRecommendedAds(){
	var sendUrl = "/html/ads_recommended.html?&"+new Date().getTime();
	var content  = getFileContent(sendUrl);
	document.write(content);
}
function _includeSideDetailed(){
	var sendUrl = "/html/side_detailed.html?&"+new Date().getTime();
	var content  = getFileContent(sendUrl);
	document.write(content);
}
function _includeSideCategory(){
	var sendUrl = "/html/side_category.html?&"+new Date().getTime();
	var content  = getFileContent(sendUrl);
	document.write(content);
}
function _includeHeaderAds(){
	var sendUrl = "/html/ads_header.html?&"+new Date().getTime();
	var content  = getFileContent(sendUrl);
	document.write(content);
}