/*
US and foreign Patents PENDING © 1999 Dancecats.com Incorporated. All rights reserved. 
*/
//initalization routines

function setPrefsCountry(theForm)
{   var expires = new Date();
   expires.setTime(expires.getTime() + 3E11);      
   
   with(theForm.elements["country"]) 
    {         
        if (options.length > 0 )
            setCookie("_COUNTRY", options[selectedIndex].value, expires); 
    }   

   with(theForm.elements["state"]) 
    {
        if (options.length > 0 )
            setCookie("_STATE", options[selectedIndex].value, expires);
    }   

   with(theForm.elements["city"]) 
    {
    if (options.length > 0 )
        setCookie("_CITY", options[selectedIndex].value, expires);
    }   
}

function getPrefsCountry(theForm)
{
   var prefCookie  =  getCookie("_COUNTRY");
   if (prefCookie)  theForm._country.value=prefCookie;

   prefCookie  =  getCookie("_STATE");    
   if (prefCookie) theForm._state.value =prefCookie;

   prefCookie  =  getCookie("_CITY");    
   if (prefCookie)    theForm._city.value = prefCookie;

}

function initCountry()
{
    var frmToInit;
    frmToInit = getFormByName("frmInputDC");
    if ("-1" ==   frmToInit._country.value)
        getPrefsCountry(frmToInit);

    /* select Country */                 
    if ("-1" ==   frmToInit._country.value)
        return;

    selectItem( frmToInit.country, frmToInit._country.value)       
    //populateCity(frmToInit);            
    onCountryChange(frmToInit)

    if (-1 !=  frmToInit._country.value.indexOf("USA") )
    {
        if ("-1" != frmToInit._state.value)
        {          
            populateStateUSA(frmToInit); 
            selectItem( frmToInit.state, frmToInit._state.value)       
            onStateChange(frmToInit);            
        }
        else
         {  var lbElement = getElement("city"); 
            with (lbElement) 
            {                          
                for(var i = options.length - 1; i > 0; i--) 
                options[i] = null;
            }
          }  
    }        
    if ("-1" !=   frmToInit._city.value)    
        selectItem( frmToInit.city, frmToInit._city.value)       
    
}
               	
var FIRST= "0";
var NEXT = "1";                    
function getCountryList()
{
if (typeof(Option)+"" != "undefined") 
{        
    var theForm, sStateList, appiCityServer;
    
    appiCityServer =  getApplet();
    if (null == appiCityServer)    
	{
	alert("Please enable Java and try again!");
        return ;
	}

   var lbElement = getElement("country"); 
   if (!lbElement) return;
   with (lbElement) 
   {  
      var i;              
      for(i = options.length - 1; i > 0; i--) 
       options[i] = null;

      i=0;
      var arList = new Array(2);
   	  strName = appiCityServer.getCountryList(FIRST);
      while( strName != "-1")      
      {
         arList[i++]  = strName;
    	   strName =appiCityServer.getCountryList(NEXT);
      } 	
      if (0 != i)
      {
         fillLb(lbElement, arList);   
         selectItem(lbElement, " USA");
         populateStateUSA(document.forms[0]);
      } 
    }
  }
}
function onCountryChange(theForm)
{
   var appiCityServer;
    appiCityServer =  getApplet();
    if (null == appiCityServer)    
        return false;   
       
            var strCountry;    
            var lbElement = getElement("country"); 
    		with (lbElement) 
            {
		    	if (0 <= selectedIndex)
				strCountry = options[selectedIndex].value;
		    }                       

            var lbState = getElement("state"); 
            with (lbState)
            {
                for(var i = options.length - 1; i > 0; i--) 
                    options[i] = null; 
                options[0] = new Option(" ", " "); 
            }

            var lbCity = getElement("city"); 
            with(lbCity)
            {
                for(var i = options.length - 1; i > 0; i--) 
                    options[i] = null; 
                options[0] = new Option(" ", " "); 
            }

            var bUSA = strCountry.indexOf("USA")!=-1;
            if (bUSA)
            {
                 populateStateUSA(theForm);                    
                 return false;   
            }
            else
                 populateStateOther(lbState);                                   
            populateCity(theForm, strCountry);
   return (true); 
}
function populateStateOther(lbElement)
{
   with (lbElement) 
   {                
      for(var i = options.length - 1; i > 0; i--) 
       options[i] = null;
      options[0] = new Option("Not Available", -1); 
      options[0].selected = true;
      enabled=false;
    }  
}                   
function populateCity(theForm, strCountry)
{
    var appiCityServer;    
    appiCityServer =  getApplet();
    if (null == appiCityServer)    
        return ;

    var lbElement = getElement("city");
	with (lbElement) 
   {                
      var i;
      for(i = options.length - 1; i > 0; i--) 
       options[i] = null;

      var arList = new Array(2);
      i=0;
   	var sCity = appiCityServer.populateCity(FIRST, strCountry);
      while(sCity != "-1")      
      {
         arList[i++]=sCity;
     	   sCity = appiCityServer.populateCity(NEXT, strCountry);
      } 	
      if (0 != i)
      {
         fillLb(lbElement, arList);   
         options[0].selected = true;
      } 
   }
}
function populateStateUSA(theForm)
{
    var appiCityServer;
    appiCityServer =  getApplet();
    if (null == appiCityServer)    
        return ;

    var lbElement = getElement("state");        
	with (lbElement) 
   {                
      var i;              

      for( i = options.length - 1; i > 0; i--) 
       options[i] = null;

      var arList = new Array(2);
      i=0;
      var sState = appiCityServer.populateStateUSA(FIRST);
      while(sState != "-1")      
      {
         arList[i++]  = sState;
     	   sState = appiCityServer.populateStateUSA(NEXT);
      } 	
      if (0 != i)
      {
         fillLb(lbElement, arList);   
         options[0].selected = true;
      } 
   }
}
function onStateChange(theForm)
{ 
  var appiCityServer;
    appiCityServer =  getApplet();
    if (null == appiCityServer)    
        return ;  

  var sState;
  var lbElement = getElement("state");
   with (lbElement) 
      {
	 	if (0 <= selectedIndex)
		sState = options[selectedIndex].value;
	 }          


   lbElement = getElement("city");
   with (lbElement) 
   {                
      var i; 
      for(i = options.length - 1; i >= 0; i--) 
       options[i] = null;
       options[0] = new Option("Not Available", -1); 
       options[0].selected = true;

      var arList = new Array(2);
      i=0;
   	var sCity = appiCityServer.populateCityUSA(FIRST, sState);
      while( sCity != "-1")      
      {
         arList[i++] = sCity;
     	   sCity = appiCityServer.populateCityUSA(NEXT, sState);
      } 
      if (0 != i)
      {
         fillLb(lbElement, arList);   
         options[0].selected = true;
      } 	
   }
}

function setupCBO_WithDataDancer()
{
    var frm;
    frm = getFormByName("frmInputDC");
    if (frm != null) 
    {	    
        selectItem( frm.iAge, 		frm._age.value);
        selectItem( frm.iEthnicity, 	frm._eth.value);
        selectItem( frm.iHeight, 	frm._ht.value);

    }
}
