function TrimString( str ) 
{
  str = str.replace( /^\s+/g, "" );// strip leading
  return str.replace( /\s+$/g, "" );// strip trailing
}
function pageLoad() {
	var page1 = document.all("SearchPage1")
	var page2 = document.all("SearchPage2")
	var page3 = document.all("SearchPage3")
	page1.style.display = "none"
	page2.style.display = ""
	page3.style.display = "none"
}

function searchPage(p) 
{
	var page1 = document.all("SearchPage1")
	var page2 = document.all("SearchPage2")
	var page3 = document.all("SearchPage3")
	
	switch (p) {
		case 1:
			page1.style.display = ""
			page2.style.display = "none"
			page3.style.display = "none"
			break
		case 2:
			page1.style.display = "none"
			page2.style.display = ""
			page3.style.display = "none"
			break
		case 3:
			page1.style.display = "none"
			page2.style.display = "none"
			page3.style.display = ""
			break
	}
}


function CollezionaMaterie()
{
  var collector = new String();
  var s = new String();
  var tags = document.getElementsByTagName( "input" );
  for( i = 0; i < tags.length; i++ )
  {
    s = tags[ i ].id;
    //alert( s.indexOf( "chk_materia_", 0 ) );
    if( s.indexOf( "chk_materia_", 0 ) > -1 )
    {
      //alert( "buono" );
      if( tags[ i ].checked )
      {
        //alert( s + " checked" );
        collector += tags[ i ].value + "|";
      }
      /*else
      {
        alert( s + " not checked" );
      }*/
    }
    else
    {
      //alert( "cattivo");
    }
  }
  
  document.getElementById( "_hidSubjects" ).value = collector;
  //alert( collector );
}

//$itemId_language_id, $itemId, $cssFreeItem, $cssPayItem, $nameContainer
function OnItemClick( id, checkBoxName, nameCheck, cssFreeItems, cssPayItems, hidFreeItemsName, hidSelectedItemsName, nameContainer, freeItemsCount )
{      
  var checkBox = document.getElementById( "_check" + checkBoxName );  
  var hidSelectedItemsName = document.getElementById( hidSelectedItemsName );
  var hidContainer = document.getElementById( nameContainer );
  
  checkBox.className = cssFreeItems;
  if ( checkBox.checked )
  {    
    var selItems = new Number();
    hidContainer.value += "|" + id + "|";
    selItems = hidSelectedItemsName.value - 0;
    selItems++;
    hidSelectedItemsName.value = selItems;           
  }
  else
  {    
    var temp = new String();
    temp = hidContainer.value;
    temp = temp.replace( "|" + id + "|", "" );
    hidContainer.value = temp;
    hidSelectedItemsName.value = hidSelectedItemsName.value - 1;
  }
  
  SetStatus( nameContainer, nameCheck, cssFreeItems, cssPayItems, freeItemsCount );  
  
  
}

function FillHidden( hiddenName, value )
{
  var hidContainer = document.getElementById( hiddenName );
  if ( hidContainer != null )
  {
    hidContainer.value = value;
  }
}

function SetStatus( nameContainer, nameCheck, cssFreeItems, cssPayItems, freeItemsCount )
{
  var hidContainer = document.getElementById( nameContainer );
  var freeItemCount = new Number();
  var temp = new String();
  temp = hidContainer.value;
  temp = temp.replace( "||", "|" );
 
  //alert ( hidContainer );
  var arIds = new Array();
  arIds = temp.split( "|" );  
  freeItemCount = freeItemsCount - 0 + 1;
  //alert ( "freeItemCount = " + freeItemCount );
  //alert( cssFreeItems );
  //alert( cssPayItems );
  for( i = 1; i <= arIds.length; i++ )
  { 
    var n = new Number();   
    n = arIds[ i ];
    //alert ( arIds[ i ] );
    //alert ( n );
    
    if ( n  )
    {
      var spanItemName = "_span" + nameCheck + "_" + arIds[ i ];
      var checkItemName = "_check" + nameCheck + "_" + arIds[ i ];
      var spanItem = document.getElementById( spanItemName );      
      var checkItem = document.getElementById( checkItemName );          
      checkItem.checked = true;
      
      
      //alert( "checkItem = " + checkItem );
      if ( spanItem != null )
      {
        //alert( "i = " + i + " freeItemCount = " + freeItemCount );
        if ( i <= freeItemCount )
        {        
          spanItem.className = cssFreeItems;
        }
        else
        {
          //alert( "set as payItems" );
          spanItem.className = cssPayItems;
        }
      }
    }
  }
  
}

function Colleziona( nameCheck  )
{
  var count = new Number( 0 );
  var collector = new String();
  var s = new String();
  var tags = document.getElementsByTagName( "input" );
  for( i = 0; i < tags.length; i++ )
  {
    s = tags[ i ].id;
    if( s.indexOf( nameCheck, 0 ) > -1 )
    {
      //alert( "buono" );
      if( tags[ i ].checked )
      {
        //alert( s + " checked" );
        collector += tags[ i ].value + "|";
        count++;
      }
      /*else
      {
        alert( s + " not checked" );
      }*/
    }
    else
    {
      //alert( "cattivo");
    }
  }
    
  return count;
}


function HideButton( buttonName )
{
  var but = document.getElementById( buttonName );    
  but.style.display = "none";    
}

function OpenStudioPrint( id_studio )
{
  //window.open( 'stampa.aspx?idfirmoffice=' + id_studio, id_studio + 'id_studio', 'menubar=no,scrollbars=yes,resizable=n,location=no,toolbar=no,width=600,height=500', true );
  window.navigate( 'stampa_studio.aspx?idfirmoffice=' + id_studio );
}

function OpenAdvocatePrint( id_advocate, id_address )
{
  //window.open( 'stampa.aspx?idfirmoffice=' + id_studio, id_studio + 'id_studio', 'menubar=no,scrollbars=yes,resizable=n,location=no,toolbar=no,width=600,height=500', true );
  window.navigate( 'stampa_advocate.aspx?id=' + id_advocate + '&idaddress=' + id_address );
}

function OpenAdvocate( id_studio, id_advocate )
{
  window.open( 'advocate.aspx?idadvocate=' + id_advocate + '&idstudio=' + id_studio, id_advocate + 'advocate', 'menubar=no,scrollbars=yes,resizable=n,location=no,toolbar=no,width=600,height=500', true );
}

function OpenStudio( id_studio )
{
  //window.open( 'studio.aspx?idstudio=' + id_studio, id_studio + 'studio', 'menubar=no,scrollbars=yes,resizable=no,location=no,toolbar=no,width=780,height=700', true );
  window.navigate( 'studio.aspx?idstudio=' + id_studio );
}
function OpenSubscriber( id_subscriber )
{
  window.navigate( 'sottoscritto.aspx?idsubscriber=' + id_subscriber );
}

function OpenSubscriberAdvocate( id_subscriber )
{
  window.navigate( 'subscriber_advocate.aspx?idsubscriber=' + id_subscriber );
}


function AddStudio( id_subscriber )
{
  //window.open( 'studio.aspx?idsubscriber=' + id_subscriber, id_subscriber + 'studio', 'menubar=no,scrollbars=yes,resizable=no,location=no,toolbar=no,width=700,height=600', true );
  window.navigate( 'studio.aspx?idsubscriber=' + id_subscriber );
}

function showRegion( id_region )
{
  if (id_region == 21 )
  {
    window.navigate( 'estero.aspx' );
  }
  else
  {
    window.navigate( 'comuni.aspx?idregione='+id_region );
  }
}

function ViewLogo( idFirmOffice, height, width )
{
  window.open( 'MakeThumbnail.aspx?idfirmoffice=' + idFirmOffice + '&height=' + height + '&width=' + width, idFirmOffice + 'logo', 'menubar=no,scrollbars=no,resizable=no,location=no,toolbar=no,width=' + width + ',height=' + height, true );
}

function OpenConfirm( status )
{
  window.open( 'conferma.aspx?id=' + status, status + 'studio', 'menubar=no,scrollbars=no,resizable=no,location=no,toolbar=no,width=300,height=100', true );
}

function OpenConfirm( status )
{
var iMyWidth;
var iMyHeight;
//half the screen width minus half the new window width (plus 5 pixel borders).
iMyWidth = (window.screen.width/2) - (75 + 10);
//half the screen height minus half the new window height (plus title and status bars).
iMyHeight = (window.screen.height/2) - (100 + 50);
//Open the window.
  var win = window.open( 'conferma.aspx?id=' + status, status + 'studio', "menubar=no,scrollbars=no,resizable=no,location=no,toolbar=no,width=300,height=100,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight, true );
  win.focus();
}

function openPopUpDetails(par,par1,par2){
  var popUpStructure = 'menubar=no,scrollbars=no,resizable=no,location=no,toolbar=no,width='+ par1 +',height=' +par2 ;
  window.open(par,'_details',popUpStructure);
}


