/**
	YUALAH ATLAS
	@version    1.0
	@author     Roberto González Vázquez
	@copyright  Yualah informatica CB, yualah.com  <info@yualah.com>
*/

ATLAS =
{
	Id_className: function (id, class_name)
	{
		var obj = document.getElementById(id);
		if (obj) obj.className=class_name;
	},

	Id_display_block: function (id)
	{
		var obj = document.getElementById(id);
		if (obj) obj.style.display='block';
	},

	Id_display_none: function (id)
	{
		var obj = document.getElementById(id);
		if (obj) obj.style.display='none';
	},

	Id_innerHTML: function (id, text)
	{
		var obj = document.getElementById(id);
		if (obj) obj.innerHTML=text;
	},

	List_select: function (title_id, new_id,  old_id)
	{
		this.Id_className(old_id,'');

		var neo = document.getElementById(new_id);

		if (neo)
		{
			neo.className ='selected';
			this.Id_innerHTML(title_id, neo.innerHTML);
		}
	},


	Form_get : function (obj)
	{
		//var tag= obj.tagName.toLowerCase();
		var tag = obj.tagName.toLowerCase()
		var type= obj.type.toLowerCase();

		if (type=='text' || type=='password' || type=='hidden' || tag=='textarea' )
			return obj.value;

		else if (type=='checkbox')
		{
			return (obj.checked)?obj.value:'';
		}

		else if (tag=='select'&& obj.selectedIndex>=0)
		{
			var opt=obj.options[obj.selectedIndex];
			return (ATLAS.Is_empty(opt.value)) ? opt.text:opt.value;
		}

		return null;
	},




	Form_set : function (obj, value)
	{
		var tag = obj.tagName.toLowerCase()
		var type= obj.type.toLowerCase();

		if (tag=='input' && type=='checkbox') obj.checked=value;

		else if (tag=='input' || tag=='textarea') obj.value=value;

		else (tag=='select')
		{
			var opt, val, i, end=obj.length;
			for (i=0; i<end; i++)
			{
				opt = obj.options[i];
				val = (ATLAS.Is_empty(opt.value)) ? opt.text:opt.value;
				if (val == value) { opt.selected = true; return; }
			}
        }
	},


	 Select_info: function (obj, id_info)
	{
	    var opt=obj.options[obj.selectedIndex];
	    document.getElementById(id_info).innerHTML = opt.title;
	},


	Is_empty :function (value)
	{
		if (value == undefined) 	return true;
		if (value.length<1)   		return true;
		return false;
	},


	Validate_string: function ( cadena )
	{
		if (ATLAS.Is_empty(cadena)) 				return false;
		if (cadena.replace(/^\s*|\s*$/g,"") =="") 	return false
		return true;
	},


	Validate_email: function (string)	{ return (string.search(/^[^@]+@[^@]+.[A-Za-z]{2,}$/i) != -1)},

	Trim_string: function ( cadena )	{ return cadena.replace(/^\s*|\s*$/g,"");},

	Select_field: function (form_field)
	{
		form_field.focus();
		form_field.select();

		if (document.all)
		{
			var rango=form_field.createTextRange()
			rango.execCommand("Copy");
		}
	},



	Swf: function ( id, url, width, height, flashvars, bg_color)
	{
		var fv_obj, fv_emb, html;

		if (flashvars)
		{
			var fv_obj="<param name='FlashVars' value='"+flashvars+"' id='"+id+"_fo'>";
			var fv_emb="FlashVars='"+flashvars+"'";
		}
		else fv_obj=fv_emb='';

		if (!bg_color) bg_color='ffffff';


		html 	= "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' "
				+ "codebase='http://fpdownload.adobe.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' "
				+ "width='"+width+"' height='"+height+"' id='"+id+"' align='middle'>"
				+ "<param name='allowScriptAccess'	value='sameDomain' >"
				+ "<param name='movie' 				value='"+url+"'>"
				+ "<param name='quality' 			value='high'></param>"
				+ "<param name='bgcolor' 			value='#"+bg_color+"' >"
				+ "<param name='wmode' 				value='transparent' >"
				+ fv_obj
				+ "<embed src='"+url+"' name='"+id+"' id='{$id}_e'"
				+ "quality='high' bgcolor='#"+bg_color+"' width='"+width+"' height='"+height+"' "+fv_emb+" "
				+ "align='middle' allowScriptAccess='sameDomain' wmode='transparent' "
				+ "type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' ></object>";

		return html;
	},

	Match: function (pattern, str)
	{
		pattern=pattern.replace(/\\/g,'\\\\');
		pattern=pattern.replace(/\./g,'\\.');
		pattern=pattern.replace(/\+/g,'\\+');
		pattern=pattern.replace(/\^/g,'\\^');
		pattern=pattern.replace(/\$/g,'\\$');
		pattern=pattern.replace(/\(/g,'\\(');
		pattern=pattern.replace(/\)/g,'\\)');
		pattern=pattern.replace(/\{/g,'\\{');
		pattern=pattern.replace(/\}/g,'\\}');
		pattern=pattern.replace(/\!/g,'\\!');
		pattern=pattern.replace(/\*/g,'.*');
		pattern=pattern.replace(/\|/g,'.');
		pattern=pattern.replace(/\</g,'(');
		pattern=pattern.replace(/\>/g,')?');


		var reg   = new RegExp('^'+pattern+'$');
		return null != reg.exec(str);
		//return pattern + ' === '+ str + ' ::: '+ (null != reg.exec(str));
	},


	On_focus :function (obj)
	{
		switch (obj.className)
		{
			case 'field_text'	: obj.className = 'field_text_focus'	; break;
			case 'field_area'	: obj.className = 'field_area_focus'	; break;
			//case 'field_lista'	: obj.className = 'field_lista_focus'	; break;
		}


	},

	On_blur:function (obj)
	{
		switch (obj.className)
		{
			case 'field_text_focus'	: obj.className = 'field_text'	; break;
			case 'field_area_focus'	: obj.className = 'field_area'	; break;
			case 'field_list_focus'	: obj.className = 'field_list'	; break;
		}
	},

	Remove_message: function()
	{
		//$("#atlas_avisos").fadeTo(800, 0.4).fadeTo(800, 1).fadeTo(800, 0.4).fadeTo(800, 1);
		//$("#atlas_avisos").animate({ height: 'hide', opacity: 'hide' }, 1000);
		$("#atlas_messages").fadeTo(2000,0.01);

	},

	Virtual_key: function (id, text)
	{
		var e=document.getElementById(id);
		a= "aa";

		if (text=='')
			 e.value = e.value.substring(0, e.value.length-1);
		else e.value = ""+e.value+text;
	},

	lang:'es',

	Set_lang: function (lang)
	{
	    ATLAS.lang = lang;
	    TX_DATE.Init();
	}
};








/**
    Basic date functions
    @copy   copyright (c) Yualah Informatica C.B.
    @author Roberto Gonzalez Vazquez -  yualah.com
*/
DATE =
{
    Is_leap_year : function (year)
    {
        if (typeof(year)=='object')  return this.Is_leap_year(year.getFullYear());

        if (year %400 == 0) return true;
        if (year %100 == 0) return false;
        if (year %4   == 0) return true;
        return false;
    },


    Month_days : function  (year, month)
    {
        if (typeof(year)=='object')  return this.Month_days(year.getFullYear(), year.getMonth());

        if (month==2) return (this.Is_leap_year(year))?29:28;
        if (month==4 || month==6 || month==9 || month==11) return 30;
        return 31;
    },

    Clone : function (src, dst)
    {
        dst.setFullYear(src.getFullYear(), src.getMonth   (), src.getDate    ());
    },


    Iso : function (iso_date, dst_obj)
    {
        var txt = iso_date.split("-");
        dst_obj.setFullYear(txt[0], (-1)+parseInt(txt[1],10), txt[2]);
    },


    New_iso:function (text)
    {
        var txt = text.split("-");
        return new Date ( txt[0], (-1)+parseInt(txt[1],10), txt[2]);
    },


    Calc_week: function (date_obj)
    {
        var first=new Date(date_obj);
        first.setMonth (0);
        first.setDate  (1);
        var day = ((first.getDay()+6)%7)*86400000;


        return Math.floor((date_obj.getTime()-first.getTime()+((first.getDay()+6)%7)*86400000)/604800000)+1;
    }

};








/**
    TX_DATE ytx para fechas
    @copy   copyright (c) Yualah Informatica C.B.
    @author Roberto Gonzalez Vazquez -  yualah.com
*/
TX_DATE =
{
    days:null,
    meses:null,
    days_2:null,
    months_3:null,
    week     :'',
    today:'',
    format:'',

    Init: function ()
    {
        this.format = 'd/m/Y';
        this.jq_format = 'DD, dd MM yy';
        this.close     = 'Cerrar';
        this.previous  = 'Ant';
        this.next      = 'Sig';

        switch (ATLAS.lang)
        {


            case 'gl':
                this.days     = ["domingo", "luns", "martes", "mércores", "xoves", "venres", "sábado"];
                this.months   = ["xaneiro", "febreiro", "marzo", "abril", "maio", "xuño", "xullo", "agosto", "setembro", "outubro", "novembro", "decembro"];
                this.days_2   = ['Do','Lu', 'Ma', 'Me', 'Xo', 'Ve', 'Sa', 'Do'];
                this.months_3 = ['xan', 'feb', 'mar', 'abr', 'mai', 'xuñ', 'xul', 'ago', 'set', 'out', 'nov', 'dec'];
                this.week     = 'Semana';
                this.today    = 'Hoxe';
                this.close    = 'Cerrar';
                this.previous = 'Ant';
                this.next     = 'Sig';

                break;

            case 'en':
                this.days     = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
                this.months   = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
                this.days_2   = ['Su','Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'];
                this.months_3 = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
                this.week     = 'Week';
                this.today    = 'Today';
                this.format   = 'm/d/Y';
                this.jq_format = 'DD, MM dd yy';
                this.close    = 'Close';
                this.previous = 'Prev';
                this.next     = 'Next';
                break;

            case 'pt':
                this.days     = ["domingo", "segunda-feira", "terça-feira", "quarta-feira", "quinta-feira", "sexta-feira", "sábado"];
                this.months   = ["janeiro", "fevereiro", "março", "abril", "maio", "junho", "julho", "agosto", "setembro", "outubro", "novembro", "dezembro"];
                this.days_2   = ['Do','Se', 'Te', 'Qa', "Qi", "Sx", "Sa", "Do"];
                this.months_3 = ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'];
                this.week     = 'Semana';
                this.today    = 'Hoje';
                this.close    = 'Cerrar';
                this.previous = 'Ant';
                this.next     = 'Seg';
                break;

            case 'ca':
                this.days     = ["diumenge", "dilluns", "dimarts", "dimecres", "dijous", "divendres", "dissabte"];
                this.months   = ["gener", "febrer", "març", "abril", "maig", "juny", "juliol", "agost", "setembre", "octubre", "novembre", "desembre"];
                this.days_2   = ['Di','Lu', 'Ma', 'Me', 'Jo', 'Ve', 'Sa', 'Di'];
                this.months_3 = ['gen', 'feb', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'oct', 'nov', 'des'];
                this.week     = 'Setmana';
                this.today    = 'Avui';
                this.close    = 'Cerrar';
                this.previous = 'Ant';
                this.next     = 'Sig';
                break;

            case 'de':
                this.days     = ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"];
                this.months   = ["Januar", "Februar", "März", "April", "Mag", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"];
                this.days_2   = ['So','Mo','Di','Mi','Do','Fr','Sa','So'];
                this.months_3 = ['Jan','Feb','Mar','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'];
                this.week     = 'Woche';
                this.today    = 'Heute';
                this.format   = 'm/d/Y';
                this.jq_format = 'DD, MM dd yy';
                this.close    = 'Close';
                this.previous = 'Prev';
                this.next     = 'Next';
                break;

            case 'fr':
                this.days     = ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"];
                this.months   = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"];
                this.days_2   = ['Di','Lu','Ma','Me','Je','Ve','Sa','Di'];
                this.months_3 = ['Jan','Fev','Mar','Avr','Mai','Jun','Jul','Aou','Sep','Oct','Nov','Dec'];
                this.week     = 'Semaine';
                this.today    = "Aujourd&apos;hui";
                this.close    = 'Close';
                this.previous = 'Prev';
                this.next     = 'Next';
                break;

            case 'it':
                this.days     = ["Domenica", "Lunedi", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato"];
                this.months   = ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"];
                this.days_2   = ['Do','Lu',';Ma','Me','Gi','Ve','Sa','Do'];
                this.months_3 = ['Gen','Feb','Mar','Apr','Mag','Giu','Lugl','Ago','Set','Ott','Nov','Dic'];
                this.week     = 'Settimana';
                this.today    = 'Oggi';
                this.close    = 'Close';
                this.previous = 'Prev';
                this.next     = 'Next';
                break;


            case 'es':
            default:
                this.days     = ["domingo", "lunes", "martes", "miércoles", "jueves", "viernes", "sábado"];
                this.months   = ["enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"];
                this.days_2   = ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa', 'Do'];
                this.months_3 = ['ene', 'feb', 'mar', 'abr', 'may', 'jun', 'jul', 'ago', 'sep', 'oct', 'nov', 'dic'];
                this.week     = 'Semana';
                this.today    = 'Hoy';
                this.close    = 'Cerrar';
                this.previous = 'Ant';
                this.next     = 'Sig';
                break;

        }
    },

    Full: function (date)
    {
        var week    = date.getDay     ();
        var day     = date.getDate    ();
        var month   = date.getMonth   ();
        var year    = date.getFullYear();

        return this.days[week] + ', '+this.Normal(date);
    },


    Normal: function (date)
    {
        var week    = date.getDay     ();
        var day     = date.getDate    ();
        var month   = date.getMonth   ();
        var year    = date.getFullYear();
        switch (ATLAS.lang)
        {
            case 'ca':  return day + ((month==3 || month==7 || month==9)? " d'" :' de ') + this.months[month]+ ' de '+ year ;

            case 'en':
            case 'de':  return this.months[month]+' '+dia+','+ year ;


            case 'fr':
            case 'it':  return day + ' ' + this.months[month] + ' ' + year ;

            case 'es':
            case 'gl':
            case 'pt':
            default:    return day + ' de ' + this.months[month] + ' de ' + year ;
        }
    },


    Short:function  (date)
    {
        var day   = date.getDate    ();
        var month = date.getMonth   ()+1;
        var year  = date.getFullYear();

        if (day<10)   day='0'+day;
        if (month<10) month='0'+month;


        switch (this.format)
        {
            case 'd-m-Y':   return day   +'-'+ month  +'-'+ year;
            case 'm-d-Y':   return month +'-'+ day    +'-'+ year;
            case 'd/m/Y':   return day   +'/'+ month  +'/'+ year;
            case 'm/d/Y':   return month +'/'+ day    +'/'+ year;
            case 'd.m.Y':   return day   +'.'+ month  +'.'+ year;
            case 'm.d.Y':   return month +'.'+ day    +'.'+ year;
            case 'Y-m-d':
            default:        return year  +'-'+ month  +'-'+ day;
        }
    }

};











/**
	Timer controler
	@copy   copyright (c) Yualah Informatica C.B.
	@author Roberto Gonzalez Vazquez -  yualah.com
*/
TIMER =
{
	obj:null,
	js:'',
	timeout:null,


	Eval: function ()
	{
		var aux_js=this.js;
		var err;
		this.Clear();

		try { if (aux_js!='') eval(aux_js);	} catch(err) {}
	},

	Clear: function ()
	{
		clearTimeout(this.timeout);
		this.js='';
	},

	Set : function(js, time, obj)
	{
		this.Timer_eval();

		this.js  = js;
		this.obj = obj
		setTimeout("YH_TIMER.Eval()", time);
	},

	Reset : function(js, time, obj)
	{
		if (obj==this.obj && js==this.js) return;
		if (obj!=this.obj)
			 this.Eval ();
		else this.Clear();

		this.js = js;
		this.obj = obj;
		setTimeout("YH_TIMER.Eval()", time);
	},


	Set_css: function  (obj,class_name,time)
	{
		if (time==null) time=200;
		this.Reset('YH_TIMER.obj.className="'+class_name+'"', time, obj);
	}
}



ATLAS.Set_lang('es');

