/*
 * Classe di gestione product_search v1.0.0
 */

function login(id)
{
	this.id=id;
	
	this.login=login;
    this.cercaAge=cercaAge;
    this.cercaCliente=cercaCliente;
	
	function login(){
		var loginForm=document.getElementById("loginform");
		
		var user=loginForm.user.value;
		var pass=loginForm.pass.value;
		
		$.ajax({
			cache: false,
			type: "POST",
			url: "ajax.php?component=login&login=1",
			data: "user=" + user + '&password=' + pass,
            success: function(html){
            	var response= html.split("::"); 
        		if(response[1]=="OK"){
        			location.href='index.php?idp=1';
                }else if(response[1]=="OKAGE"){
                    $("#hiddenAgenti").fancybox().trigger('click');
                    loginForm.user.value="";
                    loginForm.pass.value="";
        		} else {
        			var err=response[1];
        			alert(err);
        		}
			}
		});
	}
    
    function cercaAge(){
        var data=$("#txtRicCli").val();
        var tipo_ric=$("#sel_tipo_ric").val();
        
        $.ajax({
			cache: false,
			type: "POST",
			url: "ajax.php?component=login&cercaAge=1&id=" + this.id,
			data: "data=" + data + "&tipo_ric=" + tipo_ric,
            success: function(html){
            	$("#agePanel").html(html);
			}
		});
    }
    
    function cercaCliente(cod_cli){
        $.ajax({
			cache: false,
			type: "POST",
			url: "ajax.php?component=login&loginAge=1&id=" + this.id + "&cod_cli=" + cod_cli,
            success: function(html){
            	var response= html.split("::"); 
        		if(response[1]=="OK"){
        			location.href='index.php?idp=1';
        		} else {
        			var err=response[1];
        			alert(err);
        		}
			}
		});
    }
}

 $(document).ready(function(){
    $("#hiddenAgenti").fancybox(); 
});
