/* $Id: functions.js,v 1.21 2002/04/21 11:48:34 loic1 Exp $ */


/**
 * Displays an confirmation box beforme to submit a "DROP/DELETE/ALTER" query.
 * This function is called while clicking links
 *
 * @param   object   the link
 * @param   object   the sql query to submit
 *
 * @return  boolean  whether to run the query or not
 */
var confirmMsg  = 'Do you really want to ';

function confirmLink(theLink, theSqlQuery)
{
    // Confirmation is not required in the configuration file
    if (confirmMsg == '') {
        return true;
    }

    var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
    if (is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }

    return is_confirmed;
} // end of the 'confirmLink()' function



function donothing() {} 
function gotosite(site)
	{            
        if (site != "") {self.location=site;}
 	}
 	


function hover_leg_staff(leg_staff_id) {
    document.getElementById('leg_staffer_' + leg_staff_id).style.background = '#ffffcc';
    document.getElementById('change_link_' + leg_staff_id).style.display = 'block';
}

function hover_leg_staff_return(leg_staff_id) {
    document.getElementById('leg_staffer_' + leg_staff_id).style.background = 'none';
    document.getElementById('change_link_' + leg_staff_id).style.display = 'none';
}


function expose(target) {
    if(document.getElementById(target).style.display == 'block'){
    	document.getElementById(target).style.display = 'none';
    } else {
    	document.getElementById(target).style.display = 'block';
    }
}


function hide(target) {
	document.getElementById(target).style.display = 'none';
}

function show(target) {
	document.getElementById(target).style.display = 'block';
}



function swap(target1 , target2) {
    if(document.getElementById(target1).style.display == 'block'){
    	document.getElementById(target1).style.display = 'none';
    	document.getElementById(target2).style.display = 'block';
    } else {
    	document.getElementById(target1).style.display = 'block';
    	document.getElementById(target2).style.display = 'none';
    }
}

function checkedAll (id , checked , target_substring) {
	if(checked == 'true'){var checked_opposite = 'false';}
	if(checked == 'false'){var checked_opposite = 'true';}
	var el = document.getElementById(id);
	for (var i = 0; i < el.elements.length; i++) {
		//if(id_substring.length != 0){}
		//if(i > 250 && i < 255){ alert (target_substring + ' -> ' + el.elements[i].id.substring(0,5) ); }
		if( el.elements[i].id.substring(0, target_substring.length ) == target_substring){
			el.elements[i].checked = checked;
		}
	}
}

function setfocus(id){
	document.getElementById(id).focus();
}













// main function to process the fade request //
// http://www.leigeber.com/2008/05/javascript-color-fading-script/
function colorFade(id,element,start,end,steps,speed) {
  var startrgb,endrgb,er,eg,eb,step,rint,gint,bint,step;
  var target = document.getElementById(id);
  steps = steps || 20;
  speed = speed || 20;
  clearInterval(target.timer);
  endrgb = colorConv(end);
  er = endrgb[0];
  eg = endrgb[1];
  eb = endrgb[2];
  if(!target.r) {
    startrgb = colorConv(start);
    r = startrgb[0];
    g = startrgb[1];
    b = startrgb[2];
    target.r = r;
    target.g = g;
    target.b = b;
  }
  rint = Math.round(Math.abs(target.r-er)/steps);
  gint = Math.round(Math.abs(target.g-eg)/steps);
  bint = Math.round(Math.abs(target.b-eb)/steps);
  if(rint == 0) { rint = 1 }
  if(gint == 0) { gint = 1 }
  if(bint == 0) { bint = 1 }
  target.step = 1;
  target.timer = setInterval( function() { animateColor(id,element,steps,er,eg,eb,rint,gint,bint) }, speed);
}

// incrementally close the gap between the two colors //
function animateColor(id,element,steps,er,eg,eb,rint,gint,bint) {
  var target = document.getElementById(id);
  var color;
  if(target.step <= steps) {
    var r = target.r;
    var g = target.g;
    var b = target.b;
    if(r >= er) {
      r = r - rint;
    } else {
      r = parseInt(r) + parseInt(rint);
    }
    if(g >= eg) {
      g = g - gint;
    } else {
      g = parseInt(g) + parseInt(gint);
    }
    if(b >= eb) {
      b = b - bint;
    } else {
      b = parseInt(b) + parseInt(bint);
    }
    color = 'rgb(' + r + ',' + g + ',' + b + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
    target.r = r;
    target.g = g;
    target.b = b;
    target.step = target.step + 1;
  } else {
    clearInterval(target.timer);
    color = 'rgb(' + er + ',' + eg + ',' + eb + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
  }
}

// convert the color to rgb from hex //
function colorConv(color) {
  var rgb = [parseInt(color.substring(0,2),16), 
    parseInt(color.substring(2,4),16), 
    parseInt(color.substring(4,6),16)];
  return rgb;
}