//----------------------------------------------------------------
// © 2007 On-Line Services 2000, S.L. http://www.ols.es
//----------------------------------------------------------------

// Support for older js

if (location.replace == null)
   location.replace = location.assign

//----------------------------------------------------------------
   
function add2sitios(l,id)
{
return !makeHttpRequest('get',site_root,'action=sitios&func=toggle&id='+id,false,l.id,'replace_div');
}

//----------------------------------------------------------------

function add_arg2url(url,arg)
{
if (url.indexOf('?')>0)
	return url+'&'+arg;
else
	return url+'?'+arg;
}

//----------------------------------------------------------------

function add_args(args,arg)
{
if (args == '')
	return arg;
else
	return args+'&'+arg;
}

//----------------------------------------------------------------

function go_back()
{
if (history.length == 1) return true;

history.go(-1);
return false;
}

//----------------------------------------------------------------

function saveAsMe (filename)
{
document.execCommand('SaveAs',null,filename)
}

//----------------------------------------------------------------

function myemail ()
{
return 'mai' + 'lto:' + my_email.replace('=','@');
}

//----------------------------------------------------------------

function subtleRow(s, c)
{
d = document;
erow = s; //d.getElementById(s);

n=erow.className;
p=n.indexOf('_');
e=(c)?'_on':'_off';
base=n.substring(0,p)+e;
erow.className = base;
}

//----------------------------------------------------------------

function toggleOnOff(lnk)
{
var d = getParent(lnk,'DIV');

n=d.className;
p=n.indexOf('_');
c=n.substring(p);
e=(c=='_off')?'_on':'_off';
base=n.substring(0,p)+e;
d.className = base;
}

//----------------------------------------------------------------

function set_ele_class(id,cname)
{
d = document;
var e = d.getElementById(id);

e.className = cname;
return false;
}

//----------------------------------------------------------------

function get(obj,url)
{
var getstr = '';

for (i=0; i<obj.elements.length; i++)
	{	
	var ele = obj.elements[i];
	
    if (ele.tagName == "INPUT")
		{		
        if (ele.type == "text" || ele.type == "hidden")
			{
			getstr += "&" + ele.name + "=" + escape(ele.value);
            }
        if (ele.type == "checkbox")
			{
            if (ele.checked)
				{
                getstr += "&" + ele.name + "=" + escape(ele.value);
				}
            }
		if (ele.type == "radio")
			{
            if (ele.checked)
				{
                getstr += "&" + ele.name + "=" + escape(ele.value);
				}
            }
         continue;
		}   
	if (ele.tagName == "SELECT")
		{
		if (ele.selectedIndex >= 0) 
			getstr += "&" + ele.name + "=" + escape(ele.options[ele.selectedIndex].value);
        continue;
		}
	if (ele.tagName == "TEXTAREA")
		{
        getstr += "&" + ele.name + "=" + escape(ele.value);
        continue;
		}
	}

return getstr;
}

//----------------------------------------------------------------

function which_browser()
{
var detect = navigator.userAgent.toLowerCase();
var browser;

if (checkIt(detect,'konqueror')) return "Konqueror";
if (checkIt(detect,'safari')) return "Safari";
if (checkIt(detect,'omniweb')) return "OmniWeb";
if (checkIt(detect,'opera')) return "Opera";
if (checkIt(detect,'webtv')) return "WebTV";
if (checkIt(detect,'icab')) return "iCab"
if (checkIt(detect,'msie')) return "Internet Explorer"
if (!checkIt(detect,'compatible'))
	{
	return "Netscape Navigator";
	}
else
	return "An unknown browser";
}

//----------------------------------------------------------------

function checkIt(detect,string)
{
return detect.indexOf(string) + 1;
}

//----------------------------------------------------------------

function cursor_wait()
{
if (document.body) document.body.style.cursor = 'wait';
}

//----------------------------------------------------------------

function cursor_clear()
{
if (document.body) document.body.style.cursor = 'default';
}

//----------------------------------------------------------------

var requester_array = new Array();
var requester_form = '';

//----------------------------------------------------------------
// url   may contain parameters
// args  does not contain starting ?

function makeHttpRequest(method, url, args, return_xml, rname, callback_function)
{
var http_request = false;

http_request = requester_array[rname];

if (http_request && http_request.readyState != 0 && http_request.readyState != 4)
	{
	http_request.abort();
	}

if (!http_request)
	{
	if (window.XMLHttpRequest)
		{ // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType)
			{
			if (return_xml)
				http_request.overrideMimeType('text/xml');
			else
				http_request.overrideMimeType('text/html');
			}
		}
	else if (window.ActiveXObject)
		{ // IE
		try
			{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
			}
		catch (e)
			{
			try
				{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch (e) {}
		   }
	   }
	}

if (!http_request) return false;

http_request.onreadystatechange = function()
	{
	if (http_request.readyState == 4)
		{
		beep();
		cursor_clear();
		
		if (rname != '')
			{
			var div = document.getElementById(rname);
			div.className = '';
			div.enabled = true;
			}
		
		if (requester_form != '')
			{
			frm = document.getElementById(requester_form);
			form_disable(frm,false);
			}
		
		if (callback_function == '') return;
			
		if (http_request.status == 200)
			{
			if (return_xml)
				{
                eval(callback_function + '(\"' + rname + '\",http_request.responseXML)');
				}
			else
				{
				eval(callback_function + '(\"' + rname + '\",http_request.responseText)');
				}
			}
		else
			{
			alert('There was a problem with the request.(Code: ' + http_request.status + ', url:' + url + ')');
			}
		}
	} 

cursor_wait();

// Mark this request as ajax
url = add_arg2url(url,'jsa=1')

// Add session id if need
if (sid != '') url = add_arg2url(url,'PHPSESSID=' + sid);

if (rname != '')
	{
	var div = document.getElementById(rname);
	div.className = 'form_disabled';
	}
	
if (method == 'post')
	{
	http_request.open('POST', url, true);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    //args = 'q=1' + args;
    http_request.setRequestHeader("Content-length", args.length);
	http_request.send(args);
	}
else
	{
	http_request.open('GET', add_arg2url(url,args), true);
	http_request.send(null);
	}
	
return true;
}

//----------------------------------------------------------------

function clear_div(div_id)
{
var result_div = document.getElementById(div_id); 

result_div.innerHTML = '';
}

//----------------------------------------------------------------

function replace_div (div_id, body)
{
if (body.substr(0,5) == 'AJAX:')
	{
	eval(body.substr(5));
	return;
	}

var result_div = document.getElementById(div_id); 

result_div.innerHTML = body;

var x = result_div.getElementsByTagName("script"); 

for (var i=0; i < x.length; i++) 
	{
	eval(x[i].text);
	}
     
if (requester_form != '')
	{
	frm = document.getElementById(requester_form);

	// Enable all fields

	if (frm != null)
		for (i=0; i<frm.elements.length; i++)
			{	
			var ele = frm.elements[i];		
			ele.disabled = false;
			}
	}
}

//----------------------------------------------------------------

function beep()
{
/*
if (which_browser() == "Netscape Navigator")
	java.awt.Toolkit.getDefaultToolkit().beep();
*/	
}

//----------------------------------------------------------------

function confirm_ajax_action (lnk,ask)
{
if (!use_ajax)
	{
	location.replace(lnk.href);
	return false;
	}

res = confirm(ask);

if (res)
	return ajax_action(lnk);
else
	return true;
}

//----------------------------------------------------------------

function url_replace(t)
{
location.replace(t.href);
return false;
}

//----------------------------------------------------------------
// USED

function ajax_send(args)
{
return makeHttpRequest('get', site_root, args, false, '', '');
}

//----------------------------------------------------------------

function ajax_action (lnk, div_id, extra_args)
{
if (!use_ajax)
	{
	location.replace(lnk.href);
	return false;
	}

// Action url

var href = lnk.href;

if (href.indexOf('?')>0)
	{
	var parts = href.split('?');
	var q = parts[1].split('#');
	var args = q[0];
	}
else
	{
	var args = '';
	}

if (div_id == null)
	{
	var div = getParent(lnk,'DIV');
	div_id = div.id;
	}
	
//	Global ajax url

var url = site_root;

//args = add args + '&ajax_id=' + div_id;
args = add_args(args,'ajax_id=' + div_id);
	
if (extra_args != null)
	//args = args + '&' + extra_args;
	args = add_args(args,extra_args);
	
//args = args + '&ourl=' + escape(location.href);
args = add_args(args,'ourl=' + escape(location.href));

requester_form = '';

if (makeHttpRequest('get', url, args, false, div_id, 'replace_div')) return false;

// No AJAX

location.replace(lnk.href);
return false;
}

//----------------------------------------------------------------

function ajax_setdiv (args, div_id)
{
if (!use_ajax) return true;

requester_form = '';
	
if (makeHttpRequest('get', site_root, args, false, div_id, 'replace_div')) return false;

return true;
}

//----------------------------------------------------------------

function ajax_filldiv (lnk, div_id, args)
{
if (!use_ajax)
	{
	location.replace(lnk.href);
	return false;
	}

var url = site_root;

requester_form = '';

if (makeHttpRequest('get', url, args, false, div_id, 'replace_div')) return false;

// No AJAX

location.replace(lnk.href);
return false;
}

//----------------------------------------------------------------

function form_disable(frm,b)
{
for (i=0; i<frm.elements.length; i++)
	{	
	var ele = frm.elements[i];		
	ele.disabled = b;
	}
}

//----------------------------------------------------------------

function ajax_submit_form (t, args, replace)
{
var frm = getParent(t,'FORM');
var div = getParent(frm,'DIV');
var url = site_root + '?' + args;
 
return ajax_form(frm.id,div.id,url,replace);
}

//----------------------------------------------------------------

function ajax_submit_silent (t, args )
{
if (!use_ajax) return true;

var frm = getParent(t,'FORM');

// Avoid using ajax for non supported post encodings

if (frm.method == 'post' && frm.encoding == 'multipart/form-data') return true;

var url = site_root + '?' + args;

var args = get(frm);

//aurl = add_arg(url,'jsa=1')
requester_form = frm.id;

if (makeHttpRequest(frm.method, url, args, false, '', ''))
	{
	form_disable(frm,true);
	return false;
	}
	
return true;
}

//----------------------------------------------------------------

function ajax_form (form_name, div_id, url, replace )
{
frm = document.getElementById(form_name);

if (!use_ajax) return true;

// Avoid using ajax for non supported post encodings

if (frm.method == 'post' && frm.encoding == 'multipart/form-data') return true;

var args = get(frm);

// no cal, ja es fa a lib.forms
//if (sid != '') args = args + '&PHPSESSID=' + sid;

requester_form = form_name;

// jsa=1 -> Form submited via JS Ajax
//aurl = add_arg(url,'jsa=1')

if (makeHttpRequest(frm.method, url, args, false, div_id, 'replace_div'))
	{
	// Ajax succeed, disable all fields
	form_disable(frm,true);
	return false;
	}
	
// No AJAX

if (!replace || frm.method == 'post') return true;

var url = frm.action + args;
location.replace(url);
return false;
}

//----------------------------------------------------------------

function ajax_goprev(url)
{
if (!use_ajax)
	window.location = url;
else
	history.go(-1);
	
return false;
}

//----------------------------------------------------------------

function ButtonGoTo(div_id,jurl,aurl)
{
if (!use_ajax)
	{
	location.replace(jurl);
	return false;
	}

var div = document.getElementById(div_id);
var href = jurl;

if (href.indexOf('?')>0)
	{
	var parts = href.split('?');
	var o_url = parts[0];
	var q = parts[1].split('#');
	var args = '&' + q[0];
	}
else
	{
	var args = '';
	var o_url = href;
	}
	
args = args + '&ourl=' + o_url + '&ajax=0';
requester_form = '';

if (makeHttpRequest('get', aurl, args, false, div.id, 'replace_div')) return false;

// No AJAX

location.replace(jurl);
return false;
}

//----------------------------------------------------------------
/*
function GoToPage(lnk,url)
{
var div = getParent(lnk,'DIV');	

// URL per si no hi ha ajax
var url = lnk.href;

// URL ajax
var aurl = site_root + '?ajax_id=' + div.getAttribute('id');


return ButtonGoTo(div.id,url,aurl);
}
*/
//----------------------------------------------------------------

function ReloadTable(lnk)
{
if (!use_ajax)
	{
	location.replace(lnk.href);
	return false;
	}

var div = getParent(lnk,'DIV');	
var url = site_root + '?ajax_id=' + div.getAttribute('id');
var href = lnk.href;

if (href.indexOf('?')>0)
	{
	var parts = href.split('?');
	var o_url = parts[0];
	var q = parts[1].split('#');
	var args = '&' + q[0];
	}
else
	{
	var args = '';
	var o_url = href;
	}
	
args = args + '&ourl=' + o_url;
requester_form = '';

if (makeHttpRequest('get', url, args, false, div.id, 'replace_div')) return false;

// No AJAX

location.replace(lnk.href);
return false;
}

//----------------------------------------------------------------

function SortTable(lnk)
{
if (!use_ajax)
	{
	location.replace(lnk.href);
	return false;
	}

var span = false;

for (var ci=0;ci<lnk.childNodes.length;ci++)
	{
	if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span')
		{
		span = lnk.childNodes[ci];
		break;
		}
    }

if (span)
	var spantext = ts_getInnerText(span);
else
	var spantext = '';
	
var td = lnk.parentNode;
var column = td.cellIndex;
var table = getParent(td,'TABLE');
    
// Work out a type for the column
if (table.rows.length <= 1) return false;

var itm = ts_getInnerText(table.rows[1].cells[column]);

sortfn = ts_sort_caseinsensitive;

if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date;
if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date;
if (itm.match(/^[£$]/)) sortfn = ts_sort_currency;
if (itm.match(/^[\d\.\,]+$/)) sortfn = ts_sort_numeric;

SORT_COLUMN_INDEX = column;

var newRows = new Array();
var rowclass = new Array();

for (j=1;j<table.rows.length;j++)
	{
	rowclass[j-1] = table.rows[j].className;
	newRows[j-1] = table.rows[j];
	}

newRows.sort(sortfn);

var sdir = span.getAttribute("sortdir");

if (sdir == null || sdir == 'down')
	{
	ARROW = img_order;
	newRows.reverse();
	span.setAttribute('sortdir','up');
    }
else
	{
	ARROW = img_inorder;
	span.setAttribute('sortdir','down');
    }
  
for (i=0;i<newRows.length;i++)
	{
	table.tBodies[0].appendChild(newRows[i]);
	}
   
// Delete any other arrows there may be showing
var allspans = document.getElementsByTagName("span");

for (var ci=0;ci<allspans.length;ci++)
	{
	if (allspans[ci].className == 'sortarrow')
		{
		if (getParent(allspans[ci],"table") == getParent(lnk,"table"))
			{ // in the same table as us?
			allspans[ci].innerHTML = img_noorder;
            }
        }
    }
        
span.innerHTML = ARROW;

// Restore class

for (j=1;j<table.rows.length;j++)
	{
	table.rows[j].className = rowclass[j-1];
	}

return false;
}

//----------------------------------------------------------------

function ts_getInnerText(el) {
	if (typeof el == "string") return el;
	if (typeof el == "undefined") { return el };
	if (el.innerText) return el.innerText;	//Not needed but it is faster
	var str = "";
	
	var cs = el.childNodes;
	var l = cs.length;
	for (var i = 0; i < l; i++) {
		switch (cs[i].nodeType) {
			case 1: //ELEMENT_NODE
				str += ts_getInnerText(cs[i]);
				break;
			case 3:	//TEXT_NODE
				str += cs[i].nodeValue;
				break;
		}
	}
	return str;
}

//----------------------------------------------------------------

function getParent(el, pTagName) {
	if (el == null) return null;
	else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())	// Gecko bug, supposed to be uppercase
		return el;
	else
		return getParent(el.parentNode, pTagName);
}

//----------------------------------------------------------------

function ts_sort_date(a,b) {
    // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
    if (aa.length == 10) {
        dt1 = aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2);
    } else {
        yr = aa.substr(6,2);
        if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
        dt1 = yr+aa.substr(3,2)+aa.substr(0,2);
    }
    if (bb.length == 10) {
        dt2 = bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2);
    } else {
        yr = bb.substr(6,2);
        if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
        dt2 = yr+bb.substr(3,2)+bb.substr(0,2);
    }
    if (dt1==dt2) return 0;
    if (dt1<dt2) return -1;
    return 1;
}

//----------------------------------------------------------------

function ts_sort_currency(a,b) { 
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
    return parseFloat(aa) - parseFloat(bb);
}

//----------------------------------------------------------------

function ts_sort_numeric(a,b)
{ 
aa = parseFloat(ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).replace(/[.,]/g,''));
if (isNaN(aa)) aa = 0;

bb = parseFloat(ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).replace(/[.,]/g,'')); 
if (isNaN(bb)) bb = 0;

return aa-bb;
}

//----------------------------------------------------------------

function ts_sort_caseinsensitive(a,b) {
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).toLowerCase();
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).toLowerCase();
    if (aa==bb) return 0;
    if (aa<bb) return -1;
    return 1;
}

//----------------------------------------------------------------

function ts_sort_default(a,b) {
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
    if (aa==bb) return 0;
    if (aa<bb) return -1;
    return 1;
}

//----------------------------------------------------------------

function ajax_fill_select(tbox,txt,start)
{
var values = txt.split("\n");

for (i=0; i<values.length; i++)
	{
	var parts = values[i].split('=');
	if (parts[0] == '' || parts.length<2) continue;
	var no = new Option();
	no.value = parts[0];
	no.text = unescape(parts[1]);
	tbox.options[tbox.options.length] = no;
	}
}

//------------------------------------------------

function ClearBox(tbox)
{
for (var i=tbox.options.length;i>0;i--) tbox.options[i]=null;
tbox.lenght=1;
}

//------------------------------------------------

function set_sel_text(tsel,inp)
{
d = document;
tbox = d.getElementById(inp);
tbox.value = tsel.options[tsel.selectedIndex].text;
}

//------------------------------------------------

function iframe2div(from,to)
{
var x = window.frames['iframeFotos'].document.getElementsByTagName('body')[0].innerHTML;
document.getElementById('fotos_tbl').innerHTML = x;
}

//------------------------------------------------

function LoadTab(lnk,name)
{
//window.location.hash = name;
//onclick="return LoadTab(this,'opiniones');
return ajax_filldiv(this,'generic_data','page=admin_generic_'+name+'&id={get_id}');
}

// **********************************************************************
// Image fading, heavely based on Image Cross Fade Redux Version 1.0
// by steve@slayeroffice.com
// http://slayeroffice.com/code/imageCrossFade/index.html

var if_current = 1;
var if_imgo;
var if_imgn;
var if_autoshow = false;
var if_tfade = false;
var if_tnext = false;

//---------------------------------------------------

function show_stop()
{
if_autoshow = false;

if (if_tnext)
	{
	clearTimeout(if_tnext);
	if_tnext = false;
	}
}

//---------------------------------------------------

function show_image(pos)
{
if (!use_ajax) return true;

if (if_autoshow)
	{
	// Cancelar autoshow
	show_stop();
	
	if (thm_current != pos)
		{
		thm_prev = thm_current;
		thm_current = pos;
		setTimeout(show_current,60);
		}
	return false;
	}
	
return replace_img(pos);
}

//---------------------------------------------------

function replace_img(pos)
{
thm_prev = thm_current;
thm_current = pos;
show_current();
return false;
}

//---------------------------------------------------

function show_current()
{
d = document;

// Imatge actual, a ocultar
if_imgo = d.getElementById('imageContainer' + if_current);
if_imgo.xOpacity = .99;

// Imatge nova, a mostrar
if_current = (if_current == 1)?2:1;
if_imgn = d.getElementById('foto_main' + if_current);
if_imgn.src = '/fotos/' + thm_fotos[thm_current];

if_imgn = d.getElementById('imageContainer' + if_current);
if_imgn.xOpacity = 0;

// Canviar border
if_idthumb = d.getElementById('thumb_' + thm_prev);
if_idthumb.style.border="0";

if_idthumb = d.getElementById('thumb_' + thm_current);
if_idthumb.style.border="2px solid red";

// Descripcio
if_desc = d.getElementById('imageDesc');
if_desc.innerHTML = thm_desc[thm_current];

so_xfade();

return false;
}

//---------------------------------------------------

function toggle_autoshow()
{
if (!if_autoshow)
	{
	if_autoshow = true;
	show_next_auto();
	}
else
	show_stop();

return false;
}

//---------------------------------------------------

function show_next()
{
if (!use_ajax) return true;

if (if_autoshow)
	{
	show_stop();
	setTimeout(show_next,60);
	return false;
	}
	
return show_next_auto();
}

//---------------------------------------------------

function show_next_auto()
{
thm_next = thm_current+1;
if (!thm_fotos[thm_next]) thm_next = 0;

if (thm_next == thm_current) return false;

return replace_img(thm_next);
}

//---------------------------------------------------

function show_prev()
{
if (!use_ajax) return true;

if (if_autoshow)
	{
	show_stop();
	setTimeout(show_prev,60);
	return false;
	}

if (!thm_current)
	{
	for (thm_prev=0; thm_fotos[thm_prev+1]; thm_prev++);
	}
else
	thm_prev = thm_current-1;
	
return replace_img(thm_prev);
}

//---------------------------------------------------

function so_xfade()
{
if_tfade = false;
if_tnext = false;

cOpacity = if_imgo.xOpacity;
nOpacity = if_imgn.xOpacity;
	
cOpacity-=.05; 
nOpacity+=.05;
	
if_imgn.style.display = "block";
if_imgo.xOpacity = cOpacity;
if_imgn.xOpacity = nOpacity;
	
setOpacity(if_imgo); 
setOpacity(if_imgn);
	
if (cOpacity<=0)
	{
	if_imgo.style.display = "none";
	if (if_autoshow) if_tnext = setTimeout(show_next_auto,2000);
	}
else
	{
	if_tfade = setTimeout(so_xfade,50);
	}
}

//---------------------------------------------------

function setOpacity(obj)
{
if(obj.xOpacity>.99)
	{
	obj.xOpacity = .99;
	return;
	}
obj.style.opacity = obj.xOpacity;
obj.style.MozOpacity = obj.xOpacity;
obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
}

/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

function bookmarksite(title,url)
{
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else
	if(window.opera && window.print)
		{ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
		} 
	else
		if(document.all)// ie
			window.external.AddFavorite(url, title);
}

//----------------------------------------------------------------

var nt_div;
var nt_oinc;
var nt_hinc;

//----------------------------------------------------------------

function niceToggleOnOff(id)
{
d = document;
nt_steps = 20;
nt_div = d.getElementById(id);

if (nt_div.offsetHeight == 0)
	{
	// Creixer
	nt_oinc =  1/nt_steps;
	nt_div.xOpacity = 0;
	
	nt_hinc = nt_div.originalHeight/nt_steps;
	nt_div.currentHeight = 0;
	}
else
	{
	// Disminuir
	nt_oinc =  -1/nt_steps;
	nt_div.xOpacity = 1;

	if (nt_div.originalHeight == undefined)
		nt_div.originalHeight = nt_div.offsetHeight;

	nt_div.currentHeight = nt_div.originalHeight;
	nt_hinc = -nt_div.originalHeight/nt_steps;
	}

nt_div.timeout = 25;
setTimeout(nt_xfade,25);
return false;
}

//---------------------------------------------------

function nt_xfade()
{
nt_div.style.display = "block";
nt_div.xOpacity += nt_oinc;
nt_div.currentHeight += nt_hinc;

if (nt_div.xOpacity <= 0)
	{
	nt_div.style.display = "none";
	nt_div.style.height = 0;
	return;
	}

if (nt_div.xOpacity >= 1)
	{
	nt_div.style.height = nt_div.originalHeight;
	nt_div.xOpacity = 1;
	setOpacity(nt_div);
	return;
	}

if (nt_div.currentHeight <= 0)
	{
	nt_div.style.display = "none";
	nt_div.style.height = '0px';
	return;
	}

if (nt_div.currentHeight >= nt_div.originalHeight)
	{
	nt_div.style.height = nt_div.originalHeight;
	nt_div.xOpacity = 1;
	setOpacity(nt_div);
	return;
	}
	
setOpacity(nt_div);
nt_div.style.height = nt_div.currentHeight + 'px';
setTimeout(nt_xfade,nt_div.timeout);
}

//---------------------------------------------------

function getCookieVal (offset) {  
var endstr = document.cookie.indexOf (";", offset);  
if (endstr == -1)    
endstr = document.cookie.length;  
return unescape(document.cookie.substring(offset, endstr));
}

//---------------------------------------------------

function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;
}

//----------------------------------------------------------------

function SetCookie (name, value) {  
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) +  
((domain == null) ? "" : ("; domain=" + domain)) +    
((secure == true) ? "; secure" : "");
}

//----------------------------------------------------------------

function zoomText(id,tipo)
{
obj = document.getElementById(id);

if (obj.style.fontSize=="")
	{
	obj.style.fontSize="100%";
	actual = 100;
	}
else
	actual = parseInt(obj.style.fontSize);
	
incremento = 20;
	
if (tipo == 0)
	{
	obj.style.fontSize = "100%";
	}
else if (tipo == 1)
	{
	valor = actual+incremento;
	obj.style.fontSize = valor+"%";
	}
else if (tipo == -1)
	{
	valor=actual-incremento;
	obj.style.fontSize = valor+"%";
	}
}

//----------------------------------------------------------------

function site_sndml(lnk,strCipher,subj)
{
var strPlain = "";

for (var i = 0; i < strCipher.length; i++)
	{ 
	c = strCipher.charAt(i);
	p = sndml.indexOf(c,0);
	if (p<0)
		strPlain = strPlain + c;
	else
		strPlain = strPlain + sndml.charAt(27-p);
	}
		
lnk.href='mai'+'lto:'+strPlain;

if (subj) lnk.href = lnk.href + '?' + subj;
return true;
}

//----------------------------------------------------------------

function site_rmbeml(lnk)
{
var parts = lnk.href.split("=");
lnk.href = parts[0] + "=" + document.login_form.email.value;
}

//----------------------------------------------------------------

function site_div_state(szDivID, iState) // 1 visible, 0 hidden
{
var obj = document.layers ? document.layers[szDivID] : document.getElementById ?  document.getElementById(szDivID).style :document.all[szDivID].style;
obj.visibility = document.layers ? (iState ? "show" : "hide") :  (iState ? "visible" : "hidden");
}
