function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}


function ajax(url,vars)
{
	var xmlHttp
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }

	xmlHttp.onreadystatechange=function ()
	{
		if (xmlHttp.readyState!=4 && xmlHttp.readyState!="complete")
		 {
			document.getElementById('home').innerHTML="<p align='center'><b><i>Loading...</i></b></p>"
			document.body.style.cursor="wait"
		 }else
		 {
		 document.body.style.cursor=""
		 document.getElementById('home').innerHTML=xmlHttp.responseText
		 }
	}
	xmlHttp.open("POST",url,true)
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
	xmlHttp.send(vars)
}




// ham ajax dung cho the div co id =  home
function Ajax_Show(url)
{
	var xmlHttp;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 }
	xmlHttp.onreadystatechange=function stateChanged() {
		if (xmlHttp.readyState!=4 && xmlHttp.readyState!="complete")
		 {
			document.getElementById('home').innerHTML="<p align='center'><b><i>Loading...</i></b></p>"
			document.body.style.cursor="wait"
		 }else
		 {
		 document.body.style.cursor=""
		 document.getElementById('home').innerHTML=xmlHttp.responseText
		 }
		}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

// ham ajax dung cho the div co id =  showimage
function Ajax_Show1(url)
{
	var xmlHttp;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 }
	xmlHttp.onreadystatechange=function stateChanged() {
				if (xmlHttp.readyState!=4 && xmlHttp.readyState!="complete")
				 {
					document.getElementById('showimage').innerHTML="<p align='center'><b><i>Loading...</i></b></p>"
					document.body.style.cursor="wait"

				 }else
				 {
				  document.body.style.cursor=""
				 document.getElementById('showimage').innerHTML=xmlHttp.responseText
				 }
		}

	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}


// ham ajax dung cho the div co id =  showimage
function Ajax_Show2(url)
{
	var xmlHttp;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 }
	xmlHttp.onreadystatechange=function stateChanged() {
				if (xmlHttp.readyState!=4 && xmlHttp.readyState!="complete")
				 {
					document.body.style.cursor="wait"
				 }else
				 {
				  document.body.style.cursor=""
				 document.getElementById('subcat').innerHTML=xmlHttp.responseText
				 }
		}

	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

// ham ajax dung cho the div co id =  showimage
function Ajax_Show3(url)
{
	var xmlHttp;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request")
		 return
	 }
	xmlHttp.onreadystatechange=function stateChanged() {
				if (xmlHttp.readyState!=4 && xmlHttp.readyState!="complete")
				 {
					document.getElementById('foods').innerHTML="<p align='center'><b><i>Loading...</i></b></p>"
					document.body.style.cursor="wait"
				 }else
				 {
				  	document.body.style.cursor=""
				 	document.getElementById('foods').innerHTML=xmlHttp.responseText
				 }
		}

	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

// het ajax

function check_email(email)
{
	regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	if(regex.test(email))
	{
		return true;
	}else
	{
		return false;
	}
}

function show_div(id)
{	if(document.getElementById('first_cat')!=null)
	{
		document.getElementById('first_cat').style.display='none';
	}
	document.getElementById('show_cat').style.display='block';
	if(document.getElementById(id)!=null)
	{
		document.getElementById('show_cat').innerHTML=document.getElementById(id).innerHTML;
	}
}
function show_sub_cat(id)
{
	//alert(id);
	if(document.getElementById('subcat')!=null)
	{
		document.getElementById('subcat').style.display='none';
	}
	document.getElementById('show_sub_cat').style.display='block';
	if(document.getElementById(id)!=null&&document.getElementById(id).innerHTML!=null)
	{
		document.getElementById('show_sub_cat').innerHTML=document.getElementById(id).innerHTML;
	}else
	{
		document.getElementById('show_sub_cat').innerHTML=='';
	}
}


var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all

//drag drop function for NS 4////
/////////////////////////////////

var dragswitch=0
var nsx
var nsy
var nstemp

function drag_dropns(name){
if (!ns4)
return
temp=eval(name)
temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
temp.onmousedown=gons
temp.onmousemove=dragns
temp.onmouseup=stopns
}

function gons(e){
temp.captureEvents(Event.MOUSEMOVE)
nsx=e.x
nsy=e.y
}
function dragns(e){
if (dragswitch==1){
temp.moveBy(e.x-nsx,e.y-nsy)
return false
}
}

function stopns(){
temp.releaseEvents(Event.MOUSEMOVE)
}

//drag drop function for ie4+ and NS6////
/////////////////////////////////


function drag_drop(e){
if (ie4&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx
crossobj.style.top=tempy+event.clientY-offsety
return false
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx+"px"
crossobj.style.top=tempy+e.clientY-offsety+"px"
return false
}
}

function initializedrag(e){
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
var firedobj=ns6? e.target : event.srcElement
var topelement=ns6? "html" : document.compatMode && document.compatMode!="BackCompat"? "documentElement" : "body"
while (firedobj.tagName!=topelement.toUpperCase() && firedobj.id!="dragbar"){
firedobj=ns6? firedobj.parentNode : firedobj.parentElement
}

if (firedobj.id=="dragbar"){
offsetx=ie4? event.clientX : e.clientX
offsety=ie4? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}
document.onmouseup=new Function("dragapproved=false")

////drag drop functions end here//////

function hidebox(){
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
if (ie4||ns6)
crossobj.style.display="none"
else if (ns4)
document.showimage.visibility="hide"
}

//////////////check form dang ky, form dang nhap
function check_accept()
{

	if(document.getElementById('nam').checked==true)
	{
		document.dangky.gioitinh.value=1;
	}else
	{
		document.dangky.gioitinh.value=0;
	}
	if(document.dangky.check.checked ==true)
	{

		document.dangky.accept.value=1;

	}else
	{
		document.dangky.accept.value=0;

	}
	if(document.dangky.cookiecheck.checked ==true)
	{

		document.dangky.cookie.value=1;

	}else
	{
		document.dangky.cookie.value=0;

	}

}
function register_check(ho_err,ten_err,dienthoai_err,telefon_err,pho_err,sonha_err,tang_err,mavung_err,makhuvuc_err,email_err,gio_err,min_gio,phut_err,min_phut)
{

	var ho=document.dangky.ho.value;
	var ten=document.dangky.ten.value;
	var dienthoai=document.dangky.dienthoai.value;
	var pho=document.dangky.pho.value;
	var sonha=document.dangky.sonha.value;
	var tang=document.dangky.tang.value;
	var mavung=document.dangky.mavung.value;
	var makhuvuc=document.dangky.makhuvuc.value;
	var email=document.dangky.email.value;
	var gio=document.dangky.gio.value;
	var phut=document.dangky.phut.value;
	if(ho=="" || ho==" ")
	{
		alert(ho_err);
		document.dangky.ho.focus();
		return false;
	}
	if(ten=="" || ten==" ")
	{
		alert(ten_err);
		document.dangky.ten.focus();
		return false;
	}
         if(isNaN(dienthoai))
         {
         	alert(telefon_err);
                 document.dangky.dienthoai.focus();
                 return false;
         }
         if(dienthoai=="" || dienthoai==" ")
	{
		alert(dienthoai_err);
		document.dangky.dienthoai.focus();
		return false;
         }
         if(pho=="" || pho ==" ")
	{
		alert(pho_err);
		document.dangky.pho.focus();
		return false;
	}
	if(sonha=="" || sonha==" ")
	{
		alert(sonha_err);
		document.dangky.sonha.focus();
		return false;
	}
	if(mavung=="" || mavung==" " || isNaN(mavung))
	{
		alert(mavung_err);
		document.dangky.mavung.focus();
		return false;
	}
	if(makhuvuc=="" || makhuvuc==" ")
	{
		alert(makhuvuc_err);
		document.dangky.makhuvuc.focus();
		return false;
	}
	if(tang=="" || tang==" ")
	{
		alert(tang_err);
		document.dangky.tang.focus();
		return false;
	}
	if(email!="" && email!=" ")
	{
		if(!check_email(email))
		{
			alert(email_err);
			document.dangky.email.focus();
			return false;
		}
	}
	if(gio!="" && gio !=" ")
	{
		if(isNaN(gio))
		{
			alert(gio_err);
			document.dangky.gio.focus();
			return false;
		}else
		{
			if(!(gio>min_gio && gio<=24))
			{
				alert(gio_err);
				document.dangky.gio.focus();
				return false;
			}
		}
	}
	if(phut!="" && phut !=" ")
	{
		if(isNaN(phut))
		{
			alert(phut_err);
			document.dangky.phut.focus();
			return false;
		}else
		{
			if(gio==min_gio+1){
				if(!(phut>min_phut && phut<=59))
				{
					alert(phut_err);
					document.dangky.phut.focus();
					return false;
				}
			}else{
				if(!(phut>=0 && phut<=59))
				{
					alert(phut_err);
					document.dangky.phut.focus();
					return false;
				}
			}
		}
	}

	check_accept();
}
//////////////////////////////
function check_remark_form(noidung_err)
{
	if(document.remark.noidung.value=="")
	{
		alert(noidung_err);
		document.remark.noidung.focus();
		return false;
	}

}
/////////////////////////
function login_check(email_err,pwd_err)
{
	var email = document.dangnhap.email.value;
	var pwd = document.dangnhap.pwd.value;
	if(!check_email(email))
	{
		alert(email_err);
		document.dangnhap.email.focus();
		return false;
	}
	if(pwd=="")
	{
		alert(pwd_err);
		document.dangnhap.pwd.focus();
		return false;
	}
}
function contact_check(tieude_err,email_err,noidung_err)
{
	var tieude = document.lienhe.tieude.value;
	var email = document.lienhe.email.value;
	var noidung = document.lienhe.noidung.value;
	if(tieude=="")
	{
		alert(tieude_err);
		document.lienhe.tieude.focus();
		return false;
	}
	if(!check_email(email))
	{
		alert(email_err);
		document.lienhe.email.focus();
		return false;
	}
	if(noidung=="")
	{
		alert(noidung_err);
		document.lienhe.noidung.focus();
		return false;
	}

}




///////////////////////////////image viewer/////////////////////////////////////////


var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip" onclick="document.getElementById(this.id).style.display='+"none"+'"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="arrow2.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip

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

function selectTab(obj)
{
	var objArr = document.getElementById('header').childNodes
	for (i = 0; i < objArr.length; i++)
	{
		if (objArr[i].nodeName.toLowerCase() == 'a')
		{
			objArr[i].className = ''
		}
	}
	obj.className = 'active'
}

function selectTab2(obj)
{
	for (i = 1; i<=5; i++ )
	{
		document.getElementById('tabnav'+ i).className = ''
	}
	obj.className = 'active'
}
