/*-------------------------------------------------------------------------------------------------------------
EVENTS SEARCH BLOCK --> MOUSEOVER FOR DAYS BUTTONS
-------------------------------------------------------------------------------------------------------------*/

function dayMOver ( obj,sNum )
{
	iNum = parseInt(sNum, 10);
	obj.className = "tab_bg";
	gid('but_tab'+sNum).src     = './images/general/events_tab_button_bg_left.gif';
	gid('but_tab'+(iNum+1)).src = './images/general/events_tab_button_bg_right.gif';
}

function dayMOut ( obj, sNum )
{
	iNum = parseInt(sNum, 10);
	obj.className="tab_bg_ov";
	gid('but_tab'+sNum).src='./images/general/event_tab_sep.gif';
	gid('but_tab'+(iNum+1)).src='./images/general/event_tab_sep.gif';
}


/*-------------------------------------------------------------------------------------------------------------
ADD AN EVENT
-------------------------------------------------------------------------------------------------------------*/


var flag=0;
var tt=0;


function ae_obj_ov(obj)
{
	obj.style.backgroundColor = "#B6D2E8";
	obj.style.backgroundImage = "";
}

function ae_obj_out(obj)
{
	obj.style.backgroundImage = "url(images/general/bg_sel_ev.gif)";
	obj.style.backgroundColor = "";
}


function ch_bg_ov(ob)
{
	if(flag==0) {ae_obj_ov(ob);}//ob.className="addEvbg_ov";
}


function ch_bg_out(ob)
{
	if(flag==0)	{ae_obj_out(ob);}//ob.className="addEvbg";
}


function ch_bg_cl(rad)
{
	flag=1;
	
	var prbg = document.getElementById('prbg');
	var pbbg = document.getElementById('pbbg');
	
	if(rad=='public')
	{
		ae_obj_ov(pbbg);
		ae_obj_out(prbg);
	}
	if(rad=='private')
	{
		ae_obj_ov(prbg);
		ae_obj_out(pbbg);
	}
}


function addEvent()
{
	if (document.getElementById('private').checked)
	{
		window.location = "events_add.php?type=private";
	}
	else
	{
		window.location = "events_add.php?type=public";
	}
}



/*-------------------------------------------------------------------------------------------------------------
SEARCH EVENT CALENDAR POPUP
-------------------------------------------------------------------------------------------------------------*/


var bDateRange = false;


function showESCalendar(obj,sDate)
{
	var sFID = obj.name;
	var iLeft = 0;
	var iTop = 0;
	
	if (obj.offsetParent)
	{
		el = obj;
		iLeft = el.offsetLeft;
		iTop = el.offsetTop;
		while ( el = el.offsetParent)
		{
			iLeft += el.offsetLeft;
			iTop  += el.offsetTop;
		}
	}
	
	//var sRQ = bDateRange ? '&dr=1' : '';
	show_popup_calendar(sDate,'e_search','new',iTop+18,iLeft-189,sFID);
}


function setCalDate ( sDate )
{
	var sFID = gid('calendar_body').attributes.getNamedItem("name").value;
	
	gid(sFID).value = sDate;
	//gid(sFID).innerHTML = gid(sFID).value;
}


onShowCalPopup = function ()
{
	showDateRange( bDateRange?1:-1 );
};


/*-------------------------------------------------------------------------------------------------------------
SHOW CALENDAR for slider
-------------------------------------------------------------------------------------------------------------*/


function event_calendar_show(el)
{
	/*var curleft = curtop = 0;
	var obj = el;
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj=obj.offsetParent)
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	
	document.getElementById('event_calen').style.display=""
	document.getElementById('event_calen').style.left = curleft - 551;
	document.getElementById('event_calen').style.top = curtop - 240;
	document.getElementById('cal_icon_bg').className="cal_ov";
	document.getElementById('but_tab8').src='images/general/event_tab_sep.gif';
	document.getElementById('but_tab9').src='images/general/event_tab_sep.gif';*/

	for ( var i=1;i<4;i++ )
	{
		CDSelector.clear_calendar( gid('calendar'+i).getElementsByTagName('div')[0] );
	}
	
	oSlide.construct(Array('calendar1','calendar2','calendar3'), displayEventsCalendar,Array('escright','escleft'),nextCalendar);
	
	/*el.onmouseover = null;
	el.onmouseout  = null;
	el.onclick = function() { event_calendar_hide(el) };*/
}


function event_calendar_hide(obj)
{
	document.getElementById('calpp').style.display="none";
	//document.getElementById('cal_icon_bg').className="cal";
	
	//document.getElementById('cal_dis_top').style.display="none";
	if(gid('mp1').childNodes[0]) {
	startMostPopular();
	}
	
	//showtab_show('but_tab8','cal_icon_bg','but_tab9');
	

	//obj.onmouseover = function () { dayMOver(obj,8); };
	//obj.onmouseout  = function () { dayMOut(obj,8);  };
	//obj.onclick = function () { event_calendar_show(obj); };
}

/*function displayEventsCalendarListPre(sDate,sDivID)
{
	setTimeout(function(){displayEventsCalendar(sDate,sDivID);}, 4000);
}*/

function displayEventsCalendarListPre(date1, date2, date3) {
	var url = 'ajax_calendar_slider.php?date1=' + escape(date1) +'&date2=' + escape(date2) +'&date3=' + escape(date3) + '&rnd=' + Math.floor(Math.random()*1000000 );
	var sdate = new Array(date1, date2, date3);
	var rq = GetXmlHttpObject();
	var func = function ()
	{
		xmlDoc=rq.responseText;
		result = xmlDoc.split("<calendar>"); 
		for(var i=1; i< 4; i++) {

                var CalContainer = document.createElement('div');
                CalContainer.setAttribute('name',sdate[i-1]);
                CalContainer.setAttribute('style',"width:199px;height:187px;");
                gid('calendar'+i).innerHTML = '';
                gid('calendar'+i).appendChild(CalContainer);
			CalContainer.innerHTML = result[i];
			CDSelector.attach_calendar(CalContainer);
			
		}
		event_calendar_show(gid('cal_icon_bg'));
	};
	
	rq.onreadystatechange = function() { onRSC(rq,func); };
	rq.open( "GET", url, true );
	rq.send( null );
	
	//return CalContainer;
}


function displayEventsCalendar(sDate,sDivID,fAdd)
{
	var url = 'ajax_calendar.php?date=' + escape(sDate) +'&type=evslider'+ '&rnd=' + Math.floor(Math.random()*1000000 );
	
	var rq = GetXmlHttpObject();
	
	var CalContainer = document.createElement('div');
		CalContainer.setAttribute('name',sDate);
		CalContainer.setAttribute('style',"width:199px;height:187px;");
	gid(sDivID).innerHTML = '';
	gid(sDivID).appendChild(CalContainer);				
	
	var func = function ()
	{
		CalContainer.innerHTML = rq.responseText;
		if (fAdd||false) {fAdd();}
		CDSelector.attach_calendar(CalContainer);
	};
	
	rq.onreadystatechange = function() { onRSC(rq,func); };
	rq.open( "GET", url, true );
	rq.send( null );
	
	return CalContainer;
}


function nextCalendar(val,dir)
{
	var dY = 0;
	var aDate = val.split('-');
		aDate[1] = parseInt(aDate[1],10);
	
	if ( dir==1 )
	{
		aDate[0] = aDate[1]==12 ? parseInt(aDate[0],10)+1 : aDate[0]; 
		aDate[1] = aDate[1]==12 ? 1 : aDate[1]+1;
	}
	
	if ( dir==-1 )
	{
		aDate[0] = aDate[1]==1 ? parseInt(aDate[0],10)-1 : aDate[0]; 
		aDate[1] = aDate[1]==1 ? 12 : aDate[1]-1;
	}
	
	
	return aDate.join('-');
}


/*-------------------------------------------------------------------------------------------------------------
MOST POPULAR for slider
-------------------------------------------------------------------------------------------------------------*/

var iMostPopularCount=0;
var iMPECount = 3;
var iPB = 5;
var iPBWidth = 0;


function displayMostPopular(iPlace,sDivID,fAdd)
{
	
	var homeloc = gid('homelocChanged').value;
	var url = 'ajax_most_popular.php?place=' + iPlace[0] +'&homeloc='+homeloc+ '&rnd=' + getRandom();
	var request = GetXmlHttpObject();
	
		//MPEContainer.setAttribute('name',iPlace);
	//gid(sDivID).innerHTML = '';
	//gid(sDivID).appendChild(MPEContainer);				
	var myPlace;
	var sendArr = new Array();
	var func = function ()
	{
		
		var result = request.responseText;
		result = result.split("..tt.."); 
		for(i=0; i<result.length; i++) {
			if(i == result.length-1 && iPlace[0] == 0) {
				iMostPopularCount = result[i];
				iMostPopularCount = Math.floor(iMostPopularCount/iMPECount)*iMPECount;
				oSlide.end = iMostPopularCount - 1;
			} else {
				var myPlace = "MPEContainer" + i;
				myPlace = document.createElement('div');
				myPlace.setAttribute('name',iPlace[i]);
				gid(sDivID[i].id).innerHTML = '';
				gid(sDivID[i].id).appendChild(myPlace);
				myPlace.innerHTML = result[i];
				sendArr.push(myPlace);
			}
		}
		progressMostPopular();
		if (fAdd||false) {fAdd();}
	};
	
	request.onreadystatechange = function() { onRSC(request,func); };
	request.open( "GET", url, true );
	request.send( null );
	
	 
	 return sendArr;
}


function nextMPE (val,dir)
{
	val = parseInt(val,10);
	//val = val;
	val += dir>0 ? 1 : -1;
	return val;
}


function startMostPopular(aSC)
{
	aSC = (aSC||false) ? aSC : false;
	oSlide.construct(Array('mp1','mp2','mp3'), displayMostPopular,Array('mpcright','mpcleft'),nextMPE,aSC,0,iMostPopularCount,progressMostPopular,true);
}


function startMostPopularSlider()
{
	//var homeloc = gid('homelocChanged').value;
	//var url = 'ajax_most_popular.php?count=1&homeloc='+homeloc+'&rnd=' + getRandom();
	//var rq = GetXmlHttpObject();

	//var func = function()
	//{
		//var aRes = /MPE COUNT : ([\d]+) :/.exec(rq.responseText);
		//iMostPopularCount = aRes[1];
		//iMostPopularCount = Math.floor(iMostPopularCount/iMPECount)*iMPECount;
		// startMostPopular(Array(0,1,2));
		//startMostPopular('');
	//};
	
	//rq.onreadystatechange = function(){onRSC(rq,func);};

	//rq.open( "GET", url, true );
	//rq.send( null );
	
	//iMostPopularCount = 15
	startMostPopular(Array(0,1,2));
}



function progressMostPopular()
{
	var iMPC = iMPECount*iPB;
	var iNum = parseInt(gid('mp1').childNodes[0].attributes.getNamedItem("name").value,10);
		iNum = iNum%iMPC;
	var k = Math.round(iNum/iMPC*iPB);
	for (var i=0; i<iPB; i++)
	{
		gid('MPE_PB_item_'+i).src= (i==k) ? "./images/icons/general/rating_rec_fill.gif" : "./images/icons/general/rating_rec_empty.gif";
	}

	/*
	if ( iMostPopularCount>0 )
	{
		var iNum = parseInt(gid('mp1').childNodes[0].attributes.getNamedItem("name").value,10);
		
		if (iPBWidth==0)
		{
			iPBWidth = iMostPopularCount>=15 ? 1 : Math.round( (iMPECount*iPB)/iMostPopularCount );
		}
		
		var iStart = iNum/iMostPopularCount*iPB;
		var iEnd   = iStart+iPBWidth;
		var k = 0;

		for (var i=0; i<iPB; i++)
		{
			k = i+0.5;
			gid('MPE_PB_item_'+i).src= (iStart<=k && k<iEnd) ? "./images/icons/general/rating_rec_fill.gif" : "./images/icons/general/rating_rec_empty.gif" ;
		}
	}
	*/
}



/*-------------------------------------------------------------------------------------------------------------
SLIDER OBJECT
-------------------------------------------------------------------------------------------------------------*/


var oSlide = new Object();
	oSlide.divs = new Array();
	oSlide.getContent = null;
	oSlide.progressBar = false;
	oSlide.controls = new Array();
	oSlide.slides = new Array();
	oSlide.start = 0;
	oSlide.end = 0;
	oSlide.step = 0;
	oSlide.tripleClick = false;


	oSlide.free = function()
	{
		this.divs = new Array();
		this.getContent = null;
		this.progressBar = false;
		this.controls = new Array();
		this.slides = new Array();
		this.start = 0;
		this.end = 0;
		this.step = 0;
	};


	oSlide.construct = function(divs,func,controls,step,aSC,iStart,iEnd,pb_func,tripleClick)
	{
		
		this.free();

		this.tripleClick = (tripleClick||false) ? tripleClick : false;
		this.step = step;
		if (iEnd||false)
		{
			this.start = parseInt(iStart,10);
			this.end = parseInt(iEnd,10)-1;
		}
		
		if ( pb_func || false )
		{
			this.progressBar = pb_func;
		}
		
		for(var i=0;i<divs.length;i++) {this.divs.push(gid(divs[i]));}
		
		this.getContent = func;
		
		for(var i=0;i<controls.length;i++) {this.controls.push(gid(controls[i]));}

		this.controls[0].onclick = oSlide.left;
		this.controls[1].onclick = oSlide.right;

		if ( aSC||false )
		{	if(func == displayMostPopular) {
				this.content(aSC,this.divs);
			} else {
				for(var i=0,l=aSC.length;i<l;i++) {this.content(aSC[i],this.divs[i]);}
			}
		}
		else
		{
			var o;
			for(var i=0,l=this.divs.length;i<l;i++)
			{
				o = this.divs[i].childNodes[0];
				var sPalce = o.getAttribute('name'); 
				this.slides[sPalce] = o;
			}
			this.check();
		}
	
		if(tripleClick){
			//oSlide.controls[0].style.visibility = 'hidden';
			//oSlide.controls[1].style.visibility = 'hidden';
		}
	};

	
	oSlide.left = function()
	{
		if ( oSlide.tripleClick)
		{	var splaceArr = new Array(); 
			var iLast = oSlide.divs.length-1;
			var sPlace = oSlide.divs[iLast].childNodes[0].getAttribute('name');
			for  (var i=0; i<=iLast; i++ )
			{
				oSlide.divs[i].removeChild(oSlide.divs[i].childNodes[0]);
				sPlace = oSlide.step(sPlace,1);
				splaceArr.push(sPlace);
				//oSlide.content(sPlace,oSlide.divs[i]);
			}
			//alert(oSlide.divs);
			oSlide.content(splaceArr,oSlide.divs);
		}
		else
		{
			var iLast = oSlide.divs.length - 1;
			var ePrevious = oSlide.divs[iLast].childNodes[0];
			var sPlace = oSlide.step(ePrevious.attributes.getNamedItem("name").value,1);
			oSlide.divs[iLast].removeChild(ePrevious);
			oSlide.content(sPlace,oSlide.divs[iLast]);
			for  (var i=iLast-1; i>=0; i--)
			{
				eRemoved = oSlide.divs[i].removeChild(oSlide.divs[i].childNodes[0]);
				oSlide.divs[i].appendChild(ePrevious);
				ePrevious = eRemoved;
			}
		}
	};


	oSlide.right = function()
	{
		if ( oSlide.tripleClick)
		{  var splaceArr = new Array(); 
			var slidDiv = new Array();
			var iLast = oSlide.divs.length-1;
			var sPlace = oSlide.divs[0].childNodes[0].getAttribute('name');
			for  (var i=iLast; i>=0; i-- )
			{
				oSlide.divs[i].removeChild(oSlide.divs[i].childNodes[0]);
				sPlace = oSlide.step(sPlace,-1);
				splaceArr.push(sPlace);
				slidDiv.push(oSlide.divs[i]);
				//if(oSlide.content != displayMostPopular) {
					//oSlide.content(sPlace,oSlide.divs[i]);
				//}
			}
		oSlide.content(splaceArr.reverse(),oSlide.divs);
		
		}
		else
		{
			var eNext = oSlide.divs[0].childNodes[0];
			var sPlace = oSlide.step(eNext.attributes.getNamedItem("name").value,-1);
			oSlide.divs[0].removeChild(eNext);
			
			for  (var i=1, l=oSlide.divs.length; i<l; i++ )
			{
				eRemoved = oSlide.divs[i].removeChild(oSlide.divs[i].childNodes[0]);
				oSlide.divs[i].appendChild(eNext);
				eNext = eRemoved;
			}
			
			oSlide.content(sPlace,oSlide.divs[0]);
		}
	};
	
	
	oSlide.content = function (sPlace,eDiv)
	{
		if ( this.slides[sPlace] || false )
		{
			eDiv.innerHTML = '';
			eDiv.appendChild(this.slides[sPlace]);
			oSlide.check();
			if (oSlide.progressBar) {oSlide.progressBar();}
			
		}
		else
		{
			if(oSlide.tripleClick) {
				//alert("1");
				var tree = this.getContent(sPlace,eDiv,oSlide.check);
				for(var i=0;i<tree.length;i++)
				{
					this.slides[i] = tree[i];
				}
				/*this.slides[sPlace[0]] = tree[0];
				this.slides[sPlace[1]] = tree[1];
				this.slides[sPlace[2]] = tree[2];
				*/
			} else {
				this.slides[sPlace] = this.getContent(sPlace,eDiv.id,oSlide.check);
			}	
		}
	};
	
	
	oSlide.check = function()
	{
		if ( oSlide.end>0 )
		{
			var iPlace;
			//alert(oSlide.divs.length);

			iPlace = parseInt( oSlide.divs[0].childNodes[0].attributes.getNamedItem("name").value,10 );
			oSlide.controls[1].style.visibility = iPlace<=oSlide.start ? 'hidden' : 'visible';

			iPlace = parseInt( oSlide.divs[oSlide.divs.length-1].childNodes[0].attributes.getNamedItem("name").value, 10);
			//iPlace = iPlace + 2;
			oSlide.controls[0].style.visibility = iPlace>=oSlide.end ? 'hidden' : 'visible';
			//alert(oSlide.end);
			//alert(iPlace);

		}
	};




/*-------------------------------------------------------------------------------------------------------------
FUNCTIONS FOR CALENDAR SLIDER
-------------------------------------------------------------------------------------------------------------*/


var  CDSelector = {

	_dragged : false,
	_drag_start_date : false,
	_drag_last_date : false,
	_drag_last_element : false,
	_marked : true,
	

	attach_calendar : function ( parent )
	{
		var oT  = CDSelector._get_cd_table(parent);
		var aTR = oT.tBodies[0].rows;
		var aTC;
		var sDate;
		
		for (var i=0,l=aTR.length;i<l;i++)
		{
			aTC = aTR[i].cells;
			for (var k=0,m=aTC.length;k<m;k++)
			{
				if ( aTC[k].getAttribute('date') ) { CDSelector._attach_controls( aTC[k] ); }
				else 
				{
					aTC[k].onmouseover = function () {return false;};
					aTC[k].onmousedown = function () {return false;};
					aTC[k].onmouseup   = function () {return false;};
				}
			}
		}
	},


	clear_calendar : function ( parent )
	{
		var oT  = CDSelector._get_cd_table(parent);
		var aTR = oT.tBodies[0].rows;
		var aTC;
		var sDate;
		
		for (var i=0,l=aTR.length;i<l;i++)
		{
			aTC = aTR[i].cells;
			for (var k=0,m=aTC.length;k<m;k++)
			{
				if ( sDate=aTC[k].getAttribute('date') )
				{
					CDSelector._highlight_date( aTC[k], 0 );
					aTC[k].setAttribute('selected',0);
					CDSelector._attach_controls( aTC[k] );
				}
			}
		}
	},


	_attach_controls : function ( oElem ) 
	{
		oElem.onmousedown = CDSelector._mDown;
 		oElem.onmouseover = CDSelector._mOver;
		oElem.onmouseout  = CDSelector._mOut;
	},
	
	
	_mDown : function ()
	{
		var oElem = this;
		var sDate = oElem.getAttribute('date');
		
		CDSelector._marked = oElem.getAttribute('selected')==1 ? false : true; 
		CDSelector._drag_last_element = oElem;
		CDSelector._drag_last_date = sDate;
		CDSelector._drag_start_date = sDate;
		CDSelector._select_date( oElem );
		
		CDSelector._dragged = true;
		
		document.onmousemove = function () { return false; };
		document.onmouseup   = CDSelector._mUp;
		gid('ESBlock').onmouseout = CDSelector._mUp;
	
		return false;
	},
	
	
	_mUp : function ()
	{
		CDSelector._dragged = false;
		CDSelector._marked = true;
		
		document.onmousemove = null;
		document.onmouseup   = null;
		gid('ESBlock').onmouseout = null;
		//for calendar search in events_list page		
		if(window.location.href.indexOf('events_list.php') != -1) {
			oF.oSearch.startSearch();
		}
	},
	
	
	_mOver : function ()
	{
		oElem = this;
		CDSelector._highlight_date( oElem, CDSelector._marked ? 1 : 0 );
		if ( CDSelector._dragged ) { CDSelector._select_date( oElem ); }
		
		return false;
	},
	
	
	_mOut : function ()
	{
		var oElem = this;
		CDSelector._highlight_date( oElem, 0 );
	},
	
	
	_select_date : function ( oElem )
	{
		if ( CDSelector._dragged )
		{
			var sStart, eStart, sEnd, eEnd;
			
			var sSelDate  = oElem.getAttribute('date');
			var sLastDate = CDSelector._drag_last_date;
			var sStartDate = CDSelector._drag_start_date;
			
			var comperison = function ()
			{
				if ( sStart>=sStartDate )
				{
					return sStart>sLastDate; // ? true : false;
				}
				else
				{
					return sStart<sLastDate; // ? true : false; 
				}
			};
			
			if ( sSelDate>=sLastDate )
			{
				sStart = sLastDate;
				eStart = CDSelector._drag_last_element;
				sEnd = sSelDate;
				eEnd = oElem;
			}
			else
			{
				sStart = sSelDate;
				eStart = oElem;
				sEnd = sLastDate;
				eEnd = CDSelector._drag_last_element;
			}
			
			var obj = eStart;
			while ( sStart<sEnd )
			{
				if ( sStart>=sStartDate )
				{
					obj = CDSelector._next_date( obj );
					sStart = obj.getAttribute('date');
				}
				
				CDSelector[ comperison() ? "_mark_date" : "_unmark_date" ]( obj );
				
				if ( sStart<sStartDate )
				{
					obj = CDSelector._next_date( obj );
					sStart = obj.getAttribute('date');
				}
			}
			
			CDSelector._drag_last_element = oElem;
			CDSelector._drag_last_date = sSelDate;
		}
		else
		{
			CDSelector._mark_date( oElem );
		}
	},
		
	
	_highlight_date : function ( oElem, isSelected )
	{
		switch ( isSelected ) {
			case 1 : 		
			oElem.style.color = '#ffffff';
			oElem.style.backgroundColor = '#61A4EB';
			break;
			
			case 0 :
			oElem.style.color='#000000';
			oElem.style.backgroundColor='#ffffff';
			break;
		}
	},
	
	
	_mark_date : function ( oElem )
	{
		if ( CDSelector._marked )
		{
			CDSelector._highlight_date( oElem,1 );
			oElem.setAttribute('selected',1);
			oElem.onmouseout = null;
		}
		else if ( oElem.getAttribute('selected')=='1' )
		{
			CDSelector._highlight_date( oElem,0 );
			oElem.setAttribute('selected',-1);
			oElem.onmouseout = CDSelector._mOut;
		}
		
	},
	
	
	_unmark_date : function ( oElem )
	{
		if ( CDSelector._marked )
		{
			CDSelector._highlight_date( oElem, 0 );
			oElem.setAttribute('selected',0);
			oElem.onmouseout = CDSelector._mOut;
		}
		else if ( oElem.getAttribute('selected')=='-1' )
		{
			CDSelector._highlight_date( oElem, 1 );
			oElem.setAttribute('selected',1);
			oElem.onmouseout = null;
		}
	},
	
	
	_next_date : function ( oElem )
	{
		var parent = false;
		var o = oElem;
		
		do {
			o = o.nextSibling;
			if ( o===null )
			{
				parent = parent ? parent : oElem.parentNode;
				do {
					parent = parent.nextSibling;
					if ( parent===null )
					{
						parent = CDSelector._next_calendar(oElem);
						break;
					}
				} while ( parent.nodeType!=1 );
				o = parent.childNodes[0];
			}
		} while ( o.nodeType!=1 || !o.getAttribute('date') );
		return o;
	},
	
	
	_next_calendar : function ( oElem ) 
	{
		do {
			oElem = oElem.parentNode;
		} while ( oElem.id=='' || oElem.tagName.toLowerCase()!= 'div' );
		
		var sCal = oElem.id;
		var sNextCal;
		
		switch (sCal) {
			case "calendar1" :
				sNextCal = "calendar2";
				break;

			case "calendar2" :
				sNextCal = "calendar3";
				break;
		}
		
		return CDSelector._get_cd_table( gid(sNextCal) ).tBodies[0].rows[0];
	},
	
	
	_get_cd_table : function ( oDiv )
	{
		
		var oCDTable = oDiv.getElementsByTagName('table')[0].getElementsByTagName('table')[0].getElementsByTagName('table')[0];
	
		if ( oCDTable.getAttribute('name')=='calendar_dates' )
		{
			return oCDTable;
		}
		else
		{
			//alert("ERROR : BAD CALENDAR");
			return false;
		}
	},
	
	
	_collect_dates : function ()
	{
		var a = oSlide.slides;
		var oT, aTR, aTC;
		var aDates = new Array();
		
		for ( var i in a )
		{
			oT  = CDSelector._get_cd_table(a[i]);
			aTR = oT.tBodies[0].rows;
			var hol = "";
			var endhol= "";
			for (var j=0,n=aTR.length;j<n;j++)
			{
				aTC = aTR[j].cells;
				//alert(aTC.length);
				
				for (var k=0,m=aTC.length;k<m;k++)
				{  if((typeof(aTC[k].getAttribute('date'))=="string")||(typeof(aTC[k].getAttribute('date1'))=="string")){
						
						if ( aTC[k].getAttribute('selected')==1 && hol!="" ){
							endhol = aTC[k].getAttribute('date');
							
						}
						if ( aTC[k].getAttribute('selected')==1 && hol=="" ){
							hol =aTC[k].getAttribute('date');
							endhol = "";
						}
						if ( aTC[k].getAttribute('selected')!=1 ){
							if(hol!=""){
								//alert(hol);alert(endhol);
								if(endhol!=="") { 
									hol +="|"+endhol;
								}
								aDates.push(hol);
								
							}
							hol="";endhol="";
						}
					}
					//if ( aTC[k].getAttribute('selected')==1 ) aDates.push(aTC[k].getAttribute('date'))
				}
			}
		}
		
		return aDates.join(':');
	}
};


function view_events()
{	/*var str = CDSelector._collect_dates()+"";
	var eData = str.split(":");
	var eachstr = eData[0];
	if(eData.length >1)
		eachstr += "|"+eData[eData.length-1];
	sData = 'sdate:' + eachstr;
	*/

	var sData = 'sdate:' + CDSelector._collect_dates() + ';time:m:d:5:8:l'; 
	//alert(sData);
	if(!CDSelector._collect_dates()) {
		sData = 'date:n' + ';time:m:d:5:8:l';
	}
	gid('ESQuery').value = sData;
	gid('ESform').submit();
}



function reportInapproriatePhoto(obj, photo_fn, event_id){
	var pop_up_obj_width = 360;
	var adjustment = 0;
	var obj_l= getposOffset(obj,'left');
	var obj_t= getposOffset(obj,'top');
	var review_id;
        document.getElementById('cur_id').value=photo_fn;
        document.getElementById('elp_msg').value=event_id;
        
	try{if (document.getElementById('alert').style.display == '')
	{
		document.getElementById('alert').style.display = 'none';
		adjustment = 61;
	}} catch(e){}
	document.getElementById('baloonpopup').style.left = obj_l - pop_up_obj_width - 25;
	document.getElementById('baloonpopup').style.top = obj_t + obj.scrollHeight;
	document.getElementById('baloonpopup').style.display = '';

}


// NOT WORK NOW. WE SHOULD TO CAUSE IT ON LOAD POP UP 
function ev_space()
{
  if(document.all)
  {
      document.getElementById('pr_ev').style.paddingTop="2px";
  }
}
