

//////////////BEGIN xmlhttp script//////////////

var debug = false;

/**
Returns the correct XMLHttpRequest object
*/
function GetXmlHttp() {
	var xmlhttp = false;
	if (window.XMLHttpRequest)//mozilla based browsers
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)// code for IE
	{
		if (window.VV_XMLHttpRequestProgID) {
			return new ActiveXObject(window.VV_XMLHttpRequestProgID);
		} else {
			var progIDs = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
			for (var i = 0; i < progIDs.length; ++i) {
				var progID = progIDs[i];
				try {
					var x = new ActiveXObject(progID);
					window.VV_XMLHttpRequestProgID = progID;
					xmlhttp = x;
				} catch (e) {
				}
			}
		}
	}
	return xmlhttp;
}


/**
///<summary>
///Responsible for xmlhttp communication with the server.  Posts the form data and processes any response string received back
///from the server when the callback is completed.
///</summary>
///<param name="clientID">ID of the control that is making the callback request</param>
///<param name="CbEvent">EventID to send to server</param>
///<param name="htmlElementToUpdate">If found this HTML element will be updated with the response string returned from the server (by setting its innerHTML property)</param>
///<param name="serverControlToRender">(optional) If server finds a control matching this uniqueid the server control will be rendered and its contents returned back in the server response</param>
///<param name="htmlElementLoadingMsgDisplay">(optional) Html element on the page to show the loading message</param>
///<param name="onCallbackCompleteFunction">(optional) Used to call a javascript function when callback is completed</param>
///<param name="cbFunctionArguments">(optional) Used to send parameter list to javascript function when callback is completed</param>
*/

function vvCallbackGetHTML(clientID,cbEvent,htmlElementToUpdate,serverControlToRender,htmlElementLoadingMsgDisplay,onCallbackCompleteFunction,cbFunctionArguments)

{
  
	//arguments should be in string format of &item1=value&item2=value...
	var url='?' //send xmlhttp form post to the page referencing this script
	var xmlhttp = new GetXmlHttp();
	var elementToUpdate = htmlElementToUpdate;
	var elementLoadingMsg = htmlElementLoadingMsgDisplay;	
	var encodedData = '&cbvvClientID=' + clientID + '&cbvvEvent=' + cbEvent + '&cbControlUniqueIDToRender=' + serverControlToRender;
	var postAllFormData = 'true';
	
	//add logic to decide if we should post all form fields or just the form fields that are children of controlToUpdate
	
	if (document.forms.length > 0 && postAllFormData == 'true') 
	{
		var form = document.forms[0]; //use getElementById(FormID) if there is ever more than 1 form;
		for (var elementIndex = 0; elementIndex < form.length; ++elementIndex) {
			var element = form.elements[elementIndex];
			if (element.name) {
				var elementValue = null;
				if (element.nodeName == "INPUT") {
					var inputType = element.getAttribute("TYPE").toUpperCase();
					if (inputType == "TEXT" || inputType == "PASSWORD" || inputType == "HIDDEN") {
						elementValue = element.value;
					} else if (inputType == "CHECKBOX" || inputType == "RADIO") {
						if (element.checked) {
							elementValue = element.value;
						}
					}
				} else if (element.nodeName == "SELECT") {
					if (element.multiple) {
						elementValue = [];
						for (var i = 0; i < element.length; ++i) {
							if (element.options[i].selected) {
								elementValue.push(element.options[i].value);
							}
						}
					} else {
						elementValue = element.value;
					}
				} else if (element.nodeName == "TEXTAREA") {
					elementValue = element.value;
				}
				if (elementValue instanceof Array) {
					for (var i = 0; i < elementValue.length; ++i) {
						encodedData += "&" + element.name + "=" + encodeURIComponent(elementValue[i]);
					}
				} else if (elementValue) {
					encodedData += "&" + element.name + "=" + encodeURIComponent(elementValue);
				}
				elementValue = null;
			}
		}
		
		if (typeof form.__VIEWSTATE == "undefined" || form.__VIEWSTATE.value.length == 0) {
			encodedData += "&__VIEWSTATE=";
		}
		if (typeof form.__EVENTTARGET == "undefined" || form.__EVENTTARGET.value.length == 0) {			
			encodedData += "&__EVENTTARGET=";
		}
		if (typeof form.__searchFolders == "undefined" || form.__searchFolders.value.length == 0) {			
			encodedData += "&__searchFolders=";
		}
		
	}
	else if (postAllFormData != 'true')
	{	
		
		//add code here to post a selected form element's form fields		
		//if we are not posting the entire form then make sure to include required hidden fields
					
		try{
			encodedData += "&__vsKey=" + form.__vsKey.value ;
		}
		catch(e){
			encodedData += "&__vsKey=";
		}	
		
		try{
			encodedData += "&__vState=" + form.__vState.value ;
		}
		catch(e){
			encodedData += "&__vState=";
		}	
		
		try{
			encodedData += "&__vsPageIndex=" + form.__vsPageIndex.value ;
		}
		catch(e){
			encodedData += "&__vsPageIndex=";
		}	
		
		try{
			encodedData += "&__VIEWSTATE=" + form.__VIEWSTATE.value;
		}
		catch(e){
			encodedData += "&__VIEWSTATE="			
		}	
		
		try{
			encodedData += "&__EVENTTARGET=" + form.__EVENTTARGET.value;
		}
		catch(e){
			encodedData += "&__EVENTTARGET="			
		}	
		
		try{
			encodedData += "&__formID=" + form.__formID.value;
		}
		catch(e){
			encodedData += "&__formID="			
		}	
		
	}		
	
	
	//get the XmlHttpRequest object, send the request.
	if (xmlhttp)
	{
		//debugger;
		xmlhttp.onreadystatechange = function ()
									{
										if (xmlhttp && xmlhttp.readyState==1)
										{//request sent to server..
											var element;
											
											//debugger;
											
											if(typeof htmlElementLoadingMsgDisplay != 'object'){
												element = document.getElementById(htmlElementLoadingMsgDisplay);
											}
											else{
												element = htmlElementLoadingMsgDisplay;
											}
											
											if (element)
											{//display loading message...
												element.innerHTML ='';
												
												try{
													element.innerHTML = "<table height='60%' vAlign='middle' align='center'><tr height='60%'><td style='font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 8pt;'>Loading... <img src='./images/spinner.gif' border='0'></td></tr></table>";
												}
												catch(e){
													element.innerHTML = "<span style='font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 8pt;'>Loading... <img src='./images/spinner.gif' border='0'></span>";
												}
												
											}
										}
																			
										if (xmlhttp && xmlhttp.readyState==4)
										{//we got something back..
										
											var form = document.forms[0]
										
											if (form.__EVENTTARGET){
												form.__EVENTTARGET.value = "";
											}											
											
											if (xmlhttp.status==200)
											{
											
												var responseText = "";
											
												if(debug){
													alert(xmlhttp.responseText);
												}
												
												
												
												//ViewState management												

												if (xmlhttp.responseText.indexOf('<vsKey>') != -1){
													//look for viewstate values in the response text
													//update hidden form fields with updated values
													
													var viewStateValues = xmlhttp.responseText.split('[$$]');
													
													var vsKey = viewStateValues[1];
													var vsPageIndex = viewStateValues[2];
													var vState = viewStateValues[3];	
													
													//clean up the response text
													
													//remove the viewstate values by splitting the string
													viewStateValues = xmlhttp.responseText.split('[$$$]');
													responseText = xmlhttp.responseText.replace(viewStateValues[1],'');		
													
													//remove [$$$] used to split the string
													responseText = responseText.replace('[$$$]','');		
													
																											
													//find the hidden form fields and update viewstate values
													
													//viewstate key (guid)
													var element = document.getElementById('__vsKey');
													
													if (element){
														element.value = vsKey;
													}													
													
													//viewstate page index
													var element = document.getElementById('__vsPageIndex');
													
													if (element){
														element.value = vsPageIndex;
													}	
													
													//viewstate data
													var element = document.getElementById('__vState');
													
													if (element){
														element.value = vState;
													}											
														
												}else {		
													//if not a redirect and the vsKey is not found there is an error condition
													//reload the page using the current URL		
													responseText = xmlhttp.responseText;									
													if (responseText.indexOf('<vvRedirect>') == -1){
														document.location=document.location;
													}
												}  
												
												
												//look for client messagebox markup in the response text
												//if found then find or create the messagebox div element 
												//and insert the messagebox html
													
												//the messagebox markup will be present in the response string
												//if the showpopup method was called the server	
																								
												var msgStart = responseText.indexOf('<clientMessageBox>');
												
												if (msgStart != -1){		
												
													
													//get the messagebox markup substring out of the response text
													var iLen = String(responseText).length;
													var msgEnd = responseText.indexOf('</clientMessageBox>');
													msgEnd += String('</clientMessageBox>').length;
													
													var clientMsg = String(responseText).substring(msgStart, msgEnd);
													
													//remove clientMsg from the response text
													responseText = responseText.replace(clientMsg,'');
													
													//strip the tags out of clientMsg
													clientMsg = clientMsg.replace('<clientMessageBox>','');
													clientMsg = clientMsg.replace('</clientMessageBox>','');
														
													//find the messagebox div element and replace its contents
													var form = document.forms[0];
													var clientMessageBox;
													clientMessageBox = document.getElementById('__clientMessageBox');
													
													if (clientMessageBox) {
														clientMessageBox.innerHTML = clientMsg;
													} else {
														clientMessageBox = document.createElement("div");
														clientMessageBox.setAttribute("id", "__clientMessageBox");
														//clientMessageBox.setAttribute("style", "Z-INDEX: 999;LEFT: 0px; VISIBILITY: hidden;POSITION: absolute");
														//clientMessageBox.setAttribute("onmousedown","javascript:clientMovablesettbl(this);clientMb_StartDrag(event);");
														clientMessageBox.innerHTML = clientMsg;
														form.appendChild(clientMessageBox);														
													}
													
													//if startTimer property set on the server side messagebox control then start the timer
													//else stop the timer if running
													if (clientMsg.indexOf('__timerCallerID') != -1){
															//start timer and show the messagebox
															initTimer();						
													} else if(timerRunning) {
														stopTimer();	
													}
																										
													//if hideMessageBox property set on the server side messagebox control then hide the messagebox
													if (clientMsg.indexOf('__hideMessageBox') != -1){
														clientMBHideMessageBox();						
													} 
												}
												
												try {
													var vvCallbackScriptStart = responseText.indexOf('<vvCallbackScript>');
													var vvCallbackScript = '';
													if (vvCallbackScriptStart != -1){	
														var iLen = String(responseText).length;
														var vvCallbackScriptEnd = responseText.indexOf('</vvCallbackScript>');
														vvCallbackScriptEnd += String('</vvCallbackScript>').length;
														
														vvCallbackScript = String(responseText).substring(vvCallbackScriptStart, vvCallbackScriptEnd);
														responseText=responseText.replace(vvCallbackScript,'');
														vvCallbackScript = vvCallbackScript.replace('<vvCallbackScript>','');
														vvCallbackScript = vvCallbackScript.replace('</vvCallbackScript>','');
														//alert(vvCallbackScript);
														eval(vvCallbackScript);
													}	
												} catch(e) {
												
												}
												var redirectStart = responseText.indexOf('<vvRedirect>');
												var redirectURL = '';
												if (redirectStart != -1){		
													//get the messagebox markup substring out of the response text
													var iLen = String(responseText).length;
													var redirectEnd = responseText.indexOf('</vvRedirect>');
													redirectEnd += String('</vvRedirect>').length;
													
													var redirectURL = String(responseText).substring(redirectStart, redirectEnd);
													
													//remove clientMsg from the response text
													responseText = '';
													
													redirectURL = redirectURL.replace('<vvRedirect>','');
													redirectURL = redirectURL.replace('</vvRedirect>','');
													
													if (redirectURL == 'window.close') {
														window.close();
													}
													else if (redirectURL.indexOf('window.opener.location=') != -1){
														var parentLocation = redirectURL.replace('window.opener.location=','');
																												
														if (parentLocation.length > 0){
															window.opener.location = parentLocation;
														}			
														
														window.close();											
													}
													else if (redirectURL != '') {
														window.location = redirectURL;
													}
												} 
												if (String(redirectURL).length == 0) {
												//If we 
												//try to update the page with server response
												
													try{
															if(typeof elementToUpdate == 'object'){
																//TODO: Clear the innerHTML if using IE on a Mac
																//do not clear it on other browsers to ovoid the "flashing" effect
																//elementToUpdate.innerHTML ='';																
																elementToUpdate.innerHTML = responseText;
															}else {
																//if no obj_id found then we don't need to update the page
																if (document.getElementById(elementToUpdate)){
																	//document.getElementById(elementToUpdate).innerHTML = '';
																	//var test=getPostBack;
																	document.getElementById(elementToUpdate).innerHTML = responseText;
																	
																}
																												
															}
																								
															// if server response contained clientMessageBox then show the message
															if (msgStart != -1){
																clientMBShowMessageBox();
															}												
													}
													catch(e){
															if (responseText.indexOf('<title>VisualVault Login</title>') != -1){
																document.location.reload();
															}
															else{															
																window.location = 'ErrorConfirmation.aspx';
															}											
													}							      
												}
											
											} 
											if (onCallbackCompleteFunction != undefined && onCallbackCompleteFunction != '' && cbFunctionArguments != undefined && cbFunctionArguments !='')
											{
											
												try {
													//call javascript function when callback is complete and append arguments
													var functionToCall = onCallbackCompleteFunction + "('" + cbFunctionArguments + "')";
													if(debug){
														alert(response);
														alert (functionToCall);
													}
													eval(functionToCall);
												}
												catch (e){
												
												}												
												
											} else if (onCallbackCompleteFunction != undefined && onCallbackCompleteFunction != '')
											{
												try {
													//call javascript function when callback is complete without appending arguments
													var functionToCall = onCallbackCompleteFunction;
													if(debug){
														alert(response);
														alert(functionToCall);
													}
													eval(functionToCall);		
												}
												catch (e){
												
												}																					
											}else if(debug){
												document.write(xmlhttp.responseText);
											}											
										}
									}
		
		xmlhttp.open("POST",url,true);
		//Prevent caching
		xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		//make request appear as normal form post
		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		//encode the arguments and post to server	   
	   	xmlhttp.send(encodedData);
	}
}



/**
///<summary>
///Initiates a callback request and sets up the the hidden form input field __EVENTTARGET
///so that the server knows what control initiated the postback (server thinks it is a postback).
///This function is called by the VisualVault custom controls click event or onChange event (VVLinkButton,VVImageButton,VVDropDownList...)
///</summary>
///<param name="clientID">server control's unique ID value - this is the server control that is firing the callback request</param>
///<param name="htmlElementToUpdate">if found this element will be updated with the response string returned from the server (by setting its innerHTML property)</param>
///<param name="serverControlToRender">server control's unique ID value - this is the server control that will be rendered to the client function during the asp.net page render event</param>
///<param name="htmlElementLoadingMsgDisplay">Should usually be set to the same value as htmlElementToUpdate</param>
///<param name="onCallbackCompleteFunction">Javascript function to run when callback is completed. Useful to modify screen after server side processing.</param>
///<param name="cbFunctionCompleteArguments">String value used to send parameter to Javascript function</param>
///<param name="onCallbackStartFunction">Javascript function to run prior to initiating callback. Useful to set hidden form field values.</param>
///<param name="cbFunctionStartArguments">String value used to send parameter to Javascript function</param>
///<param name="evt">Javascript event object passed from control's click event.  Useful to get the coordinates of the click or to stop bubbling of the click event to other elements.</param>

*/

function vvCallbackFireEvent(clientID,htmlElementToUpdate,serverControlToRender,htmlElementLoadingMsgDisplay,onCallbackCompleteFunction,cbFunctionCompleteArguments,onCallbackStartFunction,cbFunctionStartArguments,evt) {
	
	var form = document.forms[0];
	var eventTargetControl = null;
	if (form.__EVENTTARGET) {
		var input = form.__EVENTTARGET;
		input.value = clientID;
	} else {
		var input = document.createElement("INPUT");
		input.setAttribute("name", "__EVENTTARGET");
		input.setAttribute("type", "hidden");
		input.setAttribute("value", clientID);
		form.appendChild(input);
		form.__EVENTTARGET = input;
	}
	
	//if there is a callback start function attempt to run client script, if script cannot be evaluated then do a normal callback. 
	
	if (onCallbackStartFunction) {
	
			var functionToCall;
	
			if (cbFunctionStartArguments){	
				functionToCall = onCallbackStartFunction +"('" + cbFunctionStartArguments + "')";
			}
			else{
				functionToCall = onCallbackStartFunction;
			}
	
			try{				
					
				//selectTab function to makes its own callback
				if (onCallbackStartFunction != 'selectTab'){					
					eval(functionToCall);
					//vvCallbackGetHTML(clientID,'fireevent',htmlElementToUpdate,serverControlToRender,htmlElementLoadingMsgDisplay,onCallbackCompleteFunction,cbFunctionCompleteArguments);	
				}
				else{
					selectTab(cbFunctionStartArguments,htmlElementToUpdate,serverControlToRender,htmlElementLoadingMsgDisplay,onCallbackCompleteFunction,cbFunctionCompleteArguments)
					//eval(functionToCall);
				}
			}
			catch(e){
				vvCallbackGetHTML(clientID,'fireevent',htmlElementToUpdate,serverControlToRender,htmlElementLoadingMsgDisplay,onCallbackCompleteFunction,cbFunctionCompleteArguments);	
			}
		
	}else{
		vvCallbackGetHTML(clientID,'fireevent',htmlElementToUpdate,serverControlToRender,htmlElementLoadingMsgDisplay,onCallbackCompleteFunction,cbFunctionCompleteArguments);	
	}
	
	//if there is an event object, cancel event bubbling
	if (evt){
		evt.cancelBubble = true; 
		evt.returnValue = false; 
		return false;
	}
	
}

//////////////END xmlhttp //////////////


//////////////START Client Message Box //////////////

			// Global variables
			var clientSDragged='';
			var clientTempx, clientTempy, clientOffsetx, clientOffsety;
			var clientMovablemouseDown=false;
			var clientXOffset;
			var clientYOffset;
			var clientMovabletbl;
			var clientMessageboxName = 'clientMessageBox';

			var clientGi = 0;
			var clientGPopupMask = null;
			var clientIntervalProcess = null;

			function clientMbAction(callerUniqueID,messageBoxID,action,onCallbackCompleteFunction,cbFunctionArguments,cbControlClientIDLoadingMsg,cbControlClientIDToUpdate,cbControlUniqueIDToRender)
				{				
					//hide messagebox
					clientMBHideMessageBox();
					
					// action=6 indicates no response back to server
					if (action != '6'){
					
						//set the eventtarget hidden form field to the messagebox's client ID
						if (document.getElementById("__EVENTTARGET")) {
							document.getElementById("__EVENTTARGET").value=messageBoxID;
						}
												
						//send button click event to server
						//if clientScript contains valid javascript function name or script
						//it will be ran when the callback is completed
						vvCallbackGetHTML(callerUniqueID,action,cbControlClientIDLoadingMsg,cbControlClientIDToUpdate,cbControlUniqueIDToRender,onCallbackCompleteFunction,cbFunctionArguments)
					} else {
						
						/////////////////////////////////
						if (onCallbackCompleteFunction != undefined && onCallbackCompleteFunction != '' && cbFunctionArguments != undefined && cbFunctionArguments !='')
						{
						
							try {
								//call javascript function when callback is complete and append arguments
								var functionToCall = onCallbackCompleteFunction + "('" + cbFunctionArguments + "')";
								if(debug){
									alert(response);
									alert (functionToCall);
								}
								eval(functionToCall);
							}
							catch (e){
							
							}												
							
						} else if (onCallbackCompleteFunction != undefined && onCallbackCompleteFunction != '')
						{
							try {
								//call javascript function when callback is complete without appending arguments
								var functionToCall = onCallbackCompleteFunction;
								if(debug){
									alert(response);
									alert(functionToCall);
								}
								eval(functionToCall);		
							}
							catch (e){
							
							}																					
						}
						
						
						///////////////////////////////
					}					
				}
				
			function clientMbUpdateLabels(id1,id2,text1,text2)
			{
			    	
				var span1=document.getElementById(id1);
				var span2=document.getElementById(id2);
				
				if (span1 != null){
					span1.innerHTML = text1;
				}
				
				if (span2 != null){
					span2.innerHTML = text2;
				}
			}

			function clientMBInitPopUp() {

				clientMBShowMessageBox();
				
				//clientMBInitMask();
			}

			//places a mask over the entire screen so only the message box area is clickable
			function initUploadMask() {

				var theBody = document.documentElement;
				var scTop = parseInt(theBody.scrollTop,10);
				var scLeft = parseInt(theBody.scrollLeft,10);
				var fullHeight = clientGetViewportHeight();
				var fullWidth = clientGetViewportWidth();
				
				clientHideSelectBoxes(); //Try to just hide immediately;
				clientIntervalProcess = setInterval('clientHideSelectBoxes()',5);
				setTimeout('clientStopHideSelectBoxes()',5000);
				
				var uploadMask = document.getElementById("uploadMask");				
				
				if (uploadMask != null) uploadMask.style.display = "block";						
			
			}
			
			//places a mask over the entire screen so only the message box area is clickable
			function initUploadMaskWithoutHide() {

				//var theBody = document.documentElement;
				//var scTop = parseInt(theBody.scrollTop,10);
				//var scLeft = parseInt(theBody.scrollLeft,10);
				//var fullHeight = clientGetViewportHeight();
				//var fullWidth = clientGetViewportWidth();
				
				//clientHideSelectBoxes(); //Try to just hide immediately;
				//clientIntervalProcess = setInterval('clientHideSelectBoxes()',5);
				//setTimeout('clientStopHideSelectBoxes()',5000);
				
				var uploadMask = document.getElementById("uploadMask");				
				
				if (uploadMask != null) uploadMask.style.display = "block";						
			
			}

			function clientFirstFocus(defaultButton) {
				var firstFocusButton = null

				if (document.getElementById(defaultButton)) {
					clientFirstFocus = document.getElementById(defaultButton);
					clientFirstFocus.focus();
				}
				else {
					/* NO DEFAULT BUTTON, FOCUS ON THE OK BUTTON*/
					if (document.getElementById("Ok")) {
						clientFirstFocus = document.getElementById("Ok");
						clientFirstFocus.focus();
					}
					/* IF THERE IS A CANCEL BUTTON, FOCUS ON IT INSTEAD */
					if (document.getElementById("Cancel")) {
						clientFirstFocus = document.getElementById("Cancel");
						clientFirstFocus.focus();
					}
				}
			}

			function clientStopHideSelectBoxes() {
				clearInterval(clientIntervalProcess);
			}

			//for IE we hide the selects because they stay on top of every element regardless of zIndex
			function clientHideSelectBoxes() {
			var bFoundElement = false;
				for(var i = 0; i < document.forms.length; i++) {
					for(var e = 0; e < document.forms[i].length; e++){
						if(document.forms[i].elements[e].tagName == "SELECT") {
							document.forms[i].elements[e].style.visibility="hidden";
							bFoundElement = true;
						}
					}
				}
				
				if (bFoundElement == true) {
					clearInterval(clientIntervalProcess);
				}
			}

			function clientGetViewportHeight() {
				if (window.innerHeight!=window.undefined) return window.innerHeight;
				if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
				if (document.body) return document.body.clientHeight; 
				return window.undefined; 
			}
			function clientGetViewportWidth() {
				if (window.innerWidth!=window.undefined) return window.innerWidth; 
				if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
				if (document.body) return document.body.clientWidth; 
				return window.undefined; 
			}

			function clientShowSelectBoxes() {
				for(var i = 0; i < document.forms.length; i++) {
					for(var e = 0; e < document.forms[i].length; e++){
						if(document.forms[i].elements[e].tagName == "SELECT") {
							document.forms[i].elements[e].style.visibility="visible";
							document.forms[i].elements[e].style.display = ''; 
							bFoundElement = true;				
						}
					}
				}
			}

			function clientMBHideMessageBox()
			{
			
				stopTimer();
				
				window.showModalDialog = null;
				clientGPopupMask = document.getElementById("clientPopupMask");
				clientGPopupMask.style.display = 'none';
				
				if (document.getElementById(clientMessageboxName + "_trMBHeader")) {
					clientMovabletbl = document.getElementById(clientMessageboxName + "_trMBHeader");
					clientMovabletbl = clientMovabletbl.parentNode;
					clientMovabletbl.style.visibility = 'hidden';
					clientMovabletbl.parentNode.style.visibility = 'hidden';
					clientShowSelectBoxes();
				}
				if (document.getElementById("bg_" + clientMessageboxName)) {
					clientMovabletbl = document.getElementById("bg_" + clientMessageboxName);
					clientMovabletbl.style.visibility = 'hidden';
					clientMovabletbl.style.display = 'none';
				}
				
				if (document.getElementById(clientMessageboxName + "_cellButton")) {
					var clientButtons = document.getElementById(clientMessageboxName + "_cellButton");
					clientButtons.style.visibility = 'hidden';			
				}	
						
				if (document.getElementById("bg_" + clientMessageboxName)) {
					var mask = document.getElementById("bg_" + clientMessageboxName);
					mask.style.visibility = 'hidden';
					mask.style.display = 'none';	
					mask.style.height = '0px';
					mask.style.width = '0px';					
				}
				
				if (document.getElementById(clientMessageboxName + "_table")) {
					var _table = document.getElementById(clientMessageboxName + "_table");
					_table.style.visibility = 'hidden';	
					_table.style.display = 'none';		
				}	
			}

			function clientMBShowMessageBox() 
			{
				var clientDiv
					
				clientGPopupMask = document.getElementById("clientPopupMask");
				
				if (clientGPopupMask){
					clientGPopupMask.style.display = 'block';
				}	
				
				if (document.getElementById(clientMessageboxName + "_trMBHeader")) {
					clientMovabletbl = document.getElementById(clientMessageboxName + "_trMBHeader");
					clientMovabletbl = clientMovabletbl.parentNode;
					clientMovabletbl.style.visibility = 'visible';	
					clientMovabletbl.parentNode.style.visibility = 'visible';
					clientMovabletbl.parentNode.id = "MessageBoxMove"
					clientDiv="MessageBoxMove";
					MsgBox_HideSelects(clientDiv);				
				}
				if (document.getElementById("bg_" + clientMessageboxName)) {
					clientMovabletbl = document.getElementById("bg_" + clientMessageboxName);
					clientMovabletbl.style.visibility = 'visible';
					clientMovabletbl.style.display = 'block';		
				}				
				
			}

			//Check for table and fix it...
			function clientInitializeMessageTable(){
				if (document.getElementById(clientMessageboxName + "_trMBHeader")) {
					alert("Found");
					clientMovabletbl = document.getElementById(clientMessageboxName + "_trMBHeader");
					clientMovabletbl = clientMovabletbl.parentNode.parentNode.parentNode;
					clientMovabletbl.id = "MessageBoxMove"
					clientSDragged="MessageBoxMove";
					MsgBox_HideSelects(clientSDragged);
				}
				else 
				{
				alert("Not Found");
				//Do nothing
				}
			}


			// Customized IE Scripts
			function clientMovablesettbl(varvr){ 
				clientMovabletbl = varvr.parentNode.parentNode.parentNode;
				clientMovabletbl.id = "MessageBoxMove"
				//alert("Set Table")
				clientSDragged="MessageBoxMove";
				MsgBox_HideSelects(clientSDragged);
				
			}

			function clientMb_StartDrag(event){
				if (window.event.srcElement.parentElement.parentElement.parentElement){	
					document.onmousemove=clientMb_B;	document.onmouseup=clientMb_C;
					clientMovabletbl = window.event.srcElement.parentElement.parentElement.parentElement;	
					clientXOffset= clientMovabletbl.offsetLeft-window.event.x;	
					clientYOffset=clientMovabletbl.offsetTop-window.event.y;	
					clientMovablemouseDown=true;
					
					MsgBox_HideSelects(clientSDragged);

				}
			}

			function clientMb_B(event){	
				if(!clientMovablemouseDown)return;	
				window.event.cancelBubble=true;	
				window.event.returnValue=false;	
				clientMovabletbl.style.left=(window.event.x+clientXOffset)+"px";	
				clientMovabletbl.style.top=(window.event.y+clientYOffset)+"px";
				MsgBox_HideSelects(clientSDragged);
			}

			function clientMb_C(event){	
				clientMovablemouseDown=false;		
				document.onmousemove=document.onmouseup=null;
				//MsgBox_RestoreSelects();
				MsgBox_HideSelects(clientSDragged);
			}

			// Functions to hide select statements
			var clientArrSelects = document.getElementsByTagName('select'); 
			function MsgBox_HideSelects(mbLayer) {
				for (var i=0; i<clientArrSelects.length; i++) {
					if (clientMsgBox_Overlapping(document.getElementById(mbLayer), clientArrSelects[i])) {
						clientArrSelects[i].style.display = 'none'; 
					};
				};
			};
			function MsgBox_RestoreSelects() {
				for (var i = 0; i < clientArrSelects.length; i++) {
					clientArrSelects[i].style.display = ''; 
				};
			};	

			function clientMsgBox_Overlapping(l, s) {
				var lLeft = clientMsgBox_pageX(l) - window.document.body.scrollLeft; 
				var lTop = clientMsgBox_pageY(l) - window.document.body.scrollTop; 
				var lRight = lLeft + l.offsetWidth; 
				var lBottom = lTop + l.offsetHeight;
				var sLeft = clientMsgBox_pageX(s) - window.document.body.scrollLeft; 
				var sTop = clientMsgBox_pageY(s) - window.document.body.scrollTop; 
				var sRight = sLeft + s.offsetWidth; 
				var sBottom = sTop + s.offsetHeight;
					
				if (lRight<=sLeft || lBottom<=sTop || lLeft>=sRight || lTop>=sBottom) {
					return false; 
				} else {
					return true;
				};
			};
			function clientMsgBox_pageX(o) {
				var i=0;
				do 
					i += o.offsetLeft;
				while ((o = o.offsetParent));
				return i; 
			}
			function clientMsgBox_pageY(o) {
				var i=0;
				do 
					i += o.offsetTop; 
				while ((o = o.offsetParent));
				return i; 
			}

//////////////END Client Message Box Script//////////////


///////////////////START Timer Script///////////////////

//timer is initialized when the response text from the server (after a callback)
//detects that a messagebox is present and contains a request to start the timer
//to start the timer, use ClientMessageBox.StartTimer on the server in conjunction
//with ClientMessageBox.ShowPopup

var timerID = null
var timerRunning = false
var delay = 4000 //4 seconds
var onStopScriptName = '';
var onStopScriptArg = '';


function initTimer()
{
	if (!(timerRunning)){
		timerRunning = true;
		startTimer();	
	}	
}

//startTimer calls itself every interval and requests an update to the messagebox
//until stopTimer function is called

function startTimer()
{	        
    if (timerRunning)    
    {                
    
		var callerID;
    
		//get the ID of control that started timer
		if (document.getElementById("__timerCallerID")) {
			callerID = document.getElementById("__timerCallerID").value;			
		}
		
		//set the eventtarget hidden form field to the messagebox's client ID
		if (document.getElementById("__EVENTTARGET")) {
			document.getElementById("__EVENTTARGET").value='clientmessagebox';
		}
		
		//look for client script to run when timer is stopped
		if (document.getElementById('__onTimerEndClientScript')){
			onStopScriptName = document.getElementById('__onTimerEndClientScript').value;
																			
			if (document.getElementById('__onTimerEndClientScriptArgument')){
				onStopScriptArg = document.getElementById('__onTimerEndClientScriptArgument').value;
			}
					
		}				
    
		//request messsagebox update
		vvCallbackGetHTML(callerID,'ClientMessageBoxTimer','','MessageBox','MessageBox','','');
    
        timerID = self.setTimeout("startTimer()", delay);
    }
}

//stopTimer calls clearTimeout to stop the timer, hides the messagebox and then 
//attempts to refresh the treeview after the drag/drop operation is completed

function stopTimer()
{
    if(timerRunning){
		clearTimeout(timerID);
		timerRunning = false;	
		
		//if ClientMessagebox server control's onTimerEndClientScript property contains a value
		//attempt to execute the script
		var functionToCall = onStopScriptName +"('" + onStopScriptArg + "')";
		//alert(functionToCall);
		if (onStopScriptName.length > 0){
			try{
			eval(functionToCall);
			}
			catch(e){													
			}	
		}
		
		//clear the variables
		onStopScriptName = '';
		onStopScriptArg = '';
		
		//hide the messagebox
		//clientMBHideMessageBox();
	} 
}

///////////////////END Timer Script///////////////////
