// JavaScript Document

function setCookie(c_name,value,expiredays) {
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}


function getCookie(c_name) {
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return ""
}

function getToday(dformat) {
	var mydate= new Date();
	var theyear=mydate.getFullYear();
	var themonth=mydate.getMonth()+1;
	var thetoday=mydate.getDate();
	
	var myDays = ["Chủ Nhật","Thứ Hai","Thứ Ba","Thứ Tư","Thứ Năm","Thứ Sáu","Thứ Bảy","Chủ Nhật"];
	thisDay=mydate.getDay();
	thisDay=myDays[thisDay];
	
	dformat = dformat.replace('dow',thisDay);
	dformat = dformat.replace('dd',thetoday);
	dformat = dformat.replace('mm',themonth);
	dformat = dformat.replace('yy',theyear);

	return dformat;
}


//------------------------------------------------------
function getCurTime() {

var a_p = "";
var d = new Date();
var curr_hour = d.getHours();

a_p = (curr_hour < 12)?"AM":"PM";

if (curr_hour == 0)  curr_hour = 12;
curr_hour = (curr_hour>12)?curr_hour-12:curr_hour;
curr_hour = curr_hour + "";
curr_hour = (curr_hour.length==1)?"0"+curr_hour:curr_hour;


var curr_min = d.getMinutes();
curr_min = curr_min + "";
curr_min = (curr_min.length==1)?"0"+curr_min:curr_min;

var curr_sec = d.getSeconds();
curr_sec = curr_sec + "";
curr_sec = (curr_sec.length==1)?"0"+curr_sec:curr_sec;

return curr_hour+':'+curr_min+':'+curr_sec+' '+a_p;
}

//------------------------------------------------------
function showDateTime() {
	document.getElementById('datetime').innerHTML = getToday('dow dd/mm/yy')+', '+getCurTime()+'';
	setTimeout('showDateTime()',1000);
}

function linkTo(url) {
	window.location = url;
}

//------------------------------------------------------
function linkToNewWin(url) {
	window.open(url);
}
	
//------------------------------------------------------
function menuOver(obj, z) {
	switch (z)
	{
		case 0:
			obj.style.backgroundColor = '#F7F3DE';
			obj.style.textDecoration = '';
			break;
		case 1:
			obj.style.backgroundColor = '#D7CDAF';
			obj.style.textDecoration = 'underline';
			break;
	}
}

//------------------------------------------------------
function submenuOver(obj, z) {
	switch (z)
	{
		case 0:
			obj.style.backgroundColor = '#E4E0CD';
			obj.style.textDecoration = '';
			break;
		case 1:
			obj.style.backgroundColor = '#D7CDAF';
			obj.style.textDecoration = 'underline';
			break;
	}
}

//------------------------------------------------------
function doOver(obj, z) {
	switch (z)
	{
		case 0:
			obj.style.backgroundImage = 'url(../Resources/Images/Blue/menuitem_bg.gif)';
			obj.style.textDecoration = 'none';
			break;
		case 1:
			obj.style.backgroundImage = 'url(../Resources/Images/Blue/menuitem_bg_on.gif)';
			obj.style.textDecoration = 'underline';
			break;
	}
}


function showSubMenu(obj) {
	var id = obj.id+'_sub';

	var cur_state = document.getElementById(id).style.display;
	
	if (cur_state=='block')
	{
		document.getElementById(id).style.display = 'none';
	}
	else
	if (cur_state=='none'||cur_state.length==0)
	{
		document.getElementById(id).style.display = 'block';
	}
	
	var st = document.getElementById(obj.id).innerHTML;
	if (st.indexOf('icn_plus.gif')!=-1)
		st = st.replace('icn_plus.gif','icn_minus.gif')
	else
	if (st.indexOf('icn_minus.gif')!=-1)
		st = st.replace('icn_minus.gif','icn_plus.gif');
	
	document.getElementById(obj.id).innerHTML =st;	
}


function linkTo(url) {
	window.location = url;
}

function linkToNewWin(url) {
	window.open(url);
}

function changeSortIcon(obj) {
	var st = obj.innerHTML;
	if (st.indexOf('sortInc')!=-1)
		st = st.replace('sortInc','sortDec')
	else
	if (st.indexOf('sortDec')!=-1)
		st = st.replace('sortDec','sortInc');
	
	obj.innerHTML =st;
}

function changeIconGroup(id, z) {
	var icontag = document.getElementById(id).innerHTML;
	switch (z)
	{
		case 0: icontag = icontag.replace('arrow_opened','arrow_closed'); break;
		case 1: icontag = icontag.replace('arrow_closed','arrow_opened'); break;
	}
	document.getElementById(id).innerHTML = icontag;
}

function replaceCode(id,oldst,newst) {
	var xcode = '';
	xcode = document.getElementById(id).innerHTML
	xcode = xcode.replace(oldst,newst);
	document.getElementById(id).innerHTML = xcode;
}

var cur_group ='';
function showhideDetail(obj) {
	var id = obj.id+'_sub';
	if (cur_group.length>0) //case: have a group opening
	{
		// first: hide current group
		document.getElementById(cur_group).style.display='none';
		var old_parent = cur_group.replace('_sub','');
		document.getElementById(old_parent).style.borderBottom='solid #D6CFCE 1px';
		changeIconGroup(old_parent,0);
		
		if (cur_group!=id)
		{
			// second: and now, show clicked group and save current id
			document.getElementById(id).style.display='block';
			document.getElementById(obj.id).style.borderBottom='';
			changeIconGroup(obj.id,1);
			cur_group = id;
		}
		else
			cur_group='';
	}
	else //case: no group opened
	{
		// show clicked group and save current id
		document.getElementById(id).style.display='block';
		document.getElementById(obj.id).style.borderBottom='';
		changeIconGroup(obj.id,1);
		cur_group = id;
	}
}	


