function mergi(url)
{
	window.location.href=url;
}

function deschide(url, w, h)
{
	var l=(screen.width-w)/2;
	var t=(screen.height-h)/2;
	window.open(url, '', 'left='+l+', top='+t+', status=yes, scrollbars=no, width='+w+', height='+h);
}

function deschideP(url, w, h)
{
	var l=(screen.width-w)/2;
	var t=(screen.height-h)/2;
	window.open(url, '', 'left='+l+', top='+t+', status=yes, scrollbars=yes, width='+w+', resizable=yes, height='+h);
}

function mark(obj)
{
	var pObj=obj.parentElement.parentElement;
	if(obj.checked)
	{
		pObj.style.backgroundColor="#f2f2f2";
	}
	else
		{
			pObj.style.backgroundColor="#ffffff";
		}

		event.cancelBubble=true;
	}
	function mark2(obj, id)
	{
		var pObj=obj.parentElement.parentElement;
		var aObj=document.all["d"+id];
		if(obj.checked)
		{
			pObj.style.backgroundColor="#f2f2f2";
			for(i=0;i<aObj.length;i++)
			{
				if(aObj[i].cells.length>1)
				{
					aObj[i].style.backgroundColor="#f2f2f2";
					if(aObj[i].cells[aObj[i].cells.length-1].children[0])
					{
						aObj[i].cells[aObj[i].cells.length-1].children[0].checked=true;
						aObj[i].cells[aObj[i].cells.length-1].children[0].disabled=true;
					}
				}
			}
		}
		else
			{
				pObj.style.backgroundColor="#ffffff";
				for(i=0;i<aObj.length;i++)
				{
					if(aObj[i].cells.length>1)
					{
						aObj[i].style.backgroundColor="#ffffff";
						if(aObj[i].cells[aObj[i].cells.length-1].children[0])
						{
							aObj[i].cells[aObj[i].cells.length-1].children[0].checked=false;
							aObj[i].cells[aObj[i].cells.length-1].children[0].disabled=false;
						}
					}
				}
			}
			event.cancelBubble=true;
		}
		function schimba(obj, culoare)
		{
			if(obj.style.backgroundColor!="#f2f2f2")
			obj.style.backgroundColor=culoare;
		}
		function del(obj)
		{
			if(confirm("Sigur vreti sa stergeti aceste inregistrari?"))
			{
				obj.submit();
			}
			else
				{
					return false;
				}
			}
			function delContracte(obj)
			{
				if(confirm("Sigur vreti sa stergeti aceste inregistrari?"))
				{
					if(confirm("Inregistrarile vor fi sterse definitiv!"))
					{
						obj.submit();
					}
					else
						{
							return false;
						}
					}
					else
						{
							return false;
						}
					}
					function expand(id)
					{
						var obj=document.all["d"+id];
						var s=document.all["i"+id];
						for(i=0;i<document.all["d"+id].length;i++)
						{
							if(obj[i].style.display=="none")
							{
								obj[i].style.display="block";
								s.src="../images/sageata_sus.gif";
							}
							else
								{
									obj[i].style.display="none";
									s.src="../images/sageata_jos.gif";
								}
							}
						}
						function cautaContract(tip)
						{
							window.location.href='/contracte/?tipPag='+tip+'&client='+document.getElementById('compania').value+'&piata='+document.getElementById('piata').value;
						}
						var blnk=0;
						function blink()
						{
							obj=document.getElementById("alertcurs");
							if(blnk % 2==0)
							obj.style.color="#ffffff";
							else
								obj.style.color="#4E4E4E";
								blnk++;
								setTimeout("blink()", 500);
							}


							function winOpen(page)
							{
								popupWin=open(page,"popup","status=yes,toolbar=no,directories=no,scrollbars=yes,menubar=no,resizable=yes")
								popupWin.focus()
								return false;
							}

							function bpressed(el,btn)
							{
								el.form.submitted.value=btn;
							}

							function selectplan(el,btn)
							{
								el.form.plan_name.value=btn;
							}


							function copyToList(from,to)
							{


								//fromList = eval(form1 + 'category_1');

								//toList = eval(form1 + to);

								fromList=from;
								toList=to;
								if (toList.options.length > 0 && toList.options[0].value == 'temp')
								{
									toList.options.length = 0;
								}
								var sel = false;
								for (i=0;i<fromList.options.length;i++)
								{
									var current = fromList.options[i];
									if (current.selected)
									{
										sel = true;
										if (current.value == 'temp')
										{
											alert ('You cannot move this text!');
											return;
										}
										txt = current.text;
										val = current.value;
										toList.options[toList.length] = new Option(txt,val);
										fromList.options[i] = null;
										i--;
									}
								}
								if (!sel) alert ('You haven\'t selected any options!');

							}

							function phpPrepareForm(form1)
							{
								for ( i=0; i < form1.length; i++ )
								{
									if (form1.elements[i].type=="select-multiple")
									{
										namebrackets=form1.elements[i].name + "[]";
										form1.elements[i].name=namebrackets;
									}
								}
							}


							function allSelect(select1)
							{
								List = select1;

								for (i=0;i<List.length;i++)
								{
									List.options[i].selected = true;
								}

							}

							function confirmDelete(name)
							{
								return confirm('Are you sure you want to delete category '+unescape(name)+" ?\nDeleting it will also delete all related solutions." );
							}

							function confirmDelete2(name)
							{
								return confirm('Are you sure you want to delete solution '+unescape(name)+" ?" );
							}

							/*
							function setBgColor(element, color) {
							if (element.style.originalBackgroundColor == null) {
							element.style.originalBackgroundColor = element.style.backgroundColor;
							}
							element.style.backgroundColor = color;
							}

							function clearBgColor(element) {
							element.style.backgroundColor = element.style.originalBackgroundColor;
							}

							function setBgImage(element, image) {
							if (element.style.originalBackgroundImage == null) {
							element.style.originalBackgroundImage = element.style.backgroundImage;
							}
							element.style.backgroundImage = 'url("'+image+'")';
							}

							function clearBgImage(element) {
							if (element.style.originalBackgroundImage) {
							element.style.backgroundImage = element.style.originalBackgroundImage;
							}
							else {
							element.style.backgroundImage = 'none';
							}
							}

							function highlight(element) {
							setBgColor(element,'#EBF4FD');
							setBgImage(element, '/alop/images/highlight_bg.gif');
							}

							function clearBg(element) {
							clearBgColor(element);
							clearBgImage(element);
							}
							*/

							function highlight(element)
							{
								if (element.oldClassName == null)
								{
									element.oldClassName = element.className;
								}
								element.className += ' listRowHover';
							}

							function clearBg(element)
							{
								element.className = element.oldClassName;
							}

							function check_on_off(e,idval)
							{
								var elem=document.getElementById(idval);
								var x=elem.getElementsByTagName('input');
								for(var i=0;i<x.length;i++)
								{
									if(x[i].type=='checkbox')
									{
										x[i].checked=e.checked;
									}
								}
							}

							function check_parent(e,idcap,idsubcap)
							{

								if(e.checked==false)
								{
									if(idsubcap!='')
									{
										var check1=document.getElementById('c'+idsubcap);
										check1.checked=false;
									}
									if(idcap!='')
									{
										var check2=document.getElementById('c'+idcap);
										check2.checked=false;
									}
								}
							}

							function hide_show(idval,idimg)
							{
								var obj=document.getElementById(idval);
								var img=document.getElementById(idimg);

								if(obj.style.display=='none')
								{
									obj.style.display='block';
									img.src = 'images/tree_minus.gif';
								}
								else
									{
										obj.style.display='none';
										img.src = 'images/tree_plus.gif';
									}
								}

function validate_field(element, message,rule, rule_parameter)
	{
		var the_value = element.value;
		var result=true;

		

		if ((rule == 'required')|| (rule == 'req')) if(!(the_value > '')) result=false;

		if ((rule == 'regexp') || (rule == 'regex') || (rule == 'ereg')) if(!(((the_value == '') || (the_value.match(rule_parameter))))) result=false;
		if ((rule == 'integer') || (rule == 'int')) if(!(((the_value == '') || (the_value.match('/^[-+]?\d*/'))))) result=false;
		if ((rule == 'float') || (rule == 'real') || (rule == 'decimal')) if(!(the_value.match('/^([-+]?\d*(\.\d+)?)?/'))) result=false;
		if ((rule == 'min'))  if(!(((the_value == '') || (parseFloat(the_value) >= rule_parameter)))) result=false;
		if ((rule == 'min_')) if(!(((the_value == '') || (parseFloat(the_value) > rule_parameter)))) result=false;
		if ((rule == 'max'))  if(!(((the_value == '') || (parseFloat(the_value) <= rule_parameter)))) result=false;
		if ((rule == 'max_')) if(!(((the_value == '') || (parseFloat(the_value) < rule_parameter)))) result=false;
		if ((rule == 'mail') || (rule == 'email')) if(!(the_value.match('/^(\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+)?/'))) result=false;
		if ((rule == 'date_ee'))  if(!(the_value.match('/^((3[01]|[1-9]|0[1-9]|[12]\d)[\/-\\\.]([1-9]|0[1-9]|1[012])[\/-\\\.]\d{4})?/'))) result=false;
		if ((rule == 'date_us'))  if(!(the_value.match('/^(([1-9]|0[1-9]|1[012])[\/-\\\.](3[01]|[1-9]|0[1-9]|[12]\d)[\/-\\\.]\d{4})?/'))) result=false;
		if ((rule == 'date_mysql'))  if(!(the_value.match('/^(\d{4}[-\/\\\.]([1-9]|0[1-9]|1[012])[-\/\\\.](3[01]|[1-9]|0[1-9]|[12]\d))?/'))) result=false;
		if ((rule == 'phone'))  if(!((the_value == '') || the_value.match('/^(\(\+?[0-9 ]{2,}\))?([0-9 ]{4,})/'))) result=false;

		if ((rule == 'equal')) if(!(the_value == rule_parameter)) result=false;

		//if ((rule == 'confirm')) js_rule = "the_value == f.elements['rule_parameter'].value";

		if (result==false)
		{
			alert(message);
			element.focus();
			return false;
		}
		
		return true;
	}

var states = new Array();

function togglePanel(img, panelId, size, action, initialValue) {
	if ( states[panelId] == null ) {
		states[panelId] = parseInt(initialValue, 10);
	}
	
	// state: 0 = este ascuns, 1 = vizibil
	
	var s = parseInt(document.getElementById('leftPanel').style.marginLeft, 10);
	var newSize;
	
	if (action == 'hide') {
		if ( states[panelId] == 1 ) {
			newSize = s-size;
			states[panelId] = 0;
		}
	}
	else if (action == 'show') {
		if ( states[panelId] == 0 ) {
			newSize = s+size;
			states[panelId] = 1;
		}
	}
	else {
		if ( states[panelId] == 0 ) {
			newSize = s+size;
		}
		else {
			newSize = s-size;
		}
		
		// toggle state
		img.state = states[panelId] = 1 - states[panelId];
		
		
		if ( states[panelId] == 0 ) {
			img.src = 'templates/images/panel_show.gif';
		}
		else {
			img.src = 'templates/images/panel_hide.gif';
		}
	}
	
	document.getElementById(panelId).style.marginLeft = newSize+'px';
}

function imageHover(img, panelId, initialValue) {
	if ( img.state == null ) {
		img.state = parseInt(initialValue, 10);
	}
	
	if ( img.state == 0 ) {
		img.src = 'templates/images/panel_show_hover.gif';
	}
	else {
		img.src = 'templates/images/panel_hide_hover.gif';
	}
}

function imageOut(img, panelId, initialValue) {
	if ( img.state == null ) {
		img.state = parseInt(initialValue, 10);
	}
	
	if ( img.state == 0 ) {
		img.src = 'templates/images/panel_show.gif';
	}
	else {
		img.src = 'templates/images/panel_hide.gif';
	}
}

function toggleDetails(caller, divId, imgId) {
	var div = document.getElementById(divId);
	var img = document.getElementById(imgId);
	
	if ( div.style.display == 'none' ) {
		img.src = 'templates/images/more.gif';
		caller.title = 'Ascunde detalii';
		div.style.display = '';
	}
	else {
		img.src = 'templates/images/less.gif';
		caller.title = 'Arata detalii';
		div.style.display = 'none';
	}
}

function toggleFacturiPenalizare( rowId, imgId,noRows) {
	
	var img = document.getElementById('toggle_'+imgId);
	var caller=document.getElementById('button_'+imgId);
	for(i=0;i<noRows;i++)
	{
		//alert(imgId+'_'+i);
		
	var row = document.getElementById(imgId+'_'+i);
	//alert(row);
	if ( row.style.display == 'none' ) {
		img.src = 'templates/images/more.gif';
		caller.title = 'Ascunde facturi penalizare';
		row.style.display = '';
	}
	else {
		img.src = 'templates/images/less.gif';
		caller.title = 'Arata facturii penalizare';
		row.style.display = 'none';
	}
	
	}
}


var dropdowns = new Array();

function toggleDropdown(id) {
	if ( dropdowns[id] == null ) dropdowns[id] = 0;
	
	dropdowns[id] = 1-dropdowns[id]; // toggle state
	
	document.getElementById(id).style.display = dropdowns[id]?'':'none';
}

var currentContextMenu = false;

function showContextMenu(elemId) {
	//if ( elemId == currentContextMenu ) return;
	if ( currentContextMenu ) hideContextMenu(currentContextMenu);
	document.getElementById(elemId).className = 'contextMenuHover';
	currentContextMenu = elemId;
}

function hideContextMenu(elemId) {
	if (! elemId ) return;
	document.getElementById(elemId).className = 'contextMenuHidden';
	currentContextMenu = false;
}

function loading() {
	document.getElementById('loadingPanel').style.display = '';
} 