/*
function setAsHomePage()
{
    var itemObj = gmobj("el" + _itemRef);
    itemObj.style.behavior = "url(#default#homepage)";
    itemObj.setHomepage(location.href);

    //alert("Sorry, your browser does not support this function.");
}
*/ 


function createBookmarkLink() {
    title = document.title;
    url = location.href;
    // Mozilla Firefox
    if (window.sidebar) 
     {  
        window.sidebar.addPanel(title, url, "");
        return;
     }   
    else if( window.external ) { // IE Favorite        
        window.external.AddFavorite( url, title);
        return;
    }
    else if(window.opera && window.print) { // Opera Hotlist
        var mbm = document.createElement('a');
        mbm.setAttribute('rel', 'sidebar');
        mbm.setAttribute('href', url);
        mbm.setAttribute('title', title);
        mbm.click();
        return;
    }
    alert("Sorry, your browser does not support this function.");
}


function getById(idElement) {
    return document.getElementById(idElement);
}


function manageKeyEnter(evt, idElement) {
    evt = (evt) ? evt : event;    
    var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
    
    if (charCode == 13 || charCode == 3) {
        eval(getById(idElement).onclick());
        return false;
    }  
    return true;
}


function openPopUp( url, w, h )
{ 
  var l = Math.floor((screen.width-w)/2);
  var t = Math.floor((screen.height-h)/2);
  popupWindow = window.open( url, null, 'width=' + w + ',height=' + h + ",top=" + t + ",left=" + l + ',status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0' );
  popupWindow.focus();
}

/*
function fnCtr(f) 
{   
 
    var radio  = f.radioSelected; // gruppo di radio button
    var textToSearch = f.textToSearch.value;

    if (radio[0].checked && radio[0].value == "0")
            textToSearch = "site:www.myok.it" + " " + textToSearch;   
    
    f.text.value = textToSearch;

    f.submit();    
}
*/

function checkSelectValue(index) 
{  
    var select0 = document.getElementById('category0');
    var value0 = select0.options[select0.selectedIndex].value;
    
    var select1 = document.getElementById('category1');
    var value1 = select1.options[select1.selectedIndex].value;
    
    var select2 = document.getElementById('category2');
    var value2 = select2.options[select2.selectedIndex].value;
    
    if ( index == 0 ) {   
        if ( ( value0 == value1 || value0 == value2 ) && ( value0 != 0 ) ) {
            alert( "Attenzione: categoria già selezionata!!!" );
            select0.selectedIndex = 0;
        }
    }
    
    if ( index == 1 ) {
        if ( ( value1 == value0 || value1 == value2 ) && ( value1 != 0 ) ) {
            alert( "Attenzione: categoria già selezionata!!!" );
            select1.selectedIndex = 0;
        }
    }
    
    if ( index == 2 ) {
        if ( ( value2 == value0 || value2 == value1 ) && ( value2 != 0 ) ) {
            alert( "Attenzione: categoria già selezionata!!!" );
            select2.selectedIndex = 0;
        }
    }
}

function fnCountChar(textArea) 
{
    var BANNER_CHAR_NUMBER = 600;
    var passed = 0;

    var text = textArea.value;

    if(text.length > BANNER_CHAR_NUMBER) {
        text = text.substring(0,(BANNER_CHAR_NUMBER-1));
        textArea.value = text;
        if(!passed) {
            alert('Per motivi di spazio nel banner sono ammessi al massimo ' + BANNER_CHAR_NUMBER + ' caratteri.');
            passed = 1;
        }
        return false;
    }   
}

function checkGoogleMap( basePath )
{
   var address = document.getElementById('address');
   var valueAddress = address.value;
   var city = document.getElementById('city');
   var valueCity = city.value;
   var province = document.getElementById('province');
   var valueProvince = province.value;
   var nation = document.getElementById('nation');
   var valueNation = nation.value;

   if ( valueAddress == "" || valueCity == "" || valueProvince == "" || valueNation == "" )
    {
      var message = 'Per poter utilizzare il servizio di Google Maps,\nriempire i seguenti campi:\n\n';
      if ( valueAddress == "" )
         message = message + "> INDIRIZZO\n";
      if ( valueCity == "" )
         message = message + "> CITTA'\n";
      if ( valueProvince == "" )
         message = message + "> PROVINCIA\n";
      if ( valueNation == "" )
         message = message + "> NAZIONE";
      alert(message);
      return false;
    }
    else
    {
      var completeAddress = valueAddress+", "+valueCity+", "+valueProvince+", "+valueNation;
      openPopUp( basePath + 'jsp/googleMaps.jsp?address=' + completeAddress,700, 400 );
      return false;
    }
}

function fnSceltaConfirm(id) {
    flag = 'Sei sicuro di voler cancellare il sito?';    
    if ( confirm(flag) ) {
        window.location = '../deleteSite.do?idProposal=' + id;
    }   
}


function retrieveSecondOptions(select,indexCategory) {  
    selectedOption = select.options[select.selectedIndex].value;    
    var url = "../retrieveSecondOptions.do?idFilterValue=" + selectedOption + "&" + "indexCategory=" + indexCategory; 
    SetInnerHTMLFromAjaxResponse( url, "subCategory"+indexCategory);        
}


function openDiv(formToOpen)
{
  document.getElementById(formToOpen).style.display = "block";
}

function closeDiv(formToClose)
{
  document.getElementById(formToClose).style.display = "none";
}