﻿var isPrintButtonClicked = false;
var isPrintButtonVisible = false;
// number of milliseconds in day
var MILLIS_IN_DAY = 86400000;
// number of milliseconds in year
var MILLIS_IN_YEAR = MILLIS_IN_DAY * 365;
// maximum number of banners
var MAX_BANNERS_NUMBER = 7;
var isFlashBannerCreated = false;
var drawSpacerDiv = true;
var spacerDiv = '<div style="height:10px"><spacer height="10" width="1" type="block"/></div>';

function setCookie(name, value, isSession, expireMillis) {
	if (!name) return;
	var result = name;
	if (value) result += "=" + escape(value);
	result += ";";
	if (!isSession)
		result += "expires=" + new Date(getMillis(expireMillis)).toUTCString() + ";"
	result += "path=/;";
	document.cookie = result;
}

function getCookie(sName) {
	var aCookie = document.cookie.split("; ");
	for (var i = 0; i < aCookie.length; i++) {
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0])
			return unescape(aCrumb[1]);
	}
	return null;
}

function getCookieHex(sName) {
    var aCookie = document.cookie.split("; ");
    for (var i = 0; i < aCookie.length; i++) {
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0]) {
          return decodeHex(aCrumb[1]);
        }
    }
    return null;
}

function eraseCookie(name) {
    setCookie(name, "", false, -99999999);
}

function isCookieless() {
	setCookie("test_cookieless", "1", true, MILLIS_IN_DAY);
	var cookie = document.cookie;

	if (cookie == null || cookie == '') {
		return true;
	} else {
		return false;
	}
}

function getMillis(increment) {
	var curr = new Date();
	curr = Date.parse(curr.toGMTString());
	return curr + increment;
}

function createBannerHTML(indexElement) {
	var specialsHTML = '';
	var temp = indexElement["imageLink"];
	var extension = temp.split(".");
	var targetLink = indexElement["targetLink"];
	isFlashBannerCreated = false;

	specialsHTML += '<div>';
	if (targetLink != '') {
		if (indexElement["isNewWindowLink"] == 'popup') {
			specialsHTML += '<a href="javascript:void(0)" onclick="openPopup(\'' + getFixURL(targetLink) + '\')">';
		} else {
			specialsHTML += '<a href="' + getFixURL(targetLink) + '" ';
			if (indexElement["isNewWindowLink"] == 'true') {
				specialsHTML += 'target="_blank"';
			}
			specialsHTML += ">";
		}
	}
	if (extension[extension.length - 1].substring(0, 3) == "swf") {
		specialsHTML += createFlashBannerHTML(indexElement["imageLink"], indexElement["title"], indexElement["width"], indexElement["height"], "flash_banner_" + indexElement["ID"], indexElement["altImg"]);
	} else {
		specialsHTML += createImageHTML(indexElement["imageLink"], indexElement["title"], indexElement["width"], indexElement["height"], 0);
	}
	if (targetLink != '') {
		specialsHTML += "</a>";
	}
	specialsHTML += '</div>';
	return specialsHTML;
}

// create image HTML
function createImageHTML(link, title, width, height, vspace) {
	var resHtml = "";
	// default is width="219" height="99"
	resHtml += '<img border="0" ';
	resHtml += 'vspace="' + vspace + '" ';
	resHtml += 'src="' + link + '" ';
	resHtml += 'title="' + title + '" ';
	resHtml += 'alt="' + title + '" ';
	resHtml += 'width="' + width + '" ';
	resHtml += 'height="' + height + '"/>';

	return resHtml;
}

// create flash banner HTML
function createFlashBannerHTML(link, title, width, height, name, imgLink) {
	isFlashBannerCreated = false;
	//document.write(spacerDiv);
	return createFlashHTML(link, title, width, height, '#FFFFFF', name, imgLink);
	//document.write(spacerDiv);
}

function createFlashHTML(link, title, width, height, bgcolor, name, imgLink) {
	return createFlashHTML(link, title, width, height, bgcolor, name, imgLink, 7, null);
}

function createFlashHTML(link, title, width, height, bgcolor, name, imgLink, version) {
	return createFlashHTML(link, title, width, height, bgcolor, name, imgLink, version, null);
}

function createFlashHTML(link, title, width, height, bgcolor, name, imgLink, version, paramList) {
	var resHtml = "";

	if (typeof (version) == 'undefined') version = 7;

	var fo = new FlashObject(link, name, width, height, version, bgcolor);

	if (fo.installedVer.versionIsValid(fo.getAttribute("version"))) {
		fo.addParam("wmode","transparent");
		if (paramList != null) {
        		for (var i = 0; i < paramList.length; i++)
        			fo.addVariable(paramList[i]["name"], paramList[i]["value"]);
    		}
		if (drawSpacerDiv) document.write(spacerDiv);
		document.write('<div id="flashholder_' + name + '"></div>');

		fo.write("flashholder_" + name);
		isFlashBannerCreated = true;

		return '';
	} else if (imgLink != '') {
		if (name.indexOf("flash_banner_") != -1) {
			resHtml += createImageHTML(imgLink, title, width, height, 0);
			return resHtml;
		} else {
			resHtml += '<a href="http://www.macromedia.com/go/getflashplayer/" target="_blank">';
			resHtml += createImageHTML(imgLink, title, width, height, 0);
			resHtml += '</a>';
			document.write(resHtml);
		}
	}
}

// create left banners
function createSpecials() {
	var specialsHTML = '';
	var tmpHTML = '';
	var bannerCounter = 0;
	var checkCount = 0;

	if (allBanners) {
		checkCount = (MAX_BANNERS_NUMBER > specialsArray.length) ? specialsArray.length : MAX_BANNERS_NUMBER;
		for (var i = 0; i < specialsArray.length; i++) {
			if (bannerCounter < checkCount && specialsArray[i]["isActive"] == 'true') {
				if (specialsArray[i]["showIn"] == '' || (specialsArray[i]["showIn"] != '' && isAmerica)) {
					drawSpacerDiv = true;
					tmpHTML = createBannerHTML(specialsArray[i]);
					if (!isFlashBannerCreated) {
						specialsHTML += spacerDiv;
						specialsHTML += tmpHTML;
					}
					bannerCounter++;
				}
			}
		}
	} else {
		bannerCounter = 0;
		checkCount = (MAX_BANNERS_NUMBER > specialsID.length) ? specialsID.length : MAX_BANNERS_NUMBER;
		var excludeBannerArray = new Array();
		excludeBannerArray.length = 0;
		for (var i = 0; i < checkCount; i++) {
			for (var j = 0; j < specialsArray.length; j++) {
				if (specialsID[i]["ID"] == specialsArray[j]["ID"]) {
					if (specialsArray[j]["showIn"] == '' || (specialsArray[j]["showIn"] != '' && isAmerica)) {
						excludeBannerArray[excludeBannerArray.length] = specialsArray[j]["ID"];
						drawSpacerDiv = true;
						tmpHTML = createBannerHTML(specialsArray[j]);
						if (!isFlashBannerCreated) {
							specialsHTML += spacerDiv;
							specialsHTML += tmpHTML;
						}
						bannerCounter++;
					}
				}
			}
		}

		// show top 5 banners from queue logic
		var isShow = false;
		if (showTopBanners && bannerCounter < MAX_BANNERS_NUMBER) {
			for (var i = 0; i < specialsArray.length; i++) {
				if (bannerCounter < MAX_BANNERS_NUMBER && specialsArray[i]["isActive"] == 'true') {
					isShow = true;
					for (var j = 0; j < excludeBannerArray.length; j++) {
						if (specialsArray[i]["ID"] == excludeBannerArray[j]) {
							isShow = false;
							break;
						}
					}
					if (isShow) {
						if (specialsArray[i]["showIn"] == '' || (specialsArray[i]["showIn"] != '' && isAmerica)) {
							drawSpacerDiv = true;
							tmpHTML = createBannerHTML(specialsArray[i]);
							if (!isFlashBannerCreated) {
								specialsHTML += spacerDiv;
								specialsHTML += tmpHTML;
							}
							bannerCounter++;
						}
					}
				}
			}
		}
	}
	specialsHTML += '<div style="height:10px"><spacer type="block" width="1" height="10" /></div>';
	document.write(specialsHTML);
}

function updateBannerIndex() {
	var currentIndex;
	currentIndex = parseInt(getCookie("bannerIndex"), 10);
	if (currentIndex != null) {
		currentIndex += 1;
		setCookie("bannerIndex", currentIndex, true, MILLIS_IN_DAY);
	} //else {
	//	bannerIndex = 0;
	//	setCookie("bannerIndex", "0", false, MILLIS_IN_DAY);
	//}	
}

function createTopBanners() {
	var topBannersHTML = '';
	var bannerIndex = '';

	if (!isCookieless()) {
		bannerIndex = getCookie("bannerIndex");
		if (bannerIndex == '' || bannerIndex == null || bannerIndex == 'NaN' || bannerIndex == 'undefined' || bannerIndex >= bannersArray.length) {
			bannerIndex = 0;
			setCookie("bannerIndex", "0", true, MILLIS_IN_DAY);
		}
	} else {
		bannerIndex = Math.floor(Math.random()*bannersArray.length);
	}

	drawSpacerDiv = false;

	if (bannersArray.length > 0) {
		if (bannersArray[bannerIndex]["isActive"] == 'true') {
			if (bannersArray[bannerIndex]["showIn"] == '' || (bannersArray[bannerIndex]["showIn"] != '' && isAmerica)) {
				topBannersHTML += createBannerHTML(bannersArray[bannerIndex]);
				topBannersHTML += '<div style="height:3px"><spacer type="block" width="1" height="3"/></div>';	
			}
		}
	}
	
	document.write(topBannersHTML);
}

// Open Popup
var op = null;
function openPopup(page) {
	if (!is_opera8) {
		if (op != null && !op.closed) op.close();
	}

	op = window.open(page, 'popup', 'resizable=no,menubar=no,status=no,scrollbars=yes,width=556,height=595,top=10,left=10');
	if (op != null) {
		op.focus();
	}
	return false;
}

function openPopupNoScroll(page) {
	if (!is_opera8) {
		if (op != null && !op.closed) op.close();
	}

	op = window.open(page, 'popup', 'resizable=no,menubar=no,status=no,scrollbars=no,width=540,height=595,top=10,left=10');
	if (op != null) {
		op.focus();
	}
	return false;
}

function openPopupCustom(link, width, height) {
	if (!is_opera8) {
		if (op != null && !op.closed) op.close();
	}
	var style = 'resizable=no,menubar=no,status=no,scrollbars=no,top=10,left=10';
	style += ',width=' + width;
	style += ',height=' + height;
	op = window.open(rootPath + link, 'popup', style);
	if (op != null) {
		op.focus();
	}
	return false;
}

function openPopupCustom(link, width, height, scrollbars) {
	if (!is_opera8) {
		if (op != null && !op.closed) op.close();
	}
	var style = 'resizable=no,menubar=no,status=no,';
	style += 'scrollbars=' + scrollbars;
	style += ',top=10,left=10';
	style += ',width=' + width;
	style += ',height=' + height;
	op = window.open(rootPath + link, 'popup', style);
	if (op != null) {
		op.focus();
	}
	return false;
}

var sp=null;
function openPopupImage(image) {
	//if(sp!=null && !sp.closed) sp.close();
	sp=window.open('','photo','resizable=no,menubar=no,status=no,scrollbars=no,width=10,height=10,top=0,left=0');
 
	var html='';
	html+='<html><head><title>S7 Airlines</title><meta http-equiv="content-type" content="text/html; charset=UTF-8" /></head><body style="margin:0px;padding:0px;background:#BAD405">';
	html+='<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td align="center" valign="top"><div style="height:30px"><spacer /></div><table border="0" cellpadding="2" cellspacing="0"><tr><td style="border:1px solid #6EB33E;background:#FFFFFF">';
	html+='<a href="javascript:void(0)" onclick="window.close();"><img src="'+ image +'" border="0" onload="window.resizeTo(this.width+80,this.height+110)" title="Закрыть окно" alt="Закрыть окно"/></a>';
	html+='</td></tr></table></td></tr></table>';
	html+='</body></html>';

	if (sp != null) {
		sp.document.open();
		sp.document.write(html);
		sp.onload=sp.focus;
		sp.focus();
	}
	return false;
}

function openWinPopup(page) {
	if (!is_opera8) {
		if (op != null && !op.closed) op.close();
	}
	op = window.open(page, 'popup', 'toolbar=yes,location=yes,resizable=yes,menubar=yes,status=yes,scrollbars=yes,width=800,height=580,top=10,left=10');
	if (op != null) {
		op.focus();
	}
	return false;
}

var om = null;
function openMap(page) {
	if (!is_opera8) {
		if (om != null && !om.closed) om.close();
	}
	om = window.open(page, 'map', 'resizable=yes,menubar=no,status=no,scrollbars=no,width=760,height=527,top=0,left=0');
	if (om != null) {
		om.focus();
	}
}

function showPrint() {

	var forPrintDivBot = document.getElementById('forPrintDivBot');
	if (forPrintDivBot != null) {
		fillPrintBot();
	}
	var url = document.location.href;
	if (is_opera && !is_opera7) {
		alert(badBrowser);
		return false;
	}


	openPopup(langPath + 'print.html?print=true&pageURL=' + url + '#&rootPath=' + rootPath + '&langPath=' + langPath);

	return false;
}

function fillPrintBot() {
	var form = getActiveForm();
	var year = "";
	var month = "";
	var currentDiv;

	//origin city

	currentDiv = document.getElementById('divOriginCity');
	var currentField = form.elements['origin'];
	var values = initialCityList.split(";");
	var i = 0;
	for (i; i < values.length; i++) {
		var value = values[i].split(":");
		if (value[0] == currentField.options[currentField.selectedIndex].value) {
			currentDiv.innerHTML = value[1].substring(0, 27);
		}
	}

	//destination city

	currentDiv = document.getElementById('divDestCity');
	currentField = form.elements['destination'];
	values = initialCityList.split(";");
	i = 0;
	if (currentField.selectedIndex != 0) {
		for (i; i < values.length; i++) {
			var value = values[i].split(":");
			if (value[0] == currentField.options[currentField.selectedIndex].value) {
				currentDiv.innerHTML = value[1].substring(0, 27);
			}
		}
	} else
		currentDiv.innerHTML = '';

	//departure day-month-year

	currentDiv = document.getElementById('divDay1');
	currentField = form.elements['day1'];
	if (currentField.selectedIndex != 0) {
		value = currentField.options[currentField.selectedIndex].value;
		currentDiv.innerHTML = value;
	} else
		currentDiv.innerHTML = '';

	currentDiv = document.getElementById('divMonthYear1');
	currentField = form.elements['monthyear1'];
	if (currentField.selectedIndex != 0) {
		value = currentField.options[currentField.selectedIndex].value;
		month = value.substring(value.indexOf("-") + 1);
		var c1 = month.charAt(0);
		if (c1 == '0') {
			var c2 = month.charAt(1);
			month = c2;
		}
		year = value.substring(0, value.indexOf("-"));
		currentDiv.innerHTML = monthNamesNormal[parseInt(month) - 1] + " " + year;
	} else
		currentDiv.innerHTML = '';

	//return day-month-year

	currentDiv = document.getElementById('divDay2');
	currentField = form.elements['day2'];
	if (currentField.selectedIndex != 0) {
		value = currentField.options[currentField.selectedIndex].value;
		currentDiv.innerHTML = value;
	} else
		currentDiv.innerHTML = '';

	currentDiv = document.getElementById('divMonthYear2');
	currentField = form.elements['monthyear2'];
	if (currentField.selectedIndex != 0) {
		value = currentField.options[currentField.selectedIndex].value;
		month = value.substring(value.indexOf("-") + 1);
		var c1 = month.charAt(0);
		if (c1 == '0') {
			var c2 = month.charAt(1);
			month = c2;
		}
		year = value.substring(0, value.indexOf("-"));
		currentDiv.innerHTML = monthNamesNormal[parseInt(month) - 1] + " " + year;
	} else
		currentDiv.innerHTML = '';

	//radio buttons

	if (form.elements['returnradio'][0].checked) {
		currentDiv = document.getElementById('divOneWay');
		currentDiv.className = 'divRadioOn';
		currentDiv.innerHTML = 'X';
		currentDiv = document.getElementById('divReturn');
		currentDiv.className = 'divRadioOn';
		currentDiv.innerHTML = '';
	} else
		if (form.elements['returnradio'][1].checked) {
			currentDiv = document.getElementById('divOneWay');
			currentDiv.className = 'divRadioOn';
			currentDiv.innerHTML = '';
			currentDiv = document.getElementById('divReturn');
			currentDiv.className = 'divRadioOn';
			currentDiv.innerHTML = 'X';
		}
}

function onBodyLoad() {
	var form = document.forms['form_search'];
	var query = getCookie('query');
	var queryElem;

	if (query != null) {
		queryElem = form.elements['query'];
		queryElem.value = query;
	}

	if (cityIndex && location.href.indexOf('#offices') < 0) {
		location.href = '#offices';
	}
	return false;
}

function onPrintableBodyLoad() {
	var printContentForMeasuring = document.getElementById('divContentForMeasuring');
	var printContentForShowing = document.getElementById('divContentForShowing');
	var divShield = document.getElementById('divShield');
	var divPrintButton = document.getElementById('divPrintButton');
	var printPage = document.getElementById('divPage');
	var url = document.location.href;
	url = url.toLowerCase();

	if (url.indexOf('print=true') > 0) {
		//print popup
		var parentPageContent = null;
		//if ((url.indexOf('faq_popup.html') > 0)) {
		//	parentPageContent = printContentForShowing;
		//} else {
			parentPageContent = opener.document.getElementById('centerContentDiv');
		//}
		if (parentPageContent != null) {

			printContentForMeasuring.innerHTML = parentPageContent.innerHTML;
			if (url.indexOf('shield=true') > 0) {
				printContentForShowing.innerHTML = '<div id="divContent" style="z-index:10">' + parentPageContent.innerHTML + '</div><div id="divShield2" style="position:absolute;top:140px;width:100%;z-index:50;background:url(/images/common/empty1x1.gif)"></div>';
				setDivHeight('divShield2', getDivHeight('divContent'));

			} else {
				printContentForShowing.innerHTML = parentPageContent.innerHTML;
			}


			hideDivsOnPrintPage();
			divPrintButton.style.visibility = "visible";
			setDivHeight('divShield', getDivHeight('divPage'));

			printContentForMeasuring.innerHTML = "";
			hideDivsOnPrintPage();
			printContentForShowing.style.visibility = "visible";
			printPage.style.visibility = "hidden";
		}
	}
	if (isPrintButtonVisible == true) {
		divPrintButton.style.visibility = "visible";
	}
	printContentForShowing.style.visibility = "visible";

	showDivsOnPrintPage();
	return false;
}

function showDivsOnPrintPage() {
	var forPrintUpper = document.getElementById('forPrintDivBot');
	if (forPrintUpper != null) {
		forPrintUpper.style.display = "block";
		forPrintUpper.style.visibility = "visible";
	}
}

function hideDivsOnPrintPage() {
	var notForPrintUpper = document.getElementById('notForPrintDivUpper');
	if (notForPrintUpper != null) {
		notForPrintUpper.style.display = "none";
	}
	var notForPrintLower = document.getElementById('notForPrintDivLower');
	if (notForPrintLower != null) {
		notForPrintLower.style.display = "none";
	}
	//hiding additional divs
	var i = 1;
	while (true) {
		var divName = "notForPrintDiv_" + i;
		var objDiv = document.getElementById(divName);
		if (objDiv != null) {
			objDiv.style.display = "none";
		} else {
			break;
		}
		i++;
	}
}

function getFixURL(url) {
	var fixURL = '';
	if (url.indexOf(":") != -1 && url.indexOf(":") < 11) {
		fixURL = url;
	} else {
		fixURL = rootPath + url;
	}

	return fixURL;
}

function getDivHeight(divName) {
	if (is_ie) {
		return document.all[divName].offsetHeight;
	} else {
		return document.getElementById(divName).offsetHeight;
	}
}

function setDivHeight(divName, h) {
	if (is_ie) {
		document.all[divName].style.height = h + "px";
		document.all[divName].style.visibility = "visible";
	} else {
		document.getElementById(divName).style.height = h;
		document.getElementById(divName).style.visibility = "visible";
	}
}

// Open Calendar
var oc = null;
function openCalendar(url, day, month, year) {
	if (!is_opera5) {
		var form = getActiveFormName();
		var popup = "width=230,height=167,status=no,scrollbars=no,toolbar=no,menubar=no,location=no,resizable=no";
		if (!is_opera8) {
			if (oc != null && !oc.closed) oc.close();
		}
		oc = window.open(url + '?form=' + form + '&day=' + day + '&month=' + month + '&year=' + year, 'viewCalendar', popup);
		oc.focus();
	}
}

// Set Home
function setHome(obj, url) {
	if (document.all) {
		obj.style.behavior = 'url(#default#homepage)';
		obj.setHomePage(url);
		return false;
	}

	return true;
}

function getValueFromQuery(name) {
	if (!name)return;
	var pairs = document.location.href.slice(document.location.href.indexOf("?") + 1, document.location.href.length);
	pairs = unescape(pairs).split("&");
	for (var i = 0; i < pairs.length; i++)
		if (pairs[i].split("=")[0] == name) return pairs[i].split("=")[1];

	return "";
}

function printPage() {
	if (!isPrintButtonClicked) {
		if (is_opera && !is_opera7) {
			alert(badBrowser);
		} else {
			isPrintButtonClicked = true;
			setTimeout("isPrintButtonClicked = false", 7000);
			temporaryHideDiv("divPrintButton", 7000);
			window.print();
		}
	}
	return false;
}

function temporaryHideDiv(strDivName, intTime) {
	var objDivToHide = document.getElementById(strDivName)
	if (objDivToHide != null) {
		objDivToHide.style.visibility = 'hidden';
		setTimeout("document.getElementById('" + strDivName + "').style.visibility='visible';", intTime);
	}
}

// Business Lounge
function openHall(id, name) {
	var oh = window.open(langPath + 'about_us/image.html?id=' + id + '&name=' + name, 'viewHall', 'resizable=no,menubar=no,status=no,scrollbars=no,width=524,height=610');
	oh.focus();
	return false;
}

function selectHall(id, flag, name) {
	if (document.images) {
		eval('document.hall' + id + '.src = "' + rootPath + 'images/hall/' + name + '/' + id + '_small' + flag + '.jpg"');
		if (flag != "_on") id = 0;
		eval('document.text.src = "' + langPath + 'images/hall/' + name + '/' + id + '_text.gif"');
	}
}

function loadHallImages() {
	if (!document.images)
		return;
	for (var i = 0; i < imgHallArray.length; i++) {
		var img = new Image();
		img.src = imgHallArray[i];
		imgHallLoadedArray[i] = img;
	}
}

//set time at status bar
function tick() {
	var t = new Date();
	t.setTime(t.getTime() + (t.getTimezoneOffset() + 60) * 60000);
	var precision = 1;
	var yr = t.getFullYear();
	var mo = t.getMonth() + 1;
	var day = t.getDate();

	var b = (Math.floor((t.getHours() * 3600 + t.getMinutes() * 60 + t.getSeconds()) / .864) / 100).toFixed(2);

	var s = b.toString();
	if (b < 100) s = "0" + s;
	if (b < 10)  s = "0" + s;

	var d = s.indexOf(".");
	if (d > 0) s = s.substr(0, precision > 0 ? d + precision + 1 : d);
	return s;
}

function formatTime(hours, min, lang) {
	var time;
	if (min.toString().length == 1) {
		min = "0" + min;
	}
	if (hours >= 24) {
		hours = hours - 24;
	}
	if (hours < 0) {
		hours = hours + 24;
	}
	if (lang == 'en') {
		if (hours > 12) {
			time = (hours - 12) + ":" + min + " PM";
		} else {
			time = hours + ":" + min + " AM";
		}
	} else {
		time = hours + ":" + min;
	}

	return time;
}

function setTime(serverMinutes, serverHours, iNetTime, timeZone, lang) {
	// switch between summer/winter time migrated to .NET side
	var gmtHours = serverHours - timeZone / 60;
	var mowTime = formatTime(gmtHours + 3, serverMinutes, lang);
	var gmtTime = formatTime(gmtHours, serverMinutes, lang);
	var iktTime = formatTime(gmtHours + 8, serverMinutes, lang);
	var ovbTime = formatTime(gmtHours + 6, serverMinutes, lang);
	var strTime = "GMT " + gmtTime + "      MOW " + mowTime + "      OVB " + ovbTime + "      IKT " + iktTime + "    Internet Time @" + iNetTime + " beats";
	window.status = strTime;
}

function increaseTime() {
	serverMinutes = parseInt(serverMinutes) + 1;
	if (serverMinutes > 59) {
		serverMinutes = 0;
		serverHours = parseInt(serverHours) + 1;
	}
	if (serverHours == 24) {
		serverHours = 0;
	}
	setTime(serverMinutes, serverHours, tick(), timeZone, lang);
}

function countSymbols(form, elemNum) {		
	var textArea = $("form *[name='"+elemNum+"']");

	//inputStr = form.elements[elemNum].value;
        inputStr = textArea.val();
	strlength = inputStr.length;
	if (strlength > maxLen) {
		//form.elements[elemNum].value = inputStr.substring(0, maxLen - 1);
		$textArea.val( inputStr.substring(0, maxLen - 1) );
		alert(maxSymbolAlert);
	}	
	
	counterElement = document.getElementById(elemNum+'Num');	
//	counterElement.value = (maxLen - form.elements[elemNum].value.length);	
	counterElement.value = (maxLen - textArea.val().length);	

//	numsim = maxLen - form.elements[elemNum].value.length;
	numsim = maxLen - textArea.val().length;
	                                         	
	if (numsim >= 0) {
		counterElement.value=numsim;
	} else {
		counterElement.value=0;
	}
}

function resizeVote() {
	if (getCookie("showVoteDiv") == 'false') {
		document.getElementById("vote").style.visibility = "hidden";
		return;
	} else {
		document.getElementById("vote").style.visibility = "visible";
	}

	objVote = document.getElementById("vote");
	objShield = document.getElementById("voteShield");
	objIframe = document.getElementById("voteIframe");

	pageWidth = document.body.offsetWidth;
	x = (pageWidth - 335) / 2;
	objVote.style.left = x;

	if (is_ie) {
		objShield.style.left = x;
		objIframe.style.height = objVote.offsetHeight;
	}
}

function closeVote() {
	document.getElementById("vote").style.visibility = "hidden";
	if (is_ie) document.getElementById("voteShield").style.visibility = "hidden";
}


function resizeFlash() {
	var flashWidth = 442;
	var flashHeight = 340;
	var pageWidth;
	var pageHeight;

	//if (getCookie("showRichMedia") != "false") {
	document.getElementById("flash").style.visibility = "visible";
	//}

		pageWidth = document.body.offsetWidth;
		pageHeight = document.body.offsetHeight;
		x = (pageWidth - flashWidth) / 2;
		y = (pageHeight - flashHeight) / 2;
		document.getElementById("flash").style.left = x;
		document.getElementById("flash").style.top = "180";
	}

function closeFlash() {
	document.getElementById("flash").style.visibility = "hidden";
	//setCookie("showRichMedia", "false", false, MILLIS_IN_YEAR);
}

function toggleWeatherLayer(switchOffLayer, switchOnLayer) {
	if (document.getElementById) {
		// this is the way the standards work
		document.getElementById(switchOffLayer).style.display = "none";
		document.getElementById(switchOnLayer).style.display = "block";
	} else if (document.all) {
		// this is the way old msie versions work
		document.all[switchOffLayer].style.display = "none";
		document.all[switchOnLayer].style.display = "block";
	} else if (document.layers) {
		// this is the way nn4 works
		document.layers[switchOffLayer].style.display = "none";
		document.layers[switchOnLayer].style.display = "block";
	}
}

function fullTextSearchCall(query, page) {
    document.getElementById('fullTextSearchFormQuery').value=query;
    document.getElementById('fullTextSearchFormPage').value=page;
    document.fullTextSearchForm.submit();
}


function decodeHex(hexstr) {
        var string = "";
        var i = 0;

        while ( i < hexstr.length/2 ) {
            var h = parseInt("0x"+hexstr.substr(i*2,2));
            
            if (h < 128) {
                string += String.fromCharCode(h);
                i++;
            }
            else if((h > 191) && (h < 224)) {
                var h2 = parseInt("0x"+hexstr.substr(i*2+2,2));
                string += String.fromCharCode(((h & 31) << 6) | (h2 & 63));
                i += 2;
            }
            else {
                var h2 = parseInt("0x"+hexstr.substr(i*2+2,2));
                var h3 = parseInt("0x"+hexstr.substr(i*2+4,2));
                string += String.fromCharCode(((h & 15) << 12) | ((h2 & 63) << 6) | (h3 & 63));
                i += 3;
            }
        }

        return string;
    }
