function valt(max,obj) {
	var id=obj.id.replace('label_', '');
	
	for (var i=1; i<=max; i++)
	{
		document.getElementById('box_'+i).style.display="none";
		$('label_'+i).className = '';
	}
	document.getElementById('box_'+id).style.display="block";
	$(obj).className = 'active';
	
	ajaxRequest = new Ajax.Request(
		'controlpanel.php?sid=' + id,
		{
			method: 'get',
			onComplete: function(request)
			{
				// alert(request.responseText);
			}
		}
	);
}
function Ajax_Submit_Controlpanel( process, fullproc, method, form )
{
	myFormData = '';
	if( !method )
	{
		method = 'get';
	}
	if( !form )
	{
		form = false;
	}
	else
	{
		myFormData = $(form).serialize(true);
	}
	
	var simple = false;
	if(!fullproc)
	{
		fullproc = 'controlpanel.php?';
	}
	else
	{
		fullproc = '';
		simple = true;
	}

	// alert(process);
	ajaxRequest = new Ajax.Request(
		fullproc + process,
		{
			method: method,
			parameters: myFormData,
			onComplete: function(request)
			{
				// alert(request.responseText);
				var myMesArr = request.responseText.split("##");
				
				if( myMesArr[0] == 'ok' )
				{
					var index = 1;
					if( !$(myMesArr[index]) && $('resp') && !myMesArr[index].include('jscode') )
					{
						// alert(myMesArr[index++]);
						$('resp').innerHTML = myMesArr[index++];
						$('resp').style.display='';
						position_layer('resp', 1, 0, -200);
					}
					
					if( myMesArr[index].include('jscode') )
					{
						code = myMesArr[index].split('jscode');
						// alert(code[1]);
						if( code[1].include('js#') )
						{
							codes = code[1].split('js#');
							// alert(codes.length);
							for( var k=0; k<codes.length; k++ )
							{
								eval( codes[k] );
							}
						}
						else
						{
							eval( code[1] );
						}
						index++;
					}
					
					while( true )
					{
						if( $(myMesArr[index]) )
						{
							$(myMesArr[index++]).innerHTML = myMesArr[index++];
						}
						else
						{
							break;
						}
					}
					
					if( myMesArr[index].include('jscode') )
					{
						code = myMesArr[index].split('jscode')
						eval( code[1] );
						index++;
					}
					
				}
				else
				{
					alert(request.responseText);
				}
			}
		}
	);
}
function Load_Hire_Calendar( process, width, load )
{
	if( !load )load=2;
	if( !width )width=600;
	
	if( load==2 )
	{
		Load_Waiting();
	}
	
	new Effect.Move('product_full', { x: -1*width, y: 0 });
	
	if( load==2 )
	{
		Ajax_Submit_Controlpanel( process );
	}
}

function Load_Waiting()
{
	$('calendar_wrap').innerHTML = '<div class="resp_message">Please wait ...</div><div style="margin:auto;text-align:center;padding-top:10px;"><img src="images/ajax_loader5.gif" border="0" /></div>';
}

function position_layer(div, type, korx, kory )
{
	if( !type ) type = 1;
	if( !korx ) korx = 0;
	if( !kory ) kory = 0;
	
  var dim = document.viewport.getDimensions();
  var myLayer = $(div);
  AktTop = document.viewport.getScrollOffsets().top;
  mywidth = myLayer.getWidth();
  myheight = myLayer.getHeight();
  // myheight += (myheight<50 ? plusheight : 0);
	
	// alert( dim.width + ' - ' + AktTop + ' :: ' + mywidth + ' - ' + myheight );
  
  newLeft = (dim.width-mywidth)/2;
	if(myheight > dim.height)newtop = AktTop + 10;
  else newtop = AktTop + (dim.height-myheight)/2;
	if(newLeft < 10)newLeft = 10;
	if(newtop < 10)newtop = 10;

	if( type == 1 )
	{
		myLayer.setStyle({ left : newLeft + "px", top : newtop + "px" });
	}
	else if( type == 2 )
	{
		myLayer.setStyle({ left : newLeft + korx + "px" });
	}
	else if( type == 3 )
	{
		myLayer.setStyle({ top : newtop + kory + "px" });
	}
  // alert(myLayer.style.left + ' - ' + myLayer.style.top);
  // myLayer.style.left = newLeft + "px";
  // myLayer.style.top = newtop + "px";
}
function php_Calendar_pager(div, process, fullproc ){
	
	var simple = false;
	if(!fullproc)
	{
		fullproc = 'controlpanel.php?';
	}
	else
	{
		fullproc = '';
		simple = true;
	}
	
	// myFormData = $(form).serialize(true);
	
	// alert(div + ' - ' + process);
	ajaxRequest = new Ajax.Request(
		fullproc + process,
		{
			method: 'get',
			// parameters: myFormData,
			onComplete: function(request) 
			{ 
				var myMesArr = request.responseText.split("##");
				
				var tform = $(div);
				// if( !tform = $(div) )alert('Error: ' + div + ' doesn\'t exist');
				
				if( myMesArr[0] == 'ok' )
				{
					// alert(request.responseText);
					tform.innerHTML = myMesArr[1];
					if( !simple )
					{
						Resize_Product_Panel();
					}
					
					index = 2;
					if( myMesArr[index].include('jscode') )
					{
						code = myMesArr[index].split('jscode');
						if( code[1].include('js#') )
						{
							codes = code[1].split('js#');
							for( var k=0; k<codes.length; k++ )
							{
								eval( codes[k] );
							}
						}
						else
						{
							eval( code[1] );
						}
						index++;
					}
					
				}
				else
				{
					alert(request.responseText);
				}
			}
		}
	)  
	return false;
}
function Resize_Product_Panel()
{
	myheight = $('product_full').getHeight();
	$('product_wrap').setStyle({ height : myheight + "px" });
}

function AjaxHint(id, divHint) {
		var oThis = this;
		this.divHint = $(divHint);
		
		if(this.divHint){
			Event.observe(id, 'mouseover', function(e) { oThis.getHint(e);});
			Event.observe(id, 'mouseout', function(e) { oThis.hideHint(e);});
		}
		// alert('ok12');
	}
	
AjaxHint.prototype = {
	ajaxRequest: null,
	hintedObject:  null,
	hintTimer: null,
	
	cancelActivity: function () {
		if (this.hintTimer) {
			clearTimeout(this.hintTimer);
			this.hintTimer = null;
		}
		if (this.ajaxRequest) {
			this.ajaxRequest.transport.abort();
			this.ajaxRequest = null;
		}
	},
	
	getHint: function (event) {
		element = Event.element(event);
		if (element.tagName.toLowerCase() != 'a') {
			return;
		}
		this.hintedObject = element;
		//alert(2);
		//alert(this.hintedObject.id.substring(4));
		if(isNaN(this.hintedObject.id)){//alert('nan');
			//this.hintedObject.style.cursor = 'wait';
			var oThis = this;
			this.hintTimer = setTimeout(
				function() {oThis.timerGetHint()}, 
				500
			);
		}
		else{
			//new Effect.Fade(this.divHint, {duration:1});
			this.divHint.style.display = 'none';
			this.hintedObject = null;
		}
	},
	
	timerGetHint: function () {
		if (! this.hintedObject) {
			return;
		}
		// var whichKey = 16;
		// if(document.adminForm.k_1.checked)whichKey += 1;
		// if(document.adminForm.k_2.checked)whichKey += 2;
		// if(document.adminForm.k_3.checked)whichKey += 4;
		// if(document.adminForm.k_4.checked)whichKey += 8;

		// if(whichKey > 16){
			// if(myYear == 0 || myMonth == 0){
				// now = new Date();
				// myYear = now.getYear();
				// myMonth = now.getMonth()+1;
			// }
			// alert(this.hintedObject.id.substring(4));
			var oThis = this;
			this.divHint.innerHTML = '<div class="book_message">Please wait ...</div><div class="book_message_loader"><img src="images/ajax_loader_book.gif" border="0" /></div>';
			this.divHint.style.display = 'block';
			this.setPosition();
			this.ajaxRequest = new Ajax.Request(
				'controlpanel.php?set=true&datid=' + this.hintedObject.id.substring(4),
				{
					method: 'get',
					onComplete: function(request) 
						{ oThis.ajaxGetHint(request); }
				}
			);
		// }
	},
	
	hideHint: function (event) {
		element = Event.element(event);
		if (element.tagName.toLowerCase() != 'td') {
			return;
		}
		this.cancelActivity();
		//this.hintedObject.style.cursor = 'hand';
		this.hintedObject = null;
		this.divHint.style.display = 'none';
		// new Effect.Fade(this.divHint);
		
	},
	
	ajaxGetHint: function (request) {
		//this.hintedObject.style.cursor = 'hand';
		this.divHint.innerHTML = request.responseText;
		// alert(request.responseText);
		if(request.responseText == ""){
			this.hintedObject = null;
			this.divHint.style.display = 'none';
		}
		else{
			this.setPosition();
			/*
			var pos = Position.cumulativeOffset(this.hintedObject);
			// alert(this.divHint.innerHTML);
			// this.divHint.style.left = pos[0] + 'px';
			this.divHint.style.left = (pos[0]-107) +  'px';
			this.divHint.style.top = (pos[1] + this.hintedObject.offsetHeight - 115) + 'px';
			// this.divHint.style.bottom = (pos[1] + this.hintedObject.offsetHeight) + 'px';
			this.divHint.style.display = 'block';*/
		}
		//new Effect.Appear(this.divHint, {duration:0.2});
		//alert(this.hintedObject.style.cursor);
		//alert(this.hintedObject.style.cursor);
	},
	
	setPosition: function()
	{
		var pos = Position.cumulativeOffset(this.hintedObject);
		// alert(this.divHint.innerHTML);
		// this.divHint.style.left = pos[0] + 'px';
		var plusLeft = 109;
		var plusTop = 110;
		if(/MSIE (8|7|6|5|4)/.test(navigator.userAgent))
		{
			plusLeft = 106;
			plusTop = 110;
		}
		else if( /Firefox/.test(navigator.userAgent) )
		{
			plusLeft = 100;
			plusTop = 110;
		}
		
		this.divHint.style.left = (pos[0]-plusLeft) +  'px';
		this.divHint.style.top = (pos[1] + this.hintedObject.offsetHeight - plusTop) + 'px';
		// this.divHint.style.bottom = (pos[1] + this.hintedObject.offsetHeight) + 'px';
		this.divHint.style.display = 'block';
	}
}

