var xmlhttp;

try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}

	
var ajax = {
	//ajax produto personalizado
	recalcula : function() {
		//document.getElementById('price').innerHTML = "Recalculando...";
		
		param = "prod="+document.frm_compra.prod.value+"&proditem="+ajax.seleciona_prod();
		xmlhttp.open("POST", "http://pcinformatica1.tempsite.ws/recalcula_prod.php", true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		
		xmlhttp.onreadystatechange = function(){
				//document.getElementById('price').innerHTML = "Recalculando...";
				if(xmlhttp.readyState == 4) { 
					if(xmlhttp.status == 200){ 
						document.getElementById('price').innerHTML = xmlhttp.responseText;
					}else{ //Não encotra os dados
						document.getElementById('price').innerHTML = "Erro: returned status code " + xmlhttp.status + " " + xmlhttp.statusText;
					}
				}
			}
			xmlhttp.send(param);
	} ,
	//seleciona produtos marcados
	seleciona_prod : function () {
		aux = ''; //valores selecionados
		for (i=0; i < document.frm_pers.length; i++) {
			if (document.frm_pers[i].type == 'checkbox') {
				if (document.frm_pers[i].checked) {
					aux = aux + document.frm_pers[i].value + '|';
				}
			}
		}
		return aux;
	}
}
