
function switchBorder(box){
	if(box.style.borderColor == 'rgb(170, 170, 170)'){
		box.style.border = "2px solid #FFFFFF";
	}else{
		box.style.border = "2px solid #AAAAAA";
	}

}

function switchCheckBox(idCheckBox){
	var checkBox = document.getElementById(idCheckBox);
	if(checkBox.checked == 1){checkBox.checked = 0;}else{checkBox.checked = 1;}
}

var xhr_object = null;

function communicate(url,values,recieve_function){
	if(window.XMLHttpRequest) xhr_object = new XMLHttpRequest();
	else if (window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	xhr_object.open("POST", url, true);
	xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr_object.setRequestHeader("Content-length", values.length);
	xhr_object.onreadystatechange = recieve_function;
	xhr_object.send(values);
}

function updateListing(page){

	var listing_container = document.getElementById('listing_container');
	listing_container.innerHTML = '<center><img src="images/loading.gif" alt="Chargement..." style="margin:20px;"/></center>';
	
	var tagsQuery = '';
	var j = 1;
	
	while(document.getElementById('tags_' + j)){
	    var i = 1;
	    while(document.getElementById('tag_' + j + '_' + i)){
	      if(document.getElementById('tag_' + j + '_' + i).checked == 1){
        tagsQuery = tagsQuery  + ';' + document.getElementById('tag_' + j + '_' + i).value;
	      }
	      i = i + 1;  
	      }    
        tagsQuery = tagsQuery  + '|';
        j = j + 1;
  }
	
	var optionsQuery = '';
	j = 1;
	while(document.getElementById('attribute_' + j)){
	      if(document.getElementById('attribute_' + j).checked == 1){
		optionsQuery = optionsQuery + ';' + document.getElementById('attribute_' + j).value;
	      }
	      j = j + 1;
	}

	if(page > 0){ pageFilter = '&page=' + page; }else{ pageFilter = ''; }

	var cPath = document.getElementById('cPath').value;
	var urlListing = 'index.php';
	var values = 'tags=' + tagsQuery + '&options=' + optionsQuery + '&ajaxListing=1&cPath=' + cPath + pageFilter;
	
	communicate(urlListing,values,function(){
		 if ( xhr_object.readyState == 4 ){
		 	listing_container.innerHTML = xhr_object.responseText;
		 }
	});
	

}

