//---------------------------------------------------------------------
// Author:		Marc van Heugten
// Date:		16-01-2004
// Description: Validate the input controls
// Reference:	TD Webshop 300
//---------------------------------------------------------------------

//-----------------------------------------------------------------------
// Author:		Daniel Wauben
// Date  :		12-03-2004
// Description:	Validation for Numbers,letters,special,pathname and content
//				Allowed characters for numbers	:	0-9 and the first character may not be 0
//				Allowed characters for letters	:	A-Z and a-z
//				Allowed characters for special	:	0-9 A-Z and a-z space ( ) @ ? ! % _ - ; : + = . ,
//				Allowed characters for special2 :   0-9 A-Z and a-z space ( ) @ ? ! % _ - ; : + = . , ` # $ ^ & * \ ' " /
//              Allowed characters for pathname	:	0-9 A-Z a-z space ( ) _ - . and /
// Reference:     TD Content Manager Webshop
//----------------------------------------------------------------------- 
function removeInvalidChars(evt, formElement, myString, StringType, AllowFirstZero) 
{
	removeInvalidChars(evt, formElement, myString, StringType,AllowFirstZero, "")
}

//-----------------------------------------------------------------------
// Author:		Daniel Wauben
// Date  :		12-03-2004
// Description:	Validation for Numbers,letters,special,pathname and content
//				Allowed characters for numbers	:	0-9 and the first character may not be 0
//				Allowed characters for letters	:	A-Z and a-z
//				Allowed characters for special	:	0-9 A-Z and a-z space ( ) @ ? ! % _ - ; : + = . ,
//				Allowed characters for special2 :   0-9 A-Z and a-z space ( ) @ ? ! % _ - ; : + = . , ` # $ ^ & * \ ' " /
//              Allowed characters for pathname	:	0-9 A-Z a-z space ( ) _ - . and /
// Reference:     TD Content Manager Webshop
//----------------------------------------------------------------------- 
// Modified by:	Stan Padgett
// Date:		13-04-2008
// Change:		Allowed characters for special2 changed to exclude unicode letter symbols 0x2000-0x2BFF
//-----------------------------------------------------------------------
function removeInvalidChars(evt, formElement, myString, StringType, AllowFirstZero, ProductInput) 
{
	  //---------------------------------------------------------------------
	  // Change the StringType if a CustomerSpecificData product
	  // must be validated.
	  //---------------------------------------------------------------------
	  if (StringType == "productinput" || StringType == "productinput1")
	  {
			//---------------------------------------------------------------------
			// HagemeyerPartNumber
			//---------------------------------------------------------------------		
			if (ProductInput.toUpperCase() == "HNA")
			{
				//---------------------------------------------------------------------
				// HNA = Letters & Numbers
				//---------------------------------------------------------------------		
				StringType = "letters"
			}
			else
			{
				//---------------------------------------------------------------------
				// Basic = Numbers
				//---------------------------------------------------------------------		
				StringType = "numbers"
			}
	  }
	  
	  if (StringType == "productinput2")
	  {
			//---------------------------------------------------------------------
			// CustomerPartNumber
			//---------------------------------------------------------------------
			StringType = "productinput_customerspecificdata"
	  }
	  
	  if (StringType == "productinput3")
	  {
			//---------------------------------------------------------------------
			// ManufacturerPartNumber
			//---------------------------------------------------------------------
			StringType = "productinput_customerspecificdata"
	  }
	  
	  
      var intPeriod = 0;
      var oldString = myString;
      if (!evt) var evt = Event;
      //alert(evt);
      if (evt.keyCode == 13 || evt.keyCode == 8 || evt.keyCode == 9 || evt.keyCode == 35 || evt.keyCode == 36 || evt.keyCode == 37 || evt.keyCode == 39 || evt.keyCode == 45 ||evt.keyCode == 46 || evt.keyCode == 13)
      {
                  //---------------------------------------------------------------------
                  // Allowed characters:
                  // - Enter (13)
                  // - Backspace (8)
                  // - Tab (9)
                  // - KeyLeft (37)
                  // - KeyRight (39)
                  // - Insert (45)
                  // - Delete (46)
                  // - Home (35)
                  // - End (36)
                  //---------------------------------------------------------------------
      }
      else
      {
            if (typeof myString != "string") 
            { 
                  return myString; 
            }
            
            //---------------------------------------------------------------------
            // Remove leading and trailing spaces
            //---------------------------------------------------------------------
            
            for (var i = 0; i < myString.length; i++)
            {
                  A_char = myString.charCodeAt(i)
 
                  //---------------------------------------------------------------------
                  // We are validating for numbers
                  //---------------------------------------------------------------------
                  if (StringType == "numbers")
                  {
                        if (A_char > 47 && A_char < 58)
                        {
                              //---------------------------------------------------------------------
                              // It's a number
                              //---------------------------------------------------------------------
                              if (myString == '0' && !AllowFirstZero)
                              {
                                    //---------------------------------------------------------------------
                                    // First character cannot be a zero
                                    //---------------------------------------------------------------------
                                    myString = '';
                              }
                              else
                              {
                                    continue;
                              }
                        }
                        else
                        {
                              myString = myString.substring(0,i)
                        }
                  }
 				  else if(StringType == "letters")
                  {
                        //---------------------------------------------------------------------
                        // We are validating for letters (including numbers)
                        //---------------------------------------------------------------------
                        if ((A_char > 64 && A_char < 91) || (A_char > 47 && A_char < 58))
                        {
                              //---------------------------------------------------------------------
                              // Upper case letter
                              //---------------------------------------------------------------------
                              continue;
                        }     
                        else
                        {
                              if (A_char > 96 && A_char < 123)
                              {
                                    //---------------------------------------------------------------------
                                    // Lower case letter
                                    //---------------------------------------------------------------------
                                    continue;
                              }
                              else
                              {
                                    myString = myString.substring(0,i) + myString.substring(i+1,myString.Length);
                                    i--;
                              }
                        }
                  }
				  else if(StringType == "lettersonly")
                  {
                        //---------------------------------------------------------------------
                        // We are validating for letters 
                        //---------------------------------------------------------------------
                        if (A_char > 64 && A_char < 91)
                        {
                              //---------------------------------------------------------------------
                              // Upper case letter
                              //---------------------------------------------------------------------
                              continue;
                        }     
                        else
                        {
                              if ((A_char > 96 && A_char < 123) || (A_Char = 45))
                              {
                                    //---------------------------------------------------------------------
                                    // Lower case letter
                                    //---------------------------------------------------------------------
                                    myString = myString.toUpperCase();
                                    continue;
                              }
                              else
                              {
                                    myString = myString.substring(0,i) + myString.substring(i+1,myString.Length);
                                    i--;
                              }
                        }
                  }                
 				  else if(StringType == "special")
                  {
                         //---------------------------------------------------------------------
                        // We are validating for special characters:
                        // 0 1 2 3 4 5 6 7 8 9
                        // a-z, A-Z
                        // ( ) @ ? ! % _ - ; : + = . , 
                        //---------------------------------------------------------------------
                        if ((A_char > 64 && A_char < 91) || (A_char > 47 && A_char < 58))
                        {
                              //---------------------------------------------------------------------
                              // Upper case letter & Numbers
                              //---------------------------------------------------------------------
                              continue;
                        }     
                        else
                        {
                              if (A_char > 96 && A_char < 123)
                              {
                                    //---------------------------------------------------------------------
                                    // Lower case letter
                                    //---------------------------------------------------------------------
                                    continue;
                              }
                              else
                              {
                                    if (A_char == 32 || A_char == 33 || A_char == 37 || A_char == 40 || A_char == 41 || A_char == 43 || A_char == 44 || A_char == 45 || A_char == 46 || A_char == 58 || A_char == 59 || A_char == 61 || A_char == 63 || A_char == 64 || A_char == 95 || (A_char > 192 && A_char < 255))
                                    {
                                          //---------------------------------------------------------------------
                                          // [space] ( ) @ ? ! % _ - ; : + = . ,
                                          //---------------------------------------------------------------------
                                          continue;                                 
                                    }
                                    else
                                    {
  										  myString = myString.substring(0,i) + myString.substring(i+1,myString.Length);
                                          i--;
                                    }
                              }
                        }
                  }
                  else if(StringType == "special2")
                  {
						//---------------------------------------------------------------------
                        // We are validating for special characters:
                        // 0 1 2 3 4 5 6 7 8 9
                        // a-z, A-Z
                        // ( ) @ ? ! % _ - ; : + = . ,
                        // and added ones: ` # $ ^ & * \ ' " /
                        //---------------------------------------------------------------------
                        if ((A_char > 64 && A_char < 91) || (A_char > 47 && A_char < 58))
                        {
                              //---------------------------------------------------------------------
                              // Upper case letter & Numbers
                              //---------------------------------------------------------------------
                              continue;
                        }     
                        else
                        {
                              if (A_char > 96 && A_char < 123)
                              {
                                    //---------------------------------------------------------------------
                                    // Lower case letter
                                    //---------------------------------------------------------------------
                                    continue;
                              }
                              else
                              {
                                    if (A_char == 32 || A_char == 33 || A_char == 37 || A_char == 40 || A_char == 41 || A_char == 43 || A_char == 44 || A_char == 45 || A_char == 46 || A_char == 58 || A_char == 59 || A_char == 61 || A_char == 63 || A_char == 64 || A_char == 95 || (A_char > 192 && A_char < 255))
                                    {
                                          //---------------------------------------------------------------------
                                          // [space] ( ) @ ? ! % _ - ; : + = . ,
                                          //---------------------------------------------------------------------
                                          continue;                                 
                                    }
                                    else if(A_char == 96 || A_char == 35 || A_char == 36 || A_char == 94 || A_char == 38 || A_char == 42 || A_char == 92 || A_char == 39 || A_char == 34 || A_char == 47)
                                    {
										//---------------------------------------------------------------------
                                        // The new ones: ` # $ ^ & * \ ' " /
                                        //---------------------------------------------------------------------
                                        continue;                                 
                                    }
                                    else if ((A_char >= 256 && A_char<0x2000)  || (A_char>0x2BFF))
                                    {
										//---------------------------------------------------------------------
                                        // Non Ascii Characters but not unicode symbols: (chinese for example)
                                        //---------------------------------------------------------------------
                                        continue;                                 
                                    }
                                    else
                                    {
  										  myString = myString.substring(0,i) + myString.substring(i+1,myString.Length);
                                          i--;
                                    }
                              }
                        }
                  }
				  else if(StringType == "reference")
                  {
                        //---------------------------------------------------------------------
                        // We are validating for special characters:
                        // 0 1 2 3 4 5 6 7 8 9
                        // a-z, A-Z
                        // ( ) @ ? ! % _ - ; : + = . , /
                        //---------------------------------------------------------------------
                        if ((A_char > 64 && A_char < 91) || (A_char > 47 && A_char < 58))
                        {
                              //---------------------------------------------------------------------
                              // Upper case letter & Numbers
                              //---------------------------------------------------------------------
                              continue;
                        }     
                        else
                        {
                              if (A_char > 96 && A_char < 123)
                              {
                                    //---------------------------------------------------------------------
                                    // Lower case letter
                                    //---------------------------------------------------------------------
                                    continue;
                              }
                              else
                              {
                                    if (A_char == 32 || A_char == 33 || A_char == 37 || A_char == 40 || A_char == 41 || A_char == 43 || A_char == 44 || A_char == 45 || A_char == 46 || A_char == 47 || A_char == 58 || A_char == 59 || A_char == 61 || A_char == 63 || A_char == 64 || A_char == 95 || (A_char > 192 && A_char < 255))
                                    {
                                          //---------------------------------------------------------------------
                                          // [space] ( ) @ ? ! % _ - ; : + = . , /
                                          //---------------------------------------------------------------------
                                          continue;                                 
                                    }
                                    else
                                    {
  										  myString = myString.substring(0,i) + myString.substring(i+1,myString.Length);
                                          i--;
                                    }
                              }
                        }
                  }
                  else if(StringType == "productinput_customerspecificdata")
                  {
                        //---------------------------------------------------------------------
                        // We are validating for special characters:
                        // 0 1 2 3 4 5 6 7 8 9
                        // a-z, A-Z
                        // ( ) @ ? ! % _ - ; : + = . , / \ $ £
                        //---------------------------------------------------------------------
                        if ((A_char > 64 && A_char < 91) || (A_char > 47 && A_char < 58))
                        {
                              //---------------------------------------------------------------------
                              // Upper case letter & Numbers
                              //---------------------------------------------------------------------
                              continue;
                        }     
                        else
                        {
                              if (A_char > 96 && A_char < 123)
                              {
                                    //---------------------------------------------------------------------
                                    // Lower case letter
                                    //---------------------------------------------------------------------
                                    continue;
                              }
                              else
                              {
                                    if (A_char == 32 || A_char == 33 || A_char == 37 || A_char == 40 || A_char == 41 || A_char == 43 || A_char == 44 || A_char == 45 || A_char == 46 || A_char == 58 || A_char == 59 || A_char == 61 || A_char == 63 || A_char == 64 || A_char == 95 || (A_char > 192 && A_char < 255) || A_char == 47 || A_char == 92 || A_char == 36 || A_char == 156)
                                    {
                                          //---------------------------------------------------------------------
                                          // [space] ( ) @ ? ! % _ - ; : + = . , / \ $ £
                                          //---------------------------------------------------------------------
                                          continue;                                 
                                    }
                                    else
                                    {
  										  myString = myString.substring(0,i) + myString.substring(i+1,myString.Length);
                                          i--;
                                    }
                              }
                        }
                  }
                  else if(StringType == "date")
                  {
                        //---------------------------------------------------------------------
                        // We are validating for special characters:
                        // 0 1 2 3 4 5 6 7 8 9
                        //  - . / 
                        //---------------------------------------------------------------------
                        if (A_char > 44 && A_char < 58)
                        {
                              //---------------------------------------------------------------------
                              // 0 1 2 3 4 5 6 7 8 9
							  //  - . / 
                              //---------------------------------------------------------------------
                              continue;
                        }     
                        else
                        {
                                myString = myString.substring(0,i) + myString.substring(i+1,myString.Length);
                                i--;
                        }
                  }
                  else if(StringType == "specialnospace")
                  {
                        //---------------------------------------------------------------------
                        // We are validating for special characters:
                        // 0 1 2 3 4 5 6 7 8 9
                        // a-z, A-Z
                        // ( ) @ ? ! % _ - ; : + = . , 
                        //---------------------------------------------------------------------
                        if ((A_char > 64 && A_char < 91) || (A_char > 47 && A_char < 58))
                        {
                              //---------------------------------------------------------------------
                              // Upper case letter & Numbers
                              //---------------------------------------------------------------------
                              continue;
                        }     
                        else
                        {
                              if (A_char > 96 && A_char < 123)
                              {
                                    //---------------------------------------------------------------------
                                    // Lower case letter
                                    //---------------------------------------------------------------------
                                    continue;
                              }
                              else
                              {
                                    if (A_char == 33 || A_char == 37 || A_char == 40 || A_char == 41 || A_char == 43 || A_char == 44 || A_char == 45 || A_char == 46 || A_char == 58 || A_char == 59 || A_char == 61 || A_char == 63 || A_char == 64 || A_char == 95 || (A_char > 192 && A_char < 255))
                                    {
                                          //---------------------------------------------------------------------
                                          // ( ) @ ? ! % _ - ; : + = . ,
                                          //---------------------------------------------------------------------
                                          continue;                                 
                                    }
                                    else
                                    {
                                          myString = myString.substring(0,i) + myString.substring(i+1,myString.Length);
                                          i--;
                                    }
                              }
                        }
                  }

                  else if (StringType == "pathname")
                  {
                        //---------------------------------------------------------------------
                        // We are validating for special path characters:
                        // 0 1 2 3 4 5 6 7 8 9
                        // a-z, A-Z
                        // ( ) / _ - .  
                        //---------------------------------------------------------------------
                        if ((A_char > 64 && A_char < 91) || (A_char > 47 && A_char < 58))
                        {
                              //---------------------------------------------------------------------
                              // Upper case letter & Numbers
                              //---------------------------------------------------------------------
                              continue;
                        }                 
                        else
                        {
                              if (A_char > 96 && A_char < 123)
                              {
                                    //---------------------------------------------------------------------
                                    // Lower case letter
                                    //---------------------------------------------------------------------
                                    continue;
                              }
                              else
                              {
                                    if (A_char == 32 || A_char == 40 || A_char == 41 || A_char == 45 || A_char == 46 || A_char == 47 || A_char == 95)
                                    {
                                          //---------------------------------------------------------------------
                                          // [space] ( ) / _ - . 
                                          //---------------------------------------------------------------------
                                          continue;                                 
                                    }
                                    else
                                    {
                                          myString = myString.substring(0,i) + myString.substring(i+1,myString.Length);
                                          i--;
                                    }
                              }
                        }     
                  }
            }           
            
            //---------------------------------------------------------------------
            // Fill textbox with the correct value
            //---------------------------------------------------------------------
            if (myString != oldString)
            {
                  formElement.value = myString;
            }
      }
}

//-----------------------------------------------------------------------
// Author:		Daniel Wauben
// Date  :		12-03-2004
// Description:	Validation for Numbers,letters,special,pathname and content
//				Allowed characters for numbers	:	0-9 and the first character may not be 0
//				Allowed characters for letters	:	A-Z and a-z
//				Allowed characters for special	:	0-9 A-Z and a-z space ( ) @ ? ! % _ - ; : + = . ,
//              Allowed characters for pathname	:	0-9 A-Z a-z space ( ) _ - . and /
// Reference:     TD Content Manager Webshop
//----------------------------------------------------------------------- 
function removeInvalidCharsPrice(evt, formElement, myString, StringType, AllowFirstZero, NumberFormat) 
{
      var intPeriod = 0;
      var oldString = myString;
      if (!evt) var evt = Event;
      if (evt.keyCode == 13 || evt.keyCode == 8 || evt.keyCode == 9 || evt.keyCode == 35 || evt.keyCode == 36 || evt.keyCode == 37 || evt.keyCode == 39 || evt.keyCode == 45 ||evt.keyCode == 46 || evt.keyCode == 13)
      {
                  //---------------------------------------------------------------------
                  // Allowed characters:
                  // - Enter (13)
                  // - Backspace (8)
                  // - Tab (9)
                  // - KeyLeft (37)
                  // - KeyRight (39)
                  // - Insert (45)
                  // - Delete (46)
                  // - Home (35)
                  // - End (36)
                  //---------------------------------------------------------------------
      }
      else
      {
            //---------------------------------------------------------------------
            // Remove leading and trailing spaces
            //---------------------------------------------------------------------
            for (var i = 0; i < myString.length; i++)
            {
                  A_char = myString.charCodeAt(i)
 
                  //---------------------------------------------------------------------
                  // We are validating for price
                  //---------------------------------------------------------------------
                  if (StringType == "price")
                  {
                        if (A_char > 47 && A_char < 58)
                        {
                              //---------------------------------------------------------------------
                              // Number
                              //---------------------------------------------------------------------
                              continue;
                        }
                        else
                        {
							  if (A_char == 44 || A_char == 46)
                              {
                                    //---------------------------------------------------------------------
                                    // . , 
                                    //---------------------------------------------------------------------
                                    if (NumberFormat == 'CommaDot')
                                    {
										// DotComma
										if (A_char == 46)
										{
											continue;
										}
										else
										{
											myString = myString.substring(0,i)
										}
                                    }
                                    else
                                    {
										// CommaDot
										if (A_char == 44)
										{
											continue;
										}
										else
										{
											myString = myString.substring(0,i)
										}
                                    }
                              }
                              else
                              {
                                    myString = myString.substring(0,i)
                              }
                        }
                  }
	        }           
            
            //---------------------------------------------------------------------
            // Fill textbox with the correct value
            //---------------------------------------------------------------------
            if (myString != oldString)
            {
                  formElement.value = myString;
            }
      }
}


//---------------------------------------------------------------------
// Author:		Marc van Heugten
// Date:		5-02-2004
// Description: Sets the focus to another control when the user presses enter
// Reference:	TD Webshop 300
//---------------------------------------------------------------------
function ChangeFocusToControl(evt, control)
{
    if (!evt) var evt = Event;
	if (evt.keyCode == 13)
	{
		control.focus();
	}
}

//---------------------------------------------------------------------
// Author:		Marc van Heugten
// Date:		5-02-2004
// Description: Raises the click event of another control when the user presses enter
// Reference:	TD Webshop 300
//---------------------------------------------------------------------
function ClickControl(evt, control)
{
    if (!evt) var evt = Event;
	if (evt.keyCode == 13)
	{
		control.click();
	}
}

//--------------------------------------------------------IsDate Functions---------------------------------------------
// Author:		Marc van Heugten
// Date:		16-02-2004
// Description: Functions needed by the IsDate() function:
//				- isNumber
//				- stripCharsInBag
//				- daysInFebruary
//				- DaysArray
// Reference:	TD Webshop 300


function isNumber(s){
	var i;
	for (i = 0; i < s.length; i++){   
		//---------------------------------------------------------------------
		// Check that current character is number.
		//---------------------------------------------------------------------
	var c = s.charAt(i);
	if (((c < "0") || (c > "9"))){
			return false;
		}
	}
	//---------------------------------------------------------------------
	// All characters are numbers.
	//---------------------------------------------------------------------
	return true;
}

function stripCharsInBag(s, bag)
{
	var i;
	var returnString = "";
	//---------------------------------------------------------------------
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	//---------------------------------------------------------------------
	for (i = 0; i < s.length; i++){   
	var c = s.charAt(i);
	if (bag.indexOf(c) == -1){
			returnString += c;
		}
	}
	return returnString;
}

function daysInFebruary (year)
{
	//---------------------------------------------------------------------
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
	//---------------------------------------------------------------------
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) 
{
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11){
			this[i] = 30;
		}
		if (i==2){
			this[i] = 29;
		}
	}
	return this;
}

//---------------------------------------------------------------------
// Author:		Marc van Heugten
// Date:		16-02-2004
// Description: Checks if a date is valid. 
// Input:		- obj: the form.textfield that must be validated
//				- DateSeperator (. or -)
//				- DateFormat (uppercase)
// Output:		- true if the date is valid
//				- false if the date is not valid
// Reference:	TD Webshop 300
//---------------------------------------------------------------------
function IsDate(obj, DateSeperator, DateFormat)
{	
	var dtCh = DateSeperator;
	var minYear = 1900;
	var maxYear = 2100;
	var dtFormat = DateFormat;

	var daysInMonth = DaysArray(12);
	var pos = new Array(4);
	var dtStr = obj.value;
		
	if (obj.value.length < 1){
		//alert('1');
		return false;
	}

	pos[0] = -1;
	if (DateSeperator.length > 0)
	{
		pos[1] = dtFormat.indexOf(dtCh);	
		pos[2] = dtFormat.indexOf(dtCh, pos[1] + 1);	
		pos[3] = dtFormat.length;
	}
	else
	{
		if (dtFormat.substring(0,4) == 'YYYY')
		{
			pos[1] = 4;	
		}
		else
		{
			pos[1] = 2;	
		}
		pos[2] = dtFormat.indexOf(dtCh, pos[1] + 2);	
		pos[3] = dtFormat.length;
	}
	var strDay = "";
	var strMonth = "";
	var strYear = "";
	for (var i = 0; i <= 2; i++) {
		var strChunk = dtFormat.substring(pos[i] + 1, pos[i] + 2);
		if (strChunk.toUpperCase() == "D") {
			strDay = dtStr.substring(pos[i] + DateSeperator.length, pos[i + 1]);
		}
		if (strChunk.toUpperCase() == "M") {
			strMonth = dtStr.substring(pos[i] + DateSeperator.length, pos[i + 1]);
		}
		if (strChunk.toUpperCase() == "Y") {
			strYear = dtStr.substring(pos[i] + DateSeperator.length, pos[i + 1]);
		} 
	}
		
	if (strMonth.charAt(0)=="0" && strMonth.length>1){
		strMonth=strMonth.substring(1);
	}
	
	for (var i = 1; i <= 3; i++) {
		if (strYear.charAt(0)=="0" && strYear.length>1){
			strYear=strYear.substring(1);
		}
	}
	
	//alert(strDay);
	//alert(strMonth);
	//alert(strYear);
	
	if (DateSeperator.length > 0)
	{
		if (dtStr.length != 10)
		{
			return false;
		}
	}
	else
	{
		if (dtStr.length != 8)
		{
			return false;
		}	
	}
	
	var month=parseInt(strMonth);
	var day=parseFloat(strDay);
	var year=parseInt(strYear);
	var blnOK = true;

	if (!isNumber(strDay) || !isNumber(strMonth) || !isNumber(strYear)){
		//obj.select();
		//obj.focus();
		//alert('2');
		return false;
	}
	if (pos[1]==-1 || pos[2]==-1){
		//obj.select();
		//obj.focus();
		//alert('3');
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		//obj.select();
		//obj.focus();
		//alert('4');
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//obj.select();
		//obj.focus();
		//alert('5');
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//obj.select();
		//obj.focus();
		//alert('6');
		return false;
	}
	if ((dtStr.indexOf(dtCh,pos[2] + 1)!=-1 && dtStr.length == 10) || isNumber(stripCharsInBag(dtStr, dtCh))==false){
		//obj.select();
		//obj.focus();
		//alert('7');
		return false;
	}
	return true;
}

//-------------------------------------------------------/IsDate Functions---------------------------------------------


//---------------------------------------------------------------------
// Author:		Richard Wittens
// Date:		30-02-2004
// Description: calculates the Difference between two dates
// Input:		- DateBegin: field Begin
//				- DateEnd: end field
//				- interval (d,D,h,H,m,M,s,S)
//				- rounding boolean
// Output:		- a valid date time field
// Reference:	TD Webshop 300
//---------------------------------------------------------------------
function DateDiff(DateBegin, DateEnd, interval, rounding)
{
	//-------------------------------------------------------------------------------
	// declare variables
	//-------------------------------------------------------------------------------
	var intYearBegin;
	var intMonthBegin;
	var intDayBegin;
	var intYearUntil;
	var intMonthUntil;
	var intDayUntil;
	var dtBegin;
    var dtEnd;
    var intNumber;
    var intResult;

	//-------------------------------------------------------------------------------
	// get integers of the date variable, for creating dates in javascript
	//-------------------------------------------------------------------------------
	intYearBegin = parseInt(DateBegin.substr(0,4));
	intMonthBegin = parseInt(DateBegin.substr(5,2));
	intDayBegin = parseInt(DateBegin.substr(8,2));

	intYearUntil = parseInt(DateEnd.substr(0,4));
	intMonthUntil = parseInt(DateEnd.substr(5,2));
	intDayUntil = parseInt(DateEnd.substr(8,2));
	
	//-------------------------------------------------------------------------------
	// subtract 1 from month, because of zero based month
	//-------------------------------------------------------------------------------
	intMonthBegin = intMonthBegin - 1;
	intMonthUntil = intMonthUntil - 1;
	
	//-------------------------------------------------------------------------------
	// set the date and other variables for calculating the differece
	//-------------------------------------------------------------------------------
	dtBegin = new Date( intYearBegin, intMonthBegin, intDayBegin) ;
    dtEnd = new Date( intYearUntil, intMonthUntil, intDayUntil) ;
    intResult = 0;

	//---------------------------------------------------------------------
	// check that the start parameter is a valid Date. 
	//---------------------------------------------------------------------
    if ( isNaN (dtBegin) || isNaN (dtEnd) ) 
    {
        return null ;
    }

	//---------------------------------------------------------------------
    // check that an interval parameter was not numeric. 
	//---------------------------------------------------------------------
    if ( interval.charAt == 'undefined' ) {
		//---------------------------------------------------------------------
        // the user specified an incorrect interval, handle the error. 
		//---------------------------------------------------------------------
        return null ;
    }

	//---------------------------------------------------------------------
    // subtract date end from date begin.
	//---------------------------------------------------------------------
	intNumber = dtEnd - dtBegin;
	
	//---------------------------------------------------------------------
    // what kind of add to do? 
	//---------------------------------------------------------------------
    switch (interval.charAt(0))
    {
        case 'd': case 'D': 
            intResult = parseInt(intNumber / 86400000) ;
            if(rounding) intResult += parseInt((intNumber % 86400000)/43200001) ;
            break ;
        case 'h': case 'H':
            intResult = parseInt(intNumber / 3600000 ) ;
            if(rounding) intResult += parseInt((intNumber % 3600000)/1800001) ;
            break ;
        case 'm': case 'M':
            intResult = parseInt(intNumber / 60000 ) ;
            if(rounding) intResult += parseInt((intNumber % 60000)/30001) ;
            break ;
        case 's': case 'S':
            intResult = parseInt(intNumber / 1000 ) ;
            if(rounding) intResult += parseInt((intNumber % 1000)/501) ;
            break ;
        default:
	        return null ;
    }
    return intResult ;
}

//---------------------------------------------------------------------
// Author:		Richard Wittens
// Date:		30-02-2004
// Description: calculates the Difference between two dates
// Input:		- FormatDate: string with date to format
//				- DateSeperator 
//				- DateFormat
// Output:		- a date formatted in YYYY-MM-DD
// Reference:	TD Webshop 300
//---------------------------------------------------------------------
function FormatDate(FormatDate, DateFormat)
{
	//-------------------------------------------------------------------------------
	// declare variables
	//-------------------------------------------------------------------------------
	var strFormat = new String();
	var strYear = new String();
	var strMonth = new String();
	var strDay = new String();
	
	//-------------------------------------------------------------------------------
	// change the format
	//-------------------------------------------------------------------------------
	strFormat = FormatDate;
	switch(DateFormat.toLowerCase())
	{
		case 'dd-mm-yyyy': case 'dd.mm.yyyy': case 'dd/mm/yyyy': 
		{
			strYear = strFormat.substr(6,4);
			strMonth = strFormat.substr(3,2);
			strDay = strFormat.substr(0,2);
			break;
		}
		case 'mm-dd-yyyy': case 'mm.dd.yyyy': case 'mm/dd/yyyy': 
		{
			strYear = strFormat.substr(6,4);
			strMonth = strFormat.substr(0,2);
			strDay = strFormat.substr(3,2);
			break;
		}
		case 'yyyy-mm-dd': case 'yyyy/mm/dd': case 'yyyy.mm.dd':
		{
			strYear = strFormat.substr(0,4);
			strMonth = strFormat.substr(5,2);
			strDay = strFormat.substr(8,2);
			break;
		}
		case 'yyyymmdd':
		{
			strYear = strFormat.substr(0,4);
			strMonth = strFormat.substr(4,2);
			strDay = strFormat.substr(6,2);
			break;
		}		
		case 'mmddyyyy':
		{
			strMonth = strFormat.substr(0,2);
			strDay = strFormat.substr(2,2);
			strYear = strFormat.substr(4,4);
			break;
		}
		case 'ddmmyyyy':
		{
			strDay = strFormat.substr(0,2);		
			strMonth = strFormat.substr(2,2);
			strYear = strFormat.substr(4,4);
			break;
		}		
		
		default:
		{
			strYear = '';
			strMonth = '';
			strDay = '';
			break;
		}
	}
	
	return strYear + strMonth + strDay;
}

//---------------------------------------------------------------------
// Author:		Richard Wittens
// Date:		20-02-2004
// Description: This function Disables the button as it is clicked
// Reference:	TD Webshop 300
//---------------------------------------------------------------------
function DisableButton(btnClicked)
{
	btnClicked.disabled=true;
	return true;
}

//---------------------------------------------------------------------
// Author:		Richard Wittens
// Date:		20-02-2004
// Description: This function Disables the button as it is clicked
// Reference:	TD Webshop 300
//---------------------------------------------------------------------
function EnableButton(btnClicked)
{
	btnClicked.disabled=false;
	return true;
}

//---------------------------------------------------------------------
// Author:		Daniel Wauben
// Date:        01-03-2005
// Description: This function Checks if the password field is correctly formatted
// Reference:   TD Webshop 300
//---------------------------------------------------------------------
function CheckFormat(FormFieldOne)
{
	var blnResult = false;
    var i;
    var Numbers = false;
    var Characters = false;

	if (FormFieldOne.value.length >= 6)

	{
	    blnResult = true;
	}

	if (blnResult)
	{
		for (i = 0; i < FormFieldOne.value.length; i++)
			{   
				//---------------------------------------------------------------------
                // Check that current character is number.
                //---------------------------------------------------------------------
                var c = FormFieldOne.value.charCodeAt(i);         
                if ((c > 47) && (c < 58))
                {
					Numbers = true;
                }           
                if (((c > 96) && (c < 123)) || ((c > 64) && (c < 91)))
                {
					Characters = true;
                }           
            }
            if (Numbers && Characters)
            {
                blnResult = true;
            }
            else
            {
                blnResult = false;
            }
	}
	return blnResult;

}

function RemoveMaxLength(max, formElement)
{
	if(formElement.value.length > max)
	{
		var str = formElement.value;
		formElement.value = str.substr(0,max);
	}
}

//---------------------------------------------------------------------
// Author:		Richard Wittens
// Date:		28-04-2004
// Description: This function Checks if the value is filled
// Reference:	TD Webshop 300
//---------------------------------------------------------------------
function CheckMandatory(FormField)
{
	var blnResult = false;
	
	if (FormField.value != "")
	{
		blnResult = false;
	}
	else
	{
		blnResult = true;
	}
	
	return blnResult;
}

//---------------------------------------------------------------------
// Author:		Richard Wittens
// Date:		28-04-2004
// Description: This function Checks if the value is between the min
//				and max value
// Reference:	TD Webshop 300
//---------------------------------------------------------------------
function CheckValue(FormField, NumberFormat, MinValue, MaxValue)
{   
	var strResult = "";
	var blnError = false;
	
	if (NumberFormat == "DotComma")
	{
		strResult = FormField.value.replace(".","");
		strResult = strResult.replace(",",".");
	}
	else
	{
		strResult = FormField.value.replace(",","");
	}
	
	
	//---------------------------------------------------------------------
	// Check if the min value is filled, and if the value filled in is valid
	//---------------------------------------------------------------------
	if (MinValue != null)
	{
		if (strResult < MinValue)
		{
			blnError = true;
		}	
	}

	//---------------------------------------------------------------------
	// Check if the min value is filled, and if the value filled in is valid
	//---------------------------------------------------------------------
	if (MaxValue != null)
	{
		if (strResult > MaxValue)
		{
			blnError = true;
		}	
	}
		
	return blnError;
}

//---------------------------------------------------------------------
// Author:		Richard Wittens
// Date:		10-05-2004
// Description: This function Checks if the two fields are equal
// Reference:	TD Webshop 300
//---------------------------------------------------------------------
function CheckEqual(FormFieldOne, FormFieldTwo)
{
	var blnResult = false;
	
	if (FormFieldOne.value != FormFieldTwo.value)
	{
		blnResult = false;
	}
	else
	{
		blnResult = true;
	}
	
	return blnResult;
}

function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, "").replace(/\s+$/g, "");
}

function isNumber(s)
{
	var i;
	if (s.length == 0)
	{
		return false;
	}
	for (i = 0; i < s.length; i++)
	{   
		//---------------------------------------------------------------------
		// Check that current character is number.
		//---------------------------------------------------------------------
		var c = s.charAt(i);
		if (((c < "0") || (c > "9")))
		{
			return false;
		}
	}
	//---------------------------------------------------------------------
	// All characters are numbers.
	//---------------------------------------------------------------------
	return true;
}