String.prototype.pad = function(l, s, t){
	return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
		+ 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
		+ this + s.substr(0, l - t) : this;
};

function puncte(ko) {

	nr_ko		= '';
	ko		= ko.toString();

	lung_ko		= ko.length;
	moduloko	= lung_ko % 3;

	if (ko.length < 4) nr_ko = ko;
	else if (moduloko == 0) {
		for (i = 0; i < lung_ko - 3; i = i + 3)
			nr_ko += ko.substring(i, i+3) + ".";
		nr_ko = nr_ko + ko.substring(lung_ko - 3, lung_ko);
	}
	else nr_ko = ko.substring(0, moduloko) + "." + puncte (ko.substring(moduloko, lung_ko));

	return nr_ko;

}


function prel2 (nr, zec) {

	if (
		isNaN(nr) ||
		(nr * 1 == 0)
	) return 0;
	else {
		q = (Math.round (nr * Math.pow(10, zec))).toString();
		l = q.length;
		qunit = q.substring(0, l-zec) + "." + q.substring(l-zec, l); 
		qunit = 1 * qunit;

		return qunit;
	}
	
}

function prel3 (nr, zec) {

	if (
		isNaN(nr) ||
		(nr * 1 == 0)) return '';
	else {
		if (nr < 1)
			for (i=0; i<8; i++) {
				ar7845 = ((prel2 (nr * 1 + 1, zec + i)).toString()).split('.');
				if (ar7845[1]) {
					uniq = "0." + ar7845[1];
					uniq=(1 * uniq == 0) ? " " : 1 * uniq;
					return uniq;
					break;
				}
				else if (ar7845[0] * 1 != 1) {
					return ar7845[0] * 1 - 1;
					break;
				}
			}
		else return prel2 (nr, zec);
	}

}

function prel (nr, zec) {

	if (nr < 0) {
		poz852 = prel3 (-nr, zec);
		return -poz852;
	}
	if (
		!isNaN(nr) ||
		(nr * 1 != 0)
	) return prel3 (nr, zec);
	if (nr * 1 == 0 ) return "";

}

function prelcu0 (nr, zec) {

	return nr * 1 == 0 ? 0 : prel (nr, zec);

}

function sch() {

	var al1 = document.form1.vlt1.value;
	document.form1.vmn11.value = campuri_sc[al1];

}

function sch2() {

	var al2 = document.form1.vlt2.value;
	document.form1.vmn12.value = campuri_sc[al2];

	if (campuri_sc[al2] == "RON")
		idtva.style.visibility = "visible";
	else idtva.style.visibility = "hidden";

}


function calculeaza_tva(tva_tva) {

	wr = prelcu0 (tva_tva, 6);
	wr = wr.toString();
	te_tva = wr.split('.');

	te_tva[1] = te_tva[1] ? "," + te_tva[1] : te_tva[1]="";

	return puncte(te_tva[0]) + te_tva[1];

}

function calculeaza() {

	var form = document.forms['currencyForm'];

	var al1	= form.currencyA.value;
	var al2	= form.currencyB.value;

	var c	= 1;
	var din	= 0;
	var inn	= 1;
	var ccc	= 0;
	var c	= parseFloat(form.sum.value);
	
	restafara	= '';
	restafara_tva	= '';

	var din	= parseFloat(al1);
	var inn	= parseFloat(al2);
	gtot = c * din / inn;

	if (c * 1 == 0) {
		form.total.value	=
		form.tva.value		=
		form.tva_bun.value	= '';
		form.sum.focus();
	}

	else {
		restafara	= calculeaza_tva(gtot);
		restafara_tva	= calculeaza_tva(1.19 * c * din / inn);
		curattva	= 1.19 * c * din / inn - c * din / inn;
		restafara_cutva	= calculeaza_tva(1.19 * c * din / inn - c * din / inn);
	}

	if (!isNaN(gtot))
		form.total.value = gtot;  
	//form.tva.value	= restafara_tva;
	//form.tva_bun.value	= restafara_cutva;

}
/*
/* ********************************************************************************************
*/

function editEntry(id, method) {
	makeActive (4);
	window.location.href = 'editEntry.php?id=' + id + '&method=' + method;
}

function viewEntry (id) {
	xwin ('viewEntry.php?id=' + id, 'viewEntry', 750, 550);	
}

function makeActive(id) {
        var item = parent.frames['leftMenu'].document.getElementById('menu');
        var elements = item.getElementsByTagName('li');

        for (i = 0; i < elements.length; i++) {
                elements[i].type = 'circle';
        }

        parent.frames['leftMenu'].document.getElementById(id).type='disc';
}

<!--
var xmlhttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (E) {
		xmlhttp = false;
	}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
}

function getElementTextNS(prefix, local, parentElem, index) {
	var result = "";
	if (prefix && isIE) {
		// IE/Windows way of handling namespaces
		result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
	} else {
		// the namespace versions of this method 
		// (getElementsByTagNameNS()) operate
		// differently in Safari and Mozilla, but both
		// return value with just local name, provided 
		// there aren't conflicts with non-namespace element
		// names
		result = parentElem.getElementsByTagName(local)[index];
	}
	if (result) {
		// get text, accounting for possible
		// whitespace (carriage return) text nodes 
		if (result.childNodes.length > 1) {
			return result.childNodes[1].nodeValue;
		} else {
			return result.firstChild.nodeValue;    		
		}
	} else {
		return "n/a";
	}
}

function xwin(url, name, width, height, features){
  var l = (window.screen.availWidth) ? (window.screen.availWidth - width)/2 : 0;
  var t = (window.screen.availHeight) ? (window.screen.availHeight - height)/2 : 0;
  if (typeof(features) == 'string')
     features = ',' + features;

  var w = window.open(url, name, 'top=' + t + ',left=' + l + ',height=' + height + ',width=' + width + ', scrollbars=auto' + features);
  if (!w){
     return;
  }
  w.resizeTo(width, height);
  return w;
}

function MM_findObj(n, d) { //v4.01
	var
		p,
		i,
		x;
		
	if (!d) d=document;
	if (
		(p = n.indexOf("?")) > 0 &&
		parent.frames.length
	) {
		d = parent.frames[n.substring (p + 1)].document;
		n = n.substring (0, p);
	}
	if (
		!(x = d[n]) &&
		d.all
	) x = d.all[n];
	for (i=0; !x && i < d.forms.length; i++) x = d.forms[i][n];
	for (i=0; !x && d.layers && i < d.layers.length; i++) x=MM_findObj (n,d.layers[i].document);
	if (
		!x &&
		d.getElementById
	) x = d.getElementById (n);
	return x;
}
function toggle () { //v6.0
	var
		i,
		p,
		v,
		obj,
		args = toggle.arguments;
		
	for (i=0; i < (args.length-2); i += 3)
		if ((obj=MM_findObj(args[i]))!=null) {
			v=args[i+2];
			if (obj.style) {
			obj=obj.style;
			v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v;
			}
			obj.visibility=v; 
		}
}
	    
function sortBy (key, table, mode) {
	if (mode == 'ASC') mode = 'DESC';
	else mode = 'ASC';
	window.location.href = '?sortTable=' + table +  '&sortField=' + key + '&sortMode=' + mode;
}

function delId (id, table) {
	if (confirm ('Are you sure?')) window.location.href='?delId=' + id + '&table=' + table;
}
function sendText (id) {
	if (confirm ('Are you sure?')) window.location.href='?sendTextId=' + id;
}
function checkAll (object) {
	var elems = object.form.elements;
	for (var i = 0; i < elems.length; i++) {
		var elem = elems[ i ];
		if (elem.type == 'checkbox' && elem != this) {
			elem.checked = object.checked;
		}
	}
}

function debugElement(elem) {
	str = "";
	j = 0;
	for (i in elem) {
		//str+="<center><big>" + i + "</big></center><br/>\n";
		str+=i + "\n";
		j++;
		if (j==20) {
			//document.write(str);
			alert(str);
			str="";
			j = 0;
		}
	}
}

function xwin(url, name, width, height, features){
  var l = (window.screen.availWidth) ? (window.screen.availWidth - width)/2 : 0;
  var t = (window.screen.availHeight) ? (window.screen.availHeight - height)/2 : 0;
  if (typeof(features) == 'string')
     features = ',' + features;

  var w = window.open(url, name, 'top=' + t + ',left=' + l + ',height=' + height + ',width=' + width + features);
  if (!w){
     return;
  }
  w.resizeTo(width, height);
  return w;
}
