var menuOpen=null;
var menuOver = null;
var _scolor = null;
var isIE = false; // 1 for Internet Explorer, 0 for other browsers
var submenus = new Array();
if(navigator.appName.indexOf('Microsoft') !=-1) {
	isIE = true;
}
var submenuitems=new Array();
//var _stack = new Stack();
var OVERLAP_WIDTH = 40;
var OVERLAP_HEIGHT = 2;
var TID = setInterval('hidemenu()', 2000);


function getdom(objid) {
	return (document.getElementById(objid));
}


function fillmenuitesms()
{
	
	if (window.XMLHttpRequest) {
	xmlRequest = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
	xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
	return false
	}
	
	if (xmlRequest)
	{
		pageUrl="pipe.php"
			xmlRequest.open("GET", pageUrl, true);
    xmlRequest.send(null);
	xmlRequest.onreadystatechange=function()
	{
	if(xmlRequest.readyState==4)
	{
	if(xmlRequest.responseText!=0){
		result=new Array();
	result=xmlRequest.responseText
		fillarray(result);
	}
	else
		return false;
	}
	}
	}
}

function fillarray(result)
{
	arrResult=result.split("^");
	for(i=0;i<arrResult.length-1;i++)
	{
		arrSubResult=arrResult[i].split(":");
		submenuitems[i]=arrSubResult;
	}
}


function showmenu(menuid, scolor) {

	obj=getdom("mcontainer");
	if(obj)
	{
removeAllChildren(obj)
	}
	menuOpen=menuid;
    menuOver = menuid;
    _scolor = scolor;
		

    
result="";
arrID=menuid.split("-");
recordID=arrID[1];

if(submenuitems.length>0)
	{
	qq = getdom('mcontainer');
  		if(isIE) {
  			qq.style.top= findPosY(getdom(menuid))+11;
  			qq.style.left = findPosX(getdom(menuid))+203;
  		} else {
  			qq.style.top = findPosY(getdom(menuid))-3 + 'px';
  			qq.style.left=findPosX(getdom(menuid))+193+ 'px';
  		}

qq.style.position = 'absolute';
qq.style.backgroundColor = '#624B65';


	nmenu = document.createElement('div');
    qq.appendChild(nmenu);
    
    nmenu.style.backgroundColor = '#624B65';
    nmenu.style.position = 'absolute';
    nmenu.style.width = '193px';

	sTop=findPosY(getdom(menuid));
	nmenu.style.backgroundColor = '#624B65';
    nmenu.id = '_' + menuid;
		nrsub=submenuitems.length
    // create the menu items
		mainText=0;
		for(x=0; x < nrsub; x++) {
		if(submenuitems[x][2]==recordID)
			{
			qq.style.display = 'block';
			
			//------------ Add text at the atsrt fo sub menu
			if(mainText==0){
			mainTextDiv=document.createElement('div');
			nmenu.appendChild(mainTextDiv);
			mainTextDiv.style.backgroundColor = '#624B65';
			mainTextDiv.className='bmenuon_new';
			mainTextDiv.innerHTML='<table width=100% ><tr><td width=100%  class=bmenuon valign=top>Cliquez sur la cat&eacute;gorie correspondant &agrave; votre demande afin de recevoir 3 devis gratuits </td></tr><tr><td height="3px"></td></tr></table>';
			//------------ Add the White line after this text------
			subTextDiv=document.createElement('div');
			nmenu.appendChild(subTextDiv);
			subTextDiv.style.backgroundColor = '#624B65';
			subTextDiv.className='bmenuon_new';
			subTextDiv.style.height="2px";
			//-----------------------------------------------------
			mainText=1;
			}
			//-------------------------------------------


			categoryname=submenuitems[x][1];
			categoryid=submenuitems[x][0];
			ndiv=document.createElement('div');
        nmenu.appendChild(ndiv);
			ndiv.className='bmenuon_new';
			ndiv.style.backgroundColor = '#624B65';
        ndiv.id = 'menu' + menuid;
		
			ndiv.innerHTML= '<table width=100% border=0><tr><td width=5%><img src="images/small_box.jpg" border=0 width=6 height=6></td><td width=95%  class=bmenuon valign=top>' +categoryname+ '</td></tr></table>';
		ndiv.style.cursor="pointer";
		ndiv.setAttribute('openlink', 'form.php?id='+categoryid);
        
			ndiv.onclick=function() {
					document.location.href=this.getAttribute('openlink');
			};
        
        if ( x != nrsub-1 ) {
  			ndiv.onmouseover=function() {
  					this.style.backgroundColor = '#978998';
                    this.style.color = '#ffffff';
                    menuOver = this;
  			};
  			ndiv.onmouseout=function(scolor) {
  					this.style.backgroundColor = '#624B65';
                    this.style.color = '#ffffff';
                    menuOver = null;
  			};
        } else {
            ndiv.onmouseover = function() {
				
				
                    this.style.backgroundImage =  'url(images/rollover.jpg)';
                    this.style.color = '#ffffff';
                    menuOver = this;
                    if (submenus[this.id]) {
                      showmenu(this.id, this.getAttribute('scolor'));
                    };
            }
            ndiv.onmouseout = function() {
                    this.style.backgroundImage = 'url(images/bg_' + _scolor + '.gif)';
                    this.style.color = '#000000';
                    menuOver = null;
            }
        }
		}
		
		
	}
		
	}


}



function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent)	{
			curleft += obj.offsetLeft;
			if(!obj.offsetParent) {
				break;
			}
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent)	{
			curtop += obj.offsetTop;
			if(!obj.offsetParent) {
				break;
			}
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function hidemenu() {
	
tobj=getdom("mcontainer");
if(!menuOver)
	{
 removeAllChildren(tobj)
	}
}

function removeAllChildren(tobj) {
	if(tobj.childNodes.length > 0 ) {
		while(tobj.childNodes.length) {
			tobj.removeChild(tobj.firstChild);
		}
	}
	// hide the container
	tobj.style.display='none';
}

