//////////////////////////////////////////////////////
// focus formfield



//////////////////////////////////////////////////////
// Session Cookie

function createCookie(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 readCookie(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 eraseCookie(name) {
	createCookie(name,"",-1);
}

///////////////////////////////////////////////////
// show a specific tab backup
function mkInvisible_formlines() {

       // quit if this function has already been called
       if (arguments.callee.done) return;

       // flag this function so we don't do the same thing twice
       arguments.callee.done = true;

        //alert ('is invisible')
	var tabs = getElementsByClass('formline', 'Default', 'all');
	for(i=0; i<tabs.length; i++)
		tabs[i].className = 'hidden_set';

        //letztgeoeffnete anzeigen

        x = readCookie('open');

	var tabs = getElementsByClass('hidden_set', x);
	for(i=0; i<tabs.length; i++)
		tabs[i].className = 'formline';
}

///////////////////////////////////////////////////
// show a specific tab backup
function mkVisible_fmp(fmp_name) {

	var tabs = getElementsByClass('hidden_set', fmp_name);
	// show every element with class 'hidden_set' 

        if (tabs.length > 0) {
        //alert ('there are hidden elements');
	for(i=0; i<tabs.length; i++)
		tabs[i].className = 'formline';
	// show every element with class 'hidden_set'

        //set Cookie
        createCookie('open',fmp_name,1);
        //x = readCookie('open');
        //alert(x);

        } else {

	var tabs = getElementsByClass('formline', fmp_name);
	// hide every element with class 'formline' 
        //alert ('there are visible elements');
	for(i=0; i<tabs.length; i++)
		tabs[i].className = 'hidden_set';
	// hide every element with class 'hidden_set'

        //deleteCookie
        eraseCookie('open');
        //x = readCookie('open');
        //alert(x);
        }
        
 }

///////////////////////////////////////////////////
// get Elements by Class
function getElementsByClass(searchClass, fmp, domNode,  tagName) {
	if (domNode == 'all') domNode = document;
	if (domNode == null) domNode = document.getElementById(fmp);
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;

// Kontrollausgabe
alert (searchClass + ', is visible');
}

///////////////////////////////////////////////////
// show a specific tab
function mkVisible_fmp2(fmp_name) {

//	var tabs = getElementsByClass('formline', fmp_name, 'all');
//	for(i=0; i<tabs.length; i++)
//		tabs[i].setAttribute('class', 'hidden_set');

	// show every element with class 'hidden_set' 
	var tabs = getElementsByClass('hidden_set', fmp_name);
        // Kontrollausgabe
        x = document.getElementById('Default');
        //alert (x + ', is visible');
	for(i=0; i<tabs.length; i++)
		tabs[i].className = 'formline';
	// show every element with class 'hidden_set'		

        var currtabs = getElementsByClass('formline', fmp_name);
        if (currtabs.length > 0){
            alert('no invisble lines')
            for(i=0; i<currtabs.length; i++)
		currtabs[i].className = 'formline';
       }else{
            alert('invisble lines');
       }
 }



///////////////////////////////////////////////////
// make forminfo visible
function mkVisible(anId , aStrg){

x = document.getElementById(anId);

String.prototype.replaceAll=function(s1, s2) { 
	  return this.replace(new RegExp(s1,"g"), s2);
	}
endStrg = aStrg.replaceAll('bla',' ');

x.setAttribute('class', 'pop_nav_fieldinfo');
x.innerHTML = endStrg;

// Kontrollausgabe
//alert ( y + ', is visible');
}

///////////////////////////////////////////////////
// make forminfo invisible
function mkInvisible(anId){

x = document.getElementById(anId);
x.innerHTML = '';

// Kontrollausgabe
//alert ( anId.id + ', is visible');

}

///////////////////////////////////////////////////
// make forminfo invisible
function mkInvisible_alt(anId){

anId.setAttribute('class', 'pop_nav_fieldinfoInvis');

// Kontrollausgabe
//alert ( anId.id + ', is visible');

}
