/* app_shared.js */

/* Form behavior */

// Used to display the popouts in the same style/format as UC - Reg app.
function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >=4) { win.window.focus(); }
}

/* Validate form -- Helper function */
function validateThisFormField(ThisFormFieldName, ThisMessage) {
	//alert(ThisFormFieldName)
	ThisFormFieldName = '' + ThisFormFieldName // fixes it for FireFox
	if (document.getElementById(ThisFormFieldName).value.length == 0){
		validateDisplayHelper(ThisFormFieldName,ThisMessage,1)
		ThisResult = false
	} else {
		validateDisplayHelper(ThisFormFieldName,'',0)
		ThisResult = true
	}
	return ThisResult
}

/* Validate form -- Helper function */
function validateDisplayHelper(ThisFormFieldName, ThisMessage, ThisValue) {
	//alert(ThisFormFieldName)
	ThisFormFieldName = '' + ThisFormFieldName // fixes it for FireFox
	ThisMessage       = '' + ThisMessage       // fixes it for FireFox
	document.getElementById(ThisFormFieldName).value = Trim(document.getElementById(ThisFormFieldName).value) // Trim() is three JS functions
	document.getElementById("err_" + ThisFormFieldName).innerHTML = ThisMessage
	ValidationErrorCounter = ValidationErrorCounter + ThisValue
}

/* Validate form -- Helper function */
function validateRadioButtons(ThisRadioButtonGroupName) {
	var ValidationErrorCounter = false
	var ThisRadioGroup = document.getElementsByName(ThisRadioButtonGroupName)
	for (i=0; i<ThisRadioGroup.length; i++) {
		if (ThisRadioGroup[i].checked == true) {
			ValidationErrorCounter = true
		}
	}
	if (ValidationErrorCounter == false) {
		return false
	}
	return true
}

/* Validate form -- Helper function */
function LTrim(str) { 
	for (var k=0; k<str.length && str.charAt(k)<=" " ; k++) ;
	return str.substring(k,str.length);
}
function RTrim(str) {
	for (var j=str.length-1; j>=0 && str.charAt(j)<=" " ; j--) ;
	return str.substring(0,j+1);
}
function Trim(str) {
	return LTrim(RTrim(str));
}

/* Validate form -- Helper function */
var ThisColor = "#FFDEE4"

function colorSwitcher(ThisDivID) {
	if ( ThisColor == "#FFDEE4" || ThisColor == "" ) {
		ThisColor = "#FFFFDF" // manila
	} else {
		ThisColor = "#FFDEE4" // off-pink
	}
	document.getElementById(ThisDivID).style.backgroundColor = ThisColor
}

