function clearField(element){
	if(element.value == 'email@example.com' || element.value == 'Type message here...') element.value = '';	
	element.style.border = 'none';
}
function changeLoc( strLoc ) {

	arrTmp = Array();
	strUrl = window.location.href;
	arrTmp = strUrl.split("/");
	
	arrTmp[(arrTmp.length-1)] = strLoc;

	return (arrTmp.join("/"));
}
function validateForm( objForm ) {

	var objCurrentInput;
	var boolEmail = true;
	var boolComplete = true;
	var tmp;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	// loop through elements in form
	for(var x = 0; x<objForm.elements.length;x++) {
	
		// set temporary element
		objCurrentInput = objForm.elements[x];
		// check if element is an object
		if( typeof( objCurrentInput ) != 'object' ) continue;
		
		//Only continue if field is required:
		if(objCurrentInput.name.indexOf('_required') > -1){
						
			// set temp value
			tmp = objCurrentInput.value;
	
			if(objCurrentInput.name.indexOf('email') > -1){
				// check for valid email
				
				if(tmp == "email@example.com" || !filter.test(tmp)) {
					boolEmail = false;
					//objCurrentInput.style.border = '2px solid red';
				}
			}
			
			// check for completeness
			if( tmp == null || tmp == "") {
				boolComplete = false;
				objCurrentInput.style.border = '2px solid red';
			}
		
		}
	
	}
	
	if( boolEmail && boolComplete ){
		returnVal = true;
	} else if(!boolEmail && boolComplete){
		alert( "Please supply a valid email address." );
		returnVal = false;
	} else {
		alert( "Please fill out the entire form before submitting." );
		returnVal = false;
	}
	
	//return returnVal;
	if(returnVal) objForm.submit();

}
function resetBorder(field){
	field.style.border = '1px solid #FFAC45';
}

function Gallery() {

	this.arrImages = Array();
	this.currentImg = 0;
	this.noImages = 0;
	
	this.registerImage = function( strFile, intImageNo ) {
	
		this.arrImages[intImageNo] = strFile;
		this.noImages++;
	
	}

	this.switchGallery = function( intImageNo ) {

		// get image elements		
		objMainImg = document.getElementById('main_gallery_image');
		strNewImage = this.arrImages[intImageNo];
	
		// split new url with original filename on the end
		var arrTmp = objMainImg.src.split("\/xl_");
	
		// change file to large copy
		arrTmp[arrTmp.length-1] = "xl_"+strNewImage;
	
		// join source back together
		strTmp = arrTmp.join("/");

		// switch image
		objMainImg.src = strTmp;
		this.currentImg = intImageNo;
		this.fixHeight();

	}

	this.prevImage = function() {


		if( this.currentImg == 0 ) this.currentImg = this.noImages;
		
		this.currentImg--;
		
		this.switchGallery( this.currentImg );

	}

	this.nextImage = function() {

		if( this.currentImg == (this.noImages-1) ) {
			this.currentImg = 0;
		} else {
			this.currentImg++;
		}
		
		this.switchGallery( this.currentImg );

	}
	
	this.fixHeight = function() {
	
		objBigImg = document.getElementById('main_gallery_image');
		
		intH = objBigImg.offsetHeight;
		
		//objBigImg.style.top = "50%";
		objBigImg.style.marginTop = "-"+(intH/2)+"px";
		
	}

}

objGallery = new Gallery();

	switchImg = function( int ) {
		
		objRef = eval("pimg_l"+int);
		
		if(objRef.src.indexOf('blank') < 0){
			objBigImg.src=objRef.src;		
			fixHeight();
		}
		
	}
	
	fixHeight = function() {
	
		objBigImg = document.getElementById('big_img');
		
		intH = objBigImg.offsetHeight;

		objBigImg.style.top = "50%";
		objBigImg.style.marginTop = "-"+(intH/2)+"px";
		
}

	
	function submitDownloads( objForm ) {
	
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
		strName = objForm.name.value;
		strEmail = objForm.email.value;
		
		if( strName == '' || strEmail == '' ) {
			alert( 'Please fill out all required fields' );
			return;
		}
		
		if(reg.test(strEmail) == false) {
			alert('Please supply a valid email address.');
			return;
		}
		
		objForm.submit();
	
	}