// Function Defintions:
//    getFile(fileName) - returns source text of a file (IE and FireFox)
// 	goPage(form) - uses a Select item named 'select1' and opens a new window with the
//		link passed in the value of the option selected
//	HilightCell(CellRef, color1, color2)
//	PlaySound(fileURL) - opens assoc. application to play a sound
//	scrollStatusInit(delay, direction) - uses a variable 'msgStatus' to scroll a message
//		in the status bar
//    parseRSS(RSS Link) - returns HTML string from an RSS feed (IE and FireFox except x-domain)
function getFile(fileName){
    oxmlhttp = null;
    try{
        oxmlhttp = new XMLHttpRequest();
        oxmlhttp.overrideMimeType("text/xml");
    }
    catch(e){
        try{
            oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e){
            return null;
        }
    }
    if(!oxmlhttp) return null;
    try{
       oxmlhttp.open("GET",fileName,false);
       oxmlhttp.send(null);
    }
    catch(e){
       return null;
    }
    return oxmlhttp.responseText;
}

function goPage(form){
    window.open(form.select1.options[form.select1.selectedIndex].value, form.select1.options[form.select1.selectedIndex].label);
    form.select1.selectedIndex=99;
    return false;
}

function HilightCell(CellRef, c1, c2){
	var ColorArray = new Array ('white', 'black', 'blue', 'navy', 'teal', 'red', 'yellow', 'green', 'lime', 'purple', 'maroon', 'silver', 'gray');
	CellRef.style.backgroundColor = ColorArray[c1];
	CellRef.style.color=ColorArray[c2];
}

function PlaySound(sound_id){
	MusicWin=window.open("sounds/"+sound_id,"MusicWindow","scrollbars resizable width=260 height=80");
	MusicWin.focus();
}

function scrollStatusInit(sDelay,sDir){
	var spc130='                                                                                                                                 '
	msgStatus=spc130+msgStatus;
	window.status=msgStatus;
	if (sDir!='right'){
		setInterval('scrollStatusL()',sDelay);}
	else{
		setInterval('scrollStatusR()',sDelay);}
}

function scrollStatusL(){
	var tempStr='';
	tempStr=msgStatus.substring(0,1);
	msgStatus=msgStatus.slice(1)+tempStr;
	window.status=msgStatus;
}

function scrollStatusR(){
	var tempStr='';
	tempStr=msgStatus.substring(msgStatus.length-1,msgStatus.length);
	msgStatus=tempStr+msgStatus.slice(0,msgStatus.length-1);
	window.status=msgStatus;
}

function ViewThumbnail(image_id,window_width,window_height){
	if (window_height < 200) window_height=260; else window_height=window_height+50;
	if (window_width < 300) window_width=330; else window_width=window_width+50;
	ViewWin=window.open(image_id,"ThumbView"," status resizable width="+window_width+" height="+window_height);
	ViewWin.focus();
}

function parseRSS(rsslink, ChannelDesc) {
	var newxml = document.createElement("XML");
	if (navigator.appName == "Netscape") newxml = document.implementation.createDocument("", "", null);
	newxml.async = false;
	try {
		var LinkCheck=newxml.load(rsslink);
	}
	catch (e){
   	return '<p style="color:red; font-weight:bold">' +  e + ":</p>If this page uses cross domain feeds you may need to modify your security settings.<br />";
	}
	var strHTML="";
	var siteTitle="";
   if (LinkCheck){
		if(newxml.getElementsByTagName("channel").item(0).getElementsByTagName("title").item(0) != null)
			var siteTitle=newxml.getElementsByTagName("channel").item(0).getElementsByTagName("title").item(0).firstChild.nodeValue;
		if (newxml.getElementsByTagName("channel").item(0).getElementsByTagName("copyright").item(0) != null)
			siteTitle += '<br /><font size=-4>'+newxml.getElementsByTagName('channel').item(0).getElementsByTagName("copyright").item(0).firstChild.nodeValue+'</font><br>';
		if (newxml.getElementsByTagName('channel').item(0).getElementsByTagName("pubDate").item(0) != null)
			siteTitle += '<br /><font size=-4>'+newxml.getElementsByTagName('channel').item(0).getElementsByTagName("pubDate").item(0).firstChild.nodeValue+'</font><br>';
		var siteImage=' ';
		if (newxml.getElementsByTagName('image').length > 0){
			var siteImage='<img src="'+newxml.getElementsByTagName('image').item(0).getElementsByTagName('url').item(0).firstChild.nodeValue;
			siteImage += '" width='+newxml.getElementsByTagName('image').item(0).getElementsByTagName('width').item(0).firstChild.nodeValue;
			siteImage += ' height='+newxml.getElementsByTagName('image').item(0).getElementsByTagName('height').item(0).firstChild.nodeValue+'>';
		}

		strHTML = '<table border=0><th style="font-size: 14;" bgcolor="#ADD8E6">'+siteTitle+siteImage+'</th>';

		if (newxml.getElementsByTagName('channel').item(0).getElementsByTagName("description").item(0) != null && ChannelDesc ){
			strHTML += '<tr bgcolor="#ADD8E6"><td style="font-size: 10;">';
			strHTML += newxml.getElementsByTagName('channel').item(0).getElementsByTagName("description").item(0).firstChild.nodeValue;
			strHTML += '</td></tr>';
		}

		if (newxml.getElementsByTagName('item')){
			var newsitems = newxml.getElementsByTagName('item');
			for(i = 0; i < newsitems.length; i++) {
				strHTML +='<tr bgcolor="#ADFFE6"><td style="font-size: 14;">'
				if (newsitems.item(i).getElementsByTagName("link").item(0) != null)
					 strHTML += '<a href="'+newsitems.item(i).getElementsByTagName("link").item(0).firstChild.nodeValue +'"> ';
				if (newsitems.item(i).getElementsByTagName("title").item(0) != null)
					strHTML += '<b>'+newsitems.item(i).getElementsByTagName("title").item(0).firstChild.nodeValue + '</b>';
				strHTML += "</a></td></tr>";
 				if (newsitems.item(i).getElementsByTagName("description").item(0) != null)
 					strHTML += '<tr><td style="font-size: 14;color:white">'+newsitems.item(i).getElementsByTagName("description").item(0).firstChild.nodeValue+'</td></tr>';
			}

			strHTML += "</table>";
		}
	}else strHTML='<table border=0><th style="font-size: 14;" bgcolor="#ADD8E6">Invalid Link:<br>'+rsslink+'</th></table>';
	return strHTML;
}