﻿$(document).ready(function() {
    noticeStartmarquee(28,28,1500); //滚动属性(滚动高度,速度,延迟);
})

// 顶部菜单选中效果
MenuSelectShow();
// 用户登录脚本
LoginUserShow();

// 获取服务器时间
function ServerTimeGet()
{
    var nowtime =  "";

    $.ajax({
        url: "/Handler/HandlerGet.ashx",
        type: 'post', dataType: 'json',
        async:false,
        data: { action: "ServerTimeGet"},
        success: function(data, textStatus) { 
            nowtime = data.time;
        }   
    }) 

    return nowtime;
}

// 顶部搜索
function Search()
{
	var key=$("#txtSearchKey").val();
	var type=$("#drpSearchType").val();

	var url="";
	if (type=="商品")
		url="ProductsSearch.aspx?active=0&key="+key;
	else if (type=="店铺")
		url="ShopsSearch.aspx?active=0&key="+key;
	else if (type=="供求")
		url="publishsSearch.aspx?active=0&key="+key;
	
	if ( url!="" && key!="" )
		window.location.href = encodeURI(url);
	else
		alert("友情提示：\r\n\r\n 请填写搜索关键字");
}

// 存静态上用的页面用户动态
function LoginUserShow()
{
	$.ajax({
		url: "/Handler/HandlerGet.ashx",
		type: 'post', dataType: 'json',
		data: { action: "GetLoginUser" },
		beforeSend:function(XMLHttpRequest){

		},
		complete:function(XMLHttpRequest, textStatus){
			
		},
		success: function(resultData) {
			if (resultData.Status == "1") {
				$("#spanTopOutAndLogin").text("退出"); 
				$("#aTopOutAndLogin").attr({"href":"/Logout.aspx"});        
				$("#spanTopUser").text("您好，"+resultData.username);  
				if (resultData.rankId=="1")
				{
					$("#aTopMy").attr({"href":"/UserManage/UMArticles.aspx"}); 
				}
				else
				{
					$("#aTopMy").attr({"href":"/User/UMyInfoDefault.aspx"}); 
				}      
				
			    $("#htmDivLogined").css({"display":""});
			    $("#htmDivlogining").css({"display":"none"});
			    $("#loginusername").text(resultData.username);      
			}
			else
			{
				$("#spanTopOutAndLogin").text("登录");
				$("#aTopOutAndLogin").attr({"href":"/Login.aspx"});  
				$("#spanTopUser").text("您好，欢迎来到53乐"); 
				$("#aTopMy").attr({"href":"/User/UMyInfoDefault.aspx"}); 
				
			}
		}
	});
}

// 存静态页菜单选择显示
function MenuSelectShow()
{
	var url =String(window.location).toUpperCase();
    
	if (url.indexOf("BIDDINGPTS")!=-1)
	{
	    $("#htmlliBiddingPts").attr({"class":"select"});
	    $("#htmlliDefault").attr({"class":""});
	}
	else if (url.indexOf("XIANSHIPTS")!=-1)
	{
	    $("#htmlliXianShiPts").attr({"class":"select"});
	    $("#htmlliDefault").attr({"class":""});
	}
	else if (url.indexOf("ARTICLES")!=-1)
	{
	    $("#htmlliArticles").attr({"class":"select"});
	    $("#htmlliDefault").attr({"class":""});
	}
	else if (url.indexOf("THEMES")!=-1)
	{
	    $("#htmlliThemes").attr({"class":"select"});
 	    $("#htmlliDefault").attr({"class":""});
	}
	else if (url.indexOf("BIDDINGPTOVERS")!=-1)
	{
	    $("#htmlliBiddingPtOvers").attr({"class":"select"});
 	    $("#htmlliDefault").attr({"class":""});
	}
	else if (url.indexOf("HELP_")!=-1)
	{
	    $("#htmlliHelp").attr({"class":"select"});
 	    $("#htmlliDefault").attr({"class":""});
	}
}

// 店铺弹出框加载
var strUserId;    
function Show(recordId,userId,object) {
   
    if ($("#windowLink").css("display")!="none" && strUserId==userId)
        openSelect(0,200,'windowLink')
    else
    {               
        
        openSelect(0,200,'windowLink');         

        $.ajax({
            url: "/Handler/HandlerGet.ashx",
            type: 'post', dataType: 'json',
            data: { action: "GetShopInfo", recordId: recordId,userId:userId },
            beforeSend:function(XMLHttpRequest){
                openSelect(1,200,'windowProgress');
            },
            complete:function(XMLHttpRequest, textStatus){
                openSelect(0,100,'windowProgress');
            },
            error:function(XMLHttpRequest,textStatus,errorThrown){
                    alert(2);
            },
            success: function(resultData) {
                if (resultData.Status == "1") {
                    strUserId=userId;
                                         
                    $("#htmlSpanShopLogo").html("<a href=\"UCDefault-"+userId+".htm\" >"+"<img src=\""+resultData.logoUrl+"\" height=\"80\">"+"</a>");
                    
                    var introduction = resultData.introduction;
                    $("#htmlSpanIntroduction").html(introduction+"[<a href=\"UCIntroduction-"+userId+".htm\" style=\"color:red;\">详细</a>]");
                    
                    $("#htmLinkUCDefault").attr({"href":"UCDefault-"+userId+".htm"});
                    
                    $("#htmlSpanShopName").html("<a href=\"UCDefault-"+userId+".htm\" >"+resultData.shopname+"</a>");
                    
                    if (resultData.tb!=undefined)
                    {
                        $("#htmLinktb").css({"display":""});
                        $("#htmLinktb").attr({"href":resultData.tb});
                    }
                    else
                    {
                        $("#htmLinktb").css({"display":"none"});
                        $("#htmLinktb").attr({"href":"#"});
                    }
                    
                    if (resultData.pp!=undefined)
                    {
                        $("#htmLinkpp").css({"display":""});
                        $("#htmLinkpp").attr({"href":resultData.pp});
                    }
                    else
                    {
                        $("#htmLinkpp").css({"display":"none"});
                        $("#htmLinkpp").attr({"href":"#"});
                    }
                    
                    if (resultData.ya!=undefined)
                    {
                        $("#htmLinkya").css({"display":""});
                        $("#htmLinkya").attr({"href":resultData.ya});
                    }
                    else
                    {
                        $("#htmLinkya").css({"display":"none"});
                        $("#htmLinkya").attr({"href":"#"});
                    }
                    
                    if (resultData.dl!=undefined)
                    {
                        $("#htmLinkdl").css({"display":""});
                        $("#htmLinkdl").attr({"href":resultData.dl});
                    }
                    else
                    {
                        $("#htmLinkdl").css({"display":"none"});
                        $("#htmLinkdl").attr({"href":"#"});
                    }
                    
                    openSelect(1,200,'windowLink');
                    
                }
            
            }
        });
    }
    
}
 
function noticeStartmarquee(lh,speed,delay) {   //函数 函数名(变量1,变量2,变量3)

    var p=false; //定义变量 p为假;
    var t; //定义变量t了
    var o=document.getElementById("Noticemarqueebox"); //定义变量o为document.getElementById("marqueebox")对象
    if (o==undefined)
        return;
    o.innerHTML+=o.innerHTML; //设置变量o的innerHTML对象为自加
    o.style.marginTop=0; //o的属性，设置或获取对象的上边距宽度
    o.onmouseover=function(){p=true;} //光标在滚动字幕范围内暂停滚动
    o.onmouseout=function(){p=false;} //光标在滚动字幕范围外也就是离开的时候继续滚动

    function start(){ //“开始”函数
        t=setInterval(scrolling,speed); //给前面定义的变量t赋值=自动（滚动，速度）
        if(!p) 
        { 
            o.style.marginTop=parseInt(o.style.marginTop)-1+"px"; //当P为空，属性o的上边距宽度为数字[把变量o上边距宽度转为integer类型，其中parseInt功能为转换]
        }
    }

    function scrolling(){ //“滚动”函数
        if(parseInt(o.style.marginTop)%lh!=0){ //如果对象o的上边距宽度为空，则为0（parseInt为转换作用）
            o.style.marginTop=parseInt(o.style.marginTop)-1+"px"; //上边距宽度为数字[把变量o上边距宽度转为integer类型，其中parseInt功能为转换]
            if(Math.abs(parseInt(o.style.marginTop))>=o.scrollHeight/2) 
            {
                o.style.marginTop=0; //如果计算出来的上边距宽度大于或者等于滚动的高度除以2 则o的上边距宽度为0
            }
        }else{ //否则
            clearInterval(t); //指定T为空
            setTimeout(start,delay);//指定暂停时间(开始，延迟)
        }//相当于end if，表示结束如果
    }//相当于end if，表示结束如果
    //新的开始，不包含在前面的如果里面

    setTimeout(start,delay); //指定暂停时间(开始，延迟)
}

function WantToBuy()
{
    
    var dec = $("#txtWantToBuy").val();
    
    if (dec=="你想购什么?写下来我们帮你找货")
        dec="";

    if (dec=="")
    {
        alert("友情提示：\r\n\r\n 请填写想要买的商品");
        return;
    }
    
	$.ajax({
		url: "/Handler/HandlerGet.ashx",
		type: 'post', dataType: 'json',
		data: { action: "WantToBuy",dec:dec },
		success: function(resultData) {
		
			if (resultData.Status == "1") {
			    $("#txtWantToBuy").val("");
				alert("提交成功，谢谢支持");      
			}
			else if ( resultData.Status == "2" )
			{
                alert("友情提示：\r\n\r\n 请登陆以后再提交想要买的商品");
                window.location.href = "login.aspx";
			}
			else
			{
                alert("友情提示：\r\n\r\n 内容再50个字符以内");
                window.location.href = "login.aspx";
			}
		}
	});  
}



