function start9050794InputEvents(){
	$( "#p12iEmisor" ).bind( "keyup", function() {
		if( $( "#p12iEmisor" ).val().length > 7){
			$( "#p12iSufijo" ).focus();
		}
	});
	
	$( "#p12iSufijo" ).bind( "keyup", function() {
		if( $( "#p12iSufijo" ).val().length > 2){
			$( "#p12iReferencia" ).focus();
		}
	});
	
	$( "#p12iReferencia" ).bind( "keyup", function() {
		if( $( "#p12iReferencia" ).val().length > 12){
			$( "#p12iIdentificacion" ).focus();
		}
	});
	
	$( "#p12iIdentificacion" ).bind( "keyup", function() {
		if( $( "#p12iIdentificacion" ).val().length > 5){
			$( "#p12iImporteEnteros" ).focus();
		}
	});
	
	$( "#p12iImporteEnteros" ).bind( "keyup", function() {
		if( $( "#p12iImporteEnteros" ).val().length > 7){
			$( "#p12iImporteDecimales" ).focus();
		}
	});
}

function start9050299InputEvents(){
	$( "#p12iEmisor" ).bind( "keyup", function() {
		if( $( "#p12iEmisor" ).val().length > 5){
			$( "#p12iReferencia" ).focus();
		}
	});
	
	$( "#p12iReferencia" ).bind( "keyup", function() {
		if( $( "#p12iReferencia" ).val().length > 11){
			$( "#p12iIdentificacion" ).focus();
		}
	});
	
	$( "#p12iIdentificacion" ).bind( "keyup", function() {
		if( $( "#p12iIdentificacion" ).val().length > 6){
			$( "#p12iImporteEnteros" ).focus();
		}
	});
	
	$( "#p12iImporteEnteros" ).bind( "keyup", function() {
		if( $( "#p12iImporteEnteros" ).val().length > 5){
			$( "#p12iImporteDecimales" ).focus();
		}
	});
}

function start9052180InputEvents(){
	$( "#p12iEmisor" ).bind( "keyup", function() {
		if( $( "#p12iEmisor" ).val().length > 5){
			$( "#p12iReferencia" ).focus();
		}
	});
	
	$( "#p12iReferencia" ).bind( "keyup", function() {
		if( $( "#p12iReferencia" ).val().length > 11){
			$( "#p12iIdentificacion" ).focus();
		}
	});
	
	$( "#p12iIdentificacion" ).bind( "keyup", function() {
		if( $( "#p12iIdentificacion" ).val().length > 9){
			$( "#p12iImporteEnteros" ).focus();
		}
	});
	
	$( "#p12iImporteEnteros" ).bind( "keyup", function() {
		if( $( "#p12iImporteEnteros" ).val().length > 5){
			$( "#p12iImporteDecimales" ).focus();
		}
	});
}

function showLoader() {
	var $this = $( this ),
	theme = $this.jqmData( "theme" ) || $.mobile.loader.prototype.options.theme,
	msgText = $this.jqmData( "msgtext" ) || $.mobile.loader.prototype.options.text,
	textVisible = $this.jqmData( "textvisible" ) || $.mobile.loader.prototype.options.textVisible,
	textonly = !!$this.jqmData( "textonly" );
	html = $this.jqmData( "html" ) || "";
	$.mobile.loading( "show", {
	text: msgText,
	textVisible: textVisible,
	theme: theme,
	textonly: textonly,
	html: html
	});
};
		
function check9050794Form(){

	document.getElementById('popupPersonalizedText').style.display = 'none';
	document.getElementById('popupStandardText').style.display = 'block';

	if(check9050794FormData()){
		showLoader();
		
		$.ajax({
		  type: "POST",
		  url: "p12kRPCDispatcherServlet",
		  data: { "module":"ICSB",
		  "function":"preInitialize",
		  "p12iAction":"nuevo",
		  "p12iCpr":$( "#p12iCpr" ).val(),
		  "p12iEmisor": $( "#p12iEmisor" ).val(),
		  "p12iSufijo": $( "#p12iSufijo" ).val(),
		  "p12iReferencia": $( "#p12iReferencia" ).val(),
		  "p12iIdentificacion": $( "#p12iIdentificacion" ).val(),
		  "p12iImporteEnteros": $( "#p12iImporteEnteros" ).val(),
		  "p12iImporteDecimales": $( "#p12iImporteDecimales" ).val()
		  }
		})
		.done(function( msg ) {
			var resultado = $(msg).find("returnValue").text();
			
			if(resultado.indexOf("ERROR") > -1){
				$.mobile.loading( "hide" );
				document.getElementById("popupPersonalizedText").innerHTML = resultado
				document.getElementById('popupPersonalizedText').style.display = 'block';
				document.getElementById('popupStandardText').style.display = 'none';
				$("#overlayDialog").click();
			}else{
				document.getElementById("p12iOidsPago").value = resultado;
				document.getElementById('p12FormCPR9050794').submit();
			}
		});
	}else{
		$("#overlayDialog").click();
	}
}
function check9050794FormData(){
	if( $( "#p12iEmisor" ).val().length < 8){
		return false;
	}
	
	if($.isNumeric( $( "#p12iEmisor" ).val()) === false ){
		return false;
	}
	
	if( $( "#p12iSufijo" ).val().length < 3){
		return false;
	}
	
	if($.isNumeric( $( "#p12iSufijo" ).val()) === false ){
		return false;
	}
	
	if( $( "#p12iReferencia" ).val().length < 13){
		return false;
	}
	
	if($.isNumeric( $( "#p12iReferencia" ).val()) === false ){
		return false;
	}

	if( $( "#p12iIdentificacion" ).val().length < 6){
		return false;
	}
	
	if($.isNumeric( $( "#p12iIdentificacion" ).val()) === false ){
		return false;
	}
	
	if( $( "#p12iImporteEnteros" ).val().length < 1){
		return false;
	}
	
	if($.isNumeric( $( "#p12iImporteEnteros" ).val()) === false ){
		return false;
	}
	
	if( $( "#p12iImporteDecimales" ).val().length < 2){
		return false;
	}
	
	if($.isNumeric( $( "#p12iImporteDecimales" ).val()) === false ){
		return false;
	}
	
	return true;
}

function check9050299Form(){
	document.getElementById('popupPersonalizedText').style.display = 'none';
	document.getElementById('popupStandardText').style.display = 'block';

	if(check9050299FormData()){
		showLoader();
		
		$.ajax({
		  type: "POST",
		  url: "p12kRPCDispatcherServlet",
		  data: { "module":"ICSB",
		  "function":"preInitialize",
		  "p12iAction":"nuevo",
		  "p12iCpr":$( "#p12iCpr" ).val(),
		  "p12iEmisor": $( "#p12iEmisor" ).val(),
		  "p12iReferencia": $( "#p12iReferencia" ).val(),
		  "p12iIdentificacion": $( "#p12iIdentificacion" ).val(),
		  "p12iImporteEnteros": $( "#p12iImporteEnteros" ).val(),
		  "p12iImporteDecimales": $( "#p12iImporteDecimales" ).val()
		  }
		})
		.done(function( msg ) {
			var resultado = $(msg).find("returnValue").text();
			
			if(resultado.indexOf("ERROR") > -1){
				$.mobile.loading( "hide" );
				document.getElementById("popupPersonalizedText").innerHTML = resultado
				document.getElementById('popupPersonalizedText').style.display = 'block';
				document.getElementById('popupStandardText').style.display = 'none';
				$("#overlayDialog").click();
			}else{
				document.getElementById("p12iOidsPago").value = resultado;
				document.getElementById('p12FormCPR9050299').submit();
			}
		});
	}else{
		$("#overlayDialog").click();
	}
}

function check9050299FormData(){
	if( $( "#p12iEmisor" ).val().length < 6){
		return false;
	}
	
	if($.isNumeric( $( "#p12iEmisor" ).val()) === false ){
		return false;
	}
	
	if( $( "#p12iReferencia" ).val().length < 12){
		return false;
	}
	
	if($.isNumeric( $( "#p12iReferencia" ).val()) === false ){
		return false;
	}

	if( $( "#p12iIdentificacion" ).val().length < 7){
		return false;
	}
	
	if($.isNumeric( $( "#p12iIdentificacion" ).val()) === false ){
		return false;
	}
	
	if( $( "#p12iImporteEnteros" ).val().length < 1){
		return false;
	}
	
	if($.isNumeric( $( "#p12iImporteEnteros" ).val()) === false ){
		return false;
	}
	
	if( $( "#p12iImporteDecimales" ).val().length < 2){
		return false;
	}
	
	if($.isNumeric( $( "#p12iImporteDecimales" ).val()) === false ){
		return false;
	}
	
	return true;
}

function check9052180Form(){
	document.getElementById('popupPersonalizedText').style.display = 'none';
	document.getElementById('popupStandardText').style.display = 'block';

	if(check9052180FormData()){
		showLoader();
		
		$.ajax({
		  type: "POST",
		  url: "p12kRPCDispatcherServlet",
		  data: { "module":"ICSB",
		  "function":"preInitialize",
		  "p12iAction":"nuevo",
		  "p12iCpr":$( "#p12iCpr" ).val(),
		  "p12iEmisor": $( "#p12iEmisor" ).val(),
		  "p12iReferencia": $( "#p12iReferencia" ).val(),
		  "p12iIdentificacion": $( "#p12iIdentificacion" ).val(),
		  "p12iImporteEnteros": $( "#p12iImporteEnteros" ).val(),
		  "p12iImporteDecimales": $( "#p12iImporteDecimales" ).val()
		  }
		})
		.done(function( msg ) {
			var resultado = $(msg).find("returnValue").text();
			
			if(resultado.indexOf("ERROR") > -1){
				$.mobile.loading( "hide" );
				document.getElementById("popupPersonalizedText").innerHTML = resultado
				document.getElementById('popupPersonalizedText').style.display = 'block';
				document.getElementById('popupStandardText').style.display = 'none';
				$("#overlayDialog").click();
			}else{
				document.getElementById("p12iOidsPago").value = resultado;
				document.getElementById('p12FormCPR9052180').submit();
			}
		});
	}else{
		$("#overlayDialog").click();
	}
}

function check9052180FormData(){
	if( $( "#p12iEmisor" ).val().length < 6){
		return false;
	}
	
	if($.isNumeric( $( "#p12iEmisor" ).val()) === false ){
		return false;
	}
	
	if( $( "#p12iReferencia" ).val().length < 12){
		return false;
	}
	
	if($.isNumeric( $( "#p12iReferencia" ).val()) === false ){
		return false;
	}

	if( $( "#p12iIdentificacion" ).val().length < 10){
		return false;
	}
	
	if($.isNumeric( $( "#p12iIdentificacion" ).val()) === false ){
		return false;
	}
	
	if( $( "#p12iImporteEnteros" ).val().length < 1){
		return false;
	}
	
	if($.isNumeric( $( "#p12iImporteEnteros" ).val()) === false ){
		return false;
	}
	
	if( $( "#p12iImporteDecimales" ).val().length < 2){
		return false;
	}
	
	if($.isNumeric( $( "#p12iImporteDecimales" ).val()) === false ){
		return false;
	}
	
	return true;
}

function onStartIndex(){
	start9050794InputEvents();
	start9050299InputEvents();
	start9052180InputEvents();
}

function loadCPRSelection(cpr){
	eval("document.p12FormCPR.p12iCpr.value='"+cpr+"';");
	document.getElementById("p12FormCPR").submit();
}

function showJSP(jspName, lang){
	eval("document.p12MainViewForm.p12iIdioma.value='"+lang+"';");
	document.getElementById("jspName").value = jspName;
	document.getElementById("p12MainViewForm").submit();
}

$( document ).on( "pagecreate", "#main-page", function() {
	$( document ).on( "swipeleft", "#main-page", function( e ) {
		if ( $( ".ui-page-active" ).jqmData( "panel" ) !== "open" ) {
			if ( e.type === "swipeleft" ) {
				$( "#right-panel" ).panel( "open" );
			}
		}
	});
});

$( document ).on( "click", ".show-page-loading-msg",
	function() {
		var $this = $( this ),
		theme = $this.jqmData( "theme" ) || $.mobile.loader.prototype.options.theme,
		msgText = $this.jqmData( "msgtext" ) || $.mobile.loader.prototype.options.text,
		textVisible = $this.jqmData( "textvisible" ) || $.mobile.loader.prototype.options.textVisible,
		textonly = !!$this.jqmData( "textonly" );
		html = $this.jqmData( "html" ) || "";
		$.mobile.loading( "show", {
		text: msgText,
		textVisible: textVisible,
		theme: theme,
		textonly: textonly,
		html: html
	});
}).on( "click", ".hide-page-loading-msg", function() {
	$.mobile.loading( "hide" );
});

function initializePayment(){
	document.getElementById("p12InitializePaymentForm").submit();
}

function payOnlineFinantialOrg(finantialOrg){
	//document.getElementById("p12iOidEntidad").value = finantialOrg;
	eval("document.p12FinantialForm.p12iOidEntidad.value='"+finantialOrg+"';");
	document.getElementById("p12FinantialForm").submit();
}

function overTPVMaxImport(finantialOrgOid){
	$("#overlayDialog").click();
}

function requestInvoice9050794Form(){

	document.getElementById('popupPersonalizedText').style.display = 'none';
	document.getElementById('popupStandardText').style.display = 'block';

	if(check9050794FormData()){
		showLoader();
		
		$.ajax({
		  type: "POST",
		  url: "p12kRPCDispatcherServlet",
		  data: { "module":"ICSB",
		  "function":"checkPaymentInvoice",
		  "p12iCpr":$( "#p12iCpr" ).val(),
		  "p12iEmisor": $( "#p12iEmisor" ).val(),
		  "p12iSufijo": $( "#p12iSufijo" ).val(),
		  "p12iReferencia": $( "#p12iReferencia" ).val(),
		  "p12iIdentificacion": $( "#p12iIdentificacion" ).val(),
		  "p12iImporteEnteros": $( "#p12iImporteEnteros" ).val(),
		  "p12iImporteDecimales": $( "#p12iImporteDecimales" ).val()
		  }
		})
		.done(function( msg ) {
			var resultado = $(msg).find("returnValue").text();
			
			if(resultado.indexOf("ERROR") > -1){
				$.mobile.loading( "hide" );
				document.getElementById("popupPersonalizedText").innerHTML = resultado
				document.getElementById('popupPersonalizedText').style.display = 'block';
				document.getElementById('popupStandardText').style.display = 'none';
				$("#overlayDialog").click();
			}else{
				var dataResult = resultado.split("#");
				document.getElementById("pagoID").value = dataResult[0];
				document.getElementById("pagoNRC").value = dataResult[1];
				document.getElementById('p12InvoiceCPR9050794').submit();
				$.mobile.loading( "hide" );
			}
		});
	}else{
		$("#overlayDialog").click();
	}
}

function requestInvoice9050299Form(){

	document.getElementById('popupPersonalizedText').style.display = 'none';
	document.getElementById('popupStandardText').style.display = 'block';

	if(check9050299FormData()){
		showLoader();
		
		$.ajax({
		  type: "POST",
		  url: "p12kRPCDispatcherServlet",
		  data: { "module":"ICSB",
		  "function":"checkPaymentInvoice",
		  "p12iCpr":$( "#p12iCpr" ).val(),
		  "p12iEmisor": $( "#p12iEmisor" ).val(),
		  "p12iReferencia": $( "#p12iReferencia" ).val(),
		  "p12iIdentificacion": $( "#p12iIdentificacion" ).val(),
		  "p12iImporteEnteros": $( "#p12iImporteEnteros" ).val(),
		  "p12iImporteDecimales": $( "#p12iImporteDecimales" ).val()
		  }
		})
		.done(function( msg ) {
			var resultado = $(msg).find("returnValue").text();
			
			if(resultado.indexOf("ERROR") > -1){
				$.mobile.loading( "hide" );
				document.getElementById("popupPersonalizedText").innerHTML = resultado
				document.getElementById('popupPersonalizedText').style.display = 'block';
				document.getElementById('popupStandardText').style.display = 'none';
				$("#overlayDialog").click();
			}else{
				var dataResult = resultado.split("#");
				document.getElementById("pagoID").value = dataResult[0];
				document.getElementById("pagoNRC").value = dataResult[1];
				document.getElementById('p12InvoiceCPR9050299').submit();
				$.mobile.loading( "hide" );
			}
		});
	}else{
		$("#overlayDialog").click();
	}
}

function requestInvoice9052180Form(){

	document.getElementById('popupPersonalizedText').style.display = 'none';
	document.getElementById('popupStandardText').style.display = 'block';

	if(check9052180FormData()){
		showLoader();
		
		$.ajax({
		  type: "POST",
		  url: "p12kRPCDispatcherServlet",
		  data: { "module":"ICSB",
		  "function":"checkPaymentInvoice",
		  "p12iCpr":$( "#p12iCpr" ).val(),
		  "p12iEmisor": $( "#p12iEmisor" ).val(),
		  "p12iReferencia": $( "#p12iReferencia" ).val(),
		  "p12iIdentificacion": $( "#p12iIdentificacion" ).val(),
		  "p12iImporteEnteros": $( "#p12iImporteEnteros" ).val(),
		  "p12iImporteDecimales": $( "#p12iImporteDecimales" ).val()
		  }
		})
		.done(function( msg ) {
			var resultado = $(msg).find("returnValue").text();
			
			if(resultado.indexOf("ERROR") > -1){
				$.mobile.loading( "hide" );
				document.getElementById("popupPersonalizedText").innerHTML = resultado
				document.getElementById('popupPersonalizedText').style.display = 'block';
				document.getElementById('popupStandardText').style.display = 'none';
				$("#overlayDialog").click();
			}else{
				var dataResult = resultado.split("#");
				document.getElementById("pagoID").value = dataResult[0];
				document.getElementById("pagoNRC").value = dataResult[1];
				document.getElementById('p12InvoiceCPR9052180').submit();
				$.mobile.loading( "hide" );
			}
		});
	}else{
		$("#overlayDialog").click();
	}
}

function sendInvoiceByMail(){
	var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(regex.test($( "#p12iMail" ).val())){
		showLoader();
		$.ajax({
			type: "POST",
			url: "p12kRPCDispatcherServlet",
			data: { 
				"module":"IU",
				"function":"enviarJustificante",
				"pagoID":$( "#pagoID" ).val(),
				"pagoNRC": $( "#pagoNRC" ).val(),
				"p12iIdioma": $( "#p12iIdioma" ).val(),
				"p12iMail": $( "#p12iMail" ).val()
			}
		})
		.done(function( msg ) {
			var resultado = $(msg).find("returnValue").text();
			if(resultado.indexOf("ERROR") > -1){
				$.mobile.loading( "hide" );
				document.getElementById("popupErrorText").innerHTML = resultado
				document.getElementById('popupErrorText').style.display = 'block';
				document.getElementById('popupSuccessText').style.display = 'none';
				document.getElementById('popupWrongText').style.display = 'none';
				$("#overlayDialog").click();
			}else{
				$.mobile.loading( "hide" );
				document.getElementById('popupWrongText').style.display = 'none';
				document.getElementById('popupSuccessText').style.display = 'block';
				document.getElementById('popupErrorText').style.display = 'none';
				$("#overlayDialog").click();
			}
		});
	}else{
		$.mobile.loading( "hide" );
		document.getElementById('popupWrongText').style.display = 'block';
		document.getElementById('popupSuccessText').style.display = 'none';
		document.getElementById('popupErrorText').style.display = 'none';
		$("#overlayDialog").click();
	}
}

function downloadInvoice(){
alert("1");
	$.ajax({
		type: "POST",
		url: "http://www.euskadi.ejiedes.eus:8080/p12iWar/p12iGeneradorJustificanteServlet",
		data: {
			"pagoID":$( "#pagoID" ).val(),
			"pagoNRC": $( "#pagoNRC" ).val()
		}
	})
	.done(function( msg ) {
		alert("2");
		var resultado = $(msg).find("returnValue").text();
		alert("3 "+resultado);
		if(resultado.indexOf("ERROR") > -1){
			$.mobile.loading( "hide" );
			document.getElementById("popupPersonalizedText").innerHTML = resultado
			document.getElementById('popupPersonalizedText').style.display = 'block';
			$("#overlayDialog").click();
		}
	});
}
//VERSION ESTATICA


			
			function loadCPRHtml(htmlPage){
				document.getElementById('p12FormHTMLCPR').action = htmlPage;
				document.getElementById('p12FormHTMLCPR').submit();
			}
			
			function check9050794FormEstaticos(){
				if(check9050794FormData()){
					showLoader();
					document.getElementById('formulario').submit();
				}else{
					$("#overlayDialog").click();
				}
			}
			
			function check9050299FormEstaticos(){
				if(check9050299FormData()){
					showLoader();
					document.getElementById('formulario').submit();
				}else{
					$("#overlayDialog").click();
				}
			}
			
			function check9052180FormEstaticos(){
				if(check9052180FormData()){
					showLoader();
					document.getElementById('formulario').submit();
				}else{
					$("#overlayDialog").click();
				}
			}
			
			