<!--

//--------------------------------------------
//        Various Utility Functions
//--------------------------------------------
function zeroPad(n, totalDigits) 
    { 
        n = n.toString(); 
        var pd = ''; 
        if (totalDigits > n.length) 
        { 
            for (var i=0; i < (totalDigits-n.length); i++) 
            { 
                pd += '0'; 
            } 
        } 
        return pd + n.toString(); 
    } 

function checkleapyear(datea)
{
	datea = parseInt(datea);

	if(datea%4 == 0)
	{
		if(datea%100 != 0)
		{
			return true;
		}
		else
		{
			if(datea%400 == 0)
				return true;
			else
				return false;
		}
	}
return false;
}

function setOptionsBeta(cbMonth, cbDay, cbYear){
var chosen = cbMonth.options[cbMonth.selectedIndex].value;
cbDay.options.length=0;

if (chosen==" "){
	cbDay.options[0] = new Option('Please select month first',' ');
	}

if (chosen == "01" || chosen == "03" || chosen == "05" || chosen == "07"  || chosen == "08"  || chosen == "10" || chosen == "12") {
	for (var i = 1; i<=31; i++) {
		cbDay.options[cbDay.options.length] = new Option(zeroPad(i,2),zeroPad(i,2));
		}
	}

if (chosen == "04" || chosen == "06" || chosen == "09"  || chosen == "11") {
	for (var i = 1; i<=30; i++) {
		cbDay.options[cbDay.options.length] = new Option(zeroPad(i,2),zeroPad(i,2));
		}
	}
	
if (chosen == "02") {
  for (var i = 1; i<=28; i++) {
	cbDay.options[cbDay.options.length] = new Option(zeroPad(i,2),zeroPad(i,2));
	}
	if (checkleapyear(cbYear.options[cbYear.selectedIndex].value)) {
		cbDay.options[cbDay.options.length]  = new Option('29','29');
		}
	
}

}

function matchPulldownToValue(pulldown,value,fireOnChange) {
var i, len;
len = pulldown.options.length;
for (i=0;i<len;i++){
	if (pulldown.options[i].value.toLowerCase()==value.toString().toLowerCase()) {
		pulldown.options[i].selected=true;
		if (fireOnChange==true) {
			pulldown.onchange();
			}
		}
	}
}

function matchRadioToValue(radio,value,fireOnClick) {
var i, len;
len = radio.length;
for (i=0;i<len;i++){
	if (radio[i].value.toLowerCase()==value.toLowerCase()) { 
		radio[i].checked=true;
		if (fireOnClick==true) {
			if (radio[i].onclick) {
				radio[i].onclick();
				} else {
				alert(radio[i].name + "," + i + " does not have an onclick");
				}
			}
		break;	
		}

	}

}

function pulldownValue(element) {
	var ret = undefined;
	if (element.selectedIndex>-1) {
		ret = element.options[element.selectedIndex].value;
		}
	return ret;
}


function valueOfRadioChecked(radio) {
var i, len, value;
len = radio.length;
for (i=0;i<len;i++){
	if (radio[i].checked) {
		value=radio[i].value;
		break;
		}
	}
return value;
}

function removePulldownValue(element, value) {
for (var i=0, len=element.options.length;i<len;i++) {
	if (element.options[i].value == value) {
		element.remove(i);
		break;
		}
	}
}

function writeLimitedText(element, value) {
	element.value = value.substring(0, (element.maxLength<=0) ? value.length:element.maxLength);
}
//-->