var errorMsg = new Array()

errorMsg['ok']  				= 'Alles in Ordnung.';
errorMsg['generel'] 		= 'Bitte füllen Sie die rot eingefärbten Felder korrekt aus.\n\n';
errorMsg['empty'] 			= '- Mindestens ein Feld ist nicht ausgefüllt.';
errorMsg['email']				= '- Die eingegebene Email-Adresse ist nicht gültig.';
errorMsg['url']					= '- Die eingegebene URL-Adresse ist nicht gültig.';
errorMsg['datum']					= '- Das eingegebene Datum ist nicht gültig.';
errorMsg['contactType']	= 'Bitte geben Sie an, warum Sie uns kontaktieren möchten, damit wir Ihre Anfrage schnellst möglich bearbeiten können.';
errorMsg['gruempi_spieltag'] = 'Bitte wählen Sie mind. ein möglicher Spieltag aus.';


if(window.location.href.indexOf("index.php?pid=home")!=-1 || window.location.pathname=="/" || window.location.pathname=="")
{
	$(window).load(function() {
		$('#slideshow').orbit({
			
	     timer: true, 			 // true or false to have the timer
	     advanceSpeed: 7400, 		 // if timer is enabled, time between transitions 
	     pauseOnHover: true, 		 // if you hover pauses the slider
	     startClockOnMouseOut: true, 	 // if clock should start on MouseOut
	     startClockOnMouseOutAfter: 100, 	 // how long after MouseOut should the timer start again
	     directionalNav: false, 		 // manual advancing directional navs
	     animationSpeed: 1400,                // how fast animtions are
	     bullets: true			 // true or false to activate the bullet navigation
		});
	});
}




// Browserfunktion
function Browser() {
	var b=navigator.appName
	if (b=='Netscape') this.b='ns'
	else if (b=='Microsoft Internet Explorer') this.b='ie'
	else this.b=b
	this.version=navigator.appVersion
	this.v=parseInt(this.version)
	this.vNo=parseFloat(navigator.appVersion)//
	this.ns=(this.b=='ns' && this.v>=4)
	this.ns4=(this.b=='ns' && this.v==4)
	this.nsMinor406=(this.b=='ns' && this.vNo<=4.05)//
	this.ns5=(this.b=='ns' && this.v==5)
	this.ie=(this.b=='ie' && this.v>=4)
	this.ie4=(this.version.indexOf('MSIE 4')>0)
	this.ie5=(this.version.indexOf('MSIE 5')>0)
	this.ie55=(this.version.indexOf('MSIE 5.5')>0)
	this.dom=((document.createRange&&(document.createRange().createContextualFragment) || document.getElementById)?true:false)
	this.min=(this.ns||this.ie)
	var ua=navigator.userAgent.toLowerCase()
	if (ua.indexOf('win')>-1) this.platform='win32'
	else if (ua.indexOf('mac')>-1) this.platform='mac'
	else this.platform = 'other'
}
is=new Browser();

// Popupfenster
function wopen(url,popupname,attributes){
  win= window.open(url,popupname,attributes);
  win.focus();
}
function openPopupSmall(url) {
	wopen(url,'YOGAPRAXIS_Small','left=100,top=100,width=470,height=500,scrollbars=yes,menubar=no,location=no,toolbar=no,resizable=no');
}
function openPopupLarge(url) {
	wopen(url,'YOGAPRAXIS_Large','left=0,top=0,width=1024,height=746,scrollbars=yes,menubar=no,location=no,toolbar=no,resizable=yes');
}
function openPopupVideo(url) {
	wopen(url,'YOGAPRAXIS_Large','left=0,top=0,width=465,height=540,scrollbars=no,menubar=no,location=no,toolbar=no,resizable=no');
}
// Gibt ein Formularobjekt zurueck
function getFormObj(){
  return document.forms[0];
}
function checkForm(){
	var firstErrorField = null;
	errorCode = new Array();	
	
	formObj = getFormObj();
  
  requIndex = 0;
  
	for(i=0; i < formObj.elements.length; i++){		
  	el = formObj.elements[i];
  	// Den roten Rahmen wieder entfernen
  	el.className = (el.type.indexOf("checkbox") != -1 || el.type.indexOf("radio") != -1) ? 'checkbox':'';  	
 	
  	// Ist es ein Pflichfeld
  	if( el.name==requFields[requIndex] && el.value=='' )	{
  		requIndex++;
  		el.className = 'alert';
  		errorCode['empty'] = true;
  	}
  	else if( el.name==requFields[requIndex] && el.value!='') {
  		requIndex++;
  	}
  	// Ist es eine Email-Adresse
  	if( el.name.indexOf('email')!=-1 && el.value != '')	{
  		if(!checkEmail(el)){
  			el.className = 'alert';
  			errorCode['email'] = true;
  		}
  	}
  	// Ist es eine URL-Adresse
  	if( el.name.indexOf('url')!=-1 && el.value != '')	{
  		if(!checkURL(el)){
  			el.className = 'alert';
  			errorCode['url'] = true;
  		}
  	}
  	// Ist es ein Datum
  	if(el.name.indexOf("datum") != -1 && el.value != '')	{
      if(!formateDate(el, i)){
      	el.className = 'alert';
  			errorCode['datum'] = true;
  		}
    }
  }
  // Setze den Errorstring zusammen
  var errorString = '';
  for (key in errorCode) {
  	if(errorString == '') {
  		errorString += errorMsg['generel'];
  	}
  	errorString += errorMsg[key] + '\n';
  }
  if(errorString != '') {
  	alert(errorString);
  } else {
  	formObj.submit();
  }
}
function checkEmail(el){
  if(el.value.indexOf('@') == -1 || el.value.indexOf('.') == -1){
  	return false;
  }
  return true;
}
function checkURL(el){
  if(el.value.indexOf('www.') == -1){
  	return false;
  }
  return true;
}
function checkCheckBoxGroup(group, errorCode){
	var checkboxChecked = false;
  
  formObj = getFormObj();
  el = formObj.elements[group];
  
  for(j=0; j<el.length; j++){
  	if(el[j].checked) {
  		checkboxChecked = true;
  	}
  }
  if(!checkboxChecked) {
  	alert(errorMsg[errorCode]);
  	return true;
  }
  return false;
}

function formateDate(field, i) {
	formated = false;
	//check if the entered date has "." as separator
	tmpArr = field.value.split(".");

  // if the separator is "." and the correct number of entries is entered, the length of the tmpArr must be 3.
  // if it is not 3, the date is wrong formated
  if(tmpArr.length != 3){
    return false;
  }
  else{
    // check if the date has the correct 2 digit format,
    // if it is a one digit, correct it (add an "0" infront of the single digit), save the new value in the array  and set the variable formated to "true"
    // this will indicate dat a formation has been done.

    if(tmpArr[0].length == 1 && tmpArr[0] < 10){
      tmpArr[0] = "0" + tmpArr[0]
      formated = true
    }
    if(tmpArr[1].length == 1 && tmpArr[1] < 10){
      tmpArr[1] = "0" + tmpArr[1]
      formated = true
    }
    if(tmpArr[2].length == 1 && tmpArr[2] < 10){
      tmpArr[2] = "0" + tmpArr[2]
      formated = true
    }
    if(tmpArr[2].length == 2){
    	var currentTime = new Date();
    	var fullYear = String(currentTime.getFullYear());
    	if(tmpArr[2] < fullYear.substr(2,2) && tmpArr[2] >= 0 ) {
      	tmpArr[2] = "20" + tmpArr[2];
      } else {
      	tmpArr[2] = "19" + tmpArr[2];
      }
      formated = true
    }
    // if anything has been formated, overwrite the inputfield with the new value
    if(formated == true){
      formatedValue = tmpArr[0] + "." + tmpArr[1] + "." + tmpArr[2];
      field.value = formatedValue;
    }
    // checking format  dd.mm.yyyy
    if( !checkDayInMonth(tmpArr[0],tmpArr[1],tmpArr[2])
     || tmpArr[1] < "01" || tmpArr[1] > "12"
     || tmpArr[2] < "1900" || tmpArr[2] > "2099" ){
     	
      return false;
    }
  }
  return true;
}

//check the day as valid in dependency of month and year
function checkDayInMonth(day, month, year) {
  iDay = parseInt(day,10);
  iMonth = parseInt(month,10);
  iYear = parseInt(year,10);

  var daysInMonth = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
  // February has 29 days in any year evenly divisible by four,
  // EXCEPT for centurial years which are not also divisible by 400.
  daysInMonth[1] = ((iYear % 4==0) && ( (!(iYear % 100==0)) || (iYear % 400==0))) ? 29:28;

  if (iDay < 1 || iDay > daysInMonth[iMonth-1]) return false;
  else return true;
}
