//-------------------------------------------------------------------------
function isUndefinedTchegbe(arg) {
	return (typeof arg == "undefined");
}

//--------------------------------------------------------------------------
function getHiddenParamsTchegbe(obj){
	var str = "";
	
	for(var i = 0; i < obj.elements.length; i++){
		switch(obj.elements[i].type){
           case "hidden":
                str += obj.elements[i].name + "=" + escape(obj.elements[i].value) + "&";
                 break;
       }
	}
	
	return str;
}

//---------------------------------------------------------------------------
function checkUncheckAllTchegbe(obj) {
	var xform = obj.form, eidx = 0;
	while (xform[eidx].type == 'checkbox' && xform[eidx].name != 'checkboxToggle') {
		xform[eidx].checked = obj.checked;
		eidx++;
 	}
}

function checkFieldTchegbe(obj){
	var xform = obj.form, eidx = 0;
	
	if(!obj.checked){
		xform.checkboxToggle.checked = false;
		return;
	}
	
	while (xform[eidx].type == 'checkbox' && xform[eidx].name != 'checkboxToggle') {
		if(!xform[eidx].checked) {
			xform.checkboxToggle.checked = false;
			return;
		}
		eidx++;
 	}
 	
 	xform.checkToggle.checked = true;
}

//------------------------------------------------------------------
function changeClassTchegbe(id, className){
	document.getElementById(id).className = className;
}

function changeClassWithCookieTchegbe(id, className, cookieName){
	document.getElementById(id).className = className;
	createCookieTchegbe(cookieName,className,365);
}


function restoreClassTchegbe(id, cookieName, defaultClassName){
	var savedClass = readCookieTchegbe(cookieName);
	if(savedClass != null)
		document.getElementById(id).className = savedClass;
	else 
		document.getElementById(id).className = defaultClassName;
}

function createCookieTchegbe(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookieTchegbe(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookieTchegbe(name) {
	createCookie(name,"",-1);
}
//------------------------------------------------------------------
//save class first then replace and restor on mouse out
//get this.parent(td).parent(tr).childs[]
var bgColorOnTchegbe = "bgHighLight";
var bgColorOffTchegbe = "bgWhite";
var currentOTchegbe = null;

function highlightByCheckboxTchegbe(j) {
  if (j.checked) {
      highlightTchegbe(j, false);
  } else {
      unHighlightTchegbe(j);
  }
}

function highlightTchegbe(j) {
  highlightTchegbe(j, true);
}

function highlightTchegbe(j, unTprevious) {
  var n = null;
  if (j.parentNode && j.parentNode.parentNode) {
      n = j.parentNode.parentNode;
  }
  else if (j.parentElement && j.parentElement.parentElement) {
      n = j.parentElement.parentElement;
  }
  if (n) {
    if(unTprevious && currentOTchegbe != null) unHighlightTchegbe(currentOTchegbe);
    
        n.className = bgColorOnTchegbe;
        currentOTchegbe = j;
  }
}

function unHighlightTchegbe(j) {
    var n = null;
  if (j.parentNode && j.parentNode.parentNode) {
      n = j.parentNode.parentNode;
  }
  else if (j.parentElement && j.parentElement.parentElement) {
      n = j.parentElement.parentElement;
  }
  if (n) {
        n.className = bgColorOffTchegbe;
  }
}

//----------------------------------------------------------------------
function changeValueTchegbe(fieldId, value){
  document.getElementById(fieldId).value = value;
}

function copyValueTchegbe(fromFieldRef, toFieldId){
  document.getElementById(toFieldId).value = fromFieldRef.value;
}

function copyValueToParentTchegbe(fromFieldId, toFieldId){
  window.opener.document.getElementById(toFieldId).value = document.getElementById(fromFieldId).value;
}

function hideSectionOnParentTchegbe(sID){
  window.opener.document.getElementById(sID).style.display='none';
}

function hideSectionTchegbe(sID){
  document.getElementById(sID).style.display='none';
}

function showSectionOnParentTchegbe(sID){
  window.opener.document.getElementById(sID).style.display='block';
}

function showSectionTchegbe(sID){
  document.getElementById(sID).style.display='block';
}

function hideTchegbe(sectionId, showId, hideId){
  hideSectionTchegbe(hideId);
  showSectionTchegbe(showId);
  hideSectionTchegbe(sectionId);
}

function restoreTchegbe(sectionId, showId, hideId, cookieName, showByDefault){
    var value = readCookieTchegbe(cookieName);
    var showIt = showByDefault;
    
    if(value != null){
        if(value == 'true') showIt = true;
        else showIt = false;
    }
    
    if(showIt)
        showTchegbe(sectionId, showId, hideId);
    else 
        hideTchegbe(sectionId, showId, hideId);
}

function showTchegbe(sectionId, showId, hideId){
  hideSectionTchegbe(showId);
  showSectionTchegbe(hideId);
  showSectionTchegbe(sectionId);  
}

function submitTchegbe(formValue){
  document.forms[formValue].submit();
}

function submitParentTchegbe(formValue){
  window.opener.document.forms[formValue].submit();
}

function closeWindowTchegbe(){
  window.close();
}

function openWindowFullScreenTchegbe(theURL, theWindowName){
    popupWindow=window.open(theURL, theWindowName, ',type=fullWindow,fullscreen,resizable=yes,scrollbars=yes');
    if (popupWindow) {
        popupWindow.focus();
    }
}

function openWindowSizeTchegbe(theURL, theWindowName, theWidth, theHeight){
    var x = (screen.width-theWidth)/2;
    var y = (screen.height-theHeight)/2;
    popupWindow=window.open(theURL,theWindowName,"location=0,toolbar=no,menubar=no,resizable=yes,status=1,scrollbars=1,width=" + theWidth + ",height=" + theHeight + ",left=" + x + ",top=" + y); 
    if (popupWindow) {
        popupWindow.focus();
    }   
}

//---------------------------------------------------------------------------------------
function addLoadEvent(anOnLoadFunc) {
    var oldonload = window.onload; 
    if (typeof window.onload != 'function') { 
        window.onload = anOnLoadFunc;
    } else {
        window.onload = function() { 
            if(oldonload) oldonload(); 
            anOnLoadFunc(); 
        };
    }
}
