function checkContinent(checked, id)
{   
    var nodes = document.getElementById('c'+id).childNodes;
    var temp = '';
    for(var i=0;i<nodes.length;i++)
    {
       nodes[i].childNodes[1].checked = checked;
       if((nodes[i].id!='CMS_division_bar')&&(nodes[i].id!='CMS_country_bar'))
       {
         checkDivision(checked, nodes[i].id);
       }
       
    }
}


// Triggered when mouseover or out countrybar in backend
function overCountry(div, bColor, optionsId, ooo)
{
    div.style.backgroundColor= bColor;
    if(ooo == 'over')
      document.getElementById(optionsId).style.visibility = 'visible';
    else
      document.getElementById(optionsId).style.visibility = 'hidden';
}

function checkDivision(checked, id)
{
    var nodes = document.getElementById(id).childNodes;
    
    for(var i=0;i<nodes.length;i++)
    {
       nodes[i].childNodes[1].checked = checked;
    }

}

function clapContinent(id)
{

	div = document.getElementById('c'+id);
	if(div.style.visibility == 'hidden'){
	  div.style.visibility = 'visible';
	  div.style.position = '';

	}
	else{
	  div.style.position = 'absolute';
	  div.style.visibility = 'hidden';
	}
	
}

function addCountryToContinent(id)
{
    div = document.getElementById('CMS_country_bar_new_country_row_'+id);
	if(div.style.visibility == 'hidden'){
	  div.style.visibility = 'visible';
	  div.style.position = '';
	  document.getElementById('c'+id).style.paddingTop = '25px'; 
	}
	else{
	  div.style.position = 'absolute';
	  div.style.visibility = 'hidden';
	  document.getElementById('c'+id).style.paddingTop = '0px'; 
	}
}

function addDivisionToContinent(id)
{
    div = document.getElementById('CMS_country_bar_new_division_row_'+id);
	if(div.style.visibility == 'hidden'){
	  div.style.visibility = 'visible';
	  div.style.position = '';
	  document.getElementById('c'+id).style.paddingTop = '25px'; 
	}
	else{
	  div.style.position = 'absolute';
	  div.style.visibility = 'hidden';
	  document.getElementById('c'+id).style.paddingTop = '0px'; 
	}
}

function postDivision(id)
{
   input = document.getElementById('CMS_country_bar_new_division_input_'+id);
   name = input.value;
   continent = id;
   division = 0;
   file = 'postDivision.php?';
   file += 'name='+name;
   file += '&continent='+continent;
   dbRequest('postDivision', file, 0, 0,'../');
}


function postCountry(id)
{
   input = document.getElementById('CMS_country_bar_new_country_input_'+id);
   name = input.value;
   continent = id;
   division = 0;
   file = 'postCountry.php?';
   file += 'name='+name;
   file += '&continent='+continent;
   file += '&division='+division;
   dbRequest('postCountry', file, 0, 0,'../');
}

function deleteCountry(name)
{
  file = 'deleteCountry.php?';
  file += 'name='+name;
  dbRequest('deleteCountry', file, 0, 0,'../');
}

function deleteContact(id)
{
  if(confirm('Weet je zeker dat je deze persoon wilt verwijderen?'))
  {
    file = 'deleteContact.php?';
    file += 'id='+id;
    dbRequest('deleteContact', file, 0, 0,'');
  }
}

function getCountryContacts(name)
{
  file = 'getCountryContacts.php?';
  file += 'name='+name;
  dbRequest('getCountryContacts', file, 0, 0,'../');
}

function updateAllContactsList(id)
{
  file = 'updateAllContactsList.php';
  if(id)
    file += '?country_id='+id;
  dbRequest('updateAllContactsList', file, 0, 0,'');
}

function uploadNewContactsOrder()
{
   var newContact = false;
   var list = document.getElementById('countryContactList');
   var nodes = list.childNodes;
   var countryId = document.getElementById('countryId').value;


   for(var i=0;i<nodes.length;i++)
   {
   
      var file = 'updateContactOrder.php';
      var contactId = nodes[i].id.substring(2,nodes[i].id.length);
      file += '?countryId='+countryId;
      file += '&contactId='+contactId;
      file += '&newOrder='+i;
      dbRequest('updateContactOrder',file,0,0,'');
   }
   
}

function upload()
{
window.open("upload.php",null,"height=200,width=400,status=no,toolbar=no,menubar=no,location=no");
}

function removeContactFromCountry(contactId)
{
  var countryId = document.getElementById('countryId').value;
  var file = 'removeContactFromCountry.php';
  file += '?countryId='+countryId;
  file += '&contactId='+contactId;
  dbRequest('removeContactFromCountry',file,0,0,'')
}