function prepareErrorForAjaxCall(error) {
	//alert("error val:"+error);
	if(error == parallelSessionError) {
		//alert("parallelSessionError");
		document.forms[0].action= contextPath +"/logout.do?operation=doSessionOut";  //Note: contextPath defined in pagelayout.jsp
		document.forms[0].submit();
	} else if(error == sessionTimeOutError) {
		//alert("sessionTimeOutError");
		document.forms[0].action= contextPath +"/logout.do?operation=doSessionOut";  //Note: contextPath defined in pagelayout.jsp
		document.forms[0].submit();
	} else if(error == userHasBeenEdited){
		//alert("userHasBeenEdited");
		document.forms[0].action= contextPath +"/logout.do?operation=doSessionOut";  //Note: contextPath defined in pagelayout.jsp
		document.forms[0].submit();
	} else{
		//alert("other Error : " + error);
		//alert("contextPath:"+contextPath);
		document.forms[0].action= contextPath +"/logout.do?operation=doSessionOut";  //Note: contextPath defined in pagelayout.jsp
		document.forms[0].submit();
	}
}

function getDocumentHeight() {
	var body = document.getElementsByTagName("body")[0];
	var innerHeight = 0;
	if(self.innerHeight){
		innerHeight = self.innerHeight;
	}
	if (!document.compatMode || document.compatMode=="CSS1Compat") {
	var topMargin = 0;
	var bottomMargin = 0;
	return Math.max(body.offsetHeight + topMargin + bottomMargin,document.documentElement.clientHeight,document.documentElement.scrollHeight, 0);
	}
	return Math.max(body.scrollHeight, body.clientHeight,0);
 }
 
 function getDocumentWidth() {
	var body = document.getElementsByTagName("body")[0];
	var innerWidth = 0;
	if(self.innerWidth){
		innerWidth = self.innerWidth;
	}
	if (!document.compatMode || document.compatMode=="CSS1Compat") {
	var topMargin = 0;
	var bottomMargin = 0;
	return Math.max(body.offsetWidth + topMargin + bottomMargin,document.documentElement.clientWidth,document.documentElement.scrollWidth, 0);
	}
	return Math.max(body.scrollWidth, body.clientWidth,0);
 }
 
 function showOverlaydiv(){
	resizeOverlaydiv();
	document.getElementById("overlayDiv").style.display='';
	showOverlayFrame();
	
 }

 function hideOverlaydiv(){
	document.getElementById("overlayDiv").style.display='none';
	hideOverlayFrame();
	
 }
 
 function showOverlayFrame(){
 	resizeOverlaydiv();
 	document.getElementById("overlayFrame").style.display='';
 }
 
 function hideOverlayFrame(){
 	document.getElementById("overlayFrame").style.display='none';
 }

function resizeOverlaydiv(){
	document.getElementById("overlayDiv").style.height = getDocumentHeight() + "px";
	document.getElementById("overlayDiv").style.width = getDocumentWidth() + "px";
	document.getElementById("overlayFrame").style.height = getDocumentHeight() + "px";
	document.getElementById("overlayFrame").style.width = getDocumentWidth() + "px";
}

/**This function is used to place an element on center of browser**/
 function getCenterPos(Xwidth,Yheight) {
	// First, determine how much the visitor has scrolled
	var scrolledX, scrolledY;
	if( self.pageYoffset ) {
	scrolledX = self.pageXoffset;
	scrolledY = self.pageYoffset;
	} else if( document.documentElement && document.documentElement.scrollTop ) {
	scrolledX = document.documentElement.scrollLeft;
	scrolledY = document.documentElement.scrollTop;
	} else if( document.body ) {
	scrolledX = document.body.scrollLeft;
	scrolledY = document.body.scrollTop;
	}

 	var centerX = 0, centerY = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
	  //Non-IE
	  centerX = window.innerWidth;
	  centerY = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	  //IE 6+ in 'standards compliant mode'
	  centerX = document.documentElement.clientWidth;
	  centerY = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	  //IE 4 compatible
	  centerX = document.body.clientWidth;
	  centerY = document.body.clientHeight;
    }
	
	// Xwidth is the width of the div, Yheight is the height of the
	// div passed as arguments to the function:
	var leftoffset = scrolledX + (centerX - Xwidth) / 2;
	var topoffset = scrolledY + (centerY - Yheight) / 2;
	// the initial width and height of the div can be set in the
	// style sheet with display:none; divid is passed as an argument to // the function
	return [leftoffset,topoffset];
 } 
 
 function cloner(element){
 	return element.cloneNode(true);
 }
 
 function showError(error)
 	{
 			var jsErrorDiv = $("jsErrorDiv");
     		var jsErrorMsg = $("jsErrorMsg");
     		var focusDiv = $("focusDiv");
     		var focusField = $("focusField");
     		if(jsErrorMsg){
     			jsErrorMsg.innerHTML = error;
     		}
     		if(jsErrorDiv){
     			jsErrorDiv.style.display = "block";
     			if(focusDiv){
     				focusDiv.style.display="";
     			}
     			if(focusField){
     				focusField.focus();
     			}
     		} else {
     			alert(error);
     		}
     		return false; 
 	}
 

 
  
 String.prototype.trim = function() {
 	a = this.replace(/^\s+/, '');
 	return a.replace(/\s+$/, '');
 };
 
 String.prototype.startWith = function(str) {
 	if(this.substr(0,str.length).match(str)) {
 		return true;
 	}
 	return false;	
 };
 
 String.prototype.endWith = function(str) {
 	if(this.substr((this.length-str.length),this.length).match(str)) {
 		return true;
 	}
 	return false;	
 };
 
 Array.prototype.exists = function(o) {
	for(var i = 0; i < this.length; i++)
	   if(this[i] == o)
	     return true;
	return false;
 }
 
 Array.prototype.asSet = function() {
  
 	var tempArr = new Array();
 	for(var i = 0; i < this.length; i++) {
 		if(!tempArr.exists(this[i])){
 			tempArr[tempArr.length] = this[i];
 		}
 	}
 	return tempArr;
 }
 
 Array.prototype.removeObject = function(o) {
 	var tempArr = new Array();
 	for(var i = 0; i < this.length; i++) {
 		if(this[i] != o){
 			tempArr[tempArr.length] = this[i];
 		}
 	}
 	return tempArr;
 }
 
 function createElement(tagname){
 	var newElement = document.createElement(tagname);
 	return newElement;
 }
 
 function updateMultiSelectByName(elementName){
 	var ele = document.getElementsByName(elementName)[0];
 	if(ele){
	   	if(ele.selectedIndex==-1){
	   		var option = createElement('option');
	   		option.innerHTML="";
	   		option.style.display = 'none';
	   		ele.appendChild(option);
	   		ele.options[ele.options.length-1].selected=true;
	   	}
	 }
 }
 
 
	//set maxlength for textarea field
	function maxLen(limitField, limitNum) 
	{ 	
		
		limitNum=limitNum-1; 
		if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
		} 
	}
	
	function paginationFormChange(form, selectionElement, requestURI){
		selectElement = selectionElement.options[selectionElement.selectedIndex].value;
		form.action = requestURI + selectElement;
		form.submit();
	}
	
	function removeAllChild(parentNode){
 	 	while(parentNode.hasChildNodes()){
 	 		parentNode.removeChild(parentNode.lastChild);
 	 	}
 	}

 	function get_previoussibling(n)
	{
		var x=n.previousSibling;
		while (x.nodeType!=1)
		{
		x=x.previousSibling;
		}
		return x;
	}
	
	function getOperator(op){
 		if(op == "is equal to") {
 			return "=";
 		} else if(op == "is not equal to") {
 			return "!=";
 		} else if(op == "is greater than") {
 			return ">";
 		} else if(op == "is less than") {
 			return "<";
 		} else if(op == "is greater than or equal to") {
 			return ">=";
 		} else if(op == "is less than or equal to") {
 			return "<=";
 		} else {
 			return op;
 		} 
 	}
 	
 	function elementByName(eleName){
		var elements = document.getElementsByName(eleName);
		if(elements.length == 0){
			alert("No element found with name " + eleName);
			return null;
		} else {
			return elements[0];
		}
	}
	
	/*This function is used to float a div while scrolling through the page*/
	function JSFX_FloatDiv(id, sx, sy)
	{
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		var px = document.layers ? "" : "px";
		window[id + "_obj"] = el;
		if(d.layers)el.style=el;
		el.cx = el.sx = sx;el.cy = el.sy = sy;
		el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
	
		el.floatIt=function()
		{
			var pX, pY;
			pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
			document.documentElement && document.documentElement.clientWidth ? 
			document.documentElement.clientWidth : document.body.clientWidth;
			pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
			document.documentElement.scrollTop : document.body.scrollTop;
			if(this.sy<0) 
			pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
			document.documentElement.clientHeight : document.body.clientHeight;
			this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
			this.sP(this.cx, this.cy);
	
	
			setTimeout(this.id + "_obj.floatIt()", 2);
		}
		return el;
	}
