// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function org_type_options(field) {
  if(field.value == 2) {
    // Show the hidden fields
    new Effect.BlindDown('district-website', {duration: .3});
    new Effect.BlindDown('school-accounts', {duration: .3});
  }
  else {
    // Hide the fields not needed
    new Effect.BlindUp('district-website', {duration: .3});
    new Effect.BlindUp('school-accounts', {duration: .3});
    // Empty out the fields that were hidden
    $('account_purchased_schools').value  = 0;
    $('account_district_website').value   = 0;
  }
}

function add_space_invoice_type(field) {
  if(field.value == 5) {
    // Show the hidden fields
    new Effect.BlindDown('billing-info', {duration: .3});
  }
  else {
    // Hide the fields not needed
    new Effect.BlindUp('billing-info', {duration: .3});
    // Empty out the fields that were hidden
    $('additional_space_address').value = '';
    $('additional_space_city').value    = '';
    $('additional_space_state').value   = '';
    $('additional_space_zip').value     = '';
  }
}


////////////////////////////////
// Admin Resend Emails
function check_resend_email_type(field) {
  if(field.value == 'user') {
    new Effect.BlindDown('user-emails', {duration: .3});
    new Effect.BlindDown('select-user', {duration: .3});
    new Effect.BlindUp('account-emails', {duration: .3});
  }
  else if(field.value == 'account') {
    new Effect.BlindDown('account-emails', {duration: .3});
    new Effect.BlindUp('user-emails', {duration: .3});
    new Effect.BlindUp('select-user', {duration: .3});
  }
}

function update_select_options( target, opts_array, clear_select_list ) {
    if( $(target).type.match("select" ) ){ // Confirm the target is a select box

        // Remove existing options from the target and the clear_select_list
        clear_select_list[clear_select_list.length] = target // Include the target in the clear list

        for( k=0;k < clear_select_list.length;k++){
            obj = $(clear_select_list[k]);
            if( obj.type.match("select") ){
                len = obj.childNodes.length;
                for( var i=0;i < len;i++){obj.removeChild(obj.firstChild);}
            }
        }

        // Populate the new options
        for(i=0;i < opts_array.length;i++){
            o = document.createElement( "option" );
            o.appendChild( document.createTextNode( opts_array[i][0] ) );
            o.setAttribute( "value", opts_array[i][1] );
            obj.appendChild(o);
        }
    }
}
////////////////////////////////

////////////////////////////////
// Admin Invoice Update
// - Don't allow both `paid` and `void` to both be selected
function invoice_paid() {
  invoice_void = $('invoice_void');
  invoice_void.checked = false;
}
function invoice_void() {
  invoice_paid = $('invoice_paid');
    invoice_paid.checked = false;
}
////////////////////////////////

function deny_account_email() {
  no_email = $('no_email');
  if(no_email.checked == true) {
    new Effect.BlindUp('notes', {duration: .3});
    new Effect.BlindUp('message', {duration: .3});    
	} else {
    new Effect.BlindDown('notes', {duration: .3});
    new Effect.BlindDown('message', {duration: .3});    
	}
}
