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 placeSubmit()
{
//alert();
//return false;
  var myForm = document.post_place;  
  var submitto = myForm.submitto.value;  
  
  if(myForm.place_name.value=="")
  {
     alert('请输入地点名称！');
    // myForm.date_name.focus();
     return false;
  }
  if(myForm.place_class.value=="")
  {
     alert('请选择地点分类！');
     //myForm.date_city.focus();
     return false;
  }
 
  if(submitto=='fill'&&myForm.place_local_city.value=='')
  {
     alert('请选择地点所在城市！');
     //myForm.place.focus();
     return false;
  }
	
  if(myForm.place_address.value=='')
  {
     alert('请填写详细地址！');
     return false;
  }
	myForm.place_classname.value=document.getElementById("place_class").options[getSelectedIndex('place_class')].text;
	if(submitto=='fill')
	{
	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;
	}
  document.post_place.submit();
}




//我喜欢这个地点
function likeit(plikeid,premoveid,pnumid,placeid)
{
	$.get("place.php?ac=likeit&placeid="+placeid,
	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 = "";
		}
		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,placeid)
{
	$.get("place.php?ac=dontlikeit&placeid="+placeid,
	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 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 rateit(index,ppid)
{
	//显示
	for(i=1;i<6;i++)
	$(".star-rating").removeClass("rating-"+i); 
	$(".star-rating").addClass("rating-"+index); 
	//操作
	$.get("place.php?ac=rateit&placeid="+ppid+"&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");
		$(".events").after(str);
		}
		else if(data=='tolog')
		{
		 alert("请先登入");
		}
    }
	);
}

//to submit the form of commques
function ajax_form_send_commques(FormName,ToUrl)
{
 var options = { 
		url:  ToUrl,
        beforeSubmit:function(formData, jqForm, options){

          return true; 
		},
        success:function(responseText, statusText){
          alert(responseText);
		}
    }; 
    $('#'+FormName+'').ajaxForm(options); 
}
//
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 interestedfilter(placeid,what,obj,t)
{
	$(".filter > a").attr("class","all");
	$(obj).attr("class","current all");
	ajax_replace('list_2','place.php?ac=interestedfilter&placeid='+placeid+'&for='+what+'&t='+t,'');
}

//
//地点详情中的相关联的活动的我喜欢这个地点
function place2eventlikeit(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
		{
			//$("#"+pDivId).html(pFail);
		}
	}
	);
}


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,3000);
	})
}

function addAnotherUploadInput(obj){
	$('#uploadform').prepend('<input type="file" name="image[]" value="" />');
	if($('#uploadform > input').length>7)
	$(obj).css('display','none');

}
//分享地点
function sharePlace(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的动作，所以需要此处触发下提交的动作
}

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","好友请求验证中...");
}


function search_palce_same(val)
{
//alert();
if(val.length>1){
$.get('ajax_add_place.php?ac=getsameplace&input='+escape(val),
    function(data){
		if(data){
		//alert(data);
          $("#placehaved").css('display','block');
		  $("#placehaved").html(data);
		}
		else
		{
		  $("#placehaved").html('');
          $("#placehaved").css({display:'none'});
		}
    }
	);
  }
}


  //图片按比例缩放
  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 bookshow(obj, id){
	if(obj==1){
		document.getElementById(id).style.display="";
	}else{
		document.getElementById(id).style.display="none";
	}
}

function ajaxBookSubmit(obj,id){
	$(obj).ajaxForm(function(r){
		showAlertContainer("y",r,3000);
		document.getElementById(id).style.display="none";
	})
}

function ajaxVoteForm(obj){
	$(obj).ajaxForm(function(r){
		showAlertContainer("y",r,3000);
	})
}
