function openWindow(title, url, width, height) {

	window.open(url, title, 'width='+width+',height='+height+',resizable=0,status=0,menubar=0');

}

function changePic(urlLeft, urlRight) {

	parent.leftFrame.location = urlLeft;
	if(urlRight != 'undefined')
		parent.rightFrame.location = urlRight;

}

function ajaxLoadDepartamentos(sede_id, dire_id) {

	//verifica se o browser tem suporte a ajax
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}
			catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = null;
			}
		}
	}
	
	//se tiver suporte ajax
	if(ajax) {
		
		//deixa apenas o elemento 1 no option, os outros são excluídos
		document.forms[1].departamento.options.length = 1;

		// pega o primeiro option do select
		idOpcao  = document.forms[1].departamento.options[0];

		ajax.open("POST", "contato.xml.departamento.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

		ajax.onreadystatechange = function() {
			
			//enquanto estiver processando...emite a msg de carregando
			if(ajax.readyState == 1) {
				idOpcao.innerHTML = "Carregando...";
			}
			//após ser processado - chama função processXML que vai varrer os dados
			if(ajax.readyState == 4) {
				if(ajax.responseXML) {
					ajaxProcessXMLDepartamentos(ajax.responseXML, dire_id);
				}
				else {
					//caso não seja um arquivo XML emite a mensagem abaixo
					idOpcao.innerHTML = "-- Selecione uma sede --";
				}
			}
		}
		
		//passa o código da organização escolhida
		var params = "sede_id=" + sede_id;
		
		// envia
		ajax.send(params);

	}

}

function ajaxProcessXMLDepartamentos(obj, dire_id) {

	//pega a tag user
	var dataArray = obj.getElementsByTagName("departamento");

	var arrayLength = dataArray.length;

	//total de elementos contidos na tag user
	if(arrayLength > 0) {

		//percorre o arquivo XML paara extrair os dados
		for(var i = 0; i < arrayLength; i++) {

			var item = dataArray[i];
			
			//contéudo dos campos no arquivo XML
			var id =  item.getElementsByTagName("id")[0].firstChild.nodeValue;
			var name = item.getElementsByTagName("titulo")[0].firstChild.nodeValue;
		
			idOpcao.innerHTML = "-- " + arrayLength + " departamento(s) --";

			//cria um novo option dinamicamente  
			var novo = document.createElement("option");
			//atribui um ID a esse elemento
			novo.setAttribute("id", "opcoes");
			//atribui um valor
			novo.value = id;
			//atribui um texto
			novo.text  = name;
			if(id == dire_id) {
				novo.setAttribute("selected", "selected");
			}
			
			//finalmente adiciona o novo elemento
			document.forms[1].departamento.options.add(novo);

		}
	}
	else {
		//caso o XML volte vazio, printa a mensagem abaixo
		idOpcao.innerHTML = "-- Nenhum departamento encontrado --";
	}

}

function youtube(url){
	document.write('<object><param name="movie" value="'+url+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+url+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>');
}