function selectLanguage(selectedLocale){
	window.location = '/kb/'+articleId+'?viewlocale='+selectedLocale;
}

KmLoader.relatedVideosSuccess = function(json, requestId) {
	var html = '';
	if(json==undefined || json==null) {
		//alert('Something went wrong. Please try again!') 
	}
	else if(json['results'].length>0) {
		 var relatedDivName='related';
         $(relatedDivName).show(); 
		
		for(i=0; i<json['results'].length; i++) {
			//do not show results that have the same title as the article we are looking at
			var showResult = (ACUtil.trim(json.results[i].title).substring(0, 60)==ACUtil.trim($('article').getElementsByTagName('h1')[0].innerHTML).substring(0,60)) ? false : true;
			
			if (showResult) {
				var title = json.results[i].title;
				html += '<li class="top-results dt-thumbnail"><div class="thumbnail">';
				html += '<a href="' + json.results[i].url + '" onclick="s_objectID=\'' +  json.results[i].url + '_p' + requestId + '-' + i + '\';"><img src="' + json.results[i].thumbnail + '" alt="thumbnail"></a>';
				html += '</div><h3>';
				html += '<a href="' + json.results[i].url + '" onclick="s_objectID=\'' + json.results[i].url + '_p' + requestId + '_' + i + '\';">' + json.results[i].title + '</a>';
				html += '</h3></li>';
			}
		}
		
		if (html!=""){
			$('results-Support-ul').innerHTML = html;			
		}else{
			$('related-videos').hide();
		}

	}
}

KmLoader.relatedVideosError = function(errorMsg, requestId){
	$('related-videos').hide();
}

KmLoader.relatedArticlesSuccess = function(json, requestId) {
    
    if ($('portlet_1') != null) {

        // fix spacing for manually coded linked lists above/below portlet
        if ($('portlet_1').previous() != undefined && $('portlet_1').previous().match('ul')) {
            $('portlet_1').previous().setStyle({paddingBottom: '0px'}); 
        }
        if ($('portlet_1').next() != undefined && $('portlet_1').next().match('ul')) {
            $('portlet_1').setStyle({paddingBottom: '0px'}); 
        }

        if(json==undefined || json==null) {
            //alert('Something went wrong. Please try again!') 
        }
		else if(json['results'].length>0) {

            var portletData = '';
            var relatedDivName='related';
            $(relatedDivName).show(); 

            for(i=0;i<json['results'].length;i++) {
                if (json.results[i] != null) {
					//do not show results that have the same title as the article we are looking at
					var showResult = (ACUtil.trim(json.results[i].title).substring(0, 60)==ACUtil.trim($('article').getElementsByTagName('h1')[0].innerHTML).substring(0,60)) ? false : true;
					var url = json.results[i].url;
					
                    if(showResult) {
                        
                        // get icon based on doctype
                        var iconStyle = '';
						var docId = url.substr(url.lastIndexOf("/")+1);
                        switch (docId.substr(0,2)) {
                            case 'HT':
                                iconStyle = "dt-howto-articles";
                                break;
                            case 'TS':
                                iconStyle = "dt-troubleshooting-articles";
                                break;
                            default:
                                iconStyle = "dt-document";
                                break
                        }

                        // get excerpt, truncate if necessary
                        var excerpt = (json.results[i].excerpt.length>0) ? json.results[i].excerpt: '&nbsp;';
                        if (excerpt.length > 200) {
                            excerpt = excerpt.substring(0, 200);
                            excerpt = excerpt.replace(/\w+$/, '');
                            excerpt += "...";
                        }

                        portletData += "<li class=\"portlet-results " + iconStyle + "\">";
                        portletData += "<h3><a href=\"" + url + "\" onclick=\"s_objectID='" +  url + "_p" + requestId + "-" + i + "';\">" + json.results[i].title + "</a></h3>";
                        portletData += "<div class=\"excerpt\">" + excerpt + "</div></li>";
                    }
                }
            }
            $('portlet_1').innerHTML = portletData;
        }
    }
}

KmLoader.relatedArticlesError = function(errorMsg, requestId){
	$('related-articles').hide();
}
