
	function mydecodeurl(s){return decodeURIComponent(s);}
	function myencodeurl(s){return encodeURIComponent(s);}

	function hiddenSendBox(){
		if ($('#SendBoxHeader').attr("alt") == 'open'){
			$('#SendBoxForm').slideUp();
			$('#SendBoxBottom').slideUp();
			$('#SendBoxHeader').attr('alt', 'close');
			$('#SendBoxHeader').attr('src', $('#SendBoxHeader').attr('src').replace('Top', 'Top2'));
		} 	else {
			$('#SendBoxForm').slideDown();
			$('#SendBoxBottom').slideDown();
			$('#SendBoxHeader').attr('alt', 'open');
			$('#SendBoxHeader').attr('src', $('#SendBoxHeader').attr('src').replace('Top2', 'Top'));
		}
	}
	
	
	function checkEmail(el){
		var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z-]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]|net|NET|asia|ASIA|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT|cn|CN|cc|CC)$"
		var re = new RegExp(regu);
		if(el.search(re) == -1)
			return true; //非法
		else
			return false;
	}
	
	function SetOnFoc(op,obj){
		if(op==1){
			if($(obj).val()=="公司名/联系人"){
				$(obj).val("");
			}
		}else if(op==2){
			if($(obj).val()=="邮箱"){
				$(obj).val("");
			}
		}else if(op==3){
			if($(obj).val()=="QQ"){
				$(obj).val("");
			}
		}else if(op==4){
			if($(obj).val()=="电话"){
				$(obj).val("");
			}
		}
	}
	
	function SetOutFoc(op,obj){
		 SendMailMessage = '<div style="position:absolute; height:25px; left:-152px;" ><div style="position:relative; font-size:12px; width:166px; height:259px; overflow:hidden; background:url(http://www.51dzw.com/v1/plugs/sendmailfloatbox/images/SendBoxErr.png) left top no-repeat; line-height:27px; color:#555; padding-left:4px;">message</div></div>';
		if(op==1){
			if ($(obj).val() != '公司名/联系人' && $(obj).val().length > 1){
				$(obj).parent().find("div", this).remove();
			} else {
				$(obj).parent().parent().find("div").remove();
				$(obj).parent().prepend(SendMailMessage.replace('message', '请填写正确的公司名/联系人！'));
				$(obj).val('公司名/联系人');
			}
		}else if(op==2){
			if ($(obj).val() != '邮箱' && !checkEmail($(obj).val())){
				$(obj).parent().find("div", this).remove();
			} else {
				$(obj).parent().parent().find("div").remove();
				$(obj).parent().prepend(SendMailMessage.replace('message', '请填写正确的邮箱！'));
				$(obj).val('邮箱');
			}
		}else if(op==3){
			if ($(obj).val() != 'QQ' && $(obj).val().length > 4 && !isNaN($(obj).val())){
				$(obj).parent().find("div", this).remove();
			} else {
				$(obj).parent().parent().find("div").remove();
				$(obj).parent().prepend(SendMailMessage.replace('message', '请填写正确的QQ！'));
				$(obj).val('QQ');
			}
		}else if(op==4){
			if ($(obj).val() != 'tel' && $(obj).val().length > 6){
				$(obj).parent().find("div", this).remove();
			} else {
				$(obj).parent().parent().find("div").remove();
				$(obj).parent().prepend(SendMailMessage.replace('message', '请填写正确的电话！'));
				$(obj).val('电话');
			}
		}
	}


	function checkSendMailForm(obj){
		var company;
		var email;
		var qq;
		var tel;
		var partno;
		var partnonum;
		var descript = '';
		var sendmailinfo;
		var sendmailinfoarray = new Array();
		var message;
		var state;
		var geturl = '';
		company = $(obj).find("[name = 'company']", this).val();
		email = $(obj).find("[name = 'email']", this).val();
		qq = $(obj).find("[name = 'qq']", this).val();
		tel = $(obj).find("[name = 'tel']", this).val();
		sendmailinfo = $(obj).find("[name = 'sendmailinfo']", this).val();
		SendMailMessage = '<div style="position:absolute; height:25px; left:-152px;" ><div style="position:relative; font-size:12px; width:166px; height:259px; overflow:hidden; background:url(http://www.51dzw.com/v1/plugs/sendmailfloatbox/images/SendBoxErr.png) left top no-repeat; line-height:27px; color:#555; padding-left:4px;">message</div></div>';
		SendMailLoad = '<div name=\"sendMailLoadBox\" style=\"z-index:100px; width:181px; height:165px; position:absolute; text-align:center; padding-top:50px; background:#fff; left:10px; top:38px; filter:alpha(opacity=60); opacity: 0.6;\"><img src=\"http://www.51dzw.com/v1/plugs/sendmailfloatbox/loading.gif\" /></div>'
		state = true;
		if (company == '公司名/联系人' || company.length < 2){
			$(obj).find("[name = 'company']", this).parent().prepend(SendMailMessage.replace('message', '请写正确填公司名/联系人！'));
			state = false;
		}
		if (email == '邮箱' || checkEmail(email)){
			$(obj).find("[name = 'email']", this).parent().prepend(SendMailMessage.replace('message', '请正确填写的邮箱！'));
			state = false;
		}
		if (qq == 'QQ' || qq.length < 5 || isNaN(qq)){
			$(obj).find("[name = 'qq']", this).parent().prepend(SendMailMessage.replace('message', '请正确填写的QQ！'));
			state = false;
		}
		if (tel == 'tel' || tel.length < 7){
			$(obj).find("[name = 'tel']", this).parent().prepend(SendMailMessage.replace('message', '请正确填写的电话！'));
			state = false;
		}
		sendmailinfoarray = sendmailinfo.split("\n");
		for(i = 0; i < sendmailinfoarray.length; i++){
			switch(i){
				case 0: partno = sendmailinfoarray[i].replace(/[ ]/g, "").replace('型号：', '');
				case 1: partnonum = sendmailinfoarray[i].replace(/[ ]/g, "").replace('数量：', '');
				default: 
					if(i != 0 && i != 1) {descript += sendmailinfoarray[i].replace(/[ ]/g, "").replace('描述：', '');}
			}
		}
		if(state){
			$(obj).append(SendMailLoad);
			geturl += '/v1/plugs/sendmailfloatbox/index.asp?';
			geturl += 'partno=' + partno;
			geturl += '&partnonum=' + partnonum;
			geturl += '&email=' + email;
			geturl += '&qq=' + qq;
			geturl += '&tel=' + tel;
			geturl += '&qiugou=1';
			geturl += '&company=' + company;
			geturl += '&descript=' + descript;
			$.ajax({
				type : 'get',
				url : geturl,
				dataType : 'json',
			    jsonp: "callback",
				success : function(json){
					switch(json.state){
						case 'partnoTableErr' : alert('型号有误，请联系维护人员！'); break;
						case 'insertUserErr' : alert('用户注册失败，请联系维护人员！'); break;
						case 'insertPartnoErr' : alert('查询型号有误，请联系维护人员！'); break;
						case 'insertPartnoSuccess' : 
							var r=confirm("询价成功！\n用户名：" + json.username + "\n密码：" + json.password + "\n请牢记您的用户名与密码！\n需要等待报价点击\"确定\"，继续询价点击\"取消\"!");
							if (r==true) { 
							 	window.location.href = 'http://member.51dzw.com/mylogin.asp?type=xunjialeibiao&username=' + json.username + '&password=' + json.password;
								break;
							} else {
								$(obj).find("[name = 'company']", this).val('公司名/联系人');
								$(obj).find("[name = 'email']", this).val('邮箱');
								$(obj).find("[name = 'qq']", this).val('QQ');
								$(obj).find("[name = 'tel']", this).val('电话');
								$(obj).find("[name = 'sendMailLoadBox']", this).remove();
								break;}
						default : alert("莫名错误！"); break;
					}
				}, error : function(){
					$(obj).find("[name = 'sendMailLoadBox']", this).remove();
					alert('网络堵塞！');
					
					}
			});
		} 
		
		return false;
	}
	var sendmailpartno = $('body').attr('title');
	document.writeln("<style type=\"text/css\">");
	document.writeln("	#SendBox {width:203px; height:auto; right:0; bottom:0px; position:fixed; _position:absolute; _top: expression(documentElement.scrollTop+documentElement .clientHeight-this.offsetHeight);}");
	document.writeln("	#SendBox img {padding:0px;  margin:0px; border:0px; vertical-align:top;}");
	document.writeln("	#SendBox #SendBoxHeader {cursor:pointer;}");
	document.writeln("	#SendBox	form {width:181px; height:auto; margin:0px; padding:0px 11px; background:url(http://www.51dzw.com/v1/plugs/sendmailfloatbox/images/SendBoxMain.jpg) left top repeat-y;}");
	document.writeln("	#SendBox	form ul {width:181px; height:auto; overflow:hidden; margin:0px; padding:7px 0px;  z-index:10;}");
	document.writeln("	#SendBox	form ul li {width: 177px; height:auto; overflow:hidden; padding:2px 7px; list-style:none;}");
	document.writeln("	#SendBox	form ul li .inputText {width:157px; height:18px; border:#888 1px solid;}");
	document.writeln("	#SendBox	form ul li textarea {width:157px; heigth:410px; border:#888 1px solid; font-size:12px; color:#666; overflow:hidden;  padding:0px 3px;}");
	document.writeln("	#SendBox	form ul li p {padding:0px; margin:0px; display:block; width:90px; height:25px; float:left; font-size:12px;  color:#666; z-index:10000;}");
	document.writeln("	#SendBox	form ul li input { vertical-align:middle; padding:0px 3px;  color:#666; z-index:10000;}");
	document.writeln("	#SendBox	form ul li .button {float:right; border:none; width:79px; height:24px; background:url(http://www.51dzw.com/v1/plugs/sendmailfloatbox/images/SendBoxButton.jpg) left top no-repeat; cursor:pointer}");
	document.writeln("</style>");
	document.writeln("<div id=\"SendBox\">");
	document.writeln("	<img id=\"SendBoxHeader\" alt=\"open\" src=\"http://www.51dzw.com/v1/plugs/sendmailfloatbox/images/SendBoxTop.jpg\" onclick=\"hiddenSendBox()\" />");
	document.writeln("   <form id=\"SendBoxForm\" name=\"sendboxform\" onsubmit=\"return checkSendMailForm(this);\" action=\"\">");
	document.writeln("      <ul>");
	document.writeln("      	<li><input class=\"inputText\" type=\"text\" onblur=\"SetOutFoc(1, this)\" onfocus=\"SetOnFoc(1, this)\" name=\"company\" id=\"SendMailCompany\" value=\"公司名/联系人\" /></li>");
	document.writeln("      	<li><input class=\"inputText\" type=\"text\" onblur=\"SetOutFoc(2, this)\" onfocus=\"SetOnFoc(2, this)\" name=\"email\" id=\"SendMailEmail\" value=\"邮箱\" /></li>");
	document.writeln("      	<li><input class=\"inputText\" type=\"text\" onblur=\"SetOutFoc(3, this)\" onfocus=\"SetOnFoc(3, this)\" name=\"qq\" id=\"SendMailQq\" value=\"QQ\" /></li>");
	document.writeln("      	<li><input class=\"inputText\" type=\"text\" onblur=\"SetOutFoc(4, this)\" onfocus=\"SetOnFoc(4, this)\" name=\"tel\" id=\"SendMailTel\" value=\"电话\"/></li>");
	document.writeln("      	<li class=\"text\">");
	document.writeln("      	   <textarea name=\"sendmailinfo\" id=\"SendMailInfo\" rows=\"4\">型号：" + sendmailpartno + "");
	document.writeln("数量：1000");
	document.writeln("描述：急需求购</textarea>");
	document.writeln("      	</li>");
	document.writeln("      	<li><input class=\"button\" type=\"submit\" id=\"SendMailButton\" value=\"\" /><p><input name=\"SendMailBuy\" type=\"checkbox\" value=\"1\" checked=\"checked\" />发布求购");
	document.writeln("      	   <input type=\"hidden\" name=\"partno\" id=\"SendMailButton\" value=\"\" />");
	document.writeln("      	</p>");
	document.writeln("      	</li>");
	document.writeln("      </ul>");
	document.writeln("   </form>");
	document.writeln("	<img id=\"SendBoxBottom\" src=\"http://www.51dzw.com/v1/plugs/sendmailfloatbox/images/SendBoxBottom.jpg\" />");
	document.writeln("</div>");