﻿var returnUrl = "";
var baseDomain = "http://"+window.location.hostname;
function wopen(url, name, w, h){w += 32;h += 96;wleft = (screen.width - w) / 2;wtop = (screen.height - h) / 2;var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' + 'left=' + wleft + ', top=' + wtop + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=no, resizable=no');win.resizeTo(w, h); win.moveTo(wleft, wtop);win.focus();}
function wopensc(url, name, w, h){w += 32;h += 96;wleft = (screen.width - w) / 2;wtop = (screen.height - h) / 2;var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' + 'left=' + wleft + ', top=' + wtop + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=yes, resizable=no');win.resizeTo(w, h); win.moveTo(wleft, wtop);win.focus();}
function redirect(url) { var version = parseInt(navigator.appVersion); if (version>=4 || window.location.replace) { window.location.replace(url); } else { window.location.href = url; }}
function n(url) { window.location = url; }
function sKey() {var keycode; if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which; else return true; if (keycode == 13){doSearch();return false;}else return true;}
function doSearch() { var txtSearch = document.getElementById("txtSearch"); if (txtSearch.value.length >= 3) {changeObjectVisibility('dSearch','hidden'); changeObjectVisibility('dSProgress','visible'); window.location.href = "/search/?q=" + encodeURIComponent(txtSearch.value); }}
function doSignup() { txtPasswordwindow.location.href = "/signup/?a=" + encodeURIComponent(txtEmail.value);}
function sLogin(e) {var keycode;var keychar;var numcheck;if(window.event) {keycode = e.keyCode;}else if(e.which) {keycode = e.which;} else { return true; }if (keycode == 13){doLogin();return false;}else return true;}
function getValue(obj) { if (obj != null) { return obj.options[obj.selectedIndex].value;}}
function redirect(url) { var version = parseInt(navigator.appVersion); if (version>=4 || window.location.replace) { window.location.replace(url); } else { window.location.href = url; }}
function getStyleObject(objectId) { if(document.getElementById && document.getElementById(objectId)) { return document.getElementById(objectId).style; } else if (document.all && document.all(objectId)) {return document.all(objectId).style; } else if (document.layers && document.layers[objectId]) {return document.layers[objectId]; } else { return false; }}
function changeObjectVisibility(objectId, newVisibility) { var styleObject = getStyleObject(objectId); if(styleObject) { styleObject.visibility = newVisibility; if (newVisibility == "visible") { styleObject.display = 'block'; } else { styleObject.display = 'none'; }return true; } else { return false; }}
function Disable(obj) {try { obj.disabled = true; } catch (exception) { }}
function Enable(obj) {try { obj.disabled = false; } catch (exception) { }}

function doLogin() { 
var txtUser = $("#txtUserName").val(); 
var txtPassword = $("#txtPassword").val();
if ((txtUser.length >= 2) && (txtPassword.length >= 2)) {
changeObjectVisibility('lmsg', 'visible');
changeObjectVisibility('ctl00_loginInfo', 'hidden');
$.get(uncache(baseDomain + '/authenticate/?u=' + encodeURIComponent(txtUser) + '&p=' + encodeURIComponent(txtPassword)), function(data) { doAuth(data);});
}
}

function doAuth(r){changeObjectVisibility('lmsg', 'hidden');changeObjectVisibility('ctl00_loginInfo', 'visible');
if (r != 'no_auth') 
{ changeObjectVisibility('lmsg', 'visible');
changeObjectVisibility('ctl00_loginInfo', 'hidden');
redirect(baseDomain + '/authenticate/?at=' + r + '&ru=' + returnUrl); } 
else { alert('The e-mail address or password you entered is not valid. Please try again.');}}

function eventReady() {var r = this.req.responseText; }
function hI(blockID, itemID, itemsCount) { if (itemID > itemsCount) itemID = 1;if (itemID == 0) itemID = itemsCount;$("#" + blockID +" ul li").removeClass("highlight").addClass("ord");$("#" + blockID +" ul li." + itemID).removeClass("ord").addClass("highlight");}

function clock(offset) {if (!document.layers && !document.all) {return;}
d = new Date();utc = d.getTime() + (d.getTimezoneOffset() * 60000);  
nd = new Date(utc + (3600000*2));
var hours = nd.getHours();var minutes = nd.getMinutes();var seconds = nd.getSeconds();
if (hours == 0) {hours = 12;}if (hours <= 9) {hours = "0" + hours;}if (minutes <= 9) {minutes = "0" + minutes;}
if (seconds <= 9) {seconds = "0" + seconds;}movingtime = hours + ":" + minutes + ":" + seconds;
if (document.layers) {document.layers.clocklayer.document.write(movingtime);document.layers.clocklayer.document.close();}
else if (document.all) {clocklayer.innerHTML = movingtime;}setTimeout("clock()", 1000)}

function addToFavorite( linkUrl, linkTitle ) {if ( !document.all ) alert( "Please press Ctrl-D to set it!" );else external.AddFavorite( linkUrl, linkTitle );}
function uncache(url){var d = new Date();var time = d.getTime();return url + '&uct='+time;}
function printPage() {window.print();}
function sendPage(url) {wopen ('/sendpage?url=' + encodeURIComponent(window.location), 'Send_page', 430, 340);}
function HomePage() { if ( ! document.all ) { alert("This function doesn't work under Mozilla Browsers - Netscape or FireFox! \n\nPlease set it at:\n\tEdit/Preferences/Navigator \nmanualy!"); } else { newHomepage.style.behavior='url(#default#homepage)';newHomepage.setHomePage('http://xpatathens.com'); } }
function textCounter(o, maxlimit) { var charsleft = (maxlimit - o.value.length); document.getElementById('charsleft').innerHTML = charsleft; if (charsleft <= 0) { o.value = o.value.substring(0, maxlimit); }}
function Comment(a) { returnUrl = window.location; changeObjectVisibility('commentPosted', 'hidden'); if (a != 0) { changeObjectVisibility('divComment', 'visible'); } else { changeObjectVisibility('divComment', 'hidden'); } }
function PostComment(rel) { Disable(document.getElementById('divComment'));
$.get(baseDomain + "/postcomment/", { rel:rel, txt:document.getElementById('comment').value }, function(data) { onComment(data); });}
function onComment(data) { Enable(document.getElementById('divComment')); document.getElementById('comment').value = ""; changeObjectVisibility('divComment', 'hidden'); changeObjectVisibility('commentPosted', 'visible'); document.getElementById('charsleft').innerHTML = "2000";}


if (typeof jQuery != 'undefined') {
$(document).ready(function() {
$(".itemsbox").addClass("itemsboxdefault");
$(".itemsbox").hover(function() {$(this).removeClass("itemsboxdefault").addClass("itemsboxhover"); }, function()  { $(this).removeClass("itemsboxhover").addClass("itemsboxdefault"); });

if ($("#txtSearch").val() == '') { $("#txtSearch").val('Search XpatAthens'); }
$("#txtSearch").focus(function() { if ($(this).val() == 'Search XpatAthens') { $(this).val(''); } });
$("#txtSearch").blur(function() { if ($(this).val() == '') { $(this).val('Search XpatAthens'); } });
$("#txtSearch").attr("title","Press Enter to Search");

$("#txtSearch").keypress(function (e) { if (e.which == 13) { n('/search/?q=' + encodeURIComponent($("#txtSearch").val())); return false; } });

});

}
