var current_url=null;
var current_title=null;
var current_description=null;

function menuFlash(sel)
{
	if(sel)
	{
		if(sel>0 && sel<20) insertFlash("../menu.swf?init_selected="+sel, 145, 694, "Main menu", 0);
		else insertFlash("../menu.swf?brand_code="+sel, 145, 694, "Main menu", 0);
	}
	else insertFlash("menu.swf", 145, 694, "Main menu", 0);
}

function insertFlash(url, width, height, alt_text, is_transparent, object_id)
{
	document.write('<object ');
	if(object_id) document.write('id="'+object_id+'" ');
	document.writeln('classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+width+'" height="'+height+'" alt="'+alt_text+'">');
	document.writeln('<param name=movie value="'+url+'"');
	document.writeln('<param name=quality value=high>');
	if(is_transparent>0) document.writeln('<param name="wmode" value="transparent">');
	document.write('<embed src="'+url+'" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" ');
	if(is_transparent>0) document.write('wmode="transparent" ');
	document.writeln('alt="'+alt_text+'"></embed>');
	document.writeln('</object>');
}

function closer_view(url, title, desc, is_root)
{
	current_url=url;
	current_description=desc;
	current_title=title;
	viewer_url='../closer_view.html';
	if(is_root) viewer_url='closer_view.html';
	var obj=window.open(viewer_url, 'viewer', 'width=300,height=300,left=200,top=200,status=no,scrollbars=no,resizable=yes,location=no,menubar=no,toolbar=no');

	if(obj==null || typeof(obj)=="undefined")
	{
		alert("Please disable pop-up blocker feature of your browser.");
	}
}

function clip_view(url, title, width, height, is_root)
{
	current_url=url;
	current_title=title;
	current_width=width;
	current_height=height;
	viewer_url='../view_clip.html';
	if(is_root) viewer_url='view_clip.html';
	var obj=window.open(viewer_url, 'viewer', 'width=300,height=300,left=200,top=200,status=no,scrollbars=no,resizable=yes,location=no,menubar=no,toolbar=no');

	if(obj==null || typeof(obj)=="undefined")
	{
		alert("Please disable pop-up blocker feature of your browser.");
	}
}

function floorplan_view(url, title, desc)
{
	current_url=url;
	current_description=desc;
	current_title=title;
	var obj=window.open('../floorplan_view.html', 'viewer', 'width=300,height=300,left=200,top=200,status=no,scrollbars=no,resizable=yes,location=no,menubar=no,toolbar=no');

	if(obj==null || typeof(obj)=="undefined")
	{
		alert("Please disable pop-up blocker feature of your browser.");
	}
}

function news_view(url)
{
	var obj=window.open(url, 'viewer', 'width=500,height=350,left=125,top=195,status=no,scrollbars=yes,resizable=yes,location=no,menubar=no,toolbar=no');

	if(obj==null || typeof(obj)=="undefined")
	{
		alert("Please disable pop-up blocker feature of your browser.");
	}
}

function getDesc()
{
	if(current_description) return current_description;
	else return "";
	current_description=null;
}

function getTitle()
{
	if(current_title) return current_title;
	else return "";
	current_title=null;
}

function getImageUrl()
{
	if(current_url) return current_url;
	else return "";
	current_url=null;
}

function getWidth()
{
	if(current_width) return current_width;
	else return 0;
	current_width=null;
}

function getHeight()
{
	if(current_height) return current_height;
	else return 0;
	current_height=null;
}

var is_selected=false;
var timer_id;
var selected_n;
var default_caption="<span>(point to a numbered circle to see the description)</span>";

function stop_timer()
{
	if(is_selected) { clearTimeout(timer_id); is_selected=false; }
}

function print_column(n)
{
	var start, stop;
	if(n<1) start=0; else start=n_col[n-1];
	if(n>n_col.length-1) stop=features.length; else stop=n_col[n];
	document.write("<ol start="+(start+1)+">");
	for(var i=start; i<stop; i++) document.write("<li id='"+"fli"+i+"'>"+features[i]+"</li>");
	document.write("</ol>");
}

function sel(obj)
{
	del2();
	try
	{
		var n=obj.id-1;
		document.getElementById('fli'+n).className="selected";
		document.getElementById('caption').innerHTML=(n+1)+". "+features[n];
		n_selected=n;
	}
	catch(e) {}
}

function del(obj)
{
	stop_timer();
	is_selected=true;
	timer_id=setTimeout("del2()", 1500);
}

function del2()
{
	if(is_selected)
	{
		stop_timer();
		try
		{
			document.getElementById('fli'+n_selected).className="";
			document.getElementById('caption').innerHTML=default_caption;
		}
		catch(e) {}
	}
}

function set_alts()
{
	for(var i=0; i<features.length; i++) document.getElementById(i+1).alt=features[i];
}

var current_code=null;

function getBrandCode()
{
	if(current_code) return current_code;
	else return "";
	current_code=null;
}

function dealerLocator(code, is_root)
{
	current_code=code;
	var url='dealer_locator.html';
	if(is_root!=1) url='../'+url;

	var obj=null;

	obj=window.open(url, '_blank', 'width=700,height=570,left=50,top=10,status=no,scrollbars=yes,resizable=yes,location=no,menubar=no,toolbar=yes');

	if(obj==null || typeof(obj)=="undefined")
	{
		alert("Please disable pop-up blocker feature of your browser.");
	}
}

var dl_timer_id=null;
var dl_code=null;
var dl_is_root=null;

function executeDDL()
{
	clearTimeout(dl_timer_id);
	dealerLocator(dl_code, dl_is_root);
}

function delayedDL(code, is_root)
{
	dl_code=code;
	dl_is_root=is_root;
	dl_timer_id=setTimeout("executeDDL()", 50);
}

function validateDL()
{
  var tZip = document.forms['locator'].elements['zip'].value;
 var tLoc = document.forms['locator'].elements['location'].options[document.forms['locator'].elements['location'].selectedIndex].value.toUpperCase();

 if((tZip.length == 7)&&(tZip.indexOf(" ") == 3)&&(tLoc != 'CANADA')) {
  var q = 0;
  for (i = 0; i < tZip.length; i++) {
   if (tZip.substring(i,(i+1)) == ' ') {
     q = q + 1;
   }
  }
  if(q == 1) {
   alert('It appears that you have entered a Canadian Postal code,\nbut you have not selected Canada as the country.\nCorrect data and submit again, please.');
   return false;
  }
 }

 if(tLoc == 'USA') {
  if(tZip.length < 5) {
   alert('ZIP field was filled incorrectly.\nYou should enter 5 digits.\nCorrect data and submit again, please.');
   document.forms['locator'].elements['zip'].select();
   return false;
  }
  if(tZip.length > 5) {
   document.forms['locator'].elements['zip'].value = tZip.substring(0,5);
   alert('ZIP field was filled incorrectly.\nThe data was truncated to 5 digits.\nVerify data and submit again, please.');
   document.forms['locator'].elements['zip'].select();
   return false;
  }
  if(tZip.length == 5) {
   if(!isNumber(tZip)){
    alert('ZIP field was filled incorrectly.\nYou should not use letters in a USA ZIP code.\nVerify data and submit again, please.');
    document.forms['locator'].elements['zip'].select();
    return false;
   }
  }
 }

	if(tLoc == 'CANADA')
	{
		reCanZip=/^[^\d\s]\d[^\d\s] \d[^\d\s]\d$/;
		result=reCanZip.test(tZip);
		if(!result)
		{
			alert('Postal code field was filled incorrectly.\nYou should enter code in form \"ANA NAN\"\n(where A is alpha character and N is numeric character)\nfor a Canadian Postal code.\nCorrect data and submit again, please.');
			document.forms['locator'].elements['zip'].select();
		}
		return result;
	}

 return true;
}

function select_tab(object)
{
	for(var i=1; i<9; i++)
	{
		try {	document.getElementById('tab'+i).className=""; }
		catch(e) {}
	}
	object.parentNode.className="selected";
	object.blur();
	document.all.specs.src=object.href;
}

function tab_hover(object)
{
	if(object.className!="selected") object.className="hover";
}

function tab_unhover(object)
{
	if(object.className=="hover") object.className="";
}

function magazine_view(url)
{
	var obj=window.open(url, 'viewer', 'width=700,height=570,left=50,top=10,status=yes,scrollbars=yes,resizable=yes,location=yes,menubar=yes,toolbar=yes');

	if(obj==null || typeof(obj)=="undefined")
	{
		alert("Please disable pop-up blocker feature of your browser.");
	}
}
