// JavaScript Document

var weather_first = true;

// -------------------------------------------------------
// onLoad
// -------------------------------------------------------
/*
window.onload = function() { 
	timer = setTimeout("fnWeatherFrame()", 500);
}
*/
// -------------------------------------------------------
// Display
// -------------------------------------------------------

function fnWeatherOn() {
	
	if (weather_first) {
		fnWeatherFrame();
		weather_first = false;
	}
	
	//document.getElementById("weather-frame").style.top = "0px";
	fnWeatherRefresh();
	document.getElementById("weather-frame").style.display = "block";
}

function fnWeatherOff() {
	//document.getElementById("weather-frame").style.top = "-200px";
	document.getElementById("weather-frame").style.display = "none";
}

function fnWeatherOutput() {
	document.getElementById("weather-output").style.display = "block";
	document.getElementById("weather-select").style.display = "none";
}

function fnWeatherSelect() {
	document.getElementById("weather-output").style.display = "none";
	document.getElementById("weather-select").style.display = "block";
}

// -------------------------------------------------------
// Weather
// -------------------------------------------------------

// Document Write
function fnWeatherFrame() {
	
	var my_html;
	my_html  = '<iframe src="';
	my_html += fnWeatherUrl();
	my_html += '" id="weather" name="weather" width="245" height="110" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>';

	document.getElementById("weather-if").innerHTML = my_html;
	//alert("aaa");
	//fnWeatherRefresh();
	//document.write(my_html);
}

// City Select
function fnWeatherCity() {
	
	var my_city = document.getElementById("city1").value;
	fnCookieSave('weather_city1',my_city,365);// Cookie 

	fnWeatherRefresh();
	fnWeatherOutput();
}

// Plugin URL Refresh
function fnWeatherRefresh() {
	document.getElementById("weather").src = fnWeatherUrl();
}

// Plugin URL
function fnWeatherUrl() {
	
	var my_url = "http://m.weather.com.cn/m/pn12/weather.htm";
	var my_city = fnCookieLoad('weather_city1');// Cookie Ǐo
	if ( my_city != null && my_city != "" ) my_url += "?id="+my_city;
	
	return my_url;
}


// -------------------------------------------------------
// Cookie
// -------------------------------------------------------

function fnCookieSave(cookieName,cookieValue,cookieDays) {
	var my_date = new Date();
	my_date.setTime(my_date.getTime()+(cookieDays*1000*60*60*24));
	my_date = my_date.toGMTString();
	document.cookie = cookieName +"="+ escape(cookieValue) +";expires="+ my_date;
	//document.cookie = "Mode=" + escape(mode) + ";domain=.kiranaspa.com;path=/;";
}

function fnCookieLoad(cookieName) {
	var my_result = "";
	var my_cookie = cookieName+"=";
	var my_value = document.cookie+";";
	var start = my_value.indexOf(my_cookie);
	if (start != -1) {
		var end = my_value.indexOf(";",start);
		my_result = unescape( my_value.substring(start+my_cookie.length, end));
	}
	return my_result;
}

function fnCookieCheck() {
	var my_result = "";
	fnCookieSave("checkCookie","ON",1)
	if (fnCookieLoad("checkCookie") == "ON") {
		return true;
	} else {
		return false;
	}
}


