/*
' ====================== DO NOT EDIT THIS SECTION =========================
' $RCSfile: utils.js,v $ 
' $Author: lorant $
' $Date: 2004/11/25 17:49:37 $
' $Revision: 1.5 $
' $Name:  $
' ==== Copyright Global Market Insite, Inc., 2001. All rights reserved ====
*/

function cell(txt){
  document.writeln('<tr>',txt,'</tr>');
}

function menu(txt,lnk){
  cell('<td class="MenuLink"><a href=JavaScript:link("' + lnk + '") class="MenuLink">' + txt + '</a></td>');
}

function label(txt){
  cell('<td class="MenuLabel">'+txt+'</td>');
}
function line(){
  cell('<td class="MenuLine">&nbsp</td>');
}

function link(url){
  window.location.href = url;
}

function headerlink(txt,lnk){
  document.writeln('<a href=JavaScript:link("' + lnk + '")>' + txt + '</a>&nbsp;&nbsp;');
}

function ChangeLanguage(){
  popwin=window.open("/portals/common/language.asp", "language", "height=100,width=250,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=no,status=0,toolbar=0", "language");
  popwin.moveTo(screen.width/2-50,screen.height/2-125);
}

// Validation functions

var whitespace = " \t\n\r";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz01234567890_-"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-"

function isEmpty(s){
  return ((s == null) || (s.length == 0))
}// End isEmpty

function isWhitespace (s){
  var i;

  // Is s empty?
  if (isEmpty(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;
}// End isWhiteSpace

// Returns true if character c is a digit
// (0 .. 9).
function isDigit (c){
  return ((c >= "0") && (c <= "9"))
}

function isInteger (s){
  var i;
  if (isEmpty(s))
  return true;

  // Search through string's characters one by one
  // until we find a non-numeric character.
  // When we do, return false; if we don't, return true.

  for (i = 0; i < s.length; i++){
    // Check that current character is number.
    var c = s.charAt(i);

    if (!isDigit(c)) return false;
  }

  // All characters are numbers.
  return true;
}

function isFloat (s, decimalPointDelimiter){
  var i;
  var seenDecimalPoint = false;
  
  if (isEmpty(s))
  return true;

  // Search through string's characters one by one
  // until we find a non-numeric character.
  // When we do, return false; if we don't, return true.
  for (i = 0; i < s.length; i++){
    // Check that current character is number.
    var c = s.charAt(i);

    if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
  }

  // All characters are numbers.
  return true;
}

function isEmail(s) {
	re = /^[0-9a-zA-Z\.\-\_\+\&\'\$\%\#\*\/\?]+\@[0-9a-zA-Z\.\-]+$/ig;
	if (!re.test(s))
		return false;
	re = /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/i;
	if (re.test(s))
		return false;
	re = /([0-9a-zA-Z\_]{1})\@./i;
	if (!re.test(s))
		return false;
	re = /.\@([0-9a-zA-Z]{1})/i;
	if (!re.test(s))
		return false;
	re = /.\.\-.|.\-\..|.\.\../ig;
	if (re.test(s))
		return false;
	re = /.\.\_.|.\-\_.|.\_\..|.\_\-./ig;
	if (re.test(s))
		return false;
	re = /\.([a-zA-Z]{2,4})$/i;
	if (!re.test(s))
		return false;
	return true;
}

/***
IN: str - the string we are RIGHTing
n - the number of characters we want to return

RETVAL: n characters from the right side of the string
***/
function Right(str, n){
  if (n <= 0)     // Invalid bound, return blank string
    return "";
  else if (n > String(str).length)   // Invalid bound, return
    return str;                     // entire string
  else { // Valid bound, return appropriate substring
    var iLen = String(str).length;
    return String(str).substring(iLen, iLen - n);
  }
}

