/*
--------------------------------------------------------------------------------
Feinar WebSite Javascript functions

Author:   	altera e-business solutions
Version:  	July 2006
----------------------------------------------------------------------------- */


function toggle(e) {
    if (document.getElementById) {
        if (document.getElementById(e).style.display == 'none')
           document.getElementById(e).style.display = 'block';
        else
          document.getElementById(e).style.display = 'none';
    }
}

function resistenza() {
    toggle('resistenza');
}

function slucano() {
    toggle('slucano');
}

function organico() {
    toggle('orgtable');
}

serviziOff = new Image();

function preload_servizi() {
    if (document.images) {
        pagheOn = new Image(); pagheOn.src = "img/servizi_paghe_selected.jpg";
        pagheClick = new Image(); pagheClick.src = "img/servizi_paghe_clicked.jpg";
        contabilitaOn = new Image(); contabilitaOn.src = "img/servizi_contabilita_selected.jpg";
        contabilitaClick = new Image(); contabilitaClick.src = "img/servizi_contabilita_clicked.jpg";
        sistemiOn = new Image(); sistemiOn.src = "img/servizi_sistemi_selected.jpg";
        sistemiClick = new Image(); sistemiClick.src = "img/servizi_sistemi_clicked.jpg";
        onlineOn = new Image(); onlineOn.src = "img/servizi_online_selected.jpg";
        onlineClick = new Image(); onlineClick.src = "img/servizi_online_clicked.jpg";
    }
}

function over_servizi(img) {
    if (document.images && document.getElementById) {
        var map = document.getElementById('servizi_map');
        serviziOff.src = map.src;
        map.src = eval(img + "On.src");
    }
}

function out_servizi() {
    if (document.images && document.getElementById) {
        var map = document.getElementById('servizi_map');
        map.src = serviziOff.src;
    }
}

function click_servizi(img) {
    if (document.images && document.getElementById) {
        var map = document.getElementById('servizi_map');
        map.src = eval(img + "Click.src");
    }
}

function preload_contatti() {
    if (document.images) {
        agordoClick = new Image(); agordoClick.src = "img/map_agordo_clicked.gif";
        alpagoClick = new Image(); alpagoClick.src = "img/map_alpago_clicked.gif";
        bellunoClick = new Image(); bellunoClick.src = "img/map_belluno_clicked.gif";
        cadoreClick = new Image(); cadoreClick.src = "img/map_cadore_clicked.gif";
        caprileClick = new Image(); caprileClick.src = "img/map_caprile_clicked.gif";
        comelicoClick = new Image(); comelicoClick.src = "img/map_comelico_clicked.gif";
        cortinaClick = new Image(); cortinaClick.src = "img/map_cortina_clicked.gif";
        feltreClick = new Image(); feltreClick.src = "img/map_feltre_clicked.gif";
    }
}

function click_contatti(img) {
    if (document.images && document.getElementById) {
        var map = document.getElementById('contatti_map');
        map.src = eval(img + "Click.src");
    }
}

function popup(url) {
    var location = 'popups/' + url;
    var params =    'height=450,' +
                    'width=500,' +
                    'resizable=yes,' +
                    'scrollbars=yes,' +
                    'toolbar=no,' +
                    'menubar=no,' +
                    'location=no,' +
                    'status=no,' +
                    'directories=no';
                                                                                
	var p = window.open(location, 'name', params);
	if (window.focus) { p.focus() }
	return false;
}

function popup2(url) {
    var location = url;
    var params =    'height=450,' +
                    'width=500,' +
                    'resizable=yes,' +
                    'scrollbars=yes,' +
                    'toolbar=no,' +
                    'menubar=no,' +
                    'location=no,' +
                    'status=no,' +
                    'directories=no';

        var p = window.open(location, 'name', params);
        if (window.focus) { p.focus() }
        return false;
}

function demo(url, w, h) {
	var width = (w == null || w == 0) ? 1024 : w;
	var height = (h == null || h == 0) ? 768 : h;

	var location = 'demos/' + url + ".html";
	var params =    'height=' + height + ',' +
                    'width=' + width + ',' +
                    'resizable=no,' +
                    'scrollbars=no,' +
                    'toolbar=no,' +
                    'menubar=no,' +
                    'location=no,' +
                    'status=no,' +
                    'directories=no';
                                                                                
	var p = window.open(location, 'name', params);
	if (window.focus) { p.focus() }
	return false;
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}

function getElementsByClass(node, searchClass, tag) {
	var classElements = new Array();
	var els = node.getElementsByTagName(tag); // use "*" for all elements
	var elsLen = els.length;
	var pattern = new RegExp("\\b"+searchClass+"\\b");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function disableLinks() {
	var links = getElementsByClass(document, 'disabilitato', 'a');
	for (var i=0; i < links.length; i++) {
		links[i].href = window.location.href;
	};
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

addLoadEvent(externalLinks);
addLoadEvent(disableLinks);

