tabbar_last_shown={};

function tabbarLoadDiv(id,jump,buttonid){

	var o=document.getElementById(tabbar_last_shown['tabbarname']);
	if(o)
		o.className='tabbutton';
	ajump(jump,id,'set_html');
	var o=document.getElementById(buttonid)
	o.className='tabbutton_activo';
	tabbar_last_shown['tabbarname']=buttonid
}

function tabbarShowDiv(id,tabbarname)
{
	var o=document.getElementById(id)
	if(o){
		tabbarHideDiv();

		//$(o).fadeIn(400)
		$(o).show()

		var o=document.getElementById('tabbutton_'+id)
		o.className='tabbutton_activo';
		tabbar_last_shown['tabbarname']=id
		      
	}
}


function tabbarHideDiv()
{
	var id=tabbar_last_shown['tabbarname']
	var o=document.getElementById(id)
	if(o){
		o.style.display='none';
		var o=document.getElementById('tabbutton_'+id)
		if(o)
			o.className='tabbutton';
	}

	$('#tooltip').hide();
}

function disableFormField(id)
{
	var o=document.getElementById(id)
	if(o){
		o.disabled=true;
		o.readonly=true;
	}
}

function enableFormField(id)
{
	var o=document.getElementById(id)
	if(o){
		o.disabled=false;
		o.readonly=false;
	}
}

function cleanPreview()
{
	var o=$('#previewiframe');
	if(o){
		o.attr('src','index.php?jump=tucamportal.loading');
	}

}

function showPreview(src)
{
 var o=$('#previewiframe');
        if(o){
                // set the iframe
                // Error, it must reload always, reload button do not work always as site could be out of the domain
                // and the navigator complains if the domain is different
                /*
                if( ! o.attr('src') || o.attr('src') == 'index.php?jump=tucamportal.loading' || o.attr('src')!=src ){
                        o.attr('src',src);
                }
                */

                o.attr('src',src);

                // show all ( showing the container )
                container=$('#tucamportal_preview').css("zIndex","5").
                show(400).
                css("position","absolute").
                css("top","5px").
                css("left","5px");      // put a default
                if( window.innerWidth ){        // try to center
                        w=parseInt(o.css('width'));
                        if( w < window.innerWidth ){
                                container.css("left",(window.innerWidth-w)/2+"px");
                        }else{
                                container.css("left","0px");
                        }
                }
        }

}

function closePreview(src)
{
	var o=$('#previewiframe');
	if(o){
		// show the all ( showing the container )
		$('#tucamportal_preview').css("zIndex","5").
		hide(300).
		css("position","absolute")
	}
}


function changeSize(id,field)
{
	o=$('#'+id)
	if(o){
		value=field.options[field.selectedIndex].value.split('x')
		w=value[0]
		h=value[1]

		var o=$('#previewiframe');
		if(o){
			// set the iframe size
			o.css("width",w+"px");
			o.css("height",h+"px");
		}

		// if size is changed we need to move the container so it get's centered
		
		container=$('#tucamportal_preview')
		if( window.innerWidth ){	// try to center
			w=parseInt(o.css('width'));
			if( w < window.innerWidth ){
				container.css("left",(window.innerWidth-w)/2+"px");
			}else{
				container.css("left","0px");
			}
		}
	}
}

function tooltip(event)
{
	o=$('#tooltip')
	o.css("position","absolute");	
	o.css("zIndex","8");	
	o.css("top",event.pageY-20);	
	o.css("left",event.pageX-320);	
	if(event.data[0]=='I'){
		// no inner HTML ?, cutting the first 2 chars...
		o.show();
		document.getElementById('tooltip').innerHTML = event.data.slice(2);
		o.bind('mouseout','O,'+event.data, tooltip);
		o.bind('click','O,'+event.data, tooltip);
	}else{		// out
		o.hide()
	}
}



function addkeyword(v,formid){
	var keywords=document.getElementById(formid+'keywords').value
	if( keywords){
		keywords=keywords.split(', ')
	}else{
		keywords=[]
	}
	keywords[keywords.length]=v
	document.getElementById(formid+'keywords').value=keywords.join(', ')
}


function showLightBox(selector,loadcontent){

	var o=document.getElementById('aux');
//	o.style.left = 	(x+window.innerWidth/2)+"px";

	var y=0
	var x=0

	function _showLightBox(st)
	{
		if(o && st=='200'){
			o.style.cursor='default'
			o.style.position='absolute'
			o.style.zIndex=10
			o.style.display='block';
			o.style.left=x
			o.style.top=y
		}
	}
	loadcontent( _showLightBox );
}

function checknavigator(msg){
	if($.browser.msie && parseFloat($.browser.version)<7){
				$('#auxmsg').fadeOut("normal",function(){;
					$('.formtable input').attr('disabled','true').css('background-color','#e7e7e7')
					$('#auxmsg').html(msg+'<br>')
					$('#auxmsg').fadeIn();
					$('.formtable td').css('color','#e7e7e7')
				}
		);
	}
}

function centerMe(id,width,height)
{
	var y=$(window).scrollTop();
	var x=$(window).scrollLeft();
	var o=window.document.getElementById('aux');
	if(o){
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}

		o.style.left="0px";
		o.style.top="0px";
		o.style.position='absolute'
		o.style.paddingTop = (y+myHeight/2-height/2) + "px";
		o.style.paddingBottom =	 o.style.paddingTop
		o.style.paddingLeft = (x+myWidth/2-width/2) + "px";
		o.style.paddingRight = o.style.paddingLeft ;
		o.style.backgroundImage='url(images/bgcopy.png)';
		$(o).show();
	}
}

function do_acordion(){
	if( !ie() ){
		navigator.appVersion.indexOf('MSIE')	
		$(document).ready(function() { $('#acordeon').accordion(); });
	}else{
		$(document).ready(function() {
			$('#acordeon').css('height','550px').css('overflow-y','auto').css('overflow-x','hidden').css('width','300px');
			$('#acordeon .title').css('background-color','#FF8200').css('font-size','1.2em').css('padding-left','4px').css('margin-top','10px').css('margin-bottom','10px');
			$('#acordeon .title a').css('color','#ffffff');
			});
	}
}
