function loadCampo(tmp_idSelecionando,tmp_idcampo,tmp_rotina){
	resetSelect(tmp_idcampo);
	var a = new Ajax();
	a.onLoad = function(){
		var str = this.html;
		var campo = document.getElementById(tmp_idcampo);
		var arr = str.split("###");//separa por registro
		var arraux = new Array();
		
		if (str != '') {
			for(var x = 0; x < arr.length; x++){
				arraux = arr[x].split("...");
				
				addOption(campo,arraux[1],arraux[0]);
				if (arraux[0] == '') {
					campo.options[x+2].style.fontWeight = 'bold';
				}
			}
			campo.disabled = '';
		} else {
			addOption(campo,'Nenhum item encontrado','');
			campo.disabled = true;
		}
	}
	a.get('site/inc/routines/routines.php?rotina='+tmp_rotina+'&id_selecionado='+tmp_idSelecionando);
}
function resetSelect(tmp_idcmapo){
	var campo = document.getElementById(tmp_idcmapo);
	for(var x=campo.length-1;x>=2;x--){
		campo.remove(x);
	}
}
function addOption(obj_select,tmp_text,tmp_value){
	var option = document.createElement('option');
	option.value = tmp_value;
	option.text = tmp_text;
	
	try {//outros navegadores
		obj_select.add(option,null);
	} catch(ex) {//para IE
		obj_select.add(option);
	}
}
function loadByCep(cep){
	$("Cidade_CMB1").value = "Buscando...";
	$("Estado_CMB1").value = "Buscando...";
	
	var a = new Ajax();
	a.onLoad = function() {
		arr_retorno = this.html.split("#");
		if($("Cidade_CMB1").value == "Buscando..."){
			alert(arr_retorno[0]);
			$("Cidade_CMB1").value = arr_retorno[0];
		}
		if($("Estado_CMB1").value == "Buscando...")
			$("Estado_CMB1").value = arr_retorno[1];
		
		for(var i = 0; i < $("Cidade_CMB1").length; i++){
		
			if($("Cidade_CMB1").options[i].text == arr_retorno[0]){
				$("Cidade_CMB1").selectedIndex = i;
				break;
			}
		}	
		for(var j = 0; j < $("Estado_CMB1").length; j++){
			if($("Estado_CMB1").options[j].id == arr_retorno[1]){
				$("Estado_CMB1").selectedIndex = j;
				break;
			}
		}
	}
	a.get('site/inc/routines/routines.php?rotina=endereco&cep='+cep);
}
function dropMenu(m){
	if($("m"+m).style.display = "none")
		$("m"+m).style.display = "";
}
function dropMenuOut(m){
	if($("m"+m))
		$("m"+m).style.display = "none";
}
function popLocalizacao(who){
	//var popup = new Popup(635,545);
	var popup = new Popup(650,575);
	popup.open(who);
}

function popZoom(who){
	//var popup = new Popup(635,545);
	var popup = new Popup(413,490);
	popup.open(who);
}
function popZoom2(who){
	//var popup = new Popup(635,545);
	var popup = new Popup(573,430);
	popup.open(who);
}

function buscaTxt(obj, focus){
	if(focus){
		if(obj.value == "Digite aqui o produto desejado"){
			obj.value = "";
		}
	} else {
		if(obj.value == ""){
			obj.value = "Digite aqui o produto desejado";
		}
	}
}
function zoom(args, w, h){//w padrão, h é altura da imagem
	//var p = new Popup(510,h);
	if(h < 230)
		h = 230;
	var p = new Popup(520,h+10);
	p.template = 2;
	p.open("zoomProdutos.php"+args);
}
function zoomImagem(tmp_src,tmp_w,tmp_h){
	/*if(tmp_w == null || tmp_h == null) {
		tmp_w = 500;
		tmp_h = 306;
	}*/
	var p = new Popup(tmp_w,tmp_h);
	p.overflow = 'hidden';
	p.position = "fixed";
	p.open('site/inc/structure/zoom.php?src='+tmp_src+'&w='+tmp_w+'&h='+tmp_h);
}

function aboutList(){
	//var p = new Popup(511,645);
	var p = new Popup(520,655);
	p.template = 2;
	p.position = "fixed";
	p.open("aboutList.php");
}
function enviarLista(){
	var p = new Popup(511,245);
	p.template = 2;
	p.position = "fixed";
	p.open("enviarEmail.php");
}
function addLista(id){
	var a = new Ajax();
	a.onLoad = function () {
		if(this.html != ""){
			if(this.html > 0){
				alert("Produto inseridos com sucesso na sua lista!");
				var img = parent.document.getElementById("IMGconfira_lista");
				if(img)
					img.style.display = "";
			} else {
				alert("Por alguma razão a lista está vazia. Contate os administradores do sistema.");
			}
		} else {
			alert("Desculpe, ocorreu um problema na hora de inserir na lista... por favor, contate os administradores do site.");
		}
	}
	a.get("site/inc/routines/routines.php?rotina=addItemList&item="+id);
}
function openList(){
	window.location = "lista_produto.php";
}
function refreshList(){
	var arrChecks = document.getElementsByName("chkLista");
	var news = "";
	var novo = false;
	for(x=0;x<arrChecks.length;x++){
		if(arrChecks[x].checked){
			if(novo){
				news += ",";
			}
			news += arrChecks[x].value;
			novo = true;
		}
	}
	if(news == ""){
		alert("Por favor, selecione ao menos um item para ser inserido na lista.");
	} else {
		var a = new Ajax();
		a.onLoad = function () {
			if(this.html != ""){
				if(this.html > 0){
					alert("Produto(s) inseridos com sucesso na sua lista!");
					var img = parent.document.getElementById("IMGconfira_lista");
					if(img)
						img.style.display = "";
				} else {
					alert("Por alguma razão a lista está vazia. Contate os administradores do sistema.");
				}
			} else {
				alert("Desculpe, ocorreu um problema na hora de inserir na lista... por favor, contate os administradores do site.");
			}
		}
		a.get("site/inc/routines/routines.php?rotina=addArrayList&listaPro="+news);
	}
}

function str_replace (search, replace, subject, count) {
    j = 0,
    temp = '',
    repl = '',
    sl = 0,        fl = 0,
    f = [].concat(search),
    r = [].concat(replace),
    s = subject,
    ra = r instanceof Array,        sa = s instanceof Array;
s = [].concat(s);
if (count) {
    this.window[count] = 0;
} 
for (i = 0, sl = s.length; i < sl; i++) {
    if (s[i] === '') {
        continue;
    }        for (j = 0, fl = f.length; j < fl; j++) {
        temp = s[i] + '';
        repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
        s[i] = (temp).split(f[j]).join(repl);
        if (count && s[i] !== temp) {                this.window[count] += (temp.length - s[i].length) / f[j].length;
        }
    }
}
return sa ? s : s[0];
}
