var myWidth = 0, myHeight = 0,  myWidth_1 = 0, myHeight_1 = 0,  myWidth_2 = 0, myHeight_2 = 0;
switch (window.location.host){
	case "www.fluxair.it":
		window.location.href = window.location.href.replace("www.fluxair.it","www.materassi-fluxair.it");
		break;
	case "www.fluxair.com":
		window.location.href=window.location.href.replace("www.fluxair.com","www.fluxair-mattresses.com");
		break;
	default:
}
function altezzaWindow() {
	// altezza #blow
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth_1 = window.innerWidth;
		myHeight_1 = window.innerHeight;		
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth_1 = document.documentElement.clientWidth;
		myHeight_1 = document.documentElement.clientHeight + 20;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth_1 = document.body.clientWidth;
		myHeight_1 = document.body.clientHeight;
	}
	//
	myWidth_2 = document.body.clientWidth;
	myHeight_2 = document.body.clientHeight;
	//
	if (myWidth_1 > myWidth_2) {
		myWidth = myWidth_1-17;
	} else {
		myWidth = myWidth_2;
	}
	//
	if (myHeight_1 > myHeight_2) {
		myHeight = myHeight_1-20;
	} else {
		myHeight = myHeight_2; 
	}
}


function loading() {
	altezzaWindow();
	$("#loading").css({width:myWidth, height:myHeight+20, position:"absolute", top:"0px", left:"0px", zIndex:100, opacity:0.8, display:"block"});
}


function sistemaSwapImg() {
	$("#dett_1, #dett_2").hide();
	$("#dett_img li a").mouseover(function(){
		var swap = $(this).attr("rev");
		$("#dettagli p").hide();
		$("#"+swap).show();
	});
}


function sistemaClose() {
	$("#fa_premium:visible, #fa_signum:visible, #fa_planaria:visible, #fa_accessori:visible").hide();
}


function sistema(){
	$("#collezione a.close").click(function(){
		sistemaClose();
		return false;
	});
	
	$("#fa_premium, #fa_signum, #fa_planaria, #fa_accessori").hide();
	
	$("#sub_menu_prod ul li a").click(function(){
		sistemaClose();
		var myDiv = $(this).attr("href");
		if ($.browser.msie) {
			$(myDiv).show();
		} else {
			$(myDiv).fadeIn("normal");
		}
		$("#collezione a.close").show();
		return false;
	});
}


/*post form*/
var alertColor = '#a10000'

function validateForm() {	
	var str = '';
	var err = false;
	$('input:visible,select:visible').each(function(i){
		  if ($(this).prev().filter(':contains("*")').html() != null)   
		 {
			 if ($(this).val().length == 0) 
			 	{err=true; 
				$(this).prev().css({color:alertColor});
				} 
			else 
				{$(this).prev().css({color: "" })}
				// gestione eccezioni
				switch (this.id) {
					case 'femail':
						var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
						if (!filter.test(this.value)) 
							{err=true; 
								$(this).prev().css({color:alertColor});
							} 
						else 
							{$(this).prev().css({color: "" })}						 
					break;														
				}
		 } 
	});	
	if (!err) {				
		 sendEmail();
		} 
}

function returnParms() {
	var myParms = {
	  nome: $('#fnome').val(), 
	  azienda: $('#fnomeazienda').val(), 
	  indirizzo: $('#fvia').val(),
	  cap: $('#fcap').val(),   
	  citta: $('#fcitta').val(), 
	  email: $('#femail').val(),
	  provincia: $('#fprovincia').val(),
	  stato: $('#fstato').val(),
	  telefono: $('#ftelefono').val(),
	  fax: $('#ffax').val(), 
	  rivenditore: document.getElementById('frivenditore').checked,
	  visita: document.getElementById('fvisita').checked,
	  catgratis: document.getElementById('fcatgratis').checked	  
  }
  return myParms;
}

function sendEmail() {
var Esito = 0
var url = location.href.split("_")[1].split(".")[0];
Esito = $.post("sendmail.asp?act=Send",
	returnParms(),
  function(data){
		$('#formContatti').hide();
		$('#responseContatti').show();
		if (url == "it") {
			pageTracker._trackPageview("/funnel_G1/invia_form.html");
		} else if (url == "en") {
			pageTracker._trackPageview("/funnel_G2/invia_form.html");
		}
  });
}
/*post form*/


$(document).ready(function(){

	if (location.href.indexOf("#") != -1) {
		if (location.href.indexOf("_link") == -1) {
			mioUrl = location.href.split("#")[1];
			realUrl = "#" + mioUrl.split("_link")[0];
			url = "#concept";
			self.status = realUrl;
			location.href = url;
			menuNav(realUrl);
			location.href = realUrl + "_link";
		}
	}
	
	
	$("#marker").show();
	$("#menu ul li a[@href='concept']").addClass("on");
	loading();
	sistemaSwapImg();
	sistema();
	supahbox();
	$("#tecnologia .testi ul").supahfade("slow",3000,"auto");
	$("#technology .testi ul").supahfade("slow",3000,"auto");
	$("#invia").click(function(){validateForm();return false;});	
	setTimeout(function(){
		if ($("#loading").size()) {
			$("#loading").fadeOut("normal",function(){
				$(this).remove();
			});
		}
	}, 4000);
});


window.onload = function() {
	$("#loading").fadeOut("normal",function(){
		$(this).remove();
	});
};