﻿function SetWidth(obj,childClassName){
    var innerDiv = obj.getElementsByTagName('DIV');
    var divCount = 0;
    var innerDivWidth = 0;
    var checkDiv;
    for(var i = 0,checkDiv;checkDiv = innerDiv[i]; i++){
        if(checkDiv.className == childClassName){
            divCount++;
            innerDivWidth = checkDiv.offsetWidth;
        }
    }
    obj.style.width = (innerDivWidth * divCount) + 'px';
}

function init(className,childClassName){
    var divs = document.getElementsByTagName('DIV');
    var checkDiv;
    for(var i = 0,checkDiv;checkDiv = divs[i];i++) if(checkDiv.className == className) SetWidth(checkDiv,childClassName);
}

window.onload = function(){
    init('listaInterventi','intervento');
}

document.getElementsByClassName = function(strClassName){
	
	oElm = this;
	strTagName = "*"
	
	
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
	strClassName = strClassName.replace("[", "\\[");
	strClassName = strClassName.replace("]", "\\]");										  
  	
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for( var i = 0, oElement; oElement = arrElements[i]; i++ ) {		
        if(oRegExp.test(oElement.className)){
			
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)

}

function openStampabile(className){
    var links = document.getElementsByClassName(className);
    var checkLink;
    for( var i = 0,checkLink; checkLink = links[i]; i++){
        if(checkLink){
            checkLink.onclick = function(){
                var winStampa = window.open(this.href, 'Stampa', 'width=700,height=600');
                winStampa.focus();
                return false;
            }
        }
    }
}

/****************************************************************************************/

function popUp(url,name,param) 
{
  var popUp;

  popUp=window.open(url,name,param);
  if (popUp==null) 
  {
    return null;
  }
  else
  {
    popUp.focus();
    return popUp;
  }  
}

function OpenCredits(url, target)
{

  leftVal = (screen.width - 350) / 2;
  topVal = (screen.height - 355) / 2;

  popUp(url, target, "width=350,height=355,left=" + leftVal +
                     ",top=" + topVal + ",scrollbars=no,resizable=no,status=no");
  
  return false;
}

/****************************************************************************************/


function shareSocialNetwork(service) {
    URLDocSP = encodeURIComponent(location.href);
    TITOLODocSP = document.title;
    TITOLODocSP = TITOLODocSP.split("'").join("\'");
    TITOLODocSP = TITOLODocSP.split("\"").join("&quot;");
    TITOLODocSP = encodeURIComponent(TITOLODocSP);

    if (service == "facebook") {
        indirizzoSC = "http://www.facebook.com/share.php?u=__URL__&t=__TITOLO__";
        indirizzoSC = indirizzoSC.split("__URL__").join(URLDocSP);
        indirizzoSC = indirizzoSC.split("__TITOLO__").join(TITOLODocSP);
        window.open(indirizzoSC);
    }
    else if (service == "myspace") {
        indirizzoSC = "http://www.myspace.com/Modules/PostTo/Pages/?l=3&u=__URL__&t=__TITOLO__&c=";
        indirizzoSC = indirizzoSC.split("__URL__").join(URLDocSP);
        indirizzoSC = indirizzoSC.split("__TITOLO__").join(TITOLODocSP);
        window.open(indirizzoSC);
    }
    else if (service == "twitter") {
        indirizzoSC = "http://twitthis.com/twit?url=__URL__&title=__TITOLO__";
        indirizzoSC = indirizzoSC.split("__URL__").join(URLDocSP);
        indirizzoSC = indirizzoSC.split("__TITOLO__").join(TITOLODocSP);
        window.open(indirizzoSC);
    }
}

