﻿/*-----------------------------------------------------------------------
 *   earth.EzyPick - Overlay pick for checkbox or radio.
 -----------------------------------------------------------------------*/
var earth;
if(earth == null) earth = {};
earth.EzyPick = function(){};
/**********************************************************************  
*   Naming provide access to each of the element full id.
*   Parameters:
*   (string) id - an unique idenitifer to identify HTML element id.
***********************************************************************/
earth.EzyPick.Naming = function(id){
    this.layerId = 'EzyPick_Layer_' + id ;
    this.okId = 'EzyPick_ok_' + id ;
    this.cancelId = 'EzyPick_cancel_' + id ;
    this.hiddenId = 'EzyPick_Hidden_' + id ;
    this.pickSelection = 'EzyPick_Selection_';
    this.checkboxGroup = 'earth_ezypick_' + id ;
};
/**********************************************************************  
*   GetValue return changed text.
*   Parameters:
*   (string) id - an unique idenitifer to identify HTML element id.
***********************************************************************/
earth.EzyPick.prototype.GetValue = function(id){
    var naming = new earth.EzyPick.Naming(id);
    var allpick = document.getElementById(naming.hiddenId).value;
    var ids = allpick.split(',');
    var selectedIds = '';    
    var cb = document.forms[0][naming.checkboxGroup];    
    if(cb.length == undefined)
	{
		if(cb.checked)
		    selectedIds = cb.value + ',';
	}	
    else
    {
        for (i = 0; i < cb.length; i++)
            if(cb[i].checked == true)
                selectedIds += cb[i].value + ',';      
    }
    if(selectedIds.length > 0)
        selectedIds = selectedIds.substring(0, selectedIds.length-1);
       
    return selectedIds;
};
/**********************************************************************  
*   ShowEzyPick display EzyPick selection input.
*   Parameters:
*   (string) id - an unique idenitifer to identify HTML element id.
*   (function) okfunc - custom js function after OK link button is clicked.
*   (function) cancelfunc - custom js function after CANCEL link buttin is clicked.
***********************************************************************/
earth.EzyPick.prototype.ShowEzyPick = function(id, okfunc, cancelfunc){
    var naming = new earth.EzyPick.Naming(id);
    Display();
    SetButtonEvent();
    function SetButtonEvent(){
        document.getElementById(naming.okId).onclick = function(){ 
            if(okfunc != null)
                okfunc();
            Hide();
        };
        document.getElementById(naming.cancelId).onclick = function(){ 
            if(cancelfunc != null)
                cancelfunc();
            Hide();
        };  
    }
    function Display(){
        document.getElementById(naming.layerId).style.display = '';
    }
    function Hide(){
        document.getElementById(naming.layerId).style.display = 'none';
    };
};

earth.EzyPick.prototype.Hide = function(id){
    var naming = new earth.EzyPick.Naming(id);
    document.getElementById(naming.layerId).style.display = 'none';
}
var ezyPick = new earth.EzyPick(); 
