function getNumericalInput(elementId) {
var el = $(elementId);
if (el != null) {
var numString = $F(el);
numString = numString.replace(/,/g, "");
numString = numString.replace(/,/g, "");
return parseInt(numString);
}
return null;
}
function disableAllForms(allowedForm) {
$$('form').each(function(form) {
if (form != allowedForm) {
form.disable();
}
});
}
function showPasswordInput() {
$("j_password_label").hide();
$("j_password").show();
$("j_password").focus();
}
function hideEmptyPasswordInput() {
if($F("j_password") == ""){
$("j_password_label").show();
$("j_password").hide();
}
}
function submitLoginForm(form) {
$("j_password_label").hide();
$("j_password").show();
disableAllForms(form);
}
function checkSignupForm(form) {
if ($F("name") == "") {
showAlert("Please enter a username");
return false;
}
if ($F("email") == "") {
showAlert("Please enter your email");
return false;
}
if ($F("password") == "") {
showAlert("Please enter a password");
return false;
}
return true;
}
/**
* highlight the list element with the given id in the main navigation
*/
function highLightMainNavigation(id) {
var e = $(id);
if (e) {
e.addClassName("active");
} else {
alert("can not hightlight main navigation with id " + id );
}
}
var currentTab;
function highLightTab(id) {
if (currentTab) {
deLightTab(currentTab);
}
var e = $(id);
if (e) {
e.addClassName("active");
} else {
alert("can not hightlight tab with id " + id );
}
currentTab = id;
}
function deLightTab(id) {
$(id).removeClassName("active");
}
function setVisible(id, state) {
if (state) {
Element.show(id);
} else {
Element.hide(id);
}
}
function getPreloaderHTML (id) {
var e = $(id);
var leftMargin = 0;
var topMargin = 0;
if (e) {
var w = $(e).getStyle('width');
var h = $(e).getStyle('height');
if (w && h) {
var strip=/[px]/gi;
leftMargin = w.replace(strip,'')/2 - 16;
topMargin = h.replace(strip,'')/2 - 16;
}
}
return new Element('img', { src: "/images/loading.gif",style:"margin-top: "+topMargin+"px; margin-left:"+leftMargin+"px;" } )
}
var ajaxCallbacks = { }; // targetId => callback
var ajaxRequests = { }; // targetId => request
function ajaxNoContent(method, page, targetid, params, callback) {
abortAjaxRequest(targetid);
var listener = function (result) {
req = ajaxRequests[targetid];
// check that it hasn't already been removed
if (req) {
if (result.responseText != null && result.responseText.indexOf("") >= 0 && result.responseText.indexOf("") < result.responseText.indexOf("
") ) {
dwrErrorHandler("Your login session has expired");
} else {
cb = ajaxCallbacks[targetid];
removeAjaxRequest(targetid);
if (cb) {
cb(result);
}
}
}
};
request = new Ajax.Request(getCacheBuster(getAbsoluteRequest(page)), {
method :method,
parameters :params,
onComplete :listener,
onFailure : dwrErrorHandler
});
ajaxRequests[targetid] = request;
ajaxCallbacks[targetid] = callback;
}
function ajaxContent(method, page, targetid, params, callback) {
Element.update(targetid,getPreloaderHTML(targetid));
abortAjaxRequest(targetid);
var listener = function (result) {
req = ajaxRequests[targetid];
// check that it hasn't already been removed
if (req) {
if (result.responseText != null && result.responseText.indexOf("") >= 0 && result.responseText.indexOf("") < result.responseText.indexOf("") ) {
dwrErrorHandler("Your login session has expired");
Element.update(targetid, "");
} else {
cb = ajaxCallbacks[targetid];
removeAjaxRequest(targetid);
Element.update(targetid, result.responseText);
if (cb) {
cb(result);
}
}
}
};
request = new Ajax.Request(getCacheBuster(getAbsoluteRequest(page)), {
method :method,
parameters :params,
onComplete :listener,
onFailure : dwrErrorHandler
});
ajaxRequests[targetid] = request;
ajaxCallbacks[targetid] = callback;
}
function abortAjaxRequest(t) {
if (ajaxRequests[t]) {
abortAndRemoveAjaxRequest(t);
}
}
function abortAndRemoveAjaxRequest(t) {
var r = ajaxRequests[t];
removeAjaxRequest(t);
r.transport.abort();
}
function removeAjaxRequest(t) {
delete ajaxRequests[t];
delete ajaxCallbacks[t];
}
/**
* update html within a page - uses post to avoid ie7 get caching
* please check your controller if it maps POST
*
* @param page
* @param targetid
* @param params
* @param callback
*/
function updateContent(page, targetid, params, callback) {
ajaxContent("post", page, targetid, params, callback);
}
/**
* update html within a page - uses get - use this method if you load static html
*
* @param page
* @param targetid
* @param params
* @param callback
*/
function getContent(page, targetid, params, callback) {
ajaxContent("get", page, targetid, params, callback);
}
function blueOverlayVisible(b,callback) {
if (b) {
if (callback) {
$('popup_box_overlay').observe('click', callback);
}
var dimensions = getPageSize();
$('popup_box_overlay').setStyle({ width: dimensions[0] + 'px', height: dimensions[1] + 'px' });
Element.show("popup_box_overlay");
} else {
Element.hide("popup_box_overlay");
}
}
function getPageSize() {
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = window.innerWidth + window.scrollMaxX;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
if(document.documentElement.clientWidth){
windowWidth = document.documentElement.clientWidth;
} else {
windowWidth = self.innerWidth;
}
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = xScroll;
} else {
pageWidth = windowWidth;
}
return [pageWidth,pageHeight];
}
/******************************************************************************
* generic popup code
******************************************************************************/
var showGenericPopup_popup;
function showGenericPopup(html, title) {
blueOverlayVisible(true,hideGenericPopup);
if (title == undefined || title == null) {
title = "";
}
var s = "";
s += "";
showGenericPopup_popup = new Element('div').update(s);
$('popup_box_overlay').insert({before: showGenericPopup_popup});
var popupHeight = -showGenericPopup_popup.getHeight() /2 ;
showGenericPopup_popup.setStyle({ marginTop: popupHeight+'px'});
}
function showGenericPopupWithNoChrome(html) {
blueOverlayVisible(true, hideGenericPopup);
showGenericPopup_popup = new Element('div').update("");
$('popup_box_overlay').insert({before: showGenericPopup_popup});
var popupHeight = -showGenericPopup_popup.getHeight() /2 ;
showGenericPopup_popup.setStyle({ marginTop: popupHeight+'px'});
}
function hideGenericPopup() {
if (showGenericPopup_popup != null) {
if (showGenericPopup_popup.parentNode != null) {
Element.remove(showGenericPopup_popup);
}
showGenericPopup_popup = null;
}
blueOverlayVisible(false);
}
/******************************************************************************
* manager popup code
******************************************************************************/
var showManagerDetailsPopup_popup;
function showManagerDetailsPopup(userid) {
blueOverlayVisible(true,closeManagerDetailsPopup);
ajaxNoContent("get", "/login/user_info_popup.htm", "user_info_popup", { id : userid }, onShowManagerDetailsPopup);
}
function onShowManagerDetailsPopup(result) {
showManagerDetailsPopup_popup = new Element('div').update("");
$('popup_box_overlay').insert({before: showManagerDetailsPopup_popup});
var popupHeight = -showManagerDetailsPopup_popup.getHeight() /2 ;
showManagerDetailsPopup_popup.setStyle({ marginTop: popupHeight+'px'});
}
function closeManagerDetailsPopup(result) {
Element.remove(showManagerDetailsPopup_popup);
blueOverlayVisible(false);
}
/******************************************************************************
* equipment popup code (used for cards, equipment, and bling)
******************************************************************************/
var showEquipmentDetailsPopup_popup;
function showEquipmentDetailsPopup(equipmentid, ioid, tradeid) {
blueOverlayVisible(true,closeEquipmentDetailsPopup);
ajaxNoContent("get", "/login/equipment_info_popup.htm", "equipment_info_popup", { itemId : equipmentid, ioId: ioid, tradeId: tradeid }, onShowEquipmentDetailsPopup);
}
function onShowEquipmentDetailsPopup(result) {
showEquipmentDetailsPopup_popup = new Element('div').update("");
$('popup_box_overlay').insert({before: showEquipmentDetailsPopup_popup});
var popupHeight = -showEquipmentDetailsPopup_popup.getHeight() /2 ;
showEquipmentDetailsPopup_popup.setStyle({ marginTop: popupHeight+'px'});
}
function closeEquipmentDetailsPopup(result) {
Element.remove(showEquipmentDetailsPopup_popup);
blueOverlayVisible(false);
}
var buyItemFromShopId = 0;
var buyItemFromTradeId = 0;
function buyItemFromShop(iditem) {
buyItemFromShopId = iditem;
showConfirmationPopup("Are you sure you wish to buy this item?", yesBuyItemFromShop, onBuyItemCancelled);
}
function yesBuyItemFromShop() {
var iditem = buyItemFromShopId;
var quantity = $F("stock_" + iditem + "_quantity");
if (quantity == 1) {
AjaxManager.buyItemFromShop(iditem, { callback: onBuyItemBought } );
} else if (quantity > 1) {
AjaxManager.buyItemsFromShop(iditem, quantity, { callback: onBuyItemBought } );
}
}
function buyItemFromTrade(idtrade) {
buyItemFromTradeId = idtrade;
showConfirmationPopup("Are you sure you wish to buy this item?", yesBuyItemFromTrade, onBuyItemCancelled);
}
function yesBuyItemFromTrade() {
var idtrade = buyItemFromTradeId;
AjaxManager.buyTrade(idtrade, { callback: onBuyItemBought } );
}
function onBuyItemBought() {
window.location.reload();
}
function onBuyItemCancelled() {
blueOverlayVisible(true,closeEquipmentDetailsPopup);
}
/******************************************************************************
* player popup code
******************************************************************************/
var showPlayerDetailsPopup_popup;
function showPlayerDetailsPopup(playerid) {
blueOverlayVisible(true,closePlayerDetailsPopup);
ajaxNoContent("get", "/login/player_info_popup.htm", "player_info_popup", { id : playerid }, onShowPlayerDetailsPopup);
}
function onShowPlayerDetailsPopup(result) {
showPlayerDetailsPopup_popup = new Element('div').update("");
$('popup_box_overlay').insert({before: showPlayerDetailsPopup_popup});
var popupHeight = -showPlayerDetailsPopup_popup.getHeight() /2 ;
showPlayerDetailsPopup_popup.setStyle({ marginTop: popupHeight+'px'});
}
function closePlayerDetailsPopup(result) {
Element.remove(showPlayerDetailsPopup_popup);
blueOverlayVisible(false);
}
/******************************************************************************
* sell popup code (used for both player equipment, and players)
******************************************************************************/
var sellPopup_popup;
function showSellPopup(itemOwnedId, url) {
blueOverlayVisible(true,closeSellPopup);
ajaxNoContent("get", url, "sell_item_popup", { id : itemOwnedId }, onShowSellPopup);
}
function onShowSellPopup(result) {
sellPopup_popup = new Element('div').update("");
$('popup_box_overlay').insert( { before: sellPopup_popup } );
var popupHeight = -sellPopup_popup.getHeight() / 2;
sellPopup_popup.setStyle( { marginTop: popupHeight + 'px' } );
}
function closeSellPopup(result) {
Element.remove(sellPopup_popup);
blueOverlayVisible(false);
}
/******************************************************************************
* confirmation popup code
******************************************************************************/
var g_okCallback = null;
var g_cancelCallback = null;
function showSimpleConfirmationPopup(message, okCallback) {
g_okCallback = okCallback;
var s = "";
s += "
";
s += "";
s += message;
s += "
";
s += "";
showGenericPopup(s);
}
function showConfirmationPopup(message, okCallback, cancelCallback) {
g_okCallback = okCallback;
g_cancelCallback = cancelCallback;
var s = "";
s += "";
s += "";
s += message;
s += "
";
s += "";
showGenericPopup(s);
}
function onConfirmationPopupOK() {
hideGenericPopup();
if (g_okCallback) {
g_okCallback();
g_okCallback = null;
}
}
function onConfirmationPopupCancel() {
hideGenericPopup();
if (g_cancelCallback) {
g_cancelCallback();
g_cancelCallback = null;
}
}
/******************************************************************************
* alert popup code
******************************************************************************/
var showAlert_popup;
function showAlert(message) {
if (showGenericPopup_popup) {
hideGenericPopup();
}
blueOverlayVisible(true,closeAlert);
var s = "";
s += "";
showAlert_popup = new Element('div').update("");
$('popup_box_overlay').insert({before: showAlert_popup});
var popupHeight = -showAlert_popup.getHeight() /2 ;
showAlert_popup.setStyle({ marginTop: popupHeight+'px'});
}
function closeAlert() {
Element.remove(showAlert_popup);
blueOverlayVisible(false);
}
/******************************************************************************
* user info box code
******************************************************************************/
function toggleMatchStatus(state) {
if (state) {
AjaxManager.setAvailableForMatches(state, {callback: onSetAvailable });
} else {
AjaxManager.setAvailableForMatches(state, {callback: onSetUnavailable });
}
}
function onSetAvailable() {
if (Namespace.Exists("ManagerOverviewPage")) {
ManagerOverviewPage.onSetStatusAvailable();
}
updateUserInfoBox();
}
function onSetUnavailable() {
updateUserInfoBox();
}
function updateUserInfoBox() {
updateContent("/login/user_info_box.htm", "user_info_box", {});
}
/******************************************************************************
* validation code
******************************************************************************/
function showUnvalidatedPopup() {
//showAlert("unvalidated : resend");
if (showGenericPopup_popup) {
hideGenericPopup();
}
blueOverlayVisible(true,closeAlert);
var s = "";
s+="";
s+="
";
s+="
Please wait - If you can see this message after the page has loaded you might need to upgrade your Flash Player";
s+="
";
s+="
";
s+="";
showAlert_popup = new Element('div').update("");
$('popup_box_overlay').insert({before: showAlert_popup});
var popupHeight = -showAlert_popup.getHeight() /2 ;
showAlert_popup.setStyle({ marginTop: popupHeight+'px'});
var validation = new SWFObject("/swf/validation.swf", "validation", "527", "282", "9.0.0","#FFFFFF");
validation.addVariable("clickthrough", "http://www.google.com");
validation.addParam("wmode", "transparent");
validation.write("swf_validation");
}
function resendValidationMail() {
closeAlert();
AjaxManager.resendValidationCodeForCurrentUser();
showSimpleConfirmationPopup("Validation mail sent, check you email and click on the link to validate your account",null);
}
/******************************************************************************
* general page initMethods
******************************************************************************/
var Namespace = {
Register : function(_Name) {
var chk = false;
var cob = "";
var spc = _Name.split(".");
for ( var i = 0; i < spc.length; i++) {
if (cob != "") {
cob += ".";
}
cob += spc[i];
chk = this.Exists(cob);
if (!chk) {
this.Create(cob);
}
}
if (chk) {
throw "Namespace: " + _Name + " is already defined.";
}
},
Create : function(_Src) {
eval("window." + _Src + " = new Object();");
},
Exists : function(_Src) {
eval("var NE = false; try{if(" + _Src
+ "){NE = true;}else{NE = false;}}catch(err){NE=false;}");
return NE;
},
Load : function(_name,_callback) {
var script = new Element('script', {'type':'text/javascript', 'src':'/js/'+_name+'.djs'});
if (_callback != null && _callback != undefined) {
var scriptCallback = _callback;
Event.observe(script, 'load', function() {
if (scriptCallback != undefined && scriptCallback != null) { scriptCallback(); scriptCallback = null; };
});
script.onreadystatechange = function () {
if (script.readyState != "loaded" && script.readyState != "complete" && script.readyState != 4) {
return;
}
if (scriptCallback != undefined && scriptCallback != null) { scriptCallback(); scriptCallback = null; };
}
}
$$('head')[0].appendChild(script);
}
}
function dwrErrorHandler(msg) {
showAlert(msg);
}
dwr.engine.setErrorHandler(dwrErrorHandler);
// also change in applicationContext-dwr.xml if you change this value
// dwr.engine.setActiveReverseAjax(true);