// JavaScript Document

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

function abrirVentana(url, width, height){
	window.open(url,'imprimir','width='+width+',height='+height+'menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=no');
}


function validaCorreo(valor) {
	var reg = /(^[a-zA-Z0-9._-]{1,30})@([a-zA-Z0-9.-]{1,30}$)/;
	if(reg.test(valor)) {
		return true;
	} else {
		return false;
	}
}

function numeros(e) { 
    tecla = (document.all) ? e.keyCode : e.which; 
    if (tecla==8) return true; //Tecla de retroceso (para poder borrar) 
    if (tecla==40 || tecla ==41 || tecla ==45) return true; //Teclas de (  ) - 
    patron = /\d/; // Solo acepta números 
    te = String.fromCharCode(tecla); 
    return patron.test(te);  
}

function offMensaje() {
	//document.getElementById('divTransparente').style.display = "none";
}

function onMensaje(sTexto) {
	//document.getElementById("divLeyendo").innerHTML = '<img src="images/lb-load.gif?v='+Math.random()+'" align="absmiddle" /><br><br>'+sTexto;
	//document.getElementById('divTransparente').style.display = "block";
}

function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}

function onDiv(divName) {
	if (trim(divName) == "") { return; }
	document.getElementById(divName).style.visibility = "visible";
}

function offDiv(divName) {
	if (trim(divName) == "") { return; }
	document.getElementById(divName).style.visibility = "hidden";
}

function CargaPagina(urlPagina, numPagina) {	
	onMensaje('UPC Technologies lo atiende...');
	var ajax = newAjax();
	urlPagina += ".php?r="+Math.random();
	if (numPagina) { urlPagina += "&pagina=" + numPagina; }
	ajax.open("POST", urlPagina, true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(null);
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4)	{				
			document.getElementById("divContenido").innerHTML = ajax.responseText;
			
		}	
		//offMensaje();
	}	
	
}


function Cerrar(){
	$("#SoporteCerrar").css("display","none");
	var ajax = newAjax();
	var sPost = "&cerrar=si";
	ajax.open("POST", "index.php?r="+Math.random(), true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(sPost);		
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4){
								
		}	
	}		
}


function setIdioma(idioma){
	$.ajax({
		url:  'includes/traduccion.php',
		type: 'POST',
		data: 'iniciar=1&idioma='+idioma,
		success: function(){
			window.location.reload();
		}
	});
}

function showChat(){
	window.open('http://mail.upccorporate.com:9090/webchat/userinfo.jsp?chatID=UxwfQc2NaS&workgroup=corporate@workgroup.mail.upccorporate.com','popup','toolbar=no,menubar=no,scrollbars=no,resizabsle=no,width=500,height=350');
}

function intranet(){
	document.location = 'es/intranet';
}

