//全局JS定义
var hostURL = "";// 在head 定义好了http://news.jongo.dev/
var splitPara = "<split-news>";
var bakMenuText = "";
var initID = "m_999999";
var initSpan = "s_999999";
var beforID;
var beforSpan;
var globalMakert = ['Shanghai','SH A-Share','SH B-Share	','SH 180','SH Fund','SH-SZ 300','Component A','Component B','Shenzhen100R','New Index','ETF Index'];
var globalMakertLink=[
'',
'http://knows.jongo.com/res/article/11799',
'',
'http://knows.jongo.com/res/article/11784',
'',
'',
'',
'',
'',
'',
''
];
var globalMakertIT = ["SINA","NTES","SOHU","TOMO","BADU","SNDA","NCTY","JOBS","CTRP","LONG","LTON","KONG","HRAY","JRJC","FMCN","CDC","ACTS","VIMC","QCOM","UTSI","ASIA","CNTF","STP","MR","EDU","HMIN"];
var globalMaketItLink=[
'http://knows.jongo.com/res/article/18149', 
'http://knows.jongo.com/res/article/18151',
'http://knows.jongo.com/res/article/18189',
'http://knows.jongo.com/res/article/18180',
'http://knows.jongo.com/res/article/18121',
'http://knows.jongo.com/res/article/18176',
'http://knows.jongo.com/res/article/18141',
'http://knows.jongo.com/res/article/18156',
'http://knows.jongo.com/res/article/18167',
'http://knows.jongo.com/res/article/18142',
'http://knows.jongo.com/res/article/18178',
'http://knows.jongo.com/res/article/18173',
'http://knows.jongo.com/res/article/18137',
'http://knows.jongo.com/res/article/18155',
'http://knows.jongo.com/res/article/18122',
'http://knows.jongo.com/res/article/18128',
'',
'',
'http://knows.jongo.com/res/article/18177',
'http://knows.jongo.com/res/article/18146',
'http://knows.jongo.com/res/article/18139',
'http://knows.jongo.com/res/article/18136',
'',
'',
'http://knows.jongo.com/res/article/18195',
''
]    
//首页需要得变量
var home_rec_topTags;
var home_cate_tags;
var isLoad = false;
var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var base64DecodeChars = new Array(
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
    -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
/**
*getRecTopNews(1,this) 获取推荐新闻
*getRecTopNews(0,this) 获取历史热门新闻
**/
function init()
{
	try
	{
		thisMovie("headline_news").initss();
		bakMenuText = $("menu-down").innerHTML;
		beforID = $(initID);
		beforSpan = $(initSpan);
		
//		var scrlSpeed=1;
		// decreasing speed for mozilla
//		scrlSpeed=(document.all)? scrlSpeed : Math.max(1, scrlSpeed-1);
//		initScroll("scrlContainer", "marquee");
	}catch(e){}
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	}
	else {
		return document[movieName]
	}
}
function base64decode(str) {
    var c1, c2, c3, c4;
    var i, len, out;

    len = str.length;
    i = 0;
    out = "";
    while(i < len) {
 /* c1 */
 do {
     c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
 } while(i < len && c1 == -1);
 if(c1 == -1)
     break;

 /* c2 */
 do {
     c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
 } while(i < len && c2 == -1);
 if(c2 == -1)
     break;

 out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));

 /* c3 */
 do {
     c3 = str.charCodeAt(i++) & 0xff;
     if(c3 == 61)
  return out;
     c3 = base64DecodeChars[c3];
 } while(i < len && c3 == -1);
 if(c3 == -1)
     break;

 out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));

 /* c4 */
 do {
     c4 = str.charCodeAt(i++) & 0xff;
     if(c4 == 61)
  return out;
     c4 = base64DecodeChars[c4];
 } while(i < len && c4 == -1);
 if(c4 == -1)
     break;
 out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
    }
    return out;
}
/*
*新闻图片切换效果JS
*/
function initPicNewsView(requestImage,requestTitle,requestDes)
{
	new Ajax.Request(hostURL+"/index.php?channel=home&action=getNewsPicView",
	{
		onSuccess:function(request)
		{
			var list = split(splitPara);
			$(requestImage).innerHTML = list[0];
			$(requestTitle).innerHTML = list[1];
			$(requestDes).innerHTML = list[2];
		}
	});
}

/**
*获取新闻
*tags 标签
*/
function getNewByTags(tags,displayID)
{
	try
	{
		$(home_rec_topTags).className = "";
		$(tags).className = "";
		home_rec_topTags = tags;
		new Ajax.Request(hostURL+"/index.php?channel=home&action="+tags,
		{
			onSuccess:function(request)
			{
				$(displayID).innerHTML = request.responseText;
			}
		});
	}catch(e){}
}
/**
*分类新闻显示
*tags 什么标签
*cateID 分类ID
*displayID = 显示ID
*/
function listNewsByCateID(tags,cateID,displayID)
{
	try
	{
		$(home_cate_tags).className = "";
		$(tags).className = "";
		home_cate_tags = tags;
		new Ajax.Request(hostURL+"/index.php?channel=home&action=getNewsByCateID&cateID="+cateID,
		{
			onSuccess:function(request)
			{
				$(displayID).innerHTML = request.responseText;
			}
		});
	}catch(e){}
}

/*****/
function getTopPhotos()
{

}

function runMar(id)
{
	if (id==1)
	{
		$("homeMarquee").stop();
	}else
	{
		$("homeMarquee").start();
	}
}


function showMenuText(obj,span,input,k)
{
	if (isLoad)
	{
		try
		{
			$(initID).className="";
			$(initSpan).className="";
			//改变当前菜单背景颜色
			try
			{
				beforID.className="";
				beforSpan.className="";

			}catch(e){}
			obj.className="on";
			$(span).className="on";

			beforID = obj;
			beforSpan = $(span);
			if (k==-1)
			{
				$("menu-down").innerHTML = $('i_999999').value;
			}else
			{
				$("menu-down").innerHTML = $(input).value;
			}
		}catch(e){}
	}
}
var callID=1;
var callPara=1;
function reMenu()
{
	callPara = 1;
	clearInterval(callID);
	callID = setInterval(huifu,2000);
}
function huifu()
{
	try
	{
		for (var i=0;i<50;i++)
		{
			$('s_'+i).className="";
			$('m_'+i).className="";
		}
	}catch(e){}
	if (callPara==1)
	{
		try
		{

			var ss = initID.slice(1,initID.length);

			$("menu-down").innerHTML = $('i'+ss).value;
			$(beforID).className="";
			$(beforSpan).className="";
			$(initID).className="on";
			$(initSpan).className="on";
			beforID = $(initID);
			beforSpan = $(initSpan);
		}catch(e){}
	}
	clearInterval(callID);

}
function clearID()
{
	callPara=0;
	try
	{
		clearInterval(callID);
	}catch(e){}
}
function displayHotNewsTitle(hotNewsTitle,hotNewsTimer,hotNewsDes,hotLink,str)
{
	var t = utf8to16(base64decode(hotNewsTitle));
	var s = utf8to16(base64decode(hotNewsDes));
	//utf8to16(base64decode(str));
	$("hotNewsTitle").innerHTML = "<a href='"+hotLink+"' onmouseout='reMenu()' class='fs18px'>"+t+"</a>"+str;
	$("hotNewsTimer").innerHTML = hotNewsTimer;
	$("hotNewsDes").innerHTML = s;
}

//utf8
// modify hu

function utf16to8(str) {
    var out, i, len, c;

    out = "";
    len = str.length;
    for(i = 0; i < len; i++) {
        c = str.charCodeAt(i);
        if ((c >= 0x0001) && (c <= 0x007F)) {
            out += str.charAt(i);
        } else if (c > 0x07FF) {
            out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
            out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));
            out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
        } else {
            out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));
            out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
        }
    }
    return out;
}

function utf8to16(str) {
    var out, i, len, c;
    var char2, char3;

    out = "";
    len = str.length;
    i = 0;
    while(i < len) {
        c = str.charCodeAt(i++);
        switch(c >> 4)
        { 
          case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
            // 0xxxxxxx
            out += str.charAt(i-1);
            break;
          case 12: case 13:
            // 110x xxxx   10xx xxxx
            char2 = str.charCodeAt(i++);
            out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
            break;
          case 14:
            // 1110 xxxx  10xx xxxx  10xx xxxx
            char2 = str.charCodeAt(i++);
            char3 = str.charCodeAt(i++);
            out += String.fromCharCode(((c & 0x0F) << 12) |
                                           ((char2 & 0x3F) << 6) |
                                           ((char3 & 0x3F) << 0));
            break;
        }
    }
    return out;
}


//<div>dsadasdas</div>
//
function getCategoryContext(obj,id,liid,cid,showNews,isSuper)
{
	$("cate_link_"+id).href = "/category/"+cid+".html";
	GetNewsByCateID(cid,showNews,isSuper,id);
	for (var i=0;i<10;i++)
	{

		try
		{
			$("ccc_"+id+"_"+i).className = "";
			$("li_"+id+"_"+i).className = "";
		}catch(e){}
	}
	obj.className = "on";
	$("li_"+id+"_"+liid).className = "on";
	//$("ccc_"+id+"_"+liid).style.fontWeight = "bold ";
}

function getNewCategoryContext(obj,id,liid,cid,showNews,isSuper,num)
{
	$("cate_link_"+id).href = "/category/"+cid+".html";
	NewGetNewsByCateID(cid,showNews,isSuper,id,num);
	for (var i=0;i<10;i++)
	{

		try
		{
			$("ccc_"+id+"_"+i).className = "";
			$("li_"+id+"_"+i).className = "";
		}catch(e){}
	}
	obj.className = "on";
	$("li_"+id+"_"+liid).className = "on";
	//$("ccc_"+id+"_"+liid).style.fontWeight = "bold ";
}

function NewGetNewsByCateID(cid,showNews,isSuper,id,num)
{

	try{
		if (isSuper==1)
		{
			cid = $("cate_"+id).value;
		}
		new Ajax.Request(hostURL+"/index.php?channel=home&action=listNewsByCateID&cateid="+cid+"&isSuper="+isSuper+"&num="+num,
		{
			onSuccess:function(request)
			{
				$(showNews).innerHTML = request.responseText;
			}
		});
	}catch(e){}
}

function GetNewsByCateID(cid,showNews,isSuper,id)
{

	try{
		if (isSuper==1)
		{
			cid = $("cate_"+id).value;
		}
		new Ajax.Request(hostURL+"/index.php?channel=home&action=listNewsByCateID&cateid="+cid+"&isSuper="+isSuper,
		{
			onSuccess:function(request)
			{

				$(showNews).innerHTML = request.responseText;
			}
		});
	}catch(e){}
}


function getRecTopNews(mode,obj)
{
	$('news_rec').className = "";
	$('news_top').className = "";
	obj.className = "on";
	try{
		new Ajax.Request(hostURL+"/index.php?channel=home&action=getRecTopNews&mode="+mode,
		{
			onSuccess:function(request)
			{

				$("new_rec_context").innerHTML = request.responseText;
			}
		});
	}catch(e){}
}

function getRecNewsByCateID(cateid,context)
{
	try{
		new Ajax.Request(hostURL+"/index.php?channel=home&action=getRecNewsByCateID&cateid="+$(cateid).value,
		{
			onSuccess:function(request)
			{

				$(context).innerHTML = request.responseText;
			}
		});
	}catch(e){}
}


//顶级分类得AJAX调用

function getSuperCateNews(context,m,cid,obj,page)
{
	if(obj!='undefined' && obj!='')
	{

		//取消所有得高亮
		for (var i=0;i<2;i++)
		{
			$('change_id_'+i).className='';
		}
		obj.className='on';
	}

	$(context).innerHTML = "loading...";
	new Ajax.Request(hostURL+"/index.php?channel=category&action=getCateLasted&m="+m+"&cid="+cid+"&page="+page,
	{
		onSuccess:function(request)
		{

			$(context).innerHTML = request.responseText;
		}
	});
}
// add by kakapo
function getSuperCatePhotoNews(context,m,cname,obj,page)
{
	if(obj!='undefined' && obj!='')
	{

		//取消所有得高亮
		for (var i=0;i<2;i++)
		{
			$('change_id_'+i).className='';
		}
		obj.className='on';
	}

	$(context).innerHTML = "loading...";
	//alert(hostURL+"/index.php?channel=photonews&action=getCateLasted&m="+m+"&cname="+cname+"&page="+page);
	new Ajax.Request(hostURL+"/index.php?channel=photonews&action=getCateLasted&m="+m+"&cname="+cname+"&page="+page,
	{
		onSuccess:function(request)
		{
           // echo "<textarea>".request.responseText."</textarea>";
			$(context).innerHTML = request.responseText;
		}
	});
}

function viewByDate(d,m,y,cid)
{
	hostURL="/";
	Sdate = $(y).value.toString()+$(m).value.toString()+f($(d).value);
	location = hostURL+cid+"/"+Sdate+".html";
}
function f(n)
{
	if(Number(n)<10)
	{
		return "0"+n;
	}else
	{
		return n;
	}
}
function getDateNewsByCateID(date,cid,context,len,obj)
{
	try
	{
		//取消所有得高亮
		for (var i=0;i<len+1;i++)
		{
			$('change_id_'+i).className='';
		}
	}catch(e){}
	obj.className='on';
	$(context).innerHTML = "loading...";
	new Ajax.Request(hostURL+"/index.php?channel=category&action=getCategoryNewsByDate&date="+date+"&cid="+cid,
	{
		onSuccess:function(request)
		{

			$(context).innerHTML = request.responseText;
		}
	});
}
function check_space(str){
	var re = /^\s+$/;
	if(re.exec(str)) {
		return false;
	}else
	{
		return true;
	}
}
String.prototype.Trim=function(){return this.replace(/(^\s*)|(\s*$)/g,"");}
function gotoPage(cid,page,is_subject)
{
	if (page.Trim()=="")
	{
		alert('please input a number');
		return;
	}
	if (isNaN(page))
	{
		alert('please input a number');
		return;
	}else
	{
		location = hostURL+"subject/more/"+cid+"/"+is_subject+"/"+page+".html";
	}
}
//获取评论列表
function getComment(aid,context)
{
	new Ajax.Request(hostURL+"/index.php?channel=comment&action=listComment&aid="+aid,
	{
		onSuccess:function(request)
		{

			$(context).innerHTML = request.responseText;
		}
	});
}


//获取评论列表
function addReport(aid)
{
	var aa = encodeURIComponent(location);
	new Ajax.Request(hostURL+"/?channel=read&action=alert&aid="+aid+"&url="+aa,
	{
		onSuccess:function(request)
		{

			alert(request.responseText);
		}
	});
}




function gotoPageForComment(aid,page)
{
	if (page.Trim()=="")
	{
		alert('please input a number');
		return;
	}
	if (isNaN(page))
	{
		alert('please input a number');
		return;
	}else
	{
		location = hostURL+"comment/"+aid+"/"+page+".html";
	}
}

function gotoURL(url)
{
	try
	{
		parent.window.document.location = url;
	}catch(e){
		document.location = url;
	}
}
function gotoURL1(url)
{
	try
	{
		window.parent.frames["mainFrame"].location=hostURL+"/"+url;
	}catch(e){}
}

function getRelatedNews(id,aid,category_id)
{
	$('content_list').innerHTML ="loading...";
	var url = document.URL;
	var item,anchor;
	item = url.substr(url.indexOf("?"));//.split('&');
	item = item.substr(1);
	item = item.split('&');
	
	for(var i=0;i<item.length;i++){
		v = item[i].split("=");
		if(v[0]=='anchor'){
			anchor = v[1];
		}
	}
	
	if (id==1)
	{
		$('s_m_2').className="";
		$('s_m_3').className="";
		$('s_m_1').className="on";
		//相关新闻
		new Ajax.Request(hostURL+"/?channel=read&action=getRelatedNews&id="+aid,
		{
			onSuccess:function(request)
			{

				$('content_list').innerHTML = request.responseText;
				document.location = "#"+anchor;
			}
		});
	}else if (id==2)
	{
		$('s_m_1').className="";
		$('s_m_3').className="";
		$('s_m_2').className="on";
		//推荐新闻
		//channel=home&action=getNewsForView&mode=0&cid='+category_id
		new Ajax.Request(hostURL+"/?channel=home&action=getNewsForView&mode=0&cid="+category_id,
		{
			onSuccess:function(request)
			{

				$('content_list').innerHTML = request.responseText;
			}
		});
	}else if (id==3)
	{
		$('s_m_1').className="";
		$('s_m_2').className="";
		$('s_m_3').className="on";
		//历史新闻
		new Ajax.Request(hostURL+"/?channel=home&action=getNewsForView&mode=1&cid="+category_id,
		{
			onSuccess:function(request)
			{

				$('content_list').innerHTML = request.responseText;
			}
		});
	}
}

function parseUrl(){

	var item,v;
	var url = document.URL;
	var loginURL = $('LoginScript').src;//('loginscript');

	item = url.substr(url.indexOf("?"));//.split('&');
	item = item.substr(1);
	item = item.split('&');

	for(var i=0;i<item.length;i++){
		v = item[i].split("=");
		if(v[0]=='__jat'){
			loginURL = loginURL+"&"+item[i];
		}
	}
	//alert(loginURL);
}


function ye()
{
	var dd=0;
	dd=getCookie("closeList");
	
	if(dd!=1){
		$('top_pop').style.display='block';
	}

}
function ye2()
{
	setCookie("closeList",1);
	$('top_pop').style.display='none';
	//new Effect.SlideUp('toppop',{duration:1.0});

}


function setCookie(Key,value){
	var today = new Date();
	var expireDay = new Date();
	var msPerMonth = 24*60*60*1000*31;
	expireDay.setTime( today.getTime() + msPerMonth );
	document.cookie = Key + "=" + value + ";expires=" + expireDay.toGMTString()+";path=/";

}

function getCookie(Key){
	var search = Key + "=";
	begin = document.cookie.indexOf(search);
	
	if (begin != -1) {
	  begin += search.length;
	  end = document.cookie.indexOf(";",begin);
	  if (end == -1) end = document.cookie.length;
	 return document.cookie.substring(begin,end);
	
	}
} 
