﻿// JavaScript Documentfunction share_ret(r){

	
	function publish_diag(){
		popup=new pop_dialog('classifieds_pop_view_dialog');
		popup.show_prompt("",'<div class="messages_div"><strong>你的资料已经修改成功</strong></div>');
		window.setTimeout("popup.fade_out(100)", 1000);
		window.setTimeout("gotoShowMydiag()", 1500);
		
		}
	function gotoShowMydiag(){
			window.location.href="http://class.renren.com";
		}
/**
*显示留言框
*
**/
var lastObjId = "";
function showCommentBox(obj,ower){
			/*取消按钮*/
			
				if(document.getElementById('com_'+obj.id+'_save')){
					removeComment(obj);
					return;
					}
				
				
				if(document.getElementById('combox_'+lastObjId)){
					Element.remove('combox_'+lastObjId);
				}
				var arr = obj.id.split('_');	
				var mg = '<div style="margin-left:56px;">';
				var mg2 = '</div>';
				var col0 = '<div class="postcomment nopadding" id="combox_'+obj.id+'">';
				var col1 = '<TEXTAREA id="text_'+obj.id+'" cols="60" rows="6" name="body" tabindex="10">回复'+ower+': </TEXTAREA>';
			    var col2='<p class="postbtn"><input type="button" class="input-button" value="留言" id="com_'+obj.id+'_save" />';
                var col3='&nbsp;<input type="button" class="input-button gray"  value="取消" id="com_'+obj.id+'_cancel" /></p></div>';
				var text = col0+col1+col2+col3;
				if(arr[3]==0){
						//var text = mg+col0+col1+col2+col3+mg2;
					
						
						new Insertion.After(document.getElementById("combox_"+arr[2]), text);
					}else{
						//var text = col0+col1+col2+col3;
						new Insertion.After(obj, text);	
					}
				
				
				/*开始绑定事件*/
				Event.observe('com_'+obj.id+'_save','click',function(){postComment(obj)},false);
				Event.observe('com_'+obj.id+'_cancel','click',function(){removeComment(obj)},false);			
				lastObjId=obj.id;
			}
			
/**
*删除留言框
*
**/
function removeComment(obj){
		Element.remove('combox_'+obj.id);
	}

function postComment(obj){
		var t = new Date().getTime();
		var arr = obj.id.split('_');	
		var url = "/ajaxreply.do";
		var text_val = document.getElementById('text_'+obj.id).value;
		var success	= function(res){showComment(res, obj);}
		var failure	= function(res){handleFailed(res, obj);}
		arr[4]=1;
		var pars ="classid="+arr[1]+"&parentid="+arr[2]+"&cc="+arr[6]+"&isReply="+arr[4]+"&body="+text_val;
		var oAjax = new Ajax.Request(url, {method:'post', postBody:pars, onSuccess:success, onFailure:failure});
	
	}
function showComment(res,obj){
		var response = res.responseText;
		var arr = obj.id.split('_');
		if(response == "error" || response.indexOf('boxcont nopadding')<0){
			alert("你不是该班级成员或发送留言失败");
			removeComment(obj);		
			return;
		}	
		new Insertion.After(document.getElementById("combox_"+arr[2]), response);	
		removeComment(obj);		
		
	}

function switchBox(obj){
	//new Effect.toggle(document.getElementById(obj.id))
		Element[Element.visible(document.getElementById(obj.id)) ? 'hide' : 'show'](document.getElementById(obj.id));
	
		var arr = obj.id.split("_");
	document.getElementById("switch_"+arr[1]).toggleClassName("switch_close");
}
function displayBox(obj){
	obj.style.display="";
	var arr = obj.id.split("_");
	document.getElementById("switch_"+arr[1]).toggleClassName("switch_open");
}

/**
*删除留言
*@word1 提示框标题
*@word2 提示框内容
*@url ajax地址
*@id 留言的id
*/
function diagAlert(word1,word2,url,id){
	var element = document.getElementById(id);
	var h = element.offsetTop-10;
	while( element = element.offsetParent ) {
     h += element.offsetTop;
    }
    document.getElementById("comfirm_diag").innerHTML = '<div id="comfirm_diag" class="generic_dialog wallpro_dialog pop_dialog" style=""><div class="generic_dialog_popup" style="top: '+h+'px;"><table class="pop_dialog_table" id="pop_dialog_table"><tbody><tr><td class="pop_topleft"/><td class="pop_border"/><td class="pop_topright"/></tr><tr><td class="pop_border"/><td id="pop_content" class="pop_content"><h2><span>'+word1+'?</span></h2><div class="dialog_content"><div class="dialog_body"><p>'+word2+'?</p></div><input type="hidden" value="d719210c2e5ee42494daa28964fade04" name="post_form_id"/><div id="dialog_buttons" class="dialog_buttons"><input type="button" onfocus="this.blur()" value="提交" onclick="this.className=\'inputsubmit gray\';this.value=\'请稍候\';guestDel(\''+url+'\',\''+id+'\');" name="dialog_confirm" id="dialog_confirm" class="inputsubmit"/><input type="button" onfocus="this.blur()" onClick="document.getElementById(\'comfirm_diag\').innerHTML=\'\';" value="取消" class="inputsubmit inputaux"/></div></div></td><td class="pop_border" /></tr><tr><td class="pop_bottomleft" /><td class="pop_border"/><td class="pop_bottomright"/></tr></tbody></table></div>';	

}


function guestDel(url,id){
    new Ajax.Request(url, {
    method: 'get',
    onComplete: function(transport) {
       document.getElementById("comfirm_diag").innerHTML = "";
	   // test(id);
       document.getElementById(id).style.display="none";
	}
   });
	
}

