function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function cambiar_bt(objeto){
	divMensaje=document.getElementById(objeto).className = "home_elite_over";
}

function cambiar_bt_news(objeto){
	divMensaje=document.getElementById(objeto).className = "home_news_over";
}

function cambiar_off(objeto){
    divMensaje=document.getElementById(objeto).className = "home_elite";
}


function cargar_news(objeto){
    window.location.href = objeto
}

var server = "/";

function nuevoAjax()
{ 
	var xmlhttp=false; 
	try 
	{ 
		// No IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } 
	return xmlhttp; 
}

function eliminaEspacios(cadena)
{
	// Funcion para eliminar espacios delante y detras de cada cadena
	while(cadena.charAt(cadena.length-1)==" ") cadena=cadena.substr(0, cadena.length-1);
	while(cadena.charAt(0)==" ") cadena=cadena.substr(1, cadena.length-1);
	return cadena;
}

function muestraMensaje(mensaje,nombre)
{
	divMensaje=document.getElementById(nombre);
	divMensaje.innerHTML=mensaje;
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// FUNCIONES DE LOGIN DE USUARIOS

function log_elite(){
	var user=eliminaEspacios(document.login.usuario.value);
	var pass=eliminaEspacios(document.login.password.value);
	var recordar = "no";
	
	if (user!="" && pass!=""){
		var ajax=nuevoAjax();
		ajax.open("POST", "php_ajax/login_site.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		//ajax.send("user="+user+"&password="+pass+"&guardar_clave="+recordar);
		ajax.send("user="+user+"&password="+pass+"&guardar_clave="+recordar);
		ajax.onreadystatechange=function(){
		   if (ajax.readyState==4){
			 var respuesta=ajax.responseText;
			 //alert(respuesta);
			 if(respuesta=="OK")	{
				location.reload(true);
			 }else{  
			 	muestraMensaje("hola","resp_login")
			 }
		  }
		}

	}else{
		muestraMensaje("Faltan datos","resp_login")
	}
}

function getRadioButtonSelectedValue(ctrl)
{
    for(i=0;i<ctrl.length;i++)
        if(ctrl[i].checked) return ctrl[i].value;
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// FUNCIONES DE REGISTO DE USUARIOS

function registro_elite(){
	var user=eliminaEspacios(document.registro.email.value);
	var pass=eliminaEspacios(document.registro.password.value);
	var nombre=eliminaEspacios(document.registro.nombre.value);
	var apellido=eliminaEspacios(document.registro.apellido.value);
	var password2=eliminaEspacios(document.registro.password2.value);
	var autorizar=document.registro.checkbox1.checked;
	
	if (nombre!="" && apellido!="" && user!="" && pass!="" && password2!=""){
		if(autorizar){
			if(pass == password2){
				var ajax=nuevoAjax();
				ajax.open("POST", "php_ajax/registro_site.php", true);
				ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				//ajax.send("user="+user+"&password="+pass+"&guardar_clave="+recordar);
				ajax.send("user="+user+"&password="+pass+"&nombre="+nombre+"&apellido="+apellido);
				ajax.onreadystatechange=function(){
				   if (ajax.readyState==4){
					 var respuesta=ajax.responseText;
					 //alert(respuesta);
					 if(respuesta=="OK")	{
						muestraMensaje("Congratulazioni! Sei appena entrato nel mondo di ELITE.<br><br><input type='button' onclick='cerrar_registro()' name='reg' id='reg' value='Cerrar' />","fin_registro")
					 }else{  
						muestraMensaje("L'indirizzo email &eacute; gi&aacute; stato registrato.","mensaje_contacto")
					 }
				  }
				}
			}else{
				muestraMensaje("Le password non combaciano","mensaje_contacto")
			}
		}else{
			muestraMensaje("Gentile Visitatore, non possiamo terminare la tua iscrizione, perch&eacute; non abbiamo la tua autorizzazione al trattamento dei dati personali.","mensaje_contacto")
		}
	}else{
		muestraMensaje("Tutti i campi sono obbligatori","mensaje_contacto")
	}
	
}

function cerrar_registro(){
	location.reload(true);
}

/*Funcion que me devuelve el numero de caracteres - blancos de una cadena*/
function trim(cadena){
	var nuevacadena="";
	nuevacadena=cadena.replace(/\ /g,"");
	return nuevacadena.length;
}

function validarRegistro(){
	if(trim(document.getElementById('email').value)==0){alert("EMAIL"); return false;}
	if(trim(document.getElementById('confirm_email').value)==0){alert("CONFERMA LA TUA EMAIL"); return false;}
	if(trim(document.getElementById('nombre').value)==0){alert("NOME"); return false;}
	if(trim(document.getElementById('apellido').value)==0){alert("COGNOME"); return false;}
	if(trim(document.getElementById('direccion').value)==0){alert("INDIRIZZO"); return false;}
	if(trim(document.getElementById('zip_code').value)==0){alert("CAP"); return false;}
	if(trim(document.getElementById('comunidad').value)==0){alert("COMUNE"); return false;}
	if(trim(document.getElementById('pais').value)==0){alert("NAZIONE"); return false;}
	if(trim(document.getElementById('ciudad').value)==0){alert("PROVINCIA"); return false;}
	if(trim(document.getElementById('telefono').value)==0){alert("TELEFONO FISSO"); return false;}
	/*if(trim(document.getElementById('ruller').value)==0){alert("TIPO DI RULLO"); return false;}*/
	/*if(trim(document.getElementById('numero_serie').value)==0){alert("NUMERO DI SERIE DEL RULLO"); return false;}*/
	if(trim(document.getElementById('pass').value)==0){alert("PASSWORD"); return false;}
	if(trim(document.getElementById('confirm_pass').value)==0){alert("CONFERMA LA PASSWORD"); return false;}
	if(document.getElementById('email').value!=document.getElementById('confirm_email').value){alert("EMAIL <>"); return false;}
	if(document.getElementById('pass').value!=document.getElementById('confirm_pass').value){alert("PASSWORD <>"); return false;}
	
	if(confirm("PLEASE CONFIRM")){
		document.frmRegistro.submit()
	}
}


function recomendar(){

	var msg ="";
	
	
	cajaemail2 = document.getElementById('email2');
	if(trim(cajaemail2.value)==0 || validaCorreo(document.getElementById('email2').value)!= true){
		msg = "Falta Ingresar email o el email no es correcto\n";
	}
	cajanombre2 = document.getElementById('nombre2');
	if(trim(cajanombre2.value)==0){
		msg = "Es necesario que ingrese el nombre del destinatario\n";
	}
	cajaemail = document.getElementById('email');
	if(trim(cajaemail.value)==0 || validaCorreo(document.getElementById('email').value)!= true){
		msg = "Falta Ingresar email o el email no es correcto\n";
	}
	cajanombre = document.getElementById('nombre');
	if(trim(cajanombre.value)==0){
		msg = "Es necesario que ingrese su nombre\n";
	}
	cajalink = document.getElementById('link');
	if(trim(cajalink.value)==0){
		msg = "Es necesario que ingrese el Link a recomendar\n";
	}
	
	if(msg!=""){
		alert(msg);
	}else{
		document.recomendar_art.submit();
	}
}

function atencion_ciu(){
		
	var msg ="";
	
	mensaje = document.getElementById('mensaje');
	if(trim(mensaje.value)==0){
		msg = "Es necesario que ingrese su mensaje\n";
	}
	telefono = document.getElementById('telefono');
	if(trim(telefono.value)==0){
		msg = "Es necesario que ingrese un numero telefonico\n";
	}
	direccion = document.getElementById('direccion_envio');
	if(trim(direccion.value)==0){
		msg = "Es necesario que ingrese una dirección\n";
	}
	cajaemail = document.getElementById('email');
	if(trim(cajaemail.value)==0 || validaCorreo(document.getElementById('email').value)!= true){
		msg = "Falta Ingresar email o el email no es correcto\n";
	}
	nit = document.getElementById('nit');
	if(trim(nit.value)==0){
		msg = "Es necesario que ingrese su cedula o nit\n";
	}
	
	nombre = document.getElementById('nombre');
	if(trim(nombre.value)==0){
		msg = "Es necesario que ingrese su nombre o razon social\n";
	}

	if(msg!=""){
		alert(msg);
	}else{
		document.frm_atencion.submit();
	}
	
}

function contactenos(){
		
	var msg ="";
	
	mensaje = document.getElementById('mensaje');
	if(trim(mensaje.value)==0){
		msg = "Es necesario que ingrese su mensaje\n";
	}		
	cajaemail = document.getElementById('email');
	if(trim(cajaemail.value)==0 || validaCorreo(document.getElementById('email').value)!= true){
		msg = "Falta Ingresar email o el email no es correcto\n";
	}
	barrio = document.getElementById('barrio');
	if(trim(barrio.value)==0){
		msg = "Es necesario que ingrese barrio y localidad";
	}
	telefono = document.getElementById('telefono');
	if(trim(telefono.value)==0){
		msg = "Es necesario que ingrese un numero telefonico\n";
	}			
	apellido = document.getElementById('apellido');
	if(trim(apellido.value)==0){
		msg = "Es necesario que ingrese un apellido\n";
	}
	nombre = document.getElementById('nombre');
	if(trim(nombre.value)==0){
		msg = "Es necesario que ingrese su nombre\n";
	}

	if(msg!=""){
		alert(msg);
	}else{
		document.frm_contactenos.submit();
	}
	
}


function validaCorreo(valor)
{
	var reg=/(^[a-zA-Z0-9._-]{1,30})@([a-zA-Z0-9.-]{1,30}$)/;
	if(reg.test(valor)) return true;
	else return false;
}
/****************************************
FUNCIONES PARA LIGTH BOX
****************************************/
var opacidad=0;
var hilo;
var ban = 0;
var banCalificacion = 0;
var cantidadCarrito =0;


// Funcio que me hace un redirect de direccion
function hacerRedirect(ruta){
	//alert(ruta);
	document.location = ruta;
}

function mostrarSaleAlert(){
	ban=3;
	divconsale = document.getElementById("divMascara");
	divconsale.style.display = "block";
	mostrarDivHasta('divMascara' , 65);
}

function mostrarRodillo(){
	ban=4;
	divconsale = document.getElementById("divMascara");
	divconsale.style.display = "block";
	mostrarDivHasta('divMascara' , 65);
}

function ocultarDivsMascara(){
	document.getElementById("divMascara").style.display = "none";
	document.getElementById("divSaleAlert").style.display="none";
	document.getElementById("divRodillo").style.display="none";
}

function MostrarDerechos(id){
	if(id == "Derecho de Petición"){
	  document.getElementById("peticion").style.display = "block";
	}else{
	  document.getElementById("peticion").style.display = "none";	
	  document.getElementById("malla_vial").style.display = "none";	
	}
	
}
function MostrarMallaVial(id){
	if(id == "Mantenimiento y Rehabilitación de Vías Locales"){
	  document.getElementById("malla_vial").style.display = "block";
	}else{
	  document.getElementById("malla_vial").style.display = "none";	
	}
}

function ocultarSaleAlert(){
	document.getElementById("divMascara").style.display = "none";
	document.getElementById("divSaleAlert").style.display="none";
}

function mostrarDiv(id) {
	clearInterval(hilo);
	opacidad=1;
	document.getElementById(id).style.opacity=".0";
	document.getElementById(id).style.filter="alpha(opacity=0)";
	hilo=setInterval("hacerOpaco('"+id+"')",7);
}

function hacerOpaco( id ) {
	opacidad++;
	opacidadFireFox=opacidad/100;
	document.getElementById(id).style.opacity=opacidadFireFox;
	document.getElementById(id).style.filter="alpha(opacity="+opacidad+")";
	if (opacidad>99) {
		clearInterval(hilo);
		document.getElementById(id).style.opacity="1";
		document.getElementById(id).style.filter="alpha(opacity=100)";
		opacidad=100;
		clearInterval(hilo);
		return;
	}
}

function hacerOpacoHasta( id , hasta) {
	opacidad+=5;
	//opacidad = 100;
	opacidadFireFox=opacidad/100;
	document.getElementById(id).style.opacity=opacidadFireFox;
	document.getElementById(id).style.filter="alpha(opacity="+opacidad+")";
	if (opacidad>hasta) {
		//document.getElementById("bodyPrincipal").style.overflowY = "hidden";
		if(ban==0){
			document.getElementById("divLogin").style.display="block";
		}else if(ban==3){
			document.getElementById("divSaleAlert").style.display="block";
		}else if(ban==4){
			document.getElementById("divRodillo").style.display="block";
		}else{
			document.getElementById("divSizeChart").style.display="block";
		}
		clearInterval(hilo);
		ban=0;
		return;
	}
}

function mostrarDivHasta(id, hasta) {
	clearInterval(hilo);
	opacidad=1;
	document.getElementById(id).style.opacity=".0";
	document.getElementById(id).style.filter="alpha(opacity=0)";
	hilo=setInterval("hacerOpacoHasta('"+id+"', "+hasta+")",7);
}
/****************************************
FIN FUNCIONES PARA LIGTH BOX
****************************************/

//Funcion para hacer redireccionamiento
function hacerRedirect(newDir){
	window.location = newDir;
}

var reestablecerlogo="";
//Funcion para cambiar el logo del producto
function cambiarLogoProduct(newimg){
	objImg = document.getElementById('logo');
	reestablecerlogo = objImg.src;
	objImg.src = newimg;
}

function restablecerLogoProduct(){
	objImg = document.getElementById('logo');
	objImg.src =reestablecerlogo;
}

//Funcion para hacer redireccionamiento
function hacerSubmit(form){
	objForm = document.getElementById(form);
	objForm.submit();
}

function mostrarAlert(alerta){
	alert(alerta);
}

/*****************************************************
Cambiamos las estrellas segun el mousemove
*****************************************************/
function selstar(val,val2,ruta_img) {
	for(x=0;x<=val2;x++){
		objStar = document.getElementById('star'+val+x);
		objStar.src = ruta_img;
	}
}
function remstar(val,val2,ruta_img){
	for(x=0;x<=val2;x++){
		objStar = document.getElementById('star'+val+x);
		objStar.src = ruta_img;
	}
}

/*****************************************************
FIN Cambiamos las estrellas segun el mousemove
*****************************************************/


function carga_foto(server,id_alb,id_img){
	
	var ajax=nuevoAjax();
	ajax.open("POST", server+"consulta.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("id="+id_alb+"&img="+id_img);
	
	ajax.onreadystatechange=function(){
	  if (ajax.readyState==4){

		var results = ajax.responseText.split("||");
		crear_htmlimg(server,results[0],results[1]);
	  }
	}
	
}

function crear_htmlimg(server,img,desc){
	
	td = document.createElement("td");
	td.width="487";
	td.height="365";
	td.style.background="url('"+server+"images/multimedia/images/"+img+"')";
	td.vAlign="bottom";
	
	table=document.createElement("table");
	table.width="487";
	table.border="0";
	table.cellPadding="0";
	table.cellSpacing="0";
	tbody = document.createElement('tbody');
	
	tr=document.createElement("tr");
	td2=document.createElement("td");
	
	td2.width="487";
	td2.height="70";
	td2.style.backgroundImage="url("+server+"img/transparencia.png)";
	td2.setAttribute('class','opacidad');
	td2.style.textAlign="justify";
	td2.appendChild(document.createTextNode(desc));
	td2.style.paddingLeft="25px";
	td2.style.paddingRight="25px";
	td2.vAlign="middle";
	
	tr.appendChild(td2);
	tbody.appendChild(tr);
	table.appendChild(tbody);
	td.appendChild(table);
	
	div="fotoalbum";
	limpiarDiv(div);
	document.getElementById(div).appendChild(td);
	
	
}


function limpiarDiv(id){
	var div;
	
	div = document.getElementById(id);
	
	while(div.hasChildNodes()){
		div.removeChild(div.lastChild);
	}
}
 
/*Funcion que ejecuta el Submit de buscar*/
function lanzar_buscar(){
	var msg ="";
	
	cajabuscar = document.getElementById('buscar');
	if(trim(cajabuscar.value)==0){
		msg = "Es necesario que escriba algo\n";
	}else if(cajabuscar.value.length<1){
		msg= "la busqueda de ser minimo de 1 caracter\n";
	}
	
	if(msg!=""){
		alert(msg);
	}else{
		document.frm_buscar.submit();
	}
}

/*Funcion que ejecuta el Submit de buscar*/
function lanzar_buscar1(){
	var msg ="";
	
	cajabuscar = document.getElementById('busqueda');
	if(trim(cajabuscar.value)==0){
		msg = "Es necesario que escriba algo\n";
	}else if(cajabuscar.value.length<1){
		msg= "la busqueda de ser minimo de 1 caracter\n";
	}
	
	if(msg!=""){
		alert(msg);
	}else{
		document.frm_buscar1.submit();
	}
}

/*validar buscar */
function validarBuscar(){
		
	palabra=document.getElementById('busqueda').value;
	
	if(palabra.length<1){
		alert("la palabra debe ser más de un caracter");
		return false;
	}
}

/*Funcion que ejecuta el Submit de contrataciones Historicas*/
function lanzar_contratacion(){
	
		document.contratacion_hist.submit();
	
}

/*Noticias*/
var not;
function iniciaCarga(id,intervalo){	
    //alert("entro"+id)
	not=setTimeout('carga_noticias_act(' + id + ','+ intervalo +')',intervalo);
	
}

function cargar_not(id,interval){
	clearTimeout(not);
	carga_noticias_act(id,interval);
	
}

function carga_noticias_act(id,intervalo){
	//alert("hola");
	var ajax=nuevoAjax();
	ajax.open("POST", server+"consulta_not.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("id="+id);
	
	ajax.onreadystatechange=function(){
		//alert(ajax.readyState);
		if (ajax.readyState==4){
			
			var results = ajax.responseText.split("|");			
			//alert (results[0])
			if(results[0]=="si"){			  
			  //alert(results[2]);
			  document.getElementById("divnoticias").innerHTML = results[2];
			  iniciaCarga(results[1],intervalo)
			
			}
				
		}
	}
	
}

/*Header*/

var enc;
function iniciaCabecera(server,id,intervalo){
    //alert("entro"+id)
	not=setTimeout('carga_cabecera_act("'+ server +'",' + id + ','+ intervalo +')',intervalo);
	
}

function carga_cabecera_act(server,id,intervalo){
	//alert("hola");
	var ajax=nuevoAjax();
	ajax.open("POST", server+"consulta_cabecera.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("id="+id);
	
	ajax.onreadystatechange=function(){
		//alert(ajax.readyState);
		if (ajax.readyState==4){
			
			var results = ajax.responseText.split("|");
			
			if(results[0]=="si"){
			  document.getElementById("divcabecera").innerHTML = results[2];
			  //alert(results[1]);
			  iniciaCabecera(server,results[1],intervalo)
			  
			}
		}
	}
}
