function leftTrim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}

function rightTrim(sString)
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}




function trim(sString)
{
	return leftTrim(rightTrim(sString));
}



function validateField(fieldName, promt, badValue, focusObject)
{
	//alert('in validate field');
	var bValue = (badValue == null) ? "" : badValue;
	promt = (promt == null) ? "Please enter "+fieldName : promt;
	focusObject = (focusObject == null) ? fieldName : focusObject;
	//if(trim(validateField.value) == bValue)
	if(fieldName.value == bValue)
	{
		
		alert(promt);
		focusObject.focus();
		return false;
	}
	//alert('returnig true');
	return true;
}


function validateEmail(mail, message)
{
	//alert('hi');
	validRegExp 	= /^[^@]+@[^@]+.[a-z]{2,}$/i;
	if (mail.value.search(validRegExp) == -1)
	{
		alert(message);
		return false;
	}
	return true;
}

function getkey(e)
{
  if (window.event)
     return window.event.keyCode;
  else if (e)
     return e.which;
  else
    return null;
}
function acceptKeys(e, goods)
{
 var key, keychar;
 key = getkey(e);
  if (key == null) return true;
	// get character
      keychar = String.fromCharCode(key);
      keychar = keychar.toLowerCase();
      goods = goods.toLowerCase();
   // check goodkeys
    if (goods.indexOf(keychar) != -1)
	 return true;
    // control keys
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
	   return true;
	// else return false
	return false;
}


function acceptNoKeys(e)
{
	//alert('acceptNoKeys');
	var key = getkey(e);
	if(key == null  || key==0 || key==13 || key==27)
		return true;
	else
		return false;
	//alert(key);
	//keychar = String.fromCharCode(key);
	//alert(keychar);
}

//onkeypress="return acceptKeys(event,'0123456789');"