
/* This functions are used to load a portlet in a parent porltetset with controller card 
if this portletset has a hidden ProxyPortlet where it can load the new portlet.
If there are not a portletset with controller card and a hidden ProxyPortlet, the portlet loads maximized.
*/

CardProxyUrls = new Array ();						
CardProxyNames = new Array ();	
CurrentCard = -1; //Marca el la posicion del array que contiene el card con el proxy oculto activo.
	
function loadCardProxy (portlet,position,portlettype,extraname,extravalue){
	if (position >= 0)
	{
		document.forms.LoadCardProxy.elements[0].name= CardProxyNames[position]+'.target';
		document.forms.LoadCardProxy.elements[0].value= portlet;
		document.forms.LoadCardProxy.elements[2].value= portlettype;
		document.forms.LoadCardProxy.action = CardProxyUrls[position];
		if (extraname != ''){
			document.forms.LoadCardProxy.elements[1].name= extraname;
			document.forms.LoadCardProxy.elements[1].value= extravalue;			
		}
		document.forms.LoadCardProxy.submit ();
	} else {
		document.forms.LoadCardProxy.elements[0].name= 'portlet';
		document.forms.LoadCardProxy.elements[0].value= portlet;	
		urlAction = "";
		/* Home is declarated in head of the page */
		if (Home.indexOf (";jsessionid=") > -1){
			urlAction = Home.substring(0,Home.indexOf (";jsessionid=")) + '/portlet/' + portlet + Home.substring(Home.indexOf (";jsessionid="),Home.length);			
		} else {
			urlAction = Home + '/portlet/' + portlet;
		}				
		document.forms.LoadCardProxy.action = urlAction; 
		if (extraname != ''){
			document.forms.LoadCardProxy.elements[1].name= extraname;
			document.forms.LoadCardProxy.elements[1].value= extravalue;			
		}		
		document.forms.LoadCardProxy.submit ();		
	}
	return false;
}		

function searchContext (position){															
	if (position >= 0)
	{
		document.forms.buscadorLocal.elements[0].name= CardProxyNames[position]+'.target';
		document.forms.buscadorLocal.action = CardProxyUrls[position];																
	} else {
		document.forms.buscadorLocal.elements[0].name= 'portlet';
		urlAction = "";
		/* Home is declarated in head of the page */
		if (Home.indexOf (";jsessionid=") > -1){
			urlAction = Home.substring(0,Home.indexOf (";jsessionid=")) + '/portlet/' + portlet + Home.substring(Home.indexOf (";jsessionid="),Home.length);			
		} else {
			urlAction = Home + '/portlet/' + portlet;
		}				
		document.forms.buscadorLocal.action = urlAction; 
	}
	return true;
}		


function getPositionCard (){
	return (CurrentCard);
}	

function mChange(elem, clase) {
	elem.className=clase;
}



function getDateValue(dayValueNumber) {
	
	var dateValue = new Date();
	var dayValue = dateValue.getDay();
	var monthValue = dateValue.getMonth();
	var monthValueName = monthName(monthValue);
	
	var yearValue = dateValue.getYear();
	var dayValueWeek = dayName( dayValue);
	
	var dateValueFinal=dayValueWeek+" "+dayValueNumber+' de '+monthValueName;
	
	return(dateValueFinal);	
}


function dayName( day ) {
	var dias = new Array(7);
	dias[0] = "Domingo";
	dias[1] = "Lunes";
	dias[2] = "Martes";
	dias[3] = "Miercoles";
	dias[4] = "Jueves";
	dias[5] = "Viernes";
	dias[6] = "Sabado";
	
//	return dias[dayOfWeek(day, month, year)];
	return dias[day];
}

function monthName(month ) {
	var meses = new Array(12);
	meses[0] = "Enero";
	meses[1] = "Febrero";
	meses[2] = "Marzo";
	meses[3] = "Abril";
	meses[4] = "Mayo";
	meses[5] = "Junio";
	meses[6] = "Julio";
	meses[7] = "Agosto";
	meses[8] = "Septiembre";
	meses[9] = "Octubre";
	meses[10] = "Noviembre";
	meses[11] = "Diciembre";
	if (month > 12) month = 12;
	if (month < 1) month = 1;
	
	return meses[month];
}


/* This code emulates the behavior of insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement() methods
*/

if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentElement = function (where,parsedNode)
	{		
		
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) 
				this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function (where,htmlStr)
	{				
		
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);				
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function (where,txtStr)
	{
		
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}	
}

function jtrim(sal){
    re = /\s*(\S+)/;
    sal=sal.replace(re,"$1");
    ind=sal.length;
    while (sal.charAt(ind-1)==' '&&ind>=0)	ind--;
	
	return sal.substring(0,ind);
}

/* This function throws contained funcitons in "functionsOnLoad" array  */

functionsOnLoad = new Array ();						
function initFunctionsOnLoad (i)
{				
	if (i<functionsOnLoad.length)
	{
		eval (functionsOnLoad[i]);
		cont=i+1;
		setTimeout('initFunctionsOnLoad (cont)',10);
	}		
	return;								
}
		
/* This function allows load a marked card in a control paned or tree from a portlet */

/* This function load the sport events from a month and his calendar */
function loadEvent (uri,month, portletNamePrefix){
	formEvent = document.forms.LoadEvent;
	formEvent.action = uri;
	numMonth = "0";
	numNextMonth = "0";
	if (month<10){
		numMonth = numMonth + month;
		if (month == 9){
			numNextMonth = "10";
		} else {
			numNextMonth = numNextMonth + (month+1);
		}										
	} else {
		numMonth = "" + month;
		if (month == 12){
			numNextMonth = "";
		} else {
			numNextMonth = "" + (month+1);
		}
	}
	numMonth = portletNamePrefix + numMonth;
	numNextMonth = portletNamePrefix + numNextMonth;				
	formEvent.elements[0].value = numMonth;
	formEvent.elements[1].value = numNextMonth;
	formEvent.submit ();
	return;
}
