var wnd = false;

function init() {
	changeBackGround();
}
function changeBackGround() {
	var aux = document.body;
	if (screen.width >= 1280) {
		aux.style.background = "url('http://www.oceanpacific.com.br/images/fundo1280.gif')";
	} else if (screen.width == 800) {
		aux.style.background = "url('http://www.oceanpacific.com.br/images/fundo800.gif');";
	} else {
		aux.style.background = "url('http://www.oceanpacific.com.br/images/fundo1024.gif')";
	}
	aux.style.backgroundAttachment = 'fixed';
}

function getEl(id) {
	return document.getElementById(id);
}
function openFinishedBuildings(whichBuild) {
	wnd = window
			.open(
					whichBuild,
					'_blank',
					'height = 550, width = 600, menubar =no, status = no, toolbar = no, scrollbars = yes, top = 25, left=100');

	wnd.onload = addCloseButton;
	return true;
}

function addCloseButton() {
	if (wnd == false)
		return;
	var centered = wnd.document.createElement('center');
	var closeButton = wnd.document.createElement('input');
	closeButton.setAttribute("type", "button");
	closeButton.setAttribute("value", "Fechar");
	closeButton.setAttribute("onclick", "self.close();");
	centered.appendChild(closeButton);
	wnd.document.body.appendChild(centered);
	wnd = false;
}

function contact_validate(form) {
	if (form == null)
		return false;
	document.getElementById("error").innerHTML = "";
	var aux = document.getElementById("nome");
	if (aux != null) {
		if (aux.value.indexOf("Digite seu nome aqui") >= 0) {
			document.getElementById("error").appendChild(document
					.createTextNode("Preencha seu nome corretamente"));
			aux.select();
			return false;
		}
	}
	aux = document.getElementById("email");
	if (aux != null) {
		if (aux.value.indexOf('@') <= 3 || aux.value.indexOf('.') < 5) {
			document.getElementById("error").appendChild(document
					.createTextNode("Preencha seu email corretamente"));
			aux.select();
			return false;
		}
	}
	aux = document.getElementById("comment");
	if (aux != null) {
		if (aux.value.length < 20) {
			document
					.getElementById("error")
					.appendChild(document
							.createTextNode("Preencha sua duvida ou sugestao corretamente"));
			aux.focus();
			return false;
		}
	}
	form.submit();
}
function contact_onmykeyup(event, form) {
	if (event.keyCode == 13)
		contact_validate(form);
}
function success_page()
{
	if( document.location.toString().indexOf( "#sucesso" ) > 0 )
	{
		getEl("content").innerHTML = "<h1>Seu formulario foi enviado com sucesso, aguarde. <br><br>Em breve entraremos em contato.</h1>";
	}
}
