﻿<!--//
var $URL="http://www.365csc.com";
var $URL_USER="http://user.365csc.com";
/**********************************完善系统方法*****************************************/
String.prototype.trim = function()
{
    var s = this;
    return s.replace(/(^\s*)|(\s*$)/g, "");
}
/**********************************与收藏与窗口操作相关的方法*****************************************/
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,"");
		else alert("您的浏览器不支持当前操作！");
	},
	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]);

	}
};
/**********************************与窗口操作相关的脚本**********************************/
var $W = {
	close:function()
	{
	    window.opener = null;
		window.close();
	},
	print:function()
	{
	    window.print();
	    return;
	},
	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+"");
    arrItems[1] = new Array("逛市场","请输入市场关键词",$URL+"");
    arrItems[2] = new Array("找店铺","请输入店铺关键词",$URL+"");

    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.initEvents();
    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){ 
        alert(e.srcElement.id);
        currentObj.doSearch();
        return false;
    }); 
    
    $("body").keypress(function(e){
        e.stopPropagation();  
        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:"/Shop/List.html",defaultKey:"请输入市场关键字",urls:[]},
                  {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;})
}
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: '/SysManager/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].select();
		    }
		}
	});
};
/*站点选择脚本*/
var managerControl ={
    areaCode:"",
    categoryCode:"",
    platformType:1,
    loadSiteList:function(o)
    {
        var _this = this;
        jQuery.ajax({
        url: '/sysmanager/ajax/g.ashx',
        type: 'get',
        data: "act=901&ac=" + _this.areaCode +"&hc="+ _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)
    {
          o.length =1;
          if(r)
          {
            for(var i=0; i <r.length; i ++)
            {
                o.options[i+1] =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) );
    }
};
-->

