﻿///<reference path="jquery.intellisense.js"/>
 var $jmodalImg,$jmodalurl;
/*屏蔽键盘*/
function window_onkeydown(){
	//F1=112;F2=113;F3=114,F4=115;F5=116;F6=117;
	if ((event.keyCode==112)||(event.keyCode==113)||(event.keyCode==114)||(event.keyCode==115)||(event.keyCode==116)||(event.keyCode==117)||(event.ctrlKey && event.keyCode==78)||(event.ctrlKey && event.keyCode==80)){ 
		event.keyCode=0;
		event.returnValue=false;
	}
	//屏蔽 ctrl+P 键
	if ((event.ctrlKey)&&(event.keyCode==80)){
		event.keyCode=0;
		event.returnValue=false;
	}
}

function setCookie(name,value)
{
	/*检测参数*/ 
	if(!name || !value)
	{
		/*throw new Error("SetCookie(name,value) 参数必须")*/ 
	}
	var argv = arguments; 
	var argc = arguments.length; 
	var nextyear = new Date();
	nextyear.setFullYear(nextyear.getFullYear() + 1); 
	var c = name + "=" + encodeURIComponent(value) +";path=/;" +"expires=" + nextyear.toGMTString(); 
	document.cookie = c;
};
function getCookie(name)
{ 
	var arg = name + "="; 
	var alen = arg.length; 
	var clen = document.cookie.length; 
	var i = 0; 
	while (i < clen) 
	{ 
		var j = i + alen; 
		if (document.cookie.substring(i, j) == arg)
		{ 
			return getCookieVal (j);  
		} 
		i = document.cookie.indexOf("", i) + 1; 
		if (i == 0){ break; }  
	}
	return null;
};
function getCookieVal (offset)
{ 
	var endstr = document.cookie.indexOf (";", offset); 
	if (endstr == -1)
	{ 
		endstr = document.cookie.length; 
	} 
	return decodeURIComponent(document.cookie.substring(offset, endstr));
};
function indexSearch(parent)
{
    $(".IndexSearch > ul > li > img").each(function(fn){
        if(parent==this)
        {
            hidePanel(this.id);
            this.src=this.src.replace("_b.jpg","_r.jpg");
        }
        else
        {
            this.src=this.src.replace("_r.jpg","_b.jpg");
        }
       });
}
function childSearch(value)
{
    hidePanel(value);
}
function hidePanel(value)
{
    
    if(value=="ss_tab_book")
    {
        $("#searchBook").show();
    }
    else
    {
        $("#searchBook").hide();
    }
        
    if(value=="ss_tab_brand")
    {
        $("#searchBrand").show();
    }else
    {
        $("#searchBrand").hide();
    }
     if(value=="ss_tab_image")
    {
        $("#searchImage").show();
    }else
    {
        $("#searchImage").hide();
    }
     if(value=="ss_tab_sort")
    {
        $("#searchSort").show();
    }else
    {
        $("#searchSort").hide();
    }
     if(value=="ss_tab_display")
    {
        $("#searchDisplay").show();
    }else
    {
        $("#searchDisplay").hide();
    }
    if (value == "ss_tab_Origin")
    {
        $("#searchOrigin").show();
    }else{

        $("#searchOrigin").hide();
    }
    if (value == "ss_tab_region") {
        $("#searchregion").show();
    } else {

        $("#searchregion").hide();
    }
}
// 获取宽度
function getWidth()
{
    var strWidth,clientWidth,bodyWidth;
    clientWidth = document.documentElement.clientWidth;
    bodyWidth = document.body.clientWidth;
    if(bodyWidth > clientWidth){
        strWidth = bodyWidth + 20;
    } else {
        strWidth = clientWidth;
    }
    return strWidth;
}
//获取高度
function getHeight()
{
    var strHeight,clientHeight,bodyHeight;
    clientHeight = document.documentElement.clientHeight;
    bodyHeight = document.body.clientHeight;
    if(bodyHeight > clientHeight){
        strHeight = bodyHeight + 30;
    } else {
        strHeight = clientHeight;
    }
    return strHeight+1000;
}
// 锁屏
function showScreen(id)
{
    var Msg = document.getElementById(id);
    var Bg = document.getElementById('Screen');
    Bg.style.width = getWidth()+'px';
    Bg.style.height = getHeight()+'px';
    document.getElementById(id).style.left=(document.body.clientWidth/2)-200+"px"; // alert(screen.height/2-240);
    document.getElementById(id).style.top=screen.height/2-140+"px";
    Msg.style.display = 'block';
    Bg.style.display = 'block';
}
//解屏
function hideScreen(id)
{
    var Msg = document.getElementById(id);
    var Bg = document.getElementById('Screen');
    Msg.style.display = 'none';
    Bg.style.display = 'none';
}
function submitdateSearch(owner) {
    var cname = $(owner).find("#cname").val();
    var sortid = $(owner).find("#sortid").val();
    var dcid = $(owner).find("#dcid").val();
    var regionid = $(owner).find("#regionid").val();
    var localurl = "http://"+window.location.host;
    if (cname != null && cname.length > 0) {
        localurl += "/" + cname;
    }
    else {
        alert('查询地址有错误！'); return;
    }
    if (sortid != null && sortid.length > 0) {
        if (sortid > 6) {
            localurl += "/" + sortid;
        }
    }
    if (dcid != null && dcid.length > 0) {
        if (dcid > 0) {
            localurl += "/a" + dcid;
        }
    }
    if (regionid != null && regionid.length > 0) {
        if (regionid > 0) {
            localurl += "/b" + regionid;
        }
    }
//alert(localurl); return;
    var sdate = $(owner).find("#d4311").val();
    var edate = $(owner).find("#d4312").val();
    var newUrl;
    if (sdate != null && sdate.length>0 && edate != null && edate.length > 0) {
        newUrl = localurl + "/" + sdate + "_" + edate + "/";
    }
    else if (sdate != null && sdate.length>0) {
        newUrl = localurl + "/" + sdate + "_/";
    }
    else if (edate != null && edate.length > 0) {
        newUrl = localurl + "/" + "_" + edate + "/";
    }
    else {
        alert("请选择查询日期!"); return;
    }
    if (typeof (newUrl) != "undefine") {
        window.location = newUrl;
    }
    else {
        alert('系统错误！'); return;
    }
//    alert(localurl);
//    alert(sdate);
//    alert(edate);
}
function submitSearch(owner)
{
    var diff=$(owner).find("#datediff").val();
    var type=$(owner).find("#searchType").val();
    var scope=$(owner).find("#searchScope").val();
    var keyword = $(owner).find("#txtKeyword").val();
    var ocode = $(owner).find("#origincode").val();
    var origintype = $(owner).find("#origintype").val();
    
    var newUrl;
    switch(type)
    {
        case "book" :
        case "display":
        case "brand":
            newUrl = "/" + type + "/" + scope + "/index_" + diff+"/";
            if (ocode != null && ocode.length > 0) {
                newUrl = "/" + type + "/" + scope + "/index_" + diff + "_" + ocode + "/";
            }
            if (keyword != null && keyword.length > 0) {
                newUrl = newUrl + "/" + encodeURI(keyword) + "/";
            }
            break;
        case "sort":
            if (scope == 0) {
                alert("请选择分类目录"); return;
            }
            newUrl = "/" + type + "/" + scope + "/index_" + diff+"/";
            if (ocode != null && ocode.length > 0) {
                newUrl = "/" + type + "/" + scope + "/index_" + diff + "_" + ocode + "/";
            }
            if (keyword != null && keyword.length > 0) {
                newUrl = newUrl + "/" + encodeURI(keyword) + "/";
            }
            break;
        case "image":
            if (keyword == '' || keyword.length == 0) 
            {
                alert("请填写关键字"); return;
            }
            if (origintype == 2) {
                newUrl = "/Search_list_index.aspx?diff=" + diff + "&keyword=" + encodeURI(keyword);
            }
            else {
                newUrl = "/search.aspx?diff=" + diff + "&keyword=" + keyword;
            }
            break;
    case "origin":
        if (ocode != null && ocode.length > 0) {
            if (origintype == 2) {
                newUrl = "/" + ocode + "/list/";
            }
            else {
                //newUrl = "/" + ocode + "/index_" + diff + "/";
                newUrl = "/" + ocode + "/";
            }
        }
        else {
            alert("请选择来源编号！"); return;
        }
        break;
    case "region":
        if (scope != null && scope.length > 0) {
            newUrl = "/" + scope + "/";
        }
        else {
            alert("请选择地区！"); return;
        }
        break;
    }
    
    if(typeof(newUrl)!="undefine")
    {
        window.location=newUrl;
    }
    else
    {
        alert('此功能暂未开放');        
    }
    //return false;
}
function submitSortSearch(owner) {
    var diff = $(owner).find("#datediffsort").val();
    var scope = $(owner).find("#searchScopesort").val();
    var newUrl;
    if (scope == 0) {
        alert("请选择分类目录"); return;
    }
    newUrl = "/sort/" + scope + "/index_" + diff+"/";
    if (typeof (scope) != "undefine") {
        window.location = newUrl;
    }
    else {
        alert('参数错误！');
    }
}
function submitBookSearch(owner) {
    var diff = $(owner).find("#datediffbook").val();
    var scope = $(owner).find("#searchScopebook").val();
    var newUrl;
    newUrl = "/book/" + scope + "/index_" + diff+"/";
    if (typeof (scope) != "undefine") {
        window.location = newUrl;
    }
    else {
        alert('参数错误！');
    }
}
function submitDisplaySearch(owner) {
    var diff = $(owner).find("#datediffdisplay").val();
    var scope = $(owner).find("#searchScopedisplay").val();
    var newUrl;
    newUrl = "/display/" + scope + "/index_" + diff+"/";
    if (typeof (scope) != "undefine") {
        window.location = newUrl;
    }
    else {
        alert('参数错误！');
    }
}
function submitBrandSearch(owner) {
    var diff = $(owner).find("#datediffbrand").val();
    var scope = $(owner).find("#searchScopebrand").val();
    var newUrl;
    newUrl = "/brand/" + scope + "/index_" + diff+"/";
    if (typeof (scope) != "undefine") {
        window.location = newUrl;
    }
    else {
        alert('参数错误！');
    }
}
function submitImageSearch(owner) {
    var diff = $(owner).find("#datediffimage").val();
    var keyword = $(owner).find("#txtKeyword").val();
    var origintype = $(owner).find("#origintype").val();
    if (keyword == '' || keyword.length == 0 || keyword == '请输入关键字') {
        alert("请输入关键字"); return;
    }
    if (origintype == 2) {
        newUrl = "/Search_list_index.aspx?diff=" + diff + "&keyword=" + encodeURI(keyword);
    }
    else {
        newUrl = "/search.aspx?diff=" + diff + "&keyword=" + keyword;
    }
    window.location = newUrl;
}
function playSlide(intPid, strScript) {
    var intScreenWidth = window.screen.width;

    if (intScreenWidth < 600) {
        alert("分辨率太低，无法正常浏览图片！\n\n请调高您显示器的分辨率，谢谢！");
    }
    else {
        var intWidth = window.screen.availWidth;
        var intHeight = window.screen.availHeight;

        var strState = "dialogWidth=" + intWidth + "px;dialogHeight=" + intHeight + "px;dialogLeft=0;dialogTop=0;help=no;status=no;scroll=no;";
        var strUrl = "/slider/player.aspx?time=" + new Date().getTime() + "&pid=" + intPid + "&_script=" + strScript;
        if (!$.browser.msie) {
            //alert("提示：鞋样图书馆要求必须使用IE浏览器进行浏览！");
            //判断是否手机用户
            var sUserAgent = navigator.userAgent.toLowerCase();
            var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
            var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
            var bIsMidp = sUserAgent.match(/midp/i) == "midp";
            var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
            var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
            var bIsAndroid = sUserAgent.match(/android/i) == "android";
            var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
            var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
            if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
                window.location.href = strUrl;
            }
            else {
                var dWin = window.open(strUrl, "bigimg", strState);
                dWin.moveTo(0, 0);
                dWin.resizeTo(window.screen.width, window.screen.height - 20);
            }
        }
        else {
            var dWin = window.open(strUrl, "bigimg", strState);
            dWin.moveTo(0, 0);
            dWin.resizeTo(window.screen.width, window.screen.height - 20);
        }
        //	    var intWidth = window.screen.availWidth;
        //	    var intHeight = window.screen.availHeight;

        //	    var strState = "dialogWidth=" + intWidth + "px;dialogHeight=" + intHeight + "px;dialogLeft=0;dialogTop=0;help=no;status=no;scroll=no;";
        //	    //var strState = "Status=no,scrollbars=no,resizable=no";

        //	    var strUrl = "/slider/player.aspx?time=" + new Date().getTime() + "&pid=" + intPid + "&_script=" + strScript;

        //	    var dWin = window.open(strUrl, "bigimg", strState);

        //	    dWin.moveTo(0, 0);
        //	    dWin.resizeTo(window.screen.width, window.screen.height - 20);

        //var dWin = window.showModelessDialog(strUrl,window.dialogArguments,strState);
        //$('<iframe width='+intWidth+' height='+intHeight+'>').attr('src', strUrl).appendTo("body").displayBox(); 
    }
}
function slidePlay(intPid)
{
   playSlide(intPid,$("#_script").val());
}
function slidePlaynew(intPid) {
    playSlide(intPid, $("#_scriptnew").val());
}
$(document).ready(function(){
    $jmodalImg=$('#imgPanel').jqm({ajax:'/ajaxpage/favimgpanel.aspx?timestamp='+new Date().getTime(),modal: true,overlay: 30}); 
    $jmodalurl=$('#urlPanel').jqm({ajax:'/ajaxpage/favurlpanel.aspx?timestamp='+new Date().getTime(),modal: true,overlay: 30}); 
    if(window.location.href.indexOf("/book/")>-1)
    {
        $("#bookChilds").show();
        $("#menu_book_over").addClass("menunow");
        $("#menu_brand").hover(
        function(){
            $("#bookChilds").hide();
            $("#brandChilds").show();
        },
        function(){
            $("#brandChilds").hide();
            $("#bookChilds").show();
        }
        );
    }
    else if(window.location.href.indexOf("/brand/")>-1)
    {
         $("#brandChilds").show();
         $("#menu_brand_over").addClass("menunow");
         $("#menu_book").hover(
            function(){
                $("#brandChilds").hide();
                $("#bookChilds").show();
            },
            function(){
                $("#bookChilds").hide();
                $("#brandChilds").show();
            }
         );
    }
    else if(window.location.href.indexOf("/display/")>-1)
    {
        $("#menu_display_over").addClass("menunow");
        $("#menu_book").hover(
        function(){
            $("#bookChilds").show();
        },
        function(){
            $("#bookChilds").hide();
        }
        );
    
        $("#menu_brand").hover(
            function(){
                $("#brandChilds").show();
            },
            function(){
                $("#brandChilds").hide();
            }
        );          
    }
    else if(window.location.href.indexOf("/capture/")>-1)
    {
        $("#menu_capture_over").addClass("menunow");
        $("#menu_book").hover(
        function(){
            $("#bookChilds").show();
        },
        function(){
            $("#bookChilds").hide();
        }
        );
    
        $("#menu_brand").hover(
            function(){
                $("#brandChilds").show();
            },
            function(){
                $("#brandChilds").hide();
            }
        );          
    }
    else if(window.location.href.indexOf("/element/")>-1)
    {
        $("#menu_element_over").addClass("menunow");
        $("#menu_book").hover(
        function(){
            $("#bookChilds").show();
        },
        function(){
            $("#bookChilds").hide();
        }
        );
    
        $("#menu_brand").hover(
            function(){
                $("#brandChilds").show();
            },
            function(){
                $("#brandChilds").hide();
            }
        );          
    }
    else if(window.location.href.indexOf("/design/")>-1)
    {
        $("#menu_design_over").addClass("menunow");
        $("#menu_book").hover(
        function(){
            $("#bookChilds").show();
        },
        function(){
            $("#bookChilds").hide();
        }
        );
    
        $("#menu_brand").hover(
            function(){
                $("#brandChilds").show();
            },
            function(){
                $("#brandChilds").hide();
            }
        );          
    }
    else if(window.location.href.indexOf("/sort/")>-1)
    {
        $("#menu_sort_over").addClass("menunow");
        $("#menu_book").hover(
        function(){
            $("#bookChilds").show();
        },
        function(){
            $("#bookChilds").hide();
        }
        );
    
        $("#menu_brand").hover(
            function(){
                $("#brandChilds").show();
            },
            function(){
                $("#brandChilds").hide();
            }
        );          
          
    }
    else
    {
        $("#bookChilds").hide();
        $("#brandChilds").hide();
        $("#menu_index_over").addClass("Nonce_v3");
        $("#menu_book").hover(
        function(){
            $("#bookChilds").show();
        },
        function(){
            $("#bookChilds").hide();
        }
        );
    
        $("#menu_brand").hover(
            function(){
                $("#brandChilds").show();
            },
            function(){
                $("#brandChilds").hide();
            }
        );
    }  
      $("#favmenu").hover(
      function () {
        $("#favcontext").fadeIn("slow");
      },
       function () {
        $("#favcontext").fadeOut("slow");
      }
    );
    
    
   $.contextMenu.defaults({

    menuStyle : {
      width:"165px"},
    itemStyle :{
      margin:"auto auto auto 4px"
    
    }

    });
    /*后台*/
    $(document).contextMenu('myMenu', {

      bindings: {
        'back': function(t) {
            window.history.go(-1);
        },
        'forward':function(t){
            window.history.go(1);
        },
        'refresh':function(t){
            window.location.reload();
        },
        'myhelper':function(t){
            window.location.href="/member/default.aspx";
        },
        'favorites':function(t){
            window.location.href="/Member/Favorite.aspx";
        },
        'addfavorites':function(t){
            showFavPanel();
            //window.location.href="/Member/Favorite.aspx";
        },
        'emailbox':function(t){
            window.location.href = "/member/MyDemands.aspx";
        },
        'helper':function(t){
        },
        'exit':function(t){
            window.location.href="/Member/Login.Ashx?Action=Logout";
        }
      }
    });
    $(".Pro_C img,.Pro_S img,.Issue_R img,.Issue_L img").contextMenu('demandsMenu',{
        bindings:{
            'addtodemands':function(t){
              $("#addSrc").val(t.src);
              $("#frmSendToDemands").submit();
            }
        }
    });
    

});

$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};

var cpid;
function showImgPanel(pid)
{
    if($("#imgPanel").length==0)
    {
        alert('您还未登录系统，请登录后再使用收藏功能！');
        return;
    }
    cpid=pid;
    $jmodalImg.jqmShow(); 
}
function hidImgPanel(r)
{
    try{
    if(typeof(r)=='undefined'){$(".jqmWindow").jqmHide();return;}
    if(r!='' && r.length>0)
    {
        alert(r);
        $(".jqmWindow").jqmHide();
    }else
    {
        alert('收藏失败：系统忙碌，请稍候再尝试。');
    }}catch(e){}
}
function showFavPanel()
{
    if($("#urlPanel").length==0)
    {
        alert('您还未登录系统，请登录后再使用收藏功能！');
        return;
    }
    $jmodalurl.jqmShow(); 
}
function hidUrlPanel(r) {
    try{
        if (typeof (r) == 'undefined') { $(".jqmWindow").jqmHide(); return; }
    if (parseInt(r) > 2) {
        alert('添加收藏成功！');
        $(".jqmWindow").jqmHide();
    }
    else if (parseInt(r) == 2) {
        alert('推荐成功！');
        $(".jqmWindow").jqmHide();
    }
    else if (parseInt(r) == 1) {
        alert('填写会员号错误，请检查！');
    }
    else {
        alert('收藏失败：系统忙碌，请稍候再尝试。');
    } }catch(e){}
} 
function login_tip(tag)
{
    $("#username").focus();
    alert('提示：登入后才能使用“'+$(tag).text()+'”');
    return false;
}
function login_onSubmit()
{
    try{
        var txtName=$('#username');
        var txtPass=$('#password');
        var txtVerify=$('#verify');
        if(txtName.val()=="" || txtName.val().length==0)
        {
            alert('用户名不能为空.');
            txtName.focus();
            return false;
        } 
        if(txtPass.val()=="" || txtPass.val().length==0)
        {
            alert('用户密码不能为空.');
            txtPass.focus();
            return false;
        }
        if(txtVerify.val()=="" || txtVerify.val().length==0)
        {
            alert('验证码不能为空.');
            txtVerify.focus();
            return false;
        }
        return true;
    }
    catch(e)
    {
        return false;
    }
} 

function favImg()
	{ 
		var intPatternID,intCatalogID,strMemo,strXML;
		var objXmlDoc,objRoot,objNode,objAttribute; 
		/*-------------------------------------------------------------------*/
		var classID = $('#selFavSortIDImg').val();
		var uName = $('#UserName').val();
		//alert(typeof(uName));
		if (typeof (uName) == 'undefined') {
		    uName='';
		}
		else {
		    uName = uName.replace(/^\s+|\s+$/g, "");
		}
		intPatternID =cpid;
		strMemo = $("#FaviMemo").val();
        if(classID==''|| parseInt(classID)==0 || parseInt(classID)=='NaN')
        {
            alert('请指定收藏目录，如果还没有收藏目录，请先创建一个！');
            return;
        }
		if(strMemo.length>20)
		{
		    alert('备注内容请不要超过20个字符！');
		    return;
		}
		/*-------------------------------------------------------------------*/
		$.post("/slider/SaveFavi.ashx", { folderid: classID, pid: intPatternID, remark: strMemo, uName: escape(uName) }, function (r) { hidImgPanel(r); });
        
        
}
function favUrl()
{
    //var classID=$('#ddlClass').val();
    var classID=$('#selFavSortID').val();
    var fName = $('#txtFName').val();
    var uName = $('#UserName').val();
    var cUrl = document.location.href;
    if (typeof (uName) == 'undefined') {
        uName = '';
    }
    else {
        uName = uName.replace(/^\s+|\s+$/g, "");
    }
    if (uName == '') {
        if (classID == '' || parseInt(classID) == 0 || parseInt(classID) == 'NaN') {
            alert('请指定收藏目录，如果还没有收藏目录，请先创建一个！');
            return;
        }
    }
    if(fName=='')
    {
        alert('目录名称必须填写!');return;
    }
    if(fName.length>100)
    {
        alert('目录名称最多不能少过100个字符。请精简后再试');return;
    }
    $.post("/ajaxpage/saveUrl.ashx", { timestamp: new Date().getTime(), classID: classID, fName: escape(fName), fUrl: cUrl, uName: escape(uName) }, function (r) { hidUrlPanel(r) });
}
var curID;
function getDirectory(did,type,cname)
{
    $("#hideDirectoryTree"+curID).hide();
    $("#hideDirectoryTree"+did).load("/AjaxPage/ResultTopDirectory.aspx?did="+did+"&type="+type+"&cname="+cname+"&time="+new Date().getTime()).show("slow");
    curID=did;
}
function restoreDirectory(did,type,cname)
{
    $("#hideDirectoryTree"+did).load("/AjaxPage/ResultTopDirectory.aspx?did="+did+"&type="+type+"&cname="+cname+"&time="+new Date().getTime()).show();
    curID=did;
}
function DownloadDirectoryRar(IndexCoding) {
    var DirectoryRarUrl;
    DirectoryRarUrl = "/API/DownloadDcrar.ashx?code=" + IndexCoding ;
    $('#downrar').attr('src', DirectoryRarUrl);
}
