function IsValidIdentityNumber(checkStr)
{
	//Check if is 13 Characters
	if(checkStr.length != 13)
	{
		return false;
	}
	
	//Check if is Numeric
	if(!IsNumeric(checkStr))
	{
		return false;
	}
	
	//Do Modulus Check - Add all odds excl last, make number of evens - mult by 2 and add digits, add both results, control makes mod 10 = 0
	d = -1; 
  
  //Build Odd Section
  a = 0; 
  for(i = 0; i < 6; i++) 
  { 
     a += parseInt(checkStr.charAt(2*i)); 
  } 
  
  //Build even section
  b = 0; 
  for(i = 0; i < 6; i++) 
  { 
     b = b*10 + parseInt(checkStr.charAt(2*i+1)); 
  } 
  
  b *= 2; 
  
  c = 0; 
  do 
  { 
     c += b % 10; 
     b = ((b - (b % 10)) / 10) ; 
  } 
  while(b > 0); 
  
  //Add
  c += a; 
  
  //Check control makes mod 10 == 0
  return (((c + parseInt(checkStr.charAt(12))) % 10) == 0);
}

function IsNumeric(checkStr) {
        var checkOK = "0123456789";
        var allValid = true;
        var decPoints = 0;
        var allNum = "";
        if(checkStr.length != 0)
        {
        	for (i = 0;  i < checkStr.length;  i++) {
            ch = checkStr.charAt(i);
            for (j = 0;  j < checkOK.length;  j++)
                if (ch == checkOK.charAt(j))
                    break;
            if (j == checkOK.length) {
                allValid = false;
                break;
            }
            allNum += ch;
        	}
        }
        else
        {
        	allValid = false;
      	}
      return allValid;
    }

function IsValidPhone(checkStr) {
        var checkOK = "0123456789)(-+ ";
        var allValid = true;
        var decPoints = 0;
        var allNum = "";
        for (i = 0;  i < checkStr.length;  i++) {
            ch = checkStr.charAt(i);
            for (j = 0;  j < checkOK.length;  j++)
                if (ch == checkOK.charAt(j))
                    break;
            if (j == checkOK.length) {
                allValid = false;
                break;
            }
            allNum += ch;
        }
        return allValid;
    }

    function KillSpaces(Strng) {
        TempString = "";
        for(t=0;t <= Strng.length-1;t++) {
			if (Strng.charAt(t) == " ") {
				TempString = TempString + "";
			} else {
               TempString = TempString + Strng.charAt(t);
        	}
		}
        return(TempString);
    }
    
    function IsValidEmail(checkStr) 
    {
	atFound = false;
	domainFound = false;
	
	//Ensure format x@y.z
	//Force at least one char in domain pre "@" by starting at 1
	for(i=1; i<checkStr.length; i++)
	{
		if(!atFound)
		{
			if(checkStr.charAt(i) == "@")
			{
				atFound = true;
				//Force at least one char in domain pre "."
				i++;
			}
		}
		else if(!domainFound)
		{
			if(checkStr.charAt(i) == ".")
			{
				domainFound = true;
			}
		}
		else
		{
			return true;
		}
	}
	
	return false;
    }
    
    function IsValidDate(dateValue)
    {
    	part = 0;	
    	
    	year = "";
    	month = "";
    	day = "";
    	
	//Parse the string
    	for(i=0; i<dateValue.length; i++)
	{
		currentChar = dateValue.charAt(i);
		
		if(currentChar == "/")
		{
			part++;
			
			if(part > 2)
			{
				return false;
			}
		}
		else
		{
			if(part == 0)
			{
				year += currentChar;
			}
			else if(part == 1)
			{
				month += currentChar;
			}
			else if(part == 2)
			{
				day += currentChar;
			}
		}
	}//End of parse loop
    	
	//Check parts
    	if(part != 2)
    	{
    		return false;
    	}
    	
    	//Check they are all numeric
    	if(!IsNumeric(year) || !IsNumeric(month) || !IsNumeric(day))
    		return false;
    	
	//Check Year Range
    	if((year < 1900) || (year > 2100))
    		return false; 
    	
    	//Check Month Range
    	if((month < 1) || (month > 12))
   		return false; 
   		
    	//Calc Leap Year days
    	leapDays = 28 + ((year%4==0)?1:0) - ((year%100==0)?1:0) + ((year%400==0)?1:0);
    	
    	//Check Day Range
    	if((day < 1) || (day > 31))
    	{
    		return false;
    	}
    	else if((month==4  || month==6 || month==9 || month==11) && (day > 30))
    	{
    		return false; 
    	}
    	else if((month==2) && (day > leapDays))
    	{
    		return false; 
    	}
    	
	return true;
    }

function NumbersOnly(keycode)
{
	alert(keycode);
	return ((keycode < 58) && (keycode > 47))?true:false;
}

function IsValidVAT(checkStr)
{
	//Check if is 10 Characters
	if(checkStr.length != 10)
	{
		return false;
	}
	
	//Check if is Numeric
	if(!IsNumeric(checkStr))
	{
		return false;
	}
	
	return true;
}

function IsNumericWithinLimit(checkStr, limit)
{
	if(!IsNumeric(checkStr))
	{
		return false;
	}

	a = parseInt(checkStr); 
	if (a > limit)
	{
		return false;
	}
	
	return true;
}
