﻿var check_array = new Array();

/**
 * checks if all required fields are filled.
 *
 * params: [iForm (form number), sCheck ("all", "one") aFields (required fields array)]
 */
function check_required ()
	{
	if ( check_required.arguments.length >= 2 )
		{
		iForm = check_required.arguments[0];
		sCheck = check_required.arguments[1]; 
		}
	else
		{
		iForm = 0;
		sCheck = "all";
		}
		
	if ( check_required.arguments.length >= 3 )
		{
		check_array = check_required.arguments[2];
		}
	
	if ( sCheck == "all" )
		{
		
		for( i = 0; i < check_array.length; i++ )
			{
			bselectfeld=false;
			if(document.forms[iForm].elements[check_array[i][0]].type == "select-one")
				{
				if(document.forms[iForm].elements[check_array[i][0]].options.selectedIndex == 0)
					{
					bselectfeld=true;
					}
				}
			
			if( document.forms[iForm].elements[check_array[i][0]].type == "checkbox" && !document.forms[iForm].elements[check_array[i][0]].checked )
				{
				alert( "Bitte geben Sie fuer \n\n"+check_array[i][1]+"\n\neinen gueltigen Wert ein." );
				
				document.forms[iForm].elements[check_array[i][0]].focus();
				
				return false;				
				}
			
			if( document.forms[iForm].elements[check_array[i][0]].value == "" || bselectfeld)
				{
				
				alert( "Bitte geben Sie fuer \n\n"+check_array[i][1]+"\n\neinen gueltigen Wert ein." );
				
				document.forms[iForm].elements[check_array[i][0]].focus();
				
				return false;
				
				}
			
			}
		
		}
	else if ( sCheck == "one" )
		{
		sMesg = "Bitte geben Sie fuer \n\n";
		for ( i = 0; i < check_array.length; i++ )
			{
			sMesg += check_array[i][1];
			if ( i == check_array.length - 2 )
				sMesg += " oder";
			else if ( i != check_array.length - 1 )
				sMesg +=  ",";
			sMesg += "\n";
			if( document.forms[iForm].elements[check_array[i][0]].value != "" )
				{
				
				return true;
				}
			}
		alert( sMesg +"\neinen gueltigen Wert ein." );
		document.forms[iForm].elements[check_array[0][0]].focus();
		return false;
		}

	return true;
	}

/**
 * simple check if the given string is a correct email address.
 */
function check_email( sEMail, sName )
	{
	if ( check_email.arguments.length > 2 )
		{
		iForm = check_email.arguments[2];
		}
	else
		{
		iForm = 0;
		}

	if ( sEMail.length == 0 )
		return true;

	if ( sEMail.indexOf("@") == -1 ||
			sEMail.indexOf(".") == -1 ||
			sEMail.indexOf(">") > -1 ||
			sEMail.indexOf("<") > -1 ||
			sEMail.indexOf(" ") > -1 )
		{		

		alert("'" + sEMail + "' ist keine korrekte eMail-Adresse.");

		document.forms[iForm].elements[sName].focus();

		return  false;
		}

   return true;
   }


/**
 * compares the number of checked check- and radioboxes with
 * the given num.
 */
function check_count (sHow, iNum)
	{
	if ( check_count.arguments.length > 2 )
		{
		iForm = check_count.arguments[2];
		}
	else
		{
		iForm = 0;
		}

	iCount = 0;
	for ( i = 0; i < document.forms[iForm].elements.length; i++ )
		{
		if ( document.forms[iForm].elements[i].type == "checkbox" || document.forms[iForm].elements[i].type == "radio" )
			{
			if ( document.forms[iForm].elements[i].checked )
				iCount++;
			}
		}

	if ( sHow == "exact" )
		{
		bRet = iCount == iNum;
		if ( !bRet ) sMesg = "Bitte " + ((iCount > iNum) ? "nur ": "") + iNum + " Element" + ((iNum > 1) ? "e" : "") + " wählen.";
		}
	else if ( sHow == "min" )
		{
		bRet = iCount >= iNum;
		if ( !bRet ) sMesg = "Sie müssen mindestens " + iNum + " Element" + ((iNum > 1) ? "e" : "") + " wählen.";
		}
	else if ( sHow == "max" )
		{
		bRet = iCount <= iNum;
		if ( !bRet )
			{
			if ( iNum == 0 )
				sMesg = "Sie dürfen kein Element wählen.";
			else
				sMesg = "Sie dürfen höchstens " + iNum + " Element" + (iNum > 1) ? "e" : "" + " wählen.";
			}
		}

	if ( !bRet ) alert (sMesg);
	
	return bRet;
	}



function set_hotel_date(iVID)
		{
		
		nohotel=false;	
		onehotel=false;	
		twohotel=false;	
		
		// wenn keine uebernachtung vorgesehen ist
		if( document.list['CategoryID[' + iVID + ']'].value == 1434 ||
			document.list['CategoryID[' + iVID + ']'].value == 1435 ||
			document.list['CategoryID[' + iVID + ']'].value == 1436 ||
			document.list['CategoryID[' + iVID + ']'].value == 1442 ||
			document.list['CategoryID[' + iVID + ']'].value == 1444 ||
			document.list['CategoryID[' + iVID + ']'].value == 1445 ||
			document.list['CategoryID[' + iVID + ']'].value == 1447 ||
			document.list['CategoryID[' + iVID + ']'].value == 1448 ||
			document.list['CategoryID[' + iVID + ']'].value == 1449
			 )
			
			nohotel=true;	
			;			

		// wenn eine uebernachtung vorgesehen ist
		if( document.list['CategoryID[' + iVID + ']'].value == 1430 ||
			document.list['CategoryID[' + iVID + ']'].value == 1431 ||
			document.list['CategoryID[' + iVID + ']'].value == 1437 ||
			document.list['CategoryID[' + iVID + ']'].value == 1440 ||
			document.list['CategoryID[' + iVID + ']'].value == 1441 ||
			document.list['CategoryID[' + iVID + ']'].value == 1443 ||
			document.list['CategoryID[' + iVID + ']'].value == 1447 ||
			document.list['CategoryID[' + iVID + ']'].value == 1446
			 )
			
			onehotel=true;
			;			
		
		// wenn zwei uebernachtungen vorgesehen ist
		if( document.list['CategoryID[' + iVID + ']'].value == 1432 ||
			document.list['CategoryID[' + iVID + ']'].value == 1433 ||
			document.list['CategoryID[' + iVID + ']'].value == 1438 ||
			document.list['CategoryID[' + iVID + ']'].value == 1439 )
						
			twohotel=true;
			;
		
		if(nohotel)
			{
			document.list['UENvon[' + iVID + '][Date_Day]' ].options.selectedIndex = 2;
			document.list['UENbis[' + iVID + '][Date_Day]' ].options.selectedIndex = 2;
			}
		if(onehotel)
			{
			document.list['UENvon[' + iVID + '][Date_Day]' ].options.selectedIndex = 2;
			document.list['UENbis[' + iVID + '][Date_Day]' ].options.selectedIndex = 3;
			}
		if(twohotel)
			{
			document.list['UENvon[' + iVID + '][Date_Day]' ].options.selectedIndex = 1;
			document.list['UENbis[' + iVID + '][Date_Day]' ].options.selectedIndex = 3;
			}
		
		 
		}

