/* this file: functions.js 
General AJAX functions to control website
Author: Fernando Teodoro teodoro dot f at gmail dot com
Last revision: mar 25, 2010
*/

function comboParceiros() {
	var xmlHttp=GetXmlHttpObject();
	var categoria_id = document.getElementById("categoria_id").value;
	
	var url="ajax_combo_parceiros.php?categoria_id="+categoria_id;
	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);

	var resposta = xmlHttp.responseText;
	resposta = resposta.replace(/\+/g," ");
    resposta = unescape(resposta);

	document.getElementById('parceiros_lista').innerHTML = resposta;
}


function showDiv() {
	var xmlHttp=GetXmlHttpObject();
	
	var ytLink = "http://www.youtube.com/v/Sca-ePxw2Kc?version=3&feature=player_detailpage&autoplay=1&rel=0";
	var resposta = "<br>";
	var resposta = resposta + "<object style='height: 390px; width: 640px'>";
	var resposta = resposta + "<param name='movie' value='"+ytLink+"'>";
	var resposta = resposta + "<param name='allowFullScreen' value='true'>";
	var resposta = resposta + "<param name='allowScriptAccess' value='always'>";
	var resposta = resposta + "<embed src='"+ytLink+"' type='application/x-shockwave-flash' allowfullscreen='true' allowScriptAccess='always' width='640' height='360'>";
	var resposta = resposta + "</object>";
	var resposta = resposta + "<div style='margin: 20px auto;'><a href='Javascript:hideDiv();'><img src='img/close_video.jpg' border='0' alt='fechar vídeo'></a></div>";
	
	
	document.getElementById('popupHome').innerHTML = resposta;	
	/* document.getElementById('hideshow').style.visibility = "visible"; */
	document.getElementById('hideshow').style.display = "block";
	
}

function hideDiv() {
	/* document.getElementById('hideshow').style.display = "none"; */
	document.location.reload();
}

function closePopUp() {
	document.getElementById('hideshow').style.display = "none"; 
}

function clearInput(fieldname) {
	document.getElementById(fieldname).value = "";
	document.getElementById(fieldname).style.color = "#000";
}

function tipoImovel(tipo) {
	var xmlHttp=GetXmlHttpObject();

	document.getElementById('tipoimovel').value = tipo;	
	document.forms['form_home'].submit();
}


/* ----------------------- daqui prá baixo tá sem uso ------------------------------- */
function popup_cod_add(module,return_url) {
	var xmlHttp=GetXmlHttpObject();
	
	var url="popup_cod_add.php?return_url="+return_url;
	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);

	var resposta = xmlHttp.responseText;
	resposta = resposta.replace(/\+/g," ");
    resposta = unescape(resposta);
	
	document.getElementById('popup_add').innerHTML = resposta;
	document.getElementById('popup_add').style.visibility = "visible";
}

function popup_contato_add() {
	var xmlHttp=GetXmlHttpObject();
	
	var url="popup_contato_add.php";
	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);

	var resposta = xmlHttp.responseText;
	resposta = resposta.replace(/\+/g," ");
    resposta = unescape(resposta);
	
	document.getElementById('popup_contato_add').innerHTML = resposta;
	document.getElementById('popup_contato_add').style.visibility = "visible";
}

function popup_contato_edit(id) {
	var xmlHttp=GetXmlHttpObject();
	
	var url="popup_contato_edit.php?id="+id;
	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);

	var resposta = xmlHttp.responseText;
	resposta = resposta.replace(/\+/g," ");
    resposta = unescape(resposta);
	
	document.getElementById('popup_contato_add').innerHTML = resposta;
	document.getElementById('popup_contato_add').style.visibility = "visible";
}

function popup_visita(codigo) {
	var xmlHttp=GetXmlHttpObject();
		
	var url="popup_visita.php?codigo="+codigo;
	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);

	var resposta = xmlHttp.responseText;
	resposta = resposta.replace(/\+/g," ");
    resposta = unescape(resposta);

	document.getElementById('popup_visita').innerHTML = resposta;
	document.getElementById('popup_visita').style.visibility = "visible";
}

function validaStep1() {
	var cli = document.getElementById("cliente").value;
	var fon = document.getElementById("fone1").value;
	var erro = 0;
	var msg = "Erro ao preencher o cadastro:\n";
	
	if( cli.length < 7 ) {
		msg = msg + "O nome deve conter pelo menos 10 letras\n";
		erro = 1;
	}
	
	if( fon.length < 8 ) {
		msg = msg + "O número do telefone 1 deve ser informado\n";
		erro = 1;
	}
	
	if( erro > 0 ){
		alert(msg);
		return false;
	} else {
		return true;
	}
}

function validaBusca() {
	var txt = document.getElementById("busca_parabrisa").value;
	if( txt.length < 3 ) {
		alert("Informe as palavras chave de sua pesquisa e clique no botão buscar!");
		return false;
	} else {
		return true;
	}
}

function parabusca(tipo) {
	var txt = document.getElementById("busca_parabrisa").value;
	
	if( txt.length < 2 ) {
		alert("Informe as palavras chave de sua pesquisa e clique no botão buscar!");
		return false;
	} else {
		window.location.href = "search.php?q="+tipo+"&keywords="+txt;
	}
}

function maxLength(textAreaField, limit) {
	var ta = document.getElementById(textAreaField);
 		
	if (ta.value.length >= limit) {
 		ta.value = ta.value.substring(0, limit-1);
 	}
}

function zoom(pag) {
	var xmlHttp=GetXmlHttpObject();
	var newimg = "<img src='pages/"+pag+".jpg' data-magnifysrc='zoom/"+pag+".jpg' id='myimage' border='0'>"; 
	document.getElementById("fullpage").innerHTML = newimg; 
}

function popup_temporada(block_id, imovel_id) {
	var xmlHttp=GetXmlHttpObject();

	var url="temporada_detalhes.php?id="+imovel_id;
	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);

	document.getElementById(block_id).innerHTML = xmlHttp.responseText;
	document.getElementById(block_id).style.visibility = "visible";
}

function hidepopup(block_id) {
	document.getElementById(block_id).style.visibility = "hidden";
}

function thumb_zoom(photo) {
	document.getElementById('photo_frame').innerHTML = "<img src='"+photo+"' border='0' style='margin: 10px 0px 0px 0px;'>";
}

function GetXmlHttpObject() {
	var xmlHttp;
	try {
	  xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

