/*
  Utility functions
  D. Goldman
 
  Copyright 1998 Galactic Ventures, Inc. All rights reserved.
*/ 

var word_chars = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
                  "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
                  "0","1","2","3","4","5","6","7","8","9"," ",",",".","-"];
 
var whitespace = [" ",'\t','\n','\r','\f','\v'];
                  
function setSelectedOption ( selectList, optionValue )
{

  for (count=0; count < selectList.length; count++)
    if (selectList.options[ count ].value == optionValue)
    {
      selectList.options[ count ].selected = true;
      return;
    }  
}

function setSelectedRadio (radioList, radioValue)
{
  for (count=0; count < radioList.length; count++)
    if (radioList[ count ].value == radioValue)
    {
      radioList[ count ].checked = true;
      return;
    }  
}


function isBlank( str ) 
{     
  var Blank = true;
  var i, j;
  
  for (i = 0; i < str.length && Blank == true; i++)
  {
    Blank = false;
    for (j = 0; j < 6 && Blank == false; j++)
      if (str.charAt(i) == whitespace[j])
        Blank = true;
  }    
  return Blank;
  
//    if (str.charAt(i).search(/\w/) > -1) 
//      allBlanks = false;
  
} 


function valPassword( str ) 
{
  var valid_password = true;
  var i, j;
  
  if (str.length < 6)
    return false;
  
  for (i = 0; i < str.length && valid_password == true; i++)
  {
    valid_password = false;
    for (j = 0; j < 62 && valid_password == false; j++)
      if (str.charAt(i) == word_chars[j])
        valid_password = true;
  }
  return valid_password;


//  if (str.search(/\W/) > -1)
//    return false;

} 

function valPhoneNumber(str)
{

  var valid_phone = true;
  var i, j;
  
  for (i = 0; i < str.length && valid_phone == true; i++)
  {
    valid_phone = false;
    for (j = 0; j < 66 && valid_phone == false; j++)
      if (str.charAt(i) == word_chars[j])
        valid_phone = true;
  }
  return(valid_phone);  
  
  
//  if (str.search(/[^ a-zA-Z0-9,.-]/) > -1)
//    return false;

}

function valPhoneAreaCode(str)
{
  var valid_area_code = true;
  var i, j;
  
  for (i = 0; i < str.length && valid_area_code == true; i++)
  {
    valid_area_code = false;
    for (j = 0; j < 62 && valid_area_code == false; j++)
      if (str.charAt(i) == word_chars[j])
        valid_area_code = true;
  }
  return(valid_area_code);  


//  if (str.search(/[^a-zA-Z0-9]/) > -1)
//    return false;

}
    
function isNull( val ) 
{

  var isValid = false;

  if (val+"" == "null")
    isValid = true;
  return isValid;
}


function isUndef( val ) 
{
  var isValid = false;
  if (val+"" == "undefined")
    isValid = true;
  return isValid;
}


function showSelectedValue( selectObject )
{ 
  var list = "";
  
  if (selectObject == null)
   return null;
  
  for (var i=0; i < selectObject.length; i++) 
    if (selectObject.options[i].selected) 
      list +=  selectObject.options[i].value;
  return list;
 }

function showSelectedText( selectObject )
{ 
  var list = "";
  if (selectObject == null)
    return null;
  for (var i=0; i < selectObject.length; i++) 
    if (selectObject.options[i].selected)
      list +=  selectObject.options[i].text;
  return list;
}
    			
function valNumber(str)
{
  var valid_number = true;
  var i, j;
  
  for (i = 0; i < str.length && valid_number == true; i++)
  {
    valid_number = false;
    for (j = 52; j <= 61 && valid_number == false; j++)
      if (str.charAt(i) == word_chars[j])
        valid_number = true;
  }
  return(valid_number);  
}

function popwindow(popurl, p_width, p_height)
{

popWin = window.open(popurl,"exportComplianceWindow","resizeable=yes,toolbar=no,screenx=20,screeny=20,top=20, left=20,width="+p_width+",height="+p_height+",scrollbars=yes");
popWin.focus();
			}

function newwindow(popurl, p_width, p_height)
{

popWin = window.open(popurl,"exportComplianceWindow","resizeable=yes,toolbar=yes,screenx=20,screeny=20,top=20, left=20,width="+p_width+",height="+p_height+",scrollbars=yes");
popWin.focus();
			}			
			
			
function valEmail( fieldName ) 
{
  txt=fieldName;

  if (txt.indexOf("@") < 1)            /* Must have "@" not in first position */
  {
    alert ("An e-mail address must contain an \"@\" sign not in the first position");
    return(false);
  }
  if (txt.indexOf(".") == -1)          /* Must have "." */
  {
    alert ("An e-mail address must contain a \".\"");
    return(false);
  }
  if (txt.indexOf(".") == txt.length - 1) /* Must have a top level domain after the "." */
  {
    alert("An e-mail address must contain a top level domain (e.g. \".com\") after the \".\"");
    return(false);
  }  
  if (txt.indexOf(".") == txt.indexOf("@")+1)  /*  Must have some character between "@" and "." */
  {
    alert("An e-mail address must contain a domain");
    return(false);
  }

/***** The following condition is too restrictive 
      if ((txt.indexOf(".com")<5)&&(txt.indexOf(".org")<5)
      &&(txt.indexOf(".gov")<5)&&(txt.indexOf(".net")<5)
      &&(txt.indexOf(".mil")<5))
      {
        alert("Please"
        +" check the suffix of your e-mail address. (It should end with a "
        +".com,.net,.org,.gov or .mil)");
        fieldName.focus();
        return(false);
      }
****************/        
  return(true);
}

