if (!window.GetData)
	window.GetData = {};

GetData.Page = function() 
{
}

var host;
GetData.Page.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
	    host = rootElement;
		this.control = control;
		var btn = rootElement.findName("btnCvs");
		var btn2 = rootElement.findName("btnCvs2");
		var btnDL = rootElement.findName("btnCvsDL");
		btn.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
		btn2.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
		btnDL.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUpDL));
	},
	handleMouseUp: function(sender, eventArgs) 
	{
	    var str = "";
	    if (sender.Name == "btnCvs2")
	    {
	        str = "2"; //if you wanted to pass in a querystring to retrieve different data, or leave blank.
	    }
	    else
	    {   
	        str = "";
	    }
		showCustomer(str)
	}
	,
	handleMouseUpDL: function(sender, eventArgs) 
	{
	    window.location = "Silverlight_GetData.zip";
	}
}
var xmlHttp
function showCustomer(str)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="data.aspx";
	url=url+"?q="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function stateChanged() 
{ 
    var txtData = host.findName("txtData");
	if (xmlHttp.readyState==4)
	{ 
		txtData.Text = xmlHttp.responseText;
	}
	else
	{	
	    txtData.Text = "Loading Data from an XML file...";
	}
}
function GetXmlHttpObject()
{
	var xmlHttp=null;
    try
    {
	    xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
	        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
	        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}
