
  var req;
  var responsecontainer;
  
  
function initReq()
{
	if (window.XMLHttpRequest) {
		try { req = new XMLHttpRequest(); }
		catch (e) {}
	} else if (window.ActiveXObject) {
		try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) {
		try { req = new AciveXObject("Microsoft.XMLHTTP"); }
		catch (e) {}
		}
	}
 }
 

 function processReqChange()
 {
	if (req.readyState==4)
	{
		responsecontainer.innerHTML="";
		responsecontainer.innerHTML=req.responseText;
		//responsecontainer.parentNode should be the ModalNode!
/*		try
		{
			if (responsecontainer.parentNode.CustomLeft==null)
				responsecontainer.parentNode.style.left="20%";
			if (responsecontainer.parentNode.CustomTop==null)
				responsecontainer.parentNode.style.top="30%";
			if (responsecontainer.parentNode.CustomHeight==null)
				responsecontainer.parentNode.style.height="60%";
			if (responsecontainer.parentNode.CustomWidth==null)
				responsecontainer.parentNode.style.width="60%";
		}
		catch(e)
		{
		}
*/	}
 }
 
 function GetPage(responsecontainerobj,URL,poststring)
 {
	if(req) 
 	{
 		req.abort();
	}
	req=null;
	initReq();
	responsecontainer=responsecontainerobj;
	responsecontainer.innerHTML="";
	responsecontainer.appendChild(CreateProgressBar());
	req.onreadystatechange = processReqChange;
	req.open("POST",URL,true);
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	req.send(poststring);
 }

function CreateProgressBar()
{
	var img=document.createElement("img");
	img.style.position="absolute";
	img.style.left="40%";
	img.style.top="48%";
	img.style.height="4%";
	img.style.width="20%";
	img.src="Images/ProgressBar.gif";

	return img;
}

function ajax_GetPostArguments(Form)
{
	var output="";
	for (var i=0;i < Form.childNodes.length;++i)
	{
		try
		{
			if (Form.childNodes[i].tagName.toLowerCase()=="input")
			{
			//alert("processing input of "+Form.childNodes[i].name+"="+Form.childNodes[i].value);
			if (Form.childNodes[i].type=="checkbox")
				output+=Form.childNodes[i].name+"="+Form.childNodes[i].checked+"&";
			else			
				output+=Form.childNodes[i].name+"="+Form.childNodes[i].value+"&";
			}
			else
			if (Form.childNodes[i].tagName.toLowerCase()=="select")
			{
			//	alert("processing input of "+Form.childNodes[i].name+"="+Form.childNodes[i].selectedIndex);
				output+=Form.childNodes[i].name+"="+Form.childNodes[i].selectedIndex+"&";
			}
			else
			{
			//	alert("moving into "+Form.childNodes[i].tagName);
				output=output+ajax_GetPostArguments(Form.childNodes[i]);
			}
		}
		catch(e)
		{
			if (Form.childNodes[i])
			{
			//	alert("TryCatch Event...moving now into "+Form.childNodes[i].tagName);
				output=output+ajax_GetPostArguments(Form.childNodes[i]);
			}
				
		}
	}
	if (output.indexOf("undefined") > -1)
		return "";
	return output;
}


function ajax_setOpacity(Element,value)
{
    Element.style.opacity = value/10;
    Element.style.filter = 'alpha(opacity=' + value*10 + ')';
}

function ajax_myInfoType()
{
    var Form=null;
    var BackgroundNode=null;
    var HasIFrame=false;
}


function DoAJAXPopUp(doc,URL,postparameters,ResponseEvent,width,height,top,left,hidecontainer)
{
    var Form=doc.forms[0];
    var ModalNode = doc.createElement("span");
    var BackgroundNode = doc.createElement("span");
   
    Form.appendChild(BackgroundNode);

    BackgroundNode.style.zIndex=170;
    BackgroundNode.style.position="absolute";
    BackgroundNode.style.left="0px";
    BackgroundNode.style.top="0px";
    BackgroundNode.style.height="400%";
    BackgroundNode.style.width="200%";
    BackgroundNode.style.backgroundColor="gray";
    BackgroundNode.style.display="inline";
    BackgroundNode.innerHTML="<br>";

    ajax_setOpacity(BackgroundNode,6);
   
    ModalNode.style.zIndex=170;
    ModalNode.style.display="inline";
    ModalNode.style.position="absolute";
    if (left!=null)
    {
		ModalNode.style.left=left;
		ModalNode.CustomLeft=left;
	}
	else
		ModalNode.style.left="20%";
    if (top!=null)
    {
		ModalNode.style.top=top;
		ModalNode.CustomTop=top;
	}
	else
		ModalNode.style.top="30%";
    if (height!=null)
	{
		ModalNode.style.height=height;
		ModalNode.CustomHeight=height;
	}
	else
		ModalNode.style.height="60%";
    if (width!=null)
	{
		ModalNode.style.width=width;
		ModalNode.CustomWidth=width;
	}
	else
		ModalNode.style.width="60%";

    ModalNode.myInfo=new ajax_myInfoType();
    ModalNode.myInfo.Form=Form;
    ModalNode.myInfo.BackgroundNode=BackgroundNode;
    if (hidecontainer==true)
	{
	}
	else
    {
		ModalNode.style.border="solid 1px black";
		ModalNode.style.backgroundColor="whitesmoke";
    }
    ModalNode.id="ModalNode";
    ModalNode.style.overflow="visible";

    var contentspancontainer=doc.createElement("span");
    ModalNode.appendChild(contentspancontainer);
    contentspancontainer.style.position="relative";
    //contentspancontainer.style.display="inline";
    contentspancontainer.style.left="0px";
    contentspancontainer.style.top="0px";
    contentspancontainer.style.width="100%";
    contentspancontainer.style.height="10px";
    contentspancontainer.style.overflow="visible";
    contentspancontainer.innerHTML=" ";

    GetPage(contentspancontainer,URL,postparameters);

    var spantag=doc.createElement("span");
    spantag.style.position="relative";
    spantag.style.display="inline";
    spantag.style.left="0px";
    spantag.style.top="0px";
    spantag.style.height="30px";

    var okbutton=doc.createElement("input");
    okbutton.type="button";
    okbutton.value="OK";
    okbutton.style.position="absolute";
    okbutton.style.left="130px";
    okbutton.style.top="2px";
    okbutton.style.width="60px";
    okbutton.style.height="24px";
    spantag.appendChild(okbutton);

 	ModalNode.appendChild(spantag);

    spantag.style.width="100%";
  
    if (hidecontainer==true)
	{
		spantag.style.width="0px";
		spantag.style.height="0px";
		spantag.style.overflow="hidden";
		spantag.style.display="none";
	}
	
    ModalNode.okbutton=okbutton;
    ModalNode.TextResponse="";

    ModalNode.style.overflow="visible";
	if (ajax_IsIE6orOlder())
	{
		ajax_EncapsulateWithAnIFrame(doc,ModalNode);
	}

    okbutton.onclick=function(){return ReturnAJAXPopUp(ModalNode,true,ResponseEvent);};
    Form.appendChild(ModalNode);
}

function ajax_IsIE6orOlder()
{
	if (window.XMLHttpRequest) 
	{
		// IE 7, mozilla, safari, opera 9
		return false;
	} else 
	{
		// IE6, older browsers
		return true;
	}
}

function ajax_EncapsulateWithAnIFrame(doc,myObject)
{
	var somespan=doc.createElement("span");
	somespan.style.top="0px";
	somespan.style.left="0px";
	somespan.style.width=myObject.style.width;
	somespan.style.height=myObject.style.height;
	somespan.style.zIndex="170";
    somespan.style.overflow="visible";
	somespan.style.position="absolute";
	
	for (i=0;i < myObject.childNodes.length;++i)
	{
		var count=myObject.childNodes.length;

		somespan.appendChild(myObject.childNodes[i]);
		try
		{
			if (count==myObject.childNodes.length)
				myObject.removeChild(myObject.childNodes[i]);
		}
		catch(e)
		{
		}
	}
	
	var theiframe=doc.createElement("iframe");
	theiframe.style.top="0px";
	theiframe.style.left="0px";
	theiframe.style.width="100%";
	theiframe.style.height="100%";
	theiframe.style.zIndex="169";
	theiframe.style.position="absolute";
	//theiframe.src="";
	
	myObject.appendChild(somespan);
	myObject.appendChild(theiframe);
	myObject.myInfo.HasIFrame=true;
}

function ReturnAJAXPopUp(ModalNode,Result,ResponseEvent)
{
    try
    {
    
        ajax_setOpacity(ModalNode,3);
		try
		{
	       ResponseEvent(Result,ModalNode.TextResponse);
		}
		catch (e2)
		{
		}
        ModalNode.myInfo.Form.removeChild(ModalNode.myInfo.BackgroundNode);
        ModalNode.myInfo.Form.removeChild(ModalNode);
        return Result;
    }
    catch(e)
    {
        return false;
    }
}

function ajax_CreateHiddenField(doc,FieldName,FieldValue,parentControl)
{
	var HiddenField=doc.createElement("input");
	HiddenField.type="hidden";
	HiddenField.name=FieldName;
	HiddenField.id=FieldName;
	HiddenField.value=FieldValue;
	try
	{
		if (parentControl!=null)
			parentControl.appendChild(HiddenField);
	}
	catch(e)
	{
	}
	return HiddenField;
}

function get_RadioListSelectedIndex(doc,Name)
{
	var RadioList=document.getElementsByName(Name);
	for (var i=0;i < RadioList.length;++i)
	{
		if (RadioList[i].checked==true)
			return i;
	}
	return -1;
	
}


/*

  var req;
  var responsecontainer;
  
  var pagerequestarray=new Array();
  var isRequesting=false;
  
 function HoldState(responsecontainerobj,URL,poststring)
 {
	var ResponseContainerObj=responsecontainerobj;
	var url=URL;
	var PostString=poststring;
 }
  
function initReq()
{
	if (window.XMLHttpRequest) {
		try { req = new XMLHttpRequest(); }
		catch (e) {}
	} else if (window.ActiveXObject) {
		try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) {
		try { req = new AciveXObject("Microsoft.XMLHTTP"); }
		catch (e) {}
		}
	}
 }
 
 function processReqChange()
 {
	if (req.readyState==4)
	{
		responsecontainer.innerHTML="";
		responsecontainer.innerHTML=req.responseText;
		
		//responsecontainer.parentNode should be the ModalNode!
		
		try // try executing code!!!
		{
			var spanblocks=document.getElementsByName("ExecutableCode");
			for (var i=0;i < spanblocks.length;++i)
			{
				spanblocks[i].blur();
			}
		}
		catch(e)
		{
		}
		
		//done. Now check for more requests
		if (pagerequestarray.length > 0)
		{
			isRequesting=false;
			GetPage(pagerequestarray[0].ResponseContainerObj,pagerequestarray[0].url,pagerequestarray[0].PostString);
			pagerequestarray.shift();
		}
		else
		{
			isRequesting=false;
		}
	}
 }
 
 function GetPage(responsecontainerobj,URL,poststring)
 {
	if (isRequesting==true)
	{
		var newrequest=new HoldState(responsecontainerobj,URL,poststring);
		pagerequestarray.push(newrequest);
	}
	else
	{
		isRequesting=true;
		if(req) 
 		{
 			req.abort();
		}
		req=null;
		initReq();
		responsecontainer=responsecontainerobj;
		responsecontainer.innerHTML="";
		responsecontainer.appendChild(CreateProgressBar());
		req.onreadystatechange = processReqChange;
		req.open("POST",URL,true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.send(poststring);
	}
 }


*/