//On load page, init the timer which check if the there are anchor changes each 300 ms  
$().ready(function(){  
  //  window['set'+'Interval']('checkAnchor()', 300); 
   //setInterval('checkAnchor()', 300); 
});  
var please_wait = null;
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 = "section=home";  
          else  
          {  
              //Creates the  string callback. This converts the url URL/#main&id=2 in URL/?section=main&id=2  
              var splits = currentAnchor.substring(1).split('&');  
              //Get the section  
              var section = splits[0];  
              delete splits[0];  
              //Create the params string  
              var params = splits.join('&');  
              var query = "section=" + section + params;
			  
		  }  
          //Send the petition  
          $.get("callba3.php",query, function(data){  
              $("#contentMDiv").html(data);  
          });  
      }
}

function open_url(url, target) {
 	if ( ! document.getElementById) {
  		return false;
 	}

 	if (please_wait != null) {
  		document.getElementById(target).innerHTML = please_wait;
 	}

 	if (window.ActiveXObject) {
  		link = new ActiveXObject("Microsoft.XMLHTTP");
 	} else if (window.XMLHttpRequest) {
  		link = new XMLHttpRequest();
 	}

 	if (link == undefined) {
  		return false;
 	}
 	link.onreadystatechange = function() { response(url, target); }
 	link.open("GET", url, true);
 	link.send(null);
}

function response(url, target) {
 	if (link.readyState == 4) {
	 	document.getElementById(target).innerHTML = (link.status == 200) ? link.responseText : "Ooops!! A broken link! Please contact the webmaster of this website ASAP and give him the fallowing errorcode: " + link.status;
	}
}

function set_loading_message(msg) {
 	please_wait = msg;
}

function loadTab(pageUrl,target) 
{ 
    $.ajax( 
    { 
        url: pageUrl, 
        cache: false,
		dataType: "html",
        success: function(message) 
        { 
            $(target).empty().append(message); 
        } 
    }); 
} 

function evalScript(scripts)
{	try
	{	if(scripts != '')	
		{	var script = "";
			scripts = scripts.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(){
	       	                         if (scripts !== null) script += arguments[1] + '\n';
 	        	                        return '';});
			if(script) (window.execScript) ? window.execScript(script) : window.setTimeout(script, 0);
		}
		return false;
	}
	catch(e)
	{	alert(e)
	}
}


