// Javascript Module
jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);

};

function showhide()
{
	//$("#op").toggle(500);
	$("#opOthers").toggle(500);
	$("#viewO").toggle();
	$("#closeO").toggle();
}
function showhideNews()
{
	$("#minutoN").toggle();
	$("#leidasN").toggle();
}
function restore(e)
{
    //document.getElementById('div'+e.id).innerHTML='';
    document.getElementById(e).className='inputB';
    document.getElementById('errorLog').style.display='none';
}
function Norestore()
{
    document.getElementById('username').className='req';
    document.getElementById('password').className='req';
    document.getElementById('errorLog').style.display='';
}
function GoNext()
{
    name=document.getElementById('username').value;
	paswd=document.getElementById('password').value;
	if (name!='' && paswd!='') document.userLogin.submit();
	else  Norestore();
}
function GoNext1()
{
	$("#username").keyup(function(e){
		if(e.keyCode==13) GoNext();
   	});
}
function GoNext2()
{
	$("#password").keyup(function(e){
		if(e.keyCode==13) GoNext();
   	});
}

function validate()
{
	sw=true;
	if (document.getElementById('search').value=='')
		{
		sw=false;
		scroll(0,0);
		}
	else{
		dato=document.getElementById('search').value;
		domainS=document.getElementById('dom').value;
		document.location.href=domain+'/'+domainS+'='+dato+'/'; 
		}
}

function validateF(){
	if (!document.getElementById('searchF').value){
		scroll(0,0);
	}
	else{
		dato=document.getElementById('searchF').value;
		domainS=document.getElementById('domainF').value;
		document.location.href=domainS+'='+dato+'/'; 
	}
}
function validate2()
{
		AdvHisto=document.getElementById('searchH').value;
		AdvDe=document.getElementById('dateH1').value;
		AdvHasta=document.getElementById('dateH2').value;
		AdvCateg=document.getElementById('categ').value;
		domain=document.getElementById('domi').value;
		domainS=document.getElementById('domS').value;
		document.location.href=domain+domainS+'='+AdvHisto+'_'+AdvDe+'_'+AdvHasta+'_'+AdvCateg+'/'; 
}
function validate3()
{
	$("#search").keyup(function(e){
		if(e.keyCode==13) validate();
   	});
}

function validateFot()
{
	sw=true;
	if (document.getElementById('searchF').value=='')
		{
		sw=false;
		scroll(0,0);
		}
	else{
		dato=document.getElementById('searchF').value;
		domain=document.getElementById('domF').value;
		domainS=document.getElementById('sdFo').value;
		document.location.href=domain+'/'+domainS+'='+dato+'/'; 
		}
}
function validateFot2(dato)
{
		domain=document.getElementById('domF').value;
		domainS=document.getElementById('sdFo').value;
		document.location.href=domain+'/'+domainS+'='+dato+'/'; 
}
function validateFotent()
{
	$("#searchF").keyup(function(e){
		if(e.keyCode==13) validateFot();
   	});
}

function controlDownload()
{
	domain=document.getElementById('sd').value;
	$.ajax({
	   type: "POST",
	   url: domain+"/code/controlDownload.php",
	   success: function(url){
		 $('#conDown').html(url);
	   }
	 });
}

function validateS()
{
	$("#searchH").keyup(function(e){
		if(e.keyCode==13) validate2();
   	});
}

var nTry = 0;
function submitReminder(){

	reminderBox = $('#reminderBox').val();
	domain=document.getElementById('sd').value;
	if(reminderBox!='' && nTry < 5 ){
		$('#loading').fadeIn();
		$.ajax({
					url: domain+'/code/reminderPass.php',
					data: 'reminderBox='+reminderBox,
					type:"POST",
					complete : function(ob){
									$("#results_msg").html(ob.responseText);
									nTry = nTry + 1;
									$('#loading').fadeOut();
									contador = 1;
									return false;
								}
		 });
		return false;	 
	}
}
var contador=1;
function GoReminder(){
	$("#reminderBox").keyup(function(e){
		if(e.keyCode==13 && contador==1) {contador = contador + 1;submitReminder(); return false;}
   	});
}

// Ready section
 $(document).ready(function(){
	domain=document.getElementById('sd').value;
	var target = domain+'/code/login.php';
	
	$("#userLogin input").keypress(function(){
		$("#userLogin").attr('action',target);
		$('#lastURL').val(window.location.pathname);
	});
	
	$("#userLogin input").bind('paste', function(e) { 
    	$("#userLogin").attr('action',target);
		$('#lastURL').val(window.location.pathname);
   	});
	
	$('#logout').click(function(){
	 	location.href = domain+'/code/logout.php?lastURL='+window.location.pathname;						
	});
	
});
