// JavaScript Document

function max_count_field(text_id,dest_id,limit)
{
    field_length=$(text_id).val().length;
    if(field_length>limit)
    {
        $(dest_id).html("字数过多");
    }
    else
    {
        $(dest_id).html(limit-field_length);
    }
}

function getAreaSelect(obj)
{
ajax_replace('place_local_xian','ajax_add_place.php?ac=getAreaSelect&city='+obj.value,'请选择城市');
}


function search_venues_data(val,tarId)
{
//alert();
if(val.length>1){
$.get('ajax_add_event.php?ac=getVenues&input='+escape(val),
    function(data){
		if(data){
		//alert(data);
		  $("#venue_results").html(data);
		  var venue_results = document.getElementById("venue_results");
          venue_results.style.display = "";
		}
		else
		{
		  $("#venue_results").html('未找到匹配地址');
		  var venue_results = document.getElementById("venue_results");
          venue_results.style.display = "";
		}
    }
	);
}
}
function eventSubmit()
{
  var myForm = document.post_event;
  if(myForm.thing_name.value=="")
  {
	    showAlertContainer('n','请输入活动名称！');
		//location.href="#alert";
		myForm.thing_name.focus();
		return false;
  }
  if(myForm.date_classid.value=="")
  {
	    showAlertContainer('n','请选择活动分类！');
		//myForm.date_city.focus();
		return false;
  }
  if(myForm.datetime_begin.value=='')
  {
	    showAlertContainer('n','请输入活动时间！');
		myForm.datetime_begin.focus();
		return false;
  }
  if(myForm.datetime_begin.value!='')
  {
    var a,aS,hh,mm;
		var b,bss,bD,bS;
		a=new Date();
		b=myForm.datetime_begin.value;
		aS=a.getTime(); //得到从 1970 年 1 月 1 日开始计算到 Date 对象中的时间之间的毫秒数
		//alert(a);

		bss=b.split("-");
		hh= myForm.eTimeStartHour.value;
		mm= myForm.eTimeStartMinute.value;
		bD=new Date(bss[0],bss[1]-1,bss[2],hh,mm);
		//alert(b);
		//alert(bD);
		bS=bD.getTime();
		//alert(myForm.edit_type2.value);
		//alert((bS<aS&&myForm.organizer_type.value!=1&&myForm.edit_type2.value!=1));
		if ((bS<aS&&myForm.organizer_type.value!=1&&myForm.edit_type2.value!=1)){
	    showAlertContainer('n','活动起始时间不能小于当前时间！');
    myForm.datetime_begin.focus();
    return false;
    }
  }
  if(myForm.has_end_date.value==1&&myForm.datetime_end.value=='')
  {
	    showAlertContainer('n','请输入活动结束时间！');
		myForm.datetime_end.focus();
		return false;
  }
  if(myForm.datetime_begin.value!=''&&myForm.datetime_end.value!='')
  {
		var a,aS,hh,mm;
		var b,bss,bD,bS,c,css,cD,cS;
		a=new Date();
		b=myForm.datetime_end.value;
		c=myForm.datetime_begin.value;
		aS=a.getTime(); //得到从 1970 年 1 月 1 日开始计算到 Date 对象中的时间之间的毫秒数
		//alert(a);

		bss=b.split("-");
		css=c.split("-");
		hh= myForm.eTimeStartHour.value;
		mm= myForm.eTimeStartMinute.value;
		bD=new Date(bss[0],bss[1]-1,bss[2],hh,mm);
		cD=new Date(css[0],css[1]-1,css[2],hh,mm);
		//alert(b);
		//alert(bD);
		bS=bD.getTime();
		cS=cD.getTime();
		//alert(bS);
		//alert(aS);
		if(bS<aS&&myForm.organizer_type.value!=1&&myForm.edit_type2.value!=1){
	    showAlertContainer('n','活动结束时间不能小于当前时间！');
		myForm.datetime_begin.focus();
		return false;
		}
		if(cS>bS)
		{
	    showAlertContainer('n','活动结束时间不能早于活动起始时间！');
		myForm.datetime_begin.focus();
		return false;
		}

  }

  if(myForm.is_add_place.value!=1&&myForm.selected_venue.value=='')
  {
	 showAlertContainer('n','请输入活动地点，并选择一个地点或新增加一个地点！');
     //myForm.place.focus();
     return false;
  }
  if(myForm.is_add_place.value==1)
  {
		if(myForm.place_name.value=="")
		{
	         showAlertContainer('n','请输入地点名称！');
			// myForm.date_name.focus();
			 return false;
		}
		if(myForm.place_class.value=="")
		{
	         showAlertContainer('n','请选择地点分类！');
			 //myForm.date_city.focus();
			 return false;
		}

		if(myForm.place_local_city.value=='')
		{
	         showAlertContainer('n','请选择地点所在城市！');
			 //myForm.place.focus();
			 return false;
		}

		if(myForm.place_address.value=='')
		{
	         showAlertContainer('n','请填写详细地址！');
			 return false;
		}
	    myForm.place_classname.value=document.getElementById("place_class").options[getSelectedIndex('place_class')].text;
		myForm.place_province.value=document.getElementById("place_local_pro").options[getSelectedIndex('place_local_pro')].text;
		myForm.place_city.value=document.getElementById("place_local_city").options[getSelectedIndex('place_local_city')].text;
  }
  myForm.event_classname.value=document.getElementById("date_classid").options[getSelectedIndex('date_classid')].text;
  document.post_event.submit()
  return true;
}


//活动展示页面中我喜欢和我不喜欢的js


//我喜欢这个地点
function likeit(plikeid,premoveid,pnumid,eventid)
{
	$.get("Event.php?ac=likeit&eventid="+eventid,
	function(data){
		if(data=='success'){
			$("#"+pnumid).html(parseInt($("#"+pnumid).html())+1);
			var obj = document.getElementById(plikeid);
			obj.style.display = "none";
			var obj = document.getElementById(premoveid);
			obj.style.display = "";
			var obj = document.getElementById('added-to-my-events-'+eventid);
			obj.style.display = "";
		}
		else
		{
			getADialog('addEvent',false,'hidden',true,false,true,646,'center','2','请先登入');
			jQuery.get('ajax_add_event.php?ac=post',
			function(data){
				document.getElementById('popue_box').innerHTML=data;
			});
		}
	}
	);
}
//我不喜欢了
function dontlikeit(plikeid,premoveid,pnumid,eventid)
{
	$.get("Event.php?ac=dontlikeit&eventid="+eventid,
	function(data){
		if(data=='success'){
			//alert(parseInt($("#"+pnumid).html()));
			$("#"+pnumid).html((parseInt($("#"+pnumid).html())-1)+'');
			var obj = document.getElementById(plikeid);
			obj.style.display = "";
			var obj = document.getElementById(premoveid);
			obj.style.display = "none";
		}
		else
		{
			//$("#"+pDivId).html(pFail);
		}
	}
	);
}

//评价
function rateit(index,ptid)
{
	//显示
	for(i=1;i<6;i++)
	$(".star-rating").removeClass("rating-"+i);
	$(".star-rating").addClass("rating-"+index);
	//操作
	$.get("Event.php?ac=rateit&eventid="+ptid+"&rate="+index,
    function(data){
		if(data=='success'){
		//评论成功在概论里面替换内容
		//$("li").remove(".rate");
		var str='\
		  <li class="rating">\
		    <ol class="star-rating rating-'+index+' type-venue id- interactive">\
            <li class="rating-1"></li>\
            <li class="rating-2"></li>\
            <li class="rating-3"></li>\
            <li class="rating-4"></li>\
            <li class="rating-5"></li>\
            </ol>\
		  </li>\
		';
		$("li").remove(".rating");
		$(".photos").after(str);
		}
		else if(data=='tolog')
		{
		 alert("请先登入");
		}
    }
	);
}

//散步谣言的换问题
function changquestion(index,totalnum)
{
	var showindex=(index+1)>3?1:(index+1);
	$(".questions li:nth-child("+showindex+")").css({ "display": ""});
	disdow(100,'questions',index);
}
function disdow(alpha,objstr,index){
alpha=alpha-10;
$("."+objstr+" li:nth-child("+index+")").css({ "filter": "alpha(opacity="+alpha+")", "margin-top": ""+100-alpha+""});
if(alpha>0)
    setTimeout("disdow("+alpha+",'"+objstr+"',"+index+")",5);
else
	$(".questions li:nth-child("+index+")").css({ "filter": "alpha(opacity=100)", "display": "none", "margin-top": "0"});
}

//感兴趣的用户筛选功能
//筛选男生，女生，全部
function interestedfilter(eventid,what,obj,t)
{
	$(".filter > a").attr("class","all");
	$(obj).attr("class","current all");
	ajax_replace('list_2','event.php?ac=interestedfilter&eventid='+eventid+'&for='+what+'&t='+t,'');
}

//通过时间筛选活动
function filtereventbydate(what)
{
var sWidth=$("#event_list").width();
var sHeight=$("#event_list").height();
var bgObj=document.createElement("div");
var loadingimg='<img src="images/large_blue_dashes_circle.gif" alt="加载中" style="margin:25 120">';
bgObj.setAttribute('class','portlet portlet-');
bgObj.setAttribute('id','bg');
bgObj.style.position="absolute";
bgObj.style.background="#FFFFFF";
bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
bgObj.style.opacity="0.6";
bgObj.style.width=sWidth + "px";
bgObj.style.height=sHeight + "px";
bgObj.style.zIndex = "1000";
var loadingObj=document.createElement("div");
loadingObj.setAttribute('id','loading');
loadingObj.style.position="absolute";
loadingObj.style.background="#FFFFFF";
loadingObj.style.border="1px #AAAAAA solid";
loadingObj.style.margin="140 170";
loadingObj.style.border="1px #AAAAAA solid";
loadingObj.style.width="320px";
loadingObj.style.height="110px";
loadingObj.style.zIndex = "1001";
loadingObj.innerHTML=loadingimg;
$("#event_list").before(bgObj);
$("#event_list").before(loadingObj);
$.get('event.php?ac=ajaxfilterevent&for='+what,
    function(data){
		if(data){
		  $("#event_list").replaceWith(data);
		  $("#bg").remove();
		  $("#loading").remove();
		  init();
		}
		else
		{
		  alert('通信失败，请检查网络');
		  $("#bg").remove();
		  $("#loading").remove();
		}
    }
	);
}

function changeSelect(obj){
	$(".navigation > .selected").attr("class","unselected");
	$(obj).parent().attr("class","selected");
}


//分享活动
function shareEvent(opEvent,pLock_1,url,title,ev,width_1,coordinate){
	getADialog(opEvent,pLock_1,'hidden',true,false,true,width_1,coordinate,'2',title,ev);
	$.get(url,
	function(data){
		document.getElementById('popue_box').innerHTML=data;//替换弹出框中的内容
	});
}

//分享四种转换
function getshow(obj){
	for (i=0; i<=3; i++){
		if (i==obj){
			$("#list_"+i).removeClass("unselected");
			$("#list_"+i).addClass("selected");
			$("#info_"+i).css({display:''});
		}else{
			$("#list_"+i).removeClass("selected");
			$("#list_"+i).addClass("unselected");
			$("#info_"+i).css({display:'none'});
		}
	}
	htmlstr="";
	if (obj!=0){
		num=obj-1;
		htmlstr=htmlstr+"<input type='button' class='submit' onclick='getshow("+num+")' value='<上一个'>";
	}
	if(obj!=3){
		num=obj+1;
		htmlstr=htmlstr+"<input type='button' class='submit' onclick='getshow("+num+")' value='下一个>'>";
	}
	document.getElementById("show_what").innerHTML=htmlstr;
}

//活动分享中切换文字和输入文字
function switchInputTxt(pTxtObjId,pInputId){
	//alert($("#"+pTxtObjId).css("display"));
	if($("#"+pTxtObjId).css("display")=='none'){
	$("#"+pTxtObjId).css({display:""});
	$("#"+pInputId).css({display:"none"});
	$("#"+pTxtObjId).html($("#"+pInputId).val());
	}
	else{
	$("#"+pTxtObjId).css({display:"none"});
	$("#"+pInputId).css({display:""});
	$("#"+pInputId).focus();
	//document.getElementById(pInputId).focus();

	}
}

//发送活动共享的邮件的ajax方法

function sendmailSubmit(){
    var options = {
		url:  'event.php?ac=sendmail',
        beforeSubmit:function(formData, jqForm, options){
            var canSubmit=true;
            $('#messageSendState').html("");
            if(typeof($("#tags_id").attr("value"))=='undefined'&&($("#tagtoinput").attr("value")==''||$("#tagtoinput").attr("value")=='输入Email后，请按”回车“确认')){
            $('#messageSendState').html("请输入邮件的收件人");
            canSubmit=false;
            }
            if($("#message_subject_input").attr("value")==''){
            $('#messageSendState').html("请输入邮件的主题");
            canSubmit=false;
            }
            if($("#message_body").attr("value")==''){
            $('#messageSendState').html("请输入邮件的内容");
            canSubmit=false;
            }
            if(canSubmit){
                return true;
            }
            else {
                return false;
            }

		},
        success:function(responseText, statusText){
          if(statusText=="success"){
			  if(responseText.search("成功")>0){
			  ___Dialog['shareEvent_1'].CloseDialog();
			  showAlertContainer('y','邮件发送成功！过几分钟你的朋友就能收到你的邀请邮件了！')
			  }
			  else
			  $('#messageSendState').html("邮件发送失败，因为："+responseText);
          }
          else{
			  $('#messageSendState').html("邮件发送失败，通讯失败");
              
          }
			 // $("#TB_load").remove();
		}
    };
    $('#sendmailForm').ajaxForm(options);
    $('#sendmailForm').submit();//因为是按钮，所以没有submit的动作，所以需要此处触发下提交的动作
}


function ShowFrame(opEvent,pLock_1,url,title,ev,width_1,coordinate){
	getADialog(opEvent,pLock_1,'hidden',true,false,true,width_1,coordinate,'2',title,ev);
	$.get(url+'&opEvent='+opEvent,
	function(data){
		document.getElementById('popue_box').innerHTML=data;//替换弹出框中的内容
	});
}


function ajaxPostForm(obj,id,opEvent){
	$(obj).ajaxForm(function(r){
		___Dialog[opEvent].CloseDialog();
		showAlertContainer("y",r);
	})
}


function ScrollBtn(obj,btn,objto,op,BoxLen,ScrW){
	var maxLen = $(objto).children(".list").width();
	var ScrPos = $(objto).attr("scrollLeft");
	var Scr_n = eval(ScrPos+op+ScrW);
//	alert(ScrPos+"|||||"+op+"|||||"+ScrW+"|||||"+Scr_n);
	$(objto).animate({scrollLeft:Scr_n},{queue: false, duration: 1000});
	if (objto=="#list_1"){
		if (Scr_n>0){
			$("#left_11").css({display: ""});
		}else{
			$("#left_11").css({display: "none"});
		}
	}
	if (objto=="#list_2"){
		if (Scr_n>0){
			$("#left_12").css({display: ""});
		}else{
			$("#left_12").css({display: "none"});
		}
	}
}

function addAnotherUploadInput(obj){
	$('#uploadform').prepend('<input type="file" name="image[]" value="" />');
	if($('#uploadform > input').length>7)
	$(obj).css('display','none');

}

var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);

//复制URL地址
function setCopy(_sTxt){
	if(is_ie) {
		clipboardData.setData('Text',_sTxt);
		alert ("网址“"+_sTxt+"”\n已经复制到您的剪贴板中\n您可以使用Ctrl+V快捷键粘贴到需要的地方");
	} else {
		prompt("请复制网站地址:",_sTxt); 
	}
}


function ShowFrame_box(opEvent,url,title,ev,login){
	width_l =	466;
	if (login == 0){
		width_l = 640;
	}
	getADialog(opEvent,false,'hidden',true,false,true,width_l,'center','2',title,ev);
	$.get(url+"&opEvent="+opEvent,function(data){
		$("#popue_box").html(TextPlace(data));
		//document.getElementById('popue_box').innerHTML=data;//替换弹出框中的内容
	});
}
function TextPlace(str){
	return str.replace("waiting_for_the_other_test","好友请求验证中...");
}


  //图片按比例缩放
  var   flag=false;
function   DrawImage(ImgD,Tw,Th){
  var   image=new   Image();
  var   iwidth   =   Tw;     //定义允许图片宽度
  var   iheight   =   Th;     //定义允许图片高度
  image.src=ImgD.src;
  if(image.width>0   &&   image.height>0){
  flag=true;
  if(image.width/image.height>=   iwidth/iheight){
  if(image.width>iwidth){
  ImgD.width=iwidth;
  ImgD.height=(image.height*iwidth)/image.width;
  }else{
  ImgD.width=image.width;
  ImgD.height=image.height;
  }
  ImgD.alt=image.width+"×"+image.height;
  }
  else{
  if(image.height>iheight){
  ImgD.height=iheight;
  ImgD.width=(image.width*iheight)/image.height;
  }else{
  ImgD.width=image.width;
  ImgD.height=image.height;
  }
  ImgD.alt=image.width+"×"+image.height;
  }
  }
}

function mdate_del(dateid,uid){
$.get('space.php?do=event&flag=delplugdata&uid='+uid+'&dataid='+dataid,
	function(data){
		alert(data);
	});
}

//以下是小Q活动专用
//------------------------------------------------------------
function event_refresh(obj){
$.get('xiaoq.php?flag=ajax_get_list&tab='+obj,
    function(data){
		if(data){
		  document.getElementById('event_index').innerHTML=data;
		}else{
		  alert('通信失败，请检查网络');
		}
    }
	);
}

function getkufouinfo(obj){
$.get('xiaoq.php?flag=ajax_get_info&arrid='+obj,
    function(data){
		if(data){
			if(data=="first"){
				alert("已是最前一个");
			}else if(data=="last"){
				alert("已是最后一个");
			}else{
				document.getElementById('xiaoq_mm').innerHTML=data;
			}
		}else{
			alert("参数传递错误");
		}
    });
}
//------------------------------------------------------------

