var path = "";
function initPath()
{
	path = document.getElementById("path").value;
}
 //截取时间字段
function formatDates(str)
{
 	return str.length >10 ? str.substring(0,16) : str;
}

//添加活动留言
   function addActivityMessage(sessionUser)
   {
	   if(sessionUser == null || sessionUser=='null' || sessionUser == "")
	   {
	   		getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
	   		showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
			return false;
	   	}
	   	else
	   	{
	   		
			var content = jsTrim(document.getElementById("content").value);
		   	if(content == "" || content == null || StringLength(content)>1000)
		   	{
		   		document.getElementById("leaveMessageStatus").innerHTML="<font style='color:red'>留言内容不能少于1个字或多于500字！</font>";
		   		document.getElementById("content").focus(); 
		   		return false;
		   	}
		   	else
		   	{
		   		
		   		document.getElementById("leaveMessageStatus").innerHTML="<img src='"+path+"/common/images/ajax/waitting_1.gif'/>&nbsp;正在保存留言信息,请稍等... ...";
		   		return true;
		   	}
	   	}
   }
 function showPaths2(str)
{
	document.getElementById("imageUrl").value=str;
	document.getElementById("statuss").innerHTML="";
	document.getElementById("previews").innerHTML="<a target='_blank' href='"+str+"'><img border='1' height='80'  style='padding:1px' src='"+str+"' /></a>";
}
function saveMessage(sessionUser)
{
	if (sessionUser == null || sessionUser== 'null' || sessionUser =='')
	{
		getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
	   	showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
	}
	else
	{
		var p = document.getElementById("imageUrl").value;
	  	var imgPath = "";
	  	if(p != "")
	  	{
	  		imgPath = "<img src=\""+p+"\"/><br/>"
	  	}
	  	
	  	var content = imgPath+document.getElementById("content").value;
	  	document.getElementById("content").value=content;
	  	
	  	XMLHttp.sendReq('post', ''+path+'/ajax/getNewReplyAjax.html?operationType=checkAddLevMessageIsExistKeyWords&content='+encodeURI(content), '', saveMessageAjaxCallBack);

	}
}
  
   function saveMessageAjaxCallBack(http_request)
{
   	/*是否成功请求*/
   	if(http_request.responseText!="")
   	{
   		var results=http_request.responseXML;
		var roots=results.documentElement;
		var ajaxMessage=roots.getAttribute("ajaxMessage");
		var html=roots.getAttribute("html");
		var id = roots.getAttribute("id");
		var replyId = roots.getAttribute("replyId");
		if(ajaxMessage == "nosession")
		{
			getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
			showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
		}
		else if(ajaxMessage == "isExistKeyWords")
		{
			getScreenByStatus("jsAddScreenInfo","info","","","","","");
			showScreen("","ScreenInForss","promptBoxInForss",null,260,10);
  	 		document.getElementById("p_content").innerHTML="该条留言内容中包含敏感关键词，禁止发送。";
		}
		else
		{
			
		  	var content=document.getElementById("content").value;
		  	var leaveType = document.getElementById("leaveType").value;
		  	var cityName = document.getElementById("hiddenCityName").value;
		  	var activityId = document.getElementById("objIdJS").value;
		  	var activityUser = document.getElementById("activityUserJS").value;
		  	var activityTitle = document.getElementById("objTitleJS").value;
		  	var cityCode = document.getElementById("cityCodeJS").value;
		  	var leaveMType = document.getElementById("leaveMTypeJS").value;
		  	window.location.href=""+path+"/activityInfo.html?status=addActivityMessage&activityId="+activityId+"&userId="+activityUser+"&leaveMType="+leaveMType+"&isType="+leaveType+"&content="+encodeURI(content)+"&objTitle="+encodeURI(activityTitle)+"&albumId=0&cityName="+encodeURI(cityName)+"&cityCode="+cityCode;
		}
    }
}  
function toggle(el)
{  	
 	document.getElementById(el+"_message").innerHTML="";	
	el=document.getElementById(el);
	el.style.display="none";
	return;
}

function toggles(el)
{  		
	el=document.getElementById(el);
	el.style.display="";
	return;
}

function showRevert(revertId,diaryId,userId)
{
	XMLHttp.sendReq('post', ''+path+'/ajax/activityMessageAjax.html?operationType=getActivityMessage&revertId='+jsTrim(revertId)+'&userId='+jsTrim(userId)+'&activityId='+diaryId, '', showRevertInfo);
}
function checkRevert(el)
{
	var content = jsTrim(document.getElementById(el+"_revertContent").value);
	var revertId = document.getElementById(el+"_revertId").value;
	var userId = document.getElementById(el+"_userId").value;
	var revertType = document.getElementById(el+"_revertType").value;
	var diaryId = document.getElementById(el+"_diaryId").value;
	if(content == "" || content == null || StringLength(content)>1000)
	{
   		document.getElementById(el+"_message").innerHTML="<font style='color:red'>留言内容不能少于1个字或多于500字！</font>";
   		document.getElementById(el+"_revertContent").focus(); 
   		return false;
   	}
   	else
   	{
   		XMLHttp.sendReq('post', ''+path+'/ajax/activityMessageAjax.html?operationType=getActivityMessage&mth=revertInsert&revertId='+jsTrim(revertId)+'&userId='+jsTrim(userId)+'&content='+encodeURI(content)+'&el='+jsTrim(el)+'&revertType='+jsTrim(revertType)+'&activityId='+diaryId, '', showRevertInfo);
   		document.getElementById(el+"_message").innerHTML="<img src='"+path+"/common/images/ajax/waitting_1.gif'/>&nbsp;正在保存留言信息,请稍等... ...";
   	}
}

function showRevertInfo(http_request){
	 /*是否成功请求*/
   if(http_request.responseText!="")
   {
		 var results=http_request.responseXML;
		 var roots=results.documentElement;
		 var ajaxMessage=roots.getAttribute("ajaxMessage");
		 if(ajaxMessage=="success")
		 {
		 	var message=roots.getAttribute("message");
		 	var revertId = roots.getAttribute("revertId");
		 	document.getElementById("revertContent_"+revertId).innerHTML = message;	
		 	if(roots.getAttribute("mth")== "revertInsert")
		 	{
		 		document.getElementById(roots.getAttribute("el")).style.display="none";
		 		document.getElementById(roots.getAttribute("el")+"_revertContent").value="";
		 		document.getElementById(roots.getAttribute("el")+"_message").innerHTML="";
		 	}
		 }
		 else
		 {
		 	getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
		 	showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
		 }
	}	 	
}

function showJoin()
{
	path = document.getElementById("path").value;
	var activityId = document.getElementById("objIdJS").value;
	XMLHttp.sendReq('post', ''+path+'/ajax/activityJoinAjax.html?operationType=getActivityJoin&activityId='+activityId, '', showJoinInfo);
}

function deleteJoin(joinId)
{
	var activityId = document.getElementById("objIdJS").value;
	XMLHttp.sendReq('post', ''+path+'/ajax/activityJoinAjax.html?operationType=getActivityJoin&activityId='+activityId+'&mth=deletejoinActivity&joinId='+joinId, '', showJoinInfo);
}

//参加活动
function joinActivity(joinType,id,aid)
{
	if(id == 'null' || id == "")
	{
		getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
		showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
   	}
   	else
   	{
   		var activityId="";
   		var activityUser = "";
   		if(document.getElementById("objIdJS")!=null)
   			activityId = document.getElementById("objIdJS").value;
   		if(aid!=null && aid!='')
   			activityId=aid;
   		if(document.getElementById("activityUserJS")!=null)
   			activityUser = document.getElementById("activityUserJS").value;
		XMLHttp.sendReq('post', ''+path+'/ajax/activityJoinAjax.html?operationType=getActivityJoin&activityId='+activityId+'&activityUserId='+activityUser+'&mth=joinActivity&joinType='+joinType, '', showJoinInfo);
	   	if(document.getElementById("joinActivityCount")!=null)
	   		var joinActivityCount=document.getElementById("joinActivityCount").innerHTML;
		if(joinType == "1")
		{	
			if(document.getElementById("joinActivityCount")!=null)
 				document.getElementById("joinActivityCount").innerHTML=parseInt(joinActivityCount)+1;
 		}
	
	}
}

function showJoinInfo(http_request)
{
	 /*是否成功请求*/
   if(http_request.responseText!="")
   {
		 var results=http_request.responseXML;
		 var roots=results.documentElement;
		 var ajaxMessage=roots.getAttribute("ajaxMessage");
		 var joinActivityCount="0";
		 var activityOverStatus=roots.getAttribute("activityOverStatus");
		 if(document.getElementById("joinActivityCount")!=null)
		 	joinActivityCount=document.getElementById("joinActivityCount").innerHTML;
		 if(ajaxMessage=="success")
		 {
		 	if(roots.getAttribute("type") == "1")
		 	{
		 		if(document.getElementById("uploadActivityPhoto")!=null)
 					document.getElementById("uploadActivityPhoto").style.display="block";
 			}
		 	if(roots.getAttribute("type") == "0")
		 	{
		 		document.getElementById("uploadActivityPhoto").style.display="none";
		 		if(roots.getAttribute("realJoin") == "realJoin")
		 		{
		 			if(document.getElementById("joinActivityCount")!=null)
		 				document.getElementById("joinActivityCount").innerHTML=parseInt(joinActivityCount)-1;
		 		}
		 	}
		 	if(document.getElementById("joinDiv")!=null)
		 	{
		 		document.getElementById("joinDiv").innerHTML = roots.getAttribute("joinDiv");
		 	}
		 	else
		 	{
		 		if(activityOverStatus!=null && activityOverStatus=='false')
		 		{
		 			getScreenByStatus("jsAddScreenInfo","info","","","","","");
	   	  			document.getElementById("p_content").innerHTML="活动参加成功！";
					showScreen("","ScreenInForss","promptBoxInForss",null,260,17);
		 		}
		 		else if(activityOverStatus!=null && activityOverStatus=='true')
		 		{
		 			getScreenByStatus("jsAddScreenInfo","info","","","","","");
	   	  			document.getElementById("p_content").innerHTML="该活动已过期！";
					showScreen("","ScreenInForss","promptBoxInForss",null,260,17);
		 		}
		 		else
		 		{
		 			getScreenByStatus("jsAddScreenInfo","info","","","","","");
	   	  			document.getElementById("p_content").innerHTML="您已经参加了该活动！";
					showScreen("","ScreenInForss","promptBoxInForss",null,260,17);
		 		}
		 		
		 	}
		 	if(document.getElementById("joinsDiv")!=null)
		 		document.getElementById("joinsDiv").innerHTML = roots.getAttribute("joinsDiv");
		 	if(document.getElementById("aboutJoinDiv")!=null)
		 		document.getElementById("aboutJoinDiv").innerHTML = roots.getAttribute("aboutJoinDiv");
		 }
		 else
		 {
		 	getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
			 showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
		 }
	}	
}

//根据活动标题关键字搜索
 	function queryActivity(cityCode,cityName)
 	{
		var title = document.getElementById("activityTitle").value;
		if(cityCode==null || cityCode=='null')cityCode='';
		if(cityName==null || cityName=='null')cityName='';
		if(title == "" || title == "请输入搜索活动标题...")
		{
			getScreenByStatus("jsAddScreenInfo","info","","","","","");
	   	  	document.getElementById("p_content").innerHTML="请输入活动标题关键字进行搜索！";
			showScreen("","ScreenInForss","promptBoxInForss",null,260,17);
		}
		else
		{
		  	//var cityName = document.getElementById("hiddenCityName").value;
 			//var cityCode = document.getElementById("cityCodeJS").value;
 			window.location.href=''+path+'/activityIndex.html?query=otherActivity&titleValue='+encodeURI(jsTrim(title))+'&cityCode='+cityCode+'&cityName='+encodeURI(cityName);
			//window.location.href=""+path+"/activityIndex.html?mth=title&cityCode="+cityCode+"&cityName="+cityName+"&typeContent="+encodeURI(title); 
		}
	}


//*************************************************myactivity页面*******************************/
function getJoinActivityTypeMe(activityId,divId)
{
	path = document.getElementById("path").value;
	XMLHttp.sendReq('post', ''+path+'/ajax/joinActivityTypeAjax.html?operationType=getActivityJoin&activityId='+activityId+'&divId='+divId, '', joinTypeResultMe);
}
/*---------------------方法回调-----------------------*/
function joinTypeResultMe(http_request){
	/*是否成功请求*/
	   if(http_request.responseText!="")
	   {
			var results=http_request.responseXML;
			var roots=results.documentElement;
			var ajaxMessage=roots.getAttribute("ajaxMessage");
			if(ajaxMessage == "nosession")
			{
				getScreenByStatus("jsAddScreenNologin","noLogin","","","","","");
				showScreen("ifrNoLogins","ScreenNoLogins","waitBoxNoLogins",'','','');
			}
			else
			{
				if(roots.getAttribute("ajType") == "1")
				{
					document.getElementById(roots.getAttribute("divId")+"_type").innerHTML="决定参加";
				}
				else
				{
					document.getElementById(roots.getAttribute("divId")+"_type").innerHTML="可能参加";
				}
				document.getElementById(roots.getAttribute("divId")+"_joinId").innerHTML=roots.getAttribute("ajId");
			}
		}
}
//取消参加活动
function activityMessageDeleteMe(e,el)
{
	var mouse_x;
    var mouse_y;
    if(!document.all)
    {
		mouse_x=e.pageX;
		mouse_y=e.pageY;
	}
	else
	{
		mouse_x=document.documentElement.scrollLeft+e.clientX;
		mouse_y=document.documentElement.scrollTop+e.clientY;
	}
    var Element = document.getElementById('deleteMessageBox');
    Element.style.left=(1*mouse_x-170)+"px";
    Element.style.top=(1*mouse_y-80)+"px";
    document.getElementById("hiddenJoinId").value = jsTrim(document.getElementById(el+"_joinId").innerHTML);
    document.getElementById("hiddenActivityId").value = jsTrim(document.getElementById(el+"_activityId").innerHTML);
    Element.style.display='block';
}
//取消参加活动
function canlDdiaryMessageDeleteMe()
{
    var Element = document.getElementById('deleteMessageBox');
    Element.style.display='none';
}
//确定取消参加活动
function shueDiaryMessageDeleteMe(type)
{
	window.location.href=""+path+"/s/myActivity.html?mth=deleteJoin&type="+type+"&activityId="+document.getElementById("hiddenActivityId").value+"&joinId="+document.getElementById("hiddenJoinId").value;
}
//按钮回车执行
function searchActivityToSubmit(e,cityCode,cityName)
{
	var k = window.event?window.event.keyCode:e.which;
	if(k==13)
 	{
   		queryActivity(cityCode,cityName);
 	}
}






