+
+### Java Script ###
+print"<script>\n";
+
+# Generate Java Script Array which contains the provider that support token.
+my $line = "";
+$line = join("', '", @token_provider);
+
+print "\t// Array which contains the providers that support token.\n";
+print "\ttoken_provider = ['$line']\;\n\n";
+
+print <<END
+ // Java Script function to swap the text input fields for
+ // username and password or token.
+ var update_auth = function() {
+ if(inArray(\$('#SERVICE').val(), token_provider)) {
+ \$('.username').hide();
+ \$('.password').hide();
+ \$('.token').show();
+ } else {
+ \$('.username').show();
+ \$('.password').show();
+ \$('.token').hide();
+ }
+ };
+
+ // Java Script function to check if a given value is part of
+ // an array.
+ function inArray(value,array) {
+ var count=array.length;
+
+ for(var i=0;i<count;i++) {
+ if(array[i]===value){
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ // JQuery function to call corresponding function when
+ // the service provider is changed or the page is loaded for showing/hiding
+ // the username/password or token area.
+ \$(document).ready(function() {
+ \$('#SERVICE').change(update_auth);
+ update_auth();
+ });
+
+</script>
+END
+;
+