/////////////////////////
// FUNCIONES AJAX
/////////////////////////

// OBJETO AJAX
function GetXmlHttpObject(){

	var xmlHttp=null;
	try
		{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		}
	catch (e)
		{
		//Internet Explorer
		try
			{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
		catch (e)
			{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}

	return xmlHttp;
}

// CARGAR CONTENIDO DINAMICO
// MANDAMOS EL IDNUMBER DEL DIV, LA PAGINA EXTERNA Y LAS VARIABLES
// EN FORMATO STRING: "dia=09&mes=02"
function DinamicContent(idnumber,url,data,loadingani) {
	var divContenido;
	var ajax;

	divContenido = document.getElementById('dinamic_content_'+idnumber); // Div donde se mostrará el contenido

	ajax=GetXmlHttpObject(); // Ajax Request
	ajax.open("GET", url+data); // Mandamos las variables url y data en el GET

	// Div de Loading
	divContenido.innerHTML =  
	'<div class=\"divloading\" style=\"position: absolute; margin: auto; margin-left: 48px; margin-top: 75px;\">' +
	'<img src=\"'+loadingani+'\" alt="Loading" title="Loading" />' + 
	'</div>';

	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divContenido.innerHTML = ajax.responseText; // Mostramos el resultado
		}
	}

	ajax.send(null)
}

//PARA EL UPLOADER
function startUpload(){
	document.getElementById('f1_upload_form').innerHTML = '<input name="myfile" type="file" style="position: absolute; margin: auto; margin-top: 42px; margin-left: -60px;" onchange="document.uploadform.submit(); startUpload();" />';
	document.getElementById('f1_upload_process').style.visibility = 'visible';
	return true;
}

function stopUpload(success, targetpath){
	document.getElementById('f1_upload_process').style.visibility = 'hidden';
	var result = '';
	var imgcabsrc = '';
	// ESTO ES PARA QUE SE REFRESQUE BIEN EL CACHE
	var rnd = Math.floor(Math.random()*1000)
	
	if (success == 1){
	imgcabsrc='data/images/'+targetpath+'?d='+rnd;
	result = '<span class="uploadmsg"><i>Imagen OK.</i><\/span>';	
	}
	else if (success == 2){
	result = '<span class="uploademsg"><i>Error!</i><\/span>';
	}
	else {
	result = '<span class="uploademsg"><i>Error!</i><\/span>';
	}
		
	document.getElementById('f1_upload_form').innerHTML = '<input name="myfile" type="file" style="position: absolute; margin: auto; margin-top: 42px; margin-left: -60px;" onchange="document.uploadform.submit(); startUpload();" />'+ result;
	document.getElementById('f1_upload_process').style.visibility = 'hidden';
	document.getElementById('f1_upload_form').style.visibility = 'visible';
	if (success==1) document.getElementById('f1_DivCab').innerHTML = '<img border="0" class="dinimage" src="'+imgcabsrc+'" />';
	else document.getElementsByName('myfile').value='';
	
	return true;
}
// FIN UPLOADER