/**********************************************************************************************
**
**  File name: functions.js
**  Creation date: 24th May, 2001
**  Author: Alex Lui
**
**
**
**  Functions:
**
**    Image functions -
**      void MM_swapImgRestore()    // from Dreamweaver4
**      void MM_preloadImages(String, String, ......, String)    // from Dreamweaver4
**      void MM_findObj()    // from Dreamweaver4
**      void MM_swapImage(String,null,String,)    // from Dreamweaver4
**
**    Layers functions -
**      void MM_showHideLayers()    // from Dreamweaver4
**      void showMenu(String)
**      void hideMenu(String)
**
**    String functions -
**      boolean isWhitespace(String)
**      boolean isAlphaNumeric(String)
**      boolean isAlphabets(String)
**      boolean isInteger(String)
**      boolean isFloat(String)
**      boolean isEmail(String)
**
**********************************************************************************************/

///////////////////////////////////////////////////////////////////////////////////////////////
//  function name: MM_swapImgRestore
//  return value: void
//  parameter(s): void
//  description:
//    This function restores the images that was swapped by the function MM_swapImage
//  Note: this function is copied from Macromedia Dreamweaver 4. P.s. reference DW4 for detail
//        it is always used as counter part with function MM_swapImg()
///////////////////////////////////////////////////////////////////////////////////////////////
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

///////////////////////////////////////////////////////////////////////////////////////////////
//  function name: MM_preloadImages
//  return value: void
//  parameter(s): a list of strings of the full path of the image files that are to be preloaded
//  description:
//    This function restores the images that was swapped by the function MM_swapImage
//  Note: this function is copied from Macromedia Dreamweaver 4. P.s. reference DW4 for detail
///////////////////////////////////////////////////////////////////////////////////////////////
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

///////////////////////////////////////////////////////////////////////////////////////////////
//  function name: MM_findObj
//  Note: this function is copied from Macromedia Dreamweaver 4. P.s. reference DW4 for detail
///////////////////////////////////////////////////////////////////////////////////////////////
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

///////////////////////////////////////////////////////////////////////////////////////////////
//  function name: MM_swapImage
//  return value: void
//  parameter(s): String - image name
//                String - usually empty string ''
//                String - full path name of the image file to swap with
//  description:
//    This function swaps the image named as the 1st parameter with the image specified by the
//    3rd parameter
//  Note: this function is copied from Macromedia Dreamweaver 4. P.s. reference DW4 for detail
//        it is always used as counter part with function MM_swapImgRestore()
///////////////////////////////////////////////////////////////////////////////////////////////
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

///////////////////////////////////////////////////////////////////////////////////////////////
//  function name: MM_showHideLayers
//  return value: void
//  parameter(s): String - layer name
//                String - usually empty string ''
//                String - action, either 'hide' or 'show'
//  description:
//    This function hides or shows the layer named as the 1st parameter
//  Note: this function is copied from Macromedia Dreamweaver 4. P.s. reference DW4 for detail
//////////////////////////////////////////////////////////////////////////////////////////////
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

///////////////////////////////////////////////////////////////////////////////////////////////
//  function name: showMenu
//  return value: void
//  parameter(s): String - menu layer name
//  description:
//    This function shows the menu layer named as the 1st parameter
//  Note: this function create and accesses a variable menuOpened in document object
//        it is always used as counter part with function hideMenu(String)
///////////////////////////////////////////////////////////////////////////////////////////////
function showMenu(navName) {
  if( document.menuOpened!=null )
    hideMenu(navName);
  document.menuOpened = navName;
  MM_showHideLayers(navName,'','show');
}

///////////////////////////////////////////////////////////////////////////////////////////////
//  function name: hideMenu
//  return value: void
//  parameter(s): String - layer name
//                String - usually empty string ''
//                String - action, either 'hide' or 'show'
//  description:
//    This function hides the menu layer named as the 1st parameter
//  Note: this function accesses a variable menuOpened in document object
//        it is always used as counter part with function showMenu(String)
///////////////////////////////////////////////////////////////////////////////////////////////
function hideMenu() {
  navName = document.menuOpened;
  document.menuOpened=null;
  setTimeout("if(document.menuOpened==null || document.menuOpened!='"+navName+"') MM_showHideLayers('"+navName+"','','hide');",10);
}

///////////////////////////////////////////////////////////////////////////////////////////////
//  function name: isWhitespace
//  return value: boolean, i.e. true or flase
//  parameter(s): a String
//  description:
//    This function will return false only if it reaches a character inside the string
//    that is not one of the following characters: space, tab, next line
///////////////////////////////////////////////////////////////////////////////////////////////
function isWhitespace(str)
{
  for(var i=0; i<str.length; i++) {
    var c = str.charAt(i);
    if( c!=' ' && c!='\n' && c!='\t' )
      return false;
  }
  return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////
//  function name: isAlphaNumeric
//  return value: boolean, i.e. true or flase
//  parameter(s): a String
//  description:
//    This function will return true only if the string contains only numbers(0-9) and
//    alphabets(a-z, A-Z)
///////////////////////////////////////////////////////////////////////////////////////////////
function isAlhpaNumeric(str)
{
  for(var i=0; i<str.length; i++) {
    var c = str.charAt(i);
    if( !((c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9')) )
      return false;
  }
  return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////
//  function name: isAlphabets
//  return value: boolean, i.e. true or flase
//  parameter(s): a String
//  description:
//    This function will return true only if the string contains alphabets(a-z, A-Z)
///////////////////////////////////////////////////////////////////////////////////////////////
function isAlphabets(str)
{
  for(var i=0; i<str.length; i++) {
    var c = str.charAt(i);
    if( !((c>='A' && c<='Z') || (c>='a' && c<='z')) )
      return false;
  }
  return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////
//  function name: isEmail
//  return value: boolean, i.e. true or flase
//  parameter(s): a String
//  description:
//    This function will return false only the string is not iin the pattern
//    "string@string.string"
///////////////////////////////////////////////////////////////////////////////////////////////
function isEmail(str)
{
  return true;
}