/**
 * Some usefull tools
 *
 * @author 	Eric Jeker <eric.jeker@virtua.ch>
 * @version	0.1
 * @licence DWYW : Do Whatever You Want
**/

// Return an element by its id
function getById(id)	{
	if (document.getElementById)	{
		return document.getElementById(id) ;
	} else if (document.all)	{
		return document.all[id] ;
	} else	{
		return null ;
	}
}

function getByTag(tag)	{
	if (document.getElementsByTagName)	{
		return document.getElementsByTagName(tag) ;
	} else	{
		return null ;
	}
}

/**
 * get element
 */
function get_element(n)
	{
	if (document.getElementById) { // DOM3 = IE5, NS6
		return document.getElementById(n);
		}
	else if (document.layers) { // Netscape 4
			return document[n];
		}
	else { // IE 4
		return document.getElementById(n);
		}
	}

/**
 * Delete the address
 */
function del(url, warning)
	{
	if(confirm(warning)) {
		location.href= url;
		}
	}

/**
 * impression d'un article
 **/
function print_item(id)
	{
	var e = document.getElementById('printframe');
	e.src = '/detail/print_it?id='+id;
	}


/**
 * Submit with the current value
 */
function submitWithValue(form, name, value)
	{
	o = get_element(name);
	o.value = value;
	f = get_element(form);
	f.submit();
	}

// Open a popup window
function popup(url, h, w)	{
	window.open(url, 'popup', 'alwaysRaised=yes,dependent=yes,toolbar=no,height='+h+',width='+w+',menubar=no,resizable=yes,scrollbars=yes,status=no');
}

// Return the date in the selected format
function getNow(format)	{
	/**
	 * %y = year  (2006)
	 * %m = month (02)
	 * %d = day   (26)
	 * %h = hours	  (21)
	 * %i = minutes (08)
	 * %s = seconds (12)
	**/ 
	
	if (!format)	{
		format = '%h:%i:%s' ;
	}
	
	var now = new Date();
	var y = now.getFullYear();
	var m = now.getMonth();
	var d = now.getDate();
	var h = now.getHours() ;
	var i = now.getMinutes();
	var s = now.getSeconds();
	
	if (parseInt(m) < 10) {
		m = '0'+m;
	}

	if (parseInt(d) < 10) {
		d = '0'+d;
	}

	if (parseInt(h) < 10) {
		h = '0' + h;
	}

	if (parseInt(i) < 10) {
		i = '0'+i;
	}

	if (parseInt(s) < 10) {
		s = '0'+s;
	}
	
	var result = new String(format) ;
	result = result.replace('%y', y) ;
	result = result.replace('%m', m) ;
	result = result.replace('%d', d) ;
	result = result.replace('%h', h) ;
	result = result.replace('%i', i) ;
	result = result.replace('%s', s) ;
	
	return result.toString() ;
}

/**
 * hide a layer
 */
function hidediv(pi_layerName)
	{
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(pi_layerName).style.visibility = 'hidden';
		document.getElementById(pi_layerName).style.position = 'absolute';
		}
	else {
		if (document.layers) { // Netscape 4
			document[pi_layerName].visibility = 'none';
			}
		else { // IE 4
			document.all.pi_layerName.style.visibility = 'hidden';
			document.getElementById(pi_layerName).style.position = 'absolute';
			}
		}
	}

/**
 * show a layer
 */
function showdiv(pi_layerName)
	{
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(pi_layerName).style.position = 'absolute';
		document.getElementById(pi_layerName).style.visibility = 'visible';
		}
	else {
		if (document.layers) { // Netscape 4
			document[pi_layerName].visibility = 'visible';
			}
		else { // IE 4
			document.getElementById(pi_layerName).style.position = 'absolute';
			document.all.pi_layerName.style.visibility = 'visible';
			}
		}
	}

/**
 * change client in contact form
 */
function showhide(div)
	{
	if (document.getElementById) { // DOM3 = IE5, NS6
		var onoff = document.getElementById(div).style.visibility=='visible';
		}
	else {
		if (document.layers) { // Netscape 4
			var onoff = document[div].visibility=='visible';
			}
		else { // IE 4
			var onoff = document.getElementById(div).style.visibility=='visible';
			}
		}

	if(onoff)
		hidediv(div);
	else
		showdiv(div);
	}

function load_flash(flash_url, vars, width, height)
	{
	var flash = '' ;
	flash += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' ;
	flash += '    codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"' ;
	flash += '    width="' + width + '" height="' + height + '" id="PUB" align="middle">' ;
	flash += '    <param name="allowScriptAccess" value="sameDomain" />' ;
	flash += '    <param name="movie" value="' + flash_url + '" />' ;
	flash += '    <param name="flashvars" value="' + vars + '" />' ;
	flash += '    <param name="quality" value="high" />' ;
	flash += '    <param name="wmode" value="transparent"/>' ;
	flash += '    <embed src="' + flash_url + '?' + vars + '"' ;
	flash += '        quality="high" wmode="transparent" width="' + width + '" height="' + height + '" name="PUB" ' ;
	flash += '        align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"' ;
	flash += '        pluginspage="http://www.macromedia.com/go/getflashplayer" />' ;
	flash += '</object>' ;
	document.write(flash) ;
	}

