﻿
(function($){$.toJSON=function(o){if(typeof(JSON)=='object'&&JSON.stringify)return JSON.stringify(o);var type=typeof(o);if(o===null)return"null";if(type=="undefined")return undefined;if(type=="number"||type=="boolean")return o+"";if(type=="string")return $.quoteString(o);if(type=='object'){if(typeof o.toJSON=="function")return $.toJSON(o.toJSON());if(o.constructor===Date){var month=o.getUTCMonth()+1;if(month<10)month='0'+month;var day=o.getUTCDate();if(day<10)day='0'+day;var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10)hours='0'+hours;var minutes=o.getUTCMinutes();if(minutes<10)minutes='0'+minutes;var seconds=o.getUTCSeconds();if(seconds<10)seconds='0'+seconds;var milli=o.getUTCMilliseconds();if(milli<100)milli='0'+milli;if(milli<10)milli='0'+milli;return'"'+year+'-'+month+'-'+day+'T'+hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}if(o.constructor===Array){var ret=[];for(var i=0;i<o.length;i++)ret.push($.toJSON(o[i])||"null");return"["+ret.join(",")+"]";}var pairs=[];for(var k in o){var name;var type=typeof k;if(type=="number")name='"'+k+'"';else if(type=="string")name=$.quoteString(k);else
continue;if(typeof o[k]=="function")continue;var val=$.toJSON(o[k]);pairs.push(name+":"+val);}return"{"+pairs.join(", ")+"}";}};$.evalJSON=function(src){if(typeof(JSON)=='object'&&JSON.parse)return JSON.parse(src);return eval("("+src+")");};$.secureEvalJSON=function(src){if(typeof(JSON)=='object'&&JSON.parse)return JSON.parse(src);var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered))return eval("("+src+")");else
throw new SyntaxError("Error parsing JSON, source is not valid.");};$.quoteString=function(string){if(string.match(_escapeable)){return'"'+string.replace(_escapeable,function(a){var c=_meta[a];if(typeof c==='string')return c;c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}return'"'+string+'"';};var _escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var _meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};})(jQuery);
jQuery.fn.pagination=function(maxentries,opts){opts=jQuery.extend({items_per_page:10,num_display_entries:10,current_page:0,num_edge_entries:0,link_to:"#",prev_text:"上一页",next_text:"下一页",ellipse_text:"...",prev_show_always:true,next_show_always:true,callback:function(){return false;}},opts||{});return this.each(function(){function numPages(){return Math.ceil(maxentries/opts.items_per_page);}
function getInterval(){var ne_half=Math.ceil(opts.num_display_entries/2);var np=numPages();var upper_limit=np-opts.num_display_entries;var start=current_page>ne_half?Math.max(Math.min(current_page-ne_half,upper_limit),0):0;var end=current_page>ne_half?Math.min(current_page+ne_half,np):Math.min(opts.num_display_entries,np);return[start,end];}
function pageSelected(page_id,evt){current_page=page_id;drawLinks();var continuePropagation=opts.callback(page_id,panel);if(!continuePropagation){if(evt.stopPropagation){evt.stopPropagation();}
else{evt.cancelBubble=true;}}
return continuePropagation;}
function drawLinks(){panel.empty();var interval=getInterval();var np=numPages();var getClickHandler=function(page_id){return function(evt){return pageSelected(page_id,evt);}}
var appendItem=function(page_id,appendopts){page_id=page_id<0?0:(page_id<np?page_id:np-1);appendopts=jQuery.extend({text:page_id+1,classes:""},appendopts||{});if(page_id==current_page){var lnk=jQuery("<span class='current'>"+(appendopts.text)+"</span>");}else{var lnk=jQuery("<a>"+(appendopts.text)+"</a>").bind("click",getClickHandler(page_id)).attr('href',opts.link_to.replace(/__id__/,page_id));}
if(appendopts.classes){lnk.addClass(appendopts.classes);}
panel.append(lnk);}
if(opts.prev_text&&(current_page>0||opts.prev_show_always)){appendItem(current_page-1,{text:opts.prev_text,classes:"prev"});}
if(interval[0]>0&&opts.num_edge_entries>0)
{var end=Math.min(opts.num_edge_entries,interval[0]);for(var i=0;i<end;i++){appendItem(i);}
if(opts.num_edge_entries<interval[0]&&opts.ellipse_text)
{jQuery("<span>"+opts.ellipse_text+"</span>").appendTo(panel);}}
for(var i=interval[0];i<interval[1];i++){appendItem(i);}
if(interval[1]<np&&opts.num_edge_entries>0)
{if(np-opts.num_edge_entries>interval[1]&&opts.ellipse_text)
{jQuery("<span>"+opts.ellipse_text+"</span>").appendTo(panel);}
var begin=Math.max(np-opts.num_edge_entries,interval[1]);for(var i=begin;i<np;i++){appendItem(i);}}
if(opts.next_text&&(current_page<np-1||opts.next_show_always)){appendItem(current_page+1,{text:opts.next_text,classes:"next"});}}
var current_page=opts.current_page;maxentries=(!maxentries||maxentries<0)?1:maxentries;opts.items_per_page=(!opts.items_per_page||opts.items_per_page<0)?1:opts.items_per_page;var panel=jQuery(this);this.selectPage=function(page_id){pageSelected(page_id);}
this.prevPage=function(){if(current_page>0){pageSelected(current_page-1);return true;}
else{return false;}}
this.nextPage=function(){if(current_page<numPages()-1){pageSelected(current_page+1);return true;}
else{return false;}}
drawLinks();opts.callback(current_page,this);});}


function isNumber(oNum) 
{ 
  if(!oNum) return false; 
  var strP=/^\d+(\.\d+)?$/; 
  if(!strP.test(oNum)) return false; 
  try{ 
  if(parseFloat(oNum)!=oNum) return false; 
  } 
  catch(ex) 
  { 
   return false; 
  } 
  return true; 
}

function BigImageCyc(options) {
    options = $.extend(
    {
        id: "bigImageCyc",
        src: {}
    }, options);
    var $div, adTimer, index = 0, len = options.src.length;
    function Init() {
        if (len > 0) {
            $div = $("#" + options.id);
            $div.find("li").mouseover(function() {
                index = $div.find("li").index(this);
                ShowImage(index);
            });
            $div.find("img").unbind("click").click(function () { window.open(options.src[0].URL); });
            $div.hover(function() {
                clearInterval(adTimer);
            }, function() {
                adTimer = setInterval(function() {
                    index++;
                    if (index == len) {
                        index = 0;
                    }
                    ShowImage(index);
                }, 5000);
            }).trigger("mouseleave");
        }
    }
    function ShowImage(idx) {

        $div.find("li").removeClass("on").eq(idx).addClass("on");
        var _selfimg = $div.find("img");
        _selfimg.hide();
        var img = new Image();
        $(img).load(function() {
            _selfimg.attr("src", options.src[idx].PicAddress);
            _selfimg.fadeIn("slow");
            _selfimg.unbind("click").click(function () { window.open(options.src[0].URL); });
        }).attr("src", options.src[idx].PicAddress);
    }
    Init();
}

function CommonError(ans) {
    CleanMessage();
    for (var i = 0; i < ans.error.length; i++) {
        if (ans.error[i]["ErrorControlID"] == "alerterror") {
            alert(ans.error[i]["ErrorMessage"]);
            return;
        }
        var node = $("#" + ans.error[i]["ErrorControlID"]), type = node.attr("nodeName").toLowerCase();
        if (type == "span" || type == "div") {
            node.next(".font14b").eq(0).remove();
            node.prev(".font14b").eq(0).remove();
            node.html(ans.error[i]["ErrorMessage"]);
            node.parents(".leftitbor").show();
        }
        else {
            node.after("<span class='error'>" + ans.error[i]["ErrorMessage"] + "</span>");
        }
    }
}

var CommonErrorMessage;
$(function() {
    CommonErrorMessage = $(".leftitbor").filter(function(index) {
        return $(this).css("display") == "none";
    });
})
function CleanMessage() {
    $(".error").remove();
    CommonErrorMessage.hide();
}

function AddOverLayLoding(time) {
    if(time==0){
        $("body").append("<div class='overlayAjax'></div><div id='pageloading' class='LoadingAjax'>正在加载数据...</div>");
        return;
    }
    var t = 500;
    if (time) {
        t = time;
    }
    layloding = true;
    setTimeout(function() {
        if (layloding) {
            $("body").append("<div class='overlayAjax'></div><div id='pageloading' class='LoadingAjax'>正在加载数据...</div>");
        }
    }, t);
}

var layloding = true;
function RemoveOverLayLoding() {
    layloding = false;
    $("body .overlayAjax").remove()
    $(".LoadingAjax").remove();
}

(function($) {
    $.ajaxJson = function(settings) {
        this.defaults = 
        {
            url: "",
            data: {},
            type: "post",
            cache: false,
            async:true,
            facade:"",
            isIP:false,
            progressshow:true,
            success: function() {
            }
        };
        var config = $.extend(this.config, this.defaults, settings);
        CleanMessage();
        if(config.progressshow)
        {AddOverLayLoding(config.time);}        
        if(config.facade!=""){
            config.data=$.extend({},config.data,{"facadeName":"Facade.front."+config.facade});
            if(config.isIP)
            {
                 config.url="../Utility/FacadeIPHandler.ashx";

            }
            else{
                 config.url="../Utility/FacadeHandler.ashx";
            }
        }
        $.ajax(
        {
            url: config.url,
            dataType: 'json',
            async:config.async,
            type: config.type,
            data: config.data,
            cache: config.cache,
            success: function(ans) {
                if(config.progressshow)
                {RemoveOverLayLoding();}                
                config.success(ans);
            }
        });
    }
})(jQuery);


//按比例显示部分图片，不留空白为优先
function DrawImageRateFullArea(ImgD, iwidth, iheight, itop, ileft) {
    var $image = $(ImgD);
    var image = new Image();
    image.src = $image.attr("src");
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height <= iwidth / iheight) {
            if (image.width > iwidth) {
                $image.css("width", iwidth + "px");
                $image.css("height", (image.height * iwidth) / image.width + "px");
            } else {
                $image.css("width", image.width + "px");
                $image.css("height", image.height + "px");
            }
        }
        else {
            if (image.height > iheight) {
                $image.css("width", (image.width * iheight) / image.height + "px");
                $image.css("height", iheight + "px");
            } else {
                $image.css("width", image.width + "px");
                $image.css("height", image.height + "px");
            }
        }
    }
    ImgPositionCenter($image, iwidth, iheight, itop, ileft);
}

//按比例显示全图，可留空白
function DrawImageRateFullImg(ImgD, iwidth, iheight) {
    var $image = $(ImgD);
    var image = new Image();
    image.src = $image.attr("src");
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height > iwidth / iheight) {//过于宽
            if (image.width > iwidth) {
                $image.css("width", iwidth + "px");
                $image.css("height", (image.height * iwidth) / image.width + "px");
            } else {
                $image.css("width", image.width + "px");
                $image.css("height", image.height + "px");
            }
        }
        else {//过于窄
            if (image.height > iheight) {
                $image.css("width", (image.width * iheight) / image.height + "px");
                $image.css("height", iheight + "px");
            } else {
                $image.css("width", image.width + "px");
                $image.css("height", image.height + "px");
            }
        }
    }
    ImgPositionCenter($image, iwidth, iheight);
}
function ImgPositionCenter(ImgD, iwidth, iheight) {
    var $image = $(ImgD);
    var nowwidth = $image.css("width").replace("px", "");
    var nowheight = $image.css("height").replace("px", "");
    $image.parent().css("position", "relative");
    $image.css("position", "absolute");
    $image.css("top", (iheight - nowheight) / 2  + "px");
    $image.css("left", (iwidth - nowwidth) / 2 + "px");
}

function PicMove(directiontype, steplength, showwidth, parentdivID, prevbtn, nextbtn) {
    var $divparentpart = $("#" + parentdivID);
    var currleft = parseInt($divparentpart.css("left").replace("px", ""));
    var tolwidth = parseInt($divparentpart.css("width").replace("px", ""));
    var expectedleft = currleft + steplength;
    expectedleft = expectedleft < showwidth - tolwidth ? showwidth - tolwidth : expectedleft;
    expectedleft = expectedleft > 0 ? 0 : expectedleft;
    var tosteplength = expectedleft - currleft;
    if (directiontype == "lr") {
        $divparentpart.animate({ left: "+=" + tosteplength + "px" }, 500, function () { });
    }
    else {
        $divparentpart.animate({ top: "+=" + tosteplength + "px" }, 500, function () { });
    }
}


function ScrollMoreText(th) {
    var $th = $(th);
    var parentwidth = $th.parent().css("width").replace("px", "");
    $th.css("left", -10);
}


function SetSelectedUtility(index) {
    var selecteditem = $(".leftmenuitemtext").eq(index);
    selecteditem.addClass("leftmenuitemtexthover");
    selecteditem.attr("onmouseover", "");
    selecteditem.attr("onmouseout", "");
}

