// JavaScript Document
var temp;
var tama=0;
var http = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
var ta;
var newwindow;
/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};
/* ******************   End    ******************** */
function id(numo){

	num = numo * 1;
	
	// Comprobación inicial
	if(num < 40000000 || num >= 60000000)
		return 5;
	
	// Comcel 
	if(

		((40000000<= num) && (num <= 40999999)) ||
		((45000000<= num) && (num <= 46999999)) ||
		((48720000<= num) && (num <= 50099999)) ||
		((50300000<= num) && (num <= 50699999)) ||
		((51500000<= num) && (num <= 52099999)) ||
		((53000000<= num) && (num <= 53099999)) ||
		((53140000<= num) && (num <= 53899999)) ||
		((55200000<= num) && (num <= 55299999)) ||
		((55500000<= num) && (num <= 55539999)) ||
		((55800000<= num) && (num <= 55819999)) ||
		((57000000<= num) && (num <= 57099999)) ||
		((57190000<= num) && (num <= 57899999)) ||
		((58000000<= num) && (num <= 58099999)) ||
		((58190000<= num) && (num <= 58199999)) ||
		((58800000<= num) && (num <= 59099999)) ||
		((59180000<= num) && (num <= 59199999)) ||
		((59900000<= num) && (num <= 59999999)) 

	)
		return 2;
		
	// Telefónica
	else if(
		((43000000<= num) && (num <=44759999)) ||
		((50200000<= num) && (num <=50299999)) ||
		((50700000<= num) && (num <=51099999)) ||
		((51400000<= num) && (num <=51499999)) ||
		((52100000<= num) && (num <=52999999)) ||
		((53120000<= num) && (num <=53139999)) ||
		((53900000<= num) && (num <=54099999)) ||
		((55000000<= num) && (num <=55099999)) ||
		((55180000<= num) && (num <=55199999)) ||
		((55400000<= num) && (num <=55429999)) ||
		((55450000<= num) && (num <=55499999)) ||
		((56000000<= num) && (num <=56099999)) ||
		((56400000<= num) && (num <=56899999)) ||
		((57900000<= num) && (num <=57999999)) ||
		((59150000<= num) && (num <=59179999)) 

	)
		return 1;
		
	// Claro
	else if(

		((41000000<= num) && (num <=42999999)) ||
		((47000000<= num) && (num <=47419999)) ||
		((50100000<= num) && (num <=50199999)) ||
		((51100000<= num) && (num <=51399999)) ||
		((53100000<= num) && (num <=53119999)) ||
		((54100000<= num) && (num <=54999999)) ||
		((55100000<= num) && (num <=55179999)) ||
		((55300000<= num) && (num <=55399999)) ||
		((55430000<= num) && (num <=55449999)) ||
		((55540000<= num) && (num <=55799999)) ||
		((55820000<= num) && (num <=55999999)) ||
		((56100000<= num) && (num <=56399999)) ||
		((56900000<= num) && (num <=56999999)) ||
		((57100000<= num) && (num <=57189999)) ||
		((58100000<= num) && (num <=58189999)) ||
		((58200000<= num) && (num <=58799999)) ||
		((59100000<= num) && (num <=59149999)) ||
		((59200000<= num) && (num <=59899999))

	)
		return 3;
	
	// Desconocido
	else
		return 4;

}
function mensaje(mensaje,timeout){
	pm = true;
	window.clearTimeout(ta);
	document.getElementById('mensaje').innerHTML=mensaje+' <a href="#" onclick="encoger(\'mensaje\');" style="font-size:10px; color:#FF0000"> [cerrar]</a>';
	agrandar('mensaje', 30);
	if(timeout)
		ta=window.setTimeout('encoger("mensaje");', 3000);
}
function modbox(id, num, nom, fav){
	document.getElementById('modid').value=id;
	document.getElementById('modnum').value=num;
	document.getElementById('modnombre').value=nom;
	mostrarSolo('modcontacto');
	//document.getElementById('modfav').checked=(fav=='1')?'checked':'';
}
function enviar(numero, comp, sincopia){
	if(sincopia == null)
	{
		ntmp = document.getElementById('numero');
		ntmp.value = numero;
		copy(ntmp);

		mensaje("Numero de telefono copiado, lo puedes pegar con Ctrl+V.");
	}
	if(comp==null)
		comp = id(numero);
	switch(comp){
		case 1:
			//abrir('movistar.php?p='+numero+'&d='+nombre);
			var winpops=window.open("http://www.corporativo.telefonica.com.gt/EnviarSMSGT/","","width=525,height=395,resizable");
			if(!winpops)
				alert('Tu bloqueador de popups ha bloqueado la ventana, desactivalo para mensajin.com porfavor!');

			break;
		case 2:
			//var url='http://www.mensajin.com/clientev11.swf?dstphone1='+numero+'&nickglobal='+nombre;
			//abrir(url);
			var winpops=window.open("http://www.mensajin.com/tigo.html","","width=328,height=482,resizable");
			if(!winpops)
				alert('Tu bloqueador de popups ha bloqueado la ventana, desactivalo para mensajin.com porfavor!');
			break;
		case 3:
			//abrir('http://www.blackowlsoft.com/c.php?p='+numero+'&d='+nombre);
			var winpops=window.open("http://mensajes.claro.com.gt/mensaje_claro.php","","width=450,height=350,resizable");
			if(!winpops)
				alert('Tu bloqueador de popups ha bloqueado la ventana, desactivalo para mensajin.com porfavor!');
			break;
		case 5:
			mensaje('Numero de telefono incorrecto.', 3000);
			break;
		case 4:
			mensaje('Numero de telefono desconocido.', 10000);
			break;			
			
		}		
}
function encoger(id){
	window.clearTimeout(ta);
	var cosa=document.getElementById(id);
	if(parseInt(cosa.style.height)>5){
		cosa.style.height=parseInt(cosa.style.height)-5+'px';
		var encoger=window.setTimeout('encoger("'+id+'")', 50);
	}
	else{
		cosa.style.display='none';
	}
}
function esconder(id){
	var cosa=document.getElementById(id);
	cosa.style.display='none';
}
function mostrar(id){
	var cosa=document.getElementById(id);
	cosa.style.display='block';
}
function mostrarSolo(id){
	var divs=document.getElementsByTagName('div');
	for(var i=0; i<divs.length; i++){
		if(divs[i].className=='contenido')
			if(divs[i].id!=id)
				divs[i].style.display='none';
			else
				divs[i].style.display='block';
	}
	fadeIn(id, 100);
}
function inputs(){
	var inputs=document.getElementsByTagName('input');
	for(i=0;i<inputs.length;i++){
		if(inputs[i].name!='x'&&inputs[i].name!='cod'){
			inputs[i].onmouseover=function(){this.className=(this.className=='iactive')?'iactive':'ihover';};
			inputs[i].onmouseout=function(){this.className=(this.className=='iactive')?'iactive':''};
			inputs[i].onblur=function(){this.className='';};
			inputs[i].onfocus=function(){this.className='iactive';};
		}
	}
	inputs =document.getElementsByTagName('textarea');
	for(i=0;i<inputs.length;i++){
		if(inputs[i].name!='x'&&inputs[i].name!='cod'){
			inputs[i].onmouseover=function(){this.className=(this.className=='iactive')?'iactive':'ihover';};
			inputs[i].onmouseout=function(){this.className=(this.className=='iactive')?'iactive':''};
			inputs[i].onblur=function(){this.className='';};
			inputs[i].onfocus=function(){this.className='iactive';};
		}
	}
}
function docload(){
	inputs();
	mostrarSolo(mostrar);
	var theHandle = document.getElementById("frame_handle");
	var theRoot   = document.getElementById("frame");
	Drag.init(theHandle, theRoot);
	if(mostrar=='agenda')
		contacts();
}
function agrandar(id, tam){
	if(tama==0){
		tama+=5;
		document.getElementById(id).style.display='block';
		agranda=window.setTimeout("agrandar('"+id+"','"+tam+"');", 50);
	}
	else{
		if(tam==tama||tama>(tam-5)){
			window.clearTimeout(agranda);
			document.getElementById(id).style.height=tama+'px';
			tama=0;
		}
		else{
			document.getElementById(id).style.height=tama+'px';
			tama+=Math.sqrt(tam-tama);
			agranda=window.setTimeout("agrandar('"+id+"','"+tam+"');", 50);
		}
	}
}
function fadeIn(id, paso){
	if(paso<3){
		cambiaOpac(100, id);	
	}
	else{
		if(paso==100){
			document.getElementById(id).style.display='block';
		}
		cambiaOpac(100-paso, id);	
		paso-=4;
		fade=window.setTimeout("fadeIn('"+id+"','"+paso+"');", 10);
	}
}

function cambiaOpac(op, id) { 
	var object = document.getElementById(id).style; 
	object.opacity = (op / 100); 
	object.MozOpacity = (op / 100); 
	object.KhtmlOpacity = (op / 100); 
	object.filter = "alpha(opacity=" + op + ")"; 
} 
function abrir(url){

	document.getElementById('frame').style.display='inline';
	document.getElementById('formas').src=url;

}

function fadeOut(id, paso){
	if(paso>2){
		cambiaOpac(paso, id);
		paso-=2;
		fade=window.setTimeout("fadeOut('"+id+"',"+paso+")", 10);
	}
	else{
		document.getElementById('estado').style.display='none';
	}
}
function contacts(){
	var tds=document.getElementsByTagName('tr');
	for(var i=0; i<tds.length; i++){
		if(tds[i].className=='agenda_e'){
			tds[i].onmouseover=function(){this.bgColor='#C1DEEE';};
			tds[i].onmouseout=function(){this.bgColor='#FFFFFF';};
		}				
	}
}
function borrar(id, nom){
	var borrar=confirm("¿Realmente deseas borrar "+nom+" de tu lista de contactos?");
	if(borrar){
		top.location='?ir=agenda&op=borrar&id='+id;
	}
}
function cierraF(){
	document.getElementById('frame').style.display='none';
	document.getElementById('formas').src='about:blank';
}
function copy(inElement) {
  copied = false;
  if (inElement.createTextRange) {
    var range = inElement.createTextRange();
    if (range && range.execCommand)
	{
	  copied = true;
      range.execCommand('Copy');
	}
	else 
		copied = false;
  } if(!copied) {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
}
