var change = null;
var runnin = false;
var origsz = 0;
var stdsz  = null;
var icrop  = null;
var target = null;
var last   = false;
function git(id){return document.getElementById(id);}

function wildSlideUp(id){
	b=$(id);
	if(b.visible())
		Effect.SlideUp(b, {duration:0.4});
}
function wildSlideDown(id){
	b=$(id);
	if(!b.visible())
		Effect.SlideDown(b, {duration:0.2});
}
/* forces a text field to only contain numbers */
function beNum(obj){
	if( obj.type == 'text' ){
		if( obj.value.match(/[^0-9]/) ){
			obj.value=obj.value.replace(/[^0-9]/,'');
		}
	}
		
}
function shazam(id){
	if(runnin){return;}
	runnin=true;
	window.clearInterval(change);
	target=git(id);
	sz=target.offsetHeight;
	alert("size="+sz)
	target.style.height=sz+'px';
	if(stdsz==null)
		stdsz=sz+'px';
	if(origsz==0)
		origsz=sz;
	if(icrop=null)
		icrop=target.style.overflow;

	if(target.style.display=='none'){
		target.style.height='1px';
		target.style.overflow='hidden';
		target.style.display='block';
		change=window.setInterval("grow("+origsz+")",1);
	}else{
		last = false;
		target.style.overflow='hidden';
		change=window.setInterval("shrink()",1);
	}
}
function maxmaxheight(){
	h=document.body.clientHeight;
	if(h==null)
		h = window.innerHeight;
	return h;
}
function shazam_cleanup(){
	if(icrop!=null){target.style.overflow=icrop;}
	target=null;
	window.clearInterval(change);
	runnin=false;
	last=false;
}
function grow(max){
	sz=target.offsetHeight+2;
	done=false;
	document.getElementById('thedivdata').innerHTML = "next: " + sz + " max: " + max;
	if(sz>=max){sz=max;done=true;}
	target.style.height=sz+'px';
	if(done){shazam_cleanup();}
}
function shrink(){
	if(last){
		last=false;
		target.style.display='none';
		target.style.height=origsz+'px';
		shazam_cleanup();
	}else{
		sz=target.offsetHeight-10;
		if(sz<=1){sz=1;last=true;}
		target.style.height=sz+'px';	
	}
}	

function toggleDiv( divName, checked ) {
  	if( checked == true ) {
		git(divName).style.display="block";
  	}	else {
     	git(divName).style.display="none";
  	}
}
function toggleCheck( field, checkId ) {
  ck = git(checkId)
  if (ck != null){ ck.checked = (field.value.replace(/\s+/,'').length > 0);}
}

function onChildrenSelect( num ) {
  
  	for ( i = 1; i <= 6; i++ ) {
	  	if ( i <= num ) {
	  	  	eval( getDocObj( "child" + i + "Info" ) ).style.display="block";
	  	}	  	  
	  	else {
	  	  	eval( getDocObj( "child" + i + "Info" ) ).style.display="none";
	  	}
	}
}

function phTab(here,there){
    if (there.length > 0  && here.getAttribute&&here.value.length==here.getAttribute('maxlength'))
      git(there).focus();
}

function toggleLink(aLink,id){
	tog = aLink.rel;
    blk = git(id);
	if(blk.style.display=='none'){
		blk.style.display='block';
		aLink.innerHTML='[ hide ]';
	}else{
		blk.style.display='none';
		aLink.innerHTML='[ show ]';
	}
	
}
