
/* ------------- special form processing ------------------ */

	//contact form toggles
	$(document).ready(function(){
		var isOptionSelected = ( $('#field14:checked').size() > 0 );
		
		if( isOptionSelected ){
			$('#radio-station').show();
		}else{
			$('#radio-station').hide();
		}
		
		//since we can't use the backend validation for the radio option
		$('#contact-form').submit(function() {
			var isOptionSelected = ( $('#field14:checked').size() > 0 && $('#radio-station > select').val() == '-- Choose Station --' );
			
			if( isOptionSelected ){
				//only add the error message once (why is it duplicated?)
				if( $('#radio-station > .error-message').size() == 0 ){
					$("#radio-station").append('<p class="error-message">Please choose an appropriate value.</p>');
				}
				return false;
			}else{
			}
		});
		
	});


/* ------------- //end special form processing ------------------ */


/* Auto Tabbing */
/* Original:  Cyanide_7 (leo7278@hotmail.com)
	Web Site:  http://members.xoom.com/cyanide_7

	This script and many more are available free online at
	The JavaScript Source!! http://javascript.internet.com */

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
			index++;
		return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input)index = i;
			else i++;
		return index;
	}
	return true;
}

/**
 * For conditionally shown form elements
 */
function ToggleElement(el) {
		e = document.getElementById(el);
		if (e.style.display == "none") {
			e.style.display = "block";
		} else {
			e.style.display = "none";
		}
	}
/**
 * For conditionally shown form elements - using this.checked
 */
function ToggleElement(el, flag) {
		e = document.getElementById(el);
		if (flag) {
			e.style.display = "block";
		} else {
			e.style.display = "none";
		}
	}

/**
 * Check the file extensions
 */
function check_extension(filefield, extensions){
	var extArray, ext, isValid;
	extArray = extensions.split(';');
	ext = filefield.value.substring( filefield.value.lastIndexOf('.')+1 ).toLowerCase();
	
	isValid = false;
	for(var x in extArray){
		if( extArray[x] == ext ){
			isValid = true;
		}
	}
	
	if(!isValid){
		alert("Invalid File Type - requires (" + extArray.join(" | ") + ")");
		filefield.value = '';
	}
	return isValid;
}