
var main;
var head;
var colonnaSx;
var container;
var colonnaDx;
var footer;
var heightTotale;

function headHeight(){
	head = document.getElementById('head');
	head.style.height  = head.offsetHeight + 'px';
}

function containerHeight(){
	container = document.getElementById('container');
	container.style.height  = container.offsetHeight + 'px';
}

function colonnaSxHeight(){
	colonnaSx = document.getElementById('colonnaSx');	
	colonnaSx.style.height  = colonnaSx.offsetHeight + 'px';
}

function colonnaDxHeight(){
	colonnaDx = document.getElementById('colonnaDx');
	colonnaDx.style.height  = colonnaDx.offsetHeight + 'px';
}
function footerHeight(){
	footer = document.getElementById('footer');
	footer.style.height  = footer.offsetHeight + 'px';
}

function mainHeight(){
	headHeight();
	colonnaSxHeight();
	containerHeight();
	colonnaDxHeight();
	footerHeight();
	main = document.getElementById('main');

	container = document.getElementById('container');
	var container_offsetHeight = container.offsetHeight;
	if($('frm_dettagli_richiesta')) container_offsetHeight += 350
	Element.setStyle(container,
	{
		'height':Math.max(colonnaSx.offsetHeight,Math.max(colonnaDx.offsetHeight,container_offsetHeight))+'px'
	});
	Element.setStyle(colonnaSx,
	{
		'height':Math.max(colonnaSx.offsetHeight,Math.max(colonnaDx.offsetHeight,container_offsetHeight))+'px'
	});
	Element.setStyle(colonnaDx,
	{
		'height':Math.max(colonnaSx.offsetHeight,Math.max(colonnaDx.offsetHeight,container_offsetHeight))+'px'
	});
//	questa quando il layout è a tre colonne	
	heightTotale = Math.max(colonnaSx.offsetHeight,Math.max(colonnaDx.offsetHeight,container_offsetHeight)) + head.offsetHeight + footer.offsetHeight;
	main.style.height = heightTotale + 20 + 'px';
}



//preload immagini
function preloadIMG(){	
	var images = document.getElementsByTagName('img');
	var immagini=new Array();	
	var cont = 0;
	//percorro tutte le immagini		
	for (var i=0; i<images.length; i++){
		var image = images[i];
		var relAttribute = String(image.getAttribute('name'));
		//se hanno match preload... associo funzioni di preload
		if (relAttribute.toLowerCase().match('preload')){
			immagini[cont]=new Image();
			immagini[cont].src=image.src;
			cont++;
		}
	}
}

//	Switch immagini
function attachSwitch(){	
	var images = document.getElementsByTagName('img');
	//percorro tutte le immagini		
	for (var i=0; i<images.length; i++){
		var image = images[i];
		var relAttribute = String(image.getAttribute('name'));
		
		//se hanno match over... associo funzioni di swap img
		if (relAttribute.toLowerCase().match('over')){
			
			image.onmouseover = function(){
				if(this.className!="active"){
					this.src= this.src.replace('_off', '_on');
				}
			};
			image.onmouseout = function(){
				if(this.className!="active"){
					this.src= this.src.replace('_on', '_off');
				}
			};			
		}
		if(image.className == "active"){
			image.src= image.src.replace('_off', '_on');
		}
	}
}

//	over menu
function startMenu() {
	var node;
	var displaymenu;

	displaymenu = document.getElementById("menu");
	for (i=0; i<displaymenu.childNodes.length; i++) {
		node = displaymenu.childNodes[i];
		if (node.nodeName=="LI") {
			node.onmouseover=function() {
				this.className+=" over";
			}
			node.onmouseout=function(){                  
				this.className=this.className.replace("over", "")
			}
		}
	}
}

//	Corregge la visualizzazione dei PNG in explorer
function correctPNG() {
	for(var i=0; i<document.images.length; i++){
		var img = document.images[i];
		var imgName = img.src.toUpperCase();
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
			var imgID = (img.id) ? "id='" + img.id + "' " : "";
			var imgClass = (img.className) ? "class='" + img.className + "' " : "";
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			var imgStyle = "display:inline-block;" + img.style.cssText ;
			if (img.align == "left") imgStyle = "float:left;" + imgStyle;
			if (img.align == "right") imgStyle = "float:right;" + imgStyle;
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;     
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='crops');\"></span>";
			img.outerHTML = strNewHTML;
			i = i-1;
		}
	}
}


function goToLocation(elem){
	if(elem.firstChild)
	window.location.href= elem.firstChild.href;
}
function PNG()
{
	if(document.all&&document.styleSheets)
	{	
		var stylesheets=document.styleSheets;
		for(var i=0;i<stylesheets.length;i++)
		{
			var stylesheet=stylesheets[i];
			var rules=stylesheet.rules;
			for(var j=0;j<rules.length;j++)
			{
				var curRule=rules[j];
				if(curRule.style.backgroundImage&&(curRule.style.backgroundImage.indexOf('.png')>0))
				{
					var imageName=curRule.style.backgroundImage;
					imageName=imageName.substr(4,imageName.length-5);
					imageName= imageName.replace('../','');
					
					curRule.style.backgroundImage='';
					curRule.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://88.56.239.174/hotelatlantic/"+imageName+"')";
				}
			}
		}
	}
}

/*BOF FORM CONTATTI*/

//restituisco true in caso di errore
function validateFormElement(elem)
{
	if(elem.value=="")
	{
		errorOnFormElement(elem);
		return true;
	}
	else 
	{
		return false;
	}
}


function validateHiddenElement(element)
{
	if(validateFormElement(element))
	{
		errorOnFormElement('fieldset_dettagli_richiesta');
		errorOnFormElement('fieldset_dettagli_preventivo');
		return true;
	}
	else return false;



}

function validateCheckBoxElement(elem)
{
	if(elem.checked)
	{
		return false;
	}
	else
	{
		errorOnFormElement(elem.parentNode);	
		return true;
	}
}

function validateFormEmail(elem)
{
	var emailRegexp = RegExp('^[A-Za-z0-9._-]+[@]([A-Za-z0-9-]+[.])+([A-za-z]{2,4})$', 'i');
	
	if (emailRegexp.test(elem.value))
	{
		return false;
	}
	else
	{
		errorOnFormElement(elem);
		return true;
	}
}


function errorOnFormElement(elem)
{
	Effect.Shake(elem);
	new Effect.Highlight(elem);
}

function submitConfirm()
{
	var d = new Date()
	param = d.getTime();
	var form = $('confirm_form');
	
//inizio validazione
	var error_found = 0;			
	if(validateFormElement(form.frm_nome)) error_found++;
	if(validateFormEmail(form.frm_email)) error_found++;
//fine validazione	

	if(error_found==0)
	{
		Effect.BlindUp('form_confirm_all_fields');

		form.request({
		
		  onComplete: function()
		  { 	
			Effect.BlindDown('form_confirm_thanks');
			

			  return false; 
		   }
		
		});


//	document.forms['confirm_form'].submit();		

	}	
	return false;
	
}

function submitTherealguestbook()
{
	var d = new Date()
	param = d.getTime();
	var form = $('guestbooksign');
	
	document.forms['guestbooksign'].secure.value = param;
	document.forms['guestbooksign'].secure.value = param;

//inizio validazione
	var error_found = 0;			
	if(validateFormElement(form.frm_nome)) error_found++;
	if(validateFormEmail(form.frm_email)) error_found++;
//fine validazione	

	if(error_found==0)
	{
		Effect.BlindUp('form_guestbook_all_fields');


		form.request({
		
		  onComplete: function()
		  { 	
			Effect.BlindDown('form_guestbook_thanks');
			Form.reset('guestbooksign');

			  return false; 
		   }
		
		});


//	document.forms['guestbooksign'].submit();		

	}	
	return false;
	
}


function submitGuestBook()
{
	var d = new Date()
	param = d.getTime();
		
	var form = $('guestbooksign');
	document.forms['guestbooksign'].secure.value = param;


	//copio testo della text area
	if (document.forms['guestbooksign'].frm_tipo_richiesta.value=="richiesta preventivo")
	{
		document.forms['guestbooksign'].frm_messaggio.value=document.forms['guestbooksign'].frm_messaggio_a.value;
	}
	else
	{
		document.forms['guestbooksign'].frm_messaggio.value=document.forms['guestbooksign'].frm_messaggio_b.value;	
	}

//inizio validazione
	var error_found = 0;
			
	if(validateFormElement(form.frm_nome)) error_found++;
	if(validateFormEmail(form.frm_email)) error_found++;
	if(validateFormElement(form.frm_telefono)) error_found++;
	if(validateCheckBoxElement(form.frm_privacy_a) && validateCheckBoxElement(form.frm_privacy_b)) error_found++;
	//if(validateHiddenElement(form.frm_tipo_richiesta)) error_found++;
//fine validazione	


	if(error_found==0)
	{
		Effect.BlindUp('form_email_all_fields');

		form.request({
		
		  onComplete: function()
		  { 	
			Effect.BlindDown('form_email_thanks');
			Form.reset('guestbooksign');

			  return false; 
		   }
		
		});

/*
	document.forms['guestbooksign'].submit();		
*/	
	}	
	return false;
}



function showOnClick(element)
{
	
	if($(element).style.display == '') return false;
	else
	{
		if(element == 'frm_dettagli_richiesta')
		{
			Effect.BlindUp($('frm_dettagli_preventivo'), {afterFinish: down=function()
			{
				Effect.BlindDown(element, {afterFinish: down2=function()
				{
				
				}
				});				
												
				document.forms['guestbooksign'].frm_tipo_richiesta.value = 'richiesta informazioni';				
				
			}});
		}
		else
		{
			Effect.BlindUp($('frm_dettagli_richiesta'), {afterFinish: down=function()
			{
				Effect.BlindDown($('frm_dettagli_preventivo'), {afterFinish: down2=function()
				{
							
				}
				});
				document.forms['guestbooksign'].frm_tipo_richiesta.value = 'richiesta preventivo';
				
			}});
		}
	}
	
}

/*EOF FORM CONTATTI*/




function allFunctions()
{
	
	var loading = document.getElementById('page_loading');		
	var main = document.getElementById('main');
	
	//main.style.visibility="hidden";	
	
	
	preloadIMG();
	attachSwitch();
//	startMenu();
	mainHeight();
	//if(navigator.userAgent.match('MSIE')) correctPNG();
	
	
	/*
	var loading_page = document.getElementById('page_loading');
	if(navigator.userAgent.match('MSIE 6')) PNG();
	loading_page.style.display = 'none';
	main.style.visibility="visible";
	*/
}