


dojo.require("dojo.widget.*");
dojo.require("dojo.undo.browser");
dojo.require("dojo.io.*");
	dojo.hostenv.writeIncludes(); // this is a new line

/*
dojo.require("dojo.widget.TabContainer");
dojo.require("dojo.widget.LinkPane");
dojo.require("dojo.widget.ContentPane");
dojo.require("dojo.widget.LayoutContainer");
dojo.require("dojo.lfx.rounded");
dojo.require("dojo.lfx.*");

	dojo.require("dojo.widget.Checkbox");
	dojo.require("dojo.undo.browser");
	dojo.require("dojo.io.*");
	dojo.require("dojo.widget.TabContainer");
	dojo.require("dojo.widget.LinkPane");
	dojo.require("dojo.widget.ContentPane");
	dojo.require("dojo.widget.LayoutContainer");
	dojo.require("dojo.lfx.rounded");
	dojo.require("dojo.lfx.*");
 
*//*
ApplicationState is an object that represents the application state.
It will be given to dojo.undo.browser to represent the current application state.
*/
ApplicationState = function(stateData, outputDivId, backForwardOutputDivId, bookmarkValue){
	this.stateData = stateData;
	this.outputDivId = outputDivId;
	this.backForwardOutputDivId = backForwardOutputDivId;
	this.changeUrl = bookmarkValue;
}

ApplicationState.prototype.back = function(){
//	this.showBackForwardMessage("BACK for State Data: " + this.stateData);
	if (this.stateData != 'Initial State') this.showStateData();
}

ApplicationState.prototype.forward = function(){
//	this.showBackForwardMessage("FORWARD for State Data: " + this.stateData);
	this.showStateData();
}

ApplicationState.prototype.showStateData = function(){
	updateDivContent("browser",this.stateData);
}

ApplicationState.prototype.showBackForwardMessage = function(message){
	dojo.byId(this.backForwardOutputDivId).innerHTML += message + '<br />';
}
		//****************************************
		/*
		This method illustrates using dojo.io.bind() that also saves an application
		state via dojo.undo.browser (dojo.io.bind() will automatically use dojo.undo.browser
		if the dojo.io.bind() request object contains a back for forward function).
		*/
curTargetDiv = "mainPane";
isInitialState = true;

function setDivContent(targetDivId,eventUrl,originator,bookmarkValue) {
	curTargetDiv = targetDivId;
	dojo.byId(targetDivId).innerHTML='<img src="/srvinc/ice/indicator.gif" />';
	if(eventUrl.length > 0)
	{
			dojo.io.bind({
				url: eventUrl,
				mimetype: "text/html",				
				//Standard dojo.io.bind parameter: if this is a value that evaluates
				//to true, then the page URL will change (by adding a fragment identifier
				//to the URL)
				changeUrl: bookmarkValue,
				//Data for use once we have data for an ApplicationState object
				outputDivId: "output",
				backForwardOutputDivId: "dataOutput",
	    executeScripts:true,
	    scriptSeparation:true,
				
				//A holder for the application state object.
				//It will be created once we have a response from the bind request.
				appState: null,
				
				//Standard dojo.io.bind parameter. The ioRequest object is returned
				//to the load function as the fourth parameter. The ioRequest object
				//is the object we are creating and passing to this dojo.io.bind() call.
				load:updateDivContent,
/*
				load: function(type, evaldObj, xhrObject, ioRequest){
					var stateData = "XHR: " + evaldObj.getElementsByTagName("data")[0].childNodes[0].nodeValue;
					ioRequest.appState = new ApplicationState(stateData, ioRequest.outputDivId, ioRequest.backForwardOutputDivId);
					ioRequest.appState.showStateData();
				},
 */
		
				back: function(){
					this.appState.back();
				},
				
				forward: function(){
					this.appState.forward();
				}
			});

	  if (originator) {
	  	var flO = dojo.lfx.html.fadeOut(originator,300);
	  	var flI = dojo.lfx.html.fadeIn(originator,777);
			dojo.lfx.chain(flO,flI).play();
	  }
	}
}

function updateDivContent(type, data, evt, ioRequest) {
	var stateData = data;
	faO = dojo.lfx.html.fadeOut(dojo.byId(curTargetDiv),420,null,function(n){ dojo.widget.byId(curTargetDiv).setContent(data)});
	faI = dojo.lfx.html.fadeIn(dojo.byId(curTargetDiv),420);
	dojo.lfx.chain(faO,faI).play();
	if(ioRequest) {
		ioRequest.appState = new ApplicationState(stateData, "output", "dataOutput");
		ioRequest.appState.showStateData();
	}
	if(isInitialState) {
		dojo.undo.browser.setInitialState(appState);
		isInitialState = false;
	}
}


		//****************************************
		dojo.addOnLoad(function(){
			//See if there is a bookmark hash on the page URL.
			var bookmarkId = location.hash;
			if(bookmarkId){
				bookmarkId = bookmarkId.substring(1, bookmarkId.length);
			}
			//If we have a bookmark, load that as the initial state.
			// FIXME: load whatever page and set whatever page, duh
			if(bookmarkId){
				//Load the XHR data for the bookmarked URL
				//alert('loading from bookmark');
				//alert(bookmarkId);
				dojo.undo.browser.setInitialState(appState);
				setMainPane("?"+bookmarkId);
//				dojo.io.bind({
//					url: "?" + bookmarkId,
//					dataId: bookmarkId,
//					load: function(type, evaldObj, http, kwArgs){
//						var stateData = "(Initial State) XHR: " + evaldObj;
//						var appState = new ApplicationState(stateData, "output", "dataOutput");
//						appState.showStateData();
//
//						//Since this is the initial state, don't add it to the dojo.undo.browser
//						//history stack (notice that this dojo.io.bind() request does not define
//						//any back or forward functions). Instead, register the result of this bind
//						//as the initial state for the page.
//						dojo.undo.browser.setInitialState(appState);
//					}
//				});
			}else{
				var appState = new ApplicationState("Initial State", "output", "dataOutput");
				//appState.showStateData();
				dojo.undo.browser.setInitialState(appState);
		isInitialState = false;
			}
		});
function setTabUrl(theTab, theUrl) {
	var docPane = dojo.widget.getWidgetById(theTab);
	var tabCont = dojo.widget.getWidgetById("mainTabContainerPane");
	docPane.setUrl(theUrl);
	tabCont.selectChild(docPane);
}

function addTab(container, tabid, title, eventUrl, selected, scriptSep) {
	var tabPane = dojo.widget.byId(container);
	if (!dojo.widget.byId(tabid)) {
		if (scriptSep) {
			var tabProps = {
					id :tabid,
					href :eventUrl,
					refreshOnShow :"false",
					scriptSeperation :true,
					executeScripts :false,
					label :title,
					closable :"true"
				};
			ifram = document.createElement("iframe");
			ifram.frameborder=0;
			ifram.style.border=0;
			var tab = dojo.widget.createWidget("ContentPane", tabProps,ifram);
			ifram.src = eventUrl;
			tabPane.addChild(tab);
		} else {
			var tabProps = {
				id :tabid,
				href :eventUrl,
				refreshOnShow :"false",
				label :title,
				executeScripts :"true",
				scriptSeperation :false,
				closable :"true"
			};
			var tab = dojo.widget.createWidget("LinkPane", tabProps);
			tabPane.addChild(tab);
		}
	} else {
		var tab = dojo.widget.byId(tabid);
		if(scriptSep) {
			ifram.src = eventUrl;
		} else {
			tab.setUrl(eventUrl);
		}
	}
	if (selected) {
		tabPane.selectChild(tab);
	}
	//TODO: fiqure a nice selected tabs memory deal
	//window.location.hash = eventUrl.split("?")[1];
}

function selectTab(container, tabid) {
	var tabPane = dojo.widget.byId(container);
	var tab = dojo.widget.byId(tabid);
	tabPane.selectChild(tab);
}


function replaceTabLabel(oldLabel, newLabel) {
	var tabWidget = dojo.widget.byId("mainTabContainerPane");
	var buttons = tabWidget.tablist.children;
	for ( var n = 0; n < buttons.length; n++) {
		var button = buttons[n];
		var node = button.domNode;
		if (dojo.dom.textContent(node) == oldLabel) {
			// node.id="tabLabel"+dojo.dom.textContent(node);
			node.innerHTML = node.innerHTML.replace('>' + oldLabel + '<',
					'>' + newLabel + '<');
		}
	}
}
    var scriptScope = this;
    if(typeof _container_ == 'undefined'){
        var _container_ = dojo;
    }


	var properties = {
		hasShadow: true,
		displayCloseAction: true,
		toggle: "fade",
		executeScripts: true,
		closeOnBackgroundClick:true,
		constrainToContainer: false,
		toggleDuration: 300,
		id: "modalWindow"
	};
	
	modalPop = {
			init: function () {
			// create modal background
			modalWindowDiv = document.createElement("div");
			modalWindowDiv.style.width = "100%";
			modalWindowDiv.style.height = "100%";
			
			document.body.appendChild(modalWindowDiv);
				dlgProg = dojo.widget.createWidget("dojo:Dialog",properties, modalWindowDiv);
				//var btn2 = document.getElementById("hider2");
				//dlgProg.setCloseControl(btn2);
			},
			show: function() {
			  dlgProg.show();
			},
			setContent: function(content) {
			  dlgProg.setContent(content);
			},
			hide: function(content) {
			  dlgProg.hide();
			}
	}
	
	_container_.addOnLoad(modalPop.init);
	
	
				var modalWindowDiv;
	
				function setupModalDialog() {
	
					// create modal background
					modalWindowDiv = document.createElement("div");
					modalWindowDiv.style.width = "100%";
					modalWindowDiv.style.height = "100%";
					modalWindowDiv.style.position = "absolute";
					modalWindowDiv.style.top = 0 +"px";
					modalWindowDiv.style.left  = 0 +"px";
					modalWindowDiv.style.display = "none";
					modalWindowDiv.style.backgroundColor = "#BEBEBE";
					modalWindowDiv.style.zIndex = 7;
					
						document.body.appendChild(modalWindowDiv);
				
				}
				dojo.addOnLoad(setupModalDialog);
	
				var dojoWindow = null; 
				var node = null;
				var saveSuccess = true;
				
				function changeSaveSuccess(whatis) {
				  saveSuccess = whatis;
				}
				
				function openModalWindow() {
				
					// Set size of the dialog
					var dlgWidth = 400;
					var dlgHeight = 420;
				
					// Configure DOJO window and DOM node
					var properties = {
						hasShadow: true,
						displayCloseAction: true,
						toggle: "fade",
						executeScripts: true,
						constrainToContainer: false,
						toggleDuration: 399,
						style: "display:none",
						title: "Results",
						titleHeight: "20",
						resizable: true,
						id: "modalWindow"
					};
					node = document.createElement("div");
					node.style.width = dlgWidth +"px";
					node.style.height = dlgHeight + "px";
					node.style.left = 150 + "px";
					node.style.top = 150 + "px";
					node.innerHTML = "Processing...";
					node.style.zIndex = 99999;
				
					// Launch DOJO window
					document.body.appendChild(node);
					dojoWindow = dojo.widget.createWidget("FloatingPane",properties,node);
					modalWindowDiv.style.display = "block";
					dojo.html.setOpacity(modalWindowDiv,0.5);
					
					dojo.event.connect(dojoWindow, "closeWindow", this,"closeDojoWindowCleanup"); 
//					dojo.lfx.rounded({
//							tl:{ radius:5 },
//							bl:{ radius:5 },
//							tr:{ radius:5 },
//							br:{ radius:5 }
//						}, 
//						["modalWindow"]
//					);
					return dojoWindow;	
				}
				
				this.closeDojoWindowCleanup = function() {
					modalWindowDiv.style.display = "none";
					dojoWindow = null;
				};
	
				
				function modalSubmitFormToEvent(formId,eventUrl,successUrl,saveButton) {
					curSaveButton = dojo.widget.byId(saveButton);
					curSuccessUrl = successUrl;
					curForm = formId;
					if (allInputValid(dojo.byId(formId)))
					{
						curSaveButton.setDisabled(true);
					  openModalWindow();
					  // dlg.show();
						//fadeForm = dojo.lfx.html.fade(curForm,{start:1, end:.5}, 300);
						//fadeForm.play();
					  dojo.io.bind ({
					    url: eventUrl,
					    handler: modalCallBack,
				    	sync:true,
					    //backButton:function(){alert('back');},
					    formNode: dojo.byId(formId),
			    		mimetype: "text/html",
			    		executeScripts:true
					  });
					}
				}

				function setModalFromEvent(eventUrl,formId) {
					  dojo.io.bind ({
					    url: eventUrl,
					    handler: function(type, data, evt){ dojoWindow.setContent(wrapWithOK(data)); },
					    sync:true,
					    formNode: formId,
			    		mimetype: "text/html",
			    		executeScripts:true
					  });
				}
				
				function okButtonOnClick() {
					if(typeof curafterSuccessJS != 'undefined') { 
						eval(curafterSuccessJS);
						dojoWindow.closeWindow();
					} 
					else {
						dojoWindow.closeWindow();
					}
				}

				function wrapWithOK(content) {
					 if(content.search(/error/i) > 0 || content.search(/Oops!/i) > 0 || content.search(/Declined/i) > 0) {
							dojo.event.connect(dojoWindow, "closeWindow", function(n){curSaveButton.setDisabled(false)});
							curafterSuccessJS = "curSaveButton.setDisabled(false);";
					 }
					 else {
							dojo.event.connect(dojoWindow, "closeWindow", function(n){eval(curafterSuccessJS)});
					 }
				   var b = dojo.widget.createWidget("Button", {caption: "OK", onClick: okButtonOnClick });
					 var resultDiv = document.createElement("div");
					 var buttonDiv = document.createElement("div");
				   resultDiv.innerHTML = content;
				   buttonDiv.style.paddingTop = "15px";
				   buttonDiv.align = "center";
				 	 buttonDiv.appendChild(b.domNode);
				 	 resultDiv.appendChild(buttonDiv);
					 //dojo.event.connect(b, "onclick", dojoWindow.closeWindow);
					 //dojo.event.connect(b, "onclick", function(n){eval(curafterSuccessJS)});
				 	 return resultDiv;
				}
				
				function validateCallBack(type, data, evt) {
				   var b = dojo.widget.createWidget("Button", { caption: "OK"});
					 var resultDiv = document.createElement("div");
					 var buttonDiv = document.createElement("div");
				   resultDiv.innerHTML = data;
				   buttonDiv.style.paddingTop = "15px";
				   buttonDiv.align = "center";
				 	 buttonDiv.appendChild(b.domNode);
				 	 resultDiv.appendChild(buttonDiv);
					 dojo.event.connect(resultDiv, "onclick", dojoWindow.closeWindow);
					 //alert(data.substring(4,9))
					 if (data.substring(4,9) == 'Saved') {
					 //if (saveSuccess) {
					 		dojo.event.connect(resultDiv, "onclick", function(n){setMainPane(curSuccessUrl)});
							dojo.event.connect(dojoWindow, "closeWindow", function(n){setMainPane(curSuccessUrl)});
					 } else {
					 		dojo.event.connect(resultDiv, "onclick", function(n){curSaveButton.setDisabled(false)});
							dojo.event.connect(dojoWindow, "closeWindow", function(n){curSaveButton.setDisabled(false)}); 
					 }
				   dojoWindow.setContent(resultDiv);
				}
				
				function modalCallBack(type, data, evt) {
				   var b = dojo.widget.createWidget("Button", { caption: "OK"});
					 var resultDiv = document.createElement("div");
					 var buttonDiv = document.createElement("div");
				   resultDiv.innerHTML = data;
				   buttonDiv.style.paddingTop = "15px";
				   buttonDiv.align = "center";
				 	 buttonDiv.appendChild(b.domNode);
				 	 resultDiv.appendChild(buttonDiv);
					 dojo.event.connect(resultDiv, "onclick", dojoWindow.closeWindow);
					 //alert(data.substring(4,9))
/* 					 if (data.substring(4,9) == 'Saved') {
					 //if (saveSuccess) {
					 		dojo.event.connect(resultDiv, "onclick", function(n){setMainPane(curSuccessUrl)});
							dojo.event.connect(dojoWindow, "closeWindow", function(n){setMainPane(curSuccessUrl)});
					 } else {
 */
 					 		dojo.event.connect(resultDiv, "onclick", function(n){curSaveButton.setDisabled(false)});
							dojo.event.connect(dojoWindow, "closeWindow", function(n){curSaveButton.setDisabled(false)}); 
/*
 					 }
 */
 				   dojoWindow.setContent(resultDiv);
				}					
	function addNavHistory (text,url) {
  dojo.io.bind ({
    url: "?event=public.navigation.history.add",
		// handler: retFormData,
		// changeUrl: 'form',
		content: { historyText : text, historyUrl : url}
  });
//	var historySelect = dojo.widget.byId('navigationHistory');
//	historySelect.setAllValues(text,url);
}

function setMainPane(eventUrl,originator) {
	var mgevent = eventUrl.split('?')[1]; // get just the script_name and query string
	//var mgevent = eventUrl.split('/')[eventUrl.split('/').length-1]; // get just the script_name and query string
	//var mgevent = eventUrl.split('?')[1].split('=')[1];  // get only the event name
	var text = "";
	if(originator) {
		if (originator.title) {
			text = originator.title;
		}
		if (!originator.innerHTML.indexOf('img ')) {
			text = originator.innerHTML;
		}
		if(text.length > 0) {
			addNavHistory(text,eventUrl);
		}
	}
	setDivContent('mainPane',eventUrl,originator,mgevent);
}

function confirmation(destURL) {
		window.location = destURL;
	/*
	var answer = confirm("Go to payment site?");
	if (answer){
		window.location = destURL;
	}
	else{
		alert("Feel free to browse around some more!");
	}
	*/
}
function allInputValid(f) {
	var s = '';
	var canSubmit = true;
  var inValidMsg = '';
  var hasReqMsg = '';
	for (var i = 0; i < f.elements.length; i++) {
	    var elem = f.elements[i];
	    aDojoWidget = dojo.widget.byId(elem.name);
	    if (aDojoWidget && typeof aDojoWidget.isMissing != 'undefined') {
	    /*
	    s += elem.name + ": " + elem.value + 
	    " valid: " + aDojoWidget.isValid() + 
	    " is missing:" +aDojoWidget.isMissing() +
	    "" + aDojoWidget.missingMessage + "\n";//with elem.isValid() didn't work too
	    */
	    if (aDojoWidget.isMissing()) {
	        aDojoWidget.updateClass('Invalid');
          canSubmit = false;
					hasReqMsg = 'Please correct the fields marked as required';
      }
	    if (!aDojoWidget.isValid()) {
	        aDojoWidget.updateClass('Invalid');
          canSubmit = false;
					inValidMsg = '\nPlease correct the fields marked as invalid';
	    }
    }
	}
	if(!canSubmit) alert(hasReqMsg+inValidMsg);
	return canSubmit;
}

function dojoSubmitForm(formId,eventUrl,successUrl,afterSuccessJS,saveButton) {
	curSuccessUrl = successUrl;
	curafterSuccessJS = afterSuccessJS;
	if (allInputValid(dojo.byId(formId))) {
		if (saveButton) {
			curSaveButton = dojo.widget.byId(saveButton);
			curSaveButton.setDisabled(true);
		}
		if (successUrl) {
			if (eventUrl == successUrl) {
			  openModalWindow();
			 	setModalFromEvent(eventUrl,formId);
			}
			else {
			  openModalWindow();
				curSuccessUrl = successUrl;
				curafterSuccessJS = afterSuccessJS;
				curForm = formId;
			  dojo.io.bind ({
			    url: eventUrl,
			    handler: dojoSubmitCallBack,
			    formNode: formId,
			    sync:true,
	    		mimetype: "text/html",
	    		executeScripts:true,
	    		scriptSeparation:true
			  });
			}
		}
		else {
		  dojo.io.bind ({
		    url: eventUrl,
		    formNode: formId,
		    sync:true
		  });					
		}
	}
}

function dojoSubmitCallBack(type, data, evt) {
	 //alert(data.substring(4,9))
	 if (data.length < 5) {
		 	setModalFromEvent(curSuccessUrl);
	 } 
	 else {
	   	dojoWindow.setContent(wrapWithOK(data));
	 }
}


		// this is how we communicate with the cart. uncheck == ID of checkbox to uncheck, if there is one
		function submitFormToEvent(cartItem,formId,eventUrl,uncheckId) {
			 if(dojo.byId('sec'+cartItem)) {
			 	targetSwap = dojo.byId('sec' + cartItem);
			 	} 
			 else { 
			 	targetSwap = dojo.byId('crt' + cartItem);
			 }
			curCartItem = targetSwap;
			cartElement = dojo.byId('cartNav');
			curUncheck = uncheckId;
			if(curCartItem) curCartItem.style.backgroundColor = "#749C9C";
			fadeO = dojo.lfx.html.fadeOut(cartElement,100).play();
		  dojo.io.bind ({
		    url: eventUrl,
		    handler: callBack,
		    formNode: dojo.byId(formId),
		    mimetype: "text/html"
		  });
		}

		function formToVoidEvent(formId,eventUrl) {
		  dojo.io.bind ({
		    url: eventUrl,
		    //handler: callBack,
		    formNode: dojo.byId(formId),
		    mimetype: "text/html"
		  });
		}

		function destryOldCBs() {
			var checkBoxDiv = dojo.byId('cartNav');
			var boxes = checkBoxDiv.getElementsByTagName("input");
      for(var i = 0; i < boxes.length; i++){
        var elm = boxes[i];
     		if (elm.type=="checkbox" || elm.type=="button") {
            var ck = dojo.widget.byId(elm.name);
            ck.destroy();
            //ck._updateImgSrc();
          }
			}
		}

    function unCheckDojo(checkBoxId) {
    	var chkBx = dojo.widget.byId(checkBoxId);
			if (chkBx){
				chkBx.setValue(false);
			}
    }

		function checkUn() {
			if(curUncheck){
				unCheckDojo(curUncheck);
			}
		}
		
		function callBack(type, data, evt) {
			//destryOldCBs();
	   	dojo.widget.byId('cartNav').setContent(data);
			swapLeft = dojo.lfx.html.implode(curCartItem,cartElement, 700, null, checkUn);
			swapRight = dojo.lfx.html.explode(cartElement,curCartItem, 700);
			fadeI = dojo.lfx.html.fadeIn(cartElement,300);
			dojo.lfx.chain(swapLeft,swapRight,fadeI).play();
			/*
			if(curCartItem.alt == 'add to cart') {
				curCartItem.alt='remove from cart';
				curCartItem.title='remove from cart';
				curCartItem.src='cart_remove.gif';
				curCartItem.style.backgroundColor = "#660000";
			} else {
				curCartItem.alt='add to cart';
				curCartItem.title='add to cart';
				curCartItem.src='cart_round.gif';
				curCartItem.style.backgroundColor = "#749C9C";
			}
			*/
			// var renderCartChecks = dojo.widget.createWidget(dojo.byId('cartNav'));
		}
		    var o = {
		        listen: function(evt){
		        	  var currentEl = evt.target;
		//             alert(currentEl.nodeName.toLowerCase());
	//            	 dojo.debugShallow(currentEl);
//                 evt.preventDefault(); // stop the link from unloading your page
                if (currentEl.parentNode.nodeName.toLowerCase()=='a') {
                	currentEl = currentEl.parentNode;
                }
                
		            // if the onclick came from a "a" link we stop it.
		            if( (currentEl.nodeName.toLowerCase()=='a' || currentEl.nodeName.toLowerCase()=='area')
		            	&& currentEl.target.toLowerCase() != '_blank'){
		                evt.preventDefault(); // stop the link from unloading your page
		                if(typeof currentEl.onclick == 'undefined' || currentEl.onclick == null ) {
			                setMainPane(currentEl.href);
		                }
		            }
		            if(currentEl.onchange) currentEl.onchange = ''; 
		            if(currentEl.type && (currentEl.type.toLowerCase()=='submit' || currentEl.type.toLowerCase()=='image')){
		          //  	dojo.debugShallow(currentEl.parentNode);
		                //DP_Debug.dump(currentEl);
		          //      alert('proxing');
//						formSubmitProxy(currentEl.parentNode);
//						dojo.debugShallow(currentEl.parentNode.name);
/*
						tes = new dojo.io.FormBind({
						    // reference your form
						    formNode: currentEl.parentNode,								
						    load: function(load, data, e) {
						      // what to do when the form finishes
						      // for example, populate a DIV:
						      dojo.byId('mainPane').innerHTML = data;
						    }
						  });
						  currentEl.parentNode.submit();
 */
		 					  	var queryStr = (currentEl.form.action.split("?")[1] || '');
									evt.preventDefault(); // stop the link from unloading your page
				 					bindDaForm(currentEl,currentEl.form,currentEl.form.action.split("?")[0] + "?" + queryStr);
		            }
		        }
		    }

    dojo.addOnLoad(function(){
     // this and the "o" above handle "a href" replacemnt
     // catch the onclick when it has bubbeled up to our domNode
     //container = dojo.widget.byId('mainPane');
     //dojo.event.connect(container.domNode, "onclick", o, "listen");
     dojo.event.connect(document.body, "onclick", o, "listen");
		});

    dojo.addOnUnload(function(){
     dojo.event.disconnect(document.body, "onclick", o, "listen");
    });

    function bindDaForm(sourceButton,formNode,url) {
		  var subbut = document.createElement('input');
		  subbut.setAttribute('type',"hidden");
		  subbut.setAttribute('id',sourceButton.id);
		  subbut.setAttribute('name',sourceButton.name);
		  subbut.setAttribute('value',sourceButton.value);   
		  formNode.appendChild(subbut);
			if (allInputValid(formNode)) {
			  dojo.io.bind ({
			    url: url,
			    handler: retFormData,
					// changeUrl: 'form',
			    formNode: formNode,
			    executeScripts:true
			  });
			}
    }

    function retFormData(type,data,evt) {
    	whyDoIhaveTo = data;
    	updateDivContent(type,whyDoIhaveTo,evt);
    }
		    

		    
var scriptScope = this;
if(typeof _container_ == 'undefined'){
    var _container_ = dojo;
}


	focusMainTab = function () {
		var docPane = dojo.widget.getWidgetById("mainPane");
		var tabCont= dojo.widget.getWidgetById("mainTabContainerPane");
		tabCont.selectChild(docPane);
	}


	focuser = {
			init: function () {
				dojo.event.connect("after", "setMainPane", "focusMainTab");
				//dojo.event.connect("after",this,"setMainPane",focuser,"setTabFocus");
				dojo.event.connect("after", "bindDaForm", "focusMainTab");
				//dojo.event.connect("after",this,"setMainPane",focuser,"setTabFocus");
			},
			destroyMe: function () {
				dojo.event.disconnect("after", "setMainPane", "focusMainTab");
				dojo.event.disconnect("after", "bindDaForm", "focusMainTab");
			},
			setTabFocus: function () {
				var docPane = dojo.widget.getWidgetById("mainPane");
				var tabCont= dojo.widget.getWidgetById("mainTabContainerPane");
				tabCont.selectChild(docPane);
			}
	}

_container_.addOnLoad(focuser.init);
_container_.addOnUnload(focuser.destroyMe);



