// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

//-------------------------------------------------------- LowPro/Prototype Behaviors
// http://www.danwebb.net/lowpro

  // Behavior that ajaxifies will_paginate links
  //Event.addBehavior.reassignAfterAjax = true;
  //Event.addBehavior({
  //  'div#ajax_pagination a' : Remote.Link
  //})

//-------------------------------------------------------- String utilities

String.prototype.trim = function() {
    return this.replace(/^\s*|\s*$/g, "");
}

function isStringEmpty(string) {
    if (string == null)
        return true;
    else {
        var str = string.trim();        
        if (str.length == 0)
            return true;
        else
            return false;
    }
}

//-------------------------------------------------------- Form utilities

function openFulfillment(login) {
	var url = "http://fbc.qimarketplace.com/splash.php";
	var elements_hash = new Hash();
	elements_hash.set('FBCUID', login);
	
	postFormToUrl(url, elements_hash);
}

/**
 * Setup submission form url to post elements_hash to Fulfillment
*/
function postFormToUrl(url, elements_hash) {
	var form = new Element('form');
	form.id = "form_post_to_url"
	form.action = url;
	form.method = 'post';
	form.style.display = 'none';

	document.body.appendChild(form);

	elements_hash.keys().each(function(key) {
		var input = new Element('input');
		input.type = 'hidden';
		input.name = key;
		input.value = elements_hash.get(key);

		var f = $('form_post_to_url');
		f.elements[f.elements.length] = input;
	});

	var f = $('form_post_to_url');
	f.submit();
}

/**
 * Clears all of the fields on the member search form
 */
function resetMemberSearchForm() {
    $('fq_state').selectedIndex = 0;
    $('fq_location_id').selectedIndex = 0;
    $('fq_activity_type_id').selectedIndex = 0;
    $('fq_boat_class_id').selectedIndex = 0;
    $('fq_keywords').value = '';
}

/**
 * Called from a <select> control where
 * the value of the options are URLs.
 * Switches to the selected URL.
 */
function changeLink(selector) {
    selIndex = selector.selectedIndex;
    if (selIndex > 0) {
        url = selector.options[selIndex].value;
        window.location = url;
    }
}

/** 
* Clears all the checkboxes in the array of checkboxes.
* @param checkboxArray - the DOM reference to the checkbox array.
*/
function clearAllCheckboxes(checkboxArray) {
    if (checkboxArray == null) {
        return;
    }
    if(checkboxArray.length != null) {
        for (i = 0; checkboxArray.length > i; i++) {
            checkboxArray[i].checked = false;
        }
    }
    else {
        checkboxArray.checked = false;
    }
}

/** 
* Selects all the checkboxes in the array of checkboxes.
* @param checkboxArray - the DOM reference to the checkbox array.
*/
function selectAllCheckboxes(checkboxArray) {
    if (checkboxArray == null) {
        alert("No checkboxes found.");
        return;
    }
    if(checkboxArray.length != null) {
        for (i = 0; checkboxArray.length > i; i++) {
            checkboxArray[i].checked = true;
        }
    }
    else {
        checkboxArray.checked = true;
    }
}

/**
* Returns an array of IDs, or an empty array
* if none of the checkboxes were checked.
*/
function getSelectedCheckboxValues(checkboxArray) {
    var values = new Array();
    if (checkboxArray == null) {
        alert("No checkboxes found.");
        return values;
    }
    if (checkboxArray.length != null) {
        for (i = 0; checkboxArray.length > i; i++) {
            if (checkboxArray[i].checked == true) {
                values.push(checkboxArray[i].value);
            }
        }
    }
    else {
        if (checkboxArray.checked == true) {
            values.push(checkboxArray.value);
        }
    }
    return values;
}

/**
 * Called when the select list of location states
 * is changed, limits the location selector to 
 * only those that are in the selected state.
 */
function updateLocationSelectNav() {
    
}

function clear_textbox() {
	if (document.homeLoginBlock.login.value == "Username")
	document.homeLoginBlock.login.value = "";
}


function validateForm(form) {
	
	
	/*if (form == 'new_info_request') {
		alert(document.getElementById('info_request_name').val());
		return false;
		var name = document.getElementById('info_request_name').val();
		var name = $('#info_request_name').val();
		var email = $('#info_request_email').val();
		var phone = $('#info_request_phone').val();
		
		var error = '';
		if (name == '') { error += "<li>The <strong>name</strong> field cannot be blank.</li>" }
		if (email == '') { error += "<li>The <strong>email</strong> field cannot be blank.</li>" }
		if (phone == '') { error += "<li>The <strong>phone</strong> field cannot be blank.</li>" }
		
		if (error != '') {
			$('#new_info_request_error').html("<strong>Error:</strong><ul>" + error + "</ul>").show();
			return false;
		} else {
			return true;
		}
		// <b>Error:</b> <?php echo $form_error ?>
	}
	
	return true; */
	
	//info_request_name
	//info_request_email
	//info_request_phone
	
}
