var defaultBackUrl = "/index.php"; // 切换城市的默认跳转页面


/** 城市切换*/
$(document).ready(function() {
	$('.citySwitchHref').cluetip({activation: 'click', local: true,sticky: true, closePosition: 'title',positionBy: 'mouse', leftOffset: -20, closeText: '[取消]'});
});

/* -------------- 工具方法 ------------------------*/

/** 将URL中参数值替换为特定值(注意只支持URL中只有一个你给定的参数 )*/
function replateUrlParameter(pName, pValue, url){
	if (url) {
		;;
	} else {
		url = document.location + '';		
	}
	indexOfPara = url.indexOf(pName);
	if ( indexOfPara > 0) {		
		/** 判断pName是不是最后一个参数 */
		endOfPara = url.indexOf('&', indexOfPara); 
		if ( endOfPara > 0) {		
			/* cate_id不是最后一个参数 */
			url = url.substring(0, indexOfPara) + pName + "=" + pValue + url.substring(endOfPara);			
		} else {
			/* cate_id是最后一个参数 */
			url = url.substring(0, indexOfPara) + pName + "=" + pValue;
		}
	} else {
		/** URL没有pName*/
		if ( url.indexOf('?') > 0 ) {
			/** URL有其他参数 */
			url += "&" + pName + "=" + pValue;
		} else {
			/** URL还没有任何参数 */
			url += "?" + pName + "=" + pValue;
		}
	}	
	return url;
}


/* ----------------------页面方法 -------------------------*/

/** 切换城市，并返回原页面*/
function citySwitch(cityId){	
	backUrl = document.location + '';
	if (backUrl.indexOf('detail.php') > 0 ) {
		backUrl = defaultBackUrl;
	}	
	document.location = replateUrlParameter('city_id', cityId, backUrl);	
}
/** 点击更多城市，到达所有城市页面 */
function moreCitySwitch(moreClick){			
	forward = moreClick.href;	
	if ( forward.indexOf('?') > 0 ) { 
		forward += "&back_url=" + escape(document.location + '');  
	} else {
		forward += "?back_url=" + escape(document.location + '');  
	}	
	document.location = forward;
}

/**
 * 从所有城市页面跳转回原来的页面
 */
function goBackFromCitySwitch(backUrl, cityId){	
	if (backUrl.indexOf('detail.php') > 0 ) {
		backUrl = defaultBackUrl;
	}
	if (backUrl.indexOf('show_all_cities.php') > 0 ) {
		backUrl = defaultBackUrl;
	}		
	document.location = replateUrlParameter('city_id', cityId, backUrl);	
}

/** 
 * 检查用户评论
 */
function insertComment()
{
	theForm = document.poiComment;
	contentLeng = theForm.comment_content.value.length;	
	if(contentLeng == 0)
	{
		alert("您没有发表评论!");				
	}
	else
	{
		if(contentLeng > 300){
			alert("您输入的评论太长！");						
		} else {			
			theForm.submit();
		}
	}
}

/**
 * 检查周边店铺
 */
function showSurround(cateId){		
	document.location = replateUrlParameter('cate_id', cateId);	;
}