/**
 * JavaScript Document
 * Generic javascript/Ajax for Sta Isic - Request pages out of refresh.
 * 
 * This file check the param by variable 'url' and check that page.
 * Send urls by object XMLHttpRequest to right pages and return always something for the <div>
 * 
 * $Rev: 77 $:
 * $Author: leandro $:
 * $Date: 2008-06-27 14:58:56 $:
 *
 * @author Leandro carvalho <leandro@magicmemories.co.nz>
 * @copyright 15 october 2007
 *
 */

function processResults(url,where)
{
req = null;

	if(where == "form"){
		var word = document.formSearch.search_for_profile.value;
		var url 		= url+word

		// If more tham 1 caracter enable button		
		if(word.length > 0){
			document.getElementById('search').disabled=false;
		} else {
			document.getElementById('search').disabled=true;		
		}
		// If more tham 2 search...
		if(word.length < 3){
			return false;
		}
	} else  {
		var url = url
	}

	var process  = results;

// Find objetives (Mozilla/Safari)
if (window.XMLHttpRequest) {
	req = new XMLHttpRequest();
	req.onreadystatechange = process;
	req.open("POST",url,true);
	req.send(null);

// Find objetives ActiveX (IE)
 } else if (window.ActiveXObject) {
	req = new ActiveXObject("Microsoft.XMLHTTP");
  if (req) {
	req.onreadystatechange = process;
	req.open("POST",url,true);
	req.send();
  }
 }
}

function results()
{
	//when loading process print loading...
	if(req.readyState == 1) {
	 document.getElementById('results').innerHTML = "<div align=center><br/><br/><img src=/global_images/loading.gif /><br/>loading, please wait...<br/><br/></div>";
	}
	// just when complete process
	if (req.readyState == 4) {
		// just when return "OK"
		if (req.status == 200) {
			// find div id="results" and input value
			if(req.responseText == ""){
				document.getElementById('results').innerHTML = "Enter with your search";
			} else {
				document.getElementById('results').innerHTML = req.responseText;
				req.responseText == "";
			}	 
	
		} else {
			alert("You have a problem:n" + req.readyState);
		}
	}
}

