var lang = null;
var MSG = {};
MSG = {
	"es":{
		"MSG_INPUT_EVENT_NAME":"Debe ingresar el nombre del evento",
		"MSG_SELECT_CATEGORY":"Debe seleccionar la categoría",
		"MSG_SELECT_CONNECTION":"Debe seleccionar la conexión",
		"MSG_SELECT_START_DATE":"Debe seleccionar la fecha de inicio",
		"MSG_SELECT_END_DATE":"Debe seleccionar la fecha de finalización",
		"MSG_SELECT_COUNTRY":"Debe seleccionar el país",
		"MSG_SELECT_REGION":"Debe seleccionar la región",
		"MSG_INPUT_CITY_TOWN":"Debe ingresar la ciudad / localidad", //You should input the city / town
		"MSG_END_DATE_CAN_NOT_BE_LESS_THAN_START_DATE":"La fecha de fin del Evento no puede ser menor a la fecha de inicio", //// The end date of the event can not be less than the starting date
		"MSG_START_DATE_CAN_NOT_BE_LESS_THAN_CURRENT_DATE":"La fecha de inicio no puede ser menor a la fecha actual", // The starting date can not be smaller than the current date
		"MSG_LOCATION_CAN_NOT_HAVE_MORE_THAN_250_CHARACTERS":"La dirección no puede tener mas de 250 caracteres", // The location can not be over than 250 characters
		"MSG_DESCRIPTION_CAN_NOT_HAVE_MORE_THAN_500_CHARACTERS":"La descripción no puede tener mas de 500 caracteres", // Description can not be over than 500 characters
		"MSG_LOCALITY_INFORMATION_CAN_NOT_HAVE_MORE_THAN_250_CHARACTERS":"La información sobre la localidad no puede tener mas de 250 caracteres", // Locality/Town can not be over than 250 characters
		"MSG_INPUT_HOST_NAME":"Debe ingresar el nombre del organizador", // You should specify the host name
		"MSG_HOST_CAN_NOT_HAVE_MORE_THAN_300_CHARACTERS":"El campo organizador no puede tener mas de 300 caracteres", // Host can not be over than 300 characters
		"MSG_SELECT_LIMIT_DATE":"Debe seleccionar la fecha límite", // You should select the deadline
		"MSG_SELECT_LANGUAGE":"Debe seleccionar el idioma", // You must select the language
		"MSG_LIMIT_DATE_CAN_NOT_BE_LESS_THAN_CURRENT_DATE":"La fecha límite no puede ser menor a la fecha actual", // The deadline can not be smaller than the current date
		"MSG_LIMIT_DATE_CAN_NOT_BE_GREATER_THAN_END_DATE":"La fecha límite no puede ser mayor a la fecha final del evento", // The deadline can not be greater than the closing date of the event
		"MSG_SPECIFY_YOUR_PARTICIPATION":"Debe indicar su participación", // You should specify your participation
		"MSG_SPECIFY_WHO_CAN_SEE_THE_LIST":"Debe indicar que personas pueden ver la lista",
		"MSG_SPECIFY_IF_RSVP_IS_REQUIRED":"Debe especificar si RSVP es requerido",
		"MSG_LIMIT_DATE_CAN_NOT_BE_GREATER_THAN_START_DATE":"La fecha límite no puede ser mayor a la fecha de inicio del evento",
		"MSG_IMPUT_EMAIL":"Debe ingresar un email válido"
		// "MSG_SELECT_EVENT_CONNECTION":"Debe indicar si el evento hará parte de una conexión"
	},
	"en":{
		"MSG_INPUT_EVENT_NAME":"You should specify the event name",
		"MSG_SELECT_CATEGORY":"You should select the category",
		"MSG_SELECT_CONNECTION":"You should select the connection",
		"MSG_SELECT_START_DATE":"You should select the start date",
		"MSG_SELECT_END_DATE":"You should select the end date",
		"MSG_SELECT_COUNTRY":"You should select the country",
		"MSG_SELECT_REGION":"You should select the State / Region ",
		"MSG_INPUT_CITY_TOWN":"You should specify the City / Town",
		"MSG_END_DATE_CAN_NOT_BE_LESS_THAN_START_DATE":"The end date can not be less than start date",
		"MSG_START_DATE_CAN_NOT_BE_LESS_THAN_CURRENT_DATE":"The start date can not be less than current date",
		"MSG_LOCATION_CAN_NOT_HAVE_MORE_THAN_250_CHARACTERS":"Location field can not have more than 250 characters",
		"MSG_DESCRIPTION_CAN_NOT_HAVE_MORE_THAN_500_CHARACTERS":"Description field can not have more than 500 characters",
		"MSG_LOCALITY_INFORMATION_CAN_NOT_HAVE_MORE_THAN_250_CHARACTERS":"Locality/Town field can not have more than 250 characters",
		"MSG_INPUT_HOST_NAME":"You should specify the host name",
		"MSG_HOST_CAN_NOT_HAVE_MORE_THAN_300_CHARACTERS":"Host field can not have more than 300 characters",
		"MSG_SELECT_LIMIT_DATE":"You should select the limit date",
		"MSG_SELECT_LANGUAGE":"You should select the language",
		"MSG_LIMIT_DATE_CAN_NOT_BE_LESS_THAN_CURRENT_DATE":"The limit date can not be smaller than the current date",
		"MSG_LIMIT_DATE_CAN_NOT_BE_GREATER_THAN_END_DATE":"The limit date can not be greater than end date of the event",
		"MSG_SPECIFY_YOUR_PARTICIPATION":"You should specify your participation",
		"MSG_SPECIFY_WHO_CAN_SEE_THE_LIST":"You should specify who can see the list",
		"MSG_SPECIFY_IF_RSVP_IS_REQUIRED":"You should specify if RSVP is required",
		"MSG_LIMIT_DATE_CAN_NOT_BE_GREATER_THAN_START_DATE":"The limit date can not be greater than start date of the event",
		"MSG_IMPUT_EMAIL":"You should specify a valid email"
		// "MSG_SELECT_EVENT_CONNECTION":"You should specify if the event will be part of a connection"
	}
}


function goStepTwo() {
	var s = "";
	var asociar = document.getElementById('asociar_conexion').value;
	
	if( trim(document.form.nombre.value) == 0 ) { s = s + MSG[lang]['MSG_INPUT_EVENT_NAME'] + "\n"; }
	if( document.form.cat.selectedIndex == 0 ) { s = s + MSG[lang]['MSG_SELECT_CATEGORY'] + "\n"; }
	
	if( asociar == 1 ) { 
		if( document.form.conexion.selectedIndex == 0 ) { s = s + MSG[lang]['MSG_SELECT_CONNECTION'] + "\n"; }
	}
	
	if( trim(document.form.ini_f.value) == 0 ) { s = s + MSG[lang]['MSG_SELECT_START_DATE'] + "\n"; }
	if( trim(document.form.fin_f.value) == 0 ) { s = s + MSG[lang]['MSG_SELECT_END_DATE'] + "\n"; }
	if( document.form.pais.selectedIndex == 0 ) { s = s + MSG[lang]['MSG_SELECT_COUNTRY'] + "\n"; }
	if (document.form.region.length > 1 ) {
		if( document.form.region.selectedIndex == 0 ) { s = s + MSG[lang]['MSG_SELECT_REGION'] + "\n"; }
	}
	if( trim(document.form.ciudad.value) == 0 ) { s = s + MSG[lang]['MSG_INPUT_CITY_TOWN'] + "\n"; }
	if( document.form.fin_f.value < document.form.ini_f.value  ) { s = s + MSG[lang]['MSG_END_DATE_CAN_NOT_BE_LESS_THAN_START_DATE'] + "\n"; }
	if( document.form.ini_f.value < document.form.f_base.value  ) { s = s + MSG[lang]['MSG_START_DATE_CAN_NOT_BE_LESS_THAN_CURRENT_DATE'] + "\n"; }
	if( trim(document.form.dir.value).length > 250 ) { s = s + MSG[lang]['MSG_LOCATION_CAN_NOT_HAVE_MORE_THAN_250_CHARACTERS'] + "\n"; }
	if( trim(document.form.des.value).length > 500 ) { s = s + MSG[lang]['MSG_DESCRIPTION_CAN_NOT_HAVE_MORE_THAN_500_CHARACTERS'] + "\n"; }
	if( trim(document.form.info.value).length > 250 ) { s = s + MSG[lang]['MSG_LOCALITY_INFORMATION_CAN_NOT_HAVE_MORE_THAN_250_CHARACTERS'] + "\n"; }
	
	if( s != "" ) {
		alert(s);
		return false;
	}
	
	document.getElementById("nombre_evento").innerHTML = trim(document.form.nombre.value);
	if ( document.getElementById("nombre_evento_2") ) {
		document.getElementById("nombre_evento_2").innerHTML = trim(document.form.nombre.value);
	}
	document.getElementById("miperfilbloquegen").style.display="none";
	document.getElementById("miperfilbloquegen-3").style.display="none";
	document.getElementById("miperfilbloquegen-2").style.display="";
	return true;
}
function goStepThree() {
	var s = "";
	if( trim(document.form.organizador.value).length == 0 ) { s = s + MSG[lang]['MSG_INPUT_HOST_NAME'] + "\n"; }
	if( trim(document.form.organizador.value).length > 300 ) { s = s + MSG[lang]['MSG_HOST_CAN_NOT_HAVE_MORE_THAN_300_CHARACTERS'] + "\n"; }
	
	
	if ( parseInt(document.form.ss.value) == 1 ) {
		if ( parseInt(document.form.tipo.value) == 1 || parseInt(document.form.tipo.value) == 2 ) {
			if ( !isEmail( trim(document.form.email_organizador.value) ) ) {
				s = s + MSG[lang]['MSG_IMPUT_EMAIL'] + "\n"; 
			}
		}
	}
	
	
	if( trim(document.form.limit_f.value) == 0 ) { s = s + MSG[lang]['MSG_SELECT_LIMIT_DATE'] + "\n"; }
	if( document.form.lenguaje.selectedIndex == 0 ) { s = s + MSG[lang]['MSG_SELECT_LANGUAGE'] + "\n"; }
	if( document.form.limit_f.value < document.form.f_base.value ) { s = s + MSG[lang]['MSG_LIMIT_DATE_CAN_NOT_BE_LESS_THAN_CURRENT_DATE'] + "\n"; }
	if( document.form.limit_f.value > document.form.fin_f.value ) { s = s + MSG[lang]['MSG_LIMIT_DATE_CAN_NOT_BE_GREATER_THAN_END_DATE'] + "\n"; }
	if( document.form.limit_f.value > document.form.ini_f.value ) { s = s + MSG[lang]['MSG_LIMIT_DATE_CAN_NOT_BE_GREATER_THAN_START_DATE'] + "\n"; }
	
	if ( parseInt(document.form.tipo.value) != 3  ) {
		if ( parseInt(document.form.ss.value) == 0 ) {
			j=0;
			for( i=0; i<document.form.asistir.length; i++ ){
				if( document.form.asistir[i].checked == false ) {
					j++;
				}
			}
			if( j ==  document.form.asistir.length ) { s = s + MSG[lang]['MSG_SPECIFY_YOUR_PARTICIPATION'] + "\n"; }
		}
	}	
	
	j=0;
	for( i=0; i<document.form.ver_lista.length; i++ ){
		if( document.form.ver_lista[i].checked == false ) {
			j++;
		}
	}
	if( j ==  document.form.ver_lista.length ) { s = s + MSG[lang]['MSG_SPECIFY_WHO_CAN_SEE_THE_LIST'] + "\n"; }
	j=0;
	for( i=0; i<document.form.rsvp.length; i++ ){
		if( document.form.rsvp[i].checked == false ) {
			j++;
		}
	}
	if( j ==  document.form.rsvp.length ) { s = s + MSG[lang]['MSG_SPECIFY_IF_RSVP_IS_REQUIRED'] + "\n"; }
	if( s != "" ) {
		alert(s);
		return false;
	}
	document.getElementById("miperfilbloquegen").style.display="none";
	switch( parseInt(document.form.ss.value) ) {
		case 0:
			document.getElementById("miperfilbloquegen-2").style.display="none";
			document.getElementById("miperfilbloquegen-3").style.display="";
		break;
	}
	return true;
}
function backStepOne() {
	document.getElementById("miperfilbloquegen").style.display="";
	document.getElementById("miperfilbloquegen-2").style.display="none";
	document.getElementById("miperfilbloquegen-3").style.display="none";
}
function backStepTwo() {
	document.getElementById("miperfilbloquegen").style.display="none";
	document.getElementById("miperfilbloquegen-2").style.display="";
	document.getElementById("miperfilbloquegen-3").style.display="none";
}
/*
function __goSave() {
	document.form.invitados.name = "invitados[]";
	var space = "";
	var j = 0;
	for( i=0; i<document.form.invitados.length; i++ ) {
		if ( document.form.invitados.options[i].value > 0 ) {
			space = j == 0 ? "" : ",";
			document.getElementById("reference").value =  String( document.getElementById("reference").value + space + document.form.invitados.options[i].value );
			j++;
		}
		document.form.invitados.options[i].value = document.form.invitados.options[i].text;
	}
	for( i=0; i<document.form.invitados.length; i++ ) {
		document.form.invitados.options[i].selected = "selected";
	}
	document.form.MM_insert.value=1;
	document.form.submit();
}
*/
function goSave() {
	var space = "";
	var j = 0;
	for( i=0; i<document.form.invitados.length; i++ ) {
		document.form.invitados.options[i].selected = "selected";
	}
	document.form.invitados.name = "invitados[]";
	
	
	document.form.MM_insert.value=1;
	document.form.submit();
}

function openList() {
	window.open('contactos_list.php','window','width=540,height=480,toolbar=0,location=0,directories=0,menubar=0,scrollbars=1,resizable=1');
}

// Busquedas en los formularios
function searchEvento() {
	if( document.formSearch.hasta.value < document.formSearch.desde.value ) {
		alert(MSG[lang]['MSG_END_DATE_CAN_NOT_BE_LESS_THAN_START_DATE']);
		return false;
	}
	document.formSearch.MM_search.value=1;
	document.formSearch.submit();
}
function cleanForm() {
	document.formSearch.pais.selectedIndex = 0;
	document.formSearch.categoria.selectedIndex = 0;
	document.formSearch.lenguaje.selectedIndex = 0;
	document.formSearch.tema.value = "";
	document.formSearch.desde.value = "";
	document.formSearch.hasta.value = "";
	document.formSearch.zip.value = "";
	document.formSearch.ciudad.value = "";
	document.formSearch.miciudad.checked = false;
}


function goEdit() {
	var s = "";
	if( trim(document.form.organizador.value).length == 0 ) { s = s + MSG[lang]['MSG_INPUT_HOST_NAME'] + "\n"; }
	if( trim(document.form.organizador.value).length > 300 ) { s = s + MSG[lang]['MSG_HOST_CAN_NOT_HAVE_MORE_THAN_300_CHARACTERS'] + "\n"; }
	
	if ( parseInt(document.form.ss.value) == 1 ) {
		if ( parseInt(document.form.tipo.value) == 1 || parseInt(document.form.tipo.value) == 2 ) {
			if ( !isEmail( trim(document.form.email_organizador.value) ) ) {
				s = s + MSG[lang]['MSG_IMPUT_EMAIL'] + "\n"; 
			}
		}
	}
	
	if( trim(document.form.limit_f.value) == 0 ) { s = s + MSG[lang]['MSG_SELECT_LIMIT_DATE'] + "\n"; }
	if( document.form.lenguaje.selectedIndex == 0 ) { s = s + MSG[lang]['MSG_SELECT_LANGUAGE'] + "\n"; }
	if( document.form.limit_f.value < document.form.f_base.value  ) { s = s + MSG[lang]['MSG_LIMIT_DATE_CAN_NOT_BE_LESS_THAN_CURRENT_DATE'] + "\n"; }
	if( document.form.limit_f.value > document.form.fin_f.value  ) { s = s + MSG[lang]['MSG_LIMIT_DATE_CAN_NOT_BE_GREATER_THAN_END_DATE'] + "\n"; }
	
	if ( parseInt(document.form.tipo.value) != 3  ) {
		if ( parseInt(document.form.ss.value) == 0 ) {
			j=0;
			for( i=0; i<document.form.asistir.length; i++ ){
				if( document.form.asistir[i].checked == false ) {
					j++;
				}
			}
			if( j ==  document.form.asistir.length ) { s = s + MSG[lang]['MSG_SPECIFY_YOUR_PARTICIPATION'] + "\n"; }
		}
	}	
	
	j=0;
	for( i=0; i<document.form.ver_lista.length; i++ ){
		if( document.form.ver_lista[i].checked == false ) {
			j++;
		}
	}
	if( j ==  document.form.ver_lista.length ) { s = s + MSG[lang]['MSG_SPECIFY_WHO_CAN_SEE_THE_LIST'] + "\n"; }
	j=0;
	for( i=0; i<document.form.rsvp.length; i++ ){
		if( document.form.rsvp[i].checked == false ) {
			j++;
		}
	}
	if( j ==  document.form.rsvp.length ) { s = s + MSG[lang]['MSG_SPECIFY_IF_RSVP_IS_REQUIRED'] + "\n"; }
	if( s != "" ) {
		alert(s);
		return false;
	}
	document.form.MM_update.value=1;
	document.form.submit();
}

function showHideConnection(v) {
	switch(parseInt(v)) {
		case 1:
			document.getElementById("rowConexion").style.display="";
		break;
		default:
			document.getElementById("rowConexion").style.display="none";
			document.form.conexion.selectedIndex = 0;
		break;
	}
}