var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);
function showImageButtonHover(lnk_id,imageOver,imageOut){
	$("#" + lnk_id).hover(
		function(){
			$(this).find("img").attr("src",imageOver);
			$(this).find("input").attr("src",imageOver);
		},
		function(){
			$(this).find("img").attr("src",imageOut);
			$(this).find("input").attr("src",imageOut);
		}
	);
}
function email_valid(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false
	 }

	 return true					
}
function CA1()
{
	for (var i=0;i< document.cpform.elements.length;i++)
	{
		var e=document.cpform.elements[i];
		if ((e.name != 'checkall1'))
		{
			e.checked=document.cpform.checkall1.checked;
		}
	}
}


function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}

function chooseRank(type,rank,id){
	var url = main_url+"/ajax/cal_rank.php";
	var post = "id="+id+"&type="+type+"&rank="+rank;
	accessAjax(url,post,"POST",calQRankResult);		
}

function accessAjax(url,data_post,method,do_request_function){
		/*--------------------------------------------*/
		// Main function to do on request
		// Must be defined first!!
		/*--------------------------------------------*/
		
		/*do_request_function = function()
		{
			//----------------------------------
			// Ignore unless we're ready to go
			//----------------------------------
			
			if ( ! xmlobj.readystate_ready_and_ok() )
			{
				// Could do a little loading graphic here?
				//xmlobj.show_loading("Bạn hãy chờ giây lát !");
				return;
			}
			//xmlobj.hide_loading();
			
			//----------------------------------
			// INIT
			//----------------------------------
			
			var html = xmlobj.xmlhandler.responseText;
			return html;
		}*/
		
		//----------------------------------
		// LOAD XML
		//----------------------------------
		if (method == "")
			method = "POST";
		xmlobj = new ajax_request();
		xmlobj.onreadystatechange( do_request_function );
		xmlobj.process( url, method, data_post);
}
function getChecked(cpform)
{
	var dacheck = false;
	for (var i=0;i<cpform.elements.length;i++)
	{
		var e=cpform.elements[i];
		if ((e.name != 'checkall1') && (e.name.indexOf('khongluu')==-1))
		{
			if (e.checked==true)
				dacheck = true;
		}
	}
	return dacheck;
}

function show_div(ob1) {
  if (document.getElementById(ob1).style.display == "none") {
    document.getElementById(ob1).style.display = "";
  } else {
    document.getElementById(ob1).style.display = "none";
  }
}
function ge()
{
  var ea;
  for( var i = 0; i < arguments.length; i++ ) {
    var e = arguments[i];
    if( typeof e == 'string' )
      e = document.getElementById(e);
    if( arguments.length == 1 )
      return e;
    if( !ea )
      ea = new Array();
    ea[ea.length] = e;
  }
  return ea;
}

function show_div()
{
  for( var i = 0; i < arguments.length; i++ ) {
    var element = ge(arguments[i]);
    if (element && element.style) element.style.display = '';
  }
  return false;
}

function hide_div()
{
  for( var i = 0; i < arguments.length; i++ ) {
    var element = ge(arguments[i]);
    if (element && element.style) element.style.display = 'none';
  }
  return false;
}

var old_a = '';
function show_loading(message)
{
	if ( message )
	{
		if (old_a)
			document.getElementById( old_a ).style.display  = 'none';
		document.getElementById( message ).style.display  = '';
	}
	old_a = message;
	
	var centerdiv = new center_div();
	centerdiv.divname = 'loadinglayer';
	centerdiv.move_div();
}
function hide_loading()
{
	var centerdiv = new center_div();
	centerdiv.divname = 'loadinglayer';
	centerdiv.move_div();	
	centerdiv.hide_div();
	document.getElementById("layout").style.display = "";		
	if (document.getElementById( "fullscreen" ))
		document.getElementById( "fullscreen" ).style.display  = 'none';
	
/*		var date = new Date();
		date.setTime(date.getTime()+(60*60));
		var expires = "; expires="+date.toString();
		document.cookie = "closeadv=true"+expires+"; path=/";*/
}

function center_div()
{
	this.divname = '';
	this.divobj  = '';
}

/*-------------------------------------------------------------------------*/
// Main run function
/*-------------------------------------------------------------------------*/

center_div.prototype.move_div = function()
{
	try
	{
		this.divobj = document.getElementById( this.divname );
	}
	catch(e)
	{
		return;
	}
	
	//----------------------------------
	// Figure width and height
	//----------------------------------
	
	var my_width  = 0;
	var my_height = 0;
	
	if ( typeof( window.innerWidth ) == 'number' )
	{
		//----------------------------------
		// Non IE
		//----------------------------------
	  
		my_width  = window.innerWidth;
		my_height = window.innerHeight;
	}
	else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//----------------------------------
		// IE 6+
		//----------------------------------
		
		my_width  = document.documentElement.clientWidth;
		my_height = document.documentElement.clientHeight;
		
	}
	else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//----------------------------------
		// Old IE
		//----------------------------------
		
		my_width  = document.body.clientWidth;
		my_height = document.body.clientHeight;
	}

	//----------------------------------
	// Show...
	//----------------------------------
	
	this.divobj.style.position = 'absolute';
	this.divobj.style.display  = 'block';
	this.divobj.style.zIndex   = 99;
	
	//----------------------------------
	// Get div height && width
	//----------------------------------
	
	var divheight = parseInt( this.divobj.style.height );
	var divwidth  = parseInt( this.divobj.style.width );

	divheight = divheight ? divheight : 200;
	//divheight = divheight ? divheight : 200;
	divwidth  = divwidth  ? divwidth  : 500;

	//----------------------------------
	// Get current scroll offset
	//----------------------------------
	
	var scrolly = this.getYscroll();
	
	//----------------------------------
	// Finalize...
	//----------------------------------
	
	var setX = ( my_width  - divwidth  ) / 2;
	var setY = ( my_height - divheight ) / 2 + scrolly;

	setX = ( setX < 0 ) ? 0 : setX;
	setY = ( setY < 0 ) ? 0 : setY;
	
	this.divobj.style.left = setX + "px";
	this.divobj.style.top  = setY + "px";
}

/*-------------------------------------------------------------------------*/
// Hide div
/*-------------------------------------------------------------------------*/

center_div.prototype.hide_div = function()
{
	try
	{
		if ( ! this.divobj )
		{
			return;
		}
		else
		{
			this.divobj.style.display  = 'none';
		}
	}
	catch(e)
	{
		return;
	}
}

/*-------------------------------------------------------------------------*/
// Get YScroll
/*-------------------------------------------------------------------------*/

center_div.prototype.getYscroll = function()
{
	var scrollY = 0;
	
	if ( document.documentElement && document.documentElement.scrollTop )
	{
		scrollY = document.documentElement.scrollTop;
	}
	else if ( document.body && document.body.scrollTop )
	{
		scrollY = document.body.scrollTop;
	}
	else if ( window.pageYOffset )
	{
		scrollY = window.pageYOffset;
	}
	else if ( window.scrollY )
	{
		scrollY = window.scrollY;
	}
	
	return scrollY;
}