﻿/*******************************************************************
* Methoden zeigt Untermenü aus Hautnavigation
*******************************************************************/
function show(element){
	element.className = "hover";
}

/*******************************************************************
* Methoden verbirgt Untermenü aus Hautnavigation
*******************************************************************/
function hide(element){
	element.className = "";
}


function checkData(){	
	
	if($("#tx-srfeuserregister-pi1-date_of_birth").val()!="" && 
			!validateDate($("#tx-srfeuserregister-pi1-date_of_birth").val())){
		alert("Bitte geben sie ein gültiges Datumsformat an tt-mm-jjjj");
	}else if($("#tx-srfeuserregister-pi1-depotdate").val()!="" && 
			!validateDate($("#tx-srfeuserregister-pi1-depotdate").val())){ 
		alert("Bitte geben sie ein gültiges Datumsformat an tt-mm-jjjj");
	}else{
		document.fe_users_form.submit();
	}
}


function validateDate( strValue ) {
	/************************************************
	DESCRIPTION: Validates that a string contains only 
	    valid dates with 2 digit month, 2 digit day, 
	    4 digit year. Date separator can be ., -, or /.
	    Uses combination of regular expressions and 
	    string parsing to validate date.
	    Ex. dd-mm-yyyy
	    
	PARAMETERS:
	   strValue - String to be tested for validity
	   
	RETURNS:
	   True if valid, otherwise false.
	   
	REMARKS:
	   Avoids some of the limitations of the Date.parse()
	   method such as the date separator character.
	*************************************************/
	  var objRegExp = /^\d{1,2}(\-)\d{1,2}\1\d{4}$/
	 
	  //check to see if in correct format
	  if(!objRegExp.test(strValue))
	    return false; //doesn't match pattern, bad date
	  else{
	    var strSeparator = strValue.substring(2,3) //find date separator
	    var arrayDate = strValue.split(strSeparator); //split date into month, day, year
	    //create a lookup for months not equal to Feb.
	    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
	                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
	    var intDay = parseInt(arrayDate[0],10); 

	    //check if month value and day value agree
	    if(arrayLookup[arrayDate[1]] != null) {
	      if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
	        return true; //found in lookup table, good date
	    }
	    
	    //check for February (bugfix 20050322)
	    //bugfix  for parseInt kevin
	    //bugfix  biss year  O.Jp Voutat
	    var intMonth = parseInt(arrayDate[1],10);
	    if (intMonth == 2) { 
	       var intYear = parseInt(arrayDate[2]);
	       if (intDay > 0 && intDay < 29) {
	           return true;
	       }
	       else if (intDay == 29) {
	         if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
	             (intYear % 400 == 0)) {
	              // year div by 4 and ((not div by 100) or div by 400) ->ok
	             return true;
	         }   
	       }
	    }
	  }  
	  return false; //any other values, bad date
	}
