
function ValidateHTML( strHTML )
{
	var strHTMLCopy = strHTML;
	strHTMLCopy = strHTMLCopy.toLowerCase();
	//
	if( CountHTML( strHTMLCopy, "<", ">" ) == false )	{		return false;	}

	//
	strHTMLCopy = strHTML;
	strHTMLCopy = strHTMLCopy.toLowerCase();
	if( IsCountEven( strHTMLCopy, "\"" ) == false )	{		return false;	}

	//
	strHTMLCopy = strHTML;
	strHTMLCopy = strHTMLCopy.toLowerCase();
	
	//var strHTMLCopyOld = "";
	while( strHTMLCopy.search( "'" ) != -1 ) strHTMLCopy = strHTMLCopy.replace( "'", "<Q>" );
	while( strHTMLCopy.search( "<Q>" ) != -1 ) strHTMLCopy = strHTMLCopy.replace( "<Q>", "''" );
	//alert(strHTMLCopy);
	if( IsCountEven( strHTMLCopy, "'" ) == false )	{		return false;	}

	strHTMLCopy = strHTML;
	strHTMLCopy = strHTMLCopy.toLowerCase();
	while( strHTMLCopy.search( " " ) != -1 ) strHTMLCopy = strHTMLCopy.replace( " ", "" );
	
	/* count <b /b> <a /a> <li /li> <ul /ul> */
	while( strHTMLCopy.search( "<br>" ) != -1 ) strHTMLCopy = strHTMLCopy.replace( "<br>", "" );
	while( strHTMLCopy.search( "<hr>" ) != -1 ) strHTMLCopy = strHTMLCopy.replace( "<hr>", "" );
	//
	if( CountHTML( strHTMLCopy, "<b", "/b>" ) == false )	{		return false;	}

	strHTMLCopy = strHTML;
	strHTMLCopy = strHTMLCopy.toLowerCase();
	//while( strHTMLCopy.search( " " ) != -1 ) strHTMLCopy = strHTMLCopy.replace( " ", "" );
	if( CountHTML( strHTMLCopy, "<a ", "/a>" ) == false )	{		return false;	}

	strHTMLCopy = strHTML;
	strHTMLCopy = strHTMLCopy.toLowerCase();
	//while( strHTMLCopy.search( " " ) != -1 ) strHTMLCopy = strHTMLCopy.replace( " ", "" );
	if( CountHTML( strHTMLCopy, "<li", "/li>" ) == false )	{		return false;	}
	
	strHTMLCopy = strHTML;
	strHTMLCopy = strHTMLCopy.toLowerCase();
	//while( strHTMLCopy.search( " " ) != -1 ) strHTMLCopy = strHTMLCopy.replace( " ", "" );
	if( CountHTML( strHTMLCopy, "<ul", "/ul>" ) == false )	{		return false;	}
	
	//alert( "Valid HTML" );
	return true;
}

function CountHTML( strHTMLCopy, str1, str2 )
{
	var nLen = strHTMLCopy.length;
	while( strHTMLCopy.search( str1 ) != -1 ) strHTMLCopy = strHTMLCopy.replace( str1, "" );
	var nLenDif1 = (nLen - strHTMLCopy.length) / str1.length;
	/*alert( str1.length );
	alert( nLen - strHTMLCopy.length );
	alert( nLenDif1 );*/
	
	nLen = strHTMLCopy.length;
	while( strHTMLCopy.search( str2 ) != -1 ) strHTMLCopy = strHTMLCopy.replace( str2, "" );
	var nLenDif2 = (nLen - strHTMLCopy.length) / str2.length;
	/*alert( str2.length );
	alert( nLen - strHTMLCopy.length );
	alert( nLenDif2 );*/
	
	var strMissing = ((nLenDif1 > nLenDif2) ? str1 : str2);
	if( nLenDif1 != nLenDif2 ) 
	{
		//alert( strHTMLCopy );
		alert( "Invalid HTML - Missing: " + strMissing + "" );
		return false;
	}
	return true;
}
function IsCountEven( strHTMLCopy, str1 )
{
	nLen = strHTMLCopy.length;
	while( strHTMLCopy.search(str1) != -1 ) strHTMLCopy = strHTMLCopy.replace( str1, "" );
	var nLenDif3 = nLen - strHTMLCopy.length;
	if( nLenDif3 % 2 != 0 )
	{
		alert( "Invalid HTML - Missing: " + str1 + "" );
		return false;
	}
	return true;
}

