//article counter
function article_counter(id,maincat_id){
	xmlHttp=GetXmlHttpObject();
	var url="/article/article_counter.php";
	url=url+"?id="+id+"&maincat_id"+maincat_id;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);		
}
function prarticle_counter(val){
	xmlHttp=GetXmlHttpObject();
	var url="/pressrelease/prarticle_counter.php";
	url=url+"?id="+val;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);		
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return null
}

function setCookie(c_name,value,expiredays){
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate)
}

//font size new
var bh_fontsize = new Array("10","12","14");
function setFontReSize(sz){
	if(sz == 10 || sz == 12 || sz == 14){
		document.getElementById("bodytext1").className= "fontresize" + sz;
 		document.getElementById("bodytext2").className= "fontresize" + sz;
 		setCookie("IBTIMES_FONTSIZE_NEW", sz,1);
		for(var i=0;i<bh_fontsize.length;i++){
			if(sz==bh_fontsize[i]){
				document.getElementById("size"+bh_fontsize[i]).className= "font_bold";
				document.getElementById("sizebtm"+bh_fontsize[i]).className= "font_bold";}
			else {
				document.getElementById("size"+bh_fontsize[i]).className= "font_normal";
				document.getElementById("sizebtm"+bh_fontsize[i]).className= "font_normal";}
		}
 	}
}
function setFontSize(sz){
	if(sz == 10 || sz == 12 || sz == 14){
		document.getElementById("bodytext1").className = "fontresize" + sz;
 		document.getElementById("bodytext2").className = "fontresize" + sz;
 		setCookie("IBTIMES_FONTSIZE_NEW", sz, 1);
 	}
}
function loadingFontReSize(){
	var sz = parseInt(getCookie("IBTIMES_FONTSIZE_NEW"));
	if(!sz)sz=10;
	document.getElementById("bodytext1").className= "fontresize" + sz;
	document.getElementById("bodytext2").className= "fontresize" + sz ;
	for(var i=0;i<bh_fontsize.length;i++){
		if(sz==bh_fontsize[i]){
			document.getElementById("size"+bh_fontsize[i]).className= "font_bold";}
		else {
			document.getElementById("size"+bh_fontsize[i]).className= "font_normal";}
	}
}

//most popular tab
var which_part;
var argnum;
var settime;
function over_change_top(val){
	for(var i=0;i<arr2.length;i++){
		for(var j=0;j<arr.length;j++){
			for(var k=1;k<8;k++){
				if(document.getElementById(arr[j]+k))document.getElementById(arr[j]+k).style.color = "#0860A8";
			}
		}
		if(val==i&&document.getElementById(arr2[i])){
			document.getElementById(arr2[i]).style.background= "url(/images/most_bar_bg3.gif)";
			document.getElementById(arr2[i]).style.color = "#CC0000";
			document.getElementById(arr[i]).style.display = "block";
		}else if(document.getElementById(arr2[i])){
			document.getElementById(arr2[i]).style.background = "url(/images/most_bar_bg2.gif)";
			document.getElementById(arr2[i]).style.color = "#000000";
			document.getElementById(arr[i]).style.display = "none";			
		}else{
			document.getElementById(arr2[i]).style.background = "url(/images/most_bar_bg2.gif)";
			document.getElementById(arr2[i]).style.color = "#000000";
			document.getElementById(arr[i]).style.display = "none";				
		}
	}	
	which_part = arr[val];
	clearTimeout(settime);
	argnum = 1;
	if(document.getElementById(which_part+"7"))mostread_top();
}	

function mostread_top(){
	document.getElementById(which_part+argnum).style.color="#000000";
	if(argnum!=1){ 
		document.getElementById(which_part+(argnum-1)).style.color="#0860A8";
	}else{
	    document.getElementById(which_part+"7").style.color="#0860A8";
	}
	if(argnum++ == 7) argnum=1;
	settime = setTimeout("mostread_top()",2500);
}

function tab_color(val,val2){
	for(var i=1;i<=val2;i++){
		if(i==val){
			document.getElementById("tag"+val).style.backgroundColor="#3A5EC6";
			document.getElementById("tag"+val).style.color="#ffffff";
			document.getElementById("article_tag"+val).style.display = "block";
		}else{
			document.getElementById("tag"+i).style.backgroundColor="#ffffff";
			document.getElementById("tag"+i).style.color="#3A5EC6";	
			document.getElementById("article_tag"+i).style.display = "none";	
		}
	}
}
function article_tags(val,val2,keywords,article_id){
	xmlHttp=GetXmlHttpObject();
	for(var i=1;i<=val2;i++){
		if(i==val){
			document.getElementById("tag"+val).style.backgroundColor="#3A5EC6";
			document.getElementById("tag"+val).style.color="#ffffff";
		}else{
			document.getElementById("tag"+i).style.backgroundColor="#ffffff";
			document.getElementById("tag"+i).style.color="#3A5EC6";	
		}
	}
	var url='/article/article_tags.php';
	url=url+'?article_id='+article_id+'&keywords='+keywords;
	xmlHttp.onreadystatechange=changed_article_tags; 
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);			
}
function changed_article_tags() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete'){
		 var gettext=xmlHttp.responseText.split('@@');
		document.getElementById(gettext[0]).innerHTML=gettext[1];
	}
} 
function news_val(Obj,num){
	if(num	== 1){
		Obj.value	= "";
	}else if(num	== 2){
		Obj.value	= "email";
	}
}
/////// comment///
function checkform(f,val){
	if(f.nickname.value==""){ 
		alert("Please type in nickname");
		f.nickname.focus();
		return false;
	}
	if(f.comments.value==""){
		alert("Please type in comment");
		f.comments.focus();
		return false;
	}
	f.artid.value = artid;
	f.src_from.value = s_from;
	f.keywords.value = keywords;
	f.date.value = c_date;
	if(val==0)	f.re_reid.value = 0;
	else        f.re_reid.value = value;
	return true;
}

//print article
function POPprint(num,table){
	window.open("/services/pop_print.htm?id="+num+"&tb="+table,"printing","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=520,height=520 ,left = 100,top = 100");
}
function POPemail(num){
	window.open("/services/pop_email.htm?artid="+num,"email","toolbar=0,scrollbars=auto,location=0,statusbar=0,menubar=0,resizable=0,width=585,height=670 ,left = 100,top = 100");
}
function popUp(URL, width, height) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, 'infoPage', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left = 100,top = 0');");
}

//photo resize(like graph somthing)
var container_img;
function photos_realsize(Obj,val) { 
	if(!container_img){
		container_img = document.createElement("div");
		document.body.appendChild(container_img);
		container_img.className="artimg";
		container_img.style.position = "absolute";
		container_img.onclick = pimg_close;
	}else{ 
		container_img.innerHTML = '';
		container_img.style.display = "block";
	}
	container_img.style.left = (findPos(Obj)[0]-50)+"px";
	container_img.style.top  = (findPos(Obj)[1])+"px";
	container_img.innerHTML = "<img src='"+val+"' class='hand'>";
} 
function pimg_close(){
	container_img.style.display = "none";
}
 //new photo resize
 var img_orgsize;
 var img_newsize;
 function resizeImg(Obj,size) {
 img_orgsize=Obj.width;
 Obj.name = Obj.width;
 Obj.width=size;
 img_newsize=size;
 Obj.onclick = function(){
  if(!container_img){
   container_img = document.createElement("div");
   document.body.appendChild(container_img);
   container_img.className="artimg";
   container_img.style.position = "absolute";
   container_img.onclick = pimg_close;
  }else{ 
   container_img.innerHTML = '';
   container_img.style.display = "block";
  }
  container_img.style.left = (findPos(Obj)[0]+(img_newsize/2)-(Obj.name/2))+"px";
  container_img.style.top  = (findPos(Obj)[1])+"px";
  container_img.innerHTML = "<img src='"+Obj.src+"' class='hand'>"; 
 }
 }
 
//voting system
var votetotal, cook_art;
var rt_status=true;
function checkVotes(){
	var c_value=getCookie(voteCookie);
	if (c_value!=null){
		if(rt_status==true){
			var arr = c_value.split(",");
			for(var i=0;i<arr.length;i++){
				cook_art = arr[i].split(":");
				if(cook_art[0] == article_id){
					rt_status = false;
					voteThis('thankyou');
					break;
				}
			}
			if(i>4){
				rt_status = false;
				voteThis('5voted');
			}
		}
	}
	document.getElementById('vote_loading').style.display="none";
	document.getElementById('vote_button').style.display="block";
}
function votes(){
	var c_value=getCookie(voteCookie);
	if (c_value!=null){
		if(rt_status==true){
			var arr = c_value.split(",");
			for(var i=0;i<arr.length;i++){
				cook_art = arr[i].split(":");
				if(cook_art[0] == article_id){
					rt_status = false;
					voteThis('voted_article');
					break;
				}
			}
			if(i>4){
				rt_status = false;
				voteThis('5voted');
			}
			if(rt_status==true){
				c_value += ","+article_id+":"+5;
				setCookie(voteCookie,c_value,1);
				voteThis('true');
			}
		}
	}else{
	  setCookie(voteCookie,article_id+":"+5,1);
	  voteThis('true');
	}
}
function voteThis(status){
	xmlHttp=GetXmlHttpObject();
	var url='/forex/inner/vote_ajax.php';
	url=url+'?article_id='+article_id+'&status='+status;
	xmlHttp.onreadystatechange=changed_voteThis; 
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);
}
function changed_voteThis(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete'){
		 var gettext=xmlHttp.responseText.split('@@');
		document.getElementById('vote_button').innerHTML=gettext[1];
		if(gettext[0]=="True")document.getElementById('votebox').innerHTML=nowvoted+1;
	}else{
		document.getElementById('vote_button').innerHTML="Loading ...";
	}
}


