

// Make confirmation box with given 'message', then proceed to the given 'page'.
function popWin(page,message)
	{ if (confirm(message)) { location.href = page; } }


// Delete a cookie
function delete_cookie(cookie_name)
	{
	var kill_time = new Date("November 30, 1975");
	var kill_string = "client_name="+cookie_name+";expires=" + kill_time.toGMTString();
	document.cookie = kill_string;
	}


// Cross browser printing ------------------------
// --- Istvan - 25/05/2004
function printit()
	{  
	if (window.print) { window.print(); }
		else
		{
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowser1.ExecWB(6, 2); //Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
		}
	}



// trim() function - Does what trim() does in, for example, ColdFusion or PHP. -------------------------
// Returns the trimmed string.
// --- Istvan - 25/05/2004

function trim(s) 
	{
	if (typeof s != "string") { return s; }
	else
	{
	// Remove leading spaces and carriage returns
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')) { s = s.substring(1,s.length); }
	// Remove trailing spaces and carriage returns
	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')) { s = s.substring(0,s.length-1); }
	return s;
	}
	}

// --- Delayed pop-up-subscribe window --------------------------------------------------------------
// --- Istvan - 15/01/2004
function addslashes(str) {
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\0/g,'\\0');
return str;
}

// -- Optional feature to automatically close the pop-up window after a defined amount of time. --
closetime = 0; // '0' means don't close automatically.

function Start(url, width, height) {
// -- Creates the popup window with 'delay' seconds delay. --
	windowprops = "left=50,top=50,width=" + width + ",height=" + height;
	preview = window.open(url, "preview", windowprops);
	if (closetime) setTimeout("preview.close();", closetime*1000);
	}

function doPopup(url, width, height, delay) {
// -- Sets up to create the popup window. --
	// These variables are sent through the "readPopupCookie()" function in the pagestart.cfm file.
	// url = Link to the pop-up file. I.e.: '/popup.cfm' 
	// width = Width of window in pixels. I.e.: '300'
	// height = Height of window in pixels. I.e.: '200'
	// delay = Time in seconds before popup opens. I.e.: '10'	
	url1 = url;
	width1 = width;
	height1 = height;
	timer = setTimeout("Start(url1, width1, height1)", delay*1000);
	}

function getDaysExpiry(noDays){
// -- Calculate expiry time when days are used. --
    var today = new Date();
    var expr = new Date(today.getTime() + noDays*24*60*60*1000);
    return expr.toGMTString();
	}
	
function getHoursExpiry(noHours){
// -- Calculate expiry time when hours are used. --
    var today = new Date();
    var expr = new Date(today.getTime() + noHours*60*60*1000);
    return expr.toGMTString();
	}

function wwwPathToDomainName(www_path){
// -- Remove 'http://', 'www.' and 'www.members.' from 'www_path' --
	var pattern1 = /\bhttp:\/\//ig; // anything that begins with 'http://'.
	var pattern2 = /\bwww\./ig; // anything that begins with 'www.'.
	var pattern3 = /\bmembers\./ig; // anything that begins with 'members.'.
	siteDomainA = www_path.replace(pattern1,""); // replace 'http://' with nothing... ie: remove it.
	siteDomainB = siteDomainA.replace(pattern2,""); // replace 'www.' with nothing... ie: remove it.
	siteDomain = siteDomainB.replace(pattern2,""); // if after removing 'www.' the remaining string begins with 'members.', replace that with nothing as well... ie: remove it.
	return siteDomain;
	}

function readPopupCookie(siteID, url, width, height, delay, num_hours, www_path){
// -- Checks and/or makes pop-up cookie and runs pop-up function if no disabling cookies have been set. --
// -- Set in the 'pagestart.cfm' file. --
	var siteDomain = wwwPathToDomainName(www_path); // Clean-up www_path.
	var smShownPop = 'smShownPop' + siteID; // Make name of cookie.
	var smSubscribed = 'smSubscribed' + siteID; // Make name of cookie.
	
	var smShownPopC = document.cookie.indexOf(smShownPop); // This exists if popup has alredy appeared within 'num_hours'.
	var smSubscribedC = document.cookie.indexOf(smSubscribed); // This exists if someone has already submitted through the popup within 'num_days' (set in the 'subscribed()' function below).
	
    if (smShownPopC == -1 && smSubscribedC == -1) { // If no pop-up disabling cookies exist... then...
		doPopup(url, width, height, delay); // Runs pop-up function, pop-up appears in 'delay' seconds... and...
		document.cookie=smShownPop + "=shown; path=/; domain=" + siteDomain + "; expires=" + getHoursExpiry(num_hours); // Sets cookie to disable pop-up for 'num_hour' hours.
    	}
	}

function subscribed(siteID, num_days, www_path){
// -- Sets cookie when submit button is pressed in the popup window. --
// -- Will disable the popup for 'num_days' days. --
// -- Set in the pop-up file's submit button with 'onClick'. --
	var siteDomain = wwwPathToDomainName(www_path); // Clean-up www_path.
	var smSubscribed = 'smSubscribed' + siteID; // Make name of cookie.
    document.cookie = smSubscribed + "=subscribed; path=/; domain=" + siteDomain + "; expires=" + getDaysExpiry(num_days); // Set cookie.
	}

// - P O P - U P  W I N D O W  F U N C T I O N S  E N D  H E R E  ---------


	

// ---- Macromedia image rollover -------------------

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];}
}

function MM_showHideLayers() { //v6.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	obj.visibility=v; }
}

function searchItems(){
	var items = document.getElementById('searchTerms').value;
	if (items!="")
	{
		location.href='index.php?process=actions/search.php&terms=' + items;
	}
}

function print_this_page()
{
	var loc = document.location.href;
	
	var length = loc.search('#');
	if (length < 0) length = loc.length;
	var loc = loc.substring(0,length);	
	
	var and = (loc.search(/\?/) != -1) ? '&' : '?';
	var loc = loc + and + 'action=print';
	MM_openBrWindow(loc,'','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=622');
}

// ---- disappearing/reappearing text in the signup and search text field ---------------------------------------


function focusName(element) {		if (element.value == " name...")	{ element.value = ""; }}
function blurName(element) {		if (element.value == "")			{ element.value = " name..."; } }

function focusFirstName(element) {		if (element.value == " first name...")	{ element.value = ""; }}
function blurFirstName(element) {		if (element.value == "")			{ element.value = " first name..."; } }

function focusYourName(element) {	if (element.value == " your name")	{ element.value = ""; } }
function blurYourName(element) { 	if (element.value == "")			{ element.value = " your name"; } }

function focusEmail(element) {		if (element.value == " email...")	{ element.value = ""; } }
function blurEmail(element) {		if (element.value == "")			{ element.value = " email..."; } }

function focusSurname(element) {		if (element.value == " surname...")	{ element.value = ""; } }
function blurSurname(element) {		if (element.value == "")			{ element.value = " surname..."; } }

function focusConfirmEmail(element) {		if (element.value == " confirm email...")	{ element.value = ""; } }
function blurConfirmEmail(element) {		if (element.value == "")			{ element.value = " confirm email..."; } }

function focusYourEmail(element) {	if (element.value == " your email")	{ element.value = ""; } }
function blurYourEmail(element) {	if (element.value == "")			{ element.value = " your email"; } }

function focusKeyword(element) {	if (element.value == " keyword...")	{ element.value = ""; } }
function blurKeyword(element) {		if (element.value == "")			{ element.value = " keyword..."; } }

function focusUsername(element) {	if (element.value == "username")	{ element.value = ""; } }
function blurUsername(element) {	if (element.value == "")			{ element.value = "username"; } }

function focusPassword(element) {	if (element.value == "password")	{ element.value = ""; } }
function blurPassword(element) {	if (element.value == "")			{ element.value = "password"; } }

function focusThis(element, text){ if (element.value == text)	{ element.value = ""; } }
function blurThis(element, text){ if (element.value == "")	{ element.value = text; }}


// ---- Bookmark script --------------------------------------------
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function bookmark(url, description)
	{
	_d = document;
	operaMsg="Please press CTRL+T to bookmark this site.";
	otherMsg="Please press CTRL+D to bookmark this site.";
	// Check what browser is being used
	ie4=(!_d.getElementById&&_d.all)?true:false;
	ieNewer=(navigator.appVersion.indexOf("MSIE")!=-1)?true:false;
	opra=(navigator.userAgent.indexOf("Opera")!=-1)?true:false;
	// If IE is used
	if (ie4 || ieNewer) { window.external.AddFavorite(url, description); }
	// If Opera is used.
	else if (opra) { alert(operaMsg); }
	// If some other browser is used, like Netscape or Mozilla.
	else { alert(otherMsg); }
	}

function openTellAFriend(user, id){
	if (typeof user!='undefined')
	{
		MM_openBrWindow('index.php?process=views/tellAFriend.php&popup=true&&pageId=' + id,'Tell_A_Friend','width=374,height=679');
	} else
	{
		refer = document.location;
		tell_about = document.title;
		openTellAFriend_v2(refer,tell_about);
	}
}

function openTellAFriend_v2(refer_page, tell_about, include_message){
	if (typeof(refer_page)=="undefined") refer_page="";
	if (typeof(tell_about)=="undefined") tell_about="";
	if (typeof(include_message)=="undefined") include_message="";
	MM_openBrWindow('index.php?process=views/tellAFriend.php&popup=true&refer_page='+escape(refer_page)+"&tell_about="+escape(tell_about)+"&include_message="+escape(include_message),'Tell_A_Friend','width=374,height=679');
}

function ValidateForm()
	{
	if (!(document.theForm.firstname.value)) { alert("Please enter your First Name."); return false; }
	if (!isValidEmail(document.theForm.emailadd.value)) { alert("Please enter a VALID Email Address"); return false; }
	return true;
	}


// specifically, for galleryView2 (lightbox) - load image box
function loadImages() {
	
	if (!document.getElementById('hidepage')) return;
	
	if (document.getElementById) {  // DOM3 = IE5, NS6
		document.getElementById('hidepage').style.visibility = 'hidden';
	} else {
		if (document.layers) {  // Netscape 4
			document.hidepage.visibility = 'hidden';
		}else {  // IE 4
			document.all.hidepage.style.visibility = 'hidden';
      }
   }
}

// add a class 'highlight'
function highlight(obj){
	addStyleClass(obj, 'highlight');
}
function lowlight(obj){
	removeStyleClass(obj, 'highlight');
}
	
function addStyleClass(obj, cname){
	if (obj.className.indexOf(cname)<0)
		obj.className += " " + cname;
	return obj;
}
function removeStyleClass(obj, cname){
	var cnameregex = new RegExp(cname, 'gi');
	if (obj != null)
		obj.className = obj.className.replace(cnameregex, "");
	return obj;
}	


// This function decodes the any string
// that's been encoded using URL encoding technique
function URLDecode(psEncodeString){
	var lsRegExp = /\+/g; 	// Create a regular expression to search all +s in the string
	return unescape(String(psEncodeString).replace(lsRegExp, " "));
}

function  getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return URLDecode(pair[1]);
		}
	}
	return false;
}

function is_int(sText){
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++)
		if (ValidChars.indexOf(sText.charAt(i)) == -1)
			IsNumber = false;
	return IsNumber;
}
function is_array(v){
	return (v.constructor.toString().indexOf("Array") >= 0)
}
function is_object(v){
	return (typeof(v)=="object");
}
function urlencode(str) {
	str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	str = str.replace('&', '%26');
	str = str.replace('=', '%3D');
	return str;
}

function urldecode(str) {
	str = str.replace('+', ' ');
	str = unescape(str);
	return str;
}
function http_build_query( formdata, numeric_prefix, key ) {
	var numeric_prefix = (typeof(numeric_prefix)=="undefined") ? null : numeric_prefix;
	var key = (typeof(key)=="undefined") ? null : key;
	var res = new Array();
	for (var k in formdata) {
		var v = formdata[k];
		if (typeof(v)=='function') continue; // skip this, it's not what we want
		var tmp_key = encodeURI( is_int(k) ? new Number(numeric_prefix)+new Number(k) : k);
		if (key) tmp_key = key+'['+tmp_key+']';
		add_to_res  = ( ( is_array(v) || is_object(v) ) ? http_build_query(v, key, tmp_key) : tmp_key+"="+escape(v) );
		res.push(add_to_res);
	}
	separator = '&';
	return res.join(separator);
}

function get_checked_radioObj_value(radioObj){
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";	
}

function text_select_change(show_select, select_field, text_field, change_butt){
	if (show_select){
		select_field.style.display='';
		text_field.style.display='none';				
		change_butt.style.display='none';
		select_field.disabled=false;
		text_field.disabled=true;
	} else {
		select_field.style.display='none';
		text_field.style.display='';		
		change_butt.style.display='';
		select_field.disabled=true;		
		text_field.disabled=false;		
	}
}

in_array = function ( arr, obj ) {
	var len = arr.length;
	for ( var x = 0 ; x <= len ; x++ ) {
		if ( arr[x] == obj ) return true;
	}
	return false;
}

function $(el) {
    if (!el) {
        return null;
    }
    if (el.htmlElement) {
        return Garbage.collect(el);
    }
    if ([window, document].contains(el)) {
        return el;
    }
    var type = $type(el);
    if (type == "string") {
        el = document.getElementById(el);
        type = el ? "element" : false;
    }
    if (type != "element") {
        return null;
    }
    if (el.htmlElement) {
        return Garbage.collect(el);
    }
    if (["object", "embed"].contains(el.tagName.toLowerCase())) {
        return el;
    }
    $extend(el, Element.prototype);
    el.htmlElement = function () {};
    return Garbage.collect(el);
}