 
jQuery().ready(function() {
	jQuery(".external").attr("target","_blank");
}); 


function insert_flash( url, width, height, module_name, id ) {
	var str = "", style = "";
	
	if( width || height ) {
		style = " style=\""+(width?"width:"+width+"px;":"")+(height?"height:"+height+"px;":"")+"\"";
		if( width ) {
			width = " width=\""+width+"\"";
		}
		if( height ) {
			height = " height=\""+height+"\"";
		}
	}
	
	str = "<object class=\"flash "+module_name+""+id+"\" type=\"application/x-shockwave-flash\" data=\""+ url +"\"";
	str += style;
	str += width;
	str += height;
	str += ">\n<param name=\"movie\" value=\""+ url +"\" />\n</object>\n";
	
	document.write(str);
}

// taken from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

function  getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}

// Ajax loader

$("#country-documents").change(function(){
	$("#ajax-loader").show();
	countryContent = $.ajax({
		      url: "/extra/tools/parser/",
		      global: false,
		      type: "POST",
		      cache: false,
		      data: ({ url: "/html/parse/country_documents.html", p: $("#countries").val(), action: getUrlVars()["action"], id: getUrlVars()["id"], module_instance: getUrlVars()["module_instance"], navid: getUrlVars()["id"] }),
		      dataType: "html",
		      async: false,
		      success: function(msg){
		         $("#ajax-loader").hide();
		      },
		      error: function(msg){
		      	alert("Ett fel uppstod!");
		      } 
		   }
		).responseText;
	})
