// JavaScript Document

//<!--

var req;
function loadXMLDoc(url, submenu, id){
	req = null;

	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		switch (id) {
			case 1:
				req.onreadystatechange = processReqChange1;
				break;
		}
		req.open("GET", url, true); 
		req.send(null);
	} else if (window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP.4.0");
		} catch(e) {
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP.3.0");
			} catch(e) {
				try {
					req = new ActiveXObject("Msxml2.XMLHTTP");
				} catch(e) {
					try {
						req = new ActiveXObject("Microsoft.XMLHTTP");
					} catch(e) {
						req = false;
					}
				}
			}
		}
		if (req) {
			switch (id) {
				case 1:
					req.onreadystatechange = processReqChange1;
					break;
			}
			req.open("GET", url, true);
			req.send();
		}
	}
}

function processReqChange1(){ // STAGE
	if (req.readyState == 4) {
		if (req.status == 200) {
			document.getElementById("flow").innerHTML = req.responseText;
			//initShowHideDivs();
		} else {
			alert("An error was occurred. The requested page was not found:\n" + req.statusText);
		}
	}
}

function atualiza(alvo, submenu, id){ // Gerenciador de carregamento de páginas Ajax
	loadXMLDoc(alvo, submenu, id);
}

function validaForm(id){ // Validação dos formulários
	switch (id)	{
		case 1: // CONTATO
			d = document.contact;
			
			if (d.name.value=="" || d.phone.value=="" || d.email.value=="" || d.found.value=="" || d.message.value=="") {
				msgErro(1);
				return false;
			}
			
			return true;
			break;
	}
}

function msgErro(tipo){
	switch (tipo) {
		case 1: // CONTATO
			msg = "Please fill out the following form to send us an inquiry.\nRequired fields are marked with asterisk.";
			break;
	}
	alert (msg);
}

//

var dhtmlgoodies_slideSpeed = 10;	// Higher value = faster
var dhtmlgoodies_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
function showHideContent(e,inputId)
{
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);
	
	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){

		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	var obj =document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				
			}
		}else{
			dhtmlgoodies_activeId = inputId;
		}
	}
}

function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='dhtmlgoodies_question'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'dhtmlgoodies_q'+divCounter;
			
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			
			answer.id = 'dhtmlgoodies_a'+divCounter;	
			
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='dhtmlgoodies_answer_content';
			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}
}

//

function search() {
	queryTxt = document.getElementById("queryTxt").value;
	if (queryTxt!='') {
		window.open('search.php?query=' + queryTxt,'_self');
	}
}

//-->
