// Globalsvar ValidationFailed;var PicklistOk;var ValidationFailedFieldnames;var formObject;var DBNameHTML_C = getRelativeDatabaseName();function doOnLoad( ){    if( window.doCustomOnLoad )        doCustomOnLoad( );    doHideWhens( );}function doDoubleClick( ){    if( window.doCustomDoubleClick )        doCustomDoubleClick( );}function doHideWhens( ){    // Call subform-specific hide-whens    doSubformHideWhens( );    // If available, do custom hide-whens    if( window.doCustomHideWhens )        doCustomHideWhens( );}// Ophalen database name (tot en met .nsf en slash), maar zonder host gedeelte// Server redirects (tussen dubbele vierkante haken) werken alleen met relatieve url'sfunction getRelativeDatabaseName() {    var currentUrl = new String( window.location.pathname );    var urlArray  = currentUrl.split('.nsf' );    return urlArray[0] + '.nsf/';} // getDatabaseName()function writeHelp( sHelpText, sHTML ){    /*		Write an help-icon that displays a pop-up text when mouse-overed		sHelpText		the text that will be displayed when mouseovered		sHTML			HTML code that the user can mouseover; if left empty, an 'Info' icon will be shown	*/    if( (! sHTML ) || sHTML == "" )    {        sHTML = '<IMG src="' + DBNameHTML_C + '/Info%20Icon%20transparant%2016x16.gif!OpenImageResource" width="16" height="16" alt="" style="margin-left: 10px; margin-top: 2px; margin-bottom: 2px;">'    }    document.write( '<SPAN onmouseover="return overlib(unescape(\'' + sHelpText + '\'), STICKY, MOUSEOFF);" onmouseout="return nd();">' );    document.write( sHTML );    document.write( '</SPAN>' );} // writeHelp()function checkTextField( fieldObject, fieldMessage, checkString, properCase )// Validates if the given fieldObject is the same as checkString (this will be the empty string, mostly).// If this is the case, the ValidationFailed counter is increased and the fieldMessage is added// to the error outputstring. Optional: if properCase is true, the field value will be converted to Proper case.{    if ( fieldObject ) {        if ( fieldObject.value == checkString )        {            ValidationFailed++;            ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + fieldMessage + "\n"        } else {            if (properCase )            {                fieldObjectValue = fieldObject.value;                if ( fieldObjectValue.substring(0,1) != fieldObjectValue.substring(0,1).toUpperCase() )                {                    fieldObject.value = fieldObjectValue.substring(0,1).toUpperCase() + fieldObjectValue.substring(1, fieldObjectValue.length).toLowerCase();                }            }        }    }}function checkRadioButton( fieldObject, fieldMessage )// Validates if the given fieldObject has a checked Radio Button;// if this is not the case, the ValidationFailed counter is increased and the fieldMessage is added// to the error outputstring.{    if( fieldObject )    {        subValidationFailed = true;        for (var i = 0; i < fieldObject.length; i++)        {            if ( fieldObject[i].checked )            {                subValidationFailed = false;            }        }        if ( subValidationFailed  )        {            ValidationFailed++;            ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + fieldMessage + "\n"        }    }}function checkSingleValuePicklist( fieldObject, fieldMessage, checkString )// Validates if the given fieldObject has an item selected, other than the checkString;// if this is not the case, the ValidationFailed counter is increased and the fieldMessage is added// to the error outputstring.{    if ( fieldObject )    {        if ( fieldObject.options[fieldObject.selectedIndex].value == checkString )        {            ValidationFailed++;            ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + fieldMessage + "\n"        }    }}function checkMultiValuePicklist( fieldObject, fieldMessage )// Validates if the given fieldObject has an item selected;// if this is not the case, the ValidationFailed counter is increased and the fieldMessage is added// to the error outputstring.{    if ( fieldObject )    {        for( var i = 0; i < fieldObject.length; i++ )        {            if (fieldObject.options[i].selected == true)            {                PicklistOk++            }        }        if ( PicklistOk == 0 )        {            ValidationFailed++;            ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + fieldMessage + "\n"            PicklistOk == 0;        }    }}function checkFieldLength( fieldObject, fieldMessage, fieldLengthMinimum, fieldLengthMaximum )// Validates if the given fieldObject has a minimum length of fieldLengthMinimum, and a maximum length of fieldLengthMaximum;// if it fails to comply with these boundaries, the ValidationFailed counter is increased and the fieldMessage is added// to the error outputstring.// A length of 0 indicates no limit.{    if ( fieldObject )    {        if ( fieldLengthMinimum > 0 )        {            if ( fieldObject.value.length < fieldLengthMinimum )            {                ValidationFailed++;                ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + fieldMessage + "\n"            }        }        if ( fieldLengthMaximum > 0 )        {            if ( fieldObject.value.length > fieldLengthMaximum )            {                ValidationFailed++;                ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + fieldMessage + "\n"            }        }    }}function checkEmail( fieldObject, fieldMessage )// Validates if the given fieldObject contains an @ sign, a period and no spaces;// if it fails to comply, the ValidationFailed counter is increased and the fieldMessage is added to the error outputstring.{    if ( fieldObject )    {        // Set the initial variable to 2, because there are two characters that must be present in the string.        // Each characters that is present decreases the count by one.        fieldObject.value = fieldObject.value.toLowerCase();        var subValidationFailed = 2;        for( var i=0; i < fieldObject.value.length; i++ )        {            if ( fieldObject.value.charAt(i) =="@"  )            {                subValidationFailed--;            }        }        for( var i=0; i < fieldObject.value.length; i++ )        {            if ( fieldObject.value.charAt(i) =="."  )            {                subValidationFailed--;            }        }        for( var i=0; i < fieldObject.value.length; i++ )        {            if ( fieldObject.value.charAt(i) ==" "  )            {                subValidationFailed++;            }        }        // Did the check fail anywhere?        if ( subValidationFailed > 0 )        {            ValidationFailed++;            ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + fieldMessage + "\n"        }    }}function checkNumbers( fieldObject, fieldMessage, fieldMinLength, fieldMaxLength )// Validates if the given fieldObject contains only numbers;// if it fails to comply, the ValidationFailed counter is increased and the fieldMessage is added to the error outputstring.{    if( fieldObject )    {        var subValidationFailed = 0        if(            ( fieldMinLength > 0 && fieldObject.value.length < fieldMinLength ) ||            ( fieldMaxLength > 0 && fieldObject.value.length > fieldMaxLength )            )            {            subValidationFailed++;        } else {            for( var i=0; i < fieldObject.value.length; i++ )            {                charCode = fieldObject.value.charCodeAt(i);                if ( charCode < 48 || charCode > 57 )                {                    subValidationFailed++;                }            } // for        }        // Did the check fail anywhere?        if ( subValidationFailed > 0 )        {            ValidationFailed++;            ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + fieldMessage + "\n"        }    } // if( fieldObject )}function checkValueRange( fieldObject, fieldMessage, iMinValue, iMaxValue )// Validates if the given fieldObject contains only numbers that are between or equal to iMinValue and iMaxValue;// Setting either iMinValue or iMaxValue to null skips their check.// if it fails to comply, the ValidationFailed counter is increased and the fieldMessage is added to the error outputstring.{    if ( fieldObject )    {        var subValidationFailed = 0        var intValue = parseInt( fieldObject.value, 10 );        if( isNaN( intValue ) || ( iMinValue != null && intValue < iMinValue ) || ( iMaxValue != null && intValue > iMaxValue ) )        {            subValidationFailed++;        }        // Did the check fail anywhere?        if ( subValidationFailed > 0 )        {            ValidationFailed++;            ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + fieldMessage + "\n";        }    }}function doFormatPC( fieldObject ){    // Formats the given field to comply with the Dutch Postal code format , for example "1066 EE"    if ( fieldObject )    {        // Followed by a space        sValue = fieldObject.value.toUpperCase( );        if ( sValue.charAt(4) != " " )        {            // Recompose the postal code            sLetters		= sValue.substring( 4, ( sValue.length ) );            sValue		= sValue.substring( 0, 4 ) + " " + sLetters;        }        fieldObject.value = sValue.substring( 0, 7 );    }}function checkPostcode( fieldObject, fieldMessage )// Validates if the given fieldObject is formatted to comply with the Dutch Postal code, for example "1066 EE";// if it fails to comply, the ValidationFailed counter is increased and the fieldMessage is added to the error outputstring.{    if ( fieldObject )    {        fieldObject.value = fieldObject.value.toUpperCase();        var subValidationFailed = 0        if ( fieldObject.value.length != 7 )        {            ValidationFailed++;            ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + fieldMessage + "\n"        } else {            // The first four characters must be numbers            for( var i=0; i < 4; i++ )            {                if ( isNaN( fieldObject.value.charAt(i) )  )                    subValidationFailed++;            }            // Followed by a space            if ( fieldObject.value.charAt(4) != " " )                subValidationFailed++;            // The last two characters must be letters            for( var i=5; i < 7; i++ ) {                if ( fieldObject.value.charCodeAt(i) < 65 | fieldObject.value.charCodeAt(i) > 90 )                    subValidationFailed++;            }        }        // Did the check fail anywhere?        if ( subValidationFailed > 0 )        {            ValidationFailed++;            ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + fieldMessage + "\n"        }    }}function checkReferencenr( fieldObject, fieldMessage )// Validates if the given fieldObject is formatted according to a reference number standard, for example "T24512";// if it fails to comply, the ValidationFailed counter is increased and the fieldMessage is added to the error outputstring.{    if ( fieldObject )    {        fieldObject.value = fieldObject.value.toUpperCase();        var subValidationFailed = 0        if ( fieldObject.value.length != 6 )        {            ValidationFailed++;            ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + fieldMessage + "\n"        } else {            // The first character must be a letter            for( var i=0; i < 1; i++ )            {                if ( fieldObject.value.charCodeAt(i) < 65 | fieldObject.value.charCodeAt(i) > 90 )                {                    subValidationFailed++;                }            }            // The next five characters must be numbers            for( var i=1; i < 6; i++ )            {                if ( isNaN( fieldObject.value.charAt(i) )  )                {                    subValidationFailed++;                }            }        }        // Did the check fail anywhere?        if ( subValidationFailed > 0 )        {            ValidationFailed++;            ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + fieldMessage + "\n"        }    }}function checkBankAccount( fieldObject, sFM1, sFM2 ){    // Checks for valid Dutch bank account numbers, by performing the 11-check    // sFM1 = message for wrong length (giro account is 3 to 7 digits, bank account 9)    // sFM2 = message for invalid bank account number (if empty, takes sFM1 as value)    if( fieldObject )    {        var sFV = fieldObject.value;        // Remove any dots        sFV = sFV.replace( /(\.)+/gi, '' );        if( sFM2 == undefined ) sFM2 = sFM1;        if( sFV.length < 3 || ( sFV.length > 7 && sFV.length != 9 ) )        {            ValidationFailed++;            ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + sFM1 + "\n";        } else{            if( sFV.length == 9 )            {                // This should be a bank account                var iTotal = 0;                var iNine = 9;                for( var ii = 0; ii < sFV.length; ii++ )                {                    iTotal = iTotal + ( sFV.charAt( ii ) * iNine );                    iNine--;                }                if( Math.floor( iTotal / 11 ) != iTotal / 11 )                {                    // The given number cannot be divided by 11 -> not a valid bank account                    ValidationFailed++;                    ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + sFM2 + "\n";                }            } else{        // This is not a bank account, it might be a giro account (3 to 7 digits)        // No further checks        }        }    }} // END checkBankAccountfunction getDutchDateArray( sDateString ){    // Returns an array with these elements: 0=day, 1=month, 2=year    // Compatible with American and Dutch date formats    // Check for American date-format (12/31/2005)    if( sDateString.indexOf( '/' ) > -1 )    {        var aDate	= sDateString.split( '/' );        return new Array        (            aDate[1],            aDate[0],            aDate[2]            );    }    else    {        // Assume Dutch date format (31-12-2005)        return sDateString.split( '-' )    }} // END getDutchDateArrayfunction getDateString( sDateBase ){    /*	Returns a Date string from the given 3-field date	In:		base of the 3-field date object: 'BD' is the base for BD_D, BD_M and BD_Y	Out:	string in Dutch date format: 31-12-2005	*/    var sReturnValue =    getValue( sDateBase + '_D' ) + '-' +    getValue( sDateBase + '_M' ) + '-' +    getValue( sDateBase + '_Y' );    /*	oForm = document.forms[0];	var sReturnValue =		eval( 'oForm.' + sDateBase + '_D' ).value + '-' +		eval( 'oForm.' + sDateBase + '_M' ).value + '-' +		eval( 'oForm.' + sDateBase + '_Y' ).value;*/    return sReturnValue;}function checkDate( sDate, iYearDifference, sFM1, sFM2 ){    /* Checks if the given date is correct and (optionally) if it is before the given number of years		In:			sDate 				-	date in Dutch date format (31-12-2005)			iYearDifference	-	integer or null:										integer does a comparison between the date and (Today -iYearDifference)										null doesn't compare the date			sFM1				-	message if the date is not correct			sFM2				-	message if the date isn't before (only needed if iYearDifference != null)	*/    var aDate	= getDutchDateArray( sDate );    var oDate	= null;    // JS month is 0-based, correct the given month    sMonth		= ( isNaN( aDate[1] ) ) ? '' : ( aDate[1] -1 );    if(        aDate[0] != '' &&        aDate[1] != '' &&        aDate[2] != ''        )        {        oDate	= new Date( aDate[2], sMonth, aDate[0] );    }    if(        oDate == null ||        isNaN( oDate )        )        {        // Incorrect date given, validation failed        ValidationFailed++;        ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + sFM1 + "\n";    }    else    {        // Date is correct, now compare it to today - iYearsBefore        if( iYearDifference == null )        {        // No further check is necessary, this date is correct        }        else        {            var oToday		= new Date( );            var iTimeDiff	= oToday - oDate;            var iYearMS	= iYearDifference * 365 * 24 * 60 * 60 * 1000;            if( iTimeDiff < iYearMS )            {                // Date isn't older than the specified # years                ValidationFailed++;                ValidationFailedFieldnames = ValidationFailedFieldnames + "- " + sFM2 + "\n";            }        }    }} // END checkDate/*******************************************	Returns the value of a named element.*	Supported INPUT types: text, radio, checkbox and select.*	If the document is opened in read-mode,*	the value is taken from the contents of the*	ID that the element is in. This ID must have*	the same name as the element******************************************/function getValue( sObjectName ){    var oObject = document.forms[0][ sObjectName ];    var sReturnValue = '';    if( oObject != null )    {        // The field object exists        if( oObject.length != null )        {            // Field is a multi-value type - radio, checkbox, select-one or select-multiple            //			var sObjectType = ( oObject[0].type == null ) ? oObject.type : oObject[0].type;            var aValue = new Array( "" );            var iCounter = 0;            for( var i = 0; i < oObject.length; i++ )            {                if(                    ( oObject[i].checked == null ) ? oObject[i].selected : oObject[i].checked                    )                    {                    aValue[iCounter] = ( oObject[i].value == '' ) ? oObject[i].text : oObject[i].value;                    iCounter++;                } // if            } // for            // Implode the multi value to a string            for( var i = 0; i < aValue.length; i++ )            {                sReturnValue += ( i == ( aValue.length -1 ) ) ? aValue[i] : aValue[i] + ', ';            }        }        else // if( oObject.length != null )        {            // Field is a single-value            sReturnValue = oObject.value;        } // if( oObject.length != null )        //		alert( sReturnValue );        return sReturnValue;    }    else // if( oObject != null )    {        // The field object doesn't exist - try to get the value from        // the contents of the ID with the same name        var oObject = document.getElementById( sObjectName );        if( oObject != null ) 		{            return oObject.innerText;        }    } // if( oObject != null )    // If none of the above returned anything, return null    return null;} // function getValue( sObjectName )function showElement( oObject ) {    // Works on individual elements as well    // as on an array of elements    if( oObject == null )        return;    if( oObject[0] == null )    {        oObject.style.visibility='visible';        oObject.style.display='inline';    } else{        for( var ic = 0; ic < oObject.length - 1; ic++ )        {            oObject[ic].style.visibility="visible";            oObject[ic].style.display="inline";        }    }} // end showElementfunction hideElement( oObject ) {    if( oObject == null )        return;    if( oObject[0] == null )    {        oObject.style.visibility='hidden';        oObject.style.display='none';    } else{        for( var ic = 0; ic < oObject.length - 1; ic++ )        {            oObject[ic].style.visibility='hidden';            oObject[ic].style.display='none';        }    }} // end hideElementfunction conditionalShow( bCondition, oObject ){    // If bCondition is true, the object is shown, otherwise it's hidden.    if( bCondition )        showElement( oObject );    else        hideElement( oObject );}function doHTMLPreview( oForm ){    // Submits the document    // Check if there is an HTML field that contains HTML that should be merged    // with values in the form    var sPlaceholderS		= "{[";    var sPlaceholderE		= "]}";    var iFieldStart				= -1;    var iFieldEnd				= -1;    var sFieldName			= "";    var sFieldValue			= "";    var sHTML_Email_Source	= getValue( "HTML_Email_Source" );    // The HTML Preview fields initially contains the same HTML    var sHTML_Preview	= sHTML_Email_Source;    var regEx;    // HTML field found, replace the field placeholders with actual values from the document    // Loop the HTML source, searching for field tags    for( var iIndex = 0; iIndex < sHTML_Email_Source.length; iIndex++ )    {        iFieldStart = sHTML_Email_Source.indexOf( sPlaceholderS, iIndex );        if( iFieldStart > -1 )        {            // Found start of field            // Search for end of field            iFieldEnd = sHTML_Email_Source.indexOf( sPlaceholderE, iFieldStart );            if( iFieldEnd > -1 )            {                // Found end of field                // Extract the field name and get it's value                sFieldName	= sHTML_Email_Source.substring( iFieldStart + sPlaceholderS.length, iFieldEnd );                sFieldValue	= getValue( sFieldName );                if( sFieldValue != null )                {                    // Replace the placeholder in the HTML code                    // For some strange reason, "{[" cannot be used as a regex search value, so we'll use "{."...                    regEx					= new RegExp( "{." + sFieldName + sPlaceholderE, "" );                    sHTML_Preview	= sHTML_Preview.replace( regEx, sFieldValue );                //				alert( "Field found: " + sFieldName + "\nregEx.toString()=" + regEx.toString() + "\nsFieldValue=" + sFieldValue );                }                // Set the index to continue after the field found                iIndex = iFieldEnd + sPlaceholderS.length;            } // if( iFieldEnd > -1 )        } // if( iFieldStart > -1 )    } // for    // Show the HTML code instead of the input form    var oInputArea			= document.getElementById( "InputArea" );    var oPreviewArea		= document.getElementById( "PreviewArea" );    var oHTML_Preview	= document.getElementById( "HTML_Preview" );    oForm.HTML_Email.value		= sHTML_Preview;    oHTML_Preview.innerHTML	= sHTML_Preview;    hideElement( oInputArea );    showElement( oPreviewArea );}function doSubmit( oForm ){    oForm.submit();} // doSubmitfunction doPreSubmit( oForm ){    // Only show the HTML Preview if there is HTML code present and the    // document is not being reviewed by a reviewer (Workflow ID will be present)    if    (        getValue( "HTML_Email_Source" ) == "" ||        document.getElementById( "Workflow" ) != null        )        {        // No HTML e-mail code present, submit the doc immediately                        // Here we check if the Workshops subform was passed        if ($("#reallySubmit").val()=="1"){                    // WORKSHOP SPECIFIC                   if($("#wsins").val()=="1"){                             if($("#fldKaldenBach option:selected").val() == "Ja"){          	  stroom = "Groen";		      }  		      if($("#fldKaldenBach option:selected").val() == "Nee"){	            stroom = "Blauw";     		 }                              var userFirstName = $("#VoorNaam").val();                var userLastName = $("#AchterNaam").val();                var mailAddress = $("#EmailAddress").val();                var fullName = userFirstName + ' ' + userLastName;             	                alert("Naam: " + fullName);                alert("mailAddress: " + mailAddress);             	                var url = DBNameHTML_C + "ajaxCheckKeywords?OpenAgent&stroom="                url += stroom;                url += "&user=";                url += fullName;                url += "&mailaddress=";                url += mailAddress;             	                if(stroom == "Groen") {                    url += "&wsgroen1="                    url += $('#wsGroen1 option:selected').val();                    url += "&wsgroen2="                    url += $('#wsGroen2 option:selected').val();                }                else if ( stroom == "Blauw" ) {                    url += "&wsblauw1="                    url += $('#wsBlauw1 option:selected').val();	               url += "&wsblauw2="                    url += $('#wsBlauw2 option:selected').val();                    url += "&wsblauw3="                    url += $('#wsBlauw3 option:selected').val();                }                else {	             	                }		                    //Ajax: check the keywords 	                  //alert(url);                var retMsg = $.ajax({                    url: url,                    async: false                }).responseText;                if (retMsg != "fail"){            //alert(retMsg);            };            // END OF Here we check if the Workshops subform was passed                            }            doSubmit( oForm )        }    } else {        // HTML present, show the doc in preview mode first        doHTMLPreview( oForm );    }} // doPreSubmitfunction checkResults( formObject )// If any of the required fields failed the validation, display a message, otherwise submit the document, update the parent and close this document// Updating the parentdocument is done by the $$Return field{    var doCaptchaCheck = "0";    var captchaDiv = document.getElementById("myRecaptcha");    if(captchaDiv!=null){        doCaptchaCheck = "1"    }    switch ( ValidationFailed ) {        case 0:            // Validation OK, submit the document            if(doCaptchaCheck == "1"){                checkRecaptcha( formObject );            } else {    			 $("#reallySubmit").val("1");                doPreSubmit( formObject )            }            break;        case 1:            // A single field failed the validation            alert ( MessageAll + MessageSingle + ValidationFailedFieldnames );            break;        default:            // Multiple fields failed the validation            alert ( MessageAll + MessageMulti + ValidationFailedFieldnames );    }}function returnToInput( ){    var oInputArea			= document.getElementById( "InputArea" );    var oPreviewArea		= document.getElementById( "PreviewArea" );    showElement( oInputArea );    hideElement( oPreviewArea );}function eBeforePrint(){    // JR_JD.style.height = "auto";    oRemarks = document.all.Remarks;    if( oRemarks ) {        oRemarks.style.display = "none";        Remarks_Print.innerHTML = oRemarks.value;        Remarks_Print.style.display = "inline";    }}function eAfterPrint(){    // JR_JD.style.height = "80px";    oRemarks = document.all.Remarks;    if( oRemarks ) {        oRemarks.style.display = "inline";        Remarks_Print.style.display = "none";    }}function editDoc( sDocID ){    document.location = DBNameHTML_C + "/v0001WBE1/" + sDocID + "?EditDocument";}function openDoc( sDocID ){    document.location = DBNameHTML_C + "/v0001WBE1/" + sDocID + "?OpenDocument";}function deleteDoc( sDocID, sPrompt ){    if( confirm( sPrompt ) )    {        window.location = DBNameHTML_C + "/v0001WBE1?OpenView";        var URL = DBNameHTML_C + "/v0001WBE1/" + sDocID + "?DeleteDocument";        var Features = 'unadorned:yes;edge:raised;help:no;scroll:no;status:no;resizable:no;dialogLeft:0px;dialogTop:0px;dialogWidth:1px;dialogHeight:1px';        var returnValue = window.showModalDialog( URL, window, Features );    }}// Functions for date fields - set todays datevar Now = new Date();var NowDay = Now.getDate();var NowMonth = Now.getMonth();var NowYear = Now.getYear();if (NowYear < 2000) NowYear += 1900; // for Netscapefunction DaysInMonth(WhichMonth, WhichYear){    // function for returning how many days there are in a month including leap years    var DaysInMonth = 31;    if (WhichMonth == "04" || WhichMonth == "06" || WhichMonth == "09" || WhichMonth == "11") DaysInMonth = 30;    if (WhichMonth == "02" && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;    if (WhichMonth == "02" && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;    return DaysInMonth;}function ChangeOptionDays(Which){    // function to change the available days in a month    formObject = document.forms[0];    oDays	= eval("formObject." + Which + "D");    oMonth	= eval("formObject." + Which + "M");    oYear	= eval("formObject." + Which + "Y");    Month	= oMonth[oMonth.selectedIndex].value;    //  Year		= oYear[oYear.selectedIndex].value;    Year		= getValue( Which + 'Y' );    DaysForThisSelection = DaysInMonth(Month, Year);    CurrentDaysInSelection = oDays.length - 1;    if (CurrentDaysInSelection > DaysForThisSelection) {        for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)  {            oDays.options[oDays.options.length - 1] = null        }    }    if (DaysForThisSelection > CurrentDaysInSelection) {        for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++) {            NewOption = new Option( oDays.options.length, oDays.options.length );            oDays.add(NewOption);        }    }    if( oDays.selectedIndex < 0) oDays.selectedIndex == 0;}function SetToToday(Which){    // function to set options to today    formObject = document.forms[0];    oDays	= eval("formObject." + Which + "D");    oMonth	= eval("formObject." + Which + "M");    oYear	= eval("formObject." + Which + "Y");    oMonth[NowMonth + 1].selected = true;    ChangeOptionDays(Which);    oDays[NowDay].selected = true;}function SetYearOptions(iYearsBefore, iYearsAhead, sSelected){    //function to write option years    var line = "";    var iYear = 0;    for ( var i=iYearsBefore; i<=iYearsAhead; i++)    {        iYear = NowYear + i;        if( iYear.toString()==sSelected)        {            line += '<OPTION VALUE="' + iYear + '" SELECTED>' + iYear;        } else{            line += '<OPTION VALUE="' + iYear + '">' + iYear;        }    }    return line;}function initDate(Which){    // Initialize the Date fields indicated by Which;    formObject = document.forms[0];    if( document.URL.indexOf( "&Seq=" ) == -1 ) {        SetToToday( Which );    }}function setCookie(name, value, expire){    // Sets cookie values. Expiration date is optional (taken from Netscape JS ClientGuide 1.3)    document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))}function getCookie(Name){    // Gets cookie values.  (taken from Netscape JS ClientGuide 1.3)    var search = Name + "=";    if (document.cookie.length > 0)    { // if there are any cookies        offset = document.cookie.indexOf(search);        if (offset != -1)        { // if cookie exists            offset += search.length;            // set index of beginning of value            end = document.cookie.indexOf(";", offset);            // set index of end of cookie value            if (end == -1)                end = document.cookie.length;            return unescape(document.cookie.substring(offset, end));        }    }}function setCF(oField){    // Sets a cookie with name and value of the given field    if(oField)    {        // alert( 'oField.name=' + oField.name + '\ngetValue( oField.name )=' + getValue( oField.name ) );        setCookie( oField.name, getValue( oField.name ) );    }}function setField(oField){    // Sets the value of the given field to the value of a found cookie with the same name as the field    if(oField)    {        var sFieldName	= oField.name;        var sFieldType	= oField.type;        if( oField.length > -1 && oField[0].type == 'radio' )        {            sFieldName	= oField[0].name;            sFieldType		= oField[0].type;        }        //		alert( 'sFieldType=' + sFieldType + '\nsFieldName=' + sFieldName );        var sCV = getCookie(sFieldName);        if( sCV != "" && sCV != null )        {            // alert( 'sFieldName=' + sFieldName + '\nsFieldType=' + sFieldType + '\ncookie value=' + sCV );            switch( sFieldType )            {                case 'select-one' :                    for( var iC = 0; iC < oField.length; iC++ )                    {                        if( oField.options[iC].value == sCV )                            oField.options[iC].selected = true;                    }                    break;                case 'radio' :                    for( var iC = 0; iC < oField.length; iC++ )                    {                        if( oField[iC].value == sCV )                            oField[iC].checked = true;                    }                    break;                default :                    if( oField.value == "" )                    {                        oField.value = sCV;                    }            }        }    }}function contains( sString, sSubstring ){    /*		Determines whether a substring is stored within a string.		sString			String or Array. The string(s) you want to search.		sSubstring			String. The string you want to search for in sString.	*/    var bReturn = false;    if( sString == null )        return false;    if( typeof( sString ) == "string" )    {        // sString is a String        if( sString.indexOf( sSubstring ) > -1 )            bReturn = true;    } else{        // sString is an Array        for( var i=0; i < sString.length; i++ )        {            if( sString[i].indexOf( sSubstring ) > -1 )                bReturn = true;        }    }    return bReturn;}function getBlockCounter( sBlockName ){    // Get the counter from stored field    var sCounterField	= sBlockName + "_Counter";    var iCounter_tmp	= getValue( sCounterField );    if( iCounter_tmp == "" )    {        // Reset to the minimum value if the field is empty        iBlock_Min		= eval( "BLOCK_" + sBlockName.toUpperCase() + "_MIN" );        //		alert( "getBlockCounter() - iBlock_Min=" + iBlock_Min );        iCounter_tmp	= iBlock_Min;    }    return parseInt( iCounter_tmp );} // end getBlockCounterfunction setBlockCounter( sBlockName, iCounter_tmp ){    // Put new value of counter back in the field    var sCounterField	= sBlockName + "_Counter";    var oCounter			= eval( "document.forms[0]." + sCounterField );    if( oCounter != null )    {        oCounter.value = iCounter_tmp;    }} // end setBlockCounterfunction changeBlockCounter( sBlockName, iAmount ){    var iCounter_tmp	= getBlockCounter( sBlockName );    var iBlock_Min		= eval( "BLOCK_" + sBlockName.toUpperCase() + "_MIN" );    var iBlock_Max		= eval( "BLOCK_" + sBlockName.toUpperCase() + "_MAX" );    iCounter_tmp		= iCounter_tmp + iAmount;    if( iCounter_tmp <= iBlock_Min )        iCounter_tmp = iBlock_Min;    if( iCounter_tmp >= iBlock_Max )        iCounter_tmp = iBlock_Max;    setBlockCounter( sBlockName, iCounter_tmp );    doHideWhens();} // end changeBlockCounterfunction doBlockHideWhens( sBlockName ){    var iCounter_tmp	= getBlockCounter( sBlockName );    var iBlock_Min		= eval( "BLOCK_" + sBlockName.toUpperCase() + "_MIN" );    var iBlock_Max		= eval( "BLOCK_" + sBlockName.toUpperCase() + "_MAX" );    // Array containing objects that are dynamically shown or hidden    var aBlockIDs		= new Array( iBlock_Max );    //	alert( "doBlockHideWhens() - iCounter_tmp=" + iCounter_tmp );    // Loop all sBlockName objects    for( var i = 0; i < iBlock_Max; i++ )    {        aBlockIDs[i] = document.getElementById( sBlockName + "_"  + ( ( i + 1).toString() ) );        if( i < iCounter_tmp )        {            // Objects to show            showElement( aBlockIDs[i] );        } else {            // Rest of the objects are not shown            hideElement( aBlockIDs[i] );        }    } // for    // Show/hide ...Min and ...Plus buttons based on the given counter    // The buttons ID should end in "_Min" and "_Plus"    var oElem = document.getElementById( sBlockName + '_Min' );    if( iCounter_tmp <= iBlock_Min )    {        hideElement( oElem );    } else {        showElement( oElem );    }    oElem = document.getElementById( sBlockName + '_Plus' );    if( iCounter_tmp >= iBlock_Max )    {        hideElement( oElem );    } else {        showElement( oElem );    }} // end doBlockHideWhens( )function checkRecaptcha( oForm ){    $(document).ready(function() {        $.getJSON("http://jsonip.appspot.com?callback=?",function(data){            var stripped="";            var userIP = data.ip;            var capChallenge = Recaptcha.get_challenge();            var capResponse = Recaptcha.get_response();            var agtURL = DBNameHTML_C + "/getURL?openagent&remoteip=" + userIP + "&challenge=" + capChallenge + "&response=" + capResponse + "&privatekey=";            $.ajax({                async: false,                url: agtURL,                success: function(data) {                    stripped = data.replace(/(<([^>]+)>)/ig,"");                    stripped = stripped.replace(/[\n\r\t]/g,"");                    if(stripped=="truesuccess") {                        $("#reallySubmit").val("1");                        doPreSubmit( oForm )                    } else {                        alert('Please re-enter the Captcha text and try again');                        Recaptcha.reload()                    }                }            })        })    })}
