function mudarestadoselecaocliente_prehome() {
    var mylist = document.getElementById("comboEstadoSelecaoCliente");
    var val = mylist.options[mylist.selectedIndex].value;
    wsLoadData('mudarestadoselecaocliente_prehome', 'GET', '/ws/wsGeral.asmx/mudarestadoselecaocliente?id=' + val);
}

function mudarestadoselecaocliente_prehomeVolta(dados) {
    window.location.href = '/default.aspx?ref=preHome';
}



function mudarestadoselecaocliente() {
    var mylist = document.getElementById("comboEstadoSelecaoCliente");
    var val = mylist.options[mylist.selectedIndex].value;
    wsLoadData('mudarestadoselecaocliente', 'GET', '/ws/wsGeral.asmx/mudarestadoselecaocliente?id=' + val);
}
function mudarestadoselecaoclientemodal() {
    var mylist = document.getElementById("comboEstadoSelecaoClienteModal");
    var val = mylist.options[mylist.selectedIndex].value;
    wsLoadData('mudarestadoselecaocliente', 'GET', '/ws/wsGeral.asmx/mudarestadoselecaocliente?id=' + val);
}


function mudarestadoselecaoclienteVolta(dados) {
    window.location.href = unescape(window.location).replace('neb=', '');  
}


function mudarestadoselecaocliente_escolher() {
    var valor = getCookieSubValue('tmp', 'ebcmb');
    if (valor == '')
        valor = '3';
    trocarOpcaoCombo_usandoValue(valor, 'comboEstadoSelecaoCliente');
}


function trocarOpcaoCombo_usandoValue(valor, idControle) {

    var objSel = document.getElementById(idControle);
    for (i = 0; i < objSel.length; i++) {

        if (objSel.options[i].value.toUpperCase() == valor.toUpperCase()) {
            objSel.selectedIndex = i;
            break;
        }
    }

}



function trocarOpcaoCombo(valor, idControle) {
    var objSel = document.getElementById(idControle);
    for (i = 0; i < objSel.length; i++) {
        qtd = valor.length;
        if (objSel.options[i].text.substring(0, qtd).toUpperCase() == valor.toUpperCase()) {
            objSel.selectedIndex = i;
            break;
        }
    }
}



function trocarFoto(controle,caminho) {
	document.getElementById(controle).src=caminho;
}

function trocarLink(controle,caminho) {
	document.getElementById(controle).href=caminho;
}


function wsLoadData(acao,metodo, URL, parametros) {

// alert('chamando wsLoadData inicio da funcao.');

// Create the XML request
    xmlReq = null;
    if(window.XMLHttpRequest) xmlReq = new XMLHttpRequest();
    else if(window.ActiveXObject) xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
    if (xmlReq == null) return; // Failed to create the request

// Anonymous function to handle changed request states
    xmlReq.onreadystatechange = function()
    {
        switch(xmlReq.readyState)
        {
        case 0: // Uninitialized
            break;
        case 1: // Loading
            break;
        case 2: // Loaded
            break;
        case 3: // Interactive
            break;
        case 4: // Done!
			// Retrieve the data between the <quote> tags
			wsDoSomethingWithData(xmlReq.responseXML.getElementsByTagName('string')[0].firstChild.data,acao);
            break;
        default:
            break;
        }
    }

	// Make the request
    xmlReq.open (metodo, URL, true);

	if(parametros=='')
		xmlReq.send (null);
	else
		xmlReq.send (parametros);

}

function wsDoSomethingWithData(datastr,acao) {

    if (acao == 'navprod')
        mostraNavProdVolta(datastr);
   
    if (acao == 'zoom')
        trocarCorVolta(datastr);
        
    if (acao == 'sacola')
        incluirSacolaVolta(datastr);

    if (acao == 'cep')
        recuperarCepVolta(datastr);

    if (acao == 'combina')
        combinaComVolta(datastr);

    if (acao == 'tamanho')
        tamanhoVolta(datastr);

    if (acao == 'mudarestadoselecaocliente')
        mudarestadoselecaoclienteVolta(datastr);

    if (acao == 'mudarestadoselecaocliente_prehome')
        mudarestadoselecaocliente_prehomeVolta(datastr);

}



function mostraNavProd(idProduto,idCor) {
    wsLoadData('navprod', 'GET', '/ws/wsProdutos.asmx/navProd?idCor='+idCor+'&idProduto=' + idProduto);
}

function mostraNavProdVolta(dados) {
    document.getElementById('navProd').innerHTML = dados;
    posDiv('navProd');
}

function escondeNavProd() {
    hL('navProd');
}


















function changeBorder(object, classe) {
    obj = document.getElementById(object);
    obj.className = classe;
}

function sL(object) {
    if (document.getElementById(object) != null )  {
        obj = document.getElementById(object).style; 
        obj.display = "block";
    }
}
function hL(object) {
    if (document.getElementById(object) != null )  {
        obj = document.getElementById(object).style; 
        obj.display = "none";
    }
}

function hLall() {
    for (x = 1; x <= tabs; x++) {
		tab = "tab0" + x;
		obj = document.getElementById(tab);
		obj.style.display = "none";
	}
}

function showHide(object) {
    obj = document.getElementById(object).style;
    obj.display = obj.display == "block" ? "none" : "block";
} 

function getChars(object,object2) {
    obj = document.getElementById(object);
    obj.innerHTML = object2.innerHTML;
}

function ativaFundo(object,classe) {
	obj = document.getElementById(object);
	obj.className = classe;
}

function desativaTodos() {
	for(i = 1; i <= tabItens; i++) {
		coluna = "tabItem0" + i;
		document.getElementById(coluna).className = "";
	}
}

function contador(campo) {
    if((campo.value.length) >= caracteres) {
        campo.value = campo.value.substr(0,caracteres);
    }
    document.getElementById("count").innerHTML = caracteres-campo.value.length
}

function posDiv_antigo(object) {
    div = document.getElementById(object);
    esq = div.style.left = "150px";
    topo = window.pageYOffset;
    if (topo <= 550) {
        div.style.top = "355px";
    } else {
        div.style.top = topo + "px";
    }
    sL(object);
}

function posDiv(object) {
    var topo;
    div = document.getElementById(object);
    esq = div.style.left = "50px";
    if (navigator.appName == 'Microsoft Internet Explorer') {
        topo = document.documentElement.scrollTop;
        if (topo <= 550) {
            div.style.top = "300px";
        } else {
            div.style.top = (topo-100) + "px";
        }
    }
    else {
        topo = window.pageYOffset;
        if (topo <= 550) {
            div.style.top = "300px";
        } else {
            div.style.top = (topo-100) + "px";
        }
    }
    sL(object);
}

function geraFlash($arquivo, $largura, $altura) {
    document.writeln('<object type="application/x-shockwave-flash" data="' + $arquivo + '" width="' + $largura + '" height="' + $altura + '">');
    document.writeln('<param name="movie" value="' + $arquivo + '" />');
    document.writeln('<param name="menu" value="false" />');
    document.writeln('<param name="quality" value="high" />');
    document.writeln('<param name="wmode" value="transparent" />');
    document.writeln('</object>');
}



//trim completo
function trim(str) {
    return str.replace(/^\s+|\s+$/g, "");
}

//left trim
function ltrim(str) {
    return str.replace(/^\s+/, "");
}

//right trim
function rtrim(str) {
    return str.replace(/\s+$/, "");
}





function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function getCookieSubValue(c_name, c_subname) {

    var valcookie = getCookie(c_name);

    chaves = (unescape(valcookie)).split("&")
    for (i = 0; i < chaves.length; i++) {
        chaves[i] = chaves[i].split("=");
        if (chaves[i][0] == c_subname) return (chaves[i][1]);
    }
    return ""
}

/* para trocar a imagem na listagem */
function rollOverImage(imageElem, cache_image_url, event) {
    imageElem.src = cache_image_url;
}




function exibirModalBloqueio() {
    var id = '#dvAvisosBloq';
    var maskWidth = '100%'; /* $(window).width(); */
    var maskHeight = $(document).height();
    var alturaJanela = $(window).height();
    var alturaClick = 0;
    var scrolTop = $(window).scrollTop()
    $('#mascaraBloqueio').css({ 'width': maskWidth, 'height': maskHeight });
    $('#mascaraBloqueio').fadeIn(1000);
    $('#mascaraBloqueio').fadeTo("slow", 0.8);
    var winH = (((alturaClick - (alturaJanela)) / 2) + (scrolTop) + (alturaJanela / 2));
    var winW = $(window).width();
    $(id).css('top', (winH - ($(id).height() / 2) + 300)); // +400 fmc
    $(id).css('left', winW / 2 - $(id).width() / 2);
    $(id).fadeIn(2000);
}

