// Pour Promotelec

function trim(s) {
    return s.replace(/^\s+/, '').replace(/\s+$/, '');
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


function IsInteger(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

////////////////////////////////////////////////////////////////////////////////
/// POPUP

function OpenSpecificPopModal(ascx)
{	
	ArrayParam = new Array (1); 
	ArrayParam[0] =window;
	// Ouvre la fenętre PopUP
	window.showModalDialog( 'ModalMaster.aspx?mnu=' + ascx+ '' ,ArrayParam,'resizable: 0;status=0;scroll=0;center=yes' );

}

function OpenSpecificPopModalWithSize(ascx, var_width, var_height)
{	
	ArrayParam = new Array (1); 
	ArrayParam[0] =window;
	// Ouvre la fenętre PopUP
	window.showModalDialog( 'ModalMaster.aspx?mnu=' + ascx+ '' ,ArrayParam,'resizable: yes;dialogWidth=' + var_width + ';dialogHeight=' + var_height + ';status=0;scroll=0;center=yes;' );
}


// Ouvre une modaldialog avec un composant spécifique avec des arguments
function OpenSpecificPopModalWithArguments( ascx, argItems )
{
	ArrayParam = new Array (1); 
	ArrayParam[0] = window;

	window.showModalDialog( 'ModalMaster.aspx?mnu=' + ascx + argItems + '' , ArrayParam,'resizable: 0;status=0;scroll=0;center=yes');
}

function OpenSpecificPopModalWithSizeAndArguments(ascx, argItems, var_width, var_height)
{	
	ArrayParam = new Array (1); 
	ArrayParam[0] =window;
	// Ouvre la fenętre PopUP
	window.showModalDialog( 'ModalMaster.aspx?mnu=' + ascx + argItems + '' ,ArrayParam,'resizable: yes;dialogWidth=' + var_width + ';dialogHeight=' + var_height + ';status=0;scroll=0;center=yes;' );
}

function  OpenUserControlPopModalWithSizeAndArguments(ascx, argItems, var_width, var_height)
{	
	ArrayParam = new Array (1); 
	ArrayParam[0] =window;
	// Ouvre la fenętre PopUP
	window.showModalDialog( 'ModalMaster.aspx?userControlPopup=true&mnu=' + ascx + argItems + '' ,ArrayParam,'resizable: yes;dialogWidth=' + var_width + ';dialogHeight=' + var_height + ';status=0;scroll=0;center=yes;' );
}


function TrackList( ListBox, Tracker, NegativeItem )
{

	var i;
	
	Tracker.value = '';
	
	for( i=ListBox.options.length-1; i>=0; i--)
	{
		if( ListBox.options[i].value == -1 )
		{
			if( NegativeItem == 1 )
				Tracker.value = Tracker.value + ListBox.options[i].value + '|';
		}
		else
		{
			Tracker.value = Tracker.value + ListBox.options[i].value + '|';
		}
	}
}


	
function AnneeBissex(Annee)
{
	if (Annee % 4 == 0)
		return true;
	else
		return false;

}
	
function Valide_date(nDate,nA1,nA2,nFormat,textMsgBox) {
	// Format valide: (ne pas utiliser d'autre format...
	// - dd/mm/yyyy
	// - mm/dd/yyyy
	// - yyyy/mm/dd
	//nA1,nA2 intervalle ex 1950,2030
	//nDate un champ date
	 
	var ok = "oui";
	var nChar;
	var aDate;
	var nJ;
	var nM;
	var nA;
	var jMax = 31;
	nAccepte = "0123456789/";
	var nDateTxt;
	
	if (nDate.value)
		nDateTxt = nDate.value;
	else
		nDateTxt = nDate;
		
	
	if (nDateTxt.length > 0) 
	{
    
    	if (nDateTxt.length < 6 || nDateTxt.length > 10) 
    	{
			{ok = "non";}
		}
		else
		{
			for (var i=0; i<nDateTxt.length; i++) 
			{
				nChar = "" + nDateTxt.substring(i, i+1);
				if (nAccepte.indexOf(nChar) == "-1") ok = "non";
			}
		}
		if (ok == "oui") 
		{
			aDate = nDateTxt.split("/");
			if (nFormat == "dd/mm/yyyy") 
			{ 
				nJ = aDate[0]; 
				nM = aDate[1]; 
				nA = aDate[2];
			} 
			else if (nFormat == "mm/dd/yyyy") 
			{ 
				nJ = aDate[1]; 
				nM = aDate[0]; 
				nA = aDate[2];
			} 
			else if (nFormat == "yyyy/mm/dd") 
			{ 
				nJ = aDate[2]; 
				nM = aDate[1]; 
				nA = aDate[0]; 
			}
			else if (nFormat == "mm/yyyy") 
			{ 
				nJ = 1; 
				nM = aDate[0]; 
				nA = aDate[1];
			} 
			
			if ((nJ < 1 || nJ > jMax) || (nM < 1 || nM > 12) || (nA < nA1 || nA > nA2)) 
			{
				ok = "non";
			}
			else 
			{
				if (nM == 2) 
				{ 
					if (AnneeBissex(nA) == true) 
					{ 
						jMax = 29 
					} 
					else 
					{ 
						jMax = 28 
					}
				}
				
				if ((nM == 1 || nM == 3 || nM == 5 || nM == 7 || nM == 8 || nM == 10 || nM == 12)) jMax = 31
				if ((nM == 4 || nM == 6 || nM == 9 || nM == 11)) jMax = 30
				if (nJ < 1 || nJ > jMax) ok = "non";
			}
		}
		
		if (ok == "non") 
		{
			
			if (nDate.value)
			{
				nDate.focus();
				nDate.select();
			}
			alert ( textMsgBox + "\n(format " + nFormat + ")");
			
			return false;
		}
		else
		{
			return true;
		}
	}
  
}

