﻿var Brower = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/msie ([\d.]+)/)) ? Brower.ie = s[1] :
(s = ua.match(/firefox\/([\d.]+)/)) ? Brower.firefox = s[1] :
(s = ua.match(/chrome\/([\d.]+)/)) ? Brower.chrome = s[1] :
(s = ua.match(/opera.([\d.]+)/)) ? Brower.opera = s[1] :
(s = ua.match(/version\/([\d.]+).*safari/)) ? Brower.safari = s[1] : 0;
if(!document.all)
{
    HTMLElement.prototype.attachEvent=function (type,fn)
    { 
    this.addEventListener(type.substring(2,type.length),fn,false);
    }
    HTMLElement.prototype.detachEvent=function (type,fn)
    {
        this.removeEventListener(type.substring(2,type.length),fn,false);
    }
}
function bind(obj,fn)
{
    return function(){
        fn.apply(obj,arguments);
    };
}
var inputWater={
    init:function(id,emptyClass,hasValueClass)
    {
        this.input = document.getElementById(id);
        this.emptyClass=emptyClass;
        this.hasValueClass=hasValueClass;
        this.tips=this.input.getAttribute("tips");
        this.input.value=this.tips;
        this.input.className=emptyClass;
        this.input.attachEvent("onblur",bind(this,this.blur));
        this.input.attachEvent("onfocus",bind(this,this.focus));
    },
    blur:function()
    {
        if(this.input.value.replace(/^\s*|\s*$/,"")=="")
        {
            this.input.value=this.tips;
            this.input.className=this.emptyClass;
        }
    },
    focus:function()
    {
        this.input.className=this.hasValueClass;
        if(this.input.value.replace(/^\s*|\s*$/,"")==this.tips)
        {
            this.input.value="";
        }
    }
};
var Cookie={
    setCookie:function(sName,sValue,dayOfLive){
        var date=new Date();
        date.setTime(date.getTime()+dayOfLive*24*60*60*1000);
        document.cookie=sName+"="+escape(sValue)+"; expires="+date.toGMTString();
    },
    delCookie:function(sName){
        if(Cookie.getCookie(sName))
        {
            Cookie.setCookie(sName,"",0);
        }
    },
    enableCookie:function(){
        if(navigator.cookiesEnabled)
           return true;
        Cookie.setCookie("testCookie","test",1);
        if(Cookie.getCookie("testCookie")!="")
        {
            Cookie.delCookie("testCookie",0);
            return true;
        }
        return false;
    },
    getCookie:function(sName){
        var aCookie=document.cookie.split("; ");
        for(var i=0;i<aCookie.length;i++)
        {
            var aCrumb=aCookie[i].split("=");
            if(sName==aCrumb[0])
                return unescape(aCrumb[1]);
        }
        return"";
}};
var LightBox={
    hidden:function(id)
    {
        document.getElementById(id).style.display="none";
        document.getElementById("temp_shadowDiv").style.display="none";
    },
    show:function(id)
    {
        //var a = new Drag(id,{Handle: "idHandle"});
        var obj=document.getElementById(id);
        var currentStyle=obj.currentStyle||document.defaultView.getComputedStyle(obj,null);
        var objHeight=parseInt(currentStyle['height'],10);
        var objWidth=parseInt(currentStyle['width'],10);
        var innerArea=function(){
            var height=window.innerHeight||document.documentElement.clientHeight;
            var width=window.innerWidth||document.documentElement.clientWidth;
            return {'height':height,'width':width};
        }
        var objLeft=innerArea().width/2-objWidth/2;
        var objtop=innerArea().height/2-objHeight/2;
        obj.style.left=objLeft+"px";
        if(Brower.ie=="6.0")
        {
            obj.style.top=document.documentElement.scrollTop+objtop+"px";
            obj.style.position="absolute";
        }
        else
        {
            obj.style.top=objtop+"px";
            obj.style.position="fixed";
        }
        //obj.style.position="fixed";
        
        var height=Math.max(document.documentElement.scrollHeight,innerArea().height);
        var width=Math.max(document.documentElement.scrollWidth,innerArea().width);
        var shadowDiv=document.getElementById('temp_shadowDiv');
        if(shadowDiv!=null)
        {
            shadowDiv.style.display="block";
            shadowDiv.style.height=height+"px";
            (Brower.ie=="6.0")&&(shadowDiv.style.width=width+"px");
            
        }
        else
        {
            shadowDiv=document.createElement("div");
            shadowDiv.id="temp_shadowDiv";
            var cssText="position:absolute;top:0px;left:0px;width:100%;width:"+ width +";height:"+ height +"px;opacity=.3;filter:alpha(opacity=50);z-index:1000;";
            shadowDiv.style.cssText+=cssText;
            shadowDiv.style.opacity=0.3;
            shadowDiv.style.cursor="not-allowed";
            shadowDiv.className = "modalShadow";
            var parent = obj.parentNode;
            parent.appendChild(shadowDiv);
        }
        obj.style.display="block";
        obj.style.zIndex=9999;
    }
};
function openNewWindow(url,width,height)
{
    var area = GetScreenArea();
    var top=(area.height-height)/2;
    var left=(area.width-width)/2;
    var featured = "alwaysRaised=yes; top="+top+",left="+ left +",width="+width+",height="+height+",toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no,dependent=yes";
    var a=window.open(url,null,featured);
}
function GetScreenArea()
{
    var height=screen.availHeight;
    var width=screen.availWidth;
    return {height:height,width:width};
}
function JSAddFavorite(url,title)
{
    if ( window.sidebar && "object" == typeof( window.sidebar ) && "function" == typeof( window.sidebar.addPanel ) )
    {
        window.sidebar.addPanel( title, url, title );
    }
    else if ( document.all && "object" == typeof( window.external ) )
    {
        window.external.addFavorite( url, title );
    }
}