// JavaScript Document
function hide_show(hide,show){
	document.getElementById(hide).style.display = 'none';
	document.getElementById(show).style.display = '';
}

function fcheck(){
	var fm = document.form;
	//return true;
	if(fm.department.value == ''){
		alert ('请选择你要提交的单位');
		fm.department.focus();
		return false;
	}
	
	if(document.getElementById('proposer_type1').checked){
		if(fTrim(fm.CI_name.value) == ''){
			alert ('请输入姓名');
			fm.CI_name.focus();
			return false;
		}
		
		if(fTrim(fm.CI_unit.value) == ''){
			alert ('请输入工作单位(居所)');
			fm.CI_unit.focus();
			return false;
		}
		
		if(document.getElementById('CI_paperName1').checked){

			if(!CheckValue(fTrim(fm.CI_paperNum.value))){
				fm.CI_paperNum.focus();
				return false;	
			}
		}
		else{
			if(fTrim(fm.CI_paperNum.value) == ''){
				alert ('请输入军官证号码');
				fm.CI_paperNum.focus();
				return false;
			}	
		}
		
		if(fTrim(fm.CI_contactPhone.value) == ''){
			alert ('请输入联系电话');
			fm.CI_contactPhone.focus();
			return false;
		}
		
		if(fTrim(fm.CI_postalcode.value) == ''){
			alert ('请输入邮政编码');
			fm.CI_postalcode.focus();
			return false;
		}
		
		if(fTrim(fm.CI_address.value) == ''){
			alert ('请输入联系地址');
			fm.CI_address.focus();
			return false;
		}
		
		if(fTrim(fm.CI_email.value) == ''){
			alert ('请输入电子邮箱');
			fm.CI_email.focus();
			return false;
		}
		else{
			if(!CheckEmail(fTrim(fm.CI_email.value))){
				fm.CI_email.focus();
				return false;	
			}	
		}
	}
	else{
		if(fTrim(fm.CO_name.value) == ''){
			alert ('请输入姓名');
			fm.CO_name.focus();
			return false;
		}
		
		if(fTrim(fm.CO_artificialPerson.value) == ''){
			alert ('请输入法人代表');
			fm.CO_artificialPerson.focus();
			return false;
		}
		
		if(fTrim(fm.CO_code.value) == ''){
			alert ('请输入组织机构代码');
			fm.CO_code.focus();
			return false;
		}
		
		if(fTrim(fm.CO_linkmanName.value) == ''){
			alert ('请输入联系人姓名');
			fm.CO_linkmanName.focus();
			return false;
		}
		
		if(fTrim(fm.CO_linkmanNamePhone.value) == ''){
			alert ('请输入联系人电话');
			fm.CO_linkmanNamePhone.focus();
			return false;
		}
		
		if(fTrim(fm.CO_postcode.value) == ''){
			alert ('请输入邮政编码');
			fm.CO_postcode.focus();
			return false;
		}
		
		if(fTrim(fm.CO_linkmanNameAddr.value) == ''){
			alert ('请输入联系地址');
			fm.CO_linkmanNameAddr.focus();
			return false;
		}
		
		if(fTrim(fm.CO_linkmanNameEmail.value) == ''){
			alert ('请输入电子邮箱');
			fm.CO_linkmanNameEmail.focus();
			return false;
		}
		else{
			if(!CheckEmail(fTrim(fm.CO_linkmanNameEmail.value))){
				fm.CO_linkmanNameEmail.focus();
				return false;	
			}	
		}
		
	}
	
	if(fTrim(fm.depict.value) == ''){
		alert ('请输入所需信息的内容描述');
		fm.depict.focus();
		return false;	
	}
	else if(fm.depict.value.length > 10000){
		alert ('所需信息的内容描述内容不能超过10000个字');
		fm.depict.focus();
		return false;	
	}
	
	if (fm.purpose.value.length>250){
		alert('所需信息的内容用途内容不能超过250个字');
		purpose.focus();
		return false;
	}
	
	if(document.getElementById('offermodel1').checked || document.getElementById('offermodel2').checked || document.getElementById('offermodel3').checked || document.getElementById('offermodel4').checked){
		
	}
	else{
		alert ('请选择所需信息的指定提供方式');
		return false;	
	}
	
	if(document.getElementById('getmodel1').checked || document.getElementById('getmodel2').checked || document.getElementById('getmodel3').checked || document.getElementById('getmodel4').checked || document.getElementById('getmodel5').checked){
		
	}
	else{
		alert ('请选择获取信息的方式');
		return false;	
	}
	
	if(confirm("是否确定提交?")){
		return true;	
	}
	else{
		return false;	
	}
	
}

function fTrim(str)
{
	return str.replace(/(^\s*)|(\s*$)/g, ""); 
}

//验证E-mail
function CheckEmail(email){
	if(email.length < 6){
		alert('E-mail格式不正确!');
		return false;	
	}

	var pattern   =/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	if(!pattern.test(email)){
		alert('E-mail格式不正确!');
		return false;
	}
	
	return true;
}

//身份证-------------------------
var yyyy;
var mm;
var dd;
var birthday;
var sex;
function getYear(){
	return yyyy;
}
function getMonth(){
	return mm;
}
function getDate(){
	return dd;
}
function getBirthday(){
	return birthday;
}
function getSex(){
	return sex;
}
function CheckValue(idCard){
	var id=idCard;
	var id_length=id.length;
	if (id=="" || id_length==0){
		alert('请输入身份证号码!');
		return false;
	}
	if (id_length!=15 && id_length!=18){
		alert('身份证号长度应为15位或18位!');
		return false;
	}
	if (id_length==15){
		yyyy="19"+id.substring(6,8);
		mm=id.substring(8,10);
		dd=id.substring(10,12);
		if(!idNumCheck(id.substring(0,15))){
			alert('输入身份证号中有非法字符!');
			return false;	
		}
		if (mm>12 || mm<=0){
			alert('输入身份证号,月份非法!');
			return false;
		}
		if (dd>31 || dd<=0){
			alert('输入身份证号,日期非法!');
			return false;
		}
		birthday=yyyy+ "-" +mm+ "-" +dd;
		if ("13579".indexOf(id.substring(14,15))!=-1){
			sex="1";
		}else{
			sex="2";
		}
	}
	else if (id_length==18){
		if(!idNumCheck(id.substring(0,17))){
			alert('输入身份证号中有非法字符!');
			return false;	
		}
		if (id.indexOf("X") > 0 && id.indexOf("X")!=17 || id.indexOf("x")>0 && id.indexOf("x")!=17){
			alert('身份证中\"X\"输入位置不正确!');
			return false;
		}
		yyyy=id.substring(6,10);
		if (yyyy>2200 || yyyy<1900){
			alert('输入身份证号,年度非法!');
			return false;
		}
		mm=id.substring(10,12);
		if (mm>12 || mm<=0){
			alert('输入身份证号,月份非法!');
			return false;
		}
		dd=id.substring(12,14);
		if (dd>31 || dd<=0){
			alert('输入身份证号,日期非法!');
			return false;
		}
		if (id.charAt(17)=="x" || id.charAt(17)=="X")
		{
			if ("x"!=GetVerifyBit(id) && "X"!=GetVerifyBit(id)){
				alert('身份证校验错误，请检查最后一位!');
				return false;
			}

		}else{
			if (id.charAt(17)!=GetVerifyBit(id)){
				alert('身份证校验错误，请检查最后一位!');
				return false;
			}
		}
	}
	return true;
}
function idNumCheck(str) {
	var i,j,strTemp;
	strTemp = "0123456789";
	if (str.length == 0) return false;
	for (i=0; i<str.length; i++) {
		j = strTemp.indexOf(str.charAt(i));
		if (j==-1) {
			return false;
		}
	}
	return true;
}

//15位转18位中,计算校验位即最后一位
function GetVerifyBit(id){
	var result;
	var nNum=eval(id.charAt(0)*7+id.charAt(1)*9+id.charAt(2)*10+id.charAt(3)*5+id.charAt(4)*8+id.charAt(5)*4+id.charAt(6)*2+id.charAt(7)*1+id.charAt(8)*6+id.charAt(9)*3+id.charAt(10)*7+id.charAt(11)*9+id.charAt(12)*10+id.charAt(13)*5+id.charAt(14)*8+id.charAt(15)*4+id.charAt(16)*2);
	nNum=nNum%11;
	switch (nNum) {
	   case 0 :
		  result="1";
		  break;
	   case 1 :
		  result="0";
		  break;
	   case 2 :
		  result="X";
		  break;
	   case 3 :
		  result="9";
		  break;
	   case 4 :
		  result="8";
		  break;
	   case 5 :
		  result="7";
		  break;
	   case 6 :
		  result="6";
		  break;
	   case 7 :
		  result="5";
		  break;
	   case 8 :
		  result="4";
		  break;
	   case 9 :
		  result="3";
		  break;
	   case 10 :
		  result="2";
		  break;
	}
	//document.write(result);
	return result;
}
//身份证-------------------------