function go(url){
	var form = document.getElementById('mode').value;
	var howMany = document.getElementById('numParticipants').value;
	var thisUrl = url+'&whichForm='+form+'&howMany='+howMany;
	window.location = thisUrl;
}
function hide(divName) {
	document.getElementById(divName).style.display = 'none';
}

function show(divName) {
	document.getElementById(divName).style.display = 'block';
}

function formShowHide(selectName){
	var max = 3;
	mode = document.getElementById(selectName).value;
	for(i=1;i<=max;i++){
		if (i == mode){
			show('formPrices_'+i);
			show('formNotes_'+i);	
		}else{
			hide('formPrices_'+i);
			hide('formNotes_'+i);
		}
	}
	if(mode == '3'){
		show('coyunturaTable');
		hide('seminarTable')
	}else{
		hide('coyunturaTable');
		show('seminarTable')
	}
	clearChilds('seminarTable',3);
	clearChilds('coyunturaTable',3);
	document.getElementById('numParticipants').value = 1;
	hide('multipleParticipants');
	show('oneParticipant');
}

function clearChilds(divId,leave){
	var cell = document.getElementById(divId).getElementsByTagName("tbody")[0];

	if ( cell.hasChildNodes() )
	{
	    while ( cell.childNodes.length > leave )
	    {
	        cell.removeChild( cell.childNodes[cell.childNodes.length-1] );       
	    } 
	}
	
}
function moreFields(selectName){
	numberOfFields = document.getElementById('numParticipants').value;
	mode = document.getElementById(selectName).value;
	var fieldType = [];
	var fieldName = [];
	switch (mode){
		case '1':
			divId = 'seminarTable';
			fieldType[0] = 'text';
			fieldType[1] = 'text';
			fieldType[2] = 'text';
			fieldType[3] = 'text';
			fieldType[4] = 'text';
			fieldType[5] = 'text';
			fieldName[0] = 's_firstname';
			fieldName[1] = 's_lastname';
			fieldName[2] = 's_position';
			fieldName[3] = 's_phone';
			fieldName[4] = 's_fax';
			fieldName[5] = 's_email';
		break;
		
		case '2':
			divId = 'seminarTable';
			fieldType[0] = 'text';
			fieldType[1] = 'text';
			fieldType[2] = 'text';
			fieldType[3] = 'text';
			fieldType[4] = 'text';
			fieldType[5] = 'text';
			fieldName[0] = 's_firstname';
			fieldName[1] = 's_lastname';
			fieldName[2] = 's_position';
			fieldName[3] = 's_phone';
			fieldName[4] = 's_fax';
			fieldName[5] = 's_email';
		break;
		
		case '3':
			divId = 'coyunturaTable';
			fieldType[0] = 'text';
			fieldType[1] = 'text';
			fieldType[2] = 'text';
			fieldType[3] = 'text';
			fieldType[4] = 'text';
			fieldType[5] = 'text';
			fieldType[6] = 'text';
			fieldType[7] = 'select';
			fieldType[8] = 'select';
			fieldName[0] = 'firstname';
			fieldName[1] = 'lastname';
			fieldName[2] = 'position';
			fieldName[3] = 'phone';
			fieldName[4] = 'fax';
			fieldName[5] = 'email';
			fieldName[6] = 'postal';
			fieldName[7] = 'type';
			fieldName[8] = 'method';
		break;
	}
	clearChilds(divId,3)
	if(numberOfFields != '1'){
		show('multipleParticipants');
		hide('oneParticipant');
		for (i = 1; i < numberOfFields; i++) {
			addTableRow(divId,i,fieldType,fieldName);	
		}
	}else{
		hide('multipleParticipants');
		show('oneParticipant');
	}
}

function addTableRow(divId,i,fieldType,fieldName){
		var row = document.createElement("tr");
		for(f=0; f < fieldName.length; f++){
			var division = document.createElement("td");
			if (fieldType[f] == 'select') {
				var field = document.createElement("select");
				field.setAttribute("id", fieldName[f] + "_" + i);
				field.setAttribute("name", fieldName[f] + "_" + i);
				if (fieldName[f] == 'type') {
					var value1 = document.createElement("option");
					value1.setAttribute("value", "regular");
					value1.innerHTML = 'Regular - $450';
					field.appendChild(value1);
					var value2 = document.createElement("option");
					value2.setAttribute("value", "dominicana");
					value2.innerHTML = 'Incluyendo República Dominicana - $600';
					field.appendChild(value2);
				}
				if (fieldName[f] == 'method') {
					var value1 = document.createElement("option");
					value1.setAttribute("value", "email");
					value1.innerHTML = 'Vía correo electrónico';
					field.appendChild(value1);
					var value2 = document.createElement("option");
					value2.setAttribute("value", "print");
					value2.innerHTML = 'Impreso';
					field.appendChild(value2);
					var value3 = document.createElement("option");
					value3.setAttribute("value", "both");
					value3.innerHTML = 'Vía correo electrónico e impreso';
					field.appendChild(value3);					
				}
				division.appendChild(field);
			}
			else {
				var field = document.createElement("input");
				field.setAttribute("id", fieldName[f] + "_" + i);
				field.setAttribute("type", fieldType[f]);
				field.setAttribute("name", fieldName[f] + "_" + i);
				if (fieldName[f] == 'phone' || fieldName[f] == 'fax' || fieldName[f] == 's_phone' || fieldName[f] == 's_fax') {
					field.setAttribute("class", 'short,validate[\'required\',\'phone\']');
				}
				division.appendChild(field);
			}		
			row.appendChild(division);		
		}
		document.getElementById(divId).getElementsByTagName("tbody")[0].appendChild(row);
}

function removeFileInput(divName,i){
	var elm = document.getElementById(i);
	document.getElementById("moreUploads").removeChild(elm);
}
