/* The following function creates an XMLHttpRequest object... */


function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* You can get more specific with version information by using 
	parseInt(navigator.appVersion)
	Which will extract an integer value containing the version 
	of the browser being used.
*/
/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 

/* Function called to get the product categories list */
function getLink(quallink,cod){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will 		
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
        var cod;
        var quallink;

        
            var qqq =  quallink +'.php?cod='+ cod;
//           window.alert(qqq);
            http.open('get', qqq);




	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts;
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}



function getFiltroBairro(quallink,cod){

        var cod;
        var quallink;
        var qqq =  quallink +'.php?cod_bairro='+ cod;
//           window.alert(qqq);
        http.open('get', qqq);

	http.onreadystatechange = handleProducts;
	http.send(null);
}


function getFiltroComer(quallink,cod){

        var cod;
        var quallink;
        var qqq =  quallink +'.php?tipo_comercializacao='+ cod;
//           window.alert(qqq);
        http.open('get', qqq);

	http.onreadystatechange = handleProducts;
	http.send(null);
}

function getImob(qualimob){

    http.open('get', '_classimob/imob_request.php?cod='+ qualimob);
	http.onreadystatechange = handleProducts;
	http.send(null);
}

function editCorretor(qualcorretor){

    http.open('get', 'corretor_request.php?cod='+ qualcorretor);
	http.onreadystatechange = handleProducts;
	http.send(null);
}

function editBairro(qualbairro){

    http.open('get', 'bairro_request.php?cod='+ qualbairro);
	http.onreadystatechange = handleProducts;
	http.send(null);
}
function editTipo_imovel(qualtipo){

    http.open('get', 'tipo_imovel_request.php?cod='+ qualtipo);
	http.onreadystatechange = handleProducts;
	http.send(null);
}


function editImovel(qualimovel){

    http.open('get', 'imovel_request.php?cod='+ qualimovel);
	http.onreadystatechange = handleProducts;
	http.send(null);
}
/*
function excluirFoto(qualfoto){
    var choice2 = window.confirm("Deseja excluir essa foto ?");

    if (choice2) {
    http.open('get', 'excluir_foto.php?cod='+ qualfoto);
	http.onreadystatechange = handleProducts;
	http.send(null);
	
	} else {
        return false;
    }
}
*/

function excluir(cod,campo,tabela){
    var choice = window.confirm("Deseja excluir esse item ?");

    if (choice) {
        http.open('get', 'exclui.php?cod='+ cod +'&campo=' + campo +'&tabela=' + tabela);
        http.onreadystatechange = handleProducts;
        http.send(null);
        
    } else {
        return false;
    }

}




/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleProducts(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 1){ 
		var response = "Carregando ...";
		document.getElementById('details').innerHTML = response;

	}
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		document.getElementById('details').innerHTML = response;
	}
}


function lista_imoveis(){
	if(http.readyState == 1){
		var response = "Carregando ...";
		document.getElementById('lista_imoveis').innerHTML = response;
	}
	if(http.readyState == 4){
		var response = http.responseText;
		document.getElementById('lista_imoveis').innerHTML = response;
	}
}




function getValores(quallink){

         jsqual_bairro = document.forms[0].qual_bairro.value;
         jsqual_comerc = document.forms[0].qual_comerc.value;
         jsqual_tipo_imovel = document.forms[0].qual_tipo_imovel.value;
         jsqual_valor = document.forms[0].qual_valor.value;


        var quallink;
        var qqq =  quallink +'.php?cod_bairro='+ jsqual_bairro +'&tipo_comercializacao=' + jsqual_comerc + '&tipo_imovel=' + jsqual_tipo_imovel + '&valor=' + jsqual_valor;
//        window.alert(qqq);

        http.open('get', qqq);

	http.onreadystatechange = handleProducts;
	http.send(null);



}




