//
// Script to process Cumulus realtime data in XML
//    (http://sandaysoft.com)
// ****************************************************************
// Version  locherie_ajax 1.5 - Aug 2010
// ****************************************************************
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
// USA.
// ****************************************************************
// Version 1.5      Enhancements to power La Locherie Weather 
//                  www.lalocherie.com/weather/ by Helen Davies
// Version 1.4      Amended and renamed to power La Locherie Weather 
//                  www.lalocherie.com/weather/ by Helen Davies
//                  
// ****************************************************************
// (c) S.M.Blinkhorn 2009
//// Special thanks to: Kevin Reed http://www.tnetweather.com
// Special thanks to: Pinto http://www.joske-online.be
//
function initialize(xmlfile,loop) {
// ****************************************************************
// initialize - call this from <body> javascript
//      The XML file will be parsed once.
//
// ****************************************************************
    var FlashTime = 0; // seconds, 0 disables
    var FlashColour = '#00FF00'; // Green
// ----------------------------------------------------------------
    var x = navigator;
    document.write('<form>');
    document.write('<input type="hidden" id="appCodeName">');
    document.write('<input type="hidden" id="appMinorVersion">');
    document.write('<input type="hidden" id="appName">');
    document.write('<input type="hidden" id="appVersion">');
    document.write('<input type="hidden" id="cookieEnabled">');
    document.write('<input type="hidden" id="cpuClass">');
    document.write('<input type="hidden" id="onLine">');
    document.write('<input type="hidden" id="platform">');
    document.write('<input type="hidden" id="useragent">');
    document.write('<input type="hidden" id="browserLanguage">');
    document.write('<input type="hidden" id="systemLanguage">');
    document.write('<input type="hidden" id="userLanguage">');
    document.write('<input type="hidden" id="xmlfile">');
    document.write('<input type="hidden" id="loop">');
    document.write('<input type="hidden" id="timeout">');
    document.write('<input type="hidden" id="flashtime">');
    document.write('<input type="hidden" id="flashcolour">');
    document.write('<input type="hidden" id="gotstatics">');
    document.write('<input type="hidden" id="interval">');
    document.write('<input type="hidden" id="realtimeinterval">');
    document.write('<input type="hidden" id="tempunit">');
    document.write('<input type="hidden" id="pressunit">');
    document.write('<input type="hidden" id="rainunit">');
    document.write('<input type="hidden" id="windunit">');
    document.write('<input type="hidden" id="windrununit">');
    document.write('</form>');

    document.getElementById("appCodeName").value=x.appCodeName;
    document.getElementById("appMinorVersion").value=x.appMinorVersion;
    document.getElementById("appName").value=x.appName;
    document.getElementById("appVersion").value=x.appVersion;
    document.getElementById("cookieEnabled").value=x.cookieEnabled;
    document.getElementById("cpuClass").value=x.cpuClass;
    document.getElementById("onLine").value=x.onLine;
    document.getElementById("platform").value=x.platform;
    document.getElementById("useragent").value=x.userAgent;
    document.getElementById("browserLanguage").value=x.browserLanguage;
    document.getElementById("systemLanguage").value=x.systemLanguage;
    document.getElementById("userLanguage").value=x.userLanguage;
// xml data file
    if(xmlfile==undefined) xmlfile='cumulus.xml';
    document.getElementById("xmlfile").value=xmlfile;

    document.getElementById("flashtime").value=FlashTime;
    document.getElementById("flashcolour").value=FlashColour;
    document.getElementById("gotstatics").value=0;
// refresh loop interval
    if(loop==undefined) loop='62';
    document.getElementById("loop").value=loop;

    var symbian = new RegExp("symbian","i");
    if (symbian.test(x.userAgent)) {
        document.getElementById("timeout").value=Math.min(loop*10,900); // seconds, capped @ 15 mins
    } else {
        document.getElementById("timeout").value=loop; // seconds
    }

// uncomment the next line to switch off the loop for testing
// document.getElementById("timeout").value=0;

    var IE = new RegExp("MSIE","i");
    if (IE.test(x.userAgent)) {
        document.onreadystatechange=fnStartInit;
    } else {
        loadXMLDoc(document.getElementById("xmlfile").value+'?'+Math.random());
    }

}
function fnStartInit() {
    if (document.readyState=="complete") {
        loadXMLDoc(document.getElementById("xmlfile").value+'?'+Math.random());
    }
}

function loadXMLDoc(url) {
    xmlDoc=GetXmlHttpObject();
    if (xmlDoc!=null) {
        xmlDoc.onreadystatechange=state_Change;
        xmlDoc.open("GET",url,true);
        xmlDoc.send(null);
        timeout=document.getElementById("timeout").value;
        flashtime=document.getElementById("flashtime").value;
//        alert(flashtime);
        if(timeout!=0) setTimeout("loadXMLDoc(document.getElementById('xmlfile').value+'?'+Math.random())",timeout*1000);
        if(flashtime!=0) setTimeout("reset_ajax_color()",flashtime*1000);
    } else {
        alert("Your browser does not support XMLHTTP.");
        return;
    }
}

function GetXmlHttpObject() {
    var xmlHttp=null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e) {
    // Internet Explorer
    try {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
    catch (e) {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function state_Change() {
    if (xmlDoc.readyState==4) {// 4 = "loaded"
        if (xmlDoc.status==200) {// 200 = OK
//            alert("loaded OK");
            if(document.getElementById("gotstatics").value==0) {
                getNamedElement("interval");
                getNamedElement("realtimeinterval");
                getNamedElement("tempunit");
                getNamedElement("pressunit");
                getNamedElement("rainunit");
                getNamedElement("windunit");
                getNamedElement("windrununit");
                document.getElementById("gotstatics").value=1;
            }
            set_ajax_obs();
        } 
//	    else {
//          alert("Problem retrieving XML data");
//   }
    }
}

function set_ajax_obs() {
//  get a handle to the XML document
    var x=xmlDoc.responseXML.documentElement;
    if(x!=null) {  // xml doc was NOT modified while we were parsing it
//      set up constants        
        var flashtime=document.getElementById("flashtime").value;
        var flashcolour=document.getElementById("flashcolour").value;
        var pattern=new RegExp("_"); // mask used to ignore the ajax element 'unique-ifier'
//      get a list of all the XML elements
        var items=x.getElementsByTagName("item")
        var numitems=items.length;
//      get a list of all the 'ajax' elements in the document
        elements=getElementsByClass("span","ajax");
        var numelements=elements.length;
//      start loop to store xml data
        for (var i=0;i!=numitems;i++) { // step through each XML element
            var xid=items.item(i).attributes.getNamedItem("name"); // get the name of the XML element
            for (var index=0;index!=numelements;index++) { // and look for it in the 'ajax' elements list
                var ajx=elements[index];
                var aid=ajx.attributes.getNamedItem("id");
                if(xid.value==aid.value.split(pattern)[0]) { // match found save data
                    var cls=x.getElementsByTagName("class")[i].childNodes[0];
                    var val=x.getElementsByTagName("value")[i].childNodes[0];
					var img=x.getElementsByTagName("image")[i].childNodes[0];

                    if(val) { // if there is a stored value then use it
                        val=val.nodeValue;
                    } else { // insert something (nothing) to display
                        val="";
                    }

                    lastval = ajx.getAttribute("lastval");
                    if(cls.nodeValue=='static' && lastval!=null) break; // static data, won't change, get next data item
                    if(val==lastval) break; // not changed since last time - get next data item
                    ajx.setAttribute("lastval",val);

                    var unt=x.getElementsByTagName("unit")[i].childNodes[0];
                    if(unt) { // if there is a unit defined in the XML then tack it on
                        unt=unt.nodeValue;
                    } else {
                        unt="";
                    }
                    ajx.innerHTML=val + unt; // and write the xml element into the document
					
//                  change moon image when moon phase changes	
                	switch(val)
					{
					case "Full Moon":
					    document.getElementById('moonphaseimage').innerHTML='<img src="images/' + val + '.png" id="moonphaseimage" title="Current Moon Phase" width="64" height="64" hspace="10" align="right" border="0">';
					break;
					case "New Moon":
						document.getElementById('moonphaseimage').innerHTML='<img src="images/' + val + '.png" id="moonphaseimage" title="Current Moon Phase" width="64" height="64" hspace="10" align="right" border="0">';		
					break;
					case "Waxing Gibbous":
						document.getElementById('moonphaseimage').innerHTML='<img src="images/' + val + '.png" id="moonphaseimage" title="Current Moon Phase" width="64" height="64" hspace="10" align="right" border="0">';
					break;
					case "Waning Gibbous":
						document.getElementById('moonphaseimage').innerHTML='<img src="images/' + val + '.png" id="moonphaseimage" title="Current Moon Phase" width="64" height="64" hspace="10" align="right" border="0">';		
					break;
					case "Waxing Cresent":
						document.getElementById('moonphaseimage').innerHTML='<img src="images/' + val + '.png" id="moonphaseimage" title="Current Moon Phase" width="64" height="64" hspace="10" align="right" border="0">';		
					break;
					case "Waning Cresent":
						document.getElementById('moonphaseimage').innerHTML='<img src="images/' + val + '.png" id="moonphaseimage" title="Current Moon Phase" width="64" height="64" hspace="10" align="right" border="0">';		
					break;
					case "First Quarter":
						document.getElementById('moonphaseimage').innerHTML='<img src="images/' + val + '.png" id="moonphaseimage" title="Current Moon Phase" width="64" height="64" hspace="10" align="right" border="0">';		
					break;
					case "Last Quarter":
						document.getElementById('moonphaseimage').innerHTML='<img src="images/' + val + '.png" id="moonphaseimage" title="Current Moon Phase" width="64" height="64" hspace="10" align="right" border="0">';		
					break;
					}
				    
//                  change forecast graphic when forecast changes
                   					
					switch(val)
					{
					case "1_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "1_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "2_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "2_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "3_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "3_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "4_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "4_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "5_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "5_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "6_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "6_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "7_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "7_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "8_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "8_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "9_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "9_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "10_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "10_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "11_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "11_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "12_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "12_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "13_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "13_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "14_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "14_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "15_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "15_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "16_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "16_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "17_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "17_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "18_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "18_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "19_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "19_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "20_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "20_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "21_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "21_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "22_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "22_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "23_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "23_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "24_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "24_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "25_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "25_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "26_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "26_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "-26_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "-26_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "-1_0":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					case "-1_1":
					    document.getElementById('forecasticon').innerHTML='<img src="myimages/weather_' + val + '.png" id="forecasticon" title="Station Forecast" width="36" height="36" style="vertical-align:bottom">';
					break;
					}
                    if(flashtime!=0) ajx.style.color=flashcolour;
                }
	       }
        }
    }
}

function getElementsByClass(tag, targetclass) {
    var arr = new Array();
    var elem = document.getElementsByTagName(tag);
    var numelem = elem.length;
    for(i = 0,iarr = 0; i != numelem; i++) {
        x = elem[i].getAttributeNode('class');
        if(x!=null) {
            att = x.nodeValue;
            if(att == targetclass) {
                arr[iarr] = elem[i];
                iarr++;
            }
        }
    }
    return arr;
}

function reset_ajax_color( ) {
// reset all the <span class="ajax"...> styles to have no colour override
    elements = getElementsByClass("span","ajax");
    numelements = elements.length;

    for (var index=0;index!=numelements;index++) {
        element = elements[index];
        element.style.color='';
    }
}

function getNamedElement(element) {
//  get a list of all the XML elements
    var x=xmlDoc.responseXML.documentElement;
    var items=x.getElementsByTagName("item")
    var numitems=items.length;
//  loop to get names of xml elements
    for (var i=0;i!=numitems;i++) { // step through each XML element
        var xid=items.item(i).attributes.getNamedItem("name"); // get the name of the XML element
        if(xid.value==element) { // match found store the element
            var val=x.getElementsByTagName("value")[i].childNodes[0];

            if(val) { // if there is a stored value then use it
                val=val.nodeValue;
            } else { // insert something (nothing) to display
                val="";
            }
            document.getElementById(element).value=val;
            break; // stop looking already found
        }
    }
}

// script to add and change tags
// adapted from joe_cumulus.js by Helen Davies Mar 2010
// for La locherie Weather www.lalocherie.com/weather/
// v1.2 open
// originally developed by beteljuice - September 2009

// -- Feels like decision and comfort text
 
function feels(windch, heatind, unit) { 
	this_chill = windch *1;
	this_heat = heatind *1;


	if( (unit == '&deg;C' && this_chill <= 15) || (unit == '&deg;F' && this_chill <= 59) ) {
		feel_temp = this_chill;
	} else {
		feel_temp = this_heat;
	}

	document.write(feel_temp + " " + unit);

} // END function feels()

//------------ Create Comfort Index Text - various reasoning ! -------------
function comfort(windch, heatind, temp, unit, rh, iso) {

	this_chill = windch *1;
	this_heat = heatind *1;
	this_temp = temp *1;
	this_rh = rh *1;

	CI_text = "";				// default if reasoning fails !

	if ((this_temp >= 16) && (this_temp < 22)) {
		CI_text = ('&nbsp;Feels&nbsp;<span style="color: #CC3300;">warm,</span>'); 
	}
	if ((this_temp >= 22) && (this_temp < 26)) {	
		CI_text = ('&nbsp;Feels&nbsp;<span style="color: #F87217;">very warm,</span>');
	}
	if ((this_temp >= 26) && (this_temp < 31)) {	
		CI_text = ('&nbsp;Feels&nbsp;<span style="color: #F87217;">hot,</span>');
	}
	if ((this_temp >= 31) && (this_heat < 38)){
		CI_text = ('&nbsp;Feels&nbsp;<span style="color: #FF0000;">very hot,</span>');  
	}
	if (this_heat >= 38) {
		CI_text = ('&nbsp;Feels&nbsp;<span style="color: #FF0000; text-decoration: blink;">dangerously hot,</span>'); 
	}
	if (this_chill < 16) {
		CI_text = ('&nbsp;Feels&nbsp;<span style="color: #E9AB17;">mild,</span>');  
		if (this_chill < 10) {
			CI_text = ('&nbsp;Feels&nbsp;<span style="color: #82CAFA;">cool,</span>');  
		}
		if (this_chill < 3) {
			CI_text = ('&nbsp;Feels&nbsp;<span style="color: #6698FF;">cold,</span>');   
		}
		if (this_chill < -7) {
			CI_text = ('&nbsp;Feels&nbsp;<span style="color: #306EFF; text-decoration: blink;">very cold,</span>');  
		}
		if (this_chill < -35) {
			CI_text = ('&nbsp; Feels&nbsp;<span style="color: #2554C7; text-decoration: blink;">dangerously cold,</span>');  
		}
	}
	document.write(CI_text);
} // END function comfort()

