﻿function getObjects(id){
	if(document.all)
		return document.all[id];
	else if(document.getElementById(id))
		return document.getElementById(id);
	else return null;
}
function setVisibles(id,show){
	var obj = getObject(id);
	if(typeof(show)!="undefined")obj.style.display = (show?'':'none');
	else obj.style.display = (obj.style.display!='none')?'none':'';
}

function getObject(id)
{
	if(document.getElementById(id))
		return document.getElementById(id);
	else if(document.all)
		return document.all[id];
	else if(document.layers)
	{
		var o = document.layers[id];
		o.style = document.layers[id];
		return o;
	}
	else return null;
}
function setVisible(id, show)
{
	var obj = getObject(id);
	if(typeof(show)!="undefined")obj.style.display = (show?'':'none');
	else obj.style.display = (obj.style.display!='none')?'none':'';
}

function swapImage(obj, minus, plus)
{
	var index = obj.src.lastIndexOf('/')+1;
	obj.src=obj.src.substring(0, index)+((obj.src.indexOf(minus)!=-1)?plus:minus);
}

function swapBackground(obj, over, out)
{
	var index = obj.background.lastIndexOf('/')+1;
	obj.background=obj.background.substring(0, index)+((obj.background.indexOf(over)!=-1)?out:over);
}

function changeInnerHtml(id, text)
{
	var obj = getObject(id);
	if(obj.innerHTML==text)
	{
			obj.innerHTML = obj.oldInner;
	}
	else
	{
		obj.oldInner = obj.innerHTML;
		obj.innerHTML = text;
	}
}
//=======================Tab bar==============================
function switchCell(n) {
	nc=getObjects("navcell");
	if(nc){
		t=getObjects("tb")
		for(i=0;i<nc.length;i++){
			nc.item(i).className="tab-off";
			t.item(i).className="hide-table";
		}
		nc.item(n-1).className="tab-on";
		t.item(n-1).className="tab-content show-table";
	}else if(navcell){
		for(i=0;i<navcell.length;i++){
			navcell[i].className="tab-off";
			tb[i].className="hide-table";
		}
		navcell[n-1].className="tab-on";
		tb[n-1].className="tab-content show-table";
	}
}



// Bookmark specific page
function Bookmark()		{
 		if (navigator.appName == 'Microsoft Internet Explorer') 
		window.external.AddFavorite(document.location, document.title);
}

//=========================Time==========================
function ShowTimeNow(id)
{
	var dt = new Date();
	var thu="";
	if(dt.getDay()==0)thu="Chủ nhật";
	else if(dt.getDay()==1)thu="Thứ hai";
	else if(dt.getDay()==2)thu="Thứ ba";
	else if(dt.getDay()==3)thu="Thứ tư";
	else if(dt.getDay()==4)thu="Thứ năm";
	else if(dt.getDay()==5)thu="Thứ sáu";
	else if(dt.getDay()==6)thu="Thứ bảy";
	getObject(id).innerHTML =thu + ", " + Round2Digit(dt.getDate()) + "/" + Round2Digit(dt.getMonth()+1) + "/" + dt.getFullYear()+ " " + Round2Digit(dt.getHours()) + ":" + Round2Digit(dt.getMinutes()) + ":" + Round2Digit(dt.getSeconds());
}

function ShowTimeNowInterval(id, amount)
{
	setInterval("ShowTimeNow('" + id + "');", amount);
}

function showTimePublish(content,id){
    var tDates = content.split(" ");
	var tDay = tDates[0].split("/");
	//var tTime = tDates[1].split(":");
	var oDay = new Date();	
	var rStr="";	
	//date
	oDay.setFullYear(tDay[2],tDay[1]-1,tDay[0]);		
	switch(oDay.getDay()) {
		case 0:
			rStr = 'Chủ nhật'; break;
		case 1:
			rStr = 'Thứ hai'; break;
		case 2:
			rStr = 'Thứ ba'; break;
		case 3:
			rStr = 'Thứ tư'; break;
		case 4:
			rStr = 'Thứ năm'; break;
		case 5:
			rStr = 'Thứ sáu'; break;
		case 6:
			rStr = 'Thứ bảy'; break;
		default: 
			rStr = ''; break;
	}
    
    getObject(id).innerHTML =rStr+", " + content;
}

function dFormat(strDate,id) {
	var rStr = '';
	//var sDate='';
	if(strDate=='') {
		rStr='';
	}
	else {
		var tDates = strDate.split(" ");
		var tDay = tDates[0].split("/");
		var tTime = tDates[1].split(":");
		var oDay = new Date();		
		//date
		oDay.setFullYear(tDay[2],tDay[0]-1,tDay[1]);		
		switch(oDay.getDay()) {
			case 0:
				rStr = 'Chủ nhật'; break;
			case 1:
				rStr = 'Thứ hai'; break;
			case 2:
				rStr = 'Thứ ba'; break;
			case 3:
				rStr = 'Thứ tư'; break;
			case 4:
				rStr = 'Thứ năm'; break;
			case 5:
				rStr = 'Thứ sáu'; break;
			case 6:
				rStr = 'Thứ bảy'; break;
			default: 
				rStr = ''; break;
		}
		rStr = rStr.concat(', ').concat(tDay[1]).concat('/').concat(tDay[0]).concat('/').concat(tDay[2]).concat(' | ');
		if(tDates[2] == 'AM') {
			if(tTime[0] < 10) {
				rStr = rStr.concat('0').concat(tTime[0]).concat(':');
			}
			else {
				rStr = rStr.concat(tTime[0]).concat(':');
			}
		}
		else {
			tTime[0] = 12 + parseInt(tTime[0]);
			rStr = rStr.concat(tTime[0]).concat(':');
		}
		
		if(tTime[1] < 10) {
			rStr = rStr.concat('0').concat(tTime[1]);
		}
		else {
			rStr = rStr.concat(tTime[1]);
		}
		
		rStr = rStr.concat(' GMT+7&nbsp;');
		//sDate = rStr;
		
		getObject(id).innerHTML=rStr;
	}
}
//=======================================================
function Round2Digit(n)
{
	if(n<=9&&n>=0)return "0"+n;else return n;
}

function OpenPopup(mypage,myname,w,h,pos,infocus)
{
	//var win=null;
	if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
	else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=2,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	win=window.open(mypage,myname,settings);
	win.focus();
}


//Moving Item in ListBox to Another
function MoveOption(objSourceElement, objTargetElement)
{
    var aryTempSourceOptions = new Array();
    var x = 0;
    
    //looping through source element to find selected options
    for (var i = 0; i < objSourceElement.length; i++) {
        if (objSourceElement.options[i].selected) {
            //need to move this option to target element
            var intTargetLen = objTargetElement.length++;
            objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
            objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;
        }
        else {
            //storing options that stay to recreate select element
            var objTempValues = new Object();
            objTempValues.text = objSourceElement.options[i].text;
            objTempValues.value = objSourceElement.options[i].value;
            aryTempSourceOptions[x] = objTempValues;
            x++;
        }
    }
    
    //resetting length of source
    objSourceElement.length = aryTempSourceOptions.length;
    //looping through temp array to recreate source select element
    for (var i = 0; i < aryTempSourceOptions.length; i++) {
        objSourceElement.options[i].text = aryTempSourceOptions[i].text;
        objSourceElement.options[i].value = aryTempSourceOptions[i].value;
        objSourceElement.options[i].selected = false;
    }
}

function kwconfirm(objMSG){
    if(confirm(objMSG)== true)  
        return true;  
    else  
        return false;    
}
function kwalert(objMSG){
    alert(objMSG);
    
}


function jumptolink(what){
    var selectedopt=what.options[what.selectedIndex]
    window.location=selectedopt.value
}
