function Trace(msg, debug){
	var who = msg.split(" - ");
	var debug = window.document.getElementById(debug);
	if (debug) debug.innerHTML += msg + "\n<br/>\n";
}

function CheckLocation(){
	if (typeof(window.document.morada) == "unloaded") {
		//alert (location.href);
		window.document.morada = location.href;
		location.reload();
	}
}
window.document.timer = window.setInterval('CheckLocation()', 3000);
window.onunload = function (){
	window.document.morada = "unloaded";
}
CheckLocation();

function loadFlash(htmlAnchor, fileName, width, height, bgColor, bgVisible, variablePairs, KeepSize){
	var html = "";
	var isIE = navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length;
	var node = window.document.getElementById(htmlAnchor);
	var htmlAnchor = htmlAnchor + "Obj";
	if (variablePairs) var variablePairs = "&" + variablePairs; else var variablePairs = "";
	var variablePairs="JSName=" + htmlAnchor + variablePairs;
	// ########################################################### Loads the Flash File #######################################################################
	if (isIE){
		html += '<embed ';
		html += ' name="' + htmlAnchor + '"';
		html += ' id="' + htmlAnchor + '"';
		html += ' src="' + fileName + '"';
		html += ' width="' + width + '" height="' + height + '"';
		html += ' bgcolor="' + bgColor + '"';
		if (variablePairs && typeof(variablePairs) == 'string') html += ' flashvars="' + variablePairs + '"';
		if (bgVisible && typeof(bgVisible) == 'boolean') html += ' wmode="transparent"';
		else html += ' wmode="opaque"';
		html += ' scale="noscale"';
		html += ' align="middle" play="true" loop="false" quality="high" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		
	} else {
		html += '<object id="' + htmlAnchor + '" name="' + htmlAnchor + '" width="' + width + '" height="' + height + '"';
		html += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">';
		html += '	<param name="movie" value="' + fileName + '" />';
		html += '	<param name="bgcolor" value="' + bgColor + '" />';
		if (variablePairs && typeof(variablePairs) == 'string') html += '	<param name="flashvars" value="' + variablePairs + '" />';
		if (bgVisible && typeof(bgVisible) == 'boolean') html += '	<param name="wmode" value="transparent" />';
		else html += '	<param name="wmode" value="opaque" />'; 
		html += '	<param name="quality" value="high" />';
		html += '	<param name="scale" value="noscale" />';
		html += '	<param name = "allowScriptAccess" value = "always" />';
		html += '</object>';
	}
	node.innerHTML = html;
	//*
	//
	// ########################################################### Prepares The Flash Object FSCommand  #######################################################
	var Obj = document.getElementById(htmlAnchor);
	// ########################################################### FSCommand Example  #########################################################################
	//*
	if (!window.document.FlashObjects) window.document.FlashObjects = new Array();
	window.document.FlashObjects[node.id] = new Object();
	window.document.FlashObjects[node.id].Obj = Obj;
	window.document.FlashObjects[node.id].Obj.ID = node.id;
	window.document.FlashObjects[node.id].Obj.KeepSize = KeepSize;
	if (KeepSize){
		window.document.FlashObjects[node.id].Obj.onResize = function (){
			if (this.id == "MainFlashObj") window.Trace("Resize Preparation!", "DEBUG");
			window.clearTimeout(this.timer);
			this.width = this.height = "100%";
			this.timer = window.setTimeout("BackToFlash('" + this.ID + "')", 10);
		}
	}
	this.timer = window.setTimeout("WaitForFlash('" + node.id + "', '" + KeepSize + "')", 100);
	//*/
}

function WaitForFlash(ID, KeepSize){
	window.clearTimeout(window.document.FlashObjects[ID].Obj.timer);
	if (typeof(window.document.FlashObjects[ID].Obj.Go) != "function") {
		window.document.FlashObjects[ID].Obj.timer = window.setTimeout('WaitForFlash("' + ID + '", "' + KeepSize + '")', 100);
		//if (ID == "MainFlash") alert("Not Ready yet");
		return;
	} else {
		//if (ID == "MainFlash") alert("Here we go....");
		window.document.FlashObjects[ID].Obj.Go();
		if (KeepSize) window.document.FlashObjects[ID].Obj.onResize();
	}
}


//*
function BackToFlash(ID){
	if (window.document.FlashObjects[ID].Obj == "MainFlashObj") window.Trace("Resize Calling Flash!", "DEBUG");
	window.clearTimeout(window.document.FlashObjects[ID].Obj.timer)
	window.document.FlashObjects[ID].Obj.Resize(ID);
}

function ResizeFlash(Who, Width, Height){
	if (Who == "MainFlash") window.Trace("Resize Finished!", "DEBUG");
	window.document.FlashObjects[Who].Obj.width = Width;
	window.document.FlashObjects[Who].Obj.height = Height;
	if (Who == "MainFlash") Trace(Width + ", " + Height, "DEBUG");
}

function CheckSizes(){
	window.Trace("Resize strated!", "DEBUG");
	for (var i in window.document.FlashObjects) {
		if (window.document.FlashObjects[i].Obj.KeepSize) window.document.FlashObjects[i].Obj.onResize();
	}
}

function TranslateArgs(Args){
	var Args = Args.split("&");
	var Propertys = new Array();
	for (var i in Args){
		var property = Args[i].split("=");
		Propertys[property[0]] = property[1];
	}
	//
	return Propertys;
}
//*/

