var Oper = new Array (
new Array ( 30000000 , 30289999 , "TIGO" ),
new Array ( 40000000 , 40999999 , "TIGO" ),
new Array ( 41000000 , 42999999 , "CLARO" ),
new Array ( 43000000 , 44759999 , "MOVISTAR" ),
new Array ( 44760000 , 46999999 , "TIGO" ),
new Array ( 47000000 , 47729999 , "CLARO" ),
new Array ( 47730000 , 48199999 , "TIGO" ),
new Array ( 48200000 , 48219999 , "UNITEL" ),
new Array ( 48220000 , 50099999 , "TIGO" ),
new Array ( 50100000 , 50199999 , "CLARO" ),
new Array ( 50200000 , 50299999 , "MOVISTAR" ),
new Array ( 50300000 , 50699999 , "TIGO" ),
new Array ( 50700000 , 51099999 , "MOVISTAR" ),
new Array ( 51100000 , 51399999 , "CLARO" ),
new Array ( 51400000 , 51499999 , "MOVISTAR" ),
new Array ( 51500000 , 51999999 , "TIGO" ),
new Array ( 52000000 , 52099999 , "TIGO" ),
new Array ( 52100000 , 52999999 , "MOVISTAR" ),
new Array ( 53000000 , 53099999 , "TIGO" ),
new Array ( 53100000 , 53119999 , "CLARO" ),
new Array ( 53120000 , 53139999 , "MOVISTAR" ),
new Array ( 53140000 , 53899999 , "TIGO" ),
new Array ( 53900000 , 54099999 , "MOVISTAR" ),
new Array ( 54100000 , 54999999 , "CLARO" ),
new Array ( 55000000 , 55099999 , "MOVISTAR" ),
new Array ( 55100000 , 55179999 , "CLARO" ),
new Array ( 55180000 , 55199999 , "MOVISTAR" ),
new Array ( 55210000 , 55299999 , "TIGO" ),
new Array ( 55310000 , 55399999 , "CLARO" ),
new Array ( 55400000 , 55429999 , "MOVISTAR" ),
new Array ( 55430000 , 55449999 , "CLARO" ),
new Array ( 55450000 , 55499999 , "MOVISTAR" ),
new Array ( 55500000 , 55539999 , "TIGO" ),
new Array ( 55540000 , 55799999 , "CLARO" ),
new Array ( 55800000 , 55819999 , "TIGO" ),
new Array ( 55820000 , 55999999 , "CLARO" ),
new Array ( 56000000 , 56089999 , "MOVISTAR" ),
new Array ( 56100000 , 56399999 , "CLARO" ),
new Array ( 56400000 , 56899999 , "MOVISTAR" ),
new Array ( 56900000 , 56999999 , "CLARO" ),
new Array ( 57000000 , 57099999 , "TIGO" ),
new Array ( 57100000 , 57189999 , "CLARO" ),
new Array ( 57190000 , 57899999 , "TIGO" ),
new Array ( 57900000 , 57999999 , "MOVISTAR" ),
new Array ( 58000000 , 58099999 , "TIGO" ),
new Array ( 58100000 , 58189999 , "CLARO" ),
new Array ( 58190000 , 58199999 , "TIGO" ),
new Array ( 58200000 , 58799999 , "CLARO" ),
new Array ( 58800000 , 59099999 , "TIGO" ),
new Array ( 59100000 , 59149999 , "CLARO" ),
new Array ( 59150000 , 59179999 , "MOVISTAR" ),
new Array ( 59180000 , 59199999 , "TIGO" ),
new Array ( 59200000 , 59899999 , "CLARO" ),
new Array ( 59900000 , 59999999 , "TIGO" )
);


function ValidarOperador (numero){
	for (p in Oper){
		if (numero >= Oper[p][0] && numero <= Oper[p][1])
			return Oper[p][2];
	}  
	return "";
}

function foper(qnum){
	if (qnum.length > 3) {
		switch (qnum.length) {
			case 4:
				qnum = qnum *10000;
				operador = ValidarOperador(qnum);
				return operador;
				break;
			case 5:
				qnum = qnum *1000;
				operador = ValidarOperador(qnum);
				return operador;
				break;
			case 6:
				qnum = qnum *100;
				operador = ValidarOperador(qnum);
				return operador;
				break;
			case 7:
				qnum = qnum *10;
				operador = ValidarOperador(qnum);
				return operador;
				break;
			case 8:
				qnum = qnum *1;
				operador = ValidarOperador(qnum);
				return operador;
				break;
			default:
				alert("saber");
				return "otro";
				break;
		}
	}
	return "otro";
}

var c=0;
var speed=500;
var bl=0;

function blink(cell){
	if(c%2==0) {
		cell.style.backgroundColor='red';
	}
	else {
		cell.style.backgroundColor='#E9E9E9';
	}
	c++;
	cello=cell;
	bl=setTimeout('blink(cello)',speed);
}


function qoper() {
	qnum = document.lpsend.lppara.value
	opera = foper(qnum);	
	clearTimeout(bl);
	cell = document.getElementById('tigob')
	cell.style.backgroundColor='#E9E9E9';
	cell = document.getElementById('movib')
	cell.style.backgroundColor='#E9E9E9';
	cell = document.getElementById('clarob')
	cell.style.backgroundColor='#E9E9E9';
	switch (opera) {
			case 'TIGO':
				blink(document.getElementById('tigob'));
				break;
			case 'MOVISTAR':
				blink(document.getElementById('movib'));
				break;	    
			case 'CLARO':
				blink(document.getElementById('clarob'));
				break;
			default: 
				break;
	}
	return "";
}


function openFrame (url,id,idiframe,altop,anchop){
	document.getElementById(id).style.display = 'inline';
	document.getElementById(idiframe).src=url;
	document.getElementById(idiframe).style.height=altop;
	document.getElementById(idiframe).style.width=anchop;
}

function getCookie(name){
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

function PopForm (from,numero,nombre){

	var res = ValidarOperador (numero);
	var div = document.getElementById('textform');
	var url ="";
	switch (res){
			case 'TIGO':
				url = 'http://www2.tigo.com.gt/mensajito';
				anchop='328px';
				altop='485px';
				break;
			case 'MOVISTAR':
				url = 'http://www.corporativo.telefonica.com.gt/EnviarSMSGT/faces/EnviarSMS2.jsp';
				window.open(url,'mywindow','width=225,height=285');
				anchop='225px';
				altop='285px';
				anchop2='600px';
				altop2='50px';
				url2 = 'http://www.sagastume.com/movipop.html';
				openFrame (url2,'eexterno','eexterno',altop2,anchop2);					
				break;	    
			case 'CLARO':
				url = 'http://mensajes.claro.com.gt/mensaje_claro.php';
				window.open(url,'mywindow','width=225,height=275');
				anchop='225px';
				altop='275px';
				anchop2='600px';
				altop2='50px';
				url2 = 'http://www.sagastume.com/claropop.html';
				openFrame (url2,'eexterno','eexterno',altop2,anchop2);					
				break;
			default: 
				alert ("Número incorrecto.  Porfavor vuelve a intentar!!!");
				guardar=false;
				break;
										
	}
	if (url!="")
		openFrame (url,'textform','ifrtext',altop,anchop);
	return false;
}

function claropop(){
	url = 'http://mensajes.claro.com.gt/mensaje_claro.php';
	window.open(url,'mywindow','width=225,height=275')
}

function movipop(){
	url = 'http://www.corporativo.telefonica.com.gt/EnviarSMSGT/faces/EnviarSMS2.jsp';
	window.open(url,'mywindow','width=225,height=285')
}

function tigopop(){
	url = 'http://www2.tigo.com.gt/mensajito';
	window.open(url,'mywindow','width=328,height=485,location=0,status=0,menubar=0,toolbar=0')
}


function any2sv(){
	window.location = "http://sv.sagastume.com"
}


function any2gt(){
	window.location = "http://gt.sagastume.com"
}

function any2hn(){
	window.location = "http://hn.sagastume.com"
}

function any2do(){
	window.location = "http://do.sagastume.com"
}


function cpais(){
	switch(document.selpais.pais.selectedIndex){
	case 0: any2gt(); break;
	case 1: any2sv(); break;
	case 2: any2hn(); break;
	case 3: any2do(); break;
	default: break;
	}
}


function fillPhones(){
	//se obtiene la cookie
	tmpCookie = getCookie('smsphones');
	
		
	//se obtiene la cookie del nombre del usuario
	from = getCookie('smsfrom');
	if (from == null)
		from ='';

	document.getElementById('lpde').value=from;	
	//se obtiene el div
	obj = document.getElementById('phones');
	
	if (tmpCookie== null || tmpCookie==''){
		obj.innerHTML='';
		return false;
	}
	
	salida = "<table>\n";
	colcount = 0;
	count = 0;
	tmpphone = '';
	tmpname='';
	step = 0;

	for (i=0;i<tmpCookie.length;i++){
	
		switch (step){
			case 1:{
				if (tmpCookie.charAt(i)!='.')
					tmpname += tmpCookie.charAt(i);
				else{
					if (colcount==0)
					salida += '<tr>\n\t';
					salida += '<td align="center"><a href="#" onclick="return go_next('+"'"+from+"'"+','+"'"+tmpphone+"'"+','+"'"+tmpname+"'"+',false);" class="phones">'+tmpname+'</a><br><a href="#" onclick="return delphone('+count+',0);" class="cphones">[x]</a> ';
					salida += '<a href="#" onclick="return go_next('+"'"+from+"'"+','+"'"+tmpphone+"'"+','+"'"+tmpname+"'"+',false);" class="phones">'+tmpphone+'</a></td>\n\t';
					colcount++;
					if (colcount==9){
						salida+= '</tr>\n';
						colcount=0;
					}//if
			
					count++;
					tmpphone = '';
					tmpname='';
					step=0;
				}//else
				break;
			}//case1
			case 0:{
				if (tmpCookie.charAt(i)!='/')
					tmpphone += tmpCookie.charAt(i);
				else 
					step=1;
				break;
			}//case 0
		}//switch
	}	//for	
		
	if (colcount!=0 && colcount<9){
		for (p=colcount;p<9;p++)
			salida += '<td>&nbsp;</td>\n\t';
		salida += '</tr>\n';
	}
	salida += '</table>\n';
	obj.innerHTML = salida;

	return true;
}

function fillPhonesver(){
	//se obtiene la cookie
	tmpCookie = getCookie('smsphones');
	//se obtiene la cookie del nombre del usuario
	from = getCookie('smsfrom');
	if (from == null)
		from ='';
	document.getElementById('lpde').value=from;	
	//se obtiene el div
	obj = document.getElementById('phones');
	if (tmpCookie== null || tmpCookie==''){
		obj.innerHTML='';
		return false;
	}
	salida = "<table>\n";
	colcount = 0;
	count = 0;
	tmpphone = '';
	tmpname='';
	step = 0;
	for (i=0;i<tmpCookie.length;i++){
		switch (step){
			case 1:{
				if (tmpCookie.charAt(i)!='.')
					tmpname += tmpCookie.charAt(i);
				else{
					if (colcount==0)
					salida += '<tr>\n\t';
					salida += '<td align="center"><a href="#" onclick="return go_next('+"'"+from+"'"+','+"'"+tmpphone+"'"+','+"'"+tmpname+"'"+',false);" class="phones">'+tmpname+'</a><br><a href="#" onclick="return delphone('+count+',0);" class="cphones">[x]</a> ';
					salida += '<a href="#" onclick="return go_next('+"'"+from+"'"+','+"'"+tmpphone+"'"+','+"'"+tmpname+"'"+',false);" class="phones">'+tmpphone+'</a></td>\n\t';
					colcount++;
//					if (colcount==9){
						salida+= '</tr>\n';
//						colcount=0;
//					}//if
					count++;
					tmpphone = '';
					tmpname='';
					step=0;
				}//else
				break;
			}//case1
			case 0:{
				if (tmpCookie.charAt(i)!='/')
					tmpphone += tmpCookie.charAt(i);
				else 
					step=1;
				break;
			}//case 0
		}//switch
	}	//for	
		
//	if (colcount!=0 && colcount<9){
//		for (p=colcount;p<9;p++)
//			salida += '<td>&nbsp;</td>\n\t';
//		salida += '</tr>\n';
//	}
	salida += '</table>\n';
	obj.innerHTML = salida;
	return true;
}

function delphone (pos,id) {
	tmpCookie = getCookie ('smsphones');
	if (tmpCookie=='')
		return false;;
	newCookie = '';
	count = 0;
	tmpphone = '';
	for (i=0;i<tmpCookie.length;i++){
		if (tmpCookie.charAt(i)!='.')
			tmpphone += tmpCookie.charAt(i);
		else {
			if (pos!= count)
				newCookie += tmpphone + '.';
			count++;
			tmpphone='';
		}
		
	}
	setCookie ('smsphones',newCookie,new Date(2100,1,1),'/','.sagastume.com',null);
	if (id==0)
		fillPhones();
	else
		fillPhones2();
	return false;
}

function obtener_valor(variable)
{
var remplaza = /\+/gi;
var url = window.location.href;
url = unescape(url);
url = url.replace(remplaza, " ");
var variable_may = variable;
var variable_pos = url.indexOf("?"+variable_may);
if (variable_pos == -1)
	variable_pos = url.indexOf ("&"+variable_may);
if (variable_pos != -1)
{
	variable_pos++;
	var pos_separador = url.indexOf("&",variable_pos);
	if (pos_separador != -1)
	{
		return url.substring(variable_pos + variable_may.length + 1, pos_separador);
	} else
	{
		return url.substring(variable_pos + variable_may.length + 1, url.length);
	}
} else
{
	return "";
}
}

function check_button(obj){
	if (!obj.checked){
		document.getElementById('divlpnombre').style.display='none';
		document.getElementById('divpara').style.display='none';
	}
	else{
		document.getElementById('divlpnombre').style.display='inline';
		document.getElementById('divpara').style.display='inline';
	}
}

function go_next (from,numero,nombre,guardar,pais){
	if (numero.length<8){
		alert("El número de celular debe ser de 8 dígitos");
		return false;
	}
	//se guardan las cookies 
	setCookie('smsphonesto',numero,null,'/','.sagastume.com',null);
	setCookie('smsphonestoname',nombre,null,'/','.sagastume.com',null);
	//se verifica si hay que guardar el número en la cookie
	if (guardar){
		//se guarda el nombre del usuario
		setCookie('smsfrom',from,new Date(2050,1,1),'/','.sagastume.com',null);
		//se obtiene la cookie
		tmpCookie = getCookie('smsphones');
		if (tmpCookie==null)
			tmpCookie = numero + '/'+nombre+'.';
		else 
			tmpCookie += numero+'/'+nombre+'.';
		setCookie('smsphones',tmpCookie,new Date (2050,1,1),'/','.sagastume.com',null);
		fillPhones();
	}
	enviarsms='sms.php?celular='+numero+'&nombreo='+from+'&nombred='+nombre+'&pais=502';
	window.location=enviarsms;
	return false;
}

function GetParams(){
	//se obtienen los datos de from
	var to= getCookie('smsphonesto');
	var toname= getCookie('smsphonestoname');
	var from= getCookie('smsfrom');
	PopForm(from,to,toname);
}



function fillPhones2(){
	//se obtiene la cookie
	tmpCookie = getCookie('smsphones');
	from = getCookie('smsfrom');
	if (from == null)
		from ='';
	//se obtiene el div
	obj = document.getElementById('phones');
	if (tmpCookie== null || tmpCookie==''){
		obj.innerHTML='';
		return false;
	}
	
	salida = "<table>\n";
	colcount = 0;
	count = 0;
	tmpphone = '';
	tmpname='';
	step = 0;
	for (i=0;i<tmpCookie.length;i++){
		switch (step){
			case 1:{
				if (tmpCookie.charAt(i)!='.')
					tmpname += tmpCookie.charAt(i);
				else{
					if (colcount==0)
					salida += '<tr>\n\t';
					salida += '<td align="center"><a href="#" onclick="return PopForm('+"'"+from+"'"+','+tmpphone+','+"'"+tmpname+"'"+',false);" class="phones">'+tmpname+'</a><br><a href="#" onclick="return delphone('+count+',1);" class="cphones">[x]</a> ';
					salida += '<a href="#" onclick="return PopForm('+"'"+from+"'"+','+tmpphone+','+"'"+tmpname+"'"+',false);" class="phones">'+tmpphone+'</a></td>\n\t';
					colcount++;
					if (colcount==9){
						salida+= '</tr>\n';
						colcount=0;
					}//if
					count++;
					tmpphone = '';
					tmpname='';
					step=0;
				}//else
				break;
			}//case1
			case 0:{
				if (tmpCookie.charAt(i)!='/')
					tmpphone += tmpCookie.charAt(i);
				else 
					step=1;
				break;
			}//case 0
		}//switch
	}	//for	
		
	if (colcount!=0 && colcount<9){
		for (p=colcount;p<9;p++)
			salida += '<td>&nbsp;</td>\n\t';
		salida += '</tr>\n';
	}
	salida += '</table>\n';
	obj.innerHTML = salida;
return true;
}
