window.errorHandler = function(e,url,l) {
  if(!e){
  	try{ e=event }
  	catch(e){ alert(EROARE_JS); return}
  }
  var txt = EROARE_JS_DETALII;
  try {
  	if('string' == typeof(e)) {
  		txt += '\n' + e
  		txt += '\n' + EROARE_LINIA + l
  	} else {
		for(var i in e){
			try{ /* IE7 was blowing up on certain values added this try/catch block to mitigate */
			  var tmp = EROARE;
			  try{ tmp = e[i] } catch(ee){}
			  txt += '\n' + i + ' - ' + tmp;
			} catch(ee){
			  try{
			      txt += '\n' + i;
			  } catch (eee) {txt += '***'}
			}
		}
  	}
  } catch (ee) {}
  alert(txt);
  return true;
}
//window.onerror = window.errorHandler;


function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}


function markRowsInit() {
    // for every table row ...
    var rows = document.getElementsByTagName('tr');
    for ( var i = 0; i < rows.length; i++ ) {
        // ... with the class 'odd' or 'even' ...
        if ( 'isr' != rows[i].className.substr(0,3) ) {
            continue;
        }
		if (rows[i].xLink > '') {
			continue;
		}

//        rows[i].id =
        // ... add event listeners ...
        // ... to highlight the row on mouseover ...
        if ( navigator.appName == 'Microsoft Internet Explorer' ) {
            // but only for IE, other browsers are handled by :hover in css
            rows[i].onmouseover = function() {
                this.className += ' hover';
            }
            rows[i].onmouseout = function() {
                this.className = this.className.replace( ' hover', '' );
            }
        }
        // Do not set click events if not wanted
        if (rows[i].className.search(/noclick/) != -1) {
            continue;
        }

        rows[i].xLink = rows[i].title;
        rows[i].title = '';
        // ... and to mark the row on click ...
        rows[i].onmousedown = function(e) {
        	if (!e) var e = window.event;
        	var trg = 0;
        	//nu lasa click pe input
        	if (e.target) trg = e.target;
        	if (e.srcElement) trg = e.srcElement;
        	if (trg) {
	        	if ('INPUT' == trg.tagName.toUpperCase()) return true;
	        	if ('A' == trg.tagName.toUpperCase()) return false;
	        	if ('SELECT' == trg.tagName.toUpperCase()) return false;
	        	//nu lasa click pe celula care are un input
	        	if ('TD' == trg.tagName.toUpperCase()) {
			        var checkbox = trg.getElementsByTagName('input')[0];
			        if (checkbox) {
			        	checkbox.click();
			        	return false;
			        }
	        	}
        	}
        	if (this.xLink > '') {
		        if (this.xLink.search(/javascript:/) >= 0) {
					eval(this.xLink)
					return false;
		        }
        		var midclick = false;
				if (e.button) midclick = ((!document.all && (e.button == 1)) || (e.button == 4));
				if (midclick) {
					window.open(this.xLink);
					e.cancelBubble = true;
					if (e.stopPropagation) e.stopPropagation();
					return false;
				} else
	        		location.href = this.xLink;
        	}
        }

        var checkbox = rows[i].getElementsByTagName('input')[0];
        if ( checkbox ) {
        	checkbox.xRow = rows[i];
            checkbox.onclick = function(i) {
                if(this.checked)
	                this.xRow.className += ' checked';
	            else
	                this.xRow.className = this.xRow.className.replace( ' checked', '' );
            }
            if(checkbox.checked)
                checkbox.xRow.className += ' checked';
            else
                checkbox.xRow.className = checkbox.xRow.className.replace( ' checked', '' );

        }
    }
}

addLoadEvent(markRowsInit);


var formConfirmations = new Array();
function submitPageForm(elem)
{
	if (elem.value > '') {
		if (formConfirmations[elem.value] > '') {
			if (!confirm(formConfirmations[elem.value])) {
				elem.selectedIndex = 0;
				return false;
			}
		}
		//daca exista in pagina o functie care sa prelucreze cererea, cheama functia
		//functia custom intoarce true daca a prelucrat, altfel se face submit ca si pana acum
		if (typeof(submitPageFormCustomized) != 'undefined') {
			if(submitPageFormCustomized(elem)) {
				elem.selectedIndex = 0;
				return true;
			}
		}

		var form = elem.form;
		if(form.module) {
			var extra = '';
			if(form.id.value) { extra = '/' + form.id.value; }
			location.href = form.module.value + form.action.value + extra;
		} else {
//			alert(form.action)
			elem.form.submit();
		}
	}
	return true;
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function submitForm(formName) {
	var form = document.forms[formName];
	if (form) {
		if(form.onsubmit && !form.onsubmit()) {
			return;
		}
		form.submit();
	}
}


var activeMenuTimeout = 0;
var activeMenu = 0;
function showMenu(elem) {
	if (elem && (elem.className.indexOf('selected') >= 0)) {
		return;
	}
	if (activeMenuTimeout > 0) {
		if (elem == activeMenu) {
			//sunt tot pe meniul curent, pleaca de aici!
			window.clearTimeout(activeMenuTimeout);
			activeMenuTimeout = 0;
		} else {
			//il ascunde pe cel curent
			window.clearTimeout(activeMenuTimeout);
			hideMenu();
		}
	}
	if (elem && (elem.className.indexOf('menuHover') < 0)) {
		activeMenu = elem;
		activeMenu.className += ' menuHover';
//		alert(elem);
	}
}

function hideMenuTimeout(elem) {
	if (elem && (elem.className.indexOf('selected') >= 0)) {
		return;
	}
/*	activeMenu = elem;*/
//	alert(elem.className)
	if (elem && (elem.className.indexOf('menuHover') < 0)) {
		return;
	}
	activeMenuTimeout = window.setTimeout('hideMenu()', 500);
}

function hideMenu(elem) {
	if(!elem) elem = activeMenu;

	if (elem) {
		activeMenu = elem;
		activeMenu.className = activeMenu.className.replace(/menuHover/gi, '');
		activeMenuTimeout = 0;
		activeMenu = 0;
//		alert(elem);
	}
}


