function trim(str) {
	var l = str.length
		
	for (var i = 0; i < l; i++)
		if (str.substr(i, 1) != ' ') break;
		
	for (var j = l - 1; j > 0; j--)
		if (str.substr(j, 1) != ' ') break;
			
	return str.substr(i, j-i+1);
}

function isEmpty(obj, msg) {
	if (trim(obj.value) == '') {
		alert(msg + ' is required.');
		try {
			obj.focus();
			obj.select();
		} catch (e) {}
		return true;
	}

	return false;
}


function isValidEmail(email){
	var InvalidKey = " ~`#$%^&*()|{}[]?<>,/\\;:'\"";
	var locAt = email.indexOf("@");
	var i;
	
	// if no input at all, just ignore checking.
	if(email.length == 0)return true;
	
	// if the dot is in the last location.
	if(email.lastIndexOf(".") == (email.length - 1)){
		return false;
	}
	
	// if the 'dot' not found in the email address.
	if(email.lastIndexOf(".") == -1){
		return false;
	}
	
	// if the dots are adjacent.
	var arr = email.split(".");
	for(i in arr){
		if(arr[i].length == 0){
			return false;
		}
	}

	// if the invalid character is in the email address.
	for(i = 0; i < InvalidKey.length; i++){
		if(email.indexOf(InvalidKey.substr(i, 1)) != -1){
			return false;
		}
	}
	
	// Check if the '@' symbol can not be found in the email address.
	if(locAt == -1){
		return false;
	}
		
	var UserName = email.substr(0, locAt);
	var HostName = email.substr(locAt + 1);
	
	// check if host name is empty or contain the '@' symbol.
	if(HostName.length == 0 || HostName.indexOf("@") != -1){
		return false;
	}
	
	return true;
}

function isError(exp, obj, msg) {
	if (exp) {
		alert('Invalid ' + msg + '.');
		obj.focus();
		try {
			obj.select();
		} catch (e) {}
	}
	
	return exp;
}

function compareDate(date1, date2) {
	if (date1 < date2)
		return -1;
	else if (date1 > date2)
		return 1;
	else
		return 0;
}

function openWindow(url, name, top, left, width, height, attr) {
	return window.open(url, name, attr + 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);
}

function openCenterWindow(url, name, width, height, attr) {
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	
	if (attr == null) attr = '';
	if (attr != '') attr += ',';

	return window.open(url, name, attr + 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);
}

function getRadioValue(radioName) {
	var obj = document.getElementsByName(radioName);
	for (var i=0; i < obj.length; i++) {
		if (obj[i].checked) return obj[i].value;
	}
	
	return '';
}

function isChecked(name) {
	var obj = document.getElementsByName(name);
	for (var i=0; i < obj.length; i++)
		if (obj[i].tagName == 'INPUT' && obj[i].type == 'checkbox' && obj[i].checked) return true;
		
	return false;
}

function showDialog(height, width, strTitle, strBody) {
	return window.showModalDialog('../Includes/dialog.aspx?title=' + strTitle, strBody, 'scroll:no;status:no;help:no;dialogHeight:' + height + 'px;dialogWidth:' + width + 'px');
}

function Prompt(height, width, strTitle, strPrompt, strValue, maxLength) {
	var strBody = '<table width="95%" height="95%" align="center" valign="middle"><tr><td>';
	strBody += '</td></tr>';
	strBody += '<tr><td>';
	strBody += strPrompt;
	strBody += '</td></tr>';
	strBody += '<tr><td>';
	strBody += '<input id="txtValue" type="text" style="width:100%" maxlength="'+maxLength+'" value="'+strValue.replace(/"/gi, '&quot')+'">';
	strBody += '</td></tr>';
	strBody += '<tr><td align="right">';
	strBody += '<button type="submit" onclick="window.returnValue=txtValue.value;window.close()">&nbsp;Okay&nbsp;</button>&nbsp;<button onclick="window.returnValue=null;window.close()">Cancel</button>';
	strBody += '</td></tr>';
	strBody += '</table>';
	strBody += '<script'+'>function window.onload() {txtValue.focus();txtValue.select();}';
	strBody += 'function window.document.body.onkeypress() {if (event.keyCode==27) window.close()}</'+'script>';

	return showDialog(height, width, strTitle, strBody);
}

	
var previous_Y;

function scrollR()
{
	try {
	var top = document.body.scrollTop;
	previous_Y = document.body.scrollTop;	
	

	window.parent.document.frames["side"].scrollTo(previous_Y, top);
	}catch(e){};
}