// JavaScript Document

<!--
var ie5 = (document.getElementById && document.all);
var ns6 = (document.getElementById && !document.all);

var alpha = "abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ";
var numeric = "1234567890";
var dateMsg = "";
var dtCh= "/";
var minYear=1900;
var maxYear=2100;



/**
// -----------------------------------------------------------------------------------------------------------
//   TEMPLATE FOR VALIDATION FUNCTIONS
// -----------------------------------------------------------------------------------------------------------

function validateFunctionTemplate(normalColour, errorColour) {
	var msg = 'Please correct the following errors:\n';
	msg += '-------------------------------------------\n\n';
	
	var ok = true;
	
	// do this for every form element you are validating
	setBGColor("!!yourElementNameHere!!",normalColour);
	
	// use the functions listed below to check your form elements
	if (!isThere("!!yourElementNameHere!!")) {
		ok = false;
		msg += "Please enter yourElementNameHere\n";
		setBGColor("!!yourElementNameHere!!",errorColour);
	}


	// if ok submit, it not display the errors
	if (!ok) {
		alert(msg);
	} else {
		document.!!yourFormNameHere!!.submit();
	}		

}
**/


// -----------------------------------------------------------------------------------------------------------
// form validation functions
// -----------------------------------------------------------------------------------------------------------
function getObj(n, d) { 
  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=getObj(n,d.layers[i].document);
	}
  if(!x && d.getElementById) {
		x=d.getElementById(n); 
	}
	return x;
}
// -----------------------------------------------------------------------------------------------------------
// checkes that a value has been entered
// -----------------------------------------------------------------------------------------------------------
function isThere(elementName) {
	var element = getObj(elementName);
	if (element.value == "") {
		return false;
	} else {
		return true;
	}
}

// -----------------------------------------------------------------------------------------------------------
// sets the background colour of an element
// -----------------------------------------------------------------------------------------------------------

function setBGColor(elementName, colour) {
	element = getObj(elementName);
	try {
		element.style.backgroundColor = colour;
	} catch (e) {
		alert(e);
	}
}

// -----------------------------------------------------------------------------------------------------------
// checks that a value has been entered and that it follows an email format.
// -----------------------------------------------------------------------------------------------------------
function emailCheck(elementName) 
{
	var email = getObj(elementName).value;
	invalidChars = " /:,;"

	if (email == "") {
		return false;
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false;
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
		return false;
	}
	if (email.indexOf("@",atPos+1) > -1) {
		return false;
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
		return false;
	}
	if (periodPos+3 > email.length)	{
		return false;
	}
	return true;
}


// -----------------------------------------------------------------------------------------------------------
// checkes that a value has been entered
// -----------------------------------------------------------------------------------------------------------
function isThere(elementName) {
	var element = getObj(elementName);
	if (element.value == "") {
		return false;
	} else {
		return true;
	}
}

// -----------------------------------------------------------------------------------------------------------
// sets the background colour of an element
// -----------------------------------------------------------------------------------------------------------

function setBGColor(elementName, colour) {
	element = getObj(elementName);
	try {
		element.style.backgroundColor = colour;
	} catch (e) {
		alert(e);
	}
}

// -----------------------------------------------------------------------------------------------------------
// check a form elements length agains the entered value
// -----------------------------------------------------------------------------------------------------------
function checkLength(elementName, length) {
	var element = getObj(elementName);
	if (element.value.length < length) {
		return false;
	} else {
		return true;
	}
}

// -----------------------------------------------------------------------------------------------------------
// checkes to see if a select drop box matches a particular value
// -----------------------------------------------------------------------------------------------------------
function selectMatches(elementName, value) {
	var element = getObj(elementName);
	var elementValue = element.options[element.selectedIndex].value;
	if (elementValue == value) {
		return true;
	} else {
		return false;
	}
}

// -----------------------------------------------------------------------------------------------------------
// checkes to see if a value has been entered and that it is numeric
// -----------------------------------------------------------------------------------------------------------
function isNumeric(elementName) {
	var element = getObj(elementName);
	var strString = element.value;
	if (strString == "") {
		return false;
	}
  var strValidChars = "0123456789.";
  var strChar;
  var blnResult = true;

  if (strString.length == 0) return false;

  //  test strString consists of valid characters listed above
  for (i = 0; i < strString.length && blnResult == true; i++)
     {
     strChar = strString.charAt(i);
     if (strValidChars.indexOf(strChar) == -1)
        {
        blnResult = false;
        }
     }
  return blnResult;

}

// -----------------------------------------------------------------------------------------------------------
// checkes to see if a value has been entered and that it matches a credit card (can include spaces)
// -----------------------------------------------------------------------------------------------------------
function isCC(elementName) {
	var element = getObj(elementName);
	var strString = element.value;
	if (strString == "") {
		return false;
	}
  var strValidChars = "0123456789 ";
  var strChar;
  var blnResult = true;

  if (strString.length == 0) return false;

  //  test strString consists of valid characters listed above
  for (i = 0; i < strString.length && blnResult == true; i++)
     {
     strChar = strString.charAt(i);
     if (strValidChars.indexOf(strChar) == -1)
        {
        blnResult = false;
        }
     }
  return blnResult;

}

// -----------------------------------------------------------------------------------------------------------
// checkes to see if a value has been entered and that it matches a phone number
// does not do format checking, only checks that the characters entered are
// valid for a phone number
// -----------------------------------------------------------------------------------------------------------
function isPhoneNumber(elementName) {
	var element = getObj(elementName);
	var strString = element.value;
	if (strString == "") {
		return false;
	}
  var strValidChars = "0123456789 ()+";
  var strChar;
  var blnResult = true;

  if (strString.length == 0) return false;

  //  test strString consists of valid characters listed above
  for (i = 0; i < strString.length && blnResult == true; i++)
     {
     strChar = strString.charAt(i);
     if (strValidChars.indexOf(strChar) == -1)
        {
        blnResult = false;
        }
     }
  return blnResult;

}

// -----------------------------------------------------------------------------------------------------------
// checks if two elements values match
// -----------------------------------------------------------------------------------------------------------
function valuesMatch(element1, element2) {
	var e1 = getObj(element1);
	var e2 = getObj(element2);
	if (e1.value == e2.value) {
		return true;
	} else {
		return false;
	}
}

// -----------------------------------------------------------------------------------------------------------
// checks that a value has been entered and that it follows an email format.
// -----------------------------------------------------------------------------------------------------------
function emailCheck(elementName) 
{
	var email = getObj(elementName).value;
	invalidChars = " /:,;"

	if (email == "") {
		return false;
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false;
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
		return false;
	}
	if (email.indexOf("@",atPos+1) > -1) {
		return false;
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
		return false;
	}
	//if (periodPos+3 > email.length)	{
		//return false;
	//}
	return true;
}

// -----------------------------------------------------------------------------------------------------------
// checks that a value has been entered and that it is a valid date
// -----------------------------------------------------------------------------------------------------------

function isDate(dtStr){
	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){
		dateMsg = "The date format should be : mm/dd/yyyy";
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		dateMsg = "Please enter a valid month";
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		dateMsg = "Please enter a valid day";
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		dateMsg = "Please enter a valid 4 digit year between "+minYear+" and "+maxYear;
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		dateMsg = "Please enter a valid date"
		return false;
	}
	return true;
}

// -----------------------------------------------------------------------------------------------------------
// Utility function for isDate()
// -----------------------------------------------------------------------------------------------------------

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;
}

// -----------------------------------------------------------------------------------------------------------
// Utility function for isDate()
// -----------------------------------------------------------------------------------------------------------

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;
}

// -----------------------------------------------------------------------------------------------------------
// Utility function for isDate()
// -----------------------------------------------------------------------------------------------------------

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
}

// -----------------------------------------------------------------------------------------------------------
// Other functions
// -----------------------------------------------------------------------------------------------------------


// -----------------------------------------------------------------------------------------------------------
// formats a number to a particular number of decimals
// -----------------------------------------------------------------------------------------------------------
function formatNumber(expr, decplaces) {
	var str = "" + Math.round(eval(expr) * Math.pow(10, decplaces));
	while (str.length <= decplaces)
	{
		str += "0";
	}

	var decpoint = str.length - decplaces;

	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}

function showhide(qid) {
	for (var x=1; x <= 50; x++) {
	
		if (getObj('answer-' + x) != null) {
			getObj('answer-' + x).style.display = 'none';
		}
	}
	getObj('answer-' + qid).style.display = 'block';
}



function IsDropSelected(name) {
	var objDrop=getObj(name);
	if (objDrop.selectedIndex==0) {
		return false;
	} else {
		return true;
	}
}

function typeit(){
	getObj('typing').insertAdjacentText("beforeEnd",". ")
	setTimeout("typeit()",100)
}

function golink() {
	var sel = getObj('quicklinks').options[getObj('quicklinks').selectedIndex].value;
	window.document.location = sel;
}

function displaydatetime() {
	dateVar = new Date();
	thisday = dateVar.getDate();
	thismonth = getCalendarMonth(dateVar.getMonth());
	thisyear = dateVar.getFullYear();
	thishrs = dateVar.getHours();
	thismins = String(dateVar.getMinutes());
	
	if (thismins.length < 2) {
		thismins = '0' + thismins;
	}
	
	document.write(thisday + ' ' + thismonth + ' ' + thisyear + ' ' + thishrs + ':' + thismins);
	
	function getCalendarMonth(monthNum) {
			
		var moy = new Array(12)
		moy[0] = "January" 
		moy[1] = "February" 
		moy[2] = "March" 
		moy[3] = "April" 
		moy[4] = "May" 
		moy[5] = "June" 
		moy[6] = "July" 
		moy[7] = "August" 
		moy[8] = "September" 
		moy[9] = "October" 
		moy[10] = "November" 
		moy[11] = "December" 
		return moy[monthNum] 
	}
}

function openWindow(theURL, winName, features) {
	newWin=window.open(theURL, winName, features);
	newWin.originalWindow=window; // keep a reference to this window
}

function setBGColour(element, colour){

	element.style.backgroundColor = colour;

}



function LimitNumericValue(strName,intLimit) {
	var i;
	var thisObj=getObj(strName);
	var strText=thisObj.value;
	var strFinal='';
	var flagError=false;
	window.status=strText;
    for (i = 0; i < strText.length; i++){   

        var c = strText.charAt(i);
        if (((c < "0") || (c > "9"))) {
			flagError=true;
		} else {
			strFinal+=c;
		}
    }
	var intActualValue=Number(strFinal);
	if (intActualValue>intLimit) { 
		intActualValue=intLimit;
		flagError=true;
	}
	if (flagError==true) {
		thisObj.value=intActualValue;
	}
    return true;
}


function popupWin(width, height, url)
{

	var intScWidth,intScHeight,intXPos,intYPos;
	
	intScWidth = screen.availWidth;
	intScHeight = screen.availHeight;
	
	intXPos = ((intScWidth - width) / 2);
	intYPos = ((intScHeight - height) / 2);

	var features = "height="+height+",width="+width+",screenX=" + intXPos + ",screenY=" + intYPos + ",left=" + intXPos + ",top=" + intYPos + ",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes";
	window.open(url, null, features);
}

/*****************************************************************
******************************************************************
 Website specific function
******************************************************************
*****************************************************************/

// Send to a friend form
function validateSendToFriend()	{
	var blnCanSubmit = true;
	var strMsg = 'Please correct the following...\n---------------------------------------\n';

	var friend_name = document.getElementById('friend_name');
	var friend_email= document.getElementById('friend_email');
	var your_name = document.getElementById('your_name');
	var your_email= document.getElementById('your_email');

	var strPleaseCorrectColour;
	var strOKColour;
	
	strPleaseCorrectColour = '#B3B3B3';
	strOKColour = '#FFFFFF';	

	/*
	setBGColour(frmTitle,strOKColour);
	if (frmTitle.value == 0) {
		setBGColour(frmTitle,strPleaseCorrectColour);
		blnCanSubmit = false;
		strMsg += "Please select your Title \n";
	}
	*/

	setBGColour(friend_name,strOKColour);
	if(friend_name.value == ''){
		setBGColour(friend_name,strPleaseCorrectColour);
		blnCanSubmit = false;
		strMsg += 'Please enter the recipient name.\n';
	}	

	setBGColour(friend_email,strOKColour);
	if(!emailCheck("friend_email")){
		setBGColour(friend_email,strPleaseCorrectColour);
		blnCanSubmit = false;
		strMsg += 'Please enter a valid email address for the recipient.\n';
	}	
	
	setBGColour(your_name,strOKColour);
	if(your_name.value == ''){
		setBGColour(your_name,strPleaseCorrectColour);
		blnCanSubmit = false;
		strMsg += 'Please enter your name.\n';
	}			
	
	setBGColour(your_email,strOKColour);
	if(!emailCheck("your_email")){
		setBGColour(your_email,strPleaseCorrectColour);
		blnCanSubmit = false;
		strMsg += 'Please enter a valid email address for your own email address.\n';
	}	
	
	/*
	if(document.refer_page.message.value == ''){
		blnCanSubmit = false;
		strMsg += 'Please enter a message.\n';
	}
	*/		

	if(blnCanSubmit == false){
		alert(strMsg);
		return false;
	}else{
		document.sendToFriend.submit();
	}

} 


// -->


