// Functions in Ajax

var ajax;

function IniciaAjax(){
    var HTTP_REQUEST;

    try {HTTP_REQUEST = new ActiveXObject("Microsoft.XMLHTTP");}
    catch(e){
        try{HTTP_REQUEST = new ActiveXObject("Msxml2.XMLHTTP");}
        catch(ex){
            try{
                HTTP_REQUEST = new XMLHttpRequest();
                HTTP_REQUEST.overrideMimeType('text/html');
            }
            catch(exc){
                alert("Esse browser não tem recursos para uso do Ajax");
                HTTP_REQUEST = null;
            }
        }
    }
    return HTTP_REQUEST;
}


function sendMail(){
	ajax = IniciaAjax();
	
	if (ajax){
		ajax.onreadystatechange= function(){
			if(ajax.readyState==1){
				document.getElementById("contact_box").innerHTML="<div style='font-size:18px; font-weight:bold; text-align:center; width:380px; height:274px; line-height:274px;'><img src='http://www.zoje.com.br/img/spinner.gif' alt='Carregando...'>Enviando...</div>";
			}
			if(ajax.readyState==4){
				if(ajax.status==200){
					//alert(ajax.responseText);
					if(ajax.responseText!="TRUE"){
						document.getElementById("contact_box").innerHTML = "<div style='font-size:18px; color:#CC0000; margin-top:100px; font-weight:bold; text-align:center; width:380px; height:274px;'>Falha ao enviar<br><br><br><a class='close_modal_btn' onclick='unloadModal();'>fechar</a></div>";
					}else{
						document.getElementById("contact_box").innerHTML = "<div style='font-size:18px; color:#339900; margin-top:100px; font-weight:bold; text-align:center; width:380px; height:274px;'>Enviado com sucesso<br><br><br><a class='close_modal_btn' onclick='unloadModal();'>fechar</a></div>";
					}
				} else {
					//alert(ajax.statusText);
				}
			}
		}

	//alert(document.frmContact.ipt_nome.value);

	//monta a query
	dados =	'nome='		+	document.frmContact.ipt_nome.value 	+ 
			'&ddd='		+	document.frmContact.ipt_ddd.value 	+
			'&telefone='+	document.frmContact.ipt_tel.value 	+
			'&email='	+	document.frmContact.ipt_email.value	+
			'&cep='		+	document.frmContact.ipt_cep.value	+
			'&prodid=' 	+	document.frmContact.id_product.value;

	//alert(dados);


	//faz a requisicao e envio dos dados post
	ajax.open('POST', 'http://www.zoje.com.br/js/php/agendar.php', true);
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send(dados);				
	}

}



function financingSofisa($price){
ajax = IniciaAjax();

//alert($price);

	if (ajax){
		ajax.onreadystatechange= function(){
			if(ajax.readyState==1){
				document.getElementById("sofisa_text").innerHTML="<div class='loading_gallery' style='padding-top:130px; text-align:center;'><img src='http://www.zoje.com.br/img/spinner.gif' alt='Carregando...'></div>";
			}
			if(ajax.readyState==4){
				if(ajax.status==200){
					//alert(ajax.statusText);
					if (ajax.responseText!="FALSE"){
						document.getElementById('sofisa_text').innerHTML=ajax.responseText;
					} else {
						alert('Falha ao consultar financiamento, tente novamente mais tarde.');
					};
				} else {
					alert(ajax.statusText);
				}
			}
		}
	
	//monta a query

	$PJ_OR_PF=0;
	$QUANTITY=1;
	
	dados="consumer_price="+$price+"&people="+$PJ_OR_PF+"&quantity="+$QUANTITY;
	//alert(dados);
	
	//faz a requisicao e envio dos dados post
	ajax.open('POST', 'http://www.zoje.com.br/js/php/sofisa.php', true);
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send(dados);
	}

}

function financingBNDES($price){
ajax = IniciaAjax();

//alert($price);

	if (ajax){
		ajax.onreadystatechange= function(){
			if(ajax.readyState==1){
				document.getElementById("bndes_text").innerHTML="<div class='loading_gallery' style='padding-top:130px; text-align:center'><img src='http://www.zoje.com.br/img/spinner.gif' alt='Carregando...'></div>";
			}
			if(ajax.readyState==4){
				if(ajax.status==200){
					//alert(ajax.statusText);
					if (ajax.responseText!="FALSE"){
						document.getElementById('bndes_text').innerHTML=ajax.responseText;
					} else {
						alert('Falha ao consultar financiamento, tente novamente mais tarde.');
					};
				} else {
					alert(ajax.statusText);
				}
			}
		}
	
	//monta a query

	
	dados="consumer_price="+$price;
	//alert(dados);
	
	//faz a requisicao e envio dos dados post
	ajax.open('POST', 'http://www.zoje.com.br/js/php/bndes.php', true);
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send(dados);
	}

}