/**
 * @author bschank
 */


function ietrap(){
	var title = navigator.appName;
	if (title == 'Microsoft Internet Explorer'){
		var browserVer = navigator.appVersion;
		if (browserVer.match('MSIE 6')){
			alert('Message From CSCI Webmaster:: I detected that you are using IE 6 or less, Please Upgrade');
			document.location = 'http://www.mozilla.com/en-US/firefox/';
		}//END IF
		if (browserVer.match('MSIE 5')){
			document.location = 'http://www.mozilla.com/en-US/firefox/';
		}//END IF 
			
	}	//END IF
}

function selRequest(path, via, id, selectID)
	{
		$(id).innerHTML = '<h3>Loading Content...</h3>';
		var intSelected = $(selectID).selectedIndex;
		var strSelected = $(selectID).options[intSelected].value;
		var args = 'q=' + strSelected;
		var url = path;
		var pars = args;
		
		var myAjax = new Ajax.Updater(
					{success: id}, 
					url, 
					{
						method: via, 
						parameters: pars, 
						onFailure: reportError
					});
		
	}

function genRequest(path, via, id, args)
	{
		$(id).innerHTML = '<h3>Loading Content...</h3>';
		var url = path;
		var pars = "q=" + args;
		
		var myAjax = new Ajax.Updater(
					{success: id}, 
					url, 
					{
						method: via, 
						parameters: pars, 
						onFailure: reportError
					});
		
	}
	
function crsRequest(path, via, id, args)
	{
		$(id).innerHTML = '<h3>Loading Content...</h3>';
		var url = path;
		var pars = "q=" + args;
		
		var myAjax = new Ajax.Updater(
					{success: id}, 
					url, 
					{
						method: via, 
						parameters: pars, 
						onFailure: reportError
					});
		$('preview').innerHTML = '';
		
	}
	
function search_course_by_catagory(value_arg,catagory)
	{
		$('preview').innerHTML = '<h3>Loading Content...</h3>';
	    var semester_cd;
		var radioGRP = $('semester_group');
		for (i = 0; i < radioGRP.elements.length; i++){
			if (radioGRP.elements[i].checked){
				semester_cd = radioGRP.elements[i].value;
				break;
			}else{
				semester_cd = '';
			}//END ELSE
		}//END FOR
		
		var url = 'search.php';
		var pars = "q=" + semester_cd + '&searchValue=' + value_arg + '&catagory=' + catagory;
		var myAjax = new Ajax.Updater(
					{success: 'preview'}, 
					url, 
					{
						method: 'get', 
						parameters: pars, 
						onFailure: reportError
					});
		
	}//END search_course_by_instructor
	
	
	function reportError(request)
	{
		alert('Transaction Error: Contact webmaster@cs.iupui.edu');
	}
	
	
	function selectValue(id){
		intCat = $(id).selectedIndex;
		strValue = $(id).options[intCat].value;
		return strValue;
	}
	
	
	//RESEARCH INTERESTS ON PEOPLE PAGES
	
	function hideRI(id){
		var flag = $(id).style.visibility;
		if (flag == 'visible'){
			$(id).style.visibility = 'hidden';
			$(id).style.height = '0px'
		}
		else {
			$(id).style.visibility = 'visible';
			$(id).style.height = 'auto';
		}
	}
	
	
	//COURSES MENUS
	function hideMenu(id){
		var menus = new Array('ugradCourse','gradCourse','nCourse','deCourse');
	
		for (i = 0; i < menus.length; i++){
			if (menus[i] != id){
				$(menus[i]).style.visibility = 'hidden';
			}
		}
		$(id).style.visibility = 'visible';
	}
	
	
	function showSearch(){
		var vis = $('search').style.visibility;
		if (vis == 'visible'){
			$('search').style.visibility = 'hidden';
		}else{
			$('search').style.visibility = 'visible';
		}
		
	}	


	function switch_css(css_file,css_link){
		$(css_link).href = css_file;
	}
	
	
	
	//FEEDBACK SECTION ON HOMEPAGE
	
	function feedback(id){
		var flag = $(id).style.visibility;
		if (flag == 'visible'){
			$(id).style.visibility = 'hidden';
			$(id).style.height = '0px'
		}
		else {
			$(id).style.visibility = 'visible';
			$(id).style.height = 'auto';
		}
	}
	
	function close_feedback_window(id){
			$(id).style.visibility = 'hidden';
			$(id).style.height = '0px'
	}//END CLOSE FEEDBACK WINDOW
	
	function submit_feedback(question_key){
		var answer = $('answer_' + question_key).value;
		var url = 'feedback/';
		var pars = "answer=" + answer + '&question_key='+ question_key;
		
		var myAjax = new Ajax.Updater(
					{success: 'feedback_'+ question_key}, 
					url, 
					{
						method: 'post', 
						parameters: pars, 
						onFailure: reportError
					});
	}




	function form_validated(flag){
		var x = 0;
		var y = 0;
		
			if (flag){
				alert("Validated");
			}else{
				scroll(x,y);
			}
	}//END information_request_test
	
	
	
	function not_empty(id){
		var str = $(id).value;
			if (str != ""){
				$(id).style.background = '#FFF';
				return true;
			}else{
				$(id).style.background = '#FF0000';
				return false;
			}
	}//END not_empty
	
	
	
	function is_phone(id){
		var str = $(id).value;
		var filter = /^\d\d\d-\d\d\d-\d\d\d\d$/;
			if (!filter.test(str)){
				$(id).style.background = '#FF0000';
				return false;
			}else{
				$(id).style.background = '#FFF';
				return true;
			}
	}//END is_phone
	
	function state_selected(id){
		if ($(id).selectedIndex == 0) {
			$(id).style.background = '#FF0000';
			return false;
		}else{
			$(id).style.background = '#FFF';
			return true;
		}
	}//END IF


	function is_selected(id){
		if ($(id).selectedIndex == -1) {
			$(id).style.background = '#FF0000';
			return false;
		}else{
			$(id).style.background = '#FFF';
			return true;
		}
	}//END IF

	function not_selected_empty(id){
		var index = $(id).selectedIndex;
		var selectedValue = $(id).options[index].value;
		if ( selectedValue == "") {
			$(id).style.background = '#FF0000';
			return false;
		}else{
			$(id).style.background = '#FFF';
			return true;
		}
	}//END IF	
		
	function is_mail(id){
		var str = $F(id);
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(str)) {
			$(id).style.background = '#FF0000';
			return false;
		}else{
			$(id).style.background = '#FFF';
			return true;			
		}
	}//END is_mail
	
	
		function is_birthday(id){
		var str = $(id).value;
		var filter = /^\d\d-\d\d-\d\d$/;
			if (!filter.test(str)){
				$(id).style.background = '#FF0000';
				return false;
			}else{
				$(id).style.background = '#FFF';
				return true;
			}
	}//END is_phone
	
	function is_zip_code(id){
		var str = $(id).value;
		var filter_five_digit = /^\d\d\d\d\d$/;
		var filter_nine_digit = /^\d\d\d\d\d-\d\d\d\d$/;
		var flag = false;
		
		if (filter_five_digit.test(str)){
			flag = true;
		}
		if (filter_nine_digit.test(str)){
			flag = true;
		}
		if (!flag){
			$(id).style.background = '#FF0000';
			return false;
		}else{
			$(id).style.background = '#FFF';
			return true;
		}
	
	}//END is_zip_code
	
	function pwd_field_match(field_a, field_b){
		var a = $(field_a).value;
		var b = $(field_b).value;
		if (a == b){
			return true;
		}else{
			$(field_a).style.background = '#FF0000';
			$(field_b).style.background = '#FF0000';
			return false;
		}
		
	}//END PWD FIELD MATCH
	
	
	function faculty_reg_form(){

		var validated = new Array();
			
			validated[0] = not_empty("first_name");
			validated[1] = not_empty("last_name");
			validated[2] = not_empty("main_subject_area");
			validated[3] = not_empty("email");
			validated[4] = is_mail("email");
			validated[5] = not_empty("office_phone");
			validated[6] = is_phone("office_phone");
			validated[7] = not_empty("high_school");
						
		var test_count = validated.length;
		var passed = false;
		
			for(i=0;i<test_count; i++){
				if(!eval(validated[i])){
					passed = false;
					break;
				}else{
					passed = true;
				}
			}
			
		if (passed){
			//alert("The entire form validated!");
			$('faculty_reg_form').submit();
		}else{
			//alert("Something did not validate");
			form_validated(false);
		}
	}
	
	function student_reg_form(){

		var validated = new Array();
			
			validated[0] = not_empty("first_name");
			validated[1] = not_empty("last_name");
			validated[2] = not_empty("team_name");
			validated[3] = not_empty("email");
			validated[4] = is_mail("email");
			validated[5] = not_empty("high_school");
			validated[6] = not_empty("upwd");
			validated[7] = not_empty("vupwd");
			validated[8] = pwd_field_match('upwd','vupwd');
			validated[9] = not_selected_empty('sponsor');
						
		var test_count = validated.length;
		var passed = false;
		
			for(i=0;i<test_count; i++){
				if(!eval(validated[i])){
					passed = false;
					break;
				}else{
					passed = true;
				}
			}
			
		if (passed){
			//alert("The entire form validated!");
			$('student_reg_form').submit();
		}else{
			//alert("Something did not validate");
			form_validated(false);
		}
	}