/*
 * Enhydra Java Application Server Project
 * 
 * The contents of this file are subject to the Enhydra Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License on
 * the Enhydra web site (http://www.enhydra.org/).
 * 
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
 * the License for the specific terms governing rights and limitations
 * under the License.
 * 
 * The Initial Developer of the Enhydra Application Server is Lutris
 * Technologies, Inc. The Enhydra Application Server and portions created
 * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
 * All Rights Reserved.
 * 
 * Contributor(s):
 * 
 * $Id: FormControl.js,v 1.1 2003/04/11 11:56:05 jacobk Exp $
 */

//--------------------- Public functions ----------------------------

/**
 * takes a form object as the first argument and then takes an infinite amount
 * of additional arguments which are expected to be functions.  This allows for
 * the possibility of executing multiple functions (in the order provided)
 * before actual submittal of the form.  Actually, any one of the named
 * functions may submit the form themselves.  However, ___doSubmit() always
 * provides a backstop objForm.submit() in case no extra function is provided
 * or the functions that are provided don't submit the form themselves.
 *
 * @see doSubmitAndLock(objForm)
 */
function doSubmitAndNoLock(objForm) {
    return ___doSubmit(arguments);
}

/**
 * same as doSubmitAndNoLock, only this locks all form controls of type
 * 'submit', 'button', and 'image'.  Other types of controls can't be
 * locked (disabled) because they are data-rich and modern browsers won't send
 * data of disabled controls to the server.
 *
 * @see doSubmitAndNoLock(objForm)
 */
function doSubmitAndLock(objForm) {
    for (i = 0; i < objForm.elements.length; i++) {
        if (objForm.elements[i].type == 'submit' || objForm.elements[i].type == 'button' || objForm.elements[i].type == 'image') {
            objForm.elements[i].disabled = true;
        }
    }
    return ___doSubmit(arguments);
}


//--------------------- Utility functions ---------------------------


/**
 * Takes an arguments object.  Treats the first argument as the form object
 * and the rest as function to be called, with the form object as the only
 * argument.
 */
function ___doSubmit(args) {
    if (___propperArgs(arguments) && args[0].submit) {
        //args is an arguments object and the first argument of that
        //arguments object is a form object.
        
        //loop through other arguments which are expected to be functions, but
        //we'll double check anyway and ignore each argument that isn't a
        //function
        var ok = true;
        for (var i=1; i < args.length; i++) {
            if (args[i].call) {
                ok = args[i].call(null, args[0]);
                if (!ok) break;
            }
        }

        //to disable form submittal, commment out the submit()
        if (ok) args[0].submit();
    } else {
        alert('Impropper arguments!  Must be a single arguments object with the first argument of said object being a form object');
    }
    return false;
}

/**
 * checks, first, that the args argument is an arguments object and then
 * checks that the actual length of the arguments object matches the
 * expected length.
 */
function ___propperArgs(args) {
    if (!args.callee) return false;
    var actual = args.length;
    var expected = args.callee.length;
    if (actual == expected) return true;
    else return false;
}



function exampleContent(movie1,movie2)
{
    
    document.getElementById('movie2').innerHTML=
	'<object width="650" height="403">'+
		'<param name="allowfullscreen" value="true" />'+
		'<param name="allowscriptaccess" value="always" />'+
		'<param name="movie" value="'+movie1+'" />'+
		'<embed '+
			'src="'+movie1+'" '+
			'type="application/x-shockwave-flash" '+
			'allowfullscreen="true" '+
			'allowscriptaccess="always" '+
			'width="650"'+
			'height="403">'+
		'</embed>'+
	'</object>';
    
    document.getElementById('movie1').innerHTML=
	'<object width="650" height="403">'+
		'<param name="allowfullscreen" value="true" />'+
		'<param name="allowscriptaccess" value="always" />'+
		'<param name="movie" value="'+movie2+'" />'+
		'<embed '+
			'src="'+movie2+'" '+
			'type="application/x-shockwave-flash" '+
			'allowfullscreen="true" '+
			'allowscriptaccess="always" '+
			'width="650"'+
			'height="403">'+
		'</embed>'+
	'</object>';
    document.getElementById("movie2").style.display = 'block';
    document.getElementById("movie1").style.display = 'none';
    
}

function exampleContent1(movie1,movie2)
{
    
    document.getElementById('movie1').innerHTML=
	'<object width="650" height="403">'+
		'<param name="allowfullscreen" value="true" />'+
		'<param name="allowscriptaccess" value="always" />'+
		'<param name="movie" value="'+movie1+'" />'+
		'<embed '+
			'src="'+movie1+'" '+
			'type="application/x-shockwave-flash" '+
			'allowfullscreen="true" '+
			'allowscriptaccess="always" '+
			'width="650"'+
			'height="403">'+
		'</embed>'+
	'</object>';
    
    document.getElementById('movie2').innerHTML=
	'<object width="650" height="403">'+
		'<param name="allowfullscreen" value="true" />'+
		'<param name="allowscriptaccess" value="always" />'+
		'<param name="movie" value="'+movie2+'" />'+
		'<embed '+
			'src="'+movie2+'" '+
			'type="application/x-shockwave-flash" '+
			'allowfullscreen="true" '+
			'allowscriptaccess="always" '+
			'width="650"'+
			'height="403">'+
		'</embed>'+
	'</object>';
    
    document.getElementById("movie1").style.display = 'block';
    document.getElementById("movie2").style.display = 'none';
    
     
}

function callMovie(movie1)
{
    

    document.getElementById('movie1').innerHTML=
				'<object width="650" height="402">'+
					'<param name="allowfullscreen" value="true" />'+
					'<param name="allowscriptaccess" value="always" />'+
					'<param name="movie" value="'+movie1+'" />'+
						'<embed '+
							'src="'+movie1+'" '+
							'type="application/x-shockwave-flash" '+
							'allowfullscreen="true" '+
							'allowscriptaccess="always" '+
							'autoplay="true"'+
							'width="650" '+
							'height="402">'+
						'</embed>'+
				'</object>';
    
    
    document.getElementById("movie1").style.display = 'block';
    
}


function callViemoMovie(movie1)
{
    

    document.getElementById('movie1').innerHTML=
				'<object width="650" height="402">'+
					'<param name="allowfullscreen" value="true" />'+
					'<param name="allowscriptaccess" value="always" />'+
					'<param name="movie" value="'+movie1+'" />'+
						'<embed '+
							'src="'+movie1+'" '+
							'type="application/x-shockwave-flash" '+
							'allowfullscreen="true" '+
							'allowscriptaccess="always" '+
							'autoplay="true"'+
							'width="650" '+
							'height="402">'+
						'</embed>'+
				'</object>';
    
    
    document.getElementById("movie1").style.display = 'block';
    
}