﻿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 eventReady() {var r = this.req.responseText; }
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://xpatloop.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'));
$.post(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";}

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");}

$(document).ready(function() {

try { 
$('#clocklayer').jclock();
} catch (e) { }


$(".itemsbox").addClass("itemsboxdefault");
$(".itemsbox").hover(function() {$(this).removeClass("itemsboxdefault").addClass("itemsboxhover"); }, function()  { $(this).removeClass("itemsboxhover").addClass("itemsboxdefault"); });

$("#txtSearch").focus(function() {if ($("#txtSearch").val() == "Search XpatLoop.com Here") { $("#txtSearch").val('');} });
$("#txtSearch").blur(function() {if ($("#txtSearch").val().length <= 1) { $("#txtSearch").val('Search XpatLoop.com Here');} });

$("#txtLogin").focus(function() {if ($("#txtLogin").val() == "E-mail") { $("#txtLogin").val('');} });
$("#txtLogin").blur(function() {if ($("#txtLogin").val().length <= 1) { $("#txtLogin").val('E-mail');} });

$("#txtPassword").focus(function() {$("#txtPassword").hide();$("#txtPass").show().focus();});
$("#txtPass").blur(function() {
$("#txtPass").hide();$("#txtPassword").show();
 });

$("#txtSearch").keypress(function (e) {if (e.which == 13) {
if ($("#txtSearch").val().length >= 3) { 
n('/search/?q=' + encodeURIComponent($("#txtSearch").val()));return false;
}
}
});
$("#txtLogin").keypress(function (e) {if (e.which == 13) { doLogin(); return false;}});
$("#txtPass").keypress(function (e) {if (e.which == 13) { doLogin(); return false;}});

$("#login").click(function() { $(".tnstuff").hide();$("#tnlogin").show();});
$("#loginClose").click(function() { $(".tnlogin").hide();$("#tnstuff").show();});
});

function doLogin() { var txtUser = $("#txtLogin").val(); var txtPassword =  $("#txtPass").val();if ((txtUser.length >= 2) && (txtPassword.length >= 2))  {$("#tnlogin").hide();$("#authprocess").show();$.get(baseDomain + '/authenticate/', {u:txtUser, p:txtPassword}, function(data)  { doAuth(data);});}}
function doAuth(data){$("#authprocess").hide();$("#tnlogin").show();var r = data;if (r != 'no_auth') { $("#tnlogin").hide();$("#authprocess").show();redirect(baseDomain + '/authenticate/?at=' + r + '&ru=' + returnUrl); } else { alert('The e-mail address or password you entered is not valid. Please try again.');}}
