var Ocu = 
{
	SetHomePage : function()
	{
		if (document.all)
		{
			document.body.style.behavior = "url(#default#homepage);";
			document.body.setHomePage("http://www.ocu.org");
		}
		else if(navigator.appName.indexOf("Opera")!=-1)
		{
		   // Opera
		   var msg = "Ir a Herramientas > Preferencias > General y presionar 'usar pagina actual'";
		   alert(msg);
		}
		else if (document.getElementById)
		{
           var msg = "Arrastre este hipervinculo hacia el boton de inicio de su navegador.";
           alert(msg);
		}
	}
	,
	AddToBookmarks : function()
	{
		var title = "Organizacion de Consumidores y Usuarios";   
		var url = "http://www.ocu.org";  
		if (window.sidebar) 
		{ 
			// Mozilla Firefox Bookmark		
			window.sidebar.addPanel(title, url,"");	
		} 
		else if( window.external )
		{ 
			// IE Favorite		
			window.external.AddFavorite(url, title); 
		}	
		else if(window.opera && window.print)
		{
		   // Opera 
		   var bkmark = document.createElement('a');
		   bkmark.setAttribute('rel','sidebar');
		   bkmark.setAttribute('href', url);
		   bkmark.setAttribute('title', title);
		   bkmark.click();
		}
		else
		{ 
			alert("Añada de forma manual a favoritos / Marcadores.");
		} 
	}
	,
	CreateCookie : function (name,value,days) 
	{
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	,
	ReadCookie : function (name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	,
	EraseCookie : function (name) 
	{
		Ocu.CreateCookie(name,"",-1);
	}
}


function OnDocumentLoaded()
{
	document.loaded = true;
}

Events.Add(window, "load", OnDocumentLoaded);


/*********************************************************
*                                                        *
*   FUNCIONES DE TRATAMIENTO DE TEXTO                    *
*                                                        *
**********************************************************/
function LTrim(texto) {

    var bResult = true;
    
    while (bResult) {
        bResult = false;
        if (texto.length > 0) {
            if (texto.charAt(0) == " ") {
                texto = texto.substr(1);
                bResult = true;
            }
        }
    }
    
    return texto;
}

function RTrim(texto) {

    var bResult = true;
    
    while (bResult) {
        bResult = false;
        if (texto.length > 0) {
            if (texto.charAt(texto.length - 1) == " ") {
                texto = texto.substr(0, texto.length - 1);
                bResult = true;
            }
        }
    }
    
    return texto;
}

function Trim(texto) {
    return RTrim(LTrim(texto));
}


/*********************************************************
*                                                        *
*   FUNCIONES DE VALIDACION                              *
*                                                        *
**********************************************************/
function ValidarDNI(value) {
	var texto = value.substr(0, 1).toUpperCase() == "X" ? value.substr(1) : value;
	var numero = texto.substr(0, texto.length-1);
	var letra = texto.substr(texto.length - 1);
	return ValidarNIFNIE(numero, letra);
}

function ValidarNIFNIE(numero, letra) {
	var charControl = "TRWAGMYFPDXBNJZSQVHLCKE";
	var resultado = false;

	if ((!isNaN(numero)) && (letra.length == 1)) {
		var pos = parseInt(numero) % 23;
		if (charControl.substr(pos, 1) == letra.toUpperCase()) {
			resultado = true;
		}
	}
	return resultado;
}

function ValidarEmail(value) {

	var patron = "^[A-Z0-9\-a-z]+@[A-Z0-9a-z]+\.[a-zA-Z]{2,3}$";
	var regExpresion = new RegExp(patron);
	var resultado = regExpresion.test(value);
	return resultado;
}
var onlyonebarra = false;
function getbarra() {
    
    var salida = "";
    var url = encodeURI(document.URL);
    var title = encodeURI(document.title);
    //var title="prueba"

    var fcb = "http://www.facebook.com/sharer.php?u=URL&t=TITLE";
    var twt = "http://twitter.com/share?url=URL&via=consumidores&text=TITLE&lang=es";
    var mnm = "http://meneame.net/submit.php?url=URL";
    var del = "http://meneame.net/submit.php?url=URL";
    fcb = fcb.replace("URL", url).replace("TITLE", title).replace("ocu.spain.conseur.org", "www.ocu.org");
    twt = twt.replace("URL", url).replace("TITLE", title).replace("ocu.spain.conseur.org", "www.ocu.org");
    mnm = mnm.replace("URL", url).replace("TITLE", title).replace("ocu.spain.conseur.org", "www.ocu.org");
    url = url.replace("URL", url).replace("TITLE", title).replace("ocu.spain.conseur.org", "www.ocu.org");

    if (onlyonebarra == false) {
        salida = salida + '<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>';
    
    }    
    salida =salida+ "<div class='SocialBar'><span><strong>Compartir:</strong></span>";

    salida = salida + "<a  target='_blank' class='fac' rel='nofollow' title=\"compartir en facebook\"  href='" + fcb + "'>";
    salida = salida + "</a>";
    salida = salida + "<a target='_blank' rel='nofollow' title='compartir en twitter' class='twi' href='" + twt + "'>";
    salida = salida + "</a>";
    salida = salida + "<a target='_blank' rel='nofollow' title='compartir en meneame' class='men' href='" + mnm + "'>";
    salida = salida + "</a>";

    salida = salida + "<a title='Agregar a mi Delicious' onclick=\"window.open('http://www.delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=" + url + "&amp;title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;\" href='#' style=\"background:url('/site_images/SocialBar/iconos-sociales.png') repeat scroll -42px 17px transparent\"></a>";
    if (onlyonebarra == false) {
        salida = salida + "<script type='text/javascript' src='http://static.evernote.com/noteit.js'></script>";
    }
    salida = salida + "<a href='#' onclick=\"Evernote.doClip({styling:'full'}); return false;\" title='Guardar en Evernote'><img src='http://static.evernote.com/site-mem-16.png' alt='Clip to Evernote' /></a>";
    onlyonebarra = true;
/*
    salida = salida + "<script type='text/javascript' src='http://static.evernote.com/noteit.js'></script>";
    salida = salida + "<a href='#' onclick='Evernote.doClip({}); return false;'><img src='http://static.evernote.com/site-mem-16.png' alt='Clip to Evernote'></a>"
*/    
    salida = salida + "<a title='Leer después' style=\"background:url('/site_images/SocialBar/iconos-sociales.png') repeat scroll -87px 17px transparent\" href='mailto:?subject=leer en Ocu&amp;body=" + url + "' id='email-read-later'></a>"

    
    salida = salida + "<!-- Añade esta etiqueta en la cabecera o delante de la etiqueta body. -->"
    
    salida = salida + '<a href="#"><g:plusone size="small"></g:plusone></a>'
    salida = salida + "</div>";
    
    
    return salida;
}
