if (!(window.DROPDOWNONDEMAND_DEFINED)){
ip_dropDowns=new Array;
ip_objHTTP=null;
ip_dropDownLoading=null;
ip_debugOn=true;
ip_addEvent(window, "load" , ip_loadAllRootDropDowns)
DROPDOWNONDEMAND_DEFINED=true
}
function ip_loadAllRootDropDowns(){
for (var i=0; i<ip_dropDowns.length; i++){
if (!ip_dropDowns[i].hasParent()) ip_requestData(ip_dropDowns[i].nameOfDropDown);
}
}
function ip_registerDropDown(dropDownElementID){
var newDropDown=new DropDownOnDemand(dropDownElementID);
ip_dropDowns.push(newDropDown);
}
function DropDownOnDemand(dropDownElementID){
this.isLoaded=false;
this.dropDownElementID=dropDownElementID;
this.dropDownElement=document.getElementById(dropDownElementID);
this.hiddenValueElement = document.getElementById(this.dropDownElement.getAttribute('clientIDOfHiddenValue'));
this.useChaining = (this.dropDownElement.getAttribute('useChaining')=="True");
this.urlToData = this.dropDownElement.getAttribute('urlToData');
this.fileDataFormat = this.dropDownElement.getAttribute('fileDataFormat');  //"SingleValueList" or "BothValueAndTextList"
this.nameOfDropDown = this.dropDownElement.getAttribute('nameOfDropDown');
this.dropDownElement.onchange=function (){
if (this.attributes) eval("ip_dropDownOnChange('" + this.getAttribute('nameOfDropDown') + "')")
else eval("ip_dropDownOnChange('" + this.nameOfDropDown + "')")
}
if (this.useChaining){
this.nameOfChildDropDown = this.dropDownElement.getAttribute('nameOfChildDropDown');
this.nameOfParentDropDown = this.dropDownElement.getAttribute('nameOfParentDropDown');
}
else{
this.nameOfChildDropDown = "";
this.nameOfParentDropDown = "";
}
this.getValue=function(){
return (this.dropDownElement.selectedIndex<0?"":this.dropDownElement.options[this.dropDownElement.selectedIndex].value)
}
this.setValue=function(newValue){
for (var i=0; i<this.dropDownElement.options.length; i++){
if (this.dropDownElement.options[i].value==newValue){
this.dropDownElement.selectedIndex=i;
break;
}
}
if (i<this.dropDownElement.options.length) this.hiddenValueElement.value=newValue;
}
this.updateHiddenValue=function (){
this.setValue(this.getValue());
}
this.hasParent=function(){
return (this.useChaining && this.nameOfParentDropDown!="");
}
this.hasChild=function(){
return (this.useChaining && this.nameOfChildDropDown!="");
}
this.requestData=function(){
var getStr = this.urlToData + (this.useChaining?"/data.txt":"");
ip_dropDownLoading=this;
ip_httpGetAsync(getStr, this.retrieveData);
}
this.loadData=function(response){
this.dropDownElement.innerHTML = "";
var loadedOptions = response.replace(/\r/g,"").split("\n");
var indexIncrements = (this.fileDataFormat=="SingleValueList"?1:2)
for (var i=0; i<loadedOptions.length-indexIncrements; i+=indexIncrements){
var anOption = document.createElement("OPTION")
this.dropDownElement.options.add(anOption)
anOption.value=loadedOptions[i];
if (document.all) anOption.innerText=loadedOptions[i+indexIncrements-1];
else anOption.text=loadedOptions[i+indexIncrements-1];
}
this.isLoaded=true;
if (this.hiddenValueElement.value != "") {
this.setValue(this.hiddenValueElement.value);
}
else{
if (loadedOptions.length>0) this.setValue(loadedOptions[0]);
}
this.loadFirstChildDropDown();
}
this.clearDropDown=function(){
this.dropDownElement.innerHTML = "";
this.hiddenValueElement.value = "";
this.isLoaded=false;
}
this.clearChildDropDowns=function(){
if (this.hasChild()){
ip_getDropDownByName(this.nameOfChildDropDown).clearDropDown();
ip_getDropDownByName(this.nameOfChildDropDown).clearChildDropDowns();
}
}
this.loadFirstChildDropDown=function(){
if (this.hasChild()){
var childDropDown=ip_getDropDownByName(this.nameOfChildDropDown);
if (this.getValue()=="") {
childDropDown.clearDropDown();
childDropDown.clearChildDropDowns();
}
else{
childDropDown.urlToData=this.createUrlToDataForChild();
ip_requestData(childDropDown.nameOfDropDown);
}
}
}
this.createUrlToDataForChild=function(){
if (this.hasParent()){
var parentDropDown=ip_getDropDownByName(this.nameOfParentDropDown);
return parentDropDown.createUrlToDataForChild() + "/" + this.getValue();
}
else return this.urlToData  + "/" + this.getValue();
}
}
function ip_dropDownOnChange(nameOfDropDown){
ip_httpAbortRequest();
var dropDown=ip_getDropDownByName(nameOfDropDown);
dropDown.updateHiddenValue();
dropDown.clearChildDropDowns();
if (dropDown.getValue()!=null) { // && dropDown.getValue()!=""&& dropDown.getValue()!="All"
dropDown.loadFirstChildDropDown();
}
}
function ip_requestData(nameOfDropDown){
if (ip_objHTTP!=null){
setTimeout("ip_requestData('"+nameOfDropDown+"',100)")
return;
}
var dropDown=ip_getDropDownByName(nameOfDropDown);
if (dropDown.hasParent()){
if (!ip_getDropDownByName(dropDown.nameOfParentDropDown).isLoaded) setTimeout("ip_requestData('"+nameOfDropDown+"',100)")
else dropDown.requestData();
}
else dropDown.requestData();
}
function ip_getDropDownByName(nameOfDropDown){
for (var i=0; i<ip_dropDowns.length; i++){
if (ip_dropDowns[i].nameOfDropDown==nameOfDropDown) return ip_dropDowns[i];
}
alert("There was an error finding the dropdown named '" + nameOfDropDown + "', recheck your parent/child dropdown names.");
}
function ip_httpGetAsync(getStr){
if (window.ActiveXObject){
ip_objHTTP = new ActiveXObject("Microsoft.XMLHTTP")
ip_objHTTP.Open('GET',encodeURI(getStr),true)
ip_objHTTP.onreadystatechange=ip_httpGetAsyncCallBack
ip_objHTTP.Send()
}
else{
if (window.XMLHttpRequest){
ip_objHTTP=new XMLHttpRequest();
ip_objHTTP.open('GET',encodeURI(getStr),true)
ip_objHTTP.onreadystatechange=ip_httpGetAsyncCallBack
ip_objHTTP.send(null)
}
}
}
function ip_httpGetAsyncCallBack(){
if (!ip_objHTTP || ip_objHTTP.readyState!=4) return;
var response="";
if (ip_objHTTP.status==200) response=ip_objHTTP.responseText;
ip_dropDownLoading.loadData(response);
ip_objHTTP=null;
ip_dropDownLoading=null;
}
function ip_httpAbortRequest(){
if (ip_objHTTP!=null) ip_objHTTP.abort();
ip_objHTTP=null;
ip_dropDownLoading=null;
}
function ip_debugOutput(msg){
if (ip_debugOn){
if (document.getElementById("debugOutput")!=null) document.getElementById("debugOutput").innerHTML+= (msg + "<br>")
}
}
function ip_addEvent(obj, evType, fn){
if (obj.addEventListener){
obj.addEventListener(evType, fn, false);
return true;
}
else{
if (obj.attachEvent){
var r = obj.attachEvent("on"+evType, fn);
return r;
}
else return false;
}
}
function ip_cancelEvent(event){
if (window.event && window.event.cancelBubble !==null) window.event.cancelBubble=true;
else if (event!=null && event.stopPropagation) event.stopPropagation();
}