var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
var tempX = 0;
var tempY = 0;


function ExecAjax(url,parametros,func_create,func_success,func_complete,func_error,asincrono){
	if(asincrono==false){asincrono=false;}else{asincrono = true;}
	
	var result = new String();
	var objetoAjax = new Ajax.Request(
		url, 
		{
			method: 'GET', 
			encoding: 'ISO-8859-1',
			parameters: parametros, 
			onCreate : function(){if(func_create) eval(func_create);},
			onSuccess : function(){if(func_success) eval(func_success);},
			onComplete: function(transport) {
				// alert("resutlado del go llamado desde ajax: "+transport.responseText);
				if(func_complete) eval(func_complete);
				var result=transport.responseText;
			},
			onFailure:  function(){
				if(func_error==null){
					alert("Error: No se ha podido ejecutar la acción correctamente.");
				} else {
					eval(func_error);
				}
			},
			asynchronous : asincrono
		});
	return result;
}


function AbrirFicha(id,pais,idr,tracking,metodo,cantidad_sms){
	if(metodo==1 && pais!="es"){
		metodo=2;	
	} else if(metodo==2 && pais!="es"){
		metodo=4;
	}
	
	if($('popup').value==1){
		win_ficha=window.open("actions/get_ficha.php?id="+id+"&pais="+pais+"&idr="+idr+"&tracking="+tracking+"&metodo="+metodo+"&popup=1&cantidad_sms="+cantidad_sms,"win_ficha","width=500,height=280,resizable=yes");
	} else {
		$('camgratis').hide();
		$('div_ficha').hide();
		SetPosition('ficha')
		$('ficha').show();
		$('float').show();
		var rand = Math.floor(Math.random() * 1000);
		ExecAjax("actions/get_ficha.php",rand+"&id="+id+"&pais="+pais+"&idr="+idr+"&tracking="+tracking+"&metodo="+metodo+"&cantidad_sms="+cantidad_sms,"$('cargando_ficha').show();","","$('cargando_ficha').hide(); $('div_ficha').innerHTML=transport.responseText; $('div_ficha').show();","",true);
	}
}

function AbrirAcceso(id,pais,idr,tracking,metodo,cantidad_sms){
	if(metodo==1 && pais!="es"){
		metodo=2;	
	} else if(metodo==2 && pais!="es"){
		metodo=4;
	}
	if($('popup').value==1){
		win_acceso=window.open("actions/get_ficha.php?id="+id+"&pais="+pais+"&idr="+idr+"&tracking="+tracking+"&metodo="+metodo+"&popup=1&show_acceso=1&cantidad_sms="+cantidad_sms,"win_acceso","width=500,height=280,resizable=yes");
	} else {
		$('camgratis').hide();
		$('div_ficha').hide();
		SetPosition('ficha')
		$('ficha').show();
		$('float').show();
		var rand = Math.floor(Math.random() * 1000);
		ExecAjax("actions/get_ficha.php",rand+"&id="+id+"&pais="+pais+"&idr="+idr+"&tracking="+tracking+"&metodo="+metodo+"&cantidad_sms="+cantidad_sms,"$('cargando_ficha').show();","","$('cargando_ficha').hide(); $('div_ficha').innerHTML=transport.responseText;  ShowAcceso("+metodo+"); $('div_ficha').show();","",true);
	}
}

function AbrirCamgratis(id,idr,tracking,pais,metodo,cantidad_sms){
	if($('popup').value==1){
		win_camgratis=window.open("cam_gratis.php?id="+id+"&idr="+idr+"&tracking="+tracking+"&pais="+pais+"&metodo="+metodo+"&cantidad_sms="+cantidad_sms,"win_camgratis","width=430,height=480,resizable=yes");
	} else {
		$('ficha').hide();
		SetPosition('camgratis')
		$('camgratis').show();
		$('float').show();
	}
}

function ShowAcceso(metodo){
	if(metodo==1){
		$('td_description').hide();
		$('td_cuadro_sms').hide();
		$('td_cuadro_tpv').hide();
		$('td_cuadro').show();
		obtenerNumero();
	} else if(metodo==3) {
		$('td_description').hide();
		$('td_cuadro').hide();
		$('td_cuadro_tpv').hide();
		$('td_cuadro_sms').show();		
	} else {
		$('td_description').hide();
		$('td_cuadro').hide();
		$('td_cuadro_sms').hide();
		$('td_cuadro_tpv').show();
	}
}


function SetPosition(div_id){
	//$(div_id).style.left=$('coordX').value;
	
	var doc_height=parseInt(DocHeight());
	var div_height=parseInt($(div_id).getHeight());

	if(parseInt($('coordY').value)+div_height>doc_height){
		new_top=parseInt($('coordY').value) - parseInt(div_height);
		if(new_top<0) new_top=0;
		$(div_id).style.top=new_top + "px";
	} else {
		new_top=parseInt($('coordY').value);
		$(div_id).style.top=$('coordY').value + "px";
	}
}

function DocHeight(){
	var docHeight;
	if (typeof document.clientHeight != 'undefined') {
		docHeight = document.clientHeight;
	} else if (document.compatMode && document.compatMode!='BackCompat'){
		docHeight = document.documentElement.scrollHeight;
	} else if (document.body && typeof document.body.scrollHeight != 'undefined') {
		docHeight = document.body.scrollHeight;
	}
	return docHeight;
}
	
// Capturar posicion mouse.
function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;} 

	$('coordX').value=tempX;
	$('coordY').value=tempY;
	return true;
}


function showThumbnail(which,e){
    if($('thumb').visible()==false){
    	xcoord = e.pageX ? pageXOffset + e.clientX : document.body.scrollLeft + e.x;
    	ycoord = e.pageY ? pageYOffset + e.clientY : document.body.scrollTop  + e.y;
    	$('thumb').style.left = xcoord + 20;
        $('thumb').style.top  = ycoord - 200;
        $('thumb').show();
        $('thumb').innerHTML = '<div style="border:1px solid #000000; background:#FFFFFF;padding:5px;">'+ which +'</div>';
    }
}

function closeThumbnail() {
    $('thumb').hide();
}