function checkExpiryDate(theForm,todaymill) {
		mergeExpiryDate(theForm);
		if (theForm.expirydate.value.length<4) {
			alert("expiry date is required");
			return false;
		}
		if (!checkDate(theForm,todaymill)) {
		    alert("Expiry date is not valid, please input again");
			return false;
		}
		return true;
}

function mergeExpiryDate(theForm) {
		theForm.expirydate.value=theForm.ed1.value+theForm.ed2.value;
}

function checkDate(theForm,todaymill) {
        if (theForm.ed1.value <"01" || theForm.ed1.value > "12") {
			return false;
		}
    	var day = new Date();
		day.setFullYear("20"+theForm.ed2.value);
		day.setMonth(theForm.ed1.value-1);
		day.setDate("01");
		if (day.getTime() < todaymill) {
			return false;
		}
		return true;
}		

function checkAmount(amount)
{
	var points, afterPoint;
	points=0;
	afterPoint=0;
	intpart=0;
	if(amount.length <1)
	{
		return(false);
	}
	
	for(i=0;i<amount.length; i++)
	{
		if(amount.charAt(i)!='.' && isNaN(amount.charAt(i)))
		{
			return(false);
		}
		if(amount.charAt(i) == '.')
		{
			points++;
		}
		if (points == 0) {
			intpart++;
		}
		if(points > 0)
		{
			afterPoint++;
		}
    }
	if ( points > 1) {
		alert("It is not a valid amount");
		return(false);
	}
	if (intpart > 3) {
		alert("Amount can not exceed $999.99");
		return(false);
	}
	if(afterPoint > 3)
	{
		alert("Amount can not have more than two decimal");
		return(false);
	}
	return(true);
}

function checkCard(card_number)
{
	var card = card_number.value;
	if (card.length<15) {
		return (false);
        }
	for(i=0; i<card.length; i++)
	{
		if(isNaN(card.charAt(i)))
		{
			return(false);
		}
	}
	
	return(true);
}

function checkCardType(tran_code,card_number)
{
	var card =  card_number.value;
	if(tran_code == "IVSA")
	{
		if(card.charAt(0)!='4')
		{
			return(false);
		}
	}
	if (tran_code =="IAMX")
	{
		if(card.charAt(0)!='3')
		{
			return(false);
		}
	}
	if (tran_code =="IMSC")
	{
		if(card.charAt(0)!='5')
		{
			return(false);
		}
	}
	return(true);
}

function mod10(card_number)
{
	var cardNumber = card_number.value;
	var sum, tmp;
	var even;
	even=false;
	sum=0;
	for(i=cardNumber.length-1; i>=0; i--)
	{
		if(even)
		{
			tmp=(cardNumber.charAt(i)-'0') * 2;
			sum += tmp % 10;
			sum += Math.floor(tmp /10);
		}
		else
		{
			sum +=(cardNumber.charAt(i)-'0');
		}
	
		even = ! even;

	}
	if(sum % 10 == 0)
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

function checkEmail(email)
{
	if(email.search(/^.+@.+\..+$/i) == -1)
	{
		return(false);
	}
	else
	{
		return(true);
	}
}

function checkUsername(username)
{
	if(username.search(/^[a-zA-Z0-9_-]+$/) == -1)
	{
		return(false);
	}
	else
	{
		return(true);
	}
}


function checkTheAddress(address)
{
	if(address == "")
	{
		return(false);
	}
	else
	{
		return(true);
	}
}

function checkPhone(areacode,phone1,phone2) 
{	
	if (isNaN(areacode) || isNaN(phone1) || isNaN(phone2)) return false;
	if ((areacode.length!=3) || (phone1.length!=3) || (phone2.length!=4)) return false;
	return true;
}

function checkPassword(password1, password2)
{
	if (password1 == password2) 
	{
		return(true);
	} 
	else
	{
		return(false);
	}
}


function checkNumber(theNumber)
{
	if(theNumber.search(/^[0-9]+$/) == -1)
	{
		return(false);
	}
	else
	{
		return(true);
	}
}

function checkTheYear(theYear)
{
	if(theYear.search(/^[0-9]{4}$/) == -1)
	{
		return(false);
	}
	else
	{
		return(true);
	}
}

function checkTheDay(theDay)
{
	if(theDay.search(/^[0-9]{2}$/) == -1)
	{
		return(false);
	}
	else
	{
		return(true);
	}
}

