//--------------------------------------------------------------------------//
// Description: check if string length is greater than zero
function testString(f_sString)
{
	if (f_sString.length > 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}


//--------------------------------------------------------------------------//
// Description: check if string length equals a custom length
function testStringEq(f_sString, f_iLen)
{
	if (f_sString.length == f_iLen)
	{
		return true;
	}
	else
	{
		return false;
	}
}


//--------------------------------------------------------------------------//
// Description: check if string length is greater than a custom length
function testStringGt(f_sString, f_iLen)
{
	if (f_sString.length > f_iLen)
	{
		return true;
	}
	else
	{
		return false;
	}
}


//--------------------------------------------------------------------------//
// Description: check if string length is less than a custom length
function testStringLt(f_sString, f_iLen)
{
	if (f_sString.length < f_iLen)
	{
		return true;
	}
	else
	{
		return false;
	}
}


//--------------------------------------------------------------------------//
// Description: check if argument is an integer
function testInt(f_iInteger)
{
	var regInt = /^[0-9]+$/;
	
	if (regInt.test(f_iInteger) == true)
	{
		return true;
	}	
	else
	{
		return false;
	}
}


//--------------------------------------------------------------------------//
// Description: check if argument is a float number
function testFloat(f_flFloat)
{
	var regFloat = /^[0-9]+(\.[0-9]+)*$/;
	
	if (regFloat.test(f_flFloat) == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}


//--------------------------------------------------------------------------//
// Description: check if argument is an integer and is greater than zero.
function testIntGtZero(f_iInteger)
{
	var regInt = /^[0-9]+$/;
	
	if (regInt.test(f_iInteger) == true && f_iInteger > 0)
	{
		return true;
	}	
	else
	{
		return false;
	}
}


//--------------------------------------------------------------------------//
// Description: check if argument doesn't equal -1
function testMinusOne(f_iInteger)
{
	if (f_iInteger != -1)
	{
		return true;
	}	
	else
	{
		return false;
	}
}


//--------------------------------------------------------------------------//
// Description: test time format (hh:mm[:ss])
function testTime(f_sTime)
{
	var regTime = /^([0-2]?[0-9]):[0-5][0-9](:[0-5][0-9])?$/;
	var iIndex;
	var iValue;
	var sValue = f_sTime;
	
	if (regTime.test(sValue) == true)
	{
		iIndex = sValue.indexOf(":");
		iValue = sValue.substr(0,iIndex);
		
		if (iValue <= 23 && iValue >=0)
		{
			return true;
		}
		else
		{
			return false;
		}	
	}
	else
	{
		return false;
	}
}


//--------------------------------------------------------------------------//
// Description: test date format (dd.mm.yy[yy])
function testDate(f_sDate)
{
	var regDate = /^([0-3]?[0-9])\.([0-1]?[0-9])\.[1-9][0-9]{3}$/;
	var iIndex, iIndex2;
	var iMonth,iDay,iYear;
	var arrMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	var sValue = f_sDate;
	
	if (regDate.test(sValue) == true)
	{
		iIndex = sValue.indexOf(".");
		iIndex2 = sValue.indexOf(".",iIndex+1);
		
		iDay = sValue.substr(0,iIndex);
		iMonth = sValue.substring(iIndex+1,iIndex2);
		iYear = sValue.substr(iIndex2+1,sValue.length);		

		if (iMonth < 1 || iMonth > 12)
		{
			return false;		
		}
		
		if (iMonth == 2 && ( ( (iYear % 4) == 0 && (iYear % 100) != 0 ) || (iYear % 400) == 0 ) ) 
		{
			if (iDay < 1 || iDay > 29)
			{
				return false;
			}
		}
		else
		{
			if (iDay < 1 || iDay > arrMonth[iMonth-1])
			{
				return false;
			}
		}		

		return true;

	}
	else
	{
		return false;
	}
}

//----------------------------------------------------------------------------------------------------------
// Datum vergleichen  (dd.mm.yyyy)
// gibt true zurück, wenn erstes Datum (obj) kleiner gleich zweites Datum (obj2) ist, sonst false
// DATUM MUSS ZUERST MIT "testDate()"-Funktion ÜBERPRÜFT WERDEN!!!
// mode = 0 -> obj = string
// mode = 1 -> obj = form.object

function compareDate(obj,obj2,mode)
{
	if (mode == 0)
	{ 
		var sValue = obj;
		var sValue2 = obj2;		
	}
	else if (mode == 1)
	{
		var sValue = obj.value;
		var sValue2 = obj2.value;
	}
	
	iIndex = sValue.indexOf(".");
	iIndex2 = sValue.indexOf(".",iIndex+1);
	
	iDay = sValue.substr(0,iIndex);
	iDay = (iDay.length == 2) ? iDay : iDay = "0" + iDay ; 
	iMonth = sValue.substring(iIndex+1,iIndex2);
	iMonth = (iMonth.length == 2) ? iMonth : iMonth = "0" + iMonth ; 
	iYear = sValue.substr(iIndex2+1,sValue.length);	

	iIndex = sValue2.indexOf(".");
	iIndex2 = sValue2.indexOf(".",iIndex+1);
	
	iDay2 = sValue2.substr(0,iIndex);
	iDay2 = (iDay2.length == 2) ? iDay2 : iDay2 = "0" + iDay2 ; 
	iMonth2 = sValue2.substring(iIndex+1,iIndex2);
	iMonth2 = (iMonth2.length == 2) ? iMonth2: iMonth2 = "0" + iMonth2 ; 
	iYear2 = sValue2.substr(iIndex2+1,sValue.length);		
	
	iDate = parseInt(iYear + iMonth + iDay);
	iDate2 = parseInt(iYear2 + iMonth2 + iDay2);
	
	//alert(iDate + ", " + iDate2);
	
	if(iDate <= iDate2)
	{
		return true
	}
	else
	{
		return false;
	}
}


//--------------------------------------------------------------------------//
// Description: check email format
function testEmail(f_sEmail)
{
	var regEmail = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*\.([a-zA-Z]{2,4})$/;
	
	if (regEmail.test(f_sEmail) == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}


//--------------------------------------------------------------------------//
// Description: check if argument is a CH PLZ
function testChPlz(f_iPLZ)
{
	var regPLZ = /^[1-9][0-9]{3}$/;
	
	if (regPLZ.test(f_iPLZ) == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}


//--------------------------------------------------------------------------//
// Description: check if argument is a valid phone number
function testPhoneNr(f_sPhoneNr)
{
	var regInvalideChr = new RegExp("[^ 0-9-/+']");
	var regNumber = new RegExp("[\\D]","g");
	var sNumbersOnly = f_sPhoneNr.replace(regNumber, "");
	
	if(sNumbersOnly.length < 9)
	{
		return false;
	}
	else
	{
		if (!testEmpty(f_sPhoneNr) && !regInvalideChr.test(f_sPhoneNr))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}


//--------------------------------------------------------------------------//
// Description: check if argument is in a valide format that represents CHF Format xx[.yy] (yy -> steps of 5)
function testCHMoney(f_flMoney)
{
	var regMoney = /(^[1-9][0-9]*|^0)(\.[0-9](0|5))?$/;
	
	if (regMoney.test(f_flMoney) == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}


//--------------------------------------------------------------------------//
// Description: check if argument contains anything else than white space
function testEmpty(f_sString)
{
	var regWhiteSpace = /[^ \f\n\r\t]/;
	
	if (regWhiteSpace.test(f_sString))
	{
		return false;
	}
	else
	{
		return true;
	}
}
