// JavaScript Document

//Javascript for Ajax

/******************************
 *Global XMLHTTP Request object
 *Use this object to access the
 *pages and to bring back the 
 *the string necessary for div
 ******************************/
var XmlHttp;


//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}

//Called when response comes back from server
function HandleResponse()
{
	// To make sure receiving response data from server is completed
	
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{	
			
			//var jdBanner = document.getElementById("divBanner")
			//var sReturnedText = XmlHttp.responseText;
			//var sReturnedText = XmlHttp.responseXML;
			fncRefreshList(XmlHttp.responseXML.documentElement)
			//sReturnedText is now an XML Document
			
						
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}

function fncGetFiles()
{
	var requestUrl = "xmlFiles.asp";
	CreateXmlHttp();
	if(XmlHttp)
	{
		
		XmlHttp.onreadystatechange = HandleResponse;
		XmlHttp.open("GET",requestUrl,true);
		XmlHttp.send(null);
	}
		
	return true	
	
}


function fncRefreshList( xmlFileNode)
{
	var listselFile = document.getElementById("selFile")
	//First clear out the list
	for(i=listselFile.options.length-1;i > -1;i--)
	{
		listselFile.options[i] = null;
	}
	var fileNodes = xmlFileNode.getElementsByTagName('xmlFile');
	var fileValue;
	var optionFile;
	
	//Add New items
	optionFile = new Option( "Select Mail List", "",  false, false);
	optionFile.selected = true;
	listselFile.options[listselFile.length] = optionFile;

	for (i=0;i<fileNodes.length;i++)
	 {
		 fileValue = GetInnerText(fileNodes[i])
		 optionFile = new Option( fileValue, fileValue,  false, false);
		 listselFile.options[listselFile.length] = optionFile;
	 }
	
}

//Returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}


function fncUploadList()
{	
	sWidth = ((screen.width/4)-150)
	sHeight = ((screen.height/4)-38)
	
	winLoc = "toolbar=no, titlebar=no, top=" + sHeight + ", left=" + sWidth + ", location=no, directories=no, "
	winLoc += "status=no, menubar=no, scrollbars=no,"
	winLoc += " resizable=no, copyhistory=no, width=600px, height=160px"
	window.open("fileupload/fileupload.aspx","_blank",winLoc)
	return
}

	
