// JavaScript Document


/* customised version of the Macromedia OpenWindow Behaviour
This makes sure that the newly opened window is always 
at the front i.e focussed */

function MM_openBrWindow(theURL,winName,features) { //v2.0
  var newwin = window.open(theURL,winName,features);
  newwin.focus();
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {
	  if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
		document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; 
		}
	}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
	
MM_reloadPage(true);

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { 
		obj=obj.style; 
		v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
	}
    obj.visibility=v; }
}

function MM_findObj(n, d) { //v4.01
	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=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}



function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

/* ================================================ */



/* =========================================================================================================== */
/* Start of Popup calendar functions */

var monthArray = ["January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"];
var monthNumArray = ["01", "02", "03", "04", "05", "06", "07", "08", "09","10", "11", "12"];

var hilite = ''
var dateFieldObj , calDivObj



function ShowCalendarPopUp(dateFieldName,calendarDiv) {
		dateFieldObj 	= document.getElementById(dateFieldName);
		calDivObj 		= document.getElementById(calendarDiv);
		ShowCalendar(dateFieldObj.value)		
}


function HideCalendar(){
	if (calDivObj.style) {
		calDivObj.style.display = "none";
	}
	else {
		calDivObj.display = "none";
	}
}


function ShowCalendar(dateValue){

// if there is no date yet, make a new one. 
//Otherwise, use the date in the input box or the date passed by the next/previous buttons.

var currentDate = (dateValue == null || dateValue == "") ? new Date() : FormatDate(dateValue) ;

var prevYear = new Date(currentDate);
prevYear.setYear(currentDate.getFullYear()-1);

var prevMonth = new Date(currentDate);
prevMonth.setMonth(currentDate.getMonth()-1);

var nextMonth = new Date(currentDate);
nextMonth.setMonth(currentDate.getMonth()+1);

var nextYear = new Date(currentDate);
nextYear.setYear(currentDate.getFullYear()+1);

var currentYear 		= currentDate.getFullYear();
var currentMonth 		= currentDate.getMonth();
var currentDisplayDate 	= currentDate.getDate();

// shift the current day to day 1 to make calendar to build it from day 1.
var firstDay = new Date(currentDate);
firstDay.setDate(1);

var currentDay = new Date(firstDay);

// clear current calendar (if exists)
var calHTML = "";

// show calendar

if (calDivObj.style) {
	calDivObj.style.display = "block";
}
else {
	calDivObj.display = "block";
}


//================================================================
// Start of the Calendar table 
//================================================================
// write out calendar header
calHTML += '<table cellpadding="0" cellspacing="1" >';


//================================================================
// Start of the Close Calendar Row
// calHTML += '<tr class="calHead"><th colspan="7" align="right"><a href="javascript:HideCalendar();" title="Close"><img src="images/furniture/icon_close.gif" width="17" height="15" border="0" alt="Close"></a></th></tr>';
// End of the Close Calendar Row
//================================================================



//================================================================
// Start of the Month Row
calHTML += '<tr class="calHead">';

// This is the line that adds the << Previous Month link
calHTML += '<th colspan="2" align="left">&nbsp;<a href="" title="Previous Month" onclick="ShowCalendar(\''+FormatRawDate(prevMonth)+'\'); return false;">&lt;&lt;</a>&nbsp;';



// This is the line that adds the Current Month 
calHTML +=  '<th colspan="3" align="center">' +  monthArray[currentMonth] + '</th>' ;


// This is the line that adds the >> Next Month link
calHTML += '<th colspan="2" align="right">&nbsp;<a href="" title="Next Month" onclick="ShowCalendar(\''+FormatRawDate(nextMonth)+'\'); return false;">&gt;&gt;</a>&nbsp;</th> '


calHTML += '</tr>';
// End of the Month Row
//================================================================================


//================================================================================
// Start of the Year row 
calHTML += '<tr>';

// This is the line that adds the <<< Previous Year link
calHTML += '<th colspan="2" align="left">&nbsp;<a href="" title="Previous Year" onclick="ShowCalendar(\''+FormatRawDate(prevYear)+'\'); return false;">&lt;&lt;&lt;&nbsp;</a>';


// This is the line that adds the Current  Year 
calHTML += '<th colspan="3" align="center">' + currentYear + '</th>' ;


// This is the line that adds the >>> Next Year link
calHTML += '<th colspan="2" align="right">&nbsp;<a href="" title="Next Year" onclick="ShowCalendar(\''+FormatRawDate(nextYear)+'\'); return false;">&gt;&gt;&gt;</a>&nbsp;</th>'


calHTML += '</tr>';
// End of the Year Row
//================================================================================

	

//================================================================================
// Start of the Mo Tu We Th Fr row
calHTML += '<tr><th>Su</th><th>Mo</th><th>Tu</th><th>We</th><th>Th</th><th>Fr</th><th>Sa</th></tr>';

var curCell = 1;

// as long as we are in the current month, write out the calendar days
while(currentDay.getMonth() == firstDay.getMonth()) {
					
	// begin row
	calHTML += '<tr>';
	// iterate through each week
	for (var i=0; i<7; i++)
	{
//		calHTML += '<td>';
		// as long as this week is in the same month, write out days
		if ( currentDay.getMonth() == firstDay.getMonth() ) {
			
			if (currentDisplayDate == currentDay.getDate() ) {
				hilite = 'selectedOne' ;
			}
			else {
				hilite = '' ;
			}
			
	
			// if first day is not reached yet, write a blank
			if(curCell <= firstDay.getDay())
				{
				calHTML += '<td>&nbsp;</td>';
				}
			// otherwise write out the date
			else
				{
				calHTML += '<td><a class="' +hilite + '" href="" title="Click to choose date" onclick="SelectDate(' +  currentDay.getDate() + ',' + currentDay.getMonth() + ',' + currentDay.getFullYear() + '); return false;">' + currentDay.getDate() + '</a></td>';

				currentDay.setDate(currentDay.getDate() + 1);
				}
		}
		curCell++
	}
	calHTML += '</tr>';
}
// Start of the Mo Tu We Th Fr row
//================================================================================



calHTML += '</table>';
calDivObj.innerHTML = calHTML;
}


function SelectDate( selDay, selMo, selYear) {
	if (eval(selDay) < 10) { 
		selDay = "0" + selDay ;
	}
		
	// UK Date format  dd/mm/yyyy
	dateFieldObj.value = selDay + "/" + monthNumArray[selMo] + "/" +  selYear;

	if (calDivObj.style) {
		calDivObj.style.display = "none";
	}
	else {
		calDivObj.display = "none";
	}
	
}

function FormatDate(dateValue) {
// At this point all we have is a string like "28/02/2004" if UK format or "02/28/2004" if American format
// We must have a date object, so we make one based on the string date
// and return it to the main function
	var dateValArray = dateValue.split("/");

// new Date() takes argument yyyy/mm/dd
	var currentDate = new Date(dateValArray[2],dateValArray[1]-1,dateValArray[0]);
	return currentDate;
}

function FormatRawDate(rawDateValue) {
// The next/previous buttons have date object references. They need to be strings
// so we can send them to the function when the next/previous links are clicked.
// the string date is returned and placed into the link.
	var rawMonth = rawDateValue.getMonth()+1;
	var rawDay = rawDateValue.getDate();
	var rawYear = rawDateValue.getFullYear();
	
	// UK format dd/mm/yyyy
	var stringDate = rawDay + "/" + rawMonth + "/" +  rawYear;
	
	return stringDate;
}


/* End of Popup calendar functions */
/* =========================================================================================================== */







/* ================================================ */


//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

/* ================================================ */




/* ====================== AJAX =====================*/

/* This is the function that gets the Buildings, Floors, Rooms from the database and writes them to the page */

function ajaxGetStockists(){  

	var xmlHttp, theScript, theField, theSearch , args , urlString , theDIV;
	args = ajaxGetStockists.arguments ; 

	theSearch = args[0] ; 
	theDiv = args[1] ; 
	
	changeHTMLinner('Stockists in the ' + theSearch + ' region','pageheading_uk');
	
	try
	{    // Firefox, Opera 8.0+, Safari    
	xmlHttp=new XMLHttpRequest();    
	}
	catch (e){    // Internet Explorer    
		try {      
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		}
		catch (e) {      
			try {        
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
			}
			catch (e) {        
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange=function(theValue) {
		if(xmlHttp.readyState==4) {	
			if ((theDIV=MM_findObj(args[1]))!=null) {
//				theDIV = document.getElementById("stockist_list")		
				theDIV.innerHTML = xmlHttp.responseText;
				
								
	//			theDIV.className = "layer_visible" ; 
			}
		}
	}
	
	
	
/*	
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {	
			var theDIV ;
		
			if ((theDIV=MM_findObj("prefetchcontacts"))!=null) {
							alert(theDIV);

				var theSelect = theDIV.getElementsByTagName("select")	
				var theOptions = theSelect[0].getElementsByTagName("option")	
				
				for (i=0 ; i < theOptions.length ; i = i + 1 ) {
				
					if ( i%2) {
						theOptions[i].className = "rowstyle_odd";
					}
					else {
						theOptions[i].className = "rowstyle_even";
					}
					
					theOptions[i].setAttribute("colour",theOptions[i].className);
				
					theOptions[i].onmouseover = function() {
						window.status = this.innerHTML ;
						this.className = "row_hover"; // row_hover is a new highlight
					}
				
					theOptions[i].onmouseout = function() {
						this.className = this.getAttribute("colour");
					}
					
					theOptions[i].onclick = function() {
						theField.theValue  = this.innerHTML;
					}
				}
			}	
		}		
	}
	
*/	
	urlString = "stockists_find.asp?region=" + theSearch ;
	xmlHttp.open("GET",urlString,true);
    xmlHttp.send(null);
	
	return false ;
}

/*==================================================================================== */

/* ================================================ */
/* define the base url for the HTML editor page */

// var BaseURL = "../";

/* ================================================ */

function calculateIncome() {
/* three parameters passed in.  FIRST multiplied by  SECOND = THIRD */
	var first, second, third, obj, args=calculateIncome.arguments; 
	
	
	if (args.length == 3 ) {
		if (  ((first=MM_findObj(args[0]))!=null)  &&  ((second=MM_findObj(args[1]))!=null)  && ((third=MM_findObj(args[2]))!=null) )  { 

//		alert("about to do " + first.name  + " * " + second.name  + " = " + third.name )

			if  ( (first.value!=null) && (second.value!=null) ) { 
				third.value = (first.value * second.value) ;
			}
		}
	}
}


/* =================================================== */

function setField() {
//    theForm,[theField,theValue]  
	var theForm, theField, theValue,  i, args=setField.arguments;
		
	if ((theForm=MM_findObj(args[0]))!=null) {
		
		  for (i=1; i<(args.length-1); i+=2) {			 
			if ((theField=MM_findObj(args[i]))!= null) {
						theField.value=args[i+1];
			}
		  }
	}
}

/* =================================================== */

function checkAcademicEmail(theParam) {
/* 
This checks the email address to make sure that is does not contain 
any .ac.uk    or .edu addresses, which might not last when the student graduates.
It passes in 1 parameter1   theField 
*/  

	if ((  theParam.value.toLowerCase().indexOf(".ac.",1) > 3) ||  (theParam.value.toLowerCase().indexOf(".edu",1) > 3) ) {
//		theParam.value = "" ;
		theParam.focus();
		return true ; 	
	}
	else {
		return false;
	}
}


/* function showOther(theMenu) {
if (theMenu.options[theMenu.selectedIndex].value.toLowerCase() == "other") {
	MM_showHideLayers('selectother','','show') ;
	}
else {
	MM_showHideLayers('selectother','','hide') ;
	}
}
*/


function getImageSize(theImageArg,widthFieldArg,heightFieldArg,formNameArg) {
// Arguments are theImage Name, the Width Field Name and the height Field name 

var args	=	getImageSize.arguments
//if (args.length == 3 ) {
	var theImage 		= MM_findObj(theImageArg)
	var widthField 		= MM_findObj(widthFieldArg)
	var heightField 	= MM_findObj(heightFieldArg)
	
//	alert("widthField.value is '" + widthField + "'\nand image width is " +  theImage.width + "\nimage height is " + theImage.height)
	
	widthField.value = theImage.width ;

	heightField.value = theImage.height;

}


// This shows a preview of the picture to be included with the paragraph
// It also populates the width and height fields with the values taken 
// from the image.

function changePreview(field,imageObj,folder) { 
	if (field == "") { 
		imageObj.src = folder + "transpix.gif" ;
	}
	else {
		imageObj.src = folder + field ;
	}
}


/* ================================================================*/
/*  Dummy Stub functions that are later re-defined in google_maps.js */

function load() {
}

function showAddress() {
}

function GUnload() {
}

/* ================================================================*/


/* =============================================== */

//Powered by Softery.com
//Ver: 3//
function FlashSolver()
	{
	n=navigator;
	nav=n.appVersion.toLowerCase();
	if ((nav.indexOf('win')!=-1) || (nav.indexOf('nt')!=-1)) 
		{
		if (navigator.appName == "Microsoft Internet Explorer")
			{
			var tmpObject = document.getElementsByTagName('object');
			if (tmpObject && tmpObject.length) 
				{
				for (var i = 0; i < tmpObject.length; i++) 
					{
					if (tmpObject[i].getAttribute('classid').toLowerCase() == 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000') 
						{
						var ps = tmpObject[i].getElementsByTagName('param');
						if (ps && ps != null)
							{
							for (var j = 0; j < ps.length; j++) 
								{
								if (ps[j].getAttribute('name').toLowerCase() == 'flashvars') 
									{
									var variables = ps[j].getAttribute('value');
									break;
									}
								}
							}
						var obj = tmpObject[i].outerHTML + "\n";
						obj = obj.replace(/FLASHVARS" VALUE=""/i,'FLASHVARS" value="'+variables+'"');
						tmpObject[i].outerHTML = obj;
						}
					}
				tmpObject = null;
				}
			}
		}
	}
	
window.onunload = function()
	{
	n=navigator;
	nav=n.appVersion.toLowerCase();
	if ((nav.indexOf('win')!=-1) || (nav.indexOf('nt')!=-1)) 
		{
		if (navigator.appName == "Microsoft Internet Explorer")
			{
			if (document.getElementsByTagName) 
				{
				var tmpObject = document.getElementsByTagName("object"); 
				for (i=0; i<tmpObject.length; i++)
					{
					tmpObject[i].outerHTML = ""; 
					}
				}
			}
		}
	}


/* ====================================================================== */


function showOther() {
	var i,m,layer,args=showOther.arguments;

    for (i=0; i<(args.length-1); i=i+2) {
		m = args[i] ;
		layerToShow = args[i+1];
//		window.alert("about to show layer " + layerToShow + " or \nlayer_" + m.selectedIndex ) ;
		if (  layerToShow == "layer_" + m.selectedIndex ) { 
				MM_showHideLayers(layerToShow,'','show') ;
		}
		else {
				MM_showHideLayers(layerToShow,'','hide') ;
		}
	}
}


function setImageDimensions(fieldImg,theForm,theWidthField,theHeightField) {
	var is_ns6 = (!document.all && document.getElementById ? true : false);
	var img = (fieldImg && !is_ns6 ? fieldImg : this);
//	alert(" img.name is " +  img.name + "\nimg.width is " + img.width + "\nimg.hieght is " + img.height )
	
	if (img.width > 0 && img.height > 0) {

/* 
		if ((img.minWidth != '' && img.minWidth > img.width) || (img.minHeight != '' && img.minHeight > img.height)) {
			alert('Uploaded Image is too small!\nShould be at least ' + img.minWidth + ' x ' + img.minHeight);
			img.field.uploadOK = false;
			return;
		}
		if ((img.maxWidth != '' && img.width > img.maxWidth) || (img.maxHeight != '' && img.height > img.maxHeight)) {
			alert('Uploaded Image is too big!\nShould be max ' + img.maxWidth + ' x ' + img.maxHeight);
			img.field.uploadOK = false;
			return;
		}
		if (img.sizeLimit != '' && img.fileSize > img.sizeLimit) {
			alert('Uploaded Image File Size is too big!\nShould be max ' + (img.sizeLimit/1024) + ' KBytes');
			img.field.uploadOK = false;
			return;
		}
		
		if (img.saveWidth != '') {
			document.PU_uploadForm[img.saveWidth].value = img.width;
		}
		if (img.saveHeight != '') {
			document.PU_uploadForm[img.saveHeight].value = img.height;
		}
		img.field.uploadOK = true;
*/
				
		var theCommand 
		
		theCommand = "document." + theForm  + "." + theWidthField + ".value =" +  img.width ;
//		alert(theCommand);
		eval(theCommand);

		theCommand = "document." + theForm + "." + theHeightField + ".value =" +  img.height ;
//		alert(theCommand);
		eval(theCommand);
		
	}
}


function validateField(theField) {

	while ((theField.value.substring(0,1) == ' ') || (theField.value.substring(0,1) == '\n') || (theField.value.substring(0,1) == '\r')) {
		theField.value = theField.value.substring(1,theField.value.length);
	}

	if (theField.value == "")  {
		theField.value = 0 
	}
	
//	if isNaN(theField.value) == true {
//		window.alert("The Quantity field must contain a number " + theField.value);
//		theField.value=1 ;
//	}
	
}


function checkAll(theForm,startStr,theBox) { 
	if ((obj=MM_findObj(theForm))!=null) {
		for ( i = 0 ; i < obj.length ; i++ ) {
			if (obj.elements[i].name.indexOf(startStr) > -1)  {
				if ( obj.elements[i].type == "checkbox" ) {
					obj.elements[i].checked = theBox.checked ;
				}
			}
		}
	}
}

var myErr='';

function checkAtLeastOne(theForm){
	myErr="* You must select at least ONE tenant to Email\n"; 
	for (i = 0 ; i< theForm.length ; i++ ) {
		if (theForm.elements[i].type == "checkbox") { 
//		window.alert( theForm.elements[i].type + " " + theForm.elements[i].checked ) 
			if (theForm.elements[i].checked) { 
				myErr='' ;
			}
		}
	}
  document.MM_returnValue = (myErr=='');
}

/* ==================================================== */
/* 
this function clears the box of its default value on a feedback form.
it is usually called using the onFucus event handler
so that a box is cleared of its dfault value as soon at the user clicks into that box 
*/
function clearBox(theBox) {
if (theBox.value == theBox.defaultValue) {
	theBox.value = "" ;
	}	
}

/* 
this function resets the Select pull-down menu ( or list of pull doen menus, to its first option,
if the select pull down menu actually exists.
If  a select list CANNPT be found,  the function does nothing for that pull-down and moves onto the next one in the list.
*/


function clearSelect() {
	var args = clearSelect.arguments ; 
	
	for ( i=0; i<args.length ; i++ ) {
		if ((obj=MM_findObj(args[i]))!=null) {	
		
			if(obj.type == "select-one") {
				obj.selectedIndex = 0;
			}
		}
	}
}

/* ==================================================== */


function changeClass() {
	var obj , args = changeClass.arguments ;
	if ((obj=MM_findObj(args[0]))!=null) {
		if (( args[1] != "" ) && (args[1] != null) ) {
			obj.className = args[1]  ;
		}	 
	}
}


/* ==================================================== */

function setParentField(){
	var args = setParentField.arguments ; 

	alert("About to set " + args[0] + " to " + args[1] ) ;
	
	if ((obj=MM_findObj(args[0]))!=null) {
		obj.value = args[1] ;
	}
}


/* ==================================================== */

function WriteCookie (cookieName, cookieValue, expiry) {
	var expDate = new Date();
	if ( expiry ){
		expDate.setDate (expDate.getDate() + expiry);
		document.cookie = cookieName + "=" + escape(cookieValue) + "; expires=" + expDate.toGMTString();
	}
	else {
		document.cookie = cookieName + "=" + escape(cookieValue);
	}
	
}


function XMwriteCookie(n,i,t){
	var ep="";
	if (t){
		d = new Date();
		d.setTime(d.getTime()+(t*86400000));
		ep = "; expires="+d.toGMTString();
	}
	document.cookie = n+"="+i+ep+"; path=/";
}

function XMkillCookie(n){
	XMwriteCookie(n,"",-1);
}

/* ======================== validate the form ================================= */


function setStatus(theForm) { 
//	if (theForm.contact_start_work.value != "" ) { 
		if (  ((theForm.contact_employer_name.value != "none") && (theForm.contact_employer_name.value != "")) || (theForm.contact_employer_name_other.value != "") ) { 
		 	theForm.contact_status.value = "Prospect" ;
		}
		else {
			theForm.contact_status.value = "Enquiry" ;
		} 
//	}
}


var myErr='';

function MWW_checkform(theForm) { //v.1.0
// copyright (c) 2005 www.advance-training.co.uk  matt@advance-training.co.uk 
	myErr='';
	if (theForm.contact_mobile_phone.value == "" && theForm.contact_phone.value == "") {
		myErr = myErr +  "* Field 'Phone' or 'Mobile Phone' (or both) must be filled.\n"
		}
//	if (theForm.contact_sms_preference.checked == true && theForm.contact_mobile_phone.value == "") {
//		myErr =myErr +  "* You must specify 'Mobile Phone' if you wish to receive TXT messages.\n"
//		}
}


function YY_checkform() { //v4.66
//copyright (c)1998,2002 Yaromat.com
  var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
  for (var i=1; i<args.length;i=i+4){
    if (args[i+1].charAt(0)=='#'){myReq=true; args[i+1]=args[i+1].substring(1);}else{myReq=false}
    var myObj = MM_findObj(args[i].replace(/\[\d+\]/ig,""));
    myV=myObj.value;
    if (myObj.type=='text'||myObj.type=='password'||myObj.type=='hidden'){
      if (myReq&&myObj.value.length==0){addErr=true}
      if ((myV.length>0)&&(args[i+2]==1)){ //fromto
        var myMa=args[i+1].split('_');if(isNaN(myV)||myV<myMa[0]/1||myV > myMa[1]/1){addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==2)){
          var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$");if(!rx.test(myV))addErr=true;
      } else if ((myV.length>0)&&(args[i+2]==3)){ // date
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);
        if(myAt){
          var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
          var myDate=new Date(myY,myM,myD);
          if(myDate.getFullYear()!=myY||myDate.getDate()!=myD||myDate.getMonth()!=myM){addErr=true};
        }else{addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==4)){ // time
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);if(!myAt){addErr=true}
      } else if (myV.length>0&&args[i+2]==5){ // check this 2
            var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""));
            if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!myObj1.checked){addErr=true}
      } else if (myV.length>0&&args[i+2]==6){ // the same
            var myObj1 = MM_findObj(args[i+1]);
            if(myV!=myObj1.value){addErr=true}
      }
    } else
    if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
          var myTest = args[i].match(/(.*)\[(\d+)\].*/i);
          var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
      if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
      if (args[i+2]==2){
        var myDot=false;
        for(var j=0;j<myObj.length;j++){myDot=myDot||myObj[j].checked}
        if(!myDot){myErr+='* ' +args[i+3]+'\n'}
      }
    } else if (myObj.type=='checkbox'){
      if(args[i+2]==1&&myObj.checked==false){addErr=true}
      if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
    } else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
      if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
    }else if (myObj.type=='textarea'){
      if(myV.length<args[i+1]){addErr=true}
    }
    if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
  }
  if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)}
  document.MM_returnValue = (myErr=='');
}

/* =================================================== */

function to_old_win() {
	var args = to_old_win.arguments ; 
	if (args.length == 1) {
		opener.location.href = args[0];
		self.close();
	}
}


/* =================================================== */
/* =================================================== */
/* ============== Date functions ===================================== */



function calculateWeeks() {
	var theStartDate, theEndDate, theDifference, startingdate, endingdate, args=calculateWeeks.arguments;
/* 
	theStartDate=""
	theEndDate=""
	
	theStartYear=""
	theStartMonth=""
	theStartDay=""

	theEndYear=""
	theEndMonth=""
	theEndDay=""
*/

	if ( ((theStartDate=MM_findObj(args[0]))!=null) && ((theEndDate=MM_findObj(args[1]))!=null) && ((theDifference=MM_findObj(args[2]))!=null)   && theStartDate.value != "" &&  theEndDate.value != "")  {
		
//		alert(" the theStartYear is " + theStartDate + " and theEndYear is " + theEndDate );
		
		theStartYear 	= theStartDate.value.split('/')[2] ;
		theStartMonth 	= (theStartDate.value.split('/')[1])-1 ;
		theStartDay		= theStartDate.value.split('/')[0] ;

		theEndYear 		= theEndDate.value.split('/')[2] ;
		theEndMonth 	= (theEndDate.value.split('/')[1])-1 ;
		theEndDay		= theEndDate.value.split('/')[0] ;
									
		//Set the two dates
		var startingdate	=	new Date(theStartYear,theStartMonth,theStartDay) ; //Month is 0-11 in JavaScript
		var endingdate	=	new Date(theEndYear,theEndMonth,theEndDay) ; //Month is 0-11 in JavaScript
		
		var one_day	=1000*60*60*24 ;
		var one_week	= one_day * 7 ; 
		
//		window.alert("difference between " + theStartDate.name + " and " + theEndDate.name + " is " + Math.ceil((endingdate.getTime()-startingdate.getTime())/(one_week)) )
		
		theDifference.value = Math.round((endingdate.getTime()-startingdate.getTime())/(one_week)) 
	}
}


function dayetilXmas() {
//Set the two dates
today=new Date()
var christmas=new Date(today.getFullYear(), 11, 25) //Month is 0-11 in JavaScript
if (today.getMonth()==11 && today.getDate()>25) //if Christmas has passed already
christmas.setFullYear(christmas.getFullYear()+1) //calculate next year's Christmas
//Set 1 day in milliseconds
var one_day=1000*60*60*24

//Calculate difference btw the two dates, and convert to days
document.write(Math.ceil((christmas.getTime()-today.getTime())/(one_day))+
" days left until Christmas!")

}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function daysElapsed(date1,date2) {
    var difference = Date.UTC(y2k(date1.getYear()),date1.getMonth(),date1.getDate(),0,0,0)  - Date.UTC(y2k(date2.getYear()),date2.getMonth(),date2.getDate(),0,0,0);

// return difference/1000/60/60/24;

window.alert("days difference is " + difference/1000/60/60/24)
}


function isValidDate(dateField) {
// Date validation function courtesty of 
// Sandeep V. Tamhankar (stamhankar@hotmail.com) -->

// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY

var dateStr = dateField.value ;
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year

var matchArray = dateStr.match(datePat); // is the format ok?
//window.alert(" dateStr is '" + dateStr + "'");
if (matchArray == null)  {
	if  (dateStr != "") {
		alert(dateStr + " Date is not in a valid format.")
		return false;
	}
}

//window.alert("matchArray = " + matchArray) ; 

 
// month = matchArray[1];   
// American dates have Month first. MM/DD/yyy Changed to UK format with month second DD/MM/YYYY
month = matchArray[3];

// American dates have Day second. (MMDD/YYYY)  Changed to UK format, with day first DD/MM/YYYY
//day = matchArray[3];
day = matchArray[1];
year = matchArray[4];

//alert("month is " + month +", day is " + day +" year is " + year )
if (month < 1 || month > 12) { // check month range
alert("Month " + month + " must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;
}



/* ================================================================================== */
/* 
	This colors the rows of a table when hovering over the row. 
	it sets the row class to "rowstle_hover" which must be defined in the style sheet
*/

function ColorRows() {

	var oTable = document.getElementById(ColorRows.arguments[0]);
	var oRows = oTable.getElementsByTagName("TR");

	var modRemainder;
	var newClass;
	var oldClass ; 

	for(var i=0; i < oRows.length ; i=i+1 ){
		modRemainder = i % 2;

// 	skip past the first item in the array ( ii.e the top row		
		if(i == 0) continue;  
		
		
//		newClass = (modRemainder == 0) ? "row_even" : "row_odd";

		
		if (modRemainder == 0) { 
			newClass = "rowstyle_even" ; 
		}
		else {
			newClass = "rowstyle_odd" ; 
		}
				
		oRows[i].className = newClass;
		
// You might think you can attach a onmouseiver event to the row object, but it doesn't work.
//		oRows[i].onmouseover = setRowStyle(this,'row_hl')

// Instead create a Literal Function or anonymous function that changes the className to the hilite class.

//Notice the use of the object name of "this", rather than oRows[i].  Because oRows is not defined in the Literal 

		oRows[i].onmouseover = function() {
			oldClass = this.className ;
			this.className = "rowstyle_hover"; // rowHL is a new highlight
		}
		oRows[i].onmouseout = function() {
			this.className = oldClass ; // one of our row colors
		}
	}
}


/*  
These are the variables thatare used in the  Scroller function 
which is used to scroll the Testimonials on the page
*/
var theTop 		= 0;
var theHeight 	= 50;
var theWidth 	= 150;
var theLeft 	= 650;
var toClip 		= 150;
var timerObj ;

function startScroller() {
	
	var i,p,v, theDiv, toMove, args=startScroller.arguments;
	
	toMove = args[1] ;
	
	if (toMove == 1 ) {
		alert("got back to one") ;
	}
	
	window.status="toMove at top  ='" + toMove + "'" ;
	if ((theDiv=MM_findObj(args[0]))!=null) {
	
		if ( document.layers ) {
			theDiv.clip.top = toMove;
			theDiv.clip.bottom = toMove + toClip;
			theDiv.top = theTop - toMove;
		} 
		else {
			theDiv = theDiv.style;
			theDiv.clip = "rect(" + toMove + "px " + (theWidth + theLeft) + "px " + (toMove + toClip) + "px 0px)";
			theDiv.top = theTop - toMove + 'px';
		}
	
		if ( ( theTop + theHeight - toMove ) < ( theTop - theHeight - 20 ) ) {
		
			toMove = 0;
			if ( document.layers ) {	
				theDiv.clip.top = theTop;
				theDiv.clip.bottom = toClip;
				theDiv.top = theTop
			} 
			else 
			{
			theDiv.clip = "rect(" + toMove + "px " + (theWidth + theLeft) + "px " + (toMove + toClip) + "px 0px)";
			theDiv.top = theTop + 'px';
			}
		}
	
		toMove = toMove + 1 ;
		timerObj = setTimeout("startScroller('" + args[0] + "'," + toMove + ")", 100);
	}
	else {
		return ;	
	}
}

function stopScroller() {
	clearTimeout(timerObj) ; 	
}