//CREACION DE FORMULARIOS
//Autor: Iván Nieto Pérez
//Este script y otros muchos pueden
//descarse on-line de forma gratuita
//en El Código: www.elcodigo.net


function VerEjemplo(formulario) {

	//obtiene el codigo del formulario
	var pagina = ObtieneFormulario(formulario)

	//muestra el contenido del display
	ventana = open()
	ventana.document.write(pagina)
	ventana.document.close()

}

function VerScript(formulario) {
	var pagina = ObtieneFormulario(formulario)
	document.FormEleccion.display.value = pagina
	document.location = "#verscript"
}

function ObtieneFormulario(formulario) {

campo1 = ""
campo2 = ""
campo3 = ""
campo4 = ""
botones = ""
cod_formulario = ""

	with (formulario) {
	
	if (tipo1.selectedIndex != 0) {
		if (tipo1.selectedIndex == 1) 		//tipo texto
			campo1 += '<p>' + nombre1.value + '<br><input type="text" size="22" name="campo1" value="' + valorinicial1.value + '">\n'
		else if (tipo1.selectedIndex == 2)	//tipo check
			campo1 += '<p><input type="checkbox" name="campo1" value="' + valorinicial1.value + '"' + (seleccionado1.checked ? ' checked' : '' ) + '> ' + nombre1.value + '\n'
		else if (tipo1.selectedIndex == 3)	//tipo radio
			campo1 += '<p><input type="radio" name="campoRadio" value="' + valorinicial1.value + '"' + (seleccionado1.checked ? ' checked' : '' ) + '> ' + nombre1.value + '\n'
	}

	if (tipo2.selectedIndex != 0) {
		if (tipo2.selectedIndex == 1) 		//tipo texto
			campo2 += '<p>' + nombre2.value + '<br><input type="text" size="22" name="campo2" value="' + valorinicial2.value + '">\n'
		else if (tipo2.selectedIndex == 2)	//tipo check
			campo2 += '<p><input type="checkbox" name="campo2" value="' + valorinicial2.value + '"' + (seleccionado2.checked ? ' checked' : '' ) + '> ' + nombre2.value + '\n'
		else if (tipo2.selectedIndex == 3)	//tipo radio
			campo2 += '<p><input type="radio" name="campoRadio" value="' + valorinicial2.value + '"' + (seleccionado2.checked ? ' checked' : '' ) + '> ' + nombre2.value + '\n'
	}

	if (tipo3.selectedIndex != 0) {
		if (tipo3.selectedIndex == 1) 		//tipo texto
			campo3 += '<p>' + nombre3.value + '<br><input type="text" size="22" name="campo3" value="' + valorinicial3.value + '">\n'
		else if (tipo3.selectedIndex == 2)	//tipo check
			campo3 += '<p><input type="checkbox" name="campo3" value="' + valorinicial3.value + '"' + (seleccionado3.checked ? ' checked' : '' ) + '> ' + nombre3.value + '\n'
		else if (tipo3.selectedIndex == 3)	//tipo radio
			campo3 += '<p><input type="radio" name="campoRadio" value="' + valorinicial3.value + '"' + (seleccionado3.checked ? ' checked' : '' ) + '> ' + nombre3.value + '\n'
	}

	if (tipo4.selectedIndex != 0) {
		if (tipo4.selectedIndex == 1) 		//tipo texto
			campo4 += '<p>' + nombre4.value + '<br><input type="text" size="22" name="campo4" value="' + valorinicial4.value + '">\n'
		else if (tipo4.selectedIndex == 2)	//tipo check
			campo4 += '<p><input type="checkbox" name="campo4" value="' + valorinicial4.value + '"' + (seleccionado4.checked ? ' checked' : '' ) + '> ' + nombre4.value + '\n'
		else if (tipo4.selectedIndex == 3)	//tipo radio
			campo4 += '<p><input type="radio" name="campoRadio" value="' + valorinicial4.value + '"' + (seleccionado4.checked ? ' checked' : '' ) + '> ' + nombre4.value + '\n'
	}

	botones += (enviar.checked) ? '<input type="submit" value="Enviar"> \n' : ''
	botones += (borrar.checked) ? '<input type="reset" value="Restaurar"> \n' : ''
	
	cod_formulario = '<form action="' + (accion.selectedIndex == 0 ? 'mailto:' + proceso.value + '">' : proceso.value + '" ' + accion.options[accion.selectedIndex].value + '>') + '\n' +
		campo1 + campo2 + campo3 + campo4 + '<p>' + botones + '</form>'
	}	
	
	return '<html><head>\n' +
		'<title>Formulario</title>\n' +
		'</head>\n' +
		'<body>\n' + cod_formulario +
		'</body>'
}
