﻿function submitIt(nomeForm) {
	
	if(lang == 'IT') {
		txtCampi = 'Compilare i campi obbligatori';
		txtPrivacy = 'E\' necessario dare il consenso al trattamento dei dati personali per proseguire';
		txtNews = 'E\' necessaria l\'iscrizione alla Newsletter per proseguire';
	} else if(lang == 'EN') {
		txtCampi = 'To compile all the required fields';
		txtPrivacy = 'It is necessary to give the consent to the treatment of the personal data to go on';
		txtNews = 'It is necessary to subscribe the Newsletter to go on';
	} else if(lang == 'RU') {
		txtCampi = 'заполните все обязательные поля';
		txtPrivacy = 'Необходимо дать согласие о конфиденциальном использовании нами ваших персональных данных';
		txtNews = '';
	}
	
	form = document.getElementById(nomeForm);
	myFormElements = form.elements;
	var error = 0;
	//for(i=0;i<myFormElements.length;i++) {
	for(i=0;i<4;i++) {
		document.getElementById("cont_"+myFormElements[i].name).style.backgroundColor = '';
		if(myFormElements[i].value=="") {
			if(i < 4) {
				error++;
				document.getElementById("cont_"+myFormElements[i].name).style.backgroundColor = '#4c4c4c';
			}	
		}		
	}
	
	for(i=0;i<myFormElements.length;i++) {
		if(myFormElements[i].name == 'privacy' && myFormElements[i].checked == false) {
			errorP=1;
			error++;
		}
		if(myFormElements[i].name == 'newsletter' && myFormElements[i].checked == false) {
			errorN=1;
			error++;
		}
	}
	
	if(error > 0) {
		alert(txtCampi);
		if(errorP == 1) {
			alert(txtPrivacy);
		}
		if(errorN == 1) {
			alert(txtNews);
		}
	} else {
		form.submit();
	}
}

function resetIt(nomeForm) {
	form = document.getElementById(nomeForm);
	myFormElements = form.elements;
	for(i=0;i<myFormElements.length;i++) {
		document.getElementById("cont_"+myFormElements[i].name).style.backgroundColor = '';
	}
	form.reset();
}

function submitForm(form) {
	myForm = document.getElementById(form);
	myForm.submit();
}

// ROLL PRIMO MENU

function rollOverBttMenu(id) {
	if (loaded == 1) {
		//document.getElementById('bttMenu'+id).style.background  = 'url(img/bckBttActive.jpg) repeat-x';
		//document.getElementById('bttMenu'+id).style.width = '114px';
		//document.getElementById('bttMenu'+id).style.borderLeft = '1px solid #404040';
		if(id !== 1) {
			//document.getElementById('bttMenu'+id).style.borderTop = '1px solid #d0f0c0';
		}
		//document.getElementById('a'+'bttMenu'+id).style.color = '#4682b4';
		document.getElementById('bttMenu'+id).style.cursor = 'default';
	}
}
function rollOutBttMenu(id) {
	if (loaded == 1) {
		if(id !== 1) {
			//document.getElementById('bttMenu'+id).style.borderTop = '1px dotted black';
		} else {
			//document.getElementById('bttMenu'+id).style.borderTop = '0px';
		}
		//document.getElementById('bttMenu'+id).style.borderLeft = 'none';
		//document.getElementById('bttMenu'+id).style.width = '114px';
		//document.getElementById('bttMenu'+id).style.background  = 'url(img/bckBtt.jpg) repeat-x';
		//document.getElementById('a'+'bttMenu'+id).style.color = '#4682b4';
	}
}


function rollBtt(stato,btt) {
	myBtt = document.getElementById(btt);
	if(stato==1) {
		myBtt.style.color = 'black';
	} else {
		myBtt.style.color = 'white';
	}
}


function goToPage(pag) {
	if (loaded == 1) {
		document.location.href = 'index.asp?zona='+pag;
	}
}

function gotoAHAH(url,target) {
	completeAHAH.ahah(url,target,'0','GET');
}

trovato = '';

//FUNZIONI DELLA HOME



function detectFF() {
	if(navigator.userAgent.indexOf("Firefox")!=-1){
		trovato = 'FF';
	} else if (navigator.appVersion.indexOf("MSIE")!=-1){
		trovato = 'IE';
	} else {
		trovato = 'UNKNOW';
	}
}

function ridOscura() {
	width = document.body.offsetWidth;
	height = document.body.offsetHeight;
	
	cont = document.getElementById('contenitore');
	contH = cont.offsetHeight;
	
	//alert('height = '+height+' - contH = '+contH);
	detectFF();
	if(height == null || height == 0) {
		if (trovato == 'IE') {
			
			height1 = document.documentElement.scrollHeight;
			height2 = document.documentElement.clientHeight;
			if(height1 >= height2) {
				height = height1;
			} else {
				height = height2;
			}
			//alert("IE - "+height);
		} else if (trovato == 'FF') {
			height = document.documentElement.scrollHeight;
			//alert("FF - "+height);
		} else {
			height = document.documentElement.clientHeight;
			//alert("ELSE - "+height);
		}
	}
	
	if(height > contH) {
		h = height;
	} else {
		h = contH;
	}
	
		
	
	//alert('w='+width+' h='+height);
	element = document.getElementById('oscura');
	element.style.width = width+'px';
	element.style.height = h+'px';
}

function popDoc(cCount,zona) {
	window.open('doc.asp?cCount='+cCount+'&zona='+zona,'allegato','700,500');
}

function popUp(vis,id,zona) {
	if (vis == 1) {
		
		ridOscura();
		
		element = document.getElementById('oscura');
		rand = Math.floor(Math.random()*99999999);
		pageToLoad = zona+'.asp';

		if(document.getElementById('popUp').style.display != 'block') {	
			if(document.body.scrollTop) {	
				document.getElementById('popUp').style.top = (document.body.scrollTop+25)+'px';
			} else {
				document.getElementById('popUp').style.top = (document.documentElement.scrollTop+25)+'px';
			}
			bytefx.alpha(element, 0);
			element.style.display = 'block';
			bytefx.fade(element, 0, 80, 15,
				function() {
					document.getElementById('popUp').style.display = 'block';
					completeAHAH.ahah(pageToLoad+'?id='+id+'&rnd='+rand,'popUp','0','GET');
				}
			);
		} else {
			completeAHAH.ahah(pageToLoad+'?id='+id+'&rnd='+rand,'popUp','0','GET');
		}
	} else {
		completeAHAH.ahah('blank.asp','popUp','0','GET');
		document.getElementById('popUp').style.display = 'none';
		element = document.getElementById('oscura');
		bytefx.fade(element, 80, 0, 15, function(){
			document.getElementById('oscura').style.display = 'none';
		});
		//bytefx.alpha(element, 0);
		
		
	}
}

function selectSea(sea) {
	document.getElementById('selectSea').innerHTML = sea;
	document.getElementsByName('mariBarca')[0].value = sea;
	popUp('0','','');
}

function leasing(stato,param) {
	
	if(lang == 'IT') {
		txtCampi = 'Compilare tutti i campi';
		txtPrivacy = 'E\' necessario dare il consenso al trattamento dei dati personali per proseguire';
	} else if(lang == 'EN') {
		txtCampi = 'Fill in all the fields';
		txtPrivacy = 'It is necessary to give the consent to the treatment of the personal data to go on';
	} else if(lang == 'RU') {
		txtCampi = 'заполните все поля';
		txtPrivacy = 'Необходимо дать согласие о конфиденциальном использовании нами ваших персональных данных';
	}
	
	element = document.getElementById('leasing');
	etL = document.getElementById('etCalc').value;
	
	var error = 0;
	
	if(param != '') {
		myForm = document.getElementById('leasingForm');
		myFormEl = myForm.elements;
		totEl = myFormEl.length;
		
		for(i=0;i<totEl;i++) {
			document.getElementById("cont_"+myFormEl[i].name).style.backgroundColor = '';
			if(myFormEl[i].value == '') {
				error++;
				document.getElementById("cont_"+myFormEl[i].name).style.backgroundColor = '#4c4c4c';
			}
			if(myFormEl[i].name == 'privacy' && myFormEl[i].checked == true) {
				if(myFormEl[i].value == 0) {
					error=25;
				}
			}
		}
		if(error > 0) {
			alert(txtCampi);
		} 
		if(error == 25) {
			alert(txtPrivacy);
		}
	}

	if(stato > 0) {
		etL = etL+' &uarr;';
		document.getElementById('bttLeasing').href = 'javascript:leasing("0","")';
		document.getElementById('bttLeasing').innerHTML = etL;
		if(param == '') {
			pageToLoad = 'leasing.asp';
		} else if(param == 'step=2') {
			prezzo = document.getElementsByName('leasingForm')[0].prezzo.value;
			period = document.getElementsByName('leasingForm')[0].period.value;
			anni = document.getElementsByName('leasingForm')[0].anni.value;
			acconto = document.getElementsByName('leasingForm')[0].acconto.value;
			paramNew = param+'&prezzo='+prezzo+'&period='+period+'&anni='+anni+'&acconto='+acconto;
			pageToLoad = 'leasing.asp?'+paramNew;
		} else {
			pageToLoad = 'leasing.asp?'+param;
		}
		bytefx.size(
		element,
		{width:800,height:100},
		15,
			function() {
				if(error == 0) {
					if(stato > 1) {
						myForm = document.getElementById('leasingForm');
						myForm.submit();
					} else {
						completeAHAH.ahah(pageToLoad,'leasingFormDiv','0','GET');
					}
				}
			}
		);
	} else {
		etL = etL+' &darr;';
		document.getElementById('bttLeasing').href = 'javascript:leasing("1","")';
		document.getElementById('bttLeasing').innerHTML = etL;
		bytefx.size(
		element,
		{width:800,height:25},
		15,
			function() {
				completeAHAH.ahah('blank.asp','leasingFormDiv','0','GET');
			}
		);
	}
}

function display(vis,div) {
	if(vis == 1) {
		document.getElementById(div).style.display='block';
	} else {
		document.getElementById(div).style.display='none';
	}
}


var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);

function getMouseXY(e,posizione) {
	
	//var tempX = 0;
	//var tempY = 0;

	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		if(document.body.scrollTop) {
			tempY = event.clientY + document.body.scrollTop;
		} else {
			tempY = event.clientY + document.documentElement.scrollTop;
		}
		
	} else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
		//alert(tempX, tempY);	
	}  
	// catch possible negative values in NS4
	if (tempX < 0) {
		tempX = 0;
	}
	
	if (tempY < 0) {
		tempY = 0;
	} 
	
	//if (cCount2 != 0) {
					
		objDiv = document.getElementById('popUpImg');
		objHeight = objDiv.offsetHeight;
		//Y = objDiv.style.top = tempY-(objHeight/2)+'px';
		objDiv.style.top = tempY-(objHeight/2)+'px';
		//alert(posizione);
		//if (posizione == 1) {
		objDiv.style.left = tempX+35+'px';
		//} else {
			//X = objTipDiv.style.left = tempX-300+'px';
		//}
		
	//}
  return true
}


function popUpImg(vis,img,imgmdl) {
	if (vis == 1) {
		
		ridOscura();
		
		//element = document.getElementById('oscura');
		//bytefx.alpha(element, 0);
		//element.style.display = 'block';
		//bytefx.alpha(element, 0);
		//bytefx.fade(element, 0, 80, 15, function(){
		//});
		//rand = Math.floor(Math.random()*99999999);
		document.onmousemove = getMouseXY;
		pageToLoad = 'popupImg.asp?img='+img+'&imgmdl='+imgmdl;
		
		//document.getElementById('popUp').style.top = tempY-15+'px';
		document.getElementById('popUpImg').style.display = 'block';
		completeAHAH.ahah(pageToLoad,'popUpImg','0','GET');
	} else {
		completeAHAH.ahah('blank.asp','popUpImg','0','GET');
		document.getElementById('popUpImg').style.display = 'none';
		//element = document.getElementById('oscura');
		//bytefx.fade(element, 80, 0, 15, function(){
			//document.getElementById('oscura').style.display = 'none';									 
		//});
	}
}



function openSearch(vis) {
	form = document.getElementById('searchIt');
	myFormElements = form.elements;
	etSearchLang = myFormElements[0].value;
	contSearch = document.getElementById('contenitoreSearch');
	arrow = document.getElementById('searchArrow');
	etSearch = document.getElementById('etSearchMain');
	contH = contSearch.scrollHeight;
	
	element = document.getElementById('SearchBoard');
	if(vis == 1) {
		
		bytefx.size(
		element,
		{width:108,height:420},
		15);
		
		arrow.innerHTML = '<a href="javascript:openSearch(0);" title="close search">&uarr;</a>';
		etSearch.innerHTML = '<a href="javascript:openSearch(0);" title="close search">'+etSearchLang+'</a>';
		
	} else {

		bytefx.size(
		element,
		{width:108,height:18},
		15);
		
		arrow.innerHTML = '<a href="javascript:openSearch(1);" title="open search">&darr;</a>';
		etSearch.innerHTML = '<a href="javascript:openSearch(1);" title="open search">'+etSearchLang+'</a>';
	}
}



function controlloCampi() {
	var stopIt = 0;
	var form = document.contact;
	var nome = form.nome.value;
	var cognome = form.cognome.value;
	var azienda = form.azienda.value;
	var indirizzo = form.indirizzo.value;
	var cap = form.cap.value;
	var citta = form.citta.value;
	var tel = form.tel.value;
	var email = form.email.value;
	var oggettoMsg = form.oggettoMsg.value;
	var corpoMsg = form.corpoMsg.value;
	corpoMsg.replace("\r","<br />");
	
	//CONDIZION
	
	if (nome == "") {
		alert("non hai inserito il nome");
		stopIt = 1;
	}
	if (cognome == "") {
		alert("non hai inserito il cognome");
		stopIt = 1;
	}
	if (email == "") {
		alert("non hai inserito la mail");
		stopIt = 1;
	}
	if (oggettoMsg == "") {
		alert("non hai inserito l'oggetto");
		stopIt = 1;
	}
	if (corpoMsg == "") {
		alert("non hai inserito il corpo del messaggio");
		stopIt = 1;
	}
	if (stopIt == 0) {

				
		//Applico replace per sostituire Pippo con Pluto
		corpoMsg = corpoMsg.replace(/\n/g, '<br>');
		
		
		//alert(corpoMsg);
		completeAHAH.ahah('popup.asp?step=2&nome='+nome+'&cognome='+cognome+'&azienda='+azienda+'&indirizzo='+indirizzo+'&cap='+cap+'&citta='+citta+'&tel='+tel+'&email='+email+'&oggettoMsg='+oggettoMsg+'&corpoMsg='+corpoMsg,'popup','0','GET');
		//ahah('insertCliente.asp','toDb');
	}
}


//FUNZIONI DELLA GALLERY
function allineaImg(target) {
	element = document.getElementById(target);
	//bytefx.alpha(element, 0);
	hImg = element.offsetHeight;
	hBox = document.getElementById('out'+target).clientHeight;
	topImg = (hBox-hImg)/2;
	//if (topImg > 0) {
		element.style.marginTop = topImg+'px';
	//}
	
//	bytefx.alpha(element, 100);
}


//function inizializzaGallery(iniSel,txtXS,txtS,lrg) {
//	document.getElementById('lrg').src = '';
//	element = document.getElementById('outtmb'+iniSel);
//	element.style.borderColor = 'black';
//	if(document.getElementById('titTxt')) {
//		document.getElementById('titTxt').innerHTML = txtXS;
//	}
//	if(document.getElementById('descTxt')) {
//		document.getElementById('descTxt').innerHTML = txtS;
//	}
//	//document.getElementById('lrg').src = lrg;
//	//completeAHAH.ahah('zoom.asp?media='+lrg,'zoom','0','GET');
//	document.getElementById('lrg').src = lrg;
//	sel = iniSel;
//}

sel = 0;
//newSel = '';


tot = 0;
img = new Array();

function inizializzaGallery(iniSel,idrand) {	
	
	rand = Math.floor(Math.random()*99999999);
	
	document.getElementById('outtmb'+sel).style.borderColor = 'white';
	document.getElementById('outtmb'+iniSel).style.borderColor = 'black';
	
	completeAHAH.ahah('zoom.asp?id='+iniSel+'&idrand='+idrand+'&rnd='+rand,'zoom','0','GET');
	
	sel = iniSel;
}

function tmbClick(id) {
	
	
	//sel = parseInt(sel);
	
	if(id == '-2') {
		id = sel+1;
	} else if(id == '-1') {
		id = sel-1;
	} else {
		//id = parseInt(id);
	}
	
	tot = document.getElementById('tot').value;
	//tot = parseInt(tot);
	
	bttPrev = document.getElementById('bttPrev');
	bttNext = document.getElementById('bttNext');
	
	bttPrev.style.display = 'block';
	bttNext.style.display = 'block';
	
	if(id == 0) {
		bttPrev.style.display = 'none';
	} 
	if(id == tot) {
		bttNext.style.display = 'none';
	}
	
	lrg = document.getElementById('img'+id).value;
	
	document.getElementById('outtmb'+sel).style.borderColor = 'white';
	document.getElementById('outtmb'+id).style.borderColor = 'black';
	sel = id;
	document.getElementById('lrg').src = 'mdb-database/Media/'+lrg;
}

function navFoto(actual,dir,tot,actPage,maxForPage) {
	//actual = parseInt(actual);
	//dir = parseInt(dir);
	//tot = parseInt(tot);
	//actPage = parseInt(actPage);
	//maxForPage = parseInt(maxForPage);
	
	if(dir == 0 && actual !== 0) {
		toLoad = actual-1;
		if(actPage !== 0) {
			if (toLoad < ((actPage+1)*maxForPage)) {
				loadPage(actPage-1);
			}
		} else {
			if(toLoad >= 0) {
				sel = toLoad;
				//document.getElementById('tmb'+actual).style.borderColor = '#003366';
				//document.getElementById('tmb'+toLoad).style.borderColor = 'white';
				completeAHAH.ahah('zoom.asp?id='+toLoad,'zoom','0','GET');
			}
		}
	} else {
		if(dir == 1 && actual !== tot) {
			toLoad = actual+1;
			if (toLoad > ((actPage+1)*maxForPage)) {
				loadPage(actPage+1);
			} else {
				if(toLoad <= (tot-1)) {
					sel = toLoad;
					//document.getElementById('tmb'+actual).style.borderColor = '#003366';
					//document.getElementById('tmb'+toLoad).style.borderColor = 'white';
					completeAHAH.ahah('zoom.asp?id='+toLoad,'zoom','0','GET');
				}
			}
		}
	}
}


function tmbOn(id) {
	document.getElementById('outtmb'+id).style.borderColor = '#66ff00';
}

function tmbOff(id) {
	if(sel !== id) {
		document.getElementById('outtmb'+id).style.borderColor = '#2f4f4f';
	}
}

function loadPage(nPage) {
	//completeAHAH.ahah('tmbGallery.asp?page='+nPage,'tmb','0','GET');
}

