
	var username =''; var usermail='';
	var country =''; var province='';
	var sex ='2'; var degree='';
	var occupation =''; var animals='';
	var star =''; var blood='';
	var belief =''; var idcard='';
	var phone =''; var address='';
	var age ='';
	
	function Trim(str)
	{
		if(str.charAt(0)==' ')
		{
			str=str.slice(1);
			str=Trim(str);
		}
		return str;
	}

	function viewChart()
	{
		window.open('http://view.sznews.com/nis/vote/admin/survey/multipiechart.jsp?surveyid=381','_blank','width=600,height=800,toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,status=yes');
	}

	function resetSurvey381()
	{
		document.frmSurvey381.reset();
	}

	function viewSurveyResult381()
	{
		window.open('http://view.sznews.com/nis/vote/temp/surveyresult/vote381_result.htm','_blank','width=600,height=800,toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,status=yes');
	}

	function checkSubmit381()
	{
		if(document.frmSurvey381.enp_username) 
		{
			username = document.frmSurvey381.enp_username.value;
			if(username == '' ||Trim(username)==''|| username.lenght > 20)
			{
				alert('用户名不能为空或过长！');
				return false;
			}
		}
		 if(document.frmSurvey381.enp_usermail) 
		{
			usermail = document.frmSurvey381.enp_usermail.value;
			if(usermail == '' ||Trim(usermail)==''|| usermail.lenght > 50)
			{
				alert('邮件地址不能为空或过长！');
				return false;
			}
		}
	 if(document.frmSurvey381.enp_age) 
		{
			age = document.frmSurvey381.enp_age.value;
			if (!/^[0-9]\d*$/.test(age))
			{
				alert('年龄只能为正整数！');
				return false;
			}
		}
	}

	function checksurveyMaxAnswers()
	{
		if(document.all("surveyMaxAnswers"))
		{
			var surveyMaxAnswers = document.all("surveyMaxAnswers").value ;
			var counts = 0 ;
			var items = document.all("items").value ;
			items = items.substring(0,items.lastIndexOf(','));
			var itemslist = items.split(',');
			

			for(i=0;i<itemslist.length;i++)
			{
				var obj =document.all(itemslist[i]) ;
				var len = obj.length ;
				if(len == null)
				{
					if(obj.tagName=="INPUT")
					{
						if(obj.type=="radio" || obj.type=="checkbox")
						{
		
							if(obj.checked)
							{
								counts = counts + 1 ;
							}
						}
					}
					else if(obj.tagName=="TEXTAREA")
					{
						if(Trim(obj.value)!='')
						{
							counts = counts + 1 ;
						}
					}
					else if(obj.tagName=="SELECT")
					{
						if(Trim(obj.value)!='')
						{
							counts = counts + 1 ;
						}
					}
				}
				else
				{
						if(obj[0].tagName=="INPUT")
						{
							if(obj[0].type=="radio" || obj[0].type=="checkbox")
							{
								for (j = 0; j < len; j++)
								{
									if (obj[j].checked)
									{
										counts = counts + 1 ;
										break;
									}
								}
							}
						}
						else if(obj.tagName=="SELECT")
						{
							if(Trim(obj.value)!='')
							{
								counts = counts + 1 ;
							}
						}
					}
				}
			if(counts<=surveyMaxAnswers)
			{
				return true ;
			}
			else
			{
				alert("您回答的问题超出最大答题数" + surveyMaxAnswers + ",请重新填写！") ;
				return  false ;
			}
		}
		return true ;
	}

	function checkitemMaxAnswers()
	{
		if(document.all("mulitItems"))
		{
			var mulitItems = document.all("mulitItems").value ;
			mulitItems = mulitItems.substring(0,mulitItems.lastIndexOf(','));
			var mulitItemlist = mulitItems.split(',');
			for(var i=0;i<mulitItemlist.length;i++)
			{
				var counts = 0 ;
				var itemid = mulitItemlist[i].substring(0,mulitItemlist[i].lastIndexOf('_'));
				var maxanswers =  mulitItemlist[i].substring(mulitItemlist[i].lastIndexOf('_')+1);
				var obj =document.all(itemid) ;
				var len = obj.length ;
				for (var j = 0; j < len; j++)
				{
					if (obj[j].checked)
					{
						counts = counts + 1 ;
					}
				}
				if(counts<=maxanswers)
				{
					continue ;
				}
				else
				{
					alert("您填写的某个多项选择题超出最大答题数") ;
				return false ;
				}
			}
		}
		return true ;
	}
				
	function submitSurvey381()
	{
		var checkedbox ;
		var radiobox ;
		var checkedboxvalue ='' ;
		var radioboxvalue = '';
		var askvalue = '';
		var askquestions ;
		var selection ;
		var selectvalue = '' ;
		var radioExtraValue = '' ;
		var checkExtraValue = '' ;

		if(document.frmSurvey381.enp_username)
		{ 
			username = document.frmSurvey381.enp_username.value;
		}
		if(document.frmSurvey381.enp_usermail)
		{ 
			usermail = document.frmSurvey381.enp_usermail.value;
		}
		if(document.frmSurvey381.enp_country)
		{ 
			country = document.frmSurvey381.enp_country.value;
		}
		if(document.frmSurvey381.enp_province) 
		{ 
			province = document.frmSurvey381.enp_province.value;
		}
		if(document.frmSurvey381.enp_sex)
		{ 
			sex = document.frmSurvey381.enp_sex.value;
		}
		if(document.frmSurvey381.enp_degree)
		{ 
			degree = document.frmSurvey381.enp_degree.value;
		}
		if(document.frmSurvey381.enp_occupation)
		{ 
			occupation = document.frmSurvey381.enp_occupation.value;
		}
		if(document.frmSurvey381.enp_animals)
		{ 
			animals = document.frmSurvey381.enp_animals.value;
		}
		if(document.frmSurvey381.enp_star)
		{ 
			star = document.frmSurvey381.enp_star.value;
		}
		if(document.frmSurvey381.enp_blood)
		{ 
			blood = document.frmSurvey381.enp_blood.value;
		}
		if(document.frmSurvey381.enp_belief)
		{ 
			belief = document.frmSurvey381.enp_belief.value;
		}
		if(document.frmSurvey381.enp_idcard)
		{ 
			idcard = document.frmSurvey381.enp_idcard.value;
		}
		if(document.frmSurvey381.enp_phone)
		{ 
			phone = document.frmSurvey381.enp_phone.value;
		}
		if(document.frmSurvey381.enp_address)
		{ 
			address = document.frmSurvey381.enp_address.value;
		}
		if(checkSubmit381()==false)
		{
			return;
		}
		if(checkitemMaxAnswers()==false)
		{
			return;
		}
		if(checksurveyMaxAnswers()==false)
		{
			return;
		}

		var isMustList = document.frmSurvey381.isMustList.value ;
		isMustList = isMustList.substring(0,isMustList.lastIndexOf(','));
		var isMust = isMustList.split(',');
		if(Trim(isMustList)!='')
		{
			for(i=0;i<isMust.length;i++)
			{
				var isMake = false ;
				var objName =isMust[i] ;
				var obj =  document.all(objName) ;
				var len = obj.length;
				if(len == null)
				{
					if(obj.tagName=="INPUT")
					{
						if(obj.type=="radio")
						{
							if(!obj.checked)
							{
								alert('有必选的单选题没有选择!');
								return;
							}
						}
						else if(obj.type=="checkbox")
						{
							if(!obj.checked)
							{
								alert('有必选的多选题没有选择!');return;
							}
						}
					}
					else if(obj.tagName=="TEXTAREA")
					{
						if(Trim(obj.value)=='')
						{
							alert('有必填的问答题没有填写!');
							return;
						}
					}
					else if(obj.tagName=="SELECT")
					{
						if(Trim(obj.value)=='')
						{
							alert('有必选的下拉框选择题没有选择!');
							return;
						}
					}
				}
				else
				{
					var qq = 0 ;
					for(k = 0 ; k < len ; k++)
					{
						if (obj[k].id == objName)
						{
							qq = k+1 ;
							break ;
						}
					}
					if(obj[qq].tagName=="INPUT")
					{
						if(obj[qq].type=="radio")
						{
							for (j = 0; j < len; j++)
							{
								if (obj[j].checked)
								{
									isMake = true ;
									break;
								}
							}
							if(!isMake)
							{
								alert('有必选的单选题没有选择!');
								return ;
							}
						}
						else if(obj[qq].type=="checkbox")
						{
							for (j = 0; j < len; j++)
							{
								if (obj[j].checked)
								{
									isMake = true ;
									break;
								}
							}
							if(!isMake)
							{
								alert('有必选的多选题没有选择!');
								return ;
							}
						}
					}
					else if(obj[qq].tagName=="SELECT")
					{
						if(Trim(obj[qq].value)=='')
						{
							alert('有必选的下拉框选择题没有选择!');
							return;
						}
					}
				}
			}
		}

		askstring = document.frmSurvey381.askString.value;
		askstring = askstring.substring(0,askstring.lastIndexOf(','));  
		askquestions = askstring.split(','); 
		if(Trim(askstring)!='')
		{
			for(i=0;i<askquestions.length;i++)
			{
				textname = askquestions[i];
				answerarea = document.getElementById(textname);
				if(Trim(answerarea.value)=='')
					answerarea.value = '未填写' ;
				askvalue = askvalue+'#**#'+answerarea.value;
			}
			askvalue = askvalue.substring(4);
		}

		radiostring = document.frmSurvey381.radioString.value;
		radiostring = radiostring.substring(0,radiostring.lastIndexOf(','));  
		radiobox = radiostring.split(','); 
		if(Trim(radiostring)!='')
		{
			for(i=0;i<radiobox.length;i++)
			{
				radioname = radiobox[i];
				radio = document.getElementById(radioname);
				if(radio.checked)
				{
					extraid = 'remark'+radio.value;
					extravalue = 'null' ;
					if(document.all(extraid))
					{
						if(Trim(document.all(extraid).value)!='')
						{
							extravalue=document.all(extraid).value;
						}
						radioExtraValue =radioExtraValue+'##**'+extravalue; 
					}
					else
					{
						radioExtraValue =radioExtraValue+'##**'+'null';
					}
					radioboxvalue =radioboxvalue+','+radio.value  ; 
				}
			}
			radioboxvalue = radioboxvalue.substring(1);
			radioExtraValue = radioExtraValue.substring(4);
		}

		selectstring = document.frmSurvey381.selectString.value;
		selectstring = selectstring.substring(0,selectstring.lastIndexOf(','));  
		selection = selectstring.split(','); 
		if(Trim(selectstring)!='')
		{
			for(i=0;i<selection.length;i++)
			{
				selectname = selection[i];
				var select = document.getElementById(selectname);
				if(Trim(select.value)!='')
				{
					selectvalue =selectvalue+','+select.value  ; 
				}
			}
			selectvalue = selectvalue.substring(1);
		}

		checkBoxString = document.frmSurvey381.checkBoxString.value;
		checkBoxString = checkBoxString.substring(0,checkBoxString.lastIndexOf(','));
		checkedbox = checkBoxString.split(',');
		if(Trim(checkBoxString)!='')
		{
			for(i=0;i<checkedbox.length;i++)
			{
				checkname = checkedbox[i]; 
				if(document.getElementById(checkedbox[i]).checked)
				{
					extraid = 'remark'+document.all(checkedbox[i]).value;
					extravalue = 'null' ;
					if(document.all(extraid))
					{
						if(Trim(document.all(extraid).value)!='')
						{
							extravalue = document.all(extraid).value;
						}
						checkExtraValue =checkExtraValue+'##**'+extravalue; 
					}
					else
					{
						checkExtraValue =checkExtraValue+'##**'+'null';
					}
					checkedboxvalue = checkedboxvalue+','+document.getElementById(checkedbox[i]).value  ;  
				}
				else
				{
					continue;
				}
			}
			checkedboxvalue = checkedboxvalue.substring(1);
			checkExtraValue = checkExtraValue.substring(4);
		}

		document.frmSurvey381.askValue.value=escape(askvalue);
		document.frmSurvey381.radioValue.value=radioboxvalue;
		document.frmSurvey381.checkBoxValue.value=checkedboxvalue;
		document.frmSurvey381.selectValue.value=selectvalue;
		document.frmSurvey381.radioRemarkValue.value=escape(radioExtraValue);
		document.frmSurvey381.checkRemarkValue.value=escape(checkExtraValue);
		document.frmSurvey381.openfeatures381.value='width=600,height=800,toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,status=yes';

		window.open('','vote_server','width=600,height=800,toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,status=yes');
		frmSurvey381.submit();
	}
