function openNewPopup(url, w, h) {
    var _left = 100;
    var _top = 100;
    var _location = 'no';
    var _directories = 'no';
    var _menubar = 'no';
    var _resizable = 'no';
    var _scrollbars = 'no';
    var _status = 'no';
    var _titlebar = 'no';
    var _toolbar = 'no';
        
    window.popupWindow = window.open(url, '_blank', 'width='+w
        +', height='+h+',left='+_left+', top='+_top+', location='+_location
        +', directories='+_directories+', menubar='+_menubar
        +', resizable='+_resizable+', scrollbars='+_scrollbars
        +', status='+_status+', titlebar='+_titlebar+', toolbar='+_toolbar);
        
    return false;
}
function $(id) {
	if(document.getElementById(id)) {
		return document.getElementById(id);
	}
}

function inverseazaSelectia(name) {
	var checks = document.getElementsByName(name+"[]");
	for(i=0; i<checks.length; i++) {
		if(checks[i].checked) {
			checks[i].checked = false;
		} else {
			checks[i].checked = true;
		}
	}
}
function displayChilds(parent, selected) {
	var c;
	var select_source = $('new_' + parent);
	var select_dest = $('child_' + parent);
	
	if(select_source && select_dest) {
		var child_id = select_source.options[select_source.selectedIndex].value;
		var i = 1;
		select_dest.innerHTML = '';
		o = new Option("-- Selecteaza --", 0);
		select_dest.options[0] = o;
		for(c in child[child_id]) {
			o = new Option(child[child_id][c],c);
			if(selected && selected == c) {
				 o.defaultSelected = true;
			}
			select_dest.options[i] = o;
			i++;
		}
	}
}

function countChars(charId, id, max) {
	var tmp = $(id).value;
	if($(charId) && $(id)) {
		$(charId).innerHTML = max - $(id).value.length;
		if(parseInt($(charId).innerHTML,10) <=0){
			$(id).value = $(id).value.substr(0, max);
			$(charId).innerHTML = 0;
		}
	}
	return false;
}

function preloadImage(img, index) {
	if(!window.img_list) {
		window.img_list = new Array();
	}
	window.img_list[index] = img; 
}

function getPreloadedImage(img, index) {
	if($(img)) {
		$(img).src = window.img_list[index];
	}
}