// JavaScript Document

// JavaScript Document

$(function(){
	setValidateF();
	setLoginDisplay();
	setVideoHome();
	
	$('#btn_clear').click(function(){
		$('.input').val('');
	});
})

function setLoginDisplay(){
	$('#logincontainer').hover(
		function(){
			$('#loginform').css('display','block');
		},
		function(){
			$('#loginform').css('display','none');
			$('#loginform input.input').val('');
			$('#loginform .msg_error').css('display','none');
		}
	);
}

function setValidateF(){
	$('form.validate').submit(function(event){
		var post = 'ajax=1';
		var action = '';
		var prevent = 0;
		var cform = $(this);
		
		for(x=0; x < $('.input', this).length; x++){
			if($('.input:eq('+x+')', this).hasClass('checkbx')){
				if($('.input:eq('+x+')', this).is(':checked')){
					post += '&';
					post += $('.input:eq('+x+')', this).attr('name') + '=' + $('.input:eq('+x+')', this).val();
				}
			}else{
				if(post != '')post += '&';
				post += $('.input:eq('+x+')', this).attr('name') + '=' + $('.input:eq('+x+')', this).val();
			}
		}
		action = $(this).attr('action');
		$.ajax({
			type: "POST",
			url: action,
			async: false,
			data: post,
			success: function(msg){
				if(msg != ''){
					ShowAlert(msg, cform);
					prevent = 1;
				}else if($('input[name="location"]', cform).val() == undefined){
					prevent = 1;
				}else{
					$('.msg_error', cform).css('display','none');
					$(cform).attr('action', HTTP+$('input[name="location"]', cform).val());
				}
			}
 		});
		if(prevent)event.preventDefault();
	});
}

function ShowAlert(msg, cform){
	$('.msg_error', cform).css('display','none');
	$('.msg_error', cform).html(msg);
	$('.msg_error', cform).fadeIn('slow');
}

function setVideoHome(){
	$('#video-start').click(function(event){
		$('#video-start').fadeOut('fast');
		$('#videoframe').fadeIn('fast');
		event.preventDefault();
	});
}
