/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		//emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
 
 /*----------------------------check mail-----------------------------*/
 
//START AJAX

window.onerror = function(msg, err_url, line) {alert('Unkwon Error :) ' + line);}

//Detects browser type 
function makeObject(){
var x; 
var browser = navigator.appName; 
if(browser == "Microsoft Internet Explorer"){
x = new ActiveXObject("Microsoft.XMLHTTP");
}else{
x = new XMLHttpRequest();
}
return x;
}

//Call function 
var request = makeObject();

//The POST method AJAX 
function post_method(data){

var data = Kiemtraykien();

request.open('post', 'modykien.php');
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.onreadystatechange = output; 
request.send('data='+data);
}

function post_methodtintuc(){

var data = "";

request.open('post', 'modtintuc.php');
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.onreadystatechange = outputtintuc; 
request.send('data='+data);
}

function post_methodkq(data){

var data = Kiemtraykien();

request.open('post', 'modketqua.php');
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.onreadystatechange = output; 
request.send('data='+data);
}

function post_method2mess(data){

request.open('post', 'mod2mess.php');
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.onreadystatechange = output2mess; 
request.send('iKind=2mess&data='+data);

}

function post_method2messemail(){
var ten=document.frmSample.txt_name.value;
var cty=document.frmSample.txt_company.value;
var dchi=document.frmSample.txt_address.value;
var dthoai=document.frmSample.txt_tel.value;
var vmail=document.frmSample.txtEmail.value;
var sfax=document.frmSample.txt_fax.value;
var vcontent=document.frmSample.content.value;

//alert(vcontent);

request.open('post', 'mod2mess.php');
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.onreadystatechange = output2mess; 
request.send('iKind=2messemail&ten='+ten+'&cty='+cty+'&dchi='+dchi+'&dthoai='+dthoai+'&email='+vmail+'&sfax='+sfax+'&ndung='+vcontent);

}

function get_method2mess(data){

//var data = mod;//"lienhe";

request.open('get', 'main_tintuc.php?page='+data);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.onreadystatechange = output2mess; 
request.send('');

/*request.open('post', 'mod2mess.php');
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.onreadystatechange = output2mess; 
request.send('iKind=2mess&data='+data);*/

}

function output2mess()
{
if(request.readyState == 4){
var data = request.responseText;
document.getElementById('noidungweb').innerHTML = data;
//alert(data);
}
}

function outputtintuc()
{
if(request.readyState == 4){
var data = request.responseText;
document.getElementById('tintuc').innerHTML = data;
}
}

function output()
{
if(request.readyState == 4){
var data = request.responseText;
alert(data);
}
}

//END AJAX

var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only

if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.text_xemtiep1{display: none;}\n')
document.write('</style>\n')
}

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="text_xemtiep1") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById(cookievalue).style.display="block"
}
}

function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc
break
}
inc++
}
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}

if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction

if (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate

function Kiemtraykien(){
for(var i=0;i<form1.radiobutton.length;i++){
	if (form1.radiobutton(i).checked){
		
		return form1.radiobutton(i).value;
	}
}
}

//<!--
function WorldClock(){

var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()+1
if (month<10)
month="0"+month
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym

now=new Date();
ofst=now.getTimezoneOffset()/60;
secs=now.getSeconds();
sec=-1.57+Math.PI*secs/30;
mins=now.getMinutes();
min=-1.57+Math.PI*mins/30;
hr=(now.getHours() + parseInt(ofst)) + parseInt(7);//(isitlocal)?now.getHours():
hrs=-1.575+Math.PI*hr/6+Math.PI*parseInt(now.getMinutes())/360;
if (hr < 0) hr+=24;
if (hr > 23) hr-=24;

hr2 = hr;

var finaltime='Hôm nay '+daym+'-'+month+'-'+year+', '+hr2+':'+((mins < 10)?"0"+mins:mins);//+':'+((secs < 10)?"0"+secs:secs);//+' '+statusampm;

if (document.all)
worldclock.innerHTML=finaltime
else if (document.getElementById)
document.getElementById("worldclock").innerHTML=finaltime

setTimeout('WorldClock()',60000);
}
