﻿//  ************* setup css for menu top ****************************
var Items = new Array();

function Lever1_Mouseover(obj)
{
    for (var i = 0; i < Items.length; i++)
    {
        var itemId = document.getElementById(Items[i]).id;
        Set_Level1_Normal(itemId);
    }
    Set_Level1_Selected(obj.id)
    document.getElementById("menu_child").innerHTML = document.getElementById(obj.id + "_child").innerHTML;
    //set tro lai home page
     var showtime = setInterval(function() 
       {
            Set_Level1_Selected("mnu_0");
            document.getElementById("menu_child").innerHTML = document.getElementById("mnu_0_child").innerHTML;
            Set_Level1_Normal(obj.id);
        },9000);
}

function Set_Level1_Normal(id)
{
    document.getElementById(id + "_left").className = "mnu_lv1_normal";
    document.getElementById(id + "_center").className = "mnu_lv1_normal";
    document.getElementById(id + "_right").className = "mnu_lv1_normal";
}

function Set_Level1_Selected(id)
{
    document.getElementById(id + "_left").className = "mnu_lv1_selected_left";
    document.getElementById(id + "_center").className = "mnu_lv1_selected_center";
    document.getElementById(id + "_right").className = "mnu_lv1_selected_right";
}

function writeTime(s)
{
	var mydate=new Date(s)
	
	var year = mydate.getYear()
	if (year < 1000)
		year += 1900
	var month = mydate.getMonth() + 1
	if (month < 10)
		month = "0" + month
	var day = mydate.getDate()
	if (day < 10)
		day = "0" + day

	var dayw = mydate.getDay()
	
	var hour = mydate.getHours()
	if (hour < 10)
		hour = "0" + hour
	
	var minute=mydate.getMinutes()
	if (minute < 10)
		minute = "0" + minute
	var dayarray=new Array("Ch&#7911; Nh&#7853;t","Th&#7913; Hai","Th&#7913; Ba","Th&#7913; T&#432;","Th&#7913; N&#259;m","Th&#7913; S&#225;u","Th&#7913; B&#7843;y")
	document.write(dayarray[dayw]+", "+day+"/"+month+"/"+year+",&nbsp;"+hour+":"+minute+"")
}

function getTimeString(s)
{
	document.write("<span class=LargeTime2>");
	writeTime(s);
	document.write("</span>")
}

function GetPostVariable(param, defval)
{
	var	s = '&' + location.search.substr(1);
	var	i = s.indexOf('&' + param + '=');
	if (i == -1) return defval;

	s = s.substr(i + param.length + 2);
	i = s.indexOf('&');
	if (i == -1) return s;

	return s.substr(0, i);
}

//  ************* setup css for Tooltip ****************************

function content4_myChangeNewsContent( oNewsID ) {

	var sNewsContentID = jQuery(oNewsID).attr("id").replace(/news_/, "");
	var oNewsContent = jQuery( "#div_news_" + sNewsContentID )		
	if( !oNewsContent ) {
		return false;
	}
	ddrivetip(oNewsContent.html(), 0, '#fff','auto');
}

// setup CSS cho Tootip jobs //

/*
* dieu khien image slideshow
* Type:     Function use Jquery
* Name:     vonTooltip 
* Date:     Aug 20, 2008
* Update: 	jun 01, 2009
* @author   Tri Do <tridn@von-inc.com >
*/
(function($) {
		$.fn.vonTooltip = function() 
		{	
			var flag;
			var intFixLeft=null;
			function _initialize(e) {
				flag=-1;
				var intToolConLeft=0;
				$('#tooltipcontainer').html($(this).children('.tooltipcontent').html());
				$('#mytooltip').css('top',e.pageY+15);
				$('#mytooltip').css('left',e.pageX-40);		
				$('#mytooltip').show();						 
				return false;
			};
			function _finish() {
				if(flag!=0){
					$('body #mytooltip').hide();
				}
			};
			if(this.attr("static")=="true")
			{
				this.parent().unbind('mouseover','mouseout').mouseover(_initialize);
				$('#tooltipcontainer').hover(function(){
					flag=0;
				},function(){
				 	flag=1;
				});
				$(document).click(_finish);	
			}
			else{
				this.parent().mousemove(_initialize);
				this.parent().mouseout(_finish);
			}
			return false;
		};
})(jQuery);
function addPanel(){
	$('body').append('<div id="mytooltip"><div id="contbox"><div id="tooltipcontainer" class="select-free"><!--[if lte IE 6.5]><iframe></iframe><![endif]--></div><div id="tooltipconnector"></div></div></div>');
	return false;
};
$(document).ready(function(){
	addPanel();
	$('.tooltipcontent').each(function(){
		$(this).vonTooltip();
	});				   
});


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tooltip
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// <a onmouseover="ddrivetip(text, width);" onmouseout="hideddrivetip();" href=""></a>
var offsetfromcursorX=-150 //Customize x offset of tooltip
var offsetfromcursorY=15 //Customize y offset of tooltip

var offsetdivfrompointerX=1 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=1 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false

function ietruebody() {
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

var tipobj = null;

var textTips = [
		{'html':'___CONTENT___', 'width':'372px', 'background':'#FFFFFF'},
		{'html':'<div class="box-tip"><div class="box-top"><div class="box-bt">___CONTENT___</div></div></div>', 'width':'auto', 'background':'#FFFFFF'}
	];

function addTemplate(tpl, w, b){
	if(!tpl) return;
	if( tpl.constructor == Array )
		textTips = tpl
	else {
		if(tpl.constructor == String)
			tpl = {'html':tpl, 'width':(w||'auto'), 'background': (b||'#FFFFFF')};
		textTips[textTips.length] = tpl;
	}
}
//
function ietruebody(){
	if(!window.__initedTooltip) return false;
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}
/*
Example:
<a href="..." onmouseover="ddrivetip('Hello', 0)"; onmouseout="hideddrivetip()">...</a>
<a href="..." onmouseover="ddrivetip($(this).next().innerHTML, 0)"; onmouseout="hideddrivetip()">...</a><p style="display:none">
	fsad fgsd g sdghlkg hjjh
</p>
*/
function ddrivetip(thetext, type, thecolor, thewidth ){
	if(!window.__initedTooltip) return false;
	if(!tipobj)
		tipobj = $('#dhtmltooltip')[0];
	if(!type) type = 0;
	if( type >= textTips.length ) type = textTips.length-1;
	if (ns6||ie){
		if (typeof thewidth!="undefined") {
			if(thewidth != "auto") thewidth += "px";
			tipobj.style.width = thewidth;
		} else {
			tipobj.style.width = textTips[type].width;
		}
		if (typeof thecolor!="undefined" && thecolor!="")
			tipobj.style.backgroundColor = thecolor;
		else
			tipobj.style.backgroundColor = textTips[type].background;
		var html = textTips[type].html.replace( /___CONTENT___/, thetext.replace(/^\s{1,}|\s{1,}$/g, ''));
		tipobj.innerHTML = html;
		enabletip = true;
		tipobj.style.visibility="visible";
		tipobj.style.display="";
		return false;
	}
}

function positiontip(e){
	if(!window.__initedTooltip) return false;
	if(!tipobj)
		tipobj = $('#dhtmltooltip')[0];
	if (enabletip){
		var nondefaultpos=false;
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20;
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20;

		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX;
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY;

		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000;

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if ( rightedge<tipobj.offsetWidth){
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=curX-tipobj.offsetWidth+"px";
			nondefaultpos=true
		}
		else if (curX<leftedge)
			tipobj.style.left="5px";			
		else{
			//position the horizontal position of the menu where the mouse is positioned -130+
			tipobj.style.left= curX+offsetfromcursorX-offsetdivfrompointerX+"px";			
		}
		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight){
			tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px";
			nondefaultpos=true;
		}
		else{
			tipobj.style.top= curY+offsetfromcursorY+offsetdivfrompointerY+"px";
		}
		tipobj.style.visibility="visible";
		tipobj.style.display="";
	}
}

function hideddrivetip() {
	if(!window.__initedTooltip) return false;
	if(!tipobj)
		tipobj = $('#dhtmltooltip')[0];
	if (ns6||ie){
		enabletip=false
		tipobj.style.visibility="hidden";		
		tipobj.style.left="-1000px";
		tipobj.style.backgroundColor='';
		tipobj.style.width='';
	}
}

if( typeof(window.__initedTooltip) == "undefined" )
	window.__initedTooltip = false;
$(window).ready(function(){
	if(window.__initedTooltip) return;
	jQuery('<div id="dhtmltooltip" style="display:none"></div>').appendTo("body");
	tipobj = $("#dhtmltooltip")[0];
	window.__initedTooltip = true;
	$(document).bind("mousemove", positiontip);
	$(window).bind("unload", function(){
		$(document).unbind("mousemove", positiontip);
	});
});

