var type = '';

function insertAlert(formName, currentLanguage, errorDiv, aType)
//==============================================================
{
  if( validateForm(formName, currentLanguage, errorDiv) ) {
    type = aType
    postForm("", formName, manageResultAlert); 
    }
  return false;
}

function manageResultAlert(loader)
//================================
{
  var xmlDoc = loader.req.responseXML.documentElement;
	
	var elemOk = xmlDoc.getElementsByTagName("ok");
	if( elemOk &&  elemOk.length > 0 )
	{
    hide(type+'formDiv');
    show(type+'closeDiv');
  }  
}

function resetAlert(aType)
//========================
{

  setRowHidden(document.getElementById(aType+'errorTR'),true);
  show(aType+'formDiv');
  hide(aType+'closeDiv');
  var theForm = document.getElementById('alertForm_'+aType);
  for ( var i=0; i < theForm.elements.length ; i++)
  {
    var field = theForm.elements[i];
    if (field.name != "service" && field.name != "type")
      field.value = '';
  }

}

function getAlerts()
//==================
{
	var form = document.forms['searchAlert'];
	if( form.when.selectedIndex > 0 )		//when is selected clear the date fields
	{
		form.begin_date.value = "";
		form.end_date.value = "";
	}
  postForm("service=getAlerts&", 'searchAlert', fillAlertsArea);
  return false;
}

function fillAlertsArea(loader)
//=============================
{
  fillTableFromAjax(loader, 'objectsTable', 'alert', 'searchMessage', fillTableWithAlerts, managerTable, WARNING_OBJECT_NOT_FOUND);
}

function fillTableWithAlerts(len, elemObj, managerTable, tableId, messageDiv, count)
//====================================================================================
{
  //============= Fill the alerts Data
  for( var i=0; i<len; i++)
  {
    var myRowData = new Array();
    var anElem = elemObj[i];
      
    myRowData.push( getFirstElementValue(anElem , "type") );
    myRowData.push( getFirstElementValue(anElem , "creationDate") );
      
    /*var personName = getFirstElementValue(anElem , "personName");
    if( personName != "" )
      myRowData.push( personName );
    else
      myRowData.push( getFirstElementValue(anElem , "login") );
  */
    myRowData.push( getFirstElementValue(anElem , "email") );
    myRowData.push( getFirstElementValue(anElem , "status") );
    myRowData.push( getFirstElementValue(anElem , "message") );
     
    addRowToSortableTable( managerTable, tableId, 'row_', getFirstElementValue(anElem , "id"), myRowData);
    
    //120 120 188 80 267 (280-13) = 788 - 13
    if( i== 0 )
      setSizeOfTable( 'objectsTable', new Array("120", "200", "258", "60", "285" ), 'px' );
  }
  //If we force row selection the click does not operate 
  //managerTagTable.forceRowSelection( theTableBody.rows[0] );
  if( len > 0 && count != null )
  {
    var mess = "";
    if( count >= countLIMIT )
      mess = INFO_NB_LIMIT_FEMALE;
    document.getElementById(messageDiv).innerHTML = INFO_NB_ALERTS + count + mess;
  }
}

function selectAlert(row, manager)
//================================
{
  manager.redoSelected();		//if we click twice on the same row
	var id = (row.id).split("_")[1];
  //alert('to be done')
  //var requestUrl = "diaporama?service=getSite&id=" + id;
  //executeAjax( requestUrl, fillUEPAndPrescriptionArea);
  //return true;
	//document.location = "/desbons/diaporama?service=initUpdateSite&id=" + id;
}
