var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

function getCookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function readCookiesToFlash(){
  var ADSKVISCNTRY = getCookie("ADSKVISCNTRY");
  var ADSKVISINDUSSEG = getCookie("ADSKVISINDUSSEG");
  var ADSKVISMKT = getCookie("ADSKVISMKT");
  var ADSKVISZIP = getCookie("ADSKVISZIP");
  var ADSKVISBUS = getCookie("ADSKVISBUS");
  
  var cookieVars =  "ADSKVISCNTRY=" + ADSKVISCNTRY + "&ADSKVISINDUSSEG=" + ADSKVISINDUSSEG + "&ADSKVISMKT=" + ADSKVISMKT + "&ADSKVISZIP=" + ADSKVISZIP + "&ADSKVISBUS=" + ADSKVISBUS;
  var currentVars;
  var flashVars;
  var movieSrc;
  var movieH = document.getElementById("adsk91-full_width_banner").getElementsByTagName('object')[0].height;
  var movieW = document.getElementById("adsk91-full_width_banner").getElementsByTagName('object')[0].width;
  var found = 0;

  for (i = 0; i < 6; i++){
	if(found == 2) break;
	else if(document.getElementById("adsk91-full_width_banner").getElementsByTagName('param')[i].name == "FlashVars"){
		var currentVars = document.getElementById("adsk91-full_width_banner").getElementsByTagName('param')[i].value;
		found++;
	}
	else if(document.getElementsByTagName('param')[i].name == "MOVIE"){
		var movieSrc = document.getElementById("adsk91-full_width_banner").getElementsByTagName('param')[i].value
		found++;
	}
  }

  flashVars = currentVars + "&" + cookieVars;
  flashHTML(movieSrc,movieW,movieH,flashVars,null,"",document.getElementById("adsk91-full_width_banner"));
}

function flashHTML( path, width, height, vars, quality, className , target ) {
	
	var theHTML = "";
	
    function escapeValue( value ) {
        if( typeof( value ) != "string" ) {
            return value;
        }
        var str = value.replace( /"/g, "&quot;" );
        str = str.replace( /</g, "&lt;" );

        return str;
    }

    function renderAttribute( name, value ) {
        if( ! value ) {
            return;
        }
        theHTML = theHTML + " ";
        theHTML = theHTML + name;
        theHTML = theHTML + "=\"";
        theHTML = theHTML + escapeValue( value );
        theHTML = theHTML + "\"";
    }

    function renderParam( name, value ) {
        if( ! value ) {
            return;
        }
        theHTML = theHTML + "<param";
        renderAttribute( "name", name );
        renderAttribute( "value", value );
        theHTML = theHTML + "/>";
    }

    theHTML = theHTML + "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"";
    renderAttribute( "width", width );
    renderAttribute( "height", height );
    renderAttribute( "class", className );
    theHTML = theHTML + " codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\">";

    renderParam( "MOVIE", path );
    renderParam( "QUALITY", quality );
    theHTML = theHTML + "<param name=\"menu\" value=\"false\"/>";
    theHTML = theHTML + "<param name=\"allowscriptaccess\" value=\"always\"/>";
    theHTML = theHTML + "<param name=\"wmode\" value=\"transparent\"/>";
    theHTML = theHTML + "<param name=\"SeamlessTabbing\" value=\"true\"/>";
    renderParam( "FlashVars", vars );

    theHTML = theHTML + "<embed type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"";
    renderAttribute( "src", path );
    renderAttribute( "quality", quality );
    renderAttribute( "flashvars", vars );
    renderAttribute( "width", width );
    renderAttribute( "height", height );
    renderAttribute( "allowscriptaccess", "always" );
    renderAttribute( "wmode", "transparent" );
    theHTML = theHTML + ">";

    theHTML = theHTML + "</embed>";

    theHTML = theHTML + "</object>";
	
	target.innerHTML = theHTML;

}