$(document).ready(function()
{
	$('.carLiv1').click(function(){
	  $(this).children('.carLiv2').slideToggle(400);
	  return false;
	})	
    $('#vetrina-hp').flash(
        { 
          src: wwwRoot+'/comuni/swf/vetrina_hp.swf',
          width: 630,
          height: 170,
          wmode : 'opaque',
          flashvars: { basePath: wwwRoot+'/'+wwwLang+'/xml/vetrina-hp.xml'}
        },
        { version: 8 }
    );

})

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;
} 


function renderTitles() {
  
   $(".renderTitle").each(function(i) {
      var item_title      = $(this).text();
      var item_label      = escape($(this).text());
      var item_width      = $(this).css('width');
      var item_fontSize   = $(this).css('font-size');
      var item_lineHeight = $(this).css('line-height');
      var item_color      = $(this).css('color');
      if(!item_color.match('#')){
       var item_color      = rgb2hex($(this).css('color'));
      }
      else
      {
       var item_color      = item_color.replace("#","");
      }
      
      //alert(item_title+"||"+item_width+"||"+item_fontSize+"||"+item_color)
      
      
       item_label = item_label.replace('/','%2F');
      
      if (item_title != '') {
   	      var img_tag = "<img src=\""+wwwRoot+"/dynamic/img/titles/CUSTOM/"+item_width+"/"+item_fontSize+"/"+item_lineHeight+"/"+item_color+"/"+item_label+".png\" alt=\""+item_title+"\" border=\"0\"/>";
   	      $(this).text("");
   	      $(this).html(img_tag);
      }
   });
   //if ($.browser.msie) { $(".png").ifixpng(); }
}


$(document).ready(function() {
	renderMenu("");
	renderTitles();
	
	$("a.modal").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'type'	:	'iframe',
		'width'		:	500, 
		'height'		:	250, 
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});

$('#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 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 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; } 


var hexDigits = new Array
        ("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"); 

//Function to convert hex format to a rgb color
function rgb2hex(rgb) {
 rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
 return hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}

function hex(x) {
  return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
 }



