﻿var transObj = {radio:0.0,perhour:0.0,perprice:0.0,hours:0.0,subject_ratio:0.0,words:0};
var dateTime = {date:"",hour:" 12:00:00"};
var transLanguage = {source:"",target:""};
var transLevel ={level:0};
var file_index=1;
var delfile_index=0;
var hasfile=0;
var trans_lang=1;
var trans_type = 0;
var init_itemOfnum = 0;
var init_price = 0.00;
var jsonArray= {  
  "languagelist":[{'English_to_Chinese':'english-->chinese','Chinese_to_English':'chinese-->english'},
				  {'English_to_Chinese':'英文-->中文','Chinese_to_English':'中文-->英文'}],
  "fieldlist":[{'unknown':'一般(专业术语少)','zhengshu':' 证书/文凭/执照/简历 ','jinrong':' 金融/保险/证券 ','shangmao':' 商贸 ','falv':' 法律 ',
			    'xinwen':' News ','zongjiao':' 宗教 ','shichang':' 市场营销 ','wenxue':' 文学 ','yishu':' 艺术 ','tiyu':' 体育/文化 ',
				'dianzi':' 电子 ','jiaotong':' 交通 ','it':' IT/通信 ','huagong':' 化工 ','jianzhu':' 建筑/建材 ','nengyuan':' 能源 ', 
				'huanbao':' 环保 ','yejin':' 矿产/冶金 ','cailiao':' 材料 ','wuliu':' 物流/运输 ','hangkong':' 航空/航天 ','guofang':' 国防 ',
				'fangzhi':' 纺织 ','yinshua':' 印刷 ','nongmu':' 农牧 ', 'yixue':' 医学/医疗 ','dili':' 地理 ','shuxue':' 数学/统计学 ',
				'shengwu':' 生物 ','kaogu':' 考古学 ', 'gongcheng':'机械工程', 'qita':' 其他等 '	
			   },
			   {'unknown':'一般(专业术语少)','zhengshu':' 证书/文凭/执照/简历 ','jinrong':' 金融/保险/证券 ','shangmao':' 商贸 ','falv':' 法律 ',
				'xinwen':' 新闻 ','zongjiao':' 宗教 ','shichang':' 市场营销 ','wenxue':' 文学 ','yishu':' 艺术 ','tiyu':' 体育/文化 ',
				'dianzi':' 电子 ','jiaotong':' 交通 ','it':' IT/通信 ','huagong':' 化工 ','jianzhu':' 建筑/建材 ','nengyuan':' 能源 ', 
				'huanbao':' 环保 ','yejin':' 矿产/冶金 ','cailiao':' 材料 ','wuliu':' 物流/运输 ','hangkong':' 航空/航天 ','guofang':' 国防 ',
				'fangzhi':' 纺织 ','yinshua':' 印刷 ','nongmu':' 农牧 ', 'yixue':' 医学/医疗 ','dili':' 地理 ','shuxue':' 数学/统计学 ',
				'shengwu':' 生物 ','kaogu':' 考古学 ', 'gongcheng':'机械工程', 'qita':' 其他等 '	
			  }],
  "alertObj":[{
			 language:"请选择翻译语言!",
			 num:"请输入数字!",
			 file:"请选择文件后,再添加其他文件!",
			 filetype:"请选择文件类型!",
			 fieldtype:"请选择行业类型!",
			 smallContent:"请输入稿件的内容!",
			 isfile:"请选择上传的文件!",
			 transTime:"请输入交稿时间",
			 selectTime:"请选择大于当前日期的时间!",
			 commentNote:"您可以输入对稿件翻译的要求或者注意事项,甚至是上传一段参考文件,以便获得更好的翻译质量.",
			 nothingHappend:"请先填写必填选项!",	
			 priceWait:"等待报价",
			 languageNotice:"稿件内容输入有误,请重新确认!",
			 contactPhone1:"请填写联系电话，以便沟通稿件相关问题！",
			 contactPhone2:"请输入正确的手机号码或电话号码",
			 contactPhone3:"您提供的电话号码看起来有点短！",
			 contactPhone4:"您提供的电话号码看起来有点长！"							
			 },{
			 language:"请选择翻译语言!",
		     num:"请输入数字!",
			 file:"请选择文件后,再添加其他文件!",
			 filetype:"请选择文件类型!",
			 fieldtype:"请选择行业类型!",
			 smallContent:"请输入稿件的内容!",
			 isfile:"请选择上传的文件!",
			 transTime:"请输入交稿时间",
			 selectTime:"请选择大于当前日期的时间!",
			 commentNote:"您可以输入对稿件翻译的要求或者注意事项,甚至是上传一段参考文件,以便获得更好的翻译质量.",
			 nothingHappend:"请先填写必填选项!",
			 priceWait:"等待报价",
			 languageNotice:"稿件内容输入有误,请重新确认!",	
			 contactPhone1:"请填写联系电话，以便沟通稿件相关问题！",
			 contactPhone2:"请输入正确的手机号码或电话号码",
			 contactPhone3:"您提供的电话号码看起来有点短！",
			 contactPhone4:"您提供的电话号码看起来有点长！"
			 }],
  "transNote":[{smalltrans:"正在提交稿件数据,请稍候......",
  				bigtrans:"正在提交稿件数据,请稍候......"},
			   {smalltrans:"正在提交稿件数据,请稍候......",
			    bigtrans:"正在提交稿件数据,请稍候......"}],
  "transLevelObj":[{standard:"标准级",
  					expert:"专家级"},
  				   {standard:"标准级",
  				    expert:"专家级"}],
  "priceNoteObj":[{preNote:"",afterNote:"元"},{preNote:"",afterNote:"元"}],
  "referenceNote":[{note:"您可以输入对稿件翻译的要求或者注意事项,甚至是上传一段参考文件,以便获得更好的翻译质量."},{note:"您可以输入对稿件翻译的要求或者注意事项,甚至是上传一段参考文件,以便获得更好的翻译质量."}]
}	
var wordsFlag=true;
var feeObj=0.0;
var commentFlag = false;
var init_price = 0.00;
var init_itemOfnum = 0;

$(document).ready(function(){
	  var langinput=$("#langinput");
	  var langinputOffset=langinput.offset();
	  var subject=$("#subjectinput");
	  var subjectOffset=subject.offset();
	  
	  var smallcontent = $("#content");
	  
	  smallcontent.click(function(){
		  $.textCounter();
	  }).change(function(){
		  $.textCounter();
	  }).keydown(function(){
		  $.textCounter();
	  }).keyup(function(){
		  $.textCounter();
	  })
	  
		$("#search").click(function(){
					$("#alitransForm").attr("action","http://service.suiniyi.com/search.jsp")
					return true;
		})
	  langinput.click(function(){
		  $("#FieldDiv").css("visibility","hidden");
		  $("#LanguageDiv").css("visibility","visible").css("top",langinputOffset.top+langinput.height()+"px").css("left",langinputOffset.left+"px").width(langinput.width());
		})
		$("#Other_Language").attr("href","/html/special.html")
												.click(function(){
													 $("#LanguageDiv").css("visibility","hidden");
												});
		$.each(jsonArray["languagelist"][trans_lang],function(key,value){
				$("#"+key).click(function(){
					 langinput.val(value);
					 $("#source").val(key.substring(0,7));
					 $("#target").val(key.substring(11,18));
					 $("#LanguageDiv").css("visibility","hidden");
					 $.ajax({
						   type: "POST",
						   url: "/user/getparams.trans",
						   data: {method: "languageParam",source: key.substring(0,7), target: key.substring(11,18), token:new Date().getTime()},
						   success: function(json){
						    	$("#show_unit1").html(json.perhour);
						    	transObj.radio = json.radio;
						    	transObj.perhour = json.perhour;
						    	transObj.perprice = json.perprice;
						    	var isOk=true;
						    	$.each(transObj,function(obj,value){
						    		 if(value==0){
						    		 	  isOk = false;
						    		 		return false;
						    		 }
						    	})
						     if(isOk){
						     		$.transPrice();
						     	}
						   },
						  dataType:"json"
						}); 
					}).attr("href","javascript:void(0);");
								
		})
		subject.click(function(){
			$("#LanguageDiv").css("visibility","hidden");
			$("#FieldDiv").css("visibility","visible").css("top",subjectOffset.top+subject.height()+"px").css("left",subjectOffset.left+"px").width(subject.width());
		})
		$("#sourceLanguage").change(function(){
				 transLanguage.source=$(this).val();
				 if(transLanguage.source!='Chinese' && transLanguage.source!='PleaseChoose'){
					 $('#targetLanguage')[0].selectedIndex = 1;
					 transLanguage.target = 'Chinese';
					 if(trans_type == 1){
						 $.SmallInitPrice();
						 $.textCounter();
					 }
				 }else{
					 if(transLanguage.source==transLanguage.target){
						 transLanguage.target = '';
						 $('#targetLanguage')[0].selectedIndex = 0;
					 }
				 }
				 var isReady = true;
				 $.each(transLanguage,function(i,v){
					 if($.trim(v)==""||$.trim(v)=="PleaseChoose"){
						 isReady = false;
						 return false;
					 }
				 })
				 if(isReady){
					 $("#source").val(transLanguage.source);
					 $("#target").val(transLanguage.target);
					 $.ajax({
						   type: "POST",
						   url: "/user/getparams.trans",
						   data: {method: "languageParam",source: transLanguage.source, target: transLanguage.target, token:new Date().getTime()},
						   success: function(json){
						    	$("#show_unit1").html(json.perhour);
						    	transObj.radio = json.radio;
						    	transObj.perhour = json.perhour;
						    	transObj.perprice = json.perprice;
						    	var isOk=true;
						    	$.each(transObj,function(obj,value){
						    		 if(value==0){
						    		 	  isOk = false;
						    		 		return false;
						    		 }
						    	})
						    	if(isOk){
						    		$.transPrice();
							    }
						   },
						   dataType:"json"
					 }); 
				}
				 
		})
		$("#targetLanguage").change(function(){
				 transLanguage.target=$(this).val();
				 if(transLanguage.target!='Chinese'&& transLanguage.target!='PleaseChoose'){
				 			transLanguage.source = 'Chinese';
				 			$('#sourceLanguage')[0].selectedIndex = 1;
				 			if(trans_type == 1){
								 $.SmallInitPrice();
								 $.textCounter();
							}
				 }else{
				 		 if(transLanguage.target==transLanguage.source){
				 		 	  transLanguage.source = '';
				 		 		$('#sourceLanguage')[0].selectedIndex = 0;
				 		 }
				 }				 
				 var isReady = true;
				 $.each(transLanguage,function(i,v){
				 			//alert(v);
					 		if($.trim(v)==""||$.trim(v)=="PleaseChoose"){
					 				isReady = false;
					 				return false;	
					 		}
				 })	
				 	if(isReady){
						 $("#source").val(transLanguage.source);
						 $("#target").val(transLanguage.target);
						 $.ajax({
							   type: "POST",
							   url: "/user/getparams.trans",
							   data: {method: "languageParam",source: transLanguage.source, target: transLanguage.target, token:new Date().getTime()},
							   success: function(json){
							    	$("#show_unit1").html(json.perhour);
							    	transObj.radio = json.radio;
							    	transObj.perhour = json.perhour;
							    	transObj.perprice = json.perprice;
							    	var isOk=true;
							    	$.each(transObj,function(obj,value){
							    		 if(value==0){
							    		 	  isOk = false;
							    		 		return false;
							    		 }
							    	})
							     if(isOk){
							     		$.transPrice();
							     	}
							   },
							  dataType:"json"
							}); 
					}				 	
		})
		$.each([0,1],function(key,value){
				$("#tb_close_"+key).click(function(){
				$("#FieldDiv").css("visibility","hidden");
				$("#LanguageDiv").css("visibility","hidden");		
			}).attr("href","javascript:void(0);");
		})		
			
		$.each(jsonArray["fieldlist"][trans_lang],function(key,value){
			$("#"+key).click(function(){
		 		$("#subjectinput").val(value);
		 		$("#subject").val(key);
				$("#show_contenttype").html(value);
				$("#show_contenttype1").html(value);
		 	  	$("#contentType").val(key);
		 	  	$("#FieldDiv").css("visibility","hidden");
 	  			$.ajax({
					type: "POST",
					url: "/user/getparams.trans",
					data: {method: "subjectParam",subject:key, token:new Date().getTime()},
					success: function(json){
				    	transObj.subject_ratio = json.subject;
				    	var isOk = true;
				    	$.each(transObj,function(obj,value){
				    		 if(value==0){
				    		 	isOk = false;
				    		 	return isOk;
				    		 }
				    	})
				    	if(isOk){
				     		$.transPrice();
						}
						
						$("#p_show_numoffile").show();
						$("#p_show_level").show();
						$("#tr_0").hide();
						$([1,2,3,4,5,6]).each(function(i){
							i++;
							$("#tr_"+i).show();
						})
						trans_type = 0;
				  	},
				  	dataType:"json"
				}); 
			}).attr("href","javascript:void(0);");
		})
		//$.tabs("container");
		$("#filetype0").click(function(){
			
			if($("#source").val()=="" && $("#target").val()==""){
				$.languagePrice();
				if($("#source").val()=="" && $("#target").val()==""){
					alert(jsonArray["alertObj"][trans_lang].language);
					$("#filetype3").checked = true;
					document.getElementById("filetype3").style.checked=true;
				  	return false;	
				}
			}
			if($("#contentType").val()==""&& $("#subject").val()==""){
				alert(jsonArray["alertObj"][trans_lang].fieldtype);
				$("#filetype3").checked = true;
				document.getElementById("filetype3").style.checked=true;
			  	return false;
			}
			
				$("#tr_0").show();
				$("#tr_1").hide();
				$("#tr_2").hide();
				$("#tr_3").hide();	
				$("#tr_4").hide();
				$("#tr_5").hide();
				$("#tr_6").show();		
				$("#p_show_numoffile").hide();	
				$("#p_show_level").hide();	
				$("#p_show_note").hide();	
				
				$.SmallInitPrice();
				trans_type = 1;
				
		})
		$("#filetype1").click(function(){
			
			
			if(transLanguage.source=="" && transLanguage.target==""){
				$.languagePrice();
				if(transLanguage.source=="" && transLanguage.target==""){
					alert(jsonArray["alertObj"][trans_lang].language);
					$("#filetype3").checked = true;
					document.getElementById("filetype3").style.checked=true;
				  	return false;	
				}
			}
			
			if($("#contentType").val()==""&& $("#subject").val()==""){
				alert(jsonArray["alertObj"][trans_lang].fieldtype);
				$("#filetype3").checked = true;
				document.getElementById("filetype3").style.checked=true;
			  	return false;
			}
				$("#p_show_numoffile").show();
				$("#p_show_level").show();		
				$("#tr_0").hide();
				$([1,2,3,4,5,6]).each(function(i){
					  i++;
					  	$("#tr_"+i).show();
				})
			trans_type = 0;

		})
		$("#reference").click(function(){
			//alert($("#filetype3").val());
			if($("#source").val()=="" && $("#target").val()==""){
				alert(jsonArray["alertObj"][trans_lang].nothingHappend);
			  	return false;	
			}
			if($("#contentType").val()==""&& $("#subject").val()==""){
				alert(jsonArray["alertObj"][trans_lang].nothingHappend);
			  	return false;
			}
			 $.each([0,1,2],function(index){
			 		 $("#referenceFile_"+index).toggle();
			 	})	
		})
		$("#filewords").keyup(function(event){
			$("#transsubmit").attr("disabled","true");
			var myEvent = event || window.event;
			var keyCode = myEvent.keyCode;
			//alert(keyCode);
			if(keyCode>=48&&keyCode<=57 ||keyCode==8 || keyCode==46 || keyCode>=37&&keyCode<=40){
				if(transObj.perhour==0){
					alert(jsonArray["alertObj"][trans_lang].language);	
					return false;
				}
				$("#show_numofwords").html($(this).val());
				transObj.words=$(this).val();
				var isOk = true;
	 	  		
			    if(isOk){
			    
			    
			     	$.transPrice();
				}
				return true;
			}
		}).change(function(){
		
				$("#transsubmit").attr("disabled","true");
				$("#show_numofwords").html($(this).val());
				transObj.words=$(this).val();
				var isOk = true;
 	  			$.ajax({
				   type: "POST",
				   url: "/user/getparams.trans",
				   data: {method: "systemHoursParam",words:transObj.words,perhour:transObj.perhour, token:new Date().getTime()},
				   success: function(json){
							$("#show_posttime").html(json.date);
							$("#show_hour").html(json.hour);
							$("#dateString").val(json.date);
							$("#timeLimit").val(json.date+" "+json.hour);
							$('#timeLimithour')[0].selectedIndex = (json.hour).substring(0,3);
							transObj.hours = json.hours;
							
				    	dateTime.date = json.date;
				    	dateTime.hour = json.hour;
   	
				    	var isOk = true;
				    	$.each(transObj,function(obj,value){
				    		 if(value==0){
				    		 	  isOk = false;
				    		 		return isOk;
				    		 }
				    	})
				     if(isOk){
				     		$.transPrice();
							}
				   },
				  dataType:"json"
				});
	    	$.each(transObj,function(obj,value){
		    		 if(value==0){
		    		 		isOk = false;
								return false;
		    		 }
		    	})
		     if(isOk){
		     	$.transPrice();
				 	}										
				
		})
		$("#examine").click(function(){
			 if($(this).val()==0){
			 			$(this).val(1);
			 			transLevel.level = 1;
			 		  $("#show_level").html(jsonArray["transLevelObj"][trans_lang].expert);
			 }else{
			 			$(this).val(0);
			 			transLevel.level = 0;
			 			$("#show_level").html(jsonArray["transLevelObj"][trans_lang].standard);
			 }
			 var isOk = true;
		   $.each(transObj,function(obj,value){
	    		 if(value==0){
	    		 		isOk = false;
						return false;
	    		 }
	    	})
	     if(isOk){
	     	//$.transPrice();
	     	if(transLevel.level==1){
		   		feeObj=feeObj*2  ;
				}else if(transLevel.level==0){
					feeObj=feeObj/2  ;
				}
				if(wordsFlag){
					$("#show_unit2").html(jsonArray["priceNoteObj"][trans_lang].preNote+feeObj+jsonArray["priceNoteObj"][trans_lang].afterNote); 	
				}else{
					$("#show_unit2").html(jsonArray["alertObj"][trans_lang].priceWait);
				}		
				$("#quoteMoney").val(feeObj); 
				feeObj = feeObj;
			 	}		
		})
		$("#anchordateString").click(function(){
				caldateString.select(document.alitransForm.dateString,'anchordateString','yyyy-MM-dd'); 
				//alert("transObj.hours:"+transObj.hours+"   date:"+$("#dateString").val()+" "+$("#timeLimithour").val()+":00:00");
				return false
		})
		
		
		$("#timeLimithour").change(function(){
			  var timeLimithour=$("select[@name=timeLimithour] option[@selected]").text();
				dateTime.hour = timeLimithour+":00:00";
				$("#show_hour").html(dateTime.hour);
				$.SetupPrice();
				//$.getHours();
				
		})
		
		$("#appendFile").attr("href","javascript:void(0);").click(function(){
			if(file_index>=5) return false;
			
			var isfile=$("#projectFile"+file_index).val();
			if(!isfile){
					alert(jsonArray["alertObj"][trans_lang].file);
					return false;	
			}
			
			$("#show_numoffile").html(file_index);
			$("#show_note").html(file_index);
			file_index++;			
			var fileUpLoadbutton = document.createElement("input"); 
		    fileUpLoadbutton.setAttribute("type","file");
		    fileUpLoadbutton.setAttribute("name","projectFile"+file_index);
		    fileUpLoadbutton.setAttribute("id","projectFile"+file_index);
		    fileUpLoadbutton.setAttribute("onchange","javascript:$.addFileNum();");
			
			$("#hrefchiose").append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='file' id='projectFile"+file_index+"' onchange='javascript:$.addFileNum();' name='projectFile"+file_index+"' /><a id='delFile"+file_index+"' href='javascript:void(0);' onclick='javascript:$.delFile("+file_index+")'>删除</a>").append("<br id='br"+file_index+"'/>");
		   // document.getElementById("hrefchiose").appendChild(fileUpLoadbutton).appendChild("<a id='delFile"+file_index+"' href='javascript:void(0);' onclick='javascript:$.delFile("+file_index+")'>删除</a>").appendChild("<br id='br"+file_index+"'/>");
			//alert($("#hrefchiose").html());
		})
		$("#projectFile1").change(function(){
				if(hasfile==0){
						$("#show_numoffile").html(file_index);
						$("#show_note").html(file_index);
				}
				hasfile = 1;
		})
		
		$("#projectRequire").blur(function(){
			if($(this).val()==""){
				$(this).val($(this).defaultValue);
			}
		}).click(function(){
					return $.Setempty();
			})
		
		
		
		$("#transsubmit").click(function(){
			var contactPhone = $("#contactPhone").val();
		 	if($("#source").val()=="" && $("#target").val()==""){
			  	alert(jsonArray["alertObj"][trans_lang].language);
			  	return false;	
			}
			if($("#contentType").val()==""&& $("#subject").val()==""){
				alert(jsonArray["alertObj"][trans_lang].fieldtype);
				return false;
			}
			if($("#contactPhone").val()==""){
				alert(jsonArray["alertObj"][trans_lang].contactPhone1);
				return false;
			}
			if(wordsFlag){
				if($("#filewords").val()==""){
					alert(jsonArray["alertObj"][trans_lang].num);
					return false;	
				}
			}
						
			var str =  /^[^*.&@#$%^!~`{}?<>,:+=\/]+$/;
			if(!str.test($("#contactPhone").val())){
				alert(jsonArray["alertObj"][trans_lang].contactPhone2); 
				return false;
			}
			
			for(i=0;i<$("#contactPhone").val().length;i++){
				if ($("#contactPhone").val().length < 6){   
					alert(jsonArray["alertObj"][trans_lang].contactPhone3);    
		        	return false;   
				}   
			}
			if ($("#contactPhone").val().length > 20 ){   
				alert(jsonArray["alertObj"][trans_lang].contactPhone4);   
			    return false;   
			}   
			      
			if(!commentFlag){
				$("#projectRequire").val("");
			}
			if($("#projectFile1").val()==""){
				alert(jsonArray["alertObj"][trans_lang].isfile);
				return false;	
			}
			if($("#dateString").val()=="yyyy/mm/dd"||$("#dateString").val()==""){
				alert(jsonArray["alertObj"][trans_lang].transTime);
				return false;	
			}
			Loading(jsonArray["transNote"][trans_lang].bigtrans);
			$("#alitransForm").attr("action","/user/proof.trans");
			if(wordsFlag){
				$("#numOfword").val($("#filewords").val());
				$("#method").val("transPost");
			}else{
				$("#method").val("save");
			}
			
			return true;
		})
		
})

$.Setempty = function(){
	//alert(commentFlag);
	if($("#projectRequire").val()==jsonArray["alertObj"][trans_lang].commentNote)
	  $("#projectRequire").val("").focus();
	  commentFlag = true;
}
$.addFileNum = function(){
	$("#show_numoffile").html(file_index);
	$("#show_note").html(file_index);
}

$.delFile = function(index){
	$("#projectFile"+index).remove();
	$("#delFile"+index).remove();
	$("#br"+index).remove();
	file_index--;
	$("#show_numoffile").html(file_index);
	$("#show_note").html(file_index);
}
$.getHours = function(){
		var isTime = true;
		$.each(dateTime,function(i,v){
			//alert(v);
			if($.trim(v)==""){
				isTime = false;
				return false;	
			}
		})	
		if(isTime){
				$("#timeLimit").val(dateTime.date+" "+dateTime.hour);
				//alert($("#timeLimit").val());
				if(transObj.perhour!=0 && transObj.words!=0){
	 	  		$.ajax({
					   type: "POST",
					   url: "/user/getparams.trans",
					   data: {method: "customeHoursParam",datetime:encodeURI(dateTime.date+" "+dateTime.hour),radio:transObj.radio,perhour:transObj.perhour,perprice:transObj.perprice,hours:transObj.hours,subject_ratio:transObj.subject_ratio,words:transObj.words,token:new Date().getTime()},
					   success: function(json){
					   	  //alert(json.hours);
					    	transObj.hours= json.hours;
					    	var isOk = true;
					    	$.each(transObj,function(obj,value){
					    		 if(value==0){
					    		 	  isOk = false;
					    		 		return isOk;
					    		 }
					    	})
					     if(isOk){
							    //计算大单的价格
							    $.transPrice();
							 	}						    	
					   },
					  dataType:"json"
					}); 							
				}							
		}
}

$.SetupPrice = function(){

	if(!wordsFlag){
		return;
	}
	//alert($("#dateString").val()+","+$("#timeLimithour").val());
	$.ajax({
	   type: "POST",
	   url: "/user/getparams.trans",
	   data: {method: "SetupTimeParam",datetime:encodeURI($("#dateString").val()+" "+$("#timeLimithour").val()+":00:00"),radio:transObj.radio,perhour:transObj.perhour,perprice:transObj.perprice,hours:transObj.hours,subject_ratio:transObj.subject_ratio,words:transObj.words,examine:transLevel.level,token:new Date().getTime()},
	   success: function(json){
	   		//alert(json.date+","+json.hour);
				$("#show_posttime").html(json.date);
				$("#show_hour").html(json.hour+":00:00");
				$("#dateString").val(json.date);
				$("#timeLimit").val(json.date+" "+json.hour);
				$('#timeLimithour')[0].selectedIndex = (json.hour).substring(0,3);
				$("#quoteMoney").val(json.money); 
				$("#show_unit2").html(jsonArray["priceNoteObj"][trans_lang].preNote+json.money+jsonArray["priceNoteObj"][trans_lang].afterNote); 
				//transObj.hours = json.hour;
				$("#transsubmit").attr("disabled","");
				feeObj = json.money;
	    	//dateTime.date = $("#dateString").val();
	    	//dateTime.hour = $("#timeLimithour").val()+":00:00";				
	    	dateTime.date = json.date;
	    	dateTime.hour = json.hour;
				    	
	   },
	  dataType:"json"
	});
	return;
}

$.SmallInitPrice = function () {
	transLanguage.source=$("#sourceLanguage").val();
	transLanguage.target=$("#targetLanguage").val();
	$.ajax({
		   type: "POST",
		   url: "/user/getparams.trans",
		   data: {method: "SmallInitParam",source:transLanguage.source, target:transLanguage.target, C:"0", M:"getInitvar", U:""},
		   success: function(json){
			   init_price = json.Price;
			   init_itemOfnum = json.itemNum;
		   },
		   dataType:"json"
	});
	return;
}

$.textCounter = function () {
	
	trans_type = 1;
	var strTemp = "";
	var reg = "";
	var osel1 = $("#sourceLanguage").val();
	ajax_type =1;
	if(osel1=='Chinese'){
		reg=/[一-龥]/g;
	}else if(osel1!='Japanese'&& osel1!='Korea' && osel1!='Chinese'){
		reg=/[\S　]+/g;
	}else if(osel1=='Japanese'){
		//reg=/[ࠀ-一]/g;
		reg=/[一-龥 | ぁ-ㄯ]/g
	}else if(osel1=='Korea'){
		//reg=/[ࠀ-一]/g;
		reg=/[가-힣]/g
	}//else{
		//reg=/[(.|,|"|?|!|:)]/;
		//reg = "~!@#$%^&*()_+|`-=\{}[]:\";\<>?,./";
	//}
	
	var strCharCounter0 = 0;
	if($("#content").val().length>0){
		var str=$("#content").val();
		strCharCounter0=$.getlength(str.match(reg));
	}else{
		strCharCounter0=0;
	}
	
	if(init_itemOfnum==0 || init_price==0.00){
		$.SmallInitPrice();
	}
	
	//alert("strCharCounter0="+strCharCounter0+"   init_itemOfnum="+init_itemOfnum+"   init_price="+init_price);
	$("#numOfword").val(strCharCounter0);
	
	var numitem = 0;
	
	if(strCharCounter0!=0 && init_itemOfnum!=0 && strCharCounter0%init_itemOfnum == 0){
		try{
			numitem = strCharCounter0/init_itemOfnum;
		}catch(e){
			numitem = 0;
		}
		//alert("1"+numitem);
	} else {
		try{
			if(strCharCounter0!=0 && init_itemOfnum!=0){
				numitem = strCharCounter0/init_itemOfnum + 1;
				numitem = numitem.toString().split(".")[0];
			}else{
				numitem = 0;
			}
		}catch(e){
			numitem = 0;
		}
		//alert("2"+numitem);
	}
	
	if(strCharCounter0 >= 800){
		ratio = 0.9;
	}else{
		ratio = 1;
	}
	
	
	//$("#numofitem").val(numitem);
	//alert(numitem*init_price*ratio);
	var allPrice = numitem*init_price*ratio;
	//alert("allPrice:"+allPrice);
	$("#allPrice").html(allPrice.toFixed(2));
	$("#money").val(allPrice.toFixed(2));
	
	var dd = new Date();
	var bb;
	bb = $.isWork(dd);
	//alert(bb);
	if(numitem<=0) numitem=1;
  	var dd1 = bb.dateAfterDays(numitem*60);
	//var dd2 = DateUtil.dateAfterMins(numitem*30);
  	var dd3 = DateUtil.Format("yyyy/MM/dd hh:mm:00",dd1);
  	
  	$("#quoteTime").html(dd3);
	//document.getElementById("show_posttime").innerHTML= dd3;
  	return;
}

$.languagePrice = function(){
	transLanguage.source=$("#sourceLanguage").val();
	transLanguage.target=$("#targetLanguage").val();
	//alert("source:"+transLanguage.source+" target:"+ transLanguage.target);
	if(transLanguage.source=='' || transLanguage.target=='' || transLanguage.source=='PleaseChoose' || transLanguage.target=='PleaseChoose' ){
		$('#sourceLanguage')[0].selectedIndex = 0;
		$('#targetLanguage')[0].selectedIndex = 0;
		//alert(jsonArray["alertObj"][trans_lang].language);
		return false;
	}else if(transLanguage.target==transLanguage.source){
		$('#sourceLanguage')[0].selectedIndex = 0;
		$('#targetLanguage')[0].selectedIndex = 0;
		//alert(language["translate"][lang][0]);
		return false;
	}else if(transLanguage.source=='Chinese' || transLanguage.target=='Chinese'){
		var isReady = true;
		/*
		$.each(transLanguage,function(i,v){
			if($.trim(v)==""||$.trim(v)=="PleaseChoose"){
				isReady = false;
				return false;
			}
		})	
		*/
		if(isReady){
			$("#source").val(transLanguage.source);
			$("#target").val(transLanguage.target);
			$.ajax({
				type: "POST",
				url: "/user/getparams.trans",
				data: {method: "languageParam",source: transLanguage.source, target: transLanguage.target, token:new Date().getTime()},
				success: function(json){
					$("#show_unit1").html(json.perhour);
					transObj.radio = json.radio;
					transObj.perhour = json.perhour;
					transObj.perprice = json.perprice;
					/*
					var isOk=true;
					$.each(transObj,function(obj,value){
						if(value==0){
							isOk = false;
							return false;
						}
					})
					*/
					return true;
					//if(isOk){
					//	$.transPrice();
					//}
				},
				dataType:"json"
			}); 
		}
	}else{
		$('#sourceLanguage')[0].selectedIndex = 0;
		$('#targetLanguage')[0].selectedIndex = 0;
		//alert(language["translate"][lang][1]);
		return false;
	}	
}

$.transPrice=function(){
	//$.each(transObj,function(i,v){
	//	alert(v);
	//})
	try{  
	 		$.ajax({
		   type: "POST",
		   url: "/user/getparams.trans",
		   data: {method: "priceParam",radio:transObj.radio,perhour:transObj.perhour,perprice:transObj.perprice,hours:transObj.hours,subject_ratio:transObj.subject_ratio,words:transObj.words,token:new Date().getTime(),init_itemOfnum:init_itemOfnum, init_price:init_price, transtype:"proof",M:"getInitvar",source:transLanguage.source, target:transLanguage.target, U:$("#subject").val(), examine:transLevel.level},
		   
		   success: function(json){
			   		var money = json.money;
		   			if(transLevel.level==1){
		   				  money=money*2  ;
						}
						$("#show_unit2").html(jsonArray["priceNoteObj"][trans_lang].preNote+money+jsonArray["priceNoteObj"][trans_lang].afterNote); 	
						$("#quoteMoney").val(money); 
						//alert($("#quoteMoney").val());
						$("#transsubmit").attr("disabled","");
						feeObj = money;
						
						$("#show_posttime").html(json.date);
							$("#show_hour").html(json.hour);
							$("#dateString").val(json.date);
							$("#timeLimit").val(json.date+" "+json.hour);
							$('#timeLimithour')[0].selectedIndex = (json.hour).substring(0,3);
							transObj.hours = json.hours;
							
				    	dateTime.date = json.date;
				    	dateTime.hour = json.hour;
		   },
		  dataType:"json"
		}); 					
	}catch(err){  
	  alert(err.description);
	  money=0;  
	}  
}
$.Yetii= function() {

	this.defaults = {
		id: null,
		active: 1,
		timeout: null,
		interval: null,
		tabclass: 'tab_1',
		activeclass: 'active'
	};
	
	for (var n in arguments[0]) { this.defaults[n]=arguments[0][n]; };	

	this.getTabs = function() {
        var retnode = [];
        var elem = document.getElementById(this.defaults.id).getElementsByTagName('*');
				var regexp = new RegExp("(^|\\s)" + this.defaults.tabclass.replace(/\-/g, "\\-") + "(\\s|$)");
        for (var i = 0; i < elem.length; i++) {
        	 //alert(elem[i].value);
     		   if (regexp.test(elem[i].className)) retnode.push(elem[i]);
        }
        return retnode;
    };
	this.links = document.getElementById(this.defaults.id + '-nav').getElementsByTagName('a');
	this.show = function(number){
				wordsFlag = number == 1?true:false;
        for (var i = 0; i < this.tabs.length; i++) {
	        this.tabs[i].style.display = ((i+1)==number) ? 'block' : 'none';
	        this.links[i].className = ((i+1)==number) ? this.defaults.activeclass : '';
        }
    
    };
	this.rotate = function(interval){

        this.show(this.defaults.active);
        this.defaults.active++;
        if(this.defaults.active > this.tabs.length) this.defaults.active = 1;
        var self = this;
        this.defaults.timeout = setTimeout(function(){self.rotate(interval);}, interval*1000);
    
    };
	this.tabs = this.getTabs();
	this.show(this.defaults.active);
	var self = this;
	for (var i = 0; i < this.links.length; i++) {
		this.links[i].customindex = i+1;
		this.links[i].onclick = function(){ if (self.defaults.timeout) clearTimeout(self.defaults.timeout); self.show(this.customindex); return false; };
  }
	if (this.defaults.interval) this.rotate(this.defaults.interval);
	
}
$.isWork = function(datatime)  {

	  var   year=datatime.getFullYear();  
	  var   month=datatime.getMonth();  
	  var   date=datatime.getDate();  
	  var   hour=datatime.getHours();  
	  var new_hour = 0;
	  var new_date = 0;
	  var new_year = 2008;
	  var new_month= 0;
	  var new_min = 0;
	  
	  /*
	  if(datatime.getDay()==6)  
	  {  
		var uom = new Date(new Date()-0+86400000*2); 
	  	new_date = uom.getDate();
	  	new_hour = 9;
	  	new_year = uom.getFullYear();
	  	new_month = uom.getMonth();
	  	new_min = 0;
	  	var xc = new Date(new_year,new_month,new_date,new_hour,new_min,0,0);
	  	return xc;
  	  }  
	  if(datatime.getDay()==0)  
	  {  
	  	var uom = new Date(new Date()-0+86400000); 
	  	new_date = uom.getDate();
	  	new_hour = 9;
	  	new_year = uom.getFullYear();
	  	new_month = uom.getMonth();
	  	new_min = 0;
	  	var xc = new Date(new_year,new_month,new_date,new_hour,new_min,0,0);
	  	return xc;
	  }  

	  
	  if(hour < 9 && hour >=0 ){
	  	new_hour = 9;
	  	new_date = datatime.getDate();
	  	new_year = datatime.getFullYear();
	  	new_month = datatime.getMonth();
	  	new_min = 0;
	  }else if(hour >= 18){
	  	var uom = new Date(new Date()-0+86400000); 
	  	new_date = uom.getDate();
	  	new_hour = 9;
	  	new_year = uom.getFullYear();
	  	new_month = uom.getMonth();
	  	new_min = 0;
	  }else{
	  */
	  	new_hour = hour;
		new_year = year;
		new_month = month;
		new_date = date;
		new_min = datatime.getMinutes();
	  //}
	  //alert(new_year+"-"+new_month+"-"+new_date);
	  var xc = new Date(new_year,new_month,new_date,new_hour,new_min,0,0);
	  return xc;
}  
$.getlength = function(message){
	return (message?message.length:0);
}
$.isMobile = function(str) {  
	//var filter=/^(?:13\d|15[890])-?\d{5}(\d{3}|\*{3})$/; 
	var filter= "~!@%^&*;'\"?><[]{}\\|,:/=+—“”‘"; 
	return (filter.test(str));  
} 
				
$.isTel = function(str){
	var filter=/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;  
	return (filter.test(str));
}
;
