function login(pag){
	if($('#usuario').val()=='' || $('#usuario').val()=='usuario'){
		$('#usuario').focus();
		return;
	}
	if($('#password').val()=='' || $('#password').val()=='password'){
		$('#password').focus();
		return;
	}
	$.ajax({
		type: 'POST',
		url: 'login.php',
		cache: false,
		data: 'usuario=' + encodeURIComponent($('#usuario').val()) + '&password=' + encodeURIComponent($('#password').val())+ '&pag=' + encodeURIComponent(pag) + '&ajax=1',
		success: function(h){
			if(h.charAt(0)=='0'){ //Error
				$('#mensaje2').html(h.substring(2));
				$('#mensaje2').fadeIn();
				$('#usuario').focus();
				return;
			}
			if(h.charAt(0)=='1'){
				top.location.href=h.substring(2);
			}
		},
		error: function(){
			login();
		}
	});
}

function votarImagen(usr,img,n){
	$.ajax({
		type: 'POST',
		url: 'ajax_votar_imagen.php',
		cache: false,
		data: 'img=' + img + '&id_contacto=' + usr + '&ajax=1',
		success: function(h){
			if(h.charAt(0)=='0'){ //Error
				return;
			}
			if(h.charAt(0)=='1'){
				$('#voto-'+n).html(h.substring(2));
				
				return;
			}
		},
		error: function(){
			//alert('1'); return;
			//votarImagen();
		}
	});
}

function eliminarImagen(img,n){
	$.ajax({
		type: 'POST',
		url: 'ajax_eliminar_imagen.php',
		cache: false,
		data: 'img=' + img + '&ajax=1',
		success: function(h){
			if(h.charAt(0)=='0'){ //Error
				return;
			}
			if(h.charAt(0)=='1'){
				parent.$('#img-'+n).hide();
				return;
			}
		},
		error: function(){
			//alert('1');
			//votarImagen();
		}
	});
}

function votarVideo(usr,video,n){
	$.ajax({
		type: 'POST',
		url: 'ajax_votar_video.php',
		cache: false,
		data: 'video=' + video + '&id_contacto=' + usr + '&ajax=1',
		success: function(h){
			if(h.charAt(0)=='0'){ //Error
				return;
			}
			if(h.charAt(0)=='1'){
				$('#votov-'+n).html(h.substring(2));
				
				return;
			}
		},
		error: function(){
			//alert('1');
			//votarImagen();
		}
	});
}

function agregarAgenda(id){
	$.ajax({
		type: 'POST',
		url: 'ajax_agregar_agenda.php',
		cache: false,
		data: 'id=' + id + '&ajax=1',
		success: function(h){
			if(h.charAt(0)=='0'){ //Error
				return;
			}
			if(h.charAt(0)=='1'){
				location.reload();
				
				return;
			}
		},
		error: function(){
			//alert('1');
			//votarImagen();
		}
	});
}

function borrarAgenda(id){
	$.ajax({
		type: 'POST',
		url: 'ajax_borrar_agenda.php',
		cache: false,
		data: 'id=' + id + '&ajax=1',
		success: function(h){
			if(h.charAt(0)=='0'){ //Error
				return;
			}
			if(h.charAt(0)=='1'){
				location.reload();
				
				return;
			}
		},
		error: function(){
			//alert('1');
			//votarImagen();
		}
	});
}


function bloquearContacto(id){
	$.ajax({
		type: 'POST',
		url: 'ajax_bloquear_contacto.php',
		cache: false,
		data: 'id=' + id + '&ajax=1',
		success: function(h){
			if(h.charAt(0)=='0'){ //Error
				return;
			}
			if(h.charAt(0)=='1'){
				location.reload();
				
				return;
			}
		},
		error: function(){
			//alert('1');
			//votarImagen();
		}
	});
}

function desbloquearContacto(id){
	$.ajax({
		type: 'POST',
		url: 'ajax_desbloquear_contacto.php',
		cache: false,
		data: 'id=' + id + '&ajax=1',
		success: function(h){
			if(h.charAt(0)=='0'){ //Error
				return;
			}
			if(h.charAt(0)=='1'){
				location.reload();
				return;
			}
		},
		error: function(){
			//alert('1');
			//votarImagen();
		}
	});
}

function borrarMensaje(id){
	$.ajax({
		type: 'POST',
		url: 'ajax_borrar_mensaje.php',
		cache: false,
		data: 'id=' + id + '&ajax=1',
		success: function(h){
			if(h.charAt(0)=='0'){ //Error
				return;
			}
			if(h.charAt(0)=='1'){
				location.reload();
				
				return;
			}
		},
		error: function(){
			//alert('1');
			//votarImagen();
		}
	});
}

function calificar(id,calif){
	$.ajax({
		type: 'POST',
		url: 'ajax_calificar.php',
		cache: false,
		data: 'id=' + id + '&calif=' + calif + '&ajax=1',
		success: function(h){
			if(h.charAt(0)=='0'){ //Error
				return;
			}
			if(h.charAt(0)=='1'){
				location.reload();
				return;
			}
		},
		error: function(){
			alert('1');
			//votarImagen();
		}
	});
}

