//preload roundel on all pages 
var img_roundel= new Image(); img_roundel.src = "/BMW2003/Images/TopNav/roundel.gif";
// For IE browsers
if (document.all && !document.getElementById)
{
	document.getElementById = function(id) 
	{
        return document.all[id];
    }
}
function imgChange(layer,imgName,imgObj) {
	if (document.images)
   {
		if (document.layers && layer!=null) 
      {
         eval('document.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src')
      }
		else
      {
         document.images[imgName].src = eval(imgObj+".src")
      }
	}
}
function PageLocation(LocationOfPage) { 
	window.scrollTo(0, 0);
}
function doPassVar(num) {
	var topFlashId;
	var topFlash;

	if (navigator.userAgent.indexOf("MSIE") != -1) // check for IE
	{
		topFlashId = "topFlash"; //IE OBJECT Id
	}
	else
	{
		topFlashId = "topFlash_Embed"; // Other browser EMBED Id
	}

	topFlash = document.getElementById(topFlashId);
	topFlash.SetVariable("jsInputNum", num);
} 

function findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
 
function showHide() { 
  var i,p,v,obj,args=showHide.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) {v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function changeClass(i,c) {
	if (document.getElementById) {
	document.getElementById(i).style.color = "#" + c;
	} else {
	document.all[i].style.color = "#" + c;	
	}
}

function changeStyle(i,c) {
	changeTo = c;
	if (document.getElementById) {
	document.getElementById(i).className = changeTo;
	} else {
	document.all[i].className = changeTo;	
	}
}

function highlightIt(i,x,y) {
	if (document.getElementById) {
	document.getElementById(i).style.top = x + "px";
	document.getElementById(i).style.left = y + "px";
	} else {
	document.all[i].style.top = x + "px";
	document.all[i].style.left = y + "px";	
	}
}

function writeText(i,n) {
	if (document.getElementById) {
	document.getElementById(i).innerHTML = '<span class="subheadblack">' + n + '</span>';
	} else {
	document.all[i].innerHTML = '<span class="subheadblack">' + n + '</span>';
	}
}

function colorHighlightWrite (i,x,y,c,n) {
	did = i;
	dxv = x;
	dyv = y;
	dcv = c;
	dnv = n;		
	document.hform.cid.value = did;
	document.hform.cxv.value = dxv;
	document.hform.cyv.value = dyv;
	document.hform.ccv.value = dcv;
	document.hform.cnv.value = dnv;
}

function fieldsDefault () {
			
	did = 'highlight2';
	dxv = '466';
	dyv = '181';
	dcv = 'colorname';
	dnv = 'Carbon Metallic Black';		
			
	document.hform.cid.value = did;
	document.hform.cxv.value = dxv;
	document.hform.cyv.value = dyv;
	document.hform.ccv.value = dcv;
	document.hform.cnv.value = dnv;
		
	
}


function ColorDefault() {
		
	did = document.hform.cid.value;
	dxv = document.hform.cxv.value;
	dyv = document.hform.cyv.value;
	dcv = document.hform.ccv.value;
	dnv = document.hform.cnv.value;
	
	//alert (dnv);
	
	document.getElementById(dcv).innerHTML = '<span class="subheadblack">' + dnv + '</span>';
	document.getElementById(did).style.top = dxv + "px";
	document.getElementById(did).style.left = dyv + "px";
	
	}
	
function imageSwap(el,state) {
	el.src = eval(el.id + "_" + state).src;
}

function openNewWindow(url,n,w,h) { 
	   var height=h, width=w;
	    var str = "height=" + height + ",innerHeight=" + height; 
	    str += ",width=" + width + ",innerWidth=" + width + ",location=no,toolbar=no,directories=no,menubar=no,status=no,resizable=no,scrollbars=yes"; 
	    if (window.screen) { 
	        var ah = screen.availHeight - 30; 
	        var aw = screen.availWidth - 10; 
	 
	        var xc = (aw - width) / 2; 
	        var yc = (ah - height) / 2; 
	    
	        str += ",left=" + xc + ",screenX=" + xc; 
	        str += ",top=" + yc + ",screenY=" + yc; 
		} 
    return window.open(url, n, str); 	
} 

//compare 
function toggleElement(eName)
    {
      if (cbGetElement(eName).style.visibility == 'visible') 
        cbGetElement(eName).style.visibility = 'hidden'; 
      else
        cbGetElement(eName).style.visibility = 'visible'  
    }

// Cross-browser get element 
function cbGetElement(eName)
	{
    if (document.all)
    return document.all[eName]; 
    else
    return document.getElementById(eName); 
}

//printable view of the panel 
function printpanel(panelid)
{
	var url = '/bmw2003/controls/printpanel.aspx';
	var panelpop = url + "?panel=" + panelid; 
	var popwidth = 622;
	var popheight = 792;
	var winleft = (screen.width - popwidth) / 2;
	var wintop = (screen.height - popheight) / 2;
	window.open(panelpop, 'printdetails', 'height=' + popheight + ',width=' + popwidth + ',top=' + wintop + ',left=' + winleft + ',toolbar=no,scrollbars=yes,status=no,location=no,menubar=no,');
}

//popup code for fma 
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1; 
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) { 
	document.write('<script language=\"VBScript\" type=\"text/VBScript\">\n'); 
	document.write('On Error Resume Next\n'); 
	document.write('Sub fma_FSCommand(ByVal command, ByVal args)\n'); 
	document.write(' Call fma_DoFSCommand(command, args)\n'); 
	document.write('End Sub\n'); 
	document.write('</script\>\n'); 
}

// Handle all the FSCommand messages in a Flash movie. 
function fma_DoFSCommand(command, args) { 
var fmaObj = isInternetExplorer ? document.all.fma : document.fma; 
 { 
	if(command=="openWindow") 
	{ 
	openNewWindowFromFS(args); 
	} 
 } 
} 
// open window from Flash fsCommand in IE only
function openNewWindowFromFS(args)
{
    if(isInternetExplorer)
    {
        var args_arr = splitNewWindowArgs(args);
        var newWindow = openNewWindowNoScroll(args_arr[0],args_arr[1],args_arr[2],args_arr[3]);
    }
}
// open window from Flash getURL for all non IE browsers
function openNewWindowFromGetURL(url,n,w,h)
{
    if(!isInternetExplorer)
    {
        var newWindow = openNewWindowNoScroll(url,n,w,h);
    }
}//split comma delimited args for pop up and remove single quotes if exist at beginning and end 
function splitNewWindowArgs(args) 
{ 
	var args_arr = args.split(","); 
	for (var i = 0; i < args_arr.length ; i++) 
	{ 
		args_arr[i] = args_arr[i].replace(/^'/, ""); 
		args_arr[i] = args_arr[i].replace(/'$/, ""); 
	} 
	return args_arr; 
} 
//open new window without scroll bar. 
function openNewWindowNoScroll(url,n,w,h) { 
    var height=h, width=w;
    var str = "height=" + height + ",innerHeight=" + height; 
    str += ",width=" + width + ",innerWidth=" + width + ",location=no,toolbar=no,directories=no,menubar=no,status=no,resizable=no,scrollbars=no"; 
                if (window.screen) { 
                    var ah = screen.availHeight - 30; 
                    var aw = screen.availWidth - 10;

                    var xc = (aw - width) / 2; 
                    var yc = (ah - height) / 2; 
          
                    str += ",left=" + xc + ",screenX=" + xc; 
                    str += ",top=" + yc + ",screenY=" + yc; 
                        } 
    return window.open(url, n, str);            
}

function fsCommandPrep(flashObjectID)
{
      document.write('<script language=\"javascript\"\>\n');
      document.write('function ' + flashObjectID + '_DoFSCommand(command, args)\n');
      document.write('{\n');
      document.write('    fma_DoFSCommand(command, args);\n');
      document.write('}\n');
      document.write('</script\>\n');

  if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 &&
      navigator.userAgent.indexOf("Windows") != -1 && 
      navigator.userAgent.indexOf("Windows 3.1") == -1) 
    {
      document.write('<script language=\"VBScript\"\>\n');
      document.write('On Error Resume Next\n');
      document.write('Sub ' + flashObjectID + '_FSCommand(ByVal command, ByVal args)\n');
      document.write('	Call ' + flashObjectID + '_DoFSCommand(command, args)\n');
      document.write('End Sub\n');
      document.write('</script\>\n');
    }
}
