var currentSectionName = "SALES, FINANCING & PRICING";

function switchFaq(anchor) {

	var p = anchor.parentNode;

	if (p.className == "active") p.className = "";

	else p.className = "active";

	p = p.nextSibling;

	while (p.nodeType != 1) p = p.nextSibling;

	if (anchor.parentNode.className == "active") p.style.display = "block";

	else p.style.display = "none";

	anchor.blur();

	return false;

}



function rollOver(obj, flag){

	if (obj.className.indexOf("active") == -1){

			if (flag){

				  obj.className = "over";

			}else

				  obj.className = "";

	}

}



function toggleDisplay(divLayer){

		var layer=document.getElementById(divLayer);

		var hidden = "none";

		var visible = "";

		if(layer.style.display == hidden){

			layer.style.display = visible;

		}else{

			layer.style.display = hidden;

		}

	}


function toggleTT(id){
	var div = id+"C";

	if (document.getElementById(div).style.display!="block" && document.getElementById(div).className!="On"){
		document.getElementById(div).style.display='block';
		document.getElementById(lastImage+"C").style.display='none';
		document.getElementById(div).className='On';
		document.getElementById(lastImage+"C").className='Off';
		offImg(lastImage);
		offImg(id);
		lastImage=id;
	}
}

function onImg(img){
	var image=document.getElementById(img).className= img+"On";
}

function offImg(img){
	var image=document.getElementById(img);
	var div=img+"C";

	if (document.getElementById(div).style.display!="block" && document.getElementById(div).className!="On"){
		image.className=img+"Off";
	}
}

function preSelect(id){
	document.getElementById(id+"C").style.display='block';
	onImg(id);
	lastImage=id;
}

function swapVisibility(current)
	{

			 if(current == "siteNavC")
			{
			   document.getElementById("siteNavC").className='On';
			   document.getElementById("fCommercialC").className='Off';
			   document.getElementById("fCommercial").className='fCommercialOff';

			}
			else{
				document.getElementById("siteNavC").className='Off';
			   	document.getElementById("fCommercialC").className='On';
				document.getElementById("siteNav").className='siteNavOff';

			}
	}


//show and hide the questions of the selected category in the FAQ tab
function changeItem(domEl)
{
	//each elemet is composed for name + 'information'
	var itemFix = "Information";

	//get the element
	var itemInfo = domEl.id + itemFix;
	var itemTemp = "";

	for(var i=0; i < itemNames.length; i++)
	{
		if(domEl.id == itemNames[i])
		{
			// document.getElementById(itemNames[i]).className = "itemSelected";
			itemTemp = document.getElementById(itemNames[i]).getElementsByTagName('div');
			itemTemp[0].className = "itemSelected";
			currentSectionName = itemTemp[0].innerHTML.toUpperCase();
			manageSubTabsClickTrack("", currentSectionName, "", domEl.id, "", "CategoriesFAQ");
		}
		else
		{
			document.getElementById(itemNames[i]).className = "itemNotSelected";
			itemTemp = document.getElementById(itemNames[i]).getElementsByTagName('div');
			itemTemp[0].className = "itemNotSelected";


		}
		itemTemp = itemNames[i] + itemFix;
		if(itemInfo == itemTemp)
		{
			document.getElementById(itemTemp).className = "itemInformationSelected";
		}
		else
		{
			document.getElementById(itemTemp).className = "itemInformationNotSelected";
		}
	 }
}

//show and hide the questions  answer that the user select
function displayOptionInfo(domEl, category)
{
	var optionFix = "Info";
	var itemOpt = domEl.id;
	var itemOptClass = document.getElementById(itemOpt).className;
	var option = domEl.id + optionFix;
	var optionClass = document.getElementById(option).className;
	var itemTmp = domEl.getElementsByTagName('div');
	manageSubTabsClickTrack("", itemTmp[0].innerHTML, domEl.id, category, "", "QuestionCategoriesFAQ");
	if(optionClass == "optionTextVisible")
	{
		document.getElementById(option).className = "optionTextHidden";
	}
	else
	{
		document.getElementById(option).className = "optionTextVisible";
	}
	if(itemTmp[0].className == "headerItemOption")
	{
		// document.getElementById(itemOpt).className = "headerItemOptionNeg";
		itemTmp[0].className = "headerItemOptionNeg";
	}
	else
	{
		//document.getElementById(itemOpt).className = "headerItemOption";
		itemTmp[0].className = "headerItemOption";
	}
}

//change the images and style for the currect selected tab
function changeTab(domEl)
{
	dir = document.getElementById(domEl).src;
	if(domEl=="FAQ")
	{
		var condition = dir.substring(dir.lastIndexOf("_")+1, dir.lastIndexOf("."));
		if(condition=="over")
		{
			document.getElementById("ContactUs").src="/images/helpcenter/saab_help_tab_Contac_off.gif";
			document.getElementById("Glossary").src="/images/helpcenter/saab_help_tab_Glossary_off.gif";
			document.getElementById(domEl).src="/images/helpcenter/saab_help_tab_FAQ_on.gif";
			document.getElementById("DivFAQ").className="DivSelected";
			document.getElementById("DivGlossary").className="DivNoSelected";
			document.getElementById("DivContactUs").className="DivNoSelected";
			manageSubTabsClickTrack("", "", "", "", "", "VisitFAQ");
		}
	}
	else if (domEl=="ContactUs")
	{
		var condition = dir.substring(dir.lastIndexOf("_")+1, dir.lastIndexOf("."));
		if(condition=="over")
		{
			document.getElementById("FAQ").src="/images/helpcenter/saab_help_tab_FAQ_off.gif";
			document.getElementById("Glossary").src="/images/helpcenter/saab_help_tab_Glossary_off.gif";
			document.getElementById(domEl).src="/images/helpcenter/saab_help_tab_Contac_on.gif";
			document.getElementById("DivContactUs").className="DivSelected";
			document.getElementById("DivGlossary").className="DivNoSelected";
			document.getElementById("DivFAQ").className="DivNoSelected";
			manageSubTabsClickTrack("", "", "", "", "", "VisitContactUs");
		}
	}
	else if(domEl=="Glossary")
	{
		var condition = dir.substring(dir.lastIndexOf("_")+1, dir.lastIndexOf("."));
		if(condition=="over")
		{
			document.getElementById("FAQ").src="/images/helpcenter/saab_help_tab_FAQ_off.gif";
			document.getElementById(domEl).src="/images/helpcenter/saab_help_tab_Glossary_on.gif";
			document.getElementById("ContactUs").src="/images/helpcenter/saab_help_tab_Contac_off.gif";
			document.getElementById("DivContactUs").className="DivNoSelected";
			document.getElementById("DivGlossary").className="DivSelected";
			document.getElementById("DivFAQ").className="DivNoSelected";
			ViewNumber();
			manageSubTabsClickTrack("", "", "", "", "", "VisitGlossary");
		}
	}
}

//change the style on mouse over of the tabs
function mouseoverchange(domEl)
{
	dir = document.getElementById(domEl).src;
	if(domEl=="FAQ")
	{
		var condition = dir.substring(dir.lastIndexOf("_")+1, dir.lastIndexOf("."));
		if(condition=="off")
			document.getElementById(domEl).src="/images/helpcenter/saab_help_tab_FAQ_over.gif";
	}
	else if (domEl=="ContactUs")
	{
		var condition = dir.substring(dir.lastIndexOf("_")+1, dir.lastIndexOf("."));
		if(condition=="off")
			document.getElementById(domEl).src="/images/helpcenter/saab_help_tab_Contac_over.gif";
	}
	else if(domEl=="Glossary")
	{
		var condition = dir.substring(dir.lastIndexOf("_")+1, dir.lastIndexOf("."));
		if(condition=="off")
			document.getElementById(domEl).src="/images/helpcenter/saab_help_tab_Glossary_over.gif";
	}
}

//change the style on mouse out of the tabs
function mouseoutchange(domEl)
{
	dir = document.getElementById(domEl).src;
	if(domEl=="FAQ")
	{
		var condition = dir.substring(dir.lastIndexOf("_")+1, dir.lastIndexOf("."));
		if(condition=="over")
			document.getElementById(domEl).src="/images/helpcenter/saab_help_tab_FAQ_off.gif";
	}
	else if (domEl=="ContactUs")
	{
		var condition = dir.substring(dir.lastIndexOf("_")+1, dir.lastIndexOf("."));
		if(condition=="over")
			document.getElementById(domEl).src="/images/helpcenter/saab_help_tab_Contac_off.gif";
	}
	else if(domEl=="Glossary")
	{
		var condition = dir.substring(dir.lastIndexOf("_")+1, dir.lastIndexOf("."));
		if(condition=="over")
			document.getElementById(domEl).src="/images/helpcenter/saab_help_tab_Glossary_off.gif";
	}

	return false;
}


//show every number that has some term in the glossary
function ViewNumber()
{
	var number = 0;
	var boolean = false;
	while (number <= 9)
	{
		var int = 1;

		//go for all numbers and see if there is some term available for that number
		while(int <= 29)
		{
			//get the element
			var letters = document.getElementById("Block_"+int).innerHTML;

			//if it is equal to the current number, show t otherwise hide it
			if(number == letters)
			{
				boolean = true;
				break;
			}
			int++;
		}
		//Show or hidde the number
		if(boolean == true)
			document.getElementById("letters_" + number).className= "Exist";
		else
			document.getElementById("letters_" + number).className= "NoExist";
		number++;
		boolean = false;
	}
}

//remove the blank spaces
String.prototype.trim = function(){
	return this.replace(/^\s+|\s+$/g,'')
}

//search for a term in the glossary
//param word ==
function WordSearch(word, int)
{
	word= word.trim();
	if(word != " ")
	{
		word= word.toLowerCase();
		var bool= false;
		manageSubTabsClickTrack("", "word", "", "", "", "TermSearchGlossary");

		//29 is the number of the elements in the glossary
		//if a element is add it or delete it, this number must be changed
		while(int <= 29)
		{
			selectedElement  = document.getElementById("Title"+ int);
			var strings = selectedElement.innerHTML;
			strings = strings.toLowerCase();
			var Text = strings.search(word);

			//if the term is found
			if(Text != -1)
			{
				document.getElementById('int').value = int;
				selectedElement.innerHTML =  selectedElement.innerHTML + " " + "<label onClick='return nextMatch()' class='LabelLink' >Next Match</label>";
				location.href = "#" + document.getElementById("Title"+ int).id;
				bool = true;
				break;
			}
			Text ="";
			int++;
		}

		//if the term is not found a msg error is displayed
		if(bool == false)
		{
			alert("Your search returned no results.  Please modify your request and search again");
		}
	}
	return false;
}

//Remove the label "Next Match"
function DeleteLabel(int)
{
	var text = document.getElementById("Title"+ int).innerHTML.toLowerCase();;
	text = text.split("<label");
	document.getElementById("Title"+ int).innerHTML = text[0];
}

//each time the user click Glossary search, this function removes the "next match" word if exist
function FirstSearch(word, int)
{
	DeleteLabel(int);
	//set the word of the item
	document.getElementById('int').value = 1;
	WordSearch(word, 1);
	return false;
}

//when the user clicks on the "next match", the next match word is removed and the next word is selected
function nextMatch()
{
	var int = document.getElementById('int').value;
	DeleteLabel(int);
	int++;
	WordSearch(document.getElementById('TextSearch').value, int);
	return false;
}


//send the imformation to the omniture tag
function manageSubTabsClickTrack(letter, term, QuestionId, categoryId, brandId, Event)
{
	s_lnk=false;
	s_linkType="";
	s_prop1 = "";
	s_prop2 = "";
	s_prop3 = "";
	s_prop4 = "";
	s_prop6 = "";
	s_prop7 = "";
	s_prop8 = "";
	s_prop9 = "";
	s_prop10 = "";
	s_prop11 = "";
	s_prop12 = "";
	s_prop13 = "";
	s_prop14 = "";
	s_prop15 = "";
	s_prop16 = "";
	s_prop17 = "";
	s_prop18 = "";
	s_prop19 = "";
	s_prop20 = "";
	s_prop21 = "";
	s_prop22 = "";
	s_prop23 = "";
	s_prop24 = "";
	s_prop25 = "";
	s_prop26 = "";
	s_prop27 = "";
	s_prop28 = "";
	s_prop29 = "";
	s_prop30 = "";
	if (Event == "CategoriesFAQ" )
	{
		getPageOmniture("HELPCENTERFAQ2");
  		    s_prop14 = term.trim();
			if (s_prop14.indexOf("&AMP;") != -1){
				s_prop14 = s_prop14.replace('&AMP;', "&");
			}
			s_prop15 = "FAQ | " + s_prop14;
			s_prop16 = "HELP CENTER | " + s_prop15;
			s_prop17 = "DIVISIONAL | " + s_prop16;
		clickTrack("HELPCENTERFAQ2");
		// alert('Click on CategoriesFAQS -> ' + term.trim());
	}
	else if (Event == "QuestionCategoriesFAQ" )
	{
		// alert('Click on CategoriesFAQS -> ' + term.trim());
			getPageOmniture("HELPCENTERFAQ3");
  		    s_prop14 = currentSectionName + " | " + term.trim().toUpperCase();
			if (s_prop14.indexOf("&AMP;") != -1){
				s_prop14 = s_prop14.replace('&AMP;', "&");
			}
			s_prop15 = "FAQ | " + s_prop14;
			s_prop16 = "HELP CENTER | " + s_prop15;
			s_prop17 = "DIVISIONAL | " + s_prop16;
		clickTrack("HELPCENTERFAQ3");
	}
	else if (Event == "TermGlossary" )
	{
		getPageOmniture("HELPCENTERGLOSSARY2");
  	    s_prop21 = "GLOSSARY | " + term.trim().toUpperCase();
		clickTrack("HELPCENTERGLOSSARY2");
	}
	else if (Event == "ClickTermGlossary" )
	{
		getPageOmniture("HELPCENTERGLOSSARY3");
		s_prop14 = document.getElementById(categoryId).innerHTML.trim().toUpperCase();
		if (s_prop14.indexOf("&AMP;") != -1){
			s_prop14 = s_prop14.replace('&AMP;', "&");
		}
		s_prop15 = "GLOSSARY | " + s_prop14;
		s_prop16 = "HELP CENTER | " + s_prop15;
		s_prop17 = "DIVISIONAL | " + s_prop16;

		clickTrack("HELPCENTERGLOSSARY3");
	}
	else if (Event == "LetterGlossary" )
	{
		getPageOmniture("HELPCENTERGLOSSARY4");
  		    s_prop14 = letter;
			if (s_prop14.indexOf("&AMP;") != -1){
				s_prop14 = s_prop14.replace('&AMP;', "&");
			}
			s_prop15 = "GLOSSARY | " + s_prop14;
			s_prop16 = "HELP CENTER | " + s_prop15;
			s_prop17 = "DIVISIONAL | " + s_prop16;
		clickTrack("HELPCENTERGLOSSARY4");
	}
	else if (Event == "VisitContactUsEmail" )
	{
		getPageOmniture("HELPCENTERCONTACTUS2");
 		clickTrack("HELPCENTERCONTACTUS2");
	}
	else if (Event == "SubmitContactUsEmail" )
	{
		clickTrack();
	}
	else if (Event == "SubmitZipCodeQT" )
	{
		s_lnk=true;
	    s_linkType="e";
		s_pageName = "";
		s_linkName = "SAAB | HELP CENTER | QUICK TOOLS | DEALOC";
		s_prop5="SAAB | HELP CENTER | QUICK TOOLS | DEALOC";
		s_prop24="EN";
		s_prop25="SAAB";
		s_prop26 = getTimeSystem();
		s_prop27 =  getDateSystem();
		clickTrack("SAAB | HELP CENTER | QUICK TOOLS | DEALOC");
	}
	else if (Event == "AdvanceSearch" )
	{
		s_lnk=true;
	    s_linkType="e";
		s_pageName = "";
		s_linkName = "SAAB | HELP CENTER | QUICK TOOLS | DEALOC ADVANCED";
		s_prop5="SAAB | HELP CENTER | QUICK TOOLS | DEALOC ADVANCED";
		s_prop24="EN";
		s_prop25="SAAB";
		s_prop26 = getTimeSystem();
		s_prop27 =  getDateSystem();
		clickTrack("SAAB | HELP CENTER | QUICK TOOLS | DEALOC ADVANCED");
	}
	else if (Event == "ContactPreferences" )
	{
		s_lnk=true;
	    s_linkType="e";
		s_pageName = "";
		s_linkName = "SAAB | HELP CENTER | QUICK TOOLS | CONTACT PREFERENCES";
		s_prop5="SAAB | HELP CENTER | QUICK TOOLS | CONTACT PREFERENCES";
		s_prop24="EN";
		s_prop25="SAAB";
		s_prop26 = getTimeSystem();
		s_prop27 =  getDateSystem();
		clickTrack("SAAB | HELP CENTER | QUICK TOOLS | CONTACT PREFERENCES");
	}
	else if (Event == "UpdateOwner" )
	{
		s_lnk=true;
	    s_linkType="e";
		s_pageName = "";
		s_linkName = "SAAB | HELP CENTER | QUICK TOOLS | UPDATE OWNER INFO";
		s_prop5="SAAB | HELP CENTER | QUICK TOOLS | UPDATE OWNER INFO";
		s_prop24="EN";
		s_prop25="SAAB";
		s_prop26 = getTimeSystem();
		s_prop27 =  getDateSystem();
		clickTrack("SAAB | HELP CENTER | QUICK TOOLS | UPDATE OWNER INFO");
	}
	else if (Event == "RequestInfo" )
	{
		s_lnk=true;
	    s_linkType="e";
		s_pageName = "";
		s_linkName = "SAAB | HELP CENTER | QUICK TOOLS | REQUEST INFO";
		s_prop5="SAAB | HELP CENTER | QUICK TOOLS | REQUEST INFO";
		s_prop24="EN";
		s_prop25="SAAB";
		s_prop26 = getTimeSystem();
		s_prop27 =  getDateSystem();
		clickTrack("SAAB | HELP CENTER | QUICK TOOLS | REQUEST INFO");
	}
	else if (Event == "EmailUpdate" )
	{
		s_lnk=true;
	    s_linkType="e";
		s_pageName = "";
		s_linkName = "SAAB | HELP CENTER | QUICK TOOLS | EMAIL UPDATES";
		s_prop5="SAAB | HELP CENTER | QUICK TOOLS | EMAIL UPDATES";
		s_prop24="EN";
		s_prop25="SAAB";
		s_prop26 = getTimeSystem();
		s_prop27 =  getDateSystem();
		clickTrack("SAAB | HELP CENTER | QUICK TOOLS | EMAIL UPDATES");
	}
}

function clickTrack(oArg)
{
	void(s_gs(s_account));
}

//take the infoemation of the selected and change the style to be printed

function getInnerHtml(width,height,name, currentDiv)
{
	var contentbody = "";
	content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>SAAB | HELP CENTER | PRINT PREVIEW </title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><link rel="stylesheet" href="/styles/pHelpCenterPrinter.css" /></head><body><div id="headerPrint"><a href="javascript:window.print();" id="print-button-1" class="clvPrint">print</a> <a href="javascript:window.close();" class="clvClose">close</a></div>';

	//if the user want to print the contact us
	if (currentDiv == "DivContactUs"){
		contentbody = document.getElementById("DivContactUs").innerHTML;
	}
	//if the user want to print the FAQ's
	else if (currentDiv == "DivFAQ"){
		//Search the category selected

		for(i=1;i<=8;i++)
		{
			if(document.getElementById("item"+i+"Information").className == "itemInformationSelected")
			{
				contentbody = '';
				contentbody = document.getElementById("item"+i+"Information").innerHTML;
				i=8;
			}
		}
	}
	//if the user want to print the Glossary
	else if (currentDiv == "DivGlossary")
	{
		contentbody = document.getElementById("DivGlossary").innerHTML;		
	}		
	else if (currentDiv == "printview")
	{
		
		contentbody = document.getElementById("printview").innerHTML;
	}
		content +="<link REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"/styles/dealer/newLDResult.css\">";
		content +="<link REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"/styles/dealer/newLDSearch.css\">";
	content = content+contentbody+"</body></html>";
	
	//alert(content);
	PositionedWin(width,height,name,content);

	return false;

}





function PositionedWin(width,height,name,content)

{

	// DEFAULTS //

	var winW = 800, winH = 600;

	var winO = ',scrollbars=1,toolbar=0,location=0,directories=0,status=0,menubar=1,resizable=0';



	//for vertical positioning detect for IE or NN

	if ((navigator.appName == "Microsoft Internet Explorer"))

	{

		var parOffsetX = 140, parOffsetY = 90;

	}

	else

	{

		var parOffsetX = 140, parOffsetY = 215;

	}



	var debug = 0; // 0 = off, 1 = on



	// PARENT WINDOW INFO //

	//If browser is IE

	if (document.all)

	{

		var x = window.screenLeft;

		var y = window.screenTop;

		var w = window.document.body.offsetWidth;

		var h = window.document.body.offsetHeight;

	}

	else //if browser isn't IE

	{

		var x = window.screenX;

		var y = window.screenY;

		var w = window.outerWidth;

		var h = window.outerHeight;

	}



	// CHILD WINDOW INFO //

	if (width) { winW = width; }

	if (height){ winH = height; }



	// some browsers don't have access to the parent's x and y coordinants

	// so default to centering the child in the center of the screen

	if ((!x && x != 0) || (!y && y != 0))

	{ // if x | y are NaN, default to centering in screen

		if (debug)

		{

			alert("WARNING! defaulting to centering in the screen!");

		}

		var lPos = Math.round((screen.availWidth - winW) / 2);

		var tPos = Math.round((screen.availHeight - winH) / 2);

	}

	else

	{

		// if the child window will be off the screen, attempt to fix x and y so that

		// we don't run off the edge of the screen (I got varying results on this one

		// depending on what options I had turned on for the child)

		x += parOffsetX; y += parOffsetY;

		if ( (x + winW) > screen.availWidth ) { if (debug) { alert("fixing x"); } x = screen.availWidth - winW - 25; }

		if ( (y + winH) > screen.availHeight ) { if (debug) { alert("fixing y"); } y = screen.availHeight - winH - 25; }

		var lPos = x;

		var tPos = y;

	}



	winO = ',width='+winW+',height='+winH+winO;

	// for overriding automatic positioning

	if (winO.indexOf("left=") == -1)

	{

		winO = ',left='+lPos+winO;

	}

	if (winO.indexOf("top=") == -1)

	{

		winO = ',top='+tPos+winO;

	}

	// sorry for the confusion, just trying to make it fool-proof

	// after all is said and done, if our winO starts with a comma, chop it off

	if (winO.indexOf(',') == 0) { winO = winO.substring(1); }



	var winName;

	if (!name)

	{

		var i = getRandom();

		winName = 'popup_'+i;

	}

	else

	{

		winName = name;

	}

	var newPosWindow = window.open("", winName, winO);

	newPosWindow.document.write(content);

	newPosWindow.document.close();

	newPosWindow.focus();

}