/********************************************************
*RSS Reader Version 1.0 
*Date: 2004/06/21
**********************************************************/

var xmldoc;
/**
*load rssfile 
*@param URL : RSS URL 
*/
function Load(URL) {
        // Netscape 
        if (document.implementation && document.implementation.createDocument) {
                xmldoc = document.implementation.createDocument("", "", null);
                xmldoc.onload = Create;
        }else if (window.ActiveXObject) {         //IE
                xmldoc = new ActiveXObject("Microsoft.XMLDOM");
                xmldoc.onreadystatechange = CheckState;
        }
        xmldoc.load(URL);        
}

/*
*check xmldoc state 
*only MSDOM
*/
function CheckState() {
        var state = xmldoc.readyState;
        if (state == 4) {
        	      Create();
                displayWeather();                               
        }
} 

/*
*parsing rss file
*/
function  Create() {
        var channel = xmldoc.getElementsByTagName("channel");
        // get channel title
        var urlTitle = channel[0].childNodes[0].firstChild.nodeValue;
        // get channel URL
        var urlLink = channel[0].childNodes[1].firstChild.nodeValue;
        var html = urlTitle +" "+ urlLink + "<hr size=1 noshade>"
        var x = xmldoc.getElementsByTagName('item');
        for (i=0;i<x.length;i++)  {
                for (j=0;j<x[i].childNodes.length;j++) {
                	      if (x[0].childNodes[j].nodeType != 1) continue;                        
                        var nn = x[i].childNodes[j].nodeName;
                        var nv ;
                        if (nn == "category")  {
                                nv = x[i].childNodes[j].firstChild.nodeValue;
                                var category  =  nv;
                        } else if (nn == "title"){
                                nv = x[i].childNodes[j].firstChild.nodeValue;
                                var title = nv;
                        } else if (nn == "link"){
                                nv = x[i].childNodes[j].firstChild.nodeValue;
                                var link = nv;
                        } else if (nn == "description"){
                        	      var y = x[i].childNodes[j].childNodes[0].childNodes;
                        	      for(k=0;k<y.length;k = k+2) {
                        	      	addWeatherNode(y[k].firstChild.nodeValue,y[k+1].firstChild.nodeValue);
                        	      }
                        	      setWeather(category,title,link,WeatherList);         
                        	      break;
                        } else {
                                continue;
                        }
                }
                break;
                       
        }
        //return Weather;
}

var WeatherCategory;
var WeatherTitle;
var WeatherLink;
var WeatherList = new Array();

function setWeather(category,title,link,weatherList) {
	this.WeatherCategory = category;
	this.WeatherTitle = title;
	this.WeatherLink = link;
	this.WeatherList = weatherList;
}

function WeatherNode(time, fcast) {
	this.time = time;
	this.fcast = fcast;
}

function addWeatherNode(time, fcast) {
	WeatherList[WeatherList.length] = new WeatherNode(time, fcast);
}

function displayWeather() {
	if(WeatherList.length > 0) {
		var obj = document.getElementById("divWeather");
		var html = "<table border='0px' width='185px' cellpadding='0px' cellspacing='1px' style='cursor:hand' bgcolor='#C8C8C8' onClick='popup(\"" + WeatherLink + "\",\"winWeather\",520,500,10,10,\"yes\");'>";
	  html = html + "<tr>";
	  for(i=0; i<WeatherList.length; i++) {
	  	html = html + "<td height='18px' align='center' bgcolor='#E5EEF8' style='pading-top:5px;font-size:8pt'>" + WeatherList[i].time + "</td>";
	  }
	  html = html + "</tr><tr>";
	  for(i=0; i<WeatherList.length; i++) {
	  	html = html + "<td height='31px' align='center' bgcolor='#FFFFFF' title='" + getWeatherDisp(WeatherList[i].fcast)+"'>" + getWeatherFlash(WeatherList[i].fcast) + "</td>";
	  }
	  obj.innerHTML = html;
	}	
}

function getWeatherFlash(nm) {
	nms = nm.split(",");
	nm = nms[0];
	nm = nm.replace(/\s/g, "");
	var flash = "";
	if(false) {
  } else if(nm == "¸¼À½") {
		flash = "01";
	} else if(nm == "±¸¸§Á¶±Ý") {
		flash = "02";
	} else if(nm == "±¸¸§¸¹À½") {
		flash = "03";
	} else if(nm == "Èå¸²") {
		flash = "04";
	} else if(nm == "Èå¸°ÈÄ°·") {
		flash = "05";
	} else if(nm == "Â÷Â÷Èå¸²") {
		flash = "06";
	} else if(nm == "¼Ò³ª±â") {
		flash = "07";
	} else if(nm == "ºñ¿ÂÈÄÈå¸²") {
		flash = "08";
	} else if(nm == "Â÷Â÷Èå·ÁÁöºñ") {
		flash = "09";
	} else if(nm == "Èå·ÁÁöºñ¿ÂÈÄ°·") {
		flash = "10";
	} else if(nm == "´«") {
		flash = "11";
	} else if(nm == "ºñ¶Ç´Â´«") {
		flash = "12";
	} else if(nm == "´«¶Ç´Âºñ" || nm == "±¸¸§¸¹°í´«") {
		flash = "13";
	} else if(nm == "") {
		flash = "14";
	} else if(nm == "±¸¸§¸¹°íÇÑ¶§´«"  ||  nm == "±¸¸§Á¶±ÝÇÑ¶§´«") {
		flash = "15";
	} else if(nm == "") {
		flash = "16";
	} else if(nm == "ÃµµÕ¹ø°³") {
		flash = "17";
	} else if(nm == "¾È°³") {
		flash = "18";
	} else if(nm == "È²»ç") {
		flash = "19";
	} else if(nm.indexOf("ÃµµÕ") > -1) {
		flash = "17";
	} else if(nm.indexOf("´«") > -1) {
		flash = "20";
	} else if(nm.indexOf("ºñ") > -1) {
		flash = "21";
	}	
	var src = "http://www.digital.go.kr/flash/sky_" + flash + ".swf";
	var height = "25";
	var width = "25";
	var html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
	html = html + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ width + '" height="' + height + '">';
	html = html + '<param name="movie" value="' + src + '">';
	html = html + '<param name="quality" value="high">';
	html = html + '<embed src="' + src + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>';
	html = html + '</object>';
	return html;
}

function getWeatherDisp(nm) {
	var html = "";
	var nms = nm.split(",");
	for(var i=0; i<nms.length; i++) {
		html = html + nms[i];
	}
	return html;
}
