//
// get current element name
//
function getElementName()
{
	var ret = "";
	
	if( document != null && document.type == "markup" )
	{
		if( document.view == "source" )
		{
			if( document.source != null )
			{
				switch( document.source.syntax )
				{
					case "HTML Syntax":
						ret = parseNameHTML( document.source );
						break;
					
					/*
					write your own code for other syntaxes here
					case "mysyntax":
						ret = parseMySyntax( document.source );
						break;
					*/
				}
			}
		}
		else
		{
			if( document.selection != null )
			{
				var element = document.selection.element;
				
				if( element != null )
					ret = element.tagName;
			}
		}
	}
	
	return ret;
}

//
// parse source
//
function parseNameHTML( sourceView )
{
	var ret = "";
	var start = -1;
	var end   = -1;
	
	var curSel = sourceView.selectionStart;

	//
	// find start of element name
	//					
	var index = curSel-1;
	var c = "";
	var foundEnd = false;
	do
	{
		c = sourceView.textAt( index, index+1 );
		index--;
		
		foundEnd = ( c == "<" || ( c == "/" && index >= 0 && sourceView.textAt( index, index+1 ) == "<" ) ||
									( c == "!" && index >= 0 && sourceView.textAt( index, index+1 ) == "<" ) );
	
	} while( !foundEnd && index >= 0 );
	
	if( foundEnd)
	{
		// set start index of element name
		start = index+2;	

		//
		// find end index of element name
		//
		index = start
		do
		{
			c = sourceView.textAt( index, index+1 );
			index++;
		
		} while( c != " " && c != ">" );
		
		if( c == " " || c == ">" )
		{
			// set end index
			end = index-1;
			
			// set element name
			ret = sourceView.textAt( start, end );
		}
	}
	
	if( ret[0] == '/' )
		ret = ret.slice(1);
	
	return ret;
}
//
// create link for tag name
//
function getLink( tagName )
{
	var linkEntry = "";

	if( thDataBase != null && thDataBase.length > 0 )
	{
		for( var i=0; i<thDataBase.length && linkEntry==""; i++ )
		{
			if( thDataBase[i][0] == tagName )
				linkEntry = thDataBase[i][1];
		}	
	}
	
	if( linkEntry == "" )
		linkEntry = tagName;
	
	try
	{	
		var evalStr = "var thBase = '" + thDataBaseBaseURL + "';var thName = '" + tagName + "';var thMapped = '" + linkEntry + "';link=" + thLinkCreator + ";";
		evalStr = evalStr.replace( '\n', '' );
		eval( evalStr );
	}
	catch(none)
	{
		dbgwriteln( none );
	}
		
	return link;
}

//
// validate current active document
//
function validateDocument( curDoc )
{
	var valid = false;
	
	if( curDoc != null && curDoc.type == "markup" )
		valid = true;
	
	return valid;
}

