selEstadoCivil = new Array(
	new Array(1, "Soltero"),
	new Array(2, "Casado"),
	new Array(3, "Divorciado"),
	new Array(4, "Separado"),
	new Array(5, "Viudo")
);

selSexo = new Array(
	new Array(1, "Mujer"),
	new Array(2, "Hombre")
);

selEstudios = new Array(
	new Array(1, "Elementales"),
	new Array(2, "Primarios"),
	new Array(3, "Secundarios"),
	new Array(4, "Medios I"),
	new Array(5, "Medios II"),
	new Array(6, "Superiores"),
	new Array(8, "Otros")
);

selPais = new Array(
	new Array(660, "AFGANISTÁN"),
	new Array( 70, "ALBANIA"),
	new Array(  4, "ALEMANIA"),
	new Array( 43, "ANDORRA"),
	new Array(330, "ANGOLA"),
	new Array(446, "ANGUILLA"),
	new Array( 96, "ANTIGUA REP. YUGOSLAVA DE MACEDONIA"),
	new Array(459, "ANTIGUA Y BARBUDA"),
	new Array(478, "ANTILLAS NEERLANDESAS"),
	new Array(632, "ARABIA SAUDITA"),
	new Array(208, "ARGELIA"),
	new Array(528, "ARGENTINA"),
	new Array( 77, "ARMENIA"),
	new Array(474, "ARUBA"),
	new Array(800, "AUSTRALIA"),
	new Array( 38, "AUSTRIA"),
	new Array( 78, "AZERBAIJAN"),
	new Array(453, "BAHAMAS"),
	new Array(640, "BAHREIN"),
	new Array(666, "BANGLADESH"),
	new Array(469, "BARBADOS"),
	new Array( 17, "BÉLGICA"),
	new Array(421, "BELIZE"),
	new Array(284, "BENÍN"),
	new Array(413, "BERMUDAS"),
	new Array(675, "BHOUTAN"),
	new Array( 73, "BIELORRUSIA"),
	new Array(516, "BOLIVIA"),
	new Array( 93, "BOSNIA-HERZEGOVINA"),
	new Array(391, "BOTSWANA"),
	new Array(508, "BRASIL"),
	new Array(703, "BRUNEI"),
	new Array( 68, "BULGARIA"),
	new Array(236, "BURKINA-FASO (Alto Volta)"),
	new Array(328, "BURUNDI"),
	new Array(302, "CAMERÚN"),
	new Array(404, "CANADÁ"),
	new Array(512, "CHILE"),
	new Array(720, "CHINA"),
	new Array(600, "CHIPRE"),
	new Array( 45, "CIUDAD DEL VATICANO"),
	new Array(480, "COLOMBIA"),
	new Array(375, "COMORES"),
	new Array(318, "CONGO"),
	new Array(724, "COREA DEL NORTE"),
	new Array(728, "COREA DEL SUR"),
	new Array(272, "COSTA DE MARFIL"),
	new Array(436, "COSTA RICA"),
	new Array( 92, "CROACIA"),
	new Array(448, "CUBA"),
	new Array(  8, "DINAMARCA"),
	new Array(338, "DJIBOUTI"),
	new Array(460, "DOMINICA"),
	new Array(500, "ECUADOR"),
	new Array(220, "EGIPTO"),
	new Array(428, "EL SALVADOR"),
	new Array(647, "EMIRATOS ÁRABES UNIDOS"),
	new Array(336, "ERITREA"),
	new Array( 91, "ESLOVENIA"),
	new Array( 11, "ESPAÑA"),
	new Array(400, "ESTADOS UNIDOS DE AMÉRICA"),
	new Array( 53, "ESTONIA"),
	new Array(334, "ETIOPÍA"),
	new Array(823, "FEDERACIÓN DE ESTADOS DE MICRONESIA"),
	new Array(815, "FIDJI"),
	new Array(708, "FILIPINAS"),
	new Array( 32, "FINLANDIA"),
	new Array(  1, "FRANCIA"),
	new Array(314, "GABÓN"),
	new Array(252, "GAMBIA"),
	new Array(625, "GAZA Y JERICÓ"),
	new Array( 76, "GEORGIA"),
	new Array(276, "GHANA"),
	new Array( 44, "GIBRALTAR"),
	new Array(473, "GRANADA"),
	new Array(  9, "GRECIA"),
	new Array(406, "GROENLANDIA"),
	new Array(416, "GUATEMALA"),
	new Array(488, "GUAYANA"),
	new Array(310, "GUINEA ECUATORIAL"),
	new Array(260, "GUINEA"),
	new Array(257, "GUINEA-BISSAU"),
	new Array(452, "HAITÍ"),
	new Array(424, "HONDURAS"),
	new Array(740, "HONG-KONG"),
	new Array( 64, "HUNGRÍA"),
	new Array(664, "INDIA"),
	new Array(700, "INDONESIA"),
	new Array(616, "IRÁN"),
	new Array(612, "IRAQ"),
	new Array(  7, "IRLANDA"),
	new Array(104, "ISLA DE MAN"),
	new Array( 24, "ISLANDIA"),
	new Array(103, "ISLAS ANGLONORMANDAS"),
	new Array(463, "ISLAS CAYMAN"),
	new Array(107, "ISLAS COOK"),
	new Array( 41, "ISLAS FEROE"),
	new Array(529, "ISLAS MALVINAS (FALKLANDS)"),
	new Array(820, "ISLAS MARIANAS DEL NORTE"),
	new Array(824, "ISLAS MARSHALL"),
	new Array(806, "ISLAS SALOMÓN"),
	new Array(454, "ISLAS TURKS Y CAICOS"),
	new Array(468, "ISLAS VÍRGENES BRITÁNICAS"),
	new Array(457, "ISLAS VÍRGENES DE LOS ESTADOS UNIDOS"),
	new Array(811, "ISLAS WALLIS Y FORTUNA"),
	new Array(624, "ISRAEL"),
	new Array(  5, "ITALIA"),
	new Array(464, "JAMAICA"),
	new Array(732, "JAPÓN"),
	new Array(628, "JORDANIA"),
	new Array(696, "KAMPUCHEA (Camboya)"),
	new Array( 79, "KAZAJSTAN"),
	new Array(346, "KENYA"),
	new Array( 83, "KIRGUIZISTÁN"),
	new Array(812, "KIRIBATI"),
	new Array(636, "KUWAIT"),
	new Array(684, "LAOS"),
	new Array(395, "LESOTHO"),
	new Array( 54, "LETONIA"),
	new Array(604, "LÍBANO"),
	new Array(268, "LIBERIA"),
	new Array(216, "LIBIA"),
	new Array( 37, "LIECHTENSTEIN"),
	new Array( 55, "LITUANIA"),
	new Array( 18, "LUXEMBURGO"),
	new Array(118, "LUXEMBURGO"),
	new Array(743, "MACAO"),
	new Array(370, "MADAGASCAR"),
	new Array(701, "MALASIA OCCIDENTAL Y ORIENTAL"),
	new Array(386, "MALAWI"),
	new Array(667, "MALDIVAS (Islas)"),
	new Array(232, "MALI"),
	new Array( 46, "MALTA"),
	new Array(204, "MARRUECOS"),
	new Array(373, "MAURICIO"),
	new Array(228, "MAURITANIA"),
	new Array(377, "MAYOTTE"),
	new Array(412, "MÉXICO"),
	new Array( 74, "MOLDAVIA"),
	new Array(101, "MÓNACO"),
	new Array(716, "MONGOLIA"),
	new Array(470, "MONTSERRAT"),
	new Array(366, "MOZAMBIQUE"),
	new Array(676, "MYANMAR (Antigua Birmania)"),
	new Array(389, "NAMIBIA"),
	new Array(803, "NAURU"),
	new Array(672, "NEPAL"),
	new Array(432, "NICARAGUA"),
	new Array(240, "NIGER"),
	new Array(288, "NIGERIA"),
	new Array( 28, "NORUEGA"),
	new Array(809, "NUEVA CALEDONIA Y DEPENDENCIAS"),
	new Array(804, "NUEVA ZELANDA"),
	new Array(810, "OCEANÍA AMERICANA"),
	new Array(802, "OCEANÍA AUSTRALIANA"),
	new Array(814, "OCEANÍA NEO-ZELANDESA"),
	new Array(649, "OMÁN"),
	new Array(  3, "PAÍSES BAJOS"),
	new Array(662, "PAKISTÁN"),
	new Array(825, "PALAU"),
	new Array(442, "PANAMÁ"),
	new Array(801, "PAPÚA-NUEVA GUINEA"),
	new Array(520, "PARAGUAY"),
	new Array(504, "PERÚ"),
	new Array(813, "PITCAIM"),
	new Array(822, "POLINESIA FRANCESA"),
	new Array( 60, "POLONIA"),
	new Array( 10, "PORTUGAL"),
	new Array(401, "PUERTO RICO"),
	new Array(644, "QATAR"),
	new Array(890, "REGIONES POLARES"),
	new Array(  6, "REINO UNIDO"),
	new Array( 94, "REP. FED. YUGOSLAVA ( SERBIA Y MONTENEGRO)"),
	new Array(306, "REPÚBLICA CENTRO AFRICANA"),
	new Array( 61, "REPÚBLICA CHECA"),
	new Array(247, "REPÚBLICA DE CABO VERDE"),
	new Array(456, "REPÚBLICA DOMINICANA"),
	new Array( 63, "REPÚBLICA ESLOVACA"),
	new Array( 66, "RUMANÍA"),
	new Array( 75, "RUSIA"),
	new Array(324, "RWANDA"),
	new Array(819, "SAMOA OCCIDENTAL"),
	new Array(449, "SAN CRISTÓBAL Y NEVIS"),
	new Array( 47, "SAN MARINO"),
	new Array(408, "SAN PEDRO Y MIQUELON"),
	new Array(467, "SAN VICENTE"),
	new Array(329, "SANTA HELENA Y DEPENDENCIAS"),
	new Array(465, "SANTA LUCÍA"),
	new Array(311, "SANTO TOMÉ Y PRÍNCIPE"),
	new Array(248, "SENEGAL"),
	new Array(355, "SEYCHELLES Y DEPENDENCIAS"),
	new Array(264, "SIERRA LEONA"),
	new Array(706, "SINGAPUR"),
	new Array(608, "SIRIA"),
	new Array(342, "SOMALIA"),
	new Array(669, "SRI LANKA"),
	new Array(388, "SUDÁFRICA"),
	new Array(224, "SUDÁN"),
	new Array( 30, "SUECIA"),
	new Array( 39, "SUIZA"),
	new Array(492, "SURINAM"),
	new Array(393, "SWAZILAND"),
	new Array(736, "TAIWAN"),
	new Array( 82, "TAJIKISTÁN"),
	new Array(352, "TANZANIA"),
	new Array(244, "TCHAD"),
	new Array(357, "TERRITORIO BRITÁNICO DEL OCÉANO ÍNDICO"),
	new Array(680, "THAILANDIA"),
	new Array(280, "TOGO"),
	new Array(817, "TONGA"),
	new Array(472, "TRINIDAD Y TOBAGO"),
	new Array(212, "TÚNEZ"),
	new Array( 80, "TURKMENISTÁN"),
	new Array( 52, "TURQUÍA"),
	new Array(807, "TUVALU"),
	new Array( 72, "UCRANIA"),
	new Array(350, "UGANDA"),
	new Array(524, "URUGUAY"),
	new Array( 81, "UZBEKISTÁN"),
	new Array(816, "VANUATU"),
	new Array(484, "VENEZUELA"),
	new Array(690, "VIETNAM"),
	new Array(653, "YEMEN"),
	new Array(322, "ZAIRE"),
	new Array(378, "ZAMBIA"),
	new Array(382, "ZIMBABWE"),
	new Array(958, "OTROS")
);

selProvincia = new Array(
	new Array(0, "Fuera de España"),
	new Array(1, "Alava/Araba"),
	new Array(2, "Albacete"),
	new Array(3, "Alicante"),
	new Array(4, "Almería"),
	new Array(5, "Avila"),
	new Array(6, "Badajoz"),
	new Array(7, "Baleares/Illes Balears"),
	new Array(8, "Barcelona"),
	new Array(9, "Burgos"),
	new Array(10, "Cáceres"),
	new Array(11, "Cádiz"),
	new Array(12, "Castellón"),
	new Array(13, "Ciudad Real"),
	new Array(14, "Córdoba"),
	new Array(15, "Coruña, A"),
	new Array(16, "Cuenca"),
	new Array(17, "Girona"),
	new Array(18, "Granada"),
	new Array(19, "Guadalajara"),
	new Array(20, "Guipuzcoa"),
	new Array(21, "Huelva"),
	new Array(22, "Huesca"),
	new Array(23, "Jaén"),
	new Array(24, "León"),
	new Array(25, "Lérida/Lleida"),
	new Array(26, "Rioja, La"),
	new Array(27, "Lugo"),
	new Array(28, "Madrid"),
	new Array(29, "Málaga"),
	new Array(30, "Murcia"),
	new Array(31, "Navarra"),
	new Array(32, "Ourense"),
	new Array(33, "Asturias"),
	new Array(34, "Palencia"),
	new Array(35, "Plamas, Las"),
	new Array(36, "Pontevedra"),
	new Array(37, "Salamanca"),
	new Array(38, "S.C. Tenerife"),
	new Array(39, "Cantabria"),
	new Array(40, "Segovia"),
	new Array(41, "Sevilla"),
	new Array(42, "Soria"),
	new Array(43, "Tarragona"),
	new Array(44, "Teruel"),
	new Array(45, "Toledo"),
	new Array(46, "Valencia"),
	new Array(47, "Valladolid"),
	new Array(48, "Vizcaya/Bizkaia"),
	new Array(49, "Zamora"),
	new Array(50, "Zaragoza"),
	new Array(51, "Ceuta"),
	new Array(52, "Melilla")
);

function writeOptions (tabla) {
	var i;
	document.write("<option value=\"res\">- Selecciona -");
	for (i = 0; i < tabla.length; i++) {
		document.write("<option value=\""+tabla[i][0]+"\">"+tabla[i][1]);
	}
}

function intOnly(i) {
	if(i.value.length>0) {
		i.value = i.value.replace(/[^\d]+/g, ''); 
	}
}

function floatOnly(i) {
	if(i.value.length>0) {
		i.value = i.value.replace(/[^\d,\.]+/g, ''); 
	}
}

// http://javascript.internet.com/forms/limit-textarea.html
function maxText(field, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
}


function enviaForm () {
	var errtexto = "";
	if (!document.validacion.condiciones.checked) {
		
		alert("Debes leer y aceptar las condiciones antes de enviar los datos");

	} else {
	
		if (document.validacion.nombre.value == "") { errtexto = 'Falta tu nombre.\n'; }
		if (document.validacion.apellidos.value == "") { errtexto = errtexto + 'Faltan tus apellidos.\n'; }			
		if (document.validacion.edad.value == "") { errtexto = errtexto + 'Falta la edad.\n'; }
		if (document.validacion.estado.value == "") { errtexto = errtexto + 'Falta el estado civil.\n'; }
		if (document.validacion.direccion.value == "") { errtexto = errtexto + 'Faltan tu dirección.\n'; }			
		if (document.validacion.telefono.value == "") { errtexto = errtexto + 'Falta el teléfono.\n'; }
		if (document.validacion.pais.value == "") { errtexto = errtexto + 'Falta la nacionalidad.\n'; }
		
		if (document.validacion.aficiones.value == "") { errtexto = errtexto + 'Faltan tus aficiones.\n'; }
		if (document.validacion.ciudadresidencia.value == "") { errtexto = errtexto + 'Faltan tus ciudad de residencia.\n'; }
		if (document.validacion.ciudadresidencia.value == "") { errtexto = errtexto + 'Faltan tus ciudad de residencia.\n'; }		
		if (document.validacion.vives.value == "") { errtexto = errtexto + 'Falta con quién vives.\n'; }				
		if (document.validacion.dedicas.value == "") { errtexto = errtexto + 'Falta a qué te dedicas.\n'; }				
		if (document.validacion.definete.value == "") { errtexto = errtexto + 'Falta que te definas.\n'; }						
		if (document.validacion.gusta.value == "") { errtexto = errtexto + 'Falta que te gusta de Eduardo.\n'; }						
		if (document.validacion.cualidades.value == "") { errtexto = errtexto + 'Falta que cualidades buscas en un hombre.\n'; }								
		if (document.validacion.necesita.value == "") { errtexto = errtexto + 'Falta que necesita un hombre para conquistarte.\n'; }												
		
		
		if (errtexto!="") alert("¡Atención!\n" + errtexto);
		else document.validacion.submit();

	}
}


var strLetterNIF="TRWAGMYFPDXBNJZSQVHLCKET";
var strLetterCIF="ABCDEFGHKLMPQS";
var strLetterNIE="X";


function validate_document(strDocument,intType)
{
	var blnReturn;
	
	blnReturn=false;
	
	if ((strDocument=="") || (strDocument==null))
	{
		return false
	}
	switch (intType)
	{
		case 1:
			blnReturn=validate_NIF(strDocument);
			break;
		case 2:
			blnReturn=validate_CIF(strDocument);
			break;
		case 3:
			blnReturn=validate_NIE(strDocument);
			break;
		default:
			blnReturn=false;
	}
	return blnReturn;
}

function validate_NIF(strDocument)
{
	var strPart1,strPart2;
	
	if (strDocument.length!=9) return false;
	strDocument=strDocument.toUpperCase();
	strPart1=strDocument.substr(0,strDocument.length-1);
	strPart2=strDocument.substr(strDocument.length-1,1);
	if (isNaN(strPart1))
	{
		return false;
	}
	else
	{
		return strLetterNIF.substr(parseInt(strPart1,10) % 23,1)==strPart2;
	}
}

function validate_CIF(strDocument)
{
	var strPart1,strPart2,strPart3;
	var intDigit,intCumulate,intCalculated,intPos,strReturn;
	var strCumulate,strA;
	
	if (strDocument.length!=9) return false;
	strA="A";
	strDocument=strDocument.toUpperCase();
	strPart1=strDocument.substr(0,1)
	strPart2=strDocument.substr(1,strDocument.length-2);
	strPart3=strDocument.substr(strDocument.length-1,1);
	if (strLetterCIF.search(strPart1)==-1)
	{
		return false;
	}
	if (isNaN(strPart2))
	{
		return false;
	}
	else
	{
		intCumulate=0;
		for (intPos=0;intPos<strPart2.length;intPos++)
		{
			intDigit=parseInt(strPart2.charAt(intPos));
			if ((intPos+1) % 2==0)
			{
				intCumulate=intCumulate+intDigit;
			}
			else
			{
				if (intDigit>4)
				{
					intCumulate=intCumulate+2*intDigit-9;
				}
				else
				{
					intCumulate=intCumulate+2*intDigit;
				}
			}
		}
		strCumulate=intCumulate.toString();
		intCalculated=10-parseInt(strCumulate.substr(strCumulate.length-1,1),10);
		if ((strPart1=="X") || (strPart1=="P"))
		{
			strReturn=String.fromCharCode(strA.charCodeAt(0)-1+intCalculated);
		}
		else
		{
			if (intCalculated==10)
			{
				intCalculated=0;
			}
			strReturn=intCalculated;
		}
		return strReturn==strPart3;
	}
}

function validate_NIE(strDocument)
{
	var strPart1,strPart2,strPart3;
	var intDigit,intCumulate,intCalculated,intPos,strReturn;
	var strCumulate,strA;
	
	if (strDocument.length!=10) return false;
	strA="A";
	strDocument=strDocument.toUpperCase();
	strPart1=strDocument.substr(0,1)
	strPart2=strDocument.substr(1,strDocument.length-2);
	strPart3=strDocument.substr(strDocument.length-1,1);
	if (strLetterNIE.search(strPart1)==-1)
	{
		return false;
	}
	if (isNaN(strPart2))
	{
		return false;
	}
	/*else
	{
		intCumulate=0;
		for (intPos=0;intPos<strPart2.length;intPos++)
		{
			intDigit=parseInt(strPart2.charAt(intPos));
			if (intPos % 2==0)
			{
				intCumulate=intCumulate+intDigit;
			}
			else
			{
				if (intDigit>4)
				{
					intCumulate=intCumulate+2*intDigit-9;
				}
				else
				{
					intCumulate=intCumulate+2*intDigit;
				}
			}
		}
		
		strCumulate=intCumulate.toString();
		intCalculated=10-parseInt(strCumulate.substr(strCumulate.length-1,1),10);
		if ((strPart1=="X") || (strPart1=="P"))
		{
			strReturn=String.fromCharCode(strA.charCodeAt(0)-1+intCalculated);
		}
		else
		{
			if (intCalculated==10)
			{
				intCalculated=0;
				strReturn=intCalculated;
			}
		}
		return strReturn==strPart3;
	}*/
	return strLetterNIF.substr(parseInt(strPart2,10) % 23,1)==strPart3;
}


