/* =================================================================================

   SCRI JS Library 
   Last Updated: 22 April 2008

================================================================================= */


// User edit warning

function setConfirmUnload(on) {
     window.onbeforeunload = (on) ? unloadMessage : null;
}

function unloadMessage() {
     return 'You have entered new data on this page.  If you navigate away from this page without first saving your data, the changes will be lost.';
}


// Menu code
function show(id) {
		var d = document.getElementById(id);
		for (var i = 1; i<=10; i++) {
			if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
		}
		if (d) {d.style.display='block';}
		}


// Collapsing Divs v.1.0
	function expandCollapse() {
		for (var i=0; i<expandCollapse.arguments.length; i++) {
		var element = document.getElementById(expandCollapse.arguments[i]);
		element.style.display = (element.style.display == "none") ? "block" : "none";
	}
}


//Contact form (shows/hides optional fields)
function optionfields() {

	if(document.getElementById)
	{
		var linkContainer = document.getElementById('fm-intro');
		var toggle = linkContainer.appendChild(document.createElement('a'));
		toggle.href = '#';
		toggle.appendChild(document.createTextNode(' Hide optional fields?'));
		toggle.onclick = function()
		{
			var linkText = this.firstChild.nodeValue;
			this.firstChild.nodeValue = (linkText == ' Hide optional fields?') ? ' Display optional fields?' : ' Hide optional fields?';
			
			var tmp = document.getElementsByTagName('div');
			for (var i=0;i<tmp.length;i++)
			{
				if(tmp[i].className == 'fm-opt')
				{
					tmp[i].style.display = (tmp[i].style.display == 'none') ? 'block' : 'none';
				}
			}
			return false;
		}
	}
}


//clears inputs on form
function doClear(theText) {
if (theText.value == theText.defaultValue) {
theText.value = ""
}
}

function doReturn(theText) {
theText.value = theText.defaultValue
}


//Text Counter for Form Field
function textCounter (field, countfield, maxlimit)
  {
  	if (field.value.length > maxlimit)
  	field.value = field.value.substring(0, maxlimit);
  	else
  	countfield.value = maxlimit - field.value.length;
}


//IP address
function ipval() {
document.myform.ipaddr.value=ip;
	var ip = '<!--#echo var="REMOTE_ADDR"-->'
	window.onload=ipval
}



//New Window
var newwindow;
function popitup(url)
{

	var x = document.forms[0].elements;
	var properties = '';
	for (var i=0;i<x.length;i++)
	{
		if (x[i].checked)
			properties += x[i].name + '=' + x[i].value +',';
	}
	properties = properties.substring(0,properties.length-1);
	newwindow=window.open(url,'name','height=120,width=250');
	newwindow.moveTo(400,400);
	if (window.focus) {newwindow.focus()}
	return false;
}