
// Determine browser type
var bname = navigator.appName;
var bVer = parseInt(navigator.appVersion);

if (bname == "Netscape" && bVer >=4) br = "n4plus";
else if (bname == "Microsoft Internet Explorer" && bVer >= 4) br = "e4plus";
else if (bname == "Microsoft Internet Explorer" && bVer < 4) br = "e3";
else br = "notie";

// determine operating system of viewer
var userAgent = navigator.userAgent;
var userAgent = userAgent.toLowerCase();
var linux = false;
var win16 = false;

if (userAgent.indexOf("linux") != -1) {
     linux = true;
}
if (userAgent.indexOf("Win16") != -1) {
     win16 = true;
}

// Launch a new window from a submit
function openWin( sTmpWinName)
{
var sWinName = new String(sTmpWinName);

// The name tempwin is where all the post requests will target to do not change
var newWindow = window.open("", sWinName, "height=600,width=800,status=no,toolbar=no,directories=no,menubar=no,location=no,resizable=yes,scrollbars=yes,left=0,top=0");
return true;

}

// Launch a new window from a submit
function newWin( sTmpWinName)
{
var sWinName = new String(sTmpWinName);

// The name tempwin is where all the post requests will target to do not change
newWindow = window.open("", sWinName, "height=600,width=800,status=no,toolbar=no,directories=no,menubar=no,location=no,resizable=no,left=0,top=0");
}


// Launch a new window for property charges
function helpWin()
{

// The name tempwin is where all the post requests will target to do not change
var newWindow = window.open("","helpWin","toolbar=no, location=no, directories=no, status=no, menubar=no,scrollbars=yes,resizable=1,width=600,height=400");
return true;

}

// Called by the timeout
function log_user_out(){


  // If it's just one of the smaller windows please
  if (this.window.name == "tempwin")
  {
       this.window.close();
       return true;
  }
  {
       this.document.location = "login.html";
       return true;
  }
}


// Validates that the date conforms to dd/mm/yyyy
function validDate(tmpDate)
{
var tmpDay   = parseInt(tmpDate.substring(0,2), 10);
var tmpMonth = parseInt(tmpDate.substring(3,5), 10);
var tmpYear  = parseInt(tmpDate.substring(6,10), 10);

var tmpDate     = new Date(tmpYear, (tmpMonth - 1), tmpDay);
var currentDate = new Date();


 if (tmpDate == "NaN")
 {
        alert("Invalid Date format, please re-enter as dd/mm/yyyy e.g. 06/02/2007");
                return false;
 }

 //if (tmpDate < currentDate)
 //{
 //             alert("End Date, cannot be less than current Date");
 //             return false;
 //}

 if (tmpMonth < 1 || tmpMonth > 12)
 {
               alert("Invalid Date format, please re-enter as dd/mm/yyyy e.g. 06/02/2007");
               return false;
 }
 else
 {
       if (tmpDay < 1 || tmpDay > 31)
       {
                alert("Invalid Date format, please re-enter as dd/mm/yyyy e.g. 06/02/2007");
                return false;
       }
 }

 return true;

}

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

var reInteger = /^\d+$/


// isInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true),
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

function isInteger (s)

{   var i;

    if (isEmpty(s))
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    return reInteger.test(s)
}

// BOI, followed by one of these two patterns:
// (a) one or more digits, followed by ., followed by zero or more digits
// (b) zero or more digits, followed by ., followed by one or more digits
// ... followed by EOI.
var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/


// isFloat (STRING s [, BOOLEAN emptyOK])
//
// True if string s is an unsigned floating point (real) number.
//
// Also returns true for unsigned integers. If you wish
// to distinguish between integers and floating point numbers,
// first call isInteger, then call isFloat.
//
// Does not accept exponential notation.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isFloat (s)

{   if (isEmpty(s))
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    return reFloat.test(s)
}

// BOI, followed by one or more characters, followed by @,
// followed by one or more characters, followed by .,
// followed by one or more characters, followed by EOI.
var reEmail = /^.+\@.+\..+$/


// isEmail (STRING s [, BOOLEAN emptyOK])
//
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s)

{   if (isEmpty(s))
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);

    else {
       return reEmail.test(s)
    }
}


function day_check(field)
{
if (field.value != "")
{
 var val = parseInt(field.value);
 var newval = ""+val;
  if (newval != field.value)
  {
    alert("You must give numeric value for the day!");
    field.focus();
    field.select();
   }
  else
  {
   if ((val <=0) || (val >= 32))
   {
    alert("Day " + val + " never exists in a month!");
    field.focus();
    field.select();
   }
  }
}
}

function year_check(field)
{
if (field.value != "")
{
 var val = parseInt(field.value);
 var newval = ""+val;
  if (newval != field.value)
  {
    alert("You must give numeric value for the year!");
    field.focus();
    field.select();
   }
  else
  {
   if (val <=0)
   {
    alert("The selected year is not valid!");
    field.focus();
    field.select();
   }
  }
}
}

function checkdate(form)
{
 if (form.day.value == "")
 {
   alert("Please fill in a day!");
   form.day.focus();
   return false;
 }
  if (form.year.value == "")
 {
   alert("Please fill in a year!");
   form.day.focus();
   return false;
 }
  var var_date = new Date(form.year.value,form.month.value,form.day.value);
  if (var_date.getDate() != form.day.value)
  {
    alert("The month "+ form.month.options[form.month.selectedIndex].text +" has no " + form.day.value +"th day");
    return false
  }
 return true;
}

