// JavaScript Document
//当前用户景点想来来过弹出层
function showComeInfo (id) {
	var impress = $("#user_impress").val();
	var reivew = $("#user_review").val();
	$("#"+id+'_impress').val(impress);
	$("#"+id+'_contents').val(reivew);
	myshow(id);
}
function setClickImpress(tags, id) {
	var impress = $("#"+id+'_impress').val();
	impress = impress + tags + ' ' ;
	$("#"+id+'_impress').val(impress);
//	$("#user_impress").val(impress);
}
function setClickTag(tags, id) {
	var impress = $("#"+id+'_tags').val();
	impress = impress + tags + ' ' ;
	$("#"+id+'_tags').val(impress);
//	$("#user_impress").val(impress);
}
function resetThisDiv(id) {
	$("#"+id+'_impress').val('');
	$("#"+id+'_contents').val('');
	//$("#user_point").val('');
	dispalymyshow(id);
}
//设置评分星
function setClass(num, strid) {
	//__this.className = "on";
	var objid = document.getElementById(strid);
	var tags = objid.getElementsByTagName('li');
	var tagsNum = tags.length;
	for (var i = 0; i < tagsNum; i++) {
		if (i < num) {
			tags[i].className = "on";
		} else {
			tags[i].className = "off";
		}
	}
}
//取消评分星
function resetClass(strid){
	var objid = document.getElementById(strid);
	var tags = objid.getElementsByTagName('li');
	var tagsNum = tags.length;
	for (var i = 0; i < tagsNum; i++) {
		tags[i].className = "off";
	}
}

function setDivHtml(strid) {
	var powerhtml = $("#"+strid).html();
	$("#point_power").html(powerhtml);
	myshow('addinfo');
}
/* 评分 短评 印象弹出成 */
function setAddInfoDiv(types, num, impress) {
	//myshow('addinfo');
//	$("#point_power").html('');
	//1 评分 2印象 3 短评
	var power = $("#user_point").val();
	if (types == 1) {
		showComeInfo('addinfo');
		setClass(num, "point_power");
	} else if (types == 2) {
		showComeInfo('addinfo');
		$("#addinfo_open").show();
		$("#addinfo_close").hide();
		$(".addinfo_h").hide();
		setClass(power, 'point_power');
		var objid = document.getElementById('addinfo_impress');
		if (impress != '' && typeof impress != 'undefined') objid.value = impress + ' ';

		if (isFirefox=navigator.userAgent.indexOf("Firefox") <= 0) {
			if(objid==null){
   				objid=event.srcElement;
			}
			var rtextRange =objid.createTextRange();
			rtextRange.moveStart('character',objid.value.length);
			rtextRange.collapse(true);
			rtextRange.select();
		} else {
			objid.focus();	
		}
	//	objid.focus();
		//resetClass("point_power");
	} else if (types == 4) {
		showComeInfo('addinfo');
		var objid = document.getElementById('addinfo_tags');
		if (impress != '' && typeof impress != 'undefined') objid.value = impress + ' ';
		if (isFirefox=navigator.userAgent.indexOf("Firefox") <= 0) {
			if(objid==null){
   				objid=event.srcElement;
			}
			var rtextRange =objid.createTextRange();
			rtextRange.moveStart('character',objid.value.length);
			rtextRange.collapse(true);
			rtextRange.select();
		} else {
			objid.focus();	
		}
	} else {
		showComeInfo('addinfo');
		setClass(power, 'point_power');
		var objid = document.getElementById('addinfo_contents');
		objid.focus();
		//resetClass("point_power");
	}
}
//添加标签
function userAddTag(name) {
	if (name != '' || typeof name != 'undefined') {
		setAddInfoDiv(4,0,name);
	} else {
		setAddInfoDiv(4);
	}
}
function sendTerminiInfo(strid) {
	var come = $("#"+strid+'_come').val();
	var iscome = $("#user_iscome").val();
	if (typeof come == 'undefined') come = '';
	var impress = $("#"+strid+'_impress').val();
	var contents = $("#"+strid+'_contents').val();
	var ttags = $("#"+strid+'_tags').val();
	var tid = $("#terminiid").val();
	var isimpress = $("#user_isimpress").val();
	var isreview = $("#user_isreview").val();
	var ispoint = $("#user_ispoint").val();
	var elder_2 = $("#addressid").val();
	var issearch = $("#issearch").val();
	//var title = $("#terminititle").val();
	
	//获取分数
	if (strid == 'comedone') {
		var powerid = document.getElementById('point_power1');	
	} else {
		var powerid = document.getElementById('point_power');
	}
	var tags = powerid.getElementsByTagName('li');
	var tagsNum = tags.length;
	var point = 0;
	for (var i = 0; i < tagsNum; i++) {
		//alert(tags[i].className)
		if (tags[i].className == 'on') {
			point += 1;	
		} else {
			break;	
		}
	}
	//alert(come); return false;
	//alert(come+'--'+impress+'--'+contents);
	$.ajax({
		url: "/termini.php?switch=addterminiinfo",
		data: "&come="+come+"&impress="+impress+"&contents="+contents+"&tid="+tid+'&point='+point+'&iscome='+iscome+'&isimpress='+isimpress+'&isreview='+isreview+'&ispoint='+ispoint+"&elder_2="+elder_2+"&title="+g_termini_title+"&tags="+ttags,
		type: "post",
		dataType :"json",
		success:function(msg) {
			/*var arrInfo = eval(msg);
			if (arrInfo['done'] == 1) {
				$("#noeditcome").hide();
				$("#editcome").show();
				if (arrInfo.impress != '') {
					$("#userimpress").html("印象："+arrInfo.impress);
					$("#user_impress").val(arrInfo.impress);
				}
			}*/
			dispalymyshow(strid);
			if (issearch != 1) window.location.reload();		
		}
	});
}
//高级显示隐藏
function showHeight(cls, op, cl) {
	$("."+cls).show();
	$("#"+op).hide();
	$("#"+cl).show();
}
function hideHeight(cls, op, cl) {
	$("."+cls).hide();
	$("#"+op).show();
	$("#"+cl).hide();
}
//设置有用无用
function setGood(types, isgood, strid, id) {
	$.ajax({
		url: "/termini.php?switch=setgoodbad",
		data: "&types="+types+"&isgood="+isgood+"&id="+id,
		type: "post",
		success:function(msg) {
			var num = $("#"+strid).html() * 1;
			if (msg == 1) {
				$("#"+strid).html(num+1);
			} else if (msg == 2) {
				alert('请登录');	
			} else if (msg == 3) {
				alert("你已经设置过一次了");	
			}
		}
	});	
}
//折叠文章
function setHideLog(id) {
	$("#big_"+id).hide();
	$("#setgood_"+id).hide();
	$("#small_"+id).show();
}
//显示文章
function setShowLog(id) {
	$("#big_"+id).show();
	$("#setgood_"+id).show();
	$("#small_"+id).hide();
}

//热门游记
function getHotTriplog(ishot, __this, otherid) {
	var objid = document.getElementById(otherid);
	__this.className = 'conner_a ml_5';
	objid.className = 'ml_5';
	var id = $("#terminiid").val();
	$.ajax({
		url: "/termini.php?switch=gettriplog",
		data: "&ishot="+ishot+"&id="+id,
		type: "post",
		success:function(msg) {
			$("#termini_log").html(msg);
		}
	});		
}

//创建地图
var map = null;
function gMapLoad() {
	if (GBrowserIsCompatible()) {
		var mapid = document.getElementById("map");
        map = new GMap2(mapid);
        map.setCenter(new GLatLng(39.917, 116.397), 3);
		//map.addControl(new GSmallMapControl());
		//map.addControl(new GMapTypeControl());
        geocoder = new GClientGeocoder();
		mapid.childNodes[1].style.display = "none"; 
   		mapid.childNodes[2].style.display = "none"; 
  	}
	if (g_termini_latlng != '') {
		var newArr = g_termini_latlng.split(',');
		lat = newArr[0].substring(1);
		lng = newArr[1].substring(1, newArr[1].length-1);
		var setpoint = new GLatLng(lat,lng);
		map.setCenter(setpoint, 13);
		var marker =  map.addOverlay(new GMarker(setpoint));
	} else {
		 positionAddress(g_termini_address);
	}
}
//定位
function positionAddress(address) {
	if (geocoder) {
    	geocoder.getLatLng(
        	address,
        	function(point) {
        		if (!point) {
					$("#nomap").show();
					$("#map").hide();
           		//	alert('您输入的地址可能过于精细，请放大范围在试试');
					return 2;
        		} else {
				//	alert(point);
					map.setCenter(point, 13);
					var marker =  map.addOverlay(new GMarker(point));
       			}
   			}
   		)
   }
}

//回车提交搜索
function keyDown(event) {
	if (event.keyCode == 13) {
		document.form1.submit();
		return false;
		//var keyword = $("#keyword").val();
		//window.location.href = static_web + 'result--keyword-' + encodeURI(keyword) + '.html';
	}
}

//搜索页面想来来过
function searchCome(id, types) {
	$.ajax({
		url: "/termini.php?switch=ajaxsearchbox",
		data: "&id="+id+"&types="+types,
		type: "post",
		success:function(msg) {
			if (msg == 2) {
				alert('请先登录');
				return false;
			}
			$("#comedone").html(msg);
			showComeInfo('comedone');
		}
	});	
}
//简介展开
function setShowDes(objid1, objid2) {
	$("#"+objid1).hide();
	$("#"+objid2).show();
}
function setStrLen(str, __this) {
	//var len = strLen(str);
	var len = str.length;
	if (len <= 140) {
		var num = 140 - len;
		$("#textlen").html('还能输入'+ num + '个字');	
	} else {
		__this.blur();	
	}
	/*if (len <= 140) {
		var num = 140 - len;
		
	} else {
			
	}*/
}
//检查长度
function strLen(classname){
	var sStr,iCount,i,strTemp ; 
	iCount = 0 ;
	sStr = classname.split("");
	for (i = 0 ; i < sStr.length ; i ++){
		strTemp = escape(sStr[i]); 
		if (strTemp.indexOf("%u",0) == -1) { 
			iCount = iCount + 1 ;
		} else {
			iCount = iCount + 2 ;
		}
	}
	return iCount ;
}

//是否显示评分 0来过 1想来
function isShowPoint(iscome) {
	$("#addinfo_come").val(iscome);
	if (iscome == 1) {
		$("#show_point").hide();
		var objid = document.getElementById('point_power');
		var tags = objid.getElementsByTagName('li');
		for (var i = 0; i < tags.length; i++) {
			tags[i].className = "off";	
		}
	} else {
		$("#show_point").show();
	}
}

//投票
function setVote(id, uid) {
	if (uid == '' || typeof uid == 'undefined') {
		alert('您还没有登录'); return false;	
	}
	$.ajax({
		url: "/termini.php?switch=ajaxvote",
		data: "&id="+id,
		type: "post",
		success:function(msg) {
			if (msg == 1) {
				alert('投票成功');
				var vote = $("#vote_num_"+id).val();
				var v = vote * 1 + 1;
				$("#vote_"+id).text('(' + v +'票)');
			} else if (msg == 2) {
				alert('投票失败，请刷新页面重试');
			} else if (msg == 3) {
				alert('参数错误');
			} else if (msg == 4) {
				alert('您已经投过了');
			} else {
				alert('您还没有登录');
			}
		}
	});
}