/* Class names to replace */
var strTextClassNameSmall = 'vtTextSmall',strTextClassName = 'vtText', strTextAreaClassName = 'vtTextArea',strSelectClassName = 'vtSelect', strCheckClassName = 'vtCheck';

/* AJAX setup */
var strAction = './templates/default/include/', strMethod = 'post', strTemplate = './templates/default/include/register_form.php', strContainerName2 = '#signin-viewport';
//var base_url = 'http://localier.net/lib/';
var base_url ='../lib/';
/* Other Form Elements */
var strContactButton = 'submitForm';

/* Array to store the temp answers */
var arrFieldValues = {'email_login': null,'password_login':null};

var	email = $( "#email_login" ),
			password = $( "#password_login" );
			


function beforeCall2(form, options){
	
                if (window.console) 
                    console.log("Right before the AJAX form validation call");
					$("#load_box2").html('<img src="./templates/default/images/form/ajax-loader.gif"><br><b>Traitement en cours...</b>');
					$('#load_box2').css("background","transparent");
                return true;
            }


//


//


function ajaxValidationCallback2(status, form, json, options)
		{
			
			if (window.console)
			console.log(status);
			if (status === true)
			{
			var arrFormValues = { email:$('#email').val(),password:$('#password').val()
			 };
		
			var url = "./templates/default/include/ajaxValidateConnect.php";
			
			  var data = form.serialize();
		
			
			$.ajax({
				type: "POST",
				url: url,				
				data: data,
				error:function(res) {alert(res.statusText);},
				
				success: function(msg){
					
					var res = $(msg).find('heading').text();
					var txt = $(msg).find('body').text();
					if (res=='ok')
					{
						var val1 = $(msg).find('val1').text();
						var val2 = $(msg).find('val2').text();
						var val3 = $(msg).find('val3').text();
						var val4 = $(msg).find('val4').text();
						var valFin = val1+'<br>'+val2+'<br>'+val3+'<br>'+val4+'<br>';
						displaySuccess2(valFin);
						
					}
					else
					{alert (txt);}
					
					
				}
				
			});
			
			}
			
		}






$(document).ready(function(){
	$(strContainerName2+" > *").unbind('*');
	
	
	attatchEvents2();
	

});




function attatchEvents2() {
	/* displays & hides the form */	
	$("#togConnex").click(function(){
		
		//$('#quote-cover').fadeOut(100);
		if ($(this).hasClass('on')) {
			$("#load_box2").html('');
			
			$('#signin-cover').fadeOut(100);
			
			
			$('form',strContainerName2).fadeOut(50);
			$(strContainerName2).slideUp(400).next('#connexControl').children('#togConnex').removeClass("on");
			$('#togConnex').attr("title","Connexion");
			$('#togConnex').text("Connexion");
		}else{
			$('#signin-cover').css('height',$(document).height()+'px').fadeTo(400, 0.5);
			
			$(strContainerName2).slideDown(600,function() {$('form',strContainerName2).fadeIn(200)}).next('#connexControl').children('#togConnex').addClass("on");
			if($('#togConnex').text()!=="Merci !")
			{
				$('#togConnex').attr("title","En cours");
				$('#togConnex').text("En cours !");	
			}	
		}
		
		
		$('#'+strContactButton).attr('disabled', 'disabled');


		return false;
		
	});
	
	
	/* Closes the Quote div when the backdrop is clicked */
	$('#signin-cover').live('click', function() { $("#togConnex").trigger('click'); });

	}

/* On completion will slide the box up and display a message */
function displaySuccess2(text) {
	//alert(txt);
	jQuery("#formSignin").validationEngine('hide');
	$('#signinForm').hide();

	$(strContainerName2)	.css('overflow','hidden')
						.animate({ height : '130px'}, 1200);
						
						
						$('#infocon').html('<h4>Merci !</h4><br><span>'+text+'</span>');
						
						$('#togConnex').css("color","black");
						$('#togConnex').css("background","yellow");
						$('#togConnex').css("border", "2px solid #C30");
						$('#togConnex').attr("title","Merci !");
						$('#togConnex').text("Merci !");
						
						
	setInterval(function() { 	
		$('#signinForm').fadeOut(100);
		
		$(strContainerName2).slideUp(400).next('#connexControl').children('#togConnex').removeClass("on"); }, 5000);
						
}


