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);

}



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 = "150px";
    if (navigator.appName == 'Microsoft Internet Explorer') {
        topo = document.documentElement.scrollTop;
        if (topo <= 550) {
            div.style.top = "355px";
        } else {
            div.style.top = topo + "px";
        }
    }
    else {
        topo = window.pageYOffset;
        if (topo <= 550) {
            div.style.top = "355px";
        } else {
            div.style.top = topo + "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+$/, "");
}
