String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g,'');}

function abrirVentana(url, width, height, name) {
	if (name==null) {name='nueva_ventana';}
	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;
		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
	}
	str += ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";
	objwin=window.open(url, name, str);
	if (objwin)
		objwin.focus();
}

function getObj(id) {if (document.getElementById) {return document.getElementById(id)}  else if (document.all) {return document.all[id]}    else {return document.all[id]}}

function setget_attr(obj, prop, val)
{
	if (!val)
		return obj.getAttribute(prop);
	else
	{
		if (prop=="onmouseover" || prop=="onmouseout" || prop=="onclick" || typeof val=="function")
		{
			if (obj.addEventListener)
			{
				if (navegador_detect=="ie")
					val = Function(val);
			}else{
				obj.attachEvent(prop, new Function('"+val+"'), false);
			}
		}
		obj.setAttribute(prop,val);
	}
}



function validar_olvidemiclave(form) {
	var aux="E-mail incorrecto.".split("|");
	if (form.olvideemail.value.indexOf('@') < 0 || form.olvideemail.value.indexOf('.') < 0 || form.email.value.indexOf(',') > 0) { DHTMLALERT(aux[0]); form.olvideemail.focus(); return false; }
	return true;
}

function validar_login(formulario,msg) {
	if (formulario.usuario.value == '' || formulario.clave.value == '') {
	DHTMLALERT(msg); formulario.usuario.focus(); return false;
	return true;
}
}

function crear_script_tag(file,tagname) {
	var head_html = document.getElementsByTagName('head');
	if (head_html==null)
	head_html=document;
	else
		head_html=head_html[0];

	if (tagname==undefined) tagname="jscript_gen";

	scriptTag = getObj(tagname);
	if(scriptTag!=null)
	{
		head_html.removeChild(scriptTag);
		delete(scriptTag);
		scriptTag=null;
	}
	var script = document.createElement('script');
	var vch="?";
	if (file.indexOf("?")!=-1) vch="&";
	script.src = file+vch+Math.random()*1000000;
		script.type = "text/javascript";
		script.id = tagname;
		head_html.appendChild(script);
}




// VISUAL FX///////////////////////////////////////////////////////////////////////////


function force_display(ly) {
	veclayers=ly.split(",");
	for (var i=0;i<veclayers.length;i++) {
		ly=document.getElementById(veclayers[i]);
		if (ly!=null) {ly.style.display="";}
	}
}
function force_undisplay(ly) {
	veclayers=ly.split(",");
	for (var i=0;i<veclayers.length;i++) {
		ly=document.getElementById(veclayers[i]);
		if (ly!=null) {ly.style.display="none";}
	}
}
function display_undisplay(id_obj) {
	obj=getObj(id_obj);
	if(obj==null) {DHTMLALERT("objeto:"+id_obj+"no encontrado."); return;}
	if (obj.style.display=="") {
		obj.style.display="none";
	} else {
		obj.style.display="";
	}
}

function str_replace(str,s,t)
{
return str.split(s).join(t);
}
//MODIFICAR ALTO ELEMENTO
function resize_obj(id_obj, px) {
	obj=getObj(id_obj);
	if (obj.style.height==undefined) return;
	aux_h=parseInt(str_replace(obj.style.height,"px",""));
	if (isNaN(px))
		px=parseInt(str_replace(px.toString(),"px",""));
	aux_h+=px;
	if (aux_h<=0) return;
	obj.style.height=aux_h+"px";
}

//CENTRAR LAYER
function showAndCenter(id, img) {

	var obj = id;
	if (typeof obj != "object")
		obj=getObj(id);

	ancho_layer=obj.style.width;
	ancho_layer=ancho_layer.replace("px","");
	alto_layer=obj.style.height;
	alto_layer=alto_layer.replace("px","");

	if (document.body && document.body.scrollTop)
	{
		var altobody=document.body.scrollTop;
	} else if (document.documentElement && !document.documentElement.scrollTop) {
		var altobody=document.documentElement.scrollTop;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		var altobody=document.documentElement.scrollTop;
	}

	var X = ((document.body.scrollWidth-ancho_layer)/2);
	var Y = ((screen.availHeight-alto_layer)/2);

	obj.style.zIndex=99999999;
	obj.style.display="";
	obj.style.visibility="visible";
	obj.style.left=parseInt((document.body.scrollLeft+(X)))+"px";
	obj.style.top =parseInt((altobody +(Y) - 100))+"px";
}

function DHTMLALERT(msg)
{
	var dalert_msg = getObj("dhtml_alert_MSG");

	if (!dalert_msg)
		return;
	if (msg!="")
	{
		dalert_msg.innerHTML = msg;
		showAndCenter("dhtml_alert");
	} else {
		var dalert = getObj("dhtml_alert");
		dalert_msg.innerHTML = "";
		dalert.style.display="none";
		try {
			obj_focus.focus();
			obj_focus=null;
		} catch(err) {}
	}
	activar_layer_transparente("ly_transparente");
}

function activar_layer_transparente(id_obj) {
	var obj=getObj(id_obj);
	if (obj.style.display=="") {
		obj.style.display="none";
	} else {
		obj.style.display="";
		obj.style.width=getPageSize()[0];
		obj.style.height=getPageSize()[1];
	}
}

function getPageSize(){
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}