// JavaScript Document
//var content = [{text: 'Art', image: '1.bmp'},{text: 'Music', image: '1.bmp'}];
var comboboxes = [];

function HideAll(){
	for (var i = 0 ; i<comboboxes.length; i++){
		//comboboxes[i].Hide();
		comboboxes[i].Combobox.style.visibility = "hidden";
		var cat_combo = comboboxes[i];
		 //document.getElementById(this.name_obj).onclick = function () {cat_combo.Show();}
		document.getElementById(cat_combo.name_obj).firstChild.style.background = "transparent url(/images/arrow-dd-right.gif) no-repeat top left";
	}
}

function clsCombobox(name_obj){
	this.position_obj = "";
	this.name_obj = name_obj;	
	this.Combobox = document.createElement("div");
	document.body.appendChild(this.Combobox);
	var Owner = document.getElementById(this.name_obj);
	var w = Owner.offsetWidth;
	this.Combobox.style.position = 'absolute';
	this.Combobox.style.cursor = 'hand';
	this.Combobox.style.visibility = "hidden";
	this.Combobox.className = "bg-drop-list";
	this.Combobox.style.zIndex = 1010;
	comboboxes.push(this);
	
this.Show = function (){
	HideAll();
	try{
		g_o("info-"+this.html.id).style.display = 'none';
		g_o("box-"+this.html.id).style.display = 'block';
	}catch(e){}
	try{
		g_o("box-"+this.html.id+"-close").onclick = function(){cat_combo.Hide();}		
	}catch(e){}
	coord = PopupWindow_getXYPosition(this.name_obj);
	if(this.position_obj)coord = PopupWindow_getXYPosition(this.position_obj);
	  this.Combobox.appendChild(this.html);
	  this.Combobox.style.visibility = "visible";
	  this.Combobox.style.left=coord.x + "px";
	  this.Combobox.style.top= coord.y + Owner.offsetHeight + "px";
	  var cat_combo = this;
	  document.getElementById(this.name_obj).onclick = function(){cat_combo.Hide();}
	  document.getElementById(this.name_obj).firstChild.style.background = "transparent url(/images/arrow-dd-bottom.gif) no-repeat top left";
}

this.Hide = function (){
	 this.Combobox.style.visibility = "hidden";
	 var cat_combo = this;
	 document.getElementById(this.name_obj).onclick = function () {cat_combo.Show();}
	 document.getElementById(this.name_obj).firstChild.style.background = "transparent url(/images/arrow-dd-right.gif) no-repeat top left";
}

function onSelect(obj,own) {
		return function(){
			document.getElementById(own.name_obj).innerHTML = "<span class='item-selected'>" + obj.innerHTML + "</span>";
			own.CallBack(obj.childNodes[2].innerHTML);
			own.Hide();
		}
}

function onOver(obj){
		return function(){
			obj.style.backgroundColor = "#EEEEEE";

		}
}

function onOut(obj){
		return function(){
			obj.style.backgroundColor = "transparent";
		}
}

this.setHTMLContent = function(in_name){
	this.html = document.getElementById(in_name);
}

this.setContent = function(in_html){
		var master = document.createElement("div");
		master.className = "drop-list";	
				
		//array_unshift(in_html,{image: "",text: "All", value: "0"});
				
		for (var i = 0 ; i<in_html.length; i++) {
				var c_item = document.createElement("div");
				c_item.className = "item";
				c_item.onclick = onSelect(c_item, this);	
//				c_item.onmouseover = onOver(c_item);
//				c_item.onmouseout = onOut(c_item);
				
			if( /\.png$/.test( in_html[i].image.toLowerCase() ) && window.ActiveXObject) {
 				var c_img = document.createElement("div");
				c_img.style.width = 9;
				c_img.style.height = 9;
				c_img.className = "icon";
				c_img.style.overflow = "hidden";
				c_img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + in_html[i].image + "', sizingMethod='scale')";
				c_item.appendChild(c_img);
			} else {
				var c_img = document.createElement("img");
				c_img.width = 16;
				c_img.height = 19;
				c_img.className = "icon";
				c_item.appendChild(c_img);
				if ( in_html[i].image.length > 0) {
					c_img.src = in_html[i].image;
				} else {
					c_img.src = "/images/empty.gif";
				}
			}

				var c_cont = document.createElement("span");
				c_cont.innerHTML = in_html[i].text;
				c_cont.className = "title";
				
/*				c_item.onmouseover = onOver(c_cont);
				c_item.onmouseout = onOut(c_cont); */
				
				c_item.appendChild(c_cont);
				var c_val = document.createElement("span");
				c_val.innerHTML = in_html[i].value;
				c_val.style.visibility = "hidden";
				c_val.className = "hide";
				c_item.appendChild(c_val);				
				
				master.appendChild(c_item);
		}
		
		var clearing = document.createElement("div");
		clearing.className = "end-list";
		master.appendChild(clearing);
		
		this.html = master;
}
}
function PopupWindow_getXYPosition(anchorname) {
	var coordinates;
	if (this.type == "WINDOW") {
		coordinates = getAnchorWindowPosition(anchorname);
		}
	else {
		coordinates = getAnchorPosition(anchorname);
		}
	return coordinates;	
}

function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}
