var browser = "NA";

function setDebug(debugVal){
	if(debug != debugVal){
		debug = debugVal;
		document.all.vabt.innerHTML = getHtmlFlash(swfversion);
	}
}

function getInfo(){
	if(debug == 0) return;
	//alert("INFO");
}
getInfo();


function getSPTQS(){
	var result = "";
	for(i=0;i<SPTorder.length;i++){
		j = i + 2;
		result += "&" + SPTorder[i] + "=" + j;
	}
	return result;
}

function getSPT(tracerVar){
	var result = "";
	for(i=0;i<SPTorder.length;i++){
		if(tracerVar == SPTorder[i]){
			j = i + 2;
			result += j;
			break;
		}
	}
	return result;
}

function sendStats(url){
	//alert("SENDSTATS="+url);
	if(track == 1 && url != "") document.all.SPT.src = url;
}

function getSPTHtml(){
	var result = "";
	if(track == 1) result += "<img name=SPT src='" + defaultTrack + "' width=0 height=0 border=0>";
	return result;
}

function getFlashPath(swfversion,version,url){
	if(swfversion >= swfversionmin){
		path = url_download + vabt_path_swf + "?url_download=" + url_download + "&width=" + width + "&height=" + height + "&startbanner=" + startbanner_path_swf + "&endbanner=" + endbanner_path_swf + "&video_hd=" + video_hd_path_swf + "&video_md=" + video_md_path_swf + "&video_bd=" + video_bd_path_swf + "&url_tracer=" + escape(url_tracer) + getSPTQS() + "&sound_state=" + sound_state + "&debug=" + debug + "&url=" + url_redirect;
	}
	return path;
}

function displayFormat(){
	var winl = screen.height;
	var wint = screen.width;
	var topl = (winl - height)/2;
	var topt = (wint - width)/2;
	var feat = 'height=' + height + ",width=" + width + ",top=" + topl + ",left=" + topt;

	if(debug == 1){
		titre += " (DEBUG FLASH " + swfversion + ")";
		alert(titre);
	}
	if(swfversion >= swfversionmin){
		
		if (navigator.plugins != null && navigator.plugins.length > 0){ 	
			if(launchwin == 1){
				popup = window.open('','popup',feat);
				popup.document.write(getPopupHtml(getHtmlFlash(swfversion)));
				popup.document.title = titre;	
				popup.document.location.href=popup.document.location.href;
			}else{
				document.write("<div id=vabt>" + getHtmlFlash(swfversion) + "<\/div>" + getSPTHtml());
			}
		}else{
			if(launchwin == 1){
				popup = window.open('','popup',feat);
				popup.document.write(getPopupHtml(getHtmlFlash(swfversion)));
				popup.document.title = titre;
			}else{
				document.write("<div id=vabt>" + getHtmlFlash(swfversion) + "<\/div>" + getSPTHtml());
			}
		}
	}else{
		if(launchwin == 1){
			popup = window.open('','popup',feat);
			popup.document.write(getPopupHtml(getHtmlGif()));
			popup.document.title = titre;
			//popup.document.location.href=popup.document.location.href;
		}else{
			document.write("<div id=vabt>" + getHtmlGif() + "<\/div>");
		}
	}
	
}
function closewin(){
	this.close();
}

function getHtmlFlash(version){
	var flashswf = getFlashPath(swfversion,version,url_redirect);
	flashswf += "&rnd="+1000*Math.random();
	var result = "";
	result += "<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'";
	result += " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+swfversionmin+",0,0,0'";
	result += " WIDTH='" + width +"' HEIGHT='" + height +"' id='format' ALIGN=''>";
	result += " <PARAM NAME=movie VALUE='" + flashswf +"'> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#"+bgcolor+"> <EMBED src='" + flashswf +"' quality=high bgcolor=#"+bgcolor+"  WIDTH='" + width +"' HEIGHT='" + height +"' NAME='format' ALIGN=''";
	result += " swLiveConnect='true' TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'><\/EMBED>";
	result += "<\/OBJECT>";
	return result;
}

function getHtmlGif(){
	var result = "";
	result += "<a href='" + unescape(url_redirect) + "' target='_blank'><img name='format' src='" + url_download + backup_gif + "' border='0' width='"+width+"' height='"+height+"'></a>";
	result += "<img src='" + unescape(url_tracer) + getSPT('gif') + "' width=0 height=0>";
	return result;
}

function getPopupHtml(innerHtml){
	var result = "";
	result += "<html>";
	result += "<head>";
	result += "	<title>"+titre+"</title>";
	result += "</head>";
	result += "<body bgcolor=#000000 marginwidth=0 marginheight=0 topmargin=0 leftmargin=0>";
	result += "<table border=0 width='100%' height='100%'>";
	result += "<tr><td align=center>"+innerHtml+"</td></tr>";
	result += "</table>";
	result += "<\/body>";
	result += "<\/html>";
	return result;
}

function getFlashVersion() {

	var agent = navigator.userAgent.toLowerCase(); 
	
   // NS3 needs flashVersion to be a local variable
   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
   	  browser = "NS";
      flashVersion = 0;
   }
   
	// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		browser = "NS";
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') { 
			if (flashPlugin.description.indexOf('9.') != -1) flashVersion = 9;
			else if (flashPlugin.description.indexOf('8.') != -1) flashVersion = 8;
			else if (flashPlugin.description.indexOf('7.') != -1) flashVersion = 7;
			else if (flashPlugin.description.indexOf('6.') != -1) flashVersion = 6;
			else if (flashPlugin.description.indexOf('5.') != -1) flashVersion = 5;
			else if (flashPlugin.description.indexOf('4.') != -1) flashVersion = 4;
			else if (flashPlugin.description.indexOf('3.') != -1) flashVersion = 3;
		}else{
			flashVersion = -1;
		}
	}

	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
		browser = "IE";
		document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('dim obFlash \n');
		document.write('set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.8") \n');
		document.write('if IsObject(obFlash) then \n');
		document.write('flashVersion = 8 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.7") end if \n');
		document.write('if flashVersion < 8 and IsObject(obFlash) then \n');
		document.write('flashVersion = 7 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.6") end if \n');
		document.write('if flashVersion < 7 and IsObject(obFlash) then \n');
		document.write('flashVersion = 6 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.5") end if \n');
		document.write('if flashVersion < 6 and IsObject(obFlash) then \n');
		document.write('flashVersion = 5 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.4") end if \n');
		document.write('if flashVersion < 5 and IsObject(obFlash) then \n');
		document.write('flashVersion = 4 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.3") end if \n');
		document.write('if flashVersion < 4 and IsObject(obFlash) then \n');
		document.write('flashVersion = 3 \n');
		document.write('end if');
		document.write('</scr' + 'ipt\> \n');
  }
		
	// WebTV 2.5 supports flash 3
	else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

	// older WebTV supports flash 2
	else if (agent.indexOf("webtv") != -1) flashVersion = 2;

	// Can't detect in all other cases
	else {
		flashVersion = -1;
	}
	return flashVersion;
}

swfversion = getFlashVersion();
//window.onload = displayFormat();
displayFormat();
