/**
 * tools.js
  */


/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}

function validateFormmailInput(oForm, aList){
    var success = true;
        for (i=0; i< aList.length;++i) {
            var obj = oForm.elements[aList[i]];
            if(obj!=null){
                obj.value = Trim(obj.value);
                if(obj.type=="checkbox"){
                    if(!obj.checked ){
                        success = false;
                    }
                }
                if(obj.value==''){
                    if(obj.origClassName==null||obj.origClassName=='undefined'){
                        obj.origClassName = obj.className;
                    }
                    success = false;
                }
                if(success==true){
                    obj.className = obj.origClassName;
                }
                else{
                    labels = document.getElementsByTagName("label");
                    if(labels!=null){
                        for(l =0; l< labels.length;++l){
                            if(labels[l].getAttribute("for")==aList[i]){
                                labels[l].origClassName = obj.className;
                                labels[l].className="errorforka";
                            }
                            labels[l].className=labels[l].origClassName;
                        }
                    }
                    obj.className = 'errorforka';
                    //obj.focus();
                    var message = document.getElementById('errormessage');
                    if(message!=null&& message!='undefined'){
                        message.style.display='block';
                    }
                }
            }
        }
        return success;
}

//
// Popup-Fenster mit flexibler Breite und Hoehe und Scrollbars
// (Übernahme tour.ard.de)
//
function popscroll(ziel,w,h) {
  jsdatum = new Date();
  jsdatum = jsdatum.getHours() + '_' + jsdatum.getMinutes() + '_' + jsdatum.getSeconds();

  fenster = window.open(ziel,jsdatum,'width=' + w + ',height=' + h + ',resizable=yes,scrollbars=yes');
  fenster.focus();
}


// START COUNTDOWN SCRIPT
/**
 * Countdown (gibt nur die anzahl der Tage aus
 * z.b. new Countdown(2005,09,18,24,0);
 */
 function Countdown(year, month, day, hour, minute){
 	this.year = year;
	this.month = month-1;
	this.day = day;
	this.hour = hour;
	this.minute = minute;
	this.render = render;
	this.endDate = new Date(this.year, this.month, this.day, this.hour, this.minute, 0);
	this.render();
}

function render(){
	var future = this.endDate.getTime();
	var today = new Date().getTime();
	var dd = future - today;
	dday=Math.floor(dd/(60*60*1000*24)*1);
	dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
	dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
	dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
	if(dday == 0){
		document.write("heute");
	}else{
		if(dday.length < 10){
			document.write("0" + dday);
		}else{
			document.write(dday);
		}
	}
}

// END COUNTDOWN SCRIPT
//WICHTIG FUER DUMPF VOTING IAA
function DumpfVotingOnMouseOver(tr){
    tr.oldBackgroundColor = tr.style.backgroundColor;
    tr.style.backgroundColor="dddddd";
}
function DumpfVotingOnMouseOut(tr){
    tr.style.backgroundColor=tr.oldBackgroundColor;
}

function checkYoufmContactForm(){
  var theAlert = "Bitte die Pflichtfelder ausfüllen...";
  var theForm = document.forms["kontakt"];
  if (theForm.vorname.value == "")
  {
    alert(theAlert);
	theForm.vorname.focus();
	return false;
  }
  if (theForm.name.value == "")
  {
    alert(theAlert);
	theForm.name.focus();
	return false;
  }
  if(theForm.email.value == ""){
    alert(theAlert);
    theForm.email.focus();
    return false;
  }
  theForm.submit();
}
function checkYoufmRequestForm(){
  var theAlert = "Bitte die Pflichtfelder ausfüllen...";
  var theForm = document.forms["request"];
  if (theForm.vorname.value == "")
  {
    alert(theAlert);
	theForm.vorname.focus();
	return false;
  }
  if (theForm.name.value == "")
  {
    alert(theAlert);
	theForm.name.focus();
	return false;
  }
  if(theForm.email.value == ""){
    alert(theAlert);
    theForm.email.focus();
    return false;
  }
  if(theForm.interpret.value==""){
    alert(theAlert);
    theForm.interpret.focus();
    return false;
  }
  if(theForm.titel.value==""){
    alert(theAlert);
    theForm.titel.focus();
    return false;
  }
  theForm.submit();
}
function checkNewsletterForm(oForm){
  var theAlert = "Bitte die Pflichtfelder ausfüllen...";
  var theForm = form;
  if(theForm  == document.forms.newsletter){
     if (theForm.vorname.value == "")
      {
        alert(theAlert);
        theForm.vorname.focus();
        return false;
      }
      if (theForm.name.value == "")
      {
        alert(theAlert);
        theForm.name.focus();
        return false;
      }
      if(theForm.email.value==""){
        alert(theAlert);
        theForm.email.focus();
        return false;
      }
      theForm.submit();
  }
  else{
    if(theForm.email_unsubscribe.value ==""){
        alert(theAlert);
        theForm.email_unsubscribe.focus();
        return false;
    }
    theForm.submit();
  }
  return false;
}
function checkForm(oForm){
    if(oForm.name=="kontakt"){
        return checkYoufmContactForm();
    }
    if(oForm.name=="request"){
        return checkYoufmRequestForm();
    }
}
 //Playlistfenster öffnen
 // (Wird vom Flashmovie geladen)

function openPlaylist() {
    var a=window.open('http://www.you-fm.de/titelsuche.html','youfmplaylist','menubar=no,status=no,location=no,width=570,height=390,toolbar=no,scrollbars=yes,resizable=no');
}
