function verifyUserAction(isXtendForm, obj,xtdlk,caption) {
  var retVal = confirm(caption);
  if(retVal) {
    if(isXtendForm) {
      log("isXtendForm");
      xPostAction(obj, xtdlk);
    } else {
      log("NOT isXtendForm");
      obj.submit();
    }
    //requires jquery
    $(".structure").fadeOut("slow", function () {
        //$("#fadetext").text("Please wait while your page is loading...");
        $("#fadetext").addClass("normalTxtBold");
        $("#fadeimage").fadeIn("slow");
        $("#fadetext").fadeIn("slow");
        $(this).addClass("nodisplay");
        $(this).remove();
        });

  }
}
                  

// Return selected value of the select tag aName
	function SelectGetVal(aName)
 	{
 		wElmt=cFormObj.elements[aName];
 		//wElmt=document.forms[0].elements[aName];
 		if (wElmt!=null) return wElmt.options[wElmt.selectedIndex].value; else return "";
 	}
 	// Return selected Text of the select tag aName
	function SelectGetText(aName)
 	{
 		wElmt=cFormObj.elements[aName];
 		//wElmt=document.forms[0].elements[aName];
 		if ((wElmt!=null) && (wElmt.selectedIndex >= 0)) return wElmt.options[wElmt.selectedIndex].text; else return "";
 	}
 	// Select option aValue into aName - Return true if selected
	function SelectSetVal(aName,aValue)
 	{
		var wResult=false;
 		wElmt=cFormObj.elements[aName];
 		//wElmt=document.forms[0].elements[aName];
 		if (wElmt!=null) 
		{
			for (var i = 0; i < wElmt.options.length; i++) 
			{   
				//alert(wElmt.options[i].value +  "Txt=" + wElmt.options[i].text);
				if (wElmt.options[i].value==aValue)
				{
					wElmt.options[i].selected=true;
					wResult=true;
				}
			}
		}
		return wResult
 	}
	// Return today date according to X3 format
	function toDayX3()
 	{
		var wTD=new Date();
		var wResult=new String(wTD.getFullYear());
		if (wTD.getMonth()<9) wResult+="0";
		wResult+= new String(wTD.getMonth()+1);
		if (wTD.getDate()<10) wResult+="0";
		wResult+= new String(wTD.getDate());
 		return wResult;
 	}
	// Return firstday of current year
	function firstYearDayX3()
 	{
		return toDayX3().substring(0,4) + "0101";
	}
	// Read input field in current form
	function GetInputValue(aInputName) {				
	  	var wElmt=cFormObj.elements[aInputName];							
	  	//var wElmt=document.forms[0].elements[aInputName];							
  		if (wElmt!=null)
			return wElmt.value;
		else
			return '';
	}	
	// Set input field in current form
	function SetInputValue(aInputName,aValue) {														
  		var wElmt=cFormObj.elements[aInputName];							
  		//var wElmt=document.forms[0].elements[aInputName];							
  		if (wElmt!=null)
			wElmt.value=aValue;																								
	}
	// If checkbox aName is unchecked then set value to aUnCheckValue - Posted form will contain a value even if input is unchecked
	function checkBox_CheckUnChecked(aName,aUnCheckValue)
	{
		var wElmt=cFormObj.elements[aName];							
		//var wElmt=document.forms[0].elements[aName];							
  		if (wElmt!=null)
  		{
			if (!wElmt.checked) wElmt.value=aUnCheckValue;
		}
	}
	// Check radio button - Input Name (group)=aName
	// aValue=value to check
	// aDefault= index (0-N) of input to check if no value found
	function radioCheck(aName,aValue,aDefault)
	{
		var wElmts=cFormObj.elements[aName];
		//var wElmts=document.forms[0].elements[aName];
		if (wElmts!=null)
		{
			if (wElmts.length==undefined)
			{	
				if (wElmts.value==aValue)
					wElmts.checked=1; 
				else
					wElmts.checked=0; 
			}
			else
			{
				var wFound=false;
				for (var i=0;i<wElmts.length;i++)
				{     	
					if (wElmts[i].value==aValue)
					{
						wElmts[i].checked=1; 
						wFound=true;
				  	}else
						wElmts[i].checked=0; 
		  		}
				if (!wFound)
				{
					if (aDefault>=0 && aDefault<wElmts.length)
						wElmts[aDefault].checked=1; 
					else
						wElmts[0].checked=1; 
				}
			}
		}
	}
	// Return the value of checked input - empty string by default
	function radioGetCheckedValue(aName)
	{
		var wRes="";
		var wElmts=cFormObj.elements[aName];
		//var wElmts=document.forms[0].elements[aName];
		if (wElmts!=null)
		{
			if (wElmts.length==undefined)
			{	
				if (wElmts.checked==1) 
					wRes=wElmts.value;
			}
			else
			{
				for (var i=0;i<wElmts.length;i++)
				{     	
					if (wElmts[i].checked==1) 
						wRes=wElmts[i].value;
		  		}
			}
		};
		return wRes;
	}
	function getDateText(aInputName,aSep)
	{
		return SelectGetVal(aInputName + '_yyyy') + '/' + SelectGetVal(aInputName + '_mm') + '/' + SelectGetVal(aInputName + '_dd');
	}
	function getDateInput(aInputName)
	{
		return SelectGetVal(aInputName + '_yyyy') + SelectGetVal(aInputName + '_mm') + SelectGetVal(aInputName + '_dd');
	}
	// Set input date  fields according of content of field aFieldName
	// aFieldName_yy, _mm, dd - DefDate is field empty
	function setDateInput(aFieldName,aDefDate)
	{
		var wDate=GetInputValue(aFieldName);
		if (wDate.length==0) wDate=aDefDate;
		SetInputValue(aFieldName + "_yyyy",wDate.substring(0,4)); 
		SetInputValue(aFieldName + "_mm",wDate.substring(4,6)); 
		SetInputValue(aFieldName + "_dd",wDate.substring(6,8)); 
	}
	// Set input dateMin adn dateMax fields YY, MM DD with aMinDateFld and aMaxDateFld
	function setDateMinMax(aMinDateFld,aMaxDateFld)
	{
		// MinDefault=beginning of current year
		setDateInput(aMinDateFld,firstYearDayX3());
		// MaxDefault=ToDay
		setDateInput(aMaxDateFld,toDayX3());
	}
	// Save user selection into  aMinDateFld and aMaxDateFld input fields
	function saveDateMinMax(aMinDateFld,aMaxDateFld)
	{
		SetInputValue(aMinDateFld,getDateInput(aMinDateFld)); 
		SetInputValue(aMaxDateFld,getDateInput(aMaxDateFld));
	}
	// Call an anchor in a same Xtend page 
	function DoCallAnchor(aAnchor){
		wLocation = location.href.split("#");
		wAnchor = wLocation[0] + "#" + aAnchor ;
		window.location.href=wAnchor;
		//window.location.hash= aAnchor;
		return;
	}
	// Return the style of an elmt 
	function getStyle(aId)
	{
		var wElmt=document.getElementById(aId);
		if (wElmt!=null)
			return wElmt.style;
		else
			return null;
	}
	// Hide elmt aId
	function hide(aId)
	{
		var wStyle=getStyle(aId);
		if (wStyle!=null) wStyle.display="none";
	}
	// Show elmt aId
	function show(aId)
	{
              try {
		var wStyle=getStyle(aId);
		if (wStyle!=null) wStyle.display="";
		if (browser.isIE) { var mStyle = getStyle('midright_content'); mStyle.zIndex="-1";}
              } catch(e) {}
	}
	//
	function xQSArrayGetValue(aQSArray,aKey)																										
	{										
		var wRes='';
		var wKey=aKey+"="
		if (aQSArray.length!=0) 																																
		{	
			for (i=0; i < aQSArray.length && wRes.length==0; i++) 																												
			{   							
				var wElmt=aQSArray[i];
				if (wElmt.indexOf(wKey)!=-1)
				{
					wRes=wElmt.substring(wElmt.indexOf('=') + 1,wElmt.length);
				}	
				// alert( wElmt + ' - ' + wElmt.indexOf(wKey) +  ' - wRes=' + wRes);
			}																																								}																																					
		return wRes;																																			
	}
	function trim(aStr)
	{
		if (aStr!=null && aStr.indexOf(' ')!=-1)
			return aStr.replace(/\s*$/,'').replace(/^\s*/,'');
		else 
			return aStr;
	}
	function fullTrim(aStr)
	{
		if (aStr!=null)
			return aStr.replace(/\s*\r*\t*\n*$/,'').replace(/^\s*\r*\t*\n*/,'');
		else 
			return aStr;
	}
	function stringToArray(aStr,aSep)																														
	{																																								
		if (aStr==null || aStr.length==0){																																	
			return new Array(); 																																
		}else{																																						
			if (aStr.indexOf(aSep)==-1) {																													
				return new Array(aStr);																														
			 }else{																																				
				return aStr.split(aSep);}																														
		}																																							
	}
	// Set input fields with name=aInputName in current form
	function SetInputListValue(aInputName,aValue)
	{
		var wElmts=cFormObj.elements[aInputName];
		//var wElmts=document.forms[0].elements[aInputName];
		if (wElmts!=null)
		{
			var wLength=wElmts.length==undefined?1:wElmts.length;
			if (wLength==1)
				wElmts.value=aValue;
			else
			{
				for (var i=0;i<wLength;i++)
					wElmts[i].value=aValue;	
			}
		}
	}
/***********************************************/
/*          CLASS  NUMERIC STRING              */
/***********************************************/
CXNumStr=function (aValue) 
{		
	if (aValue==null)
		this.pValue=new String();
	else
		this.pValue=fullTrim(aValue.toString());	
	if (this.pValue.charAt(0)=='-')
	{
		this.pSign=-1;
		this.pValue=fullTrim(this.pValue.substring (1,this.pValue.length));
	}else if (this.pValue.charAt(0)=='+')
	{
		this.pSign=1;
		this.pValue=fullTrim(this.pValue.substring (1,this.pValue.length));
	} else
		this.pSign=1;													
} 
	// True if Qty of - Used by all classes - 0 Qties non allowed
	function checkQuantity(aQty)
	{ 	
		return new CXNumStr(aQty.toString()).isQuantity(0);
	}
	// Return input fields with name equals to aInputName into an array 
	function getArrayInput (aInputName)
	{
		var wResult=null;			
		// Init array
		var wListInput=cFormObj.elements[aInputName];
		//var wListInput=document.forms[0].elements[aInputName];
		if (wListInput!=null)
		{	// 1 fields -> wListInput contains the field else wListInput contains the list of fields
			var wLength=wListInput.length==undefined?1:wListInput.length;
			wResult=new Array(wLength);
			if (wLength==1) 
				wResult[0]=wListInput;
			else
			{
				for (var i=0;i<wLength;i++)
					wResult[i]=wListInput[i];	
			}
		}
		else 
			wResult=new Array(0);
		return wResult;
	} 
	// Extract rank from Xtend dynlink action info - Used to check qty in list - From 1 to N
	function xExtractRank(aStr)
	{
		var wId='xar=';
		var wStart=aStr.indexOf(wId,0);
		if (wStart==-1)
			return 0;
		else
			wStart=wStart+ wId.length; 
		var wStop=aStr.indexOf('&',wStart);
		if (wStop==-1) wStop=aStr.length;
		return new CXNumStr(aStr.substring(wStart,wStop)).getInteger(0);
	}
CXNumStr.prototype.isInteger=function ()
{	
	if (isNaN(parseInt(this.pValue,10)))
		return false;
	else
	{
	   var re = /[^0-9]/; 
	   return (this.pValue.match(re)==null);
	}
}
CXNumStr.prototype.getInteger=function (aDefault)
{	
	if (this.isInteger())
		return this.pSign * parseInt(this.pValue,10);
	else if (arguments.length==1)
		return this.pSign * new CXNumStr(aDefault).getInteger(0);
	else 
		return 0;
}
CXNumStr.prototype.isQuantity=function ()
{	
	return this.getInteger() > 0;
}
CXNumStr.prototype.isQuantity=function (aMinQty,aMaxQty)
{	
	if (this.isInteger())
	{
		var wQty=this.getInteger();
		if (arguments.length>1 && wQty>aMaxQty)
			return false;
		else if (arguments.length>0 && wQty<aMinQty)
			return false;
		else
			return true;
	}
	else 
		return false;
}
CXNumStr.prototype.toString=function ()
{
	return new String(getInteger());
}
/***********************************************/
/*         CLASS  INPUT FIELD ARRAY            */
/***********************************************/
CXInputArray=function (aInputName) 
{		
	this.pNameRef=aInputName;
	this.pArray=getArrayInput(aInputName);
} 
CXInputArray.prototype.checkIndex=function (aIndex)
{
	return aIndex>=0 && aIndex<this.pArray.length;
}
CXInputArray.prototype.length=function ()
{
	return this.pArray.length;
}
CXInputArray.prototype.value=function (aIndex)
{
	if (this.checkIndex(aIndex))
		return this.pArray[aIndex].value;
	else
		return "";
}
CXInputArray.prototype.fullTrim=function (aIndex)
{
	return fullTrim(this.value(aIndex));
}
CXInputArray.prototype.isQuantity=function (aIndex)
{
	if (this.checkIndex(aIndex))
		return checkQuantity(this.fullTrim(aIndex));
	else
		return false;
}
CXInputArray.prototype.isEmpty=function (aIndex)
{
	return this.fullTrim(aIndex).length==0;
}
CXInputArray.prototype.isAllEmpty=function ()
{
	var wLength=this.length();
	for (var i=0;i<wLength && this.isEmpty(i);i++)
		;
	return 	i==wLength;
}
