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
}


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(email,confemail,nombre,apellido,direccion,zipcode,comunidad,pais,ciudad,telefono,pass,confpass,datos,letter){
	if(trim(document.getElementById('email').value)==0){alert(email); return false;}
	if(trim(document.getElementById('confirm_email').value)==0){alert(confemail); return false;}
	if(trim(document.getElementById('nombre').value)==0){alert(nombre); return false;}
	if(trim(document.getElementById('apellido').value)==0){alert(apellido); return false;}
	if(trim(document.getElementById('direccion').value)==0){alert(direccion); return false;}
	if(trim(document.getElementById('zip_code').value)==0){alert(zipcode); return false;}
	if(trim(document.getElementById('comunidad').value)==0){alert(comunidad); return false;}
	if(document.getElementById('pais').selectedIndex==0){alert(pais); return false;}
	if(trim(document.getElementById('ciudad').value)==0){alert(ciudad); return false;}
	if(trim(document.getElementById('telefono').value)==0){alert(telefono); return false;}
	if(trim(document.getElementById('pass').value)==0){alert(pass); return false;}
	if(trim(document.getElementById('confirm_pass').value)==0){alert(confpass); 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(pass + "<>"); return false;}
	
	if(document.getElementById('tratamiento').checked==''){alert(datos); return false;}
	if(document.getElementById('letter').checked==''){alert(letter); return false;}
	
	if(confirm("PLEASE CONFIRM")){
		document.frmRegistro.submit()
	}
}

/********************************************
VALIDAR MY ACCOUNT
********************************************/

function validarMyAccount(nombre,apellido,direccion,zipcode,comunidad,pais,ciudad,telefono){
	
	if(trim(document.getElementById('nombre').value)==0){alert(nombre); return false;}
	else if(trim(document.getElementById('apellido').value)==0){alert(apellido); return false;}
	else if(trim(document.getElementById('direccion').value)==0){alert(direccion); return false;}
	else if(trim(document.getElementById('zip_code').value)==0){alert(zipcode); return false;}
	else if(trim(document.getElementById('comunidad').value)==0){alert(comunidad); return false;}
	else if(document.getElementById('pais').selectedIndex==0){alert(pais); return false;}
	else if(trim(document.getElementById('ciudad').value)==0){alert(ciudad); return false;}
	else if(trim(document.getElementById('telefono').value)==0){alert(telefono); return false;}
	
	else {
	
		document.frmMicuenta.submit()
	}
}



/****************************************
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";
	if(navigator.appName=="Microsoft Internet Explorer"){
		document.getElementById('divMascara').style.position='absolute';
	}else{
		document.getElementById('divMascara').style.position='fixed';
	}
	mostrarDivHasta('divMascara' , 65);
}


function mostrarComent(texto){
	//alert("entro")
	ban=5;
	divconsale = document.getElementById("divMascara");
	divconsale.style.display = "block";
	if(navigator.appName=="Microsoft Internet Explorer"){
		document.getElementById('divMascara').style.position='absolute';
	}else{
		document.getElementById('divMascara').style.position='fixed';
	}
	mostrarDivHasta('divMascara' , 65);
	
	document.getElementById('divcoment').innerHTML=texto;
}


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";
	document.getElementById("divComent").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 if(ban==5){
			document.getElementById("divComent").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);
}

function popupASP(){
	var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, width=508, height=365, top=85, left=140";
	pagina = 'http://eu.ntrsupport.com/inquiero/anonymous2.asp?lang=en&login=80793';	
	window.open(pagina,"",opciones);
	
	
	
}


function validarEliminar($dir){
 if( confirm('Confirm your request') ){
   window.location = $dir;
 }
}
