/*
		Ny javascript som förhoppnignsvis blir lite bättre än den gamla
		
		Författare:		
		Daniel Malmquist <daniel@malmqui.st> 2008
		
		Copyright till författare
*/

function AjaxLoadPage(url, div, postvar, wysiwygelements, funcpoint) {
	
	var xmlHttp;
	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("Din webläsare är för gammal!");
					  return false;
				 }
				
		  }
	 }
	 
	 
	 //On ready statefunktionen
     xmlHttp.onreadystatechange=function()
	 {
		 //laddat färdigt
		if(xmlHttp.readyState==4)
		{
			if(div == null)
			{
				div = 'mainright';	
			}
			document.getElementById(div).innerHTML = xmlHttp.responseText;
			//document.getElementById("loadingbox").style.display="none";
			
			//om vi ska ha wysiwyg
			if (wysiwygelements != null) {
				tinyMCE.init({
					theme : "advanced",
					mode : "exact",
					language : "sv",
					strict_loading_mode : true,
					gecko_spellcheck : true,
					theme_advanced_toolbar_location : "top",
					elements : wysiwygelements,
					plugins :"safari,style,layer,table,save,advhr,advimage,advlink,iespell,inlinepopups,media,searchreplace,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",
		
					// Theme options	
					theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,forecolor,|,visualchars,nonbreaking,|,cleanup,code,|,advhr,|,ltr,rtl,|,media",
					theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image",
					theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell",
					theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,,del,|,formatselect,fontselect,fontsizeselect",
					theme_advanced_toolbar_location : "top",
					theme_advanced_toolbar_align : "left",
					theme_advanced_resizing : false
				});
				
			}
			
			if (funcpoint != null) {
			
				funcpoint();
			
			}
			
			
		}
		else if (xmlHttp.readyState==1)	{ 
			//document.getElementById("loadingbox").style.display="block";
		}
	 }
	 
	 
	 if (postvar != null) {
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", postvar.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(postvar);
	 }
	 else {
	 
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	
	 }
}
