function isdefined(variable)
{
    return (typeof(window[variable]) != "undefined");
}

function trackEvent(hostUrl, category, action ,label)	 		
{
	label = encodeURIComponent(label);
	$.postMessage({type:"track",alert:"false",data:{"category":category,"action":action,"opt_label":label,"opt_value":"0"}},hostUrl,window.parent);
}

function trackEventPopUp(hostUrl, category, action ,label)	 		
{
	/*Call from I-frame to original window trackEvent*/
	window.opener.trackEvent(hostUrl, category, action ,label);
}

var hostUrl="";		
$(window).load(function(){
	
	var params=(location.search=="")?{}:jQuery.deparam.querystring(location.href);
	hostUrl = (typeof(params["host"]) == "undefined") ? "" : params["host"];
 			
	// wrappar vi samtliga a-href
	$("a").click(function() {
		// do this before - modda eller appenda href
		if (hostUrl != ""){
			var href = $(this).attr("href");
			if (href.toLowerCase().indexOf("javascript")==-1){
				href = jQuery.param.querystring(href,"host=" + hostUrl);
				$(this).attr("href",href);
			}
		}
		return true;

 	});
	
	$("form").submit(function() {
		if (hostUrl != ""){
	 		var href = $(this).attr("action");
	 		href = jQuery.param.querystring(href,"host=" + hostUrl);
	 		$(this).attr("action",href);
		}	
	    return true;
    });
	
	
	
	
	
/*	
	$.receiveMessage(function(e){
		if (hostUrl != ""){
			var test = $.deparam(e.data);
*/			
/*			var category = "";
			var action = "";
			var label = "";
			
			for (var i=0;i<e.data.split('&').length;i++){
				switch(decodeURIComponent(e.data.split('&')[i].split('=')[0]))
				{
				case "data[category]":
					category = decodeURIComponent(e.data.split('&')[i].split('=')[1]);
					break;
				case "data[action]": 
					action = decodeURIComponent(e.data.split('&')[i].split('=')[1]);
				  	break;
				case "data[opt_label]":
					label =  decodeURIComponent(e.data.split('&')[i].split('=')[1]);
					break;
				}
			}
			
			alert(category);
			alert(action);
			alert(label);
*/			
/*			$.postMessage(test,hostUrl,window.parent);
		}
	} );
*/
 


});

