function PC()
{
// INI: PRIVATE PROPERTIES
	this._public = {
		els		: {
			anchorStart	: $('.navEpc:first a'),
			activeForm	: null,
			initialForm	: $('form#primeraRegla'),
			minorThree	: $('form#registroEpcMenos'),
			majorThree	: $('form#registroEpcMas'),
			errorLabel	: '.errorForm p'
		},
		classes	: {
			getPCLogout	: 'getEpc',
			getPCLogin	: 'getEpcOk'
		},
		update : true
	}
	this.dates = new objDate();
// END: PRIVATE PROPERTIES

// INI: PRIVATE PROPERTIES
	var logged			= false;
	var hasPC			= false;
	var periodType		= -1;
	//this.anchorStart	= $('.getEpc:first');
// END: PRIVATE PROPERTIES

	var that = this;

// INI: PRIVATE METHODS
	function hasPeriodCalendar()
	{
		$.ajax({
			url		: _GLOBAL.context+'hasPC.xml',
			data	: 'nocache=' + Math.random(),
			success : function(xml)
			{
				var pc = $('data pc',xml).text();
				if ( pc == "1" )
				{
					hasPC  = true;
					periodType = $('data hasPeriod',xml).text();
					setHandlerAnchor();
				}
				else
				{
					if ( pc == "0" || pc == "") that._public.update = false;
					that._public.els.anchorStart.show();
					that._public.els.anchorStart.click(function(){
						that.setActiveForm(that._public.els.initialForm);
						that._public.els.initialForm.show();
						that.validateinitialForm();
						return false;
					});
				}
			},
			error:function(a,b,c){
				if (a.readyState == 4 && a.status== 200) {
					this.success(a.responseXML);
				}
			}
		});
	}

	function setHandlerAnchor()
	{
		if (periodType == "1")
		{
			that._public.els.anchorStart.click(function(){
				that.setActiveForm(that._public.els.initialForm);
				that._public.els.initialForm.show();
				that.validateinitialForm();
				that._public.els.activeForm.find('fieldset#utilidad').hide();
				that._public.els.activeForm.find('.separadorPopup').hide();
				return false;
			});
		}
		else if (periodType == "2")
		{
			that._public.els.anchorStart.click(function(){
				that.setActiveForm(that._public.els.initialForm);
				that._public.els.initialForm.show();
				that.validateinitialForm();
				return false;
			});
		}
		else
		{
			that._public.els.anchorStart
				.attr('class',that._public.classes.getPCLogin)
				.text('Actualiza tu Period Calendar')
				.click(function(){
					window.open(_GLOBAL.context+'showPeriodCalendarPopup.html','Period_Calendar','width=752, height=442, scrollbars=NO, resizable=NO');
					return false;
				});
		}
	}
// END: PRIVATE METHODS


// INI: CONSTRUCTOR
	(function()
	{
	// INI: Configure error layout
		$('#back').hide();
		$('#back').css({
			zIndex		: 10,
			position	: 'absolute',
			top			: '0',
			left		: '0',
			width		: $(window).width(),
			height		: $(document).height(),
			background	: '#000',
			opacity		: 0.2,
			filter		: 'alpha(opacity=20)'
		});

		$('#stiker')
			.css({
				top : (400 + $(document).scrollTop()) + 'px',
				left: (($(window).width()/2) - 107) + 'px'
			})
			.click(function(){
				$('#back').hide();
				$(this).hide();
				return false;
			})
			.find('p a').click(function(){
				$('#back').hide();
				$('#stiker').hide();
				window.open(this.href,'Evax_VIP')
				//return false;
			});
	// END: Configure error layout

	// INI: Configiure initial start
		$.ajax({
			url		: _GLOBAL.context+'isLogged.xml',
			data	: 'nocache=' + Math.random(),
			success : function(xml)
			{
				if ( $('data userName',xml).length )
				{
					logged = true;
					hasPeriodCalendar();
				}
				else
				{
					that._public.els.anchorStart.click(function()
					{
						$('#back').css('height',$(document).height());
						$('#back').show();
						$('#stiker').show();
						return false;
					});
				}
			}/*,
			error:function(a,b,c){
				if (a.readyState == 4 && a.status== 200) {
					this.success(a.responseXML);
				}
			}*/
		});
	// END: Configiure initial start
	})();
// INI: CONSTRUCTOR

// INI: PUBLIC METHODS
	// Return public methods
	return 	{
		getLogged		: function() { return logged; },
		getPC			: function() { return hasPC; },
		getPeriodType	: function() { return periodType; }
	};
// END: PUBLIC METHODS
}

PC.prototype = {
	setActiveForm		: function(f)
	{
		this._public.els.activeForm = f;
	},

	showError			: function(txt)
	{
		this._public.els.activeForm.find( this._public.els.errorLabel).html(txt);
	},

	validateinitialForm	: function()
	{
		var that = this;
		this._public.els.initialForm
			.submit(function()
			{
				var trueDates	= that._public.els.initialForm.find('select#dia').val() != "" ||
								  that._public.els.initialForm.find('select#mes').val() != "" ||
								  that._public.els.initialForm.find('select#anyo').val() != "";

				var trueAllDates= that._public.els.initialForm.find('select#dia').val() != "" &&
								  that._public.els.initialForm.find('select#mes').val() != "" &&
								  that._public.els.initialForm.find('select#anyo').val() != "";

				var trueCheck	= that._public.els.initialForm.find('fieldset#utilidad input:checked').length;


				if (trueDates)
				{	// Tiene fechas escritas
					if( trueCheck )
					{
						that.showError('No puedes marcar la casilla si has puesto una fecha.');
					}
					else if (trueAllDates)
					{
						var formDate = that._public.els.initialForm.find('select#dia').val() +
									   '/' + that._public.els.initialForm.find('select#mes').val() +
									   '/' +that._public.els.initialForm.find('select#anyo').val();
						//that.dates.setDate( formDate )
						var datePR = new Date(formDate);
						
						var dateActual = new Date();
						
						var AD = dateActual.getDate() + '/' + (dateActual.getMonth()+1) + '/' + dateActual.getFullYear();

						if ( that.dates.isMajor(formDate,AD) ) {
							that.showError('La fecha que nos has dicho es futura. Revísala, por favor.');
						}
						else {
							if ( that.dates.isValidDate(formDate) )
							{
								// OK
								that._public.els.initialForm.hide();
								that._public.els.anchorStart.unbind('click').css('visibility','hidden');

								if( that.dates.difYears(formDate,that.dates.getDate()) >= 3)
								{
									that._public.els.majorThree.show();
									that.setActiveForm(that._public.els.majorThree);
									that.validateMajorForm();
									that._public.els.majorThree.find('input#ID_Maj_epcProfile_fechaPrimeraRegla').val(
										that._public.els.initialForm.find('select#dia').val() +
										'/' + that._public.els.initialForm.find('select#mes').val() +
										'/' +that._public.els.initialForm.find('select#anyo').val()
									);
								}
								else
								{
									that._public.els.minorThree.show();
									that.setActiveForm(that._public.els.minorThree);
									that.validateMinorForm();
									that._public.els.minorThree.find('input#ID_Min_epcProfile_fechaPrimeraRegla').val(
										that._public.els.initialForm.find('select#dia').val() +
										'/' + that._public.els.initialForm.find('select#mes').val() +
										'/' +that._public.els.initialForm.find('select#anyo').val()
									)
								}
							}
							else
							{
								that.showError('La fecha que nos has dicho no es correcta. Revísala, por favor.');
							}
						}
					}
					else
					{
						that.showError('La fecha que nos has dicho está incompleta. Revísala, por favor.');

					}
				}
				else if( trueCheck )
				{
					// Es imposible que tenga marcadas las fechas porke ya se ha comprobado
					that.showError('Gracias por tu tiempo.');
					that._public.els.activeForm.hide();
					$('#envioInfo').show();
					that._public.els.anchorStart.css('visibility','hidden');
					//debugger;
				}
				else
				{
					// No tiene escogido
					that.showError('La fecha que nos has dicho está incompleta. Revísala, por favor.');
				}
				return false;
			});
	},

	/*validateMajorForm	: function()
	{
		var that = this;
		this._public.els.majorThree.submit( function()
		{
			return false;
		});
	},*/

	checkboxesConfig	: function()
	{
		var that = this;
		var prefix = this._public.els.activeForm[0].id == "registroEpcMas" ? 'ID_Maj_' : 'ID_Min_';
		this._public.els.activeForm.find('input#'+prefix+'epcProfile_recibirSMS, input#'+prefix+'epcProfile_recibirEmail').click( function()
		{
			if ( this.checked )
			{
				that._public.els.activeForm.find('input#'+prefix+'epcProfile_recibirFAQ')[0].checked = false;

				if (this.name == 'epcProfile_recibirSMS')
					$('#'+prefix+'epcProfile_telefono').attr('disabled',false);
				else if (this.name == 'epcProfile_recibirEmail')
					$('#'+prefix+'epcProfile_eMail').attr('disabled',false);
			}
			else
			{
				if (this.name == 'epcProfile_recibirSMS')
					$('#'+prefix+'epcProfile_telefono').attr('disabled',true);
				else if (this.name == 'epcProfile_recibirEmail')
					$('#'+prefix+'epcProfile_eMail').attr('disabled',true);
			}
		});

		this._public.els.activeForm.find('input#'+prefix+'epcProfile_recibirFAQ').click( function()
		{
			if ( this.checked )
			{
				that._public.els.activeForm.find('input#'+prefix+'epcProfile_recibirSMS, input#'+prefix+'epcProfile_recibirEmail').each(function()
				{
					this.checked = false;
				})
				$('#'+prefix+'epcProfile_telefono').attr('disabled',true);
				$('#'+prefix+'epcProfile_eMail').attr('disabled',true);
			}
		});
	},

	validateMinorForm	: function()
	{
		this.checkboxesConfig();
		var that = this;
		var periodCrono = {
			0	: 'penúltima',
			1	: 'antepenúltima',
			2	: 'anterior'
		}

		this._public.els.minorThree.submit( function()
		{
			that.showError('');
			// Limpiamos de espacio los campos de texto
			$('form#registroEpcMenos input[type=text]').each( function(){ this.value = $.trim(this.value) } );


			// Recuperamos el año actual como año de la ultima regla
			var d = new Date();
			var year  = parseInt(d.getFullYear());

			// Almacenamos fecha de alta
			$('input#ID_Min_epcProfile_fechaAlta').val( d.getDate() + '/' + (d.getMonth()+1) + '/' + d.getFullYear() )


			// Comprobamos fecha de la ultima regla
			if ( ( $('#ID_Min_epcConf_diaLast').val() != "" &&
				 $('#ID_Min_mes').val() != "" ) &&
				 that.dates.isValidDate( $('#ID_Min_epcConf_diaLast').val() + '/' + $('#ID_Min_mes').val() + '/' + year ) )
			{
				// Comprobamos si el mes de la priemra regla es anterior al actual, y si es menos actiualizamos el año de la ultima regla
				var lastPeriodMonth = parseInt( $('#ID_Min_mes').val() ) - 1;

				var yearLastPeriod = parseInt( $('#ID_Min_mes').val() ) > (d.getMonth()+1) ? (parseInt(d.getFullYear())-1) : parseInt(d.getFullYear());

				var lastPeriod = $('#ID_Min_epcConf_diaLast').val() + '/' + $('#ID_Min_mes').val() + '/' + yearLastPeriod;

				// Actualizamos input hidden de la ultima fecha
				$('input#ID_Min_epcProfile_fechaUltimaRegla1').val(lastPeriod);

				// Creamos chivato de control de submision del formulario
				var submit = true;

				// Comprobamos penultima regla
				// Solo si estan los dos campos rellenados hacemos la comprobacion comprobamos
				var lastDate = null;
				for(i = 0; i < 3; i++)
				{
					// Comprobamos si dejo alguno de los dos campos de fechas vacios
					if ( ( $('#ID_Min_epcConf_dia'+i).val() != "" && $('#ID_Min_mes'+i).val() == "") ||
						 ( $('#ID_Min_epcConf_dia'+i).val() == "" && $('#ID_Min_mes'+i).val() != "") )
					{
						that.showError('Debes introducir la fecha de tu \''+periodCrono[i]+'\' regla. Si no te acuerdas, puedes dejar estos campos en blanco.');
						submit = false;
						break;
					}
					// Si no, comprobamos si estan los dos rellenados
					else if ( ( $('#ID_Min_epcConf_dia'+i).val() != "" && $('#ID_Min_mes'+i).val() != "") )
					{
						// Comprobamos si la fecha es correcta
						if ( that.dates.isValidDate( $('#ID_Min_epcConf_dia'+i).val() + '/' + $('#ID_Min_mes'+i).val() + '/' + year ) )
						{
							var _month = parseInt( $('#ID_Min_mes'+i).val() ) -1;
							if ( _month > lastPeriodMonth ) yearLastPeriod--;
							var _date =  $('#ID_Min_epcConf_dia'+i).val() + '/' + $('#ID_Min_mes'+i).val() + '/' + yearLastPeriod;

							// Comprobamos si marco el ciclo
							var CM =  parseInt($('#ID_Min_ciclo').val()) || 1;

							if (i == 0)
							{
								if ( that.dates.isMajor(_date, lastPeriod) || that.dates.isEqual(_date, lastPeriod) /*> CM && $('#ID_Min_ciclo').val() != ""*/ )
								{
									// Error en el periodo de fechas entre la ultima y la penultima
									that.showError("Las fechas de tu penúltima regla no es anterior a tu última regla.");
									submit = false;
									break;
								}
								else
								{
									$('input#ID_Min_epcProfile_fechaUltimaRegla'+(i+2)).val(_date);
								}
							}
							else
							{
								if ( that.dates.isMajor(_date, lastPeriod) || that.dates.isEqual(_date, lastPeriod) /* != CM && $('#ID_Min_ciclo').val() != ""*/)
								{
									// Error en el periodo de fechas entre la ultima y la penultima
									that.showError("Las fechas de tu '"+periodCrono[i-1]+"' no es anteriors a tu '"+periodCrono[i]+"' regla.");
									submit = false;
									break;
								}
								else
								{
									$('input#ID_Min_epcProfile_fechaUltimaRegla'+(i+2)).val(_date);
								}
							}
							lastPeriod = _date;
						}
						else
						{
							if (i == 0)
							{
								that.showError("La fecha de tu penúltima regla no es correcta. Revísala, por favor.");
							}
							else
							{
								that.showError("La fecha de tu '"+periodCrono[i]+"' regla no es correcta. Revísala, por favor.");
							}
							submit = false;
							break;
						}
					}
				}
				
				var CM =  parseInt($('#ID_Min_ciclo').val());
				var reglas = [];
				reglas[0] = $('#ID_Min_epcProfile_fechaUltimaRegla1').val();
				reglas[1] = $('#ID_Min_epcProfile_fechaUltimaRegla2').val();
				reglas[2] = $('#ID_Min_epcProfile_fechaUltimaRegla3').val();
				reglas[3] = $('#ID_Min_epcProfile_fechaUltimaRegla4').val();

				if ( !isNaN(CM) ) {
					$.each(reglas,function(i){
						if ( i > 0 ) {
							if ( reglas[i] != ""	 ) {
								if ( that.dates.isValidDate(reglas[i])  ) {
									if ( that.dates.difDays(reglas[i],reglas[i-1] ) != CM ) {
										that.showError("Las fechas no coinciden con el ciclo menstrual introducido.");
										submit = false;
										i = reglas.length;
									}
								}
							}
						}
					});
				}
				/*if ( !isNaN(CM) ) {
					for(i = 0; i < 3; i++) {
						if ( ( $('#ID_Min_epcConf_dia'+i).val() != "" && $('#ID_Min_mes'+i).val() != "") ) {
							if ( that.dates.isValidDate( $('#ID_Min_epcConf_dia'+i).val() + '/' + $('#ID_Min_mes'+i).val() + '/' + year ) ) {
								var _month = parseInt( $('#ID_Min_mes'+i).val() ) -1;
								if ( _month > lastPeriodMonth ) yearLastPeriod--;
								var _date =  $('#ID_Min_epcConf_dia'+i).val() + '/' + $('#ID_Min_mes'+i).val() + '/' + yearLastPeriod;
								if (i == 0)
								{
									if ( that.dates.difDays(_date, lastPeriod) > CM && $('#ID_Min_ciclo').val() != "" )
									{
										// Error en el periodo de fechas entre la ultima y la penultima
										that.showError("Las fechas de tu última y penúltima regla no se corresponden con el ciclo menstrual que nos has dicho.");
										submit = false;
										break;
									}
									else
									{
										$('input#ID_Min_epcProfile_fechaUltimaRegla'+(i+2)).val(_date);
									}
								}
								else
								{
									if ( that.dates.difDays(_date, lastPeriod) != CM && $('#ID_Min_ciclo').val() != "")
									{
										// Error en el periodo de fechas entre la ultima y la penultima
										that.showError("Las fechas de tu '"+periodCrono[i-1]+"' y '"+periodCrono[i]+"' regla no se corresponden con el ciclo menstrual que nos has dicho.");
										submit = false;
										break;
									}
									else
									{
										$('input#ID_Min_epcProfile_fechaUltimaRegla'+(i+2)).val(_date);
									}
								}
							}
						}
					}
				}*/
				if ( submit )
				{
					// Control de checks
					if (that._public.els.minorThree.find('input#ID_Min_epcProfile_recibirSMS:checked, input#ID_Min_epcProfile_recibirEmail:checked, input#ID_Min_epcProfile_recibirFAQ:checked').length > 0)
					{

						if ( that._public.els.minorThree.find('input#ID_Min_epcProfile_recibirSMS:checked, input#ID_Min_epcProfile_recibirEmail:checked').length > 0 )
						{
							if ( that._public.els.minorThree.find('input#ID_Min_epcProfile_recibirSMS:checked').length > 0 )
							{
								// Comprobar telefono
								var r = new RegExp(/[6][0-9]{8}/);
								if ( !r.test( that._public.els.minorThree.find('input#ID_Min_epcProfile_telefono').val() ) )
								{
									that.showError('Si quieres que te avisemos vía sms, debes facilitarnos tu teléfono móvil en tu VIP. Actualízalo <a href="'+_GLOBAL.context+'zonazip" style="color:#419DE6">aquí</a>.');
									submit = false;
								}
							}
							if ( that._public.els.minorThree.find('input#ID_Min_epcProfile_recibirEmail:checked').length > 0 && submit )
							{
								// Comprobar mail
								var r = new RegExp(/^([\w\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
								if ( !r.test( that._public.els.minorThree.find('input#ID_Min_epcProfile_eMail').val() ) )
								{
									that.showError('El email que nos has dicho no es correcto. Revísalo, por favor.');
									submit = false;
								}
							}

							if ( submit )
							{
								that.showError('Enviando datos...');
								that.sendMinorThree();
							}
						}
						else
						{
							that.showError('Enviando datos...');
							that.sendMinorThree();
						}
					}
					else
					{
						that.showError('Debes indicarnos cómo quieres que te avisemos cuando llegue la fecha de tu próxima regla.');
					}
				}

			}
			else
			{
				that.showError('Debes introducir la fecha aproximada de tu última regla.');
			}

			return false;
		});
	},

	sendMinorThree	: function()
	{
		var that = this;
		var f = $('input#ID_Min_epcProfile_recibirFAQ').val();
		//$('input#ID_Min_epcProfile_recibirFAQ').val( f == "true" ? "N" : "S" );
		$.ajax({
			url		: that._public.update ? _GLOBAL.context+'updatePC.xml' : _GLOBAL.context+'savePC.xml',
			data	: 'nocache=' + Math.random() + '&' + $('input#ID_Min_epcProfile_fechaPrimeraRegla, input#ID_Min_epcProfile_CM, input#ID_Min_epcProfile_fechaUltimaRegla1, input#ID_Min_epcProfile_fechaUltimaRegla2, input#ID_Min_epcProfile_fechaUltimaRegla3, input#ID_Min_epcProfile_fechaUltimaRegla4, input#ID_Min_epcProfile_recibirEmail, input#ID_Min_epcProfile_recibirSMS , input#ID_Min_epcProfile_recibirFAQ, input#ID_Min_epcProfile_telefono, input#ID_Min_epcProfile_eMail, input#ID_Min_epcProfile_fechaAlta, select#ID_Min_ciclo').serialize(),
			success : function(xml)
			{
				//if ( $('error',xml).text() != "1" )
				if ( $('error', $(xml)[0].responseText).text() != "1" )
				{
					that._public.els.activeForm.hide();
					that._public.els.anchorStart
						.css('visibility','visible')
						.attr('class',that._public.classes.getPCLogin)
						.text('Actualiza tu Period Calendar')
						.unbind('click')
						.click(function(){
							window.open(_GLOBAL.context+'showPeriodCalendarPopup.html','Period_Calendar','width=752, height=442, scrollbars=NO, resizable=NO');
							return false;
						});
				}
				else
				{
					var errorMsg = "";
					/*$('ul',xml).each(function()
					{
						errorMsg+=$(this).find('li span').text()+'<br />';
					});*/
					errorMsg =  $('ul', $(xml)[0].responseText).text();
					that.showError(errorMsg);
				}
			},
			error:function(a,b,c){
				if (a.readyState == 4 && a.status== 200) {
					this.success(a);
				}
			}
		});
	},

	validateMajorForm	: function()
	{
		this.checkboxesConfig();
		var that = this;

		this._public.els.majorThree.submit( function()
		{

			that.showError('');
			// Limpiamos de espacio los campos de texto
			$('form#registroEpcMas input[type=text]').each( function(){ this.value = $.trim(this.value) } );


			// Recuperamos el año actual como año de la ultima regla
			var d = new Date();
			var year  = parseInt(d.getFullYear());

			// Almacenamos fecha de alta
			$('input#ID_Maj_epcProfile_fechaAlta').val( d.getDate() + '/' + (d.getMonth()+1) + '/' + d.getFullYear() )

			//var submit = true;

			// Comprobamos fecha de la ultima regla
			if ( $('#ID_Maj_epcConf_diaLast').val() != "" && $('#ID_Maj_mes').val() != "" &&
				that.dates.isValidDate( $('#ID_Maj_epcConf_diaLast').val() + '/' + $('#ID_Maj_mes').val() + '/' + year ) )
			{
				// Comprobamos si el mes de la priemra regla es anterior al actual, y si es menos actiualizamos el año de la ultima regla
				var lastPeriodMonth = parseInt( $('#ID_Maj_mes').val() ) - 1;
				var yearLastPeriod = parseInt( $('#ID_Maj_mes').val() ) > (d.getMonth()+1) ? (parseInt(d.getFullYear())-1) : parseInt(d.getFullYear());
				//var yearLastPeriod = parseInt(d.getFullYear()) - 1;
				var lastPeriod = $('#ID_Maj_epcConf_diaLast').val() + '/' + $('#ID_Maj_mes').val() + '/' + yearLastPeriod;

				// Actualizamos input hidden de la ultima fecha
				$('input#ID_Maj_epcProfile_fechaUltimaRegla1').val(lastPeriod);
				if ( $('select#ID_Maj_ciclo').val() == "" )
				{
					that.showError('Debes indicarnos tu ciclo menstrual');
				}
				else
				{
					// Control de checks
					if (that._public.els.majorThree.find('input#ID_Maj_epcProfile_recibirSMS:checked, input#ID_Maj_epcProfile_recibirEmail:checked, input#ID_Maj_epcProfile_recibirFAQ:checked').length > 0)
					{

						if ( that._public.els.majorThree.find('input#ID_Maj_epcProfile_recibirSMS:checked, input#ID_Maj_epcProfile_recibirEmail:checked').length > 0 )
						{
							var submit = true;

							if ( that._public.els.majorThree.find('input#ID_Maj_epcProfile_recibirSMS:checked').length > 0 )
							{
								// Comprobar telefono
								var r = new RegExp(/[6][0-9]{8}/);
								if ( !r.test( that._public.els.majorThree.find('input#ID_Maj_epcProfile_telefono').val() ) )
								{
									that.showError('El teléfono que nos has dicho no es correcto. Revísalo, por favor.');
									submit = false;
								}
							}
							if ( that._public.els.majorThree.find('input#ID_Maj_epcProfile_recibirEmail:checked').length > 0 && submit )
							{
								// Comprobar mail
								var r = new RegExp(/^([\w\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
								if ( !r.test( that._public.els.majorThree.find('input#ID_Maj_epcProfile_eMail').val() ) )
								{
									that.showError('El email que nos has dicho no es correcto. Revísalo, por favor.');
									submit = false;
								}
							}

							if ( submit )
							{
								that.showError('Enviando datos...');
								that.sendMajorThree();
							}
						}
						else
						{
							that.showError('Enviando datos...');
							that.sendMajorThree();
						}
					}
					else
					{
						that.showError('Debes indicarnos cómo quieres que te avisemos cuando llegue la fecha de tu próxima regla.');
					}
				}
			}
			else
			{
				that.showError('Debes introducir la fecha aproximada de tu última regla.');
			}

			return false;
		});
	},

	sendMajorThree	: function()
	{
		var that = this;
		$.ajax({
			url		: that._public.update ? _GLOBAL.context+'updatePC.xml' : _GLOBAL.context+'savePC.xml',
			dataType: 'XML',
			data	: 'nocache=' + Math.random() + '&' + $('input#ID_Maj_epcProfile_fechaPrimeraRegla, input#ID_Maj_epcProfile_CM, input#ID_Maj_epcProfile_fechaUltimaRegla1, input#ID_Maj_epcProfile_fechaUltimaRegla2, input#ID_Maj_epcProfile_fechaUltimaRegla3, input#ID_Maj_epcProfile_fechaUltimaRegla4, input#ID_Maj_epcProfile_recibirEmail, input#ID_Maj_epcProfile_recibirSMS , input#ID_Maj_epcProfile_recibirFAQ, input#ID_Maj_epcProfile_telefono, input#ID_Maj_epcProfile_eMail, input#ID_Maj_epcProfile_fechaAlta, select#ID_Maj_ciclo').serialize(),
			success : function(xml)
			{
				//if ( $('error',xml).text() != "1" )
				if ( $('error', $(xml)[0].responseText).text() != "1" )
				{
					that._public.els.activeForm.hide();
					that._public.els.anchorStart
						.css('visibility','visible')
						.attr('class',that._public.classes.getPCLogin)
						.text('Actualiza tu Period Calendar')
						.unbind('click')
						.click(function(){
							window.open(_GLOBAL.context+'showPeriodCalendarPopup.html','Period_Calendar','width=752, height=442, scrollbars=NO, resizable=NO');
							return false;
						});
				}
				else
				{
					var errorMsg = "";
					//$('ul',xml).each(function()
					//{
					//	errorMsg+=$(this).find('li span').text()+'<br />';
					//});
					errorMsg =  $('ul', $(xml)[0].responseText).text();
					that.showError(errorMsg);
				}
			},
			error:function(a,b,c){
				alert('err');
				if (a.readyState == 4 && a.status== 200) {
					this.success(a.responseXML);
				}
			}
		});
	}
}



$(function()
{
	$('.btn_volver').click(function()
	{
		$('#primeraRegla').find('.errorForm').html('');
		$('#primeraRegla').show();

		$('#registroEpcMenos, #registroEpcMas').hide();
		return false;
	});

	$('#envioInfo .btn-no').click(function()
	{
		$('#envioInfo').html('<p>Gracias por tu tiempo</p>');
		return false;
	});

	$('#envioInfo .btn-si').click(function()
	{
		$.ajax({
			url		: _GLOBAL.context+'savePC.xml',
			data	: 'epcProfile.recibirSMS=N&epcProfile.recibirFAQ=S&epcProfile.recibirEmail=S',
			success	: function(xml){
				$('#envioInfo').html('<p>Gracias por tu tiempo</p>');
			}/*,
			error:function(a,b,c){
				if (a.readyState == 4 && a.status== 200) {
					this.success(a.responseXML);
				}
			}*/
		});
		return false;
	})
});

$(function(){
	$('#ID_Min_epcProfile_telefono,#ID_Min_epcProfile_eMail,#ID_Maj_epcProfile_telefono,#ID_Maj_epcProfile_eMail').unbind('keyup').keyup(function(a){
		return false;
	})
});
