var root = '/';

// ----------------- xmlHttp ------------------- //
var xmlHttp;function GetXmlHttpObject(){var xmlHttp=null;try{xmlHttp=new XMLHttpRequest();}catch(e){try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}}return xmlHttp;}
// ----------------- xmlHttp ------------------- //

var debug = false;
var fulldebug = false;
var sent = false;
var data; // inicializa los campos que van a ser parceados
var redireccion; // inicializa redireccion por si se pide del post
var loadingMsg = "Cargando...";
var sendingMsg = "Enviando...";
var successMsg = 'Mensaje Enviado!';
var badMsg = "Verifique los campos marcados en rojo";

// --------------------------- jQuery Document Ready ----------------------------- //

$(function() {

/*$().mousemove(function(e){
      window.mouseXPos = e.pageX;
      window.mouseYPos = e.pageY;
});*/ 

// FOLOW THE MOUSE
//$("body").append('<div id="follower"></div>');

//$("#follower").hide();

// INIT RELOJ, UPDATE EVERY 1 MINUTE
setInterval("reloj('reloj_li');",30000);

$(".player").hide(); // PLAYERS
$("#video_1.player").show();
$("#imagen_1.player").show();
$("#audio_1.player").show();

$('#resultados_encuesta').hide(); // RESULTADOS ENCUESTA
$('.bt-mas li ul').hide(); // MAS VOTOS

// FOTONOTICIAS
$(".fotonoticia_container").hide();
$("#fotonoticiaitem_1.fotonoticia_container").show();

// LISTADOS
$(".listado").hide();
$("#listado_1.listado").show();

// RESULTADOS ENVIVO
$("#resultado_1.resultado").show();

$("#ranking #mas_leidas.pestana").show();
$("#estadisticas .pestana:first").show();

// seguidor
/*$('.seguidor').mousemove(function(e){
	var data = $(this).attr('rel');
	if(data!=''){
	$("#follower").html(data);
	$("#follower").show();
	$("#follower").css({
		top: (e.pageY + 15) + "px",
		left: (e.pageX + 15) + "px"
	});
	}
});

$(".seguidor").mouseout(function(e){
	$("#follower").hide();
});*/

// --------------------------- RESULTADOS ENCUESTA ----------------------------- //

$('#mostrar_resultados').click(function (){
var html = $.ajax({
url: root+"admin/_plugins/ajax/resultados.php",
async: false
}).responseText;
if($('#resultados_encuesta').is(':hidden')){
$('#resultados_encuesta').html(html).slideDown(300);
}else {
$('#resultados_encuesta').slideUp(300);
}
});

// --------------------------- PARTIDOS EN VIVO BOTON MAS ----------------------------- //

$('.bt-mas > li > a').click(function(){
$('.bt-mas li ul').fadeOut("fast");
if($(this).next().is(':hidden')){
$(this).next().fadeIn("fast");	
}
$(this).next().hover(function() {}, function(){$('.bt-mas li ul').fadeOut("fast");});
});

// --------------------------- LIGTHBOX ----------------------------- //

$('.galeria_li').lightBox({
fixedNavigation:'true',
overlayBgColor: '#ffffff',
overlayOpacity: 0,
containerResizeSpeed: 500,
txtImage: 'Imagen',
txtOf: 'de'
});

// --------------------------- SOLAPAS FOTO AUDIO VIDEO DE LA NOTA 1 ----------------------------- //

$(".pestanas_media a").click(function(){
$(".pestanas_media a").css({'font-weight':'normal'});
$(this).css({'font-weight':'bold'});
$(".foto_destacado_nota_1").hide();
$(".video_destacado_nota_1").hide();
$(".audio_destacado_nota_1").hide();
var id = $(this).attr('id');
$("."+id).fadeIn(1000);
});

// --------------------------- SOLAPAS RANKING ----------------------------- //

$("#ranking .solapas li a").click(function(){
$("#ranking .solapas li").removeClass('on');
$(this).parent().addClass('on');
$("#ranking .pestana").hide();
var id = $(this).attr('id');
id = id.split("_");
id = id[1]+'_'+id[2];
$("#ranking #"+id).fadeIn(300);
});

// --------------------------- SOLAPAS ESTADISTICAS ----------------------------- //

$("#estadisticas .solapas li a").click(function(){
$("#estadisticas .solapas li").removeClass('on');
$(this).parent().addClass('on');
$("#estadisticas .pestana").hide();
var id = $(this).attr('id');
id = id.split("_");
$("#estadisticas #pestana_"+id[1]).fadeIn(300);
});

// --------------------------- IMAGEN AMPLIADA NEXT PREV DOM ----------------------------- //


/*$(".img_next").click(function () {
var cant = $(".player").size();
var id = $(".player:visible").attr("id");
id = id.split('_');
var next = Number(id[1])+1;
if(next<=cant){
$(".player:visible").hide();
$(".player#imagen_"+next).show();
$(".controles_imagenes .orden strong").html(next);
}
});

$(".img_prev").click(function () { 
var cant = $(".player").size();
var id = $(".player:visible").attr("id");
id = id.split('_');
var prev = Number(id[1])-1;
if(prev>0){
$(".player:visible").hide();
$(".player#imagen_"+prev).show();
$(".controles_imagenes .orden strong").html(prev);
}
});*/

// --------------------------- AUDIO NEXT PREV ----------------------------- //

/*$("#audio_next").click(function () { 
var cant = $(".player").size();
var id = $(".player:visible").attr("id");
id = id.split('_');
var next = Number(id[1])+1;
if(next<=cant){
$(".player:visible").hide();
$(".player#audio_"+next).show();
$(".controles .orden strong").html(next);
}
});

$("#audio_prev").click(function () { 
var cant = $(".player").size();
var id = $(".player:visible").attr("id");
id = id.split('_');
var prev = Number(id[1])-1;
if(prev>0){
$(".player:visible").hide();
$(".player#audio_"+prev).show();
$(".controles .orden strong").html(prev);
}
});*/

// --------------------------- FOTONOTICIAS NEXT PREV ----------------------------- //

$(".fotonoticia_next").click(function () { 
var cant = $(".fotonoticia_container").size();
var id = $(".fotonoticia_container:visible").attr("id");
id = id.split('_');
var next = Number(id[1])+1;
if(next<=cant){
$(".fotonoticia_container:visible").fadeOut(0, function(){
$(".fotonoticia_container#fotonoticiaitem_"+next).fadeIn(0);
$(".fotonoticias_controles.controles .orden strong").html(next);
});
}
});

$(".fotonoticia_prev").click(function () { 
var cant = $(".fotonoticia_container").size();
var id = $(".fotonoticia_container:visible").attr("id");
id = id.split('_');
var prev = Number(id[1])-1;
if(prev>0){
$(".fotonoticia_container:visible").fadeOut(0, function(){
$(".fotonoticia_container#fotonoticiaitem_"+prev).fadeIn(0);
$(".fotonoticias_controles.controles .orden strong").html(prev);
});
}
});

// --------------------------- VIDEOS DESTACADOS NEXT PREV ----------------------------- //

$(".video_next_page").click(function () { 
var cant = $(".listado").size();
var id = $(".listado:visible").attr("id");
id = id.split('_');
var next = Number(id[1])+1;
if(next<=cant){
$(".listado:visible").fadeOut(200, function(){
$(".listado#listado_"+next).fadeIn(200);
$("#videos_dest_controles .controles .orden strong").html(next);
});
}
});

$(".video_prev_page").click(function () { 
var cant = $(".listado").size();
var id = $(".listado:visible").attr("id");
id = id.split('_');
var prev = Number(id[1])-1;
if(prev>0){
$(".listado:visible").fadeOut(200, function(){
$(".listado#listado_"+prev).fadeIn(200);
$("#videos_dest_controles .controles .orden strong").html(prev);
});
}
});

// --------------------------- MARQUEE ----------------------------- //

$(".marquee2").marquee(
{ 
       yScroll: "top",                          // the position of the marquee initially scroll (can be either "top" or "bottom") 
       showSpeed: 1000,                          // the speed of to animate the initial dropdown of the messages 
       scrollSpeed: 22,                         // the speed of the scrolling (keep number low) 
       pauseSpeed: 1000,                        // the time to wait before showing the next message or scrolling current message 
       pauseOnHover: true,                      // determine if we should pause on mouse hover 
       loop: -1,                                // determine how many times to loop through the marquees  (#'s < 0 = infinite) 
       fxEasingShow: "swing",                   // the animition easing to use when showing a new marquee 
       fxEasingScroll: "linear",                // the animition easing to use when showing a new marquee 
 
       // define the class statements 
       cssShowing: "marquee-showing2", 
 
       // event handlers 
       init: null,                              // callback that occurs when a marquee is initialized 
       beforeshow: null,                        // callback that occurs before message starts scrolling on screen 
       show: null,                              // callback that occurs when a new marquee message is displayed 
       aftershow: null                         // callback that occurs after the message has scrolled 
}
);

$(".marquee1").marquee(
{ 
       yScroll: "top",                          // the position of the marquee initially scroll (can be either "top" or "bottom") 
       showSpeed: 1000,                          // the speed of to animate the initial dropdown of the messages 
       scrollSpeed: 16,                         // the speed of the scrolling (keep number low) 
       pauseSpeed: 1000,                        // the time to wait before showing the next message or scrolling current message 
       pauseOnHover: true,                      // determine if we should pause on mouse hover 
       loop: -1,                                // determine how many times to loop through the marquees  (#'s < 0 = infinite) 
       fxEasingShow: "swing",                   // the animition easing to use when showing a new marquee 
       fxEasingScroll: "linear",                // the animition easing to use when showing a new marquee 
 
       // define the class statements 
       cssShowing: "marquee-showing1", 
 
       // event handlers 
       init: null,                              // callback that occurs when a marquee is initialized 
       beforeshow: null,                        // callback that occurs before message starts scrolling on screen 
       show: null,                              // callback that occurs when a new marquee message is displayed 
       aftershow: null                         // callback that occurs after the message has scrolled 
}
);

// --------------------------- END jQuery Document Ready ----------------------------- //

});

// --------------------------- Player Picker ----------------------------- //

function playerPicker(id,file_id){
$(".player").hide();
$(".player#"+id).fadeIn(300);
id = id.split('_');
if(id[0]=='imagen'){
$(".controles_imagenes .orden strong").html(id[1]);
}
}

// --------------------------- ENVIVO PICKER ----------------------------- //

function envivoPicker(id){
$(".resultado").hide();
$(".resultado#"+id).fadeIn(300);
id = id.split('_');
//if(id[0]=='imagen'){
//$(".controles_imagenes .orden strong").html(id[1]);
//}
}

// ----------------- jQuery ADDRESS ------------------- //

/*

	// document title
	var title = document.title;
	
	// Serialization utility
	var serialize2 = function(obj, re) {
		var result = [];
		$.each(obj, function(i, val) {
			if ((re && re.test(i)) || !re)
				result.push((typeof val == 'object' ? val.join ? '' + val.join(', ') + '' : serialize(val) : '' + val + ''));
		});
		return result.join(', ');
	}
	
	$.address.change(function(event) {
		
		// PLAYERPICKER
		var qs1 = new Querystring(serialize2(event, /queryString/));
		if(qs1.contains('file')) {
		var id = qs1.get("file");
		$(".player").hide();
		$(".player#"+id).fadeIn(300);
		}
		if(qs1.contains('id') && qs1.contains('file')== false) {
		var id = qs1.get("id");
		$(".player").hide();
		$(".fileid_"+id).fadeIn(300);
		}

		var names = $.map(event.pathNames, function(n) {
			return n.substr(0, 1).toUpperCase() + n.substr(1);
		}).concat(event.parameters.id ? event.parameters.id.split('.') : []);

		$.address.title([title].concat(names).join(' | '));
		
	});

// ----------------- PARSE QUERYSTRING ------------------- //

function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}
*/

// ----------------- RELOJ ------------------- //

function reloj(id){
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ('Tu explorador no soporta AJAX.');
		return;
	} 
	
	container = document.getElementById(id);
	
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState==4) {
		var r = xmlHttp.responseText;
		container.innerHTML = r;
		}
	}
	
	xmlHttp.open('GET',root+'admin/_plugins/ajax/reloj.php',true);
    xmlHttp.send(null);
	
	//setInterval("reloj('id_div');",1000);
	
}

///////////////////// POPUP ////////////////////////

function popup(msg,unblock,red,estate){

//if(unblock=='hold') msg = msg + ' (Enviando) ';
//if(unblock=='fade') msg = msg + ' (Cargando) ';
if(unblock=='click') msg = msg + ' (Click para continuar) ';
if(estate==1) var color = '#090';
if(estate==0) var color = '#900';

$.blockUI({ 
message: msg.replace(/\n/gi,'<br/>'),
//fadeIn: 700, 
//fadeOut: 700, 
//timeout: 3000,
showOverlay: false, 
//centerY: false, 
	css: {
		width: '350px', 
		//top: '10px', 
		//left: '',
        //top:  ($(window).height() - 500) /2 + 'px', 
        //left: ($(window).width() - 500) /2 + 'px', 
		//right: '10px', 
		border: 'none', 
		padding:'15px',
		size:'12.0pt',
		backgroundColor:color,
		backgroundColor:color,
		'-webkit-border-radius': '10px', 
		'-moz-border-radius': '10px',
		opacity: .9,
		color:'#fff'
	}
});

// UNBLOCK HOLD
if(unblock=='hold'){
	// DO NOTHING
}

// UNBLOCK FADE
if(unblock=='fade'){
	window.setTimeout($.unblockUI, 3000);
		//$(document).bind('click', function() {
			//window.setTimeout($.unblockUI, 0);
			//if(red=='si') redir('',5000);
		//});
	if(red=='si') redir('',3000);
}

// UNBLOCK CLICK
if(unblock=='click'){
		$(document).bind('click', function() {
			window.setTimeout($.unblockUI, 100);
			if(red=='si') redir('',5000);
		});
	if(red=='si') redir('',5000);
}

}

// ----------------- PAGINADO BUSQUEDA ------------------- //

function nextBusqueda(from,n,termino,categoria){

//loadingSpinner();

$('#contenedor_paginado').fadeOut(500, function(){

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ('Tu explorador no soporta AJAX.');
		return;
	} 
	
	container = document.getElementById('contenedor_paginado');
	
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState==4) {
		var r = xmlHttp.responseText;
		//alert(r);
		container.innerHTML = r;
		//$('#follower').fadeOut(500);
		$('#contenedor_paginado').fadeIn(500);
		$('.actual').html((from/n)+1);
		$('.n').html(from+n);
		}
	}
	from = from + n;
	xmlHttp.open('GET',root+'admin/_plugins/ajax/paginadoBusqueda.php?from='+from+'&n='+n+'&termino='+termino+'&categoria='+categoria+'&actual='+((from/n)+1),true);
    xmlHttp.send(null);

});

}

function prevBusqueda(from,n,termino,categoria){

//loadingSpinner();

$('#contenedor_paginado').fadeOut(500, function(){

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ('Tu explorador no soporta AJAX.');
		return;
	} 
	
	container = document.getElementById('contenedor_paginado');
	
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState==4) {
		var r = xmlHttp.responseText;
		container.innerHTML = r;
		//$('#follower').fadeOut(500);
		$('#contenedor_paginado').fadeIn(500);
		$('.actual').html((from/n)+1);
		$('.n').html(from+n);
		}
	}

	from = from - n;
	xmlHttp.open('GET',root+'admin/_plugins/ajax/paginadoBusqueda.php?from='+from+'&n='+n+'&termino='+termino+'&categoria='+categoria+'&actual='+((from/n)+1),true);
    xmlHttp.send(null);

});

}

// ----------------- VOTAR ------------------- //

function votar(id){

var send = 0;

id = id.split(',');
for(i in id){
var valor = $("label[for=opcion_"+id[i]+"]").attr('class');
var valor2 = $("#opcion_"+id[i]).attr('value');
valor2 = valor2.split(',');
if(valor=='radio_checked') {
send = id[i]+"="+valor+"&pregunta_id="+valor2[0]+"&opcion_id="+valor2[1];
}
i++;
}

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null){
alert ('Tu explorador no soporta AJAX.');
return;
} 

xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState==4) {
var r = xmlHttp.responseText;
popup(r,'fade','no',1);

var html = $.ajax({
url: root+"admin/_plugins/ajax/resultados.php",
async: false
}).responseText;

if($('#resultados_encuesta').is(':visible')){
$('#resultados_encuesta').html(html);
}


}
}
	
	xmlHttp.open("POST",root+'admin/_plugins/ajax/votar.php',true);
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader("Content-length",send.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(send);
	
}

///////////////////// LOADING BAR ////////////////////////

function loadingSpinner(){

$("#follower").css({
		background: "#FFF url("+root+"img/loading.gif) no-repeat center",
		position: "absolute",
		height: "28px",
		width: "28px",
		top: (window.mouseYPos + 15) + "px",
		left: (window.mouseXPos + 15) + "px"
});

var data = '';
$("#follower").html(data);
$("#follower").fadeIn(500);

$(document).mousemove(function(e){
	$("#follower").css({
		top: (e.pageY + 15) + "px",
		left: (e.pageX + 15) + "px"
	});
});

window.setTimeout(function(){$("#follower").fadeOut(500);}, 3000);
	
}

///////////////////// LOADING BAR ////////////////////////

function responseBar(r){

$("#follower").css({
		top: (window.mouseYPos + 15) + "px",
		left: (window.mouseXPos + 15) + "px"
});

$("#follower").html(r);
$("#follower").fadeIn(500);

$(document).mousemove(function(e){
	$("#follower").css({
		top: (e.pageY + 15) + "px",
		left: (e.pageX + 15) + "px"
	});
});

window.setTimeout(function(){$("#follower").fadeOut(500);}, 3000);

}

///////////////////// FECHAS FIXTURE ////////////////////////

function fechasFixture(cat_id,subcat_id,liga_id,from,n,modo){

//loadingSpinner();

$("#contenedor_fixture_fechas").fadeOut(500, function(){

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ('Tu explorador no soporta AJAX.');
		return;
	} 
	
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState==4) {
		var r = xmlHttp.responseText;
		$("#contenedor_fixture_fechas").html(r);
		//$('#follower').fadeOut(500);
		$('#contenedor_fixture_fechas').fadeIn(500);
		$('.actual').html((from/n)+1);
		}
	}
	if(modo==1) from = from + n;
	if(modo==0) from = from - n;
	xmlHttp.open('GET',root+'admin/_plugins/ajax/fechasFixture.php?cat_id='+cat_id+'&subcat_id='+subcat_id+'&liga_id='+liga_id+'&from='+from+'&n='+n,true);
    xmlHttp.send(null);

});

}

///////////////////// IMAGEN AMPLIADA AJAX ////////////////////////

function imagenAmpliada(cat_id,from,n,modo){

//loadingSpinner();

//$("#foto-ampliada").fadeOut(100, function(){

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ('Tu explorador no soporta AJAX.');
		return;
	} 
	
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState==4) {
		var r = xmlHttp.responseText;
		$("#foto-ampliada").html(r);
		//$('#follower').fadeOut(500);
		//$('#foto-ampliada').fadeIn(500);
		$('.actual_ampliada').html((from/n)+1);
		}
	}
	if(modo==1) from = from + n;
	if(modo==0) from = from - n;
	xmlHttp.open('GET',root+'admin/_plugins/ajax/imagenAmpliada.php?cat_id='+cat_id+'&from='+from+'&n='+n,true);
    xmlHttp.send(null);

//});

}

///////////////////// VIDEO AMPLIADO AJAX ////////////////////////

function videoAmpliado(cat_id,from,n,modo){

//loadingSpinner();

//$("#foto-ampliada").fadeOut(100, function(){

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ('Tu explorador no soporta AJAX.');
		return;
	} 
	
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState==4) {
		var r = xmlHttp.responseText;
		$("#video-ampliado").html(r);
		//$('#follower').fadeOut(500);
		//$('#foto-ampliada').fadeIn(500);
		//$('.actual_ampliada').html((from/n)+1);
		}
	}
	if(modo==1) from = from + n;
	if(modo==0) from = from - n;
	xmlHttp.open('GET',root+'admin/_plugins/ajax/videoAmpliado.php?cat_id='+cat_id+'&from='+from+'&n='+n,true);
    xmlHttp.send(null);

//});

}

///////////////////// AUDIO AMPLIADO AJAX ////////////////////////

function audioAmpliado(cat_id,from,n,modo){

//loadingSpinner();

//$("#foto-ampliada").fadeOut(100, function(){

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ('Tu explorador no soporta AJAX.');
		return;
	} 
	
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState==4) {
		var r = xmlHttp.responseText;
		$("#audio-ampliado").html(r);
		//$('#follower').fadeOut(500);
		//$('#foto-ampliada').fadeIn(500);
		//$('.actual_ampliada').html((from/n)+1);
		}
	}
	if(modo==1) from = from + n;
	if(modo==0) from = from - n;
	xmlHttp.open('GET',root+'admin/_plugins/ajax/audioAmpliado.php?cat_id='+cat_id+'&from='+from+'&n='+n,true);
    xmlHttp.send(null);

//});

}

///////////////////// PAGINADO MEDIA PICKER ////////////////////////

function paginadoMpicker(cat_id,from,n,modo,mode){

//loadingSpinner();

$("#paginadoMpickerContainer").fadeOut(100, function(){

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ('Tu explorador no soporta AJAX.');
		return;
	} 
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState==4) {
		var r = xmlHttp.responseText;
		$("#paginadoMpickerContainer").html(r);
		$("#paginadoMpickerContainer").show();
		//$('#follower').fadeOut(500);
		//$('#foto-ampliada').fadeIn(500);
		$('#videos_dest_controles .controles .orden strong').html(actual);
		}
	}
	if(modo==1) from = from + n;
	if(modo==0) from = from - n;
	var actual = (from/n)+1;	
	xmlHttp.open('GET',root+'admin/_plugins/ajax/paginadoMpicker.php?cat_id='+cat_id+'&from='+from+'&n='+n+'&mode='+mode+'&actual='+actual,true);
    xmlHttp.send(null);

});

}

///////////////////// RECUPERA PASSWORD ////////////////////////

function recuPass(){

	var email = $('#email_log').val();
	
	if(email) {
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ('Tu explorador no soporta AJAX.');
		return;
	} 
	
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState==4) {
		var r = xmlHttp.responseText;
		$("#response_recuPass").css("color","red");
		$("#response_recuPass").html(r);
		}
	}

	xmlHttp.open('GET',root+'admin/_plugins/ajax/recuPass.php?email='+email,true);
    xmlHttp.send(null);
	
	}else {
	$("#response_recuPass").css("color","red");
	}

}

///////////////////// VALIDAR ////////////////////////

function validar(campos,mode,url,up){

	if(sent) return false;
	popup(loadingMsg,'hold','no',0);
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null){
		alert ('Tu explorador no soporta AJAX.');
		return;
	} 
	
	if(url) {
	redireccion = url;
	}else {
	redireccion = 0;
	}
		
	data = document.getElementById(campos).value;
	data = data.split(',');
	var params = parseParams(data);
	
	xmlHttp.onreadystatechange = doValidar;
	xmlHttp.open("POST",root+'validate.php?mode='+mode,true);
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader("Content-length",params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
	
}

function doValidar(){ 

var errores = 0;

	if (xmlHttp.readyState==4){
	
		//$('html, body').animate({scrollTop:0}, 1500);

		var r = xmlHttp.responseText;

		// debug
		if(debug == true) alert(r);
		if(debug == true && redireccion!=0) alert('redireccionar a la url: '+redireccion+' si es que todos los campos estan validados.');
		
		var x = 0;
		var f = new Array();
		
		for(i in data){
			f[x] = r.substr(x,1);
			
			// fulldebug
			if(fulldebug == true) alert('campo numero:'+f[x]);
			
			validate(f[x],data[i]);
			x++;
		}
		
		for(i in f){
			if(f[i] == '0') errores++;
		}
		
		// fulldebug
		if(fulldebug == true) alert('errores='+errores);
				
		if(errores > 0){
			popup(badMsg,'fade','no',0);
		}else{
			sent = true;
			popup(sendingMsg,'hold','no',0);
			popup(successMsg,'fade','no',1);
			if(redireccion!=0) redir(redireccion,5000);
		}
	
	}

}

////////////////// COLOREA CAMPOS ///////////////////////////

// validate estilo de campos
function validate(status,id){
if(status == 0){
$("#"+id).css('background','#ffe3e3');
$("#"+id).css('color','red');
$("#"+id).css('border','2px solid red');
}else{
$("#"+id).css('background','#e3ffe8');
$("#"+id).css('color','green');
$("#"+id).css('border','2px solid green');
}
}

//////////////////// PARSER /////////////////////////

// parser
function parseParams(params){
var contenedor = '';
for(var contar in params){
var type = gettype(params[contar]);
if(type == 'checkbox' || type == 'radio'){
contenedor += params[contar]+'='+getcheck(params[contar])+'&';
}else if(type == 'select-multiple'){
contenedor += params[contar]+'='+getMultiple(params[contar])+'&';
}else{
contenedor += params[contar]+'='+escape(getval(params[contar]))+'&';
}
}
return contenedor.substr(0,contenedor.length-1);
}

// Get And Sets
function setval(id,val){
document.getElementById(id).value = val;
}
function getval(id){
return document.getElementById(id).value;
}
function getcheck(id){
return document.getElementById(id).checked;
}
function gettype(id){
return document.getElementById(id).type;
}
function getMultiple(ob){
ob = document.getElementById(ob);
selected = new Array();
for(var i = 0; i < ob.options.length; i++) if(ob.options[i].selected) selected.push(ob.options[i].value);
return selected;
}

///////////////// REDIR ////////////////////////////

// redir
function redir(url,timeout){
	setTimeout('doRedir(\''+url+'\')',timeout);
}
// do redir
function doRedir(url){
	window.location = url;
}

