

function swing_riding_selectValueSet(SelectName, Value) {
	 eval('SelectObject = document.' + SelectName + ';');
	 for(index = 0; index < SelectObject.length; index++) {
		if(SelectObject[index].value == Value)
		   SelectObject.selectedIndex = index;
	}
}


// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function swing_riding_setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}


function swing_riding_getFieldById(fieldId){
	if      (document.layers)         { return document.layers[fieldId]; }
	else if (document.all)            { return document.all[fieldId]; } 
	else if (document.getElementById) { return document.getElementById(fieldId); }
	else 							  { return null; }
}


function swing_riding_isBlank(element) {
	if (element==null)     {return true;}
	if (element.length==0) {return true;}
	return false;     
}


function swing_riding_isNum(num,which,min,max)
{
  switch (which) {
    case 1: re = /^\d+$/; break;  //whole positive number
    case 2: re = /^-?\d+$/; break;  //Any whole number
    case 3: re = /^-?\d+\.\d*$/; break;  //Any real number with decimal point:
    case 4: re = /^\d+\.\d$/; break;  //Any positive real number with a single decimal part:
    case 5: re = /^\d+(\.\d*)?$/; break;  //Any positive real number with or without decimal part:
    case 6: re = /^-?\d+(\.\d*)?$/; break;  //Any real number with or without decimal part:
    case 7: re = new RegExp("^-?\\d+(\\.\\d{" + min + "," + max + "})?$");  break; //Any real number with set number of decimal places.
  }
  return re.test(num);
}


function swing_riding_formatPercent(field) {
    // Update the field just changed to 
	if ( !swing_riding_isNum(field.value,4) ) {
	    fieldValue = parseFloat(swing_riding_isNum(field.value,5)?field.value:0);
		field.value = fieldValue.toFixed(1);
	}
}


function swing_riding_setElementVisibility(fieldId, showItSwitch ){
	newState = (showItSwitch ? 'inline' : 'none');
	if (document.layers) {
		document.layers[fieldId].display = newState;
	} else if (document.all) {
		document.all[fieldId].style.display = newState;
	} else if (document.getElementById)	{
		document.getElementById(fieldId).style.display = newState;
	}
}
function swing_riding_hideTable(fieldId){
	swing_riding_setElementVisibility(fieldId, false);
}
function swing_riding_showTable(fieldId){
	swing_riding_setElementVisibility(fieldId, true);
}


/**
   NOT CURRENTLY NEEDED
   
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/


function swing_riding_trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function swing_riding_ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function swing_riding_rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
**/

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ALL OF THIS CAN GO AWAY IF WE REPLACE THE "makeAlert" CALLS
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function BrowserCheck() {
var b = navigator.appName;
if (b == "Netscape") this.b = "NS";
else if (b == "Microsoft Internet Explorer") this.b = "IE";
else this.b = b;
this.v = parseInt(navigator.appVersion);
this.NS = (this.b == "NS" && this.v>=4);
this.NS4 = (this.b == "NS" && this.v == 4);
this.NS5 = (this.b == "NS" && this.v == 5);
this.IE = (this.b == "IE" && this.v>=4);
this.IE4 = (navigator.userAgent.indexOf('MSIE 4')>0);
this.IE5 = (navigator.userAgent.indexOf('MSIE 5')>0);
if (this.IE5 || this.NS5) this.VER5 = true;
if (this.IE4 || this.NS4) this.VER4 = true;
this.OLD = (! this.VER5 && ! this.VER4) ? true : false;
this.min = (this.NS||this.IE);
}

function hideAlert(){
alertBox.visibility = "hidden";
window.location=destinationWindow;}

function makeAlert(aTitle,aMessage){
document.all.alertLayer.innerHTML = "<table border=0 width=100% height=100%>" +
"<tr height=5><td colspan=4 class=alertTitle>" + " " + aTitle + "</td></tr>" +
"<tr height=5><td width=5></td></tr>" +
"<tr><td width=5></td><td width=20 align=left><img src='../images/alert.gif'></td><td align=center class=alertMessage>" + aMessage + "<BR></td><td width=5></td></tr>" + 
"<tr height=5><td width=5></td></tr>" +
"<tr><td width=5></td><td colspan=2 align=center><input type=button value='OK' onClick='hideAlert()' class=okButton><BR></td><td width=5></td></tr>" +
"<tr height=5><td width=5></td></tr></table>";
thisText = aMessage.length;
if (aTitle.length > aMessage.length){ thisText = aTitle.length; }

aWidth = (thisText * 5) + 80;
aHeight = 100;
if (aWidth < 150){ aWidth = 200; }
if (aWidth > 350){ aWidth = 350; }
if (thisText > 60){ aHeight = 110; }
if (thisText > 120){ aHeight = 130; }
if (thisText > 180){ aHeight = 150; }
if (thisText > 240){ aHeight = 170; }
if (thisText > 300){ aHeight = 190; }
if (thisText > 360){ aHeight = 210; }
if (thisText > 420){ aHeight = 230; }
if (thisText > 490){ aHeight = 250; }
if (thisText > 550){ aHeight = 270; }
if (thisText > 610){ aHeight = 290; }

alertBox.width = aWidth;
alertBox.height = aHeight;
alertBox.left = (document.body.clientWidth - aWidth)/2;
alertBox.top = (document.body.clientHeight - aHeight)/2;

alertBox.visibility = "visible";
}

// WHEN YOU WANT TO GENERATE AN ALERT DO THIS:
// CALL THE makeAlert FUNCTION AND PASS THE ALERT TITLE AND THE MESSAGE
// TO THE FUNCTION.
// eg. makeAlert('My Alert Title' , 'My Alert Message'); 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// END OF WHAT CAN BE DELETED IF WE GET RID OF THE makeAlert CALLS
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////
//************************* BEGINNING OF DATE VALIDATION CODE *******************************
/////////////////////////////////////////////////////////////////////////////////////////////

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year, year format is yyyy-mm-dd
var dtCh= "-";
var minYear=2004;
var maxYear=2009;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strYear=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : yyyy-mm-dd")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}
/////////////////////////////////////////////////////////////////////////
//***************** END OF DATE VALIDATION CODE *************************
/////////////////////////////////////////////////////////////////////////
