var is_ajax_div = "";
var is_current_location = "";
var in_url_check_interval_id = -1;

function setAjaxDiv( vs_div ) {
    is_ajax_div = vs_div;
}

function ajaxUpdate( vs_url ) {
    ajaxUpdateDiv( vs_url, is_ajax_div );
}

function ajaxUpdateDiv( vs_url, vs_div ) {


    if ( vs_url.indexOf("ajax=true") == -1 ) {
        vs_url = vs_url + "&ajax=true";
    }


    var vs_obj = vs_div;
    
    var o_ajax_target = document.getElementById(vs_obj);

    o_ajax_target.className="loadingOn";

    while( o_ajax_target.firstChild ) o_ajax_target.removeChild( o_ajax_target.firstChild );

    try {
        setHeightBeforeAjax();
    } catch ( ve_error ) {
              
    }

    var xmlObj = null;
    if(window.XMLHttpRequest){
        xmlObj = new XMLHttpRequest();
    } else if(window.ActiveXObject){
        xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        return;
    }
    
    xmlObj.onreadystatechange = function(){
        if(xmlObj.readyState == 4){
          
            o_obj = document.getElementById(vs_obj);

            o_test = xmlObj.responseXML.getElementsByTagName("div").item(0);

            //alert( o_test );

            o_test.removeAttribute("xmlns");

            try {

                o_imported_div = document.importNode( o_test, true)
                o_obj.appendChild( o_imported_div );

            } catch ( e ) {
                o_obj.innerHTML = xmlObj.responseText;
            }
           
            o_obj.className = "loadingOff";

            try {
                setHeightAfterAjax();
            } catch ( ve_error ) {
              
            }

            var o_scripts = o_obj.getElementsByTagName("script"); 
            for(var n_index=0; n_index < o_scripts.length; n_index++)
            {
                eval( o_scripts[n_index].text);
            }


            if ( o_google_page_tracker != null ) {
                o_google_page_tracker._trackPageview( unescape(vs_url) );
            }


        }
    }
    
    xmlObj.open('GET', unescape(vs_url), true);
    xmlObj.send('');

    
//    try {

        // make sure vs_url doesnt have ajax=true at the end
//        if ( vs_url.indexOf("&ajax=true") > 0 ) {
//            vs_url = vs_url.substring( 0, vs_url.indexOf("&ajax") );
//        }

//        s_cur_url = window.location.href;

//        if ( s_cur_url != vs_url && s_cur_url.substring( s_cur_url.lastIndexOf("#") + 1) != vs_url ) {

//            window.location.href = window.location.href + "#" + vs_url
            
//            if ( in_url_check_interval_id == -1 ) {
//                in_url_check_interval_id = setInterval( "checkURL()", 500 )
//            }

//        }

//        is_current_location = window.location.href;

//    } catch ( ve_error ) {
//        alert( vs_error );
//    }
    
}



function checkURL() {

    if ( window.location.href != is_current_location ) {

        s_url = window.location.href;

        if ( s_url.indexOf("#") > 0 ) {
            s_url = s_url.substring( s_url.lastIndexOf("#") + 1 );
        }

        ajaxUpdate(s_url);
        
    }

}



function setActiveTab( vo_obj ) {

    if ( typeof vo_obj == "string" ) {
        vo_obj = document.getElementById( vo_obj );
    }

    o_tabs = document.getElementById("topNavigation").childNodes;

    for (var i = 0; i < o_tabs.length; i++)
    {
        try {
            o_tabs[i].className="none";
        } catch ( e ) {
            // this block exists until we find out how to do an instanceof link
        }
    }

    vo_obj.className="activeTab";
    vo_obj.blur();
}


function addMediaGallery( vs_url, vn_id, vs_use_thumbs, vn_width, vn_height, vs_div ) {

    var s_proto = (("https:" == document.location.protocol) ? "https://" : "http://");

    s_gallery_url = s_proto + "www.d6einc.com/paragonCMS/flash/Gallery.swf?xml_file=" + escape(vs_url) + "&amp;random=" + new Date().getTime();

    so = new SWFObject( s_gallery_url , "vp", vn_width, vn_height, 9, "#FFFFFF");
    so.addParam("FlashVars", "ma_id=" + vn_id + "&amp;use_thumbnails=" + vs_use_thumbs);
    so.addParam("wmode", "transparent");
    so.write(vs_div);

}


function addVideo( vs_url, vn_id, vb_auto_play, vb_loop_video, vn_width, vn_height, vs_div ) {
    
    var s_proto = (("https:" == document.location.protocol) ? "https://" : "http://");

    s_video_url = s_proto + "www.d6einc.com/paragonCMS/flash/VideoPlayer.swf?video_file=" + escape(vs_url) + "/pcmsfile/" + vn_id + ".flv" + "&amp;random=" + new Date().getTime();

    so = new SWFObject( s_video_url , "vp", vn_width, vn_height, 9, "#FFFFFF");
    so.addParam("FlashVars", "autoplay=" + vb_auto_play + "&amp;loop_video=" + vb_loop_video);
    so.addParam("allowFullScreen", "true");
    so.addParam("wmode", "transparent");
    so.write(vs_div);
    
}