function get_xmlhttp() {
try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}
return xmlhttp
}
function enviar(xmlhttp,metodo,url,async,callback,target_object) {
 //alert('llegue met= '+metodo+' url= '+url+callback);exit;
 xmlhttp.open(metodo, url,async);
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
   callback(xmlhttp, target_object)
  }
 }
 xmlhttp.send(null)
}
function urlView( url, htmlId ) {
	//alert(url);exit;
	htmlObjId=htmlId;
	//startLoading();
 	xmlhttp=get_xmlhttp();
 	enviar(xmlhttp,"GET",url,true,urlGet);
 	//urlLink=url.substr(0,url.length-11);
 	//setFramework(urlLink);
    //document.getElementById("link").setAttribute("href",urlLink);
}
function urlGet(xmlhttp) {
//	 alert('llegue a urlGet');
	 val=""
	 for(i in xmlhttp) {
	 	try {
	 		val+="xmlhttp."+i+"="+xmlhttp[i]+"\n";
	 	} catch(e) {}
	 }
	 if(xmlhttp.status==404) {
	 	alert("Se supondría que esta página no existe")
	 }
	 if( xmlhttp.responseText!="") {
//		 document.getElementById(htmlObjId).innerHTML=xmlhttp.responseText;
		 document.getElementById(htmlObjId).innerHTML=xmlhttp.responseText;
//		 alert();
	 }
//	 stopLoading();
}
function getCategory( code){
	urlView('?module=product_category&code='+code+'&presenter=none&event=getProductList','div_body_contenido');
	//selectActive("category",id);
	//urlView1('?module=product_category&id='+id+'&presenter=none&event=getFirstElementDetail','div_productDetail');
}
function getProduct(id){
	urlView('?module=product&event=showDetail&id='+id+'&presenter=none','div_productDetail');
	selectActive("product",id);
}
function test(){
	 selectActive("category",5);
}
function selectActive(name,id){
	nuevoActivo=document.getElementById(name+id);
	padre=nuevoActivo.parentNode;
	activos=padre.getElementsByTagName("a");
	//Equivalente a foreach
	for (var i in activos){
		activos[i].className="inactive";
	}
	nuevoActivo.className="active";
}
//Funciones del carrito de compras
function addProduct( code ) {
	xmlhttp=get_xmlhttp();
	enviar(xmlhttp,"GET","?module=product_pedido&event=addProduct&code="+code,true,callbackAddProduct );
}
function callbackAddProduct(){
	urlView('?module=product_pedido&event=showCarritoDetail&presenter=none','div_carrito');
}
function updateCant( code ){
	cant=document.getElementById('cant_'+code).value;
	xmlhttp=get_xmlhttp();
	enviar(xmlhttp,"GET","?module=product_pedido&event=updateCant&code="+code+"&cant="+cant,true,callbackUpdateCant );
}
function callbackUpdateCant(){
	window.location.reload();
}
function delProd( code ){
	xmlhttp=get_xmlhttp();
	enviar(xmlhttp,"GET","?module=product_pedido&event=delProd&code="+code,true,callbackDelProd);
}
function callbackDelProd(){
	alert("Producto Eliminado");
	window.location.reload();
}
function addVote( ) {
	for (i=0; i<document.form_poll.result.length; i++){
		if (document.form_poll.result[i].checked==true){
			opt= document.form_poll.result[i].value;
			break;
		}
	}
	xmlhttp=get_xmlhttp();
	enviar(xmlhttp,"GET","?module=poll&event=regVote&code="+opt+"&presenter=none",true,callbackVote );
}
function callbackVote(){
	urlView('?module=poll&event=showResult&presenter=none','div_poll');

}

