// This file contains some of the common functions used for this site.
// To use these functions you must make reference to this page in the
// HTML pages. 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Flash content placer
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function getFlash(id, file, w, h, wmode){

var idC = document.getElementById(id);
var cont;

cont = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase="+
"'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' "+
"width='"+w+"' height='"+h+"' title='"+file+"' id='"+file+"SWF'>"+
"<param name='movie' value='../flash/"+ file +".swf' />"+
"<param name='allowScriptAccess' value='sameDomain' />"+
"<param name='quality' value='high' />"+ 
"<param name='wmode' value='"+wmode+"' />"+
"<embed src='../flash/"+ file +".swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'"+
"type='application/x-shockwave-flash' width='"+w+"' height='"+h+"' allowScriptAccess='sameDomain' name='headerSWF' swLiveConnect='true' wmode='"+wmode+"' />"+
"</object>";

idC.innerHTML = cont;
	
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Google Map code 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// GMap2 Map object
var map = null;
// Directions div
var panel = null;
// GDirections object
var dir = null;

var geocoder = null;

// Our location
var lng = 0;
var lat = 0;

locInf = "";
var directionsTo =  "";
// Map with home location displayed in centre
function initMap(point) {
	if (point){
		lat = point.lat();
		lng = point.lng();
	}
	document.getElementById("mapFrom").style.display = 'none';
	document.getElementById("mapDir").style.display = 'none';
	//document.getElementById("mapTo").style.display = 'none';

	if (!map)
		map = new GMap2(document.getElementById("map"));
	// Clear directions panel
	document.getElementById("mapDir").innerHTML = "";	
	//map.enableScrollWheelZoom();
	// Add mini map control
	map.addControl(new GOverviewMapControl()); 
	// Add  a large pan/zoom control 
    map.addControl(new GLargeMapControl());
	// Add buttons that let the user toggle between map types 
	map.addControl(new GMapTypeControl());	
	
	map.setCenter(new GLatLng(lat, lng), 10);

// Add marker in the map viewport using the default icon
var bounds = map.getBounds(lng, lat);
var width = bounds.maxX - bounds.minX;
var height = bounds.maxY - bounds.minY;
var point = new GPoint(lng, lat);	
var marker = new GMarker(point);

	map.addOverlay(marker);
	//marker.openInfoWindowHtml(locInf,{maxWidth:100});
	marker.openInfoWindowHtml(locInf);


var infoDisplay = true;
	GEvent.addListener(map, 'click', function() {
	//alert(map.getCenterLatLng() ); // Use this to get the Lat/Long of the currently centered map
 	if (infoDisplay) {
    	map.removeOverlay(marker);
		infoDisplay = false;
	
  	} 
	else{
		map.addOverlay(marker);
		marker.openInfoWindowHtml(locInf,{maxWidth:180});
		//marker.openInfoWindowHtml(locInf);
		infoDisplay = true;
  	}
	});
}

function getLocation(postCode, address,image){
	locInf = address;
	// Test to see if postCode is actually lat, lng position
	if (IsNumeric(postCode.substr(0,1))){
		var latlng=postCode.split(","); 
		lat = latlng[0];
		lng = latlng[1];
		initMap();
	}
	else
		usePointFromPostcode(postCode, initMap);
	
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


// Locate Lat/Lng from search of postcode/location using google Ajax API
// Requires postcode or location and callback function for when location is found

// Use google local search
var localSearch;
var directionsFrom;

function usePointFromPostcode(postcode, callbackFunction) {
	if (postcode == ""){
	alert("Please enter a location or postcode.");
	return
		
	}

	if (!localSearch)
		localSearch = new GlocalSearch();
		
	localSearch.setAddressLookupMode(localSearch.ADDRESS_LOOKUP_ENABLED); 
	// If not set searches may look outside the UK especially if the names are separated
	localSearch.setCenterPoint("GB"); 

	localSearch.setSearchCompleteCallback(null, 
    function() {
      if (localSearch.results[0]) {    
        var resultLat = localSearch.results[0].lat;
        var resultLng = localSearch.results[0].lng;
		
		//if (!localSearch.results[1]){
			// single location found
        	var point = new GLatLng(resultLat,resultLng);
        	callbackFunction(point);
			directionsFrom = postcode;
		/*}
		else { // more than one location
		
			var locs = "";
			document.getElementById("mapFrom").style.display = "";
			for (i=0;i<localSearch.results.length;i++){
				locs += "<div>"+localSearch.results[i].title+" "+localSearch.results[i].streetAddress+"</div>";
			}
			document.getElementById("mapFrom").innerHTML = locs;
		}*/
      }else{
        alert("Postcode or location not found!");
      }
    });  
   
  localSearch.execute(postcode + ", UK");
}

// Display directions
function getDirections(point) {
//document.getElementById("mapFrom").innerHTML = null;
//document.getElementById("mapTo").innerHTML = null;

panel = document.getElementById("mapDir");
if (!dir)
	dir = new GDirections(map, panel);
if (!geocoder)
	geocoder = new GClientGeocoder();

GEvent.addListener(dir, 'error', function() {		
				//alert (dir.getStatus().code );
	});

GEvent.addListener(dir, 'load', function() {
				
				document.getElementById("mapFrom").style.display = "";
				document.getElementById("mapDir").style.display = "";
				//document.getElementById("mapTo").style.display = "";
// Display From:/To:
				document.getElementById("mapFrom").innerHTML = "From: <strong>" + directionsFrom.toUpperCase()+"</strong>";
				document.getElementById("mapTo").style.visibility="visible";
				
	});

GEvent.addListener(dir, 'addoverlay', function() {
				//alert (dir.getStatus().code );
	});

// Now let google do the really hard work!!
dir.load("from: "+point.lat() + "," + point.lng()+" to: "+lat+","+lng);

}
//////////////////////////////////////////////
function showAddress(address) {
	geocoder.getLatLng(
		address,    
		function(point) {
		if (!point) {        
		alert(address + " not found");
		} else {        
		map.setCenter(point, 13);        
		var marker = new GMarker(point);        
		map.addOverlay(marker);        
		marker.openInfoWindowHtml(address);
		}    
	}  
)
;}


// Show Lat/Lng position
function showPointLatLng(point){
	alert("Latitude: " + point.lat() + "\nLongitude: " + point.lng());
}


// Print Map & info /////////////////////////////////////////////////

var gAutoPrint = true; // Tells whether to automatically call the print function 

function printSpecial(div) // div to print
{ 
	if (document.getElementById != null) 
	{ 
		var html = '<html>\n<head>\n'; 

		if (document.getElementsByTagName != null) 
		{ 
			var headTags = document.getElementsByTagName("head"); 
			if (headTags.length > 0) 
				html += headTags[0].innerHTML; 
		} 

		html += '\n</head>\n<body>'; 
		var printReadyElem = document.getElementById(div); 

		if (printReadyElem.innerHTML != "") 
		{ 
			
			html += printReadyElem.innerHTML; 
		} 
		else 
		{ 
			alert("Nothing to print"); 
			return; 
		} 

		html += '\n</body>\n</html>'; 
		var printWin = window.open("","_blank", "width=600,height=500,scrollbars=yes,toolbar=no,location=no" ); 
		printWin.document.open(); 
		printWin.document.write(html); 
		printWin.document.close(); 
		if (gAutoPrint) 
			printWin.print(); 
        } 
        //else 
        //{ 
			//alert("The print ready feature is only available if you are using the latest browser. Please update your browser."); 
        //} 


} 


/////////////////////////////////////////////////////////////////////////////////
// Open new window
/////////////////////////////////////////////////////////////////////////////////
function showLarge(img,w,h){
	w += 10;
	h += 10;
	//imgLarge = window.open(img,null,'width=820,status=yes,toolbar=no,menubar=no,location=no');
	imgLarge = window.open(img,null,'width='+w+',height='+h+',status=yes,toolbar=no,menubar=no,location=no');
}

/////////////////////////////////////////////////////////////////////////////////
// Change background on focus 
/////////////////////////////////////////////////////////////////////////////////

function changeBg(form,field, requiredFields, fieldNames)
{
var	c,i,z,r,brdW;
r=0;
	//brdW = field.style.borderWidth;
	//alert (brdW);
	field.style.backgroundColor = 'e1ebff';
	//setBGColor(field, 'e1ebff');
	//field.style.border = 'solid';
	//field.style.borderColor = '6699ff';
	//field.style.borderWidth = brdW ;
	
	// Find form field pos.
	for (i=0;i<form.length;i++)
	{
	if (field.name == form[i].name)
		{
			break;
		}
	}
	msg = "";
	
	c = 0;
	for (t=0;t<i;t++)
	{
		
		if ((form[t].value == "") || (form[t].value == null))
			{
				
			for (z=0;z<requiredFields.length;z++)
				{
					//alert (form.elements.length);
					if (form[t].name == requiredFields[z])
					{
						
						msg += "'" + fieldNames[z] + ":'\n";
						c++;
						if (r==0)
							r = t;
					}
				}
			
			}
		
	}
	if (c == 1){
		alert ("Please complete the required field:\n\n" + msg);
		restoreBg(field);
		form.elements[r].focus();
	}
	else if (c > 1){
		alert ("Please complete the required fields:\n\n" + msg);
		restoreBg(field);
		form.elements[r].focus();
	}
}

function restoreBg(obj)
{
	obj.style.backgroundColor = 'white';
	//obj.style.borderColor = '999999';
}

////////////////////////////////////////////////////////////////////////////////
// Navigation
////////////////////////////////////////////////////////////////////////////////

// Goback one page
function navBack(){
history.back();
}


////////////////////////////////////////////////////////////////////////////////
// Test for empty/null data
function isEmpty(data){
if ((data == null) ||
(data == "") ||
(data.length < 1))
return (true);
else return (false);
}


////////////////////////////////////////////////////////////////////////////////
// Determine MS IE or Nav
var ua = navigator.userAgent;
function IE(){
if (ua.indexOf("MSIE")>=1)
	return true;
}
////////////////////////////////////////////////////////////////////////////////
// Returns the date in long hand format
function date1 ()
{
  var d, s = "";
  var month = ["January", "February", "March", "April", "May" , "June",
  "July", "August", "September", "October", "November", "December"];
  
  var day = ["Sunday", "Monday", "Tuesday",
  "Wenesday", "Thursday", "Friday", "Saturday"];
  
  d = new Date();
  //s += day[d.getDay()] + " ";
  s += d.getDate() + " ";
  s += month[(d.getMonth())] + " ";
  s += d.getFullYear();
  return (s)
   
}
////////////////////////////////////////////////////////////////////////////////
function year ()
{
  var d, s = "";
  
  d = new Date();
  s += d.getFullYear();
  return (s)
   
}






////////////////////////////////////////////////////////////////////////////////
// Check email validity
/* 1.1.4: Fixed a bug where upper ASCII characters (i.e. accented letters
international characters) were allowed.

1.1.3: Added the restriction to only accept addresses ending in two
letters (interpreted to be a country code) or one of the known
TLDs (com, net, org, edu, int, mil, gov, arpa), including the
new ones (biz, aero, name, coop, info, pro, museum).  One can
easily update the list (if ICANN adds even more TLDs in the
future) by updating the knownDomsPat variable near the
top of the function.  Also, I added a variable at the top
of the function that determines whether or not TLDs should be
checked at all.  This is good if you are using this function
internally (i.e. intranet site) where hostnames don't have to 
conform to W3C standards and thus internal organization e-mail
addresses don't have to either.
Changed some of the logic so that the function will work properly
with Netscape 6.

1.1.2: Fixed a bug where trailing . in e-mail address was passing
(the bug is actually in the weak regexp engine of the browser; I
simplified the regexps to make it work).

1.1.1: Removed restriction that countries must be preceded by a domain,
so abc@host.uk is now legal.  However, there's still the 
restriction that an address must end in a two or three letter
word.

1.1: Rewrote most of the function to conform more closely to RFC 822.

1.0: Original  */
// -->

<!-- Begin
function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Email username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Email domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("Email username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Email destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("Email domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The email address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("The email address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

////////////////////////////////////////////////////////////////////////////////
// Set font attributes
function setFont1(ref, family, style, weight, size, color, pos){
ref.style.fontSize = size;
ref.style.fontFamily = family;
ref.style.fontStyle = style;
ref.style.fontWeight = weight;
ref.style.color = color;
ref.align = pos;
return (ref);
}
////////////////////////////////////////////////////////////////////////////////
// Set border attributes
function setBorder(ref, bg, color, width, style){
ref.style.background = bg;
ref.style.borderColor = color;
ref.style.borderWidth = width;
ref.style.borderStyle = style;
return (ref);
}

////////////////////////////////////////////////////////////////////////////////
// Form Validation
// Arrays for the required fields and discriptions are passed to this function
// from the form. If there is an 'emailaddress' field then this is tested for
// correct syntax.

function formCheck(formobj, fieldRequired, fieldDescription){

	var alertMsg = "Please complete the following field(s):\n";
	
	var l_Msg = alertMsg.length;
	var groupChecked = false;
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "checkbox": // Not likely to be used
			
				if (obj.checked == false){
					
						alertMsg += " - " + fieldDescription[i] + "\n";
				}
				
				
				break;
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == "" || obj.options[obj.selectedIndex].text == "Please Select" ){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
					}
			else	if (fieldRequired[i] == "emailaddress"){
		 			 if (!emailCheck (formobj.emailaddress.value))	
						return false;
					 }
					 
				//}
				break;
			default:
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;

	}
	else{
		alert(alertMsg);
		return false;
	}
}


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

// DHTMLapi.js custom API for cross-platform
// object positioning by Danny Goodman (http://www.dannyg.com).
// Release 2.0. Supports NN4, IE, and W3C DOMs.

// Global variables
var isCSS, isW3C, isIE4, isNN4, isIE6CSS;
// Initialize upon load to let all browsers establish content objects
function initDHTMLAPI() {
    if (document.images) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
        isIE4 = (isCSS && document.all) ? true : false;
        isNN4 = (document.layers) ? true : false;
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
    }
}
// Set event handler to initialize API
//window.onload = initDHTMLAPI;

// Seek nested NN4 layer from string name
function seekLayer(doc, name) {
    var theObj;
    for (var i = 0; i < doc.layers.length; i++) {
        if (doc.layers[i].name == name) {
            theObj = doc.layers[i];
            break;
        }
        // dive into nested layers if necessary
        if (doc.layers[i].document.layers.length > 0) {
            theObj = seekLayer(document.layers[i].document, name);
        }
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid element object reference
function getRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj) {
    var theObj = getRawObject(obj);
    if (theObj && isCSS) {
        theObj = theObj.style;
    }
    return theObj;
}

// Position an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0 
            theObj.left = x + units;
            theObj.top = y + units;
        } else if (isNN4) {
            theObj.moveTo(x,y)
        }
    }
}

// Move an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0 
            theObj.left = getObjectLeft(obj) + deltaX + units;
            theObj.top = getObjectTop(obj) + deltaY + units;
        } else if (isNN4) {
            theObj.moveBy(deltaX, deltaY);
        }
    }
}

// Set the z-order of an object
function setZIndex(obj, zOrder) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.zIndex = zOrder;
    }
}

// Set the background color of an object
function setBGColor(obj, color) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isNN4) {
            theObj.bgColor = color;
        } else if (isCSS) {
            theObj.backgroundColor = color;
        }
    }
}

// Set the visibility of an object to visible
function show(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "visible";
    }
}

// Set the visibility of an object to hidden
function hide(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "hidden";
    }
}

// Retrieve the x coordinate of a positionable object
function getObjectLeft(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("left");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.left;
    } else if (elem.style) {
        result = elem.style.left;
    } else if (isNN4) {
        result = elem.left;
    }
    return parseInt(result);
}

// Retrieve the y coordinate of a positionable object
function getObjectTop(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("top");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.top;
    } else if (elem.style) {
        result = elem.style.top;
    } else if (isNN4) {
        result = elem.top;
    }
    return parseInt(result);
}

// Retrieve the rendered width of an element
function getObjectWidth(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetWidth) {
        result = elem.offsetWidth;
    } else if (elem.clip && elem.clip.width) {
        result = elem.clip.width;
    } else if (elem.style && elem.style.pixelWidth) {
        result = elem.style.pixelWidth;
    }
    return parseInt(result);
}

// Retrieve the rendered height of an element
function getObjectHeight(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetHeight) {
        result = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}

// Return the available content width space in browser window
function getInsideWindowWidth() {
    if (window.innerWidth) {
        return window.innerWidth;
    } else if (isIE6CSS) {
        // measure the html element's clientWidth
        return document.body.parentElement.clientWidth
    } else if (document.body && document.body.clientWidth) {
        return document.body.clientWidth;
    }
    return 0;
}

// Return the available content height space in browser window
function getInsideWindowHeight() {
    if (window.innerHeight) {
        return window.innerHeight;
    } else if (isIE6CSS) {
        // measure the html element's clientHeight
        return document.body.parentElement.clientHeight
    } else if (document.body && document.body.clientHeight) {
        return document.body.clientHeight;
    }
    return 0;
}



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Get current date using Ajax object
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function getToday()
{
	getDynamicContent("http://www.foect.org.uk/php/date.php",gotToday);	
}

function gotToday(today){
	document.getElementById("date").innerHTML = today;
}

function gotRSList(RSList){
	document.getElementById("formList").innerHTML = RSList;
}

function gotCOTM(cotm){
	document.getElementById("churchofmonthLink").innerHTML = cotm;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Get content using Ajax object
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var xmlHttp;

function getDynamicContent(url,returnFunc)
{
	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.returnFunc = returnFunc;
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 4)
		{
			//returnFunc (xmlHttp.responseText);
			xmlHttp.returnFunc (xmlHttp.responseText);
		}
	}
	  	  
	xmlHttp.open("GET",url, true);
	
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	//xmlHttp.send("par="+ajaxSend);
	xmlHttp.send();
}

var xmlHttp_2;

function getDynamicContent_2(url,returnFunc)
{
	try
    {    // Firefox, Opera 8.0+, Safari
	xmlHttp_2=new XMLHttpRequest(); 
	}
  catch (e)
    {    // Internet Explorer
		try
		{      
	  		xmlHttp_2=new ActiveXObject("Msxml2.XMLHTTP"); 
		}
		catch (e)
      	{
	  		try
       		{        		
				xmlHttp_2 = new ActiveXObject("Microsoft.XMLHTTP");
			}
      		catch (e)
        	{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
    
	xmlHttp_2.returnFunc = returnFunc;
	xmlHttp_2.onreadystatechange = function()
	{
		if(xmlHttp_2.readyState == 4)
		{
			//returnFunc (xmlHttp.responseText);
			xmlHttp_2.returnFunc (xmlHttp_2.responseText);
		}
	}
	  	  
	xmlHttp_2.open("GET",url, true);
	
	xmlHttp_2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	//xmlHttp_2.send("par="+ajaxSend);
	xmlHttp_2.send();
}

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

function getChurches(){
	var area = document.add_post.AREA.value;
	if (area == "Please Select") return;
	
	// call Ajax function to get list of churches
	getDynamicContent("http://www.foect.org.uk/rs/get_church_list.php?area=" + area, gotList);	

}

function gotList(list){
	var listArray = list.split('\n');
	var area = document.add_post.AREA.value;
	
	var listSelect = "<select name='CHURCH'>";
	listSelect += "<option value='Please Select'>Please Select</option>\n";
	for (i=0;i<listArray.length;i++){
		
		listSelect += "<option value='" + listArray[i] + "' >" + listArray[i] + "</option>\n";
	}
	
	listSelect += "</select>\n";
	
	//listSelect += "<input type='hidden' name='AREA' value='" + area + "' />\n";
	
	document.getElementById("selectChurch").innerHTML = listSelect;
	//alert (listSelect);
	
}


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

function checkFileType( fileName, fileTypes ) {
	//alert (fileName);
	if (!fileName) return;

	dots = fileName.split(".")
	//get the part AFTER the LAST period.
	fileType = "." + dots[dots.length-1];

	if (fileTypes.join(".").indexOf(fileType.toLowerCase()) == -1){
		alert("Please only upload files that end in types: \n\n" + (fileTypes.join(" .")) + "\n\nPlease select a supported image file type and try again.");
	}
}

function submitFormCheck(form, msg){
	if (confirm(msg)){
		document.forms[form].submit();
		return;
	}
	else
		return false;	
}

function submitForm(f){
	document.forms[f].submit();
}



// SubMenus
var T0, T1, T2, T3, T4, T5, T6, TP=180;


function closeSub0(){
	document.getElementById("sub0").style.visibility = "hidden";			
}
function closeSub1(){
	document.getElementById("sub1").style.visibility = "hidden";			
}
function closeSub2(){
	document.getElementById("sub2").style.visibility = "hidden";			
}
function closeSub3(){
	document.getElementById("sub3").style.visibility = "hidden";			
}
function closeSub4(){
	document.getElementById("sub4").style.visibility = "hidden";			
}
function closeSub5(){
	document.getElementById("sub5").style.visibility = "hidden";			
}
function closeSub6(){
	document.getElementById("sub6").style.visibility = "hidden";			
}




