<!--

/**
* Script contains some common javascript-functions which might be needed
* every where.
*
* @autrho Juha V?in?l?
* @version 03.06.2008
*/

/**
* Returns the first key of the given associated array.
* @param obj Associated array
* @return string First key of the given associated array.
*/
function key(obj){
	if(!isArray(obj) && typeof(obj)!="object")
		return '';
	for(var key in obj)
		return key;
	
}

/**
* Checks if the given value exists within given array.
* @param obj Array from where the value is searched for.
* @param value Seached value
* @return boolean True if given value is found within given array and false otherwise
*/
function inArray(obj,value){

	//alert(obj+" "+value);
    var i;
    for (i=0; i < obj.length; i++) {
        
        if (obj[i] === value) {
            return true;
        }
    }
    return false;

}

/**
* Checks if the given object is an array.
* @param obj Checked object
* @return boolean True if given object is array and false otherwise
*/
function isArray(obj) {
   if(obj==null)
   	return false;
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

/**
* Checks, if given string is a valid integer. Uses IsNumeric-function...
* @param sText String to be checked.
* @return Boolean True, if string is valid integer and false otherwise.
*/
function IsInteger(sText){

	return IsNumeric(sText,true);
}


/**
* Checks, if given string is a valid number (integer or double).
* @param sText String to be checked.
* @param int True, if string must be a valid integer and false if string can also be double.
* @return Boolean True, if string is valid number and false otherwise.
*/
function IsNumeric(sText,forceInt){
   
 if(sText==null)
   	return false;
 else if(sText.length==0)
 	return false;
   	
   if(forceInt!=null && forceInt)
	   var ValidChars = "-0123456789";
   else
	   var ValidChars = "-0123456789.";
	   
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

/**
* Removes whitespaces from the beginning and end of the given string.
* @param str String to be trimmed
* @return String trimmed string
*/
function trim(str){

	return str.replace(/^\s+|\s+$/g, '') ;

}

-->
