/*
 * javascript resource for typo3 extemsion 'mpstartools'
 * (c) 2008-2009, mp group GmbH, frank krueger <fkrueger-at-mp-group.net>
 *
 */

// *** define sound status
var bSound = true;

// *** show ajax loader
function showAjaxLoader( fn_sID ) {
	xajax.$( fn_sID ).innerHTML = '<div style="width:99%;height:400px;text-align:center;"><br /><img src="'+fn_sLoadingImage+'" border="0" align="center" alt="'+fn_sLoadingAltText+'" title="'+fn_sLoadingTitleText+'" /></div>';
}

// *** clear div
function clearDiv( fn_sID ) {
	xajax.$( fn_sID ).innerHTML = '';
}

// *** hottopics calendar date changed
function dateChangedAjax( calendar ) {
	if ( calendar.dateClicked ) {
		var y = calendar.date.getFullYear();
		var m = calendar.date.getMonth() + 1;	// integer, 0..11
		var d = calendar.date.getDate();		// integer, 1..31

		// redirect...
		showAjaxLoader( "ht-list-container" );
		star_xajaxGetHotTopics( y + "/" + m + "/" + d );
	}
}

// *** play soundfile
function playSound( fn_sSoundfile ) {
	if ( bSound ){
		
		// *** ie
		if( xajax.$('soundeffect') ) {
			xajax.$('soundeffect').src="";
			xajax.$('soundeffect').src=fn_sSoundfile;
		}
		
		// *** mozilla / netscape
		if( xajax.$('soundeffect_noie') ) {
			xajax.$('soundeffect_noie').src="";
			xajax.$('soundeffect_noie').src=fn_sSoundfile;
			xajax.$('soundeffect_noie').data=fn_sSoundfile;
		}
	}
}
function playSoundBG( fn_sSoundfile ) {
	if ( bSound ){
		
		// *** ie
		if( xajax.$('soundbg') ) {
			xajax.$('soundbg').src="";
			xajax.$('soundbg').src=fn_sSoundfile;
		}
		
		// *** mozilla / netscape
		if( xajax.$('soundbg_noie') ) {
			xajax.$('soundbg_noie').src="";
			xajax.$('soundbg_noie').src=fn_sSoundfile;
			xajax.$('soundbg_noie').data=fn_sSoundfile;
		}
	}
}
function playSoundFF( fn_sSoundfile ) {
	if ( bSound ){
		xajax.$('soundeffectFF').src=fn_sSoundfile;
		xajax.$('soundeffectFF').Play();
	}
}

// *** toggle sound
function toggleSound( fn_sSoundOffTitle, fn_sSoundOnTitle ) {
	if( bSound ) {
		xajax.$('btnSound').innerHTML="sound off";
		xajax.$('btnSound').className="sound-off";
		xajax.$('btnSound').title="switch sound on";
		bSound = false;
		
		if( xajax.$('soundbg') ) {
			xajax.$('soundbg').src="";
		}
		if( xajax.$('soundbg_noie') ) {
			xajax.$('soundbg_noie').src="";
			xajax.$('soundbg_noie').data="";
		}
	// *** switch sound on
	} else {
		xajax.$('btnSound').innerHTML="sound on";
		xajax.$('btnSound').className="sound-on";
		xajax.$('btnSound').title="switch sound off";
		bSound = true;
	}

	// *** set sound field value
	if( xajax.$('tx_mpstartools_pi2[sound]') ) {
		xajax.$('tx_mpstartools_pi2[sound]').value = bSound;
	}
}

// *** toggle click selection
function toggleSelection( fn_iBtnNumber, fn_objTargetTag, fn_sValue ) {

	// *** assign value
	xajax.$(fn_objTargetTag).value=fn_sValue;

	// *** set / reset buttons
	fn_iCounter = 1;
	while( xajax.$('mpstartools-qoption'+fn_iCounter) ) {

		if( fn_iCounter == fn_iBtnNumber ) {
			xajax.$('mpstartools-qoption'+fn_iCounter).className="mpstartools-qoption-act"+fn_iCounter;
		} else {
			xajax.$('mpstartools-qoption'+fn_iCounter).className="mpstartools-qoption"+fn_iCounter;
		}

		// *** increase counter
		fn_iCounter++;
	}
}

// *** toggle click selection
function clickSelection( fn_objTargetTag, fn_sValue ) {

	// *** assign value
	xajax.$(fn_objTargetTag).value=fn_sValue;
	
	// *** submit form
	star_xajaxGetAnswer(xajax.getFormValues('mpstartools-qa-form'));
	return false;
}