document.write("<SCRIPT language='JavaScript' src='js/tabpane.js'      type='text/javascript'></SCRIPT>");
document.write("<SCRIPT language='JavaScript' src='js/tree.js'         type='text/javascript'></SCRIPT>");
document.write("<SCRIPT language='JavaScript' src='js/helptip.js'      type='text/javascript'></SCRIPT>");
document.write("<link rel='stylesheet' href='tab.winclassic.css' />");
document.write("<link rel='stylesheet' href='helptip.css' />");

var isIE = document.all?true:false;
var isNN4 = document.layers?true:false;
var isNN7 = (document.all && document.getElementById)?true:false;
var isOPERA = (navigator.userAgent.indexOf("Opera") != -1 && document.getElementById)?true:false;

// ---------------------------------------
// Form Action Functions |||||||||||||||||
// ---------------------------------------

function getFormElementPos(form, name){

  // Get all elements
  elms = form.elements;
 
  // Find out the (first) current element
  for (var i = 0 ; i < elms.length ; i++){
    if (elms[i].name == name){
      return i;
    }
  }
  return -1;
}

function updateOptionMenu(index, tgtOptions, group){
  for (m = tgtOptions.length-1; m > 0; m--) {
    tgtOptions[m]=null
  }
  for (i = 0; i < group[index].length; i++){
    tgtOptions[i]=new Option(group[index][i].text, group[index][i].value)
  }
  tgtOptions[0].selected=true
}

function setField(field, value) {
  if (field != null) {
    field.value = value;
  }
}

function clearField(e1, e2, e3, e4) {
    if (e1 != null) {
      e1.value = "";
    }
    if (e2 != null) {
      e2.value = "";
    }
    if (e3 != null) {
      e3.value = "";
    }
    if (e4 != null) {
      e4.value = "";
    }
}

function blankField(e1, e2, e3, e4) {
    if (e1 != null) {
      e1.value = " ";
    }
    if (e2 != null) {
      e2.value = " ";
    }
    if (e3 != null) {
      e3.value = " ";
    }
    if (e4 != null) {
      e4.value = " ";
    }
}


function uncheckElement(form, i1, i2, i3) {
  if (i1 != null && i1 >= 0) {
    form.elements[i1].checked = false;
  }
  if (i2 != null && i2 >= 0) {
    form.elements[i2].checked = false;
  }
  if (i3 != null && i3 >= 0) {
    form.elements[i3].checked = false;
  }
}

function uncheckAll(form, name, checkbox) {
  if (name != null) {
    var elements = form.elements[name];
    for(i = 0; i < elements.length; i++) {
      if (elements[i] != checkbox) {
        elements[i].checked = false;
      }
    }
  }
}

function checkAll(form, name, checkbox) {
  checkAllwithId(form, name, checkbox, null, null);
}


function checkAllwithId(form, name, checkbox, id) {
  // Get all elements
  elms = form.elements;
 
  // Find out the (first) current check
  for (var i = 0 ; i < elms.length ; i++){
    if (elms[i].name != name)
      continue;
    
    if (id != null && elms[i].id.indexOf(id) < 0)
      continue;
      
    checkIt = !elms[i].checked;
    break;
  }

  // Check all in the toggle state
  for (var i = 0 ; i < elms.length ; i++){
    if (elms[i].name != name)
      continue;
    if (id != null && elms[i].id.indexOf(id) < 0)
      continue;
    elms[i].checked = checkIt;
  }
  checkbox.checked = true;
}

function selectAll(form, name){
 selectAllwithId(form, name,null);
}

function selectAllwithId(form, name, id) {

  // Get all elements
  elms = form.elements;
 
  // Find out the (first) current value
  for (var i = 0 ; i < elms.length ; i++){
    if (elms[i].name != name)
      continue;
    
    if (id != null && elms[i].id.indexOf(id) < 0)
      continue;
      
    selectIt = elms[i].selectedIndex;
    break;
  }

  // Check all in the toggle state
  for (var i = 0 ; i < elms.length ; i++){
    if (elms[i].name != name)
      continue;
    if (id != null && elms[i].id.indexOf(id) < 0)
      continue;
    elms[i].selectedIndex = selectIt;
  }
}

function getSelectedElements(form,name,sep){
  elms  = form.elements;
  value = "";
  cpt   = 0;
  for (var i = 0 ; i < elms.length ; i++){
    if (elms[i].name != name)
      continue;
    if (! elms[i].checked)
      continue;
      
    if (cpt > 0)
      value += sep;
    
    value += elms[i].value;
    cpt++;
  }
  return value;
}

function checkAndSubmitForm(form, field1, field2, error1, error2) {
   
  if (field1 && field1.value == ""){
    alert(error1);
    return;
  }
  
  if (field2 && field2.value == ""){
    alert(error2);
    return;
  }
  
  form.submit();
}


// ---------------------------------------
// Used ? sould be removed |||||||||||||||
// ---------------------------------------


function showLayer(id, action) {
  if (isIE) {
    eval("document.all." + id + ".style.visibility='" + action + "'");
  } else if (isNN4) {
    eval("document." + id + ".style.visibility='" + action + "'");
  } else {
    eval("document.getElementById('" + id + "').style.visibility='" + action + "'");
  }
}

function toggleEltVisibility(elt, cond) {
  if (cond) {
    document.getElementById(elt).style.visibility = "visible";
  } else {
    document.getElementById(elt).style.visibility = "hidden";
  }
}

// ---------------------------------------
// Move Form Functions |||||||||||||||||||
// ---------------------------------------

// Move up/down or delete selected option of a list of select
function moveFormOption(form, pos, op, first, last) {
  array = form.elements;

  // Move Up
  if (op == "up") {
    if (pos > first) { 
      tmp = array[pos].selectedIndex;
      array[pos].selectedIndex = array[pos - 1].selectedIndex;
      array[pos - 1].selectedIndex = tmp;
    } else {
      tmp = array[first].selectedIndex;
      for(i = first; i < last; i++) {
        array[i].selectedIndex = array[i + 1].selectedIndex;
      }
      array[last].selectedIndex = tmp;
    }
  } 
  // Move Down
  else if (op == "down") {
    if (pos < last) {
      tmp = array[pos].selectedIndex;
      array[pos].selectedIndex = array[pos + 1].selectedIndex;
      array[pos + 1].selectedIndex = tmp;
    } else {
      tmp = array[last].selectedIndex;
      for(i = last; i >= first; i--) {
        array[i].selectedIndex = array[i - 1].selectedIndex;
      }
      array[first].selectedIndex = tmp;
    }
  }
  // Remove Element
  else if (op == "remove") {
    for(i = pos; i < last; i++) {
      array[i].selectedIndex = array[i + 1].selectedIndex;
    }
    array[last].selectedIndex = 0;

  }
}

// Move up/down or delete value of list of input
function moveFormElement(form, pos, op, first, last) {
  array = form.elements;

  // Move Up
  if (op == "up") {
    if (pos > first) { 
      tmp = array[pos].value;
      array[pos].value = array[pos - 1].value;
      array[pos - 1].value = tmp;
    } else {
      tmp = array[first].value;
      for(i = first; i < last; i++) {
        array[i].value = array[i + 1].value;
      }
      array[last].value = tmp;
    }
  } 
  // Move Down
  else if (op == "down") {
    if (pos < last) {
      tmp = array[pos].value;
      array[pos].value = array[pos + 1].value;
      array[pos + 1].value = tmp;
    } else {
      tmp = array[last].value;
      for(i = last; i >= first; i--) {
        array[i].value = array[i - 1].value;
      }
      array[first].value = tmp;
    }
  }
  // Remove Element
  else if (op == "remove") {
    for(i = pos; i < last; i++) {
      array[i].value = array[i + 1].value;
    }
    array[last].value = "";

  }
}

// Move up/down or delete value of list of couple of input
function move2FormElement(form, pos, op, first, last) {
  array = form.elements;

  // Move Up
  if (op == "up") {
    if (pos > (first + 1)) { 
      tmp = array[pos].value;
      array[pos].value = array[pos - 2].value;
      array[pos - 2].value = tmp;

      tmp = array[pos - 1].value;
      array[pos - 1].value = array[pos - 3].value;
      array[pos - 3].value = tmp;
    } else {
      tmp1 = array[first].value;
      tmp2 = array[first + 1].value;
      for(i = first ; i < last; i++) {
        array[i].value = array[i + 2].value;
      }
      array[last - 1].value = tmp1;
      array[last].value = tmp2;
    }
  } 
  // Move Down
  else if (op == "down") {
    if (pos < last) {
      tmp = array[pos].value;
      array[pos].value = array[pos + 2].value;
      array[pos + 2].value = tmp;

      tmp = array[pos - 1].value;
      array[pos - 1].value = array[pos + 1].value;
      array[pos + 1].value = tmp;
    } else {
      tmp1 = array[last].value;
      tmp2 = array[last - 1].value;
      for(i = last; i >= first; i--) {
        array[i].value = array[i - 2].value;
      }
      array[first + 1].value = tmp1;
      array[first].value = tmp2;
    }
  }
  // Remove Element
  else if (op == "remove") {
    for(i = pos - 1; i < last; i++) {
      array[i].value = array[i + 2].value;
    }
    array[last - 1].value = "";
    array[last].value = "";

  }
}

// ---------------------------------------
// Change URL Functions ||||||||||||||||||
// ---------------------------------------

function getUrlWithUpdatedParam(url,param,value){
	var targeturl = url.toString();
			
	re1 = new RegExp("([^\?]*\\?.*)("+param+"=[^&]*&?)(.*)","i");
	re2 = new RegExp("([^\?]*\\?)(.*)","i");
	re3 = new RegExp("([^\?]*)","i");
	
	if (targeturl.search(re1) != -1){
		if (value)
			targeturl = targeturl.replace(re1,"$1"+param+"="+value+"&$3");
		else
			targeturl = targeturl.replace(re1,"$1"+"$3");
	}
	else if (targeturl.search(re2) != -1){ 
		if (value)
			targeturl = targeturl.replace(re2,"$1"+param+"="+value+"&$2");
		else
			targeturl = targeturl.replace(re2,"$1"+"$2");
	}
	else { 
		if (value)
			targeturl = targeturl.replace(re3,"$1?"+param+"="+value);
		else
			targeturl = targeturl.replace(re3,"$1");
	}
	
	return targeturl;
}

// ---------------------------------------
// Prompt and Confirm Functions ||||||||||
// ---------------------------------------

function popupWindow(url, title, w, h){
 if (!w) w=320
 if (!h) h=260
 if (navigator.win) navigator.win.close();
 if (!window.opener) {
  navigator.win=window.open(url, title, 'status=no,width=' + w+ ',height=' + h + ',menubar=no,resizable=yes,scrollbars=yes');
  navigator.win.focus();   
  } else {
  	navigator.win=window.open(url, '_blank', 'status=no,width=' + w+ ',height=' + h + ',menubar=no,resizable=yes,scrollbars=yes');
  	navigator.win.focus(); 
  }
}

function promptAction(msg , url, param, defvalue){
  value = top.prompt(msg,defvalue);
	if (value) {
    document.location = getUrlWithUpdatedParam(url, param, value);
  }
}

function confirmAction(msg, url) {
  if (top.confirm(msg)) {
    document.location = url;
  }
}

function confirmSubmit(msg, form, action) {
  if (top.confirm(msg)) {
   submitFormAction(form,action);
  }
}

function submitFormAction(form,action) {
  if (action != null) {
    form.action.name = action;
  }

  form.submit();
}

/*
* This function will not return until (at least)
* the specified number of milliseconds have passed.
* It does a busy-wait loop.
*/
function pause(numberMillis) {
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;
    while (true) {
        now = new Date();
        if (now.getTime() > exitTime)
            return;
    }
}

// ---------------------------------------
// DOM, CrossBrowser and eventHandling |||
// ---------------------------------------

// Create a equivalent to the IE event object for Gecko and such // TO BE COMPLETED
if (document.captureEvents) {
 document.captureEvents( Event.KEYDOWN | Event.KEYUP ) ;
 window.event = new Object() ;
 function eventHandler(event) {
  if (event.type=='keydown') {
   if (event.which==17) window.event.ctrlKey=true ;
  } else if (event.type=='keyup') {
   if (event.which==17) window.event.ctrlKey=false ;
  }
 }
 document.onkeydown=eventHandler;
 document.onkeyup=eventHandler;
}

function getMouseCoord(e) {
 if (document.layers) {
  xmouse = e.pageX ; 
  ymouse = e.pageY ;
 }
 else {
  xmouse = document.body.scrollLeft+event.clientX ;
  ymouse = document.body.scrollTop+event.clientY ;
 }
}
if (document.captureEvents) document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=getMouseCoord;

if (!document.getElementById) {
 document.getElementById = function (sId) {
  if (document.all) return document.all[sId] ;
  if (document.layers) return document.layers[sId] ;
 }
}
function getElement(idStr) { ///// Got to be removed |||||||||||||||||
 if (document.getElementById) return document.getElementById(idStr) ;
 if (document.all) return document.all[idStr] ;
 if (document.layers) return document.layers[idStr] ;
}
function getElementStyle(idStr) {
 if (document.layers) return getElement(idStr) ;
 else return getElement(idStr).style ;
}


// ---------------------------------------
// Toggle Combo Functions ||||||||||||||||
// ---------------------------------------

var oldCombo = null;
function toggleCombo(combo){ 
 if (oldCombo != null && oldCombo != combo) {
 	toggleCombo(tmp);
 }
 if (combo.display=="none") {
  combo.display="block" ;
  oldCombo = combo;
 } else {
  combo.display="none" ;
  oldCombo = null;
 }
}

function toggleLangCombo() {
  toggleCombo(getElementStyle('langCombo'));
}

function toggleWorkspaceCombo() {
  toggleCombo(getElementStyle('workspaceCombo')) ;
}

function toggleLangCombo() {
  toggleCombo(getElementStyle('langCombo'));
}

function  toggleEditCombo(id) {
  toggleCombo(getElementStyle(id));
}

// ---------------------------------------
// Progress Functions ||||||||||||||||||||
// ---------------------------------------


function progressInsert(msg) {
  document.write("<div id='progress' style=\"position:absolute;display:none;top:200;left:200;border: 1px black solid;padding:3px 3px 3px 3px;background-color:#FFFFFF;font-family: sans-serif;font-size: 80%\"><NOBR><img src='images/jalios/icons/wait.gif' align='texttop'><br>" + msg + "</NOBR></div>");
  document.onmousemove = getMousePosition;
}

function progressShow() {
  document.all["progress"].style.top = mouseY + 10;
  document.all["progress"].style.left = mouseX + 10;
  document.all["progress"].visibility= "visible";
  document.all["progress"].style.display = "block";
}

function progressHide() {
  document.all["progress"].style.display = "none";
}

// ---------------------------------------
// Mouse Functions |||||||||||||||||||||||
// ---------------------------------------


function getMousePosition(e) {
  if (!isIE) {
    mouseX = e.pageX;
    mouseY = e.pageY;
  }
  if (isIE) {
    mouseX = event.clientX;
    mouseY = event.clientY;
  }
  return true;
}

// ---------------------------------------
// On Load Functions |||||||||||||||||||||
// ---------------------------------------


function doOnLoad(){
  setupAllTabs();
}

// Initialization hook up
// DOM2
if ( typeof window.addEventListener != "undefined" )
	window.addEventListener( "load", doOnLoad, false );

// IE 
else if ( typeof window.attachEvent != "undefined" )
	window.attachEvent( "onload", doOnLoad );

else {
	if ( window.onload != null ) {
		var oldOnload = window.onload;
		window.onload = function ( e ) {
			oldOnload( e );
			doOnLoad();
		};
	}
 	else 
		window.onload = doOnLoad;
}

