﻿//------------------------------------------------------------------------------------------------------------------
//Rollover
//------------------------------------------------------------------------------------------------------------------
function ShowImg(pstrImgID, pstrImgName) {
	var objImg = document.getElementById(pstrImgID)
	
	objImg.src = 'images/' + pstrImgName;
}

//------------------------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------------------------
//Center the screen
//------------------------------------------------------------------------------------------------------------------
var intContentWidth = 1024;	
var intContentHeight = 768;	
var intBrowserWidth = 0; 
var intBrowserHeight = 0;

function PositionGetBrowserSize(){
     if (typeof window.innerWidth != 'undefined')
     {
          intBrowserWidth = window.innerWidth,
          intBrowserHeight = window.innerHeight
     }
     
    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

     else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
     {
           intBrowserWidth = document.documentElement.clientWidth,
           intBrowserHeight = document.documentElement.clientHeight
     }
     
     // older versions of IE
     
     else
     {
           intBrowserWidth = document.getElementsByTagName('body')[0].clientWidth,
           intBrowserHeight = document.getElementsByTagName('body')[0].clientHeight
     }


}

function PositionGetLeftAlignment(){
	var intLeft = ((intBrowserWidth/2)-(intContentWidth/2))
	if(intLeft < 0) intLeft = 0;
	return intLeft;
}

function PositionGetTopAlignment(){
	var intTop = (intBrowserHeight/2)-(intContentHeight/2);
	if(intTop < 0) intTop = 0;
	return intTop
}

function PositionResize(){

	PositionGetBrowserSize();
	var theDivStyle = document.getElementById('SiteContent').style;

    if (getBrowserName() == 'Internet Explorer') {
	    theDivStyle.left = PositionGetLeftAlignment();
	    theDivStyle.top = PositionGetTopAlignment();
    } else {
	    theDivStyle.left = PositionGetLeftAlignment() + 'px';
	    theDivStyle.top = PositionGetTopAlignment() + 'px';
	}
}


//------------------------------------------------------------------------------------------------------------------


//------------------------------------------------------------------------------------------------------------------
// Function pops up a blank window with no url to be used as the submission target of the forms below
//------------------------------------------------------------------------------------------------------------------
function ShowPopup(name, width, height, pstrPageName){
	pop = window.open(pstrPageName, name, "resizable=no,scrollbars=yes, toolbar=no, titlebar=0, width="+width+",height="+height);
	pop.focus();
}

function ShowPopupNoScrollBar(name, width, height, pstrPageName){
	pop = window.open(pstrPageName, name, "resizable=no,scrollbars=no, toolbar=no, titlebar=0, width="+width+",height="+height);
	pop.focus();
}
//------------------------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------------------------
//Left and Right Functions
//------------------------------------------------------------------------------------------------------------------
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
//------------------------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------------------------
//Get the Browser Name
//------------------------------------------------------------------------------------------------------------------
	var detect = navigator.userAgent.toLowerCase();
var thestring, place;
		
function getBrowserName () {
	var OS,browser,version;
			
	if (checkString('konqueror'))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkString('safari')) browser = "Safari"
	else if (checkString('omniweb')) browser = "OmniWeb"
	else if (checkString('opera')) browser = "Opera"
	else if (checkString('webtv')) browser = "WebTV";
	else if (checkString('icab')) browser = "iCab"
	else if (checkString('msie')) browser = "Internet Explorer"
	else if (!checkString('compatible'))
	{
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";
			
	if (!version) version = detect.charAt(place + thestring.length);

	if (!OS)
	{
		if (checkString('linux')) OS = "Linux";
		else if (checkString('x11')) OS = "Unix";
		else if (checkString('mac')) OS = "Mac"
		else if (checkString('win')) OS = "Windows"
		else OS = "an unknown operating system";
	}
			
	return browser;
}
		
function checkString(string)
{			
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
//------------------------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------------------------
//Get and display the current server time
//------------------------------------------------------------------------------------------------------------------
var clockID = 0;
		
function padText(pstrText, pintLength, pstrChar, pblnPadAtFront) {
	var i = 0;
	var intCharsToAdd = 0;
			
	intCharsToAdd = pintLength - String(pstrText).length;
			
	for (i=0; i<intCharsToAdd; i++)	 {
		if(pblnPadAtFront) {
			pstrText = pstrChar + pstrText;
		} else {
			pstrText = pstrText + pstrChar;
		}
	}

	return pstrText;
}

function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }

   var tDate = new Date();

   document.theClock.AYClock.value = Date(tDate);
		   
   clockID = setTimeout("UpdateClock()", 1000);
}
		
function StartClock() {
   clockID = setTimeout("UpdateClock()", 500);
}
		
function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}
//------------------------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------------------------
//Trim function
//------------------------------------------------------------------------------------------------------------------
function trimAll(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
//------------------------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------------------------
//Check Email function
//------------------------------------------------------------------------------------------------------------------
function isValidEmail(pstrEmail){
	 var filter=/^.+@.+\..{2,3}$/
	
	 if (filter.test(pstrEmail))
	    return true
	 else {
		return false
	}
}
//------------------------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------------------------
//Check if a text field is numeric
//------------------------------------------------------------------------------------------------------------------
function isNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	var i;
	
	for (i = 0; i < sText.length; i++) { 
	   Char = sText.charAt(i); 

	   if (ValidChars.indexOf(Char) == -1) {
	      return false;
	   }
	}
	return true; 
}
//------------------------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------------------------//
//See if a date is valid
//------------------------------------------------------------------------------------------------------------------
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
    var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
   for (var i = 1; i <= n; i++) {
	this[i] = 31
	if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
	if (i==2) {this[i] = 29}
   } 
   return this
}


function isDate(dtStr, strFieldName){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)

	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)

	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format for the " + strFieldName + " field should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month for the " + strFieldName + " field")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day for the " + strFieldName + " field")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear + " for the " + strFieldName + " field")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date for the " + strFieldName + " field")
		return false
	}
return true
}//------------------------------------------------------------------------------------------------------------------//

