﻿// JScript File
		 var isNav = (navigator.userAgent.indexOf("Netscape")>=0);
         var isMoz = (navigator.userAgent.indexOf("Firefox")>=0);
		 var isNav4 = false;
		 var isIE4 = false;
		 var is5up = false;
		 
function AddField(theindex){
   var sel = document.getElementById(getClientID() + 'ddFields');
    var theForm = document.getElementById('aspnetForm');
   addOption(theForm,sel.options[theindex].text,sel.options[theindex].text)
   


}
function addOption(theForm, theText, thevalue, theSelect){
	if (isNav==true||isMoz==true){
		addOptionNS(theForm, theText, thevalue, theSelect);
	}
	else{
		addOptionIE(theForm, theText, thevalue, theSelect);
	}
}
function addOptionNS(theForm, theText, thevalue, theSelect){

   var sel = document.getElementById(theSelect);
	var selLength = sel.length;
   var notThere = true;
   var temp;
   var x;
if (selLength!=0){
   for(x=0;x<=selLength-1; ++x){
      temp = sel.options[x].text;
      if (temp==theText){
          notThere=false;
      }
   }
}
   if (notThere){
	   var newOpt  = new Option(theText, thevalue);
	   sel.options[selLength] = newOpt;
   }
}
function addOptionIE(theForm, theText, thevalue, theSelect){
   var sel = document.getElementById(theSelect);
	var selLength = sel.length;
   var notThere = true;
   var temp;
   var x;
if (selLength!=0){
   for(x=0;x<=selLength-1; ++x){
      temp = sel.options(x).text;
      if (temp==theText){
          notThere=false;
      }
   }
}
   if (notThere){
	   var newOpt = document.createElement("OPTION");
	   newOpt.text=theText;
	   newOpt.value=thevalue;
	   sel.add(newOpt);
   }
} 
function deleteOption(theForm, theSelect,theindex){	
	if (isNav==true||isMoz==true){
		deleteOptionNS(theForm, theSelect,theindex);
	}
	else{
		deleteOptionIE(theForm, theSelect,theindex);
	}

}
function deleteOptionNS(theForm, theSelect, theindex)
{
   var sel = document.getElementById(theSelect);
	var selLength = sel.length;
		sel.options[theindex]=null;
 
}
function deleteOptionIE(theForm, theSelect, theindex)
{
   var sel = document.getElementById(theSelect);
   sel.remove(theindex);
}
function AddGeos(thedrop, theindex){
   var theForm = document.getElementById('aspnetForm');
    //for removing temp option
   var sel = document.getElementById(getClientID() + thedrop);
   if (sel.options[0].value == 0){
      	if (isNav==true||isMoz==true){
			sel.options[0]=null;
	    }
	    else{
			sel.remove(0);
	    }
   }
   var sel3 = document.getElementById(getClientID() + 'ddSelectedGeos');
   if (sel.options[theindex].value != 'no'){
      if (sel3.length == 1){
        if (sel3.options[0].text == 'No Geography Selected'){
            if (isNav==true||isMoz==true){
			    sel3.options[0]=null;
	    }
	    else{
			    sel3.remove(0);
	    }
        }
      }
      addOption(theForm, sel.options[theindex].text, sel.options[theindex].value, getClientID() + 'ddSelectedGeos');
   }
   sel.selectedIndex = 0
sendData()
}
function AddGeosAll(thedrop){
var sel = document.getElementById(getClientID() + thedrop);
var theForm = document.getElementById('aspnetForm');

  for (var i=0; i < sel.options.length; i++) {
     AddGeos(thedrop, i)
  }
sendData()
}
function RemoveGeosAll(){
var sel = document.getElementById(getClientID() + 'ddSelectedGeos');
var theForm = document.getElementById('aspnetForm');

while(sel.options.length >= 1)
{
   deleteOption(theForm, getClientID() +'ddSelectedGeos', 0 );
}

sendData()
}
function RemoveGeos(){

   var sel = document.getElementById(getClientID() + 'ddSelectedGeos');
   var theForm = document.getElementById('aspnetForm');

   if (sel.options.selectedIndex != -1 ){
      deleteOption(theForm,getClientID() + 'ddSelectedGeos', sel.selectedIndex );
   }
	  var selLength = sel.length;
	   // if nothing selected add
   if (selLength==0){
      		if (isNav==true||isMoz==true){
				var newOpt  = new Option('No Geography Selected', 0);
				sel.options[selLength] = newOpt;
			}
			else{
				var newOpt = document.createElement("OPTION");
				newOpt.text='No Geography Selected';
				newOpt.value=0;
				sel.add(newOpt);
			}
	}
sendData()
}
