var d = document;

var _isMSIE, _isWin, _isMac, _isMoz, _isSafari, _IE5, _IE6, _IE7, _isKonq, Li, _isOpera, _linux, _winNT, _isMSIE, _isWin, _isMac, _isMoz, _isSafari;
(function() {
	var a = navigator.userAgent.toLowerCase();
	_isMSIE = a.indexOf("msie") != -1;
	_IE5 = a.indexOf("msie 5") != -1 && document.all;
	_IE6 = a.indexOf("msie 6") != -1 && document.all;
	_IE7 = a.indexOf("msie 7") != -1 && document.all;
	_isKonq = a.indexOf("konqueror") != -1;
	_isSafari = a.indexOf("safari") != -1 || _isKonq;
	var b = a.match(/ applewebkit\/(\d+)/);
	Li = b && parseInt(b[1],10) >= 522;
	_isMoz = !_isMSIE && !_isSafari && a.indexOf("mozilla") != -1;
	_isOpera = !(!window.opera);
	var c = navigator.appVersion;
	_isMac = c.indexOf("Mac") != -1;
	_isWin = (c.indexOf("Win") != -1 || c.indexOf("NT") != -1) && !_isMac;
	_winNT = c.indexOf("Windows NT 6.0") != -1;
	_linux = a.indexOf("linux") != -1;
})();
var _isGeko = _isMoz || _isOpera;

// funzione per pescare le dimensioni della pagina e della finestra
function getPageSize(){
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = d.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (d.body.scrollHeight > d.body.offsetHeight){ // all but Explorer Mac
		xScroll = d.body.scrollWidth;
		yScroll = d.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = d.body.offsetWidth;
		yScroll = d.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (d.documentElement && d.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = d.documentElement.clientWidth;
		windowHeight = d.documentElement.clientHeight;
	} else if (d.body) { // other Explorers
		windowWidth = d.body.clientWidth;
		windowHeight = d.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		var pageHeight = windowHeight;
	} else {
		var pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		var pageWidth = windowWidth;
	} else {
		var pageWidth = xScroll;
	}

	var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

// Funzione per conoscere lo scroll verticale e orizzontale
function getPageScroll(){
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (d.documentElement && d.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = d.documentElement.scrollTop;
	} else if (d.body) { // all other Explorers
		yScroll = d.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

function layout() {

	var dimPage = getPageSize();
	altezza = 0;

	if (d.getElementById('coldx')) {
		if (self.innerHeight) {
			if (d.getElementById('coldx').scrollHeight + 180 < dimPage[3]) {
				altezza = dimPage[3];
			} else {
				altezza = d.getElementById('coldx').scrollHeight + 180;
			}
		} else {
			if (d.getElementById('coldx').clientHeight + 180 < dimPage[3]) {
				altezza = dimPage[3];
			} else {
				altezza = d.getElementById('coldx').clientHeight + 180;
			}
		}
	}

	if (altezza != 0) {
		altezza = Math.round(altezza);
		if (altezza < 610)
			altezza = 660;

		d.getElementById('colsx').style.height = (altezza - 170) + 'px';
		d.getElementById('coldx').style.height = (altezza - 190) + 'px';
		d.getElementById('contenitore').style.height = altezza + 'px';
//		d.getElementById('icp').style.position = "absolute";
//		d.getElementById('icp').style.top = (altezza - 125) + "px";
	}

}
onload = function() { layout(); }
if (!_IE7) {
	onresize = function() { layout(); }
}

function abilita(action, id) {
	if (d.getElementById(id)) {
		if (d.getElementById(action).checked == true || d.getElementById(action).selected == true) {
			d.getElementById(id).disabled = false;
			d.getElementById(id).focus();
		} else {
			d.getElementById(id).value = "";
			d.getElementById(id).disabled = true;
		}
	}
}

function checkCampi() {
	if (!d.getElementById('titlemr') || d.getElementById('titlemr').value == "" || !d.getElementById('titlemrs') || d.getElementById('titlemrs').value == "" || !d.getElementById('titlemiss') || d.getElementById('titlemiss').value == "") {
		alert("The field 'Title' is neccessary.");
		d.getElementById('titlemr').focus();
		return false;
	}
	if (!d.getElementById('first_name') || d.getElementById('first_name').value == "") {
		alert("The field 'First name' is neccessary.");
		d.getElementById('first_name').focus();
		return false;
	}
	if (!d.getElementById('surname') || d.getElementById('surname').value == "") {
		alert("The field 'Surname' is neccessary.");
		d.getElementById('surname').focus();
		return false;
	}
	if (!d.getElementById('address') || d.getElementById('address').value == "") {
		alert("The field 'Address' is neccessary.");
		d.getElementById('address').focus();
		return false;
	}
	if (!d.getElementById('zip') || d.getElementById('zip').value == "") {
		alert("The field 'Postal/Zip code' is neccessary.");
		d.getElementById('zip').focus();
		return false;
	}
	if (!d.getElementById('city') || d.getElementById('city').value == "") {
		alert("The field 'City' is neccessary.");
		d.getElementById('city').focus();
		return false;
	}
	if (!d.getElementById('country') || d.getElementById('country').value == "") {
		alert("The field 'Country' is neccessary.");
		d.getElementById('country').focus();
		return false;
	}
	if (!d.getElementById('telephone') || d.getElementById('telephone').value == "") {
		alert("The field 'Telephone/Mobile number' is neccessary.");
		d.getElementById('telephone').focus();
		return false;
	}
	if (!d.getElementById('email') || d.getElementById('email').value == "") {
		alert("The field 'Email' is neccessary.");
		d.getElementById('email').focus();
		return false;
	}
	return true;
}