/*
function hidestatus(){
window.status='Welcome to Da Nang Securites Company [www.dnsc.com.vn]'
return true
}

if (document.layers)
document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)

document.onmouseover=hidestatus
document.onmouseout=hidestatus



document.oncontextmenu=function()
{
	return false
}

if(document.layers)
{
	window.captureEvents(Event.MOUSEDOWN);
	window.onmousedown=function(e)
	{
		if(e.target==document)return false;
	}
}
else
{
	document.onmousedown=function()
	{
		return false
	}
}
*/
if (navigator.cookieEnabled == 0)
  alert("You need to enable cookies for this site to load properly!");

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function rollon(a) 
{
	a.style.backgroundColor='#F0F8FF';
}	
function rolloff(a)
{
	a.style.backgroundColor='';
}

function exp_res(div_id)
{
	if(div_id.style.display == "inline")
	{ 	
		div_id.style.display = "none"; 
	}
	else
	{ 
		div_id.style.display = "inline";
	}
}

function exp_res_img(div_id,img_name)
{
	
	var btn_max = new Image();
	btn_max.src = "images/folder_off.jpg";
	var btn_min = new Image();
	btn_min.src = "images/folder_on.jpg";
	
	if(div_id.style.display == "inline")
	{ 	
		div_id.style.display = "none"; 
		if(img_name.src == btn_min.src) img_name.src = btn_max.src;
		else img_name.src = btn_min.src;
	}
	else
	{ 
		div_id.style.display = "inline";
		if(img_name.src== btn_min.src) img_name.src = btn_max.src;
		else img_name.src = btn_min.src;
	};
}

function menu_jump(url)
{
	if (url != "")
	{
		window.location=url;
	}
	else return false;
}
function menu_gourl(url)
{
	if (url != "")
	{
		window.location=url;
	}
	else return false;
}
function menu_submit(data,form)
{
	if (data != "")
	{ 
		form.action=document.URL;
		form.submit();
	}
	else return false;
}
function ask(url,msg)
{
	if (!confirm(msg))
	{ //do nothing
		return false;
	}
	else 
	{window.location = url}
}

function popup(url,width,height) 
{
	OpenWin = this.open(url,"_blank", "toolbar=no,menubar=no,location=no,scrollbars=no,status=no,resize=no,resizable=yes,width="+width+",height="+height+",top=100,left=100'");
}

function popup_status(url,width,height) 
{
	OpenWin = this.open(url,"_blank", "toolbar=no,menubar=no,location=no,scrollbars=no,status=yes,resize=no,resizable=yes,width="+width+",height="+height+",top=100,left=100'");
}

function tab_chart(img_name)
{
		document['hastc'].src='images/tab/hastc_off.jpg';
		document['hostc'].src='images/tab/hostc_off.jpg';
		
		document[img_name].src='images/tab/' + img_name + '_on.jpg';
	
		
}



// ajax
var http = createRequestObject();	
function createRequestObject()
{
	var connect;
    var browser = navigator.appName;
    if(browser == 'Microsoft Internet Explorer') 
    {
    	try
    	{
    		connect = new ActiveXObject("Msxml2.XMLHTTP");
    	}
    	catch(e)
    	{
    		try
    		{
    			connect = new ActiveXObject("Microsoft.XMLHTTP");
    		}
    		catch(e){}
    	}    	
    }
    else
    {
        connect = new XMLHttpRequest();
    }
    return connect;
}

function display(url, id)
{
	document.getElementById(id).style.display = "block";
	preloader(id); // preloading image waiting
	http.open("GET", url, true);
	http.onreadystatechange = function(){handleResponse(id);}
	http.send(null);
}

function handleResponse(id)
{
	if(http.readyState == 4 && http.status == 200)
	{
    	document.getElementById(id).innerHTML = http.responseText;
    }
}


function isValidEmail(str)
{
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function switch_tab(tab_name,id,page,param,location,numtab)
{
	
	var i = 0;
	var tabid = "";	
	for (i = 0; i < numtab; i ++)
	{			
		if ((i + 1) == id)
		{			
			tabid = tab_name + id;	
			document.getElementById(tabid + "_off").style.display = "none";
			document.getElementById(tabid + "_on").style.display = "block";
		}
		else
		{
			tabid = i + 1;				
			tabid = tab_name + tabid;
			document.getElementById(tabid + "_off").style.display = "block";
			document.getElementById(tabid + "_on").style.display = "none";
		}
	}
	// get source
	url = "inc/" + page + ".php?" + param;
	// display on location
	display(url,location);
	
}

function menu_jump_ajax(page,param,location)
{
	// get source
	url = "inc/" + page + ".php?" + param;
	// display on location
	display(url,location);
}

function switch_page(page,param,location)
{
	// get source
	url = "inc/" + page + ".php?" + param;
	// display on location
	display(url,location);
}

function changeclass(id, newclass)
{
	document.getElementById(id).className = newclass;
}
function preloader(el)
{
	var preloader = document.getElementById(el);
	preloader.innerHTML = "<div align=center><div style='width:100; padding:5px; background-color:#FFFFFF'><img src='images/loading.gif'><br/><font style='color:#666666'>Please wait !</font></div></div>";
	
}
function showimage(img_name, img_tag)
{
   alert('upload/'+img_name);
	//document.getElementById(img_tag).src = 'upload/'+img_name;
   setCookies('img_holder', 'upload/'+img_name);
}
function getCookies(cName)
{
	var cookie;
	var aCookie = document.cookie.split('; ');
	for(var i = 0; i < aCookie.length; i++)
	{
		cookie = aCookie[i].split('=');
		if(cookie[0] == cName)
			return unescape(cookie[1]);
	}
	return null;
}
function setCookies(cName, val)
{
	var date = new Date();
	date.setTime(date.getTime() + 48 * 60 * 60 * 1000);
	if((cName + "=" + escape(val)).length <= 4000)
	{
		document.cookie = cName + '=' + escape(val) + "; expires=" + date.toGMTString() + "; path=/";
		return true;
	}
	else if(confirm("Cookie exceeds 4KB and will be cut!"))
		return null;
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

////	AJAX Technology - Functions											          ////
//// 	Author:		Thái Cao Phong								            			 ////
////	E-mail:		phongsgc[at]Gmail[dot]com	         							 ////
////	Copyright: 	JavaScriptBank.com	      										 ////
//// 	THIS file is NOT open source code.									          ////
////	DO NOT try or use this file if you don't have author's agreement	    ////

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////
// XmlObject function
///////////////////////////////////////////////////////////////////////////////
function XmlObject()
{
	var xmlHttp = null;
	try
	{
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
		}
	}
	if(xmlHttp == null)
	{
		xmlHttp = new XMLHttpRequest();
		//xmlHttp.overrideMimeType(text/html);
	}
	
	if(!xmlHttp)
	{
		alert("Your browser does not support HTTP Request");
		return;
	}
	return xmlHttp;
}

///////////////////////////////////////////////////////////////////////////////
// getRequest function
///////////////////////////////////////////////////////////////////////////////
function getRequest(param, divID)
{
	if(divID)
	{
		var req = XmlObject();
		var idTimer = 0;
		if(req)
		{
			req.open('GET', /*url + '?cat=' + */param, true);
			//alert(param + "  " + divID);
			req.onreadystatechange = function()
			{
				document.getElementById(divID).innerHTML = "<p align=center><img src='../clientscript/images/loading.gif'>";
				getItem(req, divID);
			}
			req.send(null);
		}
	}
}

///////////////////////////////////////////////////////////////////////////////
// getItem function
///////////////////////////////////////////////////////////////////////////////
function getItem(req, divID)
{
	if(req.readyState == 4)
	{
	   if (req.status == 200)
	   {
			result = req.responseText;
		    document.getElementById(divID).innerHTML = result;
		}
		else
		{
			alert('There was a problem with the request.');
			document.getElementById(divID).innerHTML = 'Error! Please try again';
		   return false;
		}
	}
	/*
	else
		document.getElementById('content').innerHTML = "<p align=center><img src='clientscripts/images/loading.gif'>";*/
}

///////////////////////////////////////////////////////////////////////////////
// postRequest function
///////////////////////////////////////////////////////////////////////////////
function postRequest(url, obj, divID)
{
	var post = XmlObject(),
		para = '';
	for(var i = 0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].name != '')
			para += obj.elements[i].name + '=' + encodeURIComponent(obj.elements[i].value) + '&';
	}
	para = para.substring(0, para.length - 1) + '&rand=' + Math.random();
	
	post.onreadystatechange = function()
	{
		document.getElementById(divID).innerHTML = "<p align=center><img src='../clientscripts/images/loading.gif'>";
		getItem(post, divID);
	}
	post.open('POST', url, true);
	post.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	post.setRequestHeader("Content-length", para.length);
	post.send(para);
	post.setRequestHeader("Connection", "close");
}
function goto_page(epi, i)
{
    getRequest('goto_page.php?epi=' + epi + '&pg=' + i, 'page_changer');
}