// JavaScript Document
function gotoUrl(str){
	window.location.href = str;
}
function open_vote(urlx,twidth,theight)
{
	var frmPoll = document.voteForm;
	var len = frmPoll.elements["answer"].length;
	var check = false;
	var id = 0;
	
	for(var i=0; i<len ; i++) 
		if(frmPoll.elements["answer"][i].checked)
			{
				check = true;
				id = frmPoll.elements["answer"][i].value;
				break;
			}
	
	if(!check) {
		alert("Xin vui lòng chọn 1 tiêu chí bình chọn !");		
	}
	else {
		var strurl= urlx + '&selected_id=' + id;
		var tposx= (screen.width- twidth)/2
		var tposy= (screen.height- theight)/2;		
		var newWin=window.open(strurl,"HanhChinhVN","toolbar=no,width="+ twidth+",height="+ theight+ ",directories=no,status=no,scrollbars=yes,resizable=no, menubar=no")
		newWin.moveTo(tposx,tposy);
		newWin.focus();
	}
}
function open_vote_result(urlx,twidth,theight)
{
	var strurl= urlx;
	var tposx= (screen.width- twidth)/2
	var tposy= (screen.height- theight)/2;

	var newWin=window.open(strurl,"HanhChinhVN","toolbar=no,width="+ twidth+",height="+ theight+ ",directories=no,status=no,scrollbars=yes,resizable=no, menubar=no");
	newWin.moveTo(tposx,tposy);
	newWin.focus();
}
function confirmSubmit()
{
var agree=confirm("Are you sure ? Press [OK] to Yes, [Cancel] to No");
if (agree)
	return true ;
else
	return false ;
}
function changeimg(img){
	document.getElementById("big_image").src = ""+img;
	return false;
}


function submitsearch(){
	var f = document.getElementById('frm_head');
	var keyword1 = f.keyword.value;
	var smod1 = f.smod.value;
	if (keyword1=='Nhập từ khoá') return false;
	window.location.href = nvcms_url+"?mod="+smod1+"&keyword="+keyword1;

	return false;
}
function submitFormWithEnter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;	
	if (keycode == 13)
	{	
		var f = document.getElementById('frm_head');
		var keyword1 = f.keyword.value;
		var smod1 = f.smod.value;
		window.location.href = nvcms_url+"?mod="+smod1+"&keyword="+keyword1;
		return false;
	}
	else
	return true;
}

/*************************************************************************
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  Copyright 2003 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

var menuLayers = {
  timer: null,
  activeMenuID: null,
  activeObjID: null,
  offX: 2,   // horizontal offset 
  offY: 3,   // vertical offset 
  show: function(id, e, id2) {
    var mnu = document.getElementById? document.getElementById(id): null;
    var obj = document.getElementById? document.getElementById(id2): null;
	//obj.className="bg_leftmenu";		
    if (!mnu) return;
    this.activeMenuID = id;
	this.activeObjID = id2;
    if ( mnu.onmouseout == null ) mnu.onmouseout = this.mouseoutCheck;
    if ( mnu.onmouseover == null ) mnu.onmouseover = this.clearTimer;
    viewport.getAll();
    this.position(mnu,e, obj);
  },
  hiden_id2: function(obj) {
  	
  },  
  hide: function() {  
    this.clearTimer();
    if (this.activeMenuID && document.getElementById) 
      this.timer = setTimeout("document.getElementById('"+ menuLayers.activeMenuID +"').style.visibility = 'hidden'", 500);	
  },
  
  position: function(mnu, e, obj) {
    var x = e.pageX? e.pageX: e.clientX + viewport.scrollX;
    var y = e.pageY? e.pageY: e.clientY + viewport.scrollY;
	
    var x = findPosX(obj) + 20;
    var y = findPosY(obj)+25;
	

    if ( x + mnu.offsetWidth + this.offX > viewport.width + viewport.scrollX )
      x = x - mnu.offsetWidth - this.offX;
    else x = x + this.offX;
  
    if ( y + mnu.offsetHeight + this.offY > viewport.height + viewport.scrollY )
      y = ( y - mnu.offsetHeight - this.offY > viewport.scrollY )? y - mnu.offsetHeight - this.offY : viewport.height + viewport.scrollY - mnu.offsetHeight;
    else y = y + this.offY;
    
    mnu.style.left = x + "px"; 
	mnu.style.top  = y + "px";
    this.timer = setTimeout("document.getElementById('" + menuLayers.activeMenuID + "').style.visibility = 'visible'", 200);			
  },
  
  mouseoutCheck: function(e) {
    e = e? e: window.event;
    // is element moused into contained by menu? or is it menu (ul or li or a to menu div)?
    var mnu = document.getElementById(menuLayers.activeMenuID);
    var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
    if ( mnu != toEl && !menuLayers.contained(toEl, mnu) ) menuLayers.hide();
  },
  
  // returns true of oNode is contained by oCont (container)
  contained: function(oNode, oCont) {
    if (!oNode) return; // in case alt-tab away while hovering (prevent error)
    while ( oNode = oNode.parentNode ) 
      if ( oNode == oCont ) return true;
    return false;
  },

  clearTimer: function() {
    if (menuLayers.timer) clearTimeout(menuLayers.timer);
  }
  
}
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }



function display_sp(t){
	$('#li_sp_moi').removeClass();
	$('#li_sp_noibat').removeClass();
	$('#li_sp_banchay').removeClass();
	if (t==1){
		$('#li_sp_moi').addClass("active");
		$('#sp_moi').attr("style", "display:block");
		$('#sp_noibat').attr("style", "display:none");
		$('#sp_banchay').attr("style", "display:none");
	}else if(t==2){
		$('#li_sp_noibat').addClass("active");
		$('#sp_moi').attr("style", "display:none");
		$('#sp_noibat').attr("style", "display:block");
		$('#sp_banchay').attr("style", "display:none");
	}else{
		$('#li_sp_banchay').addClass("active");
		$('#sp_moi').attr("style", "display:none");
		$('#sp_noibat').attr("style", "display:none");
		$('#sp_banchay').attr("style", "display:block");
	}
	return false;
}

function display_sp1(t){
	if (t==1){
		$('#li_sp_noibat').removeClass();
		$('#li_sp_banchay').removeClass();
		$('#li_sp_noibat').addClass("active");
		$('#sp_noibat').attr("style", "display:block");
		$('#sp_banchay').attr("style", "display:none");
	}else{
		$('#li_sp_noibat').removeClass();
		$('#li_sp_banchay').removeClass();
		$('#li_sp_banchay').addClass("active");
		$('#sp_noibat').attr("style", "display:none");
		$('#sp_banchay').attr("style", "display:block");
	}
	return false;
}


//jQuery.noConflict();

$( function(){
    // default settings
   /* $.tooltip.defaults = $.extend( $.tooltip.defaults, {
        delay      : 0,
        showURL    : false,
        //showBody   : " - ",
        // left       : -100,
        track      : true
    });*/
    // initialize
    $( 'a.tooltip' ).tooltip({
		delay: 0,
		showBody   : " - ",
		showURL: false
	});
    // with different css
    //jQuery( '#list2 span' ).Tooltip({ extraClass: 'darktip' });

});

