$(document).ready(function() {
	init();
});

function init() {
	var getAbsoluteCoords = function (e) {
		var width = e.offsetWidth;
		var height = e.offsetHeight;
		var left = e.offsetLeft;
		var top = e.offsetTop;
		while (e=e.offsetParent) {
			left += e.offsetLeft;
			top += e.offsetTop;
		};
		var right = left+width;
		var bottom = top+height;
		return {
			'width': width,
			'height': height,
			'left': left,
			'top': top,
			'right': right,
			'bottom': bottom
		};
	};
	var getElementById = function (sId) {
	return document.getElementById(String(sId));
	};
	
	var wrapId = "dragDiv";
	var wrapTitle = "dragTitle"; 
	var wrap = getElementById(wrapId);
	var wrapTitle = getElementById(wrapTitle);
	wrapTitle.onmouseover = function () {
		wrapTitle.style.cursor = "move";
		if (window.ActiveXObject)
		wrapTitle.onselectstart = function () { event.returnValue = false; }
		wrapTitle.onmousedown = function (evt) {
			evt = window.event||evt; var a=getAbsoluteCoords(wrap);
			wrap.cx=evt.clientX-(a.left);
			wrap.cy=evt.clientY-(a.top);
			document.onmousemove = function (evt) {
				evt = window.event||evt; 
				try {
					wrap.style.left = (evt.clientX-wrap.cx)+"px";
					wrap.style.top = (evt.clientY-wrap.cy)+"px";
				} catch (ex) {};
			};
			document.onmouseup = function () {
				document.onmousemove = null;
				document.onmouseup = null;
				wrap.style.cursor="default";
			};
		};
	}
}

//打开
function showDragDiv(type,id) {
	showHiddenDiv();
	//在div里写入内容
	innerDivHtml(type,id);
	var dragDiv = document.getElementById("dragDiv");
	var winWidth = window.screen.width;
	var winHeight = window.screen.height;
	var sTop = document.body.scrollTop||document.documentElement.scrollTop;//网页被卷去的高
	divWidth = parseInt(dragDiv.style.width);
	divHeight = parseInt(dragDiv.style.height);
	dragDiv.style.left = winWidth/2 - divWidth/2 + "px";
	dragDiv.style.top = winHeight/2 + sTop - divHeight/2 - 100 + "px";
	dragDiv.style.display = "";
	return;
}

//关闭
function closeDrag()
{	
	//$("#dragContent").html("");
	var dragDiv = document.getElementById("dragDiv");
	dragDiv.style.display = "none";
	document.getElementById("hiddiv").style.display="none";
}
function closeDragAndReload()
{	
	var dragDiv = document.getElementById("dragDiv");
	dragDiv.style.display = "none";
	document.getElementById("hiddiv").style.display="none";
	window.location.reload();
}
//黑色遮盖层
function showHiddenDiv() {
	var bodyw = document.body.clientWidth;
	//var bodyh =window.screen.availHeight;
	var bodyh = document.body.clientHeight;
	var sUserAgent = navigator.userAgent;
	var isOpera = sUserAgent.indexOf("Opera") > -1;
	var isIE = sUserAgent.indexOf("compatible") > -1 && sUserAgent.indexOf("MSIE") > -1 && !isOpera;
	if (isIE == false) {
		bodyh += 25;
	} 
	var hiddiv = document.getElementById("hiddiv");
	hiddiv.style.width = bodyw + "px";
	hiddiv.style.height = bodyh + "px";
	if (hiddiv.style.display=="") {
		hiddiv.style.display="none";
	} else {
		hiddiv.style.display="";
	}
}

function innerDivHtml(type,id) {
if(id=="do"){
	var onclick="closeDragAndReload()";
}else{
	var onclick="closeDrag()";
}
var html = "";
var dragDiv = document.getElementById("dragDiv");
var dragTitleSpan = document.getElementById("dragTitleSpan");
var dragContent = document.getElementById("dragContent");
	if (type == "fav_dup") {
		html += '    <div style="width:96%; padding:2%; min-height:70px;">';
		html += '    <div style="padding:20px 0; text-align:center;">您已收藏'+id+'！</div>';
		html += '    </div>   ';
		html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;"> ';
		html += '<input type="submit" name="button3" id="button3" value="确定" class="btm" onclick="closeDrag()"/>       ';
		html += '    </div>                                                                                                             ';
		dragDiv.style.width = 380 + "px";
		dragDiv.style.height = 150 + "px";
		dragTitleSpan.innerHTML = "系统提示";
		dragContent.innerHTML = html;
		return;
	} 
	if (type == "trash") {
		html += '    <div style="width:96%; padding:2%; min-height:100px;">';
		html += '    <div style="padding:20px 0; text-align:center;">您确定要删除该记录吗？</div>';
		html += '    </div>   ';
		html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;"> ';
		if(isNull(id)){
			html += '<input type="submit" name="button3" id="button3" value="删除" class="btm" onclick="op(\''+type+'\')"/> ';
		}else{
		    html += ' <input type="submit" name="button3" id="button3" value="删除" class="btm" onclick="trash('+id+')"/>  ';  
		}
		html += '<input type="submit" name="button3" id="button3" value="取消" class="btm" onclick="closeDrag()"/>       ';
		html += '    </div>                                                                                                             ';
		dragDiv.style.width = 380 + "px";
		dragDiv.style.height = 180 + "px";
		dragTitleSpan.innerHTML = "删除";
		dragContent.innerHTML = html;
		return;
	} else if (type == "trashcomment") {
		html += '    <div style="width:96%; padding:2%; min-height:100px;">';
		html += '    <div style="padding:20px 0; text-align:center;">您确定要删除该评论吗？</div>';
		html += '    </div>   ';
		html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;">                                   ';
		html += '           <input type="submit" name="button3" id="button3" value="删除" class="btm" onclick="trashcomment('+id+')"/>                                ';
		html += '           <input type="submit" name="button3" id="button3" value="取消" class="btm" onclick="closeDrag()"/>                                ';
		html += '    </div>                                                                                                             ';
		dragDiv.style.width = 380 + "px";
		dragDiv.style.height = 180 + "px";
		dragTitleSpan.innerHTML = "删除";
		dragContent.innerHTML = html;
		return;
	} else if(type == "edit"){
		html +='<form name="editform" method= "post" id = "editform">';
        html +='<div class="win">';
        html +='<div class="biaoge">';

		html +='<span class="z"><font class="two">网</font>址：</span>';
        html +='<span class="y"><em name="edit_url"></em></span>';
        html +='<span class="clear"></span>';

		html +='<span class="z">网页标题：</span>';
        html +='<span class="y">';
        html +='<input type="text" name="edit_title" id="edit_title" class="put2"  onfocus="this.className=\'puton\'" onblur="this.className=\'put2\'"/></span>';
        html +='<span class="clear"></span>';

		html +='<span class="z"><font class="two">注</font>释：</span>';
        html +='<span class="y">';
        html +='<textarea name="edit_notes" rows="5" class="put2" id="edit_notes" onfocus="this.className=\'puton\'" onblur="this.className=\'put2\'" style="height:60px;"></textarea>';
        html +='</span> ';
        html +='<span class="clear"></span>';

		html +='<span class="z">收藏状态：</span>';
        html +='<span class="y">';
        html +='<label for="checkbox3"><input type="radio" name="open" id="edit_pub" value="1"  />公开</label>';
        html +='<font class="two"></font>';
        html +='<label for="checkbox4"><input type="radio" name="open" id="edit_pri" value="0" />私有</label>';
        html +='</span>';
		html +='<span class="clear"></span>';
                                 
        html +='<span class="z"><font class="two">分</font>类：</span>'; 
        html +='<span class="y" style="border:solid 1px #ccc;"><c:set var="count" value="0"/>'; 
		html +='<div id= "divdir" style="margin:5px; line-height:20px;">';
        html +=$("div[id='divdir']").html();
		html +='</div>';
        html +='<div style="margin:0 5px;">';
        html +=$("div[id='newbu']").html();
		html +='</div>';
        html +='</span>';  
        html +='<span class="clear"></span> ';  

        html +='</div>   ';         
        getUrl(id);
		getTitle(id);
		getOpen(id);
		getNotes(id);
		getDir(id);    
        html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;">                                   ';
		html += '           <input type="submit" name="button3" id="button3" value="确定" class="btm" onclick="editfav('+id+')"/>                                ';
		html += '           <input type="submit" name="button3" id="button3" value="取消" class="btm" onclick="closeDrag()"/>                                ';
		html += '    </div> ';
        html +='</div>';
	    html +='</div>';
		html +='</form>';
		dragDiv.style.width = 580 + "px";
		dragDiv.style.height = 300 + "px";
		dragTitleSpan.innerHTML = "编辑";
		dragContent.innerHTML = html;
		return;
	} else if(type == "more" ){
	    $.post("/fav/fav_submit.jsp",{action:"more"},function(xml){
		    html += '<div style="width:96%; padding:2%; min-height:100px;">                                                             ';
			html +='<div id= "moredir" style="display:\'\'">';
			html += xml ;
			html +='</div>';
			html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;">                                   ';
			html += '           <input type="submit" name="button3" id="button3" value="确定" class="btm" onclick="closeDrag()"/>                                ';
			html += '           <input type="submit" name="button3" id="button3" value="取消" class="btm" onclick="closeDrag()"/>                                ';
			html += '    </div> ';
			html += '</div> ';
			dragDiv.style.width = 480 + "px";
			dragDiv.style.height = 150 + "px";
			dragTitleSpan.innerHTML = "更多分类";
			dragContent.innerHTML = html;
			return;
		});
	} else if(type == "null"){
		html += '<div style="width:96%; padding:2%; min-height:100px;">';
		html += '<div style="padding:20px 0; text-align:center;">请选择要操作的记录！</div>                               ';
		html += '  </div>                                                                                                             ';
		html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;">                                   ';
		html += '           <input type="submit" name="button3" id="button3" value="确定" class="btm" onclick="closeDrag()"/>                                ';
		html += '    </div>                                                                                                             ';
		dragDiv.style.width = 380 + "px";
		dragDiv.style.height = 80 + "px";
		dragTitleSpan.innerHTML = "系统提示";
		dragContent.innerHTML = html;
		return;
	} else if (type == "loginsucc") {
		html += '    <div class="win_main">                                                                                                              ';
		html += '    		<div style="padding:20px 0; text-align:center;">                                                                            ';
		html += '    		  <h1><i>' + $("#accname_" + id).html() + '</i><br>是否跳转成功？</h1>                                                                              ';
		html += '    		  <p>                                                                                                                       ';
		html += '    		    <input type="submit" name="button" id="button" value="跳转成功" onclick="loginSuccess(\'succ\','+id+')" class="btm2"/>  ';
		html += '   		      &nbsp;                                                                                                                    ';
		html += '   		      <input type="submit" name="button2" id="button2" value="跳转失败" onclick="loginSuccess(\'lost\','+id+')" class="btm2"/>  ';
		html += '    		  </p>                                                                                                                      ';
		html += '	  </div>                                                                                                                            ';
		html += '    </div>                                                                                                                              ';
		html += '    <div class="win_close">                                                                                                             ';
		html += '    反馈后此提示将不再出现！                                                                                                            ';
		html += '      <input type="button" name="button3" id="button3" value="跳过" onclick="closeDrag()" class="btm" />                                ';
		html += '  </div>                                                                                                                                ';
		
		dragDiv.style.width = 300 + "px";
		dragDiv.style.height = 150 + "px";
		dragTitleSpan.innerHTML = "跳转反馈";
		dragContent.innerHTML = html;
		return;
	}else if (type == "20") {
		html += '    <div style="width:96%; padding:2%; min-height:100px;">';
		html += '    <div style="padding:20px 0; text-align:center;">您只能将20个条目添加到主页！</div>';
		html += '    </div>   ';
		html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;">                               ';
		html += '           <input type="submit" name="button3" id="button3" value="确定" class="btm" onclick=\"'+onclick+'\"/>                               ';
		html += '    </div>                                                                                                             ';
		dragDiv.style.width = 380 + "px";
		dragDiv.style.height = 180 + "px";
		dragTitleSpan.innerHTML = "系统提示";
		dragContent.innerHTML = html;
		return;
	}else if (type == "ck_trash") {
		html += '    <div style="width:96%; padding:2%; min-height:100px;">';
		html += '    <div style="padding:20px 0; text-align:center;">选中条目已删除！</div>';
		html += '    </div>   ';
		html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;">                               ';
		html += '           <input type="submit" name="button3" id="button3" value="确定" class="btm" onclick=\"'+onclick+'\"/>                                ';
		html += '    </div>                                                                                                             ';
		dragDiv.style.width = 380 + "px";
		dragDiv.style.height = 180 + "px";
		dragTitleSpan.innerHTML = "系统提示";
		dragContent.innerHTML = html;
		return;
	}else if (type == "ck_untop") {
		html += '    <div style="width:96%; padding:2%; min-height:100px;">';
		html += '    <div style="padding:20px 0; text-align:center;">选中条目已取消置顶！</div>';
		html += '    </div>   ';
		html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;">                               ';
		html += '           <input type="button" name="button3" id="button3" value="确定" class="btm" onclick=\"'+onclick+'\"/>                                ';
		html += '    </div>                                                                                                             ';
		dragDiv.style.width = 380 + "px";
		dragDiv.style.height = 180 + "px";
		dragTitleSpan.innerHTML = "系统提示";
		dragContent.innerHTML = html;
		return;
	}else if (type == "ck_top") {
		html += '    <div style="width:96%; padding:2%; min-height:100px;">';
		html += '    <div style="padding:20px 0; text-align:center;">选中条目已置顶！</div>';
		html += '    </div>   ';
		html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;">                               ';
		html += '           <input type="button" name="button3" id="button3" value="确定" class="btm" onclick=\"'+onclick+'\"/>                                ';
		html += '    </div>                                                                                                             ';
		dragDiv.style.width = 380 + "px";
		dragDiv.style.height = 180 + "px";
		dragTitleSpan.innerHTML = "系统提示";
		dragContent.innerHTML = html;
		return;
	}else if (type == "ck_home") {
		html += '    <div style="width:96%; padding:2%; min-height:100px;">';
		html += '    <div style="padding:20px 0; text-align:center;">选中条目已添加到首页！</div>';
		html += '    </div>   ';
		html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;">                               ';
		html += '           <input type="button" name="button3" id="button3" value="确定" class="btm" onclick=\"'+onclick+'\"/>                                ';
		html += '    </div>                                                                                                             ';
		dragDiv.style.width = 380 + "px";
		dragDiv.style.height = 180 + "px";
		dragTitleSpan.innerHTML = "系统提示";
		dragContent.innerHTML = html;
		return;
	}
	if (type == "ck_unhome") {
		html += '    <div style="width:96%; padding:2%; min-height:100px;">';
		html += '    <div style="padding:20px 0; text-align:center;">选中条目已取消添加到首页！</div>';
		html += '    </div>   ';
		html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;">                               ';
		html += '           <input type="button" name="button3" id="button3" value="确定" class="btm" onclick=\"'+onclick+'\"/>                                ';
		html += '    </div>                                                                                                             ';
		dragDiv.style.width = 380 + "px";
		dragDiv.style.height = 180 + "px";
		dragTitleSpan.innerHTML = "系统提示";
		dragContent.innerHTML = html;
		return;
	}else if (type == "ck_pup") {
		html += '    <div style="width:96%; padding:2%; min-height:100px;">';
		html += '    <div style="padding:20px 0; text-align:center;">选中条目已置为公开状态！</div>';
		html += '    </div>   ';
		html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;">                               ';
		html += '           <input type="button" name="button3" id="button3" value="确定" class="btm" onclick=\"'+onclick+'\"/>                                ';
		html += '    </div>                                                                                                             ';
		dragDiv.style.width = 380 + "px";
		dragDiv.style.height = 180 + "px";
		dragTitleSpan.innerHTML = "系统提示";
		dragContent.innerHTML = html;
		return;
	}else if (type == "ck_pri") {
		html += '    <div style="width:96%; padding:2%; min-height:100px;">';
		html += '    <div style="padding:20px 0; text-align:center;">选中条目已置为私有状态！</div>';
		html += '    </div>   ';
		html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;">                               ';
		html += '           <input type="button" name="button3" id="button3" value="确定" class="btm" onclick=\"'+onclick+'\"/>                                ';
		html += '    </div>                                                                                                             ';
		dragDiv.style.width = 380 + "px";
		dragDiv.style.height = 180 + "px";
		dragTitleSpan.innerHTML = "系统提示";
		dragContent.innerHTML = html;
		return;
	} else if (type == 'getPwd') {
		html += '    <div style="width:96%; padding:2%; min-height:100px;">';
		html += '    <div style="padding:20px 0; text-align:center;">邮件已经发送,请去邮箱收邮件查看您的密码!</div>';
		html += '    </div>   ';
		html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;">                                   ';
		html += '           <input type="button" name="button3" id="button3" value="关闭" class="btm" onclick="closeDrag()"/>                                ';
		html += '    </div>                                                                                                             ';
		dragDiv.style.width = 380 + "px";
		dragDiv.style.height = 180 + "px";
		dragTitleSpan.innerHTML = "提示";
		dragContent.innerHTML = html;
		return;
	} else if (type == 'getPwdImg') {
		html += '    <div style="width:96%; padding:2%; min-height:100px;">';
		html += '    <div style="padding:20px 0; text-align:center;"><img src="/acc/pwd_img.jsp?v=' + Math.random() + '"></div>';
		html += '    </div>   ';
		html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;">                                   ';
		html += '           <input type="button" name="button3" id="button3" value="关闭" class="btm" onclick="closeDrag()"/>                                ';
		html += '    </div>                                                                                                             ';
		dragDiv.style.width = 380 + "px";
		dragDiv.style.height = 180 + "px";
		dragTitleSpan.innerHTML = "提示";
		dragContent.innerHTML = html;
		return;
	} else if (type == 'getPwdErr') {
		html += '    <div style="width:96%; padding:2%; min-height:100px;">';
		html += '    <div style="padding:20px 0; text-align:center;">找回帐户密码出现错误，请刷新页面后重试。<br/>若还有问题，请与豌豆客服联系。</div>';
		html += '    </div>   ';
		html += '    <div style="width:96%; padding:2%; text-align:right;border-top:solid 1px #ccc;">                                   ';
		html += '           <input type="button" name="button3" id="button3" value="关闭" class="btm" onclick="closeDrag()"/>                                ';
		html += '    </div>                                                                                                             ';
		dragDiv.style.width = 380 + "px";
		dragDiv.style.height = 180 + "px";
		dragTitleSpan.innerHTML = "错误";
		dragContent.innerHTML = html;
		return;
	}
}
