// search.js

function findObj(n, d) {
    var p,i,x;  
    if(!d) d=document; 
    if ( (p=n.indexOf("?")) > 0 && parent.frames.length ) {
        d=parent.frames[n.substring(p+1)].document;
        n=n.substring(0,p);
    }
    if (! (x=d[n]) && d.all) x=d.all[n]; 
    for (i=0; !x && i<d.forms.length; i++) x=d.forms[i][n];
    for (i=0; !x && d.layers && i<d.layers.length; i++) x=findObj(n,d.layers[i].document);
    if (!x && document.getElementById) x=document.getElementById(n); 
    return x;
}
function ShowHide() {
    var i,obj,args=ShowHide.arguments;
    for (i=0; i<(args.length-1); i+=2)
    {
        if ((obj=findObj(args[i]))!=null)
        {
            if (obj.style)
                obj = obj.style;
            obj.visibility=args[i+1];
        }
    }
}

function notEmpty(st) {
    if (!(ret =  (   (st != null)
                  && (st != "")
                 )
         )
       )
        return confirm("Input field is empty\nOK to go to the search engine, CANCEL to try again.");
   return true;
}

function noneAreEmpty() {
    var i,obj,args=noneAreEmpty.arguments;
    for (i=0; i<(args.length-1); i++)
    {
        if (   ((obj=findObj(args[i]))!=null)
            && (obj.value != "")
           )
            return true;
    }
    return confirm("Input fields are empty\nOK to go to the search engine, CANCEL to try again.");
}


function checkAll(src,dest) {
// OnClick="checkAll(this,'chkbx')
    var destObj = findObj(dest);
    for (var i=0; i < destObj.length; i++)
        destObj[i].checked = src.checked;
}

function setRadio(what, which) {
findObj(what)[which].checked = true;
}

function setSel(what, which) {
findObj(what).selectedIndex = which;
}

function klume() {
    return false
}

function showWin(url,wid,hig) {
alert("showWin-url ='"+url+"'");
    if (
           (wid==null)
        || (wid < 10)
       ) wid = 640;
    if (   (hig==null)
        || (hig < 10)
       ) hig = 480;
    lef = (document.width - wid) / 2;
    if (lef < 0)
    {
        lef = 2;
        wid = document.width-4
    }
    topp= (document.height - hig) / 2;
    if (topp < 0)
    {
        topp = 2;
        hig = document.height-4
    }
    return window.open(url,'sattelite',
                "scrollbars=yes,resizable=yes,height='+hig+',width='+wid+',left='+lef+',top="+topp)
}

CIABase = "https://www.cia.gov/cia/publications/factbook/geos/";
function CIAFactBook(idx, val) {
    if (   (val != null)
        && (val != "")
        && (idx > -1 )
       )
    {
        loc = CIABase+val+".html";
        window.parent.url.document.url_form.url_text.value = loc;
        window.parent.main.location = loc;
    }
}

// ---------------------------------------------------------------