/* JavaScript Document */

function getHTTPObject() {
	var xhr = false;
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				xhr = false;
			}
		}
	}
	return xhr;
}

function grabFile(file,viewer) {
	var request = getHTTPObject();
	if (request) {
		request.onreadystatechange = function() {
			parseResponse(request,viewer);
		};
		request.open("GET", file, true);
		request.send(null);
		return true;
	} else {
		return false;
	}
}

function parseResponse(request,viewer) {
	if (request.readyState == 4) {
		if (request.status == 200 || request.status == 304) {

			while (viewer.hasChildNodes()) {
				 viewer.removeChild(viewer.lastChild);
			}

			viewer.innerHTML = request.responseText;
		}
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}


function showRequestProcessing() {
	var form_btns = document.getElementById("form_btns");
	while (form_btns.hasChildNodes()) {
		form_btns.removeChild(form_btns.lastChild);
	}

	form_btns.innerHTML = "<p>Please wait while your request is being processed. This could take a minute.</p><div class='progress_bar'></div>";
}

function prepSubmitBtn() {
	if (document.getElementById("request_form")) {
		var request_form = document.getElementById("request_form");
		request_form.onsubmit = function() {
			if(this.Name && this.Name.value=='')
			{
				alert('Please enter your name.');
				this.Name.focus();
				return false;
			}
			if(this.StudentID && this.StudentID.value=='')
			{
				alert('Please enter your student ID.');
				this.StudentID.focus();
				return false;
			}
			if(this.Phone && this.Phone.value=='')
			{
				alert('Please enter your phone number.');
				this.Phone.focus();
				return false;
			}
			if(this.Email && this.Email.value=='')
			{
				alert('Please enter your college email address.');
				this.Email.focus();
				return false;
			}
			if(this.Course && this.Course.value=='')
			{
				alert('Please enter the course for which you\'d like tutoring.');
				this.Course.focus();
				return false;
			}
			if(this.Availability && this.Availability.value=='')
			{
				alert('Please enter the days and times you are available for tutoring.');
				this.Availability.focus();
				return false;
			}
			showRequestProcessing();
			this.submit();
		}
	}
}


// The following are for the Jobs and Internships page //
function checkAll(){
	for (var i=0;i<document.forms[0].elements.length;i++)
	{
		var e=document.forms[0].elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox'))
		{
			e.checked=document.forms[0].allbox.checked;
		}
	}
}

function onoff(){
	if(document.getElementById("day").disabled==true){
		document.getElementById("day").disabled=false
		document.getElementById("month").disabled=false
		document.getElementById("year").disabled=false
	}
	else {
		document.getElementById("day").disabled=true
		document.getElementById("month").disabled=true
		document.getElementById("year").disabled=true
	}
}

function onoff2(){
	if(document.getElementById("season").disabled==true){
		document.getElementById("season").disabled=false
		document.getElementById("season1").disabled=false
	}
	else {
		document.getElementById("season").disabled=true
		document.getElementById("season1").disabled=true
	}
}
// End jobs and internships page functions /////////////



addLoadEvent(prepSubmitBtn);

///////////////////// JQUERY SECTION /////////////////////

$(function() { // Run the following code once document is fully loaded into the browser
	if($('#main_content').height() < $('#side_nav').height())
		$('#main_content').height($('#side_nav').height());

	$('#height_report').html("main content height: " + $('#main_content').height() + " | side nav height: " + $('#side_nav').height());

	//Hide (Collapse) the toggle containers on load
	$(".toggle_container").hide(); 

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$("h2.trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
		return false; //Prevent the browser jump to the link anchor
	});

	//News ticker for CAPS home page	
	$('#ticker div').vTicker({ 
		speed: 1200,
		pause: 4500,
		animation: 'fade',
		mousePause: true,
		showItems: 1
	});


});


//begin news ticker code

/*
* vertical news ticker
* Tadas Juozapaitis ( kasp3rito@gmail.com )
* http://plugins.jquery.com/project/vTicker
*/
(function(a){a.fn.vTicker=function(b){var c={speed:700,pause:4000,showItems:3,animation:"",mousePause:true,isPaused:false,direction:"up",height:0};var b=a.extend(c,b);moveUp=function(g,d,e){if(e.isPaused){return}var f=g.children("ul");var h=f.children("li:first").clone(true);if(e.height>0){d=f.children("li:first").height()}f.animate({top:"-="+d+"px"},e.speed,function(){a(this).children("li:first").remove();a(this).css("top","0px")});if(e.animation=="fade"){f.children("li:first").fadeOut(e.speed);if(e.height==0){f.children("li:eq("+e.showItems+")").hide().fadeIn(e.speed)}}h.appendTo(f)};moveDown=function(g,d,e){if(e.isPaused){return}var f=g.children("ul");var h=f.children("li:last").clone(true);if(e.height>0){d=f.children("li:first").height()}f.css("top","-"+d+"px").prepend(h);f.animate({top:0},e.speed,function(){a(this).children("li:last").remove()});if(e.animation=="fade"){if(e.height==0){f.children("li:eq("+e.showItems+")").fadeOut(e.speed)}f.children("li:first").hide().fadeIn(e.speed)}};return this.each(function(){var f=a(this);var e=0;f.css({overflow:"hidden",position:"relative"}).children("ul").css({position:"absolute",margin:0,padding:0}).children("li").css({margin:0,padding:0});if(b.height==0){f.children("ul").children("li").each(function(){if(a(this).height()>e){e=a(this).height()}});f.children("ul").children("li").each(function(){a(this).height(e)});f.height(e*b.showItems)}else{f.height(b.height)}var d=setInterval(function(){if(b.direction=="up"){moveUp(f,e,b)}else{moveDown(f,e,b)}},b.pause);if(b.mousePause){f.bind("mouseenter",function(){b.isPaused=true}).bind("mouseleave",function(){b.isPaused=false})}})}})(jQuery);


// end news ticker code


