/****************************************************************************************/
/* Floating div functions 																*/
/****************************************************************************************/

// function to open float form
function openFloat(str_id) {
	obj_window = window.parent;
	obj_window.fadeIn("overlayShade", 0, 5);
	obj_window.fadeIn(str_id, 0, 10);
}

// function to close float form
function closeFloat() {
	obj_window = window.parent;
	if (document.getElementById("hp_overlay")) {
		obj_window.fadeOut("hp_overlay", 10, 0);
	}
	if (document.getElementById("hp_movie")) {
	//	document.getElementById("hp_movie").sendEvent("STOP");
		var obj_movie = document.getElementById("hp_movie");
		var movieUrl = obj_movie.title;
		obj_movie.innerHTML = "<a href=\"#\" onclick=\"this.style.display='none';document.getElementById('new_video_player').style.display='block';setTimeout(playMovieNow,500);return false;\" style=\"display:block;height:491px;width:793px;\"><img border=0 src=\"/images/video_cover.png\" width=\"793px\" height=\"491px\"/></a><div id=\"new_video_player\" style=\"display:none;margin:auto;width:793px;height:491px;\"><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"793\" height=\"491\" id=\"new_video\"><param name=\"swliveconnect\" value=\"true\"><param name=\"movie\" value=\""+movieUrl+"\"><param name=\"FlashVars\" value=\"videos=video_complete_1.flv\"><param name=\"allowFullScreen\" value=\"true\"><param name=\"allowScriptAccess\" value=\"always\"><embed src=\""+movieUrl+"\" allowScriptAccess=\"always\" swLiveConnect=\"true\" FlashVars=\"videos=video_complete_1.flv\" allowFullScreen=\"true\" width=\"793\" height=\"491\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" name=\"new_video\"></object></div>";
	}
	if (document.getElementById("hiw_overlay_1")) {
		obj_window.fadeOut("hiw_overlay_1", 10, 0);
	}
	if (document.getElementById("hiw_overlay_2")) {
		obj_window.fadeOut("hiw_overlay_2", 10, 0);
	}
	if (document.getElementById("hiw_overlay_3")) {
		obj_window.fadeOut("hiw_overlay_3", 10, 0);
	}
	if (document.getElementById("hiw_overlay_4")) {
		obj_window.fadeOut("hiw_overlay_4", 10, 0);
	}
	if (document.getElementById("rf_overlay")) {
		obj_window.fadeOut("rf_overlay", 10, 0);
	}
	obj_window.fadeOut("overlayShade", 5, 0);
}

// function to load 'waiting' animation
/*
function waitingAnimation(str_id, bol_onOff, btn_this, frm_this) {
	var obj_window = window.parent;
	if (btn_this) {
		btn_this.disabled = true;
	}
	if (frm_this) {
		frm_this.submit();
	}
	if (bol_onOff) {
		if(str_id != '') {
			obj_window.fadeOut(str_id, 10, 5);
		}
		obj_window.fadeIn("overlayShade", 5, 7);
		obj_window.fadeIn("floatWaiting", 0, 10);
	} else {
		obj_window.fadeOut("floatWaiting", 10, 0);
		obj_window.fadeOut("overlayShade", 7, 5);
		if(str_id != '') {
			obj_window.fadeIn(str_id, 5, 10);
		}
	}
}
*/
/****************************************************************************************/
/* trim functions																		*/
/****************************************************************************************/
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

/****************************************************************************************/
/* fade functions																		*/
/****************************************************************************************/

// defaults
var int_interval_in = 32;
var int_interval_out = 32;

// function to fade div in
function fadeIn(domId, int_start, int_finish) {
	obj = document.getElementById(domId);
	function f() {
		int_start++;
		setOpaque(domId, int_start);
		if (int_start <= int_finish) {
			setTimeout(f, int_interval_in);
			obj.style.visibility = "visible";
			obj.style.zIndex = 9999999;
		}
	}
	setTimeout(f, int_interval_in);
}

// function to fade div out
function fadeOut(domId, int_start, int_finish) {
	obj = document.getElementById(domId);
//	obj.style.visibility = "hidden";
	function f() {
		int_start--;
		setOpaque(domId, int_start);
		if (int_start > int_finish) {
			setTimeout(f, int_interval_out);
		} 
		if (int_start == 0) {
			obj.style.visibility = "hidden";
		}
	}
	setTimeout(f, int_interval_out);
}

// cross-browser compliant opacity setter
function setOpaque(domId, val){
	obj = document.getElementById(domId);
	obj.style.MozOpacity = val;
	obj.style.opacity = val/10;
	obj.style.filter = 'alpha(opacity=' + val*10 + ')';
}











/***************************************************************************************/
/* Form validation functions */
/***************************************************************************************/
function validateEmailAddress(obj, formObj, formValue) {
	var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	return regex.test(formValue);
}

function validateOptionalEmail(obj, formObj, formValue) {
	if(formValue != '') {
		var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
		return regex.test(formValue);
	} else {
		return true
	}
}

/***************************************************************************************/
/* Change the display of an element */
/***************************************************************************************/
function changeElementDisplay(el)
{
	displayItem = document.getElementById(el).style
	if (displayItem.display == 'none')
		displayItem.display = '';
	else
		displayItem.display = 'none';
}

/***************************************************************************************/
/* Open window function */
/***************************************************************************************/
/* *** TEMPORARILY DISABLED AS IT MAY CLASH WITH OTHER FUNCTIONS IN THE SITE WITH THE SAME NAME ***
function OpenWindow(page,winName,winWidth,winHeight,winScroll,winStatus)
{
	windowProperty = 'toolbar=no,directories=no,resizable=yes,scrollbars='+winScroll+',status='+winStatus+',menubar=no,width='+winWidth+',height='+winHeight;
	var msg=open(page,winName,windowProperty);
}
*/

/***************************************************************************************/
/* Open general window function */
/***************************************************************************************/
function openPopupWindow(str_url, str_window, int_width, int_height, bol_toolbar, bol_scrollbar, bol_status, bol_menubar, bol_resizable) {
	var newWindow = window.open(str_url, str_window, "width="+int_width+", height="+int_height+", toolbar="+bol_toolbar+", scrollbars="+bol_scrollbar+", status="+bol_status+", menubar="+bol_menubar+", resizable="+bol_resizable);
}

/***************************************************************************************/
/* Open stats window function */
/***************************************************************************************/
function openStatsWindow(url) {
	var newWindow = window.open(url, "", "HEIGHT=338,WIDTH=600,toolbar=no,scrollbar=yes,status=no,menubar=no,resizeable=no");
}

/***************************************************************************************/
/* Macromedia Dreamweaver Rollover code */
/***************************************************************************************/
/*
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_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_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.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];}
}
*/