// JavaScript Document

var urlLogin = "";

//---------transicion banner---------
var Images=new Array();
for (var i=0; i<=9; i++){
	Images[i]=new Image();
	Images[i].src="images/index/banner"+i+".jpg";
	//alert("images/index/banner"+i+".jpg");
}

function mas1(){
var t=setTimeout("mas()",1200);	
}

function mas2 (){
    j=j+1;
	if (j<=9){
			document.getElementById("ima").src=Images[j].src;	
	}else{
		j=1;
		document.getElementById("ima").src=Images[j].src;
	}
}

function menos (){
    j=j-1;
	if (j>=1){
			document.getElementById("ima").src=Images[j].src;	
	}else{
		j=9;
		document.getElementById("ima").src=Images[j].src;
	}
}

var j=0;
function mas (){
    /*j=j+1;
	if (j<=9){
			document.getElementById("ima").src=Images[j].src;		
	}else{
		j=1;
		document.getElementById("ima").src=Images[j].src;					
	}*/
	
	document.getElementById("ima").src=Images[j].src;
	j++;
	var t=setTimeout("mas()",5000);
}

function reLocateTo(obj){
	var $v = $(obj);
	var img = $v.find("img").attr("src");
	var pks = img.split("/");
	var name = (pks[pks.length - 1]).replace(".jpg", "");
	//alert($v.attr("href") + "?show=" + name);
	if(name != "banner0")
		location = $v.attr("rel") + "?show=" + name;
	
	return false;
}

//-------------validador formularios busqueda y cobertura----------------
function validar(cual){
	 if(cual==1){
	if(document.f1.estado.value==""){
		alert ("Para poder continuar es necesario que seleccione un producto o servicio.");
  }else{
	    window.location="cobertura.php?mostrar="+document.f1.estado.value;
  }}else{
	if(document.buscador.termino_buscar.value==""){
		alert ("El campo de búsqueda esta vacío.");
  }else{
	  document.buscador.submit();
   }  	  
} }


//-----------------Validador ingreso---------------------
function ingresar(){
	if(document.ingreso.cuenta.value=="" || document.ingreso.pw.value==""){
		 alert ("Para poder ingresar al sistema es necesario que proporcione los campos de Cuenta y Contraseña.");
	}else{
		
	   cuenta = encode_base64(document.ingreso.cuenta.value);	
	   pw = encode_base64(document.ingreso.pw.value);
		//texto = document.getElementById('texto');
		//texto.innerHTML = "http://192.168.170.25/Maxcom/MaxcomBillingBridge.aspx?cta="+cuenta+"&pass="+pw;
	   	//window.location = "http://192.168.170.25/Maxcom/MaxcomBillingBridge.aspx?cta="+cuenta+"&pass="+pw;
		window.location = "http://www.maxcom.com/Portal/MaxcomBillingBridge.aspx?cta="+cuenta+"&pass="+pw;
	}
}

/*$(document).ready(function() {
    $.get("http://"+window.location.host+"/loginparam.html", function(data) {
        var fileDom = $("<p>ddddd</p>").html();
		//alert(fileDom.find("p"))
        fileDom.find('p').each(function() {
            alert($(this).text());
        });
    });
});*/


function encode_base64( what )
{
	var base64_encodetable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
	var result = "";
	var len = what.length;
	var x, y;
	var ptr = 0;

	while( len-- > 0 )
	{
		x = what.charCodeAt( ptr++ );
		result += base64_encodetable.charAt( ( x >> 2 ) & 63 );

		if( len-- <= 0 )
		{
			result += base64_encodetable.charAt( ( x << 4 ) & 63 );
			result += "==";
			break;
		}

		y = what.charCodeAt( ptr++ );
		result += base64_encodetable.charAt( ( ( x << 4 ) | ( ( y >> 4 ) & 15 ) ) & 63 );

		if ( len-- <= 0 )
		{
			result += base64_encodetable.charAt( ( y << 2 ) & 63 );
			result += "=";
			break;
		}

		x = what.charCodeAt( ptr++ );
		result += base64_encodetable.charAt( ( ( y << 2 ) | ( ( x >> 6 ) & 3 ) ) & 63 );
		result += base64_encodetable.charAt( x & 63 );

	}

	return result;
}
