/*******************************************************
funcitio ajax to load forms.
 * @param string $home the direction where will be printed the results.
 * @param string $action string of params of the url.
 * @didiv id of the div where will be printed the results.
*******************************************************/
function load_edit_form(home, action, divid){
//alert('entra en el load');
	$.ajax({
		type: "GET",
		url: home,
		data: action,
		success: function(msg){
			//document.getElementById(divid).innerHTML= '<img id="idloading" src="http://localhost/mdpixx_project//themes/standard/lightbox/lightbox-ico-loading.gif"/>';
			//alert(msg);
			document.getElementById(divid).innerHTML = msg;


		},
		error: function(xho){
			document.getElementById(divid).innerHTML = "Error:"+xho.responseText;
		}
	});
}

function load_edit_form_post(home, action, divid){
//alert('entra en el load');
	$.ajax({
		type: "POST",
		url: home,
		data: action,
		success: function(msg){
			//document.getElementById(divid).innerHTML= '<img id="idloading" src="http://localhost/mdpixx_project//themes/standard/lightbox/lightbox-ico-loading.gif"/>';
			//alert(msg);
			if(divid){
				document.getElementById(divid).innerHTML = msg;
				}


		},
		error: function(xho){
			if(divid){
				document.getElementById(divid).innerHTML = "Error:"+xho.responseText;
				}
		}
	});
}


function send_mail_form2 (home, action){
$.ajax({
        url: home,
        async:true,
        beforeSend: function(objeto){
            alert("El mail está siendo enviado");
        },
        complete: function(objeto, exito){
            //alert("Me acabo de completar")
            if(exito=="success"){
                alert("El mail se envio satisfactoriamente");
            }
        },
        contentType: "application/x-www-form-urlencoded",
        dataType: "html",
        error: function(objeto, quepaso, otroobj){
            alert("Fallom al enviar el mail");
           // alert("Pasó lo siguiente: "+quepaso);
        },
        global: true,
        ifModified: false,
        processData:true,
        success: function(action){
            alert(action);
        },
        timeout: 1000,
        type: "POST"
});
}

function load_edit_select(home, action, divid){

if(navigator.appVersion.indexOf("MSIE")<0){
load_edit_form(home, action, divid);

}else{

//alert('entra en el load');
	$.ajax({
		type: "GET",
		url: home,
		data: action,
		success: function(msg){
			//document.getElementById(divid).innerHTML= '<img id="idloading" src="http://localhost/mdpixx_project//themes/standard/lightbox/lightbox-ico-loading.gif"/>';
			//alert(msg);

			var select = document.getElementById(divid);

			//will be deleted from the select all his options.
		/*	for (i=0; i< select.length;i++){
        			document.getElementById(divid).options[i] = null;

   			 }*/
   			 document.getElementById(divid).innerHTML=''

   			 	var arra_opcs;
   			 	var arra_opts;
   			 	var arra_values;
   				var arra_texts;
   				var selectedval;

   			 if(msg.indexOf('####@@@@')>-1){
   			  	 arra_opcs=msg.split('####@@@@');
   			 	 arra_opts= arra_opcs[0].split('@@@###');
   			 	 arra_values= arra_opts[0].split('</option>');
   				 arra_texts= arra_opts[1].split('</option>');
   				 selectedval = arra_opcs[1];

   			 }else{
   			 	var arra_opts= msg.split('@@@###');
   			 	var arra_values= arra_opts[0].split('</option>');
   				var arra_texts= arra_opts[1].split('</option>');
   				 selectedval = -1;
   			 }

   			for(j=0; j< arra_values.length-1;j++){
				var opcion = document.createElement("OPTION");
				if(selectedval==arra_values[j]){
					opcion.setAttribute("selected",'selected');
				}
	    		opcion.setAttribute("value",arra_values[j]);
	    		opcion.innerHTML = arra_texts[j];
	    		select.appendChild(opcion);

    		}


			//document.getElementById(divid).innerHTML = msg;
		//	document.getElementById(divid).innerHTML = msg;


		},
		error: function(xho){
			document.getElementById(divid).innerHTML = "Error:"+xho.responseText;
		}
	});
	}
}


function report_success(home, action, divid, wasreported){
$.ajax({
		type: "POST",
		url: home,
		data: action,
		beforeSend: function(objeto){
			alert(wasreported);
        },
		success: function(msg){
		document.getElementById(divid).innerHTML = msg;


		},
		error: function(xho){
			document.getElementById(divid).innerHTML = "Error:"+xho.responseText;
		}
	});

}





