//--------------------------------------------------------------------
// THE DEBUGGER
function debug(x){
	document.getElementById('debug').innerHTML = x+"<br>"+document.getElementById('debug').innerHTML;
}
//--------------------------------------------------------------------
// use to have a cursor change on href
function func(){}
//--------------------------------------------------------------------
// simply reload the page.
function reload_page(){
	document.location = document.location.href;
}
//--------------------------------------------------------------------
// simply go to the desired page.
function go2page(page){
	document.location = page;
}
//--------------------------------------------------------------------
// simply return true or false if the var (send as STRING) is set or not.
function isset(varname){
	if(typeof( window[ varname ] ) != 'undefined'){
		return true;
	}else{
		return false;
	}
}
//--------------------------------------------------------------------
// cursor = pointer
function cursor_in(o){
	o.style.cursor = 'pointer';
}
//--------------------------------------------------------------------
// cursor = auto
function cursor_out(o){
	o.style.cursor = 'auto';
}

//--------------------------------------------------------------------
// emule the php trim function
function trim(str){
	return str.replace(/^\s+|\s+$/g, '') ;
}

//--------------------------------------------------------------------
/*
display_popup()
PURPOSE 		:	open the popup above everything
CALLER			:	
VAR					:	openclose = 'open' / 'close'

HOW TO			:	
	the div = <div id="popup"></div>
						<div id="popup_mask"></div>
						In "popup" we  will put what will be displayed.
						"popup_mask" is the dark area.
	the css = 
	#popup{
	height:0px;
	width:100%;
	position:absolute;
	z-index:101;
	}
	#popup_mask{
	height:0%;
	width:100%;
	position:absolute;
	z-index:100;
	background:#000;
	opacity:0.8;
	filter:alpha(opacity=80);
	}
*/
function display_popup(openclose){
	
	if (openclose=="open"){
		var h = document.body.scrollHeight+"px";
	}else{
		var h = "0%";
	}
	document.getElementById('popup_mask').style.height = h;
	

	if (openclose=="close"){
		document.getElementById('popup').innerHTML = "";
	}
		
}


function scrollTop (){
	body=document.body
		d=document.documentElement
		if (body && body.scrollTop) return body.scrollTop
		if (d && d.scrollTop) return d.scrollTop
		if (window.pageYOffset) return window.pageYOffset
		return 0
}


function wait_ajax(){
	// nothing for the moment
	
	
	/*
	display_popup('open');
	var popup = document.getElementById('popup');
	popup.innerHTML = "<div style='width:500px; margin:auto; margin-top:300px;'><h1>Veuillez patienter</h1></div>";
	*/
}

// function from rico.
// return a list of all the elements with the desire tag name and class name
document.getElementsByTagAndClassName = function(tagName, className) {
  if ( tagName == null )
     tagName = '*';

  var children = document.getElementsByTagName(tagName) || document.all;
  var elements = new Array();

  if ( className == null )
    return children;

  for (var i = 0; i < children.length; i++) {
    var child = children[i];
    var classNames = child.className.split(' ');
    for (var j = 0; j < classNames.length; j++) {
      if (classNames[j] == className) {
        elements.push(child);
        break;
      }
    }
  }

  return elements;
}


// change the display css of desired DOM objects
function f_display_list_tab(name, display){
//	alert(display);
	var lt = document.getElementsByTagAndClassName('td',  'list_tab_'+name);
	var display_value;
	if (display){ display_value = 'table-cell'; }else{ display_value = 'none'; }
	for(var x in lt){
		lt[x].style.display=display_value;
	}
	
}

// info on : http://www.quirksmode.org/dom/getElementsByTagNames.html
function getElementsByTagNames(list,obj) {
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++) {
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++) {
			resultArray.push(tags[j]);
		}
	}
	var testNode = resultArray[0];
	if (!testNode) return [];
	if (testNode.sourceIndex) {
		resultArray.sort(function (a,b) {
				return a.sourceIndex - b.sourceIndex;
		});
	}
	else if (testNode.compareDocumentPosition) {
		resultArray.sort(function (a,b) {
				return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
	return resultArray;
}


