/******************************************************
*	Constant used
*******************************************************/
var MENU_MOUSEOVER_COLOR	= '#ffffff'
var MENU_MOUSEDOWN_COLOR	= '#ffffff'
	
function bodyscroll() {
	var f = document.forms[0];
	if(f.ScrollTop) {
		f.ScrollTop.value = Body.scrollTop;
	}
}

function stopError() {
	return true;
}
/******************************************************
*	Open a floating window with specified url or form name
*******************************************************/
function openWindow(url, name, titlebar, navigatable, scrollable, resizable, menubar, statusbar, status, location, width, height, top, left)
{
	var realTop, realLeft;
	realTop = top;
	if(top == null){
		realTop = (screen.height - height)/2;
	}
	realLeft = left;
	if(left == null){
		realLeft = (screen.width - width)/2;
	}	
	if(width == null){
		width = screen.width;
	}
	if(height == null){
		height = screen.height;
	}
	var features =		"width="+width 
					+	",height="+height
					+	",scrollbars="+scrollable
					+	",resizable="+resizable
					+	",toolbar="+navigatable
					+	",titlebar="+titlebar
					+	",menubar="+menubar
					+	",copyhistory=no"
					+	",status="+statusbar
					+	",location="+location
					+	",top="+realTop
					+	",left="+realLeft;
	var mywin = window.open(url, name, features);
	if(statusbar != null && status != null){
		mywin.status = status;				
	}
}

/***************************************************
*	Vote or view a poll results
***************************************************/
function SubmitVote(listName, action, qid)
{
	var form = (document.forms[0]);
	var optionList = '';
	var item;
	for (var i = 0; i < form.elements.length; i++){
		item = form.elements[i];
		//if it is a checkable item and it belongs to the listName namespace
		//and is checked then add it to the option list
		if((item.type == "checkbox" 
			|| item.type == "radio")
			&& item.id.indexOf(listName) >= 0
			&& item.checked){
			if(item.type == "radio") {
				//radio button then just simple
				optionList += item.value + ",";
			} else {
				//check box, get value from parent span
				optionList += item.parentElement.value + ",";
			}
		}
	}
	if (action==0) //vote, check if some selected
	{
		if (optionList=='')
		{
			alert('Please select at least one option!');
			return;
		}
	}
	//build url with querystring
	var url = 'noconf/PollResults.aspx?itemid=' + qid + '&action=' + action + '&oid=' + optionList ;
	//open the result windows
	openWindow(url, '', '', 'no', 'no', 'no', 'no', 'no', '', 'no', 400, 400);
}






/*************************************
*	Use for numerical-only input fields
**************************************/
function CheckNumerical(control, oEvent)
{
	var keyCode = oEvent.keyCode;
	//Minus is allowed only as first char
	if ((control.value.length > 0) && (keyCode == 45)){
		oEvent.returnValue = false;
	}
	//only 0..9,-,backspace and non-keycode chars(del, arrows, ...)
	if((keyCode < 48 || keyCode > 57) && (keyCode != 45) && (keyCode != 8) && (keyCode != 0)) {
		oEvent.returnValue = false;
	}
}

function ValidateNumerical(control) {
	if (control.value == "") {
		return true;
	}
	if (isNaN(control.value*1)==true){
		control.select();
		alert('Number allowed only!');
		control.focus();
	}
}


//a replacement for __doPostBack
function DoSubmit(eventTarget, eventArgument){
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms["Form1"];
	}
	else {
		theform = document.Form1;
	}
	theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
	theform.__EVENTARGUMENT.value = eventArgument;
	theform.submit();
}

function CheckEnterAndSubmit(e, eventTarget, eventArgument){
	var kC = document.layers?e.which:document.all?event.keyCode:document.getElementById?e.keyCode:null; 
	if (kC == 13) {
		DoSubmit(eventTarget, eventArgument);
	}
	event.bubbleEvent = false;
}

/*************************************
*	Get current DateTime 
**************************************/
function getYear(curDate) {
	var y = curDate.getYear();
	y = y%100;
	y += (y<38) ? 2000 : 1900;
	return y;
}

function getEnglishDayPost(iDay) {
	if (iDay == 1 || iDay == 31) {
		return iDay+'st';
	} else if (iDay == 2) {
		return iDay+'nd';
	} else if (iDay == 3) {
		return iDay+'rd';
	} else {
		return iDay+'th';
	}
}

function displayDateTime(lan) {
	lan = (lan==0?"en-us":"vi-vn");
	//vn: Thu hai, ngay 21 thang 3 nam 2004
	//en: Monday, March 21st 2004
	var dateText = "";
	var curDate = new Date();
	if (lan == "en-us") {
		var Days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
		var Months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
		var Year = getYear(curDate);
		var MonthName = Months[curDate.getMonth()];
		var DayName = Days[curDate.getDay()];
		var DayNum = curDate.getDate();
		dateText = DayName+", "+MonthName+" "+getEnglishDayPost(DayNum)+" "+Year;
	} else if (lan == "vi-vn") {
		var Days = new Array('Chủ nhật', 'Thứ hai', 'Thứ ba', 'Thứ tư', 'Thứ năm', 'Thứ sáu', 'Thứ bảy');
		var Year = getYear(curDate);
		var Month = curDate.getMonth();
		var DayName = Days[curDate.getDay()];
		var DayNum = curDate.getDate();
		dateText = DayName+", ngày "+DayNum+" tháng "+Month+"  năm "+Year;
	}
	return dateText;
}

function high(which2, spd){
	theobject=which2
	highlighting=setInterval("highlightit(theobject)", spd)
}

function low(which2, mz, op){
	clearInterval(highlighting)
	if (which2.style.MozOpacity)
		which2.style.MozOpacity=mz
	else if (which2.filters)
		which2.filters.alpha.opacity=op
}

function highlightit(cur2){
	if (cur2.style.MozOpacity<1)
		cur2.style.MozOpacity=parseFloat(cur2.style.MozOpacity)+0.1
	else if (cur2.filters&&cur2.filters.alpha.opacity<100)
		cur2.filters.alpha.opacity+=20
	else if (window.highlighting)
		clearInterval(highlighting)
}

function yim(id) {
	location.href="ymsgr:sendIM?"+escape(id);
}