function validateForm(theForm) {
    var widgets = theForm.getChildren() ;
	for(var i = 0; i < widgets.length; ++i) {
		if ( (widgets[i].isValid) && (!widgets[i].isValid()) ) {
			widgets[i].focus() ;
			return false ;
		}
	}
	return true ;
}

// Input:  An array of errorObjects
// The object has "errorCode", "attributeName", and "message" fields
// Output:  Shows the errors in the div, and if the form contains "attributeName" as a widget, 
// it sets the error message for that attribute and moves the focus to that control. 
function showServiceErrors(errorObjs, divID, theForm) {
    var theDiv = dojo.byId(divID) ;
    if ( theDiv != null ) {
    	var errStr = "" ;
    	for(var i = 0; i < errorObjs.length; ++i) {
    		if ( (errorObjs[i].attributeName != null) && (errorObjs[i].attributeName.trim().length > 0) ) {
        		errStr = errStr + "<p>" + errorObjs[i].attributeName + " - " + errorObjs[i].message + "</p>" ;
    		} else {
    			errStr = errStr + "<p>" + errorObjs[i].message + "</p>" ;
    		}
    	}
    	if (errStr.length > 0) {
    		theDiv.innerHTML = errStr ;
    	}
    }
}

function clearErrorsDisplay(divID) {
    var theDiv = dojo.byId(divID) ;
    if ( theDiv != null ) {
      theDiv.innerHTML = "" ;
    }
}

function TabTitle() {
	this.id = "0" ;
	this.regInnerHTML = "" ;
	this.selectedInnterHTML = "" ;
	this.onSelect = null ;
	this.onUnselect = null ;
}

function TabBar(noOfItems) {
	this.tabs = new Array() ;
	this.currSelection = -1 ;

	this.addTabTitle = function(newTabTitle, pos) {
		this.tabs[pos] = newTabTitle ;
	};

	this.showTabTitles = function() {
		for(var i = 0; i < this.tabs.length; ++i) {
			if (this.tabs[i] != null) {
				dojo.byId(this.tabs[i].id).innerHTML = this.tabs[i].regInnerHTML ;
			}
		}	
	};
	
	this.selectTab = function(index) {
		if (this.currSelection != index) {
			this.unselectTab(this.currSelection) ;
			dojo.byId(this.tabs[index].id).innerHTML = this.tabs[index].selectedInnerHTML ;
			this.currSelection = index ; 
			if (this.tabs[index].onSelect != null) {
				window[this.tabs[index].onSelect]() ;
			}
		}
	};

	this.unselectTab = function(index) {
		if ( index != -1 ) {
			dojo.byId(this.tabs[index].id).innerHTML = this.tabs[index].regInnerHTML ;
		}
	};
};

function unloadMessage(page)
{
	/* action = confirm("You will lose your changes if you navigate away from this page.Do you want to proceed?");
     if (action)
         { 
         	window.location="invalidatesession.jsp" ;
         }else
         {
        	 window.location=page ;
         }*/
} 

