function submitSearchKeyPress(e)
{
	var key;
	
	if(window.event)
	{
		// ie
	  	key = window.event.keyCode;
	}
	else
	{
		// firefox
		key = e.which;
	}
	
	if(key == 13)
	{
		submitSearch();	
	}
}

function submitSearchAltKeyPress(e)
{
	var key;
	
	if(window.event)
	{
		// ie
	  	key = window.event.keyCode;
	}
	else
	{
		// firefox
		key = e.which;
	}
	
	if(key == 13)
	{
		submitSearchAlt();	
	}
}

function submitSearchIKeyPress(e, i)
{
	var key;
	
	if(window.event)
	{
		// ie
	  	key = window.event.keyCode;
	}
	else
	{
		// firefox
		key = e.which;
	}
	
	if(key == 13)
	{	
		submitSearchI(i);	
	}
}

function rateOnKeyPress(e)
{
		var key;
	
	if(window.event)
	{
		// ie
	  	key = window.event.keyCode;
	}
	else
	{
		// firefox
		key = e.which;
	}
	
	if(key == 13)
	{
		document.rate_form.submit();	
	}
}

function setFocusOnSubmitRating()
{
	var control = document.getElementById('submit_rating');
	control.focus();
}



function init()
{
	
}

function validate_account_update()
{
	var is_valid = true;
	
	is_valid = checkField(document.update_form.first_name, is_valid);
	is_valid = checkField(document.update_form.last_name, is_valid);
	is_valid = checkSelect(document.update_form.month, is_valid);
	is_valid = checkSelect(document.update_form.date, is_valid);
	is_valid = checkSelect(document.update_form.year, is_valid);
	is_valid = compareFieldSame(document.update_form.new_password, document.update_form.verify_new_password, is_valid);
	
	if(!is_valid)
	{
		alert("Please complete all required fields!");
	}
	
	return is_valid;
}

function validate_sign_up()
{
	var is_valid = true;
	
	is_valid = checkField(document.sign_up_form.first_name, is_valid);
	is_valid = checkField(document.sign_up_form.last_name, is_valid);
	is_valid = checkField(document.sign_up_form.email_address, is_valid);
	is_valid = checkSelect(document.sign_up_form.month, is_valid);
	is_valid = checkSelect(document.sign_up_form.date, is_valid);
	is_valid = checkSelect(document.sign_up_form.year, is_valid);
	is_valid = checkField(document.sign_up_form.user_name, is_valid);
	is_valid = compareFieldSame(document.sign_up_form.new_password, document.sign_up_form.verify_new_password, is_valid);

	if(!is_valid)
	{
		alert("Please complete the entire registration form!");
	}
	
	return is_valid;
}

function checkSelect(select_box, is_valid)
{
	
	if(is_valid && select_box.selectedIndex > 0)
	{
		is_valid = true;	
	}
	else
	{
		is_valid = false;
	}
	return is_valid;
}

function compareFieldSame(left, right, is_valid)
{
	if(is_valid && checkField(left, is_valid) && checkField(right, is_valid))
	{
		if(left.value == right.value)
		{
			is_valid = true;	
		}
		else
		{	
			is_valid = false;	
		}
	}
	else
	{
		is_valid = false;	
	}
	return is_valid;
}

function checkField(obj, is_valid)
{	
	if(is_valid && obj.value.length <= 0)
	{
		is_valid = false;	
	}
	
 	return is_valid;
}

function processContactSuggest()
{
	alert("Your comment has been processed thank you!");
}

function processDrop(college_index, column_name, user_name)
{
	window.location = "process_drop.php?college_index=" + college_index + "&column_name=" + column_name + "&user_name=" + user_name;	
}


function processSignUp()
{
	document.forms[0].submit();	
}

function processMyAccount()
{
	window.location = "my_account.php";	
}

function sendHome()
{
	 window.location = "index.php";
}

function submitSignUp()
{
	window.location = "sign_up.php";	
}

function submitState()
{
	var search_query = document.getElementById('states').value;
	window.location = "browse_result.php?search_query=" + search_query;	
}

function submitSearch()
{
	var search_query = document.getElementById('college_search').value;
		
	searchQuery("search.php?search_query=" + search_query); 
}

function submitSearchI(i)
{
	if( i == 0)
	{
		
		var search_query = document.getElementById('find_college').value;
		var control = document.getElementById('find_college_search');
		control.focus();
		searchQuery("search.php?search_query=" + search_query); 

	}
	else
	{
		var search_query = document.getElementById('rate_college').value;
		var control = document.getElementById('rate_college_search');
		control.focus();
		searchQuery("search.php?search_query=" + search_query); 
	}
}

function searchQuery(query)
{
	window.location = query;	
}

function submitSearchAlt()
{
	var control = document.getElementById('submit_alt_college_browse');
	
	control.focus();
	
	var search_query = document.getElementById('college_search_alt').value;
	var location = document.getElementById('location').value;
	var type = document.getElementById('type').value;
	var calendar = document.getElementById('calendar').value;
	var degree = document.getElementById('degree').value;
	var setting = document.getElementById('setting').value;

	if(location == "State")
	{
		location = "";	
	}
	
	if(type == "Type of School")
	{
		type = "";
	}
	
	if(calendar == "Calendar")
	{
		calendar = "";
	}
	
	if(degree == "Degree")
	{
		degree = "";	
	}
	
	if(setting == "Setting")
	{
		setting = "";	
	}

	window.location = "search.php?search_query=" + search_query + "&location=" + location + "&type=" + type + "&calendar=" + calendar + "&degree=" + degree + "&setting=" + setting;

}


function submitRating(college_index, college_name, p_name, p_url)
{
	window.location = "rate.php?college_index=" + college_index + "&location=" + location + "&college_name=" + college_name + "&p_name=" + p_name + "&p_url=" + p_url ; 
}

function submitCompare(college_index)
{
	window.location = "my_compares.php?college_index=" + college_index ; 
}



function init_trackbars()
{
		
}

function checkTextBox(textbox)
{
	if(textbox.value == "")
	{
		textbox.value = "Search Colleges";
	}
}

function checkTextBoxS(textbox, value_s)
{
	if(textbox.value == "")
	{
		textbox.value = value_s;
	}
}

function clearTextBox(textbox)
{
	if(textbox.value == "Search Colleges" || textbox.value == "College Name" || textbox.value == "Find a College" || textbox.value == "Rate a College")
	{
		textbox.value = "";
	}
}

function initComment()
{
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	
	var y = document.getElementById("comment_tr");
	var x = document.getElementById("comment_table");
	
	if(browser.indexOf('Microsoft') != -1)
	{	
		if(x != null)
		{
			x.style.display = "block";
		}
	}
	else
	{
		if(y != null)
		{
			y.style.visibility = "visible";
		}
	}
}


function initCompareTables()
{
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	
	var y = document.getElementById("type_tr");
	var x = document.getElementById("type_table");
	
	var yy = document.getElementById("degree_tr");
	var xx = document.getElementById("degree_table");
	
	var yyy = document.getElementById("calendar_tr");
	var xxx = document.getElementById("calendar_table");
	
	var yyyy = document.getElementById("setting_tr");
	var xxxx = document.getElementById("setting_table");
	
	var yyyyy = document.getElementById("size_tr");
	var xxxxx = document.getElementById("size_table");
	
	var yyyyyy = document.getElementById("ratings_tr");
	var xxxxxx = document.getElementById("ratings_table");
	
	var yyyyyyy = document.getElementById("list_tr");
	var xxxxxxx = document.getElementById("list_table");
	
	if(browser.indexOf('Microsoft') != -1)
	{	
		if(x != null && xx != null)
		{
			x.style.display = "block";
			xx.style.display = "block";
			xxx.style.display = "block";
			xxxx.style.display = "block";
			xxxxx.style.display = "block";
			xxxxxx.style.display = "block";
			xxxxxxx.style.display = "block";
		}
	}
	else
	{
		if(y != null && yy != null)
		{
			y.style.visibility = "visible";
			yy.style.visibility = "visible";
			yyy.style.visibility = "visible";
			yyyy.style.visibility = "visible";
			yyyyy.style.visibility = "visible";
			yyyyyy.style.visibility = "visible";
			yyyyyyy.style.visibility = "visible";
		}
	}
}



function maximizeCompare(tr, table)
{
	var browser = navigator.appName;
	var b_version = navigator.appVersion;
	
	var y = document.getElementById(tr);
	var x = document.getElementById(table);

	if(browser.indexOf('Microsoft') != -1)
	{
		switch(x.style.display)
		{
			case "none":
				x = x.style.display = "block";
				break;
		}
	}
	else
	{
		switch(y.style.visibility)
		{
			case "collapse":
				y = y.style.visibility = "visible";
				break;
		}
	}
	
}


function minimizeCompare(tr, table)
{
	var browser = navigator.appName;
	var b_version = navigator.appVersion;
	
	var y = document.getElementById(tr);
	var x = document.getElementById(table);

	if(browser.indexOf('Microsoft') != -1)
	{
		switch(x.style.display)
		{
			case "block":
				x = x.style.display = "none";
				break;
		}
	}
	else
	{
		switch(y.style.visibility)
		{
			case "visible":
				y = y.style.visibility = "collapse";
				break;
		}
	}
	

}


function minimize()
{
	var browser = navigator.appName;
	var b_version = navigator.appVersion;
	
	var displaying = document.getElementById("displaying");
	var y = document.getElementById("comment_tr");
	var x = document.getElementById("comment_table");

	if(browser.indexOf('Microsoft') != -1)
	{
		switch(x.style.display)
		{
			case "block":
				x = x.style.display = "none";
				break;
		}
	}
	else
	{
		switch(y.style.visibility)
		{
			case "visible":
				y = y.style.visibility = "collapse";
				break;
		}
	}
	
	displaying.style.color ="#666";
}


function maximize()
{
	var browser = navigator.appName;
	var b_version = navigator.appVersion;
	
	var displaying = document.getElementById("displaying");
	
	var y = document.getElementById("comment_tr");
	var x = document.getElementById("comment_table");

	if(browser.indexOf('Microsoft') != -1)
	{
		switch(x.style.display)
		{
			case "none":
				x = x.style.display = "block";
				break;
		}
	}
	else
	{
		switch(y.style.visibility)
		{
			case "collapse":
				y = y.style.visibility = "visible";
				break;
		}
	}
	
	displaying.style.color ="#fff";
}
function swapImage(img, file)
{
	img.src = "images/" + file;
}

