 
var timeOn = null;

var offsetleft = 0;
var offsettop = 1;
var delay = 400;
var tempbgcolor;
var lastitem;
var allitems = new Array();

// MENU MOUSE OVER 
function menuOver(id, parent, subid) 
{		
	var bParent = true;
	
	if (lastitem != parent)
	{
		//alert(lastitem);
		if (lastitem)
		{
			changeObjectVisibility(lastitem, 'none');
			hideFixMSIE(lastitem);
		}
        hideAllTo(parent);
		//hide(lastitem);
		if (parent == 'undefined')
		{
			bParent = false;
			hideAllMenus();
		}
	}
	
	if(subid)                                   
	{
		displaySubmenu(id,subid,bParent);
		if(allitems.indexOf(subid) === -1)
		{
			allitems.push(subid);
		}
		lastitem = subid;
	}
	clearTimeout(timeOn);
}

// MENU MOUSE OUT 
function menuOut(eDiv) 
{
    timeOn = setTimeout("hideAllMenus()", delay);
}       
 
function displaySubmenu(eParent, subid, bParent)
{
	if(bParent)
	{
		var x = getElementLeft(eParent) + getElementWidth(eParent);
		var y = getElementTop(eParent) - 1;		
	}
	else
	{
		var x = getElementLeft(eParent)  + offsetleft;
		var y = getElementTop(eParent) + getElementHeight(eParent) + offsettop;
	}
	
	changeObjectVisibility(subid, 'block');
	
	moveXY(subid, x, y); 

    getObject(subid).style.zIndex = 501;

    resizeFixMSIE(subid);  
}


function hideAllMenus()
{
	for (i=0; i<allitems.length; i++)
	{
        getObject(allitems[i]).style.zIndex = 500;
		changeObjectVisibility(allitems[i], 'none');
        hideFixMSIE(allitems[i]); 
	}
    allitems = new Array();
}

function hideAllTo(id)
{
    bVisible = true;
	for (i=0; i<allitems.length; i++)
	{
        if(allitems[i] == id)
        {
            bVisible = false;
            continue;
        }
        if(!bVisible)
        {
            getObject(allitems[i]).style.zIndex = 500;
		    changeObjectVisibility(allitems[i], 'none');
            hideFixMSIE(allitems[i]); 
        }
	}
}
 

/* Finds the index of the first occurence of item in the array, or -1 if not found */
if (typeof Array.prototype.indexOf == "undefined") {
    Array.prototype.indexOf = function(item) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] === item) {
                return i;
            }
        }
        return -1;
    }
}


// counter
function GetAllHits()
{    
    var xmlHttp;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var re = new RegExp('[a-z]+');
            if (xmlHttp.responseText.match(re))       
            {
                // for debug
                // alert(xmlHttp.responseText);
            }
            else
            { 
                getObject('counter').innerHTML = xmlHttp.responseText; 
            }
        }
    }
    
    var d = new Date();           
    xmlHttp.open("GET", strRootPath + "ajax.php5?m=counter&t=" + d.getTime(), true);
    xmlHttp.send(null);
}

// Inquiry
function CloseInquiryPopup()
{
    var d = document.body;  
    var pInquiryPopup = getObject("InquiryPopup");
    if (pInquiryPopup)
    {
        d.removeChild(pInquiryPopup);
    }
}

function InitPopupInquiry(strGetRequest)
{
    var nSelect;
    len = document.getElementsByName('radio_answer').length;
    for (i = 0; i <len; i++) 
    {
        if (document.getElementsByName('radio_answer')[i].checked) 
        {
            nSelect = document.getElementsByName('radio_answer')[i].value;
        }
    }

    
    CloseInquiryPopup();
    var xmlHttp;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }

    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        { 
            // Get Response Text
            pInquiryPopup = document.createElement('DIV');	
	        pInquiryPopup.id = 'InquiryPopup';
            pInquiryPopup.className = 'inquirypopup';
            
	        pInquiryPopup.innerHTML = xmlHttp.responseText; 
                                        
	        document.body.appendChild(pInquiryPopup);	
            
            var x = (getFrameWidth() / 2) - (pInquiryPopup.offsetWidth / 2) + getScrollX();
            var y = (getFrameHeight() / 2) - (pInquiryPopup.offsetHeight / 2) + getScrollY();   
                      
            pInquiryPopup.style.top = y + 'px';
            pInquiryPopup.style.left = x + 'px';     
        }
    }
    
    var d = new Date();             
    xmlHttp.open("GET", strRootPath + "ajax.php5?m=inquiries&a=vote" + strGetRequest + "&select=" + nSelect + "&t=" + d.getTime(), true);
    xmlHttp.send(null);
}

function Impress(strGetRequest)
{    
    // alert(strGetRequest);
    var xmlHttp;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var re = new RegExp('[a-z]+');
            if (xmlHttp.responseText.match(re))       
            {
                alert(xmlHttp.responseText);
            }
        }
    }
    
    var d = new Date();           
    xmlHttp.open("GET", strRootPath + "ajax.php5?" + strGetRequest + "&t=" + d.getTime(), true);
    xmlHttp.send(null);
}