//Places bold, underline or italic html tags around text. (Luke Frost: 28-Aug-2003)
function getFormatTags(strText, intArrayIndex)
{ 
  var strTags = new Array("<b>", "<i>", "<u>", "</b>", "</i>", "</u>")
  var strReturnValue = strTags[intArrayIndex] + strText + strTags[intArrayIndex + (strTags.length / 2)];
  return strReturnValue;
}

//Returns the current date in dd mmm yyyy format. (Luke Frost: 28-Aug-2003)
function getCurrentDate()
{
  var d = new Date()
  var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
  var date = d.getDate() + " " + monthname[d.getMonth()] + " " + d.getFullYear();
  return date;
}

//Changes the colour of text to what the user selected. (Luke Frost: 28-Aug-2003)
function getColourTags(strText, intArrayIndex)
{
  var colourtags = new Array("color=\"red\">", "color=\"yellow\">", "color=\"green\">", "color=\"blue\">")
  var strReturnValue = "<font " + colourtags[intArrayIndex] + strText + "</font>";
  return strReturnValue;
}

//Prompts the user to enter a URL for an image and creates the html for it. (Luke Frost: 30-Aug-2003)
function getImage()
{
  var strText = "";
  var strImageSource = prompt("Enter In The URL to the image","http://");
  if ((strImageSource != null) && (strImageSource != "") && (strImageSource != "http://"))
  {
    strText = "<img src=\"" + strImageSource + "\" "
    var strWidth = prompt("Enter In The width that you want the image to be","0");
    var strHeight = prompt("Enter In The height that you want the image to be","0");
    if ((strWidth != null) && (strWidth != "") && (strWidth != 0))
       strText += "width=\"" + strWidth + "\" ";
    if ((strHeight != null) && (strHeight != "") && (strHeight != 0))
       strText += "height=\"" + strHeight + "\"";
    strText += ">";
  }
  return strText;
}

//Removes the html tags from text. IE: "<b>blah</b>" - "blah" (Luke Frost: 30-Aug-2003)
function getNoTags(strText)
{
  var strReturnValue = "";
  var strStartg = strText.indexOf(">");
  var strStartl = strText.indexOf("<");
  var strEndg = strText.lastIndexOf(">");
  var strEndl = strText.lastIndexOf("<");
  if((strStartl == 0) && ((strEndl != -1) && (strEndl != strStartl)) && (strStartg != -1) && ((strEndg == (strText.length - 1)) && (strEndg != strStartg)) && ((strEndl > strStartl) && (strEndg > strStartg)))
    strReturnValue = strText.substring((strStartg + 1),strEndl);
  return strReturnValue;
}

//checks if the browser is Internet Explorer 5 and up or Netscape 7 and up (Luke Frost: 19-Sep-2003)
function browsercheck(intOption)
{
  var strAgent = navigator.userAgent.toLowerCase();
  var bolNetscape = ((navigator.vendor) && ((navigator.vendor == "Netscape6") || (navigator.vendor == "Netscape")) && (strAgent.indexOf("mozilla") != -1) && (strAgent.indexOf("spoofer") == -1) && (strAgent.indexOf("compatible") == -1) && (strAgent.indexOf("opera") == -1) && (strAgent.indexOf("webtv") == -1) && (strAgent.indexOf("hotjava") == -1));
  var IEVer = strAgent.indexOf('msie');
  var bolIE = ((IEVer != -1) && (strAgent.indexOf("opera") == -1));
  var fltVersion = 0;

  if(!bolIE)
  {
    if(!bolNetscape)
    {
      window.location.replace('incorrectbrowser.html')      
    }
    else
    {
      var bolNetscape7Up = (parseInt(navigator.vendorSub) >= 7);
      fltVersion = parseFloat(navigator.vendorSub);
      if(!bolNetscape7Up)
        window.location.replace('incorrectbrowser.html')
    }
  }
  else
  {
    fltVersion = parseFloat(strAgent.substring(IEVer+5,strAgent.indexOf(';',IEVer)));
    var bolIE5Up = (fltVersion >= 5)
    if(!bolIE5Up)
        window.location.replace('incorrectbrowser.html')
  }

  if(intOption == 1)
  {
    if(bolNetscape7Up)
    {
      document.write("Your Browser has been detected as Netscape Version " + fltVersion);
      document.write("<br>Some functions of this site will not work in Netscape.");
      document.write("<br>For full Functionality, Please use Internet Explorer 5 or Up.");
    }
  }
}

// trims leading and trailing spaces (Frank Thomsen: 16-Sep-2003)
function trim(sLine)
{
    //alert("Trim Function");
    // if sLine has characters remove spaces.
    if(sLine.length > 0)
    {
        // remove leading spaces
        while(sLine.length != 0 && sLine.charAt(0) == " ")
            sLine = sLine.replace(" ", "");
        
 
        // remove trailing spaces
        while(sLine.length != 0 && sLine.charAt(sLine.length - 1) == " ")
            sLine = sLine.substring(0, sLine.length - 1);
    }
    // return trimed string
    return sLine;
}

// tests to see if a passed string is numerical (Frank Thomsen: 30-Sep-2003)
function isNum(strNum)
{
    //alert("isNum function");
    var numTest = /\d|\ |\./;
    var flag = true;
    for(var i = 0; i < strNum.length; i++)
    {
        if(numTest.test(strNum.charAt(i)) == false)
            flag = false;        
    }
    
    return flag;
}

// tests to see of a passed date is a valid date entry (Frank Thomsen: 14-Oct-2003)
function isDate(strDay, strMonth, strYear)
{
    var dateTest = /^\d\d\/\d\d\/\d{4}$/;
    var flag = true;
    var strDate = strDay +"/"+ strMonth +"/"+ strYear;
    
    if(!isNum(strDay))
    {
        flag = false;
    }
    else if(!isNum(strMonth))
    {
        flag = false;
    }
    else if(!isNum(strYear))
    {
        flag = false;
    }
    else if(!dateTest.test(strDate))
    {
        flag = false;
    }
        
    return flag;
}

// tests 2 passed date strings (Frank Thomsen: 15-Oct-2003)
// returns true if date1 is before date2 or false if after date2
function testDate(strDate1, strDate2)
{
   var date1 = new Date(strDate1);
   var date2 = new Date(strDate2);
   flag = false;
   
   if(date1 < date2)
       flag = true;
   
   return flag;
}

// formats a numerical value to two decimal places (Frank Thomsen: 11-Oct-2003)
function frmtCurrency(fltNum)
{
    var strNum = fltNum + "";
    var strParts = strNum.split(".");
    
    if(strParts.length > 1)
    {
        switch(strParts[1].length)
        {
            case 1:
                strParts[1] = strParts[1] + "0"; break;
            case 2:
                break;
            default:
                strParts[1] = strParts[1].substring(0, 1);
        }
    }
    else
    {
        strParts[1] = "00";
    }
    
    return strParts[0] + "." + strParts[1];
}

function checkSingleDate(strDay, strMonth, strYear)
{
  var strReturn = "correct";
 
  if(strDay != "" && strMonth != "" && strYear == "")
    strReturn = "\nYear cannot be blank";
  else if(strDay != "" && strMonth == "" && strYear == "")
    strReturn = "\nMonth and Year cannot be blank";
  else if(strDay == "" && strMonth == "" && strYear != "")
    strReturn = "\nDay and Month cannot be blank";
  else if(strDay == "" && strMonth != "" && strYear != "")
    strReturn = "\nDay cannot be blank";
  else if(strDay != "" && strMonth == "" && strYear != "")
    strReturn = "Invalid Date.\nMonth cannot be blank";
  else if(strDay == "" && strMonth != "" && strYear == "")
    strReturn = "\nDay and Year cannot be blank";
  else if(!isNum(strDay))
    strReturn = "\nDay must be a number";
  else if(parseInt(strDay) > 31 || parseInt(strDay) < 1)
    strReturn = "\nDay entry must be between 1 and 31 inclusive.";
  else if(!isNum(strMonth))
    strReturn = "\nMonth must be a number";
  else if(parseInt(strMonth) > 12 || parseInt(strMonth) < 1)
    strReturn = "\nMonth entry must be between 1 and 12 inclusive.";
  else if(!isNum(strYear))
    strReturn = "\nYear must be a number";
  else if(((strYear % 4) != 0) && (strMonth == 2) && (strDay >= 29))
    strReturn = "\nFebuary has only 28 days in " + strYear;
  else if(((strYear % 4) == 0) && (strMonth == 2) && (strDay > 29))
    strReturn = "\nFebuary has only 29 days in " + strYear;
  else if((strMonth == 4 || strMonth == 6 || strMonth == 9 || strMonth == 11) && strDay == 31)
    strReturn = "\nMonth " + strMonth + " does not have 31 days";

  return strReturn;
}

function checkTwoDate(strSDay, strSMonth, strSYear, strEDay, strEMonth, strEYear)
{
  var strReturn = "correct";
  if(strSDay != "" && strSMonth != "" && strSYear == "")
    strReturn = "Invalid Start Date.\nYear cannot be blank";
  else if(strSDay != "" && strSMonth == "" && strSYear == "")
    strReturn = "Invalid Start Date.\nMonth and Year cannot be blank";
  else if(strSDay == "" && strSMonth == "" && strSYear != "")
    strReturn = "Invalid Start Date.\nDay and Month cannot be blank";
  else if(strSDay == "" && strSMonth != "" && strSYear != "")
    strReturn = "Invalid Start Date.\nDay cannot be blank";
  else if(strSDay != "" && strSMonth == "" && strSYear != "")
    strReturn = "Invalid Start Date.\nMonth cannot be blank";
  else if(strSDay == "" && strSMonth != "" && strSYear == "")
    strReturn = "Invalid Start Date.\nDay and Year cannot be blank";
  else if(!isNum(strSDay))
    strReturn = "Invalid Start Date.\nDay must be a number";
  else if(parseInt(strSDay) > 31 || parseInt(strSDay) < 1)
    strReturn = "Invalid Start Date.\nDay entry must be between 1 and 31 inclusive.";
  else if(!isNum(strSMonth))
    strReturn = "Invalid Start Date.\nMonth must be a number";
  else if(parseInt(strSMonth) > 12 || parseInt(strSMonth) < 1)
    strReturn = "Invalid Start Date.\nMonth entry must be between 1 and 12 inclusive.";
  else if(!isNum(strSYear))
    strReturn = "Invalid Start Date.\nYear must be a number";
  else if(((strSYear % 4) != 0) && (strSMonth == 2) && (strSDay >= 29))
    strReturn = "Invalid Start Date\nFebuary has only 28 days in " + strSYear;
  else if(((strSYear % 4) == 0) && (strSMonth == 2) && (strSDay > 29))
    strReturn = "Invalid Start Date\nFebuary has only 29 days in " + strSYear;
  else if((strSMonth == 4 || strSMonth == 6 || strSMonth == 9 || strSMonth == 11) && strSDay == 31)
    strReturn = "Invalid Start Date.\nMonth " + strSMonth + " does not have 31 days";
  else if(strEDay != "" && strEMonth != "" && strEYear == "")
    strReturn = "Invalid End Date.\nYear cannot be blank";
  else if(strEDay != "" && strEMonth == "" && strEYear == "")
    strReturn = "Invalid End Date.\nMonth and Year cannot be blank";
  else if(strEDay == "" && strEMonth == "" && strEYear != "")
    strReturn = "Invalid End Date.\nDay and Month cannot be blank";
  else if(strEDay == "" && strEMonth != "" && strEYear != "")
    strReturn = "Invalid End Date.\nDay cannot be blank";
  else if(strEDay != "" && strEMonth == "" && strEYear != "")
    strReturn = "Invalid End Date.\nMonth cannot be blank";
  else if(strEDay == "" && strEMonth != "" && strEYear == "")
    strReturn = "Invalid End Date.\nDay and Year cannot be blank";
  else if(!isNum(strEDay))
    strReturn = "Invalid End Date.\nDay must be a number";
  else if(parseInt(strEDay) > 31 || parseInt(strEDay) < 1)
    strReturn = "Invalid End Date.\nDay entry must be between 1 and 31 inclusive.";
  else if(!isNum(strEMonth))
    strReturn = "Invalid End Date.\nMonth must be a number";
  else if(parseInt(strEMonth) > 12 || parseInt(strEMonth) < 1)
    strReturn = "Invalid End Date.\nMonth entry must be between 1 and 12 inclusive.";
  else if(!isNum(strEYear))
    strReturn = "Invalid End Date.\nYear must be a number";
  else if(((strEYear % 4) != 0) && (strEMonth == 2) && (strEDay >= 29))
    strReturn = "Invalid End Date\nFebuary has only 28 days in " + strSYear;
  else if(((strEYear % 4) == 0) && (strEMonth == 2) && (strEDay > 29))
    strReturn = "Invalid End Date\nFebuary has only 29 days in " + strEYear;
  else if((strEMonth == 4 || strEMonth == 6 || strEMonth == 9 || strEMonth == 11) && strEDay == 31)
    strReturn = "Invalid End Date.\nMonth " + strEMonth + " does not have 31 days";
  else
  {
    var strSDate = new Date(strSYear + "/" + strSMonth + "/" + strSDay);
    var strEDate = new Date(strEYear + "/" + strEMonth + "/" + strEDay);
    var intOneDay = 1000*60*60*24
    if(Math.ceil((strEDate.getTime()-strSDate.getTime())/(intOneDay)) <= 0)
      strReturn = "Start Date must be before End Date";
  }

  return strReturn;
}