// THIS SCRIPT FILE IS USED ONLY IN PUBLIC AREAS

// used to select main image from thumbnails
function changeImage(filename,width,height) {
	document.mainimage.src = filename;
	document.mainimage.width = width;
	document.mainimage.height = height;
}

// used to select map image from thumbnails
function changeMapImage(filename,width,height) {
	document.mapimage.src = filename;
	document.mapimage.width = width;
	document.mapimage.height = height;
}

/*
// used to display the contact details iframe viewer
function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
	if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
	if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
	if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

function setIframeHeight(iframeName) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
	// pj removed due to space being added after document
	// iframeEl.style.height = "auto";   
	var docHt = getDocHeight(iframeWin.document);
	if (docHt) iframeEl.style.height = docHt + 0 + "px";
  }
}
*/

var req;
function makeRequest(pageUrl, divElementId, loadinglMessage, pageErrorMessage) {
	if(loadinglMessage) {
		document.getElementById(divElementId).innerHTML = loadinglMessage;
	}
	try {
		req = new XMLHttpRequest(); /* e.g. Firefox */
	} catch(e) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
			} catch (E) {
				req = false;
			} 
		} 
	}
	req.onreadystatechange = function() {responsefromServer(divElementId, pageErrorMessage);};
	req.open("GET",pageUrl,true);
	req.send(null);
}

function responsefromServer(divElementId, pageErrorMessage) {
	var output = '';
	if(req.readyState == 4) {
		if(req.status == 200) {
			output = req.responseText;
			document.getElementById(divElementId).innerHTML = output; // not using parseScript(output)
		} else {
			document.getElementById(divElementId).innerHTML = pageErrorMessage+"\n"+output;
		}
	}
}

function parseScript(_source) {
	var source = _source;
	var scripts = new Array();

	// Strip out tags
	while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
		var s = source.indexOf("<script");
		var s_e = source.indexOf(">", s);
		var e = source.indexOf("</script", s);
		var e_e = source.indexOf(">", e);

		// Add to scripts array
		scripts.push(source.substring(s_e+1, e));
		// Strip from source
		source = source.substring(0, s) + source.substring(e_e+1);
	}

	// Loop through every script collected and eval it
	for(var i=0; i<scripts.length; i++) {
		try {
			eval(scripts[i]);
		}
		catch(ex) {
			// do what you want here when a script fails
		}
	}
	// Return the cleaned source
	return source;

}

///////////////////////////////////////////////////
///////////////////////////////////////////////////


// <!-- Begin resize iframe, does the resizing of the iframe for the selectors in add and modify forms
function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
	if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
	if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
	if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

function setIframeHeight(iframeName) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
	iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
	var docHt = getDocHeight(iframeWin.document);
	// need to add to height to be sure it will all show
	if (docHt) iframeEl.style.height = docHt + 25 + "px";
  }
}
// End -->

function loadIframe(iframeName, url) {
  if ( window.frames[iframeName] ) {
	window.frames[iframeName].location = url;   
	return false;
  }
  else return true;
}

// <!-- Begin category list view 
function openCategoryList(url) {
	var win = window.open(url, "category_list", "scrollbars,top=50,left=50,alwaysRaised=1,height=580,width=500");
	win.focus();
}
// End -->

function explain(msg) {
	newwin = window.open('','help_window','scrollbars,top=150,left=150,width=440,height=460');
	if (!newwin.opener) newwin.opener = self;
	with (newwin.document) {
		open();
		write('<html><head><title>Help</title></head>');
		write('<body onLoad="focus()" leftmargin="10" topmargin="10"><p><input type=button style="background-color: COCOCO; border-color: 555555; border-width: 1; font-size: 10pt; font-family: arial;" value="Click to close when finished" onClick=window.close()></p>');
		write('<p>' + msg + '</p>');
		write('</body></html>');
		close();
	}
}

function mod_window(url,width,height) { 
	window.open(url,'mod_window','width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes'); 
} 

var submitted = false;
function SubmitTheForm() {
	if(submitted == true) { 
		return; 
	}
	document.myform.submit();
	document.myform.mybutton.value = '  Sending... please wait... ';
	document.myform.mybutton.disabled = true;

	document.myform.myremovebutton.disabled = true;
	submitted = true;
}

// <!-- Begin changes bgcolors in table cells of availability calendars
function highlightRow (el, color) {

	border = "1px black solid";
	color=el.checked?color:'#66FF66';
	border=el.checked?border:'1px black solid';

	while (el.tagName.toUpperCase() != 'TD' && el != null)
		el = el.parentNode;
	if (el)
		el.style.backgroundColor = color;
		el.style.border = border;

}
// End -->

// <!-- Begin textarea number of characters limiter  
function taLimit() {
	var taObj=event.srcElement;
	if (taObj.value.length==taObj.maxLength*1) return false;
}
// End -->
// <!-- Begin textarea number of characters counter  
function taCount(visCnt) { 
	var taObj=event.srcElement;
	if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
	if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}
// End -->
// <!-- Begin text box number of characters limiter  
function taLimitBox() {
	var taObj=event.srcElement;
	if (taObj.value.length==taObj.size*1) return false;
}
// End -->
// <!-- Begin text box number of characters counter  
function taCountBox(visCnt) { 
	var taObj=event.srcElement;
	if (taObj.value.length>taObj.size*1) taObj.value=taObj.value.substring(0,taObj.size*1);
	if (visCnt) visCnt.innerText=taObj.size-taObj.value.length;
}
// End -->

// <!-- Begin swapping of map imag when viewed 
function SwapImage1(url,width,height) {
	document.map.src=url;
	document.map.width=width;
	document.map.height=height;
}
// End -->

