//Copyright timeanddate.com 2005-2009, do not use without permission

data=new Array();prevselected=-1;firstRun=1;fo=null;fop=null;fos=null;function init(){fo=document.f;fop=fo["p[]"];fos=fo.s;fop.selectedIndex=-1;if(dyninit){dyninit();}
findCities();ss();ps();}
function setconf(i){var fl=i==-1;var rs="-";if(fl){nd={o:"Select one city above",a:"N/A",c:"N/A"};}else{nd=data[i];j=nd.o.lastIndexOf(" - ");rs="Default name is "+nd.o.substring(j+3);}
ih(gf("confdet"),nd.o);ih(gf("confdet2"),rs);document.f.altname.value=nd.a;document.f.altname.disabled=fl;document.f.notes.value=nd.c;document.f.notes.disabled=fl;datand=nd;}
function getfml(fn,l){var val=fo[fn].value;if(val&&val.length>l){val=val.substring(0,l);alert("Sorry, text was too long - truncated to\n"+val);}
return val;}
function savedata(){if(datand){datand.a=getfml("altname",64);datand.c=getfml("notes",200);var txt=datand.o;if(datand.a){txt=datand.a+" ["+txt+"]";}
datand.p.text=txt;}}
function tf(f){try{f.focus();}catch(e){};}
function ps(){document.f.but_add.disabled=fop.selectedIndex==-1;}
function rb(flag){document.f.but_rem.disabled=flag;document.f.but_mup.disabled=flag;document.f.but_mdo.disabled=flag;}
function ss(){var os=fos.options;var n=os.length;var j=0;var selcount=0;var selindex=0;for(var i=0;i<n;i++){if(os[i].selected){selcount++;selindex=i;}}
if(selcount==1){setconf(selindex);}else{setconf(-1);}
rb(selcount==0);}
function gf(f){if(document.getElementById){return document.getElementById(f);}
if(document.all){return document.all[f];}
return null;}
function ih(n,t){if(n){n.innerHTML=t;}}
function sv(n){var e=gf(n);if(e){e.style.visibility="visible";}}
function findCities(){var sel="";var os=fos.options;var n=os.length;var j=0;if(firstRun){firstRun=0;var e=gf("nojs_info");if(e){e.style.display="none";}
sv("td1");sv("but_add");sv("but_info");if(isLoggedIn){sv("td2");}}
for(var i=0;i<n;i++){sel+=os[i].value+";";}
document.f.sel.value=sel;}
function updateHidden(){findCities();if(isLoggedIn){for(i=0;i<maxPersonal;i++){var vn="p"+i;for(j=0;j<2;j++){letf="ac".charAt(j);vnf=vn+letf;v="";if(data[i]&&data[i][letf]){v=data[i][letf];}
document.f[vnf].value=v;}}}
return true;}
function addloc(){var os=fop.options;var n=os.length;for(var i=0;i<n;i++){var obj=os[i];if(obj.selected){var to=fos.options;var tol=to.length;var newval=obj.value;if(tol>=maxPersonal){alert("Only "+maxPersonal+" cities are allowed");break;}
var found=0;for(var j=0;j<tol;j++){if(to[j].value==newval){found=1;break;}}
if(!found){if((tol==1)&&(to[0].value==0)){tol=0;}
op=new Option(obj.text,newval);to[tol]=op;data[tol]={i:newval,o:obj.text,a:"",c:"",p:op}}
obj.selected=false;}}
findCities();ps();tf(fop);}
function remloc(){var os=fos.options;var n=os.length;var j=0;for(var i=0;i<n;i++){if(os[i].selected){}else{if(i!=j){os[j]=new Option(os[i].text,os[i].value);data[j]=data[i];}
j++;}}
if(i!=j){os.length=j;data.length=j;}
if(j==0){os[0]=new Option("--- select cities to add ---",0);}
findCities();ss();}
function swap(os,i,ito,n){if(os[i].selected){if((ito>=0)&&(ito<n)&&!os[ito].selected){moveObj=new Option(os[ito].text,os[ito].value);os[ito]=new Option(os[i].text,os[i].value);os[ito].selected=true;os[i]=moveObj;moveObj=data[ito];data[ito]=data[i];data[i]=moveObj;data[ito].p=os[ito];data[i].p=os[i];}}}
function move(dir){var os=fos.options;var n=os.length;var j=0;var moveObj="";if(dir<0){for(var i=0;i<n;i++){swap(os,i,i-1,n);}}else{for(var i=n-1;i>=0;i--){swap(os,i,i+1,n);}}
findCities();}