
/* ---------------------------------------------- */
/* dAGAROd.nET para Roberto Castello ------------ */
/* 16/01/2008  ---------------------------------- */
/* ---------------------------------------------- */


/* ---------------------------------------------- */
/* BUSCADOR DE ARTICULOS DESDE WEB -------------- */
/* ---------------------------------------------- */

function funkThis(stObjForm){
	if(stObjForm.value==""){//si está vacío
		alert("Please, write the name of the article you want to find.");
		stObjForm.focus();
		return false;
	}else{//tiene texto
		document.getElementById('buscador').action = "seekresp.asp?word="+stObjForm.value;
		document.getElementById('buscador').submit();
		return true;
	}
}

/* ---------------------------------------------- */
/* VALIDAR FORMULARIO CONTACTO ------------------ */
/* ---------------------------------------------- */

var oblig = new Array(0,1,6,8,9);

function pasa_alerta_foco(stField){
	alert("Please, fill the field");
	document.getElementById(stField.id).focus();
	return true;
}

function valContacto(){
	var totalForm = document.contacto.elements.length;
	for(var i = 0; i < (totalForm*1)-2;i++){
		if(i==8){// email
			if(testEmail(document.contacto.elements[i].value)!=true){
				document.contacto.elements[i].focus();
				return false;
			}
		}
		if(document.contacto.elements[i].value == ""){//el campo esta vacio
			for(var j=0;j<oblig.length;j++){
				if(i==oblig[j]){//es obligatorio??
					pasa_alerta_foco(document.contacto.elements[i]);
					return false;
				}
			}
		}
		
	}
	//document.forms[0].action = "procesar_form.php";
	document.forms[0].submit();
}

/* ---------------------------------------------- */
/* VALIDAR EMAIL ------------------ */
/* ---------------------------------------------- */

function testEmail(valor){
		var valido = true;
		invalidChars = " ;:,"
		
		if(valor.length == 0){
			alert("Write your e-mail, please.");
			document.getElementById('E-mail').focus();
			valido =  false;
		}else{
			
			for(i = 0; i < invalidChars.length; i++){
				novalido = invalidChars.charAt(i);
				if(valor.indexOf(novalido,0) > -1){
					alert("Wrong email.");
					valido =  false;
				}
			}
			
			posAt = valor.indexOf("@",1)
			
			if(posAt == -1){
			alert("Wrong email.");
				valido =  false;	
			}
			else{
				if(valor.indexOf("@",posAt+1) > -1){
					alert("Wrong email.");
					valido =  false;
				}
				else{
					posPunto = valor.indexOf(".",posAt)
			
					if(posPunto == -1){
						alert("Wrong email.");
						valido =  false;
					}
					else{
						if(posPunto+3 > valor.length){
							alert("Wrong email.");
							valido =  false;
						}		
		
					}
				}
			
			}
		}
	return valido;
}

/* ---------------------------------------------- */
/* REPINTADO DE TITLES Y HANDS BOTONES INPUT ---- */
/* ---------------------------------------------- */

function manoBoton(){
	try{
		var bot = document.getElementsByTagName('input');
		for(i=0;i<bot.length;i++){
			if(document.getElementsByTagName('input')[i].type == 'button' || document.getElementsByTagName('input')[i].type == 'submit' || document.getElementsByTagName('input')[i].type == 'reset'){
				document.getElementsByTagName('input')[i].style.cursor = "pointer";
				document.getElementsByTagName('input')[i].title = document.getElementsByTagName('input')[i].value;
			}
		}
	}catch(e){
		alert(e.description);
	}
}

/* ---------------------------------------------- */
