/* JavaScript Document 
Autor: www.SofyHost.com - Ing. Octavio Reyes
El contenido en el site es responsabilidad del cliente excluyendo a SofyHost de responsabilidades
*/

function envia_datos()
{
	var nombre = document.getElementById('nombre').value;
	var telefono = document.getElementById('telefono').value;
	var correo  = document.getElementById('correo');
	var mensaje  = document.getElementById('mensaje').value;
	var complete = true;
	
	var RegExPattern = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/; 
			
	if(complete)
	{
		if (correo.value.match(RegExPattern)) {        
			complete = true;   
		} else {         
		//El email no es correcto.         
			alert("Favor de ingresar un correo v\341lido.")
			correo.focus();
			complete = false;
			return false;    
		}  
	}
	
	complete = empty('nombre', 'Nombre');
	
	//if(complete)
		//complete = empty('telefono', 'Tel\351fono');
		
	if(complete)
		complete = empty('mensaje', 'Mensaje');
		
	if(complete)
		complete = empty('correo', 'Correo electr\363nico');
		
	if(complete)
	{
		var post = "nombre="+nombre+"&telefono="+telefono+"&correo="+correo.value+"&mensaje="+mensaje;
		carga_ajax_div_din("lib/envio_datos.php", post, "enviar_comentarios");
	}
}


function cambia_estatus_boton(elemento, estatus)
{
	if(!estatus)
	{
		var source = elemento.src;
	
		var estatus = source.search(/_on/i);
			
		if(estatus==-1)
			elemento.src = source.replace("_off", "_on")
		else
			elemento.src = source.replace("_on", "_off")
	}
}

function limpiar(elemento)
{
	document.getElementById(elemento).reset();
}



function cambia_estatus_pestana(elemento, estatus)
{
	if(!estatus)
	{
		var source = elemento.src;
	
		var estatus = source.search(/_on/i);
			
		if(estatus==-1)
		{
			elemento.src = source.replace("_off", "_on")
			elemento.style.height = "77px";
			elemento.style.width = "36px";
		}
		else
		{
			elemento.src = source.replace("_on", "_off");
			elemento.style.height = "67px";
			elemento.style.width = "27px";
		}
	}
}


function cambia_estatus_pestana_carta(elemento, estatus)
{
	if(!estatus)
	{
		var source = elemento.src;
	
		var estatus = source.search(/_on/i);
			
		if(estatus==-1)
		{
			elemento.src = source.replace("_off", "_on")
			elemento.style.height = "88px";
			elemento.style.width = "36px";
		}
		else
		{
			elemento.src = source.replace("_on", "_off");
			elemento.style.height = "75px";
			elemento.style.width = "27px";
		}
	}
}

function cambia_estatus_pestana_temporada(elemento, estatus)
{
	if(!estatus)
	{
		var source = elemento.src;
	
		var estatus = source.search(/_on/i);
			
		if(estatus==-1)
		{
			elemento.src = source.replace("_off", "_on")
			elemento.style.height = "100px";
			elemento.style.width = "36px";
		}
		else
		{
			elemento.src = source.replace("_on", "_off");
			elemento.style.height = "83px";
			elemento.style.width = "27px";
		}
	}
}


function cambia_estatus_pestana_carta(elemento, estatus)
{
	if(!estatus)
	{
		var source = elemento.src;
	
		var estatus = source.search(/_on/i);
			
		if(estatus==-1)
		{
			elemento.src = source.replace("_off", "_on")
			elemento.style.height = "88px";
			elemento.style.width = "36px";
		}
		else
		{
			elemento.src = source.replace("_on", "_off");
			elemento.style.height = "75px";
			elemento.style.width = "27px";
		}
	}
}



function cambia_estatus_pestana_juan_ramon(elemento, estatus)
{
	if(!estatus)
	{
		var source = elemento.src;
	
		var estatus = source.search(/_on/i);
			
		if(estatus==-1)
		{
			elemento.src = source.replace("_off", "_on")
			elemento.style.width = "36px";
		}
		else
		{
			elemento.src = source.replace("_on", "_off");
			elemento.style.width = "27px";
		}
	}
}

function selecciona_noticia_prensa(item_li)
{
	
	var estatus = item_li.className.search(/noticia_prensa_selected/i);
			
	if(estatus==-1)
	{
		//deselecciona noticia
		var clase = document.getElementById(noticia_seleccionada).className;
		var nueva_clase = clase.replace("noticia_prensa_selected", "noticia_prensa");
		document.getElementById(noticia_seleccionada).className = nueva_clase;
		
		//selecciona noticia
		clase = item_li.className;
		nueva_clase = clase.replace("noticia_prensa", "noticia_prensa_selected");
		item_li.className = nueva_clase;
		noticia_seleccionada = item_li.id
		file = noticias_pdf[item_li.id];
		
		//cambia atributos imagen
		document.getElementById('imagen_noticia').src = noticias_imagenes[item_li.id];
	}
}



function selecciona_video(item_li)
{
	
	var estatus = item_li.className.search(/noticia_prensa_selected/i);
			
	if(estatus==-1)
	{
		//deselecciona noticia
		var clase = document.getElementById(noticia_seleccionada).className;
		var nueva_clase = clase.replace("noticia_prensa_selected", "noticia_prensa");
		document.getElementById(noticia_seleccionada).className = nueva_clase;
		
		//selecciona noticia
		clase = item_li.className;
		nueva_clase = clase.replace("noticia_prensa", "noticia_prensa_selected");
		item_li.className = nueva_clase;
		noticia_seleccionada = item_li.id
		file = noticias_pdf[item_li.id];
		
		//cambia atributos imagen
		document.getElementById('imagen_noticia').src = noticias_pdf[item_li.id];
	}
}


function selecciona_promocion(item_li)
{
	
	var estatus = item_li.className.search(/noticia_prensa_selected/i);
			
	if(estatus==-1)
	{
		//deselecciona noticia
		var clase = document.getElementById(noticia_seleccionada).className;
		var nueva_clase = clase.replace("noticia_prensa_selected", "noticia_prensa");
		document.getElementById(noticia_seleccionada).className = nueva_clase;
		
		//selecciona noticia
		clase = item_li.className;
		nueva_clase = clase.replace("noticia_prensa", "noticia_prensa_selected");
		item_li.className = nueva_clase;
		noticia_seleccionada = item_li.id
		file = noticias_pdf[item_li.id];
		
		//cambia atributos imagen
		document.getElementById('imagen_noticia').src = noticias_imagenes[item_li.id];
		
		alert(document.getElementById('a_href').href)
		document.getElementById('a_href').href = noticias_pdf[item_li.id];
	}
}


function selecciona_receta(item_li)
{
	
	var estatus = item_li.className.search(/noticia_prensa_selected/i);
			
	if(estatus==-1)
	{
		//deselecciona noticia
		var clase = document.getElementById(noticia_seleccionada).className;
		var nueva_clase = clase.replace("noticia_prensa_selected", "noticia_prensa");
		document.getElementById(noticia_seleccionada).className = nueva_clase;
		
		//selecciona noticia
		clase = item_li.className;
		nueva_clase = clase.replace("noticia_prensa", "noticia_prensa_selected");
		item_li.className = nueva_clase;
		noticia_seleccionada = item_li.id
		file = noticias_pdf[item_li.id];
		
		//cambia atributos imagen
		document.getElementById('imagen_noticia').src = noticias_imagenes[item_li.id];
	}
}



function descarga_pdf()
{
	var nombre = 'archivo_seleccionado'+noticia_seleccionada;
	window.open(file,'archivo_seleccionado');
}

function descarga_croquis()
{
	var nombre = 'Croquis';
	var file = "archivos/croquisbajada.pdf";
	window.open(file,'Croquis');
}

function abre_receta()
{
	var nombre = 'archivo_seleccionado'+noticia_seleccionada;
	window.open(file,'archivo_seleccionado');
}


function carga_ajax_div_din(page, post, variableAjax)
{
	//alert("no error")
	variableAjax=objetoAjax();
	
	variableAjax.open("POST", page,true);
	variableAjax.onreadystatechange=function() {
		if (variableAjax.readyState==4) {
			if (variableAjax.status==200){
				alert(variableAjax.responseText);
			}
		}
		
		
	} 
  
	variableAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//enviando los valores
	variableAjax.send(post);

}
/* ---------------------------- */
/* XMLHTTPRequest Enable 		*/
/* ---------------------------- */
function crearXMLHttpRequest() 
{
  var xmlHttp=null;
  if (window.ActiveXObject) 
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else 
    if (window.XMLHttpRequest) 
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}

function objetoAjax(){
  var xmlhttp=false;
  try 
  	{
 		 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  	} catch (e) {
					try {
							xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
						} catch (E) {
 										 xmlhttp = false;
  									}
				}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest();
		}
  return xmlhttp;
}

//empty
function ltrim(s) {
	return s.replace(/^\s+/, "");
}

function rtrim(s) {
	return s.replace(/\s+$/, "");
}

function trim(s) {
	return rtrim(ltrim(s));
}

function empty(campo, nombre)
{
	var var_campo = document.getElementById(campo);
	//var campo_nombre = document.getElementById('nombre');
	if((trim(var_campo.value)=="")||(trim(var_campo.value)=="0"))
		{
			alert("El campo "+nombre+ " no puede estar vac\355o.");
			var_campo.focus();
			return false;
		}
	else
		return true;
}
