$(document).ready(function() {
	$('#contactForm').submit(function(){validateForm($(this))});
});

/*
function validateForm(form) {
	$(form).find('.required').val('').each(function(){alert( $(this).val() )});
}
*/

//Have the prompt box turned on by default
var promptOn = true;

function insertAtCursor(myField, type) {
	//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = getLink(type);
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		var myValue = getLink(type);
		myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
	} 	
	else {
		myField.value += getLink(type);
	}
}

//Function to add link in form field
function getLink(type) {

var value = "";
var promptText = "";
var promptText2 = "";
var prefixLink = "";

if(type == 'email'){
	prefixLink = "";
	promptText = "Enter the on screen display text for the Email";
	promptText2 = "Enter the email address to create Email to";
	prefix = "mailto:";
}
else{
	prefixLink = "http://";
	promptText = "Enter the on screen display text for the Hyperlink";
	promptText2 = "Enter the URL address to create Hyperlink to";
	prefix = "";
}

			insertText = prompt(promptText, "");
				
				if ((insertText != null) && (insertText != "")){
					insertCode = prompt(promptText2, prefixLink);
					insertCode = prefix + insertCode;
						
						if ((insertCode != null) && (insertCode != "") && (insertCode != prefixLink)){					
							value += "<LINK=" + insertCode + ">" + insertText + "</LINK>";
							return value;
						}
						
				}
				
				return value = "";


}

function checkAll(field){
	for (i = 0; i < field.length; i++)
		field[i].checked = true ;
}

function uncheckAll(field){
	for (i = 0; i < field.length; i++)
		field[i].checked = false ;
}

function toggleCheckAll(toggleField, field){
	if(toggleField.checked == false) 
		uncheckAll(field);
	else
		checkAll(field);
}

/* Scholarships sorting */
function reSortScholarships() {
	// Get selected order
	var objSelect = document.getElementById('scholarshipOrder');
	var objOption = objSelect.options[objSelect.selectedIndex].value;
	// Get current url including params
	var urlString = window.top.location.href;

	if (urlString.indexOf('sort=') != -1) {	
		var strLength = urlString.length;
		var startToken = urlString.lastIndexOf('=');
		var lastToken = urlString.substring(startToken+1, strLength);
		urlString = urlString.replace(lastToken, objOption);
	}
	else {
		// If no params, prefix sort with ?, otherwise &
		if (urlString.indexOf('?') == -1)	var preSort = '?';
		else 	var preSort = '&';	
		urlString = urlString+preSort+'sort='+objOption;
	}
	// reload page
	window.document.location = urlString;
	
}
