
//将PX值转成数字
function getPositionNum(pos) {
	return pos.replace("px","")*1;
}

var doc = document.all;

function v() {return ;}

function recordLoginCookie(){try{setCookie("loginName",document.getElementById("userName").value,3);}catch(e){}return true}

//-----打开前置的模式窗口[0]
//可用参数：urls，styles_t-top位置，styles_l--left位置，styles_w--窗口的宽，styles_h--窗口的高
function openbox_arrf(urls,styles_t,styles_l,styles_w,styles_h,strStyle,cT){
  var PrintStyle = "scroll:"+strStyle;
  var dialogArgs = new Array(); //定义参数 
  var result = new Array(); //定义参数   
  dialogArgs=cT; //参数赋值 
  styles = PrintStyle+";help:off;unadorned:no;center:yes;status:no;resizable:no;dialogTop:"+styles_t+";dialogLeft:"+styles_l+";dialogWidth:"+styles_w+"px;dialogHeight:"+styles_h+"px";
  result = showModalDialog(urls,dialogArgs,styles);
  try{return result;}
  catch(e){return 1}
}

function getCookie(NameOfCookie){
	if(document.cookie.length>0){
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin!=-1){
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";",begin);
			if (end==-1) end=document.cookie.length;
			return replaceAll(decodeURI(unescape(document.cookie.substring(begin,end)))," ","+");
		}return null;
	}return null;
}
function setCookie(NameOfCookie,value,expiredays){
	var ExpireDate = new Date();
	ExpireDate.setTime(ExpireDate.getTime()+(expiredays*24*3600*1000));
	document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays==null)?"":";expires="+ExpireDate.toGMTString()+";path=/");
}
function delCookie(NameOfCookie){
	var exp = new Date();
	exp.setTime(exp.getTime()-1);
	if(getCookie(NameOfCookie)!=null){document.cookie = NameOfCookie + "=" + ";expires="+exp.toGMTString();}
}
function hasChecked(cbid) {
	var cb = document.all[cbid];
	if(cb) {
		if(cb.length) {
			for(i=0;i<cb.length;i++) {
				if(cb[i].checked) {
					return true;
				}
			}
		} else {
			if(cb.checked) {
				return true;
			}
		}
	}
	return false;
}
/*通用checkbox检查*/

function commonCBCheck(cbid,alertStr,form) {
	if(hasChecked(cbid)) {
		if(confirm("你确定要进行此操作？")) {
			form.submit();
			return true;
		}
	} else {
		alert(alertStr);
		return false;
	}
	
}

/*通用checkbox检查*/

function commonCBCheckAndSend(cbid,alertStr,form, action) {
	if(hasChecked(cbid)) {
		if(confirm("你确定要进行此操作？")) {
			form.action = action;
			//alert(form.action);
			form.submit();
			return true;
		}
	} else {
		alert(alertStr);
		return false;
	}
	
}


/**
*	检测字符长度
*/
function checkLength(str,len) {
	if(str.length>len)
		return false;
	return true;
}
/**
* 截取字符
*/
function render(ele,size) {
	if(!checkLength(ele.value,size)) {
		ele.value = ele.value.substr(0,size);
	}
}
/**
*	显示WIN层
*/
function openWin(win) {
	//alert(window.event.clientY);
	//alert(win.id);
	//win.position = "absolute";
	win.style.display = "block";
	//win.style.top = window.event.clientY;
	//win.style.left = window.event.clientX;
	
	win.style.zIndex = "999";
}

/**
*	隐藏WIN层
*/
function closeWin(win) {
	win.style.display = "none";
}

/**
*	在转跳之前进行检测
*   tips:提示信息,如:你还否要.... 
* 	url:转跳的地址
*/
function redirectURL(tips,url) {
	
	if(confirm(tips)) {
		//alert(confirm(tips));
		self.location.href = url;
		return true;
	}
	return false;
}

/**
*	在转跳之前进行检测
*   tips:提示信息,如:你还否要.... 
* 	url:转跳的地址
*   options:可选属性
*/
function redirectURL(tips,url,options) {
	if(confirm(tips)) {
		//alert(confirm(tips));
		if(options!=null && options.type=="ajax") {
			new Ajax.Updater('',url, {asynchronous:true,onComplete:options.callBack,evalScripts:true});
		} else {
			self.location.href = url;
		}
		return true;
	}
	return false;
}

/**
*	在转跳之前进行检测
*   tips:提示信息,如:你还否要.... 
* 	url:转跳的地址
*/
function redirectAjaxURL() {
	Event.observe(document.body, 'click', function(event) {
	  	var elt = Event.element(event);
	  	if ('A' == elt.tagName && 'ajaxRedirect' == elt.className){
	  		Event.stop(event);
	  		if(confirm(elt.tips)) {
				new Ajax.Updater('',elt.href, {asynchronous:true,onComplete:refrashPage,evalScripts:true}); 
			}
		}
	});
}
function refrashPage(originalRequest) {
	self.location.reload();
}
/**
 * 添加收藏
*/
function addFavorite(typeCode,objectID) {
	new Ajax.Updater('', '/favoriteFrontManager.do?method=addFavorite&typeCode=' + typeCode + "&objectID=" + objectID, {asynchronous:true,onComplete:addFavoriteCallBack,evalScripts:true}); 
}
function addFavoriteCallBack(originalRequest) {
	if(originalRequest.responseText.Trim() == 'Login') {
		openLoginPanel();
	} else {
		callBack(originalRequest);
	}
}
/**
 * 处理AJAX返回信息
*/
function dealAjaxReturnInfo(originalRequest) {
	alert(originalRequest.responseText);
}

/**
 * 读取用户的小组列表
*/

function loadTeamList(memberId) {
	new Ajax.Updater('myTeams', '/mySpaceScript.do?method=myTeamList&memberId=' + memberId, {asynchronous:true,evalScripts:true});
}

function loadFriendList(memberId) {
	new Ajax.Updater('myFriends', '/mySpaceScript.do?method=myFriendList&memberId=' + memberId, {asynchronous:true,evalScripts:true});
}

function loadClicksTopnTeamList() {
	new Ajax.Updater('clicksTopnTeamList', '/teamListAction.do?method=clicksTopnTeamList', {asynchronous:true,evalScripts:true});
}

function loadTeamDetailRightDiv(teamId) {
	//alert('teamListAction.do?method=loadTeamDetailRightDiv&teamid'+teamId);
	new Ajax.Updater('teamDetailRightDiv', '/teamListAction.do?method=loadTeamDetailRightDiv&teamid='+teamId, {asynchronous:true,evalScripts:true});
}

function loadTeamInfoDiv(teamId) {
	//alert('teamListAction.do?method=loadTeamDetailRightDiv&teamid'+teamId);
	new Ajax.Updater('teamLeft', '/teamInfo.do?teamId='+teamId, {asynchronous:true,evalScripts:true});
}

function setPicAsBlogTopPic(postId) {
	$(postId).innerHTML = "<font color=green>请稍候...</font>";
	new Ajax.Updater('', '/postFrontManager.do?method=setPicAsBlogTopPic&postId='+postId, {asynchronous:true,onComplete:updateBlogTop,evalScripts:true});
	
}

function cancelPicAsBlogTopPic(postId) {
	$(postId).innerHTML = "<font color=green>请稍候...</font>";
	new Ajax.Updater('', '/postFrontManager.do?method=cancelPicAsBlogTopPic&postId='+postId, {asynchronous:true,onComplete:updateBlogTop,evalScripts:true});
	
}

function updateBlogTop(originalRequest) {

	if(originalRequest.responseText=="-1") {
		alert('推荐失败');
	}
	if(originalRequest.responseText=="-2") {
		alert('撤消推荐失败');
	}
	if(originalRequest.responseText.indexOf('submit')!=-1) {
		//alert(originalRequest.responseText);
		var id = originalRequest.responseText.split('_');
		//alert(id[0]);
		$(id[0]).innerHTML = "<a href='javascript:v()' onclick='cancelPicAsBlogTopPic("+id[0]+")' target='_self'><font color='red'>撤消推荐</font></a>";
	}
	if(originalRequest.responseText.indexOf('cancel')!=-1) {
		//alert(originalRequest.responseText);
		var id = originalRequest.responseText.split('_');
		//alert(id[0]);
		$(id[0]).innerHTML = "<a href='javascript:v()' onclick='setPicAsBlogTopPic("+id[0]+")' target='_self'><font color='blue'>我的推荐</font></a>";
	}
}
//将悬浮层的位置定位在屏幕中央
/*
function setDivLocation(objdiv,obj,top,left){
		
	if(obj!=null) {
		if(window.event.clientY>210 && window.event.clientY<500) {
			//alert(1);
			//alert(window.event.clientY);
			objdiv.style.top = obj[0];
			objdiv.style.left = obj[1];
		} else if(window.event.clientY>130 && window.event.clientY<500) {
			//alert(2);
			//alert(window.event.clientY);
			objdiv.style.top = window.event.clientY ;
			objdiv.style.left = obj[1];
		} else {
			alert(3);
			alert(window.event.clientY);
			objdiv.style.top = window.event.clientY + 100;
			objdiv.style.left = obj[1];
		}
	} else {
		//alert(4);
		objdiv.style.top = top;
		objdiv.style.left = left;
	}
}
*/
//将悬浮层的位置定位在屏幕中央
function setDivLocation(objdiv,obj,top,left){
		
	if(obj!=null) {
		var p = Position.cumulativeOffset(obj);
		//alert(p); 
		
		objdiv.style.top = p[1];
		objdiv.style.left = p[0];
		if(getPositionNum(objdiv.style.left)>700 ) {
			objdiv.style.left = getPositionNum(objdiv.style.left) - objdiv.offsetWidth + obj.offsetWidth + "px";
		}
		
	} else {
		objdiv.style.top = top;
		objdiv.style.left = left;
	}
}

/*
	@function - 去两边空格
	@param  - 
	@return 
*/
String.prototype.Trim = function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
/**
* - 初始化下拉框，使之默认选中initValue
* @param obj			//目标select域对象	
* @param initValue		//需要Select的值
*/
function initSelect(obj,initValue){
	try{
		var someNodeList = obj.getElementsByTagName('option');
    	var nodes = $A(someNodeList);
		var nIndex = 1;
		var i = 1;
    	nodes.each(function(node){
            if (node.innerHTML==initValue)
            	nIndex = i;
            i++;
        	});
    	obj.selectedIndex = (nIndex-1);  				
	}catch(e){window.status=e}	
}
/*
function hasUnreadNotes(originalRequest) {
	new Ajax.Updater('', 'checkUnreadNotesAJAX.do', {asynchronous:true, evalScripts:true,onComplete:noteAlert}); 
	return false;
}

function noteAlert(originalRequest) {
	if(originalRequest.responseText!="0") {
		$('unReadNotes').style.display = "inline";
		//alert(originalRequest.responseText);
		$('noteImg').alt = originalRequest.responseText;
		$('noteImg').src = "/images/icon_email2.gif";
	}
}
*/
function checkAll(checkBox,cbIndex) {
	var cb = document.all[checkBox];
	if(cb!=null) {
		if(cb.length) {
			for(i=0;i<cb.length;i++) {
				cb[i].checked = cbIndex.checked;
			}
		} else {
			cb.checked = cbIndex.checked;
		}	
	}
}

/**
 普通的reload列表方法
 div:填充列表的层或任何时候有innerHTML属性的标签
*/
function reloadList(div) {
	//alert(self.location.href);
	var url = self.location.href;
	if(url.indexOf("#")!=-1) {
		//alert(url);
		url = url.replace("#","&goto=page");
		//alert(url);
	}
	new Ajax.Updater(div, url, {asynchronous:true, evalScripts:true});
}

function switchCss(vFolder,cCurID,enabledName,disabledName){
		try{
			//alert(vFolder.length);
			for (var i=0;i<vFolder.length;i++){
//				alert("cCurID="+cCurID+"\n\nvFolder["+i+"]="+vFolder[i]+"\n\nvFolder["+i+"].className="+$(vFolder[i]+"T").className);
				var cVF = vFolder[i];
				if (cVF==cCurID){
					//document.getElementById(cVF).className='menubar';					
					//$("img"+i).src="/style/default/header/img/search_m0"+(i+1)+"b.gif";		//v1.0文件夹切换
					$(cVF).className=enabledName;
					
				}else{
					try{
						if ($(cVF).style.display!='none'){
							//document.getElementById(cVF).className='menubar1';
							//$("img"+i).src="/style/default/header/img/search_m0"+(i+1)+".gif";		//v1.0文件夹切换
							$(cVF).className=disabledName;
						}
					}catch(e){}	//-如果传入参数与定义的数组不一致时跳过
				}
			}
		}catch(e){alert("switchCss:"+e)}
	}
	
	// 明星驴友游记
 	function starMemberPostList(memberId,div,count) {
		//alert(div);
		new Ajax.Updater(div, "/memberFrontScript.do?method=starMemberPostList&count="+count+"&memberId="+memberId, {asynchronous:true, evalScripts:true});
	}
	// 明星驴友日记
	function starMemberDiaryList(memberId,div,count) {
		new Ajax.Updater(div, "/memberFrontScript.do?method=starMemberDiaryList&count="+count+"&memberId="+memberId, {asynchronous:true, evalScripts:true});
	}
	// 明星驴友相册
	function starMemberPictureList(memberId,div,count) {
		//alert(count);
		new Ajax.Updater(div, "/memberFrontScript.do?method=starMemberPictureList&count="+count+"&memberId="+memberId, {asynchronous:true, evalScripts:true});
	}
	
		// 明星驴友游记(首页显示)
 	function indexStarMemberPostList(memberId,div,count) {
		//alert(div);
		new Ajax.Updater(div, "/memberFrontScript.do?method=indexStarMemberPostList&count="+count+"&memberId="+memberId, {asynchronous:true, evalScripts:true});
	}
	// 明星驴友日记(首页显示)
	function indexStarMemberDiaryList(memberId,div,count) {
		new Ajax.Updater(div, "/memberFrontScript.do?method=indexStarMemberDiaryList&count="+count+"&memberId="+memberId, {asynchronous:true, evalScripts:true});
	}
	// 明星驴友相册(首页显示)
	function indexStarMemberPictureList(memberId,div,count) {
		//alert(count);
		new Ajax.Updater(div, "/memberFrontScript.do?method=indexStarMemberPictureList&count="+count+"&memberId="+memberId, {asynchronous:true, evalScripts:true});
	}
	
	// 显示字数
	function showStrLen(ele,strLimit,showLenDiv) {
		render(ele,strLimit);
		$(showLenDiv).innerHTML = "字数:" + ele.innerHTML.length;
	}	
	
	function marksOnShowPage(targetId,targetType,targetMemberId) {
		new Ajax.Updater('marksOnShowPage', "/markList.do?method="+targetType+"MarksOnShowPage&targetId="+targetId+"&targetType="+targetType+"&targetMemberId="+targetMemberId, {asynchronous:true, evalScripts:true});
	}
		
	function cg_rightSideBar() {
		new Ajax.Updater('cg_rightSideBar', '/cityGroup.do?method=cgRightSideBar&count=10', {asynchronous:true,evalScripts:true});
	}
	
	function postManager(postId) {
		new Ajax.Updater('manager', '/postFrontManager.do?method=postManager&postId='+postId, {asynchronous:true,evalScripts:true});
	}
	
	function albumManager(postId) {
		new Ajax.Updater('manager', '/postFrontManager.do?method=albumManager&postId='+postId, {asynchronous:true,evalScripts:true});
	}
	function recordPostClick(id) {
		new Ajax.Updater('', '/click.do?method=recordPostClick&id='+id, {asynchronous:true,evalScripts:true});
	}
	function recordClick(id) {
		new Ajax.Updater('', '/click.do?method=recordClick&id='+id, {asynchronous:true,evalScripts:true});
	}
	function credit(id,type) {
		new Ajax.Updater('credit', '/click.do?method='+type+'Credit&id='+id, {asynchronous:true,evalScripts:true});
	}
	function memberInfo(id) {
		new Ajax.Updater('memberInfo', '/memberInfo.do?memberId='+id, {asynchronous:true,evalScripts:true});
	}	
	function recordReviewClick(id) {
		new Ajax.Updater('', '/review.do?method=stat&field=hitTotal&show=false&id='+id, {asynchronous:true,evalScripts:true});
	}	
	
	
// 相关内容页面的评论显示
function commentsOnShowPage(targetId,targetType,targetMemberId) {
	new Ajax.Updater('commentsOnShowPage', "/comment.do?method=commentsOnShowPage&targetId="+targetId+"&targetType="+targetType+"&targetMemberId="+targetMemberId, {asynchronous:true, evalScripts:true});
}
	
	function loadLogin(){
		new Ajax.Updater('loginDiv', '/module/loginPanel.vm', {asynchronous:true,evalScripts:true}); 
	}
	
	function starTeamPostList(teamId,div) {
		new Ajax.Updater(div, "/teamListAction.do?method=starTeamPostList&count=5&teamid="+teamId, {asynchronous:true, evalScripts:true});
	}
	function starTeamPicList(teamId,div) {
		new Ajax.Updater(div, "/teamListAction.do?method=starTeamPicList&count=5&teamid="+teamId, {asynchronous:true, evalScripts:true});
	}
	function starTeamPartyList(teamId,div) {
		
		new Ajax.Updater(div, "/teamListAction.do?method=starTeamPartyList&count=5&teamid="+teamId, {asynchronous:true, evalScripts:true});
	}
	function starTeamMemberList(teamId,div) {
		new Ajax.Updater(div, "/teamListAction.do?method=starTeamMemberList&count=5&teamid="+teamId, {asynchronous:true, evalScripts:true});
	}
	function logout() {
		var url = "http://www.lvtou.com/bbs/api/passport.php?action=logout&forward=http%3A%2F%2Fwww.lvtou.com/bbs&verify=be2cab54ac203ec2263e1654a28c8f30";
		var f = document.getElementById('alienFrame');
		f.src = url;
		timer = window.setTimeout(logoutResult, 500);
	}	
	function logoutResult(){
		window.top.location = "/logout.do";
	}
	
	function UrlEncode1(str){
		var cReturn = encodeURI(str);
		return cReturn;
	}
	
	//日期比较
	function CompareDate(d1,d2)
	{
	  return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/"))));
	}
	
	function digg(diggType,targetId) {
		new Ajax.Updater("", "/digg.do?method=digg&diggType=" + diggType + "&targetId=" + targetId, {onComplete:callBack,asynchronous:true, evalScripts:true});
	}
	
	
function selectAll() {
  var objs = document.getElementsByTagName("input");
  for(var i=0; i<objs.length; i++) {
    if(objs[i].type.toLowerCase() == "checkbox" ){
    	if(objs[i].checked) objs[i].checked = false;
    	else  objs[i].checked = true;
	}	    
  }
}

function CopyURL(txt){
	var myHerf=top.location.href;
	var title=document.title;
	if(window.clipboardData){
	var tempCurLink=title + "\n" + myHerf;
	var ok=window.clipboardData.setData("Text",tempCurLink);
	if(ok){if(txt!="")alert(txt)};
	}else{alert("对不起，目前此功能只支持IE，请直接复制地址栏的地址！");}
}