/*
 * Copyright © 2010, 2011, 2012, Intuit, Inc.
 */

function getEnvironment() {
	var wlh = window.location.href;
	var env = 'PROD';
	var wip = 'WEB';

	if ( wlh.indexOf('//qa.') > -1 )           { env = 'QA';   wip = 'WEB'; }
	if ( wlh.indexOf('//qa1.') > -1 )           { env = 'QA';   wip = 'WEB'; }
	if ( wlh.indexOf('//aicqaws1.') > -1 )     { env = 'QA';   wip = 'WEB'; }
	if ( wlh.indexOf('//my.') > -1 )           { env = 'PROD'; wip = 'WEB'; }
	if ( wlh.indexOf('//accountant.') > -1 )   { env = 'PROD'; wip = 'WEB'; }
	if ( wlh.indexOf('//proadvisor.') > -1 )   { env = 'PROD'; wip = 'WEB'; }
	if ( wlh.indexOf('//c00000006060.') > -1 ) { env = 'DEV';  wip = 'IP'; }
	if ( wlh.indexOf('//c00000006505.') > -1 ) { env = 'QA';   wip = 'IP'; }
	if ( wlh.indexOf('//c00000056156.') > -1 ) { env = 'PRE';  wip = 'IP'; }
	if ( wlh.indexOf('//support.') > -1 )      { env = 'PROD'; wip = 'IP'; }
	if ( wlh.indexOf('//localhost') > -1 )     { env = 'LOCAL';  wip = 'IP'; }
	if ( wlh.indexOf('//192') > -1 )           { env = 'LOCAL';  wip = 'IP'; }

	var envOR = getParm( "env", window.location.href );
	if ( envOR != '' ) { env = envOR; }
	
	return {env:env, wip:wip};
}

function getLawServer() {
	var environment = getEnvironment();
	var server = 'http://support.accountant.intuit.com/law-war/'; //Default value
	
	if ( environment.wip == 'WEB') {
		if (environment.env == 'QA')    { server = 'http://c00000006505.pharos.intuit.com/law-war/'; }
		if (environment.env == 'PROD')  { server = 'http://support.accountant.intuit.com/law-war/'; }
	}

	if ( environment.wip == 'IP') {
		if (environment.env == 'DEV')   { server = 'http://c00000006060.pharos.intuit.com/law-war/'; }
		if (environment.env == 'QA')    { server = 'http://c00000006505.pharos.intuit.com/law-war/'; }
		if (environment.env == 'PRE')   { server = 'http://c00000056156.ie.intuit.net/law-war/'; }
		if (environment.env == 'PROD')  { server = 'http://support.accountant.intuit.com/law-war/'; }
		if (environment.env == 'LOCAL') { server = 'http://c00000006505.pharos.intuit.com/law-war/'; }
	}
	
	return server;
}

// Rename and remove facets
function friendlyFacet(d) {
	var fd = d;
	if ( d == 'Information Manager Channel') { fd = 'Channel'; }
	if ( d == 'Information Manager') { fd = 'Knowledge Base Content'; }
	if ( d == 'APD') { fd = 'Tax Topics'; }
	if ( d == 'FMS') { fd = 'QuickBooks Accounting Topics'; }
	if ( d == 'PSD') { fd = 'Payments'; }
	if ( d == 'Pertains To') { fd = 'Federal / State'; }
	if ( d == 'FMS Blaze IPH') { fd = 'How To'; }
	return fd;
}

function killFacet(d, product) {
	var kill = false;
	if ( product != 'QBAE') { 
		if ( d == 'Source') { kill = true; }
	}
	if ( d == 'Information Manager Channel') { kill = true; }
	if ( d == 'Doc Types') { kill = true; }
	if ( d == 'Functional') { kill = true; }
	//alert("killing " + d + kill);
	return kill;
}

function killCategory(d) {
	var kill = false;
	if ( d == 'Managed Answer KB') { kill = true; }
	if ( d == 'Process Wizard KB') { kill = true; }
	if ( d == 'Support Site FAQ') { kill = true; }
	if ( d == 'Critical Alert KB') { kill = true; }
	if ( d == 'News Alert KB') { kill = true; }
	if ( d == 'EF Atlas KB') { kill = true; }
	if ( d == 'In Product Link') { kill = true; }
	if ( d == 'Intuit Community') { kill = true; }
	//alert("killing " + d + kill);
	return kill;
}

function getFacetContent(facet, lvl, sTerm, quotedProduct, transId, quotedQuerySource) {
	var content = '';
	var facetType = "'narrow'";
	if (facet.facets) {
		$.each(facet.facets, function(ff,childfacet){
			var childId = "'" + childfacet.id + "'";
			content += '<tr>';
			content += '<td class="im-first-facet im-last-facet">';
			if (childfacet.selected == true) {
				content += '<div class="im-active-facet inset' + lvl + '">';
			} else {
				content += '<div class="im-child-facet inset' + lvl + '">';
			};
			content += '<a class="facet" href="" onClick="applyFacet(' + sTerm + ', ';
			content += transId;
			content += ', ' + quotedProduct;
			content += ', ' + childId;
			content += ', ' + facetType;
			content += ', ' + quotedQuerySource;
			content += '); return false;">';
			content += friendlyFacet(childfacet.description);
			//Turn this off - not accurate - includes items at parent level too
			content += '<span class="im-facet-count"> (' + childfacet.count + ')</span>';
			content += '</a>';
			content += '</div>';
			content += '</td>';
			content += '</tr>';
		
			//If this facet is selected, display all of the children as well
			//if (childfacet.selected == true) {
				content += getFacetContent(childfacet, lvl+1, sTerm, quotedProduct, transId, quotedQuerySource);
			//};
		});
	}	
	return content;
}

function getIQSearchResults(schterm, resturl, product, querySource) {
	var content = '';
	var wizardContent = '';
	var articleURL = '';
	var external = '';
	$.getJSON(resturl, function(data) {
		if ( data === null ) { 
			logEvent('Error', 'Empty Results', resturl, 0);
			content = '<div class="noresults">Empty results found for "' + unescape(schterm) + '". Please try your search again.</div>';
		} else {
			if ( data.exception ) {
				logEvent('Error', 'Oops', resturl + '|' + data.exception.message, 0);
				content = '<div class="search_error">Oops! We had a problem with your search. Please try again later or select a different tab above.</div>';
			} else {
				if ((!data.LAWKBSearchResultDTO ) || (data.LAWKBSearchResultDTO.pageSize === 0) || (data.LAWKBSearchResultDTO.totalResults === 0)) {
					logEvent('Error', 'No Results', resturl, 0);
					content = '<div class="noresults">No results found for "' + unescape(schterm) + '". Please try your search again.</div>';
				} else {
					var firstitem = data.LAWKBSearchResultDTO.pageStart + 1;
					var lastitem = data.LAWKBSearchResultDTO.pageStart + data.LAWKBSearchResultDTO.pageSize;
					var totalitems = data.LAWKBSearchResultDTO.pageStart + data.LAWKBSearchResultDTO.pageSize + data.LAWKBSearchResultDTO.pageMore;
					//InQuira limiting results... can't use the following
					//var totalitems = data.LAWKBSearchResultDTO.totalResults;
					var pageMore = '';
					var pageBack = '';
					var fdirection = "'FORWARD'";
					var bdirection = "'BACKWARD'";
					var quotedProduct = "'" + product + "'";
					var quotedQuerySource = "'" + querySource + "'";
					var baseurl = baseArticleUrl();
					var sTerm = "'" + schterm + "'";
					var wizExcerpt = '';
					var links = '';
					content = '';
					var myw = 0;
					var gscontent = '';
					var cookie_name = '';
					var bpc = getParm("bpc", window.location.href );

					//Guided Support Managed Answer for Phones - Pop & add to top of results
					gsactivated = 0;
					if ((data.LAWKBSearchResultDTO.articleSummaries[0].excerptHTML.indexOf("<!-- GS -->") != -1 ) || ( schterm.indexOf("gsphonetrigger") != -1 )) {
						gsactivated = 1;
						content += '<br clear="all">';
						content += '<div id="gs-div-onpage" style="display: none">';
						gscontent += getGSMessageText('phone', product);
						content += gscontent;
						content += '</div>';
						
						// Should we pop the GS message?
						cookie_name = 'Intuit-APD-GS-' + data.LAWKBSearchResultDTO.articleSummaries[0].documentId;
						if (( $.cookie(cookie_name) != 'true' ) || ( bpc ==='y' )) { 
							content += '<script>$.modal(\'' + gscontent + '\', {onClose: function (dialog) {  $.modal.close(); $(\'#gs-div-onpage\').show("slow"); }} );</script>';
							$.cookie(cookie_name, 'true', { expires: null });
							logEvent('Guided Support', 'Phone Redirect Pop', data.LAWKBSearchResultDTO.articleSummaries[0].documentId + '-' + schterm, 0);

						} else {
							content += '<script>$(\'#gs-div-onpage\').show("fast", "swing");</script>';
							logEvent('Guided Support', 'Phone Redirect Banner', data.LAWKBSearchResultDTO.articleSummaries[0].documentId + '-' + schterm, 0);
						}
					}

					//Guided Support Managed Answer for Customer Service Phones - Pop & add to top of results
					if ((data.LAWKBSearchResultDTO.articleSummaries[0].excerptHTML.indexOf("<!-- GS-CS -->") != -1 ) || ( schterm.indexOf("gsphonetrigger") != -1 )) {
						gsactivated = 1;
						content += '<br clear="all">';
						content += '<div id="gs-div-onpage" style="display: none">';
						gscontent += getGSMessageText('service', product);
						content += gscontent;
						content += '</div>';
						
						// Should we pop the GS message?
						cookie_name = 'Intuit-APD-GS-' + data.LAWKBSearchResultDTO.articleSummaries[0].documentId;
						if (( $.cookie(cookie_name) != 'true' ) || ( bpc ==='y' )) { 
							content += '<script>$.modal(\'' + gscontent + '\', {onClose: function (dialog) {  $.modal.close(); $(\'#gs-div-onpage\').show("slow"); }} );</script>';
							$.cookie(cookie_name, 'true', { expires: null });
							logEvent('Guided Support', 'Phone Redirect Pop', data.LAWKBSearchResultDTO.articleSummaries[0].documentId + '-' + schterm, 1);

						} else {
							content += '<script>$(\'#gs-div-onpage\').show("fast", "swing");</script>';
							logEvent('Guided Support', 'Phone Redirect Banner', data.LAWKBSearchResultDTO.articleSummaries[0].documentId + '-' + schterm, 1);
						}
					}

					//Guided Support Managed Answer for Chat - Pop & add to top of results
					if ((data.LAWKBSearchResultDTO.articleSummaries[0].excerptHTML.indexOf("<!-- GSC -->") != -1 ) || ( schterm.indexOf("gschattrigger") != -1 )) {
						gsactivated = 1;
						content += '<br clear="all">';

						gscontent = getGSMessageText('chat', product, 'lpButton');
						content += '<div id="gs-div-onpage" style="display: none">';
						content += gscontent;
						content += '</div>';

						gscontent = getGSMessageText('chat', product, 'lpButton-2');
						content += '<div id="gs-div-onpage-2" style="display: none">';
						content += gscontent;
						content += '</div>';

						// Should we pop the GS message?
						cookie_name = 'Intuit-APD-GS-' + data.LAWKBSearchResultDTO.articleSummaries[0].documentId;
						if (( $.cookie(cookie_name) != 'true' ) || ( bpc ==='y' )) { 
							//content += '<div id="gs-div-banner" style="display: none">' + gscontent + '</div>';
							//content += '<script>$("#gs-div-onpage-2").modal( {onClose: function (dialog) {  $.modal.close(); $(\'#gs-div-onpage\').show("slow"); }} );</script>';
							content += '<script>$("#gs-div-onpage-2").modal( {onClose: function (dialog) {  $.modal.close(); $(\'#gs-div-onpage\').show("slow"); }} );</script>';
							//content += '<script>$.modal(\'' + gscontent + '\', {onClose: function (dialog) {  $.modal.close(); $(\'#gs-div-onpage\').show("slow"); }} );</script>';
							$.cookie(cookie_name, 'true', { expires: null });
							logEvent('Guided Support', 'Chat Redirect Pop', data.LAWKBSearchResultDTO.articleSummaries[0].documentId + '-' + schterm, 0);
						} else { 
							content += '<script>$("#gs-div-onpage").show("fast");</script>';
							logEvent('Guided Support', 'Chat Redirect Banner', data.LAWKBSearchResultDTO.articleSummaries[0].documentId + '-' + schterm, 0);
						}
					}
					
					//Guided Support Managed Answer for Customer Service Chat - Pop & add to top of results
					if ((data.LAWKBSearchResultDTO.articleSummaries[0].excerptHTML.indexOf("<!-- GSC-CS -->") != -1 ) || ( schterm.indexOf("gschattrigger") != -1 )) {
						gsactivated = 1;
						content += '<br clear="all">';

						gscontent = getGSMessageText('chatservice', product, 'lpButton');
						content += '<div id="gs-div-onpage" style="display: none">';
						content += gscontent;
						content += '</div>';

						gscontent = getGSMessageText('chatservice', product, 'lpButton-2');
						content += '<div id="gs-div-onpage-2" style="display: none">';
						content += gscontent;
						content += '</div>';

						// Should we pop the GS message?
						cookie_name = 'Intuit-APD-GS-' + data.LAWKBSearchResultDTO.articleSummaries[0].documentId;
						if (( $.cookie(cookie_name) != 'true' ) || ( bpc ==='y' )) { 
							//content += '<div id="gs-div-banner" style="display: none">' + gscontent + '</div>';
							//content += '<script>$("#gs-div-onpage-2").modal( {onClose: function (dialog) {  $.modal.close(); $(\'#gs-div-onpage\').show("slow"); }} );</script>';
							content += '<script>$("#gs-div-onpage-2").modal( {onClose: function (dialog) {  $.modal.close(); $(\'#gs-div-onpage\').show("slow"); }} );</script>';
							//content += '<script>$.modal(\'' + gscontent + '\', {onClose: function (dialog) {  $.modal.close(); $(\'#gs-div-onpage\').show("slow"); }} );</script>';
							$.cookie(cookie_name, 'true', { expires: null });
							logEvent('Guided Support', 'Chat Redirect Pop', data.LAWKBSearchResultDTO.articleSummaries[0].documentId + '-' + schterm, 0);
						} else { 
							content += '<script>$("#gs-div-onpage").show("fast");</script>';
							logEvent('Guided Support', 'Chat Redirect Banner', data.LAWKBSearchResultDTO.articleSummaries[0].documentId + '-' + schterm, 0);
						}
					}

					content += '<table summary="" cellpadding="0" cellspacing="0" border="0" width="100%" class="im-table">';
					content += '<tbody>';
					content += '<tr>';

					//Facets
					if (data.LAWKBSearchResultDTO.facets) {
						content += '<td width="185px" valign="top">';
						content += '<table summary="Topics Pagination" cellpadding="0" cellspacing="0" border="0" width="185px">';
						content += '<tbody>';
						content += '<tr>';

						content += '<div class="im-filter-title" float="left">';
						content += '<tr>';
						content += '<td>';
						content += '<table summary="Topics pagination" cellpadding="0" cellspacing="0" border="0" width="185px">';
						content += '<tr>';
						content += '<td height="32px">';
						content += '</td>';
						content += '</tr>';
						content += '<tr>';
						content += '<td>';
						content += '<div class="im-paginationtop im-bottom-border im-filter-title">';
						content += '<table width="100%">';
						content += '<tbody>';
						content += '<tr>';
						content += '<td height="15px">Filter Results</td>';
						content += '<td height="15px" align="right">';
						content += '<a href="" onClick="clearFacets(' + sTerm;
						content += ', ' + quotedProduct;
						content += ', ' + quotedQuerySource;
						content += '); return false;">Reset</a>';
						content += '</td>';
						content += '</tr>';
						content += '</tbody>';
						content += '</table>';
						content += '</div>';
						content += '</td>';
						content += '</tr>';

						//Top Level Facet
//Defect - this assumes top level facet is a label & should have children - not true on LC & IRS tab - TBD						
						$.each(data.LAWKBSearchResultDTO.facets, function(f,facet){
							if ((!killFacet(facet.description, product)) && (facet.facets)){
								content += '<tr>';
								content += '<td class="im-first-facet im-last-facet" nowrap>';
								content += '<div class="im-root-facet im-filter">' + friendlyFacet(facet.description) + '</div>';
								content += '</td>';
								content += '</tr>';
								content += getFacetContent(facet,2,sTerm,quotedProduct,data.LAWKBSearchResultDTO.transactionId, quotedQuerySource);
							}
						});
					
						content += '<tr>';
						content += '<td class="im-top-border">&nbsp;</td>';
						content += '</tr>';
						content += '</table>';
						content += '</td>';
						content += '</tr>';
						content += '</div>';
						content += '</tr>';
						content += '</tbody>';
						content += '</table>';
					}
					//End Facets

					//Spacer row between facets & content
					content += '<td width="1px">&nbsp;</div>';
					
					//Content column
					content += '<td width="99%" valign="top">';
					content += '<table summary="Tpics list" cellpadding="0" cellspacing="0" border="0" width="100%">';
					content += '<thead>';
					content += '<tr>';
					content += '<th nowrap width="1%" class="im-first">&nbsp;</th>';

					if (data.LAWKBSearchResultDTO.pageMore !== 0) { 
						pageMore = ' <a href="" onClick="getMoreIQResults(' + sTerm + ', ';
						pageMore += data.LAWKBSearchResultDTO.transactionId;
						pageMore += ', ' + fdirection;
						pageMore += ', ' + quotedProduct;
						pageMore += ', ' + quotedQuerySource;
						pageMore += '); return false;">Next</a>';
					}
					if (data.LAWKBSearchResultDTO.pageStart !== 0) {
						pageBack = ' <a href="" onClick="getMoreIQResults(' + sTerm + ', ';
						pageBack += data.LAWKBSearchResultDTO.transactionId;
						pageBack += ', ' + bdirection;
						pageBack += ', ' + quotedProduct;
						pageBack += ', ' + quotedQuerySource;
						pageBack += '); return false;">Previous</a> ';
					}
					content += '<th class="im-last" width="97%" >' + pageBack + 'Results (' + firstitem + ' - ' + lastitem + ' of ' + totalitems + ')' + pageMore;
					content += '</tr>';
					content += '</thead>';

					//Wizards
					$.each(data.LAWKBSearchResultDTO.wizardSummaries, function(ww,wizard){
						myw = myw + 1;
						if ((myw)%2 === 0) {
							content += '<tr class="im-even">';
						} else {
							content += '<tr class="im-odd">';
						}
						content += '<td class="im-first" valign="top" width="1%" nowrap>';
						content += '<div class="wizard_icon"></div>';
						content += '</td>';
						content += '<td class="im-last" width="99%" valign="top">';
						links = "'" + wizard.id + "', '" + wizard.firstStep + "'";
						content += '<a class="im-wizard-subject" href="" onClick="doProcessWizard(' + links + '); return false;">' + wizard.label + '</a>';
						content += '<table>';
						content += '<tr>';
						content += '<td valign=top>';
						//$.each(wizard.steps, function(s, mystep){
						//	if (mystep.id == wizard.firstStep ) {
						//		wizExcerpt = mystep.fields[0].description;
						//	}
						//});
						//content += '<div class="im-result-excerpt-block">Step 1: ' + wizExcerpt + '</div>';
						content += '<div class="im-result-excerpt-block">' + wizard.description + '</div>';
						content += '</td>';
						content += '</tr>';
						content += '</table>';
						content += '</td>';
						content += '</tr>';
						wizardContent += '<script>function getWizard' + wizard.id + '() { return ' + JSON.stringify(wizard) + '; }</script>';
						
						if (( wizard.description.indexOf("<!-- GS -->") != -1 ) || ( schterm.indexOf("gswizardtrigger") != -1 )) {
							gscontent += '<script>$.modal(\''
							gscontent += getGSMessageText('clarify', product);
							gscontent += '\');';
							links = "'" + wizard.id + "', '" + wizard.firstStep + "'";
							gscontent += 'function doPWYesClick() { doProcessWizard(' + links + '); };';
							gscontent += '</script>';

							// Should we pop the GS message?
							cookie_name = 'Intuit-APD-GS-' + wizard.id;
							if (( $.cookie(cookie_name) != 'true' ) || ( bpc ==='y' )) { 
								content += gscontent;
								$.cookie(cookie_name, 'true', { expires: null });
								logEvent('Guided Support', 'Clarification Pop', wizard.id + '-' + schterm, 0);
							}
						}
					});

					//Articles
					$.each(data.LAWKBSearchResultDTO.articleSummaries, function(i,article){

						//Guided Support - Do not display MA or PW if they are GS triggers
						gsactivated = 0;
						if (article.excerptHTML.indexOf("<!-- GS") != -1 ) {
							//gsactivated = 1; //Al said we should display these
						}

						if ( gsactivated === 0 ) {
							if ( article.documentId !== null ) {
								articleURL = baseurl + '?product=' + product + '&id=' + article.documentId;
								external = 'n';
							} else {
								articleURL = article.documentPath;
								external = 'y';
							}
												
							myw = myw + 1;
							if ((myw)%2 === 0) {
								content += '<tr class="im-even">';
							} else {
								content += '<tr class="im-odd">';
							}
							content += '<td class="im-first" valign="top" width="1%" nowrap>';
							if ( article.documentType == "custom" ) {
								content += '<div class="managed_answer_icon"></div>';
							} else {
								content += '<div class="search_icon"></div>';
							}
							content += '</td>';
							content += '<td class="im-last" width="99%" valign="top">';

							if ( external == 'n') {
								content += '<a href="' + articleURL + '" class="im-standard-subject"';
								content += '>' + article.titleHTML + '</a>';
							} else {
								var shortTitle = article.title;
								shortTitle = shortTitle.replace(/\|.*/,''); //Chop titles at first | character
								
								content += '<a href="#" class="im-standard-subject" target="_blank"';
								content += ' onClick="doExternal(';
								content += '\'External Link\'';
								content += ', ' + quotedProduct;
								content += ', \'' + articleURL + '\'';
								content += '); return false;"';
								content += '><span class="snippet0">' + shortTitle + '</span></a>';
								//content += '>' + shortTitle + '</a>';
							}
							content += '<table>';
							content += '<tr>';
							content += '<td valign=top>';
							content += '<div class="im-result-excerpt-block">' + article.excerptHTML + '</div>';
							content += '</td>';
							content += '</tr>';
							content += '</table>';
							content += '</td>';
							content += '</tr>';
						}
					});
					content += '</table>';
					content += '</td>';
					content += '</tr>';
					
					content += '</tr>';
					content += '</tbody>';
					content += '</table>';
				}
			}
		}
		content += wizardContent;
		//alert(content);	
		//alert(wizardContent);	
		document.title = "Search Results - Ask Intuit";
		ResultsCallback(content);
	});
}

function doIQSearch(schterm, product, querySource) {
	if ( querySource === undefined) {
		querySource = 'apd.law';
	}
	var resturl = getLawServer() + "kb/articles?qs=" + querySource + "&product=" + product + "&question=" + schterm + "&callback=?";
	getIQSearchResults(schterm, resturl, product, querySource);
}

function getMoreIQResults(schterm, transactionID, direction, product, querySource) {
	//var resturl = getLawServer() + "kb/articles/search?id=" + transactionID + "&direction=" + direction + "&callback=?";
	var resturl = getLawServer() + "kb/articles/search?direction=" + direction + "&callback=?";
	logEvent('Paging',direction,schterm);
	getIQSearchResults(schterm, resturl, product, querySource);
}

function applyFacet(schterm, transactionID, product, facetId, facetType, querySource) {
	var resturl = getLawServer() + "kb/articles?qs=" + querySource + "&product=" + product + "&question=" + schterm + "&fac=" + encodeURIComponent(facetId) + "&callback=?";
	//alert("resturl="+resturl);
	ResultsCallback('<div class="searching_container"><div class="searching">Applying Filters...</div><div class="loading"></div></div>');
	logEvent('Filter','Apply',resturl);
	getIQSearchResults(schterm, resturl, product, querySource);
}

function clearFacets(schterm, product, querySource) {
	var resturl = getLawServer() + "kb/articles?qs=" + querySource + "&product=" + product + "&question=" + schterm + "&clear=y" + "&callback=?";
	//alert("resturl="+resturl);
	ResultsCallback('<div class="searching_container"><div class="searching">Clearing Filters...</div><div class="loading"></div></div>');
	logEvent('Filter','Clear',resturl);
	getIQSearchResults(schterm, resturl, product, querySource);
}	

function getIQArticle(docid) {
	var resturl = getLawServer() + "kb/articles/" + docid + "?callback=?";
	$.getJSON(resturl, function(data){
		var content = '';
		if ( data === null ) { 
			logEvent('Error', 'Empty Results', resturl, 1);
			content = '<div class="noresults">Empty results found for "' + docid + '". Please try your search again.</div>';
		} else {
			if ( data.exception ) {
				if ( data.exception.message.indexOf('FindArticleByDocId') !== -1 ) {
					//Doc Not Found Error
					var resturl2 = getLawServer() + "kb/articles/WEB12525?callback=?";
					$.getJSON(resturl2, function(data2){
						if ( data2 === null ) { 
							content = '';
							logEvent('Error', 'Oops', resturl + '|' + data.exception.message, 1);
							content = '<div class="get_article_error">Oops! We had a problem retrieving your article. Please try your search again or select another document.</div>';
						} else {
							if ( data2.exception ) {
								logEvent('Error', 'Oops', resturl + '|' + data.exception.message, 1);
								content = '<div class="get_article_error">Oops! We had a problem retrieving your article. Please try your search again or select another document.</div>';
							} else {
								if (!data2.LAWKBArticleDTO) {
									logEvent('Error', 'Oops', resturl + '|' + data.exception.message, 1);
									content = '<div class="get_article_error">Oops! We had a problem retrieving your article. Please try your search again or select another document.</div>';
								} else {
									logEvent('Error', 'Content', resturl + '|' + data.exception.message, 1);
									content += '<h1 class="im-content-title">' + data2.LAWKBArticleDTO.shortTitle + '</h1>';
									$.each(data2.LAWKBArticleDTO.sections, function(i,section){
										if ( section.body !== null ) {
											content += section.body;
										}
									});
								}
							}
						}
						document.title = "Retired Article - Ask Intuit";
						ResultsCallback(content);
					});
				} else {
					//Other Error Type
					logEvent('Error', 'Oops', resturl + '|' + data.exception.message, 1);
					content = '<div class="get_article_retired">Oops! We had a problem retrieving your article. Please try your search again or select another document.</div>';
				}
			} else {
				if (!data.LAWKBArticleDTO) {
					content = '<div class="noresults">No results found for "' + docid + '". Please try your search again.</div>';
					logEvent('Error', 'No Results', resturl, 1);
				} else {
					content = '';
					content += '<div id="topmessage"></div>';

					var articleTitle = data.LAWKBArticleDTO.title;
					if (( articleTitle === null) || ( articleTitle === "" )) {
						articleTitle = data.LAWKBArticleDTO.shortTitle;
					}

					content += '<h1 class="im-content-title">' + articleTitle + '</h1>';

					//START NEW SURVEY
					if ( data.LAWKBArticleDTO.rating !== null ) {
						var prodForSurvey = getParm("product", window.location.href);
						var medSurveyLink = '';

						//Survey - Initial Question
						content += '<div id="articleSurvey" style="float: right; clear: right; width: 200px;">';
						content += '<div class="title">Did this answer your question?</div>';
						content += '<div id="surveyQuestions">';
						content += '<a class="yes" href="javascript:">Yes, it did...</a>';
						content += '<br>';
						content += '<a class="no" href="javascript:">No, it didn&#39;t...</a>';
						content += '</div>';
						
						//Survey - Yes
						content += '<div id="surveyYes" style="display: none">';
						content += '<div class="surveyAnswer">';
						content += '<div class="yes">Yes, it did...</div>';
						content += '<div class="im-rating-title">Optional suggestions or feedback for this article:</div>';
						content += '<form id="ratingFormY" action="">';
						content += '<input type="hidden" name="docID" value="' + docid + '"/>';
						content += '<input type="hidden" name="RADIO_BUTTON:Q1" value="1:YES"/>';
						content += '<a name="rate"></a>';
						content += '<div id="ratingtable">';
						content += '<div id="ratingDiv" class="im-icon">';
						content += '<textarea id="Q2" class="xmleditfield" name="TEXT_AREA:Q3:A1" cols="24" rows="5"></textarea>';
						content += '</div>';
						content += '<input id="submit_btn" class="button" type="submit" value="" name="submit">';
						content += '</div>';
						content += '</form>';
						content += '</div>';
						content += '</div>';

						//Survey - No
						content += '<div id="surveyNo" style="display: none">';
						content += '<div class="surveyAnswer">';
						content += '<div class="no">No, it didn&#39;t...</div>';
						content += '<div class="im-rating-title">Please let us know how we can improve this article:</div>';
						content += '<form id="ratingFormN" action="">';
						content += '<input type="hidden" name="docID" value="' + docid + '"/>';
						content += '<input type="hidden" name="RADIO_BUTTON:Q1" value="2:NO"/>';
						content += '<a name="rate"></a>';
						content += '<div id="ratingtable">';
						content += '<div id="ratingDiv" class="im-icon">';
						content += '<textarea id="Q2" class="xmleditfield" name="TEXT_AREA:Q3:A1" cols="24" rows="10"></textarea>';
						content += '</div>';
						content += '<input id="submit_btn" class="button" type="submit" value="" name="submit">';
						content += '</div>';
						content += '</form>';
						content += '</div>';
						content += '</div>';

						//Thank You Sections
						content += '<div id="surveyThanksY" style="display: none"></div>';
						content += '<div id="surveyThanksN" style="display: none"></div>';
						content += '</div>';
						
						//Script
						var scontent = '';
						scontent += '<script>';

						//They said YES
						scontent += '$(\'#articleSurvey a.yes\').click(function () {';
						scontent += '$(\'#surveyQuestions\').hide(); $(\'#surveyYes\').show("slow");';
						scontent += '});'

						//They said NO
						scontent += '$(\'#articleSurvey a.no\').click(function () {';
						scontent += '$(\'#surveyQuestions\').hide(); $(\'#surveyNo\').show("slow");';
						scontent += '});'

						//Run when page loaded
						scontent += '$(document).ready(function() {';
						scontent += '$(".button").click( function() { if ( !($("#surveyYes").is(":hidden")) ) { logEvent(\'ExpSurvey\', \'TriggeronClick\', \'' + resturl + '\', 1); triggerSurvey("click"); } if ( !($("#surveyNo").is(":hidden")) ) { logEvent(\'ExpSurvey\', \'TriggeronClick\', \'' + resturl + '\', 2); triggerSurvey("click"); } return false; } );';
						scontent += '$(window).unload(   function() { if ( !($("#surveyYes").is(":hidden")) ) { logEvent(\'ExpSurvey\', \'TriggeronExit\', \'' + resturl + '\', 1); triggerSurvey("exit"); } if ( !($("#surveyNo").is(":hidden")) ) { logEvent(\'ExpSurvey\', \'TriggeronExit\', \'' + resturl + '\', 2); triggerSurvey("exit"); } return false; } );';
						scontent += '});';
						
						//Survey submit button was selected or triggered by page close
						scontent += 'function triggerSurvey(trigger) {';
						scontent += 'var medSurveyLink = "";';
						scontent += 'if ( !($("#surveyYes").is(":hidden")) ) {';
						scontent += 'var formData = $("#ratingFormY").serialize();';
						scontent += 'var surveyaddr2 = "' + getLawServer() + 'kb/articles/survey";';
						scontent += 'medSurveyLink = getMedSurveyLink("' + prodForSurvey + '", \'y\');';
						scontent += 'saveArticleSurvey(surveyaddr2, formData);';
						scontent += '$(\'#surveyYes\').hide();';
						
						//Fill up the SurveyThanksY div, then show it
						scontent += 'var sTC = \'<div id="surveyThanks">\';';
						scontent += 'sTC += \'<div class="rating_feedback_message"><br />Thank you for taking the time to give us your feedback.</div>\';';
						scontent += 'sTC += \'</div>\';'; 
						scontent += 'if ( $.cookie(\'Med_Survey_Closed\') != null ) {';
						scontent += 'logEvent(\'ExpSurvey\', \'Closed\', \'' + resturl + '\', 1);';
						scontent += '} else {';
						scontent += 'var WindowObject = window.open(medSurveyLink, \'_blank\', \'width=800,height=650,top=50,left=50,toolbars=yes,scrollbars=yes,status=no,resizable=yes\');';
						scontent += 'if (WindowObject) {';
						scontent += '$.cookie(\'Med_Survey_Closed\',\'1\',{ expires: 14 });';
						scontent += 'WindowObject.focus();';
						scontent += 'logEvent(\'ExpSurvey\', \'Pop\', \'' + resturl + '\', 1);';
						scontent += '} else {';
						scontent += 'logEvent(\'ExpSurvey\', \'PopBlocked\', \'' + resturl + '\', 1);';
						scontent += '}';
						scontent += '}';
						scontent += 'if ( trigger !== \'exit\' ) {';
						scontent += 'if ( medSurveyLink !== \'\' ) {';
						scontent += 'var clickScript = \'logEvent(\\\'ExpSurvey\\\', \\\'DisplayClick\\\', \\\'' + resturl + '\\\', 1); window.open(\\\'\' + medSurveyLink + \'\\\',\\\'_blank\\\'); return false;\';';
						scontent += 'sTC += \'<div class="medSurvey"><a href="" onClick="\' + clickScript + \'">Tell us more</a> about your experience using our self-help resources.</div>\';';
						scontent += '}';
						scontent += 'logEvent(\'ExpSurvey\', \'Display\', \'' + resturl + '\', 1);';
						scontent += '$("#surveyThanksY").html(sTC);';
						scontent += '$(\'#surveyThanksY\').show("fast");';
						scontent += '}';
						scontent += '}';

						
						scontent += 'if ( !($("#surveyNo").is(":hidden")) ) {';
						scontent += 'var formData = $("#ratingFormN").serialize();';
						scontent += 'var surveyaddr2 = "' + getLawServer() + 'kb/articles/survey";';
						scontent += 'medSurveyLink = getMedSurveyLink("' + prodForSurvey + '", \'n\');';
						scontent += 'saveArticleSurvey(surveyaddr2, formData);';
						scontent += '$(\'#surveyNo\').hide();';

						//Fill up the SurveyThanksN div, then show it
						scontent += 'var sTC = \'<div id="surveyThanks">\';';
						scontent += 'sTC += \'<div class="rating_feedback_message"><br />Thank you for taking the time to give us your feedback.</div>\';';
						scontent += 'sTC += \'</div>\';'; 
						scontent += 'if ( $.cookie(\'Med_Survey_Closed\') != null ) {';
						scontent += 'logEvent(\'ExpSurvey\', \'Closed\', \'' + resturl + '\', 2);';
						scontent += '} else {';
						scontent += 'var WindowObject = window.open(medSurveyLink, \'_blank\', \'width=800,height=650,top=50,left=50,toolbars=yes,scrollbars=yes,status=no,resizable=yes\');';
						scontent += 'if (WindowObject) {';
						scontent += '$.cookie(\'Med_Survey_Closed\',\'1\',{ expires: 14 });';
						scontent += 'WindowObject.focus();';
						scontent += 'logEvent(\'ExpSurvey\', \'Pop\', \'' + resturl + '\', 2);';
						scontent += '} else {';
						scontent += 'logEvent(\'ExpSurvey\', \'PopBlocked\', \'' + resturl + '\', 2);';
						scontent += '}';
						scontent += '}';
						scontent += 'if ( trigger !== \'exit\' ) {';
						scontent += 'if ( medSurveyLink !== \'\' ) {';
						scontent += 'var clickScript = \'logEvent(\\\'ExpSurvey\\\', \\\'DisplayClick\\\', \\\'' + resturl + '\\\', 2); window.open(\\\'\' + medSurveyLink + \'\\\',\\\'_blank\\\'); return false;\';';
						scontent += 'sTC += \'<div class="medSurvey">If you&#39;re done searching for an answer, <a href="" onClick="\' + clickScript + \'">Tell us more</a> about your experience using our self-help resources.</div>\';';
						scontent += '}';
						scontent += 'logEvent(\'ExpSurvey\', \'Display\', \'' + resturl + '\', 2);';
						scontent += '$("#surveyThanksN").html(sTC);';
						scontent += '$(\'#surveyThanksN\').show("fast");';
						scontent += '}';
						scontent += '}';

						scontent += 'return false;';
						scontent += '};';
						scontent += '</script>';
						content += scontent;
						//alert(scontent);
						//alert(content);
					}
					//END NEW SURVEY
							
					//INF Channel has description in a different place
					if ( data.LAWKBArticleDTO.channel == 'INFORMATION' ) {
						content += '<div class="attr SECTION_HEADING"><h3>Description</h3></div>';
						content += '<div class="attr SECTION_BODY"><div class="contentEXTERNAL_PUBLIC">' + data.LAWKBArticleDTO.description + '</div></div>';
					}
					
					//Article Content
					$.each(data.LAWKBArticleDTO.sections, function(i,section){
						if ( section.heading !== null ) {
							content += '<div class="attr SECTION_HEADING"><h3>' + section.heading + '</h3></div>';
						}
						if ( section.body !== null ) {
							content += '<div class="attr SECTION_BODY"><div class="contentEXTERNAL_PUBLIC">' + section.body + '</div></div>';
						}
					});

					//"Header" info
					content += '<div class="im-content-head">';
					content += '<div class="attr SECTION_HEADING"><h3>General Information</h3></div>';

					//Title & Date
					content += '<table border="0" cellpadding="2" cellspacing="0">';
					content += '<tr>';
					content += '<td align="right"><strong>Doc ID:</strong></td>';
					content += '<td>&nbsp;&nbsp;</td>';
					content += '<td>' + data.LAWKBArticleDTO.documentId + '</td>';
					content += '</tr>';
					content += '<tr>';
					content += '<td align="right">';
					content += '<strong>Updated:</strong>';
					content += '</td>';
					content += '<td>&nbsp;&nbsp;</td>';
					var d = new Date(data.LAWKBArticleDTO.updatedDate);
					var month = d.getMonth() + 1;
					var mydate = month + '/' + d.getDate() + '/' + d.getFullYear();
					content += '<td>' + mydate + '</td>';
					content += '</tr>';

					//Categories
					var catAll = '';
					var catProd = '';
					var catTTyp = '';
					var catJuri = '';
					var catTxYr = '';
					$.each(data.LAWKBArticleDTO.categories, function(c,category){
						if (!killCategory(category.name)) {
								
						if ( catAll !== '' ) {
							catAll += ', ';
						}
						catAll += category.name;
						if ( category.parentReferenceKey == 'PRODUCTS_LACERTE' ) {
							if ( catProd !== '' ) {
								catProd += ', ';
							}
							//catProd += category.name;
						}
						if (( category.parentReferenceKey == 'APD_MODULE' ) || ( category.parentReferenceKey == 'APD_MISCELLANEOUS_RETURNS' )) {
							if ( catTTyp !== '' ) {
								catTTyp += ', ';
							}
							//catTTyp += category.name;
						}
						if ( category.parentReferenceKey == 'PERTAINS_TO' ) {
							if ( catJuri !== '' ) {
								catJuri += ', ';
							}
							//catJuri += category.name;
						}
						if ( category.parentReferenceKey == 'TAX_YEAR' ) {
							if ( catTxYr !== '' ) {
								catTxYr += ', ';
							}
							//catTxYr += category.name;
						}

						//content += category.referenceKey;
						//content += category.name;
						//content += '<a href="?page=content&channel=GENERAL&cat=MODULE_BENEFIT_PLAN">Benefit Plan</a>';

						}
					});
					if ( catAll !== '' ) { 
						content += '<tr>';
						content += '<td align="right">';
						content += '<strong>Categories:</strong>';
						content += '</td>';
						content += '<td>&nbsp;&nbsp;</td>';
						content += '<td>' + catAll + '</td>';
						content += '</tr>';
					}
					if ( catProd !== '' ) { 
						content += '<tr>';
						content += '<td align="right">';
						content += '<strong>Products:</strong>';
						content += '</td>';
						content += '<td>&nbsp;&nbsp;</td>';
						content += '<td>' + catProd + '</td>';
						content += '</tr>';
					}
					if ( catTTyp !== '' ) { 
						content += '<tr>';
						content += '<td align="right">';
						content += '<strong>Tax Type:</strong>';
						content += '</td>';
						content += '<td>&nbsp;&nbsp;</td>';
						content += '<td>' + catTTyp + '</td>';
						content += '</tr>';
					}
					if ( catJuri !== '' ) { 
						content += '<tr>';
						content += '<td align="right">';
						content += '<strong>Jurisdiction:</strong>';
						content += '</td>';
						content += '<td>&nbsp;&nbsp;</td>';
						content += '<td>' + catJuri + '</td>';
						content += '</tr>';
					}
					if ( catTxYr !== '' ) { 
						content += '<tr>';
						content += '<td align="right">';
						content += '<strong>Tax Year:</strong>';
						content += '</td>';
						content += '<td>&nbsp;&nbsp;</td>';
						content += '<td>' + catTxYr + '</td>';
						content += '</tr>';
					}
					//End Categories

					content += '</table>';
					content += '</div>';
					//End Title & Date
					//End "Header" Info

					//Remove content surrounding APD-ONLY sections so they'll display
					var regex = new RegExp( "<!-- APD-ONLY (.*?) -->", "g" );
					content = content.replace(regex,"$1");
					
					//kbexpando bindings won't work on data loaded after document ready, so putting binding script here
					content += '<script>$(".kbexpandolink").click(function () { var next = $(this).next(".kbexpandoContent"); next.slideToggle("fast");if ($(this).hasClass("open")) { $(this).removeClass("open"); } else $(this).addClass("open"); }); </script>';
					content += '<script>$("#ClosedLoopFeedback").html("Please visit the <a href=\'http://support.quickbooks.intuit.com/support/articles/' + docid + '\'>QuickBooks version of this article</a> to sign up for more information when it becomes available.");</script>';
				}
			}
		}
		//alert(content);
		document.title = articleTitle + " - Ask Intuit";
		ResultsCallback(content);
		//ArticleCallback(content); //Keep this in until web pages can be updated
	});
}

function GetAlert(product, docid) {
	if ( ( docid === undefined) || ( docid === null) || ( docid === "") ) {
		var environment = getEnvironment();
		
		//DEV
		if ( (environment.env == 'DEV') || (environment.env == 'LOCAL') ) {
			if ( product === 'LACERTE_TAX')   { docid='WEB10362'; }
			if ( product === 'EASYACCT')      { docid='WEB10372'; }
			if ( product === 'LACERTE_PTI')   { docid='WEB10376'; }
			if ( product === 'PROSERIES_TAX') { docid='WEB10361'; }
			if ( product === 'PROSERIES_PTI') { docid='WEB10377'; }
			if ( product === 'QBAE')          { docid='WEB10366'; }
			if ( product === 'PTO')           { docid='WEB10365'; }
			if ( product === 'PTR')           { docid='WEB10382'; }
			if ( product === 'PPM')           { docid='WEB10383'; }
			if ( product === 'QBOA')          { docid='WEB10366'; } //Using QBAE
			if ( product === 'ISW')           { docid='WEB10386'; }
			if ( product === 'AWE')           { docid='WEB10393'; }
			if ( product === 'BA')            { docid='WEB10390'; }
		}
		//SYS
		if (environment.env == 'QA') {
			if ( product === 'LACERTE_TAX')   { docid='WEB12462'; }
			if ( product === 'EASYACCT')      { docid='WEB12468'; }
			if ( product === 'LACERTE_PTI')   { docid='WEB12476'; }
			if ( product === 'PROSERIES_TAX') { docid='WEB12461'; }
			if ( product === 'PROSERIES_PTI') { docid='WEB12472'; }
			if ( product === 'QBAE')          { docid='WEB12459'; }
			if ( product === 'PTO')           { docid='WEB12458'; }
			if ( product === 'PTR')           { docid='WEB12477'; }
			if ( product === 'PPM')           { docid='WEB12482'; }
			if ( product === 'QBOA')          { docid='WEB12487'; }
			if ( product === 'ISW')           { docid='WEB12483'; }
			if ( product === 'AWE')           { docid='WEB12497'; }
			if ( product === 'BA')            { docid='WEB12494'; }
		}
		//PRE / PERF
		if (environment.env == 'PRE') {
			if ( product === 'LACERTE_TAX')   { docid='WEB12319'; } //All are using a generic fragment
			if ( product === 'EASYACCT')      { docid='WEB12319'; }
			if ( product === 'LACERTE_PTI')   { docid='WEB12319'; }
			if ( product === 'PROSERIES_TAX') { docid='WEB12319'; }
			if ( product === 'PROSERIES_PTI') { docid='WEB12319'; }
			if ( product === 'QBAE')          { docid='WEB12319'; }
			if ( product === 'PTO')           { docid='WEB12319'; }
			if ( product === 'PTR')           { docid='WEB12319'; }
			if ( product === 'PPM')           { docid='WEB12319'; }
			if ( product === 'QBOA')          { docid='WEB12319'; }
			if ( product === 'ISW')           { docid='WEB12319'; }
			if ( product === 'AWE')           { docid='WEB12319'; }
			if ( product === 'BA')            { docid='WEB12319'; }
		}
		//PROD
		if (environment.env == 'PROD') {
			if ( product === 'LACERTE_TAX')   { docid='WEB12462'; }
			if ( product === 'EASYACCT')      { docid='WEB12468'; }
			if ( product === 'LACERTE_PTI')   { docid='WEB12476'; }
			if ( product === 'PROSERIES_TAX') { docid='WEB12461'; }
			if ( product === 'PROSERIES_PTI') { docid='WEB12472'; }
			if ( product === 'QBAE')          { docid='WEB12459'; }
			if ( product === 'PTO')           { docid='WEB12458'; }
			if ( product === 'PTR')           { docid='WEB12477'; }
			if ( product === 'PPM')           { docid='WEB12482'; }
			if ( product === 'QBOA')          { docid='WEB12487'; }
			if ( product === 'ISW')           { docid='WEB12483'; }
			if ( product === 'AWE')           { docid='WEB12497'; }
			if ( product === 'BA')            { docid='WEB12494'; }
		}
	}
	
	if ( docid != '' ) {
		getFragment(docid, 1);
	}
}

function GetFAQ(product, docid) {
	if ( ( docid === undefined) || ( docid === null) || ( docid === "") ) {
		var environment = getEnvironment();
		
		//DEV
		if ( (environment.env == 'DEV') || (environment.env == 'LOCAL') ) {
			if ( product === 'LACERTE_TAX')   { docid='WEB10367'; }
			if ( product === 'EASYACCT')      { docid='WEB10373'; }
			if ( product === 'LACERTE_PTI')   { docid='WEB10374'; }
			if ( product === 'PROSERIES_TAX') { docid='WEB10369'; }
			if ( product === 'PROSERIES_PTI') { docid='WEB10379'; }
			if ( product === 'QBAE')          { docid='WEB10371'; }
			if ( product === 'PTO')           { docid='WEB10370'; }
			if ( product === 'PTR')           { docid='WEB10380'; }
			if ( product === 'PPM')           { docid='WEB10385'; }
			if ( product === 'QBOA')          { docid='WEB10371'; } //Using QBAE
			if ( product === 'ISW')           { docid='WEB10387'; }
			if ( product === 'AWE')           { docid='WEB10394'; }
			if ( product === 'BA')            { docid='WEB10391'; }
		}
		//SYS
		if (environment.env == 'QA') {
			if ( product === 'LACERTE_TAX')   { docid='WEB12464'; }
			if ( product === 'EASYACCT')      { docid='WEB12470'; }
			if ( product === 'LACERTE_PTI')   { docid='WEB12474'; }
			if ( product === 'PROSERIES_TAX') { docid='WEB12465'; }
			if ( product === 'PROSERIES_PTI') { docid='WEB12473'; }
			if ( product === 'QBAE')          { docid='WEB12467'; }
			if ( product === 'PTO')           { docid='WEB12466'; }
			if ( product === 'PTR')           { docid='WEB12479'; }
			if ( product === 'PPM')           { docid='WEB12480'; }
			if ( product === 'QBOA')          { docid='WEB12485'; }
			if ( product === 'ISW')           { docid='WEB12484'; }
			if ( product === 'AWE')           { docid='WEB12498'; }
			if ( product === 'BA')            { docid='WEB12495'; }
		}
		//PRE / PERF
		if (environment.env == 'PRE') {
			if ( product === 'LACERTE_TAX')   { docid='WEB12317'; } //All are using a generic fragment
			if ( product === 'EASYACCT')      { docid='WEB12317'; }
			if ( product === 'LACERTE_PTI')   { docid='WEB12317'; }
			if ( product === 'PROSERIES_TAX') { docid='WEB12317'; }
			if ( product === 'PROSERIES_PTI') { docid='WEB12317'; }
			if ( product === 'QBAE')          { docid='WEB12317'; }
			if ( product === 'PTO')           { docid='WEB12317'; }
			if ( product === 'PTR')           { docid='WEB12317'; }
			if ( product === 'PPM')           { docid='WEB12317'; }
			if ( product === 'QBOA')          { docid='WEB12317'; }
			if ( product === 'ISW')           { docid='WEB12317'; }
			if ( product === 'AWE')           { docid='WEB12317'; }
			if ( product === 'BA')            { docid='WEB12317'; }
		}
		//PROD
		if (environment.env == 'PROD') {
			if ( product === 'LACERTE_TAX')   { docid='WEB12464'; }
			if ( product === 'EASYACCT')      { docid='WEB12470'; }
			if ( product === 'LACERTE_PTI')   { docid='WEB12474'; }
			if ( product === 'PROSERIES_TAX') { docid='WEB12465'; }
			if ( product === 'PROSERIES_PTI') { docid='WEB12473'; }
			if ( product === 'QBAE')          { docid='WEB12467'; }
			if ( product === 'PTO')           { docid='WEB12466'; }
			if ( product === 'PTR')           { docid='WEB12479'; }
			if ( product === 'PPM')           { docid='WEB12480'; }
			if ( product === 'QBOA')          { docid='WEB12485'; }
			if ( product === 'ISW')           { docid='WEB12484'; }
			if ( product === 'AWE')           { docid='WEB12498'; }
			if ( product === 'BA')            { docid='WEB12495'; }
		}
	}
	
	if ( docid != '' ) {
		getFragment(docid, 2);
	}
}

function getFragment(docid, divName) {
	var content = '';
	if ( docid != '' ) {
		var resturl = getLawServer() + "kb/articles/" + docid + "?callback=?";
		$.getJSON(resturl, function(data){
			if ( data === null ) { 
				//logEvent('Error', 'Empty Results', resturl, 1);
				content = '';
			} else {
				if ( data.exception ) {
					//logEvent('Error', 'Oops', resturl, 1);
					content = '';
				} else {
					if (!data.LAWKBArticleDTO) {
						content = '';
						//logEvent('Error', 'No Results', resturl, 1);
					} else {
						//Article Content
						$.each(data.LAWKBArticleDTO.sections, function(i,section){
							if ( section.body !== null ) {
								content += section.body;
							}
						});
					}
				}
			}
			//Old Style - hardcoded callback routines
			if ( divName === 1) { AlertCallback(content); }
			if ( divName === 2) { FAQCallback(content); }

			if (( divName !== 1) && ( divName !== 2)) {
				//New Style - dynamic callback routines
				if ( divName !== '' ) { FragCallback(divName, content); }
			}
		});
	}
}

function getGSMessageText(type, productin, buttondiv) {
	var message = '';
	var product = productin;

	//var product = getParm("product", window.location.href );
	if ( product === '') { product = getParm("product", window.location.href ); }
	
	if ( type === 'phone' ) {
		var phone = '';
		var opHours = '';
		if ( product === 'LACERTE_TAX')   { phone='800-933-9999 Call Us'; opHours = '<a href="http://my.lacerte.intuit.com/support/document.aspx?product=LACERTE_TAX&id=GEN59713">Hours of Operation</a>'; }
		if ( product === 'LACERTE_PTI')   { phone='800-933-9999 Call Us'; opHours = '<a href="http://my.lacerte.intuit.com/support/document.aspx?product=LACERTE_TAX&id=GEN59713">Hours of Operation</a>'; }
		if ( product === 'PROSERIES_TAX') { phone='800-434-6818 Call Us'; opHours = '<a href="http://my.proseries.intuit.com/support/document.aspx?product=PROSERIES_TAX&id=GEN70312">Hours of Operation</a>'; }
		if ( product === 'PROSERIES_PTI') { phone='800-434-6818 Call Us'; opHours = '<a href="http://my.proseries.intuit.com/support/document.aspx?product=PROSERIES_TAX&id=GEN70312">Hours of Operation</a>'; }
		if ( product === 'EASYACCT')      { phone='866-220-0488 Call Us'; opHours = '<a href="http://accountant.intuit.com/support/easyacct/document.aspx?product=EASYACCT&id=GEN56768">Hours of Operation</a>'; }
		if ( product === 'QBAE')          { phone='<a href="http://accountant.intuit.com/support/contact_choice.aspx">Contact Options</a>'; opHours = '<a href="http://accountant.intuit.com/support/contact_choice.aspx">Hours of Operation</a>'; }
		if ( product === 'PTO')           { phone='N/A'; opHours = '<a href="http://accountant.intuit.com/support/prolinetaxonline/document.aspx?product=PTO&id=GEN70962">Hours of Operation</a>'; } //Available for chat only
		if ( product === 'PTR')           { phone='800-933-9999 Call Us'; opHours = '<a href="http://my.lacerte.intuit.com/support/document.aspx?product=LACERTE_TAX&id=GEN59713">Hours of Operation</a>'; }
		if ( product === 'PPM')           { phone='800-374-7317 Call Us'; opHours = '7 am - 5 pm PST M-F'; }
		if ( product === 'QBOA')          { phone='888-333-3451 Call Us'; opHours = '6 am - 6 pm PST M-F'; }
		if ( product === 'ISW')           { phone='888-333-3451 Call Us'; opHours = '6 am - 6 pm PST M-F'; }
		
		message += '<div id="gs-msg">';
		message += '<div id="gs_call_icon"></div>';
		message += '<div class="gs-msg-box">';
		message += '<div class="gs-msg-text">We have determined by the complexity of your question, that it would be resolved faster by speaking with an agent.</div>';
		message += '<div id="call_button">' + phone + '</div>';
		message += '<div id="gs-msg-hours">' + opHours + '</div>';
		message += '</div>';
		message += '</div>';
	}
	if ( type === 'service' ) {
		var phone = '';
		var opHours = '';
		if ( product === 'LACERTE_TAX')   { phone='800-933-9999 Call Us'; opHours = '<a href="http://my.lacerte.intuit.com/support/document.aspx?product=LACERTE_TAX&id=GEN59713">Hours of Operation</a>'; }
		if ( product === 'LACERTE_PTI')   { phone='800-933-9999 Call Us'; opHours = '<a href="http://my.lacerte.intuit.com/support/document.aspx?product=LACERTE_TAX&id=GEN59713">Hours of Operation</a>'; }
		if ( product === 'PROSERIES_TAX') { phone='800-374-7317 Call Us'; opHours = '<a href="http://my.proseries.intuit.com/support/document.aspx?product=PROSERIES_TAX&id=GEN70312">Hours of Operation</a>'; }
		if ( product === 'PROSERIES_PTI') { phone='800-374-7317 Call Us'; opHours = '<a href="http://my.proseries.intuit.com/support/document.aspx?product=PROSERIES_TAX&id=GEN70312">Hours of Operation</a>'; }
		if ( product === 'EASYACCT')      { phone='866-220-0488 Call Us'; opHours = '<a href="http://accountant.intuit.com/support/easyacct/document.aspx?product=EASYACCT&id=GEN56768">Hours of Operation</a>'; }
		if ( product === 'QBAE')          { phone='<a href="http://accountant.intuit.com/support/contact_choice.aspx">Contact Options</a>'; opHours = '<a href="http://accountant.intuit.com/support/contact_choice.aspx">Hours of Operation</a>'; }
		if ( product === 'PTO')           { phone='N/A'; opHours = '<a href="http://accountant.intuit.com/support/prolinetaxonline/document.aspx?product=PTO&id=GEN70962">Hours of Operation</a>'; } //Available for chat only
		if ( product === 'PTR')           { phone='800-933-9999 Call Us'; opHours = '<a href="http://my.lacerte.intuit.com/support/document.aspx?product=LACERTE_TAX&id=GEN59713">Hours of Operation</a>'; }
		if ( product === 'PPM')           { phone='800-374-7317 Call Us'; opHours = '7 am - 5 pm PST M-F'; }
		if ( product === 'QBOA')          { phone='888-333-3451 Call Us'; opHours = '6 am - 6 pm PST M-F'; }
		if ( product === 'ISW')           { phone='888-333-3451 Call Us'; opHours = '6 am - 6 pm PST M-F'; }
		
		message += '<div id="gs-msg">';
		message += '<div id="gs_call_icon"></div>';
		message += '<div class="gs-msg-box">';
		message += '<div class="gs-msg-text">We have determined by the complexity of your question, that it would be resolved faster by speaking with an agent.</div>';
		message += '<div id="call_button">' + phone + '</div>';
		message += '<div id="gs-msg-hours">' + opHours + '</div>';
		message += '</div>';
		message += '</div>';
	}
	if ( type === 'chat' ) {
		var chatcode = '';
		var opHours = '';
		if ( 1 === 1 ) {
			if ( product === 'LACERTE_TAX')   { chatcode='<div id="chat_button"><div id="' + buttondiv + '"><script type="text/javascript">if (typeof(lpUnit)=="undefined") var lpUnit="apd-all";if (typeof(lpLanguage)=="undefined") var lpLanguage="english";lpAddVars("<Scope:page/session/visitor>","<Variable Name>","<Variable Value>");lpAddVars("page","Section","Support");lpAddVars("visitor","LoginID","Lacerte");lpAddVars("page","Site","Lacerte");lpAddVars("page","Product","<Variable Value>");lpAddVars("page","ProductYear","<Variable Value>");lpAddVars("page","Kbsubmit","<Variable Value>");lpAddVars("page","Page","<Variable Value>");lpAddVars("page","NoChat","<Variable Value>");</script></div></div>'; }
			if ( product === 'EASYACCT')      { chatcode=''; } //No Chat Queue
			if ( product === 'LACERTE_PTI')   { chatcode='<div id="chat_button"><div id="' + buttondiv + '"><script type="text/javascript">if (typeof(lpUnit)==\'undefined\') var lpUnit=\'apd-Lacerte-technical-sys\';if (typeof(lpLanguage)==\'undefined\') var lpLanguage=\'english\';lpAddVars(\'<Scope:page/session/visitor>\',\'<Variable Name>\',\'<Variable Value>\');lpAddVars(\'page\',\'Section\',\'Support\');lpAddVars(\'visitor\',\'LoginID\',\'Lacerte\');lpAddVars(\'page\',\'Site\',\'Lacerte\');lpAddVars(\'page\',\'Product\',\'<Variable Value>\');lpAddVars(\'page\',\'ProductYear\',\'<Variable Value>\');lpAddVars(\'page\',\'Kbsubmit\',\'<Variable Value>\');lpAddVars(\'page\',\'Page\',\'<Variable Value>\');lpAddVars(\'page\',\'NoChat\',\'<Variable Value>\');</script></div></div>'; }
			if ( product === 'PROSERIES_TAX') { chatcode='<div id="chat_button"><div id="' + buttondiv + '"><script type="text/javascript">if (typeof(lpUnit)==\'undefined\') var lpUnit=\'apd-all\';if (typeof(lpLanguage)==\'undefined\') var lpLanguage=\'english\';lpAddVars(\'<Scope:page/session/visitor>\',\'<Variable Name>\',\'<Variable Value>\');lpAddVars(\'page\',\'Section\',\'Support\');lpAddVars(\'visitor\',\'LoginID\',\'Proseries\');lpAddVars(\'page\',\'Site\',\'Proseries\');lpAddVars(\'page\',\'Product\',\'<Variable Value>\');lpAddVars(\'page\',\'ProductYear\',\'<Variable Value>\');lpAddVars(\'page\',\'Kbsubmit\',\'<Variable Value>\');lpAddVars(\'page\',\'Page\',\'<Variable Value>\');lpAddVars(\'page\',\'NoChat\',\'<Variable Value>\');</script></div></div>'; }
			if ( product === 'PROSERIES_PTI') { chatcode='<div id="chat_button"><div id="' + buttondiv + '"><script type="text/javascript">if (typeof(lpUnit)==\'undefined\') var lpUnit=\'apd-ProSeries-technical-sys\';if (typeof(lpLanguage)==\'undefined\') var lpLanguage=\'english\';lpAddVars(\'<Scope:page/session/visitor>\',\'<Variable Name>\',\'<Variable Value>\');lpAddVars(\'page\',\'Section\',\'Support\');lpAddVars(\'visitor\',\'LoginID\',\'Proseries\');lpAddVars(\'page\',\'Site\',\'Proseries\');lpAddVars(\'page\',\'Product\',\'<Proseries>\');lpAddVars(\'page\',\'ProductYear\',\'<Variable Value>\');lpAddVars(\'page\',\'Kbsubmit\',\'<Variable Value>\');lpAddVars(\'page\',\'Page\',\'<Variable Name>\');lpAddVars(\'page\',\'NoChat\',\'<Variable Value>\');</script></div></div>'; }
			//if ( product === 'QBAE')          { chatcode='<div id="chat_button"><div id="' + buttondiv + '"><script type="text/javascript">if (typeof(lpUnit)==\'undefined\') var lpUnit=\'apd-proadvisor\';if (typeof(lpLanguage)==\'undefined\') var lpLanguage=\'english\';lpAddVars(\'<Scope:page/session/visitor>\',\'<Variable Name>\',\'<Variable Value>\');lpAddVars(\'page\',\'Section\',\'Support\');lpAddVars(\'visitor\',\'LoginID\',\'Proadvisor\');lpAddVars(\'page\',\'Site\',\'<Variable Value>\');lpAddVars(\'page\',\'Product\',\'<Variable Value>\');lpAddVars(\'page\',\'ProductYear\',\'<Variable Value>\');lpAddVars(\'page\',\'Kbsubmit\',\'<Variable Value>\');lpAddVars(\'page\',\'Page\',\'<Variable Value>\');lpAddVars(\'page\',\'NoChat\',\'<Variable Value>\');</script></div></div>'; }
			if ( product === 'QBAE')          { chatcode='<div id="gs-msg-chatlink">Visit <a href="http://accountant.intuit.com/support/contact_choice.aspx">this page</a> and log in to chat<br /></div>'; }
			if ( product === 'PTO')           { chatcode='<div id="chat_button"><div id="' + buttondiv + '"><script type="text/javascript">if (typeof(lpUnit)==\'undefined\') var lpUnit=\'apd-pto\';if (typeof(lpLanguage)==\'undefined\') var lpLanguage=\'english\';lpAddVars(\'<Scope:page/session/visitor>\',\'<Variable Name>\',\'<Variable Value>\');lpAddVars(\'page\',\'Section\',\'Support\');lpAddVars(\'visitor\',\'LoginID\',\'<Variable Value>\');lpAddVars(\'page\',\'Site\',\'Proseries\');lpAddVars(\'page\',\'Product\',\'<Variable Value>\');lpAddVars(\'page\',\'ProductYear\',\'<Variable Value>\');lpAddVars(\'page\',\'Kbsubmit\',\'<Variable Value>\');lpAddVars(\'page\',\'Page\',\'<Variable Value>\');lpAddVars(\'page\',\'NoChat\',\'<Variable Value>\');</script></div></div>'; }
			if ( product === 'PTR')           { chatcode=''; } //No Chat Queue
			if ( product === 'PPM')           { chatcode='<div id="chat_button"><div id="' + buttondiv + '"><script type="text/javascript">if (typeof(lpUnit)==\'undefined\') var lpUnit=\'apd-ppm\';if (typeof(lpLanguage)==\'undefined\') var lpLanguage=\'english\';lpAddVars(\'<Scope:page/session/visitor>\',\'<Variable Name>\',\'<Variable Value>\');lpAddVars(\'page\',\'Section\',\'Support\');lpAddVars(\'visitor\',\'LoginID\',\'Proadvisor\');lpAddVars(\'page\',\'Site\',\'Proadvisor\');lpAddVars(\'page\',\'Product\',\'<Variable Value>\');lpAddVars(\'page\',\'ProductYear\',\'<Variable Value>\');lpAddVars(\'page\',\'Kbsubmit\',\'<Variable Value>\');lpAddVars(\'page\',\'Page\',\'<Variable Value>\');lpAddVars(\'page\',\'NoChat\',\'<Variable Value>\');</script></div></div>'; }
			if ( product === 'QBOA')          { chatcode=''; } //No Chat Queue
			if ( product === 'ISW')           { chatcode=''; } //No Chat Queue
		} else {
			if ( product === 'LACERTE_TAX')   { chatcode='<div id="gs-msg-chatlink">Visit <a href="http://my.lacerte.intuit.com/contact_us/contact_choice.aspx">this page</a> and select the chat button<br /></div>'; }
			if ( product === 'EASYACCT')      { chatcode=''; } //No Chat Queue
			if ( product === 'LACERTE_PTI')   { chatcode='<div id="gs-msg-chatlink">Visit <a href="http://my.lacerte.intuit.com/support/ProlineTaxImport/">this page</a> and select the chat button<br /></div>'; }
			if ( product === 'PROSERIES_TAX') { chatcode='<div id="gs-msg-chatlink">Visit <a href="http://my.proseries.intuit.com/contact_us/contact_choice.aspx">this page</a> and select the chat button<br /></div>'; }
			if ( product === 'PROSERIES_PTI') { chatcode='<div id="gs-msg-chatlink">Visit <a href="http://my.proseries.intuit.com/support/ProlineTaxImport/">this page</a> and select the chat button<br /></div>'; }
			if ( product === 'QBAE')          { chatcode='<div id="gs-msg-chatlink">Visit <a href="http://accountant.intuit.com/support/contact_choice.aspx">this page</a> and select the chat button<br /></div>'; }
			if ( product === 'PTO')           { chatcode='<div id="gs-msg-chatlink">Visit <a href="http://accountant.intuit.com/support/prolinetaxonline/">this page</a> and select the chat button<br /></div>'; }
			if ( product === 'PTR')           { chatcode=''; } //No Chat Queue
			if ( product === 'PPM')           { chatcode='<div id="gs-msg-chatlink">Visit <a href="http://accountant.intuit.com/support/practicemanagement/index.aspx">this page</a> and select the chat button<br /></div>'; }
			if ( product === 'QBOA')          { chatcode=''; } //No Chat Queue
			if ( product === 'ISW')           { chatcode=''; } //No Chat Queue
		}
		if ( product === 'LACERTE_TAX')   { opHours = '<a href="http://my.lacerte.intuit.com/support/document.aspx?product=LACERTE_TAX&id=INF13927">Hours of Operation</a>'; }
		if ( product === 'LACERTE_PTI')   { opHours = '<a href="http://my.lacerte.intuit.com/support/document.aspx?product=LACERTE_TAX&id=INF13927">Hours of Operation</a>'; }
		if ( product === 'PROSERIES_TAX') { opHours = '<a href="http://my.proseries.intuit.com/support/document.aspx?product=PROSERIES_TAX&id=INF13878">Hours of Operation</a>'; }
		if ( product === 'PROSERIES_PTI') { opHours = '<a href="http://my.proseries.intuit.com/support/document.aspx?product=PROSERIES_TAX&id=INF13878">Hours of Operation</a>'; }
		if ( product === 'EASYACCT')      { opHours = '<a href="http://accountant.intuit.com/support/easyacct/document.aspx?product=EASYACCT&id=GEN56768">Hours of Operation</a>'; }
		if ( product === 'QBAE')          { opHours = '<a href="http://accountant.intuit.com/support/contact_choice.aspx">Hours of Operation</a>'; }
		if ( product === 'PTO')           { opHours = '<a href="http://accountant.intuit.com/support/prolinetaxonline/document.aspx?product=PTO&id=GEN70962">Hours of Operation</a>'; } //Available for chat only
		if ( product === 'PTR')           { opHours = '<a href="http://my.lacerte.intuit.com/support/document.aspx?product=LACERTE_TAX&id=GEN59713">Hours of Operation</a>'; }
		if ( product === 'PPM')           { opHours = '7 am - 5 pm PST M-F'; }
		if ( product === 'QBOA')          { opHours = '6 am - 6 pm PST M-F'; }
		if ( product === 'ISW')           { opHours = '6 am - 6 pm PST M-F'; }
		
		//alert(chatcode);
		message += '<div id="gs-msg">';
		message += '<div id="gs_chat_icon"></div>';
		message += '<div class="gs-msg-box">';
		message += '<div class="gs-msg-text">We have determined by the complexity of your question, that it would be resolved faster by chatting with an agent.</div>';
		message += chatcode;
		message += '<div id="gs-msg-hours">' + opHours + '</div>';
		message += '</div>';
		message += '</div>';
	}
	if ( type === 'chatservice' ) {
		var chatcode = '';
		var opHours = '';
		if ( 1 === 1 ) {
			if ( product === 'LACERTE_TAX')   { chatcode='<div id="chat_button"><div id="' + buttondiv + '"><script type="text/javascript">if (typeof(lpUnit)=="undefined") var lpUnit="apd-all";if (typeof(lpLanguage)=="undefined") var lpLanguage="english";lpAddVars("<Scope:page/session/visitor>","<Variable Name>","<Variable Value>");lpAddVars("page","Section","Support");lpAddVars("visitor","LoginID","Lacerte");lpAddVars("page","Site","Lacerte");lpAddVars("page","Product","<Variable Value>");lpAddVars("page","ProductYear","<Variable Value>");lpAddVars("page","Kbsubmit","<Variable Value>");lpAddVars("page","Page","<Variable Value>");lpAddVars("page","NoChat","<Variable Value>");</script></div></div>'; }
			if ( product === 'EASYACCT')      { chatcode=''; } //No Chat Queue
			if ( product === 'LACERTE_PTI')   { chatcode='<div id="chat_button"><div id="' + buttondiv + '"><script type="text/javascript">if (typeof(lpUnit)==\'undefined\') var lpUnit=\'apd-Lacerte-technical-sys\';if (typeof(lpLanguage)==\'undefined\') var lpLanguage=\'english\';lpAddVars(\'<Scope:page/session/visitor>\',\'<Variable Name>\',\'<Variable Value>\');lpAddVars(\'page\',\'Section\',\'Support\');lpAddVars(\'visitor\',\'LoginID\',\'Lacerte\');lpAddVars(\'page\',\'Site\',\'Lacerte\');lpAddVars(\'page\',\'Product\',\'<Variable Value>\');lpAddVars(\'page\',\'ProductYear\',\'<Variable Value>\');lpAddVars(\'page\',\'Kbsubmit\',\'<Variable Value>\');lpAddVars(\'page\',\'Page\',\'<Variable Value>\');lpAddVars(\'page\',\'NoChat\',\'<Variable Value>\');</script></div></div>'; }
			if ( product === 'PROSERIES_TAX') { chatcode='<div id="chat_button"><div id="' + buttondiv + '"><script type="text/javascript">if (typeof(lpUnit)==\'undefined\') var lpUnit=\'apd-all\';if (typeof(lpLanguage)==\'undefined\') var lpLanguage=\'english\';lpAddVars(\'<Scope:page/session/visitor>\',\'<Variable Name>\',\'<Variable Value>\');lpAddVars(\'page\',\'Section\',\'Support\');lpAddVars(\'visitor\',\'LoginID\',\'Proseries\');lpAddVars(\'page\',\'Site\',\'Proseries\');lpAddVars(\'page\',\'Product\',\'<Variable Value>\');lpAddVars(\'page\',\'ProductYear\',\'<Variable Value>\');lpAddVars(\'page\',\'Kbsubmit\',\'<Variable Value>\');lpAddVars(\'page\',\'Page\',\'<Variable Value>\');lpAddVars(\'page\',\'NoChat\',\'<Variable Value>\');</script></div></div>'; }
			if ( product === 'PROSERIES_PTI') { chatcode='<div id="chat_button"><div id="' + buttondiv + '"><script type="text/javascript">if (typeof(lpUnit)==\'undefined\') var lpUnit=\'apd-ProSeries-technical-sys\';if (typeof(lpLanguage)==\'undefined\') var lpLanguage=\'english\';lpAddVars(\'<Scope:page/session/visitor>\',\'<Variable Name>\',\'<Variable Value>\');lpAddVars(\'page\',\'Section\',\'Support\');lpAddVars(\'visitor\',\'LoginID\',\'Proseries\');lpAddVars(\'page\',\'Site\',\'Proseries\');lpAddVars(\'page\',\'Product\',\'<Proseries>\');lpAddVars(\'page\',\'ProductYear\',\'<Variable Value>\');lpAddVars(\'page\',\'Kbsubmit\',\'<Variable Value>\');lpAddVars(\'page\',\'Page\',\'<Variable Name>\');lpAddVars(\'page\',\'NoChat\',\'<Variable Value>\');</script></div></div>'; }
			//if ( product === 'QBAE')          { chatcode='<div id="chat_button"><div id="' + buttondiv + '"><script type="text/javascript">if (typeof(lpUnit)==\'undefined\') var lpUnit=\'apd-proadvisor\';if (typeof(lpLanguage)==\'undefined\') var lpLanguage=\'english\';lpAddVars(\'<Scope:page/session/visitor>\',\'<Variable Name>\',\'<Variable Value>\');lpAddVars(\'page\',\'Section\',\'Support\');lpAddVars(\'visitor\',\'LoginID\',\'Proadvisor\');lpAddVars(\'page\',\'Site\',\'<Variable Value>\');lpAddVars(\'page\',\'Product\',\'<Variable Value>\');lpAddVars(\'page\',\'ProductYear\',\'<Variable Value>\');lpAddVars(\'page\',\'Kbsubmit\',\'<Variable Value>\');lpAddVars(\'page\',\'Page\',\'<Variable Value>\');lpAddVars(\'page\',\'NoChat\',\'<Variable Value>\');</script></div></div>'; }
			if ( product === 'QBAE')          { chatcode='<div id="gs-msg-chatlink">Visit <a href="http://accountant.intuit.com/support/contact_choice.aspx">this page</a> and log in to chat<br /></div>'; }
			if ( product === 'PTO')           { chatcode='<div id="chat_button"><div id="' + buttondiv + '"><script type="text/javascript">if (typeof(lpUnit)==\'undefined\') var lpUnit=\'apd-pto\';if (typeof(lpLanguage)==\'undefined\') var lpLanguage=\'english\';lpAddVars(\'<Scope:page/session/visitor>\',\'<Variable Name>\',\'<Variable Value>\');lpAddVars(\'page\',\'Section\',\'Support\');lpAddVars(\'visitor\',\'LoginID\',\'<Variable Value>\');lpAddVars(\'page\',\'Site\',\'Proseries\');lpAddVars(\'page\',\'Product\',\'<Variable Value>\');lpAddVars(\'page\',\'ProductYear\',\'<Variable Value>\');lpAddVars(\'page\',\'Kbsubmit\',\'<Variable Value>\');lpAddVars(\'page\',\'Page\',\'<Variable Value>\');lpAddVars(\'page\',\'NoChat\',\'<Variable Value>\');</script></div></div>'; }
			if ( product === 'PTR')           { chatcode=''; } //No Chat Queue
			if ( product === 'PPM')           { chatcode='<div id="chat_button"><div id="' + buttondiv + '"><script type="text/javascript">if (typeof(lpUnit)==\'undefined\') var lpUnit=\'apd-ppm\';if (typeof(lpLanguage)==\'undefined\') var lpLanguage=\'english\';lpAddVars(\'<Scope:page/session/visitor>\',\'<Variable Name>\',\'<Variable Value>\');lpAddVars(\'page\',\'Section\',\'Support\');lpAddVars(\'visitor\',\'LoginID\',\'Proadvisor\');lpAddVars(\'page\',\'Site\',\'Proadvisor\');lpAddVars(\'page\',\'Product\',\'<Variable Value>\');lpAddVars(\'page\',\'ProductYear\',\'<Variable Value>\');lpAddVars(\'page\',\'Kbsubmit\',\'<Variable Value>\');lpAddVars(\'page\',\'Page\',\'<Variable Value>\');lpAddVars(\'page\',\'NoChat\',\'<Variable Value>\');</script></div></div>'; }
			if ( product === 'QBOA')          { chatcode=''; } //No Chat Queue
			if ( product === 'ISW')           { chatcode=''; } //No Chat Queue
		}
		if ( product === 'LACERTE_TAX')   { opHours = '<a href="http://my.lacerte.intuit.com/support/document.aspx?product=LACERTE_TAX&id=INF13927">Hours of Operation</a>'; }
		if ( product === 'LACERTE_PTI')   { opHours = '<a href="http://my.lacerte.intuit.com/support/document.aspx?product=LACERTE_TAX&id=INF13927">Hours of Operation</a>'; }
		if ( product === 'PROSERIES_TAX') { opHours = '<a href="http://my.proseries.intuit.com/support/document.aspx?product=PROSERIES_TAX&id=INF13878">Hours of Operation</a>'; }
		if ( product === 'PROSERIES_PTI') { opHours = '<a href="http://my.proseries.intuit.com/support/document.aspx?product=PROSERIES_TAX&id=INF13878">Hours of Operation</a>'; }
		if ( product === 'EASYACCT')      { opHours = '<a href="http://accountant.intuit.com/support/easyacct/document.aspx?product=EASYACCT&id=GEN56768">Hours of Operation</a>'; }
		if ( product === 'QBAE')          { opHours = '<a href="http://accountant.intuit.com/support/contact_choice.aspx">Hours of Operation</a>'; }
		if ( product === 'PTO')           { opHours = '<a href="http://accountant.intuit.com/support/prolinetaxonline/document.aspx?product=PTO&id=GEN70962">Hours of Operation</a>'; } //Available for chat only
		if ( product === 'PTR')           { opHours = '<a href="http://my.lacerte.intuit.com/support/document.aspx?product=LACERTE_TAX&id=GEN59713">Hours of Operation</a>'; }
		if ( product === 'PPM')           { opHours = '7 am - 5 pm PST M-F'; }
		if ( product === 'QBOA')          { opHours = '6 am - 6 pm PST M-F'; }
		if ( product === 'ISW')           { opHours = '6 am - 6 pm PST M-F'; }
		
		//alert(chatcode);
		message += '<div id="gs-msg">';
		message += '<div id="gs_chat_icon"></div>';
		message += '<div class="gs-msg-box">';
		message += '<div class="gs-msg-text">We have determined by the complexity of your question, that it would be resolved faster by chatting with an agent. After initiating chat, select Orders and Billing.</div>';
		message += chatcode;
		message += '<div id="gs-msg-hours">' + opHours + '</div>';
		message += '</div>';
		message += '</div>';
	}
	if ( type === 'clarify' ) {
		message += '<div id="gs-msg">';
		message += '<div id="gs_question_icon"></div>';
		message += '<div class="gs-msg-box">';
		message += '<div class="gs-msg-text">In order to determine the best way to answer your question, we need to ask you a few clarifying questions. May we do that now?<br />';
		message += '<div class="gs-yn">';
		message += '<a href="" onClick="$.modal.close(); return false;">No</a>';
		message += '<a href="" onClick="$.modal.close(); doPWYesClick(); return false;">Yes</a> ';
		message += '</div>';
		message += '</div>';
		message += '</div>';
		message += '</div>';
	}
	
	return message;
}

function getMedSurveyLink(product, answer) {
	var survey = '';
	if ( answer === 'y') {
		if ( product === 'LACERTE_TAX')   { survey='http://survey.medallia.com/?intuit-without-chat&product=1'; }
		if ( product === 'EASYACCT')      { survey='http://survey.medallia.com/?intuit-without-chat&product=4'; }
		if ( product === 'LACERTE_PTI')   { survey=''; }
		if ( product === 'PROSERIES_TAX') { survey='http://survey.medallia.com/?intuit-without-chat&product=2'; }
		if ( product === 'PROSERIES_PTI') { survey=''; }
		if ( product === 'QBAE')          { survey='http://survey.medallia.com/?intuit-without-chat&product=3'; }
		if ( product === 'PTO')           { survey='http://survey.medallia.com/?intuit-without-chat&product=5'; }
		if ( product === 'PTR')           { survey=''; }
		if ( product === 'PPM')           { survey=''; }
		if ( product === 'QBOA')          { survey=''; }
		if ( product === 'ISW')           { survey=''; }
	}
	if ( answer === 'n') {
		if ( product === 'LACERTE_TAX')   { survey='http://survey.medallia.com/?intuit-with-chat&product=1'; }
		if ( product === 'EASYACCT')      { survey='http://survey.medallia.com/?intuit-with-chat&product=4'; }
		if ( product === 'LACERTE_PTI')   { survey=''; }
		if ( product === 'PROSERIES_TAX') { survey='http://survey.medallia.com/?intuit-with-chat&product=2'; }
		if ( product === 'PROSERIES_PTI') { survey=''; }
		if ( product === 'QBAE')          { survey='http://survey.medallia.com/?intuit-with-chat&product=3'; }
		if ( product === 'PTO')           { survey='http://survey.medallia.com/?intuit-with-chat&product=5'; }
		if ( product === 'PTR')           { survey=''; }
		if ( product === 'PPM')           { survey=''; }
		if ( product === 'QBOA')          { survey=''; }
		if ( product === 'ISW')           { survey=''; }
	}
	return survey;
}

function doLinkClick(articleid) {
	var myurl = baseArticleUrl();
	var paramprefix = '?';
	var myproduct = getParm("product", window.location.href );
	if( myproduct != "" ) {
		myurl += paramprefix + 'product=' + myproduct;
		paramprefix = '&';
	}
	myurl += paramprefix + 'id=' + articleid;
	self.location=myurl;
}

function saveArticleSurvey(surveyaddr2, formData) {
	logEvent('Survey','Post',formData);
	$.post(surveyaddr2, formData, function(data) {},"text/plain");
}

function doProcessWizard(wizname, wizstep) {
	//alert("Processing Wizard " + wizname + "step " + wizstep); 
	logEvent('PW',wizname,wizstep);
	
	var wizardFnName = "getWizard" + wizname;
	var wizdata = window[wizardFnName]();
	var transContent = '';
	var gscontent = '';
	
	var content = '<h1>' + wizdata.label + '</h1>';
	content += '<form name="wizardStep" method="get" action="" onsubmit="return false;">';
	content += '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
	content += '<tbody>';
	content += '<tr>';
	content += '<td valign="top">';

	var fieldid = '';
	var wlhref = window.location.href;
	wlhref = wlhref.replace(/'/,"%27"); //IE errors with Apostrophe in URL
	
	$.each(wizdata.steps, function(s, mystep){
		if (mystep.id == wizstep ) {
			$.each(mystep.fields, function(f, field){
				//alert("wizstep=" + wizstep + " Wiz type=" + field.type);
				
				//Guided Support Managed Answer for Phones - Add to top of results
				gsactivated = 0;
				if (field.description.indexOf("<!-- GS -->") != -1 ) {
					gsactivated = 1;
					content += '<br clear="all">';
					content += '<div id="gs-div-onpage">';
					gscontent += getGSMessageText('phone');
					content += gscontent;
					content += '</div>';
					logEvent('Guided Support', 'Phone Redirect Banner', wizname + '-' + wizstep, 0);
				}
				if (field.description.indexOf("<!-- GS-CS -->") != -1 ) {
					gsactivated = 1;
					content += '<br clear="all">';
					content += '<div id="gs-div-onpage">';
					gscontent += getGSMessageText('service');
					content += gscontent;
					content += '</div>';
					logEvent('Guided Support', 'Phone Redirect Banner', wizname + '-' + wizstep, 1);
				}

				//Guided Support Managed Answer for Chat - Add to top of results
				if (field.description.indexOf("<!-- GSC -->") != -1 ) {
					gsactivated = 1;
					content += '<br clear="all">';
					content += '<div id="gs-div-onpage">';
					gscontent += getGSMessageText('chat');
					content += gscontent;
					content += '</div>';
					logEvent('Guided Support', 'Chat Redirect Banner', wizname + '-' + wizstep, 0);
				}
				
				if ( gsactivated === 0 ) {
					if ( field.type == "html" ) {
						content += '<div class="im-wizard-excerpt-block">' + field.description + '</div>';
					}
				}
				
				if ( field.type == "radio" ) {
					content += '<div>' + field.description + '</div>';
					$.each(field.options, function(i,option){
						content += '<div><input class="radiofields" value="' + option.value + '" type="radio" name="' + field.id + '">' + option.text + '</div>';
					});
					fieldid = field.id;
				}
				if ( field.type == "checkbox" ) {
					$.each(field.options, function(i,option){
						content += '<div><input class="checkboxfields" value="' + option.value + '" type="checkbox" name="' + field.id + '">' + option.text + '</div>';
					});
				}
				if ( field.type == "search" ) {
					content += '<div>' + field.type + ' question type not yet supported.</div>';
				}
				if ( field.type == "select" ) {
					content += '<div>';
					content += '<select name="' + field.id + '" class="dropdown" >';
					$.each(field.options, function(i,option){
						content += '<div><option value="' + option.value + '">' + option.text + '</option></div>';
					});
					content += '</select>';
					content += '</div>';
					fieldid = field.id;
				}
				if ( field.type == "text" ) {
					content += '<div><input class="editfields" value="" type="text" name="' + field.id + '"></div>';
				}
				//if ( field.type == "true_false_radio" ) {
				//	content += '<div>' + field.type + ' question type not yet supported.</div>';
				//}
				//if ( field.type == "yes_no_radio" ) {
				//	content += '<div>' + field.type + ' question type not yet supported.</div>';
				//}
			});
			content += '<br />';
			content += "<button type=\"submit\" name=\"inqcancel\" onClick=\"self.location = '" + wlhref + "';\">Cancel</button>";

			//radioValue = getCheckedValue(document.forms["wizardStep"].elements[fieldid]);

			transContent = 'var nextStep=""; ';
			var transFound = 0;

			$.each(mystep.transitions, function(t, transition){
				transFound = 1;
				if ( transition.condition !== null ) {
					transContent += 'if ( checkedValue =="' + transition.condition.value + '") { nextStep ="' + transition.step + '"; } ';
				} else {
					transContent += 'nextStep ="' + transition.step + '"; ';
				}
			});

			var theValue = "var prevStep = popPWStack(); if (prevStep == '') { self.location = '" + wlhref + "'; } else { doProcessWizard('" + wizname + "',prevStep); };";
			content += '<button type="submit" name="inqprev" onClick="' + theValue + '">Back</button>';
			if ( transFound == 1 ) {
				theValue = "getCheckedValue(document.forms['wizardStep'].elements['" + fieldid + "'])";
				content += '<button type="submit" class="button-feature" name="inqnext" onClick="doTransition(' + theValue + ');">Next</button>';
			} else {
				theValue = "self.location = '" + window.location.href + "';";
				content += '<button type="submit" class="button-feature" name="inqfini" onClick="' + theValue + '">Finish</button>';
			}
			transContent += 'if (nextStep != "" ) {';
			transContent += 'pushPWStack("' + wizstep + '");';

			//Log the transition between PW Steps
			transContent += 'logEvent("PW Transition","' + wizname + '","' + wizstep + '-" + nextStep);';

			transContent += 'doProcessWizard("' + wizname + '", nextStep);';
			transContent += '} else { alert("Please make a selection");}';
		}
	});

	content += '</td>';
	content += '</tr>';
	content += '</tbody>';
	content += '</table>';
	content += '</form>';
	content += '<script>function doTransition(checkedValue) {' + transContent + '}; </script>';
	//alert(content);
	//alert(transContent);
	ResultsCallback(content);
}

var PWstack = new Array(); 

function pushPWStack(newVal) { 
	PWstack.push(newVal); 
} 

function popPWStack() { 
	var popVal = PWstack.pop(); 
	if (popVal === undefined) {
		return ""; 
	} else { 
		return popVal; 
	}
} 

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj) {
		return "";
	}
	var radioLength = radioObj.length;
	if(radioLength === undefined) {
		if(radioObj.checked) {
			return radioObj.value;
		} else {
			return "";
		}
	}
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
		if(radioObj[i].selected) {
			return radioObj[i].value;
		}
	}
	return "";
}

function getParm( wantedParm, url ) {
	var theResults = '';
	var name = wantedParm;
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( url );
	if( results !== null ) {
		theResults = results[1];
	}
	return theResults; 
}

function validateRating() {
	var ratingTable = document.getElementById('ratingtable');
	var radioCount = 0;
	var radioName = "";
	var checkedCount = 0;
	var ratingOptions = ratingTable.getElementsByTagName('input');
	for (var i = 0; i < ratingOptions.length; i++) {
		if (ratingOptions[i].getAttribute('type').toLowerCase() == 'radio') {
			if (radioName != ratingOptions[i].getAttribute('name')) {
				radioCount++;
				radioName = ratingOptions[i].getAttribute('name');
			}
			if (ratingOptions[i].checked) {
				checkedCount++;
			}
		}
	}
	if (radioCount == checkedCount) {
		return true;
	} else {
		return false;
	}
}

function PrintContent() {
	var DocumentContainer = document.getElementById('lawcontent');
	var WindowObject = window.open('', 'PrintWindow', 'width=750,height=650,top=50,left=50,toolbars=yes,scrollbars=yes,status=no,resizable=yes');
	//var html  = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"><html><head>" + "<link rel='stylesheet' type='text/css' href='http://aicqaws1.lab.plano.intuit.com/common/styles/law.css' />" + "</head><body>" + DocumentContainer.innerHTML + "</body></html>";
	WindowObject.document.writeln( DocumentContainer.innerHTML);
	WindowObject.document.close();
	WindowObject.focus();
	WindowObject.print();
	WindowObject.close();
	var u = window.location;
	logEvent('Print', u, '', 0);
}

function mailThisUrl() {
	//r = document.referrer;
	var u = window.location;
	logEvent('Mail', u, '', 0);
	window.location = "mailto:?subject=Intuit Support Article&body=" +escape(u);
}

function clear_form_elements(ele) {
	$(ele).find(':input').each(function() {
		switch(this.type) {
			case 'password':
			case 'select-multiple':
			case 'select-one':
			case 'text':
			case 'textarea':
				$(this).val('');
				break;
			case 'checkbox':
			case 'radio':
				this.checked = false;
		}
	});
}

function logEvent(category, action, label, value) {
	//alert("Logging: Category=" + category + ", Action=" + action + ", Label=" + label + ", Value=" + value);
	if (_gaq) {
		_gaq.push(['_trackEvent', category, action, label, value]);
	//} else {
	//	alert("No gaq");
	}
}

function doExternal(category, action, label) {
	logEvent(category, action, label);
	setTimeout(function() { window.open(label, "mywindow","status=1,toolbar=1,location=1,resizable=1,scrollbars=1"); }, 300);
	return false;
}

// Live Community Code -----------------------------------------------------------------------

//Code to get LIVE COMMUNITY "Ask your Question" results
//params = "";
function doLCSearch(searchTerm, product, resultFrame) {

	var urlSignature = "http://community.intuit.com/atc/post/new_mini?from=newpost&subject=<searchTerm>%0A&widget_id=bFjQqIFQyr3zw-abTJKvnX&category_id=<catID>";
	var url;
	//define the search term
	url = urlSignature.replace("<searchTerm>", searchTerm);

	//set the appropriate category ID based on product type
	if (product == "LACERTE_TAX") {
		url = url.replace("<catID>", 11);
	} else if (product == "PROSERIES_TAX") {
		url = url.replace("<catID>", 37);
	}else if (product == "QBAE") { 
		url = url = url.replace("<catID>", 1);
	}else if (product == "EASYACCT") { 
		url = url = url.replace("<catID>", 10);
	}else if (product == "PTO") { 
		url = url = url.replace("<catID>", 10249);
	}else if (product == "PTR") { 
		url = url = url.replace("<catID>", 12106);
	}else if (product == "PPM") { 
		url = url = url.replace("<catID>", 20553);
	}else if (product == "QBOA") { 
		url = url = url.replace("<catID>", 26005);
	}

	//getting HTML not working correctly using this -> liveCommunityRequest(url);  
	//instead, set the result frame location href

	//resultFrame.location.href = url;
	resultFrame.src = url;
}



































/*
    http://www.JSON.org/json2.js
    2010-08-25

    Public Domain.

    NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.

    See http://www.JSON.org/js.html


    This code should be minified before deployment.
    See http://javascript.crockford.com/jsmin.html

    USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
    NOT CONTROL.


    This file creates a global JSON object containing two methods: stringify
    and parse.

        JSON.stringify(value, replacer, space)
            value       any JavaScript value, usually an object or array.

            replacer    an optional parameter that determines how object
                        values are stringified for objects. It can be a
                        function or an array of strings.

            space       an optional parameter that specifies the indentation
                        of nested structures. If it is omitted, the text will
                        be packed without extra whitespace. If it is a number,
                        it will specify the number of spaces to indent at each
                        level. If it is a string (such as '\t' or '&nbsp;'),
                        it contains the characters used to indent at each level.

            This method produces a JSON text from a JavaScript value.

            When an object value is found, if the object contains a toJSON
            method, its toJSON method will be called and the result will be
            stringified. A toJSON method does not serialize: it returns the
            value represented by the name/value pair that should be serialized,
            or undefined if nothing should be serialized. The toJSON method
            will be passed the key associated with the value, and this will be
            bound to the value

            For example, this would serialize Dates as ISO strings.

                Date.prototype.toJSON = function (key) {
                    function f(n) {
                        // Format integers to have at least two digits.
                        return n < 10 ? '0' + n : n;
                    }

                    return this.getUTCFullYear()   + '-' +
                         f(this.getUTCMonth() + 1) + '-' +
                         f(this.getUTCDate())      + 'T' +
                         f(this.getUTCHours())     + ':' +
                         f(this.getUTCMinutes())   + ':' +
                         f(this.getUTCSeconds())   + 'Z';
                };

            You can provide an optional replacer method. It will be passed the
            key and value of each member, with this bound to the containing
            object. The value that is returned from your method will be
            serialized. If your method returns undefined, then the member will
            be excluded from the serialization.

            If the replacer parameter is an array of strings, then it will be
            used to select the members to be serialized. It filters the results
            such that only members with keys listed in the replacer array are
            stringified.

            Values that do not have JSON representations, such as undefined or
            functions, will not be serialized. Such values in objects will be
            dropped; in arrays they will be replaced with null. You can use
            a replacer function to replace those with JSON values.
            JSON.stringify(undefined) returns undefined.

            The optional space parameter produces a stringification of the
            value that is filled with line breaks and indentation to make it
            easier to read.

            If the space parameter is a non-empty string, then that string will
            be used for indentation. If the space parameter is a number, then
            the indentation will be that many spaces.

            Example:

            text = JSON.stringify(['e', {pluribus: 'unum'}]);
            // text is '["e",{"pluribus":"unum"}]'


            text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
            // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'

            text = JSON.stringify([new Date()], function (key, value) {
                return this[key] instanceof Date ?
                    'Date(' + this[key] + ')' : value;
            });
            // text is '["Date(---current time---)"]'


        JSON.parse(text, reviver)
            This method parses a JSON text to produce an object or array.
            It can throw a SyntaxError exception.

            The optional reviver parameter is a function that can filter and
            transform the results. It receives each of the keys and values,
            and its return value is used instead of the original value.
            If it returns what it received, then the structure is not modified.
            If it returns undefined then the member is deleted.

            Example:

            // Parse the text. Values that look like ISO date strings will
            // be converted to Date objects.

            myData = JSON.parse(text, function (key, value) {
                var a;
                if (typeof value === 'string') {
                    a =
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
                    if (a) {
                        return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
                            +a[5], +a[6]));
                    }
                }
                return value;
            });

            myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
                var d;
                if (typeof value === 'string' &&
                        value.slice(0, 5) === 'Date(' &&
                        value.slice(-1) === ')') {
                    d = new Date(value.slice(5, -1));
                    if (d) {
                        return d;
                    }
                }
                return value;
            });


    This is a reference implementation. You are free to copy, modify, or
    redistribute.
*/

/*jslint evil: true, strict: false */

/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
    call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
    getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
    lastIndex, length, parse, prototype, push, replace, slice, stringify,
    test, toJSON, toString, valueOf
*/


// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.

if (!this.JSON) {
    this.JSON = {};
}

(function () {

    function f(n) {
        // Format integers to have at least two digits.
        return n < 10 ? '0' + n : n;
    }

    if (typeof Date.prototype.toJSON !== 'function') {

        Date.prototype.toJSON = function (key) {

            return isFinite(this.valueOf()) ?
                   this.getUTCFullYear()   + '-' +
                 f(this.getUTCMonth() + 1) + '-' +
                 f(this.getUTCDate())      + 'T' +
                 f(this.getUTCHours())     + ':' +
                 f(this.getUTCMinutes())   + ':' +
                 f(this.getUTCSeconds())   + 'Z' : null;
        };

        String.prototype.toJSON =
        Number.prototype.toJSON =
        Boolean.prototype.toJSON = function (key) {
            return this.valueOf();
        };
    }

    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        gap,
        indent,
        meta = {    // table of character substitutions
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        rep;


    function quote(string) {

// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can safely slap some quotes around it.
// Otherwise we must also replace the offending characters with safe escape
// sequences.

        escapable.lastIndex = 0;
        return escapable.test(string) ?
            '"' + string.replace(escapable, function (a) {
                var c = meta[a];
                return typeof c === 'string' ? c :
                    '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
            }) + '"' :
            '"' + string + '"';
    }


    function str(key, holder) {

// Produce a string from holder[key].

        var i,          // The loop counter.
            k,          // The member key.
            v,          // The member value.
            length,
            mind = gap,
            partial,
            value = holder[key];

// If the value has a toJSON method, call it to obtain a replacement value.

        if (value && typeof value === 'object' &&
                typeof value.toJSON === 'function') {
            value = value.toJSON(key);
        }

// If we were called with a replacer function, then call the replacer to
// obtain a replacement value.

        if (typeof rep === 'function') {
            value = rep.call(holder, key, value);
        }

// What happens next depends on the value's type.

        switch (typeof value) {
        case 'string':
            return quote(value);

        case 'number':

// JSON numbers must be finite. Encode non-finite numbers as null.

            return isFinite(value) ? String(value) : 'null';

        case 'boolean':
        case 'null':

// If the value is a boolean or null, convert it to a string. Note:
// typeof null does not produce 'null'. The case is included here in
// the remote chance that this gets fixed someday.

            return String(value);

// If the type is 'object', we might be dealing with an object or an array or
// null.

        case 'object':

// Due to a specification blunder in ECMAScript, typeof null is 'object',
// so watch out for that case.

            if (!value) {
                return 'null';
            }

// Make an array to hold the partial results of stringifying this object value.

            gap += indent;
            partial = [];

// Is the value an array?

            if (Object.prototype.toString.apply(value) === '[object Array]') {

// The value is an array. Stringify every element. Use null as a placeholder
// for non-JSON values.

                length = value.length;
                for (i = 0; i < length; i += 1) {
                    partial[i] = str(i, value) || 'null';
                }

// Join all of the elements together, separated with commas, and wrap them in
// brackets.

                v = partial.length === 0 ? '[]' :
                    gap ? '[\n' + gap +
                            partial.join(',\n' + gap) + '\n' +
                                mind + ']' :
                          '[' + partial.join(',') + ']';
                gap = mind;
                return v;
            }

// If the replacer is an array, use it to select the members to be stringified.

            if (rep && typeof rep === 'object') {
                length = rep.length;
                for (i = 0; i < length; i += 1) {
                    k = rep[i];
                    if (typeof k === 'string') {
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
                        }
                    }
                }
            } else {

// Otherwise, iterate through all of the keys in the object.

                for (k in value) {
                    if (Object.hasOwnProperty.call(value, k)) {
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
                        }
                    }
                }
            }

// Join all of the member texts together, separated with commas,
// and wrap them in braces.

            v = partial.length === 0 ? '{}' :
                gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
                        mind + '}' : '{' + partial.join(',') + '}';
            gap = mind;
            return v;
        }
    }

// If the JSON object does not yet have a stringify method, give it one.

    if (typeof JSON.stringify !== 'function') {
        JSON.stringify = function (value, replacer, space) {

// The stringify method takes a value and an optional replacer, and an optional
// space parameter, and returns a JSON text. The replacer can be a function
// that can replace values, or an array of strings that will select the keys.
// A default replacer method can be provided. Use of the space parameter can
// produce text that is more easily readable.

            var i;
            gap = '';
            indent = '';

// If the space parameter is a number, make an indent string containing that
// many spaces.

            if (typeof space === 'number') {
                for (i = 0; i < space; i += 1) {
                    indent += ' ';
                }

// If the space parameter is a string, it will be used as the indent string.

            } else if (typeof space === 'string') {
                indent = space;
            }

// If there is a replacer, it must be a function or an array.
// Otherwise, throw an error.

            rep = replacer;
            if (replacer && typeof replacer !== 'function' &&
                    (typeof replacer !== 'object' ||
                     typeof replacer.length !== 'number')) {
                throw new Error('JSON.stringify');
            }

// Make a fake root object containing our value under the key of ''.
// Return the result of stringifying the value.

            return str('', {'': value});
        };
    }


// If the JSON object does not yet have a parse method, give it one.

    if (typeof JSON.parse !== 'function') {
        JSON.parse = function (text, reviver) {

// The parse method takes a text and an optional reviver function, and returns
// a JavaScript value if the text is a valid JSON text.

            var j;

            function walk(holder, key) {

// The walk method is used to recursively walk the resulting structure so
// that modifications can be made.

                var k, v, value = holder[key];
                if (value && typeof value === 'object') {
                    for (k in value) {
                        if (Object.hasOwnProperty.call(value, k)) {
                            v = walk(value, k);
                            if (v !== undefined) {
                                value[k] = v;
                            } else {
                                delete value[k];
                            }
                        }
                    }
                }
                return reviver.call(holder, key, value);
            }


// Parsing happens in four stages. In the first stage, we replace certain
// Unicode characters with escape sequences. JavaScript handles many characters
// incorrectly, either silently deleting them, or treating them as line endings.

            text = String(text);
            cx.lastIndex = 0;
            if (cx.test(text)) {
                text = text.replace(cx, function (a) {
                    return '\\u' +
                        ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
                });
            }

// In the second stage, we run the text against regular expressions that look
// for non-JSON patterns. We are especially concerned with '()' and 'new'
// because they can cause invocation, and '=' because it can cause mutation.
// But just to be safe, we want to reject all unexpected forms.

// We split the second stage into 4 regexp operations in order to work around
// crippling inefficiencies in IE's and Safari's regexp engines. First we
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
// replace all simple value tokens with ']' characters. Third, we delete all
// open brackets that follow a colon or comma or that begin the text. Finally,
// we look to see that the remaining characters are only whitespace or ']' or
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.

            if (/^[\],:{}\s]*$/
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// in JavaScript: it can begin a block or an object literal. We wrap the text
// in parens to eliminate the ambiguity.

                j = eval('(' + text + ')');

// In the optional fourth stage, we recursively walk the new structure, passing
// each name/value pair to a reviver function for possible transformation.

                return typeof reviver === 'function' ?
                    walk({'': j}, '') : j;
            }

// If the text is not JSON parseable, then a SyntaxError is thrown.

            throw new SyntaxError('JSON.parse');
        };
    }
}());






/*
 * SimpleModal 1.4.1 - jQuery Plugin
 * http://www.ericmmartin.com/projects/simplemodal/
 * Copyright (c) 2010 Eric Martin (http://twitter.com/ericmmartin)
 * Dual licensed under the MIT and GPL licenses
 * Revision: $Id: jquery.simplemodal.js 261 2010-11-05 21:16:20Z emartin24 $
 */
(function(d){var k=d.browser.msie&&parseInt(d.browser.version)===6&&typeof window.XMLHttpRequest!=="object",m=d.browser.msie&&parseInt(d.browser.version)===7,l=null,f=[];d.modal=function(a,b){return d.modal.impl.init(a,b)};d.modal.close=function(){d.modal.impl.close()};d.modal.focus=function(a){d.modal.impl.focus(a)};d.modal.setContainerDimensions=function(){d.modal.impl.setContainerDimensions()};d.modal.setPosition=function(){d.modal.impl.setPosition()};d.modal.update=function(a,b){d.modal.impl.update(a,
b)};d.fn.modal=function(a){return d.modal.impl.init(this,a)};d.modal.defaults={appendTo:"body",focus:true,opacity:50,overlayId:"simplemodal-overlay",overlayCss:{},containerId:"simplemodal-container",containerCss:{},dataId:"simplemodal-data",dataCss:{},minHeight:null,minWidth:null,maxHeight:null,maxWidth:null,autoResize:false,autoPosition:true,zIndex:1E3,close:true,closeHTML:'<a class="modalCloseImg" title="Close"></a>',closeClass:"simplemodal-close",escClose:true,overlayClose:false,position:null,
persist:false,modal:true,onOpen:null,onShow:null,onClose:null};d.modal.impl={d:{},init:function(a,b){var c=this;if(c.d.data)return false;l=d.browser.msie&&!d.boxModel;c.o=d.extend({},d.modal.defaults,b);c.zIndex=c.o.zIndex;c.occb=false;if(typeof a==="object"){a=a instanceof jQuery?a:d(a);c.d.placeholder=false;if(a.parent().parent().size()>0){a.before(d("<span></span>").attr("id","simplemodal-placeholder").css({display:"none"}));c.d.placeholder=true;c.display=a.css("display");if(!c.o.persist)c.d.orig=
a.clone(true)}}else if(typeof a==="string"||typeof a==="number")a=d("<div></div>").html(a);else{alert("SimpleModal Error: Unsupported data type: "+typeof a);return c}c.create(a);c.open();d.isFunction(c.o.onShow)&&c.o.onShow.apply(c,[c.d]);return c},create:function(a){var b=this;f=b.getDimensions();if(b.o.modal&&k)b.d.iframe=d('<iframe src="javascript:false;"></iframe>').css(d.extend(b.o.iframeCss,{display:"none",opacity:0,position:"fixed",height:f[0],width:f[1],zIndex:b.o.zIndex,top:0,left:0})).appendTo(b.o.appendTo);
b.d.overlay=d("<div></div>").attr("id",b.o.overlayId).addClass("simplemodal-overlay").css(d.extend(b.o.overlayCss,{display:"none",opacity:b.o.opacity/100,height:b.o.modal?f[0]:0,width:b.o.modal?f[1]:0,position:"fixed",left:0,top:0,zIndex:b.o.zIndex+1})).appendTo(b.o.appendTo);b.d.container=d("<div></div>").attr("id",b.o.containerId).addClass("simplemodal-container").css(d.extend(b.o.containerCss,{display:"none",position:"fixed",zIndex:b.o.zIndex+2})).append(b.o.close&&b.o.closeHTML?d(b.o.closeHTML).addClass(b.o.closeClass):
"").appendTo(b.o.appendTo);b.d.wrap=d("<div></div>").attr("tabIndex",-1).addClass("simplemodal-wrap").css({height:"100%",outline:0,width:"100%"}).appendTo(b.d.container);b.d.data=a.attr("id",a.attr("id")||b.o.dataId).addClass("simplemodal-data").css(d.extend(b.o.dataCss,{display:"none"})).appendTo("body");b.setContainerDimensions();b.d.data.appendTo(b.d.wrap);if(k||l)b.fixIE()},bindEvents:function(){var a=this;d("."+a.o.closeClass).bind("click.simplemodal",function(b){b.preventDefault();a.close()});
a.o.modal&&a.o.close&&a.o.overlayClose&&a.d.overlay.bind("click.simplemodal",function(b){b.preventDefault();a.close()});d(document).bind("keydown.simplemodal",function(b){if(a.o.modal&&b.keyCode===9)a.watchTab(b);else if(a.o.close&&a.o.escClose&&b.keyCode===27){b.preventDefault();a.close()}});d(window).bind("resize.simplemodal",function(){f=a.getDimensions();a.o.autoResize?a.setContainerDimensions():a.o.autoPosition&&a.setPosition();if(k||l)a.fixIE();else if(a.o.modal){a.d.iframe&&a.d.iframe.css({height:f[0],
width:f[1]});a.d.overlay.css({height:f[0],width:f[1]})}})},unbindEvents:function(){d("."+this.o.closeClass).unbind("click.simplemodal");d(document).unbind("keydown.simplemodal");d(window).unbind("resize.simplemodal");this.d.overlay.unbind("click.simplemodal")},fixIE:function(){var a=this,b=a.o.position;d.each([a.d.iframe||null,!a.o.modal?null:a.d.overlay,a.d.container],function(c,h){if(h){var g=h[0].style;g.position="absolute";if(c<2){g.removeExpression("height");g.removeExpression("width");g.setExpression("height",
'document.body.scrollHeight > document.body.clientHeight ? document.body.scrollHeight : document.body.clientHeight + "px"');g.setExpression("width",'document.body.scrollWidth > document.body.clientWidth ? document.body.scrollWidth : document.body.clientWidth + "px"')}else{var e;if(b&&b.constructor===Array){c=b[0]?typeof b[0]==="number"?b[0].toString():b[0].replace(/px/,""):h.css("top").replace(/px/,"");c=c.indexOf("%")===-1?c+' + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"':
parseInt(c.replace(/%/,""))+' * ((document.documentElement.clientHeight || document.body.clientHeight) / 100) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"';if(b[1]){e=typeof b[1]==="number"?b[1].toString():b[1].replace(/px/,"");e=e.indexOf("%")===-1?e+' + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"':parseInt(e.replace(/%/,""))+' * ((document.documentElement.clientWidth || document.body.clientWidth) / 100) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"'}}else{c=
'(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"';e='(document.documentElement.clientWidth || document.body.clientWidth) / 2 - (this.offsetWidth / 2) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"'}g.removeExpression("top");g.removeExpression("left");g.setExpression("top",
c);g.setExpression("left",e)}}})},focus:function(a){var b=this;a=a&&d.inArray(a,["first","last"])!==-1?a:"first";var c=d(":input:enabled:visible:"+a,b.d.wrap);setTimeout(function(){c.length>0?c.focus():b.d.wrap.focus()},10)},getDimensions:function(){var a=d(window);return[d.browser.opera&&d.browser.version>"9.5"&&d.fn.jquery<"1.3"||d.browser.opera&&d.browser.version<"9.5"&&d.fn.jquery>"1.2.6"?a[0].innerHeight:a.height(),a.width()]},getVal:function(a,b){return a?typeof a==="number"?a:a==="auto"?0:
a.indexOf("%")>0?parseInt(a.replace(/%/,""))/100*(b==="h"?f[0]:f[1]):parseInt(a.replace(/px/,"")):null},update:function(a,b){var c=this;if(!c.d.data)return false;c.d.origHeight=c.getVal(a,"h");c.d.origWidth=c.getVal(b,"w");c.d.data.hide();a&&c.d.container.css("height",a);b&&c.d.container.css("width",b);c.setContainerDimensions();c.d.data.show();c.o.focus&&c.focus();c.unbindEvents();c.bindEvents()},setContainerDimensions:function(){var a=this,b=k||m,c=a.d.origHeight?a.d.origHeight:d.browser.opera?
a.d.container.height():a.getVal(b?a.d.container[0].currentStyle.height:a.d.container.css("height"),"h");b=a.d.origWidth?a.d.origWidth:d.browser.opera?a.d.container.width():a.getVal(b?a.d.container[0].currentStyle.width:a.d.container.css("width"),"w");var h=a.d.data.outerHeight(true),g=a.d.data.outerWidth(true);a.d.origHeight=a.d.origHeight||c;a.d.origWidth=a.d.origWidth||b;var e=a.o.maxHeight?a.getVal(a.o.maxHeight,"h"):null,i=a.o.maxWidth?a.getVal(a.o.maxWidth,"w"):null;e=e&&e<f[0]?e:f[0];i=i&&i<
f[1]?i:f[1];var j=a.o.minHeight?a.getVal(a.o.minHeight,"h"):"auto";c=c?a.o.autoResize&&c>e?e:c<j?j:c:h?h>e?e:a.o.minHeight&&j!=="auto"&&h<j?j:h:j;e=a.o.minWidth?a.getVal(a.o.minWidth,"w"):"auto";b=b?a.o.autoResize&&b>i?i:b<e?e:b:g?g>i?i:a.o.minWidth&&e!=="auto"&&g<e?e:g:e;a.d.container.css({height:c,width:b});a.d.wrap.css({overflow:h>c||g>b?"auto":"visible"});a.o.autoPosition&&a.setPosition()},setPosition:function(){var a=this,b,c;b=f[0]/2-a.d.container.outerHeight(true)/2;c=f[1]/2-a.d.container.outerWidth(true)/
2;if(a.o.position&&Object.prototype.toString.call(a.o.position)==="[object Array]"){b=a.o.position[0]||b;c=a.o.position[1]||c}else{b=b;c=c}a.d.container.css({left:c,top:b})},watchTab:function(a){var b=this;if(d(a.target).parents(".simplemodal-container").length>0){b.inputs=d(":input:enabled:visible:first, :input:enabled:visible:last",b.d.data[0]);if(!a.shiftKey&&a.target===b.inputs[b.inputs.length-1]||a.shiftKey&&a.target===b.inputs[0]||b.inputs.length===0){a.preventDefault();b.focus(a.shiftKey?"last":
"first")}}else{a.preventDefault();b.focus()}},open:function(){var a=this;a.d.iframe&&a.d.iframe.show();if(d.isFunction(a.o.onOpen))a.o.onOpen.apply(a,[a.d]);else{a.d.overlay.show();a.d.container.show();a.d.data.show()}a.o.focus&&a.focus();a.bindEvents()},close:function(){var a=this;if(!a.d.data)return false;a.unbindEvents();if(d.isFunction(a.o.onClose)&&!a.occb){a.occb=true;a.o.onClose.apply(a,[a.d])}else{if(a.d.placeholder){var b=d("#simplemodal-placeholder");if(a.o.persist)b.replaceWith(a.d.data.removeClass("simplemodal-data").css("display",
a.display));else{a.d.data.hide().remove();b.replaceWith(a.d.orig)}}else a.d.data.hide().remove();a.d.container.hide().remove();a.d.overlay.hide();a.d.iframe&&a.d.iframe.hide().remove();setTimeout(function(){a.d.overlay.remove();a.d={}},10)}}}})(jQuery);




/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


