// On Document Ready Functions
// -----------------------------------------------------
$(document).ready(function()
{


			// Zoeken Select Functions IE
			if($.browser.msie && ( $.browser.version=="7.0" || $.browser.version=="8.0" ) && $('#zoekeenreis').length ) changeSelect();


	// 	Set Flash Replacement Functions onDOMLoad
	// 	-----------------------------------------------------

	// 	HeaderPhoto
	// 	-----------------------------------------------------
			swfobject.addDomLoadEvent(loadHeaderPhoto);	// Set Page HeaderPhotos (Flash Slideshow)

	// 	PhotoBox Right Column
	// 	Check for bImages - if var is found, show the photobox
	// 	And only on pages where it should be placed ( class 'area-information')
	// 	-----------------------------------------------------
			var bImages = ( isSet( top.bImages ) ) ? top.bImages : "";
			if( $('.area-information').length > 0 && bImages != "" ) swfobject.addDomLoadEvent(loadPhotoBox);

	// 	PhotoBox Home
	// 	-----------------------------------------------------
			/*
			if( $('.home-photo-comp').length > 0 ) {
				swfobject.addDomLoadEvent(loadPhotoBoxHome);
			}
			*/

    //  Activate adresxpress functionality
	// 	-----------------------------------------------------
	var postcode = document.getElementById( 'postcode' );
    var huisnummer = document.getElementById( 'huisnummer' );

    if( postcode && huisnummer )
    {
        postcode.onkeyup = huisnummer.onkeyup = function(){
            refreshAddressForm();
        }
    }


});



// Zoeken Select Functions IE
// -----------------------------------------------------
function changeSelect(){

	// Set some additional styles for IE
	$('#zoekeenreis p').css('position','relative');
	$('#zoekeenreis select').css('position','absolute');

	// Set P width the same as it's child select-element
	$('#zoekeenreis p').each( function(){
		$(this).css('width', $(this).children('select').css("width") );
	});

  // Bind IE focus functions to keep the single click
	// Change the width to accomodate the options-value-length
  $('#zoekeenreis select').bind('focusin', function() {
      $(this).addClass('focus');
			$(this).data("origWidth", $(this).css("width")).css("width", "auto");
			$(this).css('z-index', '2000');
			return true;
  }).bind('focusout', function() {
      $(this).removeClass('focus');
    	$(this).css("width", $(this).data("origWidth"));
			$(this).css('z-index', '500');
			return true;
  }).change( function() {
      $(this).removeClass('focus');
    	$(this).css("width", $(this).data("origWidth"));
			$(this).css('z-index', '500');
			return true;
  });

};


// Check Variable
// -----------------------------------------------------
function isSet( variable )
{
	return( typeof( variable ) != 'undefined' );
};


// =====================================================
// Flash Movie Functions
// =====================================================

// Custom Flash Embed function
// -----------------------------------------------------
swfobject.customEmbed = function (swfLoc, id, w, h, version, color, vars){
   if (swfobject.hasFlashPlayerVersion(version)){
      var so = swfobject.createSWF({data:swfLoc,width:w,height:h}, {flashvars:"sImages=" + vars, wmode:"transparent",bgColor:color},id);
      if(so){ return true; }
   }
   return false;
}

// Load Flash Header Photo
// -----------------------------------------------------
function loadHeaderPhoto(){
	var tImages = ( isSet( top.tImages ) ) ? top.tImages : "";
	if( tImages != "" ) var success = swfobject.customEmbed("/swf/headerphotos.swf", "headerphoto", "715", "270", "8", "#FFFFFF", tImages);
  if(!success){
     document.getElementById("headerphoto").innerHTML = '<img src="/img/img_fallback_header.gif" width="683" height="268" border="0" alt="">';
  }
}

// Load Flash Product PhotoBox Home
// -----------------------------------------------------
function loadPhotoBoxHome(){
	var success = swfobject.customEmbed("/swf/photobox_home.swf", "photobox", "585", "375", "8", "#FFFFFF");
   if(!success){
			$('#photobox .content').css('display','block');
   }
}

// Load Flash PhotoBox Right Column (2 photo set)
// -----------------------------------------------------
function loadPhotoBox(){
	$('.area-information').prepend('<div id="photobox"></div>');
	var bImages = ( isSet( top.bImages ) ) ? top.bImages : "";
	var success = swfobject.customEmbed("/swf/photobox_info.swf", "photobox", "380", "170", "8", "#FFFFFF", bImages);
  if(!success){
     $('#photobox').remove();
  }
}



// Toggle SearchBox
// -----------------------------------------------------
function toggleSearch( sVar )
{
	var es = $("#search-trigger");
	var el = $("#search-unfolded");

	if( sVar ){
		el.slideToggle('fast', function(){ es.slideToggle(); });
	} else {
		es.slideToggle('fast', function(){ el.slideToggle(); });
	}
};


// Set Page Header (H1,H2) Backgrounds
// -----------------------------------------------------
function setHeaderBG()
{
	var imgH2 = ( isSet( top.imgH2 ) ) ? top.imgH2 : '';
	var imgH3 = ( isSet( top.imgH3 ) ) ? top.imgH3 : '';
	var imgH4 = ( isSet( top.imgH4 ) ) ? top.imgH4 : '';

	// Set H2 params
	var objH2 = $(".main .page-titles h2");
	if(objH2) objH2.css('background', 'url(/files/headers/'+ imgH2 +') 0 0 no-repeat' );

	// Set H3 params
	var objH3 = $(".main .page-titles h3");
	if(objH3) objH3.css('background', 'url(/files/headers/'+ imgH3 +') 0 0 no-repeat' );

	// Set H4 params
	var objH4 = $(".main .page-titles h4");
	if(objH4) objH4.css('background-image', 'url(/files/headers/'+ imgH4 +') 0 0 no-repeat' );
};


// BOOKINGS
// =====================================================

// Booking - Boeking of Prijsindicatie
// -----------------------------------------------------
function submitStartBooking( isPrijsIndicatie ){
	$('#refresh').attr('value', 'false');
	$('#prijsIndicatie').attr('value', isPrijsIndicatie);

	//$('#boekenReis').submit();

	// IE6 can see this function, it can alert values and change values and alert the new values
	// But it won't submit the form [after those values have changed]
	// This little timeout helps IE6 in some way and the form submits succesfully
	setTimeout(" $('#boekenReis').submit(); ", 500);
};


// Edit Deelnemers
// -----------------------------------------------------
function gotoNewWebdeelnemer()
{
	$('#subaction').attr('value', 'new');
	$('#boekenReis').submit();
};

function gotoEditWebdeelnemer( pid )
{
	$('#subaction').attr('value', 'edit');
	$('#argument').attr('value', pid);
	$('#boekenReis').submit();
};

function gotoRemoveWebdeelnemer( pid )
{
	if( confirm( 'Weet u zeker dat u deze persoon wilt verwijderen?\n\nDeze gegevens gaan hiermee definitief verloren!\n ' ) )
	{
		$('#subaction').attr('value', 'remove');
		$('#argument').attr('value', pid);
		$('#boekenReis').submit();
	}
};




function toggleGeneralLoginForm( type ){

	var sLoginForm = document.getElementById( 'inloggen' );
	var sLogin = $('#divGeneralLogin');
	var sForgot = $('#divGeneralForgotPassword');
	var sIntroForgot = $('#divGeneralIntroForgotPassword');
	var sQuestionLogin = $('#questionLogin');
	var sQuestionForgot = $('#questionPassword');

	sLoginForm.type.value = type;
	sLogin.toggle();
	sQuestionLogin.toggle();
	sForgot.toggle();
	sIntroForgot.toggle();
	sQuestionForgot.toggle();


};

/* search form functionality */

var submitting = false;

function showAvailableTips( product )
{
	if( !submitting )
	{
		try
		{
			submitting = true;
			var rpcAction = document.getElementById( 'rpcAction' );
			var baseURI = document.getElementById( 'baseURI' );

			/*
			if( reissoort.selectedIndex !=0 && land.selectedIndex != 0 && bestemming.selectedIndex != 0 )
			{
				return true;
			}
			else
			{
			*/
				var params = [
					'type=rpcAvailableTipSearch',
					'baseURI=' + baseURI.value,
					'product=' + product
				]
				myLightbox.params = params.join( '&' );
				//alert( myLightbox.params );
				myLightbox.responseType = 'text';
				myLightbox.start( rpcAction.value );
				return false;
			//}
		}
		catch( failed )
		{
			submitting = false;
			if( document.debug )
			{
				alert( failed );
				return false;
			}
			else
			{
				return true;
			}
		}
	}
	else
	{
		alert( 'Een ogenblik geduld a.u.b. Uw zoekopdracht wordt verwerkt' );
		return false;
	}
};

function refreshAddressForm()
{
	try
	{
		var url = '/adresxpress/getadres.php';
		var postcode = document.getElementById( 'postcode' );
		var huisnummer = document.getElementById( 'huisnummer' );

        if( postcode.value != '' && huisnummer.value != '' )
        {
            var params = [
                'postcode=' + postcode.value,
                'huisnummer=' + huisnummer.value
            ]
            var ajaxRequest = new RealAjax();
            ajaxRequest.url = url;
            ajaxRequest.params = params.join( '&' );
            //alert( ajaxRequest.params );
            ajaxRequest.callbackObj = document;
            ajaxRequest.callback = populateAddressForm;
            ajaxRequest.responseType = '';
            ajaxRequest.send();
		}
		return true;

	}
	catch( failed )
	{
		if( document.debug )
		{
			alert( failed );
			return false;
		}
		else
		{
			return true;
		}
	}
};

function populateAddressForm( ajaxResult )
{
	try
	{
		var postcode = document.getElementById( 'postcode' );
		var huisnummer = document.getElementById( 'huisnummer' );
		var straatnaam = document.getElementById( 'straatnaam' );
		var woonplaats = document.getElementById( 'woonplaats' );

		var xmlResult = ajaxResult.responseXML;

		if( postcode )
		{
		    postcode.value = xmlResult.getElementsByTagName( 'postcode' )[0] ? xmlResult.getElementsByTagName( 'postcode' )[0].childNodes[0].nodeValue : postcode.value;
		}
		if( huisnummer )
		{
		    huisnummer.value = xmlResult.getElementsByTagName( 'huisnummer' )[0] ? xmlResult.getElementsByTagName( 'huisnummer' )[0].childNodes[0].nodeValue : huisnummer.value;
		}
		if( straatnaam )
		{
		    straatnaam.value = xmlResult.getElementsByTagName( 'straatnaam' )[0] ? xmlResult.getElementsByTagName( 'straatnaam' )[0].childNodes[0].nodeValue : straatnaam.value;
		}
		if( woonplaats )
		{
		    woonplaats.value = xmlResult.getElementsByTagName( 'woonplaats' )[0] ? xmlResult.getElementsByTagName( 'woonplaats' )[0].childNodes[0].nodeValue : woonplaats.value;
		}

	}
	catch( failed )
	{
		if( document.debug )
		{
			alert( failed );
			return false;
		}
		else
		{
			return true;
		}
	}
};

function refreshSearchForm( obj )
{
	try
	{
		var formId = obj.form.id;
		var rpcAction = document.getElementById( 'rpcAction' );
		var product = formId == 'searchReisRefine' ? document.getElementById( 'productRefine' ) : document.getElementById( 'product' );
		var reissoort = formId == 'searchReisRefine' ? document.getElementById( 'reissoortRefine' ) : document.getElementById( 'reissoort' );
		var land = formId == 'searchReisRefine' ? document.getElementById( 'landRefine' ) : document.getElementById( 'land' );
		var bestemming = formId == 'searchReisRefine' ? document.getElementById( 'bestemmingRefine' ) : document.getElementById( 'bestemming' );
		var leeftijdscategorie = formId == 'searchReisRefine' ? document.getElementById( 'leeftijdscategorieRefine' ) : document.getElementById( 'leeftijdscategorie' );
		var datumVan = formId == 'searchReisRefine' ? document.getElementById( 'datumVanRefine' ) : document.getElementById( 'datumVan' );

		var searchFormOrder = new Array( product, reissoort, land, bestemming, leeftijdscategorie, datumVan );

		for( var i = 0, found = false; i < searchFormOrder.length; i++ )
		{
			if( obj == searchFormOrder[ i ] )
			{
				found = true;
			}
			else if( found )
			{
				searchFormOrder[ i ].selectedIndex = 0;
			}
		}

		var params = [
			'type=rpcRefreshSearchForm',
			'product=' + ( ( product.type == 'select-one' ) ? product.options[ product.selectedIndex ].value : product.value ),
			'reissoort=' + reissoort.options[ reissoort.selectedIndex ].value,
			'land=' + land.options[ land.selectedIndex ].value,
			'bestemming=' + bestemming.options[ bestemming.selectedIndex ].value,
			'leeftijdscategorie=' + ( ( leeftijdscategorie.type == 'select-one' ) ? leeftijdscategorie.options[ leeftijdscategorie.selectedIndex ].value : leeftijdscategorie.value ),
			'datumVan=' + datumVan.options[ datumVan.selectedIndex ].value
		]
		var ajaxRequest = new RealAjax();
		ajaxRequest.url = rpcAction.value;
		ajaxRequest.params = params.join( '&' );
		//alert( ajaxRequest.params );
		ajaxRequest.callbackObj = document;
		ajaxRequest.callback = populateSearchForm;
		ajaxRequest.responseType = '';
		ajaxRequest.send();
		return true;

	}
	catch( failed )
	{
		if( document.debug )
		{
			alert( failed );
			return false;
		}
		else
		{
			return true;
		}
	}
};

function populateSearchForm( ajaxResult )
{
	try
	{
		var baseURI = document.getElementById( 'baseURI' );
		var product = document.getElementById( 'product' );
		var reissoort = document.getElementById( 'reissoort' );
		var land = document.getElementById( 'land' );
		var bestemming = document.getElementById( 'bestemming' );
		var leeftijdscategorie = document.getElementById( 'leeftijdscategorie' );
		var datumVan = document.getElementById( 'datumVan' );
		var productRefine = document.getElementById( 'productRefine' );
		var reissoortRefine = document.getElementById( 'reissoortRefine' );
		var landRefine = document.getElementById( 'landRefine' );
		var bestemmingRefine = document.getElementById( 'bestemmingRefine' );
		var leeftijdscategorieRefine = document.getElementById( 'leeftijdscategorieRefine' );
		var datumVanRefine = document.getElementById( 'datumVanRefine' );

		var xmlResult = ajaxResult.responseXML;
		var optionsProduct = xmlResult.getElementsByTagName( 'product' );
		var optionsReissoort = xmlResult.getElementsByTagName( 'reissoort' );
		var optionsLand = xmlResult.getElementsByTagName( 'land' );
		var optionsBestemming = xmlResult.getElementsByTagName( 'bestemming' );
		var optionsLeeftijdscategorie = xmlResult.getElementsByTagName( 'leeftijdscategorie' );
		var optionsDatumVan = xmlResult.getElementsByTagName( 'datumVan' );

		/*
		if( product.type == 'select-one' )
		{
			populateSelectFromXML( product, optionsProduct );
		}
		*/

		if( reissoort.type == 'select-one' )
		{
			populateSelectFromXML( reissoort, optionsReissoort );
		}
		if( land.type == 'select-one' )
		{
			populateSelectFromXML( land, optionsLand );
		}
		if( bestemming.type == 'select-one' )
		{
			populateSelectFromXML( bestemming, optionsBestemming );
		}
		if( leeftijdscategorie.type == 'select-one' )
		{
			populateSelectFromXML( leeftijdscategorie, optionsLeeftijdscategorie );
		}
		if( datumVan.type == 'select-one' )
		{
			populateSelectFromXML( datumVan, optionsDatumVan );
		}

		if( reissoortRefine && reissoortRefine.type == 'select-one' )
		{
			populateSelectFromXML( reissoortRefine, optionsReissoort );
		}
		if( landRefine && landRefine.type == 'select-one' )
		{
			populateSelectFromXML( landRefine, optionsLand );
		}
		if( bestemmingRefine && bestemmingRefine.type == 'select-one' )
		{
			populateSelectFromXML( bestemmingRefine, optionsBestemming );
		}
		if( leeftijdscategorieRefine && leeftijdscategorieRefine.type == 'select-one' )
		{
			populateSelectFromXML( leeftijdscategorieRefine, optionsLeeftijdscategorie );
		}
		if( datumVanRefine && datumVanRefine.type == 'select-one' )
		{
			populateSelectFromXML( datumVanRefine, optionsDatumVan );
		}
	}
	catch( failed )
	{
		if( document.debug )
		{
			alert( failed );
			return false;
		}
		else
		{
			return true;
		}
	}
};

function populateSelectFromXML( obj, optionsXML )
{
	try
	{
		obj.options.length = 0;
		if( optionsXML.length > 0 )
		{
			for( var i = 0; i < optionsXML.length; i++ )
			{
				var labelValue = optionsXML[ i ].getAttribute( 'label' );
				var valueValue = optionsXML[ i ].getAttribute( 'value' );
				var defaultSelectedValue = Boolean( parseInt( optionsXML[ i ].getAttribute( 'defaultSelected' ) ) );
				var selectedValue = Boolean( parseInt( optionsXML[ i ].getAttribute( 'selected' ) ) );
				obj.options[ obj.options.length ] = new Option( unescape( labelValue ), unescape( valueValue ), defaultSelectedValue, selectedValue );
			}
			//obj.disabled = ( obj.options.length <= 1 ) ? true : false;
		}
		else
		{
			obj.options[ obj.options.length ] = new Option( 'Geen resultaat', '', true, true );
		}
	}
	catch( failed )
	{
		if( document.debug )
		{
			alert( failed );
			return false;
		}
		else
		{
			return true;
		}
	}
};

function gotoEditWebdeelnemer( pid )
{
	document.getElementById('subaction').value = 'edit';
	document.getElementById('argument').value = pid;
	document.getElementById('boekenReis').submit();
};

function gotoRemoveWebdeelnemer( pid )
{
	if( confirm( 'Weet u zeker dat u deze persoon wilt verwijderen?\n\nDeze gegevens gaan hiermee definitief verloren!\n ' ) )
	{
		document.getElementById('subaction').value = 'remove';
		document.getElementById('argument').value = pid;
		document.getElementById('boekenReis').submit();
	}
};

function gotoNewWebdeelnemer()
{
	document.getElementById('subaction').value = 'new';
	document.getElementById('boekenReis').submit();
};

function showLoginForm()
{
	Element.toggle('loginGeneral');
}

// Show button startBooking
// -----------------------------------------------------
function startBookingProces()
{
	//Element.show('startbooking');
	new Effect.SlideDown('startbooking', { duration: 0.5, from: 0.0, to: 1.0 });
};

function showDates( isPrijsIndicatie )
{
	$('prijsIndicatie').value = isPrijsIndicatie;
	Element.hide('selectdates');
	Element.show('dates');
};

function showLargePhoto( rpcPhotoAction )
{
	try
	{
		var params = [
			'type=rpcPhoto'
		]
		myLightbox.params = params.join( '&' );
		myLightbox.responseType = 'text';
		myLightbox.start( rpcPhotoAction );
		return false;
	}
	catch( failed )
	{
		if( document.debug )
		{
			alert( failed );
			return false;
		}
		else
		{
			return true;
		}
	}
};

function showInfo( rpcInfoAction )
{
	try
	{
		var params = [
			'type=rpcInfo'
		]
		myLightbox.params = params.join( '&' );
		myLightbox.responseType = 'text';
		myLightbox.start( rpcInfoAction );
		return false;
	}
	catch( failed )
	{
		if( document.debug )
		{
			alert( failed );
			return false;
		}
		else
		{
			return true;
		}
	}
};

function showSendtofriendForm( action, url )
{
	if( !submitting )
	{
		try
		{
			submitting = true;
			var params = [
				'type=rpcSendtofriend',
				'url=' + url
			]
			myLightbox.params = params.join( '&' );
			myLightbox.responseType = 'text';
			myLightbox.start( action );
			return false;
		}
		catch( failed )
		{
			submitting = false;
			if( document.debug )
			{
				alert( failed );
				return false;
			}
			else
			{
				return true;
			}
		}
	}
	else
	{
		alert( 'Een ogenblik geduld a.u.b. Het formulier wordt geopend.' );
		return false;
	}
};

function submitSendtofriendForm( action, url )
{
	if( !submitting )
	{
		try
		{
			submitting = true;
			var senderName = document.getElementById( 'senderName' );
			var senderEmail = document.getElementById( 'senderEmail' );
			var recipientName = document.getElementById( 'recipientName' );
			var recipientEmail = document.getElementById( 'recipientEmail' );
			var params = [
				'type=rpcSendtofriend',
				'submit=1',
				'senderName=' + senderName.value,
				'senderEmail=' + senderEmail.value,
				'recipientName=' + recipientName.value,
				'recipientEmail=' + recipientEmail.value,
				'url=' + url
			]
			myLightbox.params = params.join( '&' );
			myLightbox.responseType = 'text';
			myLightbox.start( action );
			return false;
		}
		catch( failed )
		{
			submitting = false;
			if( document.debug )
			{
				alert( failed );
				return false;
			}
			else
			{
				return true;
			}
		}
	}
	else
	{
		alert( 'Een ogenblik geduld a.u.b. Het formulier wordt verzonden.' );
		return false;
	}
};



// 404
// -----------------------------------------------------

function doMail( sPre, sAfter ){
	var sMailPre = ( sPre ) ? sPre : 'info';
	var sMailAfter = ( sAfter ) ? sAfter : 'mambo.nl';
	document.location.href = 'mailto:' + sMailPre + '@' + sMailAfter;
};


// Forms Brochure & Nieuwsbrief, extra refereal
// -----------------------------------------------------
function doFormReferal( formname, inputname ){

	if( !formname || !inputname ) return;

	var sForm = $("#" + formname + '-' + inputname + "").attr('value');
	var sRow = $("#" + formname + '-' + inputname + '-row' + "");
	var sCSS = ( sForm.search('namelijk') != "-1" ) ? '' : 'none';

	sRow.css('display', sCSS );

};

// 404
// -----------------------------------------------------
function showAlert( variable ){

	var sText = "Helaas\nOnze " + variable + " staan nog niet online.\nMedio december 2008 kun je hier weer het reisaanbod vinden voor 2009.";
	alert( sText );
	return false;

};



// Nieuwsbrief Validatie BLINKER.NL
// -----------------------------------------------------
function checkNewsLetterForm(myForm) {
    try {
				var errorDiv = $('#form-error');
				var errorMessage = '<b>Het formulier kon niet worden verzonden om de volgende reden(en):</b><br><br>';
				var errorMessageEnd = 'Vul het formulier aan en probeer het s.v.p nogmaals.<br>';
        var errorFound = false;

        if (myForm.field1038 != null) {
            var anythingChecked = false;
            for (i = 0; i < myForm.field1038.length; i++) {
                if (myForm.field1038[i].checked) anythingChecked = true;
            }

            if (!anythingChecked) {
                errorMessage = errorMessage + '- Geen keuze gemaakt voor Geslacht.<br>';
                errorFound = true;
            }
        }

        if (myForm.field1040 != null) {
            if (myForm.field1040.value == '') {
                errorMessage = errorMessage + '- Geen waarde ingevuld voor Achternaam.<br>';
                errorFound = true;
            }
        }

        if (myForm.field1041 != null) {
            if (myForm.field1041.value == '') {
                errorMessage = errorMessage + '- Geen waarde ingevuld voor E-mailadres.<br>';
                errorFound = true;
            } else {
                emailAddress = myForm.field1041.value;
                if (emailAddress.search(/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&''*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i) == -1) {
                    errorMessage = errorMessage + '- Ongeldig waarde ingevuld voor E-mailadres.<br>';
                    errorFound = true;
                }
            }
        }

        if (myForm.field1048 != null) {
            if (myForm.field1048.value == '') {} else {
                date = myForm.field1048.value;
                day = date.substr(0, 2);
                month = date.substr(3, 2);
                year = date.substr(6, 4);
                foundday = day.search(/^[0-3]{1}[0-9]{0,1}$/);
                foundmonth = month.search(/^[0-1]{1}[0-9]{0,1}$/);
                foundyear = year.search(/^[0-9]{4}$/);

                if ((foundday == -1) || (foundyear == -1) || (foundmonth == -1)) {
                    errorMessage = errorMessage + '- Ongeldige datum ingevuld voor Geboorte datum.<br>';
                    errorFound = true;
                }
            }
        }

        var field1046Value = 0;

        for (i = 0; i < 5; i++) {
            if (document.getElementById('field1046_' + i).checked) {
                var bitValue = parseInt(document.getElementById('field1046_' + i).value);
                field1046Value |= bitValue
            }
        }

        document.getElementById('field1046').value = field1046Value;

			if (errorFound) {
				errorDiv.html( errorMessage + '<br>' + errorMessageEnd).css('display','block' );
				return false;
			}

        return true;
    } catch (err) {
        return false;
    }
   };
