// JavaScript Document
var secs
var timerID = null;
var timerRunning = false;
var delay = 1000;
var curLeftID = 1;
var curMainID = 1;
var interval = 10;
//var maxLeftItem = 0;
//var maxMainItem = 0;

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = interval;
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock();
		//alert("a");
		//StartTheTimer
		DoAdvertise();
		secs = interval;
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
        // Here's where you put something useful that's
        // supposed to happen after the allotted time.
        // For example, you could display a message:
        //alert("You have just wasted 10 seconds of your life.")
    }
    else
    {
        //self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}
function switchid(type, id){
	hideallids(type);
	showoneid(type, id);
}
function showoneid(type, id){
	if (type == 1){
		//left menu
		div_show(leftids[id]);
	}
	else{
		//main page
		div_show(mainids[id]);
	}
}
function hideallids(type){
	if (type == 1){
		//left menu
		for (var i=0;i<leftids.length;i++)
			div_hide(leftids[i]);
	}
	else{
		//main page
		for (i=0;i<mainids.length;i++)
			div_hide(mainids[i]);
	}
}
function DoAdvertise(){
	//left first
	if (maxLeftItem > 1){
		//neu co quang cao
		switchid(1, curLeftID);
		//thay doi id
		if (curLeftID >= maxLeftItem - 1){
			curLeftID = 0;
		}
		else{
			curLeftID ++;
		}
	}
	//main next
	if (maxMainItem > 1){
		//neu co quang cao
		switchid(2, curMainID);
		//thay doi id
		if (curMainID >= maxMainItem - 1){
			curMainID = 0;
		}
		else{
			curMainID ++;
		}
	}
}
function ShowHide(idSub, idImg){
	var d= document;
	colTR = d.getElementById(idSub);

	if (colTR.style.display=='') {
		colTR.style.display = 'none';
		col1 = d.getElementById(idImg);
		col1.src = 'imgs/gifArrowLeft1.gif';
	}
	else 
	{
		colTR.style.display = '';		
		col1 = d.getElementById(idImg);
		col1.src = 'imgs/gifArrowLeft2.gif';
	}
}
function show(showID, hideID)
{
	// Hide element
	document.getElementById(hideID).style.display = "none";
	// Show element
	document.getElementById(showID).style.display = "block";
}
function show4tab(showID, hideID1, hideID2, hideID3)
{
	// Hide element
	document.getElementById(hideID1).style.display = "none";
	// Hide element
	document.getElementById(hideID2).style.display = "none";
	// Hide element
	document.getElementById(hideID3).style.display = "none";
	// Show element
	document.getElementById(showID).style.display = "block";
}
function div_show(showID)
{
	// Show element
	document.getElementById(showID).style.display = "block";
}
function div_hide(hideID)
{
	// Hide element
	document.getElementById(hideID).style.display = "none";
}


//function to check valid email address
function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  //strEmail = document.forms[0].myemail.value;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1)
   {
      //alert('A valid e-mail address is required.\nPlease enter a valid e-mail address.');
      return false;
    }
    return true;
}

function checkNewsletter(f){
	//alert(f.txtEmail.value);
	if (f.txtEmail.value != ""){
		if (!isValidEmail(f.txtEmail.value)){//khong hop le
			alert("Địa chỉ email không hợp lệ.\nXin vui lòng nhập lại!");
			f.txtEmail.select();
			f.txtEmail.focus();
			return false;
		}
	}
	else{
		return false;
	}
	return true;
}