var core={
	ajax:function(o,_url){
		$.ajax({
			url: _url,
			type: 'POST',
			dataType: 'json',
			data: {'data': o},
			success: function(data){ 
				core.closeRegister();
				$("#register_confirmed").dialog("open");
			},
		});
	},
	closeRegister:function(){$("#register_form").dialog("close");},
	closeRegisterthx:function(){$("#register_confirmed").dialog("close");},
	submitForm:function(o){
		var bvalid = true;
		bvalid = bvalid && checkInput($('#nom'));
		bvalid = bvalid && checkInput($('#prenom'));
		bvalid = bvalid && checkInput($('#adresse'));
		bvalid = bvalid && checkInput($('#tel'));
		bvalid = bvalid && checkInput($('#fax'));
		bvalid = bvalid && checkInput($('#email'));
		bvalid = bvalid && checkInput($('#cp'));
		bvalid = bvalid && checkInput($('#ville'));
		bvalid = bvalid && checkInput($('#diplome'));
		bvalid = bvalid && checkInput($('#fac'));

		
		if( bvalid ){
			var dataForm={
					'nom':$('#nom').val(),
					'prenom':$('#prenom').val(),
					'adresse':$('#adresse').val()+' '+$('#adresse2').val(),
					'tel':$('#tel').val(),
					'fax':$('#fax').val(),
					'email':$('#email').val(),
					'cp':$('#cp').val(),
					'ville':$('#ville').val(),
					'diplome':$('#diplome').val(),
					'fac':$('#fac').val(),
					'code':$('#code').val(),
					'stage':$('#stage').val(),
					'stageville':$('#stageville').val(),
					'stageannee':$('#stageannee').val(),
					'orientation':$('#orientation').val(),
					'assistante':$('#assistante').val()	};
					
			core.ajax(dataForm,'privilege/ajax/add_member.php');
		}
	},
	login:function(o){
		var dataForm={'vip_login': $('#vip_login').val(), 'password':$('#vip_password').val() };
		$.ajax({
			url: 'privilege/ajax/login.php',
			type: 'POST',
			dataType: 'json',
			data: {'data': dataForm},
			success: function(data){ 
				if(data == 'redirect'){
					window.location.href = "./privilege/";	
				}
				
			},
		});
	},
	login2:function(o){
		var dataForm={'vip_login': $('#vip_login').val(), 'password':$('#vip_password').val() };
		$.ajax({
			url: '../privilege/ajax/login.php',
			type: 'POST',
			dataType: 'json',
			data: {'data': dataForm},
			success: function(data){ 
				if(data == 'redirect'){
					window.location.href = "../privilege/";	
				}
				
			},
		});
	}
};

// JavaScript Document
$(document).ready(function(){

	//login_form
	$("#register_form").dialog({autoOpen:false, modal: true, width:722,height:722,resizable: false,draggable: false});
	$("#register_confirmed").dialog({autoOpen:false, modal: true, width:722,height:722,resizable: false,draggable: false});
	$("#register_form").parent().attr('class','').addClass('ui-dialog');
	$("#register_confirmed").parent().attr('class','').addClass('ui-dialog');
	
	$("p.register a").click(function(){
		$("#register_form").dialog("open");
	});
	
});

function checkInput(o){
	if(o.val() == ""){
		o.addClass( "ui-state-error" );
		return false;
	}else {
		o.removeClass( "ui-state-error" );
		return true;
	}
}

function checkRegexp( o, regexp, n ) {
	if ( !( regexp.test( o.val() ) ) ) {
		o.addClass( "ui-state-error" );
		return false;
	} else {
		o.removeClass( "ui-state-error" );
		return true;
	}
}

function checkSelect(o,b){
	if(b.val() == 1){
		o.val(0);
		return true;
	}if(b.val() == 0 && o.val() != 0){
		return true;
	}else{
		o.addClass( "ui-state-error" );
		return false;
	}
}

