// JavaScript Document
function clearField(fieldId){
	var field = document.getElementById(fieldId);
	field.value = "";
}

function CadenaVacia(cadena) {
    if (cadena.length==0)
     return true;
}
function enviarSubmit(frm,ruta) {
		window.document.forms[frm].action=ruta;
		window.document.forms[frm].submit();
	}

function changeAction(action)
{
	var x=document.forms.frmList;
	x.action=action;
//	alert(x.action);
}

function email_valido(email)	{
	var i;
	var cStrCont,cStrDot;
	i = 0;
	cStrCont = 0;
	cStrDot = 0;

	for ( i=0; i < email.length ; i++ )		{
		if ( email.charAt(i) == "@" )			{
			cStrCont = cStrCont + 1
		}
		if ( email.charAt(i) == "." )			{
			cStrDot = cStrDot + 1
		}
	}

	if (cStrCont != 1 || cStrDot == 0)		{
		return false;
	}
	if ( email.charAt(email.length - 1 ) == "." )		{
		return false;
	}
	return true;
}

function valorAlText(combo,texto, idp) { 
	if(texto!="")	{
		var text = document.getElementById(texto);
		text.value = combo.options[combo.selectedIndex].text;
	}
	if(idp!="") {
		var idp = document.getElementById(idp);
		idp.value = combo.options[combo.selectedIndex].value;
	}
}

//FUNCION PARA VALIDAR FORMULARIOS
function frmValid(form){  
	if(form == "comment") // Validar campos del formulario FICHA DEL PRODUCTO
	{
		if (window.document.frmName.name.value == 0){
			alert('Ingresa tu nombre');
			document.frmName.name.focus();
			return false;
		}
		//VALIDAR E-MAIL
		if (!email_valido(window.document.frmName.email.value)){
			alert('Ingresa tu email, (Ej. sucuenta@dominio.com)');
			document.frmName.email.focus();
			return false;
		}
		
		if (window.document.frmName.comment.value == 0){
			alert('Ingresa tu comentario');
			document.frmName.comment.focus();
			return false;
		}
	}
	if(form == "contact") // Validar campos del formulario FICHA DEL PRODUCTO
	{
		if (window.document.frmContacto.nombre.value == 0){
			alert('Ingresa tu nombre');
			document.frmContacto.nombre.focus();
			return false;
		}
		//VALIDAR E-MAIL
		if (!email_valido(window.document.frmContacto.email.value)){
			alert('Ingresa tu email, (Ej. sucuenta@dominio.com)');
			document.frmContacto.email.focus();
			return false;
		}
		
		if (window.document.frmContacto.mensaje.value == 0){
			alert('Ingresa tu mensaje');
			document.frmContacto.mensaje.focus();
			return false;
		}
	}
}

