// JavaScript Document
function chkdate(strDate){
var strDate1=strDate.replace(/\s/g,"");
var i=strDate1.indexOf("/");
var dateA,dateB

if(parseInt(strDate1.substring(0,i))==0){
	dateA=parseInt(strDate1.substring(1,i));
	}
else{
	dateA=parseInt(strDate1.substring(0,i));
	}
	
if(parseInt(strDate1.substring(i+1,strDate1.length))==0){
	dateB=parseInt(strDate1.substring(i+2,strDate1.length));
	}
else{
	dateB=parseInt(strDate1.substring(i+1,strDate1.length));
	}
	
if(dateA>0 && dateA<=12){
	if(dateB>=0 && dateB<=99){
	return true;
	}
	else
	{return false;}
}
else{
return false;
}
}

function chkform()
{
var mydate=new Date();
var strCard;
var colCard;
var Caution;
var a=b=c=d=e=f=g=0;
Caution="Please complete the following files:";

colCard=document.getElementsByName("credit_card");
strCard=document.form.card_number.value;
//strCard=strCard.replace(/\s/g,"");
//strCard=strCard.replace(/-/g,"");
if(strCard!=""){
if(colCard[0].checked){
	if(!(strCard.substring(0,1)=="5" && strCard.length=="16")){
		alert("Your Master Card Number is incorrect,please check!");
		document.form.card_number.focus();
		return false;
	}
}
else if(colCard[1].checked){
	if(!(strCard.substring(0,1)=="4" && strCard.length=="16")){
		alert("Your Visa Card Number is incorrect,please check!");
		document.form.card_number.focus();
		return false;
	}
}
else if(colCard[2].checked){
	if(!(strCard.substring(0,1)=="3" && strCard.length=="15")){
		alert("Your American Express Card Number is incorrect,please check!");
		document.form.card_number.focus();
		return false;
	}
}
}

if(document.form.Expiration.value!=""){
var strExp=document.form.Expiration.value;
var dv=new Date(document.form.Expiration.value);

var myYear=mydate.getYear().toString();
var myMonth=mydate.getMonth().toString();
	if(chkdate(strExp)){
		var strExpA="20"+strExp.substring(strExp.indexOf("/")+1,strExp.length);
		if (parseInt(strExpA)<parseInt(myYear)){
		alert("Your card has exceed the time limit,please change another one.");
		return false;
		}
		var strExpB=strExp.substring(0,strExp.indexOf("/"));
		if(parseInt(strExpB)==0){
			strExpB=strExp.substring(1,2);
			}
		if(parseInt(strExpA)==parseInt(myYear) && parseInt(strExpB)<(parseInt(myMonth)+1)){
		alert("Your card has exceed the time limit,please change another one.");
		return false;
		}
	}
	else{
	alert("The format of Expiration is incorrect, please check! Correct example: 09/10");
	document.form.Expiration.focus();
	return false;
	}
}

if (document.form.Yname.value==""){
Caution=Caution+"\n"+"- Your Name";
a=1;
}
if (document.form.card_number.value==""){
Caution=Caution+"\n"+"- Card Number";
b=1;
}
if(document.form.Expiration.value==""){
Caution=Caution+"\n"+"- Expiration";
c=1;
}
if(document.form.Card_Security_Code.value==""){
Caution=Caution+"\n"+"- Card Security Code";
d=1;
}
if(document.form.phone.value==""){
Caution=Caution+"\n- Phone";
g=1;
}
if(document.form.Company_Name.value==""){
Caution=Caution+"\n"+"- Company Name";
e=1;
}
if(document.form.Email.value==""){
Caution=Caution+"\n"+"- Email";
f=1;
}
if (Caution!="Please complete the following files:"){
alert(Caution);
if (a==1){
document.form.Yname.focus();
}
else if(b==1){
document.form.card_number.focus();
}
else if(c==1){
document.form.Expiration.focus();
}
else if(d==1){
document.form.Card_Security_Code.focus();
}
else if(g==1){
document.form.phone.focus();
}
else if(e==1){
document.form.Company_Name.focus();
}
else if(f=1){
document.form.Email.focus();
}
return false;
}

//验证电话
if(document.form.phone.value!=""){
var strTel=document.form.phone.value;
var strUnit;
var x=strTel.length;
var i;
var n;
for(i=0;i<x;i++){
strUnit=strTel.substring(i,i+1);
if(isNaN(strUnit) && strUnit!="-" && strUnit!="(" && strUnit!=")" && strUnit!="_"){
alert("Phone is incorrect, please check.");
document.form.phone.focus();
return false;
break;
}
}
}
//验证邮箱
//var rule=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
var rule=/^([a-z0-9A-Z-_.]*)@([a-z0-9A-Z\-]*\.[a-z0-9A-Z\-\.]*)$/i;
if (!rule.exec(document.form.Email.value)){
alert("Incorrect email address, please recheck it.");
document.form.Email.focus();
return false;
}
}