<!--


// Browser checks 
var ie = (document.all && document.getElementById) ? true:false;
var ie5 = navigator.appVersion.indexOf("MSIE 5")!=-1 ? true:false;
var firefox = navigator.userAgent.toLowerCase().match(/firefox/) != null ? true:false;
var opera = window.opera ? true : false;

function popupCalendar(field)
{
	var popupCalendar = window.open('calendar.html' , 'popUpCalender', 'menubar=no, status=no, toolbar=no, width=180,height=140,left=500,top=100,resizable=no,scrollbars=no');
	popupCalendar.focus();
}

// Example: f&uuml;r Menue
// simplePreload( '01', '02' ); .gif und _s, _r, _d wird automatisch angeh&auml;ngt
function simplePreload()
{ 
	 var args = simplePreload.arguments;
	 document.imageArray = new Array(args.length);
	 for(var i=0; i<args.length; i++)
	 {
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i] + ".gif";
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i]+ "_r.gif";
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i]+ "_s.gif";
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i]+ "_d.gif";
	 }
}
	
simplePreload( 'ADHS', 'Behandlung' ); 	

function toggleSubNavigation(layer)
{
	var level = layer.substring(3,4);
	
	if(document.getElementById("main" + level).className=="active")
	{
		document.getElementById("main" + level).className=""; 
	}
	else 
	{
		document.getElementById("main" + level).className="active"; 
	}
	activateMenuItem();
}


function toggleLayer(showLayer, hideLayer)
{
	if(hideLayer && hideLayer.length != 0 && document.getElementById(hideLayer)) { document.getElementById(hideLayer).style.display = "none"; }
	if(showLayer && showLayer.length != 0 && document.getElementById(showLayer)) { document.getElementById(showLayer).style.display = "block"; }
}


//======== VALIDATION ===================================================================================================================
//array used to store elements that neeed form validation
var validationElements = new Array();
//first element of array; used as counter
var validationElementsCounter=0;

//general message used to notify user of the fact the form is incorrect
var globalFormValidationMessage = "Das Formular ist nicht vollständig ausgefüllt. Bitte versuchen Sie es nochmal.";

//used to trim spaces around string
function trim (str)
{
	return str.replace( /^\s+/g,'').replace(/\s+$/g,'') 
}


//fills array validationElements with objects of type validationElement
function addFieldValidation(elementId, validationElementId, elementType, sortOfValidation, validationDependsElementId, validationDependsElementType, validationDependsElementValue)
{
	validationElements[validationElementsCounter] = new validationElement(elementId, validationElementId, elementType, sortOfValidation, validationDependsElementId,  validationDependsElementType, validationDependsElementValue); 
	validationElementsCounter++;
}


var submitButton;
//adds validation to form
function addFormValidation(buttonId)
{
	submitButton = document.getElementById(buttonId);
	submitButton.onclick = function() { return validateForm(); };
	submitButton.onkeypress = function() { return validateForm(); };
}

//generic field validation checker
function fieldIsValid(e)
{
	var element = document.getElementById(e.ElementId); 
	//required fields
	
	//alert(e.SortOfValidation);
	if(e.SortOfValidation.indexOf("required") != -1 && e.ValidationDependsElementId.length==0)
	{
		if (trim(element.value).length==0) { return false; }
		else 
		{
			//email check
			if(e.SortOfValidation=="requiredEmail")
			{
				if(isValidEmail(element.value)) { return true; }
				else { return false; }
			}			
			else { return true;}
		}
	}	
	//required fields with dependancy
	if(e.SortOfValidation.indexOf("required") != -1 && e.ValidationDependsElementId.length!=0)
	{
		//dependent field is a radiobutton
		if(e.ValidationDependsElementType=="radiobutton")
		{
			if(document.getElementById(e.ValidationDependsElementId).checked) //if checked
			{
				if(e.SortOfValidation=="required")	
				{
					if (trim(element.value).length==0) { return false; }	
					else { return true; }	
				}
				else if(e.SortOfValidation=="requiredCreditcard")
				{
					if (isValidCreditcard(element.value)) { return true; }
					else { return false; }
				}
				else if(e.SortOfValidation=="requiredCreditcardDate")
				{
					if(element.value.length==6) { return true; }
					else { return false; }
				}			
			}	
			else { return true; }				
		}
		//dependent field is a select or a text field
		else
		{ 
			if(document.getElementById(e.ValidationDependsElementId).value==e.ValidationDependsElementValue)
			{
				if (trim(element.value).length==0) { return false; }
				else { return true;}
			}	
			else { return true; }			
		}
		
	}
	//identical fields
	if(e.SortOfValidation.indexOf("identical") != -1 && e.ValidationDependsElementId.length!=0)
	{
		if(element.value==document.getElementById(e.ValidationDependsElementId).value) { return true; }
		else 
		{ 
			return false; 
		}
	}
}


function toggleBundesland()
{
	var land = document.getElementById("Land");
	
	if( land.value=="Deutschland")
	{ 
		if(opera) { document.getElementById("RowBundesland").style.display="block !important"; }
		else { document.getElementById("RowBundesland").style.display="block"; }
	}
	else { document.getElementById("RowBundesland").style.display="none"; }
}

//checks if email is correct
function isValidEmail(email)
{
	var at="@";
	var dot=".";
	var lat=email.indexOf(at);
	var lstr=email.length;
	var ldot=email.indexOf(dot);
	if (email.indexOf(at)==-1) { return false;}
	if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr){ return false; }
	if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr){  return false; }
	if (email.indexOf(at,(lat+1))!=-1){ return false;}
	if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot){ return false;}
	if (email.indexOf(dot,(lat+2))==-1){ return false;}
	if (email.indexOf(" ")!=-1){ return false;}
	
	return true;
}

// Credit Card Validation Javascript
// copyright 12th May 2003, by Stephen Chapman, Felgall Pty Ltd
// http://javascript.about.com/library/blccard.htm
function isValidCreditcard(creditcard)
{
	// remove non-numerics
	var v = "0123456789";
	var w = "";
	for (i=0; i < creditcard.length; i++) 
	{
		x = creditcard.charAt(i);
		if (v.indexOf(x,0) != -1) { w += x; }
	}
	// validate number
	j = w.length / 2;
	if (j < 6.5 || j > 8 || j == 7) { return false; }
	k = Math.floor(j);
	m = Math.ceil(j) - k;
	c = 0;
	
	for (i=0; i<k; i++) 
	{
		a = w.charAt(i*2+m) * 2;
		c += a > 9 ? Math.floor(a/10 + a%10) : a;
	}
	for (i=0; i<k+m; i++) 
	{
		c += w.charAt(i*2+1-m) * 1;
	}
	return (c%10 == 0);
}

//validationElement object, used to store an element that needs validation
function validationElement(elementId, validationElementId, elementType, sortOfValidation, validationDependsElementId,  validationDependsElementType, validationDependsElementValue)
{
	this.ElementId = elementId;
	this.ValidationElementId = validationElementId; 
	this.ElementType = elementType;
	this.SortOfValidation = sortOfValidation;
	this.ValidationDependsElementId = validationDependsElementId; 
	this.ValidationDependsElementType = validationDependsElementType; 
	this.ValidationDependsElementValue= validationDependsElementValue; 	
}

//validates form according to objects of validationElement type in array validationElements
function validateForm()
{
	var result=true;
	
	for(var i=0; i<validationElements.length; i++)
	{
		//alert(validationElements[i].ValidationElementId);
		document.getElementById(validationElements[i].ValidationElementId).style.display="none"; 
		
		//alert(validationElements[i].ElementId);
		if(!fieldIsValid(validationElements[i])) 
		{
			document.getElementById(validationElements[i].ValidationElementId).style.display="block";
			result= false;
		}	
	}	
	if(!result) { alert(globalFormValidationMessage); }
	//else { submitButton.disabled = true; }
	return result;	
}



//======== END VALIDATION ===================================================================================================================
-->
