
rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
        rnd.seed = (rnd.seed*9301+49297) % 233280;
        return rnd.seed/(233280.0);
};

function rand(number) {
        return Math.ceil(rnd()*number);
};

//START RANDOM IMAGE
var currentdate = 0
var core = 0

function StringArray (n) {
  this.length = n;
  for (var i =1; i <= n; i++) {
    this[i] = ' '

  }
}

image = new StringArray(10)
image[0] = 'wideimage3.jpg'
image[1] = 'wideimage7.jpg'
image[2] = 'wideimage8.jpg'
image[3] = 'wideimage9.jpg'
image[4] = 'wideimage10.jpg'
image[5] = 'wideimage11.jpg'
image[6] = 'wideimage15.jpg'
image[7] = 'wideimage16.jpg'
image[8] = 'wideimage17.jpg'
image[9] = 'wideimage18.jpg'
image[10] = 'wideimage21.jpg'
image[11] = 'wideimage22.jpg'
image[12] = 'wideimage23.jpg'
image[13] = 'wideimage27.jpg'
image[14] = 'wideimage28.jpg'
image[15] = 'wideimage29.jpg'
image[16] = 'wideimage31.jpg'

var ran = 60/image.length

function ranimage() {
  currentdate = new Date()
  core = currentdate.getSeconds()
  core = Math.floor(core/ran)
    return(image[core])
}

///END RANDOM IMAGE

///////////////////////
////pager functions////
///////////////////////

//submit pager form
function submit_pager(page){
	
	document.pager_form.page.value = page;
	document.pager_form.submit();
}

///////////////////////

///////////////////////
////data validation////
///////////////////////

//validate email format
function isEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
		return true;
	}
	else {
		return false;
	}
}
/////////////////////////////

//validate change password
function validate_change_pass(){
	
	if (document.change_pass.new_pass.value==""){
		alert("New password required");
		document.change_pass.new_pass.focus();
		return false;
	}
	else if (document.change_pass.new_pass_again.value==""){
		alert("Confirm password required");
		document.change_pass.new_pass_again.focus();
		return false;
	}
	else if (document.change_pass.new_pass_again.value !=  document.change_pass.new_pass.value){
		alert("New Password and New Password Again do not match");
		document.change_pass.new_pass.focus();
		return false;
	}

	return true;
}
//////////////////////////

//validate staff
function validate_staff() {


	if (document.update_staff.last_name.value==""){
		alert("Last Name required");
		document.update_staff.last_name.focus();
		return false;
	}

	if (document.update_staff.email.value==""){
		alert("Please enter e-mail address ...");
		document.update_staff.email.focus();
		return false;
	} else {
		return isStaffReady();
	}
	
	return true;

}		 
function isStaffReady() {
	if (isEmail(document.update_staff.email.value) == false) {
		alert("Please enter a valid email address");
		document.update_staff.email.focus();
		return false;
	}
	return true;
}
/////////////////////////////

//validate hlc
function validate_hlc() {

	if (document.add_hlc.name.value==""){
		alert("HLC name required");
		document.add_hlc.name.focus();
		return false;
	}
	if (document.add_hlc.address.value==""){
		alert("HLC address required");
		document.add_hlc.address.focus();
		return false;
	}
	if (document.add_hlc.postcode.value==""){
		alert("HLC postcode required");
		document.add_hlc.postcode.focus();
		return false;
	}
	else if (document.add_hlc.postcode.value.length < 6 || document.add_hlc.postcode.value.length > 8){ //Code length rule
  		alert(document.add_hlc.postcode.value + " is not a valid postcode - wrong length");
  		document.add_hlc.postcode.focus();
  		return false;
  	}
	else if (!(isNaN(document.add_hlc.postcode.value.charAt(0)))){ //leftmost character must be alpha character rule
   		alert(document.add_hlc.postcode.value + " is not a valid postcode - cannot start with a number");
   		document.add_hlc.postcode.focus();
   		return false;
  	}
	else if (isNaN(document.add_hlc.postcode.value.charAt(document.add_hlc.postcode.value.length-3))){ //first character of inward code must be numeric rule
   		alert(document.add_hlc.postcode.value + " is not a valid postcode - alpha character in wrong position");
   		document.add_hlc.postcode.focus();
   		return false;
  	}
 	else if (!(isNaN(document.add_hlc.postcode.value.charAt(document.add_hlc.postcode.value.length-2)))){ //second character of inward code must be alpha rule
   		alert(document.add_hlc.postcode.value + " is not a valid postcode - number in wrong position");
   		document.add_hlc.postcode.focus();
   		return false;
  	}
 	else if (!(isNaN(document.add_hlc.postcode.value.charAt(document.add_hlc.postcode.value.length-1)))){ //third character of inward code must be alpha rule
   		alert(document.add_hlc.postcode.value + " is not a valid postcode - number in wrong position");
   		document.add_hlc.postcode.focus();
   		return false;
  	}
 	else if (!(document.add_hlc.postcode.value.charAt(document.add_hlc.postcode.value.length-4) == " ")){//space in position length-3 rule
   		alert(document.add_hlc.postcode.value + " is not a valid postcode - no space or space in wrong position");
   		document.add_hlc.postcode.focus();
   		return false;
   	}
 	count1 = document.add_hlc.postcode.value.indexOf(" ");
	count2 = document.add_hlc.postcode.value.lastIndexOf(" ");
 	if (count1 != count2){//only one space rule
   		alert(document.add_hlc.postcode.value + " is not a valid postcode - only one space allowed");
   		document.add_hlc.postcode.focus();
   		return false;
  	}

	return true;

}
///////////////////////////////////////

//validate public email form
function validate_send_email_public(){
	
	if (document.contact_email.subject.value==""){
		alert("Subject required");
		document.contact_email.subject.focus();
		return false;
	}
	else if (document.contact_email.name.value==""){
		alert("Your name is required");
		document.contact_email.name.focus();
		return false;
	}
	else if (document.contact_email.message.value==""){
		alert("Message required");
		document.contact_email.message.focus();
		return false;
	}

	if (document.contact_email.email.value==""){
		alert("Please enter e-mail address ...");
		document.contact_email.email.focus();
		return false;
	} else {
		return isContactReady();
	}

	return true;
}
//////////////////////////

function isContactReady() {
	if (isEmail(document.contact_email.email.value) == false) {
		alert("Please enter a valid email address");
		document.contact_email.email.focus();
		return false;
	}
	return true;
}

//validate email form
function validate_send_email(){
	
	if (document.contact_email.subject.value==""){
		alert("Subject required");
		document.contact_email.subject.focus();
		return false;
	}
	else if (document.contact_email.message.value==""){
		alert("Message required");
		document.contact_email.message.focus();
		return false;
	}

	return true;
}
//////////////////////////

//help popup window
function open_help(page){

	help_window = window.open("pop_help.php?page="+page, "help_win", "width=550,height=400,scrollbars=yes,toolbar=no,menubar=no,resizable=yes,left=0,top=0") 
	help_window.focus();

}