function changeclass(whichid, whichclass) {
	objid = document.getElementById(whichid);
	objid.className = whichclass;
}

function changeimg(whichid, whichimg, imgtype) {
	objidimg = document.getElementById(whichid);
	finalimgfile = "imgs/" + whichid + "-" + whichimg + "." + imgtype;
	if (objidimg.className) {
		imgclass = objidimg.className;
	} else {
		imgclass = "";
	}
	if (imgclass && imgclass == "active") {
	} else {
		objidimg.src = finalimgfile;
	}
}

/* FORM VALIDATION */
function formvalidation(whichformid) {
	formobj = document.getElementById(whichformid);
	/* INPUT VALIDATION */
	if (forminputvalidation(formobj, "requiremsg")) {
		formemailvalidation(formobj, "checkmail");
		formobj.action = "busca.cfm";
		formobj.submit();
	}
	return false;
}

function formvalidationcontact(whichformid) {
	formobj = document.getElementById(whichformid);
	/* INPUT VALIDATION */
	if (forminputvalidation(formobj, "requiremsg")) {
		formemailvalidation(formobj, "checkmail");
		formobj.action = "contatos-resposta.cfm";
		formobj.submit();
	}
	return false;
}

function formvalidationtrabalhe(whichformid) {
	formobj = document.getElementById(whichformid);
	/* INPUT VALIDATION */
	if (forminputvalidation(formobj, "requiremsg")) {
		formemailvalidation(formobj, "checkmail");
		formobj.action = "controllers/act_trabalhe_conosco.cfm";
		formobj.submit();
	}
	return false;
}

function forminputvalidation(formobj, requireatt) {
	inputaux = 0;
	var inputtag = new Array("input","textarea");
	inputtaglength = inputtag.length;
	for (f = 0; f < inputtaglength; f++) {
		if (formobj.getElementsByTagName(inputtag[f])) {
			inputelement = formobj.getElementsByTagName(inputtag[f]);	
			inputlength = formobj.getElementsByTagName(inputtag[f]).length;
			for (i = 0; i < inputlength; i++) {
				if (inputelement[i].getAttributeNode(requireatt)) {
					if (inputelement[i].id) {
						inputid = inputelement[i].id;
						inputobj = document.getElementById(inputid);
						inputobjvalue = inputobj.value;
						inputrequiremsg = inputelement[i].getAttributeNode(requireatt).nodeValue;
						if (checkvalue(inputobjvalue)) {
							alert(inputrequiremsg);
							inputobj.focus();
							inputaux = 1;
							return false;
							break;
						}
						inputobj.value = returnvalue(inputobjvalue);
					}
					//alert(inputelement[i].getAttributeNode("requiremsg").nodeValue);
				}
			}
		}
		if (inputaux != 0) {
			break;
		}
	}
	return true;
}

function checkvalue(inputobjvalue) {
	returnvalue(inputobjvalue);
	inputobjvaluereturn = inputobjvalueaux;
	if (inputobjvaluereturn.length <= 0) {
		return true;
	} else {
		return false;
	}
}

function returnvalue(inputobjvalue) {
	inputobjvaluelength = inputobjvalue.length;
	inputobjvalueaux = "";
	firstaux = 0;
	for (v = 0; v < inputobjvaluelength; v++) {
		if (inputobjvalue.charAt(v) == " " && firstaux == 0) {
			inputobjvalueaux += inputobjvalue.charAt(v).replace(" ", "");
		} else if (inputobjvalue.charAt(v) == " " && firstaux == 1) {
			inputobjvalueaux += inputobjvalue.charAt(v);
			firstaux = 2;
		} else if (inputobjvalue.charAt(v) == " " && firstaux == 2) {
			inputobjvalueaux += inputobjvalue.charAt(v).replace(" ", "");
			firstaux = 2;
		} else {
			inputobjvalueaux += inputobjvalue.charAt(v);
			firstaux = 1;
		}
	}
	return inputobjvalueaux;
}

/* E-MAIL VALIDATION */
function formemailvalidation(formobj, requireatt) {
	inputaux = 0;
	var inputtag = new Array("input");
	inputtaglength = inputtag.length;
	for (f = 0; f < inputtaglength; f++) {
		if (formobj.getElementsByTagName(inputtag[f])) {
			inputelement = formobj.getElementsByTagName(inputtag[f]);	
			inputlength = formobj.getElementsByTagName(inputtag[f]).length;
			for (i = 0; i < inputlength; i++) {
				if (inputelement[i].getAttributeNode(requireatt)) {
					if (inputelement[i].id) {
						inputid = inputelement[i].id;
						inputobj = document.getElementById(inputid);
						inputobjvalue = inputobj.value;
						//inputrequiremsg = inputelement[i].getAttributeNode(requireatt).nodeValue;
						if (checkvalue(inputobjvalue) == false) {
							inputobj.value = returnvalue(inputobjvalue);
							if (validateEmail(inputobj.value) == false) {
								alert("O e-mail não foi preenchido corretamente.");
								inputobj.focus();
								inputaux = 1;
								return false;
								break;
							}
						}
					}
				}
			}
		}
		if (inputaux != 0) {
			break;
		}
	}
	return true;
}

function validateEmail(email) {
    if (typeof(email) != "string")
	     return false;
    else if (!email.match(/^[A-Za-z0-9]+([_.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_.-][A-Za-z0-9]+)*\.[A-Za-z0-9]{2,4}$/))
         return false;
    return true;
}

/* NUMBERS ONLY */
function checknumber(event) {
	/*
	switch(window.event.keyCode)
	{
		case 48:
		case 49:
		case 50:
		case 51:
		case 52:
		case 53:
		case 54:
		case 55:
		case 56:
		case 57: break;
		default: event.returnValue = false;
		return;
	}
	*/
	var key; 
	var tecla; 
	if (navigator.appName.indexOf("Netscape")!= -1) {
		tecla = event.which;
	} else {
		tecla = event.keyCode;
	}
	if (tecla == 8 || tecla == 9 || tecla == 0) {
		return true;
	}
    	if (tecla >= 96 && tecla <= 105) {
        	return (isNum(key));
    	}
	
	// current pressed key
	var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();
	if (event.ctrlKey && (pressedKey == "c" || pressedKey == "v")) {
		// disable key press porcessing
		return false;
	}
    	if (event.shiftKey) {
        	// disable key press processing
        	return false;
    	}
	
	key = String.fromCharCode(tecla);
	return (isNum(key));
}

function isNum(caractere) {
	finalvalue = caractere.toString();
	var strValidos = "0123456789";
	if (strValidos.indexOf(finalvalue) == -1) {
		return false;
	} else {
		return true;  
	}
}


function valuechecknumber() {
	finalvalue = keyvalue.toString();
	var validChars = "0123456789";
	if (validChars.indexOf(finalvalue)) {
	}
}

//validacao de campos ADM
function validar(){
	
	var erro = 0;
	var msg = "";
	if(document.form1.especialidade.value.length == 0){
		msg += "O nome da Especialidade deve ser Preenchido.\n";
		erro ++;
	}
	if(erro > 0){
		alert(msg);
		return false;
	}	
}