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("");
		//renderMenu2Liv()
		//renderTitles("");


})



function renderMenu() {
   $("#menuTop a").each(function(i) {
      var item_title  = $(this).text();
      //alert(item_title+" "+$(this).attr('id'))
      if (item_title != '') {
       	      
  	      
          var item_label  = escape($(this).text());
          var item_id     = $(this).attr('id');
          var status      = $(this).attr('class');
          var width       = $(this).attr('width');
          var height      = $(this).attr('height');
          //alert(height)
          var img_tag = "<img id=\""+item_id+"\" src=\""+wwwRoot+"/"+wwwLang+"/img/menu/"+item_id+"_"+status+".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\"/>");

   }
 });
}
