﻿/// <reference path="jquery-1.4.1.js" />
/// <reference path="jquery.blockUI.js" />

var www =
{
    AddFav: function () {
        var title = document.title.toString();
        var url = window.location.href.toString();
        if (document.all)
            window.external.AddFavorite(url, title);
        else if (window.sidebar)
            window.sidebar.addPanel(title, url, "")
    }
}

$(function () {
    $.ajax(
        {
            type: 'POST',
            url: '/ajax.aspx',
            data: { act: 'getlogin' },
            dataType: 'html',
            success: function (data) {
                if (data.substring(0, 1) == '0') {
                }
                else if (data.length > 0) {
                    $('#glogin').html(data.substr(2));
                }
            }
        });
    $('.glogin_submit').click(function () {
        var email = $('.glogin_email');
        var pwd = $('.glogin_pwd');
        if (email.val() == '' && pwd.val() == '') {
            top.location.href = '/UserLogin.aspx';
            return false;
        }
        if (email.val() == '') {
            email.focus();
            return false;
        }
        if (pwd.val() == '') {
            pwd.focus();
            return false;
        }
        $.ajax(
        {
            type: 'POST',
            url: '/ajax.aspx',
            data: { act: 'login', email: email.val(), pwd: pwd.val() },
            dataType: 'html',
            success: function (data) {
                if (data.substring(0, 1) == '0') {
                    alert(data.substr(2));
                }
                else if (data.length > 0) {
                    $('#glogin').html(data.substr(2));
                }
            }
        });
    });
});

var anni = 1;

function type5_pg(_1) {
    if (anni <= 0) {
        anni = 1;
    }
    var current = anni + _1;
    anni = current;
    $.ajax(
    {
        type: 'GET',
        url: '/ajax.aspx',
        data: { act: 'type5_pg', page: current },
        dataType: 'html',
        success: function (data) {
            $('#type5_content').html(data);
        }
    });
}


function copyToClipboard(txt) {
    if (window.clipboardData) {
        window.clipboardData.clearData();
        window.clipboardData.setData("Text", txt);
        alert("已经成功复制标题及链接，现在可以粘贴到“QQ或MSN即时通讯系统”发给您的好友了！")
    } else if (navigator.userAgent.indexOf("Opera") != -1) {
        window.location = txt;
    } else if (window.netscape) {
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        } catch (e) {
            alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
        }
        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 = txt;
        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);
        alert("已经成功复制标题及链接，现在可以粘贴到“QQ或MSN即时通讯系统”发给您的好友了！")
    }
}

function refer() {
    copyToClipboard(document.title + '\r\n' + self.location.href);
}

$(function () {
    if (document.getElementById('JC_Container')) {
        myCompareList(true, 0);
    }
});

function myCompareList(onoff, id) {
    $.ajax(
    {
        type: 'GET',
        url: '/School/JC.aspx',
        data: { act: 'myCompareList', on: onoff, id: id },
        dataType: 'html',
        success: function (data) {
            $('#JC_Container').html(data);
        },
        error: function () { alert('请求的资源不可用，请重试！'); }
    });
}

function showOffice() {
    $('.area a').each(function () {
        $(this).mousemove(function () {
            lastOffice = parseInt($(this).attr('tag').toString());
            clearTimeout(lastOfficeTimeOut);
            showOfficeDomain(lastOffice);
        });
    });
}

var lastOffice = 0;
var lastOfficeTimeOut = setTimeout("", 2500);

function showOfficeDomain(tag) {
    lastOffice = tag;
    var count = parseInt($('.area a').length);
    if (lastOffice >= count) {
        lastOffice = 0;
    }
    $('.area a').each(function () {
        $(this).removeClass('current');
    });
    $('.officelist .item').hide();

    $('.officelist #officeS' + lastOffice).show();
    $('#officeA' + lastOffice).addClass('current');

    lastOffice++;
    lastOfficeTimeOut = setTimeout(function () { showOfficeDomain(lastOffice) }, "2000");
}

function GetSchoolAdv(id) {
    $.blockUI({ title: 'title', cursor: 'default', css: { top: 60, cursor: 'default' }, message: '<div class="blockUI"><div class="closeA" title="Close" onclick="$.unblockUI();">【 关 闭 】</div><iframe src="http://www.baidu.com" scrolling="no" width="600" height="500" frameborder="0" marginheight="0" marginwidth="0"></iframe></div>' });
}






function ObjOutshow(showId, o) {
    var width = document.documentElement.clientWidth - 3;
    if (window.screen.availHeight < document.body.scrollHeight) {
        height = document.body.scrollHeight;
    } else {
        height = window.screen.availHeight;
    }
    var newobj = document.createElement('div');
    var p = $(o).offset();
    var top = p.top;
    var left = p.left;
    var h = $("#" + showId).height();
    var w = $("#" + showId).width();

    newobj.setAttribute('id', 'bigdiv');
    newobj.style.position = "absolute";
    newobj.style.left = "0px";
    newobj.style.top = "0px";
    newobj.style.background = "#666666";
    newobj.style.width = width + "px";
    newobj.style.height = height + "px";
    newobj.style.opacity = 0;
    newobj.style.filter = "alpha(opacity=0)";
    newobj.style.zIndex = 100001;
    newobj.innerHTML = '<iframe src="javascript:void(0);" id="ss" name="ss" style="position:absolute;top:-5px;left:0;border:none;width:100%;height:100%;background:#666666;filter:alpha(opacity=0);" ></iframe>';
    document.body.appendChild(newobj);
    $("#" + showId).css({ "top": top + "px", "left": left + "px", height: 0, width: 0 });
    $("#" + showId).attr("t", top);
    $("#" + showId).attr("l", left);
    $('#bigdiv').animate({ opacity: 0.65 }, 300, function () {
        $("#" + showId).animate({ height: h + "px", width: w + "px", top: (document.documentElement.clientHeight - h) / 2 + $(window).scrollTop() + "px", left: (width - w) / 2 + "px" }, function () {
            $("#" + showId).height("auto");
            $("#" + showId).width(w);
        })
    });
    $("#" + showId).css('z-index', '100002');
}



function ObjOuthide(o) {
    var h = $("#" + o).height();
    var w = $("#" + o).width();
    $("#" + o).animate({ height: 0, width: 0, left: $("#" + o).attr("l") + "px", top: $("#" + o).attr("t") + "px" }, 300, function () {
        $("#" + o).hide();
        $("#" + o).height("auto");
        $("#" + o).width(w);
    });
    $("#" + o).parent().css('z-index', 0);
    var addId = document.getElementById('bigdiv');
    $('#bigdiv').animate({ opacity: 0 }, 300, function () {
        document.body.removeChild(addId);
    });
}


/*automove*/
function topMove(e) {

    this.speed = 1; 					//移动距离
    this.time = 50; 					//移动时间

    var margin = 0;
    var c = this;

    this.start = function () {
        $(e).append($(e).html()); 	//内容追加
        setInterval(mm, c.time);
    }

    function mm() {
        margin -= c.speed;
        $(e).css("marginTop", margin);
        if (Math.abs(margin) >= c.height) { margin = 0; }
    }
}




function autoScrollTop(e) {

    this.speedTime = 400; 			//每次移动的所用时间
    this.stopTime = 4000; 			//停止多长时间后继续移动
    this.speed = 1; 				//移动距离

    var height = $(e).height(); 	//滚动区域高度
    var margin = 0; 				//scroll变量

    var c = this;

    this.start = function () {
        this.stopTime += this.speedTime;
        $(e).append($(e).html());
        setInterval(move, c.stopTime);
    }

    function move() {
        margin -= c.speed;
        setMargin();
        $(e).animate({ marginTop: margin }, c.speedTime);
    }

    function setMargin() {
        var mAbs = Math.abs(margin);
        if (mAbs >= height + c.speed) {
            margin += height + c.speed;
            $(e).css({ marginTop: 0 });
        }
    }
}





function leftMove(e) {
    var div = $(".top2>div");
    var pWidth = $(".top2").width();
    div.append(div.html());
    var n = div.find("a").size();
    var imgWidth = div.find("a>img").eq(0).width();
    div.width(n * imgWidth);
    setInterval(mm, 15);
    var i = -1;
    function mm() {
        div.css("marginLeft", i);
        i -= 1;
        if (i <= -(n / 2 * imgWidth)) { i = 0; }
    }
}


function autoScrollLeft(e) {

    this.speedTime = 600; 			//每次移动的所用时间
    this.stopTime = 4000; 			//停止多长时间后继续移动
    this.speed = 146; 				//移动距离
    this.width; 					//区域宽度
    this.leftBtn;
    this.rightBtn;

    var leftEvent;
    var rightEvent;
    var margin = 0; 				//scroll变量
    var c = this;

    this.start = function () {
        $(e).width(c.width * 2);
        $(e).append($(e).html());
        this.stopTime += this.speedTime;
        $(c.leftBtn).click(function () { clearEvent(); rightEvent = setInterval(rightMove, c.stopTime); rightMove(); });
        $(c.rightBtn).click(function () { clearEvent(); leftEvent = setInterval(leftMove, c.stopTime); leftMove(); });
        leftEvent = setInterval(leftMove, c.stopTime); 		//向左滚动
        //rightEvent=setInterval(rightMove,c.stopTime);		//向右滚动
    }

    function leftMove() {
        margin -= c.speed;
        setLeftMargin();
        $(e).animate({ marginLeft: margin }, c.speedTime);
    }

    function rightMove() {
        margin += c.speed;
        setRightMargin();
        $(e).animate({ marginLeft: margin }, c.speedTime);
    }

    function setLeftMargin() {			//left with
        var mAbs = Math.abs(margin);
        if (mAbs >= c.width + c.speed) {
            margin += c.width + c.speed;
            $(e).css({ marginLeft: 0 });
            leftMove();
        }
    }

    function setRightMargin() {			//right with
        if (margin > 0) {
            margin -= c.width + c.speed;
            $(e).css({ marginLeft: margin });
            rightMove();
        }
    }


    function clearEvent() { clearInterval(leftEvent); clearInterval(rightEvent); }
	

    function setLeftMargin() {			//left with
        var mAbs = Math.abs(margin);
        if (mAbs >= c.width + c.speed) {
            margin += c.width + c.speed;
            $(e).css({ marginLeft: 0 });
            leftMove();
        }
    }

    function setRightMargin() {			//right with
        if (margin > 0) {
            margin -= c.width + c.speed;
            $(e).css({ marginLeft: margin });
            rightMove();
        }
    }


    function clearEvent() { clearInterval(leftEvent); clearInterval(rightEvent); }

}
