// JavaScript Document
$(document).ready(
	function(){
		$.ImageBox.init(
			{
				loaderSRC: imgWaiting,
				//closeHTML: '<img src="js/interface/img/close.jpg" />'
				textImage:'',
				textImageFrom:'',
				closeHTML: '<img src="'+imgClose+'" />'
			}
		);
	}
);

	function cicle(){
		setTimeout("pippo()",2000)	
	}
	function pippo(){
	menuHeight = (parseInt(document.body.clientHeight)-parseInt(document.getElementById("container-head").offsetHeight)-parseInt(document.getElementById("container-foot").offsetHeight))
	//alert(menuHeight+"|"+(nMax+100))
	//alert(menuHeight+"|"+$('#container-page').height()+"|"+$('#container-content').height())
	if(menuHeight > 800){
		$('#container-content').height(menuHeight)
		$("#menu").height(menuHeight)
		$("#main").height(menuHeight)
		$("#menudx").height(menuHeight)
	}
	}
window.onload = cicle

var nMax
window.onload =
	function(){
		var containerfoot = (document.getElementById("container-foot")) ? document.getElementById("container-foot").offsetHeight : 20
		//adatto i div menu sx e main al caricamento della pagina
		menuHeight = (parseInt(document.body.clientHeight)-parseInt(document.getElementById("container-head").offsetHeight)-parseInt(containerfoot))
		menuH = $("#menu").height()
		mainH = $("#main").height()
		menudxH = $("#menudx").height()
		appoMax = Math.max(menuH,mainH)
		nMax = Math.max(appoMax,menudxH)
		//alert(menuH+"|"+appoMax+"|"+nMax)
		appoH = (nMax>700) ? nMax+120 : menuHeight
		//alert("menuH:"+menuH+"| mainH:"+mainH+"| menudxH:"+menudxH+"| MAX:"+nMax+"|menuHeight:"+menuHeight+"|appoH:"+appoH)
		//se il browser ha una dimensione piccola evito di sovrapporre i div.
		
		if(document.location.href.indexOf("gallery.cfm")>=0 && document.body.clientHeight < 700) appoH = 610;
		if(document.location.href.indexOf("adminGalleria.cfm")>=0 && document.body.clientHeight < 700) appoH = 600;
		if(document.location.href.indexOf("comearrivare.cfm")>=0 && document.body.clientHeight < 700) appoH = 700;
		if($('#menudx').html() && document.body.clientHeight < 570) appoH = 580;
		if(document.body.clientHeight<500) appoH = 550;
		$('#container-content').height(appoH)
		$("#menu").height(appoH)
		$("#main").height(appoH)
		$("#menudx").height(appoH)
	}

//adatto i div menu sx e main al resize della pagina 
window.onresize = function(){
	menuHeight = (parseInt(document.body.clientHeight)-parseInt(document.getElementById("container-head").offsetHeight)-parseInt(document.getElementById("container-foot").offsetHeight))
	//alert(menuHeight+"|"+(nMax+100))
	//alert(menuHeight+"|"+$('#container-page').height()+"|"+$('#container-content').height())
	if($('#login').html()){
		var menuHeight = 550
	}
	if(document.location.href.indexOf("gallery.cfm")>=0 && document.body.clientHeight < 700) menuHeight = 610;
	if(document.location.href.indexOf("adminGalleria.cfm")>=0 && document.body.clientHeight < 700) menuHeight = 600;

	if(document.location.href.indexOf("comearrivare.cfm")>=0 && document.body.clientHeight < 700) menuHeight = 700;
	if(menuHeight > 0 && menuHeight > 500){
		$('#container-content').height(menuHeight)
		$("#menu").height(menuHeight)
		$("#main").height(menuHeight)
		$("#menudx").height(menuHeight)
	}
	//$("#appores").html(menuHeight+"|"+$("#menudx").height()+"|"+(nMax+100))
	//alert($('#login').html())
}


window.onerror = function(){
		return true
	}

function fn_responseLogin(){

	//$('#menu').load('../htm/menu/_menu.cfm?xmlMenupath=_menuAdmin.xml')
	document.location.reload()
}

function redirectTo(path){
	document.location.href = path	
}

function deleteRow(uri){
	//uri = obj.path+"?action="+obj.action+"&CLN_IDofferta="+obj.CLN_IDofferta
	if(confirm('Sicuri di voler eliminare il record?\n\nOk per continuare.')==true)
		redirectTo(uri)
}

function hideView(element, run){
	if(typeof run == 'undefined'){
		( document.getElementById(element).style.display == 'block' ) ? document.getElementById(element).style.display = 'none' :document.getElementById(element).style.display = 'block'
	}
	else{
		//if(element == "esami" || element == "anamnesi") document.getElementById('main').innerHTML = ""
		document.getElementById(element).style.display = (run == true) ? "block" : "none"
	}
}

//google maps
$(document).ready(
		function(){
			
			if(document.getElementById("map2")){
				load()
				//menuHeight = (parseInt(document.body.clientHeight)-parseInt(document.getElementById("container-head").offsetHeight)-parseInt(document.getElementById("container-foot").offsetHeight))
				//$("#map2").height(menuHeight)
			}
		}
	);

window.onunload = function(){
	if(document.getElementById("map2")){
		GUnload()
	}
}
function load() {
	if (GBrowserIsCompatible()) {		
		var map = new GMap2(document.getElementById("map2"));
		var point = new GLatLng(41.971265, 12.63005); 
		map.setCenter(point, 17);
		map.setZoom(12)
		map.addControl(new GLargeMapControl());
		map.addControl(new GOverviewMapControl());
		//map.addControl(new GMapTypeControl());
		var markTXT = "<div style='text-align:center;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:10px;'><span style='font-weight:bold'>B &amp; B Parco Azzurro</span><br />Bed & Breakfast di Paola Sinibaldi<br><br>Localit&agrave; Parco Azzurro V. Nomentana km. 15.700<br>Info.line: 0774-363923 | Cell.: 333-1024457</div>"
		map.openInfoWindowHtml(map.getCenter(), markTXT);
		var marker = new GMarker(point);
		GEvent.addListener(marker, "click", function(){marker.openInfoWindowHtml(markTXT);})
		map.addOverlay(marker);
		//map.addOverlay(createMarker(point, 1)); 


	}
}

//maxlenght textarea
function maxLength(obj,nChar){
	if(obj.value.length>nChar){
		alert("Raggiunto il limite massimo dei caratteri consentiti.\n\nIl testo verr\u00E0 troncato.")
		return obj.value = obj.value.substr(0,nChar)
		obj.focus()
	}
}

function resizeDiv(mat){
	var Hdiv = $('#container-content').height()
	
	menuHeight = (parseInt(document.body.clientHeight)-parseInt(document.getElementById("container-head").offsetHeight)-parseInt(document.getElementById("container-foot").offsetHeight))
	if(Hdiv>menuHeight){
		if(mat == "up"){
			$('#container-content').height(Hdiv+20)
			$('#menu').height(Hdiv+20)
			$('#main').height(Hdiv+20)
		}
		else if(mat == "down"){
			$('#container-content').height(Hdiv-20)
			$('#menu').height(Hdiv-20)
			$('#main').height(Hdiv-20)
		}
	}
}

function disabledSUBMIT(obj){
	obj.value='Attendere...';
	setTimeout("document.forms[0].elements['"+obj.name+"'].disabled=true",500)
	//setTimeout("document.forms[0].elements["+obj.name+"].disabled=true",500)
}