﻿jQuery.extend({easing: {easein: function(x, t, b, c, d) {return c*(t/=d)*t + b; },easeinout: function(x, t, b, c, d) {if (t < d/2) return 2*c*t*t/(d*d) + b;var ts = t - d/2;	return -2*c*ts*ts/(d*d) + 2*c*ts/d + c/2 + b;},easeout: function(x, t, b, c, d) {return -c*t*t/(d*d) + 2*c*t/d + b;},expoin: function(x, t, b, c, d) {var flip = 1;if (c < 0) {flip *= -1;c *= -1;}return flip * (Math.exp(Math.log(c)/d * t)) + b;},expoout: function(x, t, b, c, d) {var flip = 1;if (c < 0) {flip *= -1;c *= -1;}return flip * (-Math.exp(-Math.log(c)/d * (t-d)) + c + 1) + b;},expoinout: function(x, t, b, c, d) {var flip = 1;if (c < 0) {flip *= -1;c *= -1;}if (t < d/2) return flip * (Math.exp(Math.log(c/2)/(d/2) * t)) + b;return flip * (-Math.exp(-2*Math.log(c/2)/d * (t-d)) + c + 1) + b;},bouncein: function(x, t, b, c, d) {return c - jQuery.easing['bounceout'](x, d-t, 0, c, d) + b;},bounceout: function(x, t, b, c, d) {if ((t/=d) < (1/2.75)) {return c*(7.5625*t*t) + b;} else if (t < (2/2.75)) {return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;} else if (t < (2.5/2.75)) {return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;} else {return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;}},bounceinout: function(x, t, b, c, d) {if (t < d/2) return jQuery.easing['bouncein'] (x, t*2, 0, c, d) * .5 + b;return jQuery.easing['bounceout'] (x, t*2-d,0, c, d) * .5 + c*.5 + b;},elasin: function(x, t, b, c, d) {var s=1.70158;var p=0;var a=c;if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;if (a < Math.abs(c)) { a=c; var s=p/4; }else var s = p/(2*Math.PI) * Math.asin (c/a);return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;},elasout: function(x, t, b, c, d) {var s=1.70158;var p=0;var a=c;if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;if (a < Math.abs(c)) { a=c; var s=p/4; }else var s = p/(2*Math.PI) * Math.asin (c/a);return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;},elasinout: function(x, t, b, c, d) {var s=1.70158;var p=0;var a=c;if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);if (a < Math.abs(c)) { a=c; var s=p/4; }else var s = p/(2*Math.PI) * Math.asin (c/a);if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;},backin: function(x, t, b, c, d) {var s=1.70158;return c*(t/=d)*t*((s+1)*t - s) + b;},backout: function(x, t, b, c, d) {var s=1.70158;return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;},backinout: function(x, t, b, c, d) {var s=1.70158;if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;},linear: function(x, t, b, c, d) {return c*t/d + b; }}});

function initBuyAlert()
{
    
     $("#dialog_buyAlert").dialog("destroy");
     $('#dialog_buyAlert').dialog({
         autoOpen: false,
			modal: true,
        width:500,
        resizable:false,
        buttons:{
            
            "先不注册，马上发布我的求购信息":function(){
     			$(this).dialog('close');
                $('#dialog_BuyForm').dialog('open');
            },
            "马上注册为联盟会员":function(){
                $(this).dialog('close');
                location.href=indexWebHttp+"/userregister.aspx";
            }
        
        },
        close:function()
        {
           
        }
    
    });
}
var rhtmlEncodeType="utf-8";
var htmlEncodeType="utf-8";
function initBuyForm()
{
    
    
		var title = $("#butytle_a"),
			content = $("#butycont_a"),
			comp = $("#butycomp_a"),
			cass=$("#casNoP"),
			contact=$("#butytact_a"),
			people=$("#butypeo_a"),
			allFields = $([]).add(title).add(content).add(comp).add(contact).add(people).add(cass),
			tips = $("#buyFormvalidateTips");
 
		function updateTips(t) {
			tips
				.html(t)
				.removeClass("alertSuccess")
				.addClass('alertError');
//			setTimeout(function() {
//				tips.removeClass('ui-state-highlight', 1500);
//			}, 500);
		}
 
		function checkLength(o,n,min,max) {
 
			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				updateTips("" + n + "长度必须在 "+min+" - "+max+"之间.");
				var eff="pulsate";
                  var options={};

                o.show(eff,options,500,function(){
                o.removeClass('ui-state-error');
                o.focus();
                });
				return false;
			} else {
				return true;
			}
 
		}
         function ckCasNum(o)
            {
                var patrn=/^[0-9]{2,7}-[0-9]{1,7}-[0-9]{1,7}$/;  
                o.val($.trim(o.val()));
                if($.trim(o.val())!="")
                {
                    if (!patrn.exec(o.val())) 
                    {
                       updateTips("请输入正确的cas号！格式：22-82-924");
                       var eff="pulsate";
                       var options={};
                        o.addClass('ui-state-error').val("").show(eff,options,500,function(){
                            o.removeClass('ui-state-error');
                            o.focus();
                            });
                    
                      
                        return false;
                      
                    }
                    else
                    {
                      return true;
                    }
                }
                else
                {
                    return true;
                }
            }
		function checkRegexp(o,regexp,n) {
 
			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass('ui-state-error');
				updateTips(n);
				return false;
			} else {
				return true;
			}
 
		}
     $("#dialog_BuyForm").dialog("destroy");
     $('#dialog_BuyForm').dialog({
         autoOpen: false,
			modal: true,
		//	show: 'scale',
	//		hide: 'scale',
        width:500,
        resizable:false,
        buttons:{
            "取消":function(){
                $(this).dialog('close');
            },
            "马上发布我的求购信息":function(){
     				var bValid = true;
					allFields.removeClass('ui-state-error');
 
					bValid = bValid && checkLength(title,"标题",1,40);
				//	bValid = bValid && ckCasNum(cass);
					bValid = bValid && checkLength(content,"求购说明",10,300);
					bValid = bValid && checkLength(comp,"公司名称",5,30);
                    bValid = bValid && checkLength(contact,"联系方式",5,50);
                    bValid = bValid && checkLength(people,"联系人",1,30);
					//bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"eg. yourname@chem960.com");

					
					if (bValid) {
						 
						var tit=$.trim(title.val());
                        var cont=$.trim(content.val());
                      
                        var compp=$.trim(comp.val());
                        var tel=$.trim(contact.val());
                        var peo=$.trim(people.val());
                        var cas=$.trim(cass.html());
                        
                        $.post(indexWebHttp+"/cas/doAjax.aspx", { Action: "post", ActionType:4,tit:tit,cont:cont,comp:compp,tel:tel,peo:peo,cas:cas,htmlEncodeType:htmlEncodeType,
	       rhtmlEncodeType:rhtmlEncodeType},
				                        function (data, textStatus){
				                            if(data.result=="1")
				                            {
                    				            
				                               tips.removeClass('alertError').addClass('alertSuccess').html("您的求购信息已发布成功，我们将在第一时间内为您匹配优秀供应商！我们强烈建议您<a href=\"http://www.chem960.com/userregister.aspx\" target=\"_self\" style=\"color:red\">注册为我们的会员</a>，享受更多的服务！");
                    				           allFields.val('').removeClass('ui-state-error');
                    				            
				                            }
				                        }, "json");
					}
        
            }
        
        },
        close:function()
        {
           
        }
    
    });
   
}
function addBuyFree()
{
    if($('#dialog_buyAlert').length==1)
    {
        
       $('#dialog_buyAlert').dialog('open'); 
    }
    else
    {
     
        $("#addBuyFormBox").load(""+indexWebHttp+"/Models/BuyForm.aspx", function(html){
            initBuyAlert();
            initBuyForm();
            addBuyFree();
        });
        
    }
    
}
