var fgLogLoaded = false;

function redirect( url ) {
	window.location = url;
}

function confirma( txt ) {
	if( confirm( txt ) )
		return true
	return false;
}

function replaceSpecialChars( string ) {
	//string = string.replace("|","\u00F1"); //
	string = string.replace(/AAA/g,"\u00C1"); //
	string = string.replace(/aaa/g,"\u00E1"); //
	string = string.replace(/EEE/g,"\u00C9"); //
	string = string.replace(/eee/g,"\u00E9"); //
	string = string.replace(/III/g,"\u00CD"); //
	string = string.replace(/iii/g,"\u00ED"); //
	string = string.replace(/OOO/g,"\u00D3"); //
	string = string.replace(/ooo/g,"\u00F3"); //
	string = string.replace(/UUU/g,"\u00DA"); //
	string = string.replace(/uuu/g,"\u00FA"); //
	string = string.replace(/NNN/g,"\u00D1"); //
	string = string.replace(/nnn/g,"\u00F1"); //
	
	return string;
}

function focusOnField( id_field ) {
	dojo.byId( id_field ).focus();
}

function quitaEtiquetaEmail( id_objeto ) {
	if( dojo.byId( id_objeto ).value == 'e-mail' )
		dojo.byId( id_objeto ).value = '';
}

function hideDiv( obj ) {
	obj = document.getElementById( obj );
	obj.style.visibility = 'hidden';
}

function showDiv( obj ) {
		obj = document.getElementById( obj );
		obj.style.visibility = 'visible';
}

function showFloatingDiv( objetoPole, objetoMostrar, x, y ) {
	if( y == null)
		y = 0;
	
	if( x == null)
		x = 0;
	
	mostrar = getObj( objetoMostrar );
	objetoPole = getObj( objetoPole );
	
	mostrar.style.left= Left( objetoPole );
	mostrar.style.top= Top( objetoPole ) + objetoPole.offsetHeight + y;
	mostrar.style.display='';
	mostrar.style.visibility = 'visible';
}

function getObj(objID) {
    if (document.getElementById) {return document.getElementById(objID);}
    else if (document.all) {return document.all[objID];}
    else if (document.layers) {return document.layers[objID];}
}


function Left(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function Top(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function lcs2( ielem ) {
	getObj('divInfo01800').style.left=Left(ielem);
	getObj('divInfo01800').style.top=Top(ielem)+ielem.offsetHeight - 50;
	getObj('divInfo01800').style.display='';
	return;
}

function lcsclose() {
	getObj('divInfo01800').style.display='none';
}

function muestraPopUpFlotante( objAttatchTo, objToShow, x, y ) {
	
	var left, top, objBase, objShown, _x, _y ;
	var px = document.layers ? "" : "px";
	
	if( x != null )
		_x = x
	else
		_x = 0;
	
	if( y != null )
		_y = y
	else
		_y = 0;
	
	
	objBase = dojo.byId( objAttatchTo );
	left = Left( objBase ) + _x;
	top = Top( objBase ) + objBase.offsetHeight - 50 + _y;
	
	objShown = dojo.byId( objToShow );
	objShown.style.left = left + px;
	objShown.style.top = top + px;
	objShown.style.display='';
}

function escondePopUpFlotante( objToHide ) {
	objHidden = dojo.byId( objToHide );
	objHidden.style.display='none';
}

function attachObject( objAttatchTo, objToShow, x, y ) {
	var left, top, objBase, objShown, _x, _y ;
	var px = document.layers ? "" : "px";
	
	if( x != null )
		_x = x
	else
		_x = 0;
	
	if( y != null )
		_y = y
	else
		_y = 0;
	
	objBase = dojo.byId( objAttatchTo );
	objShown = dojo.byId( objToShow );
	
	if (!isNaN(x))
		left = Left( objBase ) + _x;

	if (!isNaN(y))
		top = Top( objBase ) + objBase.offsetHeight - 50 + _y;
	
	if (!isNaN(x))
		objShown.style.left = left+px;
	
	if (!isNaN(y))
		objShown.style.top = top+px;
	//objShown.style.display='';
}

function MM_openBrWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}

function findBaseUrl(https) {
	url = location.hostname + findBasePath();
	
	if (https != undefined)
	{
		if (!https)
			url = "http://" + url;
		else
			url = "https://" + url;
		
	}
	return url;
}

function findBasePath( https )
{
	// Supone que el html del archivo base está en el directorio /pages
	var path = location.pathname.replace(/\/pages\/.*$/, "");
	if (path == location.pathname)
	{
		path = location.pathname.replace(/\/[^\/]*$/, "");
	}
	
	return path;
}

function showPopupBanner(id_banner, id_popup, type, xadd, yadd) {
	var px = document.layers ? "" : "px";
	
	if (type == 0) {
		if (id_banner != '')
			attachObject(id_banner,id_popup, xadd, yadd);
		else {
			if (!isNaN(xadd))
				dojo.byId( id_popup ).style.left = xadd + px;
			if (!isNaN(yadd))
				dojo.byId( id_popup ).style.top = yadd + px;
		}
		//$("#"+id_popup).show("normal");
		dojo.byId( id_popup ).style.display='block';
	} else if (type == 1) {
		obj = document.getElementById(id_popup);
		obj.style.visibility = 'visible';
	}
}

function hidePopupBanner(id_popup, type) {
	if (type == 0) {
		//$("#"+id_popup).hide("slow");
		dojo.byId( id_popup ).style.display='none';

	} else if (type == 1) {
		obj = document.getElementById(id_popup);
		obj.style.visibility = 'hidden';
	}
}

function logEntrada() {
	if (!fgLogLoaded) {
		fgLogLoaded = true;
		re_hostname = new RegExp(location.hostname);

		if (!re_hostname.test(document.referrer) && dojo.byId('frmLogEntrada') != undefined) {
			dojo.byId('hidUrlLE').value = document.referrer;
			dojo.xhrPost({
		        url: findBasePath() + '/dojo_php_imp/log_entrada.php',
		        handleAs: "text",
		        error: errorFunction,
		        form: 'frmLogEntrada',
				handle: function(data,args){
				}
		   });
		}
	}
}

dojo.addOnLoad(logEntrada);
