﻿//-----------------------------------------------------------------------------

function isBlank(s)
{
    if (s.length == 0)
        return true;
        
    for(i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if (c != ' ') return false;
    }
    return true;
}

function isInteger(s)
{
    if (s.length == 0)
        return false;
        
    for(i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if ((c < '0') || (c > '9')) return false;
    }
    return true;
}

function isSignedInteger(s)
{
    if (s.length == 0)
        return false;
        
    var c = s.charAt(0);
    if (((c < '0') || (c > '9')) && (c != '-') && (c != '+')) return false;

    for(i = 1; i < s.length; i++)
    {
        c = s.charAt(i);
        if ((c < '0') || (c > '9')) return false;
    }
    return true;
}

function isFloatingPt(s)
{
    if (s.length == 0)
        return false;

    var dpoccurs = 0;        
    for(i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if (((c < '0') || (c > '9')) && (c != '.')) return false;
        if (c == '.')
            dpoccurs++;
    }
    
    if (dpoccurs > 1)
        return false;
        
    return true;
}

function isSignedFloatingPt(s)
{
    if (s.length == 0)
        return false;

    var dpoccurs = 0;        
    for(i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if (((c < '0') || (c > '9')) && (c != '.') && (c != '-') && (c != '+')) return false;
        if (c == '.')
            dpoccurs++;
    }
    
    if (dpoccurs > 1)
        return false;
        
    return true;
}

function isNumeric(s)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < s.length && IsNumber == true; i++) 
   { 
      Char = s.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
   }
   return IsNumber;
}
function isAlpha(s)
{
   var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -";
   var IsVal=true;
   var Char;

   for (i = 0; i < s.length && IsVal == true; i++) 
   { 
      Char = s.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsVal = false;
      }
   }
   return IsVal;
}
function isAlphaNumeric(s)
{
   var ValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -";
   var IsVal=true;
   var Char;

   for (i = 0; i < s.length && IsVal == true; i++) 
   { 
      Char = s.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsVal = false;
      }
   }
   return IsVal;
}

function isValidPhone(s)
{
   var ValidChars = "0123456789 ";
   var IsVal=true;
   var Char;

   for (i = 0; i < s.length && IsVal == true; i++) 
   { 
      Char = s.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsVal = false;
      }
   }
   return IsVal;
}

function isEmailValid(sEmail) 
{
    if (/^\w+([\.-]?\w)*@\w+([\.-]?\w)*(\.\w{2,4})+$/.test(sEmail))
    {
        return (true)
    }
    return (false)
}

function openNewWindow(url, name, features){
    if (name == null || name == '')
        name = "externalsite";

    if (features == null)
        features = "scrollbars=1,height=400,width=550,menubar=1,location=1,resizable=1,toolbar=1,status=1,screenX=0,screenY=0,left=0,top=0";

    window.open(url, name, features);
}

function openPopUpWindow(url, name){    
    
    if (name == null || name == '')
    {
        name = "externalsite";    
    }     
    sname = window.open(url, name, 'scrollbars=0,menubar=0,location=0,resizable=1,status=1,toolbar=0');    
}

function CenterWindow(){            
    winHeight=document.body.clientTop;  
    winWidth=document.body.clientWidth;      
    window.moveTo((screen.availWidth-winWidth)/2,((screen.availHeight-winHeight)/2)-250);
}

function ResizeWindow(winWidth)
{    
    var docHeight = document.height ? document.height :
    document.body && document.body.scrollHeight ? document.body.scrollHeight + 70 : null;    
    if (winWidth && docHeight) window.resizeTo(winWidth,docHeight)    
}

function promptForLogin(){
	var mesg = "You need to be logged in to use the Notepad Facilty\n\n"
	mesg = mesg + "If you are not registered, please use the [Register] link at the top of the page\n"
	mesg = mesg + "If you have previously registered, please use the [Logon] link at the top of the page\n\n"
	alert(mesg)
}

function ShowPopup(MsgID, DivTag)
{
    var messagebox = eval(DivTag).style ;
    document.all(DivTag).innerHTML = PopupMessages[0][MsgID];
    messagebox.width = PopupMessages[1][MsgID] ;
    messagebox.left = PopupMessages[2][MsgID] ;
    messagebox.top = PopupMessages[3][MsgID] ;
    messagebox.visibility = "visible"
}

function HidePopup(DivTag)
{
    var messagebox = eval(DivTag).style ;
    messagebox.visibility="hidden";
}

function OpenWindow(Url, Features) 
{ 
    TopWin = (top)?top:self; 
    NewPage = TopWin.open(Url, "NewPage", Features); 
}

function SetFocusToFirstControl(oForm)
{
    if (oForm != null) 
    {
         for (i=0; i < oForm.length; i++)
        {
            if(oForm.elements[i].type.toLowerCase() != "hidden")
            {
                oForm.elements[i].focus();
                break;
            }
        }
    }
}

function OpenWindowCentered(url, name, w, h)
{
    w += 40;
    h += 22;
    
    wleft = (screen.width - w) / 2;
    wtop = (screen.height - h) / 2;

    if (wleft < 0) 
    {
        w = screen.width;
        wleft = 0;
    }
    if (wtop < 0) 
    {
        h = screen.height;
        wtop = 0;
    }

    var win = window.open(url,
              name,
              'width=' + w + ', height=' + h + ', ' +
              'left=' + wleft + ', top=' + wtop + ', ' +
              'location=no, menubar=no, ' +
              'status=no, toolbar=no, scrollbars=no, resizable=yes');

    win.focus();
}

function verifyCompatibleBrowser()
{ 
    this.ver=navigator.appVersion;
    this.dom=document.getElementById?1:0;
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
    this.ie4=(document.all && !this.dom)?1:0; 
    this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
    this.ns4=(document.layers && !this.dom)?1:0; 
    this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5);
    return this;
}

function MM_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

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 ImgRestore() { //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 ImgSwap() { //v3.0
  var i,j=0,x,a=ImgSwap.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 toggle(id) 
{
    if(document.getElementById(id).style.display == 'none')
        document.getElementById(id).style.display = 'block';
    else
        document.getElementById(id).style.display = 'none';
}
