// EUREMUETTER.DE SHOP JS
// CREATED 2009/JULY/06
// TGXMEDIA.COM

// *** ERROR CONSTANTS
var ALL_FIELDS_ERROR = "Bitte f&uuml;lle <i>alle</i> Felder aus.";
var ZIP_ERROR        = "Gib bitte eine g&uuml;ltige Postleitzahl an.";
var EMAIL_ERROR      = "Gib bitte eine g&uuml;ltige E-Mail Adresse an.";
var COUNTRY_ERROR    = "Gib bitte ein Land an.";


function validateInput(){
    
    // REQUIRED FIELDS: ALL FIELDS
    var firstName = $('firstName').value;
    var lastName  = $('lastName').value;
    var street    = $('streetNo').value;
    var zip       = $('zip').value;
    var city      = $('city').value;
    var email     = $('email').value;
    
    var errorOccured = false;
    var errorMessage = "";
    
    if(!(firstName.length > 0 && lastName.length > 0 && street.length > 0 && zip.length > 0 && city.length > 0 && email.length > 0)){
        errorMessage = ALL_FIELDS_ERROR;
        errorOccured = true;
    }else{ // ALL FIELDS OK
    
        regEx = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
		if(!email.match(regEx)){
			errorMessage = EMAIL_ERROR;
       		errorOccured = true;
       		
		}else{ // && MAIL OK
		
			var countrySelect         = $("countrySelect");
			var selectedCountry       = countrySelect[countrySelect.selectedIndex].value;
			var selectedCustomCountry = (selectedCountry.length == 0);
			
			if(selectedCustomCountry){
			
				var customCountryInput = trim($("customCountryInput").value);
				if(customCountryInput.length == 0){
					errorMessage = COUNTRY_ERROR;
       				errorOccured = true;
				}
				
			}
			
			
		}
        
    }
    
    if(errorOccured){
    	document.getElementById('errorMessage').innerHTML = errorMessage;
    	document.getElementById('errorMessage').style.display = 'block';
    }
    
    return !errorOccured;
    
}

function updateCustomCountryInput(selectedVal){
	
	var input   = $("customCountryInput");
	input.value = "";
	
	if(trim(selectedVal).length == 0){
		Effect.Appear(input,{duration: 0.5});
		input.focus();
	}else{
		Effect.Fade(input, {duration: 0.325});
		input.blur();
	}
	
}

function trim(str){
	return str.replace (/^\s+/, '').replace (/\s+$/, '');
}

// CALLED ONLOAD...
function embedAllSWFs(){

	createVideoSWF("-x5hzNOVuAc","ndlmagYoutube");
	createVideoSWF("SUtiOkQTDCU","rfhYoutube");
	createVideoSWF("FnqgopFavpY","sdsYoutube");
	createVideoSWF("eWqEvSOv8L0","osseYoutube");
	
	createAudioPlayer("../lib/xml/osse_audio_playlist.xml","osseAudio");
	createAudioPlayer("../lib/xml/ndlmag_audio_playlist.xml","ndlmagAudio");
	createAudioPlayer("../lib/xml/sdsextra_audio_playlist.xml","sdsExtraAudio");
	
}


// CONSTANTS
var ANIM_DURATION    = 0.75;

// ANIMATE PRESS BOX
function embedYoutubeVideo(mediaBoxID,linkID,defaultLinkTitle,openedLinkTitle,videoID){
 
   var mediaBox    = $(mediaBoxID);
   var linkBtn     = $(linkID);
   
   var isOpened = function(){
   	return !(mediaBox.style.display == 'none');
   }
   
   var checkButtonState = function(){
	  if(!isOpened()){
	   	 linkBtn.innerHTML = defaultLinkTitle;
	   	 mediaBox.innerHTML = "&nbsp;" // KILL PLAYING SWF
	   	 createVideoSWF(videoID,mediaBoxID);
	   }else{
	   	 linkBtn.innerHTML = openedLinkTitle;
	   } 
   }
   
  Effect.toggle(mediaBoxID,'slide',{duration:ANIM_DURATION,scaleContent:false,afterFinish:checkButtonState});
   
}

function createVideoSWF(videoID,containerID){
	var so   = new SWFObject('http://www.youtube.com/v/' + videoID, 'YOUTUBE', '450', '364', '9', '#FFFFFF');
	so.addParam('quality', 'high');
	so.addParam('menu', 'false');
	so.addParam('scale','noScale');
	so.addParam('align','TL');
	so.addParam('allowScriptAccess', 'always');
	so.addParam('allowFullScreen','true');
	so.addParam('wmode','opaque');
	so.write(containerID);
	
}

function embedAudioPlayer(mediaBoxID,linkID,defaultLinkTitle,openedLinkTitle,playlistURL){
 
   var mediaBox    = $(mediaBoxID);
   var linkBtn     = $(linkID);
   
   var isOpened = function(){
   	return !(mediaBox.style.display == 'none');
   }
   
   var checkButtonState = function(){
	  if(!isOpened()){
	   	 linkBtn.innerHTML = defaultLinkTitle;
	   	 mediaBox.innerHTML = "&nbsp;"
	   	 createAudioPlayer(playlistURL,mediaBoxID);
	   }else{
	   	 linkBtn.innerHTML = openedLinkTitle;
	   } 
   }
   
   Effect.toggle(mediaBoxID,'slide',{duration:ANIM_DURATION,scaleContent:false,afterFinish:checkButtonState});
   
}

function createAudioPlayer(playlistURL,containerID){
		
	var so   = new SWFObject('../lib/swf/audioplayer.swf', 'AUDIO-PLAYER', '450', '198', '9', '#FFFFFF');
	so.addParam('quality', 'high');
	so.addParam('menu', 'false');
	so.addParam('scale','noScale');
	so.addParam('align','TL');
	so.addParam('allowScriptAccess', 'always');
	so.addParam('allowFullScreen','true');
	so.addParam('wmode','opaque');
	so.addVariable('file',playlistURL);
	so.addVariable('playlist','bottom');
	so.addVariable('dock','true');
	so.addVariable('icons','false');
	so.addVariable('backcolor','FFFFFF');
 	so.addVariable('frontcolor','000000');
 	so.addVariable('lightcolor','CC0000');
 	so.addVariable('screencolor','ffe100');
	so.write(containerID);
	
}
