﻿// JavaScript Document
function setLyr(obj,lyr)
{
	var newX = findPosX(obj)+150;
	var newY = findPosY(obj)+0;
	document.getElementById(lyr + "").style.top = newY + 'px';
	document.getElementById(lyr + "").style.left = newX + 'px';
}
function setLyr2(obj,lyr)
{
	var newX = findPosX(obj)+140;
	var newY = findPosY(obj)-0;
	document.getElementById(lyr + "").style.top = newY + 'px';
	document.getElementById(lyr + "").style.left = newX + 'px';
}
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;
 }
 
 <!-- Ajax for content -->
 
 var loadstatustext = "<table width='100%' style='height:300px' border='0' cellspacing='0' cellpadding='0'><tr><td valign='top' style='padding-top:20px;'><div align='center'><img src='images/waiting.gif' align='absmiddle'> <span class='content_title'>Loading...</span></div></td></tr></table>";

function stateChanged(idtag) 
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 			
			document.getElementById("pages").innerHTML=xmlHttp.responseText ;
		} 
	}	
	
function showHint(str,caption,idtag,xcx)
	{
		if (str.length==0)
		{ 
			document.getElementById("pages").innerHTML=""
			return
		}
		
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
			{
				alert ("Browser does not support HTTP Request")
				return
			} 		
		var url=""
		url=url+str
		xmlHttp.onreadystatechange=stateChanged; 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
		if(caption.length >0)
		{
			document.getElementById("title_pages").innerHTML=caption;
		}
}

function GetXmlHttpObject(idtag,handler)
	{ 
		var objXMLHttp=null
		if (window.XMLHttpRequest)
			{
				objXMLHttp=new XMLHttpRequest()
			}
		else if (window.ActiveXObject)
			{
				objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
			}
		document.getElementById("pages").innerHTML=loadstatustext
		objXMLHttp.onreadystatechange=function()
			{
				loadpage(objXMLHttp)
			}	
		function loadpage(objXMLHttp){
		if (objXMLHttp.readyState == 4 && (objXMLHttp.status==200 || window.location.href.indexOf("http")==-1))
		document.getElementById("pages").innerHTML=objXMLHttp.responseText
		}	
		return objXMLHttp
	}
	
<!-- End Ajax for content -->

var selectedpanel=0;
selectedid = 1;

function ShowHotNews(newsid)
	{		
		document.getElementById('news_' + newsid ).style.display = '';
	}
	
function ShowHideHotNews(selectedid)
	{
		//theGroup=document.getElementById("hotnewspaner");
		//divElement=theGroup.getElementsByTagName("DIV");		
		
		for(i=1;i<8;i++)
		{
			document.getElementById('menu_' + i).style.display = 'none';
		}
		document.getElementById('menu_' + selectedid).style.display = '';
}	


function menuheader(id)

{	
		for(var j = 0 ; j<7;j++)
		{			
			//document.getElementById("menu_" + j).style.backgroundImage = '';	
		}
		document.getElementById("menu_" + id).style.backgroundImage = 'url(images/menu_over_10.png)';
}
 
 function SubmitForm(action) 
{	
	var linkurl;
	//alert(location);
	with(document.frmdata)
	{
		linkurl='contact/contactus.php?contactname='+contactname.value+
				'&contactemail='+contactemail.value+
				'&contactphone='+contactphone.value+
				'&contactfax='+contactfax.value+
				'&contactaddress='+contactaddress.value+
				'&protectcode='+protectcode.value+
				'&message='+message.value;

	}
	linkurl=linkurl+'&action='+action;		
	//alert(linkurl);
	showHint(linkurl);
	//window.open(linkurl,"_parent");
}

function CheckForm()
{	
	with (document.frmdata)
	{
		if (contactname.value=="")
		{				
				alert("Xin nhập tên của bạn !.");
				contactname.focus();
				return false;
		}
		if (contactemail.value=="")
		{			
			alert(" Bạn chưa nhập e-mail !.");
			contactemail.focus();
			return false;
		}
		else
		{
			if(contactemail.value.indexOf("@")<0||contactemail.value.indexOf(".")<0)
			{
				
				alert(" Email của bạn chưa đúng định dạng.Xin nhập lại !.");
				contactemail.focus();
				return false;
			}
		}
		if (contactphone.value=="")
		{				
				alert("Xin nhập số điện thoại !.");
				contactphone.focus();
				return false;
		}
		if (contactaddress.value=="")
		{				
				alert("Xin nhập địa chỉ của bạn !.");
				contactaddress.focus();
				return false;
		}
		if (protectcode.value=="")
		{				
				alert("Hãy nhập mã bảo vệ !.");
				protectcode.focus();
				return false;
		}	
		
		if(protectcode.value!=protectcodesrc.value){
				alert("Mã bảo vệ sai  !.");
				protectcodesrc.focus();
				return false;
		}
			
		if (message.value=="")
		{				
				alert("Xin nhập nội dung liên hệ  !.");
				message.focus();
				return false;
		}	
		SubmitForm(1) ;//1 save form
	}

}