var xmlHttp;

var selectObjId = '';
var errorDiv = '';
var autoKick = false;
var pre_country, pre_place;
var link = '';
var img_string = '';
var Request_other = false;
var function_name = '';
var IntLoadingTimes = 0;
var columnist_pen_name = new Array();
var link = new Array();
var columnist_headline = new Array();
var columnist_portrait = new Array();
var columnist_content = new Array();
var sr,MyMarC;
var ch_columnist_pen_speed = 5000;
var IntTotalRecords = 5;


function raiseError(msg, div){
    //document.getElementById(div).innerHTML = '<font size=2><span class=news_line02>' +msg +'</span></font>';
}

function createXMLHttpRequest() {
    //var request = false;
		if(window.XMLHttpRequest) {
			xmlHttp = new XMLHttpRequest();
			if(xmlHttp.overrideMimeType) {
				xmlHttp.overrideMimeType('text/xml');
			}
		} else if(window.ActiveXObject) {
			var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
			for(var i=0; i<versions.length; i++) {
				try {
					xmlHttp = new ActiveXObject(versions[i]);
					if(xmlHttp) {
						return xmlHttp;
					}
				} catch(e) {
					//alert(e.message);
				}
			}
		}
		return xmlHttp;
}

function Request_columnist_pen() {
	if(createXMLHttpRequest()){
		try{
			
			xmlHttp.onreadystatechange = handleStateChange;
			var targetURL = "/columnist_pen/columnist_pen_request.php";
			
			xmlHttp.open("GET", targetURL, true);  //開啟連結
            xmlHttp.setRequestHeader("If-Modified-Since","0");
            xmlHttp.send(null);  //傳送請求
		}
		catch(e){
			raiseError(e, errorDiv);
		}
	}
}

function handleStateChange() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
			
            var rt = xmlHttp.responseText;
            rt = processText(rt);
            var s = document.getElementById(selectObjId);
            var cpt = document.getElementById("columnist_pen_table");
			
			var a_result = new Array();
			
            if(true){
            	
				var ArrResult = new Array();
				var ArrColumnistDataList = new Array();
				var ArrColumnistData = new Array();
            	var ArrPenColumnist = rt.split('\r\n');
            	
            	for(i=0; i<ArrPenColumnist.length; i++){
            		ArrColumnistDataList = ArrPenColumnist[i].split('<(=--=)>');
            		for(y=0; y<ArrColumnistDataList.length; y++){
            			ArrColumnistData = ArrColumnistDataList[y].split('-----');
            			if (ArrColumnistData.length == 2){
            				ArrResult[y] = ArrColumnistData[1];
            			}
            		}
            		
            		columnist_pen_name[i] = ArrResult[0];
    				link[i] = ArrResult[1];
    				columnist_headline[i] = ArrResult[2];
    				columnist_portrait[i] = ArrResult[3];
    				columnist_content[i] = ArrResult[4];
            	}
            	
            	if (IntLoadingTimes == 0){
	            	cpt.innerHTML = '';
	            	GetColumnist();
            	}
            	MyMarC = setInterval("GetColumnist()", ch_columnist_pen_speed);
            }else{
            }
			
			if (Request_other){
				//eval(function_name);
				//Request_other = false;
			}
        }
        else if (xmlHttp.status == 404) {
            
        }
        else{
            raiseError('發生例外狀況', errorDiv);
        }
    }
}

function GetColumnist(){
	GetTopPenColumnist(columnist_pen_name[IntLoadingTimes], columnist_headline[IntLoadingTimes], columnist_content[IntLoadingTimes], link[IntLoadingTimes], columnist_portrait[IntLoadingTimes]);
}


function GetTopPenColumnist(columnist_pen_name, columnist_headline, columnist_content, link, columnist_portrait){
	
	if (IntLoadingTimes < IntTotalRecords){
		var cpt = document.getElementById("columnist_pen_table");
		var temp = "";
		
		temp = temp + '<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">';
		temp = temp + '<tr  height="141">';
		temp = temp + '	<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
		temp = temp + '		<tr>';
		temp = temp + '			<td width="356" valign="top">';
	
		temp = temp + '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
		temp = temp + '			<tr>';
		temp = temp + '				<td colspan="2"><a href="'+link+'"><span class="f16lightblue">'+columnist_pen_name+'</span></a></td>';
		temp = temp + '			</tr>';
		temp = temp + '			<tr>';
		temp = temp + '				<td><img src="images/shim.gif" width="1" height="15"></td>';
		temp = temp + '			</tr>';
		temp = temp + '			<tr>';
		temp = temp + '				<td ><a href="'+link+'"><span class="f12"><b>'+columnist_headline+'</b><br>'+columnist_content+'</span></a></td>';
		temp = temp + '			</tr>';
		temp = temp + '		</table>';
	
		temp = temp + '	</td>';
	
		temp = temp + '	<td width="102" align="right" valign="top">';
		temp = temp + '		<table  border="0" cellspacing="0" cellpadding="1">';
		temp = temp + '			<tr>';
		temp = temp + '				<td >';
	
		if (columnist_portrait != ''){
			temp = temp + '					<a href="'+link+'" class="imghover">'+columnist_portrait+'</a>';
		}else{					
			temp = temp + '					<a href="'+link+'"><img src="images/st_property_77.jpg" width="100" height="100" border="0"/></a>';
		}
	
		temp = temp + '				</td>';
		temp = temp + '			</tr>';
		temp = temp + '		</table>';
		temp = temp + '	</td>';
		temp = temp + '	<tr><td height="5"></td></tr>';
		temp = temp + '	<tr>';
		temp = temp + '		<td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
		temp = temp + '			<tr>';
		temp = temp + '				<td width="356"><table width="100%" border="0" cellspacing="0" cellpadding="0" >';
		temp = temp + '					<tr>';
		temp = temp + '						<td  align="center" ><a href="/columnist_pen/index.php"><font size="2">更多..</font></a></td>';
		temp = temp + '					</tr>';
		temp = temp + '				</table></td>';
		temp = temp + '			</tr>';
		temp = temp + '		</table></td>';
		temp = temp + '	</tr>';
		temp = temp + '</table>';
		//return temp;
		IntLoadingTimes++;
		cpt.innerHTML = '';
		cpt.innerHTML = temp;
	}else{
		clearInterval(MyMarC);
		IntLoadingTimes = 0;
		Request_columnist_pen();
	}
}


function processText(x){
  //x = x.replace(/&#57438;/g, '匯');
  return x;
}