function enterlogin(event) {
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if (keyCode == 13) {
		procesalogin();
		}
}

function enterbuscar(event) {
}

function changelanguage() {
		if (typeof idinterval!='undefined') paratimer();
		var idioma=document.getElementById('languages').value;
		document.cookie="locale="+escape(idioma);
		if (document.getElementById('languagesfoot'))
		{
		 document.getElementById('languagesfoot').value=idioma;
		}
		actualizaidioma(idioma);
}

function changelanguagefoot() {
		if (typeof idinterval!='undefined') paratimer();
		var idioma=document.getElementById('languagesfoot').value;
		document.cookie="locale="+escape(idioma);
		if (document.getElementById('languages'))
		{
			document.getElementById('languages').value=idioma;
		}
		actualizaidioma(idioma);
}

function actualizaidioma(idioma) { 
	ajax=objetoAjax();
	ajax.open("GET", "./write_language.php?language=" + idioma);	
	ajax.onreadystatechange=function() {
	if (ajax.readyState==4) {
 			var resul = ajax.responseText;
 			window.location.reload();
		}
	}
	ajax.send(null);
}

function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
			
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function bye() {
	document.cookie="ckiduser="+" ";
	window.location.replace('./home.php');
} 

function procesalogin() {
 if (validarlogin()) {	
 		entrar()
 	}
}

function validarlogin() {
  var login = document.frmlogin.login.value;
  var clave = document.frmlogin.pass.value;
	for (j = 0; j < login.length; j++) {
		if (login.charAt(j) == '%' ) return false;
	}
	for (j = 0; j < clave.length; j++) {
		if (clave.charAt(j) == '%' ) return false;
	}
	return true;
}

function objetoAjax(){
		var xmlhttp=false;
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp = false;
	  		}
		}
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		return xmlhttp;
}

function popup(url, w, h) {
	newWindow = window.open(url,'popupWindow','width=' + w + ',height=' + h + ',menubar=no,toolbar=no,location=no,bookmarks=no,status=no,scrollbars=yes,resizable=yes');
	if (window.focus) {
		newWindow.focus();
	}
}

function utf8_decode ( str_data ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // *     example 1: utf8_decode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
 
    var string = "", i = 0, c = c1 = c2 = 0;
 
    while ( i < str_data.length ) {
        c = str_data.charCodeAt(i);
        if (c < 128) {
            string += String.fromCharCode(c);
            i++;
        } else if((c > 191) && (c < 224)) {
            c2 = str_data.charCodeAt(i+1);
            string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
 
    return string;
}

function utf8_encode ( str_data ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
 
    str_data = str_data.replace(/\r\n/g,"\n");
    var utftext = "";
 
    for (var n = 0; n < str_data.length; n++) {
        var c = str_data.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;
}

function showvideo() {
	// oculta el ventanuco
	map.getInfoWindow().hide();	
	document.getElementById("Video").style["visibility"] = "visible";
	// poner el video
	//paratimer();
	div2 = document.getElementById('videostream');
	ajax=objetoAjax();
	ajax.open("GET", "./read_video.php?&iduser="+useractual);	
	ajax.onreadystatechange=function() {
	if (ajax.readyState==4) {
 			var resul = ajax.responseText;
	   	if (resul!="") {
	   			datos = eval(resul);
				document.getElementById("videostream").innerHTML = "&nbsp;"+datos[0].urlvideo;
				}
				//activatimer();
			}
	}
	ajax.send(null);

}          

function closevideo() {
		div2 = document.getElementById('videostream')
		div2.innerHTML = "";
		document.getElementById("Video").style["visibility"] = "hidden";
} 

function goURI(href){window.location.href=href;}

function setTimeZoneCookie() {
	var rightNow = new Date();
	var date1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
	var date2 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0);
	var temp = date1.toGMTString();
	var date3 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	var temp = date2.toGMTString();
	var date4 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	var hoursDiffStdTime = (date1 - date3) / (1000 * 60 * 60);
	var hoursDiffDaylightTime = (date2 - date4) / (1000 * 60 * 60);

	if (hoursDiffDaylightTime == hoursDiffStdTime) {
	  //alert("Time zone is GMT " + hoursDiffStdTime + ".\nDaylight Saving Time is NOT observed here.");
	} else {
	   hoursDiffStdTime = hoursDiffStdTime +1;
	  //alert("Time zone is GMT " + hoursDiffStdTime + ".\nDaylight Saving Time is observed here.");
	}

	if (!Get_Cookie('zonahorarialocal')) {
		document.cookie="zonahorarialocal="+hoursDiffStdTime;
		window.location.reload();
	}
	else	{
		var zona = Get_Cookie('zonahorarialocal');
		if (zona!=hoursDiffStdTime)	{
				//alert('0');
				document.cookie="zonahorarialocal="+hoursDiffStdTime;
				window.location.reload();
				}
		else {
		}
	}
}
