<!--
function str_replace(search, replace, subject) {
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
 
    return sa ? s : s[0];
}


function encode_url(url) {
	return escape(url);
}
function decode_url(url) {
	return unescape(url.replace(/\+/g,  " "));
}

function change(id, newClass) {
	var identity = document.getElementById(id);
	identity.className=newClass;
}

function iframeloc(id, url) {
	var identity = document.getElementById(id);	
	identity.src = url;
}

function wchange(id, newClass) {
	var identity = window.opener.document.getElementById(id);
	identity.className=newClass;
}

function miHoverAction(id, newClass) {
		if (miSelected == id) {
			change(id, newClass);
		} 
}

function miHover(id, newClass) {
	miSelected = id;
	//alert(miSelected);
	setTimeout("miHoverAction('"+id+"', '"+newClass+"');", 500);
}

function miClear(id, newClass) {
	change(id, newClass);
	miSelected = '';
}

function printReport() {
	change('layout', 'disappear');
	change('pReport', 'appear print-report');
	print();
	change('pReport', 'disappear');
	change('layout', 'appear');
}

function checkForQuotesAndLength(what,limit) {
		if (limit != "") {
			if (what.value.length>=limit) {
					return false;
				}
		} 
		// A single quote ' = 34 A double quote " = 39
		if ((event.keyCode == 34) || (event.keyCode == 39)) {
			return false;
		}
		//alert(event.keyCode)
}

function Close_ImgDelWindow(type, blankimg) {
	window.opener.document[type].src = blankimg;
	window.opener.document.MWForm['h'+type].value = '';
	window.close();
}

function imgDel(type, blankimg) {
	document[type].src = blankimg;
	document.MWForm['h'+type].value = 'del';
	document.MWForm['hT'+type].value = '';
	change('h'+type+'Add','appear');
	change('h'+type+'Del','disappear');
}

function Close_ImgWindow(id, path, img) {
	//window.opener.document.MWForm.ID.value = id;

//	var base_path = 'http://www.hiddendorset.org/'; // LIVE Server
//	var base_path = 'http://fserver.local/Spaceworks/1424_Website/web/'; // Development Server


	if (path != '') {
		//path = path+'/';	
	}

	//window.opener.document[type].src = base_path+'images/'+ path + 'main/' + img;
	window.opener.document[id].src = path+img;


	window.opener.document.MWForm['h'+id].value = img;
	wchange('h'+id+'Add','disappear');
	wchange('h'+id+'Del','appear');
	window.close();
}

function PopupImgCenterWH(page, width, height, ipathnum) {
	  //var idStr = "&ID="+document.MWForm.ID.value;
	  var top=(screen.height-height)/2;
	  var left=(screen.width-width)/2;
	  window.open(page,"MWPWin","top="+top+",left="+left+",width="+width+",height="+height+","+"menubar=no,scrollbars=no,statusbar=no");
}

/*----------- Mailer Scripts -----------------------------*/

function Close_MailerImgDelWindow(pos) {
	window.opener.document['Img'+pos].src = "../images/mailer/1pxSpacer.gif";
	window.opener.document.MWForm['miImg'+pos].value = '';
	window.close();
}


function Close_MailerImg(pos, miID, img) {
	//window.opener.document.MWForm.pID.value = mmID;
	window.opener.document['Img'+pos].src = "../mailer_images/" + img;
	window.opener.document.MWForm['miImg'+pos].value = miID;
	window.close();
}

function PopupImgLibCenterWH(page, width, height) {
	  var pIDStr = "&pID="+document.MWForm.pID.value;
	  var top=(screen.height-height)/2;
	  var left=(screen.width-width)/2;
	  window.open(page+pIDStr,"MWPWin","top="+top+",left="+left+",width="+width+",height="+height+","+"menubar=no,scrollbars=yes,statusbar=no");
}

function PopupPageCenterWH(page, width, height) {
	  var top=(screen.height-height)/2;
	  var left=(screen.width-width)/2;
	  window.open(page,"MWPWin","top="+top+",left="+left+",width="+width+",height="+height+","+"menubar=no,scrollbars=yes,statusbar=no");
}

function confirm_deleteRVars(id, retID, rVars, tID, pre) {
	if (confirm('Are you sure you want to delete?')) {
		document.location.href = "delete.php?id="+id+"&return="+retID+"&rVars="+rVars+"&tID="+tID+"&pre="+pre;			
	} else {
		return false;
	}
}
/*----------- End Mailer Scripts -------------------------*/

function Close_Refresh()
{
  window.opener.location.reload();
  window.close();
}


function confirm_delete(id, retID, tID, pre) {
	if (confirm('Are you sure you want to delete?')) {
		document.location.href = "delete.php?id="+id+"&return="+retID+"&tID="+tID+"&pre="+pre;			
	} else {
		return false;
	}
}


function make_live($id, $model, $return,$pre) {
	// var base_path = 'http://www.hiddendorset.org/'; // LIVE Server
	var base_path = 'http://www.spaceworks.co.uk/'; // Development Server
	document.location.href = base_path+"index.php/fathomit/qstate/"+$id+"/"+$model+"/"+$return+"/"+$pre;
}


function make_featured(id, qVal, retID, rVar, tID, pre) {
	var base_path = 'http://www.spaceworks.co.uk/'; // LIVE Server

	document.location.href = base_path+"index.php/fathomit/make_featured/"+id+"/"+qVal+"/"+tID+"/"+pre+"/"+retID+"/"+rVar+"/index.html";
}


function IsPopupBlocker() {
	var oWin = window.open("","testpopupblocker","width=100,height=50,top=5000,left=5000");
	if (oWin==null || typeof(oWin)=="undefined") {
		return true;
	} else {
		oWin.close();
		return false;
	}
}


function PopupCenterWH(page, width, height) {
	  var top=(screen.height-height)/2;
	  var left=(screen.width-width)/2;
	  window.open(page,"MWPWin","top="+top+",left="+left+",width="+width+",height="+height+","+"menubar=no,scrollbars=no,statusbar=no");
}

function PopupCenterWHS(page, width, height) {
	  var top=(screen.height-height)/2;
	  var left=(screen.width-width)/2;
	  window.open(page,"MWPWin","top="+top+",left="+left+",width="+width+",height="+height+","+"menubar=no,scrollbars=yes,statusbar=no");
}

function PopupImgCenterWHS(page, width, height) {
	  var pIDStr = "&pID="+document.MWForm.pID.value;
	  var top=(screen.height-height)/2;
	  var left=(screen.width-width)/2;
	  window.open(page+pIDStr,"MWPWin","top="+top+",left="+left+",width="+width+",height="+height+","+"menubar=no,scrollbars=yes,statusbar=no");
}

function ValidateBrochureForm(form) {
	var isValid = true;
	var msg = "The following field(s) need to be filled in correctly:\n";
	// Check each field individually
	if(form.username.value.length == 0 || form.username.value == 'Name') {
		msg += "\tName\n";
		isValid = false;
	}
	if(form.email.value.length == 0 || form.email.value == 'Email' || form.email.value.indexOf('@')<0 || form.email.value.indexOf('.')<0) {
		msg += "\tEmail\n";
		isValid = false;
	}
	// Show the error message to the user
	if(!isValid) alert(msg);
	return isValid;
}
//-->