function strTrim(tmpStr)
{
	tmpStr = tmpStr.replace(/^\s+/,"");//remove leading
	tmpStr = tmpStr.replace(/\s+$/,"");//remove trailing
	return tmpStr;
}
//-------------------------------------------------------------------------
function trimFields()
{
	for(var i=0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].type == "text" || obj.elements[i].type == "textarea" || obj.elements[i].type == "password")
		{
			obj.elements[i].value = strTrim(obj.elements[i].value);
		}
	}
}
//-------------------------------------------------------------------------
function chkEmail(tmpStr)
{
	var email_pat = /^[a-z][a-z0-9_\.\-]*[a-z0-9]@[a-z0-9]+[a-z0-9\.\-_]*\.[a-z]+$/i;
	return(email_pat.test(tmpStr));
}
//-------------------------------------------------------------------------
function validateTALength(strField, cntlName, maxChar)
{
	if(obj.elements[cntlName].value.length > maxChar)
	{
		alert(strField+" should be within "+maxChar+" characters.");
		//obj.elements[cntlName].focus();
		//obj.elements[cntlName].select();
		return false;
	}
	return true;
}
//-------------------------------------------------------------------------
//Removes options from a dropdown
function removeOptions(cbo, allOpt)
{
	allOpt = (typeof allOpt != 'undefined')?allOpt:true;
	var startIndex = (allOpt)?1:0;
	while(cbo.options[startIndex])
		cbo.options[startIndex] = null;
}

function redirURL(id, url)
{
	window.open('redirect.php?id='+id+'&url='+url);
}

//-------------------------------------------------------------------------
//Generic AJAX object for all get/post work
var ajax;
ajax = new Object();
ajax.httpRequest = null; //Initialize
ajax.callbackFunc = null; //Initialize

//Creates http request object
function __createHttpRequest()
{
	var httpRequest = false;
	if(window.XMLHttpRequest) //Mozilla, Safari etc
	{
		httpRequest =new XMLHttpRequest();
	}
	else if(window.ActiveXObject) //IE
	{
		try
		{
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	}
	return httpRequest;
}

//GET method request
ajax.getRequest = function(url, parameters, callbackFunc)
{
	this.httpRequest = __createHttpRequest() //recreate ajax object to defeat cache problem in IE
	this.callbackFunc = callbackFunc;
	if(this.httpRequest)
	{
		this.httpRequest.onreadystatechange = __handleResponse;
		this.httpRequest.open('GET', url+"?hash="+Math.random()+'&'+parameters, true);
		this.httpRequest.send(null)
	}
}

//POST method request
ajax.postRequest = function(url, parameters, callbackFunc)
{
	this.httpRequest = __createHttpRequest() //recreate ajax object to defeat cache problem in IE
	this.callbackFunc = callbackFunc;
	if (this.httpRequest)
	{
		this.httpRequest.onreadystatechange = __handleResponse;
		this.httpRequest.open('POST', url, true);
		this.httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.httpRequest.setRequestHeader("Content-length", parameters.length);
		this.httpRequest.setRequestHeader("Connection", "close");
		this.httpRequest.send(parameters);
	}
}

//Handle response, pass the result to callbackFunc
function __handleResponse()
{
	if(ajax.httpRequest.readyState == 4)
	{
		ajax.callbackFunc(ajax.httpRequest.responseText);
	}
}

//Function for mouseover event of the left menu
function mOver(ele)
{
	ele.className = 'mnu_o';
}

function mOut(ele)
{
	ele.className = "mnu";
}

function sOut(ele)
{
	ele.className = "smnu"
}
//Function for mouseover event of data displayed in admin home page
function dOver(ele)
{
	ele.className = 'dat_o';
}

function dOut(ele)
{
	ele.className = "dat";
}

//Function for redirecting the selected menu into respective pages.
function go(pgName)
{
	self.location = pgName;
}

//Function for embeding flash
function writeFlash(swfPath, width, height)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" align="middle">\n');
	document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<param name="movie" value="'+swfPath+'" />\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
	document.write('<param name="bgcolor" value="#00000" />\n');
	document.write('<embed src="'+swfPath+'" quality="high" bgcolor="#000000" width="'+width+'" height="'+height+'" wmode="transparent"\n');
	document.write('align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"\n');
	document.write('pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');
	document.write('</object>');
}

//Opens a new window showing the uploaded image
function viewImage(imgFile)
{
	imgURL = imgFile;
	newWindow = window.open("","newWindow","titlebar=no,width=50,height=50,left=375,top=225");
	var doc = newWindow.document;
	doc.open();
	doc.write('<html>\n');
	doc.write('<head>\n');
	doc.write('<title>View Image</title>\n');
	doc.write('<meta http-equiv="imagetoolbar" content="no">\n');
	doc.write('</head>\n');
	doc.write('<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" ondblclick="self.close();"  onblur="self.close();" onload="javascript:window.resizeTo(document.getElementById(\'theImage\').width + 10, document.getElementById(\'theImage\').height + 50)">\n');
	doc.write('<img src=\"'+imgURL+'\" alt=\"File: '+imgFile+'\n(Double Click to Close)\" border="0" name="theImage" id="theImage" />\n');
	doc.write('</body>\n');
	doc.write('</html>\n');
	newWindow.focus();
	doc.close();
}

//-------------------------------------------------------------------------
