function limpar(id) {
  var tipo;
  var form = document.getElementById(id);
  var quant = form.elements.length;
  var nome;
  for(var i = 0; i < quant; i++){
  	tipo = form.elements[i].type;
    if (form.elements[i].type == "text") {
    	nome = form.elements[i].name;
    	//Verifica se o campo ? parte do controle t:Date, caso seja n?o limpa
		if ((nome.indexOf('.day') == -1) && (nome.indexOf('.year') == -1)) {
			form.elements[i].value = '';
		}
	}
	if (form.elements[i].type == "select-one") {
    	nome = form.elements[i].name;
    	//Verifica se o campo ? parte do controle t:Date, caso seja n?o limpa
		if (nome.indexOf('.month') == -1) {
			form.elements[i].selectedIndex = 0;
		}
	}
	if (form.elements[i].type == "textarea")
		form.elements[i].value = '';
	if (form.elements[i].type == "checkbox")
		form.elements[i].checked = false;
	if (form.elements[i].type == "radio")
		form.elements[i].checked = false;
  }
}

function enviar(id) {
	form = document.getElementById(id);
	form.submit();
}

function imprimir() {
	window.print();
}

function voltar() {
	history.go(-1);
}

function irSeminovos() {
	width=880;
	height=560;
	var left = Math.floor( (screen.width - width) / 2);
	var top = Math.floor( (screen.height - height) / 2);
	
	var url = '/portal/seminovos/index.jsf';
	var features = 'location = yes, menubar = yes, resizable = yes, scrollbars = yes, status = yes, titlebar = yes, toolbar = yes, width=' + width + ',height=' + height + ',top='+top+',left='+left+'';
	var newWindow = window.open(url, 'portalDeSeminovos', features);
	if (newWindow != null) {
		return false;
	}
}

function irProposta() {
	width = 590;
	height = 700;
	var url = 'proposta.jsf';
	var features = 'location = no, menubar = no, resizable = no, scrollbars = yes, status = no, titlebar = no, toolbar = no, width=' + width + ',height=' + height + ',top=0,left=0';
	var newWindow = window.open(url, 'portalServopaPropostaDeVenda', features);
	if (newWindow != null) {
		return false;
	}
}

function mostrarInformacoes() {
	width = 440;
	height = 600;
	
	var tipo = document.getElementById("tipo").value;
	if (tipo.length == 0) {
		tipo = 'frotistas';
	}
	
	var url = '/portal/portal/' + tipo + '.html';
	var features = 'location = no, menubar = no, resizable = no, scrollbars = yes, status = no, titlebar = no, toolbar = no, width=' + width + ',height=' + height + ',top = 200, left = 200';
	var newWindow = window.open(url, 'portalServopaMaisInformacoes', features);
}

function abrirPopup() {
	width=800;
	height=600;
	var left = Math.floor( (screen.width - width) / 2);
	var top = Math.floor( (screen.height - height) / 2);
	
	var url = '/portal/servopa_motos/banner/';
	var features = 'location = no, menubar = no, resizable = no, scrollbars = no, status = no, titlebar = yes, toolbar = no, width=' + width + ',height=' + height + ',top='+top+',left='+left+'';
	var newWindow = window.open(url, 'servopaMotosBanner', features);
	if (newWindow != null) {
		return false;
	}
}

/**
 * Monta um HTML para abrir em popup para impressao do mapa da empresa
 * Se for informado um segundo argumento, sera um numero
 * Busca entao por este numero em uma layer de empresa
 */
function abrirMapaImpressao(urlMapa) {
	width=650;
	height=465;
	var left = Math.floor( (screen.width - width) / 2);
	var top = Math.floor( (screen.height - height) / 2);
	
	var features = 'location = no, menubar = no, resizable = no, scrollbars = yes, status = no, titlebar = yes, toolbar = no, width=' + width + ',height=' + height + ',top='+top+',left='+left+'';
	var newWindow = window.open('', 'popupMapa', features);
	if (newWindow != null) {
		var newContent = "<html><head><title>Grupo Servopa - Localização</title></head>";
	    newContent += "<body onload=\"window.print();\" style=\"margin:0;padding:0;font-family:Verdana;font-size:11px;\">";
		if(urlMapa) {
			if(urlMapa.length > 0) {
				newContent += '<div style="text-align:center;padding:5px;">Aguarde o carregamento do mapa para impressão</div>';
				var iframe = '<iframe style="border:1px solid black;" id="frame_mapa" name="frame_mapa" width="'+631+'" height="'+height+'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'+urlMapa+'"></iframe>';
				newContent += iframe;
			}
		}
			
		//Verifica se existe a informacao da localizacao da empresa para exibir no popup
		var htmlLocalizacao = '';
		var elementoLocalizacao = newWindow.opener.document.getElementById('layerMapaEmpresaVeiculoSeminovo:mapaLocalizacaoSeminovos:infoLocalizacaoSeminovo');
		if(elementoLocalizacao){
			//Detalhes de seminovos
			htmlLocalizacao = elementoLocalizacao.innerHTML;
		}
		else {
			var elementoLocalizacao = newWindow.opener.document.getElementById('layerMapaEmpresaVeiculoNovo:mapaLocalizacaoNovos:infoLocalizacaoNovo');
			if(elementoLocalizacao){
				//Detalhes de novos
				htmlLocalizacao = elementoLocalizacao.innerHTML;
			}
			else {
				//Verifica se foi informado um segundo argumento
				if(arguments[1] >= 0){
					//Verifica se existe uma layer para o argumento
					var elementoLocalizacao = newWindow.opener.document.getElementById('localizacaoEmpresas_'+arguments[1]+':infoLocalizacaoEmpresa');
					if(elementoLocalizacao){
						//Layers das empresas
						htmlLocalizacao = elementoLocalizacao.innerHTML;
					}
				}
			}
		}
		
		//Insere no Html se tiver as informacoes de localizacao da pagina que abriu este popup
		if(htmlLocalizacao.length > 0){
			newContent += '<div id="localizacao" style="padding:5px;">' + htmlLocalizacao + '</div>';
		}
	    newContent += "</body></html>";
	    newWindow.document.write(newContent);
	    newWindow.document.close(); // Close layout stream
		return false;
	}
}

function abrirPopupVideo() {
	width=320;
	height=240;
	var left = Math.floor( (screen.width - width) / 2);
	var top = Math.floor( (screen.height - height) / 2);
	
	var url = '/portal/arquivos/video/video_181208.html';
	var features = 'location = no, menubar = no, resizable = no, scrollbars = no, status = no, titlebar = yes, toolbar = no, width=' + width + ',height=' + height + ',top='+top+',left='+left+'';
	var newWindow = window.open(url, 'popUpVideo', features);
	if (newWindow != null) {
		return false;
	}
}

function abrirPopupVideo120310() {
	width=425;
	height=344;
	var left = Math.floor( (screen.width - width) / 2);
	var top = Math.floor( (screen.height - height) / 2);
	
	var url = '/portal/arquivos/video/video_120310.html';
	var features = 'location = no, menubar = no, resizable = no, scrollbars = no, status = no, titlebar = yes, toolbar = no, width=' + width + ',height=' + height + ',top='+top+',left='+left+'';
	var newWindow = window.open(url, 'popUpVideo120310', features);
	if (newWindow != null) {
		return false;
	}
}
	
function abrirPopupVideoPrixx() {
	width=360;
	height=270;
	var left = Math.floor( (screen.width - width) / 2);
	var top = Math.floor( (screen.height - height) / 2);
	
	var url = '/portal/arquivos/video/video_210909.html';
	var features = 'location = no, menubar = no, resizable = no, scrollbars = no, status = no, titlebar = yes, toolbar = no, width=' + width + ',height=' + height + ',top='+top+',left='+left+'';
	var newWindow = window.open(url, 'popUpVideo', features);
	if (newWindow != null) {
		return false;
	}
}


/**
 * Função JavaScript para formatar data no campo. (dd/mm/aaaa)
 * 
 * @author Renato Paula Eduardo Jr
 * @since 27/05/2010
 * */
function makeDate(obj){
    //obj = document.getElementById(id);
    vl = obj.value;
    l = vl.toString().length;
    switch(l){
        case 2:
            obj.value = vl + "/";
        break;
        case 5:
            obj.value = vl + "/";
        break;
    }
}