// Global variables & functions
var isIE=-1;			// is IE browser(1) or not(0)
var isMAC=0;			// is MAC(1) or PC(0)
var isVER=0;			// which version of browser is
var isRightClickOn='0';	// 0, turn off 2nd mounse button; 1, turn on;

var dt_event = new Array([12][1]);
var calePage = "";
var dt_current = new Date();
checkBrowserType();

//Stop the Right Mouse Click for code protection
document.oncontextmenu = function() 
{
	alert("All rights reserved.");
	if (isRightClickOn=='1')
	{	return true;	}
	else
	{	return false;	}
}

function checkBrowserType()
{
	if(window.navigator.appName == "Microsoft Internet Explorer")
	{	isIE = 1;
		isVER = parseFloat(window.navigator.appVersion.substring(window.navigator.appVersion.indexOf("MSIE") + 5, 
				window.navigator.appVersion.indexOf("MSIE") + 8));
	}
	else
	{	isIE = 0;		}
	var tmpVer = window.navigator.appVersion.toUpperCase();
	if ((tmpVer.indexOf("MAC")!=-1) || (tmpVer.indexOf("POWERPC")!=-1))
	{	isMAC = 1;		}
	else
	{	isMAC = 0;		}
}
  
// Code for calendar
function calendar()
{
	var ARR_MONTHS = ["January", "February", "March", "April", "May", "June",
		"July", "August", "September", "October", "November", "December"];
	// week day titles as they appear on the calendar
	var ARR_WEEKDAYS = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
	// day week starts from (normally 0-Su or 1-Mo)
	var NUM_WEEKSTART = 0;
	// get first day to display in the grid for current month
	var dt_firstday = new Date(dt_current);

	// months as they appear in the calendar's title
	dt_firstday.setDate(1);
	dt_firstday.setDate(1 - (7 + dt_firstday.getDay() - NUM_WEEKSTART) % 7);
	//set default event dates on each month

	dt_event[0] = "";	//Jan
	dt_event[1] = "";
	dt_event[2] = "";	//March
	dt_event[3] = "";
	dt_event[4] = "";	//May
	dt_event[5] = "";
	dt_event[6] = "";	//July
	dt_event[7] = "";
	dt_event[8] = "";	//Sep
	dt_event[9] = "";
	dt_event[10] = "";
	dt_event[11] = "";	//Dec

	calePage += '<table cellpadding="3" cellspacing="0" width="100%" border="0"><tr><td bgcolor="#cc9900"></td><td align="center" width="100%" bgcolor="#cc9900"><font color="#ffffff"><b>'+ARR_MONTHS[dt_current.getMonth()]+' '+dt_current.getFullYear()+'</b></font></td><td bgcolor="#cc9900"></td></tr></table>';
	calePage += '<table class="clsOTable" cellspacing="0" width="100%" border="0" bgcolor="#CCCCCC"><tr><td colspan="3"><table cellspacing="1" cellpadding="3" border="0" width="100%"><tr bgcolor="#CCCCCC">';
	// print weekdays titles
	for (var n=0; n<7; n++)
	{
		calePage += '<td bgcolor="#EEEEEE" align="center"><font color="#333333">'+ARR_WEEKDAYS[(NUM_WEEKSTART+n)%7]+'</font></td>';
	}
	calePage += '</tr>';
	// print calendar table
	var dt_current_day = new Date(dt_firstday);
	while (dt_current_day.getMonth() == dt_current.getMonth() ||
		dt_current_day.getMonth() == dt_firstday.getMonth()) 
	{
		// print row heder	
		calePage += '<tr>';
		for (var n_current_wday=0; n_current_wday<7; n_current_wday++) 
		{
			if ((dt_current_day.getMonth() == this.dt_current.getMonth())&&(dt_event[this.dt_current.getMonth()].indexOf(","+dt_current_day.getDate()+",")!= -1))
			{	// print event date			
				calePage += '<td bgcolor="#CC9900" align="center" width="14%">';	}
			else if (dt_current_day.getDate() == dt_current.getDate() && dt_current_day.getMonth() == dt_current.getMonth())
			{	// print current date
				calePage += '<td bgcolor="#CC99FF" align="center" width="14%">';	}
			else if (dt_current_day.getDay() == 0)
			{	// print Sunday
				calePage += '<td bgcolor="#FFFFFF" align="center" width="14%">';	}
			else if (dt_current_day.getDay() == 6)
			{	// print Saturday
				calePage += '<td bgcolor="#CCCCCC" align="center" width="14%">';	}
			else
			{	// print working days of current month
				calePage += '<td bgcolor="#ffffff" align="center" width="14%">';	}
			if (dt_current_day.getMonth() == this.dt_current.getMonth())
			{	// print days of current month
				calePage += '<span style="color:#333333;font-weight:bold;" >';		}
			else 
			{	// print days of other months
				calePage += '<span style="color:#606060;">';		}	
			calePage += dt_current_day.getDate()+'</span></td>';
			dt_current_day.setDate(dt_current_day.getDate()+1);
		}
		// print row footer
		calePage += '</tr>';
		
	}
	calePage += '</table></tr></td></table>';
}
function showPage()
{
	
	if (thePage=='10')
	{	// hight light contact page
		document.getElementById("navLink_10").className = "navbarOn";
	}
	else
	{	// not for contact us page
		document.getElementById("navSel_"+thePage).style.display = "";
		document.getElementById("navLink_"+thePage).className = "navcurrent";
	}
}
//
// To swap Div block on page
// p: the div id to be turn on
// n: total div blocks in list
// 
function showDiv(p,n)
{
	for (var i=1; i <=n; i++)
	{
		if (i==p)
		{	document.getElementById("divBlock"+i).style.display = "";
			document.getElementById("leftnav_"+i).className = "leftnavOn";	
		}
		else
		{	document.getElementById("divBlock"+i).style.display = "none";
			document.getElementById("leftnav_"+i).className = "leftnav";	
		}
	}
	return false;
}
//
// To swap Div block on page but not update left nav tabs
// p: the div id to be turn on
// n: total div blocks in list
//
function showDiv2(p,n)
{
	for (var i=1; i <=n; i++)
	{
		if (i==p)
		{	document.getElementById("divBlock"+i).style.display = "";		}
		else
		{	document.getElementById("divBlock"+i).style.display = "none";	}
	}
	/* used when try to turn on context menu
	if (p=='12')
	{	//turn of 2nd button on div 12	
		isRightClickOn = '1';	}
	else
	{	isRightClickOn = '0';	}*/
	return false;
}

function openWin(obj)
{
	return openWinURL(obj.href);
}
function openWinURL(url)
{
	var screenWidth=screen.width;
	var screenHeight=screen.height;
	var windowWidth=800;
	var windowHeight=500;
	var leftPos=100;	//Math.round((screenWidth/2)-(windowWidth/2));
	var topPos=100;	//Math.round((screenHeight/2)-(windowHeight/2));	
	
	//for PC IE broswer
	var options1 = "scrollbars=yes,titlebar=no,toolbar=0,status=no,resizable=yes,width="+windowWidth+",height="+windowHeight+",left=" +leftPos+ "px,top=" +topPos+ "px;";
	//for Netscape broswer
	var options2 = "scrollbars=yes,titlebar=no,toolbar=0,status=no,menubar=no,location=no,resizable=yes,width=" +windowWidth+ ",height=" +windowHeight+ ",left=" +leftPos+ ",top=" +topPos;
	//for MAC IE broswer
	var options3 = "scrollbars=yes;titlebar=no;toolbar=0;status=no;resizable=yes;left=" +leftPos+ ";top=" +topPos+ ";dialogWidth=" +windowWidth+ ";dialogHeight=" +windowHeight+ ";";

	var winid = "";
	if (isIE > 0)
	{	winid = window.open(url,"ibpsnj", options1);	}
	else
	{
		if (isMAC > 0)
		{	winid = window.open(url,"ibpsnj", options3);	}
		else
		{	winid = window.open(url,"ibpsnj", options2);	}
	}		
	if (winid != "")
	{	winid.focus();		}
	return false;
}

// Use by Chorus member page to swap members' picture
function showPhoto(url,n)
{
	if (n=='1')
	{	document.getElementById("pic2").src = "photo/" + url;	}
	if (n=='2')
	{	document.getElementById("pic3").src = "photo/" + url;	}
	
	return true;
}

//Swap page on Wisefare
var curPage = '1';
function onPage(n)
{
	document.getElementById("pg"+curPage).style.display = "none";
	document.getElementById("pg"+n).style.display = "";
	curPage = n;
	return false;
}