function DrawImage(ImgD,FitWidth,FitHeight){     
	var image=new Image();image.src=ImgD.src;     
	if(image.width>0 && image.height>0){         
		if(image.width/image.height>= FitWidth/FitHeight){            
			if(image.width>FitWidth){ ImgD.width=FitWidth;ImgD.height=(image.height*FitWidth)/image.width;             
			}else{ ImgD.width=image.width;ImgD.height=image.height; }         
		}else{             
			if(image.height>FitHeight){ ImgD.height=FitHeight;ImgD.width=(image.width*FitHeight)/image.height;             
			}else{ ImgD.width=image.width;ImgD.height=image.height; }         
		}     
	}
}

/* change style function writed by Jones. */
function createCookie(name, value, days) {
  	if (days) {
    	var date = new Date();
    	date.setTime(date.getTime()+(days*24*60*60*1000));
    	var expires = "; expires="+date.toGMTString();
	}
  	else var expires = "";
  	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  	var ca = document.cookie.split(';');
  	var nameEQ = name + "=";
  	for(var i=0; i < ca.length; i++) {
   		var c = ca[i];
    	while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    	if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
  	return null;
}
function loadClass(obj) {
	var obj = document.getElementById(obj);
	obj.className = readCookie('style');
	var new_style = obj.className;
	if (obj.className == '' || obj.className == 'null') {
		new_style = 'xnormal';
	}
	obj.className = new_style;
	resetButtonStyle();
	switch (new_style){
		case "xsmall":
			var btn = document.getElementById("txsmall");
			btn.src='./images/xsmallhi.gif';
			break;
		case "xnormal":
			var btn = document.getElementById("txnormal");
			btn.src='./images/xnormalhi.gif';
			break;
		case "xlarge":
			var btn = document.getElementById("txlarge");
			btn.src='./images/xlargehi.gif';
			break;
	}
}

function changeClass(obj, new_style) {
	var obj = document.getElementById(obj);
	obj.className = new_style;
	resetButtonStyle();
	createCookie('style', new_style, 1);
	switch (new_style){
		case "xsmall":
			var btn = document.getElementById("txsmall");
			btn.src='./images/xsmallhi.gif';
			break;
		case "xnormal":
			var btn = document.getElementById("txnormal");
			btn.src='./images/xnormalhi.gif';
			break;
		case "xlarge":
			var btn = document.getElementById("txlarge");
			btn.src='./images/xlargehi.gif';
			break;
	}
}
function resetButtonStyle(){
	var btn = document.getElementById("txsmall");
		btn.src='./images/xsmall.gif';
	var btn = document.getElementById("txnormal");
		btn.src='./images/xnormal.gif';
	var btn = document.getElementById("txlarge");
		btn.src='./images/xlarge.gif';
}
function loadClass_e(obj) {
	var obj = document.getElementById(obj);
	obj.className = readCookie('style');
	var new_style = obj.className;
	if (obj.className == '' || obj.className == 'null') {
		new_style = 'xnormal';
	}
	obj.className = new_style;
	resetButtonStyle_e();
	switch (new_style){
		case "xsmall":
			var btn = document.getElementById("txsmall");
			btn.src='./images/xsmallhi_e.gif';
			break;
		case "xnormal":
			var btn = document.getElementById("txnormal");
			btn.src='./images/xnormalhi_e.gif';
			break;
		case "xlarge":
			var btn = document.getElementById("txlarge");
			btn.src='./images/xlargehi_e.gif';
			break;
	}
}
function changeClass_e(obj, new_style) {
	var obj = document.getElementById(obj);
	obj.className = new_style;
	resetButtonStyle_e();
	createCookie('style', new_style, 1);
	switch (new_style){
		case "xsmall":
			var btn = document.getElementById("txsmall");
			btn.src='./images/xsmallhi_e.gif';
			break;
		case "xnormal":
			var btn = document.getElementById("txnormal");
			btn.src='./images/xnormalhi_e.gif';
			break;
		case "xlarge":
			var btn = document.getElementById("txlarge");
			btn.src='./images/xlargehi_e.gif';
			break;
	}
}
function resetButtonStyle_e(){
	var btn = document.getElementById("txsmall");
		btn.src='./images/xsmall_e.gif';
	var btn = document.getElementById("txnormal");
		btn.src='./images/xnormal_e.gif';
	var btn = document.getElementById("txlarge");
		btn.src='./images/xlarge_e.gif';
}
function nextGraphNews(nextGraphNum){
	if(nextGraphNum == 16){
		nextGraphNum = 0;
		location.href="main.do?nextGraphNum="+nextGraphNum+"#graphNews";
	}else{
		location.href="main.do?nextGraphNum="+nextGraphNum+"#graphNews";
	}
}

function preGraphNews(nextGraphNum){
	if(nextGraphNum == eval(-4)){
		nextGraphNum = 16;
		location.href="main.do?nextGraphNum="+nextGraphNum+"#graphNews";
	}else{
		location.href="main.do?nextGraphNum="+nextGraphNum+"#graphNews";
	}
}

function preNews(topNewsNum){
	var newNum;
	if(topNewsNum==1){
		newNum = 5;
		location.href="main.do?nextTopNewsNum="+newNum+"#focusPic";
	}else{
		newNum = topNewsNum-1;
		location.href="main.do?nextTopNewsNum="+newNum+"#focusPic";
	}
}

function nextNews(topNewsNum){
	var newNum;
	if(topNewsNum==5){
		newNum = 1;
		location.href="main.do?nextTopNewsNum="+newNum+"#focusPic";
	}else{
		newNum = eval(topNewsNum)+1;
		location.href="main.do?nextTopNewsNum="+newNum+"#focusPic";
	}
}

function printS_previewSend()  {   
    var title = document.getElementById("newst").innerHTML;
    var forwardid = document.getElementById("forwardid").innerHTML;
    var optionvalue = document.getElementById("optionvalue").innerHTML; 
   	location.href='print.do?option='+ optionvalue;  	
 }
 
 function send_previewSend()  {   
    var title = document.getElementById("newst").innerHTML;
    var forwardid = document.getElementById("forwardid").innerHTML;
    var optionvalue = document.getElementById("optionvalue").innerHTML;
	location.href ='forward.do?option=' + optionvalue + '&newsid='+ forwardid;    	
 }
 
 function goback() {
	window.history.go(-1);
}