// JavaScript Document

function mostrar(nombres){
	array_nombres = nombres.split(',');
	for(i=0; i<array_nombres.length; i++){
		document.getElementById(array_nombres[i]).style.display = 'block';
	}		
}

function ocultar(nombres){
	array_nombres = nombres.split(',')
	for(i=0; i<array_nombres.length; i++){
		document.getElementById(array_nombres[i]).style.display = 'none';
	}
}




function trim(txt) 
{
	while (txt.substring(0,1) == ' ')
	{
		txt = txt.substring(1, txt.length);
	}
	
	while (txt.substring(txt.length-1, txt.length) == ' ')
	{
		txt = txt.substring(0, txt.length-1);
	}
	
	return txt;
}



function enviar(id)
{
	var msg = "";
	
	if (id ==1)
	{
		document.getElementById("txt-Usuario").value = trim (document.getElementById("txt-Usuario").value);
		document.getElementById("txt-Pass").value = trim (document.getElementById("txt-Pass").value);
		
		if (document.getElementById("txt-Usuario").value == "")
		{
			msg += "Debes introducir tu nombre de usuario\n";
		}
		if (document.getElementById("txt-Pass").value == "")
		{
			msg += "Debes introducir tu contraseña";		
		}
		
		if (msg)
		{
			alert(msg);
			return;
		}
	}
	
	document.formu.method = "post";
	if(id == 1)
	{
		document.formu.action = "/includes/login-proceso.cfm";
	}
	else if(id == 2)
	{
		document.formu.action = "/includes/login-cerrar-sesion.cfm";
	}
	document.formu.submit();
}


// Abrir GREYBOX
function AbreRegistro(){
	//return GB_showCenter('Registro Conocecocacola', '/registro/formulario-registro.cfm', 465, 535);
	return GB_showCenter('Registro Coca-Cola', 'http://www.conocecocacola.com/registrogen/aviso_legal.cfm?idprocedencia=1', 520, 500);	
}

function AbreRecordarPass(){
	return GB_showCenter('Recordar Contraseña', 'http://www.conocecocacola.com/registrogen/recordar.cfm?idprocedencia=1', 280, 500);
}

function AbrePolitica(){
	return GB_showCenter('Condiciones generales de acceso y uso', 'http://www.conocecocacola.com/registrogen/politica.cfm?idprocedencia=1', 470, 500)
}

function AbreCondiciones(){
	return GB_showCenter('Condiciones de Uso', '/registro/condiciones.html', 455, 460)
}

function AbreAutoria(){
	return GB_showCenter('Copyright', '/registro/autoria.html', 175, 460)
}

function AbreInstruccionesWiki(){
	return GB_showCenter('Instrucciones Wikicook', '/content/cocina_nosotros/wiki_instrucciones.cfm', 635, 550)
}



// funciones MM
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function enviar_receta(accion)
{
	var msg;
	msg="";

	if(document.formu.txtTitulo.value == "")
	{
		msg=msg+"Falta de rellenar el campo \"Título de la receta\"\n";
	}
		
	if(document.formu.rdCategoria[0].checked==false && document.formu.rdCategoria[1].checked==false && document.formu.rdCategoria[2].checked==false)
	{
		msg=msg+"Falta seleccionar el campo \"Categoría\"\n";
	}
		
	if(document.formu.txtIngredientes.value == "")
	{
		msg=msg+"Falta de rellenar el campo \"Ingredientes\"\n";
	}
		
	if(document.formu.fotoA.value=="")
	{
		if(document.formu.foto1.value=="")
		{
			msg=msg+"Falta de rellenar el campo \"Foto de ingredientes\"\n";
		}
	}
		
	if(document.formu.txtElaboracion.value == "")
	{
		msg=msg+"Falta de rellenar el campo \"Elaboración\"\n";
	}
		
	if(document.formu.fotoB.value=="")
	{
		if(document.formu.foto2.value=="")
		{
			msg=msg+"Falta de rellenar el campo \"Foto de elaboración\"\n";
		}
	}
		
	if(document.formu.txtUtensilios.value == "")

	{
		msg=msg+"Falta de rellenar el campo \"Utensilios\"\n";
	}
		
	if(document.formu.fotoC.value=="")
	{
		if(document.formu.foto3.value=="")
		{
			msg=msg+"Falta de rellenar el campo \"Foto acabado\"\n";
		}
	}
		
	if(document.formu.txtTiempo.value == "")
	{
		msg=msg+"Falta de rellenar el campo \"Tiempo de elaboración\"\n";
	}

	if(msg)
	{
		alert(msg);
	}
	else
	{
		switch (accion)
		{
			case 0: //vista previa
				document.formu.action = "subir_foto_vista_previa_profesional.cfm";
				document.formu.submit();
				break;
			case 1: //participar
				document.formu.action = "recetas_Procesa.cfm";
				document.formu.submit();
				break;
		}
	}
}


function getRadioButtonSelectedValue(ctrl)
{
	for(i=0; i<ctrl.length; i++)
	{
		if(ctrl[i].checked) 
		{
			return ctrl[i].value;
		}
	}
}	


function enviar_procesa(op)
{
	document.formu.hdnOpcion.value=op;
	document.formu.submit();
}


function enviar_amateur(accion)
{
	var msg = "";
	
	document.getElementById('txt-explicacion').value = trim(document.getElementById('txt-explicacion').value); 
	
	if(document.formu.titulo.value == "")
	{
		msg += "Debes introducir el título de la receta\n\n";
	}
	
	if (document.getElementById("txt-explicacion").value == "")
	{
		msg += "Debes introducir una explicación\n\n";
	}
	
	if (document.getElementById("fl-foto").value == "" && document.formu.flFoto_actual.value == "")
	{
		msg += "Debes introducir una foto";
	}
	
	if (msg)
	{
		alert (msg);
	}
	else
	{
		switch (accion)
		{
			case 0: //vista previa
				//GB_showCenter('Vista Previa', '/content/concurso_talentos/vista_previa_popular.cfm', 410, 540);
				document.formu.action = "subir_foto_vista_previa.cfm";
				document.formu.submit();
				break;
			case 1: //participar
				document.formu.action = "participar.cfm";
				document.formu.submit();
				break;
		}
	}
}


// Abrir Formulario Concurso

function Abrir_VP_Popular(){
	return GB_showCenter('Vista Previa', '/content/concurso_talentos/vista_previa_popular.cfm', 410, 540)
}

function Abrir_VP_Profesional(){
	return GB_showCenter('Vista Previa', '/content/concurso_talentos/vista_previa_profesional.cfm', 660, 540)
}


function cambiar()
{
	document.formu.method = "post";
	document.formu.action = "formulario.cfm";
	document.formu.submit();
}
	
function participar()
{
	document.formu.method = "post";
	document.formu.action = "participar.cfm";
	document.formu.submit();
}

function cambiar_profesional()
{
	document.formu.method = "post";
	document.formu.action = 'recetas_formulario.cfm?categoria='+document.formu.hdnCategoria.value;
	document.formu.submit();
}



function textCounter(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit)
	{
		alert("El tamaño de la receta no puede ser mayor de 2500 caracteres.");
		field.value = field.value.substring(0, maxlimit);
	}
	else 
	{
		countfield.value = maxlimit - field.value.length;
	}
}

function votar(idreceta)
{
	document.formulario.idreceta.value = idreceta;
		
	document.formulario.method = "post";
	document.formulario.action = "votaciones_insertar.cfm";
	document.formulario.submit();
}

function enviar_comentario()
{
	if(document.formulario.titulo.value == "")
	{
		alert("Debes escribir el título del comentario.");
	}
	else if(document.formulario.txtExplicacion.value == "")
	{
		alert("Debes escribir el texto del comentario.");
	}
	else
	{
		alert("Gracias por su opinión. Su comentario ha de ser validado antes de publicarse.")
		document.formulario.method = "post";
		document.formulario.action = "cocina_nosotros_comentarios_insertar.cfm";
		document.formulario.submit();
	}
	
}

function textCounter2(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit)
	{
		alert("El tamaño del comentario no puede ser mayor de 300 caracteres.");
		field.value = field.value.substring(0, maxlimit);
	}
	else 
	{
		countfield.value = maxlimit - field.value.length;
	}
}


function enviar_receta_plato_a_plato()
{
	
	document.formulario.ingredientes.value = FCKeditorAPI.GetInstance( 'ingredientes' ).GetXHTML();
	document.formulario.elaboracion.value = FCKeditorAPI.GetInstance( 'elaboracion' ).GetXHTML();
	
	if(document.formulario.titulo.value == "")
	{
		alert("Debes rellenar el nombre de la receta.");
	}
	else if(document.formulario.provincia.value == 0)
	{
		alert("Debes seleccionar una comunidad autónoma.");
	}
	else if(document.formulario.ingredientes.value == "")
	{
		alert("Debes rellenar los ingredientes de la receta.");
	}
	else if(document.formulario.elaboracion.value == "")
	{
		alert("Debes rellenar la elaboración de la receta.");
	}
	else if(document.formulario.foto.value == "")
	{
		alert("Debes seleccionar una fotografía.");
	}
	else
	{
		document.formulario.method = "post";
		document.formulario.action = "cocina_nosotros_platos_formu_accion.cfm";
		document.formulario.submit();
	}
}

