
function updateIndustrySelected()
{
   var somethingSelected = false;
   var checkboxes = $('RecommendForm').getElementsByClassName('ind_focus_checkbox');
   for (var i in checkboxes)
   {
     if (checkboxes[i].checked)
     {
       somethingSelected = true;
       break;
     }
   }
   if (somethingSelected)
    $('industrySelected').value = 1;
   else
    $('industrySelected').value = '';
}

function selectOthers(catId,indId)
{
  if ($('suggested_'+catId).value != '')
    $('industry_'+indId).checked = true;
  else $('industry_'+indId).checked = false;
  updateIndustrySelected();
}

function selectAll(catId)
{
  var last = '';
  
  var catsArray = eval('category_'+catId);
  for (var i in catsArray)
  {
    var indId = catsArray[i];
 
    if ($('industry_'+indId))
    {
        $('industry_'+indId).checked = true;
        last = indId;
    }
  }
  $('industry_'+last).checked = false;
 
  updateIndustrySelected();

}

function unselectAll(catId)
{
  var catsArray = eval('category_'+catId);
  for (var i in catsArray)
  {
    var indId = catsArray[i];
    if ($('industry_'+indId))
    {
        $('industry_'+indId).checked = false;
      
    }
  }
 
  updateIndustrySelected();

}

function selectLocation(selectedItem)
{
  if (selectedItem != null && selectedItem.id != 0)
  {
    for( var x = 0; x < selectedItem.attributes.length; x++ ) {
      if( selectedItem.attributes[x].nodeName.toLowerCase() == 'title' ) {
        $('location').value = selectedItem.attributes[x].nodeValue;
      }
    }
    $('city_id').value = selectedItem.id;
  }
  else
  {
    $('city_id').value = 0;
    $('location').value = '';
  }

}



function _NiceList( NameList, max )
{
	this.NameList = NameList;
	this.count = 0;
	this.id = 0;
	if( max ){
		this.max = max;
	} else {
		this.max = -1;
	};

	this.addElement = function( element ){

		if( element.tagName == 'INPUT' && element.type == 'text'){

			this.id++;
			element.name = 'prov_name_' + this.id;
			element.id = 'prov_name_' + this.id;
			element.className = 'prov_name';
			element.multi_selector = this;

			/*element.onchange = function() {

				var new_element = document.createElement( 'input' );
				new_element.type = 'text';
				this.parentNode.insertBefore( new_element, this );
				this.multi_selector.addElement( new_element );
				this.multi_selector.addListRow( this );
				this.style.display = 'none';
				this.value
			};*/
			if( this.max != -1 && this.count >= this.max ){
				element.disabled = true;
			};
			this.count++;
			this.current_element = element;
		}

	}

	this.addListRow = function( element ){

		var new_row = document.createElement( 'li' );

		var new_row_button = document.createElement( 'input' );
		new_row_button.type = 'button';
		new_row_button.value = 'remove';
		new_row_button.className = 'remove';

		new_row.element = element;

		new_row_button.onclick= function(){

			this.parentNode.element.parentNode.removeChild( this.parentNode.element );
			this.parentNode.parentNode.removeChild( this.parentNode );
			this.parentNode.element.multi_selector.count--;
			this.parentNode.element.multi_selector.current_element.disabled = false;
			return false;
		};

		new_row.appendChild( new_row_button );

		var fileNameSpan = document.createElement( 'span' );
		fileNameSpan.innerHTML = element.value;
		new_row.appendChild(fileNameSpan);

		this.NameList.appendChild( new_row );

	}
}

//providers names
function removeProviderName(idProvName)
{
    var oldValue = document.forms['RecommendForm'].removedProvNames.value;
    document.forms['RecommendForm'].removedProvNames.value = oldValue + ', '+ idProvName;
    $('prov_name_'+idProvName).style.display = 'none';
    $('someProviderName').value = $('someProviderName').value - 1;
}

function removeNotSaved(element)
{
	element.parentNode.parentNode.removeChild( element.parentNode );
	$('someProviderName').value = parseInt($('someProviderName').value)-1;
	return false;
}
	
function addProviderName()
{
  if ($('prov_name').value != '')
  {
	var new_element = document.createElement( 'input' );
	new_element.type = 'hidden';
	new_element.id   = 'prov_name_'+counter;
	new_element.name = 'prov_name_'+counter;
    new_element.value = $('prov_name').value;
    $('prov_name').value = '';

    var new_row = document.createElement( 'li' );
    new_row.id = 'prov_name_'+counter;

	var new_row_button = document.createElement( 'input' );
	new_row_button.type = 'button';
	new_row_button.value = 'remove';
	new_row_button.className = 'remove';

	new_row.element = new_element;

	new_row_button.onclick= function(){

		this.parentNode.element.parentNode.removeChild( this.parentNode.element );
		this.parentNode.parentNode.removeChild( this.parentNode );
		$('someProviderName').value = parseInt($('someProviderName').value)-1;
		return false;
	};
	new_row.appendChild( new_row_button );
	var fileNameSpan = document.createElement( 'span' );
	fileNameSpan.innerHTML = new_element.value;
	new_row.appendChild(fileNameSpan);

    new_row.appendChild(new_element);

	$('providers_list').appendChild( new_row );
	
    counter++;

    $('prov_names_number').value = counter;
    $('someProviderName').value = parseInt($('someProviderName').value)+1;
  }
}

function init()
{
    if (document.RecommendForm)
    {
		counter = $('prov_names_number').value;
	}
}

window.onload = init;
