function abrePopupLinkgratis (form, features, windowName) {
  if (!windowName)  windowName = 'formTarget' + (new Date().getTime());
  form.target = windowName;
  open ('', windowName, features);
}
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}




var agt = navigator.userAgent.toLowerCase();
var is_ie = (agt.indexOf('msie') != -1);
var is_ie5 = (agt.indexOf('msie 5') != -1);

function CreateXmlHttpReq(handler) {
	var xmlhttp = null;
	if (is_ie) {
		var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
		try {
			xmlhttp = new ActiveXObject(control);
			xmlhttp.onreadystatechange = handler;
		} catch(e) {
			alert("You need to enable active scripting and activeX controls");
		}
	} else {
		xmlhttp = new XMLHttpRequest(); 
		xmlhttp.onload = handler;
		xmlhttp.onerror = handler;
	}
		return xmlhttp;
}

function DummyHandler() { }
var uniqnum_counter = (new Date).getTime();
function XmlHttpGET(xmlhttp, url) {
					xmlhttp.open('GET', url, false);
					xmlhttp.setRequestHeader('Content-Type','text/xml'); 
    				xmlhttp.setRequestHeader('encoding','ISO-8859-1'); 
					xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
					xmlhttp.send(null);
					return xmlhttp.responseText;
			}
			
function SendRequest(url) {
		var xmlhttp = CreateXmlHttpReq(DummyHandler);
		++uniqnum_counter;
		return XmlHttpGET(xmlhttp, url);
}


function ajax(url, nomedadiv) { 
	document.getElementById(nomedadiv).innerHTML = SendRequest(url);
}

function materia_comentario_mostrar (id_materia) {
	var url = 'aj_materia.php?id_materia=' + id_materia;
	document.getElementById('box_comentario').innerHTML = SendRequest(url);	
}

function cadastro_new (nome,email) {
	var url = 'aj_cadastro.php?nome=' + escape(nome) + '&email=' + email;
	alert(SendRequest(url));
}



function materia_comentario_postar (nome,comentario,id_materia) {
	var url = 'aj_comentamateria.php?nome=' + escape(nome) + '&comentario=' + escape(comentario) + '&id_materia=' + id_materia;
	var resposta = SendRequest(url);
	if (resposta == 1) {
		document.comentario.nome.value = "";
		document.comentario.comentario.value = "";
		materia_comentario_mostrar(id_materia);
		alert('Comentário inserido com sucesso!');
	}
	else {
		alert(resposta);
	}
	
}



function materia_comentario_enviar (id_materia,to_nome,to_email,from_nome,from_email,comentario) {
	var url ='aj_materiaenviar.php?id_materia=' + escape(id_materia) + '&to_nome=' + escape(to_nome) + '&to_email=' + escape(to_email) + '&from_nome=' + escape(from_nome) + '&from_email=' + escape(from_email) + '&comentario=' + escape(comentario);
	var resposta = SendRequest(url);
	if (resposta == 1) {
		document.getElementById('form_from_nome').value = '';
		document.getElementById('form_from_email').value = '';
		document.getElementById('form_to_nome').value = '';
		document.getElementById('form_to_email').value = '';
		document.getElementById('form_comentario').value = '';
		alert('E-mail enviado com sucesso!');
	}
	else {
		alert(resposta);
	}
	
}


function marca_comentario_enviar (nome_marca,to_nome,to_email,from_nome,from_email,comentario) {
	var url ='aj_marcaenviar.php?nome_marca=' + escape(nome_marca) + '&to_nome=' + escape(to_nome) + '&to_email=' + escape(to_email) + '&from_nome=' + escape(from_nome) + '&from_email=' + escape(from_email) + '&comentario=' + escape(comentario);
	var resposta = SendRequest(url);
	if (resposta == 1) {
		document.getElementById('form_from_nome').value = '';
		document.getElementById('form_from_email').value = '';
		document.getElementById('form_to_nome').value = '';
		document.getElementById('form_to_email').value = '';
		document.getElementById('form_comentario').value = '';
		alert('E-mail enviado com sucesso!');
	}
	else {
		alert(resposta);
	}
	
}


function div_enviaramigo() {
	if (document.getElementById('enviaramigo').style.display == 'none') {
		document.getElementById('enviaramigo').style.display = 'block';
	}
	else {
		document.getElementById('enviaramigo').style.display = 'none';
	}	

}

function div_enviaramigo_marca() {
	if (document.getElementById('enviaramigo_marca').style.display == 'none') {
		document.getElementById('enviaramigo_marca').style.display = 'block';
	}
	else {
		document.getElementById('enviaramigo_marca').style.display = 'none';
	}	

}

