﻿document.write("<link rel='stylesheet' href='" + sitePath + "css/dialog.css' type='text/css' />");
document.write('<script language="javascript" type="text/javascript" src="/js/dom-drag.js"></script>');
function DialogBox(_width, _height, _title, _content, _top, _left)
{
	var selfObj		=	this;
	this.width		=	_width;
	this.height		=	_height;
	this.title		=	_title;
	this.content	=	_content;
	this.panel		= 	null;
	this.closeBtn	=	null;
	this.mPanel		=	null;
	this.outHidden  =   false;
	this.name       =   "";
	this.reset      =   true;
	this.disTitle   =   true;
	
	this.create = function(){
		var html = "	<div id='dialogNav" + this.name + "' class='dialogNav'>";
			html += "    	<div id='dialogTitle" + this.name + "' class='dialogTitle'></div>";
			html += "        <div id='dialogClose" + this.name + "' class='dialogClose'><img src='"+sitePath+"images/x.gif' width='16' height='16' id='btnClose" + this.name + "' class='btnClose' /></div>";
			html += "    </div>";
			html += "    <div id='dialogContent" + this.name + "' class='dialogContent'></div>";
		this.panel = $("dialogPanel" + this.name);
		if(!this.panel)
		{
			this.panel = document.createElement("div");
			this.panel.id = "dialogPanel" + this.name;
			this.panel.className = "dialogPanel";
			this.panel.style.position = "absolute";
			this.panel.style.left = "0px";
			this.panel.style.top = "0px";
			this.panel.innerHTML = html;
			document.body.appendChild(this.panel);
		}
		this.display();
		if(this.width > 0)
		    this.panel.style.width = this.width + "px";
		if(this.height > 0)
		    this.panel.style.height = this.height + "px";
		this.closeBtn = $("btnClose" + this.name);
		this.closeBtn.onclick = function(){selfObj.close();};
		if(this.outHidden)
		{
		    this.panel.onmouseout = function(){selfObj.close();};
		    this.panel.onmouseover = function(){selfObj.display();};
		}
		this.mPanel = $("dialogContent" + this.name);
		this.mPanel.innerHTML = this.content;
		$("dialogTitle" + this.name).innerHTML = this.title;
		$("dialogTitle" + this.name).style.width = (this.width - 30 -20) + "px";
		if(!this.disTitle)
		    $("dialogNav" + this.name).style.display = "none";
		if(_left + this.panel.offsetWidth > document.body.offsetWidth)
		    this.panel.style.left = document.body.offsetWidth - this.panel.offsetWidth - 10 + "px";
		else
		    this.panel.style.left = _left + "px";
		this.panel.style.top = _top + "px";
		Drag.init($("dialogNav"), this.panel);
	};
	this.display = function(){selfObj.panel.style.visibility = "visible";}
	this.close = function(){
	    selfObj.panel.style.visibility = "hidden";
	    var frms = selfObj.mPanel.getElementsByTagName("iframe");
	    for(var i=0;i<frms.length; i++)
	        frms[i].src = "";
	}
}

//更改在线状态
function showResposeState(onlineId, popCtl, disCtl)
{
	var selfObj		=	this;
	this.disCtl		=	$(disCtl);
	var html = "<select name='rspState' id='rspState'><option value='1'>在线</option><option value='2'>隐身</option></select>";
	html += " <input type='button' name='btnDialogSave' id='btnDialogSave' value='保存' />";
	var xy = getPos(popCtl);
	var dialog = new DialogBox(150, 60, "修改会话状态", html, xy.y + popCtl.offsetHeight, xy.x);	
	dialog.create();
	$("btnDialogSave").onclick = function(){
		var rspState = $("rspState");
		if(rspState.options[rspState.selectedIndex].text == selfObj.disCtl.innerText)
		{
			dialog.close();
			return;
		}
		else
		{
			var ajax = new Ajax();
			ajax.method = "POST";
			ajax.url = sitePath + "BProcess.aspx?ajax=1&cmd=setonlinestate";
			ajax.queryString = "onlineId=" + onlineId + "&state=" + rspState.value;
			ajax.callback = function(req){
				dialog.close();
				if(rspState.value == 2)
					selfObj.disCtl.innerText = "隐身";
				else
					selfObj.disCtl.innerText = "在线";
			};
			ajax.send();
		}
	};
}
function showMessage(msgId, type, popCtl)
{
    var typeName = null;
    if(type == 0)
    	typeName = "留言";
	else if(type == 1)
		typeName = "短消息";
	else
		typeName = "系统消息";
	var ajax = new Ajax();
	ajax.url = sitePath + "BProcess.aspx?ajax=1&cmd=getmessage&msgId=" + msgId;
	ajax.callback = function(req){
	    var xy = getPos(popCtl);
	    var dialog = new DialogBox(400, 0, "查看" + typeName, AjaxResponse(req).message, xy.y + popCtl.offsetHeight, xy.x);
	    dialog.create();
	}
	ajax.send();    
}
//发送短消息,留言等
function sendMessage(typeno,type, poster, postId, userId, popCtl)
{
    var selfObj		=	this;
    var typeName = null;
    if(typeno==0)
    {
      alert("此用户不允许发短消息");
      return ;
     }
    if(type == 0)
    	typeName = "留言";
	else if(type == 1)
		typeName = "短消息";
	else
		typeName = "系统消息";
	if(postId == 0)
	{
	    alert("请先登陆!");
		return;
	}
	if(postId == userId)
	{
		alert("不能给自己发" + typeName);
		return;
	}
    var html = "<div>标题：<input name='dialogTopic' type='text' id='dialogTopic' size='40' /></div>";
	html += "<div>内容：<textarea name='dialoContent' cols='40' rows='5' id='dialoContent'></textarea></div>";
	html += "<div class='btnBottom'><input type='button' name='btnDialogSave' id='btnDialogSave' value='发送' /></div>";
	var xy = getPos(popCtl);
	var dialog = new DialogBox(400, 170, "发送" + typeName, html, xy.y + popCtl.offsetHeight, xy.x);	
	dialog.create();
	$("btnDialogSave").onclick = function(){
		var topic = $("dialogTopic");
		var content = $("dialoContent");
		if(topic.value == "")
		{
			alert("请填写标题");
			topic.focus();
			return false;
		}
		if(content.value == "")
		{
			alert("请填写内容");
			content.focus();
			return false;
		}
		$("btnDialogSave").disabled="disabled";
		var ajax = new Ajax();
		ajax.method = "POST";
		ajax.url = sitePath + "BProcess.aspx?ajax=1&cmd=sendmessage";
		ajax.queryString = "itype="+type+"&userId="+userId+"&postid="+postId+"&poster="+poster+"&topic=" + escape(topic.value) + "&content=" + escape(content.value);
		ajax.callback = function(req){
			alert(AjaxResponse(req).message);
			dialog.close();
		}
		ajax.send();
	};
}
//回复留言
function ReplyMessage(poster, postId, msgid,userid,popCtl)
{
    if(postId == 0) 
	{
	    alert("请先登陆!");
		return;
	}
	if(postId!=userid)
	{
	alert("对不起，只有主人才可以回复！");
	return;
	}
	
    var selfObj=this;  
    var html ="<div>内容：<textarea name='dialoContent' cols='40' rows='5' id='dialoContent'></textarea></div>";
	html += "<div class='btnBottom'><input type='button' name='btnDialogSave' id='btnDialogSave' value='提交' /></div>";
	var xy = getPos(popCtl);
	var dialog = new DialogBox(400, 170, "回复", html, xy.y + popCtl.offsetHeight, xy.x);	
	dialog.create();
	$("btnDialogSave").onclick = function(){
		var content = $("dialoContent");
		
		if(content.value == "")
		{
			alert("请填写内容");
			content.focus();
			return false;
		}
		$("btnDialogSave").disabled="disabled";
		var ajax = new Ajax();
		ajax.method = "POST";
		ajax.url = sitePath +"BProcess.aspx?ajax=1&cmd=replymessage";
		ajax.queryString = "msgid="+msgid+"&postid="+postId+"&poster="+poster+"&content=" + escape(content.value);
		ajax.callback = function(req){
			alert(AjaxResponse(req).message);
			dialog.close();
			location.reload();
		}
		ajax.send();
	};
}

function selectSingleSpecial(specialId, sclassId, popCtl)
{
    var selfObj		=	this;
    var width = 500; height = 300;
    var html;
        html = "<div><iframe id='frmSelectSpecial' width='" + width + "' height='" + height + "' scrolling='auto' frameborder='0'></iframe></div>";
	    html += "<div class='btnBottom'><input type='button' name='btnDialogSave' id='btnDialogSave' value='确定' />";
	    html += "</div>"
	var xy = getPos(popCtl);
	var dialog = new DialogBox(width, height, "选择专题", html, xy.y + popCtl.offsetHeight, xy.x);
	dialog.create();
	$("frmSelectSpecial").src = sitePath + "Tools/SelectSpecial.aspx?sid=" + specialId + "&scid=" + sclassId+"&"+Math.random();
	$("btnDialogSave").onclick = function(){
	    var specialId = $(specialId).value;
	    var sclassId = $(sclassId).value;
	    if(type == 1 && (specialId == "" || specialId == "0"))
	    {
	        alert("请选择专题!");
			return false;
	    }
	    dialog.close();
	}
}
//选择专题
function selectSpecial(photoIds, type, popCtl)
{
    var selfObj		=	this;
    var html;
    var typeName = "选择";
    var width = 500; height = 300;
    if(type == 1)
    {
        html = "<div><iframe id='frmSelectSpecial' width='" + width + "' height='" + height + "' scrolling='auto' frameborder='0'></iframe></div>";
	    html += "<div class='btnBottom'><input type='button' name='btnDialogSave' id='btnDialogSave' value='确定' />";
	    html += "<input type='hidden' name='dialogSpecialId' id='dialogSpecialId' value='0' />";
	    html += "<input type='hidden' name='dialogSClassId' id='dialogSClassId' value='0' />";
	    html += "</div>"
	}
	else
	{
	    html = "<div>确定要退出专题吗？<input type='button' name='btnDialogSave' id='btnDialogSave' value='确定' /></div>";
	    html += "<input type='hidden' name='dialogSpecialId' id='dialogSpecialId' value='0' />";
	    html += "<input type='hidden' name='dialogSClassId' id='dialogSClassId' value='0' />";
	    typeName = "退出";
	    width = 200;
	    height = 70;
	}
	var xy = getPos(popCtl);
	var dialog = new DialogBox(width, height, typeName + "专题", html, xy.y + popCtl.offsetHeight, xy.x);
	dialog.create();
	if(type == 1)
	    $("frmSelectSpecial").src = sitePath + "Tools/SelectSpecial.aspx?sid=dialogSpecialId&scid=dialogSClassId"+"&"+Math.random();
	$("btnDialogSave").onclick = function(){
	    var specialId = $("dialogSpecialId").value;
	    var sclassId = $("dialogSClassId").value;
	    if(type == 1 && (specialId == "" || specialId == "0"))
	    {
	        alert("请选择专题!");
			return false;
	    }
	    $("btnDialogSave").disabled="disabled";
		var ajax = new Ajax();
		ajax.method = "POST";
		ajax.url = sitePath + "BProcess.aspx?ajax=1&cmd=bindspecial";
		ajax.queryString = "type=" + type + "&specialId=" + specialId + "&sclassId=" + sclassId + "&photoIds=" + photoIds;
		ajax.callback = function(req){
			alert(AjaxResponse(req).message);
			location.reload();
			dialog.close();
		}
		ajax.send();
	}
}
function selectSingleAlbum(albumPanelId, popCtl)
{
    var selfObj		=	this;
    var width = 500; height = 300;
    var html;
        html = "<div><iframe id='frmSelectAlbum' width='" + width + "' height='" + height + "' scrolling='auto' frameborder='0'></iframe></div>";
	    html += "<div class='btnBottom'><input type='button' name='btnDialogSave' id='btnDialogSave' value='确定' />";
	    html += "</div>"
	var xy = getPos(popCtl);
	var dialog = new DialogBox(width, height, "选择专辑", html, xy.y + popCtl.offsetHeight, xy.x);
	dialog.create();
	$("frmSelectAlbum").src = sitePath + "Tools/SelectAlbum.aspx?sid=" + albumPanelId;
	$("btnDialogSave").onclick = function(){
	    if($(albumPanelId).value == "")
	    {
	        alert("请选择专辑!");
			return false;
	    }
	    dialog.close();
	}
}

//选择专辑
function selectAlbum(photoIds, type, popCtl)
{
    var selfObj		=	this;
    var html;
    var typeName = "选择";
    var width = 500; height = 300;
    if(type == 1)
    {
        html = "<div><iframe id='frmSelectAlbum' width='" + width + "' height='" + height + "' scrolling='auto' frameborder='0'></iframe></div>";
	    html += "<div class='btnBottom'><input type='button' name='btnDialogSave' id='btnDialogSave' class='allbutton' value='确定' />";
	    html += "<input type='hidden' name='dialogAlbumId' id='dialogAlbumId' value='0' />";
	    html += "</div>"
	}
	else
	{
	    html = "<div>确定要退出专辑吗？<input type='button' name='btnDialogSave' id='btnDialogSave' class='allbutton' value='确定' /></div>";
	    html += "<input type='hidden' name='dialogAlbumId' id='dialogAlbumId' value='0' />";
	    typeName = "退出";
	    width = 200;
	    height = 70;
	}
	var xy = getPos(popCtl);
	var dialog = new DialogBox(width, height, typeName + "专辑", html, xy.y + popCtl.offsetHeight, xy.x);
	dialog.create();
	if(type == 1)
	    $("frmSelectAlbum").src = sitePath + "Tools/SelectAlbum.aspx?sid=dialogAlbumId"+"&"+Math.random();
	$("btnDialogSave").onclick = function(){
	    var albumId = $("dialogAlbumId").value;
	    if(type == 1 && (albumId == "" || albumId == "0"))
	    {
	        alert("请选择专辑!");
			return false;
	    }
	    $("btnDialogSave").disabled="disabled";
		var ajax = new Ajax();
		ajax.method = "POST";
		ajax.url = sitePath + "BProcess.aspx?ajax=1&cmd=bindalbum";
		ajax.queryString = "type=" + type + "&albumId=" + albumId + "&photoIds=" + photoIds;
		ajax.callback = function(req){
			alert(AjaxResponse(req).message);
			location.reload();
			dialog.close();
		}
		ajax.send();
	}
}
function modifyFriend(rid, rgid, popCtl)
{
    var html = "<div>把此用户加入到:</div>";
        html += "<div><select name='dialogRGroupId' id='dialogRGroupId'>";
        html += "<option value='2'>我的朋友</option>";
        html += "<option value='3'>我的家人</option>";
        html += "<option value='0'>陌生人</option>";
        html += "<option value='-1'>黑名单</option>";
        html += "</select> <input type='button' name='btnDialogSave' id='btnDialogSave' value='保存'></div>";
    var xy = getPos(popCtl);
	var dialog = new DialogBox(200, 100, "修改朋友关系", html, xy.y + popCtl.offsetHeight, xy.x);	
	dialog.create();
	    if(rgid == 2)
	        $("dialogRGroupId").selectedIndex = 0;
	    else if(rgid == 3)
	        $("dialogRGroupId").selectedIndex = 1;
	    else if(rgid == -1)
	        $("dialogRGroupId").selectedIndex = 3;
	$("btnDialogSave").onclick = function(){
	    $("btnDialogSave").disabled="disabled";
	    var ajax = new Ajax();
		ajax.method = "POST";
		ajax.url = sitePath + "BProcess.aspx?ajax=1&cmd=modifyfriend";
		ajax.queryString = "rgroupid="+$("dialogRGroupId").value+"&rid="+rid;
		ajax.callback = function(req){
			alert(AjaxResponse(req).message);
			dialog.close();
		}
		ajax.send();
	}
}

function setPhotoLatlon(latId, lonId, addressId, popCtl)
{
    var html = "<div><iframe id='frmSetLatLon' width='100%' height='100%' scrolling='auto' frameborder='0'></iframe></div>";
	
    var xy = getPos(popCtl);
	var dialog = new DialogBox(500, 400, "设置地理位置 -- 标注后即可关闭此窗口", html, xy.y + popCtl.offsetHeight, xy.x);	
	dialog.create();
	$("frmSetLatLon").src = sitePath + "Tools/setlatlon.aspx?w=498&h=350&latId=" + latId + "&lonId=" + lonId + "&addressId=" + addressId+"&"+Math.random();
}
function resetPhotoLatlon(photoId, userid, popCtl)
{
	if(userid == 0)
	{
		alert("请先登录！");
		return false;
	}
    var html = "<div><iframe id='frmSetLatLon' width='100%' height='100%' scrolling='auto' frameborder='0'></iframe>";
		html += "<input type='hidden' name='dialogPhotoLat' id='dialogPhotoLat' value='' />";
		html += "<input type='hidden' name='dialogPhotoLon' id='dialogPhotoLon' value='' />";
		html += "<input type='hidden' name='dialogPhotoAddress' id='dialogPhotoAddress' value='' />";
		html += "<div class='btnBottom'><input type='button' name='btnDialogSave' id='btnDialogSave' value='保存' /></div>";
	
    var xy = getPos(popCtl);
	var dialog = new DialogBox(500, 370, "设置照片地理位置 -- 标注后请点右下角的保存按扭", html, xy.y + popCtl.offsetHeight, xy.x);	
	dialog.create();
	$("frmSetLatLon").src = sitePath + "Tools/setlatlon.aspx?w=490&h=330&latId=dialogPhotoLat&lonId=dialogPhotoLon&addressId=dialogPhotoAddress&"+Math.random();
	$("btnDialogSave").onclick = function(){
	    var ajax = new Ajax();
		ajax.method = "POST";
		ajax.url = sitePath + "BProcess.aspx?ajax=1&cmd=savelatlon";
		ajax.queryString = "infoid=" + photoId + "&lat=" + $("dialogPhotoLat").value + "&lon=" + $("dialogPhotoLon").value + "&address=" + escape($("dialogPhotoAddress").value);
		ajax.callback = function(req){
			alert(AjaxResponse(req).message);
			location.reload();
		}
		ajax.send();
	    dialog.close();
	}
}

function setPhotoInfo(nameId, tagId, rgroupId, contentId, popCtl)
{
    var html = "<div>照片名称：<input name='dialoName' type='text' id='dialoName' size='30' /></div>";
		html += "<div>查看权限：<select name='dialoRGroupId' id='dialoRGroupId'><option value='0'>对所有人公开</option>";
		html += "<option value='1'>不公开</option><option value='2'>只对好友公开</option><option value='3'>只对家人公开</option></select></div>";
        html += "<div>照片标签：<input name='dialoTag' type='text' id='dialoTag' size='30' /></div>";
		html += "<div>照片说明：<textarea name='dialoContent' id='dialoContent' style='width:99%; height:50px;'></textarea></div>";
	    html += "<div class='btnBottom'><input type='button' name='btnDialogSave' id='btnDialogSave' value='确定' />";
    var xy = getPos(popCtl);
	var dialog = new DialogBox(300, 220, "编辑照片信息", html, xy.y + popCtl.offsetHeight, xy.x);	
	dialog.create();
	$("dialoName").value = $(nameId).value;
	$("dialoTag").value = $(tagId).value;
	$("dialoRGroupId").selectedIndex = parseInt($(rgroupId).value);
	$("dialoContent").value = $(contentId).value;
	$("btnDialogSave").onclick = function(){
        $(nameId).value = $("dialoName").value;
        $(tagId).value = $("dialoTag").value;
		$(rgroupId).value = $("dialoRGroupId").value;
        $(contentId).value = $("dialoContent").value;
        if($(nameId).value == "")
        {
            alert("请填写照片名称");
            $("dialoName").focus();
            return false;
        }
        dialog.close();
	}
}

function selectUserPhoto(photoXmlId, photoCountId, cPhotoCountId, panelId, popCtl)
{
	var html = "<div><iframe id='frmSelectPhoto' width='100%' height='100%' scrolling='auto' frameborder='0'></iframe></div>";
	html += "<div class='btnBottom'><input type='button' name='btnDialogSave' id='btnDialogSave' value='确定' /></div>";
    var xy = getPos(popCtl);
	var dialog = new DialogBox(500, 300, "选取照片 -- 选取后点击右下角的确定按扭", html, xy.y + popCtl.offsetHeight, xy.x);	
	dialog.create();
	$("btnDialogSave").onclick = function(){
        dialog.close();
	}
	$("frmSelectPhoto").src = sitePath + "Tools/selectPhoto.aspx?photoCountId="+photoCountId+"&photoXmlId="+photoXmlId+"&cPhotoCountId="+cPhotoCountId+"&panelId="+panelId+"&"+Math.random();
	return dialog;
}