<!--

/****************************************************************************************************************
 *
 *  VisionJinx.Net Simple AJAX API v1.0 - June, 2007 Vision Jinx (www.visionjinx.net)
 *
 *  This notice MUST stay intact for legal use. All rights are reserved.
 *  If you like this script you can visit http://www.visionjinx.net/
 *  for more cool things and please consider a link back to my site also.
 *  You also agree to use this script at your own risk.
 *
 *  Last Modified:
 *
 *	User Feature: Aug 2007 - vj_favicon feature added for adding a favicon.ico to Google Pages
 *	User Feature: Sep 2007 - Added a loading feature to show a page is being fetched
 *				 (set vj_ajax_fail_flag to 1 to turn it off)
 *
 *
 *  === How to use this script ===
 *
 *  User optional variables:
 *	vj_style - This is if you want to load your own stylesheet (vj_ajax.css)
 *  	vj_js - This is if you want to load your own javascript (vj_mods.js)
 *		You can not load a script in a fetched page
 *  	ajax_dir - This is a folder for your AJAX Pages (my_ajax_pages/)
 *		Google Pages users leave this blank, since GPC does not support folders
 *	vj_favicon - Add a favicon.ico to Google Pages. (GPC Users don't call it favicon.ico, GPC overwrites it)
 *
 *  Required HTML Elements:
 *	<div id="links_op1" style="display:none;"> - This is the container for the AJAX Links that need to load
 *	<div id="main_op1" style="display:none;"> - This is the container for the AJAX fetched results
 *
 *  Required HTML pages:
 *	ajax_links.htm - This is where you put your HTML to call the pages you want
 *
 *  Script Syntax:
 *	vj_ajax1('Page_to_Fetch','ID_For_Output','Number_Of_Subpages - or use "code" to optput the HTML code')
 *
 *  Sample Syntax:
 *	vj_ajax1('homepage','main_op1','0'); - Output homepage.htm into id="main_op1" with 0 subpages
 *	vj_ajax1('homepage','main_op1','code'); - Show the code for homepage.htm into id="main_op1"
 *
 *  Script calls:
 *	You can call it the same way as any javascript call.
 *	onclick, onmouseover, onload or from a link, button or an image etc.
 *
 *
 *  Enjoy! 8)
 *
 ****************************************************************************************************************/
// User optional variables

// load a stylesheet
var vj_style = "";

// load a javascript (vj_mods.js will be the script for the AJAX modules)
var vj_js = "vj_mods.js";

// load a Favicon (feature for Google Pages)
var vj_favicon = "fav1.ico";

// folder for AJAX Pages (my_ajax_pages/) - GPC Users leave this blank
var ajax_dir = "";


// AJAX "Loading..." container ID
var vj_container = document.getElementById('content');




/*****************************************************************************
 *
 *  DO NOT MODIFY ANYTHING BELOW HERE
 *
 *******************************************************************************/
// a function to add a javascript
if (vj_js != "") {
    vj_load_js = document.createElement('script')
    vj_load_js.setAttribute("type", "text/javascript");
    vj_load_js.setAttribute("src", vj_js);
    if (vj_load_js != "") {
        document.getElementsByTagName("head").item(0).appendChild(vj_load_js)
    }
}

// a function to add a stylesheet
if (vj_style != "") {
    vj_load_css = document.createElement("link")
    vj_load_css.setAttribute("rel", "stylesheet");
    vj_load_css.setAttribute("type", "text/css");
    vj_load_css.setAttribute("href", vj_style);
    if (vj_load_css != "") {
        document.getElementsByTagName("head").item(0).appendChild(vj_load_css)
    }
}

// a function to add a favicon to GPC
if (vj_favicon != "") {
    vj_load_favicon = document.createElement("link")
    vj_load_favicon.setAttribute("rel", "shortcut icon");
    vj_load_favicon.setAttribute("type", "image/x-icon");
    vj_load_favicon.setAttribute("href", vj_favicon);
    if (vj_load_favicon != "") {
        document.getElementsByTagName("head").item(0).appendChild(vj_load_favicon)
    }
}

// Include the Loading... notification (0 = yes and 1 = no)
var vj_ajax_fail_flag = 0;

function vj_loading(){
    if (!document.getElementById('vj_ajax_loading')) {
        var vj_cp = document.createElement('div');
        var html = "Carregando...";
        vj_cp.className = 'vj_ajax_loading';
        vj_cp.id = 'vj_ajax_loading';
        vj_cp.setAttribute('title', 'Click to close');        
        vj_cp.innerHTML = html;
        vj_container.appendChild(vj_cp);
        var vj_subel = document.getElementById('vj_ajax_loading');
        vj_subel.onclick = function(){
            this.parentNode.removeChild(this);
        };
    }
    else {
        document.getElementById('vj_ajax_loading').style.display = 'block';
    }
}

// Simple AJAX Function
function vj_ajax1(pagefinderId, resultId, pages){

    var xmlHttp;
    
    // create link path
    if (ajax_dir != "") {
        var link = ajax_dir + pagefinderId + '.htm';
    }
    else {
        var link = pagefinderId + '.htm';
    }
    
    // Check for a supported browser
    try { // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    } 
    catch (e) { // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) {
                alert("Your browser does not support AJAX!");
                vj_ajax_fail_flag = 1;
                return false;
            }
        }
    }
    
    if (vj_ajax_fail_flag != 1) {
        //vj_ajax_clear('content');
        vj_loading();
    }
    
    // copy code function
    if (pages == 'code') {
        // return fetched content
        xmlHttp.onreadystatechange = function(){
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                // generate some HTML for the output
                var html = "";
                if (document.getElementById('vj_ajax_loading')) {
                    document.getElementById('vj_ajax_loading').style.display = 'none';
                }
                html += "<textarea class=\"text_op1\" rows=\"5\" style=\"\" onfocus=\"this.select();\">";
                html += xmlHttp.responseText;
                html += "</" + "textarea><br>";
                document.getElementById(resultId).innerHTML = html;
                document.getElementById(resultId).style.display = 'block';
            }
        }
        xmlHttp.open("GET", link, true);
        xmlHttp.send(null);
    }
    else {
        // return fetched content
        xmlHttp.onreadystatechange = function(){
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                // generate some HTML for the output
                var html = "";
                var ajax_rand = "vj_" + Math.floor(Math.random() * 9999999)
                // vj_subel.parentNode.removeChild(vj_subel);
                if (document.getElementById('vj_ajax_loading')) {
                    document.getElementById('vj_ajax_loading').style.display = 'none';
                }
                if (pages >= 1) {
                    html += "<div style=\"text-align:center;\">";
                    for (count = 1; count <= pages; count++) {
                        html += "<a href=\"javascript:void(0);\" class=\"ajax_subpage_link\" onclick=\"vj_ajax1('" + pagefinderId + count + "','" + ajax_rand + "');\">Page" + count + "</" + "a> ";
                    }
                    html += "</" + "div>";
                }
                html += "<div id=\"" + ajax_rand + "\" style=\"margin-top:10px;\">";
                html += xmlHttp.responseText;
                html += "</" + "div>";
                document.getElementById(resultId).innerHTML = html;
                document.getElementById(resultId).style.display = 'block';
            }
        }
        xmlHttp.open("GET", link, true);
        xmlHttp.send(null);
    }
}

// Create Clear Function
function vj_ajax_clear(id){
    var clearAJAX = document.getElementById(id);
    clearAJAX.innerHTML = '';
    clearAJAX.style.display = 'none';
}


/***************************************************************
 *  Functions to load and run go here
 *  Edit the below as required
 *  Defaults are Load AJAX Links and Run Random Quotes
 ***************************************************************/
function init(){

    // Load AJAX Links
    //vj_ajax1('ajax_links','g_description');
    
    // Load a page for the toggle feature (Beta Feature)
    // vj_ajax1('new','vj_ajax_tip2');
    
    // Load a default body page
    // vj_ajax1('homepage','g_body');
    
    // Load Random Quotes Module (default set for footer)
    vj_quotes();
    
}

// Un-Comment this to initalize when page loads
// Leave it commented out to use a button/link to load it
// window.onload = init;
-->

