function put_content(from, to, mode) {
	for(i=0; i<from.length; i++)
		if(from.options[i].selected==true || mode) {
			opt=new Option(from.options[i].text, from.options[i].value);
			to.options[to.length]=opt;
			from.options[i]=null;
			i--;
		}
}

function get_content(from, to) {
	to.value='';
	for(i=0; i<from.length; i++) {
		if(to.value!='')
			to.value+=' ';
		to.value+=from.options[i].value;
	}
}

function populate(to, arr, sel) {
	to.options.length = 1;
	var is_sel = false;
	for(key in arr) {
		opt = new Option(arr[key]['name'], arr[key]['id']);
		to.options[to.options.length] = opt;
		if (typeof(sel) != 'object') {
			if (sel == arr[key]['id']) {
				is_sel = true;
				to.options[to.options.length-1].selected=true;
			}
		}
		else {
			for (ind in sel)
				if (sel[ind] == arr[key]['id']) {
					is_sel = true;
					to.options[to.options.length-1].selected = true;
				}
		}
	}
	if (!is_sel && !to.multiple) 
		to.options[0].selected=true;
}

function populate_a(to, arr, sel) {
	to.options.length = 0;
	var is_sel = false;
	for (key in arr) {
		if (typeof(arr[key]['name']) == 'undefined')
			continue;
			
		opt = new Option(arr[key]['name'], arr[key]['id']);
		to.options[to.options.length] = opt;
		if (typeof(sel) != 'object') {
			if (sel == arr[key]['id']) {
				is_sel = true;
				to.options[to.options.length-1].selected=true;
			}
		}
		else {
			for (ind in sel)
				if (sel[ind] == arr[key]['id']) {
					is_sel = true;
					to.options[to.options.length-1].selected = true;
				}
		}
	}
	if (!is_sel && !to.multiple && to.options.length)
		to.options[0].selected=true;
}

function openWin(obj, url) {
	if (!openedWin) {
		applyStyle(obj, 'src', url, 0);
		applyStyle(obj, 'visibility', 'visible', 1);
		openedWin = 1;
		offsetHeight = 83;
	}
}

function toggleBranch(container, obj, img, url) {
	var temp = findDOM(container, 1);
	if (temp.visibility == 'hidden') {
		applyStyle(obj, 'src', url, 0);
		applyStyle(container, 'position', 'relative', 1);
		applyStyle(container, 'visibility', 'visible', 1);
		if (img)
			applyStyle(img, 'src', 'images/toggle_branch_on.gif', 0);
	}
	else {
		applyStyle(obj, 'src', '', 0);
		applyStyle(container, 'position', 'absolute', 1);
		applyStyle(container, 'visibility', 'hidden', 1);
		if (img)
			applyStyle(img, 'src', 'images/toggle_branch.gif', 0);
	}
}

/**
* Open popup 
*
* @parameter: page = URL
* @parameter: w = width
* @parameter: h = height
* @parameter: name_popup = ame of popup
* @parameter: scrollbars (default is 0 - without scroll)
*
* @author: FlorinC
* @date creation: 05.05.04
*/
function popup(page, w, h, name_popup, scrollbars) 
{
	if(name_popup == '') name_popup='popup';
	if(scrollbars == '') scrollbars=0;
	if(w==0) w=(screen.width);
	if(h==0) h=(screen.height);
	
	options='menubar=no, scrollbars='+scrollbars+', statusbar=yes, resizable=no, toolbar=no, location=no, status=yes';
	var top=(screen.height-h)/2;
	var left=(screen.width-w)/2;
	var win_open = window.open(page, name_popup, 'top='+top+', left='+left+', width='+w+', height='+h+', '+options);
}


var openedWin = 0;
var offsetHeight = 0;

function check_form(form_name) {
	if (verif_form(form_name))
		eval('document.' + form_name + '.submit()');
}

// excel type edit module support function
var focused = '';
function setFocus(elem) {
	if (focused != '')
		focused.className = 'input_alb';
	if (elem != '')
		elem.className = 'input_focus';
	focused = elem;
}

function button_toggle(id, state, lock) {
	if (sel_button == id)
		return 0;

	if (!lock) {
		if (state) 
			$(id).className = 'button_on';
		else 
			$(id).className = 'button_off';
	}
	else {
		if (typeof($(sel_button + '_tab')) != 'undefined')
			Element.setStyle(sel_button + '_tab', {display: 'none'});
		
		$(sel_button).className = 'button_off';
		sel_button = id;
		
		if (typeof($(sel_button + '_tab')) != 'undefined') {
			Element.setStyle(sel_button + '_tab', {display: 'block'});
			new Effect.ScrollTo(sel_button + '_tab');
		}
	}
}

function showNotify(str) {
	$('notify_text').innerHTML = str;
	Element.setStyle('notify', {top: Math.round((screen.height / 2) - 150) + 'px'});
	Element.setStyle('notify', {left: Math.round((screen.width / 2) - 126) + 'px'});
	location.href = location.href.replace(/#+/, '') + '#';
	Element.setStyle('notify', {display: 'block'});
	new Effect.Highlight('notify', {duration: 3});
	setTimeout('hideNotify()', 4000);
}

function hideNotify() {
	if (Element.getStyle('notify', 'display') != 'none')
		new Effect.Fade('notify', {duration:0.5});
}

function showPopupDiv(url) {
	new Ajax.Updater('tmp_popup_div', url, {asynchronous: true, evalScripts: true});
	if (browser == 'ie')
		Element.setStyle('search_tab', {visibility: 'hidden'});
}

function hidePopupDiv() {
	new Effect.Fade('popup_div', {duration: 0.5});
	Element.setStyle('popup_div_mask', {display: 'none'});
	if (browser == 'ie')
		Element.setStyle('search_tab', {visibility: 'visible'});
	//window.onscroll = function() {};
	//window.onresize = function() {};
}

function scrollPopupDiv() {
	var dimensions = Element.getDimensions('popup_div');
	var top = Math.round(screen.height / 2 - dimensions.height / 2 - 90 + get_Scroll_Y()) + 'px';
	Element.setStyle('popup_div', {top: top});
}

function resizePopupDivMask() {
	var dimensions = Element.getDimensions(document.body);
	Element.setStyle('popup_div_mask', {width: dimensions.width + 'px'});
	Element.setStyle('popup_div_mask', {height: dimensions.height + 'px'});
}

function addToBasket(postBody_) {
	var opt = {
		asynchronous: true,
		postBody: postBody_,
		onSuccess: function() {
			new Ajax.Updater('no_pas_basket', 'index.php?obj=members&action=no_pas_basket', {asynchronous:true});
		}
	}
	
	new Ajax.Request('index.php?obj=members&action=add_panier', opt); 
	hidePopupDiv();
}

function get_Scroll_Y() {
	var sy = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		sy = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		sy = document.body.scrollTop; 
	else if (window.pageYOffset)
		sy = window.pageYOffset;
	else if (window.scrollY)
		sy = window.scrollY;
	return sy;
}

function preloadImages() {
	var imgs = new Array();
	for (var i = 0; i < arguments.length; i++) {
		imgs[i] = new Image();
		imgs[i].src = arguments[i];
	}
}