//扩展jquery的格式化方法
 $.fn.parseForm = function () {
    var serializeObj = {};
    var array = this.serializeArray();
    var str = this.serialize();
    $(array).each(function () {
        if (serializeObj[this.name]) {
            if ($.isArray(serializeObj[this.name])) {
                serializeObj[this.name].push(this.value);
            } else {
                serializeObj[this.name] = [serializeObj[this.name], this.value];
            }
        } else {
            serializeObj[this.name] = this.value;
        }
    });
    return serializeObj;
};
 

 window.alert = function (msg) {
     ShowMessage(msg);
 }
 window.alert = function (msg, type) {
     ShowMessageByType(msg, type);
 }

 $.fn.serializeObject = function () {
     var o = {};
     var a = this.serializeArray();
     $.each(a, function () {
         if (o[this.name]) {
             if (!o[this.name].push) {
                 o[this.name] = [o[this.name]];
             }
             o[this.name].push(this.value || '');
         } else {
             o[this.name] = this.value || '';
         }
     });
     return o;
 };

 function positionRoute(SEQ, Contect, Method, Result) {
     var positionType = new Object();
     positionType.SEQ = SEQ;
     positionType.Contect = Contect;
     positionType.Method = Method;
     positionType.Result = Result;
     return positionType;
 }

 function serializeArray() {
     return this.map( function() {

         // Can add propHook for "elements" to filter or add form elements
         var elements = jQuery.prop( this, "elements" );
         return elements ? jQuery.makeArray( elements ) : this;
     } )
     .filter( function() {
         var type = this.type;

         // Use .is(":disabled") so that fieldset[disabled] works
         return this.name && !jQuery( this ).is( ":disabled" ) &&
             rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
             ( this.checked || !rcheckableType.test( type ) );
     } )
     .map( function( i, elem ) {
         var val = jQuery( this ).val();

         return val == null ?
             null :
             jQuery.isArray( val ) ?
                 jQuery.map( val, function( val ) {
                     return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
                 } ) :
					{ name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
     } ).get();
 }

//合并单元格
 function Merger(gridName, CellName) {

     //得到显示到界面的id集合
     var mya = $("#" + gridName + "").getDataIDs();
     //当前显示多少条
     var length = mya.length;
     for (var i = 0; i < length; i++) {
         //从上到下获取一条信息
         var before = $("#" + gridName + "").jqGrid('getRowData', mya[i]);
         //定义合并行数
         var rowSpanTaxCount = 1;
         for (j = i + 1; j <= length; j++) {
             //和上边的信息对比 如果值一样就合并行数+1 然后设置rowspan 让当前单元格隐藏
             var end = $("#" + gridName + "").jqGrid('getRowData', mya[j]);
             if (before[CellName] == end[CellName]) {
                 rowSpanTaxCount++;
                 $("#" + gridName + "").setCell(mya[j], CellName, '', { display: 'none' });

             }
             else {
                 rowSpanTaxCount = 1;
                 break;
             }

             $("#" + CellName + "" + mya[i] + "").attr("rowspan", rowSpanTaxCount);
         }
     }
 }

//合并单元格//FrontCellName列未合并的行 不能合并
 function MergerRows(gridName, CellName, FrontCellName) {

     //得到显示到界面的id集合
     var mya = $("#" + gridName + "").getDataIDs();
     //当前显示多少条
     var length = mya.length;
     for (var i = 0; i < length; i++) {
         //从上到下获取一条信息
         var before = $("#" + gridName + "").jqGrid('getRowData', mya[i]);
         
         //定义合并行数
         var rowSpanTaxCount = 1;
         for (j = i + 1; j <= length; j++) {
             //和上边的信息对比 如果值一样就合并行数+1 然后设置rowspan 让当前单元格隐藏
             var end = $("#" + gridName + "").jqGrid('getRowData', mya[j]);
             
             
             if (before[CellName] == end[CellName] && before[FrontCellName] == end[FrontCellName]) {
                 rowSpanTaxCount++;
                 $("#" + gridName + "").setCell(mya[j], CellName, '', { display: 'none' });
                 
             }
             else {
                 rowSpanTaxCount = 1;
                 break;
             }
             
             $("#" + CellName + "" + mya[i] + "").attr("rowspan", rowSpanTaxCount);
         }
     }
 }

 function ShowMessageByType(str, type) {
     if (type == "warning") { toastr.options.timeOut = "3000"; toastr.warning(str); }
     if (type == "error") { toastr.error(str); }
     if (type == "success") { toastr.options.timeOut = "3000"; toastr.success(str); }
     if (type == "info") { toastr.options.timeOut = "3000"; toastr.info(str); }
     if (type != "warning" && type != "error" && type != "success" && type != "info") { toastr.options.timeOut = "3000"; toastr.info(str); }
 }

 function ShowMessage(str) {
     toastr.options.timeOut = "3000";
     toastr.info(str);
 }

 function ShowMessage_TimeOut(str, timeOut) {
     toastr.options.timeOut = timeOut;
     toastr.info(str);
 }

 //字符串前面补0
 function PrefixZero(num, n) {
     return (Array(n).join(0) + num).slice(-n);
 }

 function GetWeek(dateString) {
     var da = '';
     if (dateString == undefined) {
         var now = new Date();
         var now_m = now.getMonth() + 1;
         now_m = (now_m < 10) ? '0' + now_m : now_m;
         var now_d = now.getDate();
         now_d = (now_d < 10) ? '0' + now_d : now_d;
         da = now.getFullYear() + '-' + now_m + '-' + now_d;
          
     } else {
         da = dateString;//日期格式2015-12-30
     }
     var date1 = new Date(da.substring(0, 4), parseInt(da.substring(5, 7)) - 1, da.substring(8, 10));//当前日期
     var date2 = new Date(da.substring(0, 4), 0, 1); //1月1号
     //获取1月1号星期(以周一为第一天,0周一~6周日)
     var dateWeekNum = date2.getDay() - 1;
     if (dateWeekNum < 0) { dateWeekNum = 6; }
     if (dateWeekNum < 4) {
         //前移日期
         date2.setDate(date2.getDate() - dateWeekNum);
     } else {
         //后移日期
         date2.setDate(date2.getDate() + 7 - dateWeekNum);
     }
     var d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000);
     if (d < 0) {
         var date3 = (date1.getFullYear() - 1) + "-12-31";
         return getYearWeek(date3);
     } else {
         //得到年数周数
         var year = date1.getFullYear();
         var week = Math.ceil((d + 1) / 7);
         
         return week;
     }
 }