function DoViewIFRAME(que) {
	
	var answer = confirm("Continuar?");
	var caja;
	
  if (answer) {
  
  	switch(que) {
		
			case "Domiciliacion": 
			
				document.write('<form><input type=text value="cc1" name="cc1" onkeyup="filter(this)"></form>');
		    //alert(caja);
		
				break;
		
			case "Transferencia": 
			
				caja = "<div id=frame1 align=center><iframe src=transferencia.html margin=10 border=1 scrollbars=auto width=450 height=300></iframe></div>";
		    document.write("Hola<div id=frame1 align=center><iframe src=http://www.google.com margin=10 border=1 scrollbars=auto width=450 height=300></iframe></div>");
		    document.write("<h1>Comprobaci&oacute;n de cuentas corrientes</h1><form name=cctest action=><div style=display:block><input id=cc1 class=incompleto type=text size=4 maxlength=4 title=Entidad name=cc1 onkeyup=filter(this) onchange=filter(this) /><input id=cc2 class=incompleto type=text size=4 maxlength=4 title=Oficina name=cc2 onkeyup=filter(this) onchange=filter(this) /><input id=cc3 class=incompleto type=text size=2 maxlength=2 title=DC name=cc3 onkeyup=filter(this) onchange=filter(this) /><input id=cc4 class=incompleto type=text size=10 maxlength=10 title=Cuenta name=cc4 onkeyup=filter(this) onchange=filter(this) /></div><input class=button type=button name=cc_validate title=Validar Cuenta Corriente value=Validar cuenta onclick=validate() /></form>");
		    alert("Pagando...!" + que);
			
				break;
			
			case "Tarjeta": 
			
				caja = "<div id=frame1 align=center><iframe src=http://www.google.com margin=10 border=1 scrollbars=auto width=450 height=300></iframe></div>";
		    document.write("Hola<div id=frame1 align=center><iframe src=http://www.google.com margin=10 border=1 scrollbars=auto width=450 height=300></iframe></div>");
		    document.write("<h1>Comprobaci&oacute;n de cuentas corrientes</h1><form name=cctest action=><div style=display:block><input id=cc1 class=incompleto type=text size=4 maxlength=4 title=Entidad name=cc1 onkeyup=filter(this) onchange=filter(this) /><input id=cc2 class=incompleto type=text size=4 maxlength=4 title=Oficina name=cc2 onkeyup=filter(this) onchange=filter(this) /><input id=cc3 class=incompleto type=text size=2 maxlength=2 title=DC name=cc3 onkeyup=filter(this) onchange=filter(this) /><input id=cc4 class=incompleto type=text size=10 maxlength=10 title=Cuenta name=cc4 onkeyup=filter(this) onchange=filter(this) /></div><input class=button type=button name=cc_validate title=Validar Cuenta Corriente value=Validar cuenta onclick=validate() /></form>");
		    alert("Pagando...!" + que);
			
				break; 
			
			default: 
			
				alert("Pagando??");
		
		};
   	
   }
 
} // end function DoViewFrame


function validate(){
  
  var str_error = "";
  var arrCC = new Array(document.getElementById("cc1"), document.getElementById("cc2"),
       		              document.getElementById("cc3"), document.getElementById("cc4"));
	
  /* Si algún campo no ha sido completado satisfactoriamente cambiar su estilo, darle el foco y mostrar el error */
	for (i=3;i>=0;i--){
		if (arrCC[i].getAttribute("maxlength") != arrCC[i].value.length) {
			arrCC[i].setAttribute("class","incompleto");
			str_error = "No ha completado todos los datos";
			arrCC[i].focus();
		};
	};
	
	if ("" != str_error) {
		alert (str_error);
		return;
	};
 		
	/* Comprobar la cuenta corriente introducida */
	if (checkDC(arrCC[0].value+arrCC[1].value,arrCC[3].value,arrCC[2].value))
    	document.cctest.submit();
	else
		alert ("La cuenta corriente introducida no es correcta.\nPor favor, compruebe los datos.");
   		
} // end validate()

/**
 * Filtrado de los valores introducidos en los campos de texto
 * 
 * Sólo permite introducir números, y cambia el estilo del campo si ha sido completado
 * hasta el máximo de su longitud.
 *
 * IN: object objecto Campo sobre el que realizar el filtrado
*/
function filter(field){
   
	/* Eliminar todos los caracteres no numéricos del campo	*/
	field.value = field.value.replace(/\D/,"");

	/* Si el campo se ha completado hasta su maxima extensión cambiar su estilo	*/
	if (field.getAttribute("maxlength") == field.value.length)
		field.setAttribute("class","completo");
	else
		field.setAttribute("class","incompleto");	

} // end filter()


function checkDC(cc1,cc2,dc){
   
	/* Comprobar que los datos son correctos */
 		if (!(cc1.match(/^\d{8}$/) && cc2.match(/^\d{10}$/) && dc.match(/^\d{2}$/) )) return false;
   	    
 	   var arrWeights = new Array(1,2,4,8,5,10,9,7,3,6);	// vector de pesos
		var dc1=0, dc2=0;
   	    
		/* Cálculo del primer dígito de control	*/
	  for (i=7;i>=0;i--) dc1 += arrWeights[i+2] * cc1.charAt(i);
		
		dc1 = 11 - (dc1 % 11);
	  if (11 == dc1) dc1 = 0;
	  if (10 == dc1) dc1 = 1;
   	    
	  /* Cálculo del segundo dígito de control */
	  for (i=9;i>=0;i--) dc2 += arrWeights[i] * cc2.charAt(i);
		
		dc2 = 11 - (dc2 % 11);
	  if (11 == dc2) dc2 = 0;
		if (10 == dc2) dc2 = 1;
   	    
		/* Comprobar la coincidencia y delvolver el resultado	*/
 		return (10*dc1+dc2 == dc);	// Javascript infiere tipo entero para dc1 y dc2
    
} // end checkDC()
