﻿//通用库

var D=function(eid){
    return "string" == typeof eid ? document.getElementById(eid) : eid;
}


function SetHome(obj) {
    var url = window.location.href;
    try {
        obj.style.behavior = 'url(#default#homepage)';
        obj.setHomePage(url);
    } catch(e) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } catch(e) {
                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', url);
        }
    }
}

function AddFavorite() {
    var url = window.location.href;
    try {
        window.external.addFavorite(url, document.title);
    } catch(e) {
        try {
            window.sidebar.addPanel(document.title, url, "");
        } catch(e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}




//---------------------------- 弹窗警告部分 BEGIN -----------------------------------------------------------------
//依赖:popup.js

var pop1;
function loginForm(){
    pop1=new Popup({ contentType:1,scrollType:'no',isReloadOnClose:true,width:400,height:160});
    pop1.setContent("contentUrl","simpleform/login.aspx");
    pop1.setContent("title","用户登陆");
    pop1.build();
    pop1.show();
}

function madeForm(brandName, brandId){
    pop1=new Popup({ contentType:1,scrollType:'no',isReloadOnClose:true,width:450,height:200});
    pop1.setContent("contentUrl","simpleform/made.aspx?b=" + brandId);
    pop1.setContent("title","定制-" + brandName);
    pop1.build();
    pop1.show();
}

function alertForm(title,alertStr,callBack,callBackParam){
    pop1=new Popup({ contentType:4,isReloadOnClose:true,width:340,height:100});
    pop1.setContent("title",title);
    pop1.setContent("alertCon",alertStr);
    pop1.setContent("callBack",callBack);
    pop1.setContent("parameter",callBackParam);
    pop1.build();
    pop1.show();

}

var reloadUrl=function(newUrl){
    top.window.location.href=newUrl;
}

//---------------------------- 弹窗警告部分 END -----------------------------------------------------------------

//---------------------------- 登陆验证 BEGIN -----------------------------------------------------------------
//依赖:jquery

//检查是否登陆
function isLogin(){
    var loginStatus = $.ajax({
        url: "ajax/checkLogin.aspx?t="+new Date().getTime(),
        async: false
    }).responseText; 
    
    if(loginStatus=="1"){
        return true;
    }else{
        return false;
    }
    
    
}
//---------------------------- 登陆验证 END -----------------------------------------------------------------

//---------------------------- 搜索 BEGIN -----------------------------------------------------------------
function doSearch(){
    var searchKey=D("searchKey").value;
    var searchCode=D("searchCode").options[D("searchCode").selectedIndex].value;
    var searchPage;
    
    if(searchKey!=""){
        switch(searchCode){
            case "1":
                searchPage="searchMessage.aspx";
                break;
            case "2":
                searchPage="searchAlbum.aspx";
                break;
            case "3":
                searchPage="searchUser.aspx";
                break;
        }
        top.location.href = searchPage+"?q="+encodeURIComponent(searchKey);
    }
}
//---------------------------- 搜索 END -----------------------------------------------------------------

