/**
 * uCode / Javascript
 * rev. 4870 (2007-11-23)
 *
 * Copyright (c) 2005-2007 Pause Productions (http://www.pause.ca/)
 * This code may not be distributed or reproduced without a license.
 *
 * Packaged on 2007-12-14
 * 
 * DO NOT EDIT THIS FILE! If you find bugs in uCode, or wish to add 
 * functionality, edit the originals and repackage them.
 * 
 * The person who customized this uCode package selected:
 * - uDropIt.class.js rev. 2967 (dated 2007-05-25)
 *
 * Use this quick select string when re-packaging this file:
 * js.drp
 *
 * The following were also included due to requirements:
 * - uCommon.php rev. 4870 (dated 2007-11-23)
 * - uSanitize.php rev. 2850 (dated 2007-05-04)
 * - uValidate.php rev. 3726 (dated 2007-08-29)
 *
 * One or more of the included modules have supporting Javascript files.
 * To make sure these modules function properly please make sure uCode.js
 * is included in your resulting HTML. If you do not have uCode.js you can
 * generate one from the package server using the same options above.
 */

var uDropIt=function(ids,data){this.initialize(ids,data);}
uDropIt.prototype={initialize:function(ids,data){if(ids instanceof Array){this.id1=ids[0];this.id2=ids[1];}
else if(typeof ids=='string'){this.id1=ids;}
else{alert("Passed bad parameter 1 to uDropIt (string or array accepted)");return false;}
this.element1=document.getElementById(this.id1);if(!this.element1){alert(this.id1+' not found!');return false;}
if(this.element1.tagName!='SELECT'){alert(this.id1+' is not a select box!');return false;}
if(this.id2){this.element2=document.getElementById(this.id2);if(!this.element2){alert(this.id2+' not found!');return false;}
if(this.element2.tagName!='SELECT'){alert(this.id2+' is not a select box!');return false;}}
else{if(!this.element2){this.element2=document.createElement('select');this.element1.parentNode.insertBefore(this.element2,this.element1);this.element1.parentNode.removeChild(this.element1);this.element2.parentNode.insertBefore(this.element1,this.element2);}}
var success=this.analyze();if(success)this.split();},analyze:function(){this.options1={};this.options2={};var nodes=this.element1.getElementsByTagName('*');if(nodes.length==0)return true;for(var t=0;t<nodes.length;t++){var node=nodes[t];if(node.tagName=='OPTGROUP'){var value=node.label;var text=node.label;this.options1[value]=text;this.options2[value]={};}
if(node.tagName=='OPTION'){var value=node.value;var text=node.text;if(node.parentNode.tagName=='OPTGROUP'){var parentValue=node.parentNode.label;this.options2[parentValue][value]=text;if(node.selected){this.selected1=parentValue;this.selected2=value;}}
else{this.options1[value]=text;}}}
return true;},split:function(){this.element1.innerHTML='';for(var i in this.options1){var value=i;var text=this.options1[i];var option=new Option(text,value);if(this.selected1==value)option.selected=true;this.element1.options[this.element1.options.length]=option;}
this.element2.name=this.element1.name;this.element1.name='';ObserveEvent(this.element1,'change',this.update.bindAsEventListener(this));this.update();this.selected1=null;this.selected2=null;},update:function(){var value1=undefined;var text1=undefined;for(var t=0;t<this.element1.options.length;t++){if(!this.element1.options[t].selected)continue;value1=this.element1.options[t].value;text1=this.element1.options[t].text;break;}
this.element2.innerHTML='';var options2={};options2[value1]=text1;if(this.options2[value1])options2=this.options2[value1];for(i in options2){var value2=i;var text2=options2[i];var option=new Option(text2,value2);if(this.selected2==value2)option.selected=true;this.element2.options[this.element2.options.length]=option;}}}
Function.prototype.bindAsEventListener=function(object){var __method=this;return function(event){return __method.call(object,event||window.event);}}
function ObserveEvent(element,name,observer){if(element.addEventListener){element.addEventListener(name,observer,false);}else if(element.attachEvent){element.attachEvent('on'+name,observer);}}
function $(){var elements=new Array();for(var i=0;i<arguments.length;i++){var element=arguments[i];if(typeof element=='string')
element=document.getElementById(element);if(arguments.length==1)
return element;elements.push(element);}
return elements;};
