var Site = function(){};

Site.initMenu = function () {
	var menuID;
	var tabClass;
	
	$j('#menu_tab a').hover(function() {
		menuID = $j(this).parents('td').attr("id");
		$j('.menu_bottom div.' + menuID).show();
	}, function(){
		menuID = $j(this).parents('td').attr("id");
		$j('.menu_bottom div.' + menuID).hide();
	});
	
	$j('.menu_bottom div.sous_menu').hover(function(){
		tabClass = $j('#' + menuID).attr('class');
		if (tabClass != 'tab_selected') {
			$j('#' + menuID).addClass('tab_selected');	
		}
		$j(this).show();
	}, function(){
		if (tabClass != 'tab_selected') {
			$j('#' + menuID).removeClass('tab_selected');	
		}
		$j(this).hide();
	});
};

Site.validQuickPoll = function () {
	if ($j("input:radio[@name='poll'][@checked]").length) {
		$j.post('validQuickPoll.php', {
			response : $j("input:radio[@name='poll'][@checked]").val()
		}, function(data){
			Site.hideQuickPoll();
		});
	}
	else {
		alert('Please select an option.');
	}
};

Site.hideQuickPoll = function () {
	$j('#button_poll_vote').hide();
	$j('#quick_poll').html('<div style="padding: 20px 0 20px 0;text-align:center;"><strong>Thank you for your vote!</strong></div>');
};

Site.initFormContact = function () {
	var formContact = $j('#contact');
	
	if (formContact.length !== 0) {
		// Last name
		$j.form.addField('contact', 'contact_last_name', {
			required:true,
			type:'string',
			errorMessage:'Insert your last name.'
		});
		// First name
		$j.form.addField('contact', 'contact_first_name', {
			required:true,
			type:'string',
			errorMessage:'Insert your first name.'
		});
		// Email
		$j.form.addField('contact', 'contact_email', {
			required:true,
			type:'email',
			errorMessage:'Insert an valid email adress.'
		});
		// Question
		$j.form.addField('contact', 'contact_question', {
			required:true,
			type:'string',
			errorMessage:'Ask your question'
		});
		
		// VALIDATION
		$j('#contact').submit(function(){
			if (!$j.form.checkForm('contact')) {
				return(false);
			}
			
			if (	($j('#contact_theme').val() == 'business_school')
				&&	($j('#contact_area').val() == '')
				||	($j('#contact_country').val() == '')
				||	($j('#contact_school').val() == '')) {
					
				$j.debug.displayError('Please select your school.');
				
				return(false);
			}
			
			return(true);
		});
	}
};

Site.initFormRegistration = function () {
	var formContact = $j('#registration');
	
	if (formContact.length !== 0) {
		// Last name
		$j.form.addField('registration', 'lastname', {
			required:true,
			type:'string',
			errorMessage:'Insert your last name.'
		});
		// First name
		$j.form.addField('registration', 'firstname', {
			required:true,
			type:'string',
			errorMessage:'Insert your first name.'
		});
		// Email
		$j.form.addField('registration', 'email', {
			required:true,
			type:'email',
			errorMessage:'Insert an valid email adress.'
		});
		
		// VALIDATION
		$j('#registration').submit(function(){
			if (!$j.form.checkForm('registration')) {
				return(false);
			}
			
			return(true);
		});
	}
};

Site.checkFieldsToDisplayQuestion = function () {
	if (	$j.string.exist($j('#contact_last_name').val())
		&&	$j.string.exist($j('#contact_first_name').val())
		&&	$j.string.isEmail($j('#contact_email').val()) ) {
			
		$j('.displaying').show();
		return false;
	}
	$j('.displaying').hide();
};

Site.checkSelectToDisplaySchool = function () {
	if ($j('#contact_theme').val() == 'business_school') {
			
		$j('.disp_area').show();
		if ($j('#contact_area').val() != '') {
			
			$j('.disp_country').show();
			
			if ($j('#contact_country').val() != '') {
				
				$j('.disp_school').show();
			}
			else {
				$j('.disp_school').hide();
			}
		}
		else {
			$j('.disp_country').hide();
		}
		return false;
	}
	$j('.disp_area').hide();
	$j('.disp_country').hide();
	$j('.disp_school').hide();
};


Site.initFormPreRegistration= function () {
	var formPreRegistration = $j('#form_pre_registration');
	
	if (formPreRegistration.length !== 0) {
		// Last name
		$j.form.addField('form_pre_registration', 'lastname', {
			required:true,
			type:'string',
			errorMessage:'Insert your last name.'
		});
		// First name
		$j.form.addField('form_pre_registration', 'firstname', {
			required:true,
			type:'string',
			errorMessage:'Insert your first name.'
		});
		// Email
		$j.form.addField('form_pre_registration', 'email', {
			required:true,
			type:'email',
			errorMessage:'Insert an valid email adress.'
		});
		// Question
		$j.form.addField('form_pre_registration', 'text', {
			required:true,
			type:'string',
			errorMessage:'Fill your request'
		});
		
		// VALIDATION
		$j('#form_pre_registration').submit(function(){
			if (!$j.form.checkForm('form_pre_registration')) {
				return(false);
		}
			
			
		return(true);
		});
	}
};

Site.initFormGetInfo= function () {
	var formGetInfo = $j('#form_get_info');
	
	if (formGetInfo.length !== 0) {
		// Last name
		$j.form.addField('form_get_info', 'lastname', {
			required:true,
			type:'string',
			errorMessage:'Insert your last name.'
		});
		// First name
		$j.form.addField('form_get_info', 'firstname', {
			required:true,
			type:'string',
			errorMessage:'Insert your first name.'
		});
		// Email
		$j.form.addField('form_get_info', 'email', {
			required:true,
			type:'email',
			errorMessage:'Insert an valid email adress.'
		});
		// Country
		$j.form.addField('form_get_info', 'country_id', {
			required:true,
			type:'string',
			errorMessage:'Select your country.'
		});
		// Question
		//$j.form.addField('form_get_info', 'text', {
		//	required:true,
		//	type:'string',
		//	errorMessage:'Fill your request'
		//});
		
		// VALIDATION
		$j('#form_get_info').submit(function(){
			if (!$j.form.checkForm('form_get_info')) {
				return(false);
		}
		
		// Mode
		if(!document.getElementById('mode_all').checked && !document.getElementById('mode_single').checked){
				$j.debug.displayError('Please select an option between sending your request to many school or only to this business school.');
				return(false);
		};
		
		// Agree
		if(!document.getElementById('agree').checked){
				$j.debug.displayError('You must agree the conditions to process with request sending');
				return(false);
		};
			
		return(true);
		});
	}
};

