function checkall() {
	for(var i=0; i<document.forms[0].sec.length; ++i) {
		document.forms[0].sec[i].checked=true;
	}
}

function uncheckall() {
	for(var i=0; i<document.forms[0].sec.length; ++i) {
		document.forms[0].sec[i].checked=false;
	}
}

function showhelp() {
	w1=window.open (
		'##href_manager_help##',
		'newwindow',
		'resizable=yes,scrollbars=yes,width=500,height=400,left=30,top=30'
	);
}

function setloginfocus() {
	if(document.forms.length > 0) {
		if(document.forms[0].length > 0) {
			for (var i=0; i<document.forms[0].length; i++) {
				if (document.forms[0].elements[i].type=="text") {
					document.forms[0].elements[i].focus();
					break;
				}
			}
		}
	}
}

function newWindow(contenido) {
	wWidth = 400;
	wHeight = 300;
	wLeft = (screen.width - wWidth) / 2;
	wTop = (screen.height -wHeight) / 2;

	uploadWindow = window.open(contenido,
		'uploadWindow',
		'resizable=no, ' +
		'toolbar=no, ' +
		'location=no, ' +
		'menubar=no, ' +
		'status=no, ' +
		'titlebar=no, ' +
		'toolbar=no, ' +
		'directories=no, ' +
		'scrollbars=no, ' +
		'width=' + wWidth + ', ' +
		'height=' + wHeight + ', ' +
		'left=' + wLeft + ', ' +
		'top=' + wTop
	);
	uploadWindow.focus();
}

function comprobarCif(inputValue) {
	ts = document.getElementById('tipoSociedad');
	txtCif = document.getElementById('txtCif');
	cif = inputValue.toUpperCase();
	fcif = cif.replace(/\//g, '');
	cif = fcif;
	fcif = cif.replace(/\s/g, '');
	cif = fcif;
	fcif = cif.replace(/-/g, '');
	cif = fcif;
	fcif = cif.replace(/\./g, '');
	cif = fcif;
	txtCif.setAttribute('value', cif);
	letras_nif = ' TRWAGMYFPDXBNJZSQVHLCKE';
	letras_org = 'ABCDEFGHIJ';
	letra = cif.substring(0, 1);
	failed = true;
	ultimaLetra = cif.substr(cif.length - 1, 1);
	if (letra >= '0' && letra <= '9' || letra == 'X') {
		// es una Persona Física
		if (letra == 'X') {
			comprobar = cif.substr(1, cif.length - 2);
		} else {
			comprobar = cif.substr(0, cif.length - 1);
		}
		valor = parseInt(comprobar);
		mod23 = valor % 23;
		digitoControl = letras_nif.substr(mod23 + 1, 1);
		if (digitoControl == ultimaLetra) {
			if (letra == 'X') {
				ts.innerHTML = 'Persona Física Extranjera';
			} else {
				ts.innerHTML = 'Persona Física';
			}
			failed = false;
		}
	}
	if (letra >= 'A' && letra <= 'H' || letra == 'P' || letra == 'Q' || letra == 'S') {
		// es una Sociedad u Organismo
		comprobar = cif.substr(1, cif.length - 2);
		suma = 0;
		for (i = 0; i < 7; i++) {
			digito = parseInt(comprobar.substr(i, 1));
			if (i % 2 == 0) {
				digito *= 2;
				if (digito > 9) {
					digito = digito % 10;
					digito++;
				}
			}
			suma += digito;
		}
		mod10 = 10 - (suma % 10);
		if (letra >= 'A' && letra <= 'H') {
			if (mod10 == 10) {
				mod10 = 0;
			}
			if (mod10 == parseInt(ultimaLetra)) {
				switch (letra) {
				case 'A':
					ts.innerHTML = 'Sociedad Anónima';
					break;
				case 'B':
					ts.innerHTML = 'Sociedad Limitada';
					break;
				case 'C':
					ts.innerHTML = 'Sociedad Colectiva';
					break;
				case 'D':
					ts.innerHTML = 'Sociedad Comandataria';
					break;
				case 'E':
					ts.innerHTML = 'Comunidad de Bienes';
					break;
				case 'F':
					ts.innerHTML = 'Sociedad Cooperativa';
					break;
				case 'G':
					ts.innerHTML = 'Asociación';
					break;
				case 'H':
					ts.innerHTML = 'Comunidad de Propietarios';
					break;
				}
				failed = false;
			}
		} else {
			digitoControl = letras_org.substr(mod10 - 1, 1);
			if (ultimaLetra == digitoControl) {
				switch (letra) {
				case 'P':
					ts.innerHTML = 'Corporación Local';
					break;
				case 'Q':
					ts.innerHTML = 'Organismo Autónomo';
					break;
				case 'S':
					ts.innerHTML = 'Organismo del Estado';
					break;
				}
				failed = false;
			}
		}
	}
	if (failed) {
		ts.className = 'red';
		ts.innerHTML = 'CIF inválido';
		// alert('El CIF introducido no es válido.')
	}
}

function startupload(arc, ped) {
	var formulario = document.getElementById('formulario');
	formulario.submit();
	var div_ocultar = document.getElementById("antes");
	div_ocultar.style.display = 'none';
	var div_mostrar = document.getElementById("despues");
	div_mostrar.style.display = 'block';
}

function ef_upload() {
	var upload_text = '<img src="/images/ajax-loader.gif" style="{float: left; margin-right: 10px; margin-left: 10px;}" /><p><strong>Enviando archivo(s)</strong></p><p>Por favor, no cierre esta ventana hasta que no vuelva automáticamente al Gestor de archivos.<br />El proceso puede tardar bastante tiempo, en función del tamaño del archivo a subir y de la velocidad de subida de su conexión a Internet.</p>';

	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById('uploadform').style.display = 'none';
		document.getElementById('eftopmenu').style.display = 'none';
		document.getElementById('uploadmessage').innerHTML= upload_text;
	} else {
		if (document.layers) { // Netscape 4
			document.uploadform.display = 'none';
			document.eftopmenu.display = 'none';
			document.uploadmessage.innerHTML = upload_text;
		} else { // IE 4
			document.all.uploadform.style.display = 'none';
			document.all.eftopmenu.style.display = 'none';
			document.all.uploadmessage.innerHTML = upload_text;
		}
	}
}

