/**
* Uses MooTools vers: 1.11
* It uses the Fx.Slide method. For more info on Fx.Slide visit http://docs.mootools.net/Effects/Fx-Slide.js
**/
var panelSlide = "";
var panel_form = "";
var url = "";
var redirect = true;



function initDropdown(){
	panelSlide =	new Fx.Slide('pannel',{duration:500});
	hideIt(panelSlide);
	$('wrapper').style.display='block';
}
function hideIt(fx){
	fx.hide();
}
function doSlide(){
	panelSlide.toggle();		
}

window.addEvent('domready', function(){
	$('close').addEvent('click', function(e){	
		e = new Event(e);
		panelSlide.slideOut();
		if(url){ if(panelSlide.wrapper.offsetHeight == 0){redirect=false;}else{	redirect=true; setTimeout('doRedirect()', 5000);}}//this controls the redirect
		e.stop();
	});
	$('toggle').addEvent('click', function(e){
		e = new Event(e);
		panelSlide.toggle();
		if(url){ if(panelSlide.wrapper.offsetHeight == 0){redirect=false;}else{	redirect=true; setTimeout('doRedirect()', 5000);}} //this controls the redirect
		e.stop();
	});
});

function doRedirect()
{
	if(redirect && url.length >1) {
		window.location=url;
	}
}

function dosubmit(form)
{
	panel_form = form;
	panel_form.onsubmit = new Function("return validate_survey();");
}
function validate_survey(form)
{
	var survey_good = true;
	var notchecked = true;
	var alert_error = false;
	var error_string = "All Values are Required!. Please correct the errors marked in red \n and Double Your Changes of winning the scholarship!";
	
	for(i=0; i<panel_form.length; i++)
	{
		if(panel_form[i].type == "select-one"){
			if(checkDrops(panel_form[i])){if(notchecked){alert_error = true; notchecked=false;}}
		}
	}
	if(alert_error){
		alert(error_string);
		survey_good = false;
	}
	
	return survey_good;
}

function checkDrops(element){
	if(element.value==""){
		element.style.backgroundColor="red";
		element.style.color="white";
		return true;
	}else{
		element.style.backgroundColor="white";
		element.style.color="black";
		return false;
	}
}
