// www.revebel.com
// author : TastoDestro di Davide Tozzoli


// Funzioni per gestire il menu verticale
function ApriMenu_l1(id) {

	//alert("livello1");

	// chiudo tutti i menu a livello 1 visibili
	elementi_da_Chiudere = $$("div.menu_verticale_l1");
	elementi_da_Chiudere.each(
		function(el,index) {
			el.setStyle('visibility','hidden');
		}
	);

	id_complete = "menu_verticale_"+id;
	elemento=document.getElementById(id_complete);
	if (elemento!=null) {
		elemento.style.visibility = "visible";
	}
}

function ApriMenu_l2(id) {

	//alert("livello2");

	// chiudo tutti i menu a livello 2 visibili
	elementi_da_Chiudere = $$(["div.menu_verticale_l2","div.menu_verticale_l2_ie"]);
	elementi_da_Chiudere.each(
		function(el,index) {
			el.setStyle('visibility','hidden');
		}
	);
	
	id_complete = "menu_verticale_"+id;
	elemento=document.getElementById(id_complete);
	if (elemento!=null) {
		elemento.style.visibility = "visible";
	}
}

function ChiudiMenu_l2() {

	//alert("livello2");

	// chiudo tutti i menu a livello 2 visibili
	elementi_da_Chiudere = $$(["div.menu_verticale_l2","div.menu_verticale_l2_ie"]);
	elementi_da_Chiudere.each(
		function(el,index) {
			el.setStyle('visibility','hidden');
		}
	);
}


// ----------------- DIV DINAMICO ---------------------//
// Ricava lo scroll della finestra
function getScrollY() {
 	var scrOfY = 0;
 	if( typeof( window.pageYOffset ) == 'number' ) { 
		//Netscape compliant
		scrOfY = window.pageYOffset;
   	} else if( document.body && ( document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
   	} else if( document.documentElement && ( document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode 
		scrOfY = document.documentElement.scrollTop;
   	}   	
		return scrOfY;
}  

function getScrollX() {
 	var scrOfX = 0;
 	if( typeof( window.pageXOffset ) == 'number' ) { 
		//Netscape compliant
		scrOfX = window.pageXOffset;
   	} else if( document.body && ( document.body.scrollLeft ) ) {
		//DOM compliant
		scrOfX = document.body.scrollLeft;
   	} else if( document.documentElement && ( document.documentElement.scrollLeft ) ) {
		//IE6 standards compliant mode 
		scrOfX = document.documentElement.scrollLeft;
   	}   	
		return scrOfX;
}  

// crea dinamicamente un DIV
function create_dinamicDiv(metodo_dimensioni,rap_width,rap_heigth,id_div,metodo_posizione,left_px,top_px) {
	// metodo_dimensioni : fisso = fisso , relativo = dimensioni dipendono dalle dimensioni finestra
	// metodo_posizione : fisso = non dipende scroll top , relativo = dipende dallo scroll top, centrato = centrato nello schermo
	
	var window_width = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
	var window_height = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;

	// Dimensioni finestra
	if (metodo_dimensioni=="relativo") {
		w_num = Math.floor(window_width/rap_width);
		h_num = Math.floor(window_height/rap_heigth);
		w = w_num + "px";
		h = h_num + "px"; //	h=Math.floor(window_height/5*3)+"px";
	} else {
		w_num = rap_width;
		h_num = rap_heigth;
		w = w_num + "px";
		h = h_num + "px";
	}
	
	//alert(w+" x "+h);
	
 	var divTag = document.createElement("div");
   	divTag.id = id_div;
   	divTag.setAttribute("align","center");
	divTag.style.visibility="hidden";

	divTag.style.width = w;
	divTag.style.height = h;
	
	if (metodo_posizione=="relativo") {
		t = getScrollY()+top_px+"px";
	} else {
		t = top_px+"px";
	}
	
	l = left_px+"px";


	// se voglio centrato nel centro dello schermo
	if (metodo_posizione=="centrato") {
		t = getScrollY()+ Math.floor((window_height-h_num)/2)+144 + "px";
		l = Math.floor((window_width-w_num)/2)-182 + "px";
	}

	// imposto la posizione
	divTag.style.left = l;
 	divTag.style.top = t;
	//alert(l+" x "+t);

 	divTag.style.margin = "0 auto";
	divTag.className ="div_dinamico";
  	document.body.appendChild(divTag);
	divTag.style.visibility="visible";
} 

// Rimuove un DIV conoscendo ID
function removeDiv(id_elemento) {
	// Rimuovo il div loading
	y = document.getElementById(id_elemento);
	document.body.removeChild(y);
} 

function buisnessarea(stringa_risposta) {

	if (!(document.getElementById('div_buisnessarea'))) {
		create_dinamicDiv("fisso",160,60,"div_buisnessarea","centrato",100,100);

		str_contenuto = stringa_risposta;
		str_contenuto += "<p class=\"psw_label\">password</p>";
		str_contenuto += "<input type=\"password\" id=\"buisness_psw\" class=\"inp_psw\"><br />";
		str_contenuto += "<p class=\"psw_button\">";
		str_contenuto += "<a class=\"button_dinamico grassetto\" href=\"javascript:void(0);\" onClick=\"javascript:buisnessarea_go()\" alt=\"go\" title=\"go\">go</a> &nbsp;";
		str_contenuto += "<a class=\"button_dinamico\" href=\"javascript:void(0);\" onClick=\"javascript:removeDiv('div_buisnessarea')\" alt=\"close\" title=\"close\">close</a>";
		str_contenuto += "</p>";
		//alert(str_contenuto); // DEBUG

		document.getElementById("div_buisnessarea").innerHTML = str_contenuto;
	}

}

function buisnessarea_go() {
	//mootools Request
	psw = $('buisness_psw').value
	var req = new Request({url:'http://www.revebel.it/wp-content/themes/revebel/buisnessarea_psw.php',method:'post', 
		onSuccess: function(responseText) {
			//Clear the text currently inside the results div.
			//$('result').set('text', '');
			//Inject the new DOM elements into the results div.
			//$('result').adopt(html);
			if (responseText==0) {
				alert("Access Denied");	
			} else {
				//alert(responseText);
				location.href = responseText+"&pass=cvd";
			}
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function(responseText) {
			//$('result').set('text', 'The request failed.');
			alert("Access Denied");
			removeDiv('div_buisnessarea');
		}
	});
	
	//$('makeRequest').addEvent('click', function() {
		req.send('psw='+psw);
	//});
}



// HOME NEWS cambio background e url
// cambia il background delle news spot in home
function news_back_over(id) {
	document.getElementById(id).style.backgroundColor="#fed8ca";
}

function news_back_out(id) {
	document.getElementById(id).style.backgroundColor="#f5f4f3";
}

// link per news home
function news_go(url) {
	location.href=url;
}


// funzione per la ricerca nel sito
function search_TD() {
	search_text = document.getElementById("inp_search").value;
	//alert(search_text);

	if ((search_text!=null) && (search_text!="")) {
		url = "http://www.revebel.it/search/?find="+search_text;
		//alert(url);
		window.location = url;
	}
}

