function dettaglio(url,id)
{
	window.open(url,'dettaglio'+id,'width=750,height=520,scrollbars=yes');
}

function nuovoCv(url,id)
{
	window.open(url,'cv'+id,'width=750,height=600,scrollbars=yes');
}

function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}

function selectAll(field, n){
for(i=1; i<=n; i++){
	  fieldTemp = document.getElementById(field+i);
	  fieldTemp.checked=1;
   }
}

function deselectAll(field, n){
for(i=1; i<=n; i++){
	  fieldTemp = document.getElementById(field+i);
	  fieldTemp.checked=0;
   }
}

function invertSelect(field, n){
for(i=1; i<=n; i++)
  {
		fieldTemp = document.getElementById(field+i);
		if(fieldTemp.checked==0)
		{
			fieldTemp.checked=1;
		}
		else
		{
			fieldTemp.checked=0;
		}
  }
}

function one2two() {
    m1len = m1.length ;
    for ( i=0; i<m1len ; i++){
        if (m1.options[i].selected == true ) {
            m2len = m2.length;
            m2.options[m2len]= new Option(m1.options[i].text,m1.options[i].value);
        }
    }

    for ( i = (m1len -1); i>=0; i--){
        if (m1.options[i].selected == true ) {
            m1.options[i] = null;
        }
    }
}

function two2one() {
    m2len = m2.length ;
        for ( i=0; i<m2len ; i++){
            if (m2.options[i].selected == true ) {
                m1len = m1.length;
                m1.options[m1len]= new Option(m2.options[i].text,m2.options[i].value);
            }
        }
        for ( i=(m2len-1); i>=0; i--) {
            if (m2.options[i].selected == true ) {
                m2.options[i] = null;
            }
        }
}

function moveOptionsUp(selectId) {
 var selectList = document.getElementById(selectId);
 var selectOptions = selectList.getElementsByTagName('option');
 for (var i = 1; i < selectOptions.length; i++) {
  var opt = selectOptions[i];
  if (opt.selected) {
   selectList.removeChild(opt);
   selectList.insertBefore(opt, selectOptions[i - 1]);
     }
    }
}

function moveOptionsDown(selectId) {
 var selectList = document.getElementById(selectId);
 var selectOptions = selectList.getElementsByTagName('option');
 for (var i = selectOptions.length - 2; i >= 0; i--) {
  var opt = selectOptions[i];
  if (opt.selected) {
   var nextOpt = selectOptions[i + 1];
   opt = selectList.removeChild(opt);
   nextOpt = selectList.replaceChild(opt, nextOpt);
   selectList.insertBefore(nextOpt, opt);
     }
    }
}








function in_array(the_needle, the_haystack){
	 //alert(the_haystack.length)
	 // alert(the_haystack)
	 matched = false
	 for(c=0; c<=the_haystack.length; c++){
	 	  if(the_needle == the_haystack[c])
	 	  {
	 	  	matched = true
	 	  }
	 }
   return matched;
} 




$(document).ready(function() {
	renderMenu("");	
	
	
	$("a[rel='shitchTop']").click(function()
	{
		href = ($(this).attr('href'));
		$('#imgTop').css('background-image','url('+href+')');
		$('#imgTop>img').attr('width',650)
		$('#imgTop>img').attr('height',401)
		$('#imgTop>img').fadeOut('normal',function(){$('#imgTop>img').attr('src',href);$('#imgTop>img').fadeIn('fast')})
		return false;
	})
	
	
	$(".boxSquadra .vincitore").click(function()
	{
		id = $(this).attr('id');
		
		if($(this).attr('class')=='vincitore assegnato')
		{

		visibile = $("#"+id+" .preview").css('display');
		if(visibile == 'block'){
		$(".boxSquadra .vincitore").each(function(i)
		{
			idDaChiudere = $(this).attr('id');
			if($("#"+idDaChiudere+" .full").css('display')=='block')
			{
				$("#"+idDaChiudere+" .preview").css('display','block');
				$("#"+idDaChiudere+" .full").css('display','none');
			}
		})
		$("#"+id+" .preview").css('display','none');
		$("#"+id+" .full").css('display','block');}
		else{
		
		$("#"+id+" .full").css('display','none');
		$("#"+id+" .preview").css('display','block');}
		}
		return false;
	})
	$("a.modal").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'type'	:	'iframe',
		'width'		:	500, 
		'height'		:	250, 
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
  setEcardLink();

$('#menuLeft>ul>li>a').click(function()
{
	id = $(this).attr('id');
	menuDiv = $("#"+id).next();
	visible = $(menuDiv).css('display');
	//menuDiv.slideToggle();
	if(visible=='none')
	{
	  $("#menuLeft div[class^='menu']").slideUp();
	  menuDiv.slideDown();
	return false;
	}
	else if(visible=='block')
	{
	  menuDiv.slideUp();
	return false;
	}

	return false;
});
	
})


function setEcardLink()
{
	$("a.modalEcard").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'type'	:	'iframe',
		'width'		:	806, 
		'height'		:	550, 
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
}

function renderMenu() {
   $("#menuLeft>ul>li>a").each(function(i) {
      var item_title  = $(this).text();
      if (item_title != '') {
       	      
  	      
          var item_label  = escape($(this).text());
          var item_id     = $(this).attr('id');
          var status      = $(this).attr('class');
          var width       = 206;//$(this).attr('width');
          var height      = 28;//$(this).attr('height');
          var img_tag = "<img id=\""+item_id+"_test\" src=\""+wwwRoot+"/"+wwwLang+"/img/menu/"+item_id+".png\" width=\""+width+"\" height=\""+height+"\" alt=\""+item_title+"\" border=\"0\"/>";
					//img_tag = '';
          //alert(img_tag)
          $(this).text("");
			   	$(this).html(img_tag);


   	      //var img_tag = "<img id=\""+item_id+"\" src=\""+wwwRoot+"/comuni/img/menu/"+item_id+"_"+status+".png\" "+calcolaDimensioni(wwwRoot+"/comuni/img/menu/"+item_id+"_"+status+".png")+" alt=\""+item_title+"\" border=\"0\"/>";
   	      //alert(img_tag)

      }
   });
   //if ($.browser.msie) { $(".png").ifixpng(); }
}



function renderTitles(parentObj) {
   $(parentObj+" h1:not(.alt),"+parentObj+" h2:not(.alt),h3:not(.alt)").each(function(i) {
      var item_title  = $(this).text();
      
      if (item_title != '') {
      
   	   var alternativeStyle  = $(this).attr("class");
   	   if(alternativeStyle){
   	     var item_level  = alternativeStyle;
   	   }
   	   else {
   	     var item_level  = this.tagName;
   	   }
   	      
  	      
          var item_label  = escape($(this).text());
   	      var item_width  = $(this).css("width");
   	      if (item_level == 'H1') {
   	         var item_height= '21px';
   	      }
   	      else if (item_level == 'H2') {
   	         var item_height= '21px';
   	      }
   	      else if (item_level == 'H3') {
   	         var item_height= '10px';
   	      }
   	      
   	      //var item_height  = $(this).css("height");
   	      var item_id     = item_level+"_"+i;
   	      //alert(item_width+" || "+item_height);
   	      var img_tag = "<img id=\""+item_id+"\" style=\"/*width:"+item_width+";height:"+item_height+"*/\" src=\""+wwwRoot+"/dynamic/img/titles/"+item_level+"/"+item_width+"/"+item_label+".gif\" alt=\""+item_title+"\" border=\"0\"/>";
   	      
   	      $(this).text("");
   	      $(this).html(img_tag);
      }
   });
   //if ($.browser.msie) { $(".png").ifixpng(); }
}

function renderMenu2Liv() {
   $(".menuLiv2 a").each(function(i) {
      var item_title  = $(this).text();
      if (item_title != '') {
   
   	      
  	      
          var item_label  = escape($(this).text());
          var item_status  = $(this).attr('class');
          //alert(item_status)
   	      //var item_id     = item_level+"_"+i;
   	      var img_tag = "<img style=\"\" src=\""+wwwRoot+"/dynamic/img/titles/liv2_"+item_status+"/166px/"+item_label+".png\" alt=\""+item_title+"\" border=\"0\"/>";
   	      
   	      $(this).text("");
   	      $(this).html(img_tag);
      }
   });
   //if ($.browser.msie) { $(".png").ifixpng(); }
}

function stampaImmagine(item_id,status,item_title)
{
	//global wwwRoot;
 $.ajax({
   type: "GET",
   url: wwwRoot+'/ajax/calcolaDimensioni.php?img='+wwwRoot+"/comuni/img/menu/"+item_id+"_"+status+".png",
   success: function(msg){
     return ("<img id=\""+item_id+"\" src=\""+wwwRoot+"/comuni/img/menu/"+item_id+"_"+status+".png\" "+msg+" alt=\""+item_title+"\" border=\"0\"/>");

   }
 });
}


function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
}



function fbs_click(u,t) {window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer', 'toolbar=0, status=0, width=626, height=436'); return false; } 
