YAHOO.example.Data = {
keywords: [ {name: "Account", type: "DataObject"},{name: "AccountAggregate", type: "DataObject"},{name: "AccountBalance", type: "DataObject"},{name: "AccountManagement", type: "CommandGroup"},{name: "AccountRead", type: "Capability"},{name: "AccountService", type: "Service"},{name: "AccountStatus", type: "DataObject"},{name: "AccountType", type: "DataObject"},{name: "AccountUserManagementRead", type: "Capability"},{name: "AccountUserManagementWrite", type: "Capability"},{name: "AccountWrite", type: "Capability"},{name: "Ad", type: "DataObject"},{name: "AdEditorialReasons", type: "DataObject"},{name: "AdGroup", type: "DataObject"},{name: "AdGroupForecastMatchType", type: "DataObject"},{name: "AdGroupForecastRequestData", type: "DataObject"},{name: "AdGroupOptimizationGuidelines", type: "DataObject"},{name: "AdGroupOptimizationGuidelinesResponse", type: "DataObject"},{name: "AdGroupResponse", type: "DataObject"},{name: "AdGroupService", type: "Service"},{name: "AdGroupStatus", type: "DataObject"},{name: "AdResponse", type: "DataObject"},{name: "AdService", type: "Service"},{name: "AdStatus", type: "DataObject"},{name: "Address", type: "DataObject"},{name: "AdvancedTools", type: "CommandGroup"},{name: "AgeRange", type: "DataObject"},{name: "AgeTarget", type: "DataObject"},{name: "Authorization", type: "DataObject"},{name: "BasicReportRequest", type: "DataObject"},{name: "BasicReportService", type: "Service"},{name: "BasicReportType", type: "DataObject"},{name: "BasicReports", type: "CommandGroup"},{name: "BasicResponse", type: "DataObject"},{name: "BatchRead", type: "Capability"},{name: "BidInformation", type: "DataObject"},{name: "BidInformationRequest", type: "DataObject"},{name: "BidInformationService", type: "Service"},{name: "BidStatus", type: "DataObject"},{name: "BidUpdateInfo", type: "DataObject"},{name: "BillingUser", type: "DataObject"},{name: "BucketType", type: "DataObject"},{name: "BudgetingService", type: "Service"},{name: "Bulk", type: "CommandGroup"},{name: "BulkDownloadStatus", type: "DataObject"},{name: "BulkDownloadStatusInfo", type: "DataObject"},{name: "BulkDownloadStatusResponse", type: "DataObject"},{name: "BulkFeedbackFileType", type: "DataObject"},{name: "BulkFileType", type: "DataObject"},{name: "BulkService", type: "Service"},{name: "BulkUploadStatus", type: "DataObject"},{name: "BulkUploadStatusResponse", type: "DataObject"},{name: "BulkUploadTokenUrlResponse", type: "DataObject"},{name: "Campaign", type: "DataObject"},{name: "CampaignOptimization", type: "CommandGroup"},{name: "CampaignOptimizationGuidelines", type: "DataObject"},{name: "CampaignOptimizationGuidelinesResponse", type: "DataObject"},{name: "CampaignRead", type: "Capability"},{name: "CampaignResponse", type: "DataObject"},{name: "CampaignService", type: "Service"},{name: "CampaignStatus", type: "DataObject"},{name: "CampaignWrite", type: "Capability"},{name: "Capability", type: "DataObject"},{name: "Carrier", type: "DataObject"},{name: "CarrierBidInformation", type: "DataObject"},{name: "CarrierBidInformationRequest", type: "DataObject"},{name: "CombinedAccountStatus", type: "DataObject"},{name: "Company", type: "DataObject"},{name: "CompanyRead", type: "Capability"},{name: "CompanyService", type: "Service"},{name: "Continent", type: "DataObject"},{name: "ConversionMetric", type: "DataObject"},{name: "CreditCardInfo", type: "DataObject"},{name: "CustomerManagement", type: "CommandGroup"},{name: "DateRange", type: "DataObject"},{name: "DayOfTheWeek", type: "DataObject"},{name: "DayPart", type: "DataObject"},{name: "DayPartingTarget", type: "DataObject"},{name: "DayPartingTargeting", type: "DataObject"},{name: "DemographicTargeting", type: "DataObject"},{name: "DistanceUnits", type: "DataObject"},{name: "DistributionControl", type: "DataObject"},{name: "DistributionControlLevel", type: "DataObject"},{name: "EditorialStatus", type: "DataObject"},{name: "Error", type: "DataObject"},{name: "ErrorKeyType", type: "DataObject"},{name: "ErrorType", type: "DataObject"},{name: "ExcludedWord", type: "DataObject"},{name: "ExcludedWordResponse", type: "DataObject"},{name: "ExcludedWordsService", type: "Service"},{name: "FileOutputFormat", type: "DataObject"},{name: "FileOutputType", type: "DataObject"},{name: "ForecastClickData", type: "DataObject"},{name: "ForecastCreative", type: "DataObject"},{name: "ForecastImpressionData", type: "DataObject"},{name: "ForecastKeyword", type: "DataObject"},{name: "ForecastKeywordBatch", type: "DataObject"},{name: "ForecastKeywordBatchResponse", type: "DataObject"},{name: "ForecastKeywordBatchResponseData", type: "DataObject"},{name: "ForecastKeywordResponse", type: "DataObject"},{name: "ForecastMatchType", type: "DataObject"},{name: "ForecastRequestData", type: "DataObject"},{name: "ForecastResponse", type: "DataObject"},{name: "ForecastResponseData", type: "DataObject"},{name: "ForecastService", type: "Service"},{name: "Gender", type: "DataObject"},{name: "GenderTarget", type: "DataObject"},{name: "GeoLocation", type: "DataObject"},{name: "GeoLocationProbability", type: "DataObject"},{name: "GeoLocationProbabilitySet", type: "DataObject"},{name: "GeoTarget", type: "DataObject"},{name: "GeographicalDictionaryService", type: "Service"},{name: "HistoricalKeyword", type: "DataObject"},{name: "HistoricalKeywordResponse", type: "DataObject"},{name: "HistoricalKeywordResponseData", type: "DataObject"},{name: "HistoricalRequestData", type: "DataObject"},{name: "HistoricalResponseData", type: "DataObject"},{name: "Importance", type: "DataObject"},{name: "Keyword", type: "DataObject"},{name: "KeywordEditorialReasons", type: "DataObject"},{name: "KeywordForecastMatchType", type: "DataObject"},{name: "KeywordForecastRequestData", type: "DataObject"},{name: "KeywordInfoRequestType", type: "DataObject"},{name: "KeywordInfoResponseType", type: "DataObject"},{name: "KeywordInfoType", type: "DataObject"},{name: "KeywordOptimizationGuidelines", type: "DataObject"},{name: "KeywordOptimizationGuidelinesResponse", type: "DataObject"},{name: "KeywordParticipationStatus", type: "DataObject"},{name: "KeywordResearchService", type: "Service"},{name: "KeywordResponse", type: "DataObject"},{name: "KeywordService", type: "Service"},{name: "KeywordStatus", type: "DataObject"},{name: "LocationService", type: "Service"},{name: "Marketing", type: "CommandGroup"},{name: "MasterAccount", type: "DataObject"},{name: "MasterAccountRead", type: "Capability"},{name: "MasterAccountService", type: "Service"},{name: "MasterAccountStatus", type: "DataObject"},{name: "MasterAccountUserManagementWrite", type: "Capability"},{name: "MasterAccountWrite", type: "Capability"},{name: "MobileDictionaryService", type: "Service"},{name: "Network", type: "DataObject"},{name: "NotParticipatingInMarketplaceReason", type: "DataObject"},{name: "OptInAdGroupResponse", type: "DataObject"},{name: "OptInCampaignResponse", type: "DataObject"},{name: "OptInReporting", type: "DataObject"},{name: "OptInStatus", type: "DataObject"},{name: "PageRelatedKeywordRequestType", type: "DataObject"},{name: "ParticipationStatus", type: "DataObject"},{name: "PaymentInfo", type: "DataObject"},{name: "PaymentMethodInfo", type: "DataObject"},{name: "PlatformServices", type: "Capability"},{name: "RangeDefinitionRequestType", type: "DataObject"},{name: "RangeDefinitionResponseType", type: "DataObject"},{name: "RangeDefinitionType", type: "DataObject"},{name: "RangeNameType", type: "DataObject"},{name: "RangeValueType", type: "DataObject"},{name: "RelatedKeywordRequestType", type: "DataObject"},{name: "RelatedKeywordResponseType", type: "DataObject"},{name: "RelatedKeywordType", type: "DataObject"},{name: "ReportInfo", type: "DataObject"},{name: "Reporting", type: "Capability"},{name: "Research", type: "CommandGroup"},{name: "ResponseStatusCodeType", type: "DataObject"},{name: "ResponseStatusType", type: "DataObject"},{name: "Role", type: "DataObject"},{name: "Selfcare", type: "Capability"},{name: "SignupStatus", type: "DataObject"},{name: "SpendCapTactic", type: "DataObject"},{name: "SpendCapType", type: "DataObject"},{name: "SpendLimit", type: "DataObject"},{name: "SponsoredSearchMinBidRequest", type: "DataObject"},{name: "SubphraseKeywordRequestType", type: "DataObject"},{name: "TacticSpendCap", type: "DataObject"},{name: "TacticType", type: "DataObject"},{name: "TargetableLevel", type: "DataObject"},{name: "TargetingAttribute", type: "DataObject"},{name: "TargetingAttributeDescriptor", type: "DataObject"},{name: "TargetingConverterService", type: "Service"},{name: "TargetingDictionaryService", type: "Service"},{name: "TargetingPremium", type: "DataObject"},{name: "TargetingPremiumType", type: "DataObject"},{name: "TargetingProfile", type: "DataObject"},{name: "TargetingService", type: "Service"},{name: "TargetingType", type: "DataObject"},{name: "UnderAgeFilter", type: "DataObject"},{name: "UpdateForAd", type: "DataObject"},{name: "UpdateForKeyword", type: "DataObject"},{name: "UpgradeService", type: "Service"},{name: "User", type: "DataObject"},{name: "UserAuthorization", type: "DataObject"},{name: "UserManagementService", type: "Service"},{name: "UserStatus", type: "DataObject"},{name: "Vault", type: "CommandGroup"},{name: "VaultService", type: "Service"},{name: "Warning", type: "DataObject"} ]
};
YAHOO.example.ItemSelectHandler = function() {
    // Use a LocalDataSource
    var oDS = new YAHOO.util.LocalDataSource(YAHOO.example.Data.keywords);
    oDS.responseSchema = {fields : ["name", "type"]};

    // Instantiate the AutoComplete
    var oAC = new YAHOO.widget.AutoComplete("searchInput", "searchContainer", oDS);
    oAC.resultTypeList = false;
    oAC.autoHighlight = false;
    oAC.queryMatchContains = true;

    var searchHandler = function(sType, aArgs) {
        var myAC = aArgs[0]; // reference back to the AC instance
        var elLI = aArgs[1]; // reference to the selected LI element
        var oData = aArgs[2]; // object literal of selected item's result data
	var navURL=GetURL(oData.type,oData.name);
	window.location.href=navURL;
    };

	oAC.formatResult = function(oResultData, sQuery, sResultMatch) {
	var exp=new RegExp("(.*)(" + sQuery + ")(.*)","ig");
	var formatResult=sResultMatch.replace(exp,"$1<span style='font-weight:bold'>$2</span>$3");
	return formatResult;
	};
    	oAC.itemSelectEvent.subscribe(searchHandler);


	var onFormSubmit = function(e, searchForm) {
	YAHOO.util.Event.preventDefault(e);
	
	var searchBox= YAHOO.util.Dom.get("searchInput");
	if(searchBox.value)
	{
	searchURL="http://search.yahoo.com/search?p=" + searchBox.value + " inurl:searchmarketing.yahoo.com/developer";
	window.location.href=searchURL;
	}
	};
	
    	YAHOO.util.Event.addListener(YAHOO.util.Dom.get("searchForm"), "submit", onFormSubmit); 

    var GetURL=function(iType,name)
    {
	var baseURL="http://searchmarketing.yahoo.com/developer/docs/V5/reference/";
	var targetURL="";
       	switch(iType)
	{
		case "Service":
  		targetURL=baseURL + "services/" + name + ".php";
		break;
		case "DataObject":
		targetURL=baseURL + "data/" + name + ".php";
		break;
		case "Capability":
		targetURL= baseURL + "capability.php#" + name;
		break;
		case "CommandGroup":
		targetURL=baseURL + "/cmdGroup.php#" + name;
		break;
	}
	return targetURL;
    };

    return {
        oDS: oDS,
        oAC: oAC
    };
}();
