function var_dump(element, limit, depth)
{
	depth = depth?depth:0;
	limit = limit?limit:1;
	returnString = '<ol>';
	for(property in element)
	{
		//Property domConfig isn't accessable
		if (property != 'domConfig')
		{
			returnString += '<li><strong>'+ property + '</strong> <small>(' + (typeof element[property]) +')</small>';
			if (typeof element[property] == 'number' || typeof element[property] == 'boolean')
				returnString += ' : <em>' + element[property] + '</em>';
			if (typeof element[property] == 'string' && element[property])
				returnString += ': <div style="background:#C9C9C9;border:1px solid black; overflow:auto;"><code>' +
									element[property].replace(/</g, '<').replace(/>/g, '>') + '</code></div>';
			if ((typeof element[property] == 'object') && (depth <limit))
				returnString += var_dump(element[property], limit, (depth + 1));
			returnString += '</li>';
		}
	}
	returnString += '</ol>';
	if(depth == 0)
	{
		winpop = window.open("", "","width=800,height=600,scrollbars,resizable");
		winpop.document.write('<pre>'+returnString+ '</pre>');
		winpop.document.close();
	}
	return returnString;
}



// show hide div content
function show_hide(id)
{
	if (document.getElementById(id))
	{
		if (document.getElementById(id).style.display != 'none')
		{
			document.getElementById(id).style.display = 'none';
		}
		else
		{
			document.getElementById(id).style.display = 'block';
		}
	}
}

function submit_form(id,hidden,value)
{
//---------------------------------------------------------
// Submit basket form (from basket view)
//---------------------------------------------------------
	var form = document.getElementById(id);
	var hidden = document.getElementById(hidden);
	hidden.value = value;
	form.submit();
}

function toggle_select_all(check)
{
//---------------------------------------------------------
// Toggle select/deseelect all checkboxes (from basket view)
//---------------------------------------------------------
	if (check.checked)
	{
		var checks = document.getElementById('BasketContent').getElementsByTagName('input');
		for (i=0; i<checks.length; i++)
		{
			if (checks[i] != check && checks[i].type == 'checkbox')
			{
				checks[i].checked = true;
			}
		}
	}
	else
	{
		var checks = document.getElementById('BasketContent').getElementsByTagName('input');
		for (i=0; i<checks.length; i++)
		{
			if (checks[i] != check && checks[i].type == 'checkbox')
			{
				checks[i].checked = false;
			}
		}
	}
}

function verify_select_all()
{
//---------------------------------------------------------
// Check if all checkboxes (from basket view) are selected
//---------------------------------------------------------
	var checks = document.getElementById('BasketContent').getElementsByTagName('input');
	var j = -1;
	var ok = true;
	for (i=0; i<checks.length; i++)
	{
		if (checks[i].type == 'checkbox' && checks[i].name == 'check_0')
		{
			j = i;
		}
		else 
		{
			if (checks[i].type == 'checkbox' && checks[i].checked == false)
			{
				ok = false;
				break;
			}
		}
	}
	if (j > -1)
	{
		if (ok)
			checks[j].checked = true;
		else
			checks[j].checked = false;
	}
}

function verify_select()
{
//---------------------------------------------------------
// Check if some checkboxes (from basket view) are selected
//---------------------------------------------------------
	var checks = document.getElementById('BasketContent').getElementsByTagName('input');
	var ok = false;
	for (i=0; i<checks.length; i++)
	{
		if (checks[i].type == 'checkbox' && checks[i].name == 'check_0')
		{
			continue;
		}
		else 
		{
			if (checks[i].type == 'checkbox' && checks[i].checked == true)
			{
				ok = true;
				break;
			}
		}
	}
	return ok;
}

function check(id)
{
//---------------------------------------------------------
// Toggle a checkbox
//---------------------------------------------------------
	var checks = document.getElementById('BasketContent').getElementsByTagName('input');
	for (i=0; i<checks.length; i++)
	{
		if (checks[i].type == 'checkbox' && checks[i].name == 'check_0')
		{
			continue;
		}
		else 
		{
			if (checks[i].type == 'checkbox')
			{
				if(checks[i].name == 'check['+id+']')
				{
					if (checks[i].checked)
						checks[i].checked = false;
					else
						checks[i].checked = true;
					verify_select_all();
					break;
				}
			}
		}
	}
}

function select_autosuggest(elem)
{
//---------------------------------------------------------
//	On mouse click on autosuggest element
//		- search for that element
//---------------------------------------------------------	
	if (VAL != '*')
	{	
		document.getElementById('s').value = elem.innerHTML; 
		document.getElementById('search_form').submit();
	}
}

function doNothingClick() {
//---------------------------------------------------------
//	Suppress any actions for on mouse click on page body
//---------------------------------------------------------	
	document.onclick = function () {}
}

function doSomethingClick() {
//---------------------------------------------------------
//	Reactivate actions for on mouse click on page body
//---------------------------------------------------------	
	document.onclick = doOnClickBody;
}

function doOnClickBody(evt) {
//---------------------------------------------------------
//	On mouse click on page body
//		- hide autocomplete search box
//---------------------------------------------------------	
	if (document.getElementById('search_auto'))
		document.getElementById('search_auto').style.display = 'none';
}

function doOnLoadBody() {
//---------------------------------------------------------
//	Default actions on page load
//		- add default actions function for search autocomplete box
//---------------------------------------------------------	
	if (document.getElementById('search_auto'))
		document.getElementById("search_auto").onmouseover = doNothingClick;
	if (document.getElementById('search_auto'))
		document.getElementById("search_auto").onmouseout = doSomethingClick;
}

window.onload = doOnLoadBody;
document.onclick = doOnClickBody;


//-----------------------------------------------------------
// go to link from <tr><td><a></a></td></tr>
//-----------------------------------------------------------
	function goToLink(CurrentRow)
	{
		var form2Children = CurrentRow.childNodes;
		for(var i = 0; i < form2Children.length; i++)
		{
			if(form2Children.item(i).tagName == 'TD')
			{
				var TdChildren = form2Children.item(i).childNodes;
				for(var j = 0; j < TdChildren.length; j++)
				{
					if (TdChildren.item(j).tagName == 'A')
					{
						document.location = TdChildren.item(j).href;
						break;
					}
				}
			}
		}
	}


//---------------------------------------------------------
//
//	URL Encode-Decode
//
//---------------------------------------------------------
function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}


function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}


function implode( glue, pieces ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Waldo Malqui Silva
    // *     example 1: implode(' ', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: 'Kevin van Zonneveld'
 
    return ( ( pieces instanceof Array ) ? pieces.join ( glue ) : pieces );
}