// JavaScript Document
function getURL(mainpage, ancor){
	var page = location.href.split("/");
	page = page[page.length - 1];
	page = page.split(".");
	page = page[0];
	
	if( page == "" || page == "regulary" || page == "index" ){
		sendToPage( "index" );
	} else {
		sendToPage( mainpage, ancor );
	}
}

function sendToPage( page, ancor ) {
	switch( page ) {
			case "index":
				location.href = "index.html";
				break;
			case "home":
				location.href = "home.html";
				break;
			case "company":
				location.href = "company.html"
				break;
			case "prod1":
				location.href = "products1.html"
				break;
			case "prod2":
				location.href = "products2.html"
				break;
			case "prod3":
				location.href = "products3.html"
				break;
			case "prod4":
				location.href = "http://www.galloway.com.br"
				break;
			case "prod5":
				location.href = "products5.html"
				break;
				case "prod6":
				location.href = "products6.html"
				break;
				case "prod7":
				location.href = "products7.html"
				break;
			
			case "contact":
				location.href = "contact.html"
				break;
			case "team":
				location.href = "team.html"
				break;
			case "work":
				location.href = "work.html"
				break;
				case "work2":
				location.href = "faq.html"
				break;
			case "agentes":
				window.open("agentes.html");
				break;
			case "privacy":
				location.href = "privacy.html"
				break;
			case "terms":
				location.href = "terms.html"
				break;
			case "regulary":
				location.href = "regulary.html"
				break;
			case "map":
				location.href = "map.html"
				break;
			case "faq":
				location.href = "faq.html"
				break;
			case "emall":
				"mailto:atendimento@galloway.com.br"
				break;
			case "valid":
				var userName = document.getElementById("name");
				var userComp = document.getElementById("company");
				var userEmail = document.getElementById("email");
				
				if( userName.value != "" && userComp != "" && userEmail != "" && userName.value != "invalid field" && userComp.value != "invalid field" && userEmail.value != "invalid field" && validateEmail(userEmail.value) ){
					location.href = "regulary.html";
				} else {
					userName.value = "invalid field";
					userComp.value = "invalid field";
					userEmail.value = "invalid field";
				}
				break;
		}	
}

function validateEmail(elementValue){  
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
	return emailPattern.test(elementValue);  
}
