
var iBusy = 0;
var sUrl = "http://www.rock-in-stock.nl";

function hideSearchResult()
{
	var elem = document.getElementById('topSearchResult');
	if (elem.style.display=='block')
	{
		elem.style.display='none';
	}
}

function searchSiteTop(sInput)
{
	var elem = document.getElementById('topSearchResult');
	if (sInput.length > 0 && sInput != "Zoeken...")
	{
		elem.style.display='block';

		document.getElementById('topSearchResult').innerHTML='<center><br /><img src="http://www.rock-in-stock.nl/images/loading.gif"></center>';
		var theForm = 'search='+sInput;
        	make_request('http://www.rock-in-stock.nl/ajax/aSearch.php', 'returnSearch', 'POST', theForm); 

	} else {
		elem.style.display='none';
	}
}

function returnSearch(result)
{

	document.getElementById('topSearchResult').innerHTML=result;
}

$j(document).ready(function(){	

	var $x = jQuery.noConflict();

	$x('#main-nav').treeview({
		animated: "fast",
		collapsed: true,
		unique: true,
		persist: "cookie",
		toggle: function() {
			window.console && console.log("%o was toggled", this);
		}
	});

	$x('#main-nav a').click(function(){ 

	    return false;
	}); 

});

function emptyInput(sField)
{
	if (sField.value=='Zoeken...')
	{
		sField.value='';
	}
}

function searchArticles(sValue,m_id,c_name)
{
	if (iBusy==0)
	{
		theForm = "search="+sValue+"&m_id="+m_id+"&content_name="+c_name;
       		make_request('http://www.rock-in-stock.nl/ajax/aArticles.php', 'returnNewsPage', 'POST', theForm); 
	}
}

function gotoNewsPage(iPage,m_id,c_name)
{
	if (iBusy==0)
	{
		document.getElementById('article_items').innerHTML = '<img class="normal" align="absmiddle" src="http://www.rock-in-stock.nl/images/icons/loading.gif" alt="De berichten worden geladen" /> De berichten worden geladen.';
		theForm = "page="+iPage+"&m_id="+m_id+"&content_name="+c_name;
        	make_request(sUrl+'/ajax/aArticles.php', 'returnNewsPage', 'POST', theForm); 
		iBusy=1;
	}
}

function returnNewsPage(result)
{
	//alert(result);

	var aResult = result.split('|%|%|');
	document.getElementById('article_items').innerHTML = aResult[0];
	document.getElementById('pag_nav').innerHTML = aResult[1];

	iBusy=0;

}

 function create_http_object() 
    { 
        var ActiveXTypes = [ 
            "Microsoft.XMLHTTP", 
            "MSXML2.XMLHTTP.5.0", 
            "MSXML2.XMLHTTP.4.0", 
            "MSXML2.XMLHTTP.3.0", 
            "MSXML2.XMLHTTP" 
        ]; 

        for( var i = 0; i < ActiveXTypes.length; i++ ) 
        { 
            try 
            { 
                return new ActiveXObject( ActiveXTypes[i] ); 
            } 
            catch( e ) 
            { } 
        } 

        try 
        { 
            return new XMLHttpRequest(); 
        } 
        catch( e ) 
        { } 

        return false; 
    } 

    function make_request(url, callback_function, http_method, post_values, return_xml) 
    { 
        http = create_http_object(); 

        if(!http) 
        { 
            alert('Je browser ondersteunt deze feature niet.'); 
            return false; 
        } 


        http.onreadystatechange = function() 
        { 
            if(http.readyState == 4) 
            { 
                if(http.status == 200) 
                { 
                    if(callback_function) 
                    { 
                        if(return_xml) 
                        { 
                            eval(callback_function + '(http.responseXML)'); 
                        } 
                        else 
                        { 
                            eval(callback_function + '(http.responseText)'); 
                        } 
                    } 
                } 
                else 
                { 
                    alert('Error! (' + http.status + ')'); 
                } 
            } 
        } 

        if(!post_values) 
        { 
            post_values = null; 
        } 
        if(!http_method) 
        { 
            http_method = "GET"; 
        } 

        http.open(http_method, url, true); 

        if(http_method == "POST") 
        { 
            http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
        } 

        http.send(post_values); 
    } 


