var b = 0;
function startFormFlotant(Color, ampleMinim, ampleMaxim)
{

	var ampleW = window.screen.width;
	var altW = window.screen.height;



	var ample = document.getElementById("bodyDiv").offsetWidth;
		
	if(ample<ampleMinim) ample = ampleMinim;
	if(ample>ampleMaxim) ample = ampleMaxim;

	if(document.all)
	{

		document.getElementById("bodyDiv").style.width = ample - 13 + "px";
		var alt = document.getElementById("formulari").offsetHeight;	
	}
	else
	{		
		document.getElementById("bodyDiv").style.width = ample - 4 + "px";
		var alt = document.height;
	}

	
	
	if(alt > 526)
	{
		document.getElementById("bodyDiv").style.overflow = "hidden";
		document.getElementById("formulari").style.height = "536px";
		document.getElementById("formulari").style.overflow = "auto";
		document.getElementById("formulari").className = "scroll" + Color
		alt = document.getElementById("formulari").offsetHeight;
	}
	if(document.all)
	{
		alt = alt + 64 + 30;	
	}
	else
	{
		alt = alt + 64 + 30 + 18;	
	}
	window.resizeTo(ample,alt+15);	
	window.moveTo((ampleW - ample)/2,(altW-alt)/2);
}
function startFormFlotantB(Color, ampleMinim, ampleMaxim)
{
	var ampleW = window.screen.width;
	var altW = window.screen.height;
	var jaActualitzat = false;
	
	//Agafem l'ample actual i comparem amb l'ample maxim
	var ample = document.getElementById("bodyDiv").offsetWidth;	
	if(ample<ampleMinim) ample = ampleMinim;
	if(ample>ampleMaxim) ample = ampleMaxim;

	//Canviem l'ample del body div i del div
	document.getElementById("bodyDiv").style.width ="100%";
	document.getElementsByTagName("body").item(0).style.width = ample + "px";
	//alert(document.getElementsByTagName("body").item(0).style.width);

	//mirem l'alçada
	var alt = document.getElementById("formulari").offsetHeight;

	//Si es mes gran de 526px Amagem el overflow i el posem a dins de la capa form posem l'alçada a 526	
	if(alt > 526)
	{
		document.getElementById("bodyDiv").style.overflow = "hidden";
		document.getElementById("formulari").style.height = "536px";
		document.getElementById("formulari").style.overflow = "auto";
		document.getElementById("formulari").className = "scroll" + Color
		document.getElementById("bodyDiv").style.width = ample-10+"px";
		//alert("entro el body div medeix: "+document.getElementById("bodyDiv").style.width);
		jaActualitzat = true;
		alt = "568";
		//alert("a ma");
	}else{
		alt = alt + 35;
		jaActualitzat = true;
	}	

	//Incrementem els pixels del boto tancar	
	ample = document.getElementsByTagName("body").item(0).style.width;
	ample = ample.substring(0,ample.length -2);
	if(document.all && jaActualitzat == false)
	{
		alt =   document.getElementById("bodyDiv").offsetHeight+26;
		//alert("calculat");
		
	}
	else if(!document.all)
	{
		alt =   document.getElementsByTagName("body").item(0).offsetHeight+18 ;
	}
	//alert("rezise2: "+ample+" x "+alt);
	//alt = alt + 10
	window.resizeTo(ample,alt);	
	window.moveTo((ampleW - ample)/2,(altW-alt)/2);
}

function startFormFlotantC(Color, ampleMinim, ampleMaxim)
{

	var ampleW = window.screen.width;
	var altW = window.screen.height;



	var ample = document.getElementById("bodyDiv").offsetWidth;
		
	if(ample<ampleMinim) ample = ampleMinim;
	if(ample>ampleMaxim) ample = ampleMaxim;

	if(document.all)
	{

		document.getElementById("bodyDiv").style.width = ample - 13 + "px";
		var alt = document.getElementById("formulari").offsetHeight;	
	}
	else
	{		
		document.getElementById("bodyDiv").style.width = ample - 4 + "px";
		var alt = document.height;
	}

	
	
	if(alt > 526)
	{
		document.getElementById("bodyDiv").style.overflow = "hidden";
		document.getElementById("formulari").style.height = "536px";
		document.getElementById("formulari").style.overflow = "auto";
		document.getElementById("formulari").className = "scroll" + Color
		alt = document.getElementById("formulari").offsetHeight;
	}
	if(document.all)
	{
		alt = alt + 64 + 10;	
	}
	else
	{
		alt = alt + 64 + 10 + 18 ;	
		//alert(alt);
	}
	window.resizeTo(ample,alt+10);	
	window.moveTo((ampleW - ample)/2,(altW-alt+10)/2);
}

function startForm(Color){
	var Formulari = document.getElementById("formulariNoFlotant");
	var alt = document.body.clientHeight - 140;	
	Formulari.style.top = "113px";
	if(document.all)
	{
		if(Formulari.offsetHeight > alt){
			Formulari.style.height = alt;
			Formulari.style.overflow = "auto";
			Formulari.className = "scroll" + Color
		}			
	}
	else
	{	var alt = window.innerHeight - 140;		
		if(Formulari.clientHeight > alt)
		{			
			Formulari.style.height = alt;
			Formulari.style.overflow = "auto";
			Formulari.className = "scroll" + Color
		}

	}
	
}
function imprimirPag()
{
	
	var novawindow = window.open("/recursos/print.html","print","top=100000;left=100000;toolbar=0;location=0;directories=0;status=0;menubar=0;scrollbars=0;resizable=0;width=10;height=10;");
}
function prepararImpresio()
{	
	document.getElementsByTagName("Body").item(0).innerHTML = window.opener.document.getElementsByTagName("Body").item(0).innerHTML;
	
	//Treiem colors i canviem l'estil
	document.getElementById("Certificacio").id = "blanc";
	document.getElementById("bodyDiv").style.width = "19.0cm";

	var divs =	document.getElementsByTagName("DIV");					
	for (j=0; j<divs.length; j++) 
	{		

		if(divs.item(j).style.overflow == "auto" || divs.item(j).style.overflow == "scroll")
		{
			divs.item(j).style.height = "auto";
			//divs.item(j).style.width = "21cm";
			divs.item(j).style.overflow = "hidden";
			divs.item(j).style.position = "static";
			divs.item(j).style.top = "0px";			
		}
	}

	
	treurePaddingsiWidht();
	substituirTextAreas();

	//posem posicio relative perque conti per fer l'overflow
	document.getElementById("bodyDiv").style.position = "static";
	document.getElementById("bodyDiv").style.top = "10px";
	document.getElementById("bodyDiv").style.height = "auto";
	document.getElementById("bodyDiv").style.overflow = "hidden";
	



	//Posem l'overflow del body
	document.getElementsByTagName("Body").item(0).style.overflow = "auto";
	document.getElementsByTagName("Body").item(0).style.height = "100%";


	//treiem la barra
	treurelaBarra();
	window.print();
	window.close();
}

function substituirTextAreas()
{
	var nouUL;
	var texts = document.getElementsByTagName("TEXTAREA");
	var textLength = texts.length;	
	for (j3=0; j3 < textLength; j3++) 
	{					
			nouUL = document.createElement('span');			
			nouUL.className = "border";			
			nouUL.innerHTML = texts.item(0).value;
			var parent = texts.item(0).parentNode;
			parent.replaceChild(nouUL, texts.item(0));			
	}
}

function treurePaddingsiWidht()
{
	var lis = document.getElementsByTagName("LI");					
	for (j2 = 0; j2 < lis.length; j2++) 
	{		
		if(lis.item(j2).stylepaddingLeft != "0px")
		{
			lis.item(j2).style.paddingLeft = "0px";
		}
	}

	var inputs = document.getElementsByTagName("INPUT");					
	for (j=0; j<inputs.length; j++) 
	{		
			inputs.item(j).style.width = "";
	}
}

function treurelaBarra()
{
	//treiem la barra
	document.getElementById("logo").style.display = "none";
	document.getElementById("logo").style.height = "0px";
	document.getElementById("logo").style.position = "absolute";

	document.getElementById("idiomes").style.display = "none";
	document.getElementById("idiomes").style.height = "0px";
	document.getElementById("idiomes").style.position = "absolute";

	document.getElementById("segonaPart").style.display = "none";
	document.getElementById("segonaPart").style.height = "0px";
	document.getElementById("segonaPart").style.position = "absolute";

	document.getElementById("content").style.display = "none";
	document.getElementById("content").style.height = "0px";
	document.getElementById("content").style.position = "absolute";

	document.getElementById("tableBotons").style.display = "none";
	document.getElementById("tableBotons").style.height = "0px";
	document.getElementById("tableBotons").style.position = "absolute";

	if(document.all)
	{
		document.getElementById("tableBotons").nextSibling.style.display = "none";
		document.getElementById("tableBotons").nextSibling.style.height = "0px";
		document.getElementById("tableBotons").nextSibling.style.position = "absolute";
	}
	else
	{
		document.getElementById("tableBotons").nextSibling.nextSibling.style.display = "none";
		document.getElementById("tableBotons").nextSibling.nextSibling.style.height = "0px";
		document.getElementById("tableBotons").nextSibling.nextSibling.style.position = "absolute";
	}
}
