function isEmpty(theData) {
	return ((theData == null) || (theData.length == 0));
}

function stripSpaces(theString) {
	while (theString.substring(0, 1) == ' ') theString = theString.substring(1);
	return theString;
}

function isDigit (c) {
	return ((c >= "0") && (c <= "9"))
}

function isNumber(data) {
	var theChar;

	if (isEmpty(data)) return false;

	for (var i = 0; i < data.length; i++) {
		// Check that current character is number.
		theChar = data.charAt(i);
		if (!isDigit(theChar)) return false;
	}
	
	// All characters are numbers.
	return true;
}

function isCharacter(data) {
	var theChar;

	if (isEmpty(data)) return false;

	for (var i = 0; i < data.length; i++) {
		// Check that current character is number.
		theChar = data.charAt(i);
		if (!isAlfaNumeric(theChar)) return false;
	}
	
	// All characters are numbers.
	return true;
}

function MyFormatNumber(tBox) {
	var inputData = String(tBox.value);
	var formattedData = String("");
	var i = 0;
	var j = 0;
	
	for (i=inputData.length, j=0; i>=0; i--) {
		if (inputData.charAt(i) >= '0' && inputData.charAt(i) <= '9') {
			j++;
			if ((j % 3) == 0 && i != 0)
				formattedData = "." + inputData.charAt(i) + formattedData 
			else
				formattedData = inputData.charAt(i) + formattedData 
		}
	}

	tBox.value = formattedData;

	return;
}

function RemoveDigitSeperators(data) {
	var theChar;
	var returnValue = "";

	if (isEmpty(stripSpaces(data))) return returnValue;

	for (var i = 0; i < data.length; i++) {
		// Check that current character is number.
		theChar = data.charAt(i);
		if (isDigit(theChar)) returnValue += theChar;
	}
	return returnValue;
}

function SeperateDigits(theString) {
	var theChar;
	var j = 0;
	var returnValue = "";
	var tutar = String(theString.value);

	if (tutar.length > 0) {
		RemoveDigitSeperators(tutar);
		for (var i = tutar.length; i >= 0; i--) {
			theChar = tutar.charAt(i);
			if (isDigit(theChar)) {
				j++;
				if (((j % 3) == 0) && (i != 0))
					returnValue = "." + theChar + returnValue
				else
					returnValue = theChar + returnValue
			}
		}
	}

	theString.value = returnValue;
}

function SeperateDigitsForText(theString) {
	var theChar;
	var j = 0;
	var returnValue = "";
	var tutar = String(theString);

	if (tutar.length > 0) {
		RemoveDigitSeperators(tutar);
		for (var i = tutar.length; i >= 0; i--) {
			theChar = tutar.charAt(i);
			if (isDigit(theChar)) {
				j++;
				if (((j % 3) == 0) && (i != 0)) returnValue += "."
				returnValue = theChar + returnValue
			}
		}
	}

	return returnValue;
}

function isName (c) {
	return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || (c == " ") /*|| (c == ".") || (c == "'")*/ || isTurkish (c))
}

function isAlfaNumeric (c) {
	return (isName (c) || (c == "/")  || (c == "-") || (c == ":") || (c == " ") || isDigit (c))
}

function isRegistryNo (c) {
	return ((c == ".") || (c == "/")  || (c == "-") || (c == ":") || isDigit (c))
}

function isTurkish (c) {
	return ((c == "Ğ") || (c == "ğ") || (c == "Ü") || (c == "ü") || (c == "Ş") || (c == "ş") || (c == "İ") || (c == "ı") || (c == "Ö") || (c == "ö")  || (c == "Ç")  || (c == "ç"))
}

function isExtAccount (c) {
	return (isEmail(c) || (c == "/")  || (c == ":"))
}

function isIDName (c) {
	return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || isDigit(c) )
}

function isEmail (c) {
	return (isIDName (c) || (c == "_") || (c == ".") || (c == "-"))
}
function isValidKey(theString,theType,label) {
	var theChar;
	var j = 0;
	var rc;
	var returnValue = "";
	var deger = String(theString.value);
	
		if (deger.length > 0) {
			for (var i = deger.length; i >= 0; i--) {
				theChar = deger.charAt(i);
				if (theType == "D") // Digit
				{	if (isDigit(theChar)) 
					{
						j++;
						returnValue = theChar + returnValue;
					}
				}
				else if (theType == "N") // Name
				{	if (isName(theChar)) 
					{
						j++;
						returnValue = theChar + returnValue;
					}
					else
					{
						if (label == "Cevabınız")
							returnValue = theChar + returnValue;
					}
				}
				else if (theType == "A") // AlfaNumeric
				{	if (isAlfaNumeric(theChar)) 
					{
						j++;
						returnValue = theChar + returnValue;
					}
				}
				else if (theType == "I") // IDName
				{	if (isIDName(theChar)) 
					{
						j++;
						returnValue = theChar + returnValue;
					}
					else
					{
						if (label == "Kullanıcı Adı" || label == "Şifre")
							returnValue = theChar + returnValue;
					}
				}
				else if (theType == "E") // Email
				{	if (isEmail(theChar)) 
					{
						j++;
						returnValue = theChar + returnValue;
					}
				}
				else if (theType == "X") // isExtAccount
				{	if (isExtAccount(theChar)) 
					{
						j++;
						returnValue = theChar + returnValue;
					}
				}
				else if (theType == "R") // isRegistryNo
				{	if (isExtAccount(theChar)) 
					{
						j++;
						returnValue = theChar + returnValue;
					}
				}
			}
			if (j < deger.length) 
				{
				if (theType == "N") // Name
					alert("Bu alana sayı veya noktalama işareti giremezsiniz.");
				else if (label == "Şifre")
					alert("Lütfen şifrenizde son girdiğiniz karakteri kontrol ediniz. Şifrede türkçe karakter (ü,ğ,ş,ç,ı,ö,İ) kullanmayınız.")
				else if (label == "Kullanıcı Adı")
					alert("Lütfen kullanıcı adınızda türkçe karakter (ü,ğ,ş,ç,ı,ö,İ) kullanmayınız.");
				else
					alert("Lütfen " + label + " alanına girdiğiniz değeri kontrol ediniz.");
				if (theType == "E")
					returnValue = "";
				theString.form.elements[theString.name].focus();
				rc = false;
				}
			else
				rc = true;
		}
	theString.value = returnValue;
	return rc;
}
