processKeyPress = function(e, myProfileActionButton) {
	var keynum;
	if(window.event) { // IE
		keynum = e.keyCode;
	} else if(e.which) { // Netscape/Firefox/Opera
		keynum = e.which;
	}		
	if (keynum == 13) {
		myProfileActionButton.jq.trigger('click');
		return false;
	}
	
	return true;
};

function unescapePlus(str) { 
      return unescape(str).replace(/\+/g, ' '); 
}

PlayerClub = {
	userName : '',
	token : '',
	
	onPlaySuccess : function(game , info) {
		var order = info;
		if (jQuery('input[name*=play_param_url]').val().indexOf('json') == -1) {
			var json = jQuery.xml2json(order);
			if (typeof(json.items.length) == 'undefined') {
				var tmp = json.items.item;
				json.items = [tmp];
			}
			order = json;
		}
		refreshLogin();
		gapWrapper.play(game, order);
	},
	
	playCoupon : function(url, json, callback, game) {
		jQuery('input[name*=play_param_url]').val(url);
		jQuery('input[name*=play_param_data]').val(json);
		jQuery('input[name*=play_param_callback]').val(callback);
		playCouponRemote();
	},

	play_coupon : function (xml, game_code, arg0, arg1, arg2, arg3) {
		//alert(xml);
		this.playCoupon("/web/services/rs/coupon/play/" + new Date().getTime() + ".xml", 
						xml, 
						"swfobject.getObjectById('gameMovie" + arg0 + "').play_response",
						arg0);
	},
	
	calculate_coupon : function (xml, game_code, arg0, arg1, arg2, arg3) {
		//alert(xml);
		this.playCoupon("/web/services/rs/coupon/verify/.xml", 
						xml, 
						"swfobject.getObjectById('gameMovie" + arg0+ "').calculate_response",
						arg0);
	},
	
	getLiveCoupon : function(url, callback) {
		jQuery('input[name*=play_param_url]').val(url);
		jQuery('input[name*=play_param_callback]').val(callback);
		getLiveCouponRemote();
	},

	handleInvalidSession : function(logoutUrl) {
		alert('Please, login first' + logoutUrl);
	}

};

PlayerClub.Events = {
	listeners : [],
	
	add : function(listener) {
		this.listeners.push(listener);
	},
	
	notify : function(ev) {
		for (var i=0; i<this.listeners.length; i++) {
			this.listeners[i].onEvent(ev);
		}
	}
}

PlayerClub.EventListener = function(id) {
	this.id = id;
}

PlayerClub.EventListener.prototype.onEvent = function(ev) {
}





function addFlashObject(game, swf_path, xml_path, timestamp, width, height, flashArg0) {
	var flashvars = {
		load_url: xml_path,
		msecs: timestamp,
		name: PlayerClub.userName,
		token: PlayerClub.token,
		arg0: game
	}; 
	var attributes = {
		id: "gameMovie" + game,
		name: "gameMovie" + game
	};
	var params = {}; 
	
	swfobject.embedSWF(
		swf_path, 
		"flashWrapper" + game,
		width,
		height,
		"9.0.0",
		"expressInstall.swf",
		flashvars, 
		params, 
		attributes); 

	var myFlashListener = new PlayerClub.EventListener('flashListener' + game);
	myFlashListener.onEvent = function(ev) {
			var myFlash = swfobject.getObjectById("gameMovie" + game);
			if (ev.name == 'loggedIn') {
				myFlash.log_in(
					'name=' + PlayerClub.userName + '&token=' + PlayerClub.token);
			} else if (ev.name == 'loggedOut') {
				myFlash.log_out();
			}
	}

	PlayerClub.Events.add(myFlashListener);
}

PlayerClub.Ajax = {
	onAjaxStart : function(cfg) {
		if (typeof(cfg.global) == 'undefined')
			statusDialog.show();
/*		
		var sourceId = cfg.source;
		var source = document.getElementById(sourceId);
		
		if (source != null) {
			var jqId = PrimeFaces.escapeClientId(sourceId);
			if (source instanceof HTMLButtonElement) {
				jQuery(jqId).button( "option", "icons", {primary:"ajaxButtonLoad"} );
				jQuery(jqId).button("refresh");
//			jQuery(jqId).button("disable");
	
			} else if (source instanceof HTMLInputElement ||
								source instanceof HTMLSelectElement) {
				PlayerClub.Ajax.addWaitContent(jqId);
	
			} else if (source instanceof HTMLSpanElement &&
								document.getElementById(sourceId + "_input") != null) {//password
				if (jQuery(jqId).find('ui-password'))
					PlayerClub.Ajax.addWaitContent(jqId + "_input");
	
			} else if (cfg.event && cfg.event == 'slideEnd') { //slider
				PlayerClub.Ajax.addWaitContent(jqId);
	
			} else if (jQuery(jqId).hasClass('ui-datatable')) { //datatable
				if (cfg.params[sourceId + '_sorting']) {
					var where = jQuery(jqId).find('.ui-state-active')//table header
													.find('.ui-sortable-column-icon');
					PlayerClub.Ajax.addWaitContent(where);
				} else if (cfg.params[sourceId + '_paging']) {
					var where = jQuery(jqId + '_paginatorbottom');
					PlayerClub.Ajax.appendWaitContent(where);
				} else if (cfg.params[sourceId + '_rowExpansion']) {
					var where = jQuery(jqId + '_r_' + cfg.params[sourceId + '_expandedRowIndex'])
												.find('.ui-row-toggler.ui-icon-circle-triangle-e.ui-icon-circle-triangle-s');
					PlayerClub.Ajax.addWaitContent(where);
				}

			} else {
				statusDialog.show();
				alert(source + ' ' + sourceId);
			}
		} else {
//			alert(jQuery('input[name*=selectedTab]').val());
			statusDialog.show();
		}
*/
	},
	
	onAjaxEnd : function(cfg) {
		statusDialog.hide();
/*
		var sourceId = cfg.source;
		var source = document.getElementById(sourceId);
		
		if (source != null) {
			var jqId = PrimeFaces.escapeClientId(sourceId);
			if (source instanceof HTMLButtonElement) {
				jQuery(jqId).button( "option", "icons", {primary:""} );
				jQuery(jqId).button("refresh");
	//		jQuery(jqId).button("enable");
			}
		}
	
		statusDialog.hide();
		jQuery('.ajaxLoadWrapper').remove();
*/
	},
	
	addWaitContent : function(jqId) {
		jQuery(jqId).after("<span class='ajaxLoadWrapper'></span>");
	},

	appendWaitContent : function(jqId) {
		jQuery(jqId).append("<span class='ajaxLoadWrapper'></span>");
	}

}


PlayerClub.BetSlip = {
	multifactor : 1,
	strCombinatios : '',
	strReqMult : '',
	isSystem : false,
	slipGames : [],
	
	jsonStr : '',
	
	reset : function(jsonStr) {
		this.jsonStr = jsonStr;

		var tmp = jQuery.parseJSON(jsonStr);

		this.multifactor = tmp.multifactor;
		this.strCombinatios = tmp.strCombinatios;
		this.strReqMult = tmp.strReqMult;
		this.isSystem = tmp.isSystem;
		this.slipGames = tmp.slipGames;
	},
	
	update : function(multifactor, strCombinatios, strReqMult, isSystem) {
		if (multifactor != null)
			jQuery('input[name*=betSlip_multifactor]').val(multifactor);
		if (strCombinatios != null)
			jQuery('input[name*=betSlip_strCombinatios]').val(strCombinatios);
		if (strReqMult != null)
			jQuery('input[name*=betSlip_strReqMult]').val(strReqMult);
		if (isSystem != null)
			jQuery('input[name*=betSlip_isSystem]').val(isSystem);

		updateBetSlipRemote();
	},

	addGame : function(code, betGameId, markCode, standard, group) {
		jQuery('input[name*=betSlipGame_code]').val(code);
		jQuery('input[name*=betSlipGame_betGameId]').val(betGameId);
		jQuery('input[name*=betSlipGame_markCode]').val(markCode);
		jQuery('input[name*=betSlipGame_standard]').val(standard);
		jQuery('input[name*=betSlipGame_group]').val(group);

		addBetSlipGameRemote();
	},

	updateGame : function(code, betGameId, markCode, standard, group) {
		jQuery('input[name*=betSlipGame_code]').val(code);
		jQuery('input[name*=betSlipGame_betGameId]').val(betGameId);
		jQuery('input[name*=betSlipGame_markCode]').val(markCode);
		jQuery('input[name*=betSlipGame_standard]').val(standard);
		jQuery('input[name*=betSlipGame_group]').val(group);

		updateBetSlipGameRemote();
	},

	removeGame : function(code, betGameId) {
		jQuery('input[name*=betSlipGame_code]').val(code);
		jQuery('input[name*=betSlipGame_betGameId]').val(betGameId);

		removeBetSlipGameRemote();
	},

	removeAll : function() {
		removeBetSlipGamesRemote();
	}

}

/*
PlayerClub.BetSlip.Game = function(code, betGameId, markCode, standard, group) {
	this.code = code;
	this.betGameId = betGameId;
	this.markCode = markCode;
	this.standard = standard;
	this.group = group;
}
*/



