function trimLeft(str){
  if (str==null){return null;}
  for(var i=0;str.charAt(i)==" ";i++);
  return str.substring(i,str.length);
}
function trimRight(str){
  if (str==null){return null;}
  for(var i=str.length-1;str.charAt(i)==" ";i--);
  return str.substring(0,i+1);
}
function trim(str){return trimLeft(trimRight(str));}
function trimLeftAll(str) {
  if (str==null){return str;}
  for (var i=0; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i++);
  return str.substring(i,str.length);
}
function trimRightAll(str) {
  if (str==null){return str;}
  for (var i=str.length-1; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i--);
  return str.substring(0,i+1);
}
function replaceAll(varb, replaceThis, replaceBy)
 {
      newvarbarray=varb.split(replaceThis);
      newvarb=newvarbarray.join(replaceBy);
      return newvarb;
}   
function trimAll(str) {
  return trimLeftAll(trimRightAll(str));
}
// isNull(value)
//   Returns true if value is null
function isNull(val){return(val=="");}

// isBlank(value)
//   Returns true if value only contains spaces
function isBlank(val){
  return isNull(trimAll(val));
}

// isInteger(value)
//   Returns true if value contains all digits
function isInteger(val){
  if (isBlank(val)){return false;}
  for(var i=0;i<val.length;i++){
    if(!isDigit(val.charAt(i))){return false;}
  }
  return true;
}

// isNumeric(value)
//   Returns true if value contains a positive float value
function isNumeric(val){return(parseFloat(val)==(val*1)&&parseFloat(val)>=0);}

// isArray(obj)
// Returns true if the object is an array, else false
function isArray(obj){return(typeof(obj.length)=="undefined")?false:true;}

// isDigit(value)
//   Returns true if value is a 1-character digit
function isDigit(num) {
  if (num.length>1){return false;}
  var string="1234567890";
  if (string.indexOf(num)!=-1){return true;}
  return false;
}

// setNullIfBlank(input_object)
//   Sets a form field to "" if it isBlank()
function setNullIfBlank(obj){if(isBlank(obj.value)){obj.value="";}}

//Basic function added
//return true if the string is valid email string
function isEmailChar(str){
  for (i=0; i<str.length; i++){
    c = str.charAt(i);	  
    if("~!#$%^&*(),\'`:\;?<>=+\n\t \\\"".indexOf(c,0) > 0)
      return false;	
  }
  return true;
}

//return true if the parts of email are valid
function isValidEmail(email){

var array = email.split("@");
  if(array.length != 2) return false; 
  var first, last;
  first = array[0]; last = array[1];
  if( first.charAt(0)=='.') return false;  
  if( first.charAt(first.length)=='.') return false;
  if( last.charAt(0)=='.') return false;
  if(first == "" || last == "") return false;
  first = trimLeftAll(first);
  last = trimRightAll(last);
  if(!isEmailChar(first) || !isEmailChar(last)) 
    return false;
  return true;
}

// return true if number is in range of number
function isInRangeOfNumber(number, from, to){
  if(from<=number&&number<=to)
    return true;
  return false;
}

// round by type
// type="L": lowerRound. Ex: roundEx(1.255, 2, "L") = 1.25
// type="U": upperRound. Ex: roundEx(1.254, 2, "U") = 1.26
// type=others:  Ex:roundEx(1.255, 2, "") = 1.26

var DEFAULT_ROUND_TYPE = "L";
function roundEx(val, digit, type) {
  var result = val;
  if (type == "L")
    result = lowerRound(val, digit); 
  else if (type == "U")
    result = upperRound(val, digit); 
  else  
    result = round(val, digit); 
  return result;
}

// return round number. Ex: lowerRound(1.255, 2) = 1.26
function round(number, digits) { 
  var num = Math.pow(10, digits);
  var result = Math.round(number*num);
  result = result / num;
  return result; 
}

// return round number. Ex: upperRound(1.254, 2) = 1.26
function upperRound(number, digits) {
  var num = Math.pow(10, digits);
  num = num + 0.5;
  var result = Math.round(number * num);
  result = result / num;
  return result;
}

// return round number. Ex: lowerRound(1.256, 2) = 1.25
function lowerRound(number, digits) {
  var num = Math.pow(10, digits);
  var result = parseInt(number * num);
  result = result / num;
  return result;
}
//return true if the ENTER key is pressed
function isEnterPressed(evt) {
  evt = (evt) ? evt : event;
  var charCode  = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
  if (charCode == 13 || charCode == 3)
    return true;
  return false;
}
function txt_copy(txtFrom, txtTo){ 
  txtTo.value = txtFrom.value;
}
//
// Add Functions in here
//
function focusTextbox(textbox) {
  textbox.style.backgroundColor = '#E0F0FE';
}
function blurRequireTextbox(textbox) {
  textbox.style.backgroundColor = '#FFFACD';
}
function blurUnrequireTextbox(textbox) {
  if( trimAll( textbox.value ) == '' )
    textbox.style.backgroundColor = '';
  else {
    textbox.style.backgroundColor = '#FAFFED';
  }
}
function OpenWindow(url, name, width, height){
	window.open(url,name,'menubar=no,status=yes,toolbar=no,width=' + width + ',height=' + height + ',resizable=no,scrollbars=yes,top=0,left=0');
}
  function OpenSearchLink()
  {
  OpenWindow('SearchLink.aspx',400,370);
  }
  function rnd(n,min) {
    if (isNaN(min)) min = 0;
    return (Math.random()*n)+min;
  }
  function rnd2(n,min) {
    if (isNaN(min)) min = 0;
    return Math.floor((Math.random()*n))+min;
  }
