// whitespace characters
var whitespace = " \t\n\r";

////////////////////////////////////////////////////////////////////////////////
//  function: trim
//      return the string that is trimmed.
////////////////////////////////////////////////////////////////////////////////		
String.prototype.trim = function() 
{
    // skip leading and trailing whitespace
    // and return everything in between
    return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}

////////////////////////////////////////////////////////////////////////////////
//  function: isEmpty
//      return true if the value is empty
////////////////////////////////////////////////////////////////////////////////	
function isEmpty(to)
{
	if (to.value.trim().length==0)
	{
		return(true);		   
	}
}

////////////////////////////////////////////////////////////////////////////////
//  function: isEmptyValue
//      return true if the value is empty
////////////////////////////////////////////////////////////////////////////////	
function isEmptyValue(s)
{
	if (s.trim().length==0)
		return true;
	else
	    return false;
}

////////////////////////////////////////////////////////////////////////////////
//  function: isWhitespace
// 		Returns true if string s is empty or whitespace characters only.

function isWhitespace(s)
{   
	var i;
    // Is s empty?
    if (isEmptyValue(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
    }
    // All characters are whitespace.
    return true;
}

function checkDate(d) {
	//1981-05-03
	if (d.charAt(4) != "-" || d.charAt(7) != "-") {
		return true;
	}
	if (!isInt(d.substring(0, 4))) {
		return true;
	}
	if (!isInt(d.substring(5, 7))) {
		return true;
	}
	if (!isInt(d.substring(8, 10))) {
		return true;
	}
	return false;
}
function isInt(val) 
{
	for (var i=0; i < val.length; i++) 
	{
		if (!isDigit(val.charAt(i))) { return false; }
	}
	
	return true;
}
////////////////////////////////////////////////////////////////////////////////
//  function: isInteger
//      returns true if the value passed in is it of integer value
////////////////////////////////////////////////////////////////////////////////		
function isInteger(val) 
{
	for (var i=0; i < val.value.length; i++) 
	{
		if (!isDigit(val.value.charAt(i))) { return false; }
	}
	
	return true;
}

////////////////////////////////////////////////////////////////////////////////
//  function: isDigit
//      returns true if the value passed in is a number
////////////////////////////////////////////////////////////////////////////////	
function isDigit(num) 
{
	var string="1234567890";
	if (string.indexOf(num) != -1) 
	{
		return true;
	}
	
	return false;
}

////////////////////////////////////////////////////////////////////////////////
//  function: isDouble
//      returns true if the value passed in is it of double value
////////////////////////////////////////////////////////////////////////////////		
function isDouble(val) 
{
    var gotDot = 0;
	for (var i=0; i < val.value.length; i++) 
	{
		if (val.value.charAt(i) == '.')
		{
			if (gotDot == 0)
			    gotDot = 1;
			else
			    return false;
		}
		else
		if (!isDigit(val.value.charAt(i))) 
		{ return false; }
	}
	
	return true;
}

////////////////////////////////////////////////////////////////////////////////
//  function: checkTextAreaLength
//      make sure that the length of the textarea is within the max length
////////////////////////////////////////////////////////////////////////////////	
function checkTextAreaLength(id, maxlen)
{
    // Is length less than maxlen?
    if (id.value.length > maxlen )
        id.value = id.value.substring(0, maxlen-1);
}

////////////////////////////////////////////////////////////////////////////////
//  function: isEmail
// 		Email address must be of form a@b.c ... in other words:
// 		there must be at least one character before the @
// 		there must be at least one character before and after the .
// 		the characters @ and . are both required
////////////////////////////////////////////////////////////////////////////////
function isEmail(s)
{   
    // is s whitespace?
    if (isWhitespace(s))
    	return false;

    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    	i++;

    if ((i >= sLength) || (s.charAt(i) != "@")) 
    	return false;
    else 
    	i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    	i++;

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) 
    	return false;
    else 
    	return true;
}

////////////////////////////////////////////////////////////////////////////////////////////
//  function: allowNumericOnly
//      This function will restrict the user from entering alphabets
////////////////////////////////////////////////////////////////////////////////////////////
function allowNumericOnly()
{
    // Get ASCII value of key that user pressed
    var key = window.event.keyCode;

    // Was key that was pressed a numeric character (0-9)?
    if ( key > 47 && key < 58 )
        return; // if so, do nothing
    else
        window.event.returnValue = null; // otherwise, discard character
}

////////////////////////////////////////////////////////////////////////////////////////////
//  function: allowDoubleOnly
//      This function will restrict the user from entering alphabets
//      Allow only numeric and decimal point
////////////////////////////////////////////////////////////////////////////////////////////
function allowDoubleOnly()
{
    // Get ASCII value of key that user pressed
    var key = window.event.keyCode;

    // Was key that was pressed a numeric character (0-9)?
    if (( key > 47 && key < 58 ) || (key == 46))
        return; // if so, do nothing
    else
        window.event.returnValue = null; // otherwise, discard character
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}