function openpopupWindow(popupURL, width, height) {
  var w = width;
  var h = height;
  var l = Math.floor((screen.width-w)/2);
  var t = Math.floor((screen.height-h)/2);
  popupWindow = window.open(popupURL,"popupWindowDoc", "scrollbars=no, location=no, toolbar=no, directories=no, status=no, resizable=no, height=" + height + ",width=" + width + ",top=" + t + ",left=" + l);
  popupWindow.focus();
}

function changeClassToManatoryFields(idMandatoryFields, className) {
  
  var form = document.forms[0];
  
  var isChecked = false;
  
  for( var i = 0 ; i < form.chkPhone.length; i = i + 1) 
  {
    if(form.chkPhone[i].checked == true)
    {
      isChecked = true;
    }
  }
  
  
  if(isChecked == true)
  {
    if(idMandatoryFields == 'mandatoryPhone')
    {
      form.telephone.className = className;
      form.cellNumber.className = className;
    }
  }
  else
  {
    form.telephone.className = '';
    form.cellNumber.className = '';
  }
  
  for( var i = 0 ; i < form.chkBrochure.length; i = i + 1) 
  {
    if(form.chkBrochure[i].checked == true) 
    {
      isChecked = true;
    }
  }
  
  
  if(isChecked == true) 
  {
    if(idMandatoryFields == 'mandatoryBrochure')
    {
      form.address.className = className;
      form.cap.className = className;
      form.city.className = className;
      form.state.className = className;
    }
  }
  else 
  {
    form.address.className = '';
    form.cap.className = '';
    form.city.className = '';
    form.state.className = '';
  }    
}

function writeForm(url, objId) 
{
  
  //&filter[2].selectedValue=1&filter[1].selectedValue=25
  var searchForm = document.forms['ProposalFilterFormBean'];
  
  var queryString = '';

  for (var i = 0 ; i < searchForm.elements.length; i = i + 1) 
  {
    if (searchForm.elements[i].type == 'checkbox') 
    {
      if(searchForm.elements[i].checked == true)
      {
        var name = searchForm.elements[i].name;
        var value = searchForm.elements[i].value;
        queryString = queryString+ '&' +  name + '=' + value;
      }
    }
    else
    {
      
      var name = searchForm.elements[i].name;
      var value = searchForm.elements[i].value;
      queryString = queryString + '&' + name + '=' + value;
    }
    
  }
    
  obj = document.getElementById(objId);

  SetInnerHTMLFromAjaxResponse(url+queryString, obj.id);  
}

//'http://www.vacanzesmeralde.it/sites/VACANZE_SMERALDE/fla/vacanzeMappa.swf', 'Seleziona+una+regione', 'IT' 
function writeFlashHomePage()
{
  var xmlGenerated = ''
   
  var searchForm = document.forms['ProposalFilterFormBean'];
  
  for (var i = 0 ; i < searchForm.elements.length; i = i + 1) 
  {
    if(searchForm.elements[i].name == 'filter[1].selectedValue') 
    {
      for(j = 0 ; j < searchForm.elements[i].options.length; j++)
      {

        if(searchForm.elements[i].options[j].value != '*')
        {
          xmlGenerated = xmlGenerated + searchForm.elements[i].options[j].value + '|';
        }
        //var item = lst.options[ldst.selectedIndex].value;
      } 
    }
  }
  
document.write( '<object class="mainFlash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="360" height="300" id="vacanzeMappa" align="middle" viewastext="viewastext">');
  document.write( '<param name="allowScriptAccess" value="sameDomain" />');
  document.write( '<param name="movie" value="movies/italy.swf" />');
  document.write( '<param name="quality" value="high" />');
  document.write( '<param name="bgcolor" value="#f1f4f5" />');
  //document.write( '<param name="FlashVars" value="titlemappa=Seleziona+una+regione&xmlSource=" />');
  document.write( '<param name="wmode" value="transparent" />');
  document.write( '<param name="FlashVars" value="xmlSource='+ xmlGenerated+'\" />');
  document.write( '<embed src="movies/italy.swf" quality="high" bgcolor="#f1f4f5" width="360" height="300" name="Italia" align="middle" allowScriptAccess="sameDomain" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="xmlSource='+ xmlGenerated+'\" />');
  document.write( '</object>');
}

function showHideColumnBox(tl1, idBox1, tl2, idBox2, tl3, idBox3)
{
    titleBox1 = document.getElementById(tl1).className;
    titleBox2 = document.getElementById(tl2).className;
    titleBox3 = document.getElementById(tl3).className;
    box1 = document.getElementById(idBox1).className;
    box2 = document.getElementById(idBox2).className;
    box3 = document.getElementById(idBox3).className;

  if (titleBox1 == 'columnTitle')
  {
    document.getElementById(tl1).className = 'columnTitleOpen';
    document.getElementById(tl2).className = 'columnTitle';
    document.getElementById(tl3).className = 'columnTitle';
    document.getElementById(idBox1).className = 'columnBoxVisible';
    document.getElementById(idBox2).className = 'columnBoxHide';
    document.getElementById(idBox3).className = 'columnBoxHide';
}
  
  if (titleBox1 == 'columnTitleOpen')
  {
    document.getElementById(tl1).className = 'columnTitle';
    document.getElementById(idBox1).className = 'columnBoxHide';
    
  }
}


function isNotValidEmail(elem) {
        var str = elem.value;
        var re  = /\b[a-z0-9._%-]+@[a-z0-9._%-]+\.[a-z0-9._%-]{2,4}\b/;
        if (!str.match(re))
        return false;
        else
        return true;
      }

      function validator()
      {
      var theForm = document.forms[0];
      
      
      if (theForm.telephone.value == "")
      {
      alert('il numero di telefono è obbligatorio');
      theForm.telephone.focus();
      return (false);
      }
      
      if (theForm.email.value == "")
      {
      alert('l\'email è obbligatoria');
      theForm.email.focus();
      return (false);
      }
	
      if (!isNotValidEmail(document.forms[0].elements['email']))
      {
	
      alert("il formato dell'email non è corretto");
      return false;
      }
      document.forms[0].submit();
      return (true);
      }


function showHideContent(s,h)
{
   document.getElementById(s).style.display = 'block';
   document.getElementById(h).style.display = 'none';
}

function proposalListFull()
      {
        alert('<bean:message key="prompt.proposals.limit" />');
      }


function concatAddictionalInfo()
{
  var form = document.forms[0];


  var address = document.getElementById('addressInfo_0').value;
  var cap = document.getElementById('addressInfo_1').value;
  var city = document.getElementById('addressInfo_2').value;
  var province = document.getElementById('addressInfo_3').value;
  var phone = document.getElementById('addressInfo_4').value;
  var fax = document.getElementById('addressInfo_5').value;

  form.addictionalInfo.value = 'indirizzo'+ '|' + address + '|' +
                               'cap'+ '|' + cap + '|' +
                               'citt&agrave;' + '|' + city + '|' +
                               'provincia'+ '|' + province + '|' + 
                               'telefono' + '|' + phone + '|' +
                               'fax'+ '|' + fax+ '|';

}


function showHide(elementId) {
  var el = document.getElementById(elementId);
  if (el.style.display == "none")
    el.style.display = "block";
  else
    el.style.display = "none";
}


function showHideSearchBox( idImg, idBox , base )
  {  
   
   box = document.getElementById( idBox );
   img = document.getElementById( idImg );      
   
   
   if ( box.style.display == 'none')
   {
    box.style.display = 'block';
    img.src = base+'images-mymy/btn_advanced_search_open.gif';
   // document.forms['ProposalFilterFormBean'].advancedSearch.value='true';
   }
   else if (( box.style.display == 'block' ))
   {
    
    box.style.display = 'none';
    img.src = base+'images-mymy/btn_advanced_search_close.gif';
   // document.forms['ProposalFilterFormBean'].advancedSearch.value='false';
   }
   else 
   {
    box.style.display = 'block';
    img.src = base+'images-mymy/btn_advanced_search_open.gif';
    //document.forms['ProposalFilterFormBean'].advancedSearch.value='true';
   }
 }

function showHideCommentBox(idBox)
 {
   box = document.getElementById( idBox );
   
   if ( box.style.display == 'none')
   {
     box.style.display = 'block';
   }
   else if (( box.style.display == 'block' ))
   {
      box.style.display = 'none';
   }
   else 
   {
     box.style.display = 'block';
   }
 }


 function selectPhoto(photo)
 {
      images = document.getElementById('imagesContainer').getElementsByTagName('img');
      for(var i=0; i < images.length; i++)
      {
      images[i].className="";
      }
      photo.className="select";
      document.forms['ProposalFormBean'].imageSelected.value = photo.id;
      //document.forms['ProposalFormBean'].imageSelectedVirtualPath.value = photo.src;
 }

function setFast(fast)
{
   var form = document.forms[3];

   form.fast.value = fast;
   form.submit();

/*
   document.forms['PublisherFormBean'].fast.value = fast;
   document.forms['PublisherFormBean'].submit();
*/
}