var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{

    if ((version >= 5.5) && (version <7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}

function addmore(t){
ela=document.createElement('input');
elb=document.createElement('input');
elc=document.createElement('input');
eld=document.createElement('input');
ele=document.createElement('input');

ela.setAttribute('type','text');
elb.setAttribute('type','text');
elc.setAttribute('type','text');
eld.setAttribute('type','text');
ele.setAttribute('type','text');


ctr=document.createElement('tr');


ctda=document.createElement('td');
ctdb=document.createElement('td');
ctdc=document.createElement('td');
ctdd=document.createElement('td');
ctde=document.createElement('td');

if(t==4){
ctde.appendChild(ele);
ctr.appendChild(ctde);	
}

ctda.appendChild(ela);
ctdb.appendChild(elb);
ctdc.appendChild(elc);


ctr.appendChild(ctda);
ctr.appendChild(ctdb);
ctr.appendChild(ctdc);

if(t==4){

ctdd.appendChild(eld);
ctr.appendChild(ctdd);
}

switch(t){
case 4:
ta=document.getElementById('tableRenters');
ele.setAttribute('name','IDapartment[]');
ela.setAttribute('name','Nutzer[]');
elc.setAttribute('name','Einzugsdatum[]');
elb.setAttribute('name','Personenzahl[]');
eld.setAttribute('name','Auszugsdatum[]');

break;
case 3:
ta=document.getElementById('tabelul3');
ela.setAttribute('name','Kostenart2[]');
ela.setAttribute('size','20');
elb.setAttribute('name','US[]');
elb.setAttribute('size','3');
elc.setAttribute('name','Umlageschlussel[]');
elc.setAttribute('size','30');
break;
case 2:
ta=document.getElementById('tableHeizungs');
ela.setAttribute('name','Kostenart[]');
ela.setAttribute('size','40');
elb.setAttribute('name','Rechnungsdatum[]');
	if ((version >= 5.5) && (version <7)){
						elb.attachEvent('onkeyup',function (e){formatstil(1,e.target?e.target:e.srcElement)} );
						elc.attachEvent('onkeyup',function (e){formatstil(2,e.target?e.target:e.srcElement)} );
					} else {
						elb.setAttribute('onkeyup','formatstil(1,this)');
						elc.setAttribute('onkeyup','formatstil(2,this)');
					}

elc.setAttribute('name','Betrag2[]');

break;
case 1:
ta=document.getElementById('tableBrennstoffkoste');
ela.setAttribute('name','Rechnungs[]');
elb.setAttribute('name','Menge[]');
elc.setAttribute('name','Betrag[]');
beforewhat=document.getElementById('inaintederand');
break;


}



tbo=ta.firstChild;
if(t==1){
tbo.insertBefore(ctr,beforewhat);
} else {

tbo.appendChild(ctr);
}


}

function formatstil(mod,telem){
	vaal=telem.value;
	xcp=vaal;
	//vaal=vaal.replace(",","");
	//vaal=vaal.replace(".","");
	lung=vaal.length;
	switch(mod){
	case 1:
		if(lung==2){
			xcp=vaal+".";
			
		
		}
		if(lung==5){
			xcp=xcp+".";
		}
		if(lung>10){
			xcp=xcp.substr(0,10);
		}
			
	break;
	case 2:
		vaal=vaal.replace(',','');
		vaal=vaal.replace(/\./g,'');
	lung=vaal.length;
		if(lung>2){
		 xcp=vaal.substr(0,lung-2)+","+vaal.substr(lung-2,lung);
		}
		lung=xcp.length;
		if(lung>6){
		 xcp=xcp.substr(0,lung-6)+"."+xcp.substr(lung-6,lung);
		}
		lung=xcp.length;
		if(lung>10){
		 xcp=xcp.substr(0,lung-10)+"."+xcp.substr(lung-10,lung);
		}
		lung=xcp.length;
		if(lung>14){
		 xcp=xcp.substr(0,lung-14)+"."+xcp.substr(lung-14,lung);
		}
		
		
	break;
	
	case 3:
		xcp=vaal.replace(/\D/g,'');
	
	break;
	
	}

telem.value=xcp;
}

function addpict(){

br=document.createElement('br');
lb=document.createElement('label');
br2=document.createElement('br');
br3=document.createElement('br');
br4=document.createElement('br');
lb.innerHTML='<img src="images/arrow_11.gif" alt="arraw" />Image';


el=document.createElement('input');

el.setAttribute('size','43');

dd=document.getElementById('poze');
el.setAttribute('type','file');
el.setAttribute('name','image[]');
dd.appendChild(br);
dd.appendChild(lb);
dd.appendChild(br2);
dd.appendChild(el);
dd.appendChild(br3);
dd.appendChild(br4);
}

function addmoreb(v){

	tabelul=document.getElementById('more99');


	nouarand=document.createElement('tr');

	ftoe=tabelul.firstChild.firstChild;
	tfc=tabelul.firstChild;
	tfc.appendChild(nouarand);

	while(ftoe.nodeType == 3) {
		ftoe = ftoe.nextSibling;
	}
		
	ftoe=ftoe.nextSibling;


	while(ftoe.nodeType == 3) {
		ftoe = ftoe.nextSibling;
	}

	primacel=ftoe.firstChild;

	while(primacel.nodeType == 3) {
		primacel = primacel.nextSibling;
	}


	primulinput=primacel.firstChild;

	while(primulinput.nodeType==3) {
		primulinput = primulinput.nextSibling;
	}

	nouatd=document.createElement('td');
	nouainput=document.createElement('input');
	nouatd.appendChild(nouainput);
	nouainput.setAttribute('name',primulinput.getAttribute('name'));
	nouainput.setAttribute('size',primulinput.getAttribute('size'));
	nouarand.appendChild(nouatd);

		for(i=0;i<7;i++){
		
			primacel=primacel.nextSibling;

			while(primacel.nodeType == 3) {
				primacel = primacel.nextSibling;
			}
			
			primulinput=primacel.firstChild;
			
			while(primulinput.nodeType==3) {
				primulinput = primulinput.nextSibling;
			}

			nouatd=document.createElement('td');
			nouainput=document.createElement('input');
			nouatd.appendChild(nouainput);
			nouainput.setAttribute('name',primulinput.getAttribute('name'));
			nouainput.setAttribute('size',primulinput.getAttribute('size'));
				if(i==5 || i==6){
					if ((version >= 5.5) && (version <7)){
						nouainput.attachEvent('onkeyup',function(e){formatstil(1,e.target?e.target:e.srcElement)} );
					} else {
						nouainput.setAttribute('onkeyup','formatstil(1,this)');
					}
					
				}
				if(i==4){
					if ((version >= 5.5) && (version <7)){
						nouainput.attachEvent('onkeyup',function(e){formatstil(3,e.target?e.target:e.srcElement)} );
					} else {
						nouainput.setAttribute('onkeyup','formatstil(3,this)');
					}
					
				}
			nouarand.appendChild(nouatd);

		
		}
		tdcurand=document.createElement('td');
		tdcurand.innerHTML='&nbsp';
		nouarand.appendChild(tdcurand);
		//butonucopiere.setAttribute('onclick','copy(this)');
		
		
		
		return false;
}



function copyrand(t){

	randul=t.parentNode.parentNode;
	nouarand=document.createElement('tr');
	
	randulcucurent=randul.firstChild;
	
	
	while(randulcucurent.nodeType == 3) {
		randulcucurent = randulcucurent.nextSibling;
	}

	inputulcucurent=randulcucurent.firstChild;
	
	while(inputulcucurent.nodeType == 3) {
		inputulcucurent = inputulcucurent.nextSibling;
	}

	noutd=document.createElement('td');
	nouin=document.createElement('input');
	noutd.appendChild(nouin);
	valoareafixa=Number(inputulcucurent.value)+(0.01);
	nouin.value=valoareafixa.toFixed(2);
	nouin.setAttribute('name',inputulcucurent.getAttribute('name'));
	nouin.setAttribute('size',inputulcucurent.getAttribute('size'));
	nouin.setAttribute('readonly','readonly');
	nouarand.appendChild(noutd);
	
	
	
	for(i=0;i<8;i++){
	
	
	
	randulcucurent = randulcucurent.nextSibling;
		
	while(randulcucurent.nodeType == 3) {
		randulcucurent = randulcucurent.nextSibling;
	}
	
	inputulcucurent=randulcucurent.firstChild;
	
	while(inputulcucurent.nodeType == 3) {
		inputulcucurent = inputulcucurent.nextSibling;
	}
	if(i==7){
		noutd=document.createElement('td');
		noutd.appendChild(inputulcucurent);
		nouarand.appendChild(noutd);
		continue;
	}
	noutd=document.createElement('td');
	nouin=document.createElement('input');
	noutd.appendChild(nouin);
	nouin.value=inputulcucurent.value;
	nouin.setAttribute('name',inputulcucurent.getAttribute('name'));
	nouin.setAttribute('size',inputulcucurent.getAttribute('size'));
		if(i==5 || i==6){
			if ((version >= 5.5) && (version <7)){
				nouin.attachEvent('onkeyup',function(e){formatstil(1,e.target?e.target:e.srcElement)} );
			} else {
				nouin.setAttribute('onkeyup','formatstil(1,this)');
			}
			
				
		}
		if(i==4 ){
			if ((version >= 5.5) && (version <7)){
				nouin.attachEvent('onkeyup',function(e){formatstil(3,e.target?e.target:e.srcElement)} );
			} else {
				nouin.setAttribute('onkeyup','formatstil(3,this)');
			}
			
				
		}
		
	nouarand.appendChild(noutd);
	
	}
	
	tdcurand=document.createElement('td');
	
	tdcurand.innerHTML='&nbsp';
	nouarand.appendChild(tdcurand);
	
	//butonucopiere.setAttribute('onclick','copy(this)');
	bodyiul=randul.parentNode;
	
	beforewhat=randul.nextSibling;
	 
	
	bodyiul.insertBefore(nouarand,beforewhat);
	
	return false;
	
}