<!-- use html for django include, template & static compatibility -->
{% load static %} 

<!-- js -->
<script type="text/javascript">

// _____________________________________________________________________________
//
// Requests.
//

// make request.
$.ajaxSetup({ 
    beforeSend: function(xhr, settings) {
         function getCookie(name) {
             var cookieValue = null;
             if (document.cookie && document.cookie != '') {
                 var cookies = document.cookie.split(';');
                 for (var i = 0; i < cookies.length; i++) {
                     var cookie = jQuery.trim(cookies[i]);
                     // Does this cookie string begin with the name we want?
                     if (cookie.substring(0, name.length + 1) == (name + '=')) {
                         cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                         break;
                     }
                 }
             }
             return cookieValue;
         }
         if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
             // Only send the token to relative URLs i.e. locally.
             xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
         }
    } 
});
function request(
	// the url (#1).
	url,
	// the request data (#2) (include loader:loader_element & response:response_element for visual options).
	data={}, 
	// the handler function (#3).
	handler=null,
) {
	response_element = null
	loader = null
	if (data.hasOwnProperty('response') == true) { // true
		response_element = data["response"]
		delete data['response']
	}
	if (data.hasOwnProperty('loader') == true) { // true
		loader = data["loader"]
		delete data['loader']
	}
	if (response_element != null) {
		response_element.style.display = 'none'
	}
	if (loader != null) {
		loader.style.display = "block"
	}
	var error_msg = `Request (${url}) failed, error: `
	//Response.log(`Request (${url}).`)
	//console.log(" * data: "+Response.dump(data))
	$.ajax({
			url: url,
			data: data,
			type: "post",
			dataType: 'json',
			success: function (response, status, xhr) {
				
				// serialize.
				response = Response.serialize(response)

				// loader.
				if (loader != null) {
					loader.style.display = "none"
				}

				// check success response.
				if (response.success == true) {
					var msg = `Request (${url}) success [${xhr.status}]. ${response.message}.`
					if (msg.last(".") == ".") {
						msg = msg.remove_last(".")
					}
					console.log(msg)
					//console.log(" * success: "+response.message)
					if (response_element != null) {
						response_element.style.display = "block"
						response_element.style.color = '{{COLORS.green}}'
						if (response.message != null) { 
								response_element.innerHTML = response.message
						} else {
								response_element.innerHTML = "Success."
						}
						setTimeout(function() {
							response_element.style.display = 'none'
						}, 3500)
					}
					if (handler != null) { handler(response) }

				// check error.
				} else if (response.error != null) {
					var err = `Request (${url}) failed [${xhr.status}]. ${response.error}.`
					if (err.last(".") == ".") {
						err = err.remove_last(".")
					}
					console.log(err)
					//console.log(" * error: "+err)
					if (response_element != null) {
						response_element.style.display = "block"
						response_element.style.color = '{{COLORS.red}}'
						response_element.innerHTML = response.error
						setTimeout(function() {
							response_element.style.display = 'none'
						}, 3500)
					}
					if (handler != null) { handler(response) }

				// should not happen.
				} else {
					var err = `Request (${url}) failed [${xhr.status}]. ${xhr.responseText}.`
					console.log(err)
					//console.log(" * error: "+err)
					if (response_element != null) {
						response_element.style.display = "block"
						response_element.style.color = '{{COLORS.red}}'
						response_element.innerHTML = "Error: "+err
						setTimeout(function() {
							response_element.style.display = 'none'
						}, 3500)
					}
					if (handler != null) { 
						handler({
							success:false,
							message:null,
							error:err,
						})
					}
				}

			},
			error: function(xhr, status, error) {
				var err = `Request (${url}) failed [${xhr.status}]. ${error}.`
				console.log(err)
				//console.log(" * error: "+err)
				if (loader != null) {
					loader.style.display = "none"
				}
				if (response_element != null) {
					response_element.style.display = 'block'
					response_element.style.color = "{{COLORS.red}}"
					response_element.innerHTML = "Error: "+err
					setTimeout(function() {
						response_element.style.display = 'none'
					}, 3500)
				}
				if (handler != null) { 
					handler({
						"success":false,
						"message":null,
						"error":err,
					})
				}
			}
	})
}

// _____________________________________________________________________________
//
// Styling.
//

// toggle the visibility of 2 views.
function toggle_views(old_visible_id, new_visisible_id, display="block") {
	document.getElementById(old_visible_id).style.display = "none"
	document.getElementById(new_visisible_id).style.display = display
}

// set the path in the header.
function set_header_path(path) {
	e = document.getElementById("header_path")
	if (e == null) {
		console.log("Error: unable the default [header_path] element.")
	}
	if (path.substr(path.length - 1) != "/") {
		path = path + "/"
	}
	e.innerHTML = "- "+path
	document.title = ("{{NAME}}/"+path).replace("//","/").replace("//","/").replace("//","/")
}

// set the background color.
function set_background_color(color) {
	var topbar = document.getElementById("topbar")
	var content = document.getElementById("content")
	var body = document.getElementById("body")
	if (content == null) {
		console.log("Error: unable the default [content] element.")
	} else if (topbar == null) {
		console.log("Error: unable the default [topbar] element.")
	} else if (body == null) {
		console.log("Error: unable the default [body] element.")
	}
	if (body != null) {
		body.style.background = color;
		body.style.backgroundColor = color;
	}
	if (content != null) {
		content.style.background = color;
		content.style.backgroundColor = color;
	}
	if (topbar != null) {
		topbar.style.background = color;
		topbar.style.backgroundColor = color;
	}
}

// toggle full screen.
var old_fullscreen_values = {}
function toggle_full_screen(mode="toggle", options=["toggle", "show", "hide"]) {
	var content = document.getElementById("content")
	if (content == null) {
		console.log("Error: unable the default [content] element.")
	}
	if (mode == "show") {
		old_fullscreen_values = {
			left:content.style.left,
			right:content.style.right,
			top:content.style.top,
			bottom:content.style.bottom,
		}
		content.style.left = "0px"
		content.style.right = "0px"
		content.style.top = "0px"
		content.style.bottom = "0px"
		content.getAttribute("fullscreen", "true")
	} else if (mode == "hide") {
		content.style.left = old_fullscreen_values.left
		content.style.right = old_fullscreen_values.right
		content.style.top = old_fullscreen_values.top
		content.style.bottom = old_fullscreen_values.bottom
		content.getAttribute("fullscreen", "false")
	} else if (mode == "toggle") {
		if (content.getAttribute("fullscreen") == "true") {
			toggle_full_screen("hide")
		} else {
			toggle_full_screen("show")
		}
	}
}

// hide & show the left bar.
function toggle_leftbar(mode="toggle", options=["toggle", "show", "hide"]) {
	var leftbar = document.getElementById("leftbar")
	var content = document.getElementById("content")
	if (content == null) {
		console.log("Error: unable the default [content] element.")
	} else if (leftbar == null) {
		console.log("Error: unable the default [leftbar] element.")
	}
	if (mode == "show") {
		leftbar.style.display = "block"
		content.style.left = "{{LEFTBAR_WIDTH}}"
		leftbar.setAttribute("open", "true")
	} else if (mode == "hide") {
		leftbar.style.display = "none"
		content.style.left = "0px"
		leftbar.setAttribute("open", "false")
	} else if (mode == "toggle") {
		if (leftbar.getAttribute("open") == "true") {
			toggle_leftbar("hide")
		} else {
			toggle_leftbar("show")
		}
	}
}

// hide & show the right bar.
function toggle_rightbar(mode="toggle", options=["toggle", "show", "hide"]) {
	var rightbar = document.getElementById("rightbar")
	var content = document.getElementById("content")
	if (content == null) {
		console.log("Error: unable the default [content] element.")
	} else if (rightbar == null) {
		console.log("Error: unable the default [rightbar] element.")
	}
	if (mode == "show") {
		rightbar.style.display = "block"
		content.style.right = "{{RIGHTBAR_WIDTH}}"
		rightbar.setAttribute("open", "true")
		//console.log("Showed the rightbar ("+rightbar.style.display+") ({{RIGHTBAR_WIDTH}}).")
	} else if (mode == "hide") {
		rightbar.style.display = "none"
		content.style.right = "0px"
		rightbar.setAttribute("open", "false")
		//console.log("Hided the rightbar ("+rightbar.style.display+") ({{RIGHTBAR_WIDTH}}).")
	} else if (mode == "toggle") {
		if (rightbar.getAttribute("open") == "true") {
			toggle_leftbar("hide")
		} else {
			toggle_leftbar("show")
		}
	}
}

// hide & show the top bar.
function toggle_topbar(mode="toggle", options=["toggle", "show", "hide"]) {
	var topbar = document.getElementById("topbar")
	var topbar_left = document.getElementById("topbar.left")
	var topbar_right = document.getElementById("topbar.right")
	var content = document.getElementById("content")
	var leftbar = document.getElementById("leftbar")
	var rightbar = document.getElementById("rightbar")
	if (topbar == null) {
		console.log("Error: unable the default [topbar] element.")
	} else if (topbar_left == null) {
		console.log("Error: unable the default [topbar_left] element.")
	} else if (topbar_right == null) {
		console.log("Error: unable the default [topbar_right] element.")
	} else if (content == null) {
		console.log("Error: unable the default [content] element.")
	} else if (leftbar == null) {
		console.log("Error: unable the default [leftbar] element.")
	} else if (rightbar == null) {
		console.log("Error: unable the default [rightbar] element.")
	}
	if (mode == "show") {
		topbar.style.display = "block"
		if (bool(localStorage.getItem("ELECTRON")) == true) { 
			topbar_left.style.paddingTop = "15px"
			topbar_right.style.paddingTop = "15px"
			content.style.top = (int(("{{TOPBAR_HEIGHT}}").replaceAll("px",""))+15)+"px"
			leftbar.style.top = (int(("{{TOPBAR_HEIGHT}}").replaceAll("px",""))+15)+"px"
			rightbar.style.top = (int(("{{TOPBAR_HEIGHT}}").replaceAll("px",""))+15)+"px"
			topbar.style.height = (int(("{{TOPBAR_HEIGHT}}").replaceAll("px",""))+15)+"px"
		} else {
			topbar_left.style.paddingTop = "0px"
			topbar_right.style.paddingTop = "0px"
			content.style.top = "{{TOPBAR_HEIGHT}}"
			leftbar.style.top = "{{TOPBAR_HEIGHT}}"
			rightbar.style.top = "{{TOPBAR_HEIGHT}}"
			topbar.style.height = "{{TOPBAR_HEIGHT}}"
		}
		topbar.setAttribute("open", "true")
	} else if (mode == "hide") {
		topbar.style.display = "none"
		topbar_left.style.paddingTop = "0px"
		topbar_right.style.paddingTop = "0px"
		content.style.top = "0px"
		leftbar.style.top = "0px"
		rightbar.style.top = "0px"
		topbar.style.height = "{{TOPBAR_HEIGHT}}"
		topbar.setAttribute("open", "false")
	} else if (mode == "toggle") {
		if (topbar.getAttribute("open") == "true") {
			toggle_topbar("hide")
		} else {
			toggle_topbar("show")
		}
	}
}

// hide & show the left bar.
function toggle_widgets(id="my_widget", widgets={"my_widget":document.getElementById("my_widget")}, flex=false) {
	Object.entries(widgets).forEach(function([key, value]) {
		if (key == id) {
			if (flex == true || value.className == "full_window_centered" || value.className == "full_window_row_centered") {
				value.style.display = "flex"
			} else {
				value.style.display = "block"
			}
		} else {
			value.style.display = "none"
		}
	});
}

// toggle buttons.
function toggle_button(identifier, enable_event=null, disable_event=null) {
	input = document.getElementById(identifier+".input")
	button = document.getElementById(identifier+".button")
	if (input.value == "False" || input.value == "false" || input.value == false) {
		input.value = "True"
		button.style.marginLeft = "19px";
		button.style.background = "{{COLORS.green}}";
		if (enable_event != null) {
			enable_event(identifier)
		}
	} else if (input.value == "True" || input.value == "true" || input.value == true) {
		input.value = "False"
		button.style.marginLeft = "0px";
		button.style.background = "{{COLORS.red}}";
		if (disable_event != null) {
			disable_event(identifier)
		}
	}
}
function initialize_toggle_button(identifier) {
	input = document.getElementById(identifier+".input")
	button = document.getElementById(identifier+".button")
	if (input.value == "True" || input.value == "true" || input.value == true) {
		button.style.marginLeft = "19px";
		button.style.background = "{{COLORS.green}}";
	} else {// (input.value == "False" || input.value == "false" || input.value == false) {
		input.value = "False"
		button.style.marginLeft = "0px";
		button.style.background = "{{COLORS.red}}";
	}
}
function set_toggle_button(identifier, mode=true) {
	input = document.getElementById(identifier+".input")
	button = document.getElementById(identifier+".button")
	if (mode == "False" || mode == "false" || mode == false) {
		input.value = "False"
		button.style.marginLeft = "0px";
		button.style.background = "{{COLORS.red}}";
	} else if (mode == "True" || mode == "true" || mode == true) {
		input.value = "True"
		button.style.marginLeft = "19px";
		button.style.background = "{{COLORS.green}}";
	}
}
function disable_toggle_button(identifier) {
	input = document.getElementById(identifier+".input")
	button = document.getElementById(identifier+".button")
	if (input.value == "False" || input.value == "false" || input.value == false) {
		input.value = "False"
		button.style.marginLeft = "0px";
		button.style.background = "{{COLORS.red}}75";
		button.onclick = function() {}
	} else if (input.value == "True" || input.value == "true" || input.value == true) {
		input.value = "True"
		button.style.marginLeft = "19px";
		button.style.background = "{{COLORS.green}}75";
		button.onclick = function() {}
	}
}
function enable_toggle_button(identifier) {
	input = document.getElementById(identifier+".input")
	button = document.getElementById(identifier+".button")
	if (input.value == "False" || input.value == "false" || input.value == false) {
		input.value = "False"
		button.style.marginLeft = "0px";
		button.style.background = "{{COLORS.red}}";
		button.onclick = function() {
			toggle_button(identifier)
		}
	} else if (input.value == "True" || input.value == "true" || input.value == true) {
		input.value = "True"
		button.style.marginLeft = "19px";
		button.style.background = "{{COLORS.green}}";
		button.onclick = function() {
			toggle_button(identifier)
		}
	}
}

// toggle control bar elements.
function toggle_control_bar(target="references", control_bar={references:document.getElementById("references")}, main_id="references", close_id="close") {
	for (const [id, element] of Object.entries(control_bar)) {
		if (element != null) {
			if (target == main_id) {
				if (id == "close") {
					if (element.className.includes("reversed") == false) {
						element.style.backgroundColor = "{{COLORS.button_bg}}50"
					} else {
						element.style.backgroundColor = "{{COLORS.button_bg_reversed}}50"
					}
				} else {
					if (element.className.includes("reversed") == false) {
						element.style.backgroundColor = "{{COLORS.button_bg}}"
					} else {
						element.style.backgroundColor = "{{COLORS.button_bg_reversed}}"
					}
				}
			} else {
				if (id == close_id) {
					if (element.className.includes("reversed") == false) {
						element.style.backgroundColor = "{{COLORS.button_bg}}"
					} else {
						element.style.backgroundColor = "{{COLORS.button_bg_reversed}}"
					}
				} else {
					if (element.className.includes("reversed") == false) {
						element.style.backgroundColor = "{{COLORS.button_bg}}50"
					} else {
						element.style.backgroundColor = "{{COLORS.button_bg_reversed}}50"
					}
				}
			}
		}
	}
}

// toggle dark mode.
var DARKMODE = localStorage.getItem("DARKMODE")
if (DARKMODE == null || DARKMODE == "null" || DARKMODE == "None") {
	DARKMODE = "light"
	localStorage.setItem("DARKMODE", DARKMODE)
}
function toggle_darkmode(mode="toggle") {
	// to dark.
	if (mode == "dark") {
		var e = document.getElementById("body")
		if (e != null) { e.style.background = "{{COLORS.background_darkmode}}"}
		var e = document.getElementById("topbar")
		if (e != null) { e.style.background = "{{COLORS.topbar_darkmode}}" }
		var classes = [
			"widget",
			"toggle_button_input",
			"widget_container",
		]
		classes.forEach(function(item) {
			Array.from(document.getElementsByClassName(item)).forEach(function(item) {
				if (item.getAttribute("darkmode") != "false") {
					item.style.background = "{{COLORS.widgets_darkmode}}"
					item.style.backgroundColor = "{{COLORS.widgets_darkmode}}"
				}
			})
		})
		var classes = [
			"divider",
			//"loader",
		]
		classes.forEach(function(item) {
			Array.from(document.getElementsByClassName(item)).forEach(function(item) {
				if (item.getAttribute("darkmode") != "false") {
					item.style.background = "{{COLORS.widgets}}"
				}
			})
		})
		var classes = [
			"text",
			"code",
			"title",
			"subtitle",
			"input",
			"input_bordered",
			"code_input",
			"textarea",
			"textarea_bordered",
			"code_textarea",
			"toggle_button_text",
		]
		classes.forEach(function(item) {
			Array.from(document.getElementsByClassName(item)).forEach(function(item) {
				if (item.getAttribute("darkmode") != "false") {
					if (item.style.color != "{{COLORS.red}}") {
						item.style.color = "{{COLORS.text_darkmode}}"	
					}
				}
			})
		})
		var lightmode = document.getElementById("darkmode_control_bar.lightmode")
		var darkmode = document.getElementById("darkmode_control_bar.darkmode")
		lightmode.style.background = "#00000000"
		lightmode.style.boxShadow = "none"
		darkmode.style.background = "{{COLORS.widgets_reversed}}"
		darkmode.style.boxShadow = "0 0 10px #00000050"
		DARKMODE = "dark"
		localStorage.setItem("DARKMODE", DARKMODE)

	// to light.
	} else if (mode == "light") {
		var e = document.getElementById("body")
		if (e != null) { e.style.background = "{{COLORS.background}}"}
		var e = document.getElementById("topbar")
		if (e != null) { e.style.background = "{{COLORS.topbar}}" }
		var classes = [
			"widget",
			"toggle_button_input",
			"widget_container",
		]
		classes.forEach(function(item) {
			Array.from(document.getElementsByClassName(item)).forEach(function(item) {
				if (item.getAttribute("darkmode") != "false") {
					item.style.background = "{{COLORS.widgets}}"
					item.style.backgroundColor = "{{COLORS.widgets}}"
				}
			})
		})
		var classes = [
			"divider",
			//"loader",
		]
		classes.forEach(function(item) {
			Array.from(document.getElementsByClassName(item)).forEach(function(item) {
				if (item.getAttribute("darkmode") != "false") {
					item.style.background = "{{COLORS.grey}}"
				}
			})
		})
		var classes = [
			"text",
			"code",
			"title",
			"subtitle",
			"input",
			"input_bordered",
			"code_input",
			"textarea",
			"textarea_bordered",
			"code_textarea",
			"toggle_button_text",
		]
		classes.forEach(function(item) {
			Array.from(document.getElementsByClassName(item)).forEach(function(item) {
				if (item.getAttribute("darkmode") != "false") {
					if (item.style.color != "{{COLORS.red}}") {
						item.style.color = "{{COLORS.text}}"
					}
				}
			})
		})
		var lightmode = document.getElementById("darkmode_control_bar.lightmode")
		var darkmode = document.getElementById("darkmode_control_bar.darkmode")
		darkmode.style.background = "#00000000"
		darkmode.style.boxShadow = "none"
		lightmode.style.background = "{{COLORS.widgets_reversed}}"
		lightmode.style.boxShadow = "0 0 10px #00000050"
		DARKMODE = "light"
		localStorage.setItem("DARKMODE", DARKMODE)

	// toggle.
	} else if (mode == "toggle") {
		if (DARKMODE == "light") {
			toggle_darkmode("dark")
		} else if (DARKMODE == "dark") {
			toggle_darkmode("light")
		}
	}
}

// _____________________________________________________________________________
//
// Utils.
//

// Mobile detection.
var mobile_platform = {
	Android: function() {
			return navigator.userAgent.match(/Android/i);
	},
	BlackBerry: function() {
			return navigator.userAgent.match(/BlackBerry/i);
	},
	iOS: function() {
			return navigator.userAgent.match(/iPhone|iPad|iPod/i);
	},
	Opera: function() {
			return navigator.userAgent.match(/Opera Mini/i);
	},
	Windows: function() {
			return navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/WPDesktop/i);
	},
	any: function() {
			return (mobile_platform.Android() || mobile_platform.BlackBerry() || mobile_platform.iOS() || mobile_platform.Opera() || mobile_platform.Windows());
	}
};
/*
	if (mobile_platform.any()) {
		alert('Mobile')
	}
*/

// get url parameters.
function get_boolean_url_param(id) {
	var url = new URL(window.location.href);
	var value = url.searchParams.get(id);
	if (value == "true" || value == "True" || value == true) {
		return true
	}
	else { 
		return false 
	}
}
function get_url_param(id) {
	var url = new URL(window.location.href);
	return url.searchParams.get(id);
}

// retrieve the browser platform.
function get_platform() {
	if ( ( window.innerWidth <= 800 ) && ( window.innerHeight <= 600 ) ) {
		return "mobile"
	} else {
		return "desktop"
	}
}

// download source.
function download_source(source='/requests/clients/download_public_key/', output='public_key.txt') {
	var a = document.createElement('A');
	a.href = source;
	a.download = output.substr(output);
	document.body.appendChild(a);
	a.click();
	document.body.removeChild(a);
}

// copy text to clipboard.
function copy_to_clipboard(str) {
	// Create new element
	var el = document.createElement('textarea');
	// Set value (string to be copied)
	el.value = str;
	// Set non-editable to avoid focus and move outside of view
	el.setAttribute('readonly', '');
	el.style = {position: 'absolute', left: '-9999px'};
	document.body.appendChild(el);
	// Select text inside element
	el.select();
	// Copy text to clipboard
	document.execCommand('copy');
	// Remove temporary element
	document.body.removeChild(el);
}

// get cookie.
function get_cookie(name) {
    let cookieValue = null;
    if (document.cookie && document.cookie !== '') {
        const cookies = document.cookie.split(';');
        for (let i = 0; i < cookies.length; i++) {
            const cookie = cookies[i].trim();
            // Does this cookie string begin with the name we want?
            if (cookie.substring(0, name.length + 1) === (name + '=')) {
                cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                break;
            }
        }
    }
    return cookieValue;
}
// const csrftoken = get_cookie('csrftoken');

// get operating system.
function operating_system() {
  var userAgent = window.navigator.userAgent,
      platform = window.navigator.platform,
      macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'],
      windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'],
      iosPlatforms = ['iPhone', 'iPad', 'iPod'],
      os = null;

  if (macosPlatforms.indexOf(platform) !== -1) {
    os = 'macos';
  } else if (iosPlatforms.indexOf(platform) !== -1) {
    os = 'ios';
  } else if (windowsPlatforms.indexOf(platform) !== -1) {
    os = 'windows';
  } else if (/Android/.test(userAgent)) {
    os = 'android';
  } else if (!os && /Linux/.test(platform)) {
    os = 'linux';
  } else {
  	os = "unknown"
  }
  return os;
}
var OS = operating_system()

// browsers.

// Opera 8.0+
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;

// Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';

// Safari 3.0+ "[object HTMLElementConstructor]" 
var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && window['safari'].pushNotification));

// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;

// Edge 20+
var isEdge = !isIE && !!window.StyleMedia;

// Chrome 1 - 79
var isChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);

// Edge (based on chromium) detection
var isEdgeChromium = isChrome && (navigator.userAgent.indexOf("Edg") != -1);

// Blink engine detection
var isBlink = (isChrome || isOpera) && !!window.CSS;


// active tab
$(function() {
    window.isActive = true;
    $(window).focus(function() { this.isActive = true; });
    $(window).blur(function() { this.isActive = false; });
    showIsActive();
});
function showIsActive() {
    window.setTimeout("showIsActive()", 2000);
}
/*
	if (window.isActive) {
	}
*/
</script>