isIE = (document.all) ? 1 : 0;
isW3C = (document.getElementById && !document.all) ? 1 : 0;

backgroundImagesArray = ['url(/images/lhs_waves.jpg)', 
						 'url(/images/lhs_shells.jpg)', 
						 'url(/images/lhs_cliff.jpg)',
						 'url(/images/lhs_sand.jpg)',
						 'url(/images/lhs_sea.jpg)'];


function getMinContentHeight() {
	if (isW3C) {
		docObj = document.getElementById("navPanel");
		minContentHeight = document.defaultView.getComputedStyle(docObj, "").getPropertyValue("height");
		return minContentHeight.substring(minContentHeight,minContentHeight.length-2);
	} else {
		return navPanel.offsetHeight;
	}
}

function getFooterHeight() {
	if (isW3C) {
		docObj = document.getElementById("contentFooter");
		contentFooterHeight = document.defaultView.getComputedStyle(docObj, "").getPropertyValue("height");
		return contentFooterHeight.substring(0,contentFooterHeight.length-2);
	} else {
		return contentFooter.offsetHeight;
	}
}

function getContentMainHeight() {
	if (isW3C) {
		docObj = document.getElementById("contentMain");
		contentMainHeight = document.defaultView.getComputedStyle(docObj, "").getPropertyValue("height");
		return contentMainHeight.substring(0,contentMainHeight.length-2);
	} else {
		return contentMain.offsetHeight;
	}
}

function getPaddingAdjustment() {
	if (isW3C) {
		return 68;
	} else {
		return 65;
	}
}

function fixContentMainHeight() {
	currentContentMainHeight = getContentMainHeight() + getFooterHeight() + getPaddingAdjustment();
	newContentMainHeight = getMinContentHeight() - getFooterHeight() - getPaddingAdjustment();
	if (currentContentMainHeight < getMinContentHeight()) {
		if (isW3C) {
			document.getElementById("contentMain").style.height = newContentMainHeight + "px";
		} else {
			contentMain.style.height = newContentMainHeight;
		}
	}
}

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
	var tempStr = "a";
	var tempReg = new RegExp(tempStr);
	if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

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_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_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];}
}

// Browser sniffer
function Is() {
	agent = navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);
	this.ns = ((agent.indexOf('mozilla') != -1) && ((agent.indexOf('spoofer') == -1) && (agent.indexOf('compatible') == -1)));
	this.ie = (agent.indexOf("msie") != -1);
}
var is = new Is();

// Change a Stylesheet definition
function changeStyleDefinition(stylesheetIndex, ruleName, property, newValue) {
	ruleNumber = -1;
	
	if (is.ie) {
		for (i=0; i < document.styleSheets[stylesheetIndex].rules.length; i++) {
			thisRuleName = document.styleSheets[stylesheetIndex].rules[i].selectorText;
			if (thisRuleName.substring(1, thisRuleName.length).toUpperCase() == ruleName.toUpperCase()) {
				ruleNumber = i;
				break;
			}
		}
		if (ruleNumber != -1) {
			eval('document.styleSheets[stylesheetIndex].rules[ruleNumber].style.' + property + ' = "' + newValue + '"');
		}
	} else {
		for (i=0; i < document.styleSheets[stylesheetIndex].cssRules.length; i++) {
			thisRuleName = document.styleSheets[stylesheetIndex].cssRules[i].selectorText;
			if (thisRuleName.substring(1, thisRuleName.length) == ruleName) {
				ruleNumber = i;
				break;
			}
		}
		if (ruleNumber != -1) {
			eval('document.styleSheets[stylesheetIndex].cssRules[ruleNumber].style.' + property + ' = "' + newValue + '"');
		}
	}
}

// Set a random background image
function setRandomBackgroundImage() {
	x = 0;
	y = backgroundImagesArray.length - 1;
	
	var randomNumber = Math.round( (x - 0.5) +( ( (y + 0.49999) - ( x- 0.5) ) * Math.random() ) );
	
	changeStyleDefinition(0, 'navPanel', 'backgroundImage', backgroundImagesArray[randomNumber]);
}

