var bModif = false;
function WriteInputTextMaxLength(strValue, strFieldName, strSize, bTEXTAREA)
{
	WriteInputTextType(strValue, strFieldName, strSize, 'text', bTEXTAREA);
}

function MyWriteInputTextMaxLength(strValue, strFieldName, strSize, bTEXTAREA,strOnEvent,strDoEvent)
{
	//if(strSize.indexOf("DisplaySize")>=0)
		//strSize="60" ;
	if(Number(strSize)>80)
		strSize="60" ;
	MyWriteInputTextType(strValue, strFieldName, strSize, 'text', bTEXTAREA,strOnEvent,strDoEvent);
}

function MyWriteInputTextMaxLength2(strValue, strFieldName,strVisibleSize, strSize, bTEXTAREA,strOnEvent,strDoEvent)
{
	
	MyWriteInputTextType2(strValue, strFieldName, strVisibleSize, strSize, 'text', bTEXTAREA,strOnEvent,strDoEvent);
}

function WriteInputText(strValue, strFieldName, strSize)
{
	WriteInputTextType(strValue, strFieldName, strSize, 'text', false);
}

function WriteInputTextType(strValue, strFieldName, strSize, strTypeText, bIsbTEXTAREA)
{
var bModif = false;

//<input type=text Name=strFieldName value=strValue size=strSize>
 var nSizeIn = Number(strSize);
 var bTEXTAREA = bIsbTEXTAREA;
 var nTextDefaut = Number(80);
 re = /CellData/i; 
 var strText = '';
	if (strValue.search(re) == -1) 
	{
	 bModif = true ;
	}

	//if((bModif && strValue.length > nSizeIn) || nSizeIn >= nTextDefaut)
	//bTEXTAREA = true ;


 if (bTEXTAREA)
 {
	strText += '<TEXTAREA NAME=';
	strText += strFieldName;
	strText += ' ROWS=';
	var strRows = String("");
	var nRows = Number(2);
	if (nSizeIn < nTextDefaut)
	nRows = (strValue.length/nSizeIn+1);
	strText += String(nRows);
	strText += ' ';
	if (strSize != '')
	{
		strText +=  'COLS='+strSize;
	}
	strText +=  ' align=top>';
	if (strValue.search(re) == -1) 
	{
	 strText += strValue;
	 bModif = true ;
	}

	strText +=  '</TEXTAREA>';
	//alert("strText=" + strText);
 }
 else
 {
  strText += '<input type=';
  strText += strTypeText;
 strText += ' name=';
 if (strFieldName == 'password')
	strText = '<input type=password name=';
 strText += strFieldName;
	if (strValue.search(re) == -1) 
	{
	 strText += ' value="' + strValue + '"';
	 bModif = true ;
	}
	if (strSize != '')
	{
		strText += ' size=' + strSize;
		strText += ' maxlength=' + strSize;
	}
	strText += '>';

 //alert("strText=" + strText);
 }
	 document.writeln(strText);
}


function MyWriteInputTextType(strValue, strFieldName, strSize, strTypeText, bIsbTEXTAREA,strOnEvent,strDoEvent)
{
var bModif = false;

//<input type=text Name=strFieldName value=strValue size=strSize>
 var nSizeIn = Number(strSize);
 var bTEXTAREA = bIsbTEXTAREA;
 var nTextDefaut = Number(80);
 re = /CellData/i; 
 var strText = '';
	if (strValue.search(re) == -1) 
	{
	 bModif = true ;
	}

	//if((bModif && strValue.length > nSizeIn) || nSizeIn >= nTextDefaut)
	//bTEXTAREA = true ;


 if (bTEXTAREA)
 {
	strText += '<TEXTAREA NAME=';
	strText += strFieldName;
	strText += ' ROWS=';
	var strRows = String("");
	var nRows = Number(2);
	if (nSizeIn < nTextDefaut)
	nRows = (strValue.length/nSizeIn+1);
	strText += String(nRows);
	strText += ' ';
	if (strSize != '')
	{
		strText +=  'COLS='+strSize;
	}
	strText +=  ' align=top>';
	if (strValue.search(re) == -1) 
	{
	 strText += strValue;
	 bModif = true ;
	}

	strText +=  '</TEXTAREA>';
	//alert("strText=" + strText);
 }
 else
 {
  strText += '<input type=';
  strText += strTypeText;
 strText += ' name=';
 if (strFieldName == 'password')
	strText = '<input type=password name=';
 strText += strFieldName;
	if (strValue.search(re) == -1) 
	{
	 strText += ' value="' + strValue + '"';
	 bModif = true ;
	}
	if (strSize != '')
	{
		strText += ' size=' + strSize;
		strText += ' maxlength=' + strSize;
	}
	strText += ' ' + strOnEvent ;
	if(strOnEvent!="")
	{
		strText += '=' ;
		strText += '"' + strDoEvent+ '"' ;
	}
	strText += '>';

 //alert("strText=" + strText);
 }
	 document.writeln(strText);
}


function MyWriteInputTextType2(strValue, strFieldName,strVisibleSize, strSize, strTypeText, bIsbTEXTAREA,strOnEvent,strDoEvent)
{
var bModif = false;

//<input type=text Name=strFieldName value=strValue size=strSize>
 var nSizeIn = Number(strSize);
 var bTEXTAREA = bIsbTEXTAREA;
 var nTextDefaut = Number(80);
 re = /CellData/i; 
 var strText = '';
	if (strValue.search(re) == -1) 
	{
	 bModif = true ;
	}

	//if((bModif && strValue.length > nSizeIn) || nSizeIn >= nTextDefaut)
	//bTEXTAREA = true ;


 if (bTEXTAREA)
 {
	strText += '<TEXTAREA NAME=';
	strText += strFieldName;
	strText += ' ROWS=';
	var strRows = String("");
	var nRows = Number(2);
	if (nSizeIn < nTextDefaut)
	nRows = (strValue.length/nSizeIn+1);
	strText += String(nRows);
	strText += ' ';
	if (strSize != '')
	{
		strText +=  'COLS='+strVisibleSize;
	}
	strText +=  ' align=top>';
	if (strValue.search(re) == -1) 
	{
	 strText += strValue;
	 bModif = true ;
	}

	strText +=  '</TEXTAREA>';
	//alert("strText=" + strText);
 }
 else
 {
  strText += '<input type=';
  strText += strTypeText;
 strText += ' name=';
 if (strFieldName == 'password')
	strText = '<input type=password name=';
 strText += strFieldName;
	if (strValue.search(re) == -1) 
	{
	 strText += ' value="' + strValue + '"';
	 bModif = true ;
	}
	if (strSize != '')
	{
		strText += ' size=' + strVisibleSize;
		strText += ' maxlength=' + strSize;
	}
	strText += ' ' + strOnEvent ;
	if(strOnEvent!="")
	{
		strText += '=' ;
		strText += '"' + strDoEvent+ '"' ;
	}
	strText += '>';

 //alert("strText=" + strText);
 }
	 document.writeln(strText);
}

function WriteJSCTag(strValue, strFieldName, bTagJSCForModif)
{
// <!ServletDataTag> or nothing
 re = /CellData/i; 
 var strText = '<!ServletDataTag>';
 strText += strFieldName;
	if (strValue.search(re) == -1) 
	{
	 strText += ' value="' + strValue + '"';
	 bModif = true ;
	}

	if ((bTagJSCForModif && bModif) ||
		(bTagJSCForModif==false && bModif==false))
	 document.writeln(strText);
}

function bTestTextFields(strName, strValue, strMaxSize, bCanBeNullInDataBase, bIsDigit, strMaxDigit)
{
 var bOK = true ;
 var nSize = 0, nMaxSize = 0, nMaxDigit = 0;
 nSize = Number(strValue.length);
 nMaxSize = Number(strMaxSize) ;
 nMaxDigit = Number(strMaxDigit) ;

 //if (bCanBeNullInDataBase == false && nSize == 0 && false == bModif)
 
 if (bCanBeNullInDataBase == false && nSize == 0)
 {
 
  bOK = false;
  if (strName == "clientfile")
  { 
	if( true == bModif) // only modif allow empty
		bOK =true ;
	else
		alert('Please fill your photo field.');
  }
  else
  alert('Your field ' + strName + ' can not be empty. Please fill it.');
 }

 if (true == bOK)
 {

  if (nSize > nMaxSize)
  {
   bOK = false ;
   alert('Your field ' + strName + ' has limited to '+ strMaxSize+ '. Please retry.');
  }

 }
 if (true == bOK)
 {
	 if (true == bIsDigit)
	 {
	 	var bIsValueDigit = IsDigit(strValue);
		if (false == bIsValueDigit)
		{
			bOK = false ;
			alert(strName + " should be digit. Please retry." );
		}
		if (true == bOK)
		{
			var nValue = Number(strValue);
			
			if (nValue < 0 || nValue > nMaxDigit) //if out of(0,strMaxDigit)
			{
			 bOK = false ;
			 alert('Your field ' + strName + ' has limited in (0, '+ strMaxDigit+ '). Please retry.');
			}
		}
	 }
 }
 return bOK;
}

function WriteSelect(strValueToTest, strValue)
{
   WriteSelectLabel(strValueToTest, strValue, '');
}
function WriteSelectLabel(strValueToTest, strValue, strLabel)
{
 var nSizeLabel = Number(strLabel.length);

 var strText = '<option value="';
 strText += strValue + '"';
 if (strValueToTest == strValue) 
 {
	 strText += ' selected';
	 bModif = true ;
 }
 strText += '>' + strValue ;
 if (nSizeLabel > 0)
    strText +=  '-'+strLabel ;
 strText += '</option>';
 //alert(strText);

	 document.writeln(strText);
}

function WriteSelectLabel2(strValueToTest, strValue, strLabel)
{
 var nSizeLabel = Number(strLabel.length);

 var strText = '<option value="';
 strText += strValue + '"';
 if (strValueToTest == strValue) 
 {
	 strText += ' selected';
	 bModif = true ;
 }
 strText += '>' //+ strValue ;
 //if (nSizeLabel > 50)
    //strText +=  '-' ;
 strText += strLabel ;   
 strText += '</option>';
 //alert(strText);

	 document.writeln(strText);
}

function WriteRadio(strValueToTest, strValue, strRadioName)
{
    WriteRadioLabel(strValueToTest, strValue, strRadioName, '');
}

function WriteRadioLabel(strValueToTest, strValue, strRadioName, strLabel)
{
// we would like to write 'checked' for the good value
//<input type="radio" name=strRadioName value=strValue [checked]>
 var nSizeLabel = Number(strLabel.length);

 var strText = '<input type="radio" name=';
 strText += strRadioName;
 strText += ' value=';
 strText += strValue;
 if (strValueToTest == "")
  strValueToTest = '0';
 if (strValueToTest == strValue) 
 {
	 strText += ' checked';
	 bModif = true ;
 }
 else if (strValue == '0' && false == bModif ) 
 {
	 strText += ' checked';
 }
 strText += '>';

 if (nSizeLabel > 0)
    strText += strLabel ;
    strText += '<br>';
	 document.writeln(strText);

}

function WriteInputTextArea(strValue, strFieldName, strCols, strRows)
{
//<textarea name=pds_member_desc COLS=55 ROWS=20></textarea>
 re = /CellData/i; 
 var strText = '<textarea name=';
 strText += strFieldName;
	if (strCols != '')
		strText += ' COLS=' + strCols;
	if (strRows != '')
		strText += ' ROWS=' + strRows;
 strText += '>';
 	if (strValue.search(re) == -1) 
	{
	 strText += strValue;
	 bModif = true ;
	}

 strText += '</textarea>';
 //alert("strText=" + strText);
	 document.writeln(strText);
}

function IsDigit(strIntValue)
{
	var bIsDigit = true; 
	for (i = 0; i < strIntValue.length;i++)
	{
		if (strIntValue.charCodeAt(i) < 48 || strIntValue.charCodeAt(i) > 57)
		{
			bIsDigit = false;
			break ;
		}
	}
	return bIsDigit;
}

function JSCWriteText(strText)
{
//alert(strText);
	 this.document.writeln(strText);
}

function WriteCheckBoxLabel(strValueToTest, strCheckBoxName, strLabel)
{
// we would like to write 'checked' for the good value
//<input type="checkBox" name="strCheckBoxName"  value="1" [checked]> strLabel
 var strValue = '1';
 var nSizeLabel = Number(strLabel.length);

 var strText = '<input type="checkBox" name=';
 strText += strCheckBoxName;
 strText += ' value=';
 strText += strValue;
 if (strValueToTest == strValue) 
 {
	 strText += ' checked';
	 bModif = true ;
 }
 strText += '>';

 if (nSizeLabel > 0)
    strText += ' ' + strLabel ;
    strText += '<br>';
    
	 document.writeln(strText);

}

function ConvertCaseNonSensible(toConvert) 
{

	//var nSizeRadio = myForm.CaseSensible.length;
	var resultat = toConvert.value ;	
	//myForm.key.value = myForm.keyPage.value;
	
	{//begin
		var strConvertOrig = String(toConvert);
		var strConvert = strConvertOrig;
		var strConverted = String(""), strTmp=String("");
		var strLastOne = String("");
		var strKeyToExclureForOR = String("%");
		var strSub = String ("");
		var endspace = 0 ;
		strConvert = strConvert .toUpperCase();
		
		
		var i, nSize = strConvert.length, nPosB = 0;
		var nbsep=0 ;
		var nbexp=0 ;
		
		for (i = 0; i < nSize;i++)
		{
			strTmp = strConvert.charAt(i);
			strTmpLower = strTmp.toLowerCase();

			//alert("strTmp : "+strTmp) ; 
			if (strLastOne == ' ' && strTmp == ' ')
			{
				endspace = 1 ; //nothing, we skip the empty
			}
			else
			{
				if (strTmp == ' ')
				{
				
					if(i==nSize-1)
						endspace = 1 ;
						
					//alert("i="+i+"nbexp="+nbexp+" strConverted : "+strConverted+"("+eval(nPosB+nbexp)+","+eval((Number(i-nbexp)*4)+nbexp)+")") ;
				strSub = strConverted.substring(eval(nPosB+nbexp),eval((Number(i-nbexp)*4)+nbexp));
					//alert("strSub : "+strSub) ;
					
					//alert(nPosB+"-"+eval((Number(i)*4))) ;
					
					strKeyToExclureForOR += strSub + '%';
					//alert("strKeyToExclureForOR : "+strKeyToExclureForOR) ;			
					
					
					strConverted = strConverted + strConvert.charAt(i);
					
					nPosB = eval((Number(i-nbexp)*4)) ;
					nbexp++ ;
				}
				else
				{
				strConverted = strConverted +'['+strConvert.charAt(i)+strTmpLower+']';					
				}
			}
			strLastOne = strTmp;
			
		}//for
		
		//if(endspace==1)
			//alert("finit par un ou des espaces") ;
		//alert(nPosB) ;
		//alert("strConverted + taille substring : "+strConverted+"("+eval(nPosB-1)+"-"+eval((Number(i-1)*4))+")") ;
		//strSub = strConverted.substring(eval(nPosB-4), eval((Number(i-1)*4)));
		
		if(endspace == 0)
		{
		strSub = strConverted.substring(eval(nPosB+nbexp-1),eval((Number(i-nbexp)*4)+nbexp));
		
		//alert("strSub : "+strSub) ;
		strKeyToExclureForOR += strSub + '%';
		}
		//alert("strKeyToExclureForOR : "+strKeyToExclureForOR) ;
		
		}//end
	//alert("strSub"+strSub) ;
	resultat = strKeyToExclureForOR ;
	
	return resultat ;
	
}//function