function copyValues (arrFrom,arrTo) {
  for ( i=0; i < arrFrom.length; i++ ) {
    fromelement=document.getElementById(arrFrom[i]);
    toelement=document.getElementById(arrTo[i]);
    if ( fromelement && toelement ) {
      if ( toelement.tagName == "INPUT" ) { toelement.value=fromelement.value; }
      else if ( toelement.tagName == "SELECT" ) {
        for ( j=0; j < toelement.options.length; j++ ) {
          if ( toelement.options[j].value == fromelement.options[fromelement.selectedIndex].value ) { toelement.options[j].selected=1;  }
        }
      } else {
//        alert("unknown tag name: " + toelement.tagName);
      }
      if ( toelement.onchange )  { toelement.onchange.call(); }
//     alert(toelement.name + ' onchange is ' + typeof(toelement.onChange));
//      if ( typeof(toelement.onchange) == "function" ) { toelement.onChange(); }
    } else {
//      alert('field ' + arrFrom[i] + ' or ' + arrTo[i] + ' not defined!');
      return false;
    }
  }
  return false;
}

// Disables any submit button on a form... Add this to onSubmit in a form element
function disableSubmitButton ( theform, changetxt ) {
  if (document.all || document.getElementById) {
    for (i = 0; i < theform.length; i++) {
      var tempobj = theform.elements[i];
      if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset") {
        tempobj.disabled = true;
        if ( changetxt ) { tempobj.value="Please Wait..."; }
      }
    }
  }

  return true;
}

// Disables any submit button on a form... Add this to onSubmit in a form element
function enableSubmitButton ( theform ) {
  if (document.all || document.getElementById) {
    for (i = 0; i < theform.length; i++) {
      var tempobj = theform.elements[i];
      if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset") {
        tempobj.disabled = false;
      }
    }
  }

  return true;
}

function toggleVisible ( elementid ) {
  element=document.getElementById(elementid);
  if ( element ) {
    if ( element.style.display == "none" ) {
      if ( element.tagName == "TR" || element.tagName == "TBODY" ) { element.style.display="table-row-group"; } else { element.style.display="block"; }
      element.style.visibility="visible";
    } else {
      element.style.display="none";
      element.style.visibility="hidden";
    }
  } else {
//    alert('element ' + elementid + ' doesnt exist');
  }
}

function toggleInvisible ( elementid ) {
  element=document.getElementById(elementid);
  if ( element ) {
    element.style.display="none";
    element.style.visibility="hidden";
  } else {
//    alert('element ' + elementid + ' doesnt exist');
  }
}

function toggleIsvisible ( elementid ) {
  element=document.getElementById(elementid);
  if ( element ) {
    if ( element.tagName == "TR" || element.tagName == "TBODY" ) { element.style.display="table-row-group"; } else { element.style.display="block"; }
    element.style.visibility="visible";
  } else {
//    alert('element ' + elementid + ' doesnt exist');
  }
}

var google_loaded=0;
var google_lang_loaded=0;
var callback;
var args=new Array;
var loading=false;

function translate ( id, target ) {
  if ( loading ) return false;

  if ( ! google_loaded ) {
    _load_google(this,id,target);
    return true;
  } else if ( ! google_lang_loaded ) {
    _load_google_lang(this,id,target);
  } else {
    _translate(id,target);
  }
}

function _load_google_lang ( ) {
  if ( arguments.length > 0 ) {
    args=arguments;
  }
  return google.load("language","1", {'callback': _google_lang_loaded });
}  

function _google_lang_loaded ( ) {
  var myargs = args;
  if ( arguments.length > 1 ) {
    myargs = arguments;
  }

  google_lang_loaded=1;

  loading=false;

  translate.apply(translate,myargs);
}

function _load_google ( ) {
  callback=arguments[0];
  for ( i=1; i < arguments.length; i++ ) {
    args[i-1]=arguments[i];
  }
  loading=true;

  var js=document.createElement('script');
  js.setAttribute("type","text/javascript");
  js.setAttribute("src", "http://www.google.com/jsapi?key=<?php echo $config["gmaps_api_key"]; ?>");

  var head=document.getElementsByTagName('head')[0];
  head.appendChild(js);

  js.onreadystatechange=function () {
    if ( js.readyState == 'complete' ) { _google_loaded(); }
  };

  js.onload = _google_loaded;

  return true;
}

function _google_loaded () {
  google_loaded=1;
  loading=false;
  _load_google_lang();
}

function _translate ( id, target ) {
  var e = document.getElementById(id);
  if ( target ) { var t = document.getElementById(target); } else { var t = e; }

  if ( e ) {
    var text=e.innerHTML;
    t.innerHTML='<?php echo $language->text("Translated"); ?>: ' + text;

    google.language.detect(text,
      function(result) {
        if (!result.error && result.language) {
          google.language.translate(text, result.language, "<?php echo $language->current_language; ?>",
            function(result2) {
              if (result2.translation) {
                t.innerHTML = '(<?php echo $language->text("Translated"); ?>) ' + result2.translation;
                if ( t.style.visibility == "hidden" ) { t.style.visibility='show'; }
                if ( t.style.display == "none" ) { t.style.display='inline'; }
              } else {
                alert('<?php echo $language->text("Translation Failed"); ?>');
                t.innerHTML = e.innerHTML;
              }
          });
        } else {
          alert('<?php echo $language->text("Translation Failed"); ?>');
          t.innerHTML = e.innerHTML;
        }
      }
    );
  } else {
    alert('<?php echo $language->text("Translation Failed"); ?>');
  }
}

function getTimezoneName() {
	tmSummer = new Date(Date.UTC(2005, 6, 30, 0, 0, 0, 0));
	so = -1 * tmSummer.getTimezoneOffset();
	tmWinter = new Date(Date.UTC(2005, 12, 30, 0, 0, 0, 0));
	wo = -1 * tmWinter.getTimezoneOffset();

	if (-660 == so && -660 == wo) return 'Pacific/Midway';
	if (-600 == so && -600 == wo) return 'Pacific/Tahiti';
	if (-570 == so && -570 == wo) return 'Pacific/Marquesas';
	if (-540 == so && -600 == wo) return 'America/Adak';
	if (-540 == so && -540 == wo) return 'Pacific/Gambier';
	if (-480 == so && -540 == wo) return 'America/Anchorage';
	if (-480 == so && -480 == wo) return 'Pacific/Pitcairn';
	if (-420 == so && -480 == wo) return 'America/Los_Angeles';
	if (-420 == so && -420 == wo) return 'America/Phoenix';
	if (-360 == so && -420 == wo) return 'America/Denver';
	if (-360 == so && -360 == wo) return 'America/Guatemala';
	if (-360 == so && -300 == wo) return 'Pacific/Easter';
	if (-300 == so && -360 == wo) return 'America/Chicago';
	if (-300 == so && -300 == wo) return 'America/Bogota';
	if (-240 == so && -300 == wo) return 'America/New_York';
	if (-240 == so && -240 == wo) return 'America/Caracas';
	if (-240 == so && -180 == wo) return 'America/Santiago';
	if (-180 == so && -240 == wo) return 'America/Halifax';
	if (-180 == so && -180 == wo) return 'America/Montevideo';
	if (-180 == so && -120 == wo) return 'America/Sao_Paulo';
	if (-150 == so && -210 == wo) return 'America/St_Johns';
	if (-120 == so && -180 == wo) return 'America/Godthab';
	if (-120 == so && -120 == wo) return 'America/Noronha';
	if (-60 == so && -60 == wo) return 'Atlantic/Cape_Verde';
	if (0 == so && -60 == wo) return 'Atlantic/Azores';
	if (0 == so && 0 == wo) return 'Africa/Casablanca';
	if (60 == so && 0 == wo) return 'Europe/London';
	if (60 == so && 60 == wo) return 'Africa/Algiers';
	if (60 == so && 120 == wo) return 'Africa/Windhoek';
	if (120 == so && 60 == wo) return 'Europe/Amsterdam';
	if (120 == so && 120 == wo) return 'Africa/Harare';
	if (180 == so && 120 == wo) return 'Europe/Athens';
	if (180 == so && 180 == wo) return 'Africa/Nairobi';
	if (240 == so && 180 == wo) return 'Europe/Moscow';
	if (240 == so && 240 == wo) return 'Asia/Dubai';
	if (270 == so && 210 == wo) return 'Asia/Tehran';
	if (270 == so && 270 == wo) return 'Asia/Kabul';
	if (300 == so && 240 == wo) return 'Asia/Baku';
	if (300 == so && 300 == wo) return 'Asia/Karachi';
	if (330 == so && 330 == wo) return 'Asia/Calcutta';
	if (345 == so && 345 == wo) return 'Asia/Katmandu';
	if (360 == so && 300 == wo) return 'Asia/Yekaterinburg';
	if (360 == so && 360 == wo) return 'Asia/Colombo';
	if (390 == so && 390 == wo) return 'Asia/Rangoon';
	if (420 == so && 360 == wo) return 'Asia/Almaty';
	if (420 == so && 420 == wo) return 'Asia/Bangkok';
	if (480 == so && 420 == wo) return 'Asia/Krasnoyarsk';
	if (480 == so && 480 == wo) return 'Australia/Perth';
	if (540 == so && 480 == wo) return 'Asia/Irkutsk';
	if (540 == so && 540 == wo) return 'Asia/Tokyo';
	if (570 == so && 570 == wo) return 'Australia/Darwin';
	if (570 == so && 630 == wo) return 'Australia/Adelaide';
	if (600 == so && 540 == wo) return 'Asia/Yakutsk';
	if (600 == so && 600 == wo) return 'Australia/Brisbane';
	if (600 == so && 660 == wo) return 'Australia/Sydney';
	if (630 == so && 660 == wo) return 'Australia/Lord_Howe';
	if (660 == so && 600 == wo) return 'Asia/Vladivostok';
	if (660 == so && 660 == wo) return 'Pacific/Guadalcanal';
	if (690 == so && 690 == wo) return 'Pacific/Norfolk';
	if (720 == so && 660 == wo) return 'Asia/Magadan';
	if (720 == so && 720 == wo) return 'Pacific/Fiji';
	if (720 == so && 780 == wo) return 'Pacific/Auckland';
	if (765 == so && 825 == wo) return 'Pacific/Chatham';
	if (780 == so && 780 == wo) return 'Pacific/Enderbury';
	if (840 == so && 840 == wo) return 'Pacific/Kiritimati';
	return 'America/Denver';
}
