
/**
 *This function generates a flash file uploader;
 *@param uploader_id - The identifier that will have the uploader once it's created
 *@param target - The id of the element that will be replaced with the uploader
 *@param section - Section type prefix
 *@param lng - Language code
 *@param extensions - Allowed file extension list. i.e "jpg|png|gif" or "*"
 *@param width - Uploader width
 *@param height - Uploader height
 */
function appendFileUploader(uploader_id,target,section,lng,extensions,width,height){

    /**
     * This swf could fire two events.
     * 1)Upload complete, linked to function upload_complete(name,size,type,ft,dir,svar,sidphp).
     *   It fires when file upload process end.
     * 2)File Props, linked to fileProps(name,size,type,cdate,mdate,dir)
     *   It fires when a file is selected
     */


    var flashvars = {
      name: "image uploader",
      to: RELATIVE_PATH+"scripts/upload.php",
      svar: section,
      limit: 100,
      types:extensions
    };
    
    var params = {
      wmode: "opaque",
      allowScriptAccess:"always",
      quality:"high",
      scale:"noscale"
    };

    var attributes = {
      id: uploader_id,
      name: uploader_id
    };
    
    swfobject.embedSWF(RELATIVE_PATH+"scripts/uploader_"+lng+".swf?ul=100", target, width, height, "8.0.0","expressInstall.swf", flashvars, params, attributes);
}

function isCaptchaCodeCorrect(el,callback,callback_params){

    var bool = true;
    $.ajax({
        async: callback?true:false,
        type: "POST",
        url:  RELATIVE_PATH+"ajax/_ajax_captcha.php",
        data:  "opc=getCaptcha&captcha="+el.val(),
        success: function(data){
            if(data==0){
                 bool=false;
            }
            if(callback){
                if(bool == false){
                    callback.apply(this,callback_params);
                    return;
                }
            }

        }
    });
    return bool;
}

function updateCaptcha(layer){
    $.ajax({
        async: true,
        type: "POST",
        url:  RELATIVE_PATH+"ajax/_ajax_captcha.php",
        data:  "opc=updateCaptcha",
        success: function(data){
            var current_label = $(layer).find('.captcha_label').html();
            var parent =  $(layer).parent();
            $(layer).replaceWith(data).find();
            parent.find('.captcha_label').html(current_label);
        }
    });
}

function showBulletinSubscriptionForm(){
    $.ajax({
           async: true,
           type: "POST",
           url: RELATIVE_PATH+"ajax/_ajax_bulletin.php",
           data: "opc=showBulletinSubscriptionForm",
           success: function(data){
              MySimpleLightBox.loadHTML(data);
           }
     });
}

function sendBulletinSubscriptionForm(){
 
    if(checkFormFields('bulletin_form',1,0,'#808080','#DBF2E8')){
        $("#bulletin_form").addAjaxLoader();
        $.ajax({
               async: true,
               type: "POST",
               url: RELATIVE_PATH+"ajax/_ajax_bulletin.php",
               data: "opc=sendBulletinSubscriptionForm&"+$("#bulletin_form").serializeForm(),
               success: function(data){
                    
                    $.ajax({
                       async: true,
                       type: "POST",
                       url: RELATIVE_PATH+"ajax/_ajax_translate.php",
                       data: "opc=translate&word="+(parseInt(data)==1?"newsletter_registration_successfull":"existent_account"),
                       success: function(translate){
                           switch(parseInt(data)){
                                case 1:
                                    $('#newsletter_form').clearForm();
                                    msg = 'newsletter_registration_successfull';
                                    msg_type = 'info';
                                    showAlertMessage(translate,'info',true,true);
                                    break;
                                case 2:
                                    msg = 'existent_account';
                                    msg_type = 'error';
                                    showAlertMessage(translate,'error');
                                    break;
                            }
                       }
                     });
                    $("#bulletin_form").removeAjaxLoader();
               }
         });
    }
}
	
function showRecommendForm(){
    $.ajax({
           async: true,
           type: "POST",
           url: RELATIVE_PATH+"ajax/_ajax_recommend_form.php",
           data: "opc=showRecommendForm",
           success: function(data){
              MySimpleLightBox.loadHTML(data);
           }
     });
}
	
function sendRecommendForm(){
    if(checkFormFields('recommend_form',1,0,'#808080','#DBF2E8')){
        $("#recommend_form").addAjaxLoader();
        $.ajax({
               async: true,
               type: "POST",
               url: RELATIVE_PATH+"ajax/_ajax_recommend_form.php",
               data: "opc=sendRecommend&"+$("#recommend_form").serializeForm()+"&href="+document.location.href,
               success: function(data){
                  MySimpleLightBox.close();
               }
         });
    }

}
	
function sendForm(form_id){
    if(checkFormFields(form_id,1,1)){
        $("#"+form_id).addAjaxLoader();
        var vars = 'opc=sendForm&'+$("#"+form_id).serializeForm()+'&'+$("#"+form_id).serializeFormDescriptions();
        $.ajax({
           async: true,
           type: "POST",
           url: RELATIVE_PATH+"ajax/_ajax_contact_form.php",
           data: vars,
           success: function(data){
            $.ajax({
               async: true,
               type: "POST",
               url: RELATIVE_PATH+"ajax/_ajax_translate.php",
               data: "opc=translate&word="+(parseInt(data)==1?"message_sent":"message_not_sent"),
               success: function(translate){
                    showAlertMessage(translate,(data==1?"info":"error"));
               }
             });
            $("#"+form_id).clearForm();
            $("#"+form_id).removeAjaxLoader();
           }
         });
    }
}
	
function getMicrotime(){
    var micro = "";
    $.ajax({
       async: false,
       type: "POST",
       url: RELATIVE_PATH+"ajax/_ajax.php",
       data: "opc=getMicrotime",
       success: function(data){
         micro = data;
       }
     });
    return micro;
}
	
	
	
function createBookmarkLink(){
     var title = document.title;
     var url   = window.location.href;
     if (window.sidebar) { // Mozilla Firefox Bookmark
         window.sidebar.addPanel(title, url,"");
     }
     else if( window.external ) { // IE Favorite
        window.external.AddFavorite( url, title);
     }
     else if(window.opera && window.print) { // Opera Hotlist
        return true;
     }
     return true;
 }


function logalumno(a){
	var micro = "";
	$.ajax({
		async: false,
		type: "POST",
		url: RELATIVE_PATH+"ajax/_ajax_variables.php",
	
			data: "opc="+a,
		success: function(data){
		 micro = data;
		}
	});
	return micro;



}


function change(){
    $.ajax({
           async: true,
           type: "POST",
           url: RELATIVE_PATH+"ajax/_ajax_login.php",
           data: "opc=change",
           success: function(data){
              MySimpleLightBox.loadHTML(data);
           }
     });
}

function changePass(){
  var pass = $.trim( $('#pass').val() );
    $.ajax({
           async: true,
           type: "POST",
           url: RELATIVE_PATH+"ajax/_ajax_login.php",
           data: "opc=changePass&pass="+pass,
           success: function(data){
              if(data == "pass_incorrect") {
                showAlertMessage('Contraseña incorrecta.','error',true,true);
              } else {
                showAlertMessage('El sistema ha aceptado su nueva contraseña.','info',true,true);
              }
              
           }
     });
}

function showlostPassAlumnos(){
    $.ajax({
           async: true,
           type: "POST",
           url: RELATIVE_PATH+"ajax/_ajax_login.php",
           data: "opc=showLostPassAlumnos",
           success: function(data){
              MySimpleLightBox.loadHTML(data);
           }
     });
}

function recoverLostPassAlumnos(){
  var mail = $.trim( $('#email').val() );
    $.ajax({
           async: true,
           type: "POST",
           url: RELATIVE_PATH+"ajax/_ajax_login.php",
           data: "opc=recoverLostPassAlumnos&mail="+mail,
           success: function(data){
              if(data == 1){
                showAlertMessage('El sistema ha enviado una nueva contraseña a su casilla de correo','info',true,true);
                 
              } else if(data == "mail_incorrect") {
                showAlertMessage('El mail ingresado no es correcto','error',true,true);
                 
              } else {
                showAlertMessage('No se ha podido enviar el mail. Inténtelo más tarde.','error',true,true);
              }
              
           }
     });
}



function showlostPassPadres(){
    $.ajax({
           async: true,
           type: "POST",
           url: RELATIVE_PATH+"ajax/_ajax_login.php",
           data: "opc=showLostPassPadres",
           success: function(data){
              MySimpleLightBox.loadHTML(data);
           }
     });
}

function recoverLostPassPadres(){
  var mail = $.trim( $('#email').val() );
    $.ajax({
           async: true,
           type: "POST",
           url: RELATIVE_PATH+"ajax/_ajax_login.php",
           data: "opc=recoverLostPassPadres&mail="+mail,
           success: function(data){
              if(data == 1){
                showAlertMessage('El sistema ha enviado una nueva contraseña a su casilla de correo','info',true,true);
                 
              } else if(data == "mail_incorrect") {
                showAlertMessage('El mail ingresado no es correcto','error',true,true);
                 
              } else {
                showAlertMessage('No se ha podido enviar el mail. Inténtelo más tarde.','error',true,true);
              }
              
           }
     });
}



function showlostPassPersonal(){
    $.ajax({
           async: true,
           type: "POST",
           url: RELATIVE_PATH+"ajax/_ajax_login.php",
           data: "opc=showLostPassPersonal",
           success: function(data){
              MySimpleLightBox.loadHTML(data);
           }
     });
}

function recoverLostPassPersonal(){
  var mail = $.trim( $('#email').val() );
    $.ajax({
           async: true,
           type: "POST",
           url: RELATIVE_PATH+"ajax/_ajax_login.php",
           data: "opc=recoverLostPassPersonal&mail="+mail,
           success: function(data){
              if(data == 1){
                showAlertMessage('El sistema ha enviado una nueva contraseña a su casilla de correo','info',true,true);
                 
              } else if(data == "mail_incorrect") {
                showAlertMessage('El mail ingresado no es correcto','error',true,true);
                 
              } else {
                showAlertMessage('No se ha podido enviar el mail. Inténtelo más tarde.','error',true,true);
              }
              
           }
     });
}
