/*
	Funcion que estaba en login.html. Se centralizó aqui
*/
function abrirpopup(nombre,ancho,alto) {
dat = 'width=' + ancho + ',height=' + alto + ',left=0,top=0,scrollbars=yes,resize=no';
window.open(nombre,'',dat)
}


/*
	funcion que estaba en index. Es una funcion predefinida de DreamWeaver, asique seguro la usan as paginas
*/

function MM_preloadImages() { //v3.0

	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}


function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}



function submitform(formulario) {
	
	formulario.submit();	
}


/**
*
* Funcion que se utiliza en la parte de panel de control de afiliados
*
*
*/
function actualizarTransferencia(tipo)
{

	if ($F('metodo_de_pago') != '1' && $F('metodo_de_pago') !='0' )
	{
		$('ms_account_number_int').hide();		
		$('ms_account_number1').hide();
		$('ms_account_number2').hide();
		$('ms_swift_code').hide();
		$('ms_iban_code').hide();
	}
	else
	{
		if ($F('metodo_de_pago') != '0' ) {
			
			if (tipo == "I")
			{
				$('ms_account_number_int').show();		
				$('ms_account_number1').hide();
				$('ms_account_number2').hide();
				$('ms_swift_code').show();
				$('ms_iban_code').show();
			}
			else
			{
				$('ms_account_number_int').hide();		
				$('ms_account_number1').show();
				$('ms_account_number2').show();
				$('ms_swift_code').hide();
				$('ms_iban_code').hide();
			}
		}

	}


	
}

function habilita_mascara(){


	
		
		if($F('metodo_de_pago')=='0')
		{
			$('formularioControl').hide();
		}
		else 
		{

			$('formularioControl').show();	

		}

		// /////////////////////
		// PARA TRANSFERENCIAS
		// /////////////////////
		
		
		if($F('metodo_de_pago')=='1')
		{
			$('ms_tipotransf').show();
			$('ms_payableto').show();
			$('ms_epassport').hide();
			
			// determinamos si es Nacional o Intenacinal		
			$('ms_account_number').hide(); // <-- cuando se unifique borrar
	
			
			$('ms_account_number_int').show();		
			$('ms_account_number1').show();
			$('ms_account_number2').show();

			$('ms_swift_code').show();
			$('ms_iban_code').show();
			
			
			$('ms_bank_name').show();		
			$('ms_bank_country').show();
			$('ms_bank_city').show();
			actualizarTransferencia(document.form_control.tipotranf.value );
		}

		// //////////////
		// ePASSPORTE
		// /////////////
		
		if($F('metodo_de_pago')=='2')
		{		
			$('ms_payableto').show();
			$('ms_epassport').show();
			//$('ms_account_name').hide();
			$('ms_account_number').hide();
			$('ms_account_number1').hide();
			$('ms_account_number2').hide();
			$('ms_account_number_int').hide();		
			//$('ms_routing_number').hide();
			$('ms_swift_code').hide();
			$('ms_bank_name').hide();	
			$('ms_iban_code').hide();
			$('ms_tipotransf').hide();
			$('ms_bank_country').hide();
			$('ms_bank_city').hide();

		}

		// ////////////////
		// WESTERN UNION
		// ////////////////
		if($F('metodo_de_pago')=='3')
		{
			$('ms_payableto').show();
			$('ms_epassport').hide();
			$('ms_account_number').hide();
			$('ms_account_number1').hide();
			$('ms_account_number2').hide();
			$('ms_account_number_int').hide();		
			$('ms_swift_code').hide();
			$('ms_bank_name').hide();	
			$('ms_iban_code').hide();
			$('ms_tipotransf').hide();
			$('ms_bank_country').hide();
			$('ms_bank_city').hide();
		}

        
	}
	
	
	function habilita_mascara_afiliados(){

		$('formularioControl').show();	

		// /////////////////////
		// PARA TRANSFERENCIAS
		// /////////////////////
		
		
		if($F('metodo_de_pago')=='1')
		{
			$('ms_tipotransf').show();
			$('ms_payableto').show();
			$('ms_epassport').hide();
			
			// determinamos si es Nacional o Intenacinal		
			$('ms_account_number').hide(); // <-- cuando se unifique borrar
	
			
			$('ms_account_number_int').show();		
			$('ms_account_number1').show();
			$('ms_account_number2').show();

			$('ms_swift_code').show();
			$('ms_iban_code').show();
			
			
			$('ms_bank_name').show();		
			$('ms_bank_country').show();
			$('ms_bank_city').show();
			actualizarTransferencia(document.form_control.tipotranf.value );
		}

		// //////////////
		// ePASSPORTE
		// /////////////
		
		if($F('metodo_de_pago')=='2')
		{		
			$('ms_payableto').show();
			$('ms_epassport').show();
			//$('ms_account_name').hide();
			$('ms_account_number').hide();
			$('ms_account_number1').hide();
			$('ms_account_number2').hide();
			$('ms_account_number_int').hide();		
			//$('ms_routing_number').hide();
			$('ms_swift_code').hide();
			$('ms_bank_name').hide();	
			$('ms_iban_code').hide();
			$('ms_tipotransf').hide();
			$('ms_bank_country').hide();
			$('ms_bank_city').hide();

		}

		// ////////////////
		// WESTERN UNION
		// ////////////////
		if($F('metodo_de_pago')=='3')
		{
			$('ms_payableto').show();
			$('ms_epassport').hide();
			$('ms_account_number').hide();
			$('ms_account_number1').hide();
			$('ms_account_number2').hide();
			$('ms_account_number_int').hide();		
			$('ms_swift_code').hide();
			$('ms_bank_name').hide();	
			$('ms_iban_code').hide();
			$('ms_tipotransf').hide();
			$('ms_bank_country').hide();
			$('ms_bank_city').hide();
		}

        
	}


	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;
	        $('thumb').show();
	        $('thumb').innerHTML        = '<div style="border:1px solid #000000; background:#FFFFFF;padding:5px;">'+ which +'</div>';
	    }
	}
	function closeThumbnail() {
	    $('thumb').hide();
	}
	
	function ToggleFold(tabla) {
		if($(tabla).visible()){
			$(tabla).hide();	
			if($('imgfold_'+tabla)){ $('imgfold_'+tabla).src='images/acc-unfold.gif';}
			if($('imgfold_'+tabla)){ $('imgfold_'+tabla).blur();}
		} else {
			$(tabla).show();
			if($('imgfold_'+tabla)){ $('imgfold_'+tabla).src='images/acc-fold.gif';}
			if($('imgfold_'+tabla)){ $('imgfold_'+tabla).blur();}
		}
	}
	
	function OpenClose(tabla) {
		$(tabla).toggle();
	}
	
	/**
	* Realiza la carga de un modulo solicitado
	*
	*
	*/
	function loadGrafico(tab,index,concepto) {

		var url='actions/loadgrafico.do.php'
		var parametros='tab='+tab+'&concepto='+concepto+'&fromajax=1';
		var result = new String();
		var objetoAjax = new Ajax.Request(
			url, 
			{
				method: 'GET', 
				parameters: parametros, 
				onLoading : function (){CargandoTab(tab)},
				onSuccess : function (){TabCargado(tab,concepto)},
				onComplete: function(transport) {
								//alert("resutlado del go llamado desde ajax: "+unescape(transport.responseText));
								// Realizamos la carga del modulo
								showModulo(escape(transport.responseText), 'info_'+tab);
								$('cached_'+tab+'_'+index).innerHTML=$('info_'+tab).innerHTML;
				},
				onFailure:  "doError",
				asynchronous : true
			});
		return result;   
	}
	
	function changeTabImages(tab,index,status,last){
		// Cambio las imágenes de la pestaña actual.
		if($('imgtabl_'+tab+'_'+index)){
			if(index==0){
				$('imgtabl_'+tab+'_'+index).style.backgroundImage ="url(images/acctab-lb"+status+".gif)";				
			} else {
				$('imgtabl_'+tab+'_'+index).style.backgroundImage="url(images/acctab-lg"+status+".gif)";
			}
			$('imgtabm_'+tab+'_'+index).style.backgroundImage="url(images/acctab-m"+status+".gif)";
			if(index==last){
				$('imgtabr_'+tab+'_'+index).style.backgroundImage="url(images/acctab-rb"+status+".gif)";
			} else {
				$('imgtabr_'+tab+'_'+index).style.backgroundImage="url(images/acctab-rg"+status+".gif)";
				if(last)$('imgtabr_'+tab+'_'+last).style.backgroundImage="url(images/acctab-rb.gif)";
			}
			return "";
		} else {
			return index;
		}
	}
	
	function CargandoTab(tab){
		$('mostrando_'+tab).innerHTML='<img src="images/loading.gif" align="absmiddle"> Cargando...';
	}
	function TabCargado(tab,concepto){
		$('mostrando_'+tab).innerHTML='Mostrando: '+concepto;
	}
	
	function switchTab(tab,index,concepto){
		var last="";
		for(i=0;i<30;i++){
			if($(tab+'_'+i)){
				$(tab+'_'+i).style.zIndex=i+2;
			}
			last=changeTabImages(tab,i,'',last);
			if(last!="")break;
		}
		
		$(tab+'_'+index).style.zIndex=30;
		changeTabImages(tab,index,'-on',last-1)
		if($('cached_'+tab+'_'+index).innerHTML==""){
			loadGrafico(tab,index,concepto);
		} else {
			$('info_'+tab).innerHTML=$('cached_'+tab+'_'+index).innerHTML;
			TabCargado(tab,concepto);
		}
	}

	
	function loadInfo(sistema,item,concepto,parametros) {

		if($('contenidos_tabla_'+sistema+'_'+item).innerHTML==""){
			var url='go.php'
			var parametros='modulo=stats_reportes_completos&sistema='+sistema+'&concepto='+concepto+'&modo=registros&fromajax=1&'+parametros;
			var result = new String();
			var objetoAjax = new Ajax.Request(
				url, 
				{
					method: 'GET', 
					parameters: parametros, 
					onLoading : function (){
						$('concepto_'+sistema+'_'+item).innerHTML='<img src="images/loading2.gif" align="absmiddle"> Cargando...';
					},
					onSuccess : function (){
						$('concepto_'+sistema+'_'+item).innerHTML='<img src="images/'+sistema+'-icono.gif" align="absmiddle"> '+ concepto;
					},
					onComplete: function(transport) {
									//alert("resutlado del go llamado desde ajax: "+unescape(transport.responseText));
									// Realizamos la carga del modulo
									showModulo(escape(transport.responseText), 'contenidos_tabla_'+sistema+'_'+item);
									
									// Cargamos el Archivo JS correspondinte al modulo
									ejecutaAjax("get","file_exists.php?file=stats_reportes_completos",'','loadJs','',"doError", true) ;
									//loadJs(modulo);
					},
					onFailure:  "doError",
					asynchronous : true
				});
		}
		if($('contenidos_tabla_'+sistema+'_'+item).visible()){
			$('contenidos_tabla_'+sistema+'_'+item).hide();
		} else {
			$('contenidos_tabla_'+sistema+'_'+item).show();
		}
	}
	
	function FechasForm(valor){
		switch(valor){
			case "1":
				document.form1.fecha_desde.value=$('fecha_hoy').value;
				document.form1.fecha_hasta.value=$('fecha_hoy').value;
			break;
			case "2":
				document.form1.fecha_desde.value=$('fecha_ayer').value;
				document.form1.fecha_hasta.value=$('fecha_ayer').value;
			break;
			case "3":
				document.form1.fecha_desde.value=$('fecha_ultimos_desde').value;
				document.form1.fecha_hasta.value=$('fecha_ultimos_hasta').value;
			break;
			case "4":
				document.form1.fecha_desde.value=$('fecha_mesactual_desde').value;
				document.form1.fecha_hasta.value=$('fecha_mesactual_hasta').value;
			break;
			case "5":
				document.form1.fecha_desde.value=$('fecha_mesant_desde').value;
				document.form1.fecha_hasta.value=$('fecha_mesant_hasta').value;
			break;
			default:
				document.form1.fecha_desde.value=$('fecha_ayer').value;
				document.form1.fecha_hasta.value=$('fecha_hoy').value;
			break;			
		}
	}
	
	
	
	
	/**
	* Realiza el ordenamento  en el estadistico devisitas
	*
	*
	*/	
	function ordenar(criterio, formulario) {
		formulario.criterio_new.value = criterio;
		doFiltrar(formulario);
	}
	
	/**
	* Copia al portapapeles el texto ingresado
	* Es Cross Browser.
	*
	*/	
	
	function toClipBoard(text2copy) {
	  if (window.clipboardData) {
	    window.clipboardData.setData("Text",text2copy);
	  } else {
	    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="../afiliados/images/_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
	    document.getElementById(flashcopier).innerHTML = divinfo;
	  }
	}
	
	// Actualizar Códigos en Marca Blanca Videos Flash
	function ActualizarCodigosMBVF(){
		if($('modotpv').checked==true){
			var modo="tpv";
		} else {
			var modo="sms";
		}
		var cant=$('cant').value;
		var idr=$('idr').value;
		var tracking=$('tracking').value;

		for(i=0;i<cant;i++){
			if(document.form1['codigo'+i]){
				temp=document.form1['codigo'+i].id;
			} else {
				break;	
			}
			id=temp.replace("video_","");
			document.form1['codigo'+i].value='<script src="http://www.grupomarineda.net/videos_flash/videos_flash.php?id='+id+'&modo='+modo+'&idr='+idr+'&tracking='+tracking+'">'+String.fromCharCode(60)+'/script>';
		}
	}
	
	function MostrarColorPicker(t,e){
		xcoord = e.pageX ? pageXOffset + e.clientX : document.body.scrollLeft + e.x;
	    ycoord = e.pageY ? pageYOffset + e.clientY : document.body.scrollTop  + e.y;
		$('nombre_color').value=t.id;
		$('colorjack').style.left=xcoord+20;
		$('colorjack').style.top=ycoord;
		$('colorjack').show();
	}