var ZIP_XmlReq;
var ZIP_AjaxServerPageName = "DonorTrackZIPAjax.asp";

var donFormAjax = document.forms[1];
var tmpZIPAjax = "";
var loadMedia = "";

if (typeof(blockError) == "undefined")
{
	function blockError(){return true;}
	//window.onerror = blockError;
}

function ZIP_CreateXmlReq()
{
	try
	{
		ZIP_XmlReq = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			ZIP_XmlReq = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			ZIP_XmlReq = false;
		}
	}
	if((!ZIP_XmlReq) && (typeof XMLHttpRequest != "undefined")) 
	{
		try
		{
			ZIP_XmlReq = new XMLHttpRequest();
		} 
		catch(dc)
		{
			ZIP_XmlReq = false;
		}
	}
}

function getDonorMedia(sZIP)
{
	var requestUrl;
	
	if (typeof(encodeURIComponent) != "undefined")
		requestUrl = "include/" + ZIP_AjaxServerPageName + "?zip=" + encodeURIComponent(sZIP);
	else
		requestUrl = "include/" + ZIP_AjaxServerPageName + "?zip=" + sZIP;
	
	
	ZIP_CreateXmlReq();
	
	if(ZIP_XmlReq)
	{
		ZIP_XmlReq.onreadystatechange = ZIP_HandleGetDetailsWebResponse;
		ZIP_XmlReq.open("GET", requestUrl,  true);
		ZIP_XmlReq.send(null);		
	}
}

function ZIP_HandleGetDetailsWebResponse(iMediaID)
{
	
	if(ZIP_XmlReq.readyState == 4)
	{
		if(ZIP_XmlReq.status == 200)
		{			
			if(ZIP_XmlReq.responseText != "")
			{
				document.getElementById("divMedia").innerHTML = ZIP_XmlReq.responseText;
				//alert(ZIP_XmlReq.responseText)
			}
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
	
}

function reqZipAjax()
{
	if(donFormAjax.Zip.value==""){
		alert("Please fill the Zip field !");
		donFormAjax.Zip.focus();
		return false;
	}
	if (!validZIP(donFormAjax.Zip.value)) {
		donFormAjax.Zip.focus();
		return false;
	}

	return true;
}	
  
function reqMediaAjax()
{	
	var sZIP = donFormAjax.Zip.value;
	
	if (isValidZIP(sZIP))
	{
		if(sZIP != tmpZIPAjax)
		{
			tmpZIPAjax = sZIP; 
			getDonorMedia(sZIP);
		}
	}
	else 
	{
		if(tmpZIPAjax != "") 
		{
			tmpZIPAjax = ""
			getDonorMedia(sZIP);
		}
	}
	
}

loadMedia = window.setInterval("reqMediaAjax()", 300);
		