// JavaScript Document
var prod_atual = "etiquetas", form_atual = "form01";
var cor = "#efeeee", corErro = "#e6e298", cor2="eeeeef", branco="#eeeeef", borda="1px solid #9f9f9d", bordaErro="1px solid #fd2c2c";

window.onload = function(){
	document.getElementById('RadioGroup1_0').checked = "checked";
	document.getElementById('RadioGroup1_0').onclick = function(){troca(1);}
	document.getElementById('RadioGroup1_1').onclick = function(){troca(2);}
	document.getElementById('RadioGroup1_2').onclick = function(){troca(3);}
	document.getElementById('RadioGroup1_3').onclick = function(){troca(4);}
	
	document.getElementById('material').onchange = function(){ changeOp();}
	
	document.getElementById('altura').onfocus = limpa
	document.getElementById('largura').onfocus = limpa
	document.getElementById('nc').onfocus = limpa
	
	document.getElementById('material').onfocus = limpa
	document.getElementById('gramatura').onfocus = limpa
	document.getElementById('qtdEt').onfocus = limpa
	document.getElementById('rotulo_cor').onfocus = limpa
	
	document.getElementById('modelo').onfocus = limpa
	document.getElementById('qtdImp').onfocus = limpa
	
	document.getElementById('tiporibon').onfocus = limpa
	document.getElementById('qtdRi').onfocus = limpa	

	document.getElementById('adesivos').onfocus = limpa	
	
	document.getElementById('mtgem').onfocus = limpa	
	document.getElementById('lgura').onfocus = limpa	
	
	document.getElementById('rolo').onfocus = limpa	
	
	changeOp();
}

function mostralista(){
var pgWidth = 412;
var pgHeight= 465;
var pLeft = (screen.width/2) - (pgWidth/2);
var pTop =  (screen.height/2)-(pgHeight/2)-50;
window.open("lista.html","lista","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=yes, width=418, height=400, top="+pTop+",left="+pLeft+"")
}

function preenche(l,a,c,ref){
	obj1 = document.getElementById("largura");
	obj1.value = l;
	obj1.style.background = cor2;
	
	obj2 = document.getElementById("altura");
	obj2.value = a;
	obj2.style.background = cor2;
		
	obj3 = document.getElementById("nc");
	obj3.value = c;
	obj3.style.background = cor2;
	
	document.getElementById("referencia").value = ref;
}


function troca(area){
	if(area==1 && prod_atual != "etiquetas"){
		ocultar(prod_atual);
		prod_atual = "etiquetas";
		document.getElementById("info1").style.display = "block";
		document.getElementById("cor_rotulo").style.display = "none";
	}
	else if(area==2 && prod_atual != "impressoras"){
		ocultar(prod_atual);
		prod_atual = "impressoras";
		document.getElementById("info2").style.display = "block";
	}
	else if(area==3 && prod_atual != "ribons"){
		ocultar(prod_atual);
		prod_atual = "ribons";
		document.getElementById("info3").style.display = "block";
	}
	else if(area==4 && prod_atual != "rotulo"){
		ocultar(prod_atual);
		prod_atual = "rotulos";
		document.getElementById("info1").style.display = "block";
		document.getElementById("cor_rotulo").style.display = "block";
	}
}

function ocultar(oq){

	if(oq == "etiquetas"){
		document.getElementById("info1").style.display = "none";
	}
	if(oq == "impressoras"){
		document.getElementById("info2").style.display = "none";
	}
	if(oq == "ribons"){
		document.getElementById("info3").style.display = "none";
	}
	if(oq == "rotulos"){
		document.getElementById("info1").style.display = "none";
	}
}


function changeOp(){
	document.getElementById("areagramatura").style.display = "block";
	document.getElementById("qtd").style.display = "block";
	document.getElementById("metragem").style.display = "none";
	document.getElementById("arearolo").style.display = "none";
	
	var indice = document.getElementById("material").selectedIndex;
	var obj = document.getElementById("gramatura");
	obj.options[0].text = "----- GRAMATURA -----";
	obj.options[0].value = "0";
	limparitens();
	habilitaAdesivo(false);

	if(indice == 0){
		obj.disabled = true;
	}
	if(indice == 1){
		obj.disabled = false;
		insere("20g")
		insere("30g")
		habilitaAdesivo(true);
	}
	if(indice == 2){
		obj.disabled = false;
		insere("20g")
		insere("30g")
		habilitaAdesivo(true);
	}
	if(indice == 3){
		obj.disabled = false;
		insere("20g")
		insere("30g")
		insere("50g")
	}
	if(indice == 4){
		obj.disabled = false;
		insere("20g")
		insere("30g")
		insere("50g")
	}
	if(indice == 5){
		obj.disabled = false;
		insere("130g")
		insere("180g")
	}
	if(indice == 6){
		obj.disabled = false;
		obj.options[0].selected="selected"
		obj.options[0].value = "N/A";
		obj.options[0].text = "N/A";
		document.getElementById("areagramatura").style.display = "none";
		document.getElementById("qtd").style.display = "none";
		document.getElementById("metragem").style.display = "block";
	}
	if(indice == 7){
		obj.disabled = false;
		obj.options[0].selected="selected"
		obj.options[0].value = "20g";
		obj.options[0].text = "20g";
		document.getElementById("qtd").style.display = "none";
		document.getElementById("arearolo").style.display = "block";
	}
	if(indice == 8){
		obj.disabled = false;
		obj.options[0].selected="selected"
		obj.options[0].value = "30g";
		obj.options[0].text = "30g";
	}
	if(indice == 9){
		obj.disabled = false;
		obj.options[0].selected="selected"
		obj.options[0].value = "20g";
		obj.options[0].text = "20g";
	}
	if(indice == 10){
		obj.disabled = false;
		obj.options[0].selected="selected"
		obj.options[0].value = "23g";		
		obj.options[0].text = "23g";
	}
	
//	alert(obj.options[0].value);
}


function insere(valor){
  var sel = document.getElementById('gramatura');
  var lugar = sel.length	
  if (sel.selectedIndex >= 0) {
    var elOptNew = document.createElement('option');
    elOptNew.text = '' + valor;
    elOptNew.value = '' + valor;
	var elOptOld = sel.options[lugar];  
    try {
   sel.add(elOptNew, elOptOld); // standards compliant; doesn't work in IE

    }
    catch(ex) {
      sel.add(elOptNew, lugar); // IE only
    }
  }
}


function limparitens(){
  var obj = document.getElementById('gramatura');
  var indice = obj.length;
  while(indice > 0){
    obj.remove(indice);
	indice--;
  }
}

function habilitaAdesivo(con){
	if(con){
		document.getElementById("areaAdv").style.display = "block";
		//document.getElementById("info1").style.height = "265px";		
	}
	else{
		document.getElementById("areaAdv").style.display = "none";
		//document.getElementById("info1").style.height = "230px";		
	}
}

function limpa(e){
    try{var x = e.target          }catch(er){};
    try{var x = event.srcElement  }catch(er){};
	
	if(x.id == "largura") {document.getElementById("largura").style.background = cor2; document.getElementById("largura").style.border = borda; }
	if(x.id == "altura") {document.getElementById("altura").style.background = cor2;}
	if(x.id == "nc") {document.getElementById("nc").style.background = cor2;}
	if(x.id == "material") {document.getElementById("material").style.background = branco;}
	if(x.id == "gramatura") {document.getElementById("gramatura").style.background = branco;}
	if(x.id == "qtdEt") {document.getElementById("qtdEt").style.background = cor2;}
	if(x.id == "rotulo_cor") {document.getElementById("rotulo_cor").style.background = cor2;}
	
	
	if(x.id == "modelo") {document.getElementById("modelo").style.background = branco;}
	if(x.id == "qtdImp") {document.getElementById("qtdImp").style.background = branco;}
	
	if(x.id == "tiporibon") {document.getElementById("tiporibon").style.background = branco;}
	if(x.id == "qtdRi") {document.getElementById("qtdRi").style.background = branco;}
	
	if(x.id == "adesivos") {document.getElementById("adesivos").style.background = branco;}
	
	if(x.id == "lgura") {document.getElementById("lgura").style.background = branco;}
	if(x.id == "mtgem") {document.getElementById("mtgem").style.background = branco;}
	
	if(x.id == "rolo") {document.getElementById("rolo").style.background = branco;}
	
}

function limpar(){
	var fml=document.orcaForm
	fml.reset();
	if(prod_atual == "etiquetas")document.getElementById("RadioGroup1_0").checked = "checked";
	if(prod_atual == "impressoras")document.getElementById("RadioGroup1_1").checked = "checked";
	if(prod_atual == "ribons")document.getElementById("RadioGroup1_2").checked = "checked";
	if(prod_atual == "rotulos")document.getElementById("RadioGroup1_3").checked = "checked";
	avisar(false);

	document.getElementById("altura").style.background = cor2;
	document.getElementById("altura").style.border = cor2;
	document.getElementById("largura").style.background = cor2;
	document.getElementById("nc").style.background = cor2;
	document.getElementById("material").style.background = branco;
	
	document.getElementById("gramatura").style.background = branco;
	document.getElementById("gramatura").disabled = "disabled";
	document.getElementById("qtdEt").style.background = cor2;
	
	document.getElementById("modelo").style.background = branco;
	document.getElementById("qtdImp").style.background = branco;
	
	document.getElementById("tiporibon").style.background = branco;
	document.getElementById("qtdRi").style.background = branco;
	document.getElementById("adesivos").style.background = branco;
	
	document.getElementById("lgura").style.background = branco;
	document.getElementById("mtgem").style.background = branco;
	
	document.getElementById("rolo").style.background = branco;
	
	habilitaAdesivo(false);
	changeOp();
}

