Course = {
	request_path : "/job01/",
	submit : function( type ){
	/*	if(type=='A'){
			alert('付费报名功能即将开启，请12点过后再试');
			return false;
		}*/
		var errorInfo = "    友情提醒:\r\n";
		var errorNum = 0;

		var parent_type = $('parent_type').value.Trim();

		var stu_name = $('stu_name').value.Trim();
		if(stu_name.length < 2){
			errorInfo = String.format( "{0}\r\n{1}" , errorInfo , "学生姓名出错！" );
			errorNum ++;
		}

		var school_area = $('school_area').value.Trim();
		if( school_area.length <= 0 ){
			errorInfo = String.format( "{0}\r\n{1}" , errorInfo , "请选择学校区域！" );
			errorNum ++;
		}

		var obj_gender = document.getElementsByName('gender');
		var gender = obj_gender[0].checked == true?obj_gender[0].value:obj_gender[1].value;

		var stu_birthday = String.format( "{0}-{1}-{2}" , $('year').value.Trim(),$('month').value.Trim(),$('day').value.Trim() );
		if(stu_birthday.length < 2){
			errorInfo = String.format( "{0}\r\n{1}" , errorInfo , "学生生日出错！" );
			errorNum ++;
		}

		var stu_primary = $('stu_primary').value.Trim();
		if(stu_primary.length < 2){
			errorInfo = String.format( "{0}\r\n{1}" , errorInfo , "就读学校出错！" );
			errorNum ++;
		}
		var stu_grade = $('stu_grade').value.Trim();
		if(stu_grade.length <= 0){
			errorInfo = String.format( "{0}\r\n{1}" , errorInfo , "就读年级出错！" );
			errorNum ++;
		}
		var parent_name = $('parent_name').value.Trim();
		if(parent_name.length < 2){
			errorInfo = String.format( "{0}\r\n{1}" , errorInfo , "家长姓名出错！" );
			errorNum ++;
		}
		var parent_email = $('parent_email').value.Trim();
		if( !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test( parent_email ) ){
			errorInfo = String.format( "{0}\r\n{1}" , errorInfo , "邮件地址出错！" );
			errorNum ++;
		}
		var father_mobile = $('father_mobile').value.Trim();
		var mother_mobile = $('mother_mobile').value.Trim();
		if( !/^1[\d]{10}$/.test( father_mobile ) && !/^1[\d]{10}$/.test( mother_mobile ) ){
			errorInfo = String.format( "{0}\r\n{1}" , errorInfo , "父母手机至少输入一项！" );
			errorNum ++;
		}
		if( !/^1[\d]{10}$/.test( father_mobile ) )
			father_mobile = "";
		else if( !/^1[\d]{10}$/.test( mother_mobile ) )
			mother_mobile = "";
		var parent_zipcode = $('home_zipcode').value.Trim();
		if( !/^\d{6,}$/.test( parent_zipcode ) ){
			errorInfo = String.format( "{0}\r\n{1}" , errorInfo , "邮政编码出错！" );
			errorNum ++;
		}
		var parent_address = $('home_address').value.Trim();
		if(parent_address.length < 5){
			errorInfo = String.format( "{0}\r\n{1}" , errorInfo , "家庭地址出错！" );
			errorNum ++;
		}

		var telephone = $('telephone').value.Trim();
		
		var ver_code = $('ver_code').value.Trim();
		if(!/^\d{4}$/.test( ver_code )){
			errorInfo = String.format( "{0}\r\n{1}" , errorInfo , "请输入验证码！" );
			errorNum ++;
		}

		var messages = $('messages').value.Trim();

		if( errorNum > 0 ){
			alert(errorInfo);
			return false;
		}

		var param = String.format( "action=submit&parent_type={0}&stu_name={1}&gender={2}&stu_birthday={3}&stu_primary={4}&stu_grade={5}&stu_grade={6}&parent_name={7}&parent_email={8}&father_mobile={9}&parent_zipcode={10}&parent_address={11}&school_area={12}&telephone={13}&messages={14}&mother_mobile={15}&ver_code={16}" ,parent_type,stu_name,gender,stu_birthday,stu_primary,stu_grade,stu_grade,parent_name,parent_email,father_mobile,parent_zipcode,parent_address,school_area,telephone,messages,mother_mobile,ver_code );

		new Ajax.Request(String.format( '{0}index.php' , Course.request_path ),{
			method : 'post',
			parameters : param,
			onSuccess : function(response){
				if( /^\d+$/.test( response.responseText ) ){
					if( type == 'A' ){
						window.location.href="selectcourse.php";
					}else if( type== 'B' ){
						window.location.href="selectfree.php";
					}
				}else{
					alert(String.format("{0}\r\n{1}",'提交出错1',response.responseText));
					$('verification').src='verification.php?'+new Date().getTime();
				}
			}
		});
	},
oldsubmit : function(){
		var errorInfo = "    友情提醒:\r\n";
		var errorNum = 0;

		var parent_type = $('parent_type').value.Trim();

		var stu_name = $('stu_name').value.Trim();
		if(stu_name.length < 2){
			errorInfo = String.format( "{0}\r\n{1}" , errorInfo , "学生姓名出错！" );
			errorNum ++;
		}
		
		var parent_name = $('parent_name').value.Trim();
		if(parent_name.length < 2){
			errorInfo = String.format( "{0}\r\n{1}" , errorInfo , "家长姓名出错！" );
			errorNum ++;
		}
		
		var father_mobile = $('father_mobile').value.Trim();
		var mother_mobile = $('mother_mobile').value.Trim();
		if( !/^1[\d]{10}$/.test( father_mobile ) && !/^1[\d]{10}$/.test( mother_mobile ) ){
			errorInfo = String.format( "{0}\r\n{1}" , errorInfo , "父母手机至少输入一项！" );
			errorNum ++;
		}
		if( !/^1[\d]{10}$/.test( father_mobile ) )
			father_mobile = "";
		else if( !/^1[\d]{10}$/.test( mother_mobile ) )
			mother_mobile = "";
		
		var ver_code = $('ver_code').value.Trim();
		if(!/^\d{4}$/.test( ver_code )){
			errorInfo = String.format( "{0}\r\n{1}" , errorInfo , "请输入验证码！" );
			errorNum ++;
		}

		var messages = $('messages').value.Trim();

		if( errorNum > 0 ){
			alert(errorInfo);
			return false;
		}

		var param = String.format( "action=oldsubmit&parent_type={0}&parent_name={1}&stu_name={2}&father_mobile={3}&mother_mobile={4}&messages={5}&ver_code={6}" ,parent_type,parent_name,stu_name,father_mobile,mother_mobile,messages,ver_code );

		new Ajax.Request(String.format( '{0}oldindex.php' , "/job01/admin/" ),{
			method : 'post',
			parameters : param,
			onSuccess : function(response){
				if(/^\d+$/.test( response.responseText ) ){
						window.location.href="oldselectcourse.php";					
				}else{
					alert(String.format("{0}\r\n{1}",'提交出错2',response.responseText));
					$('verification').src='verification.php?'+new Date().getTime();
				}
			}
		});
	}
}

var init = function(){
	var year = $('year');
	var month = $('month');
	var day = $('day');
	for(i=0;i+1999<=2020;i++)
		year.options[i] = new Option( i+1999 , i+1999 );
	for(i=0;i<12;i++)
		month.options[i] = new Option( i+1 , i+1 );
	for(i=0;i<31;i++)
		day.options[i] = new Option( i+1 , i+1 );
}