var BVQAisLoaded = false;
function BVcheckQALoadState()
{
	if(!BVQAisLoaded)
	{
    	var page = document.getElementById('BVQAFrame').src;
		document.getElementById('BVQAFrame').src='http://answers.thescooterstoreonline.com/logging?page=' + escape(page);
    	document.getElementById('BVQAContainer').innerHTML = "<!-- QA retrieval timed out -->";
	}
}

function bvLoadQA(subjectType,subjectID)
{
	var bvQAFrameSrc = 'http://answers.thescooterstoreonline.com/answers/0532/'+subjectType+'/'+subjectID+'/questionshome.htm?format=embedded';
	var bvQuestionIDName = 'featurequestion';
	
	var bvoice_user = $bv('#BVQACustomerID').text();
	
	var bvQuestionIDRegex = new RegExp('[?&]' + bvQuestionIDName + '=([^&#]+)');
	var bvQuestionIDMatch = bvQuestionIDRegex.exec(window.location.search);
	var bvQuestionID = bvQuestionIDMatch ? decodeURIComponent(bvQuestionIDMatch[1]) : null;
	
	bvQAFrameSrc = /^[0-9]+$/.test(bvQuestionID) ? bvQAFrameSrc.replace('/questionshome.htm', '/questions.htm') + '&expandQuestion=' + bvQuestionID : bvQAFrameSrc;
	
	var bvPageMatch = /[?&]bvpage=([^&#]+)/.exec(window.location.search);
	var bvPage = bvPageMatch ? decodeURIComponent(bvPageMatch[1]) : null;
	var bvRegex = new RegExp('^' + window.location.protocol + '\/\/([A-Za-z0-9-.]+[.])?' + document.domain + '\/');
	
	if (bvPage && bvRegex.test(bvPage))
	{
		// [TODO-Tab-Open-Code] - if behind a tab, add code here to open tab
		$bv('#BVQAFrame').attr('src', bvPage.replace(/__USERID__/, bvoice_user));
	}
	else
	{
		$bv('#BVQAFrame').attr('src', bvQAFrameSrc);
	}
	
	//Timeout for QA load.  Consider content unavailable if not loaded within 15 seconds 
	setTimeout("BVcheckQALoadState()", 15000);
}
