// validates email address
function validateEmail(mailAddr)
{
	if(mailAddr.indexOf("@")==-1 || mailAddr.indexOf("@")==0 || (mailAddr.indexOf("@")==(mailAddr.length-1)))
		return false;
	for(var i=0;i<mailAddr.length;i++)
		if(mailAddr.charAt(i)==" ")
			return false;
	return true;
}

// validates email address
function validateUsername(username)
{
	var OK=true;
	for(var i=0;i<username.length;i++)
	{
		thechar=username.charAt(i);
		if((thechar<"0" || thechar>"9"))
		{		
			if((thechar<"A") || (thechar>"Z"))
			{
				if((thechar<"a") || (thechar>"z"))
				{
					OK=false;
					break;
				}
			}
		}
	}
	return OK;
}

// validates phone number to check if it contains only valid characters (0-9,(,),+,-)
function isValidPhoneNo(thestring)
{
	var OK=true;
	for(var i=0;i<thestring.length;i++)
	{
		thechar=thestring.charAt(i);
		if((thechar<"0") || (thechar>"9"))
		{
			if(!((thechar=="+") || (thechar=="(") || (thechar==")") || (thechar=="-")))
			{
				OK=false;
				break;
			}
		}
	}
	return OK;
}

// validates the zip code to see if it is minimum 5 digits and only numeric value
function isValidZIPCode(thestring)
{
	var OK=true;
	if(thestring.length<5)
	{
		OK=false;
		return OK;
	}

	for(var i=0;i<thestring.length;i++)
	{
		thechar=thestring.charAt(i);
		if((thechar<"0") || (thechar>"9"))
		{
			if(!(thechar=="-"))
			{
				OK=false;
				break;
			}
		}
	}
	
	return OK;
}

// check if the given string is a numeric value 
function isNumeric(thestring)
{
	var OK=true;
	for(var i=0;i<thestring.length;i++)
	{
		thechar=thestring.charAt(i);
		if((thechar<"0") || (thechar>"9"))
		{
			if(!(thechar=="-"))
			{
				OK=false;
				break;
			}
		}
	}
	return OK;
}

// check if the given string is a decimal value 
function isDecimal(thestring)
{
	var OK=true;
	for(var i=0;i<thestring.length;i++)
	{
		thechar=thestring.charAt(i);
		if((thechar<"0") || (thechar>"9"))
		{
			if(!(thechar=="-"  || thechar=="."))
			{
				OK=false;
				break;
			}
		}
	}
	return OK;
}

// check if given date is greater than current system date
function isGreaterThanSystemDate(dd,mm,yy)
{
	var today=new Date();
	if(yy>today.getYear())
    	return true;
    if(yy==today.getYear())
    {
		if(mm>today.getMonth()+1)
			return true;
    	if(mm==today.getMonth()+1)
		{
			if(dd>today.getDate())
	   			return true;
	 		else
	   			return false;
		}
    	else
			return false;
    }
    else
    	return false;
}

// check if 2nd date is greater than 1st and return true else return false
function compareDates(startDay,startMonth,startYear,endDay,endMonth,endYear)
{
	if(endYear>startYear)
    	return true;
  	if(endYear==startYear)
  	{
    	if(endMonth>startMonth)
        	return true;
    	if(endMonth==startMonth)
      	{
       		if(endDay>startDay)
         		return true;
       		else
         		return false;
      	}
    	else
      		return false;
  	}
  	else
    	return false;
}

// check for credit card validation as per the Luhn Check Algorithm
// Note :pass credit card number as a parameter
function doLuhnCheck(CardNumber)
{
	if(!isNumeric(CardNumber))
	{
		return false;
  	}

	var no_digit = CardNumber.length;
	var oddoeven = no_digit & 1;
	var sum = 0;

	for(var count = 0; count < no_digit; count++)
	{
		var digit = parseInt(CardNumber.charAt(count));
		if(!((count & 1) ^ oddoeven))
		{
			digit *= 2;
			if(digit > 9)
				digit -= 9;
		}
		sum += digit;
	}
	if(sum % 10 == 0)
		return true;
	else
		return false;
}

// check if the given string is empty or not
function isEmpty(str)
{
	return (str==0)?true:false;
}

// Check for equality of strings.Returns true if equal
function compareStrings(string1,string2)
{
	return (string1==string2)?true:false;
}