function checkMandatoryInputs(element,classname,myMessage){
    //first check if the mandatory fields are filled
    var elements = $(element).getElementsByClassName(classname);
    var myStop   = false;

    for(var i = 0; i < elements.length; i++){
        if(elements[i].value.length < 1 || (elements[i].type == 'checkbox' && elements[i].checked == false)){
            elements[i].style.backgroundColor = '#ffdddd';
            myStop = true;
        }else{
            elements[i].style.backgroundColor = null;
        }
    }


    if(myStop){
        if(!myMessage){
            myMessage = 'FŸllen Sie bitte alle Pflichtfelder aus!';
        }
        alert(myMessage);
        return false;
    }

    return true;
}

function saveProfile(){
    //check mandatory inputs
    if(!checkMandatoryInputs('profile','mandatory')){
        return;
    }    
    
    if($('password').value != $('password2').value){
        alert('Password 1 und Password 2 sind nicht identisch :(');
        return;
    }
    
    if($('mailinuse').style.display != 'none'){
        alert('Bitte geben Sie eine andere e-mail Adresse ein!');
        return;
    }
    
    $('profile').submit();
    $('profile').disable();
}

function dropFile(file,dir){
    if(confirm('Sind Sie sicher?')){
        window.location.href = 'dropbox.html?delete='+file+'&dir='+dir;
    }
}

function publishPodcast(){
    //check mandatory inputs
    if(!checkMandatoryInputs('podcast','mandatory')){
        return;
    }    
    
    $('podcast').submit();
    $('podcast').disable();
}

function dropUser(uid){
    if(confirm('Are you sure?')){
        window.location.href = window.location.href+'?&delete='+uid;
    }
}

function dropPodcast(pid){
    if(confirm('Are you sure?')){
        window.location.href = window.location.href+'?&delete='+pid;
    }
}

function checkMail(obj){

    (new AjaxRequest).send({
        url     : "/ajax/",
        data    : {
            action: 'checkMail',
            mail: obj.value
        },

        onSuccess  : function(data, info)
        {
            if(data.ok){
                $('mailinuse').style.display = 'none';
                $('mail').style.backgroundColor = '#FFFFFF';
            }else{            
                $('mailinuse').show();
                $('mail').style.backgroundColor = '#FFEEEE';
            }
        }
      });          
}

function pause(numberMillis) 
{
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true) 
{
now = new Date();
if (now.getTime() > exitTime)
return;
}
} 

var counter = 0;
var say     = new Array();
say[0]      = '2004 - Das Kunstwort PODCAST setzt sich aus den Begriffen iPod und Broadcast zusammen';
say[1]      = '2005 - der Begriff PODCAST wird in GroÃŸbritannien zum word of the year gewÃ¤hlt';
say[2]      = '2006 - erstmals werden Podcast-Messen, so genannte Podcast-Days, abgehalten';
say[3]      = '2007 - profipodcast wird gegrÃ¼ndet und gewinnt eine internationale Ausschreibung der Deutschen Zentrale fÃ¼r Tourismus';
say[4]      = '2008 - profipodcast etabliert sich am deutschsprachigen Markt und geht bei einem weltweiten British Airways contest als Gewinner hervor';
say[5]      = '2009 - profipodcast wird vom Projekt RUHR 2010 als exklusiver Podcaster der Podcast-Serie "Ruhrpott(d)cast" beauftragt';
say[6]      = '2010 - profipodcast bietet schon zu Beginn der 10er Jahre was Medienexperten fÃ¼r die Zukunft prophezeien';
say[7]      = 'Give your Vision a Voice!';

function advertise(){
    //$('counters').innerHTML = '<img src="/templates/main/img/loading.gif" />';
    
    if(counter < 7){
        $('ctext').style.paddingTop = '0';
    }else{
        $('ctext').style.paddingTop = '6px';
    }
    
    if(counter == 7){
        $('ctext').style.fontSize = '16px';
        $('ctext').style.color = '#A00';
        $('ctext').style.paddingTop = '5px';
    }else{
        $('ctext').style.fontSize = '13px';
        $('ctext').style.color = '#444';
    }
    
    $('ctext').innerHTML = say[counter];
    //Fat.fade_element('counters',10,1000,"#ffffaa","#ffffff");  
    
    counter++;
    if(counter>7){
        counter = 0;
    }
}