
/***********************************************
* Local Time script- © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

window.onload = function ()
{	
	if (document.getElementById('slideA')){
		//alert(0);
		setInterval(timer1,3);
	}
	else
	{
		clearInterval(timer1);
	}
	
}
var owatch=0;
var weekdaystxt=["Chủ nhật", "Thứ hai", "Thứ ba", "Thứ 4", "Thứ 5", "Thứ 6", "Thứ bảy"]
var servertimestring='';
var timeout=1000;
function showLocalTime(container, servermode, offsetMinutes, displayversion)
{
	if (!document.getElementById || !document.getElementById(container)) return
	this.container=document.getElementById(container)
	this.displayversion=displayversion
	<!--var servertimestring=(servermode=="server-php")? '<?php print date("d F Y, H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>'-->
	this.localtime=this.serverdate=new Date(servertimestring)
	this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time
	this.updateTime()
	this.updateContainer()
}

showLocalTime.prototype.updateTime=function()
{
	var thisobj=this
	this.localtime.setSeconds(this.localtime.getSeconds()+1)
	setTimeout(function(){thisobj.updateTime()}, timeout) //update time every second
}

showLocalTime.prototype.updateContainer=function()
{
	var thisobj=this
	var hour=this.localtime.getHours()
	var minutes=this.localtime.getMinutes()
	var seconds=this.localtime.getSeconds()
	var ampm=(hour>=12)? "PM" : "AM"
	var dayofweek=weekdaystxt[this.localtime.getDay()]
	if (this.displayversion=="long")
	{
		var year = this.localtime.getYear()
		if (year < 1000)
			year += 1900
		var month = this.localtime.getMonth() + 1
		if (month < 10)
			month = "0" + month
		var day = this.localtime.getDate()
		if (day < 10)
			day = "0" + day
		this.container.innerHTML= dayofweek+", "+day+"/"+month+"/"+year+",&nbsp;"+formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm //this.localtime.toLocaleString() lấy theo kiểu của máy local
	}
	else
	{		
		this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
	}
	setTimeout(function(){thisobj.updateContainer()}, timeout) //update container every second
}

function formatField(num, isHour){
if (typeof isHour!="undefined"){ //if this is the hour field
var hour=(num>12)? num-12 : num
return (hour==0)? 12 : hour
}
return (num<=9)? "0"+num : num//if this is minute or sec field
}
//-------------------------------------------------------
function writeTime(s)
{
	var mydate=new Date(s)
	
	var year = mydate.getYear()
	if (year < 1000)
		year += 1900
	var month = mydate.getMonth() + 1
	if (month < 10)
		month = "0" + month
	var day = mydate.getDate()
	if (day < 10)
		day = "0" + day
	var dayw = mydate.getDay()	
	var hour = mydate.getHours()
	if (hour < 10)
		hour = "0" + hour	
	var minute=mydate.getMinutes()
	if (minute < 10)
		minute = "0" + minute
	var dayarray=new Array("Ch&#7911; Nh&#7853;t","Th&#7913; Hai","Th&#7913; Ba","Th&#7913; T&#432;","Th&#7913; N&#259;m","Th&#7913; S&#225;u","Th&#7913; B&#7843;y")
	document.write(dayarray[dayw]+", "+day+"/"+month+"/"+year+",&nbsp;"+hour+":"+minute+" (GMT+7)")
}

function Trim(sString)
{
	if (sString==''){
	return '';
	}
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function clip_horizontally() {
 	// width of the banner container
 	var contWidth = 600;
 	// height of the banner container
 	var contHeight = 140;
 	var id1 = document.getElementById('slideA'); 
 	id1.style.left = parseInt(id1.style.left)-1 + 'px';
	if (parseInt(id1.style.left) > -(12*140+10))
	{
 		document.getElementById('slideCont').style.width = contWidth + "px";
 		document.getElementById('slideCont').style.clip = 'rect(auto,'+ contWidth +'px,' + contHeight +'px,auto)'; 	
	}
	else
	{
		id1.style.left = 600 + 'px';
	}
}
/*
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function(){clip();});
*/

function timer1()
{	
	owatch++;	
	if (owatch*5 % 10){
		clip_horizontally();		
	}	
}

function emailcheck(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		return false
	}
	
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	}
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	
	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}
	
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}
	
	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
	
	if (str.indexOf(" ")!=-1){
		return false
	}
	return true;			
}
function checkgopy()
{	

	if (Trim(document.getElementById('hoten').value)=="")
	{
		alert('Bạn chưa nhập họ tên');
		return false;
	}
	if (Trim(document.getElementById('diachi').value)=="")
	{
		alert('Bạn chưa nhập địa chỉ');
		return false;
	}
	if (Trim(document.getElementById('dienthoai').value)=="")
	{
		alert('Bạn chưa nhập điện thoại');
		return false;
	}
	if (Trim(document.getElementById('email').value)=="")
	{
		alert('Bạn chưa nhập địa chỉ Email');
		return false;
	}
	if(!emailcheck(Trim(document.getElementById('email').value)))
	{
		alert('Địa chỉ Email chưa đúng!');
		return false;
	}
	if (Trim(document.getElementById('chude').value)=="")
	{
		alert('Bạn chưa nhập chủ đề');
		return false;
	}	
	if (Trim(document.getElementById('noidung').value)=="")
	{
		alert('Bạn chưa nhập nội dung');
		return false;
	}
	
	if (document.getElementById('kiemtra').value=="")
	{
		alert('Bạn chưa nhập mã bảo vệ');
		return false;
	}		
	return true;
}
function checkdangky()
{	

	if (Trim(document.getElementById('hoten').value)=="")
	{
		alert('Bạn chưa nhập họ tên');
		return false;
	}	
	if (Trim(document.getElementById('dienthoai').value)=="")
	{
		alert('Bạn chưa nhập điện thoại');
		return false;
	}		
	if (document.getElementById('kiemtra').value=="")
	{
		alert('Bạn chưa nhập mã bảo vệ');
		return false;
	}		
	return true;
}