function get_length(id,len) {
	_obj = document.getElementById(id);
	obj = _obj.value;
	if (obj.length>=len-1){
		return 1;
	} else {
		return 0;
	}
}
function active_submit() {
	if (get_length('gbname',1) && get_length('gbcity',3) && get_length('gbtext',10) && get_length('gbcode',6)){
		document.getElementById('disable_submit').style.display="none";
		document.getElementById('active_submit').style.display="inline";
	} else {
		document.getElementById('disable_submit').style.display="inline";
		document.getElementById('active_submit').style.display="none";
	}
}

function replace_blocks (showingid,hidingid) {
  if(document.getElementById(showingid)&&document.getElementById(hidingid)) {
    document.getElementById(showingid).style.display="block";
    document.getElementById(hidingid).style.display="none";
  }
}

var defaultButton=null;
document.onkeypress=document_keypress;

function document_keypress(evt) { 
  e = evt || window.event;
  if (defaultButton==null || e.keyCode!=13) {
    return;
  }
  defaultButton.click();
  e.returnValue = false;
  return false;
}

function set_default_button(button_id) {
  if(button_id!=null) if(document.getElementById(button_id)) {
    defaultButton=document.getElementById(button_id);
  } else {
    defaultButton=null;
  }
}

function cancel_bubble(evt) {
  evt = evt || window.event;
  evt.cancelBubble = true;
}

var current_shown_popup="";

function getDocumentHeight() {
  return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
}
function getDocumentWidth() {
  return (document.body.scrollWidth > document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;
}

function show_popup(id) {
  hide_popups();
  var popup=document.getElementById(id);
  var bgpopup = document.getElementById("whitebgpopup");
  var popupLayer = document.getElementById("popup-layer");
  if(popup) {
	popupLayer.style.display="block";
    bgpopup.style.display="block";
    bgpopup.style.position="absolute";
    bgpopup.style.left="0";
    bgpopup.style.top="0";
    bgpopup.style.right="0";
    bgpopup.style.bottom="0";
    bgpopup.style.width=getDocumentWidth()+"px";
    bgpopup.style.height=getDocumentHeight()+"px";
    bgpopup.style.zIndex="7777";
    bgpopup.style.backgroundColor="#000000";
    bgpopup.style.opacity="0.3";
	bgpopup.style.filter="alpha(opacity=30)";
    popup.style.display="block";
    popup.onclick=function(evt) { cancel_bubble(evt); };
    current_shown_popup=id;
    center_popup(id);
    var obj = findFirstInputRecursive(popup);
    safeFocus(obj);
  }
}

function safeFocus(obj) {
  if ( !obj ) {
    return;
  }
  if (typeof(obj) == 'string') {
    obj = document.getElementById(id);
  }
  if (obj) {
    try { obj.focus(); } catch(e) {}
  }
}

function findFirstInputRecursive(obj) {
  if (obj.tagName == 'INPUT' || obj.tagName == 'TEXTAREA' || obj.tagName == 'SELECT') {
    return obj;
  }
  for (var i = 0; i < obj.childNodes.length; i++) {
    var child = findFirstInputRecursive(obj.childNodes[i]);
    if (child != null) {
      return child;
    }
  }
  return null;
}

function hide_popups() {
  var popup_container=document.getElementById("popup-content-cell");
  var bgpopup = document.getElementById("whitebgpopup");
  bgpopup.style.opacity="0.0";
  bgpopup.style.filter="alpha(opacity=0)";
  bgpopup.style.display="none";
  if(popup_container) {
    for(var i=0; i<popup_container.childNodes.length;i++) {
      if(popup_container.childNodes[i].nodeType == 1) {
        popup_container.childNodes[i].style.display="none";
      }
    }
  }
  current_shown_popup="";
  document.getElementById("popup-layer").style.top="0px";
}

var current_shown="";

function show_hide(id) {
  if((current_shown!="")&&(current_shown!=id)) {
    if(document.getElementById(current_shown)) {
      document.getElementById(current_shown).style.display="none";
    }
  }
  var popup=document.getElementById(id);
  if(popup.style.display=='block') {
    popup.style.display='none';
    current_shown="";
  } else {
    hide_popups();
    popup.style.display='block';
    current_shown=id;
  }
}

function hide_all_popups(evt){
  if (evt.button && evt.button == 2) {
    return false;
  }
  hide_popups();
  if(document.getElementById(current_shown)) {
    document.getElementById(current_shown).style.display="none"; current_shown="";
  }
}
        
function center_popup(id) {
  var popup=document.getElementById(id);
  if(popup) {
    if(current_shown_popup!="") {
      var abscontainer=document.getElementById("popup-layer");
      centerWidth = getClientWidth()/2;
      centerpopupWidth = popup.offsetWidth/2;
      left_start = centerWidth - centerpopupWidth;
      needtop=Math.round((getClientHeight()-popup.offsetHeight)/2);
      abscontainer.style.top=needtop-190+Math.max(document.getElementsByTagName('body')[0].scrollTop,document.documentElement.scrollTop)+"px";
      abscontainer.style.left=left_start+"px";
    }
  }
}

function center_curr_popup() {
  if(current_shown_popup!="") {
    center_popup(current_shown_popup);
  }
}

function getClientHeight() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function getClientWidth() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

var onscrollloaded=false;
window.onscroll=function w_onscroll(){ if(onscrollloaded)documentscroll(); center_curr_popup(); };
window.onresize=function w_onresize() { center_curr_popup(); };