// JavaScript Document
function enviaPOST(form, campo, valor) {
	campo.value = valor;
	form.submit();
}
var sSubAnt = null;
function sVisualiza(objeto,accion){
	document.getElementById(objeto).style.display = accion;
	if(sSubAnt!=null && sSubAnt != document.getElementById(objeto)){
		sSubAnt.style.display = 'none';
	}
	sSubAnt = document.getElementById(objeto);
}
function sComprueba(){
	if(sSubAnt!=null){
		sSubAnt.style.display = 'none';
	}
	sSubAnt = null;
}
function sCambia(objeto,valor1,valor2){
	document.getElementById(objeto).style.color = valor1;
	document.getElementById(objeto).style.background= valor2;
}
function sMueve(objeto,accion){
	document.getElementById(objeto).style.backgroundPosition = accion+' top';
}
function sValidaCorreo( objeto , valor ) {
	if( valor ) var s = valor;
	else var s = objeto.value;
	var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if ( filter.test(s) ) {
		return true;
	} else {
		return false;
		s.focus();
	}
}

function sConsulta(url,valor,titulo,idioma,objetoID){
	if(objetoID=="ESTUDIOS" && titulo.length<20){
		alert("DEBES INCLUIR EN EL CAMPO INFORME EL MOTIVO DE TU CONSULTA");
		return false;
	}
	
	if(valor != ""){
		if (valor==0) {
			document.getElementById(objetoID).innerHTML = '<select name="zona" title="'+titulo+'" xml:lang="'+idioma+'"><option value="" xml:lang="'+idioma+'">'+titulo+'</option><option value="marketing@exa.es" xml:lang="'+idioma+'">Madrid</option></select>';
			return;
		} 	
		
		var pageRequest = false;
		try {
			/*Para navegadores distintos a internet explorer*/
			pageRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				/*Para explorer*/
				pageRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				pageRequest = false;
			}
		}
		if (!pageRequest && typeof XMLHttpRequest!='undefined') pageRequest = new XMLHttpRequest();
		
		pageRequest.onreadystatechange = function(){
			sFiltroCon(pageRequest,objetoID);
		}
	
		var cid = "sectorID="+valor+"&title="+titulo+"&idioma="+idioma;
		pageRequest.open('GET',url+"?"+cid,true);
		pageRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		pageRequest.setRequestHeader("Content-Type","text/html; charset=UTF-8");
		
		pageRequest.send(cid);
	} else {
		document.getElementById(objetoID).innerHTML = '<select name="zona" title="'+titulo+'" xml:lang="'+idioma+'"><option value="" xml:lang="'+idioma+'">'+titulo+'</option></select>';
	}
}

function sGuarda(url,userID,inmuID,objetoID,valor,tipo,title,titleNO){
		
	document.getElementById(objetoID).innerHTML = '<img src="images/pixel.png" width="10" height="10" />';
	
	var pageRequest = false;
	try {
		/*Para navegadores distintos a internet explorer*/
		pageRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			/*Para explorer*/
			pageRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			pageRequest = false;
		}
	}
	if (!pageRequest && typeof XMLHttpRequest!='undefined') pageRequest = new XMLHttpRequest();
	
	pageRequest.onreadystatechange = function(){
		if(pageRequest.readyState == 4) {
			if(pageRequest.status == 200){
				if(pageRequest.responseText == "true"){
					if(valor==1){
						var salida = '<img src="images/guardarNO.gif" title="'+title+'" alt="'+title+'" width="10" height="10" onclick="javascript:sGuarda(\'funciones/guardar.inc.php\', \''+userID+'\', \''+inmuID+'\', \''+objetoID+'\', \'0\', \''+tipo+'\', \''+titleNO+'\', \''+title+'\');" style="cursor:pointer;" />';
					} else { 
						var salida = '<img src="images/guardar.gif" title="'+title+'" alt="'+title+'" width="10" height="10" onclick="javascript:sGuarda(\'funciones/guardar.inc.php\', \''+userID+'\', \''+inmuID+'\', \''+objetoID+'\', \'1\', \''+tipo+'\', \''+titleNO+'\', \''+title+'\');" style="cursor:pointer;" />';
					}					
					document.getElementById(objetoID).innerHTML = salida;
					return true;
				}
			}
		}
		if(valor==1){
			var salida = '<img src="images/guardar.gif" title="'+title+'" alt="'+title+'" width="10" height="10" onclick="javascript:sGuarda(\'funciones/guardar.inc.php\', \''+userID+'\', \''+inmuID+'\', \''+objetoID+'\', \'1\', \''+tipo+'\', \''+titleNO+'\', \''+title+'\');" style="cursor:pointer;" />';
		} else { 
			var salida = '<img src="images/guardarNO.gif" title="'+title+'" alt="'+title+'" width="10" height="10" onclick="javascript:sGuarda(\'funciones/guardar.inc.php\', \''+userID+'\', \''+inmuID+'\', \''+objetoID+'\', \'0\', \''+tipo+'\', \''+titleNO+'\', \''+title+'\');" style="cursor:pointer;" />';
		}					
		document.getElementById(objetoID).innerHTML = salida;
	}

	var cid = "id="+inmuID+"&cid="+userID+"&valor="+valor+"&tipo="+tipo;
	pageRequest.open('GET',url+"?"+cid,true);
	pageRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	pageRequest.setRequestHeader('Content-Type','text/html; charset=UTF-8');
	pageRequest.send(cid);

}

function sRecupera(url,valor,objetoID,titleSI,titleNO,boleano){
	if(boleano) {
		if( sValidaCorreo( '', valor ) == false ) { 
			alert("Inserta un correo valido"); 
			document.getElementById(objetoID).style.backgroundColor = "#CC0000"; 
			document.getElementById(objetoID).style.color = "#FFF"; 
			if(titleSI && titleNO) document.getElementById(objetoID).title = titleNO;
			sCorreo = false;
			return false;  
		}
	}
	var pageRequest = false;
	try {
		/*Para navegadores distintos a internet explorer*/
		pageRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			/*Para explorer*/
			pageRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			pageRequest = false;
		}
	}
	if (!pageRequest && typeof XMLHttpRequest!='undefined') pageRequest = new XMLHttpRequest();
	
	pageRequest.onreadystatechange = function(){
		if(titleSI && titleNO) sFiltro(pageRequest,objetoID,titleSI,titleNO);
		else sFiltro(pageRequest,objetoID)
	}

	var cid = "correo="+valor;
	pageRequest.open('GET',url+"?"+cid,true);
	pageRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	pageRequest.setRequestHeader('Content-Type','text/html; charset=UTF-8');
	pageRequest.send(cid);
}
function sFiltrea(valor,objetoID,titleSI,titleNO,boleano){
	if(boleano) {
		if( sValidaCorreo( '', valor ) == false ) { 
			alert("Inserta un correo valido"); 
			document.getElementById(objetoID).style.backgroundColor = "#CC0000"; 
			document.getElementById(objetoID).style.color = "#FFF"; 
			if(titleSI && titleNO) document.getElementById(objetoID).title = titleNO;
			sCorreo = false;
			return false;  
		}
		if(titleSI && titleNO) document.getElementById(objetoID).title = titleSI;
		document.getElementById(objetoID).style.backgroundColor = "#006633";
		document.getElementById(objetoID).style.color = "FFF";
	}
}
function sFiltro(pageRequest,objetoID,titleSI,titleNO){
	var objeto = document.getElementById(objetoID);
	if(pageRequest.readyState == 4) {
		if(pageRequest.status == 200){
			if(pageRequest.responseText=="true"){
				if(titleSI && titleNO) objeto.title = titleSI;
				objeto.style.backgroundColor = "#006633";
				objeto.style.color = "FFF";
			} else {
				if(titleSI && titleNO) objeto.title = titleNO;
				objeto.style.backgroundColor = "#CC0000";
				objeto.style.color = "#FFF";
			}
			sCorreo = pageRequest.responseText;
		} else {
			if(titleSI && titleNO) objeto.title = titleNO;
			objeto.style.backgroundColor = "#CC0000";
			objeto.style.color = "#FFF";
			sCorreo = false;
		}
	}
}
function sFiltroCon(objetoRQ,objetoID){
	if(objetoRQ.readyState == 4) {
		if(objetoRQ.status == 200){
			document.getElementById(objetoID).innerHTML = objetoRQ.responseText;
		} else {
			alert("NOP");
		}
	}
}
function sGaleria( sObjeto1, sObjeto2 , sDescripcion , sArchivo , sExtension , sTamano, sDescargas , sTipo , sID , sIdioma ){
	
	if( sExtension == "jpg" ) var sHTMLimg = '<img src="images/material/photo/' + sArchivo + '.' + sExtension + '?' + Math.random() + '" width="250" height="176" alt="' + sDescripcion + '" title="' + sDescripcion + '" class="galeria" />';
	else  var sHTMLimg = '<img src="images/material/photo/photo_' + sExtension + '.jpg?' + Math.random() + '" width="250" height="176" alt="' + sDescripcion + '" title="' + sDescripcion + '"  class="galeria" />';
	
	var sHTMLcon = '<h2 class="titulo" style="margin-top:0px;margin-right:0px;text-transform:uppercase;">' + sDescripcion + '</h2>';
		sHTMLcon += '<p class="texto">Tipo de archivo: <b>' + sExtension + '</b>';
		sHTMLcon += '<br />Tamaño de la descarga: <b>' + sTamano + '</b>';
		sHTMLcon += '<br />Número de descargas: <b>' + sDescargas + '</b></p>';
		sHTMLcon += '<p class="texto"><a href="archivos/descarga.php?tipo=' + sTipo + '&cid=' +sID + '&idioma=' + sIdioma + '"><img src="images/guardar.gif" alt="Descargar: ' + sDescripcion + '" title="Descargar: ' + sDescripcion + '" /></a> <a href="archivos/descarga.php?tipo=' + sTipo + '&cid=' +sID + '&idioma=' + sIdioma + '">DESCARGAR</a></p>';
	
	document.getElementById(sObjeto1).innerHTML = sHTMLimg;
	document.getElementById(sObjeto2).innerHTML = sHTMLcon;
	
}
function imprimir(nombre, titulo){
	var ficha = document.getElementById(nombre);
	var ventimp = window.open(' ', 'popimpr', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=544,height=400,left=0,top=0' );
	ventimp.document.write( '<html>' );
	ventimp.document.write( '<head>' );
	ventimp.document.write( '<title>' + titulo + '</title>' );
	ventimp.document.write( '<link rel="stylesheet" type="text/css" href="estilos.css" media="all">' );
	ventimp.document.write( '</head>' );
	ventimp.document.write( '<body style="background-color:#FFF;background-imagen:none;">' );
	ventimp.document.write( ficha.innerHTML );
	ventimp.document.write( '</body>' );
	ventimp.document.write( '</hmtl>' );
	ventimp.document.close();
	ventimp.print( );
	ventimp.close();
}