// JavaScript Document

/*
Esta manipulação ret_bank (function de retorno enviada pra classe makeHttpRequest na chamada) crossbrowser pega um xml e cria uma tabela em determinado banco com esse xml - crie outras manipulações(functions)
//Para tornar transparente passe o form todo pra hidden e dê um .click no submit. Tem que habilitar o botao no fim do form

function ret_bank(oRet){
var IE = document.all;
	if(IE){
	var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	}else if (document.implementation && document.implementation.createDocument){
	var xmlDoc = document.implementation.createDocument("","",null);	
	}
xmlDoc.async="false";
xmlDoc.load(oRet); //doc xml a ser enviado pro banco
var doc = IE ? xmlDoc.documentElement : oRet.documentElement;//NS:NÃO joga o xmlDoc, mas o parametro do load
var ind = IE ? 0 : 1;
var ind2 = IE ? 1 : 2;
var real_Nodes = 0;
var nodes = doc.childNodes; //;
var nodchilds = new Array;
var reg = "";
var real_reg = "";
var columns = new Array();
var count = 0;
	
	for(v=0;v < nodes[ind].childNodes.length; v++){	//define as cols do banco	
		if(IE && nodes[ind].childNodes[v].tagName != undefined){ columns[v] = nodes[ind].childNodes[v].tagName;
		} else if(nodes[ind].childNodes[v].tagName != undefined){	//fix mozilla,etc...		 
			columns[count] = nodes[ind].childNodes[v].tagName;
			count++;
		}		
	}//fim cols do banco


for(d=0;d < nodes.length; d++){ // criacao dos registros
	if(nodes[d].childNodes.length > 0){
		for(x=0;x < nodes[d].childNodes.length; x++){
			if((nodes[d].childNodes[x].firstChild) && (x == nodes[d].childNodes.length-ind2)){
				reg+=nodes[d].childNodes[x].firstChild.nodeValue;				
				real_reg += reg;	
			}else if(nodes[d].childNodes[x].firstChild) {
				reg+=nodes[d].childNodes[x].firstChild.nodeValue+"##";				
				real_reg += reg;	
			}			
		reg="";				
		}	
	nodchilds.push(real_reg);	
	real_reg="";
	}
}//fim dos registros
	
var rootel = doc.tagName; //esse é o root element do .xml
var lines = new Array;
var myForm = '<form id="myForme" method="post" action="insert_xml.php">';
	

myForm+='<input type="text" size="130" maxlength="100" name="reg0" id="reg0" value="'+rootel+'"><br>';

//define a array lines com um registro(todas as colunas) por índice e joga no hidden um por um
//mainsub_numchilds += 2; 
	for(z=0;z < nodchilds.length; z++){		
	var oLine = "";
	oLine=nodchilds[z];			
	lines[z] = oLine;
	myForm+='<input type="text" size="230" maxlength="250" name="reg'+(z+1)+'" id="reg'+(z+1)+'" value="'+lines[z]+'"><br>';
		
	}

for(n=0;n < columns.length; n++){
	myForm+='<input type="text" size="30" maxlength="100" name="'+columns[n]+'" id="'+columns[n]+'"value="colll#'+columns[n]+'"><br>';
}

//myForm+='<input id="sendit" type="submit" value="enviar"></form>';

$GEBId("retbl").innerHTML = myForm;
}//mainfunc

*/



/*

Esta manipulação logfunc recebe o retorno da busca no banco de dados por login e senha:
o parametro oRet (um integer) pode ser:
1 // login inválido
2// senha não confere
3 // campos em branco ao logar
ou 4 // tudo certo

*//*
function logfunc(oRet){//manipula como desejar a resposta do ajax/servidor
	
	//if(oRet.match(/#/)){
	//	var logg = oRet.split("#");
	//}
	if(oRet.match(/#/)) var logg = oRet.split("#");	
	if(oRet == 1){ $GEBId('answer').innerHTML = "Login inválido"; $GEBId('f1').login.value=''; $GEBId('f1').login.focus(); return;}
	if(oRet == 2){ $GEBId('answer').innerHTML = "Senha inválida"; $GEBId('f1').sen.value=''; $GEBId('f1').sen.focus(); return;}
	if(oRet == 3){ $GEBId('answer').innerHTML = "Login e Senha obrigatórios"; return;}	
	if(logg) location.href="http://localhost/ajax/ajax_full/rss/feed_reader.php?leap="+logg[1];	
		
}


bom de ter pronto - nao utilizado neste aplicativo - tem q fazer crossbrowser!!!

function initiFrame(oSrc, oStyle) {
  var testFrame = document.createElement("IFRAME");
  testFrame.id = "testFrame";
  testFrame.src = oSrc;
  testFrame.style = oStyle ? oStyle : "";
  document.body.appendChild(testFrame);
}
bom de ter pronto FIM




*/

//+"  ---  "+threecontents[1]+"  ---  "+threecontents[2]+"  ---  "+threecontents[3]
function cardsfunc(oRet){
	var threecontents = "";
	//alert("oRet: "+oRet);
	
		if(oRet.match("#w#w#")){
			
		threecontents = oRet.split("#w#w#");
		
		addcontents = threecontents[2].split("@ADDIMG@"); 		
		
		// se nao tiver imagem/banner topo (altura-largura) seta para 5
		if(addcontents[1] == "") addcontents[1] = "5"; 
		if(addcontents[2] == "") addcontents[2] = "5";
		
		
		//alert(addcontents[0]);
		if(addcontents[0] != ""){
		$GEBId("add_pic").src=addcontents[0];// imagem do anuncio
		$GEBId("add_pic").style.width=addcontents[1]+"px";	// largura
		$GEBId("add_pic").style.height=addcontents[2]+"px"; // altura
		}
		
		$GEBId("contents").innerHTML = threecontents[0]; // os produtos
		if(threecontents[1] != 0) eval(threecontents[1]); // os scripts
	
		
	
	//////////////////  FROM MERC PART 1 ////////////////////////
	/*if(threecontents[3] && threecontents[3] != 0){
		
		if(threecontents[2] == 55) $GEBId("listdireita").innerHTML = ""; //	
		$GEBId("bigtitle").innerHTML = threecontents[3];
	}*/
	
	/*if(threecontents[4] && threecontents[4] != 0){
		//alert(threecontents[4]);
	var clean = threecontents[4].replace(/XW#3X$/,"");	
	inserts = clean.split("XW#3X");
		//alert("ins.len: "+inserts.length);
		var numpaycards = (inserts.length) / 4;
		var q = 0;
		for(z=0;z < numpaycards;z++){
			for(p=1;p < 5;p++){	//este 5 é 0 numero de abas(4). deve ser definido em constante			
			eval('fill_'+(z+1)+'_'+p+'="'+inserts[q]+'";');
			q++;
			}
		
		//tirar " na parte esq da atribuição acima. já vem com " deve dar pra deixar as aspas do texto			
		}
		
		if(threecontents[5] == "gm" || threecontents[6]) var gm = 1; else var gm = 0;
		firstInsert(numpaycards,gm);
		
	}
	
	if(threecontents[5] && threecontents[5] != 0 && threecontents[5] != "gm"){
		
	$GEBId("listdireita").innerHTML = threecontents[5];	
		
	}
		
	if(threecontents[6]){
	$GEBId("selechoods").innerHTML = "";
	$GEBId("selechoods").innerHTML = threecontents[6];	
		
	}
	
	if(threecontents[7]){
		
	$GEBId("seleclocs").innerHTML = threecontents[7];	
		
	}
	
	if(threecontents[2] != 0 && threecontents[2] != 55) gt(threecontents[2]);*/
	/////////////////  FIM FROM MERC PART 1 ////////////////////////
	
	
	
	
		}else{ // if not match  #w#w#
		
		threecontents = oRet.split("#Q#Q#");			
		$GEBId("contents").innerHTML = threecontents[0];		
		if(threecontents[1] != 0 && typeof threecontents[1] != "undefined"){
		var clean = threecontents[1].replace(/XW#3X$/,"");	
		inserts = clean.split("XW#3X");
		
		//var numpaycards = (inserts.length) / 4;
		var q = 0;
		for(z=0;z < 1;z++){
			for(p=1;p < 5;p++){	//este 5 é 0 numero de abas(4). deve ser definido em constante			
			eval('fill_'+(z+1)+'_'+p+'="'+inserts[q]+'";');
			q++;
			}
		}
		
	}
	var gm = threecontents[2] ? 1 : 0;
	//alert(gm);
	//firstInsert(1,gm);
}

}
/*
function cardsextends(oRet){//cotacoes.php

//alert(oRet);
	elTwo = oRet.split("#XlCot22#");		
	$GEBId("extendscot").innerHTML=elTwo[0];
	$GEBId("extendscot").style.display="";
	$GEBId("elnombre").innerHTML=elTwo[5]+"<br />"+elTwo[1];
	$GEBId("categcontent").innerHTML=elTwo[2];
	if($GEBId("artcontent")) $GEBId("artcontent").innerHTML=elTwo[3];
	if($GEBId("lotcontent")) $GEBId("lotcontent").innerHTML=elTwo[4];
}


function mercfunc(oRet){
	//alert("oRet: "+oRet);
	if(oRet.match("#w#w#")){
	threecontents = oRet.split("#w#w#");
	//alert(threecontents[0]);
	$GEBId("contents").innerHTML = threecontents[0];
	eval(threecontents[1]);
	//alert(threecontents[2]+"  ---  "+threecontents[3]);
	}else{
		
		$GEBId("content").innerHTML = oRet;
	}
}
*/
function retInsAction(oRet){
	//alert("oRet: "+oRet);
	//return;
	var thesplit = oRet.split("##");	
	var final_oRet = thesplit[0];
	//alert(thesplit[1]);
	$GEBId("retaction_"+thesplit[1]).innerHTML = final_oRet;
}//func


function retSubProdAction(oRet){ // retorno de setCatSub
//alert("oRet: "+oRet);
var thesplit = oRet.split("###");
var oTipo = thesplit[1]; // eh subctaeg ou eh lista de produtos
//alert(thesplit[0]);
if(oTipo == "sub") $GEBId("elsubcats").innerHTML = thesplit[0];
else if(oTipo == "prod") $GEBId("elprods").innerHTML = thesplit[0];
else  $GEBId("elsubcats2").innerHTML = thesplit[0];
}


function retLimpaNots(oRet){
	
	$GEBId("newsresult").innerHTML = oRet;
	
}






//ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ   mercado way ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

function habdesabAction(oRet){
	//alert("oRet: "+oRet);
	//return;
	//var thesplit = oRet.split("##");	
	//var final_oRet = thesplit[0];
	//alert(thesplit[1]);
	$GEBId("resp_desab").innerHTML = oRet;
}//func


function divformsfunc(oRet){
	//alert("oRetdivsform: "+oRet);
	//return;
	$GEBId("respmail").style.display = "";
	$GEBId("respmail").innerHTML = oRet;
}//func


function retCollectAction(oRet){
	
	
	var listitems = oRet.split("_");
	var oTab = listitems[listitems.length-1];
	
	
	
	/*if(oTab.match(/pc/)){
	$GEBId("card_id").value = listitems[0];	
	$GEBId("artista_pcatu").value = listitems[1];
	$GEBId("expo_pcatu").value = listitems[2];
	$GEBId("local_pcatu").value = listitems[3];
	$GEBId("sigla_pcatu").value = listitems[4];
	$GEBId("texto_pcatu").value = listitems[5];
	$GEBId("days_pcatu").value = listitems[6];	
	$GEBId("rua_pcatu").value = listitems[7];
	$GEBId("num_pcatu").value = listitems[8];
	$GEBId("comp_pcatu").value = listitems[9];
	$GEBId("bairro_pcatu").value = listitems[10];
	$GEBId("cidade_pcatu").value = listitems[11];
	$GEBId("uf_pcatu").value = listitems[12];
	$GEBId("tel_pcatu").value = listitems[13];
	$GEBId("price_pcatu").value = listitems[14];
	$GEBId("parking_pcatu").value = listitems[15];
	$GEBId("about_artista_pcatu").value = listitems[16];	
	$GEBId("about_expo_pcatu").value = listitems[17];
	$GEBId("assinatura_pcatu").value = listitems[20];
	$GEBId("patros_pcatu").value = listitems[18];
	$GEBId("apoio_pcatu").value = listitems[19];
	$GEBId("assinatura_pcatu").value = listitems[25];
	//$GEBId("ste_pcatu").value = listitems[20];
	
	temp = listitems[22].split("-");
	newdateini = temp[2]+"-"+temp[1]+"-"+temp[0];
	temp = listitems[23].split("-");
	newdatefim = temp[2]+"-"+temp[1]+"-"+temp[0];
	
	$GEBId("inicio_pcatu").value = newdateini;
	$GEBId("fim_pcatu").value = newdatefim;
	
	if(listitems[24] == "S") document.form_atu_pc.typecard_pcatu[1].click();
	else document.form_atu_pc.typecard_pcatu[0].click();
	document.form2.imgid.value = listitems[0];
	}*/
		
	if(oTab.match(/products/)){	
	
	//alert(listitems[7]+" - "+listitems[8]+" - "+listitems[9]+" - "+listitems[10])
	
	$GEBId("prod_id").value = listitems[0];
	$GEBId("name_prodatu").value = listitems[1];
	$GEBId("brand_prodatu").value = listitems[2];
	$GEBId("price_prodatu").value = listitems[3];
	$GEBId("descri_prodatu").value = listitems[4];
	$GEBId("selcategs").value = listitems[5];
	$GEBId("subcategory_prodatu").value = listitems[6];
	//$GEBId("selcategs").value = listitems[5];
	//$GEBId("subcat").value = listitems[6];
	if(listitems[8] == 'S') $GEBId("exclusive_prodatu").checked = true;
	else $GEBId("exclusive_prodatu").checked = false;
	
	if(listitems[9] == 'S') $GEBId("promo_prodatu").checked = true;
	else $GEBId("promo_prodatu").checked = false;
	
	if(listitems[7] == 'S') $GEBId("new_prodatu").checked = true;
	else $GEBId("new_prodatu").checked = false;
	
	if(listitems[10] == 'S') $GEBId("espec_prodatu").checked = true;
	else $GEBId("espec_prodatu").checked = false;
	
	if(listitems[11] == 'S') $GEBId("wait_prodatu").checked = true;
	else $GEBId("wait_prodatu").checked = false;
	//$GEBId("wait_prodatu").value = listitems[11];
	//$GEBId("site_prodatu").value = listitems[11];	
	//$GEBId("about_artist_prodatu").value = listitems[12];
	
		
		document.form1.imgid.value = listitems[0];
	}
	
	
	
			
	/*if(oTab.match(/mix1/)){
	$GEBId("card_id").value = listitems[0];
	$GEBId("nome_gmixatu").value = listitems[1];
	$GEBId("rua_gmixatu").value = listitems[2];
	$GEBId("num_gmixatu").value = listitems[3];
	$GEBId("comp_gmixatu").value = listitems[4];
	$GEBId("bairro_gmixatu").value = listitems[5];
	$GEBId("cidade_gmixatu").value = listitems[6];
	$GEBId("uf_gmixatu").value = listitems[7];
	$GEBId("tel_gmixatu").value = listitems[8];
	$GEBId("days_gmixatu").value = listitems[9];
	$GEBId("parking_gmixatu").value = listitems[10];
	$GEBId("contact_gmixatu").value = listitems[19];
	$GEBId("email_gmixatu").value = listitems[11];
	$GEBId("site_gmixatu").value = listitems[12];
	$GEBId("about_card_gmixatu").value = listitems[13];	
	
	if(listitems[14] == "S") document.form_atu_gmix.typecard_gmixatu[1].click();
	else document.form_atu_gmix.typecard_gmixatu[0].click();
	document.form2.imgid.value = listitems[0];
		
	}
	
	if(oTab.match(/mix2/)){
		//alert("pop");
	$GEBId("card_id").value = listitems[0];
	$GEBId("nome_gmixatu").value = listitems[1];
	$GEBId("rua_gmixatu").value = listitems[2];
	$GEBId("num_gmixatu").value = listitems[3];
	$GEBId("comp_gmixatu").value = listitems[4];
	$GEBId("bairro_gmixatu").value = listitems[5];
	$GEBId("cidade_gmixatu").value = listitems[6];
	$GEBId("uf_gmixatu").value = listitems[7];
	$GEBId("tel_gmixatu").value = listitems[8];
	$GEBId("days_gmixatu").value = listitems[9];
	$GEBId("parking_gmixatu").value = listitems[10];
	$GEBId("contact_gmixatu").value = listitems[11];
	$GEBId("email_gmixatu").value = listitems[12];
	$GEBId("site_gmixatu").value = listitems[13];
	$GEBId("about_card_gmixatu").value = listitems[14];	
	//alert(listitems[10]);
	if(listitems[15] == "S") document.form_atu_gmix.typecard_gmixatu[1].click();
	else document.form_atu_gmix.typecard_gmixatu[0].click();
	document.form2.imgid.value = listitems[0];
	}		
	
	
	
	$GEBId("card_id").value = listitems[0];
	$GEBId("leilao_cotatu").value = leila;
	$GEBId("uf_cotatu").value = listitems[2];
	$GEBId("mes_cotatu").value = listitems[3];
	$GEBId("ano_cotatu").value = listitems[4];
	$GEBId("dias_cotatu").value = listitems[5];
	$GEBId("diasexpo_cotatu").value = listitems[6];
	$GEBId("nome_cotatu").value = listitems[7];
	$GEBId("tecnica_cotatu").value = listitems[8];
	$GEBId("assinatura_cotatu").value = listitems[9];
	$GEBId("data_cotatu").value = listitems[10];
	$GEBId("medidas_cotatu").value = listitems[11];
	$GEBId("estimativa_cotatu").value = listitems[12];
	$GEBId("day_cotatu").value = listitems[13];
	
	
	//temp = listitems[7].split("-");
	//newdatecot = temp[2]+"-"+temp[1]+"-"+temp[0];	
	
	
	
	$GEBId("descricao_cotatu").value = listitems[14];
	
	
	$GEBId("nlote_cotatu").value = listitems[15];
	$GEBId("ultreal_cotatu").value = listitems[16];
	$GEBId("ultdollar_cotatu").value = listitems[17];
	$GEBId("category_cotatu").value = listitems[18];
	
	//alert(listitems[10]);
	//if(listitems[15] == "S") document.form_atu_gmix.typecard_cotatu[1].click();
	//else document.form_atu_gmix.typecard_cotatu[0].click();
	document.form2.imgid.value = listitems[0];
	}		*/
				
	
}



function retpasslei(oRet){
	//alert(oRet);
	if(oRet == "tru") light('inslei');
	else {alert("Senha inválida"); return false;}
}

function infocolors(oRet){
	//alert(oRet);
	var temp = oRet.split("##");
	
	answer = temp[0];
	whr = temp[1];
	
	$GEBId(whr).innerHTML=answer;
	
	
	
}


function nothing(){}
//oRet alert(oRet);

// support functions
function $GEBId(id,doc) { return (doc || document).getElementById(id); } // evita a declaração document.getElementById(id).etc... para cada elemento com que se deseja trabalhar 
function $GEBTn(nome,doc) { return (doc || document).getElementsByTagName(nome); }//evita a declaração document.getElementsByTagName(nome).etc...



/*function setLeftRightNum(){ 
alert("Hellooo!");
	if("zeroR"== "zeroR"){
		$GEBId("arrow_right").innerHTML="&nbsp;";
		$GEBId("arrow_left").innerHTML="&nbsp;";
		}else{
		$GEBId("arrow_right").innerHTML="direction_right";
		$GEBId("arrow_left").innerHTML="direction_left";
			if(document.hidform.page_nums_j.value > 0){
				document.hidform.page_nums_jL.value = document.hidform.page_nums_j.value - 1;
				document.hidform.page_nums_j.value="page_nums_temp";
			}
	}
}
		setLeftRightNum();
		*/