﻿// JScript File
//function gmList_DoubleClick(){
//    gmList = document.getElementById("grantMakerList");
//    var txt = gmList.options[gmList.selectedIndex].value
//    alert(txt)
//}
function showInfo(srcList){
 var txt = srcList.options[srcList.selectedIndex].value

 namePair = txt.split("|")
 document.getElementById("infoLabel").innerHTML = namePair[1]
}
function copyvals(src, destVals, destText){    
    destValsArray = new Array()
    destTextArray = new Array()
    for( var i = 0; i < src.options.length; i++ ){      
        destValsArray[destValsArray.length] = src.options[i].value        
        destTextArray[destTextArray.length] = src.options[i].text        
    }
    destVals.value=destValsArray.join("|")
    destText.value=destTextArray.join("|")
    
}
function clearBox(ctl){    
   ctl.value = ""
  
}
function copyText(src, dest){    
    dest.value = src.value
}
function moveRight( srcList, destList){
    destList.selectedIndex=-1;
    if(destList.options.length > 4)
        return;    
   try{
    for( var i = 0; i < srcList.options.length; i++ ){	  
	    if (srcList.options[i].selected == true && destList.options.length < 5){	 
	        var newVals = srcList.options[i].value
            items = newVals.split("|")
            if(!isinList(destList,items[0])){
	            destList.options[ destList.options.length ] = new Option( items[1], items[0]);	            
	        }
	    }
    }
    
  }
  catch(e){} 
  if(destList.options.length > 1){
       fcList = document.getElementById("fiscalCategory");
       if(fcList.options[0].value == "compare"){            
            fcList.options[0] = null;
            fcList.selectedIndex=0            
       }
     } 
         
     destList.selectedIndex=-1;
     clearBox(document.getElementById("foundationSearchInput"))
}
function removeItem(srcList){
  try{
    for( var i = 0; i < srcList.options.length; i++ ){	  
	    if (srcList.options[i].selected == true){	 
	        var newVals = srcList.options[i] = null;
            
	    }
    }
    srcList.selectedIndex=0;
     fcList = document.getElementById("fiscalCategory");
       if(srcList.options.length == 1){
        if(fcList.options[0].value != "compare")
                    
            for(i = 0;i<fcList.options.length;i++)            
                fcList.options[i] = null;
                
            fcList.options[0] = new Option( "All Fiscal Categories", "compare");
            fcList.options[1] = new Option( "Assets", "assets_amt");
            fcList.options[2] = new Option( "Giving", "total_giving");
            fcList.options[3] = new Option( "Qualifying distributions", "qual_dist");
            fcList.options[4] = new Option( "Gifts received", "gifts_recvd");
                       
            fcList.selectedIndex=0
        }
  }
  catch(e){}  
    
}


function isinList(listName, value){
    for( var i = 0; i < listName.options.length; i++ ){	 
        if( listName.options[i].value == value)
            return true;
    }
    return false;
}


///////////////////////////////////
//ajax control of the word wheel///
///////////////////////////////////

function foundationSearchInput_onchange() {
    var textInput = document.getElementById("foundationSearchInput");       
    //var destList = document.getElementById("grantMakerList");
  
    if(textInput.value.length > 1){
        ret = dataService.getItems(textInput.value,OnComplete_SearchInput,OnTimeOut,OnError);                
       // ret = dataService.getItems(textInput.value,OnComplete_SearchInput);                      
    }
    return true;
}    

function OnComplete_SearchInput(args){
    var destList = document.getElementById("grantMakerList");
    var textInput = document.getElementById("foundationSearchInput");      
    destList.options.length = args.length
    for(i=0; i< args.length; i++){               
        destList.options[i] = new Option(args[i][0], args[i][1]);	       
    } 
    
}
   
function checkCache() {
    dataService.checkCache();
    return true;
} 

function OnTimeOut(arg){
    //alert("Timeout "+arg);
}
function OnError(arg){
    //alert("error "+arg);
}  

