function CollapseMenu(x,y,width,numBlocks,name) {
    this.name = (name!=null)? name : "Lyr"
    this.x = x
    this.y = y
    this.w = width
    this.numBlocks = numBlocks
    this.bgColor = '#ffffff'
    this.openStyle = "move"  // or 'glide' or 'move' or 'slide'
    this.contentIndent = 0
    this.inc = 5
    this.speed = 20
    this.active = false
    this.build = CollapseMenuBuild
    this.activate = CollapseMenuActivate
    this.toggle = CollapseMenuToggle
	this.open = CollapseMenuOpen
	this.close = CollapseMenuClose
    this.finish = CollapseMenuFinish
    this.showlayer = CollapseShowLayer
    this.onToggle = new Function()
}

function CollapseMenuBuild() {
    this.css = css(this.name,this.x,this.y,this.w,0)
    for (var i=0;i<this.numBlocks;i++) {
        this.css += css(this.name+i+'Hdr',0,0,this.w,null,this.bgColor)
        this.css += css(this.name+i+'Dtl',0,0,this.w,null,this.bgColor,null,null,'margin-left:'+this.contentIndent)
    }
    this.css += css(this.name+this.numBlocks,0,0,this.w,0,this.bgColor)
	if(is.ie)
    		this.divStart = '<div id="'+this.name+'" style="position:absolute; left:19%; top:340px;">'
	if(is.ns5)
		this.divStart = '<DIV id="'+this.name+'" style="position:relative; width:200px; height:2500px; left:0px; top:0px; display:block;">' 
	else if(is.ns) 
   		this.divStart = '<div id="'+this.name+'">'
    this.divEnd = ''
    this.divEnd += '<div id="'+this.name+this.numBlocks+'"></div>'
    this.divEnd += '</div>'
}

function CollapseMenuActivate() {

    this.lyr = new DynLayer(this.name)
    this.blocks = new Array()
    this.itemTotal = 0
    this.contentTotal = 0

    for (var i=0;i<this.numBlocks;i++) {

        this.blocks[i] = new Object()
        this.blocks[i].open = false
        this.blocks[i].trainingFormat = 0
        
        this.blocks[i].loaded = false

        this.blocks[i].itemlyr = new DynLayer(this.name+i+'Hdr')
        this.blocks[i].itemHeight = this.blocks[i].itemlyr.getContentHeight()
           //alert("Item Height"+ this.blocks[i].itemHeight);	
        this.blocks[i].itemlyr.clipTo(0,this.w,this.blocks[i].itemHeight,0)

        this.blocks[i].contentlyr = new DynLayer(this.name+i+'Dtl')
        this.blocks[i].contentHeight = this.blocks[i].contentlyr.getContentHeight()
          //alert("Content Height"+ this.blocks[i].contentHeight);	
        this.blocks[i].contentHeightOrg = this.blocks[i].contentHeight        
        this.blocks[i].contentlyr.clipTo(0,this.w,this.blocks[i].contentHeight,0)

        if (i!=0)
        {
          this.blocks[i].itemlyr.moveTo(null,this.itemTotal)
        }

        this.itemTotal += this.blocks[i].itemHeight
	this.contentTotal += this.blocks[i].contentHeight

	this.blocks[i].contentlyr.moveTo(null,this.itemTotal)

        this.blocks[i].h = this.blocks[i].itemHeight + this.blocks[i].contentHeight
    }

    this.h = this.contentTotal + this.itemTotal

    this.blocks[this.numBlocks] = new Object()
    this.blocks[this.numBlocks].lyr = new DynLayer(this.name+this.numBlocks)
    this.blocks[this.numBlocks].lyr.clipTo(0,this.w,this.h,0)
    this.blocks[this.numBlocks].lyr.css.height = this.h-this.itemTotal
    this.blocks[this.numBlocks].lyr.moveTo(null,this.h)
	//alert(this.w +","+this.h);
    this.lyr.clipTo(0,this.w,this.h,0)
}

function CollapseMenuToggle(i,wddiid,orgid,plang,locationid,startdate,enddate,orderby,orderdirection,noofrecs,trainingformat,deliverylang,debugyn,showseatsyn,countries) {
    sortload = 0;

    //alert(locationid);	    
    if (this.active) return
    this.active = true

    //Store Activity ID for Print View Check for already exists ?

  //  passactivitytoprintview(this.blocks[i].open,wddiid)

   if ((!this.blocks[i].open) || (trainingformat!=this.blocks[i].trainingFormat) ){
     if (this.blocks[i].open)
     	this.close(i,trainingformat,true)
     this.open(i,wddiid,orgid,plang,locationid,startdate,enddate,orderby,orderdirection,noofrecs,trainingformat,deliverylang,debugyn,showseatsyn,countries)
    }
    else 
    {
     this.close(i,trainingformat,false)
    } 
}


function changeTab(i,trainingformat,prevFormat,linktext,lmode){
	var leftImgName="I"+i+trainingformat+"L";
	var rightImgName="I"+i+trainingformat+"R";
	var leftSelectedImgName="I"+i+prevFormat+"L";
	var rightSelectedImgName="I"+i+prevFormat+"R";
	var linkName="A"+i+trainingformat;
	var openLinkName="A"+i+prevFormat;
	var leftTab="T"+i+trainingformat+"L";
	var bodyTab="T"+i+trainingformat+"B";	
	var rightTab="T"+i+trainingformat+"R";
	var leftSelectedTab="T"+i+prevFormat+"L";
	var bodySelectedTab="T"+i+prevFormat+"B";	
	var rightSelectedTab="T"+i+prevFormat+"R";
		
	// tab text
	for (i=0;i<document.links.length;i++){	  
	  if (document.links[i].name==linkName)
	  {
		document.links[i].innerHTML=linktext;
	  }	
	  if (trainingformat!=prevFormat && (document.links[i].name==openLinkName))
	  {
	      if (trainingformat==2 || trainingformat==4)
		document.links[i].innerHTML=opentexttbtspo;
	      else	
		document.links[i].innerHTML=opentext;	      
	  }	
	}
	
	// tab images
	
	//alert(document.tr.length);
	
//Added by Amit 5197021
		if(is.ns5)
		{
           		if (lmode=="O")
           		{
			//	alert("in lmode=0 in changeTab in is.ns5" );
				document.images[leftImgName].src = selectedLeftTabImg ;
				document.images[rightImgName].src = selectedRightTabImg ;
				//Added by Amit 5197021
				if (document.getElementById(leftTab))
					document.getElementById(leftTab).className = "selected";
				if (document.getElementById(bodyTab))
					document.getElementById(bodyTab).className = "selected";
				if (document.getElementById(rightTab))
					document.getElementById(rightTab).className = "selected";
				

	      		if (trainingformat!=prevFormat && prevFormat!=0)
	      		{
				document.images[leftSelectedImgName].src = leftTabImg ;
				document.images[rightSelectedImgName].src = rightTabImg ;
				if (document.getElementById(leftSelectedTab))
					document.getElementById(leftSelectedTab).className = "nonSelected";

				if (document.getElementById(bodySelectedTab))
					document.getElementById(bodySelectedTab).className = "nonSelected";
				if (document.getElementById(rightSelectedTab))
					document.getElementById(rightSelectedTab).className = "nonSelected";

              	//		this.doc.images[leftSelectedImgName].src = leftTabImg            
              	//		this.doc.images[rightSelectedImgName].src = rightTabImg                          
              	}
           	}
          	else
          	{
				document.images[leftImgName].src = leftTabImg ;
				document.images[rightImgName].src = rightTabImg ;
				if (document.getElementById(leftTab))
					document.getElementById(leftTab).className = "nonSelected";
				if (document.getElementById(bodyTab))
					document.getElementById(bodyTab).className = "nonSelected";
				if (document.getElementById(rightTab))
					document.getElementById(rightTab).className = "nonSelected";			
                    
          	}		 
		 }
///////////////
         else if (is.ns) 
	{
           if (lmode=="O")
           {
              this.doc.images[leftImgName].src = selectedLeftTabImg            
              this.doc.images[rightImgName].src = selectedRightTabImg                          
	      	  if (trainingformat!=prevFormat && prevFormat!=0)
	      	  {
              	this.doc.images[leftSelectedImgName].src = leftTabImg            
              	this.doc.images[rightSelectedImgName].src = rightTabImg                          
              }
           }
           else
           {
              this.doc.images[leftImgName].src = leftTabImg            
              this.doc.images[rightImgName].src = rightTabImg                          
           }
         }
         else 
         {
           if (lmode=="O")
           {
               document.images[leftImgName].src = selectedLeftTabImg
	       document.images[rightImgName].src = selectedRightTabImg     

	       for (i=0;i<document.all.length;i++){
		 if (document.all[i].id==leftTab)
			document.all[i].className="selected";	
		 if (document.all[i].id==bodyTab)
			document.all[i].className="selected";	
		 if (document.all[i].id==rightTab)
			document.all[i].className="selected";	
	       }
	       
	       if (trainingformat!=prevFormat && prevFormat!=0)
	       {
               	document.images[leftSelectedImgName].src = leftTabImg
	       	document.images[rightSelectedImgName].src = rightTabImg               

	       for (i=0;i<document.all.length;i++){
		 if (document.all[i].id==leftSelectedTab)
			document.all[i].className="nonSelected";	
		 if (document.all[i].id==bodySelectedTab)
			document.all[i].className="nonSelected";	
		 if (document.all[i].id==rightSelectedTab)
			document.all[i].className="nonSelected";	
	       }
	       	
	       }		
           }
           else
           {
               document.images[leftImgName].src = leftTabImg
	       document.images[rightImgName].src = rightTabImg               

	       for (i=0;i<document.all.length;i++){
		 if (document.all[i].id==leftTab)
			document.all[i].className="nonSelected";	
		 if (document.all[i].id==bodyTab)
			document.all[i].className="nonSelected";	
		 if (document.all[i].id==rightTab)
			document.all[i].className="nonSelected";	
	       }
	       
           }
         }
}

function CollapseMenuOpen(i,wddiid,orgid,plang,locationid,startdate,enddate,orderby,orderdirection,noofrecs,trainingformat,deliverylang,debugyn,showseatsyn,countries) {
    if ((!this.blocks[i].open) || (trainingformat!=this.blocks[i].trainingFormat)) {
        var h = this.blocks[i].contentHeight + this.blocks[i].itemHeight
        this.blocks[i].open = true
        if (this.openStyle == 'move') {
                        //show the content layer
		            layerno = i;
		            if ((!this.blocks[i].loaded) || (trainingformat!=this.blocks[i].trainingFormat)) {
		            	//alert(locationid);
                                this.blocks[i].contentlyr.loadIt("WEBREG_COURSE_RESULTSCSS.display_events?p_org_id="+orgid+"&p_lang="+plang+"&p_wddi_id="+wddiid+"&p_activity_no="+i+"&p_location_id=" + locationid + "&p_start_date=" + startdate + "&p_end_date=" + enddate + "&p_orderby=" + orderby + "&p_orderdirection=" + orderdirection + "&p_no_of_records="+noofrecs +"&p_trainingformat=" + trainingformat+"&p_delivery_lang="+ deliverylang+"&p_debug_yn=" + debugyn + "&p_show_seats=" + showseatsyn + "&p_country="+ countries);
                                //alert("WEBREG_COURSE_RESULTS.display_events?p_org_id="+orgid+"&p_lang="+plang+"&p_wddi_id="+wddiid+"&p_activity_no="+i+"&p_location_id=" + locationid + "&p_start_date=" + startdate + "&p_end_date=" + enddate + "&p_orderby=" + orderby + "&p_orderdirection=" + orderdirection + "&p_no_of_records="+noofrecs +"&p_trainingformat=" + trainingformat+"&p_delivery_lang="+ deliverylang+"&p_debug_yn=" + debugyn + "&p_show_seats=" + showseatsyn);
                                this.blocks[i].loaded = true;

    		            }
                            else
                            {

                              //Move Down all the layers below this
                               var theDifference = this.blocks[i].contentHeight
       			       this.blocks[this.numBlocks].lyr.moveBy(0,theDifference);

    			       for (j=this.numBlocks-1; j>=layerno+1; j--)
    			       {
      				 this.blocks[j].itemlyr.moveBy(0,theDifference);
      				 if (this.blocks[j].loaded)
          			 {
      				   this.blocks[j].contentlyr.moveBy(0,theDifference);
      				 }
                               }

			       this.blocks[i].contentlyr.showIt();
                            }
                            //change the closed image to open
                            //this.blocks[i].itemlyr.img('myImg'+i,'/images/emea/open.gif',closetext);
                            if (is.ie)
                            {
                            	if (trainingformat==2 || trainingformat==4 || trainingformat==6 )
                            		changeTab(i,trainingformat,this.blocks[i].trainingFormat,closetexttbtspo,"O");
                                else
                            		changeTab(i,trainingformat,this.blocks[i].trainingFormat,closetext,"O");
                            }
                            else if(is.ns5)
                            {
				//Added all else by Amit 5197021 for netscape
				if (trainingformat==2 || trainingformat==4 || trainingformat==6 )
       	                		changeTab(i,trainingformat,this.blocks[i].trainingFormat,closetexttbtspo,"O");
                                else
                            		changeTab(i,trainingformat,this.blocks[i].trainingFormat,closetext,"O");
				//////////////////////////         
                   	//this.blocks[i].itemlyr.img('I'+i+trainingformat+'R','/images/green_slant_right.gif',closetext);
                            }
                            this.finish();
            }
        this.blocks[i].trainingFormat = trainingformat            
    }
}



function CollapseMenuClose(i,trainingformat,forceclose) {
    //alert(this.blocks[i].open)
    //alert(this.blocks[i].trainingFormat)
    //alert(trainingformat)
    //alert(forceclose)
    if (((this.blocks[i].open) && (this.blocks[i].trainingFormat==trainingformat)) || forceclose) {
        var h = this.blocks[i].contentHeight
        if (!forceclose)
        {
          this.blocks[i].open = false
          this.blocks[i].trainingFormat = trainingformat
        }  
        if (this.openStyle == 'move') {

                            //move the blocks up
                            var theDifference = eval(-1 * h)
    			    for (j=i+1; j<=this.numBlocks-1; j++)
    			    {
      				this.blocks[j].itemlyr.moveBy(0,theDifference);
          			if (this.blocks[j].loaded)
          			{
      				   this.blocks[j].contentlyr.moveBy(0,theDifference);
      				}
                            }
                            this.blocks[j].lyr.moveBy(0,theDifference);

                            //hide the content layer
                            this.blocks[i].contentlyr.hideIt();

                            //change the open image to closed
                            //this.blocks[i].itemlyr.img('myImg'+i,'/images/emea/closed.gif',opentext);
			    //changeTab("A"+i+trainingformat,opentext,"A"+i+0,"I"+i+trainingformat,"I"+i+0,"C",0);	
			    if (is.ie)
			    {
			    	if (trainingformat==2 || trainingformat==4)
			    		changeTab(i,trainingformat,0,opentexttbtspo,"C");
			        else
			    		changeTab(i,trainingformat,0,opentext,"C");
			    }		
//Added else by Amit 5197021 for Netscape
			else if(is.ns5)
			{
			    	if (trainingformat==2 || trainingformat==4)
			    		changeTab(i,trainingformat,0,opentexttbtspo,"C");
			        else
			    		changeTab(i,trainingformat,0,opentext,"C");
				}		
////////////////////////////////////////////////					
                            this.finish();
                        }
    }
}

function CollapseMenuFinish() {
    this.active = false
    this.onToggle()
}


function CollapseShowLayer(ifrom)
{

 if (eventid!=null)
 {
 if (is.ie)  eventid.innerHTML=dummyframe.document.all.theHTML.innerHTML
  
//Added by Amit 5197021
if(is.ns5)
{
	ifrom = 1;
	eventid.innerHTML = window.frames["dummyframe"].window.document.getElementById("theHTML").innerHTML ;
//	eventid.innerHTML = window.frames.dummyframe.window.document.getElementById("theHTML").innerHTML ;
}

///////////////
  if ((is.ns && ifrom == 1) || (is.ie && ifrom == 0))
  {
 
   // Only do for toggle not for sort order loading	
   if (sortload != 1)
   {
    var prevContentHeight = this.blocks[layerno].contentHeight; //
    
//alert("prevContentHeight:"+prevContentHeight);
    
    this.blocks[layerno].contentHeight = this.blocks[layerno].contentlyr.getContentHeight()

//alert("contentHeight:"+this.blocks[layerno].contentHeight);
    
    var theDifference = this.blocks[layerno].contentHeight - prevContentHeight

//alert("theDifference:"+theDifference);    
//alert("contentTotal Before:"+ this.contentTotal);
    
    this.contentTotal = eval(this.contentTotal + theDifference) //

//alert("contentTotal After:"+ this.contentTotal);
//alert("w:"+this.w);
    
    this.blocks[layerno].contentlyr.clipTo(0,this.w,this.blocks[layerno].contentHeight,0);

    var lh = this.blocks[layerno].contentHeight + this.blocks[layerno].itemHeight

    this.blocks[layerno].h = lh; //

    this.h = this.contentTotal + this.itemTotal //

    // move all layers after this down

    // first current content layer

    var moveHeight = 0;
    var useMove = false;
    for (k=0;k<layerno;k++ )
    {
          moveHeight += this.blocks[k].itemlyr.getContentHeight();
          //alert(this.blocks[k].open + ":" + this.blocks[k].loaded);
          if (this.blocks[k].loaded)
          {
            if  (this.blocks[k].open)
                moveHeight += this.blocks[k].contentlyr.getContentHeight();
            else
                useMove = true;
          }

    }
    moveHeight += this.blocks[k].itemlyr.getContentHeight();

//alert("moveHeight:"+ moveHeight);

    // then all next item and content layers
    this.blocks[this.numBlocks].lyr.moveBy(0,this.blocks[layerno].contentHeight);

    for (j=this.numBlocks-1; j>=layerno+1; j--)
    {
      this.blocks[j].itemlyr.moveBy(0,this.blocks[layerno].contentHeight);
      //if (this.blocks[j].loaded)
      //{
        this.blocks[j].contentlyr.moveBy(0,this.blocks[layerno].contentHeight);
      //}
    }

    if (useMove)
      this.blocks[layerno].contentlyr.moveTo(0,moveHeight);

    this.lyr.clipTo(0,this.w,this.h,0)//

//    if (is.ns) document.height = collapse.lyr.y + collapse.h;

   }
   
    this.blocks[layerno].contentlyr.showIt();
    //this.blocks[layerno].contentlyr.focus();
   }
  }

}


function processselection(cstatus,cvalue) {

  var citem = document.forms.emea_result.emea_course;
  var cstring = "," + cvalue;
  // check for the value first
  if (cstatus){
  //add value
  citem.value += cstring;
  }
  else
  {
  // remove value
    var cstartpos = citem.value.indexOf(cstring);
    var ctempstr;
    ctempstr = citem.value.substr(0,cstartpos)+citem.value.substr(cstartpos+cstring.length);
    citem.value = ctempstr;
  }

  passeventtoprintview(cstatus,cvalue);
}

function resultvalidationlayer(thisform)
{
   if (document.forms.emea_result.emea_course.value.length == 0){alert("Please Select At Least One Course"); return false;}
   return true;
}


function processjoinwaitlist(cstatus,cvalue,ccountry,cinsearchcountry) {
    // New Version (Accept Questions)
    // First check about user login 
    //   alert(cinsearchcountry);
    if (inSearchFlag=="Yes")
    {
    	top.bookingvalidation();	
    }
    else
    {
 	window.open("emea_course_request.ask?in_course_id="+cvalue + "&in_country=" + ccountry + "&in_search_country=" + cinsearchcountry,"plannedwindow","height=600,width=800,resizable=yes,toolbar=no,scrollbars=yes,location=no");   	
    }
    // Old Version (Email)
    //show mail to request
    //    openWindow=open("mailto:"+courseInfoEmail+"?subject="+ joinWaitListEmailSubject + "("+ cvalue + ")","mailwindow");
    // if (openWindow != null)
    //    openWindow.close();
 }
 


