﻿var KeywordEntryFullyQualifiedUrl = null;

function KeywordBox( containerID, options )
{
	if( containerID && options )
	{
		if( containerID.indexOf( "#" ) == -1 )
			containerID = "#" + containerID;
		
		var hostID = options[ "hostID" ];
		var labelOptions = options[ "label" ];
		
		if( hostID && labelOptions )
		{
			var queryStringItems = new Array();
			
			// Unroll the labelOptions and put them in the array
			DictionaryToQueryString( queryStringItems, options );
			
			// Now combine the items into a query string
			var queryString = queryStringItems.join( "&" );
			
			if( KeywordEntryFullyQualifiedUrl )
				jQuery( containerID ).load( KeywordEntryFullyQualifiedUrl + "?" + queryString );
		}
	}
}

function DictionaryToQueryString( itemsArray, dict )
{
	 jQuery.each( dict, function( i, val ) {
		if( typeof( val ) == "object" )
			DictionaryToQueryString( itemsArray, val );
		else
			itemsArray.push( i + "=" + escape( val ) );
	 });
}

function InvokeKeywordBox( entryUrl, containerID, hostID, labelText )
{
	jQuery(document).ready( function() {
		KeywordEntryFullyQualifiedUrl = entryUrl;
		new KeywordBox( 
			containerID, 
			{
				hostID: hostID,
				label: {
					text:       labelText,
					color:      "Navy",
					fontFamily: "OCR A Extended",
					fontBold:   1,
					fontItalic: 0,
					fontSize:   12,
					antialias:  1,
					width:      200,
					height:     20
				}
			}
		);
	});
}

function Test()
{
	InvokeKeywordBox( "http://localhost:2879/KeywordEntry.aspx", "KeywordBox", "FPIS", "FPIS Keyword:" );
}

function Test2()
{
	var entryUrl = "http://localhost:2879/KeywordEntry.aspx";
	var containerID = "KeywordBox";
	var hostID = "SITE";
	var labelText = "Enter Keyword:";
	
	jQuery(document).ready( function() {
		KeywordEntryFullyQualifiedUrl = entryUrl;
		new KeywordBox( 
			containerID, 
			{
				hostID: hostID,
				label: {
					text:       labelText,
					color:      "Black",
					fontFamily: "Kristen ITC",
					fontBold:   0,
					fontItalic: 0,
					fontSize:   16,
					antialias:  1,
					width:      300,
					height:     30
				}
			}
		);
	});
}