function change_sub_cat()
{
	r = $('sub_cat_list');
	new Form.Element.Observer(
  		'cat_list',
  		1,  // 100 milliseconds
  		function(el, value)
  		{
			new Ajax.Request("ajax/change_list.php?id="+value,
          	{
	            method:"get",
    		    onSuccess: function(transport)
    		    {
            		r.show();
					var sel = document.getElementById('sub_cat_list');
					while (sel.options.length)
					{
						sel.options[0] = null;
					}
					var firstRes = new String(transport.responseText);
					var resArray = firstRes.split(",");
					//alert(resArray.length);
					for (var i = 0; i < resArray.length; i++)
					{
						var resString = new String(resArray[i]);
						valArray = null;
						valArray = resString.split(":");
						var newOpt = new Option(valArray[1], valArray[0]);
						sel.options[i] = newOpt;
					}
            	},
            	onFailure: function()
            	{
					alert("nothing");
            		r.innerHTML = null;
            	}
          	});
  		})
}

function search_init()
{
	r = $('results');
	new Form.Element.Observer(
  		'search_string',
  		2,  // 200 milliseconds
  		function(el, value)
  		{
        	r.innerHTML = "Searching.... please wait...";
        	new Ajax.Request("ajax/search.php?s="+value,
          	{
	            method:"get",
    		    onSuccess: function(transport)
    		    {
            		r.show();
	            	r.innerHTML = transport.responseText || "error transfering data";
            	},
            	onFailure: function()
            	{
            		r.innerHTML = "search error";
            	}
          	});
  		})
}

function top_slot_click()
{
	var elt = Event.findElement(event, 'img');
	id = elt.identify();
	new Ajax.Request("ajax/banner_click.php?id="+id+"&pos=top",
    {
		method:"get",
    	onSuccess: function(transport)
    	{
        },
        onFailure: function()
        {
        }
	});
}
function bottom_slot_click()
{
	var elt = Event.findElement(event, 'img');
	id = elt.identify();
	new Ajax.Request("ajax/banner_click.php?id="+id+"&pos=bottom",
    {
		method:"get",
    	onSuccess: function(transport)
    	{
        },
        onFailure: function()
        {
        }
	});
}

function side_slot_click()
{
	var elt = Event.findElement(event, 'img');
	id = elt.identify();
	new Ajax.Request("ajax/banner_click.php?id="+id+"&pos=side",
    {
		method:"get",
    	onSuccess: function(transport)
    	{
        },
        onFailure: function()
        {
        }
	});
}

function showTopSlot()
{
	var elems = document.getElementsByTagName("img")

	for(var i=0; i<elems.length; i++)
	{
		name = elems[i].getAttribute("name");
		if (name != "")
		{
			id = elems[i].id;
			if (name == "top_slot")
			{
				new Ajax.Request("ajax/banner_impression.php?id="+id+"&pos=top",
			    {
					method:"get",
			    	onSuccess: function(transport)
			    	{
        			},
        			onFailure: function()
        			{
        			}
				});
			}
			if (name == "bottom_slot")
			{
				new Ajax.Request("ajax/banner_impression.php?id="+id+"&pos=bottom",
			    {
					method:"get",
			    	onSuccess: function(transport)
			    	{
        			},
        			onFailure: function()
        			{
        			}
				});

			}
			if (name == "side_slot")
			{
				new Ajax.Request("ajax/banner_impression.php?id="+id+"&pos=side",
			    {
					method:"get",
			    	onSuccess: function(transport)
			    	{
        			},
        			onFailure: function()
        			{
        			}
				});
			}
		}
	}
}
