﻿//SynPortal所用的Javascript代码

// ************** Jquery Functions **********************************

/* the next line is an example of how you can override default options globally (currently commented out) ... */

// $.fn.cluetip.defaults.tracking = true;
// $.fn.cluetip.defaults.width = 'auto';
$(document).ready(function() {

    //得到本js文件的路径
    var sSiteRoot = new String();

    if (document.getElementById("cluetipcss").href.indexOf("jquery.cluetip.css") > 0) {
        sSiteRoot = document.getElementById("cluetipcss").href.substring(0, document.getElementById("cluetipcss").href.indexOf("jquery.cluetip.css"));
    }

    //	$('input[type=checkbox],input[type=radio]').prettyCheckboxes();


    // jTip theme

    //示例：<a class="jtlc" href="#" rel="p.p1">?</a> 把<p class="p1">hint content</p>的内容显示为提示信息
    //
    //读取本地数据，自动隐藏，用于提示帮助信息
    $('a.jtlc').cluetip({
        local: true,
        hideLocal: true,
        cluetipClass: 'jtip',
        arrows: true,
        dropShadow: false,
        sticky: true,
        mouseOutClose: true,
        hoverIntent: false,
        activation: 'hover',
        width: '480px',
        closePosition: 'title',
        closeText: '<img src="' + sSiteRoot + 'images/cross.png" alt="close" />'
    });


    //读取本地数据，手动隐藏，用于提示帮助信息
    $('a.jtl').cluetip({
        local: true,
        hideLocal: true,
        cluetipClass: 'jtip',
        arrows: true,
        dropShadow: false,
        sticky: true,
        mouseOutClose: false,
        hoverIntent: false,
        activation: 'hover',
        width: '480px',
        closePosition: 'title',
        closeText: '<img src="' + sSiteRoot + 'images/cross.png" alt="close" />'
    });


    //显示短的信息
    //示例：<asp:Label ID="LeftPaneHint" runat="server" CssClass="jt" ToolTip="提示|左侧面板的CSS样式为LeftPane。如不需要此面板，可设定样式{width: 0px;}。"><abbr class="NormalAlert">?</abbr></asp:Label>
    $('span.jt').cluetip({
        splitTitle: '|',
        arrows: true,
        mouseOutClose: true,
        dropShadow: false,
        cluetipClass: 'jtip'
    });

    $('a.jt').cluetip({
        splitTitle: '|',
        arrows: true,
        mouseOutClose: true,
        dropShadow: false,
        cluetipClass: 'jtip',
        width: '360px'
    });

    //读取外部文件：<a class="jtajax" href="ajax5.htm" rel="ajax5.htm">jTip Style clueTip</a>
    $('a.jtajax').cluetip({
        cluetipClass: 'jtip',
        arrows: true,
        dropShadow: false,
        sticky: true,
        mouseOutClose: true,
        ajaxCache: false,
        width: '360px',
        closePosition: 'title',
        closeText: '<img src="' + sSiteRoot + 'images/cross.png" alt="close" />'
    });


    $('span.jtajax').cluetip({
        cluetipClass: 'jtip',
        arrows: true,
        dropShadow: false,
        sticky: true,
        mouseOutClose: true,
        ajaxCache: false,
        width: '360px',
        closePosition: 'title',
        closeText: '<img src="' + sSiteRoot + 'images/cross.png" alt="close" />'
    });


    //Jquery Accordion
    $('ul.accordion').accordion();

    /*  Simple Image Viewer  */
    $("#gallery_output img").not(":first").hide();

    $("#gallery_nav a").click(function() {
        $('#gallery_nav a').removeClass('gallery_nav_active');
        if ($("#" + this.rel).is(":hidden")) {
            $("#gallery_output img").slideUp();
            $("#" + this.rel).slideDown();
            $(this).addClass('gallery_nav_active');
        }
    });


});


//SynPortal的下拉菜单的代码。对于使用relative定位的菜单，此下拉菜单是无效的。
//** Chrome Drop Down Menu- Author: Dynamic Drive (http://www.dynamicdrive.com)

var cssdropdown = {
    disappeardelay: 250, //set delay in miliseconds before menu disappears onmouseout

    dropdownindicator: 'whitedown.gif', //specify the image to add to end of each menu item with a drop down menu
    enablereveal: [true, 5], //enable swipe effect? [true/false, steps (Number of animation steps. Integer between 1-20. Smaller=faster)]
    enableiframeshim: 1, //enable "iframe shim" in IE5.5 to IE7? (1=yes, 0=no)

    //No need to edit beyond here////////////////////////

    dropmenuobj: null, asscmenuitem: null, domsupport: document.all || document.getElementById, standardbody: null, iframeshimadded: false, revealtimers: {},

    getposOffset: function(what, offsettype) {
        var totaloffset = (offsettype == "left") ? what.offsetLeft : what.offsetTop;
        var parentEl = what.offsetParent;
        while (parentEl != null) {
            totaloffset = (offsettype == "left") ? totaloffset + parentEl.offsetLeft : totaloffset + parentEl.offsetTop;
            parentEl = parentEl.offsetParent;
        }
        return totaloffset;
    },

    css: function(el, targetclass, action) {
        var needle = new RegExp("(^|\\s+)" + targetclass + "($|\\s+)", "ig")
        if (action == "check")
            return needle.test(el.className)
        else if (action == "remove")
            el.className = el.className.replace(needle, "")
        else if (action == "add" && !needle.test(el.className))
            el.className += " " + targetclass
    },

    showmenu: function(dropmenu, e) {
        if (this.enablereveal[0]) {
            if (!dropmenu._trueheight || dropmenu._trueheight < 10)
                dropmenu._trueheight = dropmenu.offsetHeight
            clearTimeout(this.revealtimers[dropmenu.id])
            dropmenu.style.height = dropmenu._curheight = 0
            dropmenu.style.overflow = "hidden"
            dropmenu.style.visibility = "visible"
            this.revealtimers[dropmenu.id] = setInterval(function() { cssdropdown.revealmenu(dropmenu) }, 10)
        }
        else {
            dropmenu.style.visibility = "visible"
        }
        this.css(this.asscmenuitem, "selected", "add")
    },

    revealmenu: function(dropmenu, dir) {
        var curH = dropmenu._curheight, maxH = dropmenu._trueheight, steps = this.enablereveal[1]
        if (curH < maxH) {
            var newH = Math.min(curH, maxH)
            dropmenu.style.height = newH + "px"
            dropmenu._curheight = newH + Math.round((maxH - newH) / steps) + 1
        }
        else { //if done revealing menu
            dropmenu.style.height = "auto"
            dropmenu.style.overflow = "hidden"
            clearInterval(this.revealtimers[dropmenu.id])
        }
    },

    clearbrowseredge: function(obj, whichedge) {
        var edgeoffset = 0
        if (whichedge == "rightedge") {
            var windowedge = document.all && !window.opera ? this.standardbody.scrollLeft + this.standardbody.clientWidth - 15 : window.pageXOffset + window.innerWidth - 15
            var dropmenuW = this.dropmenuobj.offsetWidth
            if (windowedge - this.dropmenuobj.x < dropmenuW)  //move menu to the left?
                edgeoffset = dropmenuW - obj.offsetWidth
        }
        else {
            var topedge = document.all && !window.opera ? this.standardbody.scrollTop : window.pageYOffset
            var windowedge = document.all && !window.opera ? this.standardbody.scrollTop + this.standardbody.clientHeight - 15 : window.pageYOffset + window.innerHeight - 18
            var dropmenuH = this.dropmenuobj._trueheight
            if (windowedge - this.dropmenuobj.y < dropmenuH) { //move up?
                edgeoffset = dropmenuH + obj.offsetHeight
                if ((this.dropmenuobj.y - topedge) < dropmenuH) //up no good either?
                    edgeoffset = this.dropmenuobj.y + obj.offsetHeight - topedge
            }
        }
        return edgeoffset
    },

    dropit: function(obj, e, dropmenuID) {
        if (this.dropmenuobj != null) //hide previous menu
            this.hidemenu() //hide menu
        this.clearhidemenu()
        this.dropmenuobj = document.getElementById(dropmenuID) //reference drop down menu
        this.asscmenuitem = obj //reference associated menu item
        this.showmenu(this.dropmenuobj, e)
        this.dropmenuobj.x = this.getposOffset(obj, "left")
        this.dropmenuobj.y = this.getposOffset(obj, "top")
        this.dropmenuobj.style.left = this.dropmenuobj.x - this.clearbrowseredge(obj, "rightedge") + "px"
        this.dropmenuobj.style.top = this.dropmenuobj.y - this.clearbrowseredge(obj, "bottomedge") + obj.offsetHeight + 1 + "px"
        this.positionshim() //call iframe shim function
    },

    positionshim: function() { //display iframe shim function
        if (this.iframeshimadded) {
            if (this.dropmenuobj.style.visibility == "visible") {
                this.shimobject.style.width = this.dropmenuobj.offsetWidth + "px"
                this.shimobject.style.height = this.dropmenuobj._trueheight + "px"
                this.shimobject.style.left = parseInt(this.dropmenuobj.style.left) + "px"
                this.shimobject.style.top = parseInt(this.dropmenuobj.style.top) + "px"
                this.shimobject.style.display = "block"
            }
        }
    },

    hideshim: function() {
        if (this.iframeshimadded)
            this.shimobject.style.display = 'none'
    },

    isContained: function(m, e) {
        var e = window.event || e
        var c = e.relatedTarget || ((e.type == "mouseover") ? e.fromElement : e.toElement)
        while (c && c != m) try { c = c.parentNode } catch (e) { c = m }
        if (c == m)
            return true
        else
            return false
    },

    dynamichide: function(m, e) {
        if (!this.isContained(m, e)) {
            this.delayhidemenu()
        }
    },

    delayhidemenu: function() {
        this.delayhide = setTimeout("cssdropdown.hidemenu()", this.disappeardelay) //hide menu
    },

    hidemenu: function() {
        this.css(this.asscmenuitem, "selected", "remove")
        this.dropmenuobj.style.visibility = 'hidden'
        this.dropmenuobj.style.left = this.dropmenuobj.style.top = "-1000px"
        this.hideshim()
    },

    clearhidemenu: function() {
        if (this.delayhide != "undefined")
            clearTimeout(this.delayhide)
    },

    addEvent: function(target, functionref, tasktype) {
        if (target.addEventListener)
            target.addEventListener(tasktype, functionref, false);
        else if (target.attachEvent)
            target.attachEvent('on' + tasktype, function() { return functionref.call(target, window.event) });
    },

    startchrome: function() {
        if (!this.domsupport)
            return
        this.standardbody = (document.compatMode == "CSS1Compat") ? document.documentElement : document.body
        for (var ids = 0; ids < arguments.length; ids++) {
            var menuitems = document.getElementById(arguments[ids]).getElementsByTagName("a")
            for (var i = 0; i < menuitems.length; i++) {
                if (menuitems[i].getAttribute("rel")) {
                    var relvalue = menuitems[i].getAttribute("rel")
                    var asscdropdownmenu = document.getElementById(relvalue)
                    //不是每一个指定的下拉菜单都有效
                    if (asscdropdownmenu) {
                        this.addEvent(asscdropdownmenu, function() { cssdropdown.clearhidemenu() }, "mouseover")
                        this.addEvent(asscdropdownmenu, function(e) { cssdropdown.dynamichide(this, e) }, "mouseout")
                        this.addEvent(asscdropdownmenu, function() { cssdropdown.delayhidemenu() }, "click")
                        try {
                            //得到本站点的根路径，从而得到图像的绝对路径
                            var sSiteRoot = new String();
                            if (document.getElementById("pagecss").href.lastIndexOf("/") > 0) {
                                sSiteRoot = document.getElementById("pagecss").href.substring(0, document.getElementById("pagecss").href.lastIndexOf("/"));
                            }
                            menuitems[i].innerHTML = menuitems[i].innerHTML + " " + '<img src="' + sSiteRoot + '/images/' + this.dropdownindicator + '" border="0" />&nbsp;';
                        } catch (e) { }
                        this.addEvent(menuitems[i], function(e) { //show drop down menu when main menu items are mouse over-ed
                            if (!cssdropdown.isContained(this, e)) {
                                var evtobj = window.event || e
                                cssdropdown.dropit(this, evtobj, this.getAttribute("rel"))
                            }
                        }, "mouseover")
                        this.addEvent(menuitems[i], function(e) { cssdropdown.dynamichide(this, e) }, "mouseout") //hide drop down menu when main menu items are mouse out
                        this.addEvent(menuitems[i], function() { cssdropdown.delayhidemenu() }, "click") //hide drop down menu when main menu items are clicked on
                    }
                }
            } //end inner for
        } //end outer for
        //	if (this.enableiframeshim && document.all && !window.XDomainRequest && !this.iframeshimadded){ //enable iframe shim in IE5.5 thru IE7?
        //		document.write('<IFRAME id="iframeshim" src="about:blank" frameBorder="0" scrolling="no" style="left:0; top:0; position:absolute; display:none;z-index:90; background: transparent;"></IFRAME>')
        //		this.shimobject=document.getElementById("iframeshim") //reference iframe object
        //		this.shimobject.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'
        //		this.iframeshimadded=true
        //	}
    } //end startchrome

}

// ************** SynPortal Functions **********************************

//倒计时，用于商品的限时购买，如秒杀团购功能
//StartCountDown("clock1", "08/27/2010 12:33 PM -0400", "red")
//StartCountDown("clock2", "08/27/2010 2:00 PM -0400", "#008800")
//Author: Robert Hashemian
//http://www.hashemian.com/

function StartCountDown(myDiv, myTargetDate,zh) {
    var dthen = new Date(myTargetDate);
    var dnow = new Date();
    ddiff = new Date(dthen - dnow);
    gsecs = Math.floor(ddiff.valueOf() / 1000);
    if (zh) CountBackzh(myDiv, gsecs);
    else CountBack(myDiv, gsecs);

}

function Calcage(secs, num1, num2) {
    s = ((Math.floor(secs / num1)) % num2).toString();

    //显示不需要前导0
    // if (s.length < 2) {
    //     s = "0" + s;
    // }
    return (s);
}

function CountBackzh(myDiv, secs) {
    var DisplayStr;
    var DisplayFormat = "%%D%%天 %%H%%小时 %%M%%分 %%S%%秒";

    DisplayStr = DisplayFormat.replace(/%%D%%/g, Calcage(secs, 86400, 100000));
    DisplayStr = DisplayStr.replace(/%%H%%/g, Calcage(secs, 3600, 24));
    DisplayStr = DisplayStr.replace(/%%M%%/g, Calcage(secs, 60, 60));
    DisplayStr = DisplayStr.replace(/%%S%%/g, Calcage(secs, 1, 60));
    if (secs > 0) {
        document.getElementById(myDiv).innerHTML = DisplayStr;
        setTimeout("CountBackzh('" + myDiv + "'," + (secs - 1) + ");", 990);
    }
    else {
        document.getElementById(myDiv).innerHTML = "计时已结束";
    }

}

function CountBack(myDiv, secs) {
    var DisplayStr;
    var DisplayFormat = "%%D%% Days %%H%%:%%M%%:%%S%%";


    DisplayStr = DisplayFormat.replace(/%%D%%/g, Calcage(secs, 86400, 100000));
    DisplayStr = DisplayStr.replace(/%%H%%/g, Calcage(secs, 3600, 24));
    DisplayStr = DisplayStr.replace(/%%M%%/g, Calcage(secs, 60, 60));
    DisplayStr = DisplayStr.replace(/%%S%%/g, Calcage(secs, 1, 60));
    if (secs > 0) {
        document.getElementById(myDiv).innerHTML = DisplayStr;
        setTimeout("CountBack('" + myDiv + "'," + (secs - 1) + ");", 990);
    }
    else {
        document.getElementById(myDiv).innerHTML = "Countdown Timer Stopped";
    }

}


//从URL中解析出来指定name的参数的值


function gup(url, name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(url);
    if (results == null) return "";
    else return results[1];
}

//得到屏幕的X,Y坐标，用于图像的点击放大

function getOffset(evt) {
    var target = evt.target;
    if (target.offsetLeft == undefined) {
        target = target.parentNode;
    }
    var pageCoord = getPageCoord(target);
    var eventCoord =
  {
      x: window.pageXOffset + evt.clientX,
      y: window.pageYOffset + evt.clientY
  };
    var offset =
  {
      offsetX: eventCoord.x - pageCoord.x,
      offsetY: eventCoord.y - pageCoord.y
  };
    return offset;
}

function getPageCoord(element) {
    var coord = { x: 0, y: 0 };
    while (element) {
        coord.x += element.offsetLeft;
        coord.y += element.offsetTop;
        element = element.offsetParent;
    }
    return coord;
}

function getX(evt) {
    var msg = "";
    if (evt.offsetX == undefined) {
        var evtOffsets = getOffset(evt);
        return evtOffsets.offsetX;
    }
    else {
        return evt.offsetX;

    }
}

function getY(evt) {
    var msg = "";
    if (evt.offsetX == undefined) {
        var evtOffsets = getOffset(evt);
        return evtOffsets.offsetY;
    }
    else {
        return evt.offsetY;
    }
}


//实现Hint的功能，用于“友情链接”和“推荐品牌”模块
/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX = 12 //Customize x offset of tooltip
var offsetfromcursorY = 10 //Customize y offset of tooltip

var offsetdivfrompointerX = 10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY = 14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

var rootdomain = "http://" + window.location.hostname + "/"

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<div id="dhtmlpopup" onmouseup="hidesynpopup()"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="' + rootdomain + 'images/arrowhint.gif">') //write out pointer image

var ie = document.all
var ns6 = document.getElementById && !document.all
var enabletip = false
var enablepopup = false


if (ie || ns6)
    var tipobj = document.all ? document.all["dhtmltooltip"] : document.getElementById ? document.getElementById("dhtmltooltip") : ""
var popupobj = document.all ? document.all["dhtmlpopup"] : document.getElementById ? document.getElementById("dhtmlpopup") : ""
var pointerobj = document.all ? document.all["dhtmlpointer"] : document.getElementById ? document.getElementById("dhtmlpointer") : ""

function ietruebody() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}

function syntip(thetext, thewidth, thecolor) {
    if (ns6 || ie) {
        if (typeof thewidth != "undefined") tipobj.style.width = thewidth + "px"
        if (typeof thecolor != "undefined" && thecolor != "") tipobj.style.backgroundColor = thecolor
        tipobj.innerHTML = thetext
        enabletip = true
        return false
    }
}

function synpopup(element, thetext, thecolor) {
    var coord = { x: 0, y: 0 };
    while (element) {
        coord.x += element.offsetLeft;
        coord.y += element.offsetTop;
        element = element.offsetParent;
    }
    //Find out how close the mouse is to the corner of the window
    var winwidth = ie && !window.opera ? ietruebody().clientWidth : window.innerWidth - 20

    if (ns6 || ie) {
        /* the popup is 250px by 250px*/
        if (coord.x - 50 > 0) {
            popupobj.style.left = (coord.x - 50) + "px"
        }
        else if (winwidth - coord.x + 50 < 200) {
            popupobj.style.left = (winwidth - 200) + "px"
        }
        else popupobj.style.left = "0px"
        popupobj.style.top = (coord.y - 80) + "px"
        popupobj.innerHTML = thetext
        popupobj.style.visibility = "visible"
        enablepopup = true;
        return false
    }
}

function positiontip(e) {
    if (enabletip) {
        var nondefaultpos = false
        var curX = (ns6) ? e.pageX : event.clientX + ietruebody().scrollLeft;
        var curY = (ns6) ? e.pageY : event.clientY + ietruebody().scrollTop;
        //Find out how close the mouse is to the corner of the window
        var winwidth = ie && !window.opera ? ietruebody().clientWidth : window.innerWidth - 20
        var winheight = ie && !window.opera ? ietruebody().clientHeight : window.innerHeight - 20

        var rightedge = ie && !window.opera ? winwidth - event.clientX - offsetfromcursorX : winwidth - e.clientX - offsetfromcursorX
        var bottomedge = ie && !window.opera ? winheight - event.clientY - offsetfromcursorY : winheight - e.clientY - offsetfromcursorY

        var leftedge = (offsetfromcursorX < 0) ? offsetfromcursorX * (-1) : -1000

        //if the horizontal distance isn't enough to accomodate the width of the context menu
        if (rightedge < tipobj.offsetWidth) {
            //move the horizontal position of the menu to the left by it's width
            tipobj.style.left = curX - tipobj.offsetWidth + "px"
            nondefaultpos = true
        }
        else if (curX < leftedge)
            tipobj.style.left = "5px"
        else {
            //position the horizontal position of the menu where the mouse is positioned
            tipobj.style.left = curX + offsetfromcursorX - offsetdivfrompointerX + "px"
            pointerobj.style.left = curX + offsetfromcursorX + "px"
        }

        //same concept with the vertical position
        if (bottomedge < tipobj.offsetHeight) {
            tipobj.style.top = curY - tipobj.offsetHeight - offsetfromcursorY + "px"
            nondefaultpos = true
        }
        else {
            tipobj.style.top = curY + offsetfromcursorY + offsetdivfrompointerY + "px"
            pointerobj.style.top = curY + offsetfromcursorY + "px"
        }
        tipobj.style.visibility = "visible"
        if (!nondefaultpos)
            pointerobj.style.visibility = "visible"
        else
            pointerobj.style.visibility = "hidden"
    }
    else if (enablepopup) {

    }
}

function hidesyntip() {
    if (ns6 || ie) {
        enabletip = false
        tipobj.style.visibility = "hidden"
        pointerobj.style.visibility = "hidden"
        tipobj.style.left = "-1000px"
        tipobj.style.backgroundColor = ''
        tipobj.style.width = ''
    }
}

function hidesynpopup() {
    if (ns6 || ie) {
        enablepopup = false
        popupobj.style.visibility = "hidden"
        popupobj.style.left = "-1000px"
        popupobj.style.backgroundColor = ''
        popupobj.style.width = ''

    }
}

document.onmousemove = positiontip







