/*
------------------------------------------------------------------------------------------
© Digital Industry - 2007

Autor:		Rafael Cronemberger de Assis
Cliente: 	Brother
------------------------------------------------------------------------------------------
*/

window.defaultStatus 	= "Brother";
var nmUltimaTr;

function displayFlash(largura, altura, arquivo){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="'+largura+'" height="'+altura+'" id="teste" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="transparent" />');
	document.write('<param name="movie" value="'+arquivo+'" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><embed src="'+arquivo+'" wmode="transparent" quality="best" width="'+largura+'" height="'+altura+'" name="div" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"/>');
	document.write('</object>');
}

function Field_OnFocus(objForm, stFieldValue){
	if(eval(objForm).value == stFieldValue){
		eval(objForm).value = "";
	}
}

function Field_OnBlur(objForm, stFieldValue){
	if(eval(objForm).value == ""){
		eval(objForm).value = stFieldValue;
	}
}

function validateRegexEmail(stEmail){
	if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(stEmail)){
		return false;
	}
}

function displayErrorMessage(stError){
	alert(stError)
	return false;
}

function openPopup(vURL, vNomeJanela, vParametros){
	v_pop = window.open(vURL, vNomeJanela, vParametros)
}

function validateFormCanal(obj_form){
	if(obj_form.stNome.value==""){
		alert("Favor preencher o campo Nome");
		obj_form.stNome.focus();
		return false
	}else if(obj_form.stMail.value == ""){
		alert("Favor preencher o campo e-mail");
		obj_form.stMail.focus();
		return false
	}else if(obj_form.stMail.value !=""){
		if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj_form.stMail.value)){
			alert("Favor preencher o campo e-mail corretamente.");
			obj_form.stMail.focus();
			return false
		}
	}if(obj_form.stAssunto.value == ""){
		alert("Favor preencher o campo assunto.");
		obj_form.stAssunto.focus();
		return false
	}else if(obj_form.stMensagem.value==""){
		alert("Favor preencher o campo mensagem.");
		obj_form.stMensagem.focus();
		return false
	}else{
		document.frmCanal.fgEnvio.value=1;
		window.defaultStatus = "Enviando seus dados...";
		return true;
	}
}

function validateFormCases(obj_form){
	var strMsgErro, strCabMsgErro; 
	strCabMsgErro 	= "Confira os seguintes campos:\n\n";
	strMsgErro		= "";

	if(obj_form.stNome.value==""){
		strMsgErro = strMsgErro + "Nome; \n";
		obj_form.stNome.focus();
	}

	if(obj_form.stMail.value==""){
		strMsgErro = strMsgErro +  "E-mail; \n";
		obj_form.stMail.focus();
	}
	
	if(obj_form.stMail.value !=""){
		if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj_form.stMail.value)){
			strMsgErro = strMsgErro +  "E-mail; \n";
			obj_form.stMail.focus();
		} 
	}
	
	if(obj_form.stAssunto.value==""){
		strMsgErro = strMsgErro + "Assunto; \n";
		obj_form.stAssunto.focus();
	} 
	
	if(obj_form.stMensagem.value==""){
		strMsgErro = strCabMsgErro + strMsgErro + "Mensagem; \n";
		obj_form.stMensagem.focus();
	}
	
	if(strMsgErro == ""){
		document.frmCases.fgEnvio.value="1";
		document.frmCases.submit();
	}else{
		document.frmCases.fgEnvio.value="0";
		alert(strMsgErro);
		strMsgErro = "";
		return false;	
	}
}

function validateBusca(objForm){
	if(objForm.stParametro.value==""){
		alert("Favor preencher o campo Busca");
		objForm.stParametro.focus();
		return false
	}
}

function validadeEndereco(objForm){
	if(objForm.stUF.value == "" || objForm.idCatRevenda.value==""){
		alert("Favor selecionar algum estado e categoria.");
		objForm.idCatRevenda.focus();
		return false
	}
}

function validateFormContato(obj_form){
	var nmCount1;
	var nmCount2;

	if(obj_form.stNome.value==""){
		alert("Favor preencher o campo NOME corretamente.")
		obj_form.stNome.focus();
		return false;
	}else if(validateRegexEmail(obj_form.stMail.value) == false){
		alert("Favor preencher o campo E-MAIL corretamente.")
		obj_form.stMail.focus();
		return false;
	}else if(obj_form.stDDD.value == ""){
		alert("Favor preencher o campo DDD corretamente.")
		obj_form.stDDD.focus();
		return false;
	}else if(obj_form.stTelefone.value == ""){
		alert("Favor preencher o campo TELEFONE corretamente.")
		obj_form.stTelefone.focus();
		return false;
	}else if(obj_form.stAssunto.value==""){
		alert("Favor preencher o campo ASSUNTO corretamente.")
		obj_form.stAssunto.focus();
		return false;
	}else if(obj_form.stMensagem.value==""){
		alert("Favor preencher o campo MENSAGEM corretamente.")
		obj_form.stMensagem.focus();
		return false;
	}else{
		nmCount1 = document.frmContato.idProduto2.options.length
		nmCount2 = document.frmContato.idProduto4.options.length
		
		window.defaultStatus 	= "Aguarde. Enviando seus dados...";
		document.getElementById("btnSubmit").style.display = "none";
		
		for(var i = 0; i < nmCount1; i++){
			document.frmContato.idProduto2.options[i].selected = true
		}

		for(var i = 0; i < nmCount2; i++){
			document.frmContato.idProduto4.options[i].selected = true
		}

		document.frmContato.fgEnvio.value=1;
		window.setTimeout("document.frmContato.submit();",1500);
	}
	return false;
}

function validateCategoria(obj_form){
	if(obj_form.idCatProduto.value==""){
		alert("Favor selecionar alguma categoria.");
		obj_form.idCatProduto.focus();
		return false;
	}
}

function validateFormCatalogo(obj_form){
	if(obj_form.idCatProduto.value==""){
		alert("Favor selecionar uma categoria");
		obj_form.idCatProduto.focus();
		return false;
	}
}

function validateFormManuais(obj_form){
	if(obj_form.idCatProduto.value==""){
		alert("Favor selecionar uma categoria");
		obj_form.idCatProduto.focus();
		return false;
	}
}

function validateLoginExtranet(objForm){
	objForm.stEmailUsuarioExtranet.value = Trim(objForm.stEmailUsuarioExtranet.value)
	objForm.stSenhaUsuarioExtranet.value = Trim(objForm.stSenhaUsuarioExtranet.value)

	if(validateRegexEmail(objForm.stEmailUsuarioExtranet.value) == false){
		alert("Favor preencher o campo LOGIN corretamente.")
		objForm.stEmailUsuarioExtranet.focus();
		return false;
	}else if(objForm.stSenhaUsuarioExtranet.value == ""){
		alert("Favor preencher o campo SENHA corretamente.")
		objForm.stSenhaUsuarioExtranet.focus();
		return false;
	}else{
		objForm.stAction.value = "Login"
		objForm.submit();
	}
}

function validateLoginExtranetFaqRevenda(objForm) {
    objForm.stEmailUsuarioExtranet.value = Trim(objForm.stEmailUsuarioExtranet.value)
    objForm.stSenhaUsuarioExtranet.value = Trim(objForm.stSenhaUsuarioExtranet.value)

    if (validateRegexEmail(objForm.stEmailUsuarioExtranet.value) == false) {
        alert("Favor preencher o campo LOGIN corretamente.")
        objForm.stEmailUsuarioExtranet.focus();
        return false;
    } else if (objForm.stSenhaUsuarioExtranet.value == "") {
        alert("Favor preencher o campo SENHA corretamente.")
        objForm.stSenhaUsuarioExtranet.focus();
        return false;
    } else {
        objForm.stAction.value = "Login"
        objForm.stFaqRevenda.value = "faqRevenda"
        objForm.submit();
    }
}

function validateRecoveryExtranet(objForm){
	if(validateRegexEmail(objForm.stEmailUsuarioExtranet.value) == false){
		alert("Favor preencher o campo LOGIN corretamente.")
		objForm.stEmailUsuarioExtranet.focus();
		return false;
	}

	objForm.stAction.value = "Recovery"
	objForm.submit();
}

function LTrim(stVar) {
	var re = /\s*((\S+\s*)*)/;
	return stVar.replace(re, "$1");
}

function RTrim(stVar) {
	var re = /((\s*\S+)*)\s*/;
	return stVar.replace(re, "$1");
}

function Trim(stVar){
	stVar = LTrim(RTrim(stVar));
	return stVar.replace(/^\s+|\s+$/g, "");
}

function displayLayer(idLayer){
	document.getElementById(idLayer).style.display = "";
}

function hideLayer(idLayer){
	document.getElementById(idLayer).style.display = "none";
}

function validateFaq(obj_form){
	if(obj_form.idCatProduto.value==""){
		alert("Favor selecionar uma categoria");
		obj_form.idCatProduto.focus();
		return false;
	}
}

function validateCase(obj_form){
	if(obj_form.idCatProduto.value==""){
		alert("Favor selecionar uma categoria");
		obj_form.idCatProduto.focus();
		return false;
	}
}

function validateTemaForum(objForm){
	if(objForm.idForum.value==""){
		alert("Favor selecionar algum tema");
		objForm.idForum.focus();
		return false;
	}
}

function validateTopicoResposta(objForm){
	if(objForm.stResposta.value==""){
		alert("Favor preencher o campo resposta.");
		objForm.stResposta.focus();
		return false;
	}
}

function validateForumSugestao(objForm){
	if(objForm.stNomeForum.value==""){
		alert("Favor preencher o campo nome do fórum.");
		objForm.stNomeForum.focus();
		return false;
	}else if(objForm.stMotivoForum.value==""){
		alert("Favor preencher o campo motivo do fórum.");
		objForm.stMotivoForum.focus();
		return false;
	}
}

function validateTopForum(objForm){
	if(objForm.stNomeTopicoForum.value==""){
		alert("Favor preencher o campo nome do tópico.");
		objForm.stNomeTopicoForum.focus();
		return false;
	}else if(objForm.stDescTopicoForum.value==""){
		alert("Favor preencher a descrição do tópico.");
		objForm.stDescTopicoForum.focus();
		return false;
	}
}

function validateIndicacao(objForm){
	if(objForm.stNomeUsuario.value==""){
		alert("Favor preencher o campo com o seu nome.");
		objForm.stNomeUsuario.focus();
		return false;
	}else if(validateRegexEmail(objForm.stEmailUsuario.value) == false){
		alert("Favor preencher o campo com o seu e-mail corretamente.");
		objForm.stEmailUsuario.focus();
		return false;	
	}else if(objForm.stNomeIndicao.value==""){
		alert("Favor preencher o campo com o nome do destinatário.");
		objForm.stNomeIndicao.focus();
		return false;
	}else if(validateRegexEmail(objForm.stEmailIndicado.value) == false){
		alert("Favor preencher o campo com o e-mail do destinatário corretamente.");
		objForm.stEmailIndicado.focus();
		return false;
	}
}





function abreTopico(stNomeTr, idTr){
	var nmResults;
	nmResults = document.getElementById("nmTotalItens").value;
	
	//alert(stNomeTr + idTr)
	//alert(nmResults)

	if (document.getElementById(stNomeTr + idTr).style.display == "") {
	    document.getElementById(stNomeTr + idTr).style.display = "none";
	}else{

		//alert("Aparece")
		//alert(stNomeTr + idTr)

		for(i = 0; i < nmResults; i++){
			if(idTr != i){
				document.getElementById(stNomeTr+i).style.display = "none";
			}else{
                document.getElementById(stNomeTr + i).style.display = "";
			}
		}
	}
	i 			= 0
	nmResults	= 0
}

//<![CDATA[
function hideDiv(obj) {
   
    if (document.getElementById(obj).style.display == "none") {
        document.getElementById(obj).style.display = "";

    }
    else {
        document.getElementById(obj).style.display = "none";
    }
}
//]]>

//function abreTopico2(stNomeTr2, idTr2) {
//    var nmResults2;
//    nmResults2 = document.getElementById("nmTotalItens2").value;

//   //alert(stNomeTr2 + idTr2);
//   //alert(nmResults2);

//    var obj = stNomeTr2 + idTr2;
//    alert(obj);



//    if (document.getElementById(obj).style.display == "") {
//        document.getElementById(stNomeTr2 + idTr2).style.display = "none";
//    } else {
//        //alert("Aparece")
//        //alert(stNomeTr + idTr)

//        for (j = 0; j < nmResults2; j++) {
//            if (idTr2 != j) {
//                document.getElementById(stNomeTr2 + j).style.display = "none";        

//            } else {
//                document.getElementById(stNomeTr2 + j).style.display = "";
//            }
//        }
//    }
//    j = 0;
//    nmResults2 = 0;
//}

function hideResposta(idTrResposta){
	var nmResults;
	nmResults = document.getElementById("nmTopRespForum").value;

	for(i = 0; i < nmResults; i++){
		try{
			document.getElementById("tr_resp_"+i).style.display = "none";
		}

		catch(exc){
			//alert(exc)
		}
	}
}

function Complete(obj, evt){
	if((!obj) || (!evt) || (arrayProdutos.length == 0)){
		return;
	}

	if (obj.value.length == 0){
		return;
	}
	
	var elm = (obj.setSelectionRange) ? evt.which : evt.keyCode;
	
	if ((elm < 32) || (elm >= 33 && elm <= 46) || (elm >= 112 && elm <= 123)) {
		return;
	}
	
	var txt = obj.value.replace(/;/gi, ",");
	
	elm = txt.split(",");
	txt = elm.pop();
	txt = txt.replace(/^\s*/, "");
	
	if (txt.length == 0) {
		return;
	}
	
	if (obj.createTextRange){
		var rng = document.selection.createRange();
		if (rng.parentElement() == obj) {
			elm = rng.text;
			var ini = obj.value.lastIndexOf(elm);
		}
	}else if(obj.setSelectionRange){
		var ini = obj.selectionStart;
	}
	
	for (var i = 0; i < arrayProdutos.length; i++){
		elm = arrayProdutos[i].toString();
		if(elm.toLowerCase().indexOf(txt.toLowerCase()) == 0){
			obj.value += elm.substring(txt.length, elm.length);
			break;
		}
	}
	
	if(obj.createTextRange){
		rng = obj.createTextRange();
		rng.moveStart("character", ini);
		rng.moveEnd("character", obj.value.length);
		rng.select();
	}else if(obj.setSelectionRange){
		obj.setSelectionRange(ini, obj.value.length);
	}
}

/*  Contato.  */
function carregaProdutosAjax(idCatProduto, nmBox){
	var listBoxProdutos;

	if (nmBox == 1){
		document.frmContato.nmBox.value = "1";
		listBoxProdutos		= document.frmContato.idProduto1;
	}else{
		document.frmContato.nmBox.value = "0";
		listBoxProdutos		= document.frmContato.idProduto3;
	}

	if(idCatProduto == ""){
		alert("Favor selecionar alguma categoria.");
		listBoxProdutos.focus();
	}

	listBoxProdutos.options.length = 0;
	RunAjaxRequest('POST', '../../scripts/xml/xml_produto.asp', 'idCatProduto='+idCatProduto, trataXmlProdutos);
}



/*  Manuais.  */
function carregaProdutos(idCatProduto){
	listProduto		= document.getElementById("idProdutoList");

	if(idCatProduto == ""){
		alert("Favor selecionar alguma categoria.");
		listProduto.disabled=true
		listProduto.focus();
	}

	listProduto.options.length = 0;
	RunAjaxRequest('POST', '../../scripts/xml/xml_produtoManual.asp', 'idCatProduto='+idCatProduto, trataXmlProdutoManual);
}

function carregaProdutosCatalogo(idCatProduto){
	listProduto		= document.getElementById("idProdutoList");

	if(idCatProduto == ""){
		alert("Favor selecionar alguma categoria.");
		listProduto.disabled=true
		listProduto.focus();
	}

	listProduto.options.length = 0;
	RunAjaxRequest('POST', '../../scripts/xml/xml_produtoCatalogo.asp', 'idCatProduto='+idCatProduto, trataXmlProdutoManual);
}

function carregaProdutosComparativo(idCatProduto){
	listProduto		= document.getElementById("idProdutoList");

	if(idCatProduto == ""){
		alert("Favor selecionar alguma categoria.");
		listProduto.disabled=true
		listProduto.focus();
	}

	listProduto.options.length = 0;
	RunAjaxRequest('POST', '../../scripts/xml/xml_produtoComparativo.asp', 'idCatProduto='+idCatProduto, trataXmlProdutoManual);
}

function carregaProdutosInformativos(idCatProduto){
	listProduto		= document.getElementById("idProdutoList");

	if(idCatProduto == ""){
		alert("Favor selecionar alguma categoria.");
		listProduto.disabled=true
		listProduto.focus();
	}

	listProduto.options.length = 0;
	RunAjaxRequest('POST', '../../scripts/xml/xml_produtoInformativo.asp', 'idCatProduto='+idCatProduto, trataXmlProdutoInformativo);
}
function trataXmlProdutoInformativo(objXmlRequest){

	if(objXmlRequest.readyState == 4){
		if (objXmlRequest.status == 200){
			var idProduto;
			var stNomeProduto;

			nmTotalResults 		= objXmlRequest.responseXML.getElementsByTagName("produto").length
			objXml 				= objXmlRequest.responseXML
			listBoxProdutos		= document.getElementById("idProdutoList");
			
			if(nmTotalResults > 0){
				listBoxProdutos.options[listBoxProdutos.options.length] = new Option('Favor selecionar.', 0);
				listBoxProdutos.style.height 	= "20";
				listBoxProdutos.style.width 	= "200";
				listBoxProdutos.disabled 		= false;

				for(i = 0 ; i < nmTotalResults ; i++){
					idProduto    	= (objXml.getElementsByTagName("produto")[i].getElementsByTagName("idProduto")[0].firstChild.nodeValue)
					stNomeProduto   = (objXml.getElementsByTagName("produto")[i].getElementsByTagName("stNomeProduto")[0].firstChild.nodeValue)

					listBoxProdutos.options[listBoxProdutos.options.length] = new Option(stNomeProduto, idProduto);
				}
			}else{
				listProduto.disabled=true
				alert("Não existem informações cadastradas.")
			}	  
		}
	}
}

function trataXmlProdutoManual(objXmlRequest){
	if(objXmlRequest.readyState == 4){
		//document.getElementById("spanMsgAjax").style.display = "";

		if (objXmlRequest.status == 200){
			//window.setTimeout("document.getElementById('spanMsgAjax').style.display = 'none';" , 1450);
			var idProduto;
			var stNomeProduto;

			nmTotalResults 		= objXmlRequest.responseXML.getElementsByTagName("produto").length
			objXml 				= objXmlRequest.responseXML
			listBoxProdutos		= document.getElementById("idProdutoList");
			
			if(nmTotalResults > 0){
				listBoxProdutos.options[listBoxProdutos.options.length] = new Option('Favor selecionar.', 0);
				listBoxProdutos.style.height 	= "20";
				listBoxProdutos.style.width 	= "200";
				listBoxProdutos.disabled 		= false;

				for(i = 0 ; i < nmTotalResults ; i++){
					idProduto    	= (objXml.getElementsByTagName("produto")[i].getElementsByTagName("idProduto")[0].firstChild.nodeValue)
					stNomeProduto   = (objXml.getElementsByTagName("produto")[i].getElementsByTagName("stNomeProduto")[0].firstChild.nodeValue)

					listBoxProdutos.options[listBoxProdutos.options.length] = new Option(stNomeProduto, idProduto);
				}
			}else{
				listProduto.disabled=true
				alert("Não existem informações cadastradas.")
				//objRettAjax.innerHTML = "Não existem produtos.";
				//window.setTimeout("objRettAjax.innerHTML = '';" ,1450);
			}	  
		}
	}
}

function hideComponent(){
	var stRetAjax;
	stRetAjax = document.getElementById("stRetAjax");
	stRetAjax.innerHTML = '';
}

function hideCidades(fgSuporte){
	var selCatRevenda
	selCatRevenda = document.getElementById("idSelCatRevenda")
	
	//document.getElementById("idCidadeEstado").style.display = "none";
	document.getElementById("idCidadeEstado").disabled=true
	
	if(selCatRevenda.value != ""){
		document.getElementById("idUF").disabled = false;
		document.getElementById("idUF").options[0].selected=true;
		document.getElementById("idUF").focus();

		RunAjaxRequest('POST', '../../scripts/xml/xml_estado.asp', 'fgSuporte='+fgSuporte+'&idCatProduto='+selCatRevenda.value, trataXmlEstado);
	}else{
		document.getElementById("idUF").disabled = true;
		selCatRevenda.focus();
	}
}

function trataXmlProdutos(objXmlRequest){
	if(objXmlRequest.readyState == 4){
		//window.setTimeout("imgRetAjax.style.display='none';",1450);
		window.setTimeout("hideComponent();",1250);

		if (objXmlRequest.status == 200){
			var idProduto;
			var stNomeProduto;

			nmTotalResults 	= objXmlRequest.responseXML.getElementsByTagName("produto").length
			objXml 			= objXmlRequest.responseXML
			nmBox 			= document.frmContato.nmBox.value;
			
			if (nmBox == 1){
				objRettAjax  		= document.getElementById("stRetAjax");
				listBoxProdutos		= document.frmContato.idProduto1;
			}else{
				objRettAjax  		= document.getElementById("stRetAjax2");
				listBoxProdutos		= document.frmContato.idProduto3;
			}
			
			if(nmTotalResults > 0){
				for(i = 0 ; i < nmTotalResults ; i++){
					idProduto    	= (objXml.getElementsByTagName("produto")[i].getElementsByTagName("idProduto")[0].firstChild.nodeValue)
					stNomeProduto   = (objXml.getElementsByTagName("produto")[i].getElementsByTagName("stNomeProduto")[0].firstChild.nodeValue)

					listBoxProdutos.options[listBoxProdutos.options.length] = new Option(stNomeProduto, idProduto);
				}
			}else{
				listBoxProdutos.options.length = 0;		

				objRettAjax.innerHTML = "Não existem produtos.";
				window.setTimeout("objRettAjax.innerHTML = '';" ,1450);
			}	  
		}
	}
}

function trataXmlEstado(objXmlRequest){
	if(objXmlRequest.readyState == 4){
		//window.setTimeout("imgRetAjax.style.display='none';",1450);
		//window.setTimeout("hideComponent();",1250);

		if (objXmlRequest.status == 200){
			var stEstadoCidade;

			nmTotalResults 	= objXmlRequest.responseXML.getElementsByTagName("estado").length
			objXml 			= objXmlRequest.responseXML

			//objRettAjax  		= document.getElementById("stRetAjax");
			listBoxEstados		= document.getElementById("idUF");
			listBoxEstados.options.length = 0;

			if(nmTotalResults > 0){
				listBoxEstados.options[listBoxEstados.options.length] = new Option("Favor selecionar", "");
				for(i = 0 ; i < nmTotalResults ; i++){
					stEstadoCidade   = (objXml.getElementsByTagName("estado")[i].getElementsByTagName("stEstadoCidade")[0].firstChild.nodeValue)
					listBoxEstados.options[listBoxEstados.options.length] = new Option(stEstadoCidade, stEstadoCidade);
				}
			}else{
				listBoxEstados.options.length = 0;		

				//objRettAjax.innerHTML = "Não existem produtos.";
				//window.setTimeout("objRettAjax.innerHTML = '';" ,1450);
			}	  
		}
	}
}

function moveSelectItem(fbox, tbox){
	var arrFbox = new Array();
	var arrTbox = new Array();
	var arrLookup = new Array();
	var i;
	for (i = 0; i < tbox.options.length; i++){
		arrLookup[tbox.options[i].text] = tbox.options[i].value;
		arrTbox[i] = tbox.options[i].text;
	}

	var fLength = 0;
	var tLength = arrTbox.length;
	for(i = 0; i < fbox.options.length; i++) {
		arrLookup[fbox.options[i].text] = fbox.options[i].value;
		if (fbox.options[i].selected && fbox.options[i].value != "") {
			arrTbox[tLength] = fbox.options[i].text;
			tLength++;
		}else{
			arrFbox[fLength] = fbox.options[i].text;
			fLength++;
	   }
	}
	
	arrFbox.sort();
	arrTbox.sort();

	fbox.length = 0;
	tbox.length = 0;
	
	var c;
	for(c = 0; c < arrFbox.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrFbox[c]];
		no.text = arrFbox[c];
		fbox[c] = no;
	}

	for(c = 0; c < arrTbox.length; c++){
		var no = new Option();
		no.value = arrLookup[arrTbox[c]];
		no.text = arrTbox[c];
		tbox[c] = no;
	}
}

function openPopFoto(stParametros){
	v_pop = window.open("./extranet_foto.asp?stNomeImagem="+stParametros+"", "New", "height=455,width=780,status=yes,toolbar=no,menubar=no,location=no, scrollbars=yes")
	v_pop.focus();
}

function carregaCidadesAjax(stEstadoCidade, fgSuporte, idCatRevenda){
	RunAjaxRequest('POST', '../../scripts/xml/xml_cidade.asp', 'idCatRevenda='+idCatRevenda+'&stEstadoCidade='+stEstadoCidade+'&fgSuporte='+fgSuporte, trataXmlCidade);
}

function trataXmlCidade(objXmlRequest){
	if(objXmlRequest.readyState == 4){
		if (objXmlRequest.status == 200){
			var stEstadoCidade;

			nmTotalResults 	= objXmlRequest.responseXML.getElementsByTagName("cidade").length
			objXml 			= objXmlRequest.responseXML
			
			listBoxCidade			 = document.getElementById("idCidadeEstado");
			listBoxCidade.disabled = false;
			listBoxCidade.options.length = 0;

			if(nmTotalResults > 0){

				listBoxCidade.options[listBoxCidade.options.length] = new Option("Todas as cidades", "");
				
				for(i = 0 ; i < nmTotalResults ; i++){
					idCidade    	= (objXml.getElementsByTagName("cidade")[i].getElementsByTagName("idCidade")[0].firstChild.nodeValue)
					stNomeCidade   	= (objXml.getElementsByTagName("cidade")[i].getElementsByTagName("stNomeCidade")[0].firstChild.nodeValue)
					
					listBoxCidade.options[listBoxCidade.options.length] = new Option(stNomeCidade, idCidade);
				}
			}else{
				listBoxCidade.options.length = 0;		
			}
		}
	}
}



function openCenterPopup(stUrl, stNomeJanela, stParametros, stLargura, stAltura){
	stParametrosJanela 	= ", width="+stLargura+", height="+stAltura+"";
	stParametros		= stParametros += stParametrosJanela;

	v_pop = window.open(stUrl, stNomeJanela, stParametros)
	
	nmLargura 	= (screen.width - stLargura) / 2; 
	nmAltura 	= (screen.height - stAltura) / 2; 

	v_pop.moveTo(nmLargura, nmAltura);
	v_pop.focus();
}

function validateFormManual(objForm){
	if(objForm.idCatProduto.value == ""){
		alert("Favor selecionar a categoria.");
		objForm.idCatProduto.focus();
		return false;
	}else if(objForm.idProdutoList.value == "" || objForm.idProdutoList.value == "0"){
		alert("Favor selecionar algum produto");
		objForm.idProdutoList.focus();
		return false;
	}
}
function validaCnpj(stCnpj){
	
	var i;
	var c 	= stCnpj.substr(0,12);
	var dv 	= stCnpj.substr(12,2);
	var d1 	= 0;
	
	
	if (stCnpj == ""){
		alert("O Cnpj não foi preenchido.");
		return;
	}else{
		//alert(document.frmRevenda.nmAcao.value)
		for (i = 0; i < 12; i++){
			d1 += c.charAt(11-i)*(2+(i % 8));
		}
		if (d1 == 0){
			alert("O Cnpj informado está inválido.");
			return;
		}
		d1 = 11 - (d1 % 11);
		if (d1 > 9) d1 = 0;
		if (dv.charAt(0) != d1){
			alert("O Cnpj informado está inválido.");
			return;
		}
		d1 *= 2;
		for (i = 0; i < 12; i++){
			d1 += c.charAt(11-i)*(2+((i+1) % 8));
		}
		d1 = 11 - (d1 % 11);
		if (d1 > 9) d1 = 0;
		if (dv.charAt(1) != d1){
			alert("O Cnpj informado está inválido.");
			return;
		}
		
		document.frmRevenda.nmAcao.value=1;
		//alert(document.frmRevenda.nmAcao.value)
		document.frmRevenda.submit();
	}

}

function Tecla(e)
{
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
		if (tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else
			{
				if (tecla != 8) // backspace
					event.keyCode = 0;
					//return false;
				else
					return true;
			}
}

function GoSearch(objForm){
	if(objForm.stParametro.value == "Buscar" || objForm.stParametro.value == "" || objForm.stParametro.value.length < 1 ){
		alert("Favor preencher o campo Busca corretamente com mais de 3 caracteres.");
		objForm.stParametro.focus();
	}else{
		objForm.action = "../Scripts/Busca/resultado.asp"
		objForm.submit();
	}
}

function ChangeCountry(objForm){
	var stDestiny;
	stDestiny = objForm.stCountry.value
	
	if(stDestiny == ""){
		alert("Favor selecionar o seu destino.");
		objForm.stCountry.focus();
		return false;
	}else{
		parent.location.href=(""+stDestiny+"")
		return false;
	}
}

function abreTopicoExtranet(stNomeTr, idTr){
	var nmResults;
	nmResults = document.frmMenuCategorias.nmTotalItens.value;

	if(document.getElementById(stNomeTr+idTr).style.display == ""){
		document.getElementById(stNomeTr+idTr).style.display = "none"
	}else{

		//alert("Aparece")
		//alert(stNomeTr + idTr)

		for(i = 0; i < nmResults; i++){
			if(idTr != i){
				document.getElementById(stNomeTr+i).style.display = "none";
			}else{
				document.getElementById(stNomeTr+i).style.display = "";
			}
		}
	}
	i 			= 0
	nmResults	= 0
}

function ValidateLoginOrg(objForm){
	if(objForm.stLogin.value == ""){
		alert("Favor preencher o campo LOGIN corretamente.")
		objForm.stLogin.focus();
		return false;
	}else if(objForm.stSenha.value == ""){
		alert("Favor preencher o campo SENHA corretamente.")
		objForm.stSenha.focus();
		return false;
	}
}

function abreTopicoInstitucional(stNomeTr, idTr){
	var nmResults;
	nmResults = document.frmBrother.nmTotalItens.value;

	if(document.getElementById(stNomeTr+idTr).style.display == ""){
		document.getElementById(stNomeTr+idTr).style.display = "none"
	}else{

		//alert("Aparece")
		//alert(stNomeTr + idTr)

		for(i = 0; i < nmResults; i++){
			if(idTr != i){
				document.getElementById(stNomeTr+i).style.display = "none";
			}else{
				document.getElementById(stNomeTr+i).style.display = "";
			}
		}
	}
	i 			= 0
	nmResults	= 0
}
