//////////////////////////////////////////
// main.js
//////////////////////////////////////////

//////////////////////////////////////////
// constantes
FADE_SPEED=40;
FADE_STEPS=10;

//////////////////////////////////////////
// funciones auxiliares

// ----------------------------------------------------
// isDHTML
// ----------------------------------------------------
function isDHTML(){return document.getElementById||document.all||document.layers}

// ----------------------------------------------------
// isDinamic
// ----------------------------------------------------
function isDyn(){return getCookie('dinamico')}

// ----------------------------------------------------
// popup
// ----------------------------------------------------
function popup(link, windowname, width, height){

	var href, scrollbars='no';

	if(width>screen.width){ width=screen.width; scrollbars='yes'; }
	if(height>screen.height){ height=screen.height; scrollbars='yes'; }

	var left=(screen.width-width)/2;
	var top=(screen.height-height)/2;

	if(!window.focus) return true;

	if(typeof(link)=='string') href=link;
		else href=link.href;

	var win=window.open(href, windowname,
		'width='+width+'px,height='+height+'px,scrollbars='+
		scrollbars+',toolbar=no,menubar=no,status=no,'+
		'left='+left+'px,top='+top+'px,resizable=no');

	win.focus(); 

	return false

}

// ----------------------------------------------------
// el
// ----------------------------------------------------
function el(name){

	var obj;

	if(document.getElementById) obj=document.getElementById(name)
		else if(document.all) obj=document.all[name];
			else if(document.layers) obj=document.layers[name];

	//alert('obj para name "'+name+'": '+obj);
	return obj;

}

// ----------------------------------------------------
// getWindowHeight
// ----------------------------------------------------
function getWindowHeight(){

	if(document.all) return document.body.offsetHeight; 
		else return window.innerHeight

}

// ----------------------------------------------------
// getWindowWidth
// ----------------------------------------------------
function getWindowWidth(){ 

	if(document.all) return document.body.offsetWidth; 
		else return window.innerWidth;

}

// ----------------------------------------------------
// setStyleProp
// ----------------------------------------------------
function setStyleProp(id,name,value){

	var e=el(id);
	if(e) e.style[name]=value

}

// ----------------------------------------------------
// getStyleProp
// ----------------------------------------------------
function getStyleProp(id,name){

	var e=el(id);
	return(e?e.style[name]:'')

}

// ----------------------------------------------------
// setObjProp
// ----------------------------------------------------
function setObjProp(id,name,value){
	
	var e=el(id);
	if(e) e[name]=value

}

// ----------------------------------------------------
// elProp
// ----------------------------------------------------
function getStyleProp(id,name){

	var e=el(id);
	return(e?e[name]:'');

}

// ----------------------------------------------------
// setCookie
// ----------------------------------------------------
function setCookie(name, value, expires, path, domain, secure){

	document.cookie=name+"="+escape(value)+
		((expires)?"; expires="+expires.toGMTString():"")+
		((path)?"; path="+path:"")+
		((domain)?"; domain="+domain:"")+
		((secure)?"; secure":"")

}

// ----------------------------------------------------
// getCookie
// ----------------------------------------------------
function getCookie(name){

	var dc=document.cookie,
	prefix=name+"=",
	begin=dc.indexOf("; "+prefix);

	if(begin==-1){

		begin=dc.indexOf(prefix);
		if(begin!=0) return null;

	}else begin+=2;

	end=document.cookie.indexOf(";",begin);
	if(end==-1) end=dc.length;

	return unescape(dc.substring(begin+prefix.length,end))

}

// ----------------------------------------------------
// fade
// ----------------------------------------------------
function fade(id,start,end,steps,interval){

	var i;

	start=(start!=undefined?start:0);
	end=(end!=undefined?end:100);
	steps=(steps!=undefined?steps:FADE_STEPS);
	interval=(interval!=undefined?interval:FADE_SPEED);

	for(i=0;i<steps;i++) setTimeout("changeOpac('"+id+"',"+
		(start+Math.round((end-start)/steps)*i)+")",i*interval); 

	return(steps*interval)

}

// ----------------------------------------------------
// fadeOut
// ----------------------------------------------------
function fadeOut(id){return fade(id,100,0,50)}

// ----------------------------------------------------
// fadeIn
// ----------------------------------------------------
function fadeIn(id){return fade(id,0,100,50)}

// ----------------------------------------------------
// changeOpac
// ----------------------------------------------------
function changeOpac(id,opacity){

	var e=el(id);

	if(e){

		e.style.opacity=(opacity/100);
		e.style.MozOpacity=(opacity/100);
		e.style.KhtmlOpacity=(opacity/100);
		e.style.filter="alpha(opacity="+opacity+")"

	}

}

// ----------------------------------------------------
// loadImg
// ----------------------------------------------------
function loadImg(id,src){

	var e=el(id);
	if(e) e.src=src

}

