// It disables the site putting some opacity over it
// Used in couple with  enable_site()
function disable_site() {
	var opacity_obj = document.getElementById("opacity-layer");
	//opacity_obj.style.zIndex = 100;
	var size = getPageSizeWithScroll();
	var page_height = size[1];
	opacity_obj.style.height = page_height + "px";
	opacity_obj.style.display = "block";
}

// Used in couple with  disable_site()
function enable_site() {
	var opacity_obj = document.getElementById("opacity-layer");
	opacity_obj.style.display = "none";
	//opacity_obj.style.zIndex = 1;
}

function contactme_form() {
        var contactme_form_width = 520;
	disable_site();
	var form = document.getElementById("contactme-form");
	var left_px = (window.screen.width - contactme_form_width) / 2;
	var top_px = 10;
	form.style.top = top_px + "px";
	form.style.left = left_px + "px";	
	form.style.display = "block";
}

function display_lang_confirm() {
        var lang_confirm_width = 350;
	disable_site();
	var lang_confirm_obj = document.getElementById("lang_confirm");
	var left_px = (window.screen.width - lang_confirm_width) / 2;
	var top_px = 100;
	lang_confirm_obj.style.top = top_px + "px";
	lang_confirm_obj.style.left = left_px + "px";	
	lang_confirm_obj.style.display = "block";
}

function show_notification(div_name) {
        var notification_width = 200;
	if (div_name.length > 2) {
		var notification_obj = document.getElementById(div_name);
		var left_px = (window.screen.width - notification_width) / 2;
		var top_px = 100;
		notification_obj.style.top = top_px + "px";
		notification_obj.style.left = left_px + "px";	
		notification_obj.style.display = "block";
	}
}

function close_photo() {
	var viewer = document.getElementById("photo-viewer");
	viewer.innerHTML = "";
	viewer.style.display="none";
	enable_site();
}

function close_form() {
	var form = document.getElementById("contactme-form");
	form.style.display="none";
	enable_site();
}

function close_notify_ok() {
	var notify_ok_obj = document.getElementById("notify_ok");
	notify_ok_obj.style.display="none";
}

function close_lang_confirm() {
	var lang_confirm_obj = document.getElementById("lang_confirm");
	lang_confirm_obj.style.display="none";
	enable_site();
}

function close_notify_error() {
	var notify_error_obj = document.getElementById("notify_error");
	notify_error_obj.style.display="none";		
}

function close_notify_spam() {
	var notify_spam_obj = document.getElementById("notify_spam");
	notify_spam_obj.style.display="none";		
}

function open_notify() {
	var notify_obj = document.getElementById("notify-div");
	notify_obj.style.display="display";
}

// It checks the contact form
function form_check() {
	var email_address = document.getElementById("email");
	var message = document.getElementById("msg");
	var phone_obj = document.getElementById("phone");
	var email_re = new RegExp("^([0-9a-zA-Z])([0-9a-zA-Z\._-]+)@([0-9a-zA-Z\._-]+)\.([0-9a-zA-Z]+)");
	var phone_re = new RegExp("^([0-9+\ ]+)$");
	if (email_address.value == "") {
		alert("Please, insert your email address.");
		email_address.focus();
		return false;
	}
	if (email_re.test(email_address.value) == false) {
		alert("The email address you have inserted seems to be wrong. Please, ckeck it.");
		email_address.focus();
		return false;
	}
	if ( (phone_obj.value != "") && (phone_re.test(phone_obj.value) == false) ) {
		alert("The phone number you have inserted seems to be wrong. Please, ckeck it.");
		phone_obj.focus();
		return false;
	}
	if (message.value == "") {
		alert("Please, insert your message.");
		message.focus();
		return false;
	}
	return true;
}

function getPageSizeWithScroll(){
	var yWithScroll;
	var xWithScrool;
        if (window.innerHeight && window.scrollMaxY) {// Firefox
                yWithScroll = window.innerHeight + window.scrollMaxY;
                xWithScroll = window.innerWidth + window.scrollMaxX;
        } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
                yWithScroll = document.body.scrollHeight;
                xWithScroll = document.body.scrollWidth;
        } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
                var yWithScroll = document.body.offsetHeight;
                var xWithScroll = document.body.offsetWidth;
		var browser_dim = _getBrowserDims();
		if (yWithScroll < browser_dim['height']) { // means there's something wrong
			yWithScroll = 1500 > browser_dim['height'] ? 1500 : yWithScroll + browser_dim['height'];
			xWithScroll = 1500 > browser_dim['width'] ? 1500 :  xWithScroll + browser_dim['width'];
		}
        }
        arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
        // alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
        return arrayPageSizeWithScroll;
}

// helper for getPageSizeWithScroll in the case the browser is IE6
function _getBrowserDims() {
	var intH = 0;
	var intW = 0;
	
	if(typeof window.innerWidth  == 'number' ) {
	
		intH = window.innerHeight;
		intW = window.innerWidth;
	} 
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
	
		intH = document.documentElement.clientHeight;
		intW = document.documentElement.clientWidth;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
	
		intH = document.body.clientHeight;
		intW = document.body.clientWidth;
	}
	return { width: parseInt(intW), height: parseInt(intH) };
}
