﻿//function $(id){return document.getElementById(id); }

//根据id获得元素
function gid(id){return document.getElementById?document.getElementById(id):null;}

//根据tag获得元素集合
function gname(name){return document.getElementsByTagName?document.getElementsByTagName(name):new Array()}

//html元素decode
function HtmlDecode(text){var re = {'&lt;':'<','&gt;':'>','&amp;':'&','&quot;':'"'};for (i in re) text = text.replace(new RegExp(i,'g'), re[i]);return text;}

function StrCode(str){if(encodeURIComponent) return encodeURIComponent(str);if(escape) return escape(str);}
function UnStrCode(str){if(decodeURIComponent ) return decodeURIComponent (str);if(unescape) return unescape(str);}
function Trim(s){var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);return (m == null)?"":m[1];}

//浏览器信息
function Browser(){
	var ua, s, i;
	this.isIE = false;
	this.isNS = false;
	this.isOP = false;
	this.isSF = false;
	
	ua = navigator.userAgent.toLowerCase();
	s = "opera";
	if ((i = ua.indexOf(s)) >= 0){
	  this.isOP = true;
	  return;
	}
	s = "msie";
	if ((i = ua.indexOf(s)) >= 0) {
	  this.isIE = true;
	  return;
	}
	s = "netscape6/";
	if ((i = ua.indexOf(s)) >= 0) {
	   this.isNS = true;
	   return;
	}
	s = "gecko";
	if ((i = ua.indexOf(s)) >= 0) {
	   this.isNS = true;
	   return;
	}
	s = "safari";
	if ((i = ua.indexOf(s)) >= 0) {
	   this.isSF = true;
	   return;
	}
}

//var lightbox = Class.create();
function lightbox(){

}

lightbox.prototype = {

	yPos : 0,
	xPos : 0,
 	
	activate: function(){
		//if (browser == 'Internet Explorer'){//
		var browser = new Browser();
		if(browser.isIE)//是ie
		{
			this.getScroll();
			this.prepareIE('100%', 'hidden');
			this.setScroll(0,0);
			this.hideSelects('hidden');//隐藏下拉
		}
		
		this.setOverlay(true);
	},
	
	// Ie requires height to 100% and overflow hidden or else you can scroll down past the lightbox
	prepareIE: function(height, overflow){
		bod = document.getElementsByTagName('body')[0];
		bod.style.height = height;
		bod.style.overflow = overflow;
  
		htm = document.getElementsByTagName('html')[0];
		htm.style.height = height;
		htm.style.overflow = overflow; 
	},
	
	// In IE, select elements hover on top of the lightbox
	hideSelects: function(visibility){
		selects = document.getElementsByTagName('select');
		for(i = 0; i < selects.length; i++) {
			selects[i].style.visibility = visibility;
		}
	},
	
	// Taken from lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
	getScroll: function(){
		if (self.pageYOffset) {
			this.yPos = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){
			this.yPos = document.documentElement.scrollTop; 
		} else if (document.body) {
			this.yPos = document.body.scrollTop;
		}
	},
	
	setScroll: function(x, y){
		window.scrollTo(x, y); 
	},
	
	setOverlay: function(show){ //设置遮盖层
		
		if(show){//显示
                var browser = new Browser();
	            var objScreen = gid("ScreenOver");
	            if(!objScreen){
	               objScreen = document.createElement("div");
	            }
	             
                objScreen.id = "ScreenOver"; 
               
                var oS = objScreen.style;
                oS.display = "block";
                oS.top = oS.left = oS.margin = oS.padding = "0px";
                if (document.body.clientHeight)	{
	                var wh = document.body.clientHeight + "px";
                }else if (window.innerHeight){
                    var wh = window.innerHeight + "px";
                }else{
                    var wh = "100%";
                }
                oS.width = "100%";
                oS.height = wh;
                oS.position = "absolute";
                oS.zIndex = "2";
                if ((!browser.isSF) && (!browser.isOP)){
                   oS.background = "#181818";
                }
                else{
                   oS.background = "#F0F0F0";
                }
                oS.filter = "alpha(opacity=40)";
                oS.opacity = 40/100;
                oS.MozOpacity = 40/100;
	            
                bod= document.getElementsByTagName('body')[0];
                //bod.padding = "0px";
                bod.appendChild(objScreen);	            
		}
		else{
		    var objScreen = document.getElementById("ScreenOver");
            if (objScreen) objScreen.style.display = "none";
		}
	},
	
	reset:function(){
	    var browser = new Browser();
		if(browser.isIE)//是ie
		{
			//this.getScroll();
			this.prepareIE('100%', '');
			//this.setScroll(0,0);
			this.hideSelects('visible');//隐藏下拉
			
			this.setOverlay(false);
		}
	}

}


//灰掉页面背景
function ScreenConvert(){
    var obj=new lightbox();
    obj.activate();
}

//恢复背景
function ScreenClean(){
      var obj=new lightbox();
      obj.reset();
}

var t_DiglogX,t_DiglogY,t_DiglogW,t_DiglogH;
function DialogLoc(){
	var dde = document.documentElement;
	if (window.innerWidth){
		var ww = window.innerWidth;
		var wh = window.innerHeight;
		var bgX = window.pageXOffset;
		var bgY = window.pageYOffset;
	}else{
		var ww = dde.offsetWidth;
		var wh = dde.offsetHeight;
		var bgX = dde.scrollLeft;
		var bgY = dde.scrollTop;
	}
	t_DiglogX = (bgX + ((ww - t_DiglogW)/2));
	t_DiglogY = (bgY + ((wh - t_DiglogH)/2));
}

//显示提示对话框
function DialogShow(showdata,ow,oh,w,h){
	var objDialog = document.getElementById("DialogMove");
	if (!objDialog) 
		objDialog = document.createElement("div");
	t_DiglogW = ow;
	t_DiglogH = oh;
	DialogLoc();
	objDialog.id = "DialogMove";
	var oS = objDialog.style;
	oS.display = "block";
	oS.top = t_DiglogY + "px";
	oS.left = t_DiglogX + "px";
	oS.margin = "0px";
	oS.padding = "0px";
	oS.width = w + "px";
	oS.height = h + "px";
	oS.position = "absolute";
	oS.zIndex = "5";
	oS.background = "#FFF";
	oS.border = "solid #000 0px";
	objDialog.innerHTML = showdata;
	//objDialog.onclick=_test;
	document.body.appendChild(objDialog);
     //linkEvent();
    new EventManage.DragEvent("DialogMove");//给层加支持拖拉功能
}



/********    prototype处理层的拖拉     *******/
var EventManage={
    associateObjWithEvent:function(obj, methodName){
        return (function(e){
            e = e||window.event;
            return obj[methodName](e);
        });
    }
};
EventManage.DragEvent=Class.create();
EventManage.DragEvent.prototype={
    initialize : function(handerId,elementId){
        //alert($(handerId));
	    this.hander=$(handerId);
		if(!elementId)elementId=handerId;
        this.element = $(elementId);
		this.element.style.position="absolute";
		this.top=Position.cumulativeOffset(this.element)[1];
		this.left=Position.cumulativeOffset(this.element)[0];
		this.draging=false;
		this.startMouseX=0;
        this.startMouseY=0;
        if(this.hander&&this.element){
		    this.registerEvent();
        }else{
            alert(handerId+' or '+elementId+' no exist!');
		}
    },
	registerEvent : function(){
	    //如果用prototype.js的bind方法注册事件，拖动非图片部分不会出错。拖动图片，出错。
        this.hander.onmousedown = EventManage.associateObjWithEvent(this, "doMouseDown");
		this.hander.onmousemove = EventManage.associateObjWithEvent(this, "doMouseMove");
		//this.hander.onmousedown = this.doMouseDown.bindAsEventListener(this); 
		//this.hander.onmousemove = this.doMouseMove.bindAsEventListener(this); 
		this.hander.onmouseup = EventManage.associateObjWithEvent(this, "doMouseUp");
        this.hander.onmouseout = EventManage.associateObjWithEvent(this, "doMouseOut");
	},
    doMouseDown : function (event){
		this.startMouseX=Event.pointerX(event);
        this.startMouseY=Event.pointerY(event);
        this.hander.style.cursor="move";
		this.draging=true;
		return false;
	},
    doMouseMove : function(event){
        var x=Event.pointerX(event);
		var y=Event.pointerY(event);
		if(this.draging){
            //window.status="startMouseX="+this.startMouseX+""+"startMouseY="+this.startMouseY;  //hide the prompt
            
            var curLeft=this.left;
			curLeft+=x-this.startMouseX;
            this.element.style.left=(curLeft+"px");
            
			var curTop=this.top;
			curTop+=y-this.startMouseY;
            this.element.style.top=(curTop+"px");
		}else{
           // window.status="x="+x+";y="+y; //hide the prompt
		}
		return false;
    },
	doMouseUp : function (event){
        this.hander.style.cursor="default";
		this.top=Position.cumulativeOffset(this.element)[1];
		this.left=Position.cumulativeOffset(this.element)[0];
		this.draging=false;
		return false;
	},
	doMouseOut : function(event){
	    this.doMouseUp(event, this.element);
        return false;
    }
}
/********      prototype处理层的拖拉 [end]    *******/

//隐藏相关
function DialogHide(){
   ScreenClean();
   var objDialog = document.getElementById("DialogMove");
   if (objDialog) objDialog.style.display = "none";
}

//鼠标移到 对话框X 时候出现的效果
function TitleBtnOnMouseOver()
{
  var objShut = document.getElementById('DialogTitleBtn');
  objShut.style.border='solid 1px #000000';
}

//鼠标移出 对话框X 时候出现的效果
function TitleBtnOnMouseOut()
{
  var objShut = document.getElementById('DialogTitleBtn');
  objShut.style.border='solid 1px #EEE';
}
//var vroot=window.location.protocol+"//"+window.location.host;
var vroot="http://passport.cosize.com/";
function QuickLogin(){
   //alert(vroot);
   //alert(vroot+"/Login/LoginCenter.aspx");
   window.location.href=vroot+"Members/Login/LoginCenter.aspx";

}
function QuickRegister(){window.location.href=vroot+"/Register.aspx";}
