var FrontPrice_showForm = {
	 /**
	 * 校验浮点型小数
	 *
	 * @param ojb
	 * @param msg
	 * @return
	 */
	checkFloat:function(ojb,msg){
		var theValue = trim(ojb.value);
		//if(theValue*1.0 != theValue || theValue == ''||theValue*1.0 <=0){
		//	alert(msg+i18n_price_page_isFloat);
		//	ojb.focus();
			//ojb.value = '';
		//	return false;
		//}
		//if((theValue.length>8&&theValue.indexOf(".")<0)||theValue.substring(0,theValue.indexOf(".")).length>8){
		//	alert(msg+i18n_price_page_numberLength);
			//ojb.value = '';
		//	ojb.focus();
		//	return false;
		//}
		//if((theValue.indexOf(".")>=0)&&(theValue.length-theValue.indexOf(".")>3)){
		//	alert(msg+i18n_price_page_dot);
		//	ojb.focus();
			//ojb.value = '';
		//	return false;
		//}
		if(!isfloat_8_2(theValue,true)){
			alert(i18n_price_page_isFloat);
			ojb.focus();
			return false;
		}
	},
	 /**
	 * 校验正整数
	 *
	 * @param ojb
	 * @param msg
	 * @return
	 */
	checkInt:function(ojb,msg){
		var theValue = trim(ojb.value);
		for (var i = 0; i < theValue.length; i++){
			var ch = theValue.charAt(i);
			if (ch == "+" ){
				alert(msg+i18n_price_page_isInt);
				ojb.focus();
				return false;
			}
		}
		if(theValue*1.0 != theValue || theValue.indexOf(".") >= 0 || theValue == ''||theValue*1.0 <1) {
			alert(msg+i18n_price_page_isInt);
			//ojb.value = '';
			ojb.focus();
			return false;
		}
		if(theValue.length>8){
			alert(msg+i18n_price_page_numberLength);
			//ojb.value = '';
			ojb.focus();
			return false;
		}
	},
	/**
	 * 表单验证
	 *
	 * @param formid
	 * @return
	 */
	validate:function(formid){
		var formObj = document.getElementById(formid);
		//校验 询价说明内容的字符数
		var name =formObj.inquirynote;
		if(trim(name.value).length>4000){
			alert(i18n_price_page_maxExplain);
			name.focus();
			return false;
		}
		var only_one_product = true;
		var quantity=formObj.quantity;
		//校验 预购数量
		for(var i=0;i<quantity.length;i++){
			only_one_product = false;
			var ojbStr=quantity[i].value;
			if(ojbStr==null||trim(ojbStr)==''){
				alert(i18n_price_page_quantityNotNull);
				quantity[i].focus();
				return false;
			}
			if(FrontPrice_showForm.checkInt(quantity[i],i18n_price_page_quantyty)==false){
				return false;
			}
		}
		if(only_one_product){
			//校验 商品数量
			var quantity=formObj.quantity;
			var quantity_value = quantity.value;
			if(quantity_value==null||trim(quantity_value)==''){
				alert(i18n_price_page_quantityNotNull);
				quantity.focus();
				return false;
			}
			if(FrontPrice_showForm.checkInt(quantity,i18n_price_page_quantyty)==false){
				return false;
			}
			//校验 期望单价
			var hopeprice = formObj.hopeprice;
			var hopeprice_value = hopeprice.value;
			if(hopeprice_value!=null&&trim(hopeprice_value)!=''){
				if(FrontPrice_showForm.checkFloat(hopeprice,i18n_price_page_hopePrice)==false){
					return false;
				}
			}
			
						//表单重复提交验证
	 var checkSubmitFlg = false;
   if(checkSubmitFlg == true)
   {
      return false;
   }
   checkSubmitFlg = true;
			return true;
		}else{
			var name=formObj.hopeprice;
			for(var i=0;i<name.length;i++){
				ojb=name[i].value;
				if(ojb==null||trim(ojb)==''){
					//alert("");
					//name[i].focus();
					//return false;
				}
				if(ojb!=null&&trim(ojb)!=''){
					if(FrontPrice_showForm.checkFloat(name[i],i18n_price_page_hopePrice)==false){
						return false;
					}
				}
			}
	//表单重复提交验证
	 var checkSubmitFlg = false;
   if(checkSubmitFlg == true)
   {
      return false;
   }
   checkSubmitFlg = true;
			return true;
		}
	},
	
	getFormObject:function(formId){
		return document.getElementById(formId);
	},
   /**
	 * 校验email的格式 该方法在组件中并未用到
	 * 
	 * @param str
	 * @return
	 */
	oncheckEmail:function(str){
		str=trim(str);
		var pattern1 = /^(([\u4E00-\u9FA5]|[\uFE30-\uFEFF]|[\d]|[a-zA-Z]|[\_\-\.])+[\@])(((([\d]|[a-zA-Z]|[\_\-]|[\[\]\{\}\>\<])+[\.])+)([\d]|[a-zA-Z\_\-])+)$/;
		if(!str.match(pattern1)){
			return false;
		}
		return true;
	},
	 /**
	 * 校验电话的的格式 
	 * 
	 * @param s
	 * @return
	 */
	
	isValidPhone:function(s) {
		if (!/^[\d\-()、]{0,32}$/.test(s)) return false;
		var stack = [];
		for (var i=0,c; c=s.charAt(i); i++) {
		if (c == '(') {
			stack.push(c);
		} else if (c == ')') {
			if (stack.pop() != '(')
				return false;
			}
		}
		return !stack.length;
	},
	 /**
	 * 校验手机的的格式 
	 * 
	 * @param mobile
	 * @return
	 */
	isMobilePhone:function(mobile){
		var pattern_cn = /^([0-9]|[-]|[+])*$/;
		if(pattern_cn.test(mobile)){
			return true;
		}else{
			return false;
		}
	},
   /**
	 * 表单验证
	 *
	 * @param formid
	 * @return
	 */
	toSaveNotloginCheck:function(formid){
		var formObj = document.getElementById(formid);
		//校验 询价说明内容的字符数
		var name =formObj.inquirynote;
		if(trim(name.value).length>4000){
			alert(i18n_price_page_maxExplain);
			name.focus();
			return false;
		}
		//校验 商品数量
		var quantity=formObj.quantity;
		var ojbStr = quantity.value;
		if(ojbStr==null||trim(ojbStr)==''){
			alert(i18n_price_page_quantityNotNull);
			quantity.focus();
			return false;
		}
		if(FrontPrice_showForm.checkInt(quantity,i18n_price_page_quantyty)==false){
			return false;
		}
		//校验 期望单价
		var hopeprice = formObj.hopeprice;
		var hopeprice_str = hopeprice.value;
		if(hopeprice_str!=null&&trim(hopeprice_str)!=''){
			if(FrontPrice_showForm.checkFloat(hopeprice,i18n_price_page_hopePrice)==false){
				return false;
			}
		}

		var payername = formObj.payername.value;
		payername = trim(payername);
		if(payername==""){
			alert(i18n_price_member_namenull);
			return false;
		}
		if(specialCharactersCheck(payername)){
			alert(i18n_price_member_namehasSpecSymbol);
			return false;
		}
		var payerphone = formObj.payerphone.value;
		payerphone = trim(payerphone);
		if(payerphone!=""){
			if(!FrontPrice_showForm.isValidPhone(payerphone)){
				alert(i18n_price_member_phone);
				return false;
			}
		}
		var payermobile = formObj.payermobile.value;
		payermobile = trim(payermobile);
		var ismessageObj = formObj.ismessage;
		for(var im=0;im<ismessageObj.length;im++){
			if(ismessageObj[im].value=="0"){
				if(ismessageObj[im].checked){
					if(payermobile==""){
						alert(i18n_price_member_mobilenull);
						return false;
					}
				}
			}
		}
		if(payermobile!=""){
			//校验手机号码		由数字、“+”、中横杠“-”组成
			if(!isMobileNumber(payermobile)){
				alert(i18n_price_member_mobileillegal);
				return false;
			}
		}

		var payermail = formObj.payermail.value;
		payermail = trim(payermail);
		if(payermail==""){
			alert(i18n_price_member_emailnull);
			return false;
		}
		if(!isEmail(payermail)){
			alert(i18n_price_member_emailillegal);
			return false;
		}

		var payeraddress = formObj.payeraddress.value;
		payeraddress = trim(payeraddress);
		if(payeraddress!=""){
			if(specialCharactersCheck(payeraddress)){
				alert(i18n_price_member_addresshasSpecSymbol);
				return false;
			}
		}

		var payerzipcode = formObj.payerzipcode.value;
		payerzipcode = trim(payerzipcode);
		if(specialCharactersCheck(payerzipcode)){
			alert(i18n_price_member_pchasSpecSymbol);
			return false;
		}

		var payerfax = formObj.payerfax.value;
		payerfax = trim(payerfax);
		if(payerfax!=""){
			if(!FrontPrice_showForm.isValidPhone(payerfax)){
				alert(i18n_price_member_faxillegal);
				return false;
			}
		}
		//表单重复提交验证
	 var checkSubmitFlg = false;
   if(checkSubmitFlg == true)
   {
      return false;
   }
   checkSubmitFlg = true;
		return true;
	},
	 /**
	 *  游客 生成询价单提交的方法
	 *
	 * @param formid
	 * @param compId
	 * @param ctx
	 * @return
	 */
	toSaveNotlogin:function(formid,compId,ctx){
		if(FrontPrice_showForm.toSaveNotloginCheck(formid)){
			var form = document.getElementById(formid);
			form.action=ctx+"/FrontPrice.do?method=addnotlogin&compId="+compId;
			form.submit();
		}
	},
	
	/**
	 *   首次生成询价单提交的方法  未测试
	 *
	 * @param tag
	 * @param formid
	 * @param priceDetailVOList
	 * @param compId
	 * @param ctx
	 * @param memberphone
	 * @return
	 */
	toSave:function(tag,formid,priceDetailVOList,compId,ctx,memberphone){
		var form = FrontPrice_showForm.getFormObject(formid);
		if(priceDetailVOList==null||priceDetailVOList=='[]'||priceDetailVOList==''){
			alert(i18n_price_page_productNotNull);
			return false;
		}
		if(FrontPrice_showForm.validate(formid)){
			if(tag=="add"){
				if(FrontPrice_showForm.checkadd(memberphone,formid)){
					form.create.disabled=true;
					form.action=ctx+"/FrontPrice.do?method=add&compId="+compId;
					form.submit();
				}
			} else {
				form.action=ctx+"/FrontPrice.do?method=update&compId="+compId;
				form.submit();
			}
			return true;
		}
		return false;
	},
	/**
	 * 校验当您选择了短信提醒方式，手机号码不能为空
	 *
	 * @param memberphone
	 * @param formid
	 * @return
	 */
	checkadd:function(memberphone,formid){
		var ismessageObj = document.getElementById(formid).ismessage;
		for(var im=0;im<ismessageObj.length;im++){
			if(ismessageObj[im].value=="0"){
				if(ismessageObj[im].checked){
					if(memberphone==""){
						alert(i18n_price_member_mobilenull);
						return false;
					}
				}
			}
		}
		return true;
	},
	/**
	 * 修改询价人信息 jsp 1次调用
	 *
	 * @param member_id
	 * @param href_doMemberFrontLogin
	 * @param href_getMemberDetail
	 * @return
	 */
	modify:function(member_id,href_doMemberFrontLogin,href_getMemberDetail){
		if(member_id==null||member_id==""){
			alert(i18n_price_page_notLoad);
			location.href=href_doMemberFrontLogin;
		} else {
			location.href=href_getMemberDetail;
		}
	},
	/**
	 * 继续询价 jsp 1次调用
	 *
	 * @param formid
	 * @param ctx
	 * @param compId
	 * @return
	 */
	goInquiry:function(formid,ctx,compId){
		var form = FrontPrice_showForm.getFormObject(formid);
		form.action=ctx+"/FrontPrice.do?method=addOrUpdatePriceDetailSession&compId="+compId;
		form.submit();
	},
	/**
	 * 删除询价信息 jsp 1次调用
	 *
	 * @param deleteid
	 * @param formid
	 * @param ctx
	 * @param compId
	 * @return
	 */
	toDelete:function(deleteid,formid,ctx,compId) {
		var form = FrontPrice_showForm.getFormObject(formid);
		if(confirm(i18n_price_page_deleteOne)==false) {
			return false;
		}
		form.action=ctx+"/FrontPrice.do?method=deletePriceDetail&compId="+compId+"&productid="+deleteid+"";
		form.submit();
	},
	/**
	 * 删除所有商品记录和询价说明 jsp 1次调用
	 *
	 * @param formid
	 * @param locationToDeleteall
	 * @return
	 */
	toDeleteAll:function(formid,locationToDeleteall) {
		var form = FrontPrice_showForm.getFormObject(formid);
		if(confirm(i18n_price_page_deleteAll)==false) {
			return false;
		}
		form.action=locationToDeleteall;
		form.submit();
	}
}
