
$().ready(function(){
	
	$('#i_r').focus();

	$("#i_r").keyup(function(){
		if($("#i_r").val()!=''){
			$("#l_r").text('Pressez "Entrée" pour voir les résultats');
		}
		else{
			$("#l_r").text('Tapez votre recherche');
		}
	});

	$('#d3').click(function(){
		$('#f_r').submit();
	});
	

}); 

function ts(){
	return (new Date()).getTime();
}

function isC(value){
	regC = new RegExp("[a-z]","gi");

	if(regC.test(value))
		return true;
	else
		return false;
}

function isP(value){
	regP = new RegExp("[a-z0-9._-]","gi");

	if(regP.test(value) || value.length == 0)
		return true;
	else
		return false;
}

function isI(value){
	regI = new RegExp("[0-9]","gi");

	if(regI.test(value))
		return true;
	else
		return false;
}

function isE(value){
	regE = new RegExp("^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$","gi");

	if(regE.test(value))
		return true;
	else
		return false;
}

function doEngine(lng) {
  window.external.AddSearchProvider('http://www.hooseek.com/hooseek.php?lang='+lng);
}

function sHP(curr) {
	if(navigator.appVersion.indexOf("MSIE") != -1) {
		curr.style.behavior='url(#default#homepage)';
		curr.setHomePage('http://www.hooseek.com/');
		return true;
	}
	else{
		tb_show('Mettre hooseek en page d\'accueil','homepage.php?height=250&width=400',0);
	}
}

function utilisateur_inscription(cur){

	$('#e_p, #e_e').html('');

	$('#l_e, #l_p, #l_pp').css('color', '');

	er = 0;
	l = $('#c_e').val();
	p = $('#c_p').val();
	pp = $('#c_pp').val();
	par =  $('#c_par').attr('checked')

	$.ajax({
      url : "ax/utilisateur-verif-email.php",
      data: 'email=' + l,
      cache: false,
      async: false,
      success: function(r){
    		if(r!='ok'){
    			$('#l_e').css('color', 'red');
    			$('#e_e').html(str_global[4]);
    			er++;
    		}
      }
    });

	if(er==1){}

	else if(!isE(l)){
		$('#l_e').css('color', 'red');
		$('#e_p').html(str_global[0]);
		er++;
	}
	else if(p.length < 4){
		$('#l_p').css('color', 'red');
		$('#e_p').html(str_global[1]);
		er++;
	}
	else if(p.length > 20){
		$('#l_p').css('color', 'red');
		$('#e_p').html(str_global[2]);
		er++;
	}
	else if(pp == '' || p != pp){
		$('#l_pp').css('color', 'red');
		er++;
	}

	if(er == 0){

    $.ajax({
      url : "ax/utilisateur-inscription.php",
      data: 'email=' + l + '&password=' + p + '&partenaires=' + par,
      async: false,
      success: function(r){

      	$('#creer1').hide();
      	$('#creer2').show();
      	
        if($('#c_m').attr('checked')!=undefined && $('#c_m').attr('checked')!=false){
	        doEngine();
	      }
        if($('#c_h').attr('checked')!=undefined && $('#c_h').attr('checked')!=false){
	        setHomepage(cur);
	      }
      }
    });

  }
  else{
  	$("#info").hide();	
	}
	return false;
}

function utilisateur_resend_activate(){
	$.ajax({
		url : "ax/utilisateur-resend-activate.php",
    data: 'email=' + $('#c_e').val(),
    async: false,
    success: function(r){ 	
    	$('#creer1').hide();
    	$('#creer3').show();
		}
	});
}

function utilisateur_login(){
  $.ajax({
    url : "ax/utilisateur-login.php",
    data: 'email=' + $('#i_login').val() + '&pwd=' + $('#i_pwd').val(),
    async: false,
    cache: false,
    success: function(r){
      if(r == 'false'){
        $('#fdbck').html(str_global[3]);
        return false;
      }
      else{
        window.location.href='./';
      }
    }
  });
  return false;
}

function recover_pwd(){

  $.ajax({
    url : "ax/utilisateur-recover_question.php",
    data: 'email=' + $('#recover_identifiant').val() + '&reponse=' +$('#recover_reponse').val(),
    async: false,
    cache: false,
    success: function(r){
      if(r == '#li')
        $('#recover_fdbck').html('Login introuvable');
      else if(r == '#mr'){
        $('#recover_fdbck').html('Mauvaise réponse');
				$('#recover_resultat').html('');
      }
      else{
        $('#recover_resultat').html('Votre mot de passe est : <strong>'+r+'</strong>');
        $('#recover_fdbck').html('');
      }
    }
  });

}

function recover_pwd2(){
	
  $.ajax({
    url : "ax/utilisateur-recover_pwd.php",
    data: 'email=' + $('#recover_email').val(),
    async: false,
    cache: false,
    success: function(r){
      if(r == 'ei')
        $('#email_unknown').show();
      else{
        $('#email_unknown, #recover').hide();
        $('#email_envoye span').text(r);
        $('#email_envoye').show();
      }
    }
  });
	
}

function modifier_password(){
	
	$('#l_a, #l_n, #l_nn').removeClass('r');
	$('#m_error').html('');
	
	if( $('#m_n').val().length<4 ){
		$('#l_n, #l_nn').addClass('r');
		$('#m_error').html(str_global[5]);
		$('#m_n, #m_nn').val('');
		return false;
	}

	if( $('#m_n').val()!=$('#m_nn').val() ){
		$('#l_n, #l_nn').addClass('r');
		$('#m_error').html(str_global[6]);
		return false;
	}

  $.ajax({
    url : "ax/utilisateur-modifier_pwd.php",
    data: 'apwd='+$('#m_a').val()+'&npwd='+$('#m_n').val(),
    async: false,
    cache: false,
    success: function(r){
    	if(r=='incorrect'){
    		$('#m_error').html(str_global[7]);
    		$('#l_a').addClass('r');
    		return false;
    	}
    	else{
    		tb_remove();
    	}
    }
  });
	return false;
}


function chang_lang(parametre,valeur) {
  $.ajax({
    url : "ax/chang-lang.php",
    data: 'param=' + parametre + '&val=' + valeur,
    cache: false,
    async: false
  });
  return true;
}


$().ready(function(){
	$('#f_r').submit(function(){
		reponse='w';
//		$('#hskq_m').html('<div style="margin:50px 0 0 0;text-align:center;color:#999;font-style:italic;">Recherche des résultats sur <strong>'+_ma[_t][_m][1]+'</strong> en cours...<br /><br /><img src="img/chargement.gif" alt="" /></div>');
		$('#hskq_m').html('<div style="margin:50px 300px 0 0;text-align:center;color:#999;font-style:italic;">Recherche des résultats en cours...<br /><br /><img src="img/chargement_'+ui_theme+'.gif" alt="" /></div>');
	});
	//document.getElementById("hskq").style.marginTop=(document.getElementById("t1b").offsetHeight+75)+'px';
});

function contact(){
	ok=1;
	
	if($('#i_qe').val()==''){
		$('#l_qe').addClass('r');
		ok=0;
	}
	else
		$('#l_qe').removeClass('r');

	if($('#t_qm').val()==''){
		$('#l_qm').addClass('r');
		ok=0;
	}

	if(ok==1){
		$.ajax({
	      url : "ax/contact.php",
	      data: 'o=' + $('#s_qo').val() + '&e=' + $('#i_qe').val() + '&m='+$('#t_qm').val(),
	      type: "POST",
	      success: function(r){
	      	$('#d_c').html(r);	
	      }
	  });
	}
	return false;
}

function rem_t(t){

	$('#theme_'+t).hide();
	$.ajax({
		url : "ax/mt_sort.php",
		data: 't='+t
	});
}

function add_t(t){

	$.ajax({
		url : "ax/mt_sort.php",
		data: 'ta='+t
	});
}

$().ready(function(){
	$("input[type='checkbox']").css('border','none');
});

function sw_sf(){
	if(_sf==1){
		_sf=0;
	}
	else{
		_sf=1;
		proposer_favoris(-42,tab_favoris,-42)
	}
	$.ajax({
		url : "ax/sf.php"
	});
}

function euc(chaine){
	return encodeURIComponent(chaine);
}

function feedback(nom,rep){
	$.ajax({
		url : "ax/feedback.php",
    data: 'nom='+nom+'&rep='+rep,
    cache: false,
    success: function(r){
			$('#fb_'+nom).html(r);
  	}
  });
}

$().ready(function(){


	$('#why').mouseover(function(){
		$('#d_why').fadeIn('fast');
	}).mouseout(function(){
		$('#d_why').fadeOut('fast');
	});
	
	/* affichage de "mon compte" */
	$('#compte, #d_compte').hover(function(){
		if(typeof(stoc)!='undefined')
			clearTimeout(stoc);
		$('#d_compte').show();
		$('#d_assotip').hide();
	},function(){
			stoc=setTimeout("d_hide('#d_compte');",200);
		});
		
	/* affichage des asso soutenues */
	$('#assotip, #d_assotip').hover(function(){
		if(typeof(stoa)!='undefined')
			clearTimeout(stoa);
		$('#d_assotip').show();
		$('#d_compte').hide();
	},function(){
			stoa=setTimeout("d_hide('#d_assotip');",200);
		});

	/* affichages des sites possibles */
	$('#int').hover(function(){
		te=0;
		$('#d_int').show();
	},function(){
			te=1;
			setTimeout("d_hide('#d_int');",200);
		});

	$('#d_int').hover(function(){
		te=0;
		},
		function(){
			te=1;
			setTimeout("d_hide('#d_int');",200);
		});

	$("#lang div.z").click(function(){
		$(this).parent().children("div.t").toggle();
		te=0;
	});
	
	$('#lang div.t').hover(function(){},
		function(){
			te=1;
			setTimeout("d_hide('#lang div.t');",200);
		});

});

function d_hide(div){
	$(div).fadeOut(100);
}

function view_apercu(thumbnail){
	$('#site_apercu').show().attr('src','http://img.hooseek.com/'+thumbnail);
}
		
function view_apercu_out(){
	setTimeout("d_hide('#site_apercu');",1000);
}

/* partie langue de recherche */

function dl(l){
	$('#lang .t').hide();
	$('#i_l').val(l)
	$('#lang ul').html('');
	for(i=0;i<_la.length;i++){
		a='<li onclick="dl(\''+_la[i][0]+'\');chang_lang(\'lang\',\''+_la[i][0]+'\');"';
		if(l==_la[i][0]){
			a+=' style="font-weight:bold"';
			$('#lang').css('background-position','-'+_la[i][2]+'px 0');
		}
		a+='><div style="background-position:-'+_la[i][2]+'px 0"></div><span>'+_la[i][1]+'</span></li>'	
		$('#lang ul').append(a);
	}
	
}



/*  */

$().ready(function(){

$("img.help").mouseover(function(){
	$('body').append('<div id="help_tooltip">'+$(this).attr('alt')+'</div>');
	var pos=$(this).position();
	$('#help_tooltip').css('top',pos.top+20);
	$('#help_tooltip').css('left',pos.left-100);
})
.mouseout(function(){
	$('#help_tooltip').fadeOut("fast",function(){
		$('#help_tooltip').remove();
	});
});


});

function moteur_details(moteur){
	$('.detail_moteur').hide();
	$('.moteur_description_done').hide();
	$('#detail_moteur_'+moteur).show();
}

function theme_deplie(ahref){
	$('#moteur_liste ul ul').hide();
	$(ahref).parent().parent().children('ul').show();
}

function moteur_description(moteur){
	$.ajax({
		url : "ax/moteur_presentation.php",
    data: 'id='+moteur+'&pr='+$('#moteur_description_'+moteur+' textarea').val(),
    cache: false,
    type: "POST",
    success: function(r){
			$('#moteur_description_done_'+moteur).html(r).show();
			$('#moteur_description_'+moteur).hide();
  	}
  });
}

function results_decale(){
	if(typeof(theme)!='undefined'){
		if(theme!='web'){
			$('#t1').css('height',(100+$('#cce').height())+'px');
			$('#hskq').css('padding-top',(120+$('#cce').height())+'px');
		}
	}
}
