var xmlHttp

counter=0;

function doAjaxSend(type)
{	
	
	xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	
	
	if (type == "charities"){var val = document.getElementById("charitys").value;}
	else if (type == "shops"){var val = document.getElementById("shops").value;}
	else if(type == "sponsors"){var val = document.getElementById("sponsors").value;}
	
	var url="pearls/result.php";
	url=url+"?sid="+Math.random();

	var poststr = type + "=" + encodeURI( val );
	//alert(poststr);

	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", poststr.length);
    xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(poststr);
} 




function stateChanged() 
{ 


	document.getElementById("ajaxRes").innerHTML="Please wait while we review your selection for a Pearl of wisdom. In a few seconds a link will appear to your chosen website. Feel Free to click on the link to visit that partner's website and see what they have to offer while we continue checking.";
			

	if (xmlHttp.readyState==4)
	{ 
		//document.getElementById("ajaxRes").innerHTML=xmlHttp.responseText;
		timedCount(xmlHttp.responseText);
	}
}



function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

	var c=0;
	var response;
	function timedCount(AJAX){
		response = AJAX; 
		document.getElementById('ajaxRes').innerHTML="Checking your choice. Please wait... "+(10-c)+" sec";
		c=c+1;
		var t=setTimeout("timedCount(response)",1000);
		if (c==11){
			clearTimeout(t);
			c = 0;
			document.getElementById('ajaxRes').innerHTML=response;
		}
	}
	
			var url;
			function submitcharityform(){
				var char=document.charityform
					if (char.charitys.options[char.charitys.selectedIndex].value != "null") 
					{
					  var id = char.charitys.options[char.charitys.selectedIndex].value;
					  url = "http://wisdom4all.co.uk/pearls/check/banner_bottom.php?charities=" + id;					  
					  setTimeout('openNewWin()',6000);
					  doAjaxSend('charities');
					}
				}

			function submitshopsform(){
				var shop=document.shopsform
					if (shop.shops.options[shop.shops.selectedIndex].value != "null")
					{					  
					  var id = shop.shops.options[shop.shops.selectedIndex].value;					  
					  url = "http://wisdom4all.co.uk/pearls/check/banner_bottom.php?shops=" + id;					  
					  setTimeout('openNewWin()',6000);					  					  
					  doAjaxSend('shops');
					}
				}
				
			function submitsponsorsform(){
				var spon=document.sponsorsform
					if (spon.sponsors.options[spon.sponsors.selectedIndex].value != "null")
					{
					  var id = spon.sponsors.options[spon.sponsors.selectedIndex].value;	  
					  url = "http://wisdom4all.co.uk/pearls/check/banner_bottom.php?sponsors=" + id;				  
					  setTimeout('openNewWin()',6000);				  					  
					  doAjaxSend('sponsors');
					}
				}
				
			function openNewWin(){
					newwindow=window.open("");					  
					newwindow.location=url;
			}

