﻿//On load page, init the timer which check if the there are anchor changes each 300 ms  
$().ready(function(){  
    setInterval("checkAnchor()", 300);  
});  
var currentAnchor = null;  
//Function which chek if there are anchor changes, if there are, sends the ajax petition  
function checkAnchor(){  
    //Check if it has changes  
    if(currentAnchor != document.location.hash){  
        currentAnchor = document.location.hash;  
        //if there is not anchor, the loads the default section
        if(!currentAnchor)  
            query = "page=home";  
        else  
        {  
            //Creates the  string callback. This converts the url URL/#main&amp;amp;id=2 in URL/?section=main&amp;amp;id=2  
            var splits = currentAnchor.substring(1).split('&amp;amp;');  
            //Get the section  
            var section = splits[0];  
            delete splits[0];  
            //Create the params string  
            var params = splits.join('&amp;amp;');  
            var query = "page=" + section + params;  
        }		
        //Send the petition
		$("#loading").show();
        $.get("callbacks.php",query, function(data){  
            $("#shower").html(data);  
			$("#loading").hide();
			$("#list").slideUp("fast");
        }); 
    }  
}

function searchweb()
{
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
		focusfire('focus');
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	var result = document.getElementById('searchbox').value;
	
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			$("#loading").hide();
    		document.getElementById('shower').innerHTML=xmlhttp.responseText;
    	}
		else
		{
			$("#loading").show();
		}
  	}
	xmlhttp.open("GET","request.php?page=search&text="+result,true);
	xmlhttp.send();
	
}

function lookup(inputString) {
	if(inputString.length == 0) {
		// Hide the suggestion box.
		$('#suggestions').hide();
	} else {
		$.post("autocomplete.php?page=auto", {queryString: ""+inputString+""}, function(data){
			if(data.length >0) {
				$('#suggestions').show();
				$('#autoSuggestionsList').html(data);
			}
		});
	}
} // lookup

function fill(thisValue) {
	$('#searchbox').val(thisValue);
	setTimeout("$('#suggestions').hide();", 100);
	document.getElementById("searchbox").focus();
}

function prodinc(id,command)
{
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	var result = document.getElementById('searchbox').value;
	
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
			$("#loading").hide();
    		document.getElementById('prod').innerHTML=xmlhttp.responseText;
			if(command == 'change')
			{
				document.getElementById('prod').align="center";
			}
			else
			{
				document.getElementById('prod').align="right";
				document.getElementById("producttext").focus();
			}
    	}
		else
		{
			$("#loading").show();
		}
  	}
	xmlhttp.open("GET","request.php?page=inquireprod&id="+id+"&command="+command,true);
	xmlhttp.send();
}


