/*
// ---------------------------------------------------------------------------------------------
// This module is part of ongoing modifications to the Spicerhaart source code.
//
// Author: Context Software Limited.
//
// Copyright (c) 2007. All Rights reserved by Context Software Limited. The license does not
// allow for the creation, amendment or distribution of copies of  this source code,
// without the express written permission of Context Software Limited.
// ---------------------------------------------------------------------------------------------
*/


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 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 SetFocusToFirstControl(oForm)
{
    if (oForm != null) 
    {
         for (i=0; i < oForm.length; i++)
        {
            if(oForm.elements[i].type.toLowerCase() != "hidden")
            {
                oForm.elements[i].focus();
                break;
            }
        }
    }
}

