<!--
/* 
Name:			ajax.js
Description: 	AJAX
Creator:		PBP - pbp@firedune.com.ar
--------------------------------------------------------------------------------------
Version History:
	v1	2008-04-01	PBP		Created	
--------------------------------------------------------------------------------------
*/


function AjaxDelete(url) {
	var answer = confirm ("Are you sure you want to delete?");
	if (answer){
		//alert(url);
		AjaxAdmin(url);	
	};
}

function AjaxEditHostel(url){
	Ajax(url,"divhostel","GET");	
}


function AjaxAdmin(url){
	Ajax(url,"admin","GET");	
}


function AjaxLogin(){
	var url = "seg_login.php";
	var poststr = 'user=' + encodeURI( document.getElementById("user").value ) + '&pass=' + encodeURI( document.getElementById("pass").value );
	
	//alert("URL: " + url);
	//alert("POSTSTR: " + poststr);
	Ajax(url,"admin","POST",poststr);
};


function AjaxContact(){
	var url = "contacto.php";
	var poststr = "contacto=" + encodeURI( document.getElementById("contacto").value ) + "&email=" +  document.getElementById("email").value  + "&desc=" +  document.getElementById("desc").value ;

	//alert("POSTSTR: " + poststr);
	Ajax(url,"main","POST",poststr);
};


function LoadThrobber(where){
	document.getElementById(where).innerHTML = '<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><td align="center" valign="middle"><img src="_img/_interface/spinner.gif" alt="Loading..." border="0"></td></tr></table>';
}



//ACA EMPIEZA EL AJAX PROCESS
var xmlReq = null;
function processReqChange(xmlReq, where){
	alert("Req: "+xmlReq);
 	alert("Req State"+xmlReq.readystate);
	if (xmlReq.readyState == 4 && xmlReq.status == 200){
		if (xmlReq.responseText){
			document.getElementById(where).innerHTML = xmlReq.responseText;
		} else {
			alert("There was a problem retrieving the XML data:\n" +xmlReq.statusText);
		};
	 };
};


function Ajax(url, where, method, postvars){
	xmlReq = false;

	// branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			xmlReq = new XMLHttpRequest();
        } catch(e) {
			xmlReq = false;
        };
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	xmlReq = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
         	try {
          		xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		xmlReq = false;
        	};
		};
	};
	
	if(xmlReq) {
		LoadThrobber(where);
		
		//alert("Req State: "+xmlReq.readystate);
		if(method == "GET"){
			postvars = "";	
		};
		
		xmlReq.onreadystatechange = function(){
    		if (xmlReq.readyState == 4 && xmlReq.status == 200){
      			if (xmlReq.responseText){
          			document.getElementById(where).innerHTML = xmlReq.responseText;
      			};
    		};
  		};
		//xmlReq.onreadystatechange = processReqChange(req, where);
		
		xmlReq.open(method, url, true);
		if(method == "POST"){	
			//alert("POSTVARS: " + postvars);
			//alert("POSTVARS LENGHT: " + postvars.length);
			xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xmlReq.setRequestHeader("Content-length", postvars.length);
			xmlReq.setRequestHeader("Connection", "close");
		};
		xmlReq.send(postvars);
     };
};

-->
