﻿ <?xml version="1.0" encoding="UTF-8" ?> 
 <Module>
 <ModulePrefs title="YoWindow" directory_title="YoWindow" description="Watch the weather with pleasure!" title_url="http://yowindow.com" screenshot="http://yowindow.com/img/ig/w280.png" thumbnail="http://yowindow.com/img/ig/w120.png" author="Pavel Repkin" author_email="h.zondag@gmail.com" author_link="http://yowindow.com" author_aboutme="YoWindow was created by Pavel Repkin and Yuri Elshin who reside in Saint-Petersburg, Russia. Pavel has written the code and Yuri has drawn the pictures. You may read more about us here: http://yowindow.com/team.html" author_affiliation="Repkasoft" author_location="Saint-Petersburg, Russia">
  <Require feature="setprefs" /> 
  <Require feature="dynamic-height" /> 
  <Require feature="views" /> 
  <Require feature="flash" /> 
  </ModulePrefs>
  <UserPref name="locationId" display_name="Locaton ID (www.yowindow.com/id.html):" default_value="2757783" /> 
  <UserPref name="temperatureUnits" datatype="enum" display_name="Temperature units:" default_value="">
  <EnumValue value="F" display_value="F" /> 
  <EnumValue value="C" display_value="C" /> 
  </UserPref>
 <UserPref name="timeFormat" datatype="enum" display_name="Time format:" default_value="">
  <EnumValue value="12" display_value="AM/PM" /> 
  <EnumValue value="24" display_value="24 hours" /> 
  </UserPref>
  <UserPref name="locationPath" datatype="hidden" default_value="#allContinents/6252001/5128638/5128581" /> 
 <Content type="html" view="canvas,profile">
 <![CDATA[ 
<!-- ALm6fM0apPY0cOU2xZm6iaM18C8pa2K/j4Gckio2wVOmsdU1cc89MCnTS+jRqhMNqH+oUJA1/Yowft3WM5M9DNL9kAb73YnmhvIjI1Gy6F7r1idQLq4jydbje0AioLmk5kw0IY0onDnV -->

<html><head><style type="text/css">
body,td,div,span,p{font-family:arial,sans-serif;}a {color:#0000cc;}a:visited {color:#551a8b;}a:active {color:#ff0000;}body{
	margin: 0px;
	padding: 0px;
	background-color:transparent;
}
</style>
<style type="text/css">
    object { outline:none;}

    #location_chooser_box {
    	background:#D4E6FC none repeat scroll 0 0;
    	height: 400px;
    	margin: 0;
    	padding: 0;
    	display: none;
    }

	#location_chooser_layer {
    	position: absolute;
    	left: 4px;
    	top: 0px;
    	width: 300;
    	height: 300px;
		z-index: 2;
	}

    .location_button_bar {
		position:absolute;
    	left: 0px;
    	top: 340px;
    	margin: 10px 0 0 10px;
		z-index: 3;
    }
</style>
<script language="JavaScript">
	var debug = 0;
//d	var debug = 1;

	var debug_html = "";
	var myLocationId = "";
	var myLandscape = "";
	var myIsHpPalReady = false;
//w	gadgets.util.registerOnLoadHandler(init); Does not work when the gadget is embedded
	_IG_RegisterOnloadHandler(init);

//w	var myPrefs = new gadgets.Prefs(); Does not work when the gadget is embedded
	var myPrefs = new _IG_Prefs();

	function init() {
//p	p("init()");
//p	p("myPrefs=" + myPrefs);
	
		myLocationId = myPrefs.getString("locationId");
				
//p
		p("init(), locationId=" + myLocationId);
		
		if (myLocationId == "") {
			var box = window.document.getElementById('location_chooser_box');
			box.style.display = 'display';
			validateOkButton();
		}

   		var viewName = gadgets.views.getCurrentView().getName();
   		if (viewName == 'canvas') {
   			var height = 250;
	   		var pal_box = document.getElementById('pal_box');
	   		pal_box.style.height = height;
	   	}


         _IG_EmbedCachedFlash(
        	"swf.yowindow.com/wimo/hpPal/hpLocationChooser.swf", 
        	"location_chooser_place", {
                id: "hpLocationChooser",
    	        name: "hpLocationChooser",
            	allowfullscreen: "true",
            	quality: "high",
        		allowscriptaccess: "always",
        		wmode: "transparent",
				flashvars: "base_path=#relative&location_id=" + myLocationId
        	}
        );

//.add pal swf<
		if (viewName == 'HOME') {
			
			var url = "http://swf.yowindow.com/wimo/hpPal/hpPal.swf?a=1";

//HACK<
//Avoid uncontrolled gadget height expansion in home view when locaiton chooser is opened
//But expand gadget height to 100% in embedded view
			var box = window.document.getElementById('pal_box');
			box.style.height = "250px";
//HACK>


//d				_IG_EmbedFlash(
// 
          	_IG_EmbedCachedFlash(
            	url, 
            	"pal_place", {
                    id: "hpPal",
        	        name: "hpPal",
                	allowfullscreen: "true",
                	quality: "high",
                	bgcolor: "#FFFFFF",
            		allowscriptaccess: "always",
            		allowfullscreen: "true",
            		wmode: "transparent",
                	refreshInterval:3600,
        	    	flashvars: "background=#FFFFFF&base_path=#relative&location_id=" + myLocationId 
//d trace_text_area=1&debug=true
            	}
            );
		}
		else if (viewName == 'canvas') {

            var result = _IG_EmbedCachedFlash(
            	"http://swf.yowindow.com/wimo/hpPal/hpPal.swf?a=1", 
            	"pal_place", {
                    id: "hpPal",
        	        name: "hpPal",
                	allowfullscreen: "true",
                	quality: "high",
                	bgcolor: "#FFFFFF",
            		allowscriptaccess: "always",
            		allowfullscreen: "true",
            		wmode: "transparent",
                    refreshInterval: 3600,
        	    	flashvars: "background=#FFFFFF&role=setup&mini_change_button=true&base_path=#relative&location_id=" + myLocationId 
        }
            );
//d		trace_text_area: "1",

        		
        }
//>

		adjustHeight();

	}
	
	function okLocation() {
//p		alert("okLocation()");
		
//p		p("saveLocation, myLocationId=" + myLocationId + ", myPrefs=" + myPrefs);
		var geonamesId = myLocationId.substring(3);
		myPrefs.set("locationId", geonamesId);

//p		p("getLocation, locationId=" + myPrefs.getString("locationId"));

  		var lc = document.getElementById('hpLocationChooser');
  		var locationPath = lc.getPath();
//p print ("path=" + locationPath);
		myPrefs.set("locationPath", locationPath);

		var box = window.document.getElementById('location_chooser_box');
		box.style.display = 'none';
		adjustHeight();
	}

	function cancelLocation() {
//p		alert("cancelLocation()");

		myLocationId = myPrefs.getString('locationId');
		reflectLocationToPal();

		var box = window.document.getElementById('location_chooser_box');
		box.style.display = 'none';

		adjustHeight();
	}

	function switchLocationBox() {
		var box = window.document.getElementById('location_chooser_box');
//p		p("box.style.display=" + box.style.display);
		box.style.display = (box.style.display == 'block') ? 'none' : 'block';
		adjustHeight();
	}

	function validateOkButton() {
    	var ok_btn = document.getElementById('ok_btn');
    	var ok = myLocationId != "";
    	ok_btn.disabled = !ok;
	}

    function reflectLocationToPal() {
    	if (myLocationId) {
    		var pal = document.getElementById('hpPal');

    		if (!myIsHpPalReady) {
    			return;
    		}
    		if (!pal) {
    			p("pal is missing at reflectLocationToPal()");
    			return;
    		}
//p p("setLocation(), locationId=" + myLocationId + ", pal=" + pal);

            try {
        		pal.setLocationId(myLocationId);
            }
            catch (e) {
           		p("reflectLocationToPal(), exception: " + e);
            }
	    }		
    }

//ExternalInterface, hpPal <
    function handleChangeButtonPress() {
		switchLocationBox();
    }
//ExternalInterface >


//ExternalInterface, locationChooser <
function handleLocationChange(locationId, name) {
    try {//.required in external methods, because exception here is silent for js-error console
//p	p("handleLocationChange(), locationId=" + locationId + ", name=" + name);
//.No location selected in location-chooser, do not change selected location.
    	if (!locationId) {
    		return;
    	}
//p		p("locationId change, locationId=" + locationId);
		
		myLocationId = locationId;
		validateOkButton();
    	reflectLocationToPal();
    }
    catch (e) {
//d    	alert("handleLocationChange(), exception: " + e);
    }
}

function requestUiTop() {
	try {
//p	alert("requestUiTop()");
    	var layer = document.getElementById('location_chooser_layer');
    	if (layer.style.zIndex == 4) {
    		severe("unexpected layer zIndex value, v=" + layer.style.zIndex);
    	}
    	layer.style.zIndex = 4;
//p	p("layer=" + layer);
    }
    catch (e) {
    	alert("requestUiTop(), exception: " + e);
    }
}

function releaseUiTop() {
//p	alert("releaseUiTop()");
    try {
    	var layer = document.getElementById('location_chooser_layer');
    	if (layer.style.zIndex != 4) {
    		severe("unexpected layer zIndex value");
    	}
    	layer.style.zIndex = 0;
    }
    catch (e) {
    	alert("releaseUiTop(), exception: " + e);
    }
}
//ExternalInterface >


function hpPal_DoFSCommand(command, args) {
    if (command == "partrace") {
//p p("[Pal] " + args);
    }
    else if (command == "readyForCommands") {
    	onPalReady();
    }
}

function onPalReady() {
	myIsHpPalReady = true;

	var us = detectUnitSystem();
	var tf = detectTimeFormat();

	var temperatureUnits = myPrefs.getString('temperatureUnits');
//p	p("temperatureUnits=" + temperatureUnits);
	if (temperatureUnits == 'C') {
		us = 'metric';
	}
	else if (temperatureUnits == 'F') {
		us = 'us';
	}


	var prefTf = myPrefs.getString('timeFormat');
	if (prefTf) {
		tf = prefTf;
	}

	var pal = document.getElementById('hpPal');
	pal.setUnitSystem(us);
//p	p("tf=" + tf);
	pal.setSimpleTimeFormat(tf);

//.Do not display change button when the gadget is embedded
	if (gadgets.window != null) {
		pal.setViewProperty("mini_changeButton", false);
	}

	if (myLocationId) {
		reflectLocationToPal();
	}
}

function hpLocationChooser_DoFSCommand(command, args) {
    if (command == "partrace") {
//p        p("[LC] " + args);
    }
    else if (command == "readyForCommands") {
    	onLocationChooserReady();
    }
}

function onLocationChooserReady() {
//p	p("onLocationChooserReady()");
  	var lc = document.getElementById('hpLocationChooser');
  	var locationPath = myPrefs.getString("locationPath");
  	lc.setPath(locationPath);
}

function detectUnitSystem() {
	var country = myPrefs.getCountry();
	var lang = myPrefs.getLang();
//p	print ("country=" + country);
//	print ("lang=" + lang);

//.Warning, country is US, even if Russia is selected in Google account
//However, the language is detected right
	var us = "us";
	if (lang == "en") {
		us = "us";
	}
	else if (lang == 'ru') {
		us = "russian";
	}
	else {
		us = "metric";
	}
	return us;
}

function detectTimeFormat() {
	var country = myPrefs.getCountry();
	var lang = myPrefs.getLang();

	var tf = "12";
	if (lang != "en") {
		tf = "24";
	}
	return tf;
}

function adjustHeight() {
//w gadgets.window.adjustHeight(); Does not work when embedded

	_IG_AdjustIFrameHeight();
}

function p(msg) {      
    if (!debug) {
    	return;
    }

    debug_html += msg + "<br/>";
    document.getElementById("debug_div").innerHTML = debug_html;
	adjustHeight();
}

</script>
<!--[if IE]>
<script type="text/javascript" event="FSCommand(command,args)" for="hpPal">
  hpPal_DoFSCommand(command, args);
</script>
<script type="text/javascript" event="FSCommand(command,args)" for="hpLocationChooser">
  hpLocationChooser_DoFSCommand(command, args);
</script>
<![endif]-->

	

	<div id="debug_div" style="font-size:9pt; padding:0px; color: red;"></div>
	            
	<div id="pal_box" style="width:383; height:250">
		<div id="pal_place">
            <object id="hpPal" name="hpPal"
            type="application/x-shockwave-flash" data="http://swf.yowindow.com/wimo/hpPal/hpPal.swf" width="100%" height="100%">
                <param name="movie" value="http://yowindow.com/wimo/hpPal/hpPal.swf"/>
                <param name="allowfullscreen" value="true"/>
                <param name="allowscriptaccess" value="always"/>
                <param name="wmode" value="transparant"/>
                <param name="bgcolor" value="#C0CCC0"/>
                <param name="flashvars" value="landscape=airport&amp;lang=nl&amp;background=#FFFFFF&amp;mini_change_button=false&amp;mini_locationBar=true&amp;mini_momentBar=true"/>
                The beautiful weather monitor requires the free Adoble Flash Player which you can <a href="http://get.adobe.com/flashplayer/">download here</a>.
            </object>
		</div>
    </div>

    

  ]]> 
  </Content>
  </Module>