﻿// JavaScript Document
// VARIABLES Y CONSTANTES
host="http://localhost/jmc/";
seleccionado=null;

	function resalta(elemento)
	{
		if((seleccionado!=null) && (elemento!=null) && (seleccionado!=elemento))
		{
			if(elemento.className=='item')
			{
				elemento.className='item_seleccionado';
			}else
			{
				elemento.className='item';		
			}
		}
	}

	function selecciona(elemento)
	{
		if(seleccionado!=null)
		{
			seleccionado.className="item";
		}
		elemento.className="item_seleccionado";
		seleccionado=elemento;
	}


function cargaAjaxId (url, id_contenedor)
{
	var pagina_requerida = false;
	$(id_contenedor).innerHTML="<p style='text-align:center'><img src='images/loading.gif' align='center' /></p>" ;

	new Ajax.Request(url, {
		method: 'get', 
		encoding: 'UTF-8',
		onSuccess: function(transport) {
			$(id_contenedor).innerHTML=transport.responseText;
		},	
		onComplete: function(transport) {
			$(id_contenedor).innerHTML=transport.responseText;
		},			
		onFailure: function(transport) {
			document.getElementById (id_contenedor).innerHTML="";
		}
	});	
}


function cargaAjaxIdColaboraciones (url, id_contenedor)
{
	var pagina_requerida = false;
	if (window.XMLHttpRequest)
	{
		// Si es Mozilla, Safari etc
		pagina_requerida = new XMLHttpRequest ();
	} else if (window.ActiveXObject)
	{
	// pero si es IE
	try 
	{
	pagina_requerida = new ActiveXObject ("Msxml2.XMLHTTP");
	}
	catch (e)
	{
	// en caso que sea una versión antigua
	try
	{
	pagina_requerida = new ActiveXObject ("Microsoft.XMLHTTP");
	}
	catch (e)
	{
	}
	}
	} 
	else
	return false;
	pagina_requerida.onreadystatechange = function ()
	{
	// función de respuesta
		cargarpaginaIdColaboraciones (pagina_requerida, id_contenedor);
	}
	pagina_requerida.open ('GET', url, true); // asignamos los métodos open y send
	pagina_requerida.send (null);
}


// todo es correcto y ha llegado el momento de poner la información requerida
// en su sitio en la pagina xhtml
function cargarpaginaId (pagina_requerida, id_contenedor)
{	
	if (pagina_requerida.readyState == 4 && (pagina_requerida.status == 200 || window.location.href.indexOf ("http") == - 1))
	{
		//document.getElementById (id_contenedor).innerHTML =utf8_decode(pagina_requerida.responseText);
		//document.getElementById (id_contenedor).innerHTML =pagina_requerida.responseText;
	}
}


function cargarpaginaIdColaboraciones (pagina_requerida, id_contenedor)
{	
	if (pagina_requerida.readyState == 4 && (pagina_requerida.status == 200 || window.location.href.indexOf ("http") == - 1))
	{
		texto=pagina_requerida.responseText;
		//while(texto.indexOf("%20")!=-1)
		//{
		//	texto=texto.replace(" ","cc");
		//}
		document.getElementById (id_contenedor).innerHTML = texto;
	}
}

// private method for UTF-8 decoding   
   function utf8_decode(utftext) {   
        var string = "";   
        var i = 0;   
        var c = c1 = c2 = 0;   
  
        while ( i < utftext.length ) {   
  
            c = utftext.charCodeAt(i);   
  
            if (c < 128) {   
                string += String.fromCharCode(c);   
                i++;   
            }   
            else if((c > 191) && (c < 224)) {   
                c2 = utftext.charCodeAt(i+1);   
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));   
                i += 2;   
            }   
            else {   
                c2 = utftext.charCodeAt(i+1);   
                c3 = utftext.charCodeAt(i+2);   
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));   
                i += 3;   
            }   
  
        }   
  
        return string;   
    }   


var Utf8 = {

    // public method for url encoding
    encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // public method for url decoding
    decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}


		function tooltip_ico(elemento)
		{
			elemento.src='images/idiomajapan_on.gif';
			if(!$("tooltip"))
			{
				textox="まもなくリニューアルオープン！";

				$("tool").innerHTML+="<div id='tooltip' style='position:absolute; background-color:#FFFDDE;border:1px solid #000; font-family:Helvetica, Arial; font-size:11px;'>"+textox+"</div>";
				array=Position.cumulativeOffset($("japones"));
				$("tooltip").style.top=(array[1]-40)+"px";
				if(BrowserDetect.browser.indexOf("Opera")!=-1)
				{
					$("tooltip").style.left=(array[0]+80)+"px";
				}else
				{
					$("tooltip").style.left=(array[0]-40)+"px";
				}
				$("tooltip").style.width="150px";
			}
		}
		
		function tooltip_ico_off(elemento)
		{
			elemento.src='images/idiomajapan.gif';
			if($("tooltip"))
			{
				$("tooltip").remove();
			}
		}		


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
