/****************************************************
rock-debug.js
Debug utility. Creates object rock.debug.
Depends on: rock.js 
*****************************************************/
 
/*================================================
   Object rock.debug
 =================================================*/
rock.debug = {};

/**
 * Output a message into a debug DIV which has CSS class debug_msg.
 * If there are more than one debug DIVs, only use the 1st one.
 */
rock.debug.msg = function(msg){
	this.displayAdd(msg, 0); 
}   
    
/**
 * Output a message into a debug DIV which has CSS class debug_msg.
 * If there are more than one debug DIVs, only use the 1st one.
 * The new message is appended to existing messages.
 */    
rock.debug.msgAdd = function(msg){
	this.displayAdd(msg, 0); 
}      
   
rock.debug.msgReplace = function(msg){
	this.displayReplace(msg, 0); 
} 
   
/**
 * Output a message into specified debug DIV which has CSS class debug_msg.
 * A given index id is used to specify matched debug DIV. The old messages
 * are flushed out.
 */
rock.debug.displayReplace = function(msg, debugDivIndex){
	var debugDivs = $$('div.debug_msg');
    if(debugDivs && debugDivs.length > debugDivIndex){
    		debugDivs[debugDivIndex].innerHTML = msg;        
    } 
}    	
   
/**
 * Output a message into specified debug DIV which has CSS class debug_msg.
 * A given index id is used to specify matched debug DIV. The new message
 * is appended to existing messages.
 */    
rock.debug.displayAdd = function(msg, debugDivIndex){
    var debugDivs = $$('div.debug_msg');
    if(debugDivs && debugDivs.length > debugDivIndex){
     	debugDivs[debugDivIndex].innerHTML += '<br>' + msg;        
    }     
}
      
/**
 * Check if a debug div exist.
 */
rock.debug.hasDebugDiv = function(debugDivIndex){
  	var result = false;
	var debugDivs = $$('div.debug_msg');
    if(debugDivs && debugDivs.length > debugDivIndex){
    	result = true;        
    }     
    return result;
}       

rock.debug.printObj = function(obj){
	for(prop in obj){
		this.msg(prop + ": " + obj[prop] + "<br>");
	}
}

