﻿/**
 * 获取用户登录Cookie
**/
var passport = {
	getCookie:function (name) {
		if (document.cookie && document.cookie !== '') {
			var cookieArray = document.cookie.split("; "); //得到分割的cookie名值对
			for(var i=0;i<cookieArray.length;i++){
				var arr = cookieArray[i].split("="); //将名和值分开
				//如果是指定的cookie，则返回它的值
				if(encodeURIComponent(name) == arr[0]){
					return decodeURIComponent(arr[1]);
				}
			}
		}
		return null;
	},
	checkCookie:function () {
		if(this.getCookie('TICKET')!='undefined' && this.getCookie('TICKET')!='' && this.getCookie('TICKET')!=null)
		{
			return true;
		}else{
			return false;
		}
	}
};

/**
 * 常用Tab切换
**/
function onTab(tabid, tabname, tablength, tabclass)
{
	if(tabclass == '' || tabclass == null || tabclass == undefined)
	{
		tabclass = 'current';
	}
	var subname = tabname + "_sub";
	for(i=0;i<tablength;i++)
	{
		if(tabid == i)
		{
			document.getElementById(""+tabname+"_"+i+"").className = tabclass;
			document.getElementById(""+subname+"_"+i+"").style.display = 'block';
		}else{
			document.getElementById(""+tabname+"_"+i+"").className = '';
			document.getElementById(""+subname+"_"+i+"").style.display = 'none';
		}
	}
}

function getCommentUrl(URL)
{
	URL = trim(URL);
	//alert(URL);
	if(URL == "" || URL == undefined)
	{
		document.write("");
		return false;
	}
	var urlArray = new Array(), htmlArray = new Array();
		urlArray = URL.split('/');
		htmlArray = urlArray[urlArray.length - 1].split('.');
	var aid = htmlArray[0];
		if(isNum(aid))
		{

			document.write("<a href='http://comment.hunantv.com/comment/?type=news&sid="+aid+"' target='_blank'>发表评论</a>");
		}else{
			document.write("<a href='"+URL+"' target='_blank'>发表评论</a>");
		}
}

function isNum(v)
{
	var re = /^[0-9]+.?[0-9]*$/;   //判断字符串是否为数字     //判断正整数 /^[1-9]+[0-9]*]*$/   
	if (!re.test(v))
	{
		return false;
	}
	return true;
}

/**
 * 去除前后空格
 */
function trim(str)
{
	return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1');
}

function getTypeUrl(tid)
{
	var typeArr = new Array();
		typeArr[2520] = {name:"懒杨杨", link:"http://news.hunantv.com/lhh/lyy/index.html"};
		typeArr[2521] = {name:"毛茸茸", link:"http://news.hunantv.com/lhh/mrr/index.html"};
		typeArr[2522] = {name:"剩西罗", link:"http://news.hunantv.com/lhh/sxl/index.html"};
		typeArr[2531] = {name:"阿拉娈", link:"http://news.hunantv.com/lhh/all/index.html"};
		if(isNum(tid))
		{
			document.write("所属类别：<a href=\""+typeArr[tid].link+"\" title=\""+typeArr[tid].name+"\" target=\"_blank\">"+typeArr[tid].name+"</a>作品");
		}
}

function getFav()
{
	var url = window.location.href;
	var title = document.title;
	document.write("<a href=\"javascript:window.external.addFavorite('"+url+"','"+title+"');\" class=\"collect\">收藏本页</a>");
}