var req;

function loadXMLDoc(url) {
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send("");
	}
}

function processReqChange() {
	if(req.readyState == 4) {
		if(req.status == 200) {
			var dados = req.responseText;
			document.getElementById('saibaMaisConteudoTexto').innerHTML = dados;
		} else {
			// ERRO
		}
	}
}

function rand( min, max ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Leslie Hoare
    // *     example 1: rand(1, 1);
    // *     returns 1: 1
 
    if( max ) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    } else {
        return Math.floor(Math.random() * (min + 1));
    }
}

function buscaSaibaMais(tipo,url) {
	var uri = url + "ajax/saibamais.php?rnd=" + rand(0,9999) + "&tipo=" + tipo;
	document.getElementById('saibaMaisConteudoTexto').innerHTML = '<div style="width:100%; margin-top:100px; font-size:14px; font-weight:bold; text-align:center;"><img src=' + url + 'ninui_layout/images/loading.gif> Carregando...</div>';
	if(tipo == "comprar") {
		/*document.getElementById('licomprar').className = 'liAtivo';
		document.getElementById('livender').className = 'liInativo';*/
		document.getElementById('saibaMaisComprar').style.display='block';
		document.getElementById('saibaMaisVender').style.display='none';
	} else {
		/*document.getElementById('licomprar').className = 'liInativo';
		document.getElementById('livender').className = 'liAtivo'*/
		document.getElementById('saibaMaisComprar').style.display='none';
		document.getElementById('saibaMaisVender').style.display='block';
	}
	loadXMLDoc(uri);
}
