<?php
/*
 * Copyright (c) 2004-2009 Luiz Otavio O Souza <loos.br@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/* 
 * $Id: js.inc.php 102 2009-02-05 18:37:40Z loos-br $
 */

?>
<script language="JavaScript">
<!--

    function popup(url) {
	window.open(url, '', 'height=450,width=550,scrollbars=yes');
    }

    function popup2(sb_id) {
	url = 'view.php?sb_id=' + sb_id;
	window.open(url, '', 'height=450,width=550,scrollbars=yes');
    }

    function showOptions(id) {
	var itm = null;

	if (document.getElementById) {
	    itm = document.getElementById(id);
	} else if (document.all){
	    itm = document.all[id];
	} else if (document.layers){
	    itm = document.layers[id];
	}
        
	if (!itm) {
	    // do nothing
	}
	else if (itm.style) {
	    if (itm.style.display == 'none') { itm.style.display = ''; }
	    else { itm.style.display = 'none'; }
	}
	else { itm.visibility = 'show'; }
    }

    function saveText(url, text) {
	url = url + '&value=' + text.value;
	submitChange(url);
    }

    function saveRadio(url, radio) {
	url = url + '&value=' + radio.value;
	submitChange(url);
    }

    function saveCheckBox(url, checkbox) {
	url = url + '&value=' + checkbox.checked;
	submitChange(url);
    }

    function saveSelect(url, select) {
	url = url + '&value=' +	select.options[select.selectedIndex].value;
	submitChange(url);
    }

    function submitChange(url) {

	var http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	    http_request = new XMLHttpRequest();
	    if (http_request.overrideMimeType) {
		http_request.overrideMimeType('text/xml');
	    }
	} else if (window.ActiveXObject) { // IE
	    try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
		try {
		    http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	    }
	}

	if (!http_request) {
	    alert('Giving up :( Cannot create an XMLHTTP instance');
	    return false;
	}
	http_request.onreadystatechange = function() { alertCheckUpdate(http_request); };
	http_request.open('GET', url, true);
	http_request.send(null);
    }

    function alertCheckUpdate(http_request) {

	if (http_request.readyState == 4) {
	    if (http_request.status == 200) {
		//alert(http_request.responseText);
		if (http_request.responseText != 'ok')
		    alert('Falha ao gravar alteracao !');
	    } else {
		alert('There was a problem with the request.');
	    }
	}
    }

//-->
</script>
