function HideKeywords()
{
    document.getElementById("NameAutoCompleteIFrame").style.display = "none";
    document.getElementById("NameAutoComplete").style.display = "none";
}

function ShowKeywords()
{
    document.getElementById("NameAutoCompleteIFrame").style.display = "";
    document.getElementById("NameAutoComplete").style.display = "";
}

function ChangeKeywords(CategoryID, SubCategoryID)
{
    var Object = document.getElementById("NameAutoComplete");
    var IFrameObject = document.getElementById("NameAutoCompleteIFrame");
    var Keywords = document.getElementById("q");
    if (Keywords.value.length == 0)
    {
        Object.style.display = "none";
        IFrameObject.style.display = "none";
        return;
    }
    if (Object.style.display == "none")
    {
        Object.style.display = "";
        IFrameObject.style.display = "";
        PositionElementBelow(IFrameObject, Keywords, 0, 0);
        PositionElementBelow(Object, Keywords, 0, 0);
    }
    if (CategoryID == 16)
        SetInnerHTML("NameAutoComplete", "GetBookNames.aspx?S=" + Keywords.value + "&SC=" + SubCategoryID);
    else
        SetInnerHTML("NameAutoComplete", "GetAdsNames.aspx?S=" + Keywords.value + "&C=" + CategoryID + "&SC=" + SubCategoryID);
}

function SetInnerHTML(ObjectName, URL)
{
    var xmlhttp=false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
    try 
    {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) 
    {
        try 
        {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (E) 
        {
            xmlhttp = false;
        }
    }
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
    {
	    try 
	    {
    		xmlhttp = new XMLHttpRequest();
	    } 
	    catch (e) 
	    {
		    xmlhttp=false;
	    }
    }
    if (!xmlhttp && window.createRequest) 
    {
    	try 
    	{
		    xmlhttp = window.createRequest();
	    } 
	    catch (e) 
	    {
    		xmlhttp=false;
	    }
    }
    var Index = URL.indexOf('?');
    var Query;
    if (Index == -1)
        Query = null;
    else
    {
        Query = URL.substring(URL.indexOf('?') + 1);
        URL = URL.substring(0, Index);
    }
    
    
    xmlhttp.open("POST", URL, true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Charset", "utf-8");
    
    
    xmlhttp.onreadystatechange = function() 
        {
            if (xmlhttp.readyState == 4)
            {
                document.getElementById(ObjectName).innerHTML = xmlhttp.responseText;
            }
        }
        
    xmlhttp.send(Query);
            return;
}

function GetElementPosition(Element)
{
	var offsetLeft = 0;
	var offsetTop = 0;
	while (Element)
	{
		offsetLeft += Element.offsetLeft;
		offsetTop += Element.offsetTop;
		Element = Element.offsetParent;
	}
	if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined")
	{
		offsetLeft += document.body.leftMargin;
		offsetTop += document.body.topMargin;
	}
	return {left:offsetLeft, top:offsetTop};
}

function PositionElementBelow(ElementToMove, TargetElement, Left, Top)
{
//	if (ElementToMove.style.left != null && ElementToMove.style.left.length != 0)
//		return;
	var Position = GetElementPosition(TargetElement);
	if (Left == null)
		Left = 0;
	if (Top == null)
		Top = 0;
	if (document.body.dir == "rtl")
		ElementToMove.style.left = Position.left - ElementToMove.offsetWidth + TargetElement.offsetWidth - Left;
	else
	{
//	    if (TargetElement.parentElement == null)
//	        ElementToMove.style.left = Position.left - TargetElement.offsetLeft - ElementToMove.offsetWidth + TargetElement.offsetWidth + Left;
//	    else
//	        ElementToMove.style.left = Position.left - TargetElement.parentElement.offsetLeft + Left;
        ElementToMove.style.left = Position.left - Left;
	}
	//alert(document.body.clientHeight + document.body.scrollTop);
	var offsetTop = Position.top + TargetElement.offsetHeight - 1 + Top
	ElementToMove.style.top = offsetTop;
//	if ((document.body.clientHeight + document.body.scrollTop) <= (offsetTop + ElementToMove.offsetHeight))
//	{
//		ElementToMove.style.top = offsetTop - ElementToMove.offsetHeight;// - Top;
//		alert("Move up...");
//	}
	ElementToMove.style.position = "absolute";
}
