var StopPhotoAction = false;

function closeSelect(options){
	var t = new Date().getTime();
	options.id = "opt_"+t;
	options.close = 1;
	setTimeout("closeElement('opt_"+t+"')", 200);
}
function closeElement(id){
	var el = document.getElementById(id);
	if ((el) && (el.close == 1)){
		el.style.display = 'none';
	}
}
function makeSelect(name, length){
	var select_container = document.getElementById(name);
	var options;
	var for_opt;
	/*for(var i=0;i<select_container.childNodes.length;i++){
		if (select_container.childNodes[i].id == 'but'){
			var button = select_container.childNodes[i];
			var button_image = select_container.childNodes[i].childNodes[0];
		}
		if (select_container.childNodes[i].nodeName == 'INPUT'){var input = select_container.childNodes[i];}
		if (select_container.childNodes[i].className == 'options'){var div_options= select_container.childNodes[i];}
	}*/
	for(var i=0;i<select_container.childNodes.length;i++){
		if (select_container.childNodes[i].nodeName == 'INPUT'){
			if (select_container.childNodes[i].type == 'text'){
				var input = select_container.childNodes[i];
				input.setAttribute('readonly',true);
			}
			if (select_container.childNodes[i].type == 'hidden'){
				var input_hidden = select_container.childNodes[i];
			}
		}
		if (select_container.childNodes[i].className == 'for_opt'){
			for_opt = select_container.childNodes[i];
			for(var i2=0;i2<for_opt.childNodes.length;i2++){
				if (for_opt.childNodes[i2].className == 'options'){
					options = for_opt.childNodes[i2];
					options.style.display = "none";
				}
			}
		}
		if (options){
			var sel = 0;
			var first = -1;
			for(i2=0;i2<options.childNodes.length;i2++){
				if (options.childNodes[i2].nodeName == 'LI'){
					if (first == -1){first = i2;}
					if (options.childNodes[i2].getAttribute('selected')){
						input_hidden.value = options.childNodes[i2].value;
						input.value = " "+options.childNodes[i2].innerHTML.substr(0, length);
						if (options.childNodes[i2].innerHTML.length > length){
							input.value += "...";
						}
						sel = 1;
					}
					options.childNodes[i2].onmouseover = function(){this.style.background = "#fdfbce";}
					options.childNodes[i2].onmouseout = function(){this.style.background = "none";}
					options.childNodes[i2].onclick = function(){
						input_hidden.value = this.value;
						input.value = " "+this.innerHTML.substr(0, length);
						if (this.innerHTML.length > length){
							input.value += "...";
						}
						options.style.display = 'none';
						StopPhotoAction = false;
					}
				}
			}
			if (sel == 0){
				input_hidden.value = options.childNodes[first].value;
				input.value = " "+options.childNodes[first].innerHTML.substr(0, length);
				if (options.childNodes[first].innerHTML.length > length){
					input.value += "...";
				}
			}
		}
	}
	for_opt.onmouseover = function(){
		input.style.background = "#FFFFFF url('/data/images/default/select/hover.gif') no-repeat right 50%;";
		options.style.display = "block";
		options.close = 0;
		StopPhotoAction = true;
	}
	for_opt.onmouseout = function(){
		input.style.background = "#FFFFFF url('/data/images/default/select/normal.gif') no-repeat right 50%;";
		closeSelect(options);
		//options.style.display = "none";
		StopPhotoAction = false;
	}

	input.style.background = "#FFFFFF url('/data/images/default/select/normal.gif') no-repeat right 50%;";
	input.onmouseover = function(){
		input.style.background = "#FFFFFF url('/data/images/default/select/hover.gif') no-repeat right 50%;";
		options.close = 0;
		options.style.display = "block";
		StopPhotoAction = true;
	}
	input.onmouseout = function(){
		input.style.background = "#FFFFFF url('/data/images/default/select/normal.gif') no-repeat right 50%;";
		closeSelect(options);
		StopPhotoAction = false;
	}
	input.onmousedown = function(){
		input.style.background = "#FFFFFF url('/data/images/default/select/down.gif') no-repeat right 50%;";
		StopPhotoAction = true;
	}
	input.onmouseup = function(){
		input.style.background = "#FFFFFF url('/data/images/default/select/hover.gif') no-repeat right 50%;";
		if (options.style.display == "none"){options.style.display = "block";}
		else{options.style.display = "none";}
		StopPhotoAction = false;
	}
}