// JavaScript Document
var myhost = window.location.host;
myhost = 'http://'+myhost+'/';
var folderimg = myhost+'images/';
function redimDiv(){
}
function modProperty(subject, caso){
	switch(caso){
		case 1:
			subject.style.borderColor='#f08a00';
			subject.style.cursor='pointer';
			subject.style.textDecoration='underline';
		break;
		case 2:
			subject.style.borderColor='#fff';
			subject.style.cursor='default';
			subject.style.textDecoration='none';
		break;
	}
}
var AnimEnd = false;
var opacity = 0;
var arrayTimer = Array();
var arrayWidth = Array();
arrayWidth['b_home'] = 64;
arrayWidth['b_home_ov'] = 76;
arrayWidth['b_company'] = 95;
arrayWidth['b_company_ov'] = 123;
arrayWidth['b_products'] = 103;
arrayWidth['b_products_ov'] = 132;
arrayWidth['b_clients'] = 87;
arrayWidth['b_clients_ov'] = 107;
arrayWidth['b_resources'] = 113;
arrayWidth['b_resources_ov'] = 146;
arrayWidth['b_contacts'] = 100;
arrayWidth['b_contacts_ov'] = 139;
arrayWidth['b_company_ita'] = 95;
arrayWidth['b_company_ita_ov'] = 123;
arrayWidth['b_products_ita'] = 88;
arrayWidth['b_products_ita_ov'] = 112;
arrayWidth['b_clients_ita'] = 87;
arrayWidth['b_clients_ita_ov'] = 107;
arrayWidth['b_resources_ita'] = 113;
arrayWidth['b_resources_ita_ov'] = 146;
arrayWidth['b_contacts_ita'] = 100;
arrayWidth['b_contacts_ita_ov'] = 139;
arrayWidth['b_map_ita'] = 100;
arrayWidth['b_map_ita_ov'] = 130;
arrayWidth['b_map'] = 100;
arrayWidth['b_map_ov'] = 130;
function resizeMenu(width, height){
	document.images['loading'].style.display = "none";
	document.images['aftImg'].style.display = "block";
	document.images['aftImg'].style.visibility = "hidden";
	IntervalDim = setInterval('setDim(\''+width+'\', \''+height+'\' )', 10);	
}
valore1 =0;
function setDim(larg, alt){
	//document.getElementById('messaggio').innerHTML= valore1;
		valore1++;
	div = document.getElementById('attesa');
	largDiv = parseInt(getStyle(div, "width"));
	AltDiv = parseInt(getStyle(div, "height"));	
	if(largDiv < larg-10){
		increaseWidth(10, 'attesa', 'width', 1);
		increaseWidth(10, 'contBord', 'width', 1);
	} else if(largDiv >= larg-10){
		if(largDiv < larg || largDiv < larg){
			increaseWidth(larg, 'attesa', 'width', 2);
			BordWidth = parseInt(larg)+70;
			increaseWidth(BordWidth, 'contBord', 'width', 2);
		}		
		if(AltDiv < alt-10){
			increaseWidth(10, 'attesa', 'height', 1);
			increaseWidth(10, 'prev_img', 'height', 1);
			increaseWidth(10, 'next_img', 'height', 1);
		} else if(AltDiv >= alt-10){
			increaseWidth(alt, 'attesa', 'height', 2);
			increaseWidth(alt, 'prev_img', 'height', 2);
			increaseWidth(alt, 'next_img', 'height', 2);
			marginAlt = (parseInt(alt)/2)-13;
			if(document.images['p_arrow_single']){
				document.images['p_arrow_single'].style.marginTop = marginAlt+'px';
			}
			if(document.images['p_arrow_single_inv']){
				document.images['p_arrow_single_inv'].style.marginTop = marginAlt+'px';
			}
			if(AltDiv == alt){
				clearInterval(IntervalDim);
				IntervalShow = setInterval('fadeInAft()', 10);
			}
		}
	}
}
var valore = 0;
function fadeInAft(){
	img = document.images['aftImg'];
	if(opacity <100){
		setOpacity(img, opacity);
		img.style.display = "block";
		img.style.visibility = "visible";
		opacity = opacity+10;
	} else {
		//document.getElementById('messaggio').innerHTML= valore;
		valore++;
		opacity = 0;
		AnimEnd = true;
		if(document.images['b_before']){
			document.images['b_before'].style.display = 'block';
		} else if(document.images['b_before_ita']) {
			document.images['b_before_ita'].style.display = 'block';
		}
		if(document.images['p_arrow_single']){
			document.images['p_arrow_single'].style.visibility = "visible";
		} 
		if(document.images['p_arrow_single_inv']) {
			document.images['p_arrow_single_inv'].style.visibility = 'visible';
		}
		clearInterval(IntervalShow);
	}

}
function setOpacity(obj,opacityx){
	//document.getElementById('report').innerHTML = contato;
	//contato++;
	opacityx=(opacityx==100) ? 99.999 : opacityx;
	obj.style.filter = "alpha(opacity:"+opacityx+")";  // IE/Win
	obj.style.KHTMLOpacity = opacityx/100; // Safari<1.2, Konqueror
	obj.style.MozOpacity = opacityx/100;   // Older Mozilla and Firefox
	obj.style.opacity = opacityx/100;      // Safari 1.2, newer Firefox and Mozilla, CSS3
}
function getStyle(el, style) {
   if(!document.getElementById) return;
   
     var value = el.style[toCamelCase(style)];
   
    if(!value)
        if(document.defaultView)
            value = document.defaultView.
                 getComputedStyle(el, "").getPropertyValue(style);
       
        else if(el.currentStyle)
            value = el.currentStyle[toCamelCase(style)];
     
     return value;
}
function toCamelCase( sInput ) {
    var oStringList = sInput.split('-');
    if(oStringList.length == 1)   
        return oStringList[0];
    var ret = sInput.indexOf("-") == 0 ?
       oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
    for(var i = 1, len = oStringList.length; i < len; i++){
        var s = oStringList[i];
        ret += s.charAt(0).toUpperCase() + s.substring(1)
    }
    return ret;
}
function setStyle(objId, style, value) {
    document.getElementById(objId).style[style] = value;
}
function increaseWidth(addToWidth, whichDiv, tipo, caso){
    var theDiv = document.getElementById(whichDiv);
    var currWidth = parseInt(getStyle(theDiv, tipo));
	var newWidth;
	if(caso == 1){
    	newWidth = currWidth + parseInt(addToWidth);
	} else {
		newWidth = addToWidth;
	}
    setStyle(whichDiv, tipo, newWidth + "px");
}
function invertStyle(caso, b_bef){
	
	setTimeout('timeOutStyle('+caso+', \''+b_bef+'\');', 200);
}
function timeOutStyle(caso, b_bef){
	if(AnimEnd){
		simpleRollImg(b_bef);
		switch(caso){
			case 0:
				document.images['befImg'].style.display = "none";
				document.images['aftImg'].style.display = "block";
			break;
			case 1:
				document.images['befImg'].style.display = "block";
				document.images['aftImg'].style.display = "none";
			break;
		}
	} else {
		setTimeout('timeOutStyle('+caso+');', 200);
	}
}
function simpleRollImg(imgName){
	name = imgName.replace(/_ov/i, '');
	//var regExp = RegExp("^([a-zA-Z0-9\._-]+)(_ov)$");
	document.images[name].src = 'images/'+imgName+'.jpg';
}
function simpleRollImgCont(imgName){
	name = imgName.replace(/_ov/i, '');
	//var regExp = RegExp("^([a-zA-Z0-9\._-]+)(_ov)$");
	document.images[name].src = 'immagini/'+imgName+'.jpg';
}
function rollImg(imgName){
	name = imgName.replace(/_ov/i, '');
	var regExp = RegExp("^([a-zA-Z0-9\._-]+)(_ov)$");
 	if (regExp.test(imgName)){
		caso = 1;
	} else {
		caso = 0;
	}
	aniMenu(name, caso);
}
function aniMenu(imgName, caso){
	if(caso==1){
		if(arrayTimer[imgName+'_S']!= null){
			clearInterval(arrayTimer[imgName+'_S']);
			arrayTimer[imgName+'_S']== null;
		}
		//if(arrayTimer[imgName+'_B']== null){
			idName = setInterval('dmImgBig(\''+imgName+'\')', 10);
			arrayTimer[imgName+'_B'] = idName;
		//} else {
		//document.getElementById('messaggio').innerHTML += arrayTimer[imgName+'_B']+' not null<strong>||</strong> ';
		//}
	}
	if(caso == 0){
		if(arrayTimer[imgName+'_B']!= null){
			clearInterval(arrayTimer[imgName+'_B']);
			arrayTimer[imgName+'_B']== null;
		}
		//if(arrayTimer[imgName+'_S']== null){
			idName = setInterval('dmImgSmall(\''+imgName+'\')', 10);
			arrayTimer[imgName+'_S'] = idName;
		//}
	}
}
function dmImgBig(imgName){
	var IM = document.images[imgName];
	var nomeArr = imgName+'_ov';
	var incWidth = arrayWidth[nomeArr]/20;
	//if(caso == 1){
		if(imgName == 'b_resources' || imgName == 'b_resources_ita'){
			alt = 56;
		} else {
			alt = 39;
		}
		if(IM.width < (arrayWidth[nomeArr]-incWidth)){
			IM.width = IM.width+incWidth;
		}
		if(IM.height < (alt-(alt/20))){
			IM.height = IM.height+(alt/20);
		}
		if(IM.width >= (arrayWidth[nomeArr]-incWidth) && IM.height >= (alt-(alt/20))){
			idNameSel = arrayTimer[imgName+'_B'];
			IM.height = alt;
			IM.width = arrayWidth[nomeArr];
			IM.src = folderimg+nomeArr+'.jpg';
			clearInterval(idNameSel);
			arrayTimer[imgName+'_B'] = null;
		}
	//}
}
function dmImgSmall(imgName){
	var IM = document.images[imgName];
	var nomeArr = imgName+'_ov';
	var incWidth = arrayWidth[nomeArr]/20;
	//if(caso == 0){
		if(imgName == 'b_resources' || imgName == 'b_resources_ita'){
			alt = 47;
			o_alt = 56;
		} else {
			alt = 39;
			o_alt = 39;
		}
		if(IM.width > (arrayWidth[imgName]+incWidth)){
			IM.width = IM.width-incWidth;
		}
		if(IM.height > (alt+(o_alt/20))){
			IM.height = IM.height-(o_alt/20);
		}
		if(IM.width <= (arrayWidth[imgName]+incWidth) && IM.height <= (alt+(o_alt/20))){
			idNameSel = arrayTimer[imgName+'_S'];
			IM.height = alt;
			IM.width = arrayWidth[imgName];
			IM.src = folderimg+imgName+'.jpg';
			clearInterval(idNameSel);
			arrayTimer[imgName+'_S'] = null;
		}
	//}
}
function changeColorBr(div, color){
	div.style.borderColor = color;
}
function preloadImages()
{
  if(document.images)
  {
    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;
    
    for(i=0; i<args.length; i++)
    {
      if (args[i].indexOf("#")!=0)
      {
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }
  }
}

function valida(){
	var nome = document.getElementById('nome');
	var cognome = document.getElementById('cognome');
	var email = document.getElementById('email');
	var code = document.getElementById('code');
	var reg_mail = RegExp("^([a-zA-Z0-9\._-]+)(@)([a-zA-Z0-9\.-]+)([\.]{1})([a-z]{2,4})$");
	if(nome.value == "" || cognome.value == "" || email.value == "" || code.value == ""){
		alert("Devi riempire tutti i campi.");
		return false;
	} else {
 		if (reg_mail.test(email.value)){
			return true;
		} else{
			alert("Il formato dell'indirizzo e-mail non è valido");
	        return false;
		}
	}
}

function ShowHideDiv(div){
	var element = document.getElementById(div);
	if(element.style.display == "none"){
		element.style.display = "block";
	} else{
		element.style.display = "none";
	}
}
var oldiv = 'tit_text';//null;
function AlternateShowHideDiv(div){
	var cdiv = document.getElementById(div);
	var odiv = null;
	if(oldiv != null)
	{
		odiv = document.getElementById(oldiv);
	}
	if(cdiv.style.display == "none"){
		cdiv.style.display = "block";
		if(odiv != null && odiv != cdiv)
		{
			odiv.style.display = "none";
		}
	} else{
		cdiv.style.display = "none";
	}
	oldiv = div;
}
function expande_contract(idlink)
{
	var div = document.getElementById('admintool');
	var txtlink = document.getElementById(idlink);
	if(div.className == 'hidemenu')
	{
		div.className = 'showmenu';
		txtlink.innerHTML = '<img src="images/contrai.gif" alt="contrai" title="contrai" />';
		
	} else {
		div.className = 'hidemenu';
		txtlink.innerHTML = '<img src="images/espandi.gif" alt="espandi" title="espandi" />';
	}
}
function pop(w,h,f) {
	var l = Math.floor((screen.width-w)/2);
	var t = Math.floor((screen.height-h)/2);
	window.open(f,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l +",scrollbars=no");
}
function popscroll(w,h,f) {
	var l = Math.floor((screen.width-w)/2);
	var t = Math.floor((screen.height-h)/2);
	window.open(f,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l +",scrollbars=yes");
}