﻿function loadPopup(title,page,width,height)
{
	path = unescape(document.location);
    path = path.substring(0,path.lastIndexOf("/")+1);
	
	if(page=="")
	{
		tb_show(title, "?TB_inline=inline&height="+height+"&width="+width+"&modal=false",false);
	}
	else
	{
		tb_show(title,path+"popup.php?tbinc="+page+"&height="+height+"&width="+width+"&modal=false",null)
	}
}

function loadajax(page,id,samediv,postdata,slide,loaderimage)
{
	if($("#"+id).html()!="" && $("#"+id).html()!="Error!!")return;
	
	if(loaderimage==""){loaderimage="ajax-loader7.gif";}
	
	if(samediv==true)
	{
		$("#"+id).html('<img src="admin/shared/images/'+loaderimage+'" />');
	}
	else
	{
		$("#ajaxindicator").html('<div align=\'center\'><img src=\'admin/shared/images/'+loaderimage+'\' /></div>');
		$("#"+id).css('opacity',0.5)
	}
	
	if(slide==true)
	{
		$("#"+id).slideUp();
	}
	
	var qu="ajax_page="+page+"&"+postdata;
	$.ajax(
	{
		type: "POST",
		url: "ajax_load.php",
		data: qu,
		success: function(msg)
		{
			if(slide==true)
			{
				$("#"+id).slideDown();
			}
			if(samediv==true)
			{
				$("#"+id).html(msg);
			}
			else
			{
				$("#ajaxindicator").html('');
				$("#"+id).css('opacity',1)
				$("#"+id).html(msg);
			}			
		},
		error: function()
		{
			if(slide==true)
			{
				$("#"+id).slideDown();
			}
			if(samediv==true)
			{
				$("#"+id).html("Error!!");
			}
			else
			{
				$("#"+id).css('opacity',1)
				$("#ajaxindicator").html('');
				$("#"+id).html("Failed!!");
			}
		}
	});
}

function customise_rooms_accordion()
{
	$('#acc1').hide();
	$('#acc2').hide();
	$('#acc3').hide();
	
	$('#included_items a').click(function() {
    //$('#extas_included #showhide').toggle();
	$('#acc2').slideUp();
	$('#acc3').slideUp();
	$('#acc1').toggle(400);
    return false;
	});
	
	$('#additional_items a').click(function() {
    //$('#extas_per_person #showhide1').toggle();
	$('#acc1').slideUp();
	$('#acc3').slideUp();
	$('#acc2').toggle(400);
    return false;
	});
	
	$('#extras_items a').click(function() {
	//$('#extas_per_day #showhide2').toggle();
    $('#acc1').slideUp();
	$('#acc2').slideUp();
	$('#acc3').toggle(400);
    return false;
	});
	
}

function flicker(divname,times)
{
	for(var x=0;x<times;x++)
	{
		$(divname).fadeOut(99).fadeIn(99);
	}
	$(divname).fadeTo("fast", 0.1).fadeTo("slow", 1);
}

function formatNumber(myNum, numOfDec) 
{ 
  var decimal = 1 
  for(i=1; i<=numOfDec;i++) 
	 decimal = decimal *10 

  var myFormattedNum = (Math.round(myNum * decimal)/decimal).toFixed(numOfDec) 
  return myFormattedNum;
}

function backToItems(){window.location.href="cp1.select_items.php";	}

function sendToServer(obj,sendval,params)
{
	if(sendval=="")sendval=$('#send_msg').val();
	$.ajax(
	{
		type: "POST",
		url: "proxy.php",
		data: "msg="+sendval+'&params='+params,
		success: function(msg)
		{
			$(obj).html($(obj).html()+"\n"+msg);
		},
		error: function()
		{
			$(obj).html($(obj).html()+"<br/>Error!");
		}
	});
}
