﻿function busqueda(){
    
    $frm = document.getElementById("formBuscador");
    $err = "";

    $qry = $frm.qry.value;

    if(!$qry || $qry == "Buscador" ) {
        $err += "Completar palabra a buscar. \n ";
    }

    if($qry.length < 3 ) {
        $err += "Tiene que tener como mínimo 3 caracteres. \n";
    }

    if($err ) {
        alert($err);
    }else{
        window.location.href="/notas/busqueda/"+$qry+"/";
    }
    return false;
}

function getData(suggestBoxId, gateway, inputString, inputValue, inputShow ){

    suggestBoxId = '#' + suggestBoxId;

    if(inputString.length == 0){

	    $(suggestBoxId).fadeOut();

    }else{

	    $.post(
			    gateway,
			    {
				    queryString: ""+inputString+"",
				    valueElem: inputValue,
				    showElem: inputShow
			    }, 

			    function(data){
				    $(suggestBoxId).fadeIn();
				    $(suggestBoxId).html(data);
			    });
    }
}

/*function participarSorteo(id){
    
    if($('#terminos'+id).is(':checked')){
        $('#error'+id).css("display", "none");
        
        $.ajax({
	        type: 'POST',
	        data: { 
			        'idSorteo': id
		          },
	        url: '/DatosUtiles/ParticiparSorteo/',
	        success: function(data){	

    		    $('#cajaParticipa'+id).html(data);
    		}	
	     });  
	            
    }else{
        $('#error'+id).css("display", "");
    }
}*/

function saveComment(){
    var fields =    $("#ComentarioForm").serializeArray();
    $.post(
        "/Nota/EnviarComentario",
        fields,  
        function(data){
	        $("#error_comment").fadeIn();
	        $("#error_comment").html(data);
        }
    );
}

function votar($idContenido){
    $.post(
        "/Nota/Votar",
        {
            id: $idContenido 
        },  
        function(data){
	        $("#votos_totales1").html(data);
	        $("#votos_totales2").html(data);
        }
    );
}

function fillLetter( letter ){
    $("#letter").val(letter);
    $("#page").val(1);
    $('#advSearch').val("0");
    $("#FrmDicc").submit();
}

function fillLetter2( letter ){
    $("#letter").val(letter);
    $("#page").val(1);
    $('#advSearch').val("1");
    $("#FrmDicc").submit();
}

function changePage(page){
    $("#page").val(page);
    $("#FrmDicc").submit();
}


function sugerir(){
    var fields =    $("#FrmSugerir").serializeArray();
    $.post(
        "/DatosUtiles/Sugerir",
        fields,  
        function(data){
	        $("#error_sugerir").fadeIn();
	        $("#error_sugerir").html(data);
        }
    );
}

function advSearch(){
    if( !$("#busq_letra").val() || !$("#busq_origen").val() ){
        $("#error_search").html('Seleccione filtros');
    }else{
        $("#letter").val(null);
        $("#page").val(1);
        $('#advSearch').val("1");
        $("#error_search").html('');
        $("#FrmDicc").submit(); 
    }
}

function BuscaTerminos(){

    if($("#searchStr").val() == "" || $("#searchStr").val() == "Buscar" ){
        alert("Completar palabra a buscar");
     
    }else{
        $('#advSearch').val("1");
        $("#letter").val(null);
        $("#page").val(1);
        $("#FrmDicc").submit();
    } 
}

function validate_num(e){ 
    tecla = (document.all) ? e.keyCode : e.which;

    if (tecla==8) return true; //Tecla de retroceso (para poder borrar)
    
    if (tecla==0) return true; //Tecla de tab
    
    patron = /([0-9-.]+)/;

    te = String.fromCharCode(tecla);

    return patron.test(te); 

}

function votarBebe($idContenido, $idUsr){
  
    $.post(
        "/Bebe/Votar",
        {
            idCont: $idContenido, 
            idUsr: $idUsr
        },  
        function(data){

          var temp = new Array();
          temp = data.split('_');

	       if(temp[0] == "1")
	       {
	            $("#votos_totales"+$idContenido).html(temp[1]);
	       }else{
	             alert("No podés votar más de una vez al mismo bebé.");
	             $("#votos_totales"+$idContenido).html(temp[1]);
	       }
           
        }
    );
}

$(document).ready(function(){
    
  // Increase Font Size
  $(".increaseFont").click(function(){
    var currentFontSize = $('.resize *').css('font-size').replace('px','');
    var currentFontSizeNum = parseFloat(currentFontSize, 14);
    var newFontSize = currentFontSizeNum+1;

    if(newFontSize <= 17){
        $('.resize').css('font-size', newFontSize);
        $('.resize *').css('font-size', newFontSize);
    }
    
    return false;
  });
  
  // Decrease Font Size
  $(".decreaseFont").click(function(){
    var currentFontSize = $('.resize *').css('font-size').replace('px','');
    var currentFontSizeNum = parseFloat(currentFontSize, 14);
    var newFontSize = currentFontSizeNum-1;
    
    if(newFontSize >= 9){    
    $('.resize *').css('font-size', newFontSize);
    $('.resize ').css('font-size', newFontSize);
    }
    
    return false;
  });
});

function loginEnForo(username, userKey, forumUrl){
    
    jQuery.getJSON(forumUrl+"/remoteLogin.aspx?userName="+username+"&userKey="+userKey+"&callback=?",
      function(data){
        alert(data.value); // data es el json cargado por jsonp
      })
 } 


function EnviarSorteo()
{
    var err = ""; 

    if(!$("#nombre").val()){
        err += "Falta completar nombre. \n";
    }
    if(!$("#telefono").val()){
        err += "Falta completar teléfono. \n";
    }
    if(!$("#provincia").val()){
        err += "Falta completar provincia. \n";
    }
    if(!$("#localidad").val()){
        err += "Falta completar localidad. \n";
    }
    if(!$("#email").val()){
        err += "Falta completar correo electrónico. \n";
    }
    if(!$("#documento").val()){
        err += "Falta completar documento. \n";
    }
    
    if($("#condiciones:checked").val() == null){
        err += "Falta aceptar términos y condiciones. \n";
    }
      
    if(err){
       alert(err)  ;
    }else{
       $("#frmSorteo").submit();
}  
}
   
