var PageUI = {};
var hurl="/gesi/";
PageUI.divs=new Array();
if (typeof PageUI.isGecko == "undefined") {
    var user = navigator.userAgent.toLowerCase();

    PageUI.isGecko     = (user.indexOf("gecko") > -1);
    PageUI.isOpera     = (typeof window.opera != "undefined");
    PageUI.isIe        = (user.indexOf("msie") > -1 && !PageUI.isOpera);
    PageUI.isStrict    = (document.documentElement && document.documentElement.clientHeight);
    PageUI.isSupported = (PageUI.isGecko || PageUI.isOpera || PageUI.isIe);
}
PageUI.Boxer = function(sId){
 	this._id = sId;
 	this._parent  = PageUI.Boxer;
}

PageUI.Boxer.prototype.show = function (url) {
    if (typeof this.element != "undefined")
        return;
    this.element = document.createElement("div");
    this.element.id = this._id;
    this.style = this.element.style;
    this.init(url);	
    document.body.appendChild(this.element);
}
PageUI.Boxer.prototype.hide = function () {
	//alert(typeof(this));
    document.body.removeChild(this.element);
    delete this.element;
    delete this.style;
}
PageUI.Boxer.prototype.setData = function (sData) {
    this.element.innerHTML = sData;
}
PageUI.Boxer.getPageSize = function () {
    var oDocBody = document.body;
    var iScrollWidth, iScrollHeight;
    
    if (PageUI.isGecko) {
        iScrollWidth  = oDocBody.scrollWidth;
	   iScrollHeight = window.innerHeight + window.scrollMaxY;
    } else {
        iScrollWidth  = (oDocBody.scrollWidth > oDocBody.offsetWidth)?oDocBody.scrollWidth:oDocBody.offsetWidth;
        iScrollHeight = (oDocBody.scrollHeight > oDocBody.offsetHeight)?oDocBody.scrollHeight:oDocBody.offsetHeight;
    }
    
    if (!PageUI.isIe) {
        this.windowWidth    = window.innerWidth;
        this.windowHeight   = window.innerHeight;
    } else {
        var oDocObj = (PageUI.isStrict)?document.documentElement:oDocBody;
        this.windowWidth    = oDocObj.clientWidth;
        this.windowHeight   = oDocObj.clientHeight;
    }
    this.pageHeight = (iScrollHeight < this.windowHeight)?this.windowHeight:iScrollHeight;
    this.pageWidth  = (iScrollWidth < this.windowWidth)?this.windowWidth:iScrollWidth;
}
PageUI.Boxer.getTopPosition = function(){
	 if(PageUI.isGecko){
	 	if (document.documentElement && document.documentElement.scrollTop) {
    		return document.documentElement.scrollTop;
 	    }else{
   			return document.body.scrollTop;
 		}
	 }
	 if(PageUI.isIe){
		if (document.documentElement && document.documentElement.scrollTop) {
    		return document.documentElement.scrollTop;
 	    }else{
   			return document.body.scrollTop;
 		}
	 }
}
PageUI.Boxer.getDocHeight = function(){
	 if(PageUI.isGecko){
	 	if(document.body.scrollHeight >= this.pageHeight){
   			return document.body.scrollHeight;
		}else{
			return this.pageHeight;
		}
	 }
	 if(PageUI.isIe){
		if(document.body.scrollHeight >= this.pageHeight){
   			return document.body.scrollHeight;
		}else{
			return this.pageHeight;
		}
	 }
}
PageUI.Boxer.BackScreen = new PageUI.Boxer('back_screen');
//PageUI.Boxer.LoginForm = new PageUI.Boxer('login_form');
PageUI.Boxer.SubForm = new PageUI.Boxer('sub_form');
PageUI.Boxer.SoyiBrowse = new PageUI.Boxer('reg_form');
//PageUI.Boxer.MessageBox = new PageUI.Boxer('message_box');
//PageUI.Boxer.PasswordForm = new PageUI.Boxer('password_form');
//PageUI.Boxer.PmMessageBox = new PageUI.Boxer('pm_message_box');


PageUI.Boxer.BackScreen.init = function(){
	this.style.height   = this._parent.getDocHeight()+"px";
	if(PageUI.isIe){
    	this.style.width    = "100%";
	}else{
		this.style.width    = "100%";
	}
	backHtml = '<iframe id="hideIframe" scrolling="no" frameborder="0" style="position:absolute; top:0px; left:0px;filter=progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);" height="100%" width="100%"></iframe> ';
	this.setData(backHtml);
}

PageUI.Boxer.SoyiBrowse.init = function(url){
	//PageUI.divs.push('generalBox');
	this.style.display='none';
	this.style.position = "absolute";
	this.style.zIndex = 220;
	//this.style.left = ((this._parent.pageWidth-708)/2)+'px';
	this.style.left = 50+'px';
	regHTML = '<div class="generalBox w608" id="generalBox">';
 	regHTML += '<div class="top" id="generalBoxtop"><div class="close"><span onclick="PageUI.Boxer.closeForm();"><img src="'+hurl+'images/clip/close_btn01.gif" width="8" height="8" border="0" onmouseover="javascript:this.src=\''+hurl+'images/clip/close_btn02.gif\'" onmouseout="javascript:this.src=\''+hurl+'images/clip/close_btn01.gif\'" style="cursor:pointer;"/></span></div></div>';
 	regHTML += '<div class="mid">';
	regHTML += '<iframe id="divIframes" name="divIframes" scrolling="no" frameborder="0" height="100%" width="100%" src='+url+'></iframe>';
	regHTML += '</div><div class="btm"></div></div>';
	this.setData(regHTML);	
}

PageUI.Boxer.SubForm.init = function(s){
	//PageUI.divs.push('generalBox');
	this.style.display='none';
	this.style.position = "absolute";
	this.style.zIndex = 220;
	this.style.left = 50+'px';
	regHTML = '<div class="generalBox w308" id="generalBox">';
 	regHTML += '<div class="top" id="generalBoxtop"><div class="close"><span onclick="PageUI.Boxer.closeForm();"><img src="'+hurl+'images/clip/close_btn01.gif" width="8" height="8" border="0" onmouseover="javascript:this.src=\''+hurl+'images/clip/close_btn02.gif\'" onmouseout="javascript:this.src=\''+hurl+'images/clip/close_btn01.gif\'" style="cursor:pointer;"/></span></div></div>';
 	regHTML += '<div class="mid" id="mid" style="height:200px;">';
	regHTML += '<div class="midMsg" id="midMsg"></div>';
	regHTML += '</div><div class="btm"></div></div>';
	this.setData(regHTML);	
}
/*PageUI.Boxer.LoginForm.init = function(){
	this.style.display='none';
	this.style.position = "absolute";
	this.style.zIndex = 220;
	this.style.left = ((this._parent.pageWidth-508)/2)+'px';
	loginHTML = '<div  class="generalBox">';
	loginHTML += ' <div class="top"><div class="close"><span onclick="PageUI.Boxer.closeForm();"><img src="http://www.renren.com/user/images/login/close_btn01.gif" width="8" height="8" border="0"   onmouseover="javascript:this.src=\'http://www.renren.com/user/images/login/close_btn02.gif\'" onmouseout="javascript:this.src=\'http://www.renren.com/user/images/login/close_btn01.gif\'" style="cursor:pointer;"/></span></div></div>';
	loginHTML += ' <div class="mid">';
	loginHTML += '<iframe src\"index.jsp\"></iframe>';
	loginHTML += '</div><div class="btm"></div></div>';
	this.setData(loginHTML);		
}



PageUI.Boxer.MessageBox.init = function (){
	this.style.display='none';
	this.style.position = "absolute";
	this.style.zIndex = 220;
	this.style.left = ((this._parent.pageWidth-508)/2)+'px';
}
PageUI.Boxer.MessageBox.showMessage = function (msg,act){
	PageUI.Boxer.hideOthers(this);
	msgHTML = '<div  class="generalBox">';
 	msgHTML += '<div class="top"><div class="close"><span onclick="PageUI.Boxer.closeForm();"><img src="http://www.renren.com/user/images/login/close_btn01.gif" width="8" height="8" border="0"   onmouseover="javascript:this.src=\'http://www.renren.com/user/images/login/close_btn02.gif\'" onmouseout="javascript:this.src=\'http://www.renren.com/user/images/login/close_btn01.gif\'" style="cursor:pointer;"/></span></div>'
 	msgHTML += '</div>';
 	msgHTML += '<div class="mid">';
	var backStr = '';
	if(act){
		backStr = '<br><br><input  type="image" src="http://www.renren.com/user/images/login/back.gif" onclick="'+act+'();" style="cursor:pointer;">';
	}
 	msgHTML += '<div class="errorBox">'+msg+backStr+'</div></div>';
	msgHTML += '<div class="btm"></div>';
	msgHTML += '</div>';
	this.setData(msgHTML);
}

PageUI.Boxer.PasswordForm.init = function (){
	this.style.display='none';
	this.style.position = "absolute";
	this.style.zIndex = 220;
	this.style.left = ((this._parent.pageWidth-508)/2)+'px';
	regHTML = '<div  class="generalBox">';
 	regHTML += '<div class="top"><div class="close"><span onclick="PageUI.Boxer.closeForm();"><img src="http://www.renren.com/user/images/login/close_btn01.gif" width="8" height="8" border="0"   onmouseover="javascript:this.src=\'http://www.renren.com/user/images/login/close_btn02.gif\'" onmouseout="javascript:this.src=\'http://www.renren.com/user/images/login/close_btn01.gif\'" style="cursor:pointer;"/></span></div></div>';
 	regHTML += '<div class="mid"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="login">';
	regHTML += '  <tr><td colspan="3" align="left"><span id="passwordMsg"  class="color_orange" style="padding-left:3px"></span></td></tr>';
	regHTML += '  <tr><td colspan="2" align="center" width="50%">';
	regHTML += '  			<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">';
	regHTML += '     			 <tr><td align="left"><strong class="font14">找回密码：</strong></td></tr>';
	regHTML += '      			 <tr><td align="left">用户名：<input name="rr_pwduname" id="rr_pwduname" type="text" class="mailInput"   onkeyup="replaceInput(this,event)" onfocus="javascript:this.className=\'mailInputfocus\';$(\'pwdUsernameSpan\').innerHTML=\'\';;" onblur="javascript:this.className=\'mailInput\';"/><span id="pwdUsernameSpan"></span></td></tr>';
	regHTML += '  				 <tr><td align="left" class="color_gray2">如果您注册时填写邮箱有误将无法<br />收到系统邮件！</td></tr>';
	regHTML += '      		</table></td>';
	regHTML += '       <td align="left" class="color_gray2">';
	regHTML += '  			<div class="loginText">';
	regHTML += '      			<p> <img src="http://www.renren.com/user/images/login/arrow2.gif" width="3" height="5" hspace="3" align="absmiddle" />输入您注册时登记的邮箱并提交</p>';
    regHTML += '      			<p>	<img src="http://www.renren.com/user/images/login/arrow2.gif" width="3" height="5" hspace="3" align="absmiddle" />过一会儿，去信箱查收您的密码 </p>';
 	regHTML += '  				<p><img src="http://www.renren.com/user/images/login/arrow2.gif" width="3" height="5" hspace="3" align="absmiddle" />您也可以重新尝试 <input type="button" class="inputRen" value="返回登录" onclick="showLogin();" /> </p>';
	regHTML += '      		</div></td>';
	regHTML += '  </tr>';
	regHTML += '  <tr><td height="40" colspan="2" align="center"><input name="Submit" type="image" value="提交" src="http://www.renren.com/user/images/login/getpsw.gif" align="absmiddle" onclick="sendPwdEmail()" /></td><td></td></tr>';
	regHTML += '  <tr><td height="10" colspan="2" align="center">&nbsp;</td><td>&nbsp;</td></tr>';
	regHTML += '</table>'
	regHTML += '</div><div class="btm"></div></div>';
	this.setData(regHTML);	
}

PageUI.Boxer.PmMessageBox.init = function (){
	this.style.display='none';
	this.style.position = "absolute";
	this.style.zIndex = 220;
	this.style.left = ((this._parent.pageWidth-508)/2)+'px';
}*/
/*弹出新消息提示注册函数*
PageUI.Boxer.showPmListeners=new Array();
PageUI.Boxer.addPmListeners = function(listener) {
	PageUI.Boxer.showPmListeners[PageUI.Boxer.showPmListeners.length]=listener;
}

PageUI.Boxer.PmMessageBox.showPm = function (num){
	for(var i=0;i<PageUI.Boxer.showPmListeners.length;i++){
		var func=PageUI.Boxer.showPmListeners[i];
		func.call();
	}
	if(num==null){
		num=0;
	}
	PageUI.Boxer.hideOthers(this);
	msgHTML = '<div  class="generalBox">';
 	msgHTML += '<div class="top"><div class="close"><span onclick="PageUI.Boxer.closeForm();"><img src="http://www.renren.com/user/images/login/close_btn01.gif" width="8" height="8" border="0"   onmouseover="javascript:this.src=\'http://www.renren.com/user/images/login/close_btn02.gif\'" onmouseout="javascript:this.src=\'http://www.renren.com/user/images/login/close_btn01.gif\'" style="cursor:pointer;"/></span></div>'
 	msgHTML += '</div>';
 	msgHTML += '<div class="mid">';
	msgHTML += '<table width="100%" border="0" cellpadding="0" cellspacing="0" height="200">';
	msgHTML += '	<tr><td align="center" style="font-size:14px;"><img src="http://www.renren.com/user/images/login/pm_message.gif" align="absmiddle" />&nbsp;您好，您有 <font  class="color_orange">'+num+'</font> 条新消息！<a href="/user/message/" target="_blank" onclick="PageUI.Boxer.closeForm();">[<font  class="color_orange">点击查看</font>]</a></td></tr>'
	msgHTML += '</table></div>';
	this.setData(msgHTML);
	
}
*/
PageUI.Boxer.closeFormListeners=new Array();
PageUI.Boxer.closeForm = function(){
		//alert(PageUI.Boxer.closeFormListeners.length);
	PageUI.Boxer.hideOthers();
	for(var i=0;i<PageUI.Boxer.closeFormListeners.length;i++){
		var func=PageUI.Boxer.closeFormListeners[i];
		func.hide();		
	}
	PageUI.Boxer.closeFormListeners.splice(0,PageUI.Boxer.closeFormListeners.length);
}

PageUI.Boxer.addCloseFormListener = function(listener) {
	PageUI.Boxer.closeFormListeners[PageUI.Boxer.closeFormListeners.length]=listener;
}

PageUI.Boxer.hideOthers = function (obj,url) {
	if(obj){
		PageUI.Boxer.addCloseFormListener(obj);
		
		PageUI.Boxer.getPageSize();
		PageUI.Boxer.BackScreen.show();
		obj.show(url);
		/*var topLeave=(obj._parent.getTopPosition()+(obj._parent.windowHeight-300)/2);
		//alert(obj._parent.getTopPosition()+"--"+(obj._parent.windowHeight-300)/2);
		//if(topLeave<=0||topLeave>200){
			alert(obj.style.height);
			obj.style.top = 50+'px';
		//}else{
			//obj.style.top = topLeave+'px';
		//}
		//alert(obj.style.top);
		obj.style.left = ((obj._parent.pageWidth-708)/2)+'px';*/
		var topLeave=(obj._parent.getTopPosition()+(obj._parent.windowHeight-300)/2);
		if(topLeave<=0){
			obj.style.top = 100;
		}else{
			obj.style.top = topLeave+'px';
		}
		obj.style.left = ((obj._parent.pageWidth-508)/2)+'px';
		obj.style.display='';	
	}else{
		///alert(PageUI.divs.join("|"));
		//PageUI.Boxer.SoyiBrowse.hide();
		PageUI.Boxer.BackScreen.hide();
	}
}
//PageUI.Boxer.getPageSize();
//PageUI.Boxer.LoginForm.show();
//PageUI.Boxer.MessageBox.show();
//PageUI.Boxer.PasswordForm.show();
//PageUI.Boxer.PmMessageBox.show();
//PageUI.Boxer.SubForm.show();
