// Apply getElementById patch
if ( !document.getElementById ) {
    if ( document.all ) {
        document.getElementById = function( x ) {
            return this.all[x];
        }
    }
    else if ( document.layers ) {
        document.getElementById = function( x ) {
            return this[x];
        }
    }
}

function validateInteger( strValue ) {
  var objRegExp = /(^-?\d\d*$)/;
  return objRegExp.test( strValue );
}

function enableVoteTwo() {
	document.getElementById('toptenvote2').style.display = "block";
}

function disableVoteTwo() {
	document.toptenvote.vote2.selectedIndex = 0;
	document.toptenvote.vote2.value = "";
	document.getElementById('toptenvote2').style.display = "none";
}

function validateCardNum( strValue ) {
	return (( strValue != "" ) && validateInteger( strValue ));
}

function testCard() {
	if ( validateCardNum( document.toptenvote.bcard.value )) {
		enableVoteTwo();
	} else {
		disableVoteTwo();
	}
}

function checkSelect( voteNum ) {
	selectName = "vote" + voteNum;
	fieldName = selectName + "a";
	if ( document.toptenvote.elements[selectName].selectedIndex != document.toptenvote.elements[selectName].length - 1 ) {
		document.toptenvote.elements[fieldName].value = "";
	}
}

function resetSelect( voteNum ) {
	selectName = "vote" + voteNum;
	if ( document.toptenvote.elements[selectName+"a"].value != "" ) {
		document.toptenvote.elements[selectName].selectedIndex = document.toptenvote.elements[selectName].length - 1;
	}
}

function checkVoteForm() {
	if ( document.toptenvote.name.value == "" ) {
		alert( "You must enter your full name\rto vote for the Top Ten..." );
		return false;
	}

	if ( typeof document.toptenvote.email.value.search != "undefined" ) {
		if ( document.toptenvote.email.value.search(/.+@.+\..+/) == -1 ) {
			alert ( "You must enter a valid email address\rto vote for the Top Ten..." );
			return false;
		}
	} else if (( document.toptenvote.email.value == "" ) ||
	( document.toptenvote.email.value.indexOf( '@' ) == -1 ) ||
	( document.toptenvote.email.value.indexOf( '.' ) == -1 )) {
		alert ( "You must enter a valid email address\rto vote for the Top Ten..." );
		return false;
	}
	
	if (( document.toptenvote.bcard.value != "" ) &&
	( typeof document.toptenvote.bcard.value.search != "undefined" )) {
		if ( document.toptenvote.bcard.value.search(/^[0-9]{3,5}$/) == -1 ) {
			document.toptenvote.bcard.value = "";
			alert ( "Your bCard number is invalid.\rPlease re-enter it..." );
			return false;
		}
	}

	if ((( document.toptenvote.vote1.selectedIndex == 0 ) ||
	( document.toptenvote.vote1.selectedIndex == 11 )) &&
	( document.toptenvote.vote1a.value == "" )) {
		if ((( document.toptenvote.vote2.selectedIndex == 0 ) ||
		( document.toptenvote.vote2.selectedIndex == 11 )) &&
		( document.toptenvote.vote2a.value == "" )) {
			alert ( "You must cast at least one vote..." );
			return false;
		}
	}

	return true;
}
