var curCS;var d=document;var w=window;var t=true;var f=false;var n=null;function getOffsets(obj){var offsetTop=obj.offsetTop;var offsetLeft=obj.offsetLeft;while((obj=obj.offsetParent)!=null){offsetTop+=obj.offsetTop;offsetLeft+=obj.offsetLeft;}
return[offsetLeft,offsetTop];}
function iniCustomSelect(){var lstSelect=$A(d.getElementsByTagName('select'));lstSelect.each(function(select){select.style.display='none';var newCS=d.createElement('input');newCS.id='new_'+select.id;newCS.className='newCS '+select.className;newCS.readOnly="readOnly";newCS.onclick=function(){switchOptions(this.id);}
newCS.onmouseover=function(){curCS=this.id;}
newCS.onmouseout=function(){curCS='';}
var opts=d.createElement('div');opts.id='opts_new_'+select.id;opts.className='opts';opts.style.display='none';opts.setAttribute('CS',select.id);opts.onmouseover=function(){curCS='new_'+this.getAttribute('CS');}
opts.onmouseout=function(){curCS='';}
var optTab=new Array();var lstOpt=$A(select.getElementsByTagName('option'));lstOpt.each(function(opt){if(opt.selected)newCS.value=opt.innerHTML;var tmpOpt=d.createElement('div');tmpOpt.setAttribute('value',opt.value);tmpOpt.setAttribute('CS',select.id);tmpOpt.onmouseover=function(){this.className='optHover';}
tmpOpt.onmouseout=function(){this.className='opt';}
tmpOpt.onclick=function(){setSelectValue(this.getAttribute('CS'),this.getAttribute('value'));$('new_'+this.getAttribute('CS')).value=this.innerHTML;$('new_'+this.getAttribute('CS')).style.backgroundPosition='top left';new Effect.Fade($('opts_new_'+this.getAttribute('CS')),{duration:0.3});}
var optContent=d.createTextNode(opt.innerHTML);tmpOpt.appendChild(optContent);optTab.push(tmpOpt);});optTab.each(function(opt){opts.appendChild(opt);});var pN=select.parentNode;pN.appendChild(newCS);pN.appendChild(opts);});Event.observe(d,'click',hideOpts,f);}
function switchOptions(id){if($('opts_'+id).visible()==f){hideOpts();$(id).style.backgroundPosition='bottom left';var posSelect=getOffsets($(id));$('opts_'+id).style.left='7px';$('opts_'+id).style.top=($(id).getHeight()+7)+'px';$('opts_'+id).show();$('opts_'+id).up('.form_line').style.zIndex=999;$('opts_'+id).style.overflow='auto';}}
function hideOpts(){var lstopts=$A(d.getElementsByClassName('opts'));lstopts.each(function(opts){if(opts.visible()&&'new_'+opts.getAttribute('CS')!=curCS){opts.up('.form_line').style.zIndex=1;$('new_'+opts.getAttribute('CS')).style.backgroundPosition='top left';new Effect.Fade(opts,{duration:0.3});}});}
function setSelectValue(targetSelect,valueSelect){$(targetSelect).up('.form_line').style.zIndex=1;if($(targetSelect).value!=valueSelect){var ts=$(targetSelect);var lstOpts=$A(ts.getElementsByTagName('option'));lstOpts.each(function(opt){if(opt.value==valueSelect){$(opt).writeAttribute('selected','selected');throw $break;}});if($(targetSelect).onchange!=undefined){$(targetSelect).onchange();}}
if($(targetSelect).onclick!=undefined){$(targetSelect).onclick();}}
