/**
 * @author Edu
 */
var dialog = null;

function openWindow(url, name, wid, hei) {
  wid += 32;
  hei += 96;
  wl = (screen.width - wid) / 2;
  wt = (screen.height - hei) / 2;
  var win = window.open(url,name,'width='+wid+',height='+hei+','+'left='+wl+',top='+wt+','+'location=no, menubar=no,status=no,toolbar=no,scrollbars=no,resizable=no');
  win.resizeTo(wid, hei);
  win.moveTo(wleft, wtop);
  win.focus();	
}

function add_favorite( jocid ){
	openWindow('/my/add_fav.php?jocid='+jocid,'resultat',300,200);
}

function del_favorite( jocid ){
   openWindow('/my/del_fav.php?jocid='+jocid,'resultat',300,200);
   window.reload();
}  

/**
 * Loads the content sent by the server into an Element of the current page
 * @param {Object} page
 * @param {Object} where
 * @param {Object} ondone What to do when the content is loaded (usually refresh)
 */
function loadPage(page,where,ondone){
	var callback = {
		success: function(o) {
			el = document.getElementById(where);
			if (el) {
				el.innerHTML = o.responseText;
				if(ondone!=null) ondone();
			} else {
				alert('AJAX loadPage call failure: No container');
			}
		},
		failure: function(o) {
			alert('AJAX loadPage call failure: Transaction failed');
		}
	}
	YAHOO.util.Connect.asyncRequest('GET', page, callback, null);
}

/**
 * Opens the javascript dialog with the loaded contents inside
 */
function openDialog(url,where,ondone) {
	if((typeof where == 'undefined')||(where=='')) where='dialogContent';
	document.getElementById('dialogTitle').innerHTML = '&nbsp;';
	loadPage(url,
			 where,
			 function() {
		 		dialog.render();
				dialog.show(); 
				if((typeof ondone!='undefined')&&(ondone!=null)) ondone();
			 });
	if(!dialog) dialog = new YAHOO.widget.Dialog("dialog",{fixedcenter:true,modal:true});
}

/* lights element */
function rollover(element) {
  element.className = element.className.replace(/_down/gi,"_up");
}

/* unlights element */
function rollout(element) {
  element.className = element.className.replace(/_up/gi,"_down");
}

/**
 * Sends the called form async and draws the response to the element
 */
function sendForm(formName,where,ondone) {
	frm = document.getElementById(formName);
	if(!frm) alert('sendForm: Form '+formName+' not found!!!');
	if((typeof where == 'undefined')||(where=='')) where='dialogContent';
	
	var callback = {
		success: function(o) {
			if (o.responseText == 'OK') {
				window.location.href=window.location.href;
			}
			else {
				el = document.getElementById(where);
				if (el) {
					el.innerHTML = o.responseText;
					if (ondone != null) ondone();
				}
				else {
					alert('AJAX sendForm call failure: No container');
				}
			}
		},
		failure: function(o) {
			alert('AJAX sendForm failure: Transaction failed')
		},
		upload: function(o) {
			this.success(o);
		}
	}
	YAHOO.util.Connect.setForm(frm,true);
	YAHOO.util.Connect.asyncRequest('POST',frm.action,callback,null);
}

/**
 * Shows the LOGIN dialog
 */
function showLoginDialog() {
	openDialog('index.php?p=login_dialog');
}

/* ADS */
sas_tmstp=Math.round(Math.random()*10000000000);sas_masterflag=1;
function SmartAdServer(sas_pageid,sas_formatid,sas_target) {
if (sas_masterflag==1) {sas_masterflag=0;sas_master='M';} else {sas_master='S';};
document.write('<scr'+'ipt SRC="http://ads.publicidad.net/call/pubj/' + sas_pageid + '/' + sas_formatid + '/'+sas_master + '/' + sas_tmstp + '/' + escape(sas_target) + '?"></scr'+'ipt>');
}