//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	Custom Javascript functions
//-------------------------------------------------------------------------------------------------------
//=======================================================================================================


//#########################################################################################################
//
//Video Functions
//
//#########################################################################################################

//*********************************************************************************************************
//		Function:	insertVideo
//---------------------------------------------------------------------------------------------------------
//	What it does:	place new video code into div which has an id of the_id
//*********************************************************************************************************
function insertVideo( video_path,the_id )
{
	//alert(videos);
//alert(' v path = '+video_path + ' id = '+the_id );
	// Important: keeps the active videos arrow on instead of toggling
	no_toggle = the_id;

	// Turn off all arrows + abstracts
	//for(var i = 0; i < video_ids.length; i++)
	for(video_id in videos)
	{
		var arrow_image_id 	= 'video_arrow_' + video_id;
		var abstract_id 	= 'video_abstract_' + video_id;

		//var arrow_image	= document.getElementById(arrow_image_id);
		setObjectStyle( abstract_id, 'display', 'none' );	
		setObjectStyle( arrow_image_id, 'display', 'none' );	
		//arrow_image.style.display = 'none';

	}

	// Turn on appropriate arrow
	var active_arrow 			= document.getElementById('video_arrow_' + the_id);
	active_arrow.style.display 	= 'block';

	if(videos[the_id].embed_html)
	{
		document.getElementById('player1').innerHTML = videos[the_id].embed_html;
	}
	else
	{

		video_width = videos[the_id].width != 0
					? videos[the_id].width
					: 400;

		video_height = videos[the_id].height != 0
					? videos[the_id].height
					: 328;


		flashembed( "player1",
		{ src: '/uber/FlowPlayerLight.swf', width:video_width, height:video_height, bgcolor:'#ffffff'},
		{ config: { videoFile: video_path, showMenu: false  
			, autoPlay: true 
			, loop: false 
			, usePlayOverlay: '1' 
			, initialScale: true 
		} } );
	}

	var abstract_id 	= 'video_abstract_' + the_id;

	setObjectStyle( abstract_id, 'display', 'block' );

}

//*********************************************************************************************************
//		Function:	growALittle
//---------------------------------------------------------------------------------------------------------
//	What it does:	increase element dimensions
//*********************************************************************************************************
function growALittle( elem )
{
	elem.style.width = '95px';
	elem.style.marginLeft = '-3';
	elem.style.marginTop = '-3';
}

//*********************************************************************************************************
//		Function:	growALittle
//---------------------------------------------------------------------------------------------------------
//	What it does:	decrease element dimensions
//*********************************************************************************************************
function shrinkALittle( elem )
{
	elem.style.width = '89px';
	elem.style.marginTop = '0';
	elem.style.marginLeft = '0';
}

//*********************************************************************************************************
//		Function:	toggleVisibility
//---------------------------------------------------------------------------------------------------------
//	What it does:	hide / show element
//*********************************************************************************************************
function toggleVisibility( id )
{
	if('video_arrow_' + no_toggle == id)
	{
	   	return;
	}

	var elem = document.getElementById(id);
	if(elem.style.display == 'none')
	{
		elem.style.display = 'block';
	}
	else
	{
		elem.style.display = 'none';
	}
}

//*********************************************************************************************************
//		Function:	over_row
//---------------------------------------------------------------------------------------------------------
//	What it does:	make the element visible
//*********************************************************************************************************
function over_row( id )
{
	setObjectStyle(id,'display','');
	
}

//*********************************************************************************************************
//		Function:	out_row
//---------------------------------------------------------------------------------------------------------
//	What it does:	hide element
//*********************************************************************************************************
function out_row( id )
{
	setObjectStyle(id,'display','none');
}

//*********************************************************************************************************
//		Function:	setObjectStyle
//---------------------------------------------------------------------------------------------------------
//	What it does:	chage an element style when given the id , the attribute and stylevalue
//*********************************************************************************************************
function setObjectStyle( objectid, stylename, stylevalue )
{
	object = document.getElementById( objectid );

	if ( object )
	{
		object.style[stylename] = stylevalue;
	//}else{alert(objectid);}
	}else{}
}

//*********************************************************************************************************
//		Function:	getElement
//---------------------------------------------------------------------------------------------------------
//	What it does:	returns an object
//*********************************************************************************************************
function getElement( id)
{
	return document.getElementById( id );
}

//*********************************************************************************************************
//		Function:	expand
//---------------------------------------------------------------------------------------------------------
//	What it does:	hide / show an object
//*********************************************************************************************************
function expand(param)
{
		param.style.display=(param.style.display=="none")?"block":"none";
}

//*********************************************************************************************************
//		Function:	expandById
//---------------------------------------------------------------------------------------------------------
//	What it does:	hide / show an object when given an id
//*********************************************************************************************************
function expandById(id)
{
	expand(document.getElementById(id));
}

//*********************************************************************************************************
//		Function:	locations_changed
//---------------------------------------------------------------------------------------------------------
//	What it does:	sets the programs in a given campus
//*********************************************************************************************************
function locations_changed( obj_location )
{
	var location_id;
	var program_id;
	var show_all_programs;

	obj_program		= getElement('programofinterest');
	program_id		= obj_program.options[obj_program.selectedIndex].value;
	location_id		= obj_location.options[obj_location.selectedIndex].value;
	show_all_programs = 0;

	if( !location_id )
	{
		show_all_programs = 1;
	}

	eval('loadDivContents( "/site/options_programs.php?location_id='+ location_id + '&program_id='+ program_id + '&show_all_programs='+ show_all_programs +'&tab='+ obj_program.tabIndex +'" , "div_programofinterest")');

}


//*********************************************************************************************************
//		Function:	programs_changed
//---------------------------------------------------------------------------------------------------------
//	What it does:	sets the locations a program is offered
//*********************************************************************************************************
function programs_changed( obj_program )
{
	var location_id;
	var program_id;

	obj_location = getElement('campuslocation');
	location_id  = obj_location.options[obj_location.selectedIndex].value;

	program_id	 = obj_program.options[obj_program.selectedIndex].value;

	if( !program_id )
	{
		//return;
	}
	
	eval('loadDivContents( "/site/options_locations.php?location_id='+ location_id + '&program_id='+ program_id + '&tab='+ obj_location.tabIndex +'" , "div_campuslocation")');
	
}


//*********************************************************************************************************
//		Function:	check_digits
//---------------------------------------------------------------------------------------------------------
//	What it does:	validate a user puts in a digit as he/she types it in
//*********************************************************************************************************
function check_digits( obj , total_chars ,next_field, e)
{
	var keynum;
	var keychar;
	var numcheck;
	var total_chars;
	//var control_keys = Array();

//-----------------------------------------------------------------------------------------------------
// get the value of the character that was pressed
//-----------------------------------------------------------------------------------------------------
	if(window.event) // IE
	{
	  keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
	  keynum = e.which;
	}

	keychar = String.fromCharCode(keynum);

//-----------------------------------------------------------------------------------------------------
// is this a digit?
//-----------------------------------------------------------------------------------------------------
	// check for digit
	numcheck = new RegExp(/^\d{1}$/);
	
	if( keynum )
	{
		if( numcheck.test(keychar) )
		{

		}
		else if((keynum == 8) || (keynum == 0) || (keynum == 46) || (keynum == 9 ) ||  (keynum == 37 )|| (keynum == 39 )  )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		// it might be a tab / delete 
		return true;

	}
/*
//-----------------------------------------------------------------------------------------------------
// setup variables
//-----------------------------------------------------------------------------------------------------
	if(  part == '1' )
	{
		//var pattern = new RegExp(/^\d{0,3}$/);
		total_chars = 3;
	}
	else if(  part == '2' )
	{
		//var pattern = new RegExp(/^\d{0,3}$/);
		total_chars = 3;

	}
	else if(  part == '3' )
	{
		//var pattern = new RegExp(/^\d{0,4}$/);
		total_chars = 4;
	}
	else
	{
	}
*/

//-----------------------------------------------------------------------------------------------------
// are we adding the char or moving to the next tab?
//-----------------------------------------------------------------------------------------------------
	var number_string = obj.value +  keychar;
	
	// if we have "total_chars" characters move go to the next elem
	if( number_string.length ==  total_chars )
	{
		obj.value = number_string;
		gotoNextElem( next_field );
		return false;
	}
	// if we have less than "total_chars" characters continue
	else if( number_string.length <  total_chars )
	{
		obj.value = number_string;
	}
	// if we have more than "total_chars" go to the next elem
	else if( number_string.length >  total_chars )
	{
		gotoNextElem( next_field );
	}

	// return false.
	return false;

}

//*********************************************************************************************************
//		Function:	gotoNextElem
//---------------------------------------------------------------------------------------------------------
//	What it does:	move to the next elem if one exists
//*********************************************************************************************************
function gotoNextElem( next_field )
{
	if( next_field )
	{
		var nextEl = getElement(next_field);
		nextEl.focus();

	}
	return true;
}

//*********************************************************************************************************
//		Function:	is_digit
//---------------------------------------------------------------------------------------------------------
//	What it does:	validate if the digit put in is a number
//*********************************************************************************************************
function is_digit( e)
{
	var keynum;
	var keychar;
	var numcheck;

	if(window.event) // IE
	{
	  keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
	  keynum = e.which;
	}

	keychar = String.fromCharCode(keynum);

	// check for digit
	numcheck = new RegExp(/^\d{1}$/);

	if( numcheck.test(keychar) || (keynum == 8) || (keynum == 0) || (keynum == 46) )
	{
		return true;
	}
	else
	{
		return false;
	}

}

//*********************************************************************************************************
//		Function:	is_digit
//---------------------------------------------------------------------------------------------------------
//	What it does:	validate if the digit put in is a number
//*********************************************************************************************************
function checkCommentLength( obj, e )
{

	var keynum;
	var keychar;

//-----------------------------------------------------------------------------------------------------
// get the value of the character that was pressed
//-----------------------------------------------------------------------------------------------------
	if(window.event) // IE
	{
	  keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
	  keynum = e.which;
	}

	keychar = String.fromCharCode(keynum);
//-----------------------------------------------------------------------------------------------------
// what type of char
//-----------------------------------------------------------------------------------------------------
	if((keynum == 8) || (keynum == 0) || (keynum == 46) || (keynum == 9 ) ||  (keynum == 37 )|| (keynum == 39 ) || (keynum == 17 ) )
	{
		return true;
	}

//-----------------------------------------------------------------------------------------------------
// validate
//-----------------------------------------------------------------------------------------------------
	//alert(obj.value.length);
	if( obj.value.length >= 150 )
	{
		return false
	}
	return true;
}

//*********************************************************************************************************
//		Function:	checkOther
//---------------------------------------------------------------------------------------------------------
//	What it does:	if other is selected in the dropdown, show the textbox
//*********************************************************************************************************
function checkOther(obj , other_div_id, other_obj)
{
	howdidyouknow = obj.value;

	if (howdidyouknow == "Other")
	{
		document.getElementById(other_div_id).style.display = "block";
	}
	else
	{
		control = document.getElementById(other_obj);
		control.value = "";
		document.getElementById(other_div_id).style.display = "none";
	}
}

//*********************************************************************************************************
//		Function:	popup
//---------------------------------------------------------------------------------------------------------
//	What it does:	open a popup
//*********************************************************************************************************
function popup(link,width,height)
{
	width	= width 
			? width
			: 250;

	height	= height 
			? height
			: 250;
	window.open (link,'_blank','status=1,toolbar=0,location=0,status=1,menubar=0,resizable=1,scrollbars=1,left=200,top=250,width='+width+',height='+height+';');
}

//*********************************************************************************************************
//		Function:	clear_search_text
//---------------------------------------------------------------------------------------------------------
//	What it does:	clear message on textbox
//*********************************************************************************************************
	function clear_search_text( findtext)
	{
		//alert(search_text);
		if( findtext.value == search_text )
		{
			findtext.value = '';
		}
	}

//*********************************************************************************************************
//		Function:	set_search_text
//---------------------------------------------------------------------------------------------------------
//	What it does:	set "Search site" message on the search box
//*********************************************************************************************************
	function set_search_text( findtext)
	{
		if( findtext.value == '' )
		{
			findtext.value = search_text;
		}
	}

//*********************************************************************************************************
//		Function:	goToStep2
//---------------------------------------------------------------------------------------------------------
//	What it does:	on the 2 step form, go to step 2
//*********************************************************************************************************
	function validatetwo_step_form()
	{
		var form = document.contactus;

		var controls					= new Array();
		controls['Campus Location']		= form["fields[Campus Location]"].value;
		controls['Program of Interest']	= form["fields[Program of Interest]"].value;
		controls['Education Level']		= form["fields[Education Level]"].value;
		controls['First Name']			= form["fields[First Name]"].value;
		controls['Last Name']			= form["fields[Last Name]"].value;
		controls['Email']				= form["fields[Email]"].value;
		controls['Zip']					= form["fields[Zip]"].value;
		controls['id']					= form["fields[Two Step ID]"].value;

//---------------------------------------------------------------------------------------------------------
// make sure all fields are filled
//---------------------------------------------------------------------------------------------------------
		for( idx in controls )
		{
			if ( !str_trim(controls[idx]  ))
			{
				alert(idx + ' Is Required');
				 form['fields['+idx+']'].focus();
				return false;
			}
		}

//---------------------------------------------------------------------------------------------------------
// Is valid Email
//---------------------------------------------------------------------------------------------------------
		if( !IsEmail(controls['Email']))
		{
				alert(' Invalid Email');
				 form['fields[Email]'].focus();
				return false;
		}

//---------------------------------------------------------------------------------------------------------
// IS valid zip
//---------------------------------------------------------------------------------------------------------
		if( !IsZip(controls['Zip']))
		{
				alert(' Invalid Zip');
				 form['fields[Zip]'].focus();
				return false;
		}

//---------------------------------------------------------------------------------------------------------
// ajax call
//---------------------------------------------------------------------------------------------------------
	$.ajax({
			type: "GET",
			url: "/site/2_step_aja.php",
			data: 	"campus=" + controls['Campus Location'] + 
					"&program=" + controls['Program of Interest']+
					"&id=" + controls['id']+
					"&education=" +controls['Education Level']+
					"&fname=" +controls['First Name']+
					"&lname=" +controls['Last Name']+
					"&email=" +controls['Email']+
					"&zip=" +controls['Zip'],
			success: function(id){
				if(id)
				{
					$("#two_step_id").val(id);
					toggleTwoStepForm();
				}
			}
		});
		

	}

//*********************************************************************************************************
//		Function:	goToStep2
//---------------------------------------------------------------------------------------------------------
//	What it does:	on the 2 step form, go to step 2
//*********************************************************************************************************
	function toggleTwoStepForm()
	{
		$('#form_part_1').toggle();
		$('#form_part_2').toggle();
	}

//*********************************************************************************************************
//		Function:	isZip
//---------------------------------------------------------------------------------------------------------
//	What it does:	validate zip
//*********************************************************************************************************
	function IsZip(zip)
	{
		// check for digits
		numcheck = new RegExp(/^\d{3,5}$/);
		return numcheck.test(zip);
	}

//*********************************************************************************************************
//		Function:	toggle_video()
//---------------------------------------------------------------------------------------------------------
//	What it does:	show/hide the video
//*********************************************************************************************************
function ToggleVideo( id )
{
	if( !id)
	{
		$("#site_dim").toggle();
		$('#movie_container').toggle();
		$("#movie_container").html('');
		return;
	}

	$("#site_dim").toggle();
	$('#movie_container').toggle();
	
	var video_url = '/site/aja_video.php?a='+id;
	$.ajax({  url: video_url,  cache: false,  success: function(html){    $("#movie_container").html(html);  }});
}