//
// decode()
// Takes an encoded php string and returns the decoded form.
//
function decode(encoded){

  var encodedArray = encoded.split('/');	
  var decoded;
  
  for (var i = 0; i < (encodedArray.length-1); i++) {
  	
	if (i == 0)
		decoded = String.fromCharCode((encodedArray[i]-1));
	else
		decoded += String.fromCharCode((encodedArray[i]-1));
		
  }	

  return document.write(decoded);

}


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
// Modifications by - http://huddletogether.com/projects/lightbox2/
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}




//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Modifications by - http://huddletogether.com/projects/lightbox2/
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}



function setWrap() {
	var arrayPageSize = getPageSize();
	var wrap = document.getElementById('wrap');
	
	if (wrap.offsetHeight < arrayPageSize[1]) {
		wrap.style.height = arrayPageSize[1]+"px";
	}
}

function setContent() {
	var content = document.getElementById('content');
	var ads = document.getElementById('rightad');
	var wrap = document.getElementById('wrap');
	
	var adsSize = ads.offsetHeight;
	var contentSize = content.offsetHeight;
	var wrapHeight = wrap.offsetHeight;
	
	if ((adsSize+140) > contentSize) {
			content.style.height = (adsSize+140)+"px";
			wrap.style.height = (wrapHeight+140)+"px";
	} else {
			ads.style.height = (contentSize-140)+"px";
	}
}
	


//
// validateRequired()
// Cycles through all elements with a class of "reqField", 
// and uses some basic validation.  If the element has an ID of "email"
// or "Email" it will test the value against a regular expression.
//
function validateRequired() {
	
	var fields = document.getElementsByClassName("reqField");
	var error = "The following required fields are incomplete or contain errors.\n\n";
	var returnError = false;
	var emailFilter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	
	if (fields.length != 0) {
	
		for (var i=0; i<fields.length; i++) {
			
			if (fields[i].value == null || fields[i].value.length == 0) {
				error += " - "+fields[i].id+" is empty\n";
				returnError = true;
			}
			else if (fields[i].id == "email" || fields[i].id == "Email") {
			
				if (!emailFilter.test(fields[i].value)) { 
					error += " - "+fields[i].id+" is invalid\n";
					returnError = true;
				}
			
			}

				
		}		
	
	}
	
	error += "\n\nPlease correct these fields before continuing.";

	if (returnError == true) {
		alert(error);
		return false;
	}
	else {
		return true;
	}
}


//
// clearThis()
// Clears a form element
//
function clearThis(obj) {
	obj.value = "";
}

function switchOut(region) {
	for(i=0;i<3;i++) {
		document.getElementById("region" + i).style.display = "none";
	}
	
	document.getElementById("regionNone").style.display = "none";
	document.getElementById("region" + region).style.display = "block";
	document.getElementById("regionMap").src = "images/regions/region" + region + ".gif";
}
		
		
		
		
	
	
