﻿<!--//
var $URL="http://www.365csc.com";
var $URL_USER="http://user.365csc.com";
var $URL_P = "http://passport.365csc.com";
/**********************************完善系统方法*****************************************/
String.prototype.trim = function()
{
    var s = this;
    return s.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.base64Encode = function() {
    var str = this.toString();
    str = escape(str);
    var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var output = "";
    var chr1, chr2, chr3 = "";
    var enc1, enc2, enc3, enc4 = "";
    var i = 0;
    do {
        chr1 = str.charCodeAt(i++);
        chr2 = str.charCodeAt(i++);
        chr3 = str.charCodeAt(i++);
        enc1 = chr1 >> 2;
        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
        enc4 = chr3 & 63;
        if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; };
        output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);
        chr1 = chr2 = chr3 = "";
        enc1 = enc2 = enc3 = enc4 = "";
    } while (i < str.length);
    return output;
};
String.prototype.base64Decode = function() {
    var str = this.toString();
    var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var output = "";
    var chr1, chr2, chr3 = "";
    var enc1, enc2, enc3, enc4 = "";
    var i = 0;
    var base64test = /[^A-Za-z0-9\+\/\=]/g;
    if (base64test.exec(str)) { };
    str = str.replace(/[^A-Za-z0-9\+\/\=]/g, "");
    do {
        enc1 = keyStr.indexOf(str.charAt(i++));
        enc2 = keyStr.indexOf(str.charAt(i++));
        enc3 = keyStr.indexOf(str.charAt(i++));
        enc4 = keyStr.indexOf(str.charAt(i++));
        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;
        output = output + String.fromCharCode(chr1);
        if (enc3 != 64) { output = output + String.fromCharCode(chr2); };
        if (enc4 != 64) { output = output + String.fromCharCode(chr3); };
        chr1 = chr2 = chr3 = "";
        enc1 = enc2 = enc3 = enc4 = "";
    } while (i < str.length);
    return unescape(output);
};
/**********************************Cookie读写方法**************************************/
function Cookie(ops) {
    ops = ops || {};
    var COOKIE_LIFE = { year: 31536000, month: 2592000, week: 604800, day: 86400, hour: 3600, browser: 0 };
    this.expires = ops.expires || 'browser';
    this.path = ops.path || "/";
    this.domain = ops.domain || "365csc.com";
    this.get = function(fieldName) {
        var regexp = window.eval("/" + fieldName + "=([\\w%,]+)(|;)/");
        var result = document.cookie.match(regexp);
        return (result ? unescape(result[1]) : "");
    };
    this.set = function(fieldName, fieldValue) {
        var cookie_list;
        cookie_list = fieldName + "=" + escape(fieldValue);
        cookie_list += setExpires(this.expires);
        cookie_list += setPath(this.path);
        cookie_list += setDomain(this.domain);
        document.cookie = cookie_list;
    };
    function setExpires(expires) {
        var tm = 0;
        if (typeof (expires) == 'string') {
            if (!COOKIE_LIFE[expires]) return "";
            tm = COOKIE_LIFE[expires] * 1000;
        } else if (typeof (expires) == 'number') {
            tm = expires * 1000;
        } else { return ""; }
        expires = ";expires=" + new Date(new Date().getTime() + tm).toUTCString();
        return expires;
    };
    function setPath(path) {
        if (!path) return "";
        return (";path=" + path);
    };
    function setDomain(domain) {
        if (!domain) return "";
        return (";domain=" + domain);
    };
};
/**********************************与收藏与窗口操作相关的方法*****************************************/
var $H = {
	isIE:(navigator.userAgent.toLowerCase().indexOf("msie")>=0)?true:false,
	add:function(url,title)
	{
		if(!(/^http:\/\//gi.test(url)))
		{
			var host = location.protocol+"//"+location.hostname+":"+location.port
			if(/^\//gi.test(url)) url = host + url;
			else url = host + "/"+url;
		}
		if(!title) title = document.title;
		if(this.isIE && window.external) window.external.addFavorite(url,title);
		else if(window.sidebar) window.sidebar.addPanel(title,url,"");
	},
	setHome:function(e,url)
	{
		if(!url) url = location.href;
		try
		{
			if(!e) e = window.event;
			var element = (this.isIE)?e.srcElement:e.target;
			element.style.behavior = "url(#default#homepage)";			
			element.setHomePage(url);
			return;
		}
		catch (ex1)
		{
            try
            {
				if(window.confirm("将"+url+"设置为首页，继续吗？"))
				{
					netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
					var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
					prefs.setCharPref('browser.startup.homepage',url);
				}
            }
            catch (ex2)
            {
				var msg = "错误原因如下：\n";
				msg += "1、调用格式不正确，请按照History.setHome(事件，URL)格式调用!\n";
				msg += "2、您使用的为Mozilla FireFox等浏览器，当前设置不允许使用此功能，在地址栏中输入about:config更改signed.applets.codebase_principal_support键值为true即可。\n";
				msg += "3、浏览器不支持!\n";
				window.alert(msg);
            }
		}
	},
	back:function()
	{
		window.history.back();
	},
	forward:function()
	{
		window.history.forward();
	},
	go:function()
	{
		if(arguments.length==0) return;
		if(isNaN(arguments[0]))
			window.location = arguments[0];
		else
			window.history.go(arguments[0]);

	}
};
/***********************************日期脚本*********************************************/
function $d( id ){return 'string' == typeof(id) ? document.getElementById(id) : id;};
var Calendar = function(source)
{
	if(typeof(source) == "string") source = $d(source);
	if(!source.id) {alert("请设置对象Id");return;};
	var av = source.value.replace(/[^\d\-]+/gi,"").split('-');
    if(av.length == 3) d = new Date( av[0],av[1]-1,av[2]);
	else d = new Date();
	this.y = d.getFullYear();
	this.m = d.getMonth() + 1;
	this.d = d.getDate();
	this.source = source;
	source.value = this.y + "-" + this.m + "-" + this.d;
	this.id = "wb_calendar";
	this.ns = "font-size:12px; text-align:center; background-color:#fff;";
	this.cs = "font-size:14px; font-weight:bold; color:#f60; text-align:center; border:1px solid #f60;";
};
Calendar.prototype.bindEvent = function()
{
	var spans = $d(this.id).getElementsByTagName("span");
	var tds = $d(this.id).getElementsByTagName("td");
	var flag = "";
	var cal = this;
	for(var i=0;i<spans.length;i++) spans[i].onclick = function(){cal.changeDate(this);};
	for(var i=0;i<tds.length;i++)
	{
		if(!isNaN(tds[i].innerHTML)) tds[i].onclick = function(){cal.setDate(this);};
		tds[i].onmouseover = function(){this.style.backgroundColor = "#eee";};
		tds[i].onmouseout = function(){this.style.backgroundColor = "#fff";};
	}
};
Calendar.prototype.getPos = function(e)
{
    var l, t;
	if( e.getBoundingClientRect )
	{
	    var el = e.getBoundingClientRect();
		var st = Math.max( document.documentElement.scrollTop, document.body.scrollTop );
		var sl = Math.max( document.documentElement.scrollLeft, document.body.scrollLeft );
		l = sl + el.left; t = st + el.top;
	}
	else
	{
	    l = e.offsetLeft; t = e.offsetTop;
		while( e = e.offsetParent )
		{
		    l += e.offsetLeft; t += e.offsetTop;
		};
	};
	return { x:l, y:t };
};
Calendar.prototype.setPos = function()
{
	var pos = this.getPos(this.source);
	var l, t, w = this.source.offsetWidth, h = this.source.offsetHeight;
	l = pos.x; t = pos.y + h;
	if(document.all && window.event) {l = l-2; t = t-1;}
	else {l = l; t = t + 1;};
	var o = $d(this.id);
	o.style.top = t + 'px';
	o.style.left = l + 'px';
	o.style.display = "";
};
Calendar.prototype.drawHtml = function()
{
    var i=0;
	var a = [], ct = '', w = ['日','一','二','三','四','五','六'];
	var fd = new Date(this.y, this.m - 1, 1).getDay();
	var md = new Date(this.y, this.m, 0).getDate();
	for( i = 1; i <= fd; i++ ) a.push(0);
	for( i = 1; i <= md; i++ ) a.push(i);
	ct += '<table cellspacing="0" cellpadding="0" style="width:100%; height:100%; border:1px solid #5ccaff;background-color:#fff;"><caption style="background-color:#e2f2ff; border:1px solid #5ccaff; border-bottom:0px; font-size:12px; font-weight:bold;"><span f="py" title="上一年"><<</span>&nbsp;<span f="pm" title="上一月">&lt;</span>&nbsp;<span>'+this.y+'年'+this.m+'月</span>&nbsp;<span f="nm" title="下一月">&gt;</span>&nbsp;<span f="ny" title="下一年">>></span><span f="close" title="关闭" style="margin-left:15px;">×</span></caption><thead><tr>';
	for( i = 0; i < 7; i++ ) ct += '<th>' + w[i] + '</th>';
	ct += '</tr></thead><tbody>';
	while(a.length)
	{
		ct += '<tr>';
		for( i = 1; i <= 7; i++ )
		{
			var d = a.shift();
			if(d)
			{
				if( d == this.d ) ct += '<td style="'+this.cs+'">' + d + '</td>';
				else ct += '<td style="'+this.ns+'">' + d + '</td>';
			}
			else ct += '<td style="'+this.ns+'">&nbsp;</td>';;
		};
		ct += '</tr>';
	};
	ct += '</tbody></table>';
	return ct;
};
Calendar.prototype.create = function()
{
	if(!this.source.id) return;
	var container = $d(this.id);
	if(!container)
	{
		container = document.createElement('div');
		var style = {width:"180px",height:"120px",cursor:"pointer",display:"",position:"absolute",top:"0px",backgroundColor:"#fefefe"};
		for(var s in style) container.style[s] = style[s];
		container.id = this.id;
		document.body.appendChild(container);
	};
	container.innerHTML = this.drawHtml();
	this.setPos();
	this.bindEvent();
};
Calendar.prototype.changeDate = function(source)
{
	var flag = source.getAttribute("f");
	if(flag)
	{
		switch(flag.toLowerCase())
		{
			case "py":
				this.redrawHtml(new Date(this.y - 1,this.m - 1,1));
				break;
			case "ny":
				this.redrawHtml(new Date(this.y + 1, this.m - 1, 1));
				break;
			case "pm":
				this.redrawHtml(new Date(this.y, this.m - 2, 1));
				break;
			case "nm":
				this.redrawHtml(new Date(this.y, this.m, 1));
				break;
			case "close":
			    $d(this.id).style.display = "none";
			    break;
		};
	};
};
Calendar.prototype.redrawHtml = function( d )
{
	this.y = d.getFullYear(); this.m = d.getMonth() + 1;
	$d(this.id).innerHTML = this.drawHtml();
	this.bindEvent();
};
Calendar.prototype.setDate = function(td)
{
	this.source.value = this.y + '-' + this.m + '-' + td.innerHTML;
	$d(this.id).style.display = "none";
};
function calendar(obj){new Calendar(obj).create();};
/**********************************与窗口操作相关的脚本**********************************/
var $W = {
	close:function()
	{
	if(arguments.length==1)
			window.opener = null;
		window.close();
	},
	print:function()
	{
	
	    window.print();
	    return;
		var content = arguments[0]||"";
		var w = window.open('');
		w.document.open();
		w.document.write(content);
		w.document.close();
		return w;
	},
	open:function()
	{
		var url = arguments[0]||"";
		var mode = arguments[1]||"_blank";
		var feature = arguments[2]||"location=no,status=no,menubar=no,toolbar=no,resizable=no,top=0,left=0";
		var replace = false;
		var w = window.open(url,mode,feature,replace);
		w.document.title = "自定义窗口|版权所有|365csc.com";
	},
	alert:function()
	{
		var content = arguments[0]||"继续操作么？";
		window.alert(content);
	},
	confirm:function()
	{
		var content = arguments[0]||"继续操作么？";
		return window.confirm(content);
	},
	prompt:function()
	{
		var message = arguments[0]||"";
		var _default = arguments[1]||"";
		return window.prompt(message,_default);
	},
	redirect:function()
	{
		if(arguments.length==0) return;
		var url = arguments[0];
		window.location = url;
	},
	setData:function(data)
	{
		try
	    {
		    if(data.replace(/(^[\s|　]*)|([\s|　]$)/g,"").length==0)
		    {
			    return;
		    }
		    if(window.clipboardData) 
		    {
			    window.clipboardData.setData("Text", data);
		    }
		    else if (window.netscape) 
		    {
		        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		        if (!clip) return;
		        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		        if (!trans) return;
		        trans.addDataFlavor('text/unicode');
		        var str = new Object();
		        var len = new Object();
		        var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		        var copytext=data;
		        str.data=copytext;
		        trans.setTransferData("text/unicode",str,copytext.length*2);
		        var clipid=Components.interfaces.nsIClipboard;
		        if (!clip) return false;
		        clip.setData(trans,null,clipid.kGlobalClipboard);
		    }
		    if(arguments.length==2)
		    {
			    window.alert("[=="+data+"==]已经成功复制到剪贴板上!");
		    }
		    else if(arguments.length == 1)
		    {
		        window.alert("已经成功复制到剪贴板上");
		    }
		    return false;
		}catch(ex){window.alert("您的浏览器不支持直接拷贝，请使用复合键Ctrl+C拷贝！");}
	}
};
/***************************************后台头部检索框*****************************************/
function loadMNavigator(name,objDiv){
    var arrItems = new Array();    
    arrItems[0] = new Array("搜商品","请输入商品关键词",$URL+"/Product/1_________.html");
    arrItems[1] = new Array("逛市场","请输入市场关键词",$URL+"/Site/___.html");
    arrItems[2] = new Array("找店铺","请输入店铺关键词",$URL+"/Shop/List.html");

    this.name = name;
    this.arrItem = arrItems;/*数组*/
    this.currentIndex=0;   /*当前显示第几个*/
    this.div=objDiv;
    this.txtObj=null;
    this.btnObj=null;
    this.count=0;
}
loadMNavigator.prototype.createHtmlLink=function(tabIndex)
{
    if(!this.div)
    {
        alert("加载导航搜索栏必须要有一个容器!");
        return;
    }
    this.currentIndex = tabIndex;
    var sTemp="",sCss="";
    for(var i=0 ; i < this.arrItem.length ; i++)
    {
        sCss = i == this.currentIndex ? "on" :"";
        sTemp +="<li class=\""+ sCss +"\"><a href=\"javaScript:"+ this.name +".setIndex("+ i +")" +"\">"+this.arrItem[i][0]+"</a></li>";
    }
    this.div.innerHTML = sTemp;
    this.txtObj.value = this.arrItem[this.currentIndex][1];
}
loadMNavigator.prototype.setIndex=function(tabIndex)
{
    this.createHtmlLink(tabIndex);
}
loadMNavigator.prototype.initEvents=function()
{
    var currentObj = this;

    $(this.txtObj).keypress(function(e) {
         var key = e.keyCode || e.which;
        if(key == 13) {currentObj.doSearch();return false; }
    }).focus(function(){
        $d(this).select();
    }); 

    $(this.btnObj).click(function(e){ 
            e.stopPropagation();  
        currentObj.doSearch();
        return false;
    }); 
    
    $("body").keypress(function(e){
        var obj = e.srcElement || e.target;
        if(obj && obj.type && obj.type=="textarea" )
        {
            e.stopPropagation();  
            return true;
        }
        var key = e.keyCode || e.which;
        return key==13 ?  false:true;
    })
}

loadMNavigator.prototype.doSearch=function(e)
{

    var value = this.txtObj.value.trim();
    if(value.length == 0 || value.indexOf("请输入")>=0 || value.indexOf("关键词")>=0)
    {
        alert("请输入关键词");
        this.txtObj.select();
        return;
    }
    var searchUrl = this.arrItem[this.currentIndex][2] +"?k="+ encodeURIComponent(this.txtObj.value);
    /*新打开搜索窗口*/
    openLink(this.btnObj,searchUrl);
}

function loadNavigator(name,objDiv){
    
    this.arrItem =[{id:"0",name:"搜商品",url:"/Product/{typeid}_{code}_{marketcode}_{marketlocationcode}_{shopcode}_{areacode}_{siteid}_{shopid}_{roleid}_{page}.html",defaultKey:"请输入商品关键字",urls:["/hot/","/discount/","/new/","/stock/","/group/","/bid/"]},
                  {id:"1",name:"逛市场",url:"/Site/___.html",defaultKey:"请输入市场关键字",urls:["/site/"]},
                  {id:"2",name:"找商铺",url:"/Shop/List.html",defaultKey:"请输入商铺关键字",urls:["/shop/"]}];
    this.name = name;
    this.currentIndex=0;   /*当前显示第几个*/
    this.div=objDiv;
    this.txtObj=null;
    this.btnObj=null;
    this.count=0;
}
loadNavigator.prototype.createHtmlLink=function(tabIndex)
{
    if(!this.div)
    {
        alert("加载导航搜索栏必须要有一个容器!");
        return;
    }
    this.currentIndex = tabIndex;
    var sTemp="",sCss="";
    for(var i=0 ; i < this.arrItem.length ; i++)
    {
        sCss = i == this.currentIndex ? "on" :"";
        sTemp +="<li class=\""+ sCss +"\"><a href=\"javaScript:"+ this.name +".setIndex("+ i +")" +"\">"+this.arrItem[i].name+"</a></li>";
    }
    this.div.innerHTML = sTemp;
    this.initEvents();
    this.txtObj.value = this.arrItem[this.currentIndex].defaultKey;
}
loadNavigator.prototype.setIndex=function(tabIndex)
{
    this.createHtmlLink(tabIndex);
}
loadNavigator.prototype.getCurrentIndex=function()
{
    var curURL = window.location.pathname + window.location.search;
        curURL = curURL.toLowerCase();
    
     for(var i=0 ; i < this.arrItem.length; i ++)
     {
         for(var u in this.arrItem[i].urls)
         {
            if(curURL.indexOf(this.arrItem[i].urls[u].toLowerCase())!=-1)
            {
                 return this.arrItem[i].id;
            }
         }
     }
     return 0;
}
loadNavigator.prototype.initEvents=function()
{
    var currentObj = this;
    if(this.txtObj)
    {
          var k = getParameter("k");
          if(k && k.length>0) this.txtObj.value = decodeURIComponent(k);
          else this.txtObj.value =this.arrItem[this.currentIndex].defaultKey;
    }
    $(this.txtObj).bind("focus",function(){$d(this).select();});
    $(this.txtObj).bind("keypress",function(e){   	
    	var key = e.keyCode || e.which;
        if(key == 13) { currentObj.doSearch(); }
	});
    $(this.btnObj).bind("click",function(){currentObj.doSearch();return false;})
    $("body").keypress(function(e){
        if(e.srcElement && e.srcElement.type && e.srcElement.type=="textarea" )
        {
            e.stopPropagation();  
            return true;
        }
        var key = e.keyCode || e.which;
        return key==13 ?  false:true;
    });
}
loadNavigator.prototype.doSearch=function()
{
    var value = this.txtObj.value.trim();
    if(value.length == 0 || value.indexOf(this.arrItem[this.currentIndex].defaultKey)>=0)
    {
        alert("请输入关键词");
        this.txtObj.select();
        return;
    }
    var searchUrl = this.searchParameter();
    /*新打开搜索窗口*/
    openLink(null,searchUrl);
}
loadNavigator.prototype.searchParameter=function()
{
    return  this.arrItem[this.currentIndex].url +"?k="+ encodeURIComponent(this.txtObj.value);
}
loadNavigator.prototype.pressKeyCode=function(e,obj)
{
    var iKeyCode = window.event?e.keyCode:e.which;
    if(iKeyCode==13)
    {
        this.doSearch(e);
        return false;
    }
    return true;
}

/**************************************传入A对象附链接并打开*****************************************/
function openLink(obj,url,target)
{
    if(!target) target = "_blank"
    try
    {
        if(obj && obj.tagName.toLowerCase() == "a")
        {
            obj.href= url;
            obj.target=target;
        }
        else
        {
            window.open(url,target);
        }
    }
    catch(ex){}
}
/**************************************管理页面中的“全选/反选”操作事件*****************************************/
function selectCheckboxAll(source)
{
    $(":checkbox").each(function(index,obj)
    {
        if($(obj).attr("id").toLowerCase().indexOf("cballchild")>=0)
        {
            if(source.checked) obj.checked = !obj.checked;
            else obj.checked = false;
        }
    });
}
function processCheckboxAll(e,msg)
{   
    var flag = $(":checked[id^=cbAllChild]").length>0;
    var title = "操作警告";
    if(flag)
    {
        return confirm(msg);
        /*
        e = jQuery.event.fix(e);
        e.preventDefault();
        e.stopPropagation();
        $.weeboxs.open(msg,{title:title,onok:function(box){
            box.close();
            $(e.target).removeAttr("onclick").unbind("click").trigger("click");
        }});
        */
    }
    else
    {
        alert("您未选中任何记录，无法继续进行相关操作…");
        //$.weeboxs.open('您未选中任何记录，无法继续进行相关操作…',{title:title,showCancel:false});
        return false;
    }
}
function changeStyle(obj)
{
    var style = [{"color":"#f60"},{"color":"#000"}];
    var os = $(obj).parent("td").parent("tr").children("td");
    if(obj.checked) os.css(style[0]);
    else os.css(style[1]);
}
function addStyleToCheckboxAll()
{
    $("table.content").children("tbody").children("tr").hover(
        function(){$(this).children("td").css({"cursor":"pointer","background-color":"#eee"});},
        function(){$(this).children("td").css({"cursor":"pointer","background-color":"#fff"});}
    );
    $(":checkbox[name='cbAllChild']").click(function(){
        this.checked = !this.checked;
        changeStyle(this);
    });
    
    $(":checkbox[name='cbAllChild']").parent("td").click(function(){
        var cb = $(this).children(":checkbox[name='cbAllChild']");
        if(cb.length == 1)
        {
            cb[0].checked = !cb[0].checked;
            changeStyle(cb[0]);
        }
    });
    $("#cbAll").click(function(){
        $(":checkbox[name='cbAllChild']").each(function(index,obj){
            changeStyle(obj);
        });
    });
}
/********************************通用排序js*************************/
function CommonSort(btn,t,tn,pk)
{
    var txtSort = $("#txtSort_"+pk);
	if(btn.value=="排序")
	{
	    txtSort[0].disabled="";
	    btn.value = "保存";
	    $("#spanSortMsg_"+pk).html("");
	    return;
	}
	var sort = txtSort[0].value;       
	if(!sort.match(/^\d{1,5}$/))
	{
		$("#spanSortMsg_"+pk).html("格式错误(1-99999之间)");
		txtSort[0].select();
		return;
	}
	jQuery.ajax({
		url: '/Ajax/sort.ashx',
		type: 'get',
		data: "t="+t+"&tn=" + tn +"&pk="+pk+"&sv="+ sort + "&r="+Math.random(),
		timeout: 5000,
		error: function(){},
		beforeSend:function(){$("#spanSortMsg_"+pk).html("正在排序…");},
		success: function(result){
		    if(parseInt(result)>=0)
		    {
			    $("#spanSortMsg_"+pk).html("排序成功");
			    txtSort[0].disabled="disabled";
			    btn.value="排序";
			    setTimeout(function(){$("#spanSortMsg_"+pk).html("");},2000);
		    }
		    else
		    {
			    $("#spanSortMsg_"+pk).html("排序失败");
			    txtSort[0].focus();
		    }
		}
	});
}
/*上传类
setting {txtVal:上传文件路径,spanView:预览容器,width:宽,height:高,typeId:类型,sourceId : 店铺的Id,siteId:站点id }

typeId 参数
            1-商品图片
            2-相册图片
            3-店铺Logo
            4-店铺主图
            5-Fckeditor
            6-新闻图片
            7-招商图片
            8-品牌图片
            51-站点Logo
            
btnContainerId : 放置上传按钮的容器
调用方法 :     var up1 = new upload("up1", "spanBtn1", { txtVal: "hiddenPic", spanView: "spanViewImg1", width: 200, height: 200, typeId: 1 ,sourceId:0,siteId:0});
 */
function upload(id,btnContainerId,data,delData)
{
    this.setting = {txtVal:null,spanView:null,width:100,height:100,typeId:1,sourceId:0,siteId:0};
    this.settingDel = {id:"",img:""};
    this.opener =null;
    this.id = id;
    this.btnContainerId = btnContainerId;
    if(data.txtVal)   this.setting.txtVal =  data.txtVal;
    if(data.spanView) this.setting.spanView =  data.spanView;
    if(data.width)    this.setting.width = data.width;
    if(data.height)   this.setting.height =  data.height;
    if(data.typeId)   this.setting.typeId =  data.typeId;
    if(data.sourceId) this.setting.sourceId =  data.sourceId;
    if(data.siteId) this.setting.siteId =  data.siteId;
    
    if(delData && delData.id ) this.settingDel.id = delData.id;
    if(delData && delData.img ) this.settingDel.img = delData.img;
    
    this.appendButton();
    this.deleteButtonInit();
}
upload.prototype.deleteButtonInit = function(){
    var _this = this;
    if(this.settingDel.id.length >0)
    {
         if($("#"+_this.setting.txtVal).val().length == 0)
            $("#"+_this.settingDel.id).hide();
         else
         {
            $("#"+_this.settingDel.id).show().attr("title","清空该图片");
            $("#" + this.settingDel.id).bind("click", function() { 
                
                $("#"+_this.setting.txtVal).val("");
                $("#"+_this.setting.spanView).html("<img height=\""+ _this.setting.height +"\" width=\""+_this.setting.width+"\" border=\"0\" src=\""+_this.settingDel.img+"\">");
                $("#"+_this.settingDel.id).hide();
            }); 
         }
    }
}
/*向容器内追加上传按钮*/
upload.prototype.appendButton = function(){
    if(this.btnContainerId)
    {  
        var btnSpan = document.getElementById(this.btnContainerId);
        if(btnSpan)
        {   var html;
            
            switch(this.setting.typeId)
            {
                case 1: /*上传图片*/
                case 2: 
                case 3: 
                case 4: 
                case 5:
                case 6:
                case 7:
                case 8:
                case 51:
                    html = "<div class=\"UploadPic\" onclick=\""+this.id+ ".open();\"><span >上传图片</span></div>";
                break;
            }
            btnSpan.innerHTML =html;
        }
    }
}
/*
跳转上传页面
*/
upload.prototype.open = function(){
    var url ;
    var data = "?uploader=" + this.id;
    
    if(this.setting.typeId>0)
       data +="&typeId=" + this.setting.typeId 
       
    if(this.setting.sourceId>0) 
       data +="&sourceId=" + this.setting.sourceId 
    
    if(this.setting.siteId>0)
       data +="&siteId=" + this.setting.siteId;
    
    
    switch(this.setting.typeId)
    { 
        case 1: /*上传图片*/
        case 2: 
        case 3: 
        case 4: 
        case 5:
        case 6:
        case 7:
        case 8:
        case 51:
            url = "/Photo/PhotoAdd.aspx" +data;
        break;
    }
     
    if(!this.opener)
    {
      this.opener= openWin(url,1024,768);
    }
    else
    {
      if(typeof(this.opener.body) == "unknown" || typeof(this.opener.body)=="undefined")
          this.opener= openWin(url,1024,768);
      else
        this.opener.focus();
    }
}
/*
关闭上传页面 
*/
upload.prototype.close =function()
{
    this.opener.close();
    this.opener=null;
}
/*
处理上传图片页面选中图片回调方法  data 选择图片的参数
*/
upload.prototype.uploadSucceed=function(data)
{
    var setting = this.setting;

    if(setting.txtVal) 
    {
        if(document.getElementById(setting.txtVal))
            document.getElementById(setting.txtVal).value =  data.src;
    }
    if(setting.spanView)
    {
        if(document.getElementById(setting.spanView))
        {
            var html="";
             if(data.src.indexOf(".swf")>0)
            {
                data.height=100;
                data.width=100;
   
                html = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"{1}\" height=\"{2}\">";
                html += " <param name=\"movie\" value=\"{0}\" />";
                html +=" <param name=\"quality\" value=\"high\" />";
                html +=" <param name=\"wmode\" value=\"opaque\" />";
                html +="  <embed src=\"{0}\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"{1}\" height=\"{2}\" wmode=\"opaque\"></embed>";
                html +="</object>";
   
                html = html.replace(/\{1\}/gi,data.width);
                html = html.replace(/\{2\}/gi,data.height);
                html = html.replace(/\{0\}/gi,data.url);
            }
            else 
            {
                    if (data.width > 0 && data.height > 0)
                    {
                        var w = data.width / setting.width;
                        var h = data.height / setting.height;
                        var p = data.width / data.height;
                        var p1 = data.height / data.width;
                        if (w > 1 || h > 1)
                        {
                            if (w <= h)
                            {
                                data.height = setting.height;
                                data.width = setting.height * p;
                            }
                            else if (w > h)
                            {
                                data.width = setting.width;
                                data.height = setting.width * p1;
                            }
                        }
                    }
                    else
                    {

                    }
                html = "<img height=\""+ data.height +"\" width=\""+data.width+"\" border=\"0\" src=\""+data.url+"\">";    
            }
  	        document.getElementById(setting.spanView).innerHTML = html;
        }
    }
    this.deleteButtonInit(); 
}
/*当选中一张图片的时候，需要调用父页面中的方法回显*/
function selectImg(o)
{
   var fname = getParameter("uploader");
    if(fname && confirm("你确定要应用该张图片吗？"))
    {
        if(fname=="fckeditor")
        {   
            window.top.opener.SetUrl(o.getAttribute("uimageUrl"));
            window.top.close();
            window.top.opener.focus();
            return;
        }
        eval("var pUpload =  window.opener." +fname +";");
        if(pUpload)
        {
            var data= {width:100,height:100,src:null,url:null};
            data.width = o.getAttribute("uwidth");
            data.height = o.getAttribute("uheight");
            data.src = o.getAttribute("usrc");
            data.url = o.getAttribute("uimageUrl")
            pUpload.uploadSucceed(data);
            pUpload.close();
        }
     }
}
/*得到地址栏参数*/
function getParameter(argumentName)
{
    var args = location.search;
    var reg = new RegExp('[\?&]?' + argumentName + '=([^&]*)[&$]?', 'gi');
    var matchs = args.match(reg);
    var val = RegExp.$1;
    if(matchs)
        return val;
    return "";
}
 /*得到正则表达式的源引用Value*/
function getRegExpOrigin(argumentIndex,regexp,queryText)
{
    regexp = regexp || /\/([^\/_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(\d*).html/ig;
    queryText = queryText || location.pathname;
    var val = "";
    var matchs = queryText.match(regexp);
    if(matchs)
    { 
      eval("val =RegExp.$" +argumentIndex );
    }  
    return val;
}
/*居中打开新窗口*/
function openWin(url,width, height, obj) {
    obj = obj || 'Sample';
    var fwidth = document.documentElement.offsetWidth;
    var fheight = document.documentElement.offsetHeight;
    if ($H.isIE) {
        fwidth = document.documentElement.clientWidth;
        fheight = document.documentElement.clientHeight;
    }
    var top = ((fheight - height) / 2);
    var left = ((fwidth - width) / 2);
    if (width > fwidth) left = 0;
    if (height > fheight) top = 0;
    obj = window.open(url, obj, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + '');
    return obj;
}

/***************************H_Template 简单的标签分析替换 Begin**************************************************/
/*简单的标签分析替换*/
function H_Template(inputText) {

    this.html = inputText;
    /*替换一个对象 这个对象支持json格式*/
    this.assignObj = function(jsonObj) {
        if(jsonObj)
        {
          for (var n in jsonObj) {

             this.replaces(n,jsonObj[n]);
             }
        }
    }
    /*替换一个指定的标签*/
    this.assign = function(tagName,tagValue) {
          this.replaces(tagName,tagValue);
    }
    /*加载模板*/
    this.loadTemplate = function(inputText) {
        this.html = inputText;
    }
    /*呈现*/
    this.render = function() {
        return this.html;
    }
    /*判断给定的字符串是否已超出限定的字节长度 全角/中文按两个长度计算*/
    this.isOverBytes= function(s, maxbytes) 
    { 
        var i = 0; 
        var bytes = 0; 
        var uFF61 = parseInt("FF61", 16); 
        var uFF9F = parseInt("FF9F", 16); 
        var uFFE8 = parseInt("FFE8", 16);
        var uFFEE = parseInt("FFEE", 16); 

        while (s && i < s.length) 
        {
            var c = parseInt(s.charCodeAt(i));
            if (c < 256) { 
                bytes = bytes + 1; 
            } 
            else { 
                if ((uFF61 <= c) && (c <= uFF9F)) { 
                    bytes = bytes + 1; 
                } else if ((uFFE8 <= c) && (c <= uFFEE)) { 
                                   bytes = bytes + 1; 
                           } 
                           else { 
                    bytes = bytes + 2; 
                } 
            } 
            if (bytes > maxbytes) { 
                return true; 
            } 
            i = i + 1; 
        } 
        return false; 
    }
    /*左取串*/
    this.left =function(inputText, len) {
              var result = "";
              var i = 0;
              var currLen = 0;
              var currChar = "";
              while (i < inputText.length) {
                  
                  if(i > inputText.length-1)
                    return result;
 
                  currChar= inputText.substring(i,i+1);
                  result +=  currChar ;

                  if (!this.isOverBytes(currChar, 1)) {
                      currLen += 1;
                  }
                  else {
                      currLen += 2;
                  }
                  if (currLen >= len)
                      break;
                  i++;
              }
            //  alert(result);
              return result;
    }
    this.replaces = function(tagName, tagValue) {
        if (!this.html) return "";
        var regTag = new RegExp("(\{" + tagName + ")([^\}])*\}", "ig");

        if (regTag.test(this.html)) {

            var arrMactches = this.html.match(regTag)
            for (var i = 0; i < arrMactches.length; i++) {

                var numberReg = new RegExp("\{(" + tagName + ")(:\\d+)+\}", "ig");
                if (numberReg.test(arrMactches[i])) {
                    var len = arrMactches[i].replace(numberReg, "$2").substring(1);
                    this.html = this.html.replace(arrMactches[i], this.left(tagValue,len));
                }
                else {
                    this.html = this.html.replace(arrMactches[i], tagValue);
                }
            }
        }
    }
}
/***************************H_Template 简单的标签分析替换 End**************************************************/

/***************************收藏 通用脚本开始***********************/
var member = {
          /*(源ID,名称,TypeID:收藏类型[1商品,2商铺],url*/
        favorite : function(sourceId,sourceName,typeId,url)
        {
                    this.test=function(){};
                    var alias="";
                    sourceId = sourceId || 0;
                    if(parseInt(sourceId) ==0 || !sourceName || !typeId)
                    {
                        alert("参数传递错误，无法收藏!");
                        return;
                    }
                    alias= prompt("请输入方便您的记的别名",sourceName);
                    if(!alias)
                    {
                        return;
                    }
                    else if(alias.trim()=="")
                    {
                        alert("别名不能为空，无法收藏！");
                        return;
                    }
                     jQuery.getJSON($URL_P+"/Ajax/Member.ashx?action=memberFavorite&sourceId=" + sourceId + "&alias="+encodeURIComponent(alias)+"&name="+ encodeURIComponent(sourceName)+ "&typeid=" + typeId  + "&url=" + encodeURIComponent(url)+"&jsoncallback=?", "",
                                    function(result){
                                        if(parseInt(result.count)>0)
                                        {
                                          alert("收藏成功");
                                        }
                                        else
                                        {
                                        alert(result.error);
                                        }
                                    }
                     );
                    /*
                       jQuery.ajax({
                                url:'/Ajax/Session.ashx',
                                type: 'get',
                                data: "action=memberFavorite&sourceId=" + sourceId + "&alias="+encodeURIComponent(alias)+"&name="+ encodeURIComponent(sourceName)+ "&typeid=" + typeId  + "&url=" + encodeURIComponent(url),
                                timeout: 5000,
                                dataType: "json",
                                error: function(){
                                },
                                beforeSend:function(){
                                },
                                success: function(result){
                                    if(parseInt(result.count)>0)
                                    {
                                      alert("收藏成功");
                                    }
                                    else
                                    {
                                    alert(result.error);
                                    }
                                }

                        });    */
         },
        favoriteTotal: function(sourceId,typeId,fn)
        {
            jQuery.ajax({
            url:'/Ajax/Session.ashx',
            type: 'get',
            data: "action=memberFavoriteHistory&sourceId=" + sourceId + "&typeid=" + typeId  ,
            timeout: 5000,
            dataType: "json",
            error: function(){
            },
            beforeSend:function(){
            },
            success: function(result){
                if(typeof(fn)=="function")
                fn(result);
                }
            });
        },
        processLogin : function(fn)
        {
            jQuery.getJSON($URL_P+"/Ajax/Member.ashx?action=currentMember&jsoncallback=?", "", fn);
            /*
            jQuery.ajax({
                    url:'/Ajax/Session.ashx',
                    type: 'get',
                    data: "action=currentMember",
                    timeout: 5000,
                    dataType: "json",
                    error: function(){
                       },
                    beforeSend:function(){
                      },
                    success: function(result){
                        if(typeof(fn)=="function")
                        fn(result);
                      }
                });
               */
        }
    };
/***************************收藏 通用脚本结束***********************/
/* 
   sourceId 给谁留言源id 
   typeId 类型 
   0-会员
   1-站点
   2-帮助咨询
*/
var Guestbook = function(name,sourceId,typeId,otherParameters)
{
    this.source = name;
    this.otherParameters = typeof(otherParameters) =="undefined" ?  []  : otherParameters ;
    this.sourceId =  typeof(shopId) == "undefined" ? sourceId : shopId;
    this.typeId =typeId || 0;
    this.type={para:'typeid',v:this.typeId};
    this.name = {para:'n',id:'txtName',pattern:'\.{1,16}',msg:'请输入您的昵称'};
    this.email = {para:'e',id:'txtEmail',pattern:'^[0-9a-zA-Z\\-_\\.]+@[0-9a-zA-Z]+(\\.[0-9a-zA-Z]+)+$',msg:'请输入您的Email,格式:**@**.**'};
    this.telephone = {para:'t',id:'txtTelephone',pattern:'(^\\d{3,4}\\-\\d{7,8}$)|(^\\d{11}$)',msg:'格式:区号-号码或者11位手机号码'};
    this.validateCode = {para:'v',id:'txtValidateCode',pattern:'^\\w{4}$',msg:'请输入4位验证码'};
    this.question = {para:'q',id:'txtQuestion',pattern:'\.{0,128}',msg:''};
    this.isValid = false;
    this.paras = "";
};
Guestbook.prototype.freshValidateCode = function()
{
    $("#"+this.validateCode.id).parent("div").children("img").attr("src", "/validatecode.ashx?r=" + Math.random());
};
Guestbook.prototype.validate = function()
{
    var os = [this.name,this.email,this.telephone,this.validateCode];
    var ops = [this.type];
    for(var i=0; i < this.otherParameters.length ; i ++)
    {
        ops[ops.length] = this.otherParameters[i];
    }
    
    this.isValid = true;
    this.paras = "sid="+this.sourceId;
    for(var i=0;i<os.length;i++)
    {
        var reg = new RegExp(os[i].pattern,"i");
        if(reg.test($("#"+os[i].id).val()))
        {
            $("#"+os[i].id+"Tip").removeClass("help").removeClass("wrong").addClass("right").html("输入正确");
            this.paras += '&'+os[i].para+'='+encodeURIComponent($("#"+os[i].id).val());
        }
        else
        {
            this.isValid = false;
            $("#"+os[i].id+"Tip").removeClass("help").removeClass("right").addClass("wrong").html(os[i].msg);
        }
    }
    /*其它参数处理*/
    for(var i=0; i <ops.length; i++)
    {
         this.paras += '&'+ops[i].para+'='+encodeURIComponent(ops[i].v);
    }
    this.paras += '&'+this.question.para+'='+encodeURIComponent($("#"+this.question.id).val());
};
Guestbook.prototype.reset = function()
{
    var os = [this.name,this.email,this.telephone,this.validateCode,this.question];
    for(var i=0;i<os.length;i++)
    {
        $("#"+os[i].id).val("");
        $("#"+os[i].id+"Tip").removeClass("wrong").removeClass("right").addClass("help").html(os[i].msg);
    }
};
Guestbook.prototype.getHtml = function()
{
    var gb = '<div class="formTitle"><h1>客户留言</h1><span>文明上网 登录发贴</span></div>';
    gb += '<div class="form">';
    gb += '<div><textarea name="txtQuestion" id="txtQuestion" cols="75" rows="6" class="box" tabindex="1"></textarea></div>';
    gb += '<div><label for="name">您的昵称：</label>';
    gb += '<input name="txtName" id="txtName" type="text" tabindex="2" maxlength="16" onblur="'+this.source+'.validate();"/>';
    gb += '<em>*</em><span id="txtNameTip" class="help">请输入您的昵称</span>';
    gb += '</div><div>';
    gb += '<label for="mail">电子邮箱：</label>';
    gb += '<input name="txtEmail" id="txtEmail" type="text" tabindex="3" maxlength="64" onblur="'+this.source+'.validate();"/>';
    gb += '<em>*</em><span id="txtEmailTip" class="help">请输入Email地址,格式：**@**.**</span>';
    gb += '</div><div>';
    gb += '<label for="tel"> 联系电话：</label>';
    gb += '<input name="txtTelephone" id="txtTelephone" type="text" tabindex="4" maxlength="64" onblur="'+this.source+'.validate();"/>';
    gb += '<em>*</em><span id="txtTelephoneTip" class="help">请输入联系电话(或11位手机号)</span>';
    gb += '</div><div>';
    gb += '<label for="check">验 证 码：</label>';
    gb += '<input name="txtValidateCode" id="txtValidateCode" type="text" size="4" tabindex="5" maxlength="4" onblur="'+this.source+'.validate();"/>';
    gb += ' <img src="/validatecode.ashx?r=Math.random()" style="vertical-align: top; height:22px;" /> <span class="font_gray"><a href="javascript: '+this.source+'.freshValidateCode();">刷新验证码</a></span> ';
    gb += '<input type="button" value="马上发表" tabindex="6" onclick="'+this.source+'.submitForm();"/>';
    gb += '</div><div class="mzsm">免责声明：网友评论仅供其表达个人看法，并不表明诚商城同意其观点或证实其描述</div>';
    gb += '</div>';
    return gb;   
};
Guestbook.prototype.submitForm = function()
{
    var self = this;
    self.validate();
    if(!self.isValid){alert("请按照提示填写留言");return;}
    var ps = self.paras;
    jQuery.ajax({
        url: "/guestbook.ashx",
        data: self.paras,
        type: "POST",
        dataType:"json",
        success: function(result) { 
            if(parseInt(result.count)>0) 
            {
                self.reset();
                alert("留言成功");
            }
            else
            {
                alert(result.error);
            }
        }
    });
};
/*站点选择脚本*/
var managerControl ={
    areaCode:"",
    categoryCode:"",
    platformType:1,
    appendOther: [],
    loadSiteList:function(o)
    {
        var _this = this;
        jQuery.ajax({
        url: '/Ajax/ajax.ashx',
        type: 'get',
        data: "act=loadlkjasdflkj&areaCode=" + _this.areaCode +"&code="+ _this.categoryCode + "&pt="+ _this.platformType +"&r="+Math.random(),
        timeout: 5000,
        error: function(){alert("数据加载失败,请刷新后尝试！")},
        dataType:"json",
        beforeSend:function(){},
        success: function(result){
            _this.processResult(o,result);
        }
        });
    }
    ,processResult:function(o,r)
    {
        if(r)o.length =1;
        this.areaCode =  this.areaCode == "0" ? "" : this.areaCode ;
        this.categoryCode =  this.categoryCode == "0" ? "" :  this.categoryCode;
                    
          if(this.appendOther.length>0 && this.areaCode.length==0 && this.categoryCode.length==0)
          {
            for(var i =0 ; i < this.appendOther.length ; i ++)
            {

                var op = new Option(this.appendOther[i].name,this.appendOther[i].id);
                if(this.selectedValue && (this.selectedValue == this.appendOther[i].id)) op.selected=true;
                o.options[o.length] =op;
            }
          }
          if(r)
          {
            for(var i=0; i <r.length; i ++)
            {
                o.options[o.length] =new Option(r[i].name,r[i].id);
            }
          }
    }
    ,onAreaChange:function(obj,siteControl)
    {
        this.areaCode = obj.options[obj.selectedIndex].value;
        this.loadSiteList( document.getElementById(siteControl) );
    }
    ,onCategoryChange:function(obj,siteControl)
    {
        this.categoryCode = obj.options[obj.selectedIndex].value;
        this.loadSiteList( document.getElementById(siteControl) );
    },
    append:function(o,v)
    {
      this.selectedValue = v;
      //alert(o);
      this.processResult(o,null);
    }
};
/***************************购物车开始***********************/
/* sid:源id , ct : 数量 tid : 类型 fn:回调方法*/
var cart = {
    data:"&1=1"
    ,add : function(sid,ct,tid,spid,fn)
    {
        this.exec("add" ,sid,ct,tid,fn,spid);
    }
    ,del: function(sid,ct,tid,fn)
    {  
        this.exec("del",sid,ct,tid,fn);
    }
    ,clear : function(fn)
    {
         this.exec("clear",0,0,0,fn);
    }
    ,loadList : function(fn)
    {
        this.exec("nothing" ,0,0,0,fn);
    }
    ,loadListView : function(fn)
    {
        this.exec("nothing&view=view" ,0,0,0,fn);
    }
    ,exec:function(act,sid,ct,tid,fn,spid)
    {
        spid = spid || 0;
        act += this.data;
        var ca = {"temp": Math.random()};
        jQuery.ajaxSetup({cache:false});
        $.getJSON($URL_P+"/Ajax/ShopingCart.ashx?action="+act+"&sid=" +sid+ "&spid="+ spid+  "&sc="+ ct +"&jsoncallback=?" , ca, fn);
    }
    ,gotoBuy:function(sid,ct,tid,spid)
    {
        sid = sid || 0;
        ct =ct || 0;
        tid=tid || 1;
        spid = spid || 0;
        var action = $URL + "/Member/adminMyShopGm.aspx";
        
   
        
        $("#tempform").remove();
        var  form = $("<form id='tempform'></form>");
        form.attr('action',action);
        form.attr('method','post');
        
        var sourceId = $("<input type='hidden' name='sourceId' />");
        var count = $("<input type='hidden' name='count' />");
        var typeid = $("<input type='hidden' name='typeid' />");
        var shopid = $("<input type='hidden' name='shopid' />");
        
        sourceId.attr('value',sid);
        count.attr('value',ct);
        typeid.attr('value',tid);
        shopid.attr('value',spid);
        
        form.append(sourceId);
        form.append(count);
        form.append(typeid);
        form.append(shopid);
        
        form.appendTo("body");
        form.css('display','none');
        form.submit();
    }
};
/***************************购物车结束***********************/  
-->

