var Page = {
	initialize: function() {

// input focus color
	ffocus = $$('input[type=text], input[type=password], textarea');
	ffocus.each(function(focus){
	focus.addEvent('focus', function(){focus.setStyles({backgroundColor:'#fefa8f', color:'#000000'});});
    focus.addEvent('blur', function(){focus.setStyles({backgroundColor:'#fefefe',color:'#585757'});});
  	});
  	
	// input jump-next to text input-field
	ifocus = $$('input[type=text], input[type=password], textarea');
	ifocus.each(function(myInput){
		myInput.addEvent('keyup', function (){
			myLen = this.getProperty('maxlength');
			if (myLen==-1){return;}
			
			// Die Moo-Tools-Lib ist hier nicht mehr verfuegbar ?!
			// deshalb schreibe ich dies hier in standard-JS
			// es ist sperrig und haesslich - klappt aber.
			
			if(this.value.length >= myLen)
			{	//alle <input>-Felder
				var theForm = this.form ;
				//var myForm = theForm.getElementsByTagName('input');
				var myForm = $$(theForm, "input, textarea, radio");
				//var myForm = theForm.getElementsBySelector("input, textarea");
				var theLast = myForm[myForm.length-1];
				//console.log("the last is=", theLast);
				var myPos = null;
				for ( var p=0; p<myForm.length; p++ ) {
					if( myForm[p] == this )	{myPos = p+1; break;};
				} //eo-for
			
				if ( theLast == this)  //getElements('input')[0]
					{// sind wir bereits im letzten feld ?
					console.log("no jump,return"); 
					return;
				} else 
				{ // filter alle input-Elemente vom typ =='text','textarea' oder 'passwd'
					var allowedTypes =  [ 'password', 'text', 'textarea' ];
					var myNext = false;
					for ( var p=myPos; p<myForm.length; p++ ) {
							var myField = myForm[p] ;
				    		if ( allowedTypes.contains( myField.type ) && !myField.readonly )
								{ myNext = myForm[p]; break;}
					} //eo-for
					//console.log( myNext );
					if ( myNext ) { myNext.focus(); }
					return;
				} //eo-else
			} //eo-if this.value.length
		}); // eo-myInput-addEvent
	}); //eo-ifocus.each

// opens external (class="ext" rel="small" or rel="big") links in a new window
$$('a.ext').each(function(popup){
var link = popup.getProperty('href');
 
	if (popup.getProperty('rel') == 'small'){
		popWidth = '800';
		popHeight = '450';
	} else if (popup.getProperty('rel') == 'big'){
		popWidth = '820';
		popHeight = '450';	
	} else if (popup.getProperty('rel') == 'pict'){
		popWidth = '920';
		popHeight = '700';	
	} else if (popup.getProperty('rel') == 'okat'){
		popWidth = '920';
		popHeight = '700';	
	} else if (!popup.getProperty('rel')){
		var popWidth = "650";
		var popHeight = "450";
	}
	else if (popup.getProperty('rel') == 'cass_help'){
		popWidth = '868';
		popHeight = '800';
	}
	
	popup.onclick = function() {
		window.open(link,'pop','status,scrollbars,resizable,width='+popWidth+',height='+popHeight+'');
		return false;
	};
});
 
// Problem : PopUp-Fenster, wie bspsw. Produktvideos sollen im Vordergrund bleiben, d.h. den
// Focus behalten. Die derzeitige Regelung verhindert dies, da mit jedem refresh der Hauptseite
// auch der Focus wieder dem Hauptfenster zugeordnet wird.
// L"sung : Im inc3/footer.txt befindet sich ein unsichtbares DIV-Element mit leerem Inhalt.
// Sobald dies DIV irgendeinen Inhalt erh"lt, lehnt das Hauptfenster den Focus ab. Somit bleibt 
// dem Popup der Focus erhalten. 
// Beim Erzeugen eines PopUp's sollte der Inhalt des DIV-Elementes nun entsprechend gesetzt werden.
// Mit der Scratch-Variablen [scratch vidano] wird dies momentan erledigt. Der Lebenszyklus von 'vidano'
// ist auf die Fly-Page beschr"nkt.
// Genaueres siehe auch in inc3/footer.txt
 
// NEU: set body target
window.name='cademain';
if ( $defined( $("hasVideo") ) ){
	var hasVideo = $("hasVideo");
	if (hasVideo.innerHTML != "")
		{ //irgendwas machen
		var tmp="";
		}
	else 
		{ window.focus(); }
} 
else { window.focus(); }
//eo-if-defined

}
};
 
window.addEvent('domready', function(){ Page.initialize();});
