// Javascript File
var __ComboTextBox = null;
var __ComboList;
var __ComboArray = new Array();
var __ComboListIndex = -1;
var __ComboListMode = true;
var __ComboComType;

function MWJ_findObj( oName, oFrame, oDoc ) {
	if( !oDoc ) { if( oFrame ) { oDoc = oFrame.document; } else { oDoc = window.document; } }
	if( oDoc[oName] ) { return oDoc[oName]; } if( oDoc.all && oDoc.all[oName] ) { return oDoc.all[oName]; }
	if( oDoc.getElementById && oDoc.getElementById(oName) ) { return oDoc.getElementById(oName); }
	for( var x = 0; x < oDoc.forms.length; x++ ) { if( oDoc.forms[x][oName] ) { return oDoc.forms[x][oName]; } }
	for( var x = 0; x < oDoc.anchors.length; x++ ) { if( oDoc.anchors[x].name == oName ) { return oDoc.anchors[x]; } }
	for( var x = 0; document.layers && x < oDoc.layers.length; x++ ) {
		var theOb = MWJ_findObj( oName, null, oDoc.layers[x].document ); if( theOb ) { return theOb; } }
	if( !oFrame && window[oName] ) { return window[oName]; } if( oFrame && oFrame[oName] ) { return oFrame[oName]; }
	for( var x = 0; oFrame && oFrame.frames && x < oFrame.frames.length; x++ ) {
		var theOb = MWJ_findObj( oName, oFrame.frames[x], oFrame.frames[x].document ); if( theOb ) { return theOb; } }
	return null;
}

function __ComboEventKeyUp(e, Url)
{
    var Code = __ComboGetKeyCode(e);


    //alert(Url);
    clearTimeout(__keyUpTimeout); // Clears previous timeout if presents

    // Don't send a query if arrow keys are used
        if (((Code < 37) || (Code > 40)) && (Code != 13))
        { 
//            __keyUpTimeout = setTimeout(__AjaxGet(Url), 500);
	     __AjaxGet(Url);	
        }
        else {
	    return false; // blocks default behavior
	}
}

function __TextAreaBuildListTable(AxlResponse)
{
    var Html = '';
    var part = [];
    var lastType = '';
    var Data = [];

    Data = AxlResponse.split(';');
    // Loop through the rows
    for (i = 0;i < Data.length;i++)
    {
        if (Data[i] != " ")
        {
	    part = Data[i].split('|');
	    if (part[1] != lastType) { Html = Html + "<br><br>" + part[1] + "<br>" }
            Html = Html + "<b><a href=\"placefinder?clip=" + part[2] + "\">" + part[0] + "</a></b>&nbsp;|&nbsp;";
	    lastType = part[1];
        }
    }

    if (Html == '') {
       MWJ_findObj("matchListDiv").innerHTML = 'No matching place names';
	}
    else {
       MWJ_findObj("matchListDiv").innerHTML = Html;
	}
    return true;

}

function __NamesByCounty(AxlResponse)
{
    var Html = '<hr>';
    var part = [];
    var lastType = '';
    var Data = [];

    Data = AxlResponse.split(';');
    // Loop through the rows
    for (i = 0;i < Data.length;i++)
    {
//        if (Data[i] != " ")
//        {
	    part = Data[i].split('|');
//            Html = Html + "<b><a href=\"placefinder?clip=geoname:" + part[0] + "&lbl=" + escape(part[1]) + "\">" + part[1] + "</a></b><br>";
  	    Html = Html + '<b><a href="#" onClick="navigate(\'geoname:' + part[0] + '\')">' + part[1] + '</a><br>';
//alert(Html);
//        }
    }

    if (Html == '') {
       MWJ_findObj("matchListDiv").innerHTML = 'No matching place names';
	}
    else {
       MWJ_findObj("matchListDiv").innerHTML = Html;
	}
    return true;

}

function __NamesSubStr(AxlResponse)
{
    var Html = '<hr>';
    var part = [];
    var lastType = '';
    var Data = [];

    Data = AxlResponse.split(';');
    // Loop through the rows
    for (i = 0;i < Data.length;i++)
    {
	    part = Data[i].split('|');
            Html = Html + "<a href=\"placefinder?clip=geoname:" + part[0] + "&lbl=" + escape(part[1]) + "\">" + part[1] + "</a><br>";
    }

    if (Html == '') {
       MWJ_findObj("matchListDiv").innerHTML = 'No matching place names';
	}
    else {
       MWJ_findObj("matchListDiv").innerHTML = Html;
	}
    return true;

}

function __location_opt_fill(AxlResponse)
{
//	alert(AxlResponse);

    MWJ_findObj("location_opt_div").innerHTML = AxlResponse;
    return true;
}

function __objInfoFill(AxlResponse)
{
//	alert(AxlResponse);

    MWJ_findObj("objInfoDiv").innerHTML = AxlResponse;
    return true;
}

function __cnddbQueryFill(AxlResponse)
{
//	alert(AxlResponse);

    MWJ_findObj("gfQueryDiv").innerHTML = AxlResponse;
    return true;
}

function __calwater_fill(AxlResponse)
{
//	alert(AxlResponse);

    MWJ_findObj("calwater_div").innerHTML = AxlResponse;
    return true;
}

function __map_div_fill(AxlResponse)
{
//	alert(AxlResponse);

    MWJ_findObj("map_div").innerHTML = AxlResponse;
    return true;
}

function __related_div_fill(AxlResponse)
{
//	alert(AxlResponse);
    MWJ_findObj("related_div").innerHTML = AxlResponse;
    return true;
}

function __relatedObjFillGF(AxlResponse)
{
//	alert(AxlResponse);
    relatedObj = {};
    relatedObj = eval( '(' + AxlResponse + ')' );
    listRelatedGF();
    return true;
}

function __relatedObjFill(AxlResponse)
{
//  alert(AxlResponse);
    relatedObj = {};
    relatedObj = eval( '(' + AxlResponse + ')' );
    listRelated(MWJ_findObj("relateSelect").value);
    return true;
}

function __nameMatchObjFill(AxlResponse)
{
//  alert(AxlResponse);
    nameMatchObj = {};
    nameMatchObj = eval( '(' + AxlResponse + ')' );
    listMatchObj();
    return true;
}

function __org2dsObjFill(AxlResponse)
{
//  alert(AxlResponse);
    org2dsObj = {};
    org2dsObj = eval( '(' + AxlResponse + ')' );
    listOrg2Ds();
    return true;
}

function __dsMatchObjFill(AxlResponse)
{
//  alert(AxlResponse);
    dsMatchObj = {};
    dsMatchObj = eval( '(' + AxlResponse + ')' );
    listDsMatchObj('matchListDiv');
    return true;
}

function __dsMatchObjFillGF(AxlResponse)
{
//  alert(AxlResponse);
    dsMatchObj = {};
    dsMatchObj = eval( '(' + AxlResponse + ')' );
    listDsMatchObj('gfQueryDiv');
    return true;
}

function __thesMatchObjFill(AxlResponse)
{
//  alert(AxlResponse);
    thesMatchObj = {};
    thesMatchObj = eval( '(' + AxlResponse + ')' );
    listThesMatchObj();
    return true;
}

function __placeMatchObjFill(AxlResponse)
{
//  alert(AxlResponse);
    placeMatchObj = {};
    placeMatchObj = eval( '(' + AxlResponse + ')' );
    listPlaceNameMatch();
    return true;
}

function __orgMatchObjFill(AxlResponse)
{
//  alert(AxlResponse);
    orgMatchObj = {};
    orgMatchObj = eval( '(' + AxlResponse + ')' );
    listOrgNameMatch();
    return true;
}
function __clipMatchObjFill(AxlResponse)
{
//  alert(AxlResponse);
    placeMatchObj = {};
    placeMatchObj = eval( '(' + AxlResponse + ')' );
    listClipNameMatch();
    return true;
}

function __cross_map_fill(AxlResponse)
{
//	alert(AxlResponse);
    MWJ_findObj("cross_map_div").innerHTML = AxlResponse;
    return true;
}

function __ComboBuildListTable(AxlResponse)
{
//    document.forms[0].fillTerms.value = AxlResponse;
    var Data = AxlResponse.split(',');
    __ComboArray = Data;
    var Html = "<table width=\"" + __ComboBoxWidth + "\">";
    // Loop through the rows
    for (i = 0;i < Data.length;i++)
    {
        if (Data[i] != " ")
        {
            Html = Html + "<tr width=\"" + __ComboBoxWidth + "\" class=\"trow\" id='" + __ComboTextBox.id +":lr:" + i + "'>\r\n<td height=\"" + 25 + "px\" class=\"tcell\" id=\"c1r" + i + "\"><span style='width:" + __ComboBoxWidth + ";' id='" + __ComboTextBox.id +":li:" + i + "' onclick=\"__ComboPick('ZipCode', " + i + ")\" >" + Data[i] + "</span></td></tr>";
        }
    }
    Html = Html + "</table>";
    __ComboList.innerHTML = Html;
    
    // Fill in the text box
    __ComboTextBox.value = Data[0].substring(0, __ComboTextBox.value.length);
    
    if ((Data.length == 1) && (Data[0] != " "))
    {
        var OrigValue = __ComboTextBox.value;
        __ComboTextBox.value = Data[0];
        // IE Auto suggest
        if (__ComboTextBox.createTextRange) {
            var oRange = __ComboTextBox.createTextRange(); 
            oRange.moveStart("character", OrigValue.length); 
            oRange.moveEnd("character", __ComboTextBox.value.length); 
            oRange.select();
        } else if (__ComboTextBox.setSelectionRange) {
            __ComboTextBox.setSelectionRange(OrigValue.length, __ComboTextBox.value.length);
        }
        __ComboTextBox.focus();
        __ComboHideList();
    }
}
function __ComboShowList(Sender)
{
    __ComboTextBox = Sender;
    __ComboList = document.getElementById(Sender.id + ":l");
    __ComboList.style.visibility="visible";
}
function __ComboHideList()
{
    __ComboList.style.visibility="hidden";
    __ComboListIndex = -1;
    __ComboList.innerHTML="";
}
function __ComboPick(ComType, val)
{
    __ComboTextBox.value = __ComboArray[val];
    __ComboHideList();
}
function __ComboCheckClick(e)
{
    if (__ComboTextBox)
    {
        var target = __ComboFindTarget(e);
        if (target.id != __ComboTextBox.id)
        {
            __ComboHideList();
        }
    }
}
function __ComboFindTarget(e)
{
    // From Quirksmode
    var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	return targ;
}
function __ComboEventKeyDown(e)
{
    // Make sure the list is visible
    document.getElementById(__ComboList.id).style.visibility = "visible";
	switch (__ComboGetKeyCode(e))
	{
	    case 9: // Tab;
	    case 37: // Left arrow
	    case 39: // Right arrow
	        __ComboHideList();
	        break;
	    case 38:
	        __ComboUpList();
	        break;
	    case 40:
	        __ComboDownList();
	        //alert("Down arrow");
	        break;
	    default :
	        return true;
	}
}
function __ComboGetKeyCode(e)
{
    // From Quirksmode
    var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	var character = String.fromCharCode(code);
	return code;
}
function __ComboDownList()
{
    if ((__ComboArray.length - 1) > __ComboListIndex)
    {
        // Turn off Ajax
        __ComboListMode = false;
        
        // Change the last box to the background of the 
        if (__ComboListIndex > -1)
        {
            document.getElementById(__ComboTextBox.id + ":lr:" + __ComboListIndex).style.backgroundColor = __ComboBgColor;
        }
        __ComboListIndex++;
        document.getElementById(__ComboTextBox.id + ":lr:" + __ComboListIndex).style.backgroundColor = __ComboSelectColor;
        }
        //__ComboTextBox.focus();  
}
function __ComboUpList()
{
    if (__ComboListIndex > -1)
    {
        document.getElementById(__ComboTextBox.id + ":lr:" + __ComboListIndex).style.backgroundColor = __ComboBgColor;
        __ComboListIndex--;
    }
    // If we are still in the list, then highlight
    if (__ComboListIndex > -1)
    {
        document.getElementById(__ComboTextBox.id + ":lr:" + __ComboListIndex).style.backgroundColor = __ComboSelectColor;
    }
}
