﻿window.attachEvent("onload", function(){CheckMemberState();if (SitePageType==1){CheckMemberBbsPower();}}) ;

var SearchPopupW=320;
var SearchPopupH1=200;
var SearchPopupH2=25;

var LoginPage = '/App_Site/SiteDetail.aspx?ID=216';
var MemberPage = '/App_Site/SiteDetail.aspx?ID=215';
var CommentPage = '/App_Site/SiteDetail.aspx?ID=161';

var xmlhttp;
var urlLocation = "/Common/WebService.asmx/";

var LogID;
var divUserShowID;

var SitePageType =0;
var SiteLogTypeID =0;
var SiteLogCateID =0;
var SiteLogID =0;

var SiteUserID = GetCookie("CurrentMemberID") ;
var SiteUserName = GetCookie("CurrentMemberEmail") ;

function getWebPageTitle()
{
    kdocTitle = document.title;//标题 
    if(kdocTitle == null)
    { 
        var t_titles = document.getElementByTagName("title") 
        if(t_titles && t_titles.length >0) 
        { 
           kdocTitle = t_titles[0]; 
        }else{ 
           kdocTitle = ""; 
        } 
    }
    
    return kdocTitle;
}

function getIEVersonNumber()
{   
   var ua = navigator.userAgent;   
   var IEVerson = '';  
   if (ua.indexOf('MSIE 7.0') > -1)   
   {     
      IEVerson = 'IE7';  
   }   
   else if (ua.indexOf('Firefox') > -1)   
   {     
      IEVerson = 'MOZ';   
   }   
   
   return IEVerson;
}

function setActiveStyleSheet()
{   
    var title = getIEVersonNumber();   
        
    if (title!='')   
    {      
        var str = document.getElementsByTagName('link')[0].href.replace('.css','');      
        document.getElementsByTagName('link')[0].href=str+'_'+title+'.css';   
    }
}

function GetCustomerCity()
{           
    var filePath="/Common/WebService.asmx/GetCustomerCity";
    var data = "";
    
    var txt = "";
    $.ajax({async:false,type:"post",url:filePath,data:data,dataType:"xml",timeout:50000,
        success:function(xml) { txt = $(xml).find("string").text();  }
       });
 
    return txt;
}

function GetLogContent(id)
{       
    LogID = id ;
    var filePath="/Common/WebService.asmx/GetLogContent";
    
    $.ajax({type:"post",url:filePath,data:"LogID="+id,dataType:"xml",timeout:50000,
            success:function(xml) { document.getElementById("divLogContent"+LogID).innerHTML = $(xml).find("string").text();  }
           });
}

function GetLogInfo(id)
{     
    LogID = id ;
    var filePath="/Common/WebService.asmx/GetSearchScanningByLogID";
    
    $.ajax({type:"post",url:filePath,data:"LogID="+id,dataType:"xml",timeout:50000,
        success:function(xml) { work_GetLogInfo($(xml).find("string").text());  }
       });
    
    var url = urlLocation+"GetSearchScanningByLogID";
    var data = "ID="+id;
    
    if (data != "false")
    {
        xmlhttp.open("POST",url,true);
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.setRequestHeader ("Content-Length",data.length);         
        xmlhttp.send(data);      
        xmlhttp.onreadystatechange = work_GetLogInfo;  
    }
}

function work_GetLogInfo(xmlData)
{            
	var titleheight = 25;
	var bordercolor="#336699";
	var titlecolor="#99CCFF";
	
	var sWidth=document.body.scrollWidth;
	var sHeight=document.body.scrollHeight ;
	var bgObj=document.createElement("div");
	
	bgObj.setAttribute('id','bgDiv');
	bgObj.style.position="absolute";
	bgObj.style.top="0";
	bgObj.style.background="#777";
	bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
	bgObj.style.opacity="0.6";
	bgObj.style.left="0";
	bgObj.style.width=sWidth + "px";
	bgObj.style.height=sHeight + "px";
	bgObj.style.zIndex = "10000";
	
	document.body.appendChild(bgObj);
	
	var msgw=780;
	var msgh=540;
	var msgObj=document.createElement("div")
	msgObj.setAttribute("id","msgDiv");
	msgObj.setAttribute("align","center");
	msgObj.style.background="white";
	msgObj.style.border="1px solid " + bordercolor;
	msgObj.style.position = "absolute";
    msgObj.style.left = document.body.clientWidth/2-200 +"px";
    msgObj.style.top =  document.body.scrollTop + 100 + "px";
    msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
    msgObj.style.marginLeft = "-225px" ;
    msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
    msgObj.style.width = msgw + "px";
    msgObj.style.height =msgh + "px";
    msgObj.style.textAlign = "center";
    msgObj.style.lineHeight ="25px";
    msgObj.style.zIndex = "10001";

   var title=document.createElement("div");
   title.setAttribute("id","msgTitle");
   title.setAttribute("align","right");
   title.style.margin="0";
   title.style.padding="3px";
   title.style.background=bordercolor;
   title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
   title.style.opacity="0.75";
   title.style.border="1px solid " + bordercolor;
   title.style.height="18px";
   title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
   title.style.color="white";
   title.style.cursor="pointer";
   title.innerHTML="关闭";
   
   title.onclick=function()
   {
        document.body.removeChild(bgObj);
        document.getElementById("msgDiv").removeChild(title);
        document.body.removeChild(msgObj);
        document.body.style.overflow ="auto";
   }
   
   document.body.appendChild(msgObj);
   document.getElementById("msgDiv").appendChild(title);
   
   var txt=document.createElement("div");
   txt.setAttribute("id","msgTxt");
   txt.setAttribute("vertical-align","top");
   txt.style.overflow = "auto";
   txt.style.height="500px";
   txt.style.margin="1em 0";
   txt.innerHTML = xmlData;
   
   document.getElementById("msgDiv").appendChild(txt);
   document.body.style.overflow ="hidden";
}

function GetUserShowHistory(strListType,strModel,strParams)
{   
    var filePath="/Common/WebService.asmx/GetUserShowHistory";
    var data = "ListType="+strListType+"&strModel="+strModel +"&strParams="+strParams;
    
    $.ajax({type:"post",url:filePath,data:data,dataType:"xml",timeout:50000,
            success:function(xml) { divUserShowID.innerHTML =$(xml).find("string").text(); }
           });
}

function GetSearchPopupByLogID(id)
{
    LogID = id ;
    
    var filePath="/Common/WebService.asmx/GetSearchPopupByLogID";
    var data = "ID="+id;
    
    $.ajax({type:"post",url:filePath,data:data,dataType:"xml",timeout:50000,
            success:function(xml) { work_GetSearchPopupByLogID($(xml).find("string").text()); }
           });
}

function work_GetSearchPopupByLogID(xmlData)
{
    var msgObj=document.createElement("div")
    msgObj.setAttribute("id","msgDivPopup");
    msgObj.setAttribute("class","help_box");
    msgObj.setAttribute("align","left");
    msgObj.style.position = "absolute";
    msgObj.style.background = "#F3FCED";
    msgObj.style.border="1px solid #006600" ;
    msgObj.style.left = document.body.clientWidth-SearchPopupW+"px";
    msgObj.style.top = document.body.clientHeight-SearchPopupH1+"px";
    msgObj.style.width = SearchPopupW + "px";
    msgObj.style.height =SearchPopupH1 + "px";
    msgObj.style.textAlign = "left";
    msgObj.style.lineHeight ="25px";
     
    var title1=document.createElement("div");
    title1.setAttribute("id","msgTitlePopup1");
    title1.setAttribute("class","help_title_name");
    title1.style.position="relative";
    title1.style.margin="0";
    title1.style.opacity="0.75";
    title1.style.height="18px";
    title1.style.width="100%";
    title1.style.textAlign = "left";
    title1.innerHTML="贝贝助手";
    
    var title2=document.createElement("div")
    title2.setAttribute("id","msgTitlePopup2");
    title1.setAttribute("class","help_title_btn");
    title2.style.position="absolute";
    title2.style.margin="0";
    title2.style.opacity="0.75";
    title2.style.border="0";
    title2.style.left="94%";
    title2.style.height="18px";
    title2.style.textAlign = "center";
    title2.style.cursor="pointer";
  
    var lnkTitle=document.createElement("a")
    lnkTitle.setAttribute("id","lnkTitle");
    lnkTitle.setAttribute("href","javascript:void(0)");
                
    lnkTitle.onclick=function()
    {
        if (document.getElementById("imgTitle").getAttribute("src").indexOf("zuixiao.jpg")>-1)
        {
            document.getElementById("imgTitle").setAttribute("src","/App_Images/Popup/zuida.jpg"); 
            document.getElementById("msgTxtPopup").style.display = "";
            document.getElementById("msgDivPopup").style.height = SearchPopupH1 ;
        }
        else
        {
            document.getElementById("imgTitle").setAttribute("src","/App_Images/Popup/zuixiao.jpg"); 
            document.getElementById("msgTxtPopup").style.display = "none";
            document.getElementById("msgDivPopup").style.height = SearchPopupH2 ;
        }
    }
    
    var imgTitle=document.createElement("img")
    imgTitle.setAttribute("id","imgTitle");
    imgTitle.setAttribute("src","/App_Images/Popup/zuida.jpg");
    imgTitle.setAttribute("width","16");
    imgTitle.setAttribute("height","15");
    imgTitle.style.border = "0";

    lnkTitle.appendChild(imgTitle);
    title2.appendChild(lnkTitle);
    title1.appendChild(title2);
    
    var txt=document.createElement("div");
    txt.setAttribute("id","msgTxtPopup");
    txt.setAttribute("vertical-align","top");
    txt.style.overflow = "auto";
    txt.style.margin="1em 0";
    txt.innerHTML = xmlData;

    msgObj.appendChild(title1);
    msgObj.appendChild(txt);
    document.body.appendChild(msgObj);            

    MoveSearchPopup();
}

function MoveSearchPopup() 
{
    if (document.getElementById("msgTxtPopup").style.display == "")
    {
        document.getElementById("msgDivPopup").style.top=document.body.scrollTop+document.body.clientHeight-SearchPopupH1;
    }
    else
    {
        document.getElementById("msgDivPopup").style.top=document.body.scrollTop+document.body.clientHeight-SearchPopupH2;
    }
    setTimeout("MoveSearchPopup();",80)
}

function ShowModelParam(ModelType,ModelParamSetID,ModelParamID,ModelContentID,ModelName,ModelParamValue)
{
    var ModelForm = "ModelFixed.aspx";
    
    switch (ModelType)
    {
        case 2:
          ModelForm = "ModelCategory.aspx";
          break ; 
        case 3:
          ModelForm = "ModelLog.aspx";
          break ;              
        case 4:
          ModelForm = "ModelList.aspx";
          break ; 
        case 7:
          ModelForm = "ModelListCommon.aspx";
          break ; 
        case 5:
          ModelForm = "ModelTag.aspx";
          break ;
        case 6:
          ModelForm = "ModelMenu.aspx";
          break ;
        case 8:
          ModelForm = "ModelMember.aspx";
          break ;
    }
       
    var strFlagModelParamStart = "<!--divModelParamStart-->";
    var strFlagModelParamEnd = "<!--divModelParamEnd-->";
    var strModelParam  = window.showModalDialog("../App_DesignModel/"+ModelForm+"?ModelParamValue="+escape(ModelParamValue.replace(/&/g,"$")),"ShowModelParam","dialogWidth: 540px; dialogHeight:600px; center: Yes; status: 0; help: No;scroll: No;");
    
    if (strModelParam != undefined)
    {
      document.getElementById(ModelParamSetID).setAttribute("title",ModelName +" "+ strModelParam );
      document.getElementById(ModelParamID).setAttribute("title", ModelName +" "+ strModelParam );
      document.getElementById(ModelContentID).setAttribute("title", ModelName +" "+ strModelParam );
    
      document.getElementById(ModelParamID).setAttribute("innerHTML","&nbsp;"+strFlagModelParamStart + strModelParam + strFlagModelParamEnd );
    }
    
}

function ShowModelDesign(ModelType,ModelName)
{
   window.open("../App_DesignModel/ModelDesign.aspx?ModelType="+ModelType+"&ModelName="+ModelName,"ModelDesign","Width: 640px; Height:480px; center: Yes; status: 0; help: No;scroll: No;");
}

function Request(str)
{   
    var url = location.href;
    var r = "";
    if(url==null||url=="")return r;
    if(str==null||str=="")return r;
    if(url.indexOf('?')<0)return r;
    
    var sp1 = url.split('?');
    if(sp1.length<1)return r;
    if(sp1[1].indexOf(str)<0)return r;
    
    var sp2 = sp1[1].split('&');
    if(sp2.length > 1)
    {
        for(var i=0;i<sp2.lenght;i++)
        {
            if(sp2[i].indexOf('=')<0)continue;
            var sp3=sp2[i].split('=');
            if(sp3.length<1)continue;
            if(sp3[0]==str)
            {
                r = sp3[1];
                break;
            }
        }
    }
    else
    {
        if(sp2[0].indexOf('=')<0)return r;
        var sp3=sp2[0].split('=');
        if(sp3.length<1)return r;
        if(sp3[0]==str)r = sp3[1];
    }
    return r;
}

function GetCookie(sName)
{
	var aCookie = document.cookie.split("; ");
	var aStr = "";
	
	for (var i=0; i<aCookie.length; i++)
	{
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0]) 
		{
		    if (aCrumb[1]!="undefined") aStr =aCrumb[1];
		}
	}

	return aStr;
}

function SetCookit (name, value) 
{   
    var Days = 30; 
    var exp  = new Date();   
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}

function DeleteCookie(name) 
{   
    var cval = GetCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires=Mon, 31 Dec 1977 23:59:59 UTC;";
}

function SearchSetValue()
{
    txtSearchValue.value = unescape(Request("SearchValue"));
}

function GotoSearchPage(SearchValue)
{
    window.location.href =  SearchPage+escape(SearchValue)+"&LogTypeID="+0+"&LogCateID="+0;
}

function GotoSearchPage(SearchValue,LogTypeID,LogCateID)
{
    window.location.href =  "/App_Site/SiteSearch.aspx?Title="+escape(SearchValue)+"&LogTypeID="+LogTypeID+"&LogCateID="+LogCateID;
}

function GotoSearchProductPage(Title,TypeID,CateID,Price)
{
    var strLink = '/App_Site/SiteSearchProduct.aspx?Title='+Title;
    
    if (TypeID!="") strLink +='&LogTypeID='+TypeID;
    if (CateID!="") strLink +='&LogCateID='+CateID;
    if (Price!="") strLink +='&Price='+Price;
    
    window.location.href = strLink;
}

function GotoBbsDetailPage(LogID)
{
    window.parent.location.href = '/App_Site/SiteDetail.aspx?ID='+LogID+"&IsCreateOnly=True";
}

function GotoCommentPage()
{
    window.location.href = CommentPage;
}

function GotoLoginPage()
{
    window.location.href = LoginPage;
}

function GotoMemberPage()
{
    window.location.href = MemberPage;
}

function GotoLoginOutPage()
{
    loginout();
}

function CheckMemberState()
{
    if (document.getElementById("divLoginUserName")==null) return ;
          
    if (SiteUserID=="")
    {
        document.getElementById("divLoginUserName").innerText = "";
        if (document.getElementById("divLogin")!=null) document.getElementById("divLogin").style.display="";
        if (document.getElementById("divLogout")!=null) document.getElementById("divLogout").style.display="none";
    }
    else
    {
        document.getElementById("divLoginUserName").innerText = "Hello "+SiteUserName+" ! ";
        if (document.getElementById("divLogin")!=null) document.getElementById("divLogin").style.display="none";
        if (document.getElementById("divLogout")!=null) document.getElementById("divLogout").style.display="";
    }
}

function CheckMemberBbsPower()
{   
    var Elements = document.getElementsByTagName("a");
    var msgs;
    var i;

    for (i=0;i<Elements.length;i++) 
    {
       if (Elements[i].id!="")
       {
            if (Elements[i].id.indexOf("lnkEditBbsMsg_")>-1)
            {
                msgs=Elements[i].id.split("_");
                if (msgs[1]=="" || msgs[1]!=SiteUserID)
                   Elements[i].style.display="none";
            }
       }
    }
}

function SearchChangePage(pageCount,pageIndex)
{
    var i=1;

    for(i=1;i<pageCount ;i++)
    {
        if (i==pageIndex)
        {
            document.getElementById("searchlist_Div"+i).style.display="";
        }
        else
        {
            document.getElementById("searchlist_Div"+i).style.display="none";
        }
    }
}

