// JavaScript Document
// Utility functions

document.onkeydown = getKeycode;
var enable_enter = false;

function state_enter_key(str)
{
	if(str = "on")	
	{
		enable_enter = true;
	}
	else
		enable_enter = false;
	
}

function getKeycode(e)
{
	if(!enable_enter)
	{
	  if (blnNN4)
	  {
	    var mykey = e.which;
	  }
	
	
	  if (blnDOM || blnIE4)
	  {
	    var mykey = event.keyCode;
	  } 
	
	  if (mykey ==13)
		return false;
	}
}

function trim(strObj)
{
	strObj.value = ""+strObj.value;
	var x = 0;
	var y = 0;
	var intPos1 = -1;
	var intPos2 = -1;
	var intChar = 0;
	var str = ""
	var newStr = "";
	var intLen = strObj.value.length-1;

	//Take spaces and enter keys from begining of string
	for(x=0;x<=intLen;x++)
	{
		if((strObj.value.charCodeAt(x) == 32 || (strObj.value.charCodeAt(x) == 10 || strObj.value.charCodeAt(x) == 13)) && intChar == 0)
			intPos1 = x;
		else
			intChar++;
	}

	if(intPos1 >= 0)
	{
		str = strObj.value.substr(intPos1+1,intLen);
		strObj.value = str;
	}
	else
		str = strObj.value;

	intLen = str.length-1;
	intChar = 0;

	//Take spaces and enter keys from end of string
	for(y=intLen;y>=0;y--)
	{
		if((str.charCodeAt(y) == 32 || (str.charCodeAt(y) == 10 || str.charCodeAt(y) == 13)) && intChar == 0)
			intPos2 = y;
		else
			intChar++;
	}
	if(intPos2 > 0)
	{
		newStr = str.substr(0,intPos2);
		strObj.value = newStr;
	}
	else
		newStr = strObj.value;
		
	return newStr;
}
