// JavaScript Document

ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
ns6 = ((!document.all) && (document.getElementById))? true:false 
// JavaScript Document.... created by Click4Designers...  Chris Ruecker
//	alert('Divname: ' + divname + ' & divnameName: ' + divname + '  TEST HERE!!!')


function getObj(id)
{
  if (ns6)
  {
  	this.obj = document.getElementById(id);
	this.style = document.getElementById(id).style;
  }
  else if (ie4)
  {
	this.obj = document.all[id];
	this.style = document.all[id].style;
  }
  else if (ns4)
  {
	this.obj = getObjNN4(document,id);
	this.style = this.obj;
  }
}

function getObjNN4(obj,id)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == id)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],id);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

function getIndex(form_name,this_element) {
var form_Short = new getObj(form_name);
    for (var i=0;i<form_Short.obj.elements.length;i++)	{
        if (this_element == form_Short.obj.elements[i].name)	{
            return i;	}
		}
    return -1;
}

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

// basic javascript fnctions not included already
function LTrim(str){if(str==null){return null;}for(var i=0;str.charAt(i)==" ";i++);return str.substring(i,str.length);}
function RTrim(str){if(str==null){return null;}for(var i=str.length-1;str.charAt(i)==" ";i--);return str.substring(0,i+1);}
function Trim(str){return LTrim(RTrim(str));}
function LTrimAll(str){if(str==null){return str;}for(var i=0;str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t";i++);return str.substring(i,str.length);}
function RTrimAll(str){if(str==null){return str;}for(var i=str.length-1;str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t";i--);return str.substring(0,i+1);}
function TrimAll(str){return LTrimAll(RTrimAll(str));}
function isNull(val){return(val==null);}
function isBlank(val){if(val==null){return true;}for(var i=0;i<val.length;i++){if((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}}return true;}
function isInteger(val){if(isBlank(val)){return false;}for(var i=0;i<val.length;i++){if(!isDigit(val.charAt(i))){return false;}}return true;}
function isNumeric(val){return(parseFloat(val,10)==(val*1));}
function isArray(obj){return(typeof(obj.length)=="undefined")?false:true;}
function isDigit(num){if(num.length>1){return false;}var string="1234567890";if(string.indexOf(num)!=-1){return true;}return false;}
function setNullIfBlank(obj){if(isBlank(obj.value)){obj.value="";}}
function setFieldsToUpperCase(){for(var i=0;i<arguments.length;i++){arguments[i].value = arguments[i].value.toUpperCase();}}

/** * Gets the selected value of the specified radio button set. * @param  sForm   the form name * @param  sRadio  the radio button set name * @return  the selected value or null */
function getRadioValue(sForm, sRadio) {	if(typeof(document.forms[sForm]) == 'undefined') {		return null;	}	var oForm = document.forms[sForm];	if(typeof(oForm[sRadio]) == 'undefined') {		return null;	}	var oRadio = oForm[sRadio];	if(typeof(oRadio.length) == "undefined") {		if(oRadio.checked) {			return oRadio.value;		}	} else {		for(var i = 0; i < oRadio.length; i++) {			if(oRadio[i].checked) {				return oRadio[i].value;			}		}	}	return null;}
/** * Sets the selected value of the specified radio button set. * @param  sForm   the form name * @param  sRadio  the radio button set name * @param  sValue  the value to set * @return  the selected value or null */
function setRadioValue(sForm, sRadio, sValue) {	if(typeof(document.forms[sForm]) == 'undefined') {		return;	}	var oForm = document.forms[sForm];	if(typeof(oForm[sRadio]) == 'undefined') {		return;	}	var oRadio = oForm[sRadio];	if(typeof(oRadio.length) == "undefined") {		if(oRadio.value == sValue) {			oRadio.checked = true;		}	} else {		for(var i = 0; i < oRadio.length; i++) {			if(oRadio[i].value == sValue) {				oRadio[i].checked = true;			}		}	}}


var lengthTallyArray = new Array();
var lengthTallySum = 0;
var oneMoreUp = false;
var twoMoreUp = false;
function check_length(fieldName,fieldLength,fieldMaxLength,tagLine,tagError,tagErrorSecond)	{
	// DO NOTHING
	}
function check_lengthTEST(fieldName,fieldLength,fieldMaxLength,tagLine,tagError,tagErrorSecond)	{
	var alertMsg = '';
//	alert(fieldName.name);
	var fieldTitle = fieldName.name;
	alertMsg += 'name:' + fieldTitle;
	if (fieldName.type == 'text' || fieldName.type == 'textarea' || fieldName.type == 'password')	{
		var percent = Math.round((fieldLength/fieldMaxLength ) * 100) ;
//alertMsg += '\ntagLine: ' +  tagLine;
		if ((ns4 || ns6) && fieldName.parentNode.id != 'formInput')	{	oneMoreUp = true;	tagError = 1;	tagLine = 3;	}
		}	else if (fieldName.type == 'checkbox' || fieldName.type == 'radio')	{
		var totalChecked = 0;
		if (ie4)	{
			var elementLength = fieldName.parentElement.parentElement.all.length;
			for (var idx = 0; idx < elementLength; idx++) {
				alertMsg += '\n' + idx + ' =  ' + fieldName.parentElement.parentElement.all[idx].name + ' ... ' + fieldName.parentElement.parentElement.all[idx].tagName;
				if (fieldName.parentElement.parentElement.all[idx].checked == true) {
				    totalChecked += 1;
					}
				}
			}	else if (ns4 || ns6)	{
			var elementLength = fieldName.parentNode.parentNode.childNodes.length;
			for (var idx = 0; idx < elementLength; idx++) {
				if (fieldName.parentNode.parentNode.childNodes[idx].childNodes[0] && fieldName.parentNode.parentNode.childNodes[idx].childNodes[0].checked == true)	{
					totalChecked += 1;
					}
				}
			tagError = 1;	tagLine = 3;	// in Mozilla, childNodes are grouped, and not counted as individual tags, therefore, math needs to be envoked
			}
		var percent = Math.round((totalChecked/fieldMaxLength ) * 100) ;
		var threeMoreUp=true;
		fieldLength = totalChecked;
		}	else if (fieldName.type == 'select-multiple' || fieldName.type == 'select-one')	{
		var totalSelected = 0;
		var elementLength = fieldName.length;
		for (var idx = 0; idx < elementLength; idx++) {
			if (fieldName[idx].selected) {
			    totalSelected += 1;
 			  }
			}
		alertMsg += '\nTotalSelected: ' + totalSelected;
		var percent = Math.round((totalSelected/fieldMaxLength ) * 100) ;
		fieldLength = totalSelected;
		if (ns4 || ns6)	{	tagError = 1;	tagLine = 3;	}	// in Mozilla, childNodes are grouped, and not counted as individual tags, therefore, math needs to be envoked
		}	else	{
		return false;
		}
//alertMsg += '\npercent: ' +  percent;
//alertMsg += '\nparentElement: ' + fieldName.parentNode.parentNode.tagName;
//alertMsg += '\nOneUp: ' + twoMoreUp;
	if (ie4 && threeMoreUp)	{
		var fieldName2 = fieldName.parentElement.parentElement.parentElement;
	}	else if ((ns4 || ns6) && threeMoreUp)	{
		var fieldName2 = fieldName.parentNode.parentNode.parentNode;
	}	else if (ie4 && twoMoreUp)	{
		var fieldName2 = fieldName.parentElement.parentElement;
	}	else if ((ns4 || ns6) && twoMoreUp)	{
		var fieldName2 = fieldName.parentNode.parentNode;
	}	else if (ie4 && oneMoreUp)	{
		var fieldName2 = fieldName.parentElement;
	}	else if ((ns4 || ns6) && oneMoreUp)	{
		var fieldName2 = fieldName.parentNode;
	}	else	{
		var fieldName2 = fieldName;
	}
//alertMsg += '\nfieldName2: ' + fieldName2.parentNode.childNodes[2].id;
//if (ns4 || ns6)	{	alert(alertMsg);	return false;	}
//	alert('name: ' + fieldName2.parentElement.all[tagLine].name + '\nid: ' + fieldName2.parentElement.all[tagLine].id);
//	if (!tagErrorSecond)
//		var tagError2 = tagLine + 3;
//		else
//		var tagError2 = tagErrorSecond;
	if (percent > 100)	{
		lengthTallyArray[fieldTitle] = (fieldLength - fieldMaxLength);
		if (ie4)	{
			fieldName2.parentElement.all[tagError].innerHTML = '&Oslash;&nbsp;' + (fieldLength - fieldMaxLength);
			fieldName2.parentElement.all[tagLine].style.width = '100%';
			fieldName2.parentElement.all[tagLine].style.background = '#D90000';
//			fieldName.parentElement.all[tagError2].innerHTML = 'Too many characters... please remove to get below ' + fieldMaxLength + '.';
			}	else if (ns4 || ns6)	{
			fieldName2.parentNode.childNodes[tagError+2].innerHTML = '&Oslash;&nbsp;' + (fieldLength - fieldMaxLength);
			fieldName2.parentNode.childNodes[tagLine+2].childNodes[0].style.width = '100%';
			fieldName2.parentNode.childNodes[tagLine+2].childNodes[0].style.background = '#D90000';
			}
		}	else	{
		lengthTallyArray[fieldTitle] = 0;
		if (ie4)	{
			fieldName2.parentElement.all[tagError].innerHTML = '&nbsp;';
			fieldName2.parentElement.all[tagLine].style.width = percent + '%';
			fieldName2.parentElement.all[tagLine].style.background = '#1059CE';
//			fieldName.parentElement.all[tagError2].innerHTML = '';
			}	else if (ns4 || ns6)	{
			fieldName2.parentNode.childNodes[tagError+2].innerHTML = '&nbsp;';
			fieldName2.parentNode.childNodes[tagLine+2].childNodes[0].style.width = percent + '%';
			fieldName2.parentNode.childNodes[tagLine+2].childNodes[0].style.background = '#1059CE';
			}
		}
	  lengthTallySum = 0;
	  for (anItem in lengthTallyArray)	{
	    lengthTallySum = lengthTallySum + lengthTallyArray[anItem];
		}
//	window.status = 'tallycount: for ' + fieldTitle  + '    sum: ' + lengthTallySum;
twoMoreUp = false;
oneMoreUp = false;
}

function stretch_shadows()	{
	if (ie4) {	var height = document.body.scrollHeight; var browserAdjust = 0; 	}
	if (ns4 || ns6) {	var height = document.documentElement.scrollHeight; var browserAdjust = 0; 	}
	var containerDiv = new getObj('container');
	containerDiv.style.height = (height-browserAdjust)+'px'; 		// need to add 32 for unknown reason
//	alert('Window Height: ' + height + '\nrightShort Height:' + rightShort.style.height);
	}




// Let's get the height of the available window for all browsers

function getWindowHeight()
{
var windowHeight = 0;
if (typeof(window.innerHeight) == 'number')
{
windowHeight = document.documentElement.scrollHeight;
}
else
{
if (document.documentElement && document.documentElement.clientHeight)
{
windowHeight = document.documentElement.clientHeight;
}
else
{
if (document.body && document.body.clientHeight)
{
windowHeight = document.body.clientHeight;
}
}
}
return windowHeight;
}


function setLayout(divName,offset)
{
if (document.getElementById)
{
var windowHeight = getWindowHeight();
var layoutElement = document.getElementById(divName);
var layoutHeight = layoutElement.offsetHeight;

// if the viewport is longer than the content, stretch the content
if (windowHeight > layoutHeight)
{

layoutElement.style.height = (windowHeight + offset) + 'px';
}
}
}

/*
window.onload = function()
{
setLayout('container',85); // offset contingent on height of bottom panel
setLayout('topLeftColumn',-139); // offset contingent on height of left panel
setLayout('topRightColumn',-110); // offset contingent on height of right panel
}

window.onresize = function()
{
setLayout('container',85); // offset contingent on height of bottom panel
setLayout('topLeftColumn',-139); // offset contingent on height of left panel
setLayout('topRightColumn',-110); // offset contingent on height of right panel
}
*/

function formReset(formNum)	{
//alert('formNum: ' + formNum + '\nform elements length: ' + document.forms[formNum].elements.length);
	for (k=document.forms[formNum].elements.length;k>0;k--)	{
		if (document.forms[formNum].elements[k-1].type != 'hidden' && document.forms[formNum].elements[k-1].tagName != 'SELECT')	{
			alert('k= ' + (k-1) + '\nform element type: ' + document.forms[formNum].elements[k-1].type + '\n\ntagName= ' + document.forms[formNum].elements[k-1].tagName + '\nfocused: ' + document.forms[formNum].elements[k-1].name);
			if (document.forms[formNum].elements[k-1].captureEvents)
				alert('Javascript: ' + document.forms[formNum].elements[k-1].captureEvents);
			document.forms[formNum].elements[k-1].focus();
			}	else	{
			alert('k= ' + (k-1) + '\nform element type: ' + document.forms[formNum].elements[k-1].type);
			}
		}
	}

function formResetLoop()	{
	for (i=document.forms.length;i>0;i--)	{
//		alert('i= ' + (i-1) + '\nformResetLoop: length: ' + document.forms.length + '\nformName: ' + document.forms[i-1].id);
		formReset(i-1);
		}
	}
	

//window.document.onload = formResetLoop();

/*		CHANGING STYLE SHEET ATTRIBUTES	*/

var ugly_selectorText_workaround_flag = false;
var allStyleRules;
function ugly_selectorText_workaround() {
	if((navigator.userAgent.indexOf("Gecko") == -1) ||
	   (ugly_selectorText_workaround_flag)) {
		return; // we've already been here or shouldn't be here
	}
	var styleElements = document.getElementsByTagName("style");
	
	for(var i = 0; i < styleElements.length; i++) {
		var styleText = styleElements[i].firstChild.data;
		// this should be using match(/\b[\w-.]+(?=\s*\{)/g but ?= causes an
		// error in IE5, so we include the open brace and then strip it
		allStyleRules = styleText.match(/\b[\w-.]+(\s*\{)/g);
	}

	for(var i = 0; i < allStyleRules.length; i++) {
		// probably insufficient for people who like random gobs of 
		// whitespace in their styles
		allStyleRules[i] = allStyleRules[i].substr(0, (allStyleRules[i].length - 2));
	}
	ugly_selectorText_workaround_flag = true;
}


// setStyleById: given an element id, style property and 
// value, apply the style.
// args:
//  i - element id
//  p - property
//  v - value
//
function setStyleById(i, p, v) {
	var n = document.getElementById(i);
	n.style[p] = v;
}

// getStyleById: given an element ID and style property
// return the current setting for that property, or null.
// args:
//  i - element id
//  p - property
function getStyleById(i, p) {
	var n = document.getElementById(i);
	var s = eval("n.style." + p);

	// try inline
	if((s != "") && (s != null)) {
		return s;
	}

	// try currentStyle
	if(n.currentStyle) {
		var s = eval("n.currentStyle." + p);
		if((s != "") && (s != null)) {
			return s;
		}
	}
	
	// try styleSheets
	var sheets = document.styleSheets;
	if(sheets.length > 0) {
		// loop over each sheet
		for(var x = 0; x < sheets.length; x++) {
			// grab stylesheet rules
			var rules = sheets[x].cssRules;
			if(rules.length > 0) {
				// check each rule
				for(var y = 0; y < rules.length; y++) {
					var z = rules[y].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if(allStyleRules[y] == i) {
							return z[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((z[p] != "") && (z[p] != null)) ||
						   (rules[y].selectorText == i)) {
							return z[p];
						}
					}
				}
			}
		}
	}
	return null;
}

// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - class name
//  p - CSS property
//  v - value
var ie = (document.all) ? true : false;

function setStyleByClass(t,c,p,v){
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}

// getStyleByClass: given an element type, a class selector and a property,
// return the value of the property for that element type.
// args:
//  t - element type
//  c - class identifier
//  p - CSS property
function getStyleByClass(t, c, p) {
	// first loop over elements, because if they've been modified they
	// will contain style data more recent than that in the stylesheet
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					var theStyle = eval('node.style.' + p);
					if((theStyle != "") && (theStyle != null)) {
						return theStyle;
					}
				}
			}
		}		
	}
	// if we got here it's because we didn't find anything
	// try styleSheets
	var sheets = document.styleSheets;
	if(sheets.length > 0) {
		// loop over each sheet
		for(var x = 0; x < sheets.length; x++) {
			// grab stylesheet rules
			var rules = sheets[x].cssRules;
			if(rules.length > 0) {
				// check each rule
				for(var y = 0; y < rules.length; y++) {
					var z = rules[y].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if((allStyleRules[y] == c) ||
						   (allStyleRules[y] == (t + "." + c))) {
							return z[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((z[p] != "") && (z[p] != null)) &&
						   ((rules[y].selectorText == c) ||
						    (rules[y].selectorText == (t + "." + c)))) {
							return z[p];
						}
					}
				}
			}
		}
	}

	return null;
}

// setStyleByTag: given an element type, style property and 
// value, and whether the property should override inline styles or
// just global stylesheet preferences, apply the style.
// args:
//  e - element type or id
//  p - property
//  v - value
//  g - boolean 0: modify global only; 1: modify all elements in document
function setStyleByTag(e, p, v, g) {
	if(g) {
		var elements = document.getElementsByTagName(e);
		for(var i = 0; i < elements.length; i++) {
			elements.item(i).style[p] = v;
		}
	} else {
		var sheets = document.styleSheets;
		if(sheets.length > 0) {
			for(var i = 0; i < sheets.length; i++) {
				var rules = sheets[i].cssRules;
				if(rules.length > 0) {
					for(var j = 0; j < rules.length; j++) {
						var s = rules[j].style;
						// selectorText broken in NS 6/Mozilla: see
						// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
						ugly_selectorText_workaround();
						if(allStyleRules) {
							if(allStyleRules[j] == e) {
								s[p] = v;
							}			
						} else {
							// use the native selectorText and style stuff
							if(((s[p] != "") && (s[p] != null)) &&
							   (rules[j].selectorText == e)) {
								s[p] = v;
							}
						}

					}
				}
			}
		}
	}
}

// getStyleByTag: given an element type and style property, return
// the property's value
// args:
//  e - element type
//  p - property
function getStyleByTag(e, p) {
	var sheets = document.styleSheets;
	if(sheets.length > 0) {
		for(var i = 0; i < sheets.length; i++) {
			var rules = sheets[i].cssRules;
			if(rules.length > 0) {
				for(var j = 0; j < rules.length; j++) {
					var s = rules[j].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if(allStyleRules[j] == e) {
							return s[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((s[p] != "") && (s[p] != null)) &&
						   (rules[j].selectorText == e)) {
							return s[p];
						}
					}

				}
			}
		}
	}

	// if we don't find any style sheets, return the value for the first
	// element of this type we encounter without a CLASS or STYLE attribute
	var elements = document.getElementsByTagName(e);
	var sawClassOrStyleAttribute = false;
	for(var i = 0; i < elements.length; i++) {
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if((node.attributes.item(j).nodeName == 'class') ||
			   (node.attributes.item(j).nodeName == 'style')){
			   sawClassOrStyleAttribute = true;
			}
		}
		if(! sawClassOrStyleAttribute) {
			return elements.item(i).style[p];
		}
	}
}

