/**THU VIEN GUI **/
var e_x;
var e_y;

function setEvent(event){
    e_x =event.clientX;
    e_y =event.clientY;    
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}


function getWindowsSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth,myHeight];
}

/*****************/
function newResultRow(domain, txtResult,detailInfo)
{
    var newdiv = document.createElement('div'); 
    newdiv.setAttribute('id',domain);
    newdiv.setAttribute('class','row_result');
    newdiv.innerHTML =  txtResult;
    
    var newdiv2 = document.createElement('div'); 
    newdiv2.setAttribute('id',"detail_"+domain);
    newdiv2.setAttribute('class','detailinfo');
    newdiv2.innerHTML =  detailInfo;
    
    document.getElementById("resultdomain").appendChild(newdiv);
    document.getElementById("resultdomain").appendChild(newdiv2);
}

/* phan BREAK NEWS*/
function HightLight(idDiv){
    ResetToDefault();
    var obj = document.getElementById(idDiv);
    obj.style.backgroundImage= "url('styles/style_001/ns/break_menu_bg_hover.png')";
    
}

function ResetToDefault(){    
    var obj = document.getElementById("break_menu").getElementsByTagName("div");

    for(var i=0;i<obj.length;i++)
        if (obj[i].className =="item")
           obj[i].style.backgroundImage= "url('styles/style_001/ns/break_menu_bg.png')";      

}

function SetBG(){
    ResetToDefault();
    var obj = document.getElementById("rownews_0");
    obj.style.backgroundImage= "url('styles/style_001/ns/break_menu_bg_hover.png')";
}

function nothing(){
    return false;
}
/* END BREAK NEWS*/

/* FAQS*/
function DisplayFaqs(code){
	var obj = document.getElementById("faqs_"+code);
	if (obj.style.visibility == "hidden"){
		obj.style.visibility = "visible";
		document.getElementById("faqs_"+code).style.height="auto";
		return 1;
	}else{
		obj.style.height="0px";
		obj.style.visibility = "hidden";
		return 0;
	}
}
/* END FAQS*/

/* pre Page */
function DisplayPage(){
    var objWinPrePro = document.getElementById("prePage");
    var x = e_x;
    var y = e_y;
    var xy_scroll = getScrollXY();
    var wh = getWindowsSize();
    
    if ((x + objWinPrePro.offsetWidth +30)>= wh[0])
        objWinPrePro.style.left = xy_scroll[0]+ x -10 - objWinPrePro.offsetWidth +"px";
    else
        objWinPrePro.style.left = xy_scroll[0]+ x +10+"px";
    if ((y + objWinPrePro.offsetHeight)>= wh[1])
        objWinPrePro.style.top = xy_scroll[1] + y - 25 - objWinPrePro.offsetHeight+"px";
    else
        objWinPrePro.style.top = xy_scroll[1] + y +25+"px";
}

$(function() {
	$('div#prePage').hide();
	$('span.url_prePage').hover(function(e) {
		$('div#prePage').fadeIn();
		$('div#prePage').html($(this).attr('id'));
		setEvent(e);
		DisplayPage();
		
	}, function() {
		$('div#prePage').fadeOut();
	});
});
