// Sniffer based on http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html

var uagent    = navigator.userAgent.toLowerCase();
var is_safari = ( (uagent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc.") );
var is_opera  = (uagent.indexOf('opera') != -1);
var is_webtv  = (uagent.indexOf('webtv') != -1);
var is_ie     = ( (uagent.indexOf('msie') != -1) && (!is_opera) && (!is_safari) && (!is_webtv) );
var is_ie4    = ( (is_ie) && (uagent.indexOf("msie 4.") != -1) );
var is_moz    = ( (navigator.product == 'Gecko')  && (!is_opera) && (!is_webtv) && (!is_safari) );
var is_ns     = ( (uagent.indexOf('compatible') == -1) && (uagent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_safari) );
var is_ns4    = ( (is_ns) && (parseInt(navigator.appVersion) == 4) );
var is_kon    = (uagent.indexOf('konqueror') != -1);

var is_win    =  ( (uagent.indexOf("win") != -1) || (uagent.indexOf("16bit") !=- 1) );
var is_mac    = ( (uagent.indexOf("mac") != -1) || (navigator.vendor == "Apple Computer, Inc.") );
var ua_vers   = parseInt(navigator.appVersion);


/*-------------------------------------------------------------------------*/
// Center a div on the screen
/*-------------------------------------------------------------------------*/

function show_loading(message)
{
	if ( message )
	{
		document.getElementById( 'loadinglayer-text' ).innerHTML = 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();
/*		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;
	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.8 + 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;
}

function CA1()
{
	for (var i=0;i<cpform.elements.length;i++)
	{
		var e=cpform.elements[i];
		if ((e.name != 'checkall1') && (e.name.indexOf('khongluu')==-1))
		{
			e.checked=cpform.checkall1.checked;
		}
	}
}

function getChecked()
{
	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 initPermissionMessage()
{
	strHtml='<DIV id=loadinglayer style="BORDER-RIGHT: #2c87d5 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #2c87d5 1px solid; PADDING-LEFT: 5px; BACKGROUND: #ffffff; PADDING-BOTTOM: 2px; BORDER-LEFT: #2c87d5 1px solid; WIDTH: 600px; PADDING-TOP: 0px; BORDER-BOTTOM: #2c87d5 1px solid; HEIGHT: auto; TEXT-ALIGN: center; DISPLAY: none;"  class="Normal">';
	strHtml+='    <TABLE border=0 cellSpacing=0 cellPadding=0 width="100%">';
	strHtml+='        <tr><TD align=top>';
	strHtml+='          <DIV id=loadinglayer-text>';
	strHtml+='          <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>';
    strHtml+='				<tr><TD>';
	strHtml+='                <img src="/images/khuyenmai112006.gif" border="0">';
	strHtml+='             </TD></TR>';
	strHtml+='          </TABLE>';
	strHtml+='         </DIV>';
	strHtml+='       </TD></TR>';
	strHtml+='      <TR>';
	strHtml+='        <TD align=center><A href="/hosting/">Xem chi ti&#7871;t </A> | <A href="javascript:hide_loading()">&#272;&#243;ng</A></TD>';
	strHtml+='      </TR>';
	strHtml+='   </TABLE>';
	strHtml+='</DIV>';
	
	document.write(strHtml);
}
