/*
* $Id: functions.js,v 1.4 2005/04/25 11:37:35 razvan Exp $
*/

function confirmSubmit (msg) {
	var agree=confirm(msg);
	if (agree) {
		return true ;
	} else {
		return false ;
	}
}

function is_empty (str) {
    return str.search("^[ \t\n\r]*$")>-1 ? true : false;
}

function is_int (str) {
    return str.search("^[0-9]*$")>-1 ? true : false;
}

function validField (str, msg) {
    if ( is_empty(str) ) {
		alert (msg);
		return false;
    }
    return true;
}

function multipleSelect ( arr, f, field ) {

    eval ('var val = document.forms.'+f+'.'+field+'.length');
	for ( j=0 ; j < val ; j++ ) {
	    if ( arr == 'all' ) {
	    	eval ('document.forms.'+f+'.'+field+'[j].selected = true;');
	    } else {
	        eval ('document.forms.'+f+'.'+field+'[j].selected = false;');
	    }
	}
	if ( arr == 'all' ) {
	    return "";
	}

	var b = arr.split (',');
	for ( i=0 ; i < b.length ; i++ ) {
	    for ( j=0 ; j < val ; j++ ) {
	        if ( b[i] == eval ('document.forms.'+f+'.'+field+'[j].value') ) {
	    		eval ('document.forms.'+f+'.'+field+'[j].selected = true');
	        }
	    }
	}
}

function setValue (field, f, val) {
	eval ("document.forms."+f+"."+field+".value='"+val+"'");
}

function getValue (field, f) {
	eval ("var x = document.forms."+f+"."+field+".value");
	return x;
}

function doSubmit ( f ) {
	eval ('document.forms.'+f+'.submit ();');
}

function checkboxAll (field, f, act, s, e) {
	for ( i=s ; i < e ; i++ ) {
	    if ( act == 'c' ) {
	    	eval ('document.forms.'+f+'.'+field+'['+i+'].checked = true;');
	    } else if ( act == 'u' ) {
	    	eval ('document.forms.'+f+'.'+field+'['+i+'].checked = false;');
	    }
	}
}

function inputAll (field, f, val, s, e) {
	for ( i=s ; i < e ; i++ ) {
    	eval ('document.forms.'+f+'.'+field+'['+i+'].value = "'+val+'";');
	}
}

function checkBox (f, field, m) {

	var checkbox = 	eval ('document.forms.'+f+'.'+field);
	var len = checkbox.length;

	var j = 0;
	for ( i=0 ; i < len ; i++ ) {
	    if ( checkbox[i].checked == true ) {
			j++;
			if ( j > m ) {
			    checkbox[i].checked = false;
			    alert ("Nu puteti selecta mai mult de "+m+" optiuni");
			    return false;
			}
	    }
	}
}

function checkCookie () {

var acceptsCookies = false;
if(document.cookie == '') {
    document.cookie = 'acceptsCookies=yes';
    if(document.cookie.indexOf('acceptsCookies=yes') != -1) {
	acceptsCookies = true;
    }
    return acceptsCookies;
} else {
  acceptsCookies = true;
  return acceptsCookies;
}
}


function setCookie (name, value, hours, path, domain, secure) {
    if ( checkCookie () == true ) {
        name = 'b'+name;
	var not_NN2 = (navigator && navigator.appName
		       && (navigator.appName == 'Netscape')
		       && navigator.appVersion
		       && (parseInt(navigator.appVersion) == 2))?false:true;

	if(hours && not_NN2) {
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) {
		var numHours = hours;
	    } else if (typeof(hours) == 'number') {
		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
	}
	document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':'');
    }
}


function getCookie(name) {
    if(document.cookie == '') {
		return false;
    } else {
		var firstChar, lastChar;
		var theBigCookie = document.cookie;
		firstChar = theBigCookie.indexOf(name);
		var NN2Hack = firstChar + name.length;
		if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) {
	    	firstChar += name.length + 1;
	    	lastChar = theBigCookie.indexOf(';', firstChar);
	    	if(lastChar == -1) lastChar = theBigCookie.length;
	    	return unescape(theBigCookie.substring(firstChar, lastChar));
		} else {
	    	return false;
		}
    }
}

function writeToLayer (l, txt) {
	
	if (document.layers) {
		eval ( "var lay = document.layers."+l+"" );
		lay.innerHTML = txt;
	} else if (document.all) {
		eval ( "var lay = document.all."+l+"" );
		lay.innerHTML = txt;
	} else {
		var lay = document.getElementById (l);
		lay.innerHTML = txt;
   	}
}

function getBrowserName () {
	var browserName = navigator.appName;
	if ( browserName.search ('Internet Explorer') != -1  ) {
		return 'Internet Explorer';
	} else if ( browserName.search ('Netscape') != -1 ) {
        return 'Netscape';
	} else if ( browserName.search ('Opera') != -1 ) {
        return 'Opera';
	} else {
		return 'Other';
	}
}

function setVisibility (n, act) {
	if ( getBrowserName () == 'Internet Explorer' ) {
        var selOp = eval ("document.all.div_"+n+"");
	} else {
        var selOp = eval ("document.getElementById ('div_"+n+"');");
	}
	//var selOp = eval ("document.all.div_"+n+"");
	if ( act == 't' ) {
       	selOp.style.display='';
	} else if ( act == 'f' ) {
		selOp.style.display='none';
	}
}

function getVisibility (n) {
	if ( getBrowserName () == 'Internet Explorer' ) {
        var selOp = eval ("document.all.div_"+n+"");
	} else {
        var selOp = eval ("document.getElementById ('div_"+n+"');");
	}

    return selOp.style.display;
}


function toNumber ( nr ) {
	return parseFloat ( nr );
}

function addToField (f, field, val) {
    var fField = eval ('document.forms.'+f+'.'+field);
    fField.value += val;
}

function toWindow (f, e, v) {
	eval ("window.opener.document."+f+"."+e+".value += '"+v+"'");
}

function changeColor ( t, c ) {
	var v = getElementById (t);
	t.style = "color: "+c;
}
















var ie = document.all ? 1 : 0
var ns = document.layers ? 1 : 0

if(ns){doc = "document."; sty = ""}
if(ie){doc = "document.all."; sty = ".style"}



var initialize = 0
var Ex, Ey, topColor, subColor, ContentInfo


if(ie){
Ex = "event.x"
Ey = "event.y"

topColor = "#003399"
subColor = "#CCCCCC"
}


if(ns){
Ex = "e.pageX"
Ey = "e.pageY"
window.captureEvents(Event.MOUSEMOVE)
window.onmousemove=overhere

topColor = "#003399"
subColor = "#CCCCCC"
}



function MoveToolTip(layerName, FromTop, FromLeft, e){
if(ie){eval(doc + layerName + sty + ".top = "  + (eval(FromTop) + document.body.scrollTop))}
if(ns){eval(doc + layerName + sty + ".top = "  +  eval(FromTop))}
eval(doc + layerName + sty + ".left = " + (eval(FromLeft) + 15))
}






function ReplaceContent(layerName){

if(ie){document.all[layerName].innerHTML = ContentInfo}


if(ns){

with(document.layers[layerName].document)
{
   open();
   write(ContentInfo);
   close();
}

}


}



function Activate(){initialize=1}
function deActivate(){initialize=0}


function overhere(e){
if(initialize){

MoveToolTip("ToolTip", Ey, Ex, e)
eval(doc + "ToolTip" + sty + ".visibility = 'visible'")
}

else{
MoveToolTip("ToolTip", 0, 0)
eval(doc + "ToolTip" + sty + ".visibility = 'hidden'")
}


}










function EnterContent(layerName, TTitle, TContent){

ContentInfo = '<table border="0" width="150" cellspacing="0" cellpadding="0">'+
'<tr><td width="100%" bgcolor="#000000">'+

'<table border="0" width="100%" cellspacing="1" cellpadding="0">'+
'<tr><td width="100%" bgcolor='+topColor+'>'+

'<table border="0" width="90%" cellspacing="0" cellpadding="0" align="center">'+
'<tr><td width="100%">'+

'<font class="tooltiptitle">&nbsp;'+TTitle+'</font>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+

'<tr><td width="100%" bgcolor='+subColor+'>'+

'<table border="0" width="90%" cellpadding="0" cellspacing="1" align="center">'+

'<tr><td width="100%">'+

'<font class="tooltipcontent">'+TContent+'</font>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table>';


ReplaceContent(layerName)

}function EnterContentBUC(layerName, TTitle, TContent, TTitle2, TContent2, TTitle3, TContent3, TTitle4, TContent4){

ContentInfo = '<table border="0" width="200" cellspacing="0" cellpadding="0">'+
'<tr><td width="100%" bgcolor="#000000">'+

'<table border="0" width="100%" cellspacing="1" cellpadding="0">'+
'<tr><td width="100%" bgcolor='+topColor+'>'+

'<table border="0" width="90%" cellspacing="0" cellpadding="0" align="center">'+
'<tr><td width="100%">'+

'<font class="tooltiptitle">&nbsp;'+TTitle+'</font>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+

'<tr><td width="100%" bgcolor='+subColor+'>'+

'<table border="0" width="90%" cellpadding="0" cellspacing="1" align="center">'+

'<tr><td width="100%">'+

'<font class="tooltipcontent">'+TContent+'</font>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table><table border="0" width="200" cellspacing="0" cellpadding="0">'+
'<tr><td width="100%" bgcolor="#000000">'+

'<table border="0" width="100%" cellspacing="1" cellpadding="0">'+
'<tr><td width="100%" bgcolor='+topColor+'>'+

'<table border="0" width="90%" cellspacing="0" cellpadding="0" align="center">'+
'<tr><td width="100%">'+

'<font class="tooltiptitle">&nbsp;'+TTitle2+'</font>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+

'<tr><td width="100%" bgcolor='+subColor+'>'+

'<table border="0" width="90%" cellpadding="0" cellspacing="1" align="center">'+

'<tr><td width="100%">'+

'<font class="tooltipcontent">'+TContent2+'</font>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table><table border="0" width="200" cellspacing="0" cellpadding="0">'+
'<tr><td width="100%" bgcolor="#000000">'+

'<table border="0" width="100%" cellspacing="1" cellpadding="0">'+
'<tr><td width="100%" bgcolor='+topColor+'>'+

'<table border="0" width="90%" cellspacing="0" cellpadding="0" align="center">'+
'<tr><td width="100%">'+

'<font class="tooltiptitle">&nbsp;'+TTitle3+'</font>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+

'<tr><td width="100%" bgcolor='+subColor+'>'+

'<table border="0" width="90%" cellpadding="0" cellspacing="1" align="center">'+

'<tr><td width="100%">'+

'<font class="tooltipcontent">'+TContent3+'</font>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table><table border="0" width="200" cellspacing="0" cellpadding="0">'+
'<tr><td width="100%" bgcolor="#000000">'+

'<table border="0" width="100%" cellspacing="1" cellpadding="0">'+
'<tr><td width="100%" bgcolor='+topColor+'>'+

'<table border="0" width="90%" cellspacing="0" cellpadding="0" align="center">'+
'<tr><td width="100%">'+

'<font class="tooltiptitle">&nbsp;'+TTitle4+'</font>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+

'<tr><td width="100%" bgcolor='+subColor+'>'+

'<table border="0" width="90%" cellpadding="0" cellspacing="1" align="center">'+

'<tr><td width="100%">'+

'<font class="tooltipcontent">'+TContent4+'</font>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table>'+

'</td></tr>'+
'</table>';


ReplaceContent(layerName)

}


function doOpenPopup (url, wid, hei, n) {
	if ( n == "") {
		n = "popup_url";
	}
    var w = (window.screen.width-wid)/2;
	var h = (window.screen.height-hei)/2;
	window.open(url, n, 'scrollbars=yes,resizable=no,menubar=no,statusbar=no,toolbar=no, width='+wid+', height='+hei+', left='+w+',top='+h+',screenX='+w+',screenY='+h+' ');
}

function doOpenPopup2 (url, wid, hei, n) {
	if ( n == "") {
		n = "popup_url";
	}
    var w = (window.screen.width-wid)/2;
	var h = (window.screen.height-hei)/2;
	window.open(url, n, 'scrollbars=yes,resizable=yes,menubar=no,statusbar=no,toolbar=no, width='+wid+', height='+hei+', left='+w+',top='+h+',screenX='+w+',screenY='+h+' ');
}

function doOpenPopup3 (url, wid, hei, n) {
	if ( n == "") {
		n = "popup_url";
	}
    var w = (window.screen.width-wid)/2;
	var h = (window.screen.height-hei)/2;
	window.open(url, n, 'scrollbars=no,resizable=no,menubar=no,statusbar=no,toolbar=no, width='+wid+', height='+hei+', left='+w+',top='+h+',screenX='+w+',screenY='+h+' ');
}