// JavaScript Document
function c_checkbox(arr){
  alt_checkbox(arr,true);
}

function u_checkbox(arr){
  alt_checkbox(arr,false);
}

function alt_checkbox(arr,ac){
  if(!document.getElementsByTagName('input')) return;
  var iarr = document.getElementsByTagName('input');
  for(var i=0; i < iarr.length; i++){
    if(iarr[i].type == 'checkbox' && iarr[i].name.match(arr))
    iarr[i].checked = ac;
  }
}
function addLoadEvent(func){
  var oldonload = window.onload;
  if(typeof oldonload != 'function'){
    window.onload = func;
  }else{
    window.onload = function(){
      oldonload();
      func();
    }
  }
}

function altTableRow(){
  if(!document.getElementsByTagName('table')) return;
  var tbl = document.getElementsByTagName('table');
  var odd = true;
  for(var i=0; i<tbl.length; i++){
    if(tbl[i].className == 'survey_list' || tbl[i].className == 'main'){
      row = tbl[i].getElementsByTagName('TBODY')[0].getElementsByTagName('tr');
      for(var j=0; j<row.length; j++){
        if(odd){
          row[j].className='odd';
          odd = false;
        }else{
          row[j].className='even';
          odd = true;
        }
      }
    }
  }
}

function altTableRowMouseOver(){
  if(!document.getElementsByTagName('table')) return;
  var tbl = document.getElementsByTagName('table');

  for(var i=0; i<tbl.length; i++){
    if(tbl[i].className == 'survey_list'){
      row = tbl[i].getElementsByTagName('TBODY')[0].getElementsByTagName('tr');
      for(var j=0; j<row.length; j++){
        current_row = row[j];
        current_row.id = j;
        current_row.onmouseover = function(){
          this.className = 'odd';
        }
        current_row.onmouseout = function(){
          	this.className = 'even';
        }
      }
    }
  }
}

function focusTextBox(){
  if(!document.getElementsByTagName('input')) return;
  var ip = document.getElementsByTagName('input');
  for(var i=0; el = ip[i]; i++){
    var old_border = '';
    if(el.type == 'text' || el.type == 'password'){
      el.onfocus = function(){
        old_border = this.style.border;
        this.style.border = '1px solid orange';
      }
      el.onblur = function(){
        this.style.border = old_border;
      }
    }
  }
}

function altFieldSet(){
  if(!document.getElementsByTagName('fieldset')) return;
  var fset = document.getElementsByTagName('fieldset');
  for(var i=0; i<fset.length; i++){
    fset[i].onmouseover = function(){
      this.className = 'odd';
    }
    fset[i].onmouseout = function(){
      this.className = 'even';
    }
  }
}

/**
 * @author rks
 * @param id string  element id whose visibility is to toggle
 * @access public
 * @return void
 **/
function toggle(id){
	var el = (typeof id == 'object' )?id:$(id);
	el.style.display = (el.style.display == 'none')?'':'none';
	return false;
}


/**
 * @param id string element name which is to be located in HTML
 * @access public
 * @return object of element id
 **/
function $(id){
	var obj = document.getElementById(id);
	return obj;
}
//~ addLoadEvent(altTableRowMouseOver);
//~ addLoadEvent(focusTextBox);
//~ addLoadEvent(altFieldSet);
//~ addLoadEvent(altTableRow);
//~ addLoadEvent(toolTip);

