<%
'This page is closely related to the page containing the guestbook asp code and should reside in the same folder

Const useName      = true
Const useComment   = true
Const useEmail     = true
Const useHomepage  = true
Const useCity      = true
Const useCountry   = false
Const useEmoticons = true
Const ag_gbpath    = "../guestbook/"
Const ag_gbpage    = "gastebuch.html"
Const useState     = false
%>


    <script language="JavaScript">
    function validate() {
        // validate name
        if ( document.form.name.value == "" ) {
            alert( "Bitte geben Sie einen Namen ein!" );
            document.form.name.focus();
            return false;
        }

        // validate comment
        if ( document.form.comment.value == "" ) {
            alert( "Bitte geben Sie einen Kommentar ein!" );
            document.form.comment.focus();
            return false;
        }

        // validate email
        if ( document.form.email != null ) {
            var email = document.form.email.value;
            if ( email != "" ) {
                if ( ( email.indexOf( ' ' ) != -1 ) ||
                     ( email.indexOf( '@' ) <= 0 ) || ( email.lastIndexOf( '@' ) == email.length ) ||
                     ( email.indexOf( '.' ) <= 0 ) || ( email.lastIndexOf( '.' ) == email.length ) ) {
                    alert( "Geben Sie bitte eine g&#252;ltige E-Mail-Adresse ein!" );
                    document.form.email.focus();
                    return false;
                }
            }
        }

        // adjust homepage value
        if ( document.form.homepage != null ) {
            var homepage = document.form.homepage.value;

            if ( homepage.indexOf( "http://" ) != -1) {
                document.form.homepage.value = homepage.substring( 7, homepage.length );
            }
        }

        return true;
    }

    function insertAtCursor( field, value ) {
        if ( document.selection ) {
            //IE support
            field.focus();
            sel = document.selection.createRange();
            sel.text = value;
        } else if ( field.selectionStart || field.selectionStart == '0' ) {
            //MOZILLA/NETSCAPE support
            var startPos = field.selectionStart;
            var endPos = field.selectionEnd;
            field.value = field.value.substring( 0, startPos ) + value + field.value.substring( endPos, field.value.length );
        } else {
            field.value += value;
        }
    }

    function insertEmoticon( emoticon ) {
        var ta = document.form.comment;
        var text = "";
        if ( document.form.comment != null ) {
            var text = "";

            switch ( emoticon ) {
                case "smile": text = ":)"; break;
                case "happy": text = ":D"; break;
                case "laugh": text = "=))"; break;
                case "ohwell": text = ":/"; break;
                case "sad": text = ":("; break;
                case "mad": text = "X("; break;
                case "tongue": text = ":P"; break;
                case "wink": text = ";)"; break;
            }

            insertAtCursor( document.form.comment, text );
        }
    }
    </script>

<form class="gb" name="form" method="post" action=<%= ag_gbpage & "?op=add"  %> onSubmit="return validate();">
<table class="gb">

<% If useName Then %>
    <tr class="gb">
        <td class="gb">Name*:</td>
        <td class="gb"><input class="gb" type="text" name="name" size="25"></td>
    </tr>
<% End If %>

<% If useEmail Then %>
    <tr class="gb">
        <td class="gb">E-Mail:</td>
        <td class="gb"><input class="gb" type="text" name="email" size="25"></td>
    </tr>
<% End If %>

<% If useHomepage Then %>
    <tr class="gb">
        <td class="gb">Homepage:</td>
        <td class="gb"><input class="gb" type="text" name="homepage" size="25"></td>
    </tr>
<% End If %>

<% If useCity Then %>
    <tr class="gb">
        <td class="gb">Stadt:</td>
        <td class="gb"><input class="gb" type="text" name="city" size="25"></td>
    </tr>
<% End If %>

<% If useState Then %>
    <tr class="gb">
        <td class="gb">Bundesland:</td>
        <td class="gb"><input class="gb" type="text" name="state" size="25"></td>
    </tr>
<% End If %>

<% If useCountry Then %>
    <tr class="gb">
        <td class="gb">Land:</td>
        <td class="gb"><input class="gb" type="text" name="country" size="25"></td>
    </tr>
<% End If %>

<% If useComment Then %>
    <tr class="gb">
        <td class="gb" valign="top">Kommentar*:</td>
        <td class="gb"><textarea class="gb" name="comment" rows="4" cols="60" wrap="hard"></textarea></td>
    </tr>
<% End If %>

<% If useEmoticons Then %>
    <tr class="gb">
        <td class="gb"></td>
        <td class="gb">
        <center>
        <img src="<%= ag_gbpath %>emoticons/smile.gif" onclick="insertEmoticon('smile');" style="cursor:pointer;"></img>
        <img src="<%= ag_gbpath %>emoticons/happy.gif" onclick="insertEmoticon('happy');" style="cursor:pointer;"></img>
        <img src="<%= ag_gbpath %>emoticons/laugh.gif" onclick="insertEmoticon('laugh');" style="cursor:pointer;"></img>
        <img src="<%= ag_gbpath %>emoticons/ohwell.gif" onclick="insertEmoticon('ohwell');" style="cursor:pointer;"></img>
        <img src="<%= ag_gbpath %>emoticons/sad.gif" onclick="insertEmoticon('sad');" style="cursor:pointer;"></img>
        <img src="<%= ag_gbpath %>emoticons/mad.gif" onclick="insertEmoticon('mad');" style="cursor:pointer;"></img>
        <img src="<%= ag_gbpath %>emoticons/tongue.gif" onclick="insertEmoticon('tongue');" style="cursor:pointer;"></img>
        <img src="<%= ag_gbpath %>emoticons/wink.gif" onclick="insertEmoticon('wink');" style="cursor:pointer;"></img>
        </center>
        </td>
    </tr>
<% End If %>

    <tr class="gb">
        <td class="gb"></td>
        <td class="gb"><input type="submit" value="Kommentar hinzuf&#252;gen"></td>
    </tr>
</table>
</form>
