////////////////////////////////////////////////////////////////////////////////////////
//
//          FORM VALIDATION HELPERS
//
////////////////////////////////////////////////////////////////////////////////////////

var selectedInterests;
function forceUniqueInterests( interestSelectors ){
  
  selectedInterests = new Array();
  
  //Removes an interest from all interest selectors except the selector with
  //the given selector index
  function removeInterestsFromAllExcept(interest, selectorIx){
    //Remove current value from other selectors
    if(interest != null && interest != "" && interest != "Other"){
      $(interestSelectors).each(function(j){
        if(j != selectorIx){
          var thisWidth = $(this).outerWidth();
          $(this).find("option").each(function(){
            if( $(this).text() == interest){
              $(this).remove();
            }
          });
          // IE7 has problems with removing items from a select field, we need to reset the width
          if($.browser.msie && parseInt($.browser.version) < 8){
            $(this).css("width", thisWidth + "px");
          }
        }
      })
    }
  }
  
  $(interestSelectors).each(function(i){
    
    var currentValue = $(this).val();
    selectedInterests.push( currentValue );
    
    //Remove current value from other selectors
    removeInterestsFromAllExcept(currentValue, i);
    
    //When a selection has changed...
    $(this).change(function(){
      var newValue = $(this).val();
      
      //Add old value back to all selectors
      if( selectedInterests[i] != null && selectedInterests[i] != ""){
        $(interestSelectors).each(function(j){
          if(i != j && selectedInterests[i] != "Other"){
            $(this).find("option:first").after("<option>" + selectedInterests[i] + "</option>");
          }
        })
      }
      
      selectedInterests[i] = newValue;
      
      if(newValue == "Other"){
        //If 'Other' is selected, clear the textfield
        $(this).parent().find("input.fieldbox").val("");
      }else{
        //Remove new value from other selectors
        removeInterestsFromAllExcept(newValue, i);
      }
    })
  })
}

function findFormByAction(action){
  var form = null;
  $("#f_signup").each(function(){
    if($(this).attr("action").indexOf(action) == 0){
      form = $(this);
    }
  })
  
  return form;
}

// Makes URLs valid when losing focus
function makeValidURLsOnFocusOut(){
  $("input.validURL").blur(function(){
    if($(this).val() != ""){
      $(this).val(makeValidURL($(this).val()));
    }
  })
}

// Ensures URLs begin with "http://"
function makeValidURL(url){
  url = url.replace(/http:\/\//gi,"")
  url = "http://" + url;
  return url;
}

function hideHiddenFieldsInForm(form){
  $(form).find("input").each(function(){
    if( $(this).attr("type") == "hidden" ){
      $(this).attr("name",$(this).attr("name") + "-ignore")
    }
  })
}

function unhideHiddenFieldsInForm(form){
  $(form).find("input").each(function(){
    if( $(this).attr("type") == "hidden" ){
      $(this).attr("name", $(this).attr("name").substring(0, $(this).attr("name").lastIndexOf("-ignore")))
    }
  })
}

function removeErrorNotice(){
  $("#content .errorExplanation").remove()
}

function showErrorNotice(error){
  //Only handle the first error message
  if($("#content .errorExplanation").length <= 0){
    //Add error message to notice DIV
    $("#content").prepend("<div class='errorExplanation'></div>")
    //error.appendTo($("#content .errorExplanation"))
    $("#content .errorExplanation").append(error);
  }
  //Scroll to the error message
  $.scrollTo($("#content .errorExplanation"));
}

function hasExceedWordMax(element,word_count){
  //Get value of element
  var elementValue = getFieldValue(element);

  if(elementValue != null){
    //If word count has been exceeded, return -1
    //?? NOTE: this is a hack that we can't avoid
    var words = elementValue.replace(/\s/g,' ').split(' ');
    var count = 0;
    for(var i = 0; i < words.length; i++){
      if( words[i].length > 0 ){
        count ++;
      }
    }

    if(count > word_count){
      return -1;
    }else{
      return false
    }
  }
}

function getFieldValue(element){
  //Get value of element
  var elementValue = null
  if($(element).val != null){
    elementValue = $(element).val()
  }else if($(element).text != null){
    elementValue = $(element).text()
  }
  
  if(elementValue == ""){
    elementValue = null;
  }
  
  return elementValue;
}

function validateAddAnother(container){
  
  var addRemoveElements = $(container).find(".remove:visible");
  if(addRemoveElements.length <= 0){
    return false;
  }else{
    var hasValue = false
    
    //Try to find a form element with a value
    $(addRemoveElements).each(function(){
      
      //Get all input fields that are not hidden
      var fields = $(this).find("input,select").filter(function(i){
        if($(this).attr("type") == "hidden"){
          return false;
        }else{
          return true;
        }
      });
      
      //Check if any of the fields have a value
      $(fields).each(function(){
        if( getFieldValue($(this)) != null ){
          hasValue = true;
        }
      });
    });
    
    //If a value was found, then validation was successful
    return hasValue;
  }
}

function validateExistenceOfOne(fields){
  
  if(fields.length <= 0){
    return true;
  }
  
  var valid = false;
  $(fields).each(function(){
    var value = getFieldValue($(this));
    if(value != null){
      return valid = true;
    }
  });
  
  return valid;
}

function validateExistenceOfAll(fields){
  
  var valid = true;
  $(fields).each(function(){
    var value = getFieldValue($(this));
    if(value == null){
      return valid = false;
    }
  });
  
  return valid;
}

function validateWordCountOfAll(fields,count){
  
  var valid = true;
  $(fields).each(function(){
    var value = getFieldValue($(this));
    if(hasExceedWordMax($(this),count) == -1){
      valid = false;
    }
  });
  
  return valid;
}

function makeRulesForNameFields(fields, position_name){
  
  $(fields).each(function(){
    $(this).rules("add", {
     required: {
       depends: function(element){
         return $(element).is(':visible');
       }
     },
     messages: {
       required: "Please enter " + position_name + "'s name"
     }
    });
  })
};

function makeRulesForGenericFields(fields, position_name, field_name){
  
  var message = "";
  if(position_name !== null && position_name != ""){
    message = message + "Please enter " + position_name + "'s " + field_name;
  }else{
    message = message + "Please enter " + field_name;
  }
  
  $(fields).each(function(){
    $(this).rules("add", {
     required: {
       depends: function(element){
         return $(element).is(':visible');
       }
     },
     messages: {
       required: message
     }
    });
  })
};

function makeRulesForGenericRadios(fields, position_name, field_name){
  
  $(fields).each(function(){
    $(this).rules("add", {
     required: {
       depends: function(element){
         return $(element).is(':visible');
       }
     },
     messages: {
       required: "Please select " + position_name + "'s " + field_name
     }
    });
  })
};

function makeRulesForBioFields(fields, position_name, word_count){
  
  $(fields).each(function(){
    $(this).rules("add", {
      required: {
        depends: function(element){
          return $(element).is(':visible');
        }
      },
     max: {
       depends: function(element){
         if( $(element).is(':visible') ){
            return hasExceedWordMax(element,word_count);
         }else{
            return false;
         }
       }
     },
     messages: {
       required: "Please enter " + position_name + "'s biography",
       max: "Biography for " + position_name + " can not exceed " + word_count + " words"
     }
    });
  });
  
};

function makeRulesForEmailFields(fields, position_name){

  $(fields).each(function(){
    $(this).rules("add", {
      required: {
        depends: function(element){
          return $(element).is(':visible');
        }
      },
     email: {
        depends: function(element){
          return $(element).is(':visible');
        }
     },
     messages: {
       required: "Please enter " + position_name + "'s email address",
       email: "Please enter a valid email address for " + position_name
     }
    });
  });

};

////////////////////////////////////////////////////////////////////////////////////////
//
//          CONFERENCE FORM VALIDATIONS
//
////////////////////////////////////////////////////////////////////////////////////////

function validateConferenceRegisterForm(){
  
  // Find the conference registration form
  var conferenceRegForm = findFormByAction("/conference/registration/details");
  if(conferenceRegForm === null){
    conferenceRegForm = findFormByAction("/conference/registration/additional_purchase");
  }
  
  // If the profile creation form exists...
  if(conferenceRegForm !== null){
    
    //Ignore hidden input fields 
    hideHiddenFieldsInForm(conferenceRegForm);
    
    //Enforce unique interests
    var selectors = $("#conference_register_area_of_interest_1, #conference_register_area_of_interest_2, #conference_register_area_of_interest_3");
    forceUniqueInterests(selectors);

    // Validate form
    $(conferenceRegForm).validate({

      //Handles the event in which a form is submitted
      submitHandler: function(form) {
        //No longer ignore hidden input fields
        unhideHiddenFieldsInForm(form);
        //Submit form
        form.submit();
      },
      
      focusInvalid: false,
      onfocusout: false,
      onkeyup: false,
      onclick: false,
      errorClass: "invalidField",
  
      //Required fields
      rules: { 
          "conference[type]": { 
              required: true
          }, 
          "conference[tc]": {
              required: true
          },
          "conference_register[first_name]": {
              required: true
          },
          "conference_register[last_name]": {
              required: true
          },
          "conference_register[email]": {
              required: true,
              email: true
          },
          "conference_register[email_confirmation]": {
              required: true,
              equalTo: "#conference_register_email"
          },
          "conference_register[job_title]": {
              required: true
          },
          "conference_register[company_name]": {
              required: true
          },
          "conference_register[icon]": {
              required: true,
              accept: "png|jpe?g|gif"
          },
          "conference_register[short_bio]": {
              required: true,
              max: {
                //This is a hack but it works
                depends: function(element){
                  return hasExceedWordMax(element,150);
                }
              }
          },
          "conference_register[area_of_interest_1]": {
              required: true
          },
          "area[of_interest_1]": {
              required: {
                depends: function(element) {
                  return $(element).parent().parent().find("select").val() == "Other";
                }
              }
          },
          "area[of_interest_2]": {
              required: {
                depends: function(element) {
                  return $(element).parent().parent().find("select").val() == "Other";
                }
              }
          },
          "area[of_interest_3]": {
              required: {
                depends: function(element) {
                  return $(element).parent().parent().find("select").val() == "Other";
                }
              }
          },
          "conference_register[address1]": {
              required: true
          },
          "conference_register[city]": {
              required: true
          },
          "conference_register[state]": {
              required: true
          },
          "conference_register[zip]": {
              required: true
          },
          "conference_register[phone]": {
              required: true
          },
          "conference_register[delegate_type]": {
              required: true
          },
          "conference[delegate_type]": {
              required: {
                depends: function(element) {
                  return $(element).parent().parent().find("select").val() == "Other";
                }
              }
          }

      },

      //Error messages
      messages: { 
          "conference[type]": { 
              required: "Please select conference type"
          }, 
          "conference[tc]": {
              required: "You must agree to the terms and conditions"
          },
          "conference_register[first_name]": {
              required: "Please enter first name"
          },
          "conference_register[last_name]": {
              required: "Please enter last name"
          },
          "conference_register[email]": {
              required: "Please enter valid email address",
              email: "Email address must be valid"
          },
          "conference_register[email_confirmation]": {
              required: "Please confirm the email address",
              equalTo: "Email doesn't match confirmation"
          },
          "conference_register[job_title]": {
              required: "Please enter job title"
          },
          "conference_register[company_name]": {
              required: "Please enter name of company"
          },
          "conference_register[icon]": {
              required: "Please select a profile image",
              accept: "Please select image of type PNG, JPG or GIF"
          },
          "conference_register[short_bio]": {
              required: "Please enter a short biography",
              max: "Biography is too long, maximum 150 words"
          },
          "conference_register[area_of_interest_1]": {
              required: "Please select an area of interest"
          },
          "area[of_interest_1]": {
              required: "Please enter area of interest"
          },
          "area[of_interest_2]": {
              required: "Please enter area of interest"
          },
          "area[of_interest_3]": {
              required: "Please enter area of interest"
          },
          "conference_register[address1]": {
              required: "Please enter address of registrant"
          },
          "conference_register[city]": {
              required: "Please enter registrant's city of residence"
          },
          "conference_register[state]": {
              required: "Please enter registrant's state of residence"
          },
          "conference_register[zip]": {
              required: "Please enter registrant's postal/zip code"
          },
          "conference_register[phone]": {
              required: "Please enter registrant's phone number"
          },
          "conference_register[delegate_type]": {
              required: "Please select registrant's delegate type"
          },
          "conference[delegate_type]": {
              required: "Please enter registrant's delegate type"
          }
      },
      
      //Handles the event in which a form fails to validate
      invalidHandler: function(form, validator) {
        removeErrorNotice();
      },

      //Handles the placement of error messages on the page
      errorPlacement: function(error, element) {
        showErrorNotice(error);
      }
    });
  }
}

////////////////////////////////////////////////////////////////////////////////////////
//
//          F4 FORM VALIDATIONS
//
////////////////////////////////////////////////////////////////////////////////////////

function validateF4RegisterForm(){
  
  // Find the conference registration form
  var F4RegForm = $("form.edit_submission");
  
  // If the registration form exists...
  if(F4RegForm !== null){
    
    //Ignore hidden input fields 
    hideHiddenFieldsInForm(F4RegForm);
    
    // Add dynamic fields before submission
    var submitButton = $(F4RegForm).find(".controls input").filter(function(){
      return $(this).val() == "Next";
    });
    
    $(submitButton).unbind();
    $(submitButton).click(function(){
      
      makeRulesForNameFields( $(".validate_director_name"), "director");
      makeRulesForBioFields( $(".validate_director_bio"), "director", 150);
      makeRulesForEmailFields( $(".validate_director_email"), "director");
      makeRulesForGenericFields( $(".validate_director_mobile"), "director","mobile phone number");
      makeRulesForGenericFields( $(".validate_director_credits"), "director","credits");
      
      makeRulesForNameFields( $(".validate_team_name"), "production team");
      makeRulesForGenericFields( $(".validate_team_role"), "production team","role");
      makeRulesForBioFields( $(".validate_team_bio"), "production team", 150);
      
    });
    
    // Validate form
    var validator = $(F4RegForm).validate({

      //Handles the event in which a form is submitted
      submitHandler: function(form) {
        removeErrorNotice();
        //No longer ignore hidden input fields
        unhideHiddenFieldsInForm(form);
        //Submit form
        form.submit();
      },
      
      focusInvalid: false,
      onfocusout: false,
      onkeyup: false,
      onclick: false,
      errorClass: "invalidField",
  
      //Required fields
      rules: { 
          "submission[title]": { 
              required: true
          }, 
          "submission[logline]": {
              required: true,
              max: {
                depends: function(element){
                  return hasExceedWordMax(element,30);
                }
              }
          },
          "submission[synopsis]": {
              required: true,
              max: {
                depends: function(element){
                  return hasExceedWordMax(element,200);
                }
              }
          },
          "submission[submission_name]": {
              required: true
          },
          "submission[submission_role]": {
              required: true
          },
          "submission[submission_email]": {
              required: true,
              email: true
          },
          "submission[submission_mobile]": {
              required: true
          },
          "submission[submission_address_1]": {
              required: true
          },
          "submission[submission_suburb]": {
              required: true
          },
          "submission[submission_postcode]": {
              required: true
          },
          "submission[submission_state]": {
              required: true
          },
          "submission[date_of_completion]": {
              required: true
          },
          "submission[country_of_production]": {
              required: true
          },
          "submission[country_co_productions_attributes][0][country]": {
            required: {
              //?? HACK: Tests that atleast ONE country of co production was selected
              depends: function(element){
                return !validateAddAnother($("#add_remove_country_co_productions:visible"));
              }
            }
          },
          "submission[country_films_attributes][0][country]": {
            required: {
              //?? HACK: Tests that atleast ONE country of filming was selected
              depends: function(element){
                return !validateAddAnother($("#add_remove_country_films:visible"));
              }
            }
          },
          "submission[duration]": {
              required: true
          },
          "submission[shooting_format]": {
              required: true
          },
          "submission[screening_format][]": {
              required: true
          },
          "submission[colour_format][]": {
              required: true
          },
          "submission[aspect_ratio][]": {
              required: true
          },
          "submission[previous_screenings]": {
              required: true
          }
      },

      //Error messages
      messages: { 
          "submission[title]": { 
              required: "Please enter the title of the story"
          }, 
          "submission[logline]": {
              required: "Please enter a logline"
          },
          "submission[synopsis]": {
              required: "Please enter a synopsis of the story",
              max: "Synopsis may not exceed 200 words"
          },
          "submission[submission_name]": {
              required: "Please enter name of submission contact"
          },
          "submission[submission_role]": {
              required: "Please enter role of submission contact"
          },
          "submission[submission_email]": {
              required: "Please enter email address of submission contact",
              email: "Please enter valid email address of submission contact"
          },
          "submission[submission_mobile]": {
              required: "Please enter mobile phone number of submission contact"
          },
          "submission[submission_address_1]": {
              required: "Please enter address of submission contact"
          },
          "submission[submission_suburb]": {
              required: "Please enter suburb of submission contact"
          },
          "submission[submission_postcode]": {
              required: "Please enter postcode of submission contact"
          },
          "submission[submission_state]": {
              required: "Please enter state of submission contact"
          },
          "submission[date_of_completion]": {
              required: "Please select date of completion"
          },
          "submission[country_of_production]": {
              required: "Please select country of production"
          },
          "submission[country_co_productions_attributes][0][country]": {
              required: "Please select a country of co production"
          },
          "submission[country_films_attributes][0][country]": {
              required: "Please select a country of filming"
          },
          "submission[duration]": {
              required: "Please enter duration of film"
          },
          "submission[shooting_format]": {
              required: "Please enter shooting format of film"
          },
          "submission[screening_format][]": {
              required: "Please select a screening format"
          },
          "submission[colour_format][]": {
              required: "Please select a colour format"
          },
          "submission[aspect_ratio][]": {
              required: "Please select an aspect ratio"
          },
          "submission[previous_screenings]": {
              required: "Please enter previous screenings"
          }
      },
      
      //Handles the event in which a form fails to validate
      invalidHandler: function(form, validator) {
        removeErrorNotice();
      },

      //Handles the placement of error messages on the page
      errorPlacement: function(error, element) {
        showErrorNotice(error);
      }
    });
  }
}

////////////////////////////////////////////////////////////////////////////////////////
//
//          MEETMARKET FORM VALIDATIONS
//
////////////////////////////////////////////////////////////////////////////////////////

function validateMeetmarketRegisterForm(){
  
  // Find the conference registration form
  var MeetmarketRegForm = $("form.edit_meetmarket");
  
  // If the profile creation form exists...
  if(MeetmarketRegForm !== null){
    
    //Ignore hidden input fields 
    hideHiddenFieldsInForm(MeetmarketRegForm);
    
    showTextAreaIfTrue( "meetmarket[broadcaster_attached]" );
    showTextAreaIfTrue( "meetmarket[distributor_sales_agent]" );
    
    // Add dynamic fields before submission
    var submitButton = $(MeetmarketRegForm).find(".controls input").filter(function(){
      return $(this).val() == "Next";
    });
    
    $(submitButton).unbind();
    $(submitButton).click(function(){
      
      makeRulesForNameFields( $(".validate_producer_name"), "producer");
      makeRulesForBioFields( $(".validate_producer_bio"), "producer", 100);
      makeRulesForNameFields( $(".validate_director_name"), "director");
      makeRulesForBioFields( $(".validate_director_bio"), "director", 100);
      makeRulesForNameFields( $(".validate_writer_name"), "writer");
      makeRulesForBioFields( $(".validate_writer_bio"), "writer", 100);
      
    });
    
    // Validate form
    var validator = $(MeetmarketRegForm).validate({

      //Handles the event in which a form is submitted
      submitHandler: function(form) {
        removeErrorNotice();
        //No longer ignore hidden input fields
        unhideHiddenFieldsInForm(form);
        //Submit form
        form.submit();
      },
      
      focusInvalid: false,
      onfocusout: false,
      onkeyup: false,
      onclick: false,
      errorClass: "invalidField",
  
      //Required fields
      rules: { 
          "meetmarket[mobile]": {
              required: true
          },
          "meetmarket[title]": { 
              required: true
          }, 
          "meetmarket[logline]": {
              required: true
          },
          "meetmarket[ssynopsis]": {
              required: true,
              max: {
                //This is a hack but it works
                depends: function(element){
                  return hasExceedWordMax(element,100);
                }
              }
          },
          "meetmarket[lsynopsis]": {
              required: true,
              max: {
                //This is a hack but it works
                depends: function(element){
                  return hasExceedWordMax(element,500);
                }
              }
          },
          "meetmarket[genre][]": {
              required: true
          },
          "meetmarket[countryproduction]": {
              required: true
          },
          "meetmarket[shooting_format]": {
              required: true
          },
          "meetmarket[estimated_length]": {
              required: true
          },
          "meetmarket[estimated_release]": {
              required: true
          },
          "meetmarket[country_co_productions_attributes][0][country]": {
              required: {
                //?? HACK: Tests that atleast ONE country of co production was selected
                depends: function(element){
                  return !validateAddAnother($("#add_remove_country_co_productions:visible"));
                }
              }
          },
          "meetmarket[country_films_attributes][0][country]": {
            required: {
              //?? HACK: Tests that atleast ONE country of filming was selected
              depends: function(element){
                return !validateAddAnother($("#add_remove_country_films:visible"));
              }
            }
          },
          "meetmarket[production_companies_attributes][0][name]": {
            required: {
              //?? HACK: Tests that atleast ONE production company exists
              depends: function(element){
                return !validateExistenceOfOne($(".validate_production_company:visible"));
              }
            }
          },
          "meetmarket[total_budget]": {
            required: true,
            number: true
          },
          "meetmarket[amount_still_required]": {
            required: true,
            number: true
          },
          "meetmarket[broadcaster_attached]": {
            required: true
          },
          "meetmarket[distributor_sales_agent]": {
            required: true
          },
          "meetmarket[broadcaster_details]": {
            required: {
              depends: function(element){
                var checked = $("input[name='meetmarket[broadcaster_attached]']:checked").val();
                return checked == "true";
              }
            }
          },
          "meetmarket[distributor_sales_agent_details]": {
            required: {
              depends: function(element){
                var checked = $("input[name='meetmarket[distributor_sales_agent]']:checked").val();
                return checked == "true";
              }
            }
          },
          "meetmarket[additional_financial_source]": {
            required: true
          }
      },

      //Error messages
      messages: { 
          "meetmarket[mobile]": { 
              required: "Please enter a mobile number"
          },
          "meetmarket[title]": { 
              required: "Please enter the title of the story"
          }, 
          "meetmarket[logline]": {
              required: "Please enter a logline"
          },
          "meetmarket[ssynopsis]": {
              required: "Please enter a short synopsis of the story",
              max: "Short synopsis may not exceed 100 words"
          },
          "meetmarket[lsynopsis]": {
              required: "Please enter a longer synopsis of the story",
              max: "Long synopsis may not exceed 500 words"
          },
          "meetmarket[genre][]": {
              required: "Please select a genre that fits the story"
          },
          "meetmarket[countryproduction]": {
              required: "Please select the country of production"
          },
          "meetmarket[shooting_format]": {
              required: "Please enter the shooting format"
          },
          "meetmarket[estimated_length]": {
              required: "Please enter an estimated length"
          },
          "meetmarket[estimated_release]": {
              required: "Please select an estimated release date"
          },
          "meetmarket[country_co_productions_attributes][0][country]": {
              required: "Please select a country of co production"
          },
          "meetmarket[country_films_attributes][0][country]": {
              required: "Please select a country of filming"
          },
          "meetmarket[production_companies_attributes][0][name]": {
              required: "Please enter a production company"
          },
          "meetmarket[total_budget]": {
            required: "Please enter the total budget",
            number: "Budget must be a number"
          },
          "meetmarket[amount_still_required]": {
            required: "Please enter the amount still required",
            number: "Amount must be a number"
          },
          "meetmarket[broadcaster_attached]": {
            required: "Please select if a broadcaster is attached"
          },
          "meetmarket[distributor_sales_agent]": {
            required: "Please select if distributors or sale agents are committed to the project"
          },
          "meetmarket[broadcaster_details]": {
            required: "Please enter broadcaster details"
          },
          "meetmarket[distributor_sales_agent_details]": {
            required: "Please enter distributor/sales agent details"
          },
          "meetmarket[additional_financial_source]": {
              required: "Please list any additional secured third party funding"
          }
      },
      
      //Handles the event in which a form fails to validate
      invalidHandler: function(form, validator) {
        removeErrorNotice();
      },

      //Handles the placement of error messages on the page
      errorPlacement: function(error, element) {
        showErrorNotice(error);
      }
    });
  }
}

////////////////////////////////////////////////////////////////////////////////////////
//
//          PROFILE FORM VALIDATIONS
//
////////////////////////////////////////////////////////////////////////////////////////

function validateProfileForm(){
  
  // Find the profile creation form
  var profileForm = findFormByAction("/profiles");
  
  // If the profile creation form exists...
  if(profileForm !== null){
    
    //Ignore hidden input fields 
    hideHiddenFieldsInForm(profileForm);
    
    //Enforce unique interests
    var selectors = $("#profile_area_of_interest_1, #profile_area_of_interest_2, #profile_area_of_interest_3");
    forceUniqueInterests(selectors);

    // Validate form
    $(profileForm).validate({

      //Handles the event in which a form is submitted
      submitHandler: function(form) {
        //No longer ignore hidden input fields
        unhideHiddenFieldsInForm(form);
        //Submit form
        form.submit();
      },

      focusInvalid: false,
      onfocusout: false,
      onkeyup: false,
      onclick: false,
      errorClass: "invalidField",

      //Required fields
      rules: { 
          "profile[first_name]": {
              required: true
          },
          "profile[last_name]": {
              required: true
          },
          "user[email]": {
              required: true,
              email: true
          },
          "user[email_confirmation]": {
              required: true,
              equalTo: "#user_email"
          },
          "profile[job_title]": {
              required: true
          },
          "profile[company_name]": {
              required: true
          },
          "profile[icon]": {
              required: {
                //If the default profile  image is displayed, this field is required.
                depends: function(element){
                  var profileImage = $(element).parent().find("img:first");
                  if(profileImage.length <= 0){
                    return true;
                  }else if($(profileImage).attr("alt") == "Default_profile"){
                    return true;
                  }else{
                    return false;
                  }
                }
              },
              accept: "png|jpe?g|gif|bmp|tiff"
          },
          "profile[short_bio]": {
              required: true,
              max: {
                //This is a hack but it works
                depends: function(element){
                  return hasExceedWordMax(element,150);
                }
              }
          },
          "profile[area_of_interest_1]": {
              required: true
          },
          "area[of_interest_1]": {
              required: {
                depends: function(element) {
                  return $(element).parent().parent().find("select").val() == "Other";
                }
              }
          },
          "area[of_interest_2]": {
              required: {
                depends: function(element) {
                  return $(element).parent().parent().find("select").val() == "Other";
                }
              }
          },
          "area[of_interest_3]": {
              required: {
                depends: function(element) {
                  return $(element).parent().parent().find("select").val() == "Other";
                }
              }
          },
          "profile[terms_and_conditions]": {
              required: true
          }
      },

      //Error messages
      messages: { 
          "profile[first_name]": {
              required: "Please enter first name"
          },
          "profile[last_name]": {
              required: "Please enter last name"
          },
          "user[email]": {
              required: "Please enter valid email address",
              email: "Email address must be valid"
          },
          "user[email_confirmation]": {
              required: "Please confirm the email address",
              equalTo: "Email doesn't match confirmation"
          },
          "profile[job_title]": {
              required: "Please enter job title"
          },
          "profile[company_name]": {
              required: "Please enter name of company"
          },
          "profile[icon]": {
              required: "please select a profile photo",
              accept: "Please select image of type PNG, JPG, JPEG, BMP, TIFF or GIF"
          },
          "profile[short_bio]": {
              required: "Please enter a short biography",
              max: "Biography is too long, maximum 150 words"
          },
          "profile[area_of_interest_1]": {
              required: "Please select at least one area of interest"
          },
          "area[of_interest_1]": {
              required: "Please enter area of interest"
          },
          "area[of_interest_2]": {
              required: "Please enter area of interest"
          },
          "area[of_interest_3]": {
              required: "Please enter area of interest"
          },
          "profile[terms_and_conditions]": {
              required: "You must agree to the terms and conditions of DocExchange"
          }
      },

      //Handles the event in which a form fails to validate
      invalidHandler: function(form, validator) {
        removeErrorNotice();
      },

      //Handles the placement of error messages on the page
      errorPlacement: function(error, element) {
        showErrorNotice(error);
      }
    });
  }
}

////////////////////////////////////////////////////////////////////////////////////////
//
//          SCIENCE EXCHANGE FORM VALIDATIONS
//
////////////////////////////////////////////////////////////////////////////////////////

function validateScienceExchangeForm(){
  
    // Find the science exchange form
    var scienceExForm = $(".edit_science_exchange");

    // If the trailer park form exists...
    if(scienceExForm !== null){

      //Ignore hidden input fields 
      hideHiddenFieldsInForm(scienceExForm);

      showTextAreaIfTrue( "science_exchange[represent_company_institution]" );

      // Add dynamic fields before submission
      var submitButton = $(scienceExForm).find(".controls input").filter(function(){
        return $(this).val() == "Next";
      });

      $(submitButton).unbind();
      $(submitButton).click(function(){

        makeRulesForNameFields( $(".validate_subteam_name"), "contact");
        makeRulesForBioFields( $(".validate_subteam_bio"), "contact", 100);
        makeRulesForGenericFields( $(".validate_subteam_job"), "contact", "job title");
        makeRulesForGenericFields( $(".validate_subteam_organisation"), "contact", "organisation");
        makeRulesForGenericFields( $(".validate_subteam_website"), "contact", "website");
        makeRulesForGenericFields( $(".validate_subteam_pub"), "contact", "recent relevant publications");
        makeRulesForGenericFields( $(".validate_subteam_nomin"), "contact", "nominations");
        makeRulesForGenericFields( $(".validate_subteam_awards"), "contact", "awards");
        makeRulesForGenericFields( $(".validate_subteam_ria"), "contact", "Royal Institution of Australia membership");

      });

      // Validate form
      $(scienceExForm).validate({

        //Handles the event in which a form is submitted
        submitHandler: function(form) {
          //No longer ignore hidden input fields
          unhideHiddenFieldsInForm(form);

          //Submit form
          form.submit();
        },

        focusInvalid: false,
        onfocusout: false,
        onkeyup: false,
        onclick: false,
        errorClass: "invalidField",

        //Required fields
        rules: { 
            "science_exchange[theme]": {
                required: true
            },
            "science_exchange[first_name]": {
                required: true
            },
            "science_exchange[last_name]": {
                required: true
            },
            "science_exchange[email]": {
                required: true,
                email: true
            },
            "science_exchange[email_confirmation]": {
                required: true,
                equalTo: "#science_exchange_email"
            },
            "science_exchange[job_title]": {
                required: true
            },
            "science_exchange[organisation]": {
                required: true
            },
            "science_exchange[address_1]": {
                required: true
            },
            "science_exchange[suburb]": {
                required: true
            },
            "science_exchange[state_region]": {
                required: true
            },
            "science_exchange[post_code]": {
                required: true
            },
            "science_exchange[phone_number]": {
                required: true
            },
            "science_exchange[mobile_number]": {
                required: true
            },
            "science_exchange[short_description]": {
              required: true,
              max: {
                depends: function(element){
                  return hasExceedWordMax(element,50);
                }
              }
            },
            "science_exchange[outline]": {
              required: true,
              max: {
                depends: function(element){
                  return hasExceedWordMax(element,1000);
                }
              }
            },
            "science_exchange[represent_company_institution]": {
              required: true
            },
            "science_exchange[represent_company_institution_info]": {
              required: {
                depends: function(element){
                  var checked = $("input[name='science_exchange[represent_company_institution]']:checked").val();
                  return checked == "true";
                }
              },
              max: {
                depends: function(element){
                  return hasExceedWordMax(element,200);
                }
              }
            },
            "science_exchange[company_institution_website]": {
                required: true
            },
            "science_exchange[supporting_statement]": {
                required: true,
                max: {
                  depends: function(element){
                    return hasExceedWordMax(element,100);
                  }
                }
            },
            "science_exchange[image1_title]": {
                required: true
            },
            "science_exchange[image2_title]": {
              required: {
                depends: function(element) {
                  return $("#science_exchange_image2").val() != "";
                }
              }
            },
            "science_exchange[image3_title]": {
              required: {
                depends: function(element) {
                  return $("#science_exchange_image3").val() != "";
                }
              }
            },
            "science_exchange[image4_title]": {
              required: {
                depends: function(element) {
                  return $("#science_exchange_image4").val() != "";
                }
              }
            },
            "science_exchange[image1]": {
                required: true,
                accept: "png|jpe?g|gif|bmp|tiff"
            },
            "science_exchange[image2]": {
                required: {
                  depends: function(element) {
                    return $("#science_exchange_image2_title").val() != "";
                  }
                },
                accept: "png|jpe?g|gif|bmp|tiff"
            },
            "science_exchange[image3]": {
                required: {
                  depends: function(element) {
                    return $("#science_exchange_image3_title").val() != "";
                  }
                },
                accept: "png|jpe?g|gif|bmp|tiff"
            },
            "science_exchange[image4]": {
                required: {
                  depends: function(element) {
                    return $("#science_exchange_image4_title").val() != "";
                  }
                },
                accept: "png|jpe?g|gif|bmp|tiff"
            },
            //?? NOTE: another hack to enusre the details of atelast one image is entered.
            "save[later]-ignore": {
                equalTo: {
                  depends: function(element) {
                    return !validateExistenceOfOne($(".img-title"));
                  }
                }
            }
            
        },

        //Error messages
        messages: {
            "science_exchange[theme]": {
                required: "Please select a theme"
            },
            "science_exchange[first_name]": {
                required: "Please enter first name"
            },
            "science_exchange[last_name]": {
                required: "Please enter last name"
            },
            "science_exchange[email]": {
                required: "Please enter valid email address",
                email: "Email address must be valid"
            },
            "science_exchange[email_confirmation]": {
                required: "Please confirm the email address",
                equalTo: "Email doesn't match confirmation"
            },
            "science_exchange[job_title]": {
                required: "Please enter job title"
            },
            "science_exchange[organisation]": {
                required: "Please enter name of organisation"
            },
            "science_exchange[address_1]": {
                required: "Please enter address"
            },
            "science_exchange[suburb]": {
                required: "Please enter suburb"
            },
            "science_exchange[state_region]": {
                required: "Please enter state/province/region"
            },
            "science_exchange[post_code]": {
                required: "Please enter postal/zip code"
            },
            "science_exchange[phone_number]": {
                required: "Please enter phone number"
            },
            "science_exchange[mobile_number]": {
                required: "Please enter mobile phone number"
            },
            "science_exchange[short_description]": {
                required: "Please enter description of story idea",
                max: "Description may not exceed 50 words"
            },
            "science_exchange[outline]": {
                required: "Please enter outline of proposed story",
                max: "Outline may not exceed 1000 words"
            },
            "science_exchange[represent_company_institution]": {
                required: "If yes, please provide company or institution's profile/biography"
            },
            "science_exchange[represent_company_institution_info]": {
                required: "Please enter company/institution profile/biography",
                max: "Company/institution profile/biography may not exceed 200 words"
            },
            "science_exchange[company_institution_website]": {
                required: "Please enter company/institution website"
            },
            "science_exchange[supporting_statement]": {
                required: "Please enter supporting statement",
                max: "Supporting statement may not exceed 100 words"
            },
            "science_exchange[image1_title]": {
                required: "Please provide a title for image 1"
            },
            "science_exchange[image2_title]": {
                required: "Please provide a title for image 2"
            },
            "science_exchange[image3_title]": {
                required: "Please provide a title for image 3"
            },
            "science_exchange[image4_title]": {
                required: "Please provide a title for image 4"
            },
            "science_exchange[image1]": {
                required: "Please select first image",
                accept: "Please select image of type PNG, JPG, JPEG, BMP, TIFF or GIF"
            },
            "science_exchange[image2]": {
                required: "Please select second image",
                accept: "Please select image of type PNG, JPG, JPEG, BMP, TIFF or GIF"
            },
            "science_exchange[image3]": {
                required: "Please select third image",
                accept: "Please select image of type PNG, JPG, JPEG, BMP, TIFF or GIF"
            },
            "science_exchange[image4]": {
                required: "Please select fourth image",
                accept: "Please select image of type PNG, JPG, JPEG, BMP, TIFF or GIF"
            },
            "save[later]-ignore": {
                equalTo: "Please provide at least one image"
            }
        },

        //Handles the event in which a form fails to validate
        invalidHandler: function(form, validator) {
          removeErrorNotice();
        },

        //Handles the placement of error messages on the page
        errorPlacement: function(error, element) {
          showErrorNotice(error);
        }
      });
    }
}

////////////////////////////////////////////////////////////////////////////////////////
//
//          TRAILERPARK FORM VALIDATIONS
//
////////////////////////////////////////////////////////////////////////////////////////

function validateTrailerParkForm(){
  // Find the profile creation form
  var trailerForm = $(".edit_trailer_park");
  
  // If the trailer park form exists...
  if(trailerForm !== null){
    
    //Ignore hidden input fields 
    hideHiddenFieldsInForm(trailerForm);
    
    showTextAreaIfTrue( "trailer_park[broadcaster_attached]" );
    showTextAreaIfTrue( "trailer_park[distributor_sales_agent]" );
    
    // Add dynamic fields before submission
    // ?? Should replace the other hacks with this (it is slightly better)
    var submitButton = $(trailerForm).find(".controls input").filter(function(){
      return $(this).val() == "Next";
    });
    
    $(submitButton).unbind();
    $(submitButton).click(function(){
      
      makeRulesForNameFields( $(".validate_producer_name"), "producer");
      makeRulesForBioFields( $(".validate_producer_bio"), "producer", 150);
      makeRulesForNameFields( $(".validate_director_name"), "director");
      makeRulesForBioFields( $(".validate_director_bio"), "director", 150);
      makeRulesForNameFields( $(".validate_writer_name"), "writer");
      makeRulesForBioFields( $(".validate_writer_bio"), "writer", 150);
      
    });

    // Validate form
    $(trailerForm).validate({

      //Handles the event in which a form is submitted
      submitHandler: function(form) {
        //No longer ignore hidden input fields
        unhideHiddenFieldsInForm(form);
        
        //Submit form
        form.submit();
      },

      focusInvalid: false,
      onfocusout: false,
      onkeyup: false,
      onclick: false,
      errorClass: "invalidField",

      //Required fields
      rules: { 
          "trailer_park[first_name]": {
              required: true
          },
          "trailer_park[last_name]": {
              required: true
          },
          "trailer_park[email]": {
              required: true,
              email: true
          },
          "trailer_park[email_confirmation]": {
              required: true,
              equalTo: "#trailer_park_email"
          },
          "trailer_park[job_title]": {
              required: true
          },
          "trailer_park[organisation]": {
              required: true
          },
          "trailer_park[address_1]": {
              required: true
          },
          "trailer_park[suburb]": {
              required: true
          },
          "trailer_park[state_region]": {
              required: true
          },
          "trailer_park[post_code]": {
              required: true
          },
          "trailer_park[phone_number]": {
              required: true
          },
          "trailer_park[mobile_number]": {
              required: true
          },
          "trailer_park[project_title]": { 
              required: true
          }, 
          "trailer_park[logline]": {
              required: true
          },
          "trailer_park[synopsis]": {
              required: true,
              max: {
                depends: function(element){
                  return hasExceedWordMax(element,100);
                }
              }
          },
          "trailer_park[genre][]": {
              required: true
          },
          "trailer_park[country_of_production]": {
              required: true
          },
          "trailer_park[country_co_productions_attributes][0][country]": {
              required: {
                //?? HACK: Tests that atleast ONE country of co production was selected
                depends: function(element){
                  return !validateAddAnother($("#add_remove_country_co_productions:visible"));
                }
              }
          },
          "trailer_park[country_films_attributes][0][country]": {
            required: {
              //?? HACK: Tests that atleast ONE country of filming was selected
              depends: function(element){
                return !validateAddAnother($("#add_remove_country_films:visible"));
              }
            }
          },
          "trailer_park[expected_release_date]": {
            required: true
          },
          "trailer_park[language]": {
            required: true
          },
          "trailer_park[single_series][]": {
            required: true
          },
          "trailer_park[shooting_format][]": {
            required: true
          },
          "trailer_park[aspect_ratio][]": {
            required: true
          },
          "trailer_park[expected_running_time]": {
            required: true
          },
          "trailer_park[production_companies_attributes][0][name]": {
            required: {
              //?? HACK: Tests that atleast ONE production company was selected
              depends: function(element){
                return !validateAddAnother($("#add_remove_production_companies:visible"));
              }
            }
          },
          "trailer_park[total_budget]": {
            required: true,
            number: true
          },
          "trailer_park[amount_still_required]": {
            required: true,
            number: true
          },
          "trailer_park[broadcaster_attached]": {
            required: true
          },
          "trailer_park[distributor_sales_agent]": {
            required: true
          },
          "trailer_park[broadcaster_details]": {
            required: {
              depends: function(element){
                var checked = $("input[name='trailer_park[broadcaster_attached]']:checked").val();
                return checked == "true";
              }
            }
          },
          "trailer_park[distributor_sales_agent_details]": {
            required: {
              depends: function(element){
                var checked = $("input[name='trailer_park[distributor_sales_agent]']:checked").val();
                return checked == "true";
              }
            }
          },
          "trailer_park[image1]": {
              required: true,
              accept: "png|jpe?g|gif|bmp|tiff"
          },
          "trailer_park[image2]": {
              required: true,
              accept: "png|jpe?g|gif|bmp|tiff"
          },
          "trailer_park[dvd_aspect_ratio][]": {
              required: true
          },
          "trailer_park[number_dvds]": {
              required: true
          },
          "trailer_park[additional_financial_source]": {
              required: true
          }
      },

      //Error messages
      messages: { 
          "trailer_park[first_name]": {
              required: "Please enter first name"
          },
          "trailer_park[last_name]": {
              required: "Please enter last name"
          },
          "trailer_park[email]": {
              required: "Please enter valid email address",
              email: "Email address must be valid"
          },
          "trailer_park[email_confirmation]": {
              required: "Please confirm the email address",
              equalTo: "Email doesn't match confirmation"
          },
          "trailer_park[job_title]": {
              required: "Please enter job title"
          },
          "trailer_park[organisation]": {
              required: "Please enter name of organisation"
          },
          "trailer_park[address_1]": {
              required: "Please enter address"
          },
          "trailer_park[suburb]": {
              required: "Please enter suburb"
          },
          "trailer_park[state_region]": {
              required: "Please enter state/province/region"
          },
          "trailer_park[post_code]": {
              required: "Please enter postal/zip code"
          },
          "trailer_park[phone_number]": {
              required: "Please enter phone number"
          },
          "trailer_park[mobile_number]": {
              required: "Please enter mobile phone number"
          },
          "trailer_park[project_title]": { 
              required: "Please enter the title of the story"
          }, 
          "trailer_park[logline]": {
              required: "Please enter a logline"
          },
          "trailer_park[synopsis]": {
              required: "Please enter a synopsis of the story",
              max: "Synopsis may not exceed 100 words"
          },
          "trailer_park[genre][]": {
              required: "Please select a genre that fits the story"
          },
          "trailer_park[country_of_production]": {
              required: "Please select country of production"
          },
          "trailer_park[country_co_productions_attributes][0][country]": {
              required: "Please select a country of co production"
          },
          "trailer_park[country_films_attributes][0][country]": {
              required: "Please select a country of filming"
          },
          "trailer_park[expected_release_date]": {
              required: "Please enter the expected release date"
          },
          "trailer_park[language]": {
              required: "Please enter language of project"
          },
          "trailer_park[single_series][]": {
              required: "Please select if the project is a single or series"
          },
          "trailer_park[shooting_format][]": {
              required: "Please select a shooting format"
          },
          "trailer_park[aspect_ratio][]": {
              required: "Please select an aspect ratio"
          },
          "trailer_park[expected_running_time]": {
              required: "Please enter expected running time"
          },
          "trailer_park[production_companies_attributes][0][name]": {
              required: "Please select a production company"
          },
          "trailer_park[total_budget]": {
            required: "Please enter the total budget",
            number: "Budget must be a number"
          },
          "trailer_park[amount_still_required]": {
            required: "Please enter the amount still required",
            number: "Amount must be a number"
          },
          "trailer_park[broadcaster_attached]": {
            required: "Please select if a broadcaster is attached"
          },
          "trailer_park[distributor_sales_agent]": {
            required: "Please select if distributors or sale agents are committed to the project"
          },
          "trailer_park[broadcaster_details]": {
            required: "Please enter broadcaster details"
          },
          "trailer_park[distributor_sales_agent_details]": {
            required: "Please enter distributor/sales agent details"
          },
          "trailer_park[image1]": {
              required: "Please select first image",
              accept: "Please select first image of type PNG, JPG, JPEG, BMP, TIFF or GIF"
          },
          "trailer_park[image2]": {
              required: "Please select second image",
              accept: "Please select second image of type PNG, JPG, JPEG, BMP, TIFF or GIF"
          },
          "trailer_park[dvd_aspect_ratio][]": {
              required: "Please select an aspect ratio"
          },
          "trailer_park[number_dvds]": {
              required: "Please select the number of copies being submitted"
          },
          "trailer_park[additional_financial_source]": {
              required: "Please list any additional secured third party funding"
          }
      },

      //Handles the event in which a form fails to validate
      invalidHandler: function(form, validator) {
        removeErrorNotice();
      },

      //Handles the placement of error messages on the page
      errorPlacement: function(error, element) {
        showErrorNotice(error);
      }
    });
  }
}

////////////////////////////////////////////////////////////////////////////////////////
//
//          VIDEOTHEQUE FORM VALIDATIONS
//
////////////////////////////////////////////////////////////////////////////////////////

function validateVideothequeForm(){
  // Find the profile creation form
  var videothequeForm = $(".edit_videotheque");
  
  // If the trailer park form exists...
  if(videothequeForm !== null){
    
    //Ignore hidden input fields 
    hideHiddenFieldsInForm(videothequeForm);
    
    showTextAreaIfTrue( "videotheque[broadcaster_attached]" );
    showTextAreaIfTrue( "videotheque[distributor_sales_agent]" );
    
    // Add dynamic fields before submission
    var submitButton = $(videothequeForm).find(".controls input").filter(function(){
      return $(this).val() == "Next";
    });
    
    $(submitButton).unbind();
    $(submitButton).click(function(){
      
      makeRulesForNameFields( $(".validate_producer_name"), "producer");
      makeRulesForBioFields( $(".validate_producer_bio"), "producer", 150);
      makeRulesForNameFields( $(".validate_director_name"), "director");
      makeRulesForBioFields( $(".validate_director_bio"), "director", 150);
      makeRulesForNameFields( $(".validate_writer_name"), "writer");
      makeRulesForBioFields( $(".validate_writer_bio"), "writer", 150);
      
    });

    // Validate form
    $(videothequeForm).validate({

      //Handles the event in which a form is submitted
      submitHandler: function(form) {
        //No longer ignore hidden input fields
        unhideHiddenFieldsInForm(form);
        
        //Submit form
        form.submit();
      },

      focusInvalid: false,
      onfocusout: false,
      onkeyup: false,
      onclick: false,
      errorClass: "invalidField",

      //Required fields
      rules: { 
          "videotheque[first_name]": {
              required: true
          },
          "videotheque[last_name]": {
              required: true
          },
          "videotheque[email]": {
              required: true,
              email: true
          },
          "videotheque[email_confirmation]": {
              required: true,
              equalTo: "#videotheque_email"
          },
          "videotheque[job_title]": {
              required: true
          },
          "videotheque[organisation]": {
              required: true
          },
          "videotheque[address_1]": {
              required: true
          },
          "videotheque[suburb]": {
              required: true
          },
          "videotheque[state_region]": {
              required: true
          },
          "videotheque[post_code]": {
              required: true
          },
          "videotheque[phone_number]": {
              required: true
          },
          "videotheque[mobile_number]": {
              required: true
          },
          "videotheque[original_documentary_title]": { 
              required: true
          }, 
          "videotheque[logline]": {
              required: true
          },
          "videotheque[synopsis]": {
              required: true,
              max: {
                depends: function(element){
                  return hasExceedWordMax(element,100);
                }
              }
          },
          "videotheque[genre][]": {
              required: true
          },
          "videotheque[country_of_production]": {
              required: true
          },
          "videotheque[documentary_title_in_english]": {
              required: true
          },
          "videotheque[country_co_productions_attributes][0][country]": {
              required: {
                //?? HACK: Tests that atleast ONE country of co production was selected
                depends: function(element){
                  return !validateAddAnother($("#add_remove_country_co_productions:visible"));
                }
              }
          },
          "videotheque[country_films_attributes][0][country]": {
            required: {
              //?? HACK: Tests that atleast ONE country of filming was selected
              depends: function(element){
                return !validateAddAnother($("#add_remove_country_films:visible"));
              }
            }
          },
          "videotheque[year_of_production]": {
            required: true
          },
          "videotheque[language]": {
            required: true
          },
          "videotheque[single_series][]": {
            required: true
          },
          "videotheque[shooting_format][]": {
            required: true
          },
          "videotheque[aspect_ratio]": {
            required: true
          },
          "videotheque[expected_running_time]": {
            required: true
          },
          "videotheque[production_companies_attributes][0][name]": {
            required: {
              //?? HACK: Tests that atleast ONE production company was selected
              depends: function(element){
                return !validateAddAnother($("#add_remove_production_companies:visible"));
              }
            }
          },
          "videotheque[broadcaster_attached]": {
            required: true
          },
          "videotheque[distributor_sales_agent]": {
            required: true
          },
          "videotheque[broadcaster_details]": {
            required: {
              depends: function(element){
                var checked = $("input[name='videotheque[broadcaster_attached]']:checked").val();
                return checked == "true";
              }
            }
          },
          "videotheque[distributor_sales_agent_details]": {
            required: {
              depends: function(element){
                var checked = $("input[name='videotheque[distributor_sales_agent]']:checked").val();
                return checked == "true";
              }
            }
          },
          "videotheque[festivals_and_awards]": {
              required: true
          },
          "videotheque[image1]": {
              required: true,
              accept: "png|jpe?g|gif|bmp|tiff"
          },
          "videotheque[image2]": {
              required: true,
              accept: "png|jpe?g|gif|bmp|tiff"
          },
          "videotheque[dvd_aspect_ratio]": {
              required: true
          },
          "videotheque[number_dvds]": {
              required: true
          }
      },

      //Error messages
      messages: { 
          "videotheque[first_name]": {
              required: "Please enter first name"
          },
          "videotheque[last_name]": {
              required: "Please enter last name"
          },
          "videotheque[email]": {
              required: "Please enter valid email address",
              email: "Email address must be valid"
          },
          "videotheque[email_confirmation]": {
              required: "Please confirm the email address",
              equalTo: "Email doesn't match confirmation"
          },
          "videotheque[job_title]": {
              required: "Please enter job title"
          },
          "videotheque[organisation]": {
              required: "Please enter name of organisation"
          },
          "videotheque[address_1]": {
              required: "Please enter address"
          },
          "videotheque[suburb]": {
              required: "Please enter suburb"
          },
          "videotheque[state_region]": {
              required: "Please enter state/province/region"
          },
          "videotheque[post_code]": {
              required: "Please enter postal/zip code"
          },
          "videotheque[phone_number]": {
              required: "Please enter phone number"
          },
          "videotheque[mobile_number]": {
              required: "Please enter mobile phone number"
          },
          "videotheque[original_documentary_title]": { 
              required: "Please enter the title of the original documentary"
          }, 
          "videotheque[logline]": {
              required: "Please enter a logline"
          },
          "videotheque[synopsis]": {
              required: "Please enter a synopsis of the story",
              max: "Synopsis may not exceed 100 words"
          },
          "videotheque[genre][]": {
              required: "Please select a genre that fits the story"
          },
          "videotheque[documentary_title_in_english]": {
              required: "Please enter documentary title in english"
          },
          "videotheque[country_of_production]": {
              required: "Please select country of production"
          },
          "videotheque[country_co_productions_attributes][0][country]": {
              required: "Please select a country of co production"
          },
          "videotheque[country_films_attributes][0][country]": {
              required: "Please select a country of filming"
          },
          "videotheque[year_of_production]": {
              required: "Please enter the year of production"
          },
          "videotheque[language]": {
              required: "Please enter the original language"
          },
          "videotheque[single_series][]": {
              required: "Please select if the documentary is a single or series"
          },
          "videotheque[shooting_format][]": {
              required: "Please select a shooting format"
          },
          "videotheque[aspect_ratio]": {
              required: "Please select an aspect ratio"
          },
          "videotheque[expected_running_time]": {
              required: "Please enter running time"
          },
          "videotheque[production_companies_attributes][0][name]": {
              required: "Please enter a production company"
          },
          "videotheque[broadcaster_attached]": {
            required: "Please select if a broadcaster is attached"
          },
          "videotheque[distributor_sales_agent]": {
            required: "Please select if distributors or sale agents are committed to the project"
          },
          "videotheque[broadcaster_details]": {
            required: "Please enter broadcaster details"
          },
          "videotheque[distributor_sales_agent_details]": {
            required: "Please enter distributor/sales agent details"
          },
          "videotheque[festivals_and_awards]": {
              required: "Please enter any festivals and awards"
          },
          "videotheque[image1]": {
              required: "Please select first image",
              accept: "Please select first image of type PNG, JPG, JPEG, BMP, TIFF or GIF"
          },
          "videotheque[image2]": {
              required: "Please select second image",
              accept: "Please select second image of type PNG, JPG, JPEG, BMP, TIFF or GIF"
          },
          "videotheque[dvd_aspect_ratio]": {
              required: "Please select an aspect ratio"
          },
          "videotheque[number_dvds]": {
              required: "Please select the number of copies being submitted"
          }
      },

      //Handles the event in which a form fails to validate
      invalidHandler: function(form, validator) {
        removeErrorNotice();
      },

      //Handles the placement of error messages on the page
      errorPlacement: function(error, element) {
        showErrorNotice(error);
      }
    });
  }
}

////////////////////////////////////////////////////////////////////////////////////////
//
//          MAIL FORM VALIDATIONS
//
////////////////////////////////////////////////////////////////////////////////////////

function validateMailForm(){
  
  // Find the conference registration form
  var MailForm = $("form.mail");
  
  // If the registration form exists...
  if(MailForm !== null){
    
    //Ignore hidden input fields 
    hideHiddenFieldsInForm(MailForm);
    
    // Validate form
    var validator = $(MailForm).validate({

      //Handles the event in which a form is submitted
      submitHandler: function(form) {
        removeErrorNotice();
        //No longer ignore hidden input fields
        unhideHiddenFieldsInForm(form);
        //Submit form
        form.submit();
      },
      
      focusInvalid: false,
      onfocusout: false,
      onkeyup: false,
      onclick: false,
      errorClass: "invalidField",
  
      //Required fields
      rules: { 
          "message[subject]": { 
              required: true
          }
      },

      //Error messages
      messages: { 
          "message[subject]": { 
              required: "Please enter subject of message."
          }
      },
      
      //Handles the event in which a form fails to validate
      invalidHandler: function(form, validator) {
        removeErrorNotice();
      },

      //Handles the placement of error messages on the page
      errorPlacement: function(error, element) {
        showErrorNotice(error);
      }
    });
  }
}

////////////////////////////////////////////////////////////////////////////////////////
//
//          CART FORM VALIDATIONS
//
////////////////////////////////////////////////////////////////////////////////////////

function validateCartForm(){	
	var quantity = $("#quantity").val();
	var error = null;
	if(quantity == null || quantity == "")
		error = "Please enter quantity."
	else{
		try{
		 	if(isNaN(quantity) || parseInt(quantity) < 1)
				error = "Please enter valid quantity."
		}catch(e)
		{
				error = "Please enter valid quantity."
		}
	}
	if(error != null)
	{	
		$("#cart_error").show();
		$("#cart_error").text(error);
		$("#cart_error").addClass("errorExplanation");
		
		return false;
	}
	return true;
}



$(document).ready(function() {
  if($.browser.msie && parseInt($.browser.version) < 8){
    fixIE6Forms();
  }
  if($.browser.msie && parseInt($.browser.version) < 7){
    if(DD_belatedPNG){
      DD_belatedPNG.fix("#header");
    }
  }
  // Sign-up or Sign-in controls display
  signInOrUpControls();
  
  // Check if we are sending an email to a group
  selectGroupControls();
  
  // If we are sending a message to a group, warn the user...
  submitToGroupMessage();

  // Make URL input fields valid when losing focus
  makeValidURLsOnFocusOut();
  // check for any datepickers
  $('.datePicker').datepicker({ dateFormat: 'dd-mm-yy' });
  
  // Init MeetMarket multi-form buttons
//?? CONSIDER MOVING THIS
  toggleMeetMarketMultiFormButtons();

  //Validate forms
  validateProfileForm();  
  validateConferenceRegisterForm();
  validateTrailerParkForm();
  validateMeetmarketRegisterForm();
  validateF4RegisterForm();
  validateVideothequeForm();
  validateScienceExchangeForm();
  validateGroupForm();
  validateMailForm();
	//validateCartForm();

//?? CONSIDER MOVING THIS
  // Apply click listener to radio buttons
  $('fieldset.multi-select .radio').each(function(e){
  
    var thisRadio = this;
  
    //Only apply to radio buttons and not check boxes...
    if($(thisRadio).attr("type") == "radio"){
      // Attach click listener to both radio button AND label
      $(this).bind("click", make_radio_click_listener(thisRadio));
      $(this).parent().prev().bind("click", make_radio_click_listener(thisRadio));
    }
    
  });
  
//?? CONSIDER MOVING THIS
//?? Is a hack
  //If we select "I would like to bring a guest", also select
  //"I would like to attend the closing night party"....
  // $(".additional_purchase.radio").bind("click",function(){
  //   if($("#additional_purchase_5").attr("checked") == "true" || $(this).attr("id") == "additional_purchase_5"){
  //     
  //     $("#additional_purchase_4").attr("checked","true");
  //   }
  // });

//?? CONSIDER MOVING THIS
  add_calendar_event_mouse_handlers();
  creat_tooltips_for_calendar();
  
});

function creat_tooltips_for_calendar(){
  $('#tooltip .title p[title]').qtip({
      style: 'light',
      tip: true,
      position: {
            corner: {
               target: 'topMiddle',
               tooltip: 'bottomMiddle'
            }
         }
   });
}

function submitToGroupMessage(){
  var isGroupField = $("input#is_group");
  var submitButton = $("input#sendmessage");
  $(submitButton).click(function(){
    var isGroup = isGroupField.val();
    if(isGroup == "true"){
      window.alert("You are sending a message to a whole group. This may take some time.");
    }
  });
}

function signInOrUpControls(){
  
  var sign_in_or_up = $(".signInOrSignUp");
  if( sign_in_or_up.length > 0 ){
    
    //Setup sign-in link
    var sign_in_link = $(".signin");
    if( sign_in_link.length > 0 ){
      $(sign_in_link).replaceWith("<a class='signin'>" + $(sign_in_link).text() + "</a>");
      sign_in_link = $(".signin");
      $(sign_in_link).click(function(){
        $(".signInOrSignUp").hide();
        $(".layout_search").hide();
        $("#header form#f_search").hide();
        $("#header fieldset").show();
        $("#header .controls").show();
      });
    }
  }
}

function selectGroupControls(){
  
  var selectTo = $("#message_to");
  var groups = new Array();
  
  var checkGroupSelected = function(){
    
    var selectedOption = $(selectTo).find("option:selected");
    
    var flagField = $("input#is_group");
    
    //If a group was selected
    if( $(selectedOption).parent().attr("label") == "Groups" ){
        //Flag is_group hidden field
        if( $(flagField).length > 0 ){
          flagField.val("true");
        }
    }else{
        if( $(flagField).length > 0 ){
          flagField.val("false");
        }
    }
  };
  
  if($(selectTo).length > 0){
    //Check initial selection
    checkGroupSelected();
    //When selection has changed, check if a group was selected
    selectTo.change(checkGroupSelected);
  }
}

function make_radio_click_listener(radio){
  return function(){
    //Check the field
    $(radio).attr("checked","checked");
    //Unselect all fields
    $(radio).parent().parent().find("dt").removeClass("selected");
    //Show this field as selected
    $(radio).parent().prev().addClass("selected");
  };
}

function calculate_order_total(radio){
  //+ shipping_costs.get(radio.value)
  $('order_total_cell').update(number_to_currency(order_total_without_shipping  ));
}

function number_to_currency(number, options) {
  try {
     var options   = options || {};
    var precision = options["precision"] || 2;
     var unit      = options["unit"] || "$";
     var separator = precision > 0 ? options["separator"] || "." : "";
    var delimiter = options["delimiter"] || ",";
   
     var parts = parseFloat(number).toFixed(precision).split('.');
    return unit + number_with_delimiter(parts[0], delimiter) + separator + parts[1].toString();
  } catch(e) {
    return number;
  }
 }

function number_with_delimiter(number, delimiter, separator) {
  try {
    var delimiter = delimiter || ",";
     var separator = separator || ".";

    var parts = number.toString().split('.');
    parts[0] = parts[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + delimiter);
    return parts.join(separator);
  } catch(e) {
    return number;
  }
}


function generate_interest_text_box(model , num){
  
  //Show appropriate form fields according to current selections
  show_area_of_interest_fields(model);

}

function generate_delegate_text_box(){

    var delegate_select = $("#conference_register_delegate_type");    
    var delegate_other_place = $("#place_for_other_delegate_type");
    
    if( $(delegate_select).val() == "Other" ){        
        $(delegate_other_place).show();
      }else{
        $(delegate_other_place).hide();
      }
}

function area_of_interest_text_box_on_page_load(model){
  
  //Show appropriate form fields according to current selections
  show_area_of_interest_fields(model);
  
}

function show_area_of_interest_fields(model){
  var num = 1;
  var foundBlank = false;
  
  while( $("#"+model+"_area_of_interest_"+num).length != 0){
    
    var interest_select = $("#"+model+"_area_of_interest_"+num);
    var next_interest_select = $("#"+model+"_area_of_interest_"+(num + 1));
    var interest_other_field = $("#place_for_other_text_"+num);
    
    //If we haven't located a preceding blank select field...
    if(!foundBlank){
      // Show input field if 'other' was selected
      if( $(interest_select).val() == "Other" ){
        $(interest_select).show();
        $(interest_other_field).show();
      }else{
        $(interest_other_field).hide();
      }

      // If nothing is selected in this field, hide and clear the remaining select fields
      if( $(interest_select).val() == "" ){
        foundBlank = true;
      }
      //Otherwise show the next next field
      else{
          $(next_interest_select).show();
      }
    }else{
      $(interest_select).hide();
      $(interest_select).attr("value","");
    }
    num ++;
  }
}

// this clearing div stops forms in IE6 from collapsing
function fixIE6Forms(){
  $("#content dd").each(function(i, e){
    $(e).after("<div class='clr'></div>");
  });
}


/*
MEETMARKET
*/

// used to show and hide remove button so first item can't
// be deleted when multiple countries, producers etc can be used
function toggleMeetMarketMultiFormButtons() {
    
    //For each multi-select container
    var multiField = $('.add_remove');
    $(multiField).each(function(i){

      var inputFields = $(this).find(".remove:visible");

      //If there is only one field showing, hide remove buttons
      if(inputFields.length <= 1){
        $(this).find(".remove_child").hide();
        //console.log("hiding remove buttons");
      }else{
        $(this).find(".remove_child").show();
        //console.log("showing remove buttons");
      }
    })
};

// used to Add, when multiple countries, producers etc can be used
function insert_fields(link, method, content) {
  var new_id = new Date().getTime();
  var regexp = new RegExp("new_" + method, "g");
  $(link).before(content.replace(regexp, new_id));
  toggleMeetMarketMultiFormButtons();
}

// used to Remove, when multiple countries, producers etc can be used
function remove_fields(link) {    
  var hidden_field = $(link).prev("input[type=hidden]");
  if (hidden_field) {        
      hidden_field.val('1');
  }
  $(link).closest(".remove").hide();
  toggleMeetMarketMultiFormButtons();
}

// used to show a text area if a radio button is selected with value "true"
function showTextAreaIfTrue( radio_group ){
  var buttons = $("input[name='" + radio_group + "']");
  var textArea = buttons.parent().find("textarea");
  var checked = $("input[name='" + radio_group + "']:checked").val();
  
  if( buttons.length <= 0 || textArea.length <= 0){
    return;
  }
  
  var showIfTrue = function(){
    if(checked == "true"){
        textArea.css("display","inline");
    }else{
        textArea.css("display","none");
    }
  };
  
  $(buttons).click(function(){
    checked = $("input[name='" + radio_group + "']:checked").val();
    showIfTrue();
  });
  
  showIfTrue();
}

function setCMSLayout(){
  var template = $('page_template').value;
  if (template == "single_column"){
    $("page_1_content_2_editor___Frame").hide();
    //$("page_1_content_1_editor___Frame").attr({width:"800px"});
  } else if (template == "two_column"){
    //$("page_1_content_1_editor___Frame").attr({width:"400px"});
    $("page_1_content_2_editor___Frame").show();
  } if (template == "sidebar"){
    //$("page_1_content_1_editor___Frame").attr({width:"400px"});
    $("page_1_content_2_editor___Frame").show();
  }
}

//Alternate tableviewer row colours
function colorTableviewers(){
  $("#tableviewer table").each(function(){
    $(this).find("tr").each(function(i){
      if(i == 0){
        $(this).addClass("firstRow");
      }else if(i%2 == 0){
        $(this).addClass("alternateRow");
      }
    });
  });
}

function validateGroupForm(){
  
	
  // Find the group creation form
  var groupForm = $("form#group_form"); //findFormByAction("/member/groups");
  
  // If the group creation form exists...
  if(groupForm != null){
   
    //Ignore hidden input fields 
    hideHiddenFieldsInForm(groupForm);
        

    // Validate form
    $(groupForm).validate({

      //Handles the event in which a form is submitted
      submitHandler: function(form) {
        //No longer ignore hidden input fields
        unhideHiddenFieldsInForm(form)
        //Submit form
        form.submit();
      },

      focusInvalid: false,
      onfocusout: false,
      onkeyup: false,
      onclick: false,

      //Required fields
      rules: { 
          "group[name]": {
              required: true
          },
          "group[description]": {
              required: true,
              max: {
                //This is a hack but it works
                depends: function(element){
                  return hasExceedWordMax(element,500);
                }
							}	
          },
          "group[image]": {
              required: {
                //If the default group  image is displayed, this field is required.
                depends: function(element){
                  var groupImage = $(element).parent().find("img:first");
                  if(groupImage.length <= 0){
                    return true;
                  }else if($(groupImage).attr("alt") == "Default_profile"){
                    return true;
                  }else{
                    return false;
                  }
                }
              },
              accept: "png|jpe?g|gif|bmp|tiff"
          }
      },

      //Error messages
      messages: { 
          "group[name]": {
              required: "Please enter group name"
          },
          "group[description]": {
              required: "Please enter group description" ,
							max: "Description is too long, maximum 500 words"
          },
          "group[image]": {
              required: "please select a group photo",
              accept: "Please select image of type PNG, JPG, JPEG, BMP, TIFF or GIF"
          }
      },

      //Handles the event in which a form fails to validate
      invalidHandler: function(form, validator) {
        removeErrorNotice();
      },

      //Handles the placement of error messages on the page
      errorPlacement: function(error, element) {
        showErrorNotice(error);
      }
    });
  }
}


function save_notes_form(form_url){
  
  $("#notes_progress").show('slow');
  $.ajax({
    type: "GET",
    url: form_url,                                 
    data: $('#notes_form').serialize(),    
    success: function(response) {  
      $("#notes_listing").html(response);      
      $("#notes_progress").hide();
      
    }
  });  

}

function mark_as_watched(form_url , flag){
  
  //$("#notes_progress").show('slow');
  $("#mark_as_watched_link_container").html('saving...');
  $.ajax({
    type: "GET",
    url: form_url,
    data: "want_mark=" + flag,    
     success: function(response) {  
        if(response == "true")
        {          
          html = "<a class=\"button\" onclick=\"mark_as_watched('" + form_url + "' , false);return false;\" href=\"javascript:;\">Un-Mark As Watched</a>";
        }
        else
        {          
          html = "<a class=\"button\" onclick=\"mark_as_watched('" + form_url + "' , true);return false;\" href=\"javascript:;\">Mark As Watched</a>";
        }
        $("#mark_as_watched_link_container").html(html);
       
     }
  });  


}


function mark_as_viewed(form_url , flag){
  
  //$("#notes_progress").show('slow');
  $("#mark_as_viewed_link_container").html('saving...');
  $.ajax({
    type: "GET",
    url: form_url,
    data: "want_mark=" + flag,    
     success: function(response) {  
        if(response == "true")
        {          
          html = "<a class=\"button\" onclick=\"mark_as_viewed('" + form_url + "' , false);return false;\" href=\"javascript:;\">Un-Mark As Viewed</a>";
        }
        else
        {          
          html = "<a class=\"button\" onclick=\"mark_as_viewed('" + form_url + "' , true);return false;\" href=\"javascript:;\">Mark As Viewed</a>";
        }
        $("#mark_as_viewed_link_container").html(html);
       
     }
  });  


}


function accept_reject_group_member_request(form_url){
  
  $("#div_pending_and_block_unblock").html("Saving...")
  $.ajax({
    type: "GET",
    url: form_url,                                 
    success: function(response) {  
      $("#div_pending_and_block_unblock").html(response);      
    }
  });  

}



function block_unblock_user_from_group(form_url , id , flag){
  
  //$("#notes_progress").show('slow');
  $("#div_pending_and_block_unblock").html("Saving...")
  $.ajax({
    type: "GET",
    url: form_url + "?block="+flag,
    success: function(response) {  
        $("#div_pending_and_block_unblock").html(response);       
       
     }
  });  

}

function admin_grant_revoke_from_group(form_url , id , flag){
  
  //$("#notes_progress").show('slow');
  $("#div_pending_and_block_unblock").html("Saving...")
  $.ajax({
    type: "GET",
    url: form_url + "?right="+flag,
    success: function(response) {  
        $("#div_pending_and_block_unblock").html(response);          
     }
  });  

}


function make_group_owner(form_url) {

	if(confirm("Do you really want to give group ownership to this member?")){
			$("#div_pending_and_block_unblock").html("Saving...")
		  $.ajax({
		    type: "GET",
		    url: form_url,                                 
		    success: function(response) {  
		      $("#div_pending_and_block_unblock").html(response);   
		 			fields = $('#group_details_form').find("input, textarea")
					$(fields).each(function(){ 
							$(this).attr("disabled", true); 
					});
		    }
		  });
		}
	
}

function delete_group_discussion(id)
{
	if(confirm("Do you really want to delete this group discussion?")){
		//window.location.pathname = url;
		$("#"+id).submit();
	}
	

}

function delete_event_discussion(id)
{
	if(confirm("Do you really want to delete this event discussion?")){
		$("#"+id).submit();
	}
}

function show_session_details(page_url , place_holder){
	$(place_holder).html( "<div class='cal-spinner'><img src='/images/ajax-loader.gif' alt='' > Loading...</div>")
	
	
  $.ajax({
		type: "GET", 
    url: page_url,
		error: function(response){
			  
		},
    success: function(response) {	  		
				$(place_holder).html(response);
				if(Cufon){
  				Cufon.replace('.fancy-font');
  				Cufon.now();
				}
     }
  });  
	
}

function date_picker_for_calendar(url , category ){
	$(function() {
		
  	$("#datepicker").datepicker({
  	  showOn: 'button', 
  	  //buttonImage: '/images/calendar-icon.png', 
  	  buttonImageOnly: false,
  	  dateFormat: 'yy-mm-dd',
  	  buttonText: '',
  	  onSelect: function(dateText, inst) { 
				var cat_query = "";
				
				if(category != null && category != ""){
					cat_query = "&category=" + category
				}
								
				window.location = url + "?start_date="+dateText+cat_query ;  	    
  	  }
      
  	});
  	
  	var button = $("#datepicker").parent().find("button");
  	if( button ){
  	  $(button).addClass("button");
  	}
    
  });
}

function add_calendar_event_mouse_handlers(){
  var events = $("#day_events .day_event");
  if(events.length > 0){
    $(events).each(function(){

			//Get Event link details
      var link = $(this).find("a");
      var url = $(link).attr("href");
      var title = $(link).text();
      var link_title = $(link).attr("title")
      
      //Setup rollover events
			if(url != null) {
		      $(this).hover(function(){
		        $(this).addClass("hover");
		      },function(){
		        $(this).removeClass("hover");
		      });
      
						
	      	//Remove link
	      	$(link).replaceWith("<p title='"+link_title+"'>"+title+"</p>");
      
	      	//Setup click events
	      	$(this).click(function(){
						show_session_details(url,$("#calendar_page_right_col, #group_calendar_page_right_col") );
		      });
			}
    })
  }
}


function add_remove_user_from_schedule(form_url , id , flag){
  
  //$("#notes_progress").show('slow');
  $("#add_remove_schedule").html("Saving...")
  $.ajax({
    type: "GET",
    url: form_url + "?add="+flag,
    success: function(response) {  
        $("#add_remove_schedule").html(response);       
     }
  });  

}


var add_image_handlers = function() {
  $("#main-image").data('selectedThumb', $('#main-image img').attr('src'));
  $('ul.thumbnails li').eq(0).addClass('selected');
  $('ul.thumbnails li a').click(function() {
    $("#main-image").data('selectedThumb', $(this).attr('href'));
    $('ul.thumbnails li').removeClass('selected');
    $(this).parent('li').addClass('selected');
    return false;
  }).hover(
          function() {
            $('#main-image img').attr('src', $(this).attr('href').replace('mini', 'product'));
          },
          function() {
            $('#main-image img').attr('src', $("#main-image").data('selectedThumb'));
          }
          );
};
 
jQuery(document).ready(function() {
  add_image_handlers();
});

/*
 * Copyright (c) 2009 Simo Kinnunen.
 * Licensed under the MIT license.
 *
 * @version 1.09
 */
var Cufon=(function(){var m=function(){return m.replace.apply(null,arguments)};var x=m.DOM={ready:(function(){var C=false,E={loaded:1,complete:1};var B=[],D=function(){if(C){return}C=true;for(var F;F=B.shift();F()){}};if(document.addEventListener){document.addEventListener("DOMContentLoaded",D,false);window.addEventListener("pageshow",D,false)}if(!window.opera&&document.readyState){(function(){E[document.readyState]?D():setTimeout(arguments.callee,10)})()}if(document.readyState&&document.createStyleSheet){(function(){try{document.body.doScroll("left");D()}catch(F){setTimeout(arguments.callee,1)}})()}q(window,"load",D);return function(F){if(!arguments.length){D()}else{C?F():B.push(F)}}})(),root:function(){return document.documentElement||document.body}};var n=m.CSS={Size:function(C,B){this.value=parseFloat(C);this.unit=String(C).match(/[a-z%]*$/)[0]||"px";this.convert=function(D){return D/B*this.value};this.convertFrom=function(D){return D/this.value*B};this.toString=function(){return this.value+this.unit}},addClass:function(C,B){var D=C.className;C.className=D+(D&&" ")+B;return C},color:j(function(C){var B={};B.color=C.replace(/^rgba\((.*?),\s*([\d.]+)\)/,function(E,D,F){B.opacity=parseFloat(F);return"rgb("+D+")"});return B}),fontStretch:j(function(B){if(typeof B=="number"){return B}if(/%$/.test(B)){return parseFloat(B)/100}return{"ultra-condensed":0.5,"extra-condensed":0.625,condensed:0.75,"semi-condensed":0.875,"semi-expanded":1.125,expanded:1.25,"extra-expanded":1.5,"ultra-expanded":2}[B]||1}),getStyle:function(C){var B=document.defaultView;if(B&&B.getComputedStyle){return new a(B.getComputedStyle(C,null))}if(C.currentStyle){return new a(C.currentStyle)}return new a(C.style)},gradient:j(function(F){var G={id:F,type:F.match(/^-([a-z]+)-gradient\(/)[1],stops:[]},C=F.substr(F.indexOf("(")).match(/([\d.]+=)?(#[a-f0-9]+|[a-z]+\(.*?\)|[a-z]+)/ig);for(var E=0,B=C.length,D;E<B;++E){D=C[E].split("=",2).reverse();G.stops.push([D[1]||E/(B-1),D[0]])}return G}),quotedList:j(function(E){var D=[],C=/\s*((["'])([\s\S]*?[^\\])\2|[^,]+)\s*/g,B;while(B=C.exec(E)){D.push(B[3]||B[1])}return D}),recognizesMedia:j(function(G){var E=document.createElement("style"),D,C,B;E.type="text/css";E.media=G;try{E.appendChild(document.createTextNode("/**/"))}catch(F){}C=g("head")[0];C.insertBefore(E,C.firstChild);D=(E.sheet||E.styleSheet);B=D&&!D.disabled;C.removeChild(E);return B}),removeClass:function(D,C){var B=RegExp("(?:^|\\s+)"+C+"(?=\\s|$)","g");D.className=D.className.replace(B,"");return D},supports:function(D,C){var B=document.createElement("span").style;if(B[D]===undefined){return false}B[D]=C;return B[D]===C},textAlign:function(E,D,B,C){if(D.get("textAlign")=="right"){if(B>0){E=" "+E}}else{if(B<C-1){E+=" "}}return E},textShadow:j(function(F){if(F=="none"){return null}var E=[],G={},B,C=0;var D=/(#[a-f0-9]+|[a-z]+\(.*?\)|[a-z]+)|(-?[\d.]+[a-z%]*)|,/ig;while(B=D.exec(F)){if(B[0]==","){E.push(G);G={};C=0}else{if(B[1]){G.color=B[1]}else{G[["offX","offY","blur"][C++]]=B[2]}}}E.push(G);return E}),textTransform:(function(){var B={uppercase:function(C){return C.toUpperCase()},lowercase:function(C){return C.toLowerCase()},capitalize:function(C){return C.replace(/\b./g,function(D){return D.toUpperCase()})}};return function(E,D){var C=B[D.get("textTransform")];return C?C(E):E}})(),whiteSpace:(function(){var D={inline:1,"inline-block":1,"run-in":1};var C=/^\s+/,B=/\s+$/;return function(H,F,G,E){if(E){if(E.nodeName.toLowerCase()=="br"){H=H.replace(C,"")}}if(D[F.get("display")]){return H}if(!G.previousSibling){H=H.replace(C,"")}if(!G.nextSibling){H=H.replace(B,"")}return H}})()};n.ready=(function(){var B=!n.recognizesMedia("all"),E=false;var D=[],H=function(){B=true;for(var K;K=D.shift();K()){}};var I=g("link"),J=g("style");function C(K){return K.disabled||G(K.sheet,K.media||"screen")}function G(M,P){if(!n.recognizesMedia(P||"all")){return true}if(!M||M.disabled){return false}try{var Q=M.cssRules,O;if(Q){search:for(var L=0,K=Q.length;O=Q[L],L<K;++L){switch(O.type){case 2:break;case 3:if(!G(O.styleSheet,O.media.mediaText)){return false}break;default:break search}}}}catch(N){}return true}function F(){if(document.createStyleSheet){return true}var L,K;for(K=0;L=I[K];++K){if(L.rel.toLowerCase()=="stylesheet"&&!C(L)){return false}}for(K=0;L=J[K];++K){if(!C(L)){return false}}return true}x.ready(function(){if(!E){E=n.getStyle(document.body).isUsable()}if(B||(E&&F())){H()}else{setTimeout(arguments.callee,10)}});return function(K){if(B){K()}else{D.push(K)}}})();function s(D){var C=this.face=D.face,B={"\u0020":1,"\u00a0":1,"\u3000":1};this.glyphs=D.glyphs;this.w=D.w;this.baseSize=parseInt(C["units-per-em"],10);this.family=C["font-family"].toLowerCase();this.weight=C["font-weight"];this.style=C["font-style"]||"normal";this.viewBox=(function(){var F=C.bbox.split(/\s+/);var E={minX:parseInt(F[0],10),minY:parseInt(F[1],10),maxX:parseInt(F[2],10),maxY:parseInt(F[3],10)};E.width=E.maxX-E.minX;E.height=E.maxY-E.minY;E.toString=function(){return[this.minX,this.minY,this.width,this.height].join(" ")};return E})();this.ascent=-parseInt(C.ascent,10);this.descent=-parseInt(C.descent,10);this.height=-this.ascent+this.descent;this.spacing=function(L,N,E){var O=this.glyphs,M,K,G,P=[],F=0,J=-1,I=-1,H;while(H=L[++J]){M=O[H]||this.missingGlyph;if(!M){continue}if(K){F-=G=K[H]||0;P[I]-=G}F+=P[++I]=~~(M.w||this.w)+N+(B[H]?E:0);K=M.k}P.total=F;return P}}function f(){var C={},B={oblique:"italic",italic:"oblique"};this.add=function(D){(C[D.style]||(C[D.style]={}))[D.weight]=D};this.get=function(H,I){var G=C[H]||C[B[H]]||C.normal||C.italic||C.oblique;if(!G){return null}I={normal:400,bold:700}[I]||parseInt(I,10);if(G[I]){return G[I]}var E={1:1,99:0}[I%100],K=[],F,D;if(E===undefined){E=I>400}if(I==500){I=400}for(var J in G){if(!k(G,J)){continue}J=parseInt(J,10);if(!F||J<F){F=J}if(!D||J>D){D=J}K.push(J)}if(I<F){I=F}if(I>D){I=D}K.sort(function(M,L){return(E?(M>=I&&L>=I)?M<L:M>L:(M<=I&&L<=I)?M>L:M<L)?-1:1});return G[K[0]]}}function r(){function D(F,G){if(F.contains){return F.contains(G)}return F.compareDocumentPosition(G)&16}function B(G){var F=G.relatedTarget;if(!F||D(this,F)){return}C(this,G.type=="mouseover")}function E(F){C(this,F.type=="mouseenter")}function C(F,G){setTimeout(function(){var H=d.get(F).options;m.replace(F,G?h(H,H.hover):H,true)},10)}this.attach=function(F){if(F.onmouseenter===undefined){q(F,"mouseover",B);q(F,"mouseout",B)}else{q(F,"mouseenter",E);q(F,"mouseleave",E)}}}function u(){var C=[],D={};function B(H){var E=[],G;for(var F=0;G=H[F];++F){E[F]=C[D[G]]}return E}this.add=function(F,E){D[F]=C.push(E)-1};this.repeat=function(){var E=arguments.length?B(arguments):C,F;for(var G=0;F=E[G++];){m.replace(F[0],F[1],true)}}}function A(){var D={},B=0;function C(E){return E.cufid||(E.cufid=++B)}this.get=function(E){var F=C(E);return D[F]||(D[F]={})}}function a(B){var D={},C={};this.extend=function(E){for(var F in E){if(k(E,F)){D[F]=E[F]}}return this};this.get=function(E){return D[E]!=undefined?D[E]:B[E]};this.getSize=function(F,E){return C[F]||(C[F]=new n.Size(this.get(F),E))};this.isUsable=function(){return !!B}}function q(C,B,D){if(C.addEventListener){C.addEventListener(B,D,false)}else{if(C.attachEvent){C.attachEvent("on"+B,function(){return D.call(C,window.event)})}}}function v(C,B){var D=d.get(C);if(D.options){return C}if(B.hover&&B.hoverables[C.nodeName.toLowerCase()]){b.attach(C)}D.options=B;return C}function j(B){var C={};return function(D){if(!k(C,D)){C[D]=B.apply(null,arguments)}return C[D]}}function c(F,E){var B=n.quotedList(E.get("fontFamily").toLowerCase()),D;for(var C=0;D=B[C];++C){if(i[D]){return i[D].get(E.get("fontStyle"),E.get("fontWeight"))}}return null}function g(B){return document.getElementsByTagName(B)}function k(C,B){return C.hasOwnProperty(B)}function h(){var C={},B,F;for(var E=0,D=arguments.length;B=arguments[E],E<D;++E){for(F in B){if(k(B,F)){C[F]=B[F]}}}return C}function o(E,M,C,N,F,D){var K=document.createDocumentFragment(),H;if(M===""){return K}var L=N.separate;var I=M.split(p[L]),B=(L=="words");if(B&&t){if(/^\s/.test(M)){I.unshift("")}if(/\s$/.test(M)){I.push("")}}for(var J=0,G=I.length;J<G;++J){H=z[N.engine](E,B?n.textAlign(I[J],C,J,G):I[J],C,N,F,D,J<G-1);if(H){K.appendChild(H)}}return K}function l(D,M){var C=D.nodeName.toLowerCase();if(M.ignore[C]){return}var E=!M.textless[C];var B=n.getStyle(v(D,M)).extend(M);var F=c(D,B),G,K,I,H,L,J;if(!F){return}for(G=D.firstChild;G;G=I){K=G.nodeType;I=G.nextSibling;if(E&&K==3){if(H){H.appendData(G.data);D.removeChild(G)}else{H=G}if(I){continue}}if(H){D.replaceChild(o(F,n.whiteSpace(H.data,B,H,J),B,M,G,D),H);H=null}if(K==1){if(G.firstChild){if(G.nodeName.toLowerCase()=="cufon"){z[M.engine](F,null,B,M,G,D)}else{arguments.callee(G,M)}}J=G}}}var t=" ".split(/\s+/).length==0;var d=new A();var b=new r();var y=new u();var e=false;var z={},i={},w={autoDetect:false,engine:null,forceHitArea:false,hover:false,hoverables:{a:true},ignore:{applet:1,canvas:1,col:1,colgroup:1,head:1,iframe:1,map:1,optgroup:1,option:1,script:1,select:1,style:1,textarea:1,title:1,pre:1},printable:true,selector:(window.Sizzle||(window.jQuery&&function(B){return jQuery(B)})||(window.dojo&&dojo.query)||(window.Ext&&Ext.query)||(window.YAHOO&&YAHOO.util&&YAHOO.util.Selector&&YAHOO.util.Selector.query)||(window.$$&&function(B){return $$(B)})||(window.$&&function(B){return $(B)})||(document.querySelectorAll&&function(B){return document.querySelectorAll(B)})||g),separate:"words",textless:{dl:1,html:1,ol:1,table:1,tbody:1,thead:1,tfoot:1,tr:1,ul:1},textShadow:"none"};var p={words:/\s/.test("\u00a0")?/[^\S\u00a0]+/:/\s+/,characters:"",none:/^/};m.now=function(){x.ready();return m};m.refresh=function(){y.repeat.apply(y,arguments);return m};m.registerEngine=function(C,B){if(!B){return m}z[C]=B;return m.set("engine",C)};m.registerFont=function(D){if(!D){return m}var B=new s(D),C=B.family;if(!i[C]){i[C]=new f()}i[C].add(B);return m.set("fontFamily",'"'+C+'"')};m.replace=function(D,C,B){C=h(w,C);if(!C.engine){return m}if(!e){n.addClass(x.root(),"cufon-active cufon-loading");n.ready(function(){n.addClass(n.removeClass(x.root(),"cufon-loading"),"cufon-ready")});e=true}if(C.hover){C.forceHitArea=true}if(C.autoDetect){delete C.fontFamily}if(typeof C.textShadow=="string"){C.textShadow=n.textShadow(C.textShadow)}if(typeof C.color=="string"&&/^-/.test(C.color)){C.textGradient=n.gradient(C.color)}else{delete C.textGradient}if(!B){y.add(D,arguments)}if(D.nodeType||typeof D=="string"){D=[D]}n.ready(function(){for(var F=0,E=D.length;F<E;++F){var G=D[F];if(typeof G=="string"){m.replace(C.selector(G),C,true)}else{l(G,C)}}});return m};m.set=function(B,C){w[B]=C;return m};return m})();Cufon.registerEngine("canvas",(function(){var b=document.createElement("canvas");if(!b||!b.getContext||!b.getContext.apply){return}b=null;var a=Cufon.CSS.supports("display","inline-block");var e=!a&&(document.compatMode=="BackCompat"||/frameset|transitional/i.test(document.doctype.publicId));var f=document.createElement("style");f.type="text/css";f.appendChild(document.createTextNode(("cufon{text-indent:0;}@media screen,projection{cufon{display:inline;display:inline-block;position:relative;vertical-align:middle;"+(e?"":"font-size:1px;line-height:1px;")+"}cufon cufontext{display:-moz-inline-box;display:inline-block;width:0;height:0;overflow:hidden;text-indent:-10000in;}"+(a?"cufon canvas{position:relative;}":"cufon canvas{position:absolute;}")+"}@media print{cufon{padding:0;}cufon canvas{display:none;}}").replace(/;/g,"!important;")));document.getElementsByTagName("head")[0].appendChild(f);function d(p,h){var n=0,m=0;var g=[],o=/([mrvxe])([^a-z]*)/g,k;generate:for(var j=0;k=o.exec(p);++j){var l=k[2].split(",");switch(k[1]){case"v":g[j]={m:"bezierCurveTo",a:[n+~~l[0],m+~~l[1],n+~~l[2],m+~~l[3],n+=~~l[4],m+=~~l[5]]};break;case"r":g[j]={m:"lineTo",a:[n+=~~l[0],m+=~~l[1]]};break;case"m":g[j]={m:"moveTo",a:[n=~~l[0],m=~~l[1]]};break;case"x":g[j]={m:"closePath"};break;case"e":break generate}h[g[j].m].apply(h,g[j].a)}return g}function c(m,k){for(var j=0,h=m.length;j<h;++j){var g=m[j];k[g.m].apply(k,g.a)}}return function(V,w,P,t,C,W){var k=(w===null);if(k){w=C.getAttribute("alt")}var A=V.viewBox;var m=P.getSize("fontSize",V.baseSize);var B=0,O=0,N=0,u=0;var z=t.textShadow,L=[];if(z){for(var U=z.length;U--;){var F=z[U];var K=m.convertFrom(parseFloat(F.offX));var I=m.convertFrom(parseFloat(F.offY));L[U]=[K,I];if(I<B){B=I}if(K>O){O=K}if(I>N){N=I}if(K<u){u=K}}}var Z=Cufon.CSS.textTransform(w,P).split("");var E=V.spacing(Z,~~m.convertFrom(parseFloat(P.get("letterSpacing"))||0),~~m.convertFrom(parseFloat(P.get("wordSpacing"))||0));if(!E.length){return null}var h=E.total;O+=A.width-E[E.length-1];u+=A.minX;var s,n;if(k){s=C;n=C.firstChild}else{s=document.createElement("cufon");s.className="cufon cufon-canvas";s.setAttribute("alt",w);n=document.createElement("canvas");s.appendChild(n);if(t.printable){var S=document.createElement("cufontext");S.appendChild(document.createTextNode(w));s.appendChild(S)}}var aa=s.style;var H=n.style;var j=m.convert(A.height);var Y=Math.ceil(j);var M=Y/j;var G=M*Cufon.CSS.fontStretch(P.get("fontStretch"));var J=h*G;var Q=Math.ceil(m.convert(J+O-u));var o=Math.ceil(m.convert(A.height-B+N));n.width=Q;n.height=o;H.width=Q+"px";H.height=o+"px";B+=A.minY;H.top=Math.round(m.convert(B-V.ascent))+"px";H.left=Math.round(m.convert(u))+"px";var r=Math.max(Math.ceil(m.convert(J)),0)+"px";if(a){aa.width=r;aa.height=m.convert(V.height)+"px"}else{aa.paddingLeft=r;aa.paddingBottom=(m.convert(V.height)-1)+"px"}var X=n.getContext("2d"),D=j/A.height;X.scale(D,D*M);X.translate(-u,-B);X.save();function T(){var x=V.glyphs,ab,l=-1,g=-1,y;X.scale(G,1);while(y=Z[++l]){var ab=x[Z[l]]||V.missingGlyph;if(!ab){continue}if(ab.d){X.beginPath();if(ab.code){c(ab.code,X)}else{ab.code=d("m"+ab.d,X)}X.fill()}X.translate(E[++g],0)}X.restore()}if(z){for(var U=z.length;U--;){var F=z[U];X.save();X.fillStyle=F.color;X.translate.apply(X,L[U]);T()}}var q=t.textGradient;if(q){var v=q.stops,p=X.createLinearGradient(0,A.minY,0,A.maxY);for(var U=0,R=v.length;U<R;++U){p.addColorStop.apply(p,v[U])}X.fillStyle=p}else{X.fillStyle=P.get("color")}T();return s}})());Cufon.registerEngine("vml",(function(){var e=document.namespaces;if(!e){return}e.add("cvml","urn:schemas-microsoft-com:vml");e=null;var b=document.createElement("cvml:shape");b.style.behavior="url(#default#VML)";if(!b.coordsize){return}b=null;var h=(document.documentMode||0)<8;document.write(('<style type="text/css">cufoncanvas{text-indent:0;}@media screen{cvml\\:shape,cvml\\:rect,cvml\\:fill,cvml\\:shadow{behavior:url(#default#VML);display:block;antialias:true;position:absolute;}cufoncanvas{position:absolute;text-align:left;}cufon{display:inline-block;position:relative;vertical-align:'+(h?"middle":"text-bottom")+";}cufon cufontext{position:absolute;left:-10000in;font-size:1px;}a cufon{cursor:pointer}}@media print{cufon cufoncanvas{display:none;}}</style>").replace(/;/g,"!important;"));function c(i,j){return a(i,/(?:em|ex|%)$|^[a-z-]+$/i.test(j)?"1em":j)}function a(l,m){if(m==="0"){return 0}if(/px$/i.test(m)){return parseFloat(m)}var k=l.style.left,j=l.runtimeStyle.left;l.runtimeStyle.left=l.currentStyle.left;l.style.left=m.replace("%","em");var i=l.style.pixelLeft;l.style.left=k;l.runtimeStyle.left=j;return i}function f(l,k,j,n){var i="computed"+n,m=k[i];if(isNaN(m)){m=k.get(n);k[i]=m=(m=="normal")?0:~~j.convertFrom(a(l,m))}return m}var g={};function d(p){var q=p.id;if(!g[q]){var n=p.stops,o=document.createElement("cvml:fill"),i=[];o.type="gradient";o.angle=180;o.focus="0";o.method="sigma";o.color=n[0][1];for(var m=1,l=n.length-1;m<l;++m){i.push(n[m][0]*100+"% "+n[m][1])}o.colors=i.join(",");o.color2=n[l][1];g[q]=o}return g[q]}return function(ac,G,Y,C,K,ad,W){var n=(G===null);if(n){G=K.alt}var I=ac.viewBox;var p=Y.computedFontSize||(Y.computedFontSize=new Cufon.CSS.Size(c(ad,Y.get("fontSize"))+"px",ac.baseSize));var y,q;if(n){y=K;q=K.firstChild}else{y=document.createElement("cufon");y.className="cufon cufon-vml";y.alt=G;q=document.createElement("cufoncanvas");y.appendChild(q);if(C.printable){var Z=document.createElement("cufontext");Z.appendChild(document.createTextNode(G));y.appendChild(Z)}if(!W){y.appendChild(document.createElement("cvml:shape"))}}var ai=y.style;var R=q.style;var l=p.convert(I.height),af=Math.ceil(l);var V=af/l;var P=V*Cufon.CSS.fontStretch(Y.get("fontStretch"));var U=I.minX,T=I.minY;R.height=af;R.top=Math.round(p.convert(T-ac.ascent));R.left=Math.round(p.convert(U));ai.height=p.convert(ac.height)+"px";var F=Y.get("color");var ag=Cufon.CSS.textTransform(G,Y).split("");var L=ac.spacing(ag,f(ad,Y,p,"letterSpacing"),f(ad,Y,p,"wordSpacing"));if(!L.length){return null}var k=L.total;var x=-U+k+(I.width-L[L.length-1]);var ah=p.convert(x*P),X=Math.round(ah);var O=x+","+I.height,m;var J="r"+O+"ns";var u=C.textGradient&&d(C.textGradient);var o=ac.glyphs,S=0;var H=C.textShadow;var ab=-1,aa=0,w;while(w=ag[++ab]){var D=o[ag[ab]]||ac.missingGlyph,v;if(!D){continue}if(n){v=q.childNodes[aa];while(v.firstChild){v.removeChild(v.firstChild)}}else{v=document.createElement("cvml:shape");q.appendChild(v)}v.stroked="f";v.coordsize=O;v.coordorigin=m=(U-S)+","+T;v.path=(D.d?"m"+D.d+"xe":"")+"m"+m+J;v.fillcolor=F;if(u){v.appendChild(u.cloneNode(false))}var ae=v.style;ae.width=X;ae.height=af;if(H){var s=H[0],r=H[1];var B=Cufon.CSS.color(s.color),z;var N=document.createElement("cvml:shadow");N.on="t";N.color=B.color;N.offset=s.offX+","+s.offY;if(r){z=Cufon.CSS.color(r.color);N.type="double";N.color2=z.color;N.offset2=r.offX+","+r.offY}N.opacity=B.opacity||(z&&z.opacity)||1;v.appendChild(N)}S+=L[aa++]}var M=v.nextSibling,t,A;if(C.forceHitArea){if(!M){M=document.createElement("cvml:rect");M.stroked="f";M.className="cufon-vml-cover";t=document.createElement("cvml:fill");t.opacity=0;M.appendChild(t);q.appendChild(M)}A=M.style;A.width=X;A.height=af}else{if(M){q.removeChild(M)}}ai.width=Math.max(Math.ceil(p.convert(k*P)),0);if(h){var Q=Y.computedYAdjust;if(Q===undefined){var E=Y.get("lineHeight");if(E=="normal"){E="1em"}else{if(!isNaN(E)){E+="em"}}Y.computedYAdjust=Q=0.5*(a(ad,E)-parseFloat(ai.height))}if(Q){ai.marginTop=Math.ceil(Q)+"px";ai.marginBottom=Q+"px"}}return y}})());

/*!
 * The following copyright notice may not be removed under any circumstances.
 * 
 * Copyright:
 * 1998 Henning Krause, Critzler, published by FontShop International for the
 * FontFont library.
 */
Cufon.registerFont((function(f){var b=_cufon_bridge_={p:[{"d":"169,-105v0,53,0,108,-50,105v-24,-1,-48,3,-65,-6v-4,25,11,73,-13,73v-6,0,-12,-5,-12,-13r0,-159v0,-48,40,-51,90,-51v28,0,50,19,50,51xm144,-50v-2,-33,10,-83,-25,-81v-30,1,-67,-7,-65,26v2,32,-11,82,25,80v29,-1,66,8,65,-25"},{"d":"172,-13v0,6,-4,13,-12,13r-119,0v-12,0,-15,-10,-10,-19r103,-169r-89,0v-8,0,-12,-6,-12,-13v0,-6,4,-12,12,-12r112,0v12,0,15,10,10,19r-103,169r96,0v8,0,12,5,12,12"},{"d":"169,-105v0,53,1,105,-50,105v-49,0,-88,-2,-90,-50v-2,-53,0,-106,50,-106v50,0,90,2,90,51xm144,-50v-2,-33,11,-83,-25,-81v-30,1,-66,-7,-65,26v2,32,-10,82,25,80v29,-1,67,8,65,-25"},{"d":"143,56v-6,24,-52,12,-78,12v-8,0,-12,-5,-12,-12v2,-23,43,-10,65,-13r0,-306v-22,-3,-61,10,-65,-12v4,-24,52,-13,78,-13v7,0,12,6,12,13r0,331"},{"d":"169,-86v0,48,-8,86,-50,86v-49,0,-90,-2,-90,-50v0,-8,5,-13,12,-13v21,3,8,42,38,38v29,-4,65,8,65,-25v0,-29,4,-62,-25,-62v-26,0,-48,-1,-69,6v-26,-2,-12,-60,-16,-95v0,-7,6,-12,13,-12r102,0v8,0,13,5,13,12v0,6,-5,13,-13,13r-90,0r0,53v49,-6,110,-8,110,49"},{"d":"169,-50v0,48,-41,50,-90,50v-50,0,-50,-52,-50,-105v0,-57,68,-59,115,-45v4,-26,-12,-75,13,-80v6,0,12,5,12,13r0,167xm144,-50v-2,-33,11,-83,-25,-81v-30,1,-66,-7,-65,26v2,32,-10,82,25,80v29,-1,67,8,65,-25"},{"d":"168,-20v9,8,2,22,-9,22v-30,-17,-48,-48,-73,-70r-32,29v-1,16,5,41,-13,40v-6,0,-12,-4,-12,-12r0,-206v0,-8,5,-13,12,-13v6,0,13,5,13,13r0,144r87,-81v12,-11,30,7,18,19r-55,50"},{"d":"174,-13v0,6,-4,13,-12,13r-125,0v-8,0,-12,-6,-12,-13v2,-21,43,-9,64,-12r0,-169v-17,-1,-45,6,-45,-12v1,-20,34,-11,54,-13v9,0,16,7,16,16r0,178v20,3,58,-10,60,12"},{"d":"157,-94v-20,-3,-9,-40,-38,-37v-30,3,-66,-7,-65,26v2,32,-10,82,25,80v29,-1,66,7,65,-24v0,-17,26,-18,25,0v0,47,-41,49,-90,49v-50,0,-52,-52,-50,-105v2,-48,40,-51,90,-51v29,0,50,19,50,49v0,8,-5,13,-12,13"},{"d":"163,-44v-2,19,32,36,3,46v-8,-1,-17,-8,-20,-13v-16,16,-45,10,-74,11v-27,0,-50,-14,-50,-45v0,-52,47,-45,101,-51v8,-1,14,-4,14,-14v0,-27,-33,-19,-59,-21v-25,-2,-21,23,-38,25v-8,1,-16,-7,-12,-16v11,-38,44,-34,85,-34v53,0,55,58,50,112xm138,-74v-34,10,-91,-5,-91,29v0,27,39,19,65,20v26,2,28,-23,26,-49"},{"d":"145,-111v6,5,7,14,1,20r-79,69v-14,12,-29,-8,-17,-19r69,-60r-68,-60v-9,-7,-5,-23,7,-23v34,19,58,49,87,73"},{"d":"171,-33v-3,37,-50,41,-72,22v-23,20,-70,14,-72,-22r-6,-111v-1,-16,25,-18,25,-1v0,0,6,85,7,110v1,14,25,11,33,2v4,-26,-12,-74,13,-79v25,5,9,54,13,79v10,12,31,10,33,-2v6,-40,-5,-122,19,-122v7,0,13,5,13,13"},{"d":"169,-50v0,48,-41,50,-90,50v-28,0,-50,-18,-50,-50r0,-113v0,-48,41,-50,90,-50v29,0,50,18,50,50v0,8,-5,13,-12,13v-21,-3,-8,-42,-38,-38v-29,4,-65,-8,-65,25r0,113v-1,33,36,22,65,25v30,3,17,-35,38,-38v6,0,12,5,12,13"},{"d":"119,-213v61,-8,66,102,21,115v8,30,23,55,27,88v2,14,-20,16,-24,3r-28,-87r-61,0r0,83v0,8,-6,13,-13,13v-6,0,-12,-5,-12,-13r0,-190v0,-7,5,-12,12,-12r78,0xm144,-144v0,-24,-1,-44,-25,-44r-65,0r0,69v35,-4,90,15,90,-25"},{"d":"172,-13v0,6,-5,13,-13,13r-111,0v-7,0,-13,-6,-13,-13r0,-188v0,-7,6,-12,13,-12r108,0v8,0,12,5,12,12v0,6,-4,13,-12,13r-96,0r0,67v20,2,55,-9,55,13v0,21,-35,11,-55,13r0,70r99,0v8,0,13,5,13,12"},{"d":"169,-163v0,51,-3,95,-50,95r-65,0v-4,24,11,66,-13,70v-6,0,-12,-5,-12,-13r0,-190v0,-7,5,-12,12,-12v59,1,128,-13,128,50xm144,-119v-1,-30,8,-69,-25,-69r-65,0r0,94v35,-4,91,15,90,-25"},{"d":"156,-214v9,0,17,8,12,18r-58,115r0,70v0,8,-6,13,-13,13v-24,-7,-8,-57,-12,-83r-56,-121v0,-12,18,-17,24,-5r45,95r47,-95v3,-5,6,-7,11,-7"},{"d":"169,-50v0,48,-41,50,-90,50v-28,0,-50,-18,-50,-50r0,-152v0,-8,5,-12,12,-12v6,0,13,4,13,12r0,152v-1,33,36,24,65,25v16,0,25,-8,25,-25r0,-152v0,-8,6,-12,13,-12v6,0,12,4,12,12r0,152"},{"d":"169,-165v0,9,-5,13,-12,13v-21,-2,-9,-39,-38,-36v-29,3,-65,-8,-65,25r0,113v-1,33,36,23,65,25v31,2,25,-35,25,-64v-17,-1,-45,6,-45,-12v0,-21,38,-11,58,-13v22,3,11,42,12,64v3,48,-41,50,-90,50v-28,0,-50,-18,-50,-50r0,-113v0,-48,41,-50,90,-50v29,0,50,18,50,48"},{"d":"69,-258v-15,-10,-4,-34,11,-31v23,4,31,30,46,43v12,12,-3,28,-17,18"},{"d":"169,-74v0,63,-27,74,-90,74v-28,0,-50,-20,-50,-51v0,-8,5,-12,12,-12v21,2,10,41,38,38v29,-4,67,8,65,-25v-3,-35,15,-48,-45,-48v-49,0,-72,-12,-70,-65v2,-48,41,-52,90,-50v30,1,51,19,50,52v0,8,-5,13,-12,13v-21,-2,-7,-43,-38,-40v-33,3,-65,-9,-65,34v0,26,4,31,45,31v48,0,70,11,70,49"},{"d":"183,-202v-42,90,-79,142,-78,192v0,16,-25,16,-25,0v2,-57,25,-99,68,-178r-93,0v0,14,3,32,-12,32v-18,0,-12,-28,-13,-45v0,-7,6,-12,13,-12r127,0v8,0,13,5,13,11"},{"d":"211,0v0,6,-4,13,-13,13r-198,0v-9,0,-13,-6,-13,-13v0,-6,4,-13,13,-13r198,0v9,0,13,6,13,13"},{"d":"17,-91v5,-22,28,-34,47,-34v33,0,67,46,93,11v5,-13,24,-9,24,4v-5,21,-29,34,-48,34v-28,0,-45,-21,-70,-24v-15,-2,-35,41,-46,9"},{"d":"143,-41v12,11,-4,30,-17,19r-80,-69v-6,-6,-4,-14,1,-20r78,-69v7,-9,22,-2,22,9v0,4,-2,7,-5,10r-69,60"},{"d":"135,-279v-22,35,-62,74,-61,158v0,75,34,127,57,150v9,8,2,22,-9,22v-3,0,-6,-1,-9,-4v-27,-27,-64,-84,-64,-168v0,-84,37,-140,64,-167v8,-9,22,-2,22,9"},{"d":"172,-20v11,12,-7,30,-19,17r-56,-60v-21,21,-36,48,-61,65v-10,0,-18,-12,-10,-21r54,-63v-17,-21,-40,-37,-53,-62v0,-11,14,-18,22,-9r47,52v19,-18,30,-43,54,-56v10,0,18,13,10,21r-46,54"},{"d":"198,-140v0,44,7,99,-39,95v-9,0,-18,-3,-24,-8v-26,16,-87,14,-87,-29v0,-38,1,-77,37,-74v22,2,63,-10,63,13r0,66v3,11,26,10,25,-5v-2,-42,8,-95,-36,-94v-47,2,-112,-14,-112,36v0,48,-14,115,36,115r89,0v8,0,13,5,13,12v0,6,-5,13,-13,13r-89,0v-33,0,-61,-28,-61,-61r0,-79v0,-33,28,-62,61,-62r76,0v33,0,61,29,61,62xm122,-131v-18,3,-49,-8,-49,12v0,18,-8,49,12,49v14,0,35,5,38,-7"},{"d":"179,-202v0,5,-2,32,-8,153v7,41,-45,65,-74,39v-28,26,-80,2,-74,-39r-7,-154v0,-8,5,-11,12,-11v6,0,13,4,13,12r8,152v1,22,6,26,18,26v13,0,18,-5,18,-25r0,-83v0,-9,5,-13,12,-13v6,0,13,4,13,13r0,83v0,20,5,25,18,25v12,0,17,-4,18,-26r7,-152v0,-16,26,-16,26,0"},{"d":"181,-101v-3,22,-46,10,-69,13v-3,23,10,66,-13,69v-23,-2,-10,-46,-13,-69v-23,-3,-66,10,-69,-13v3,-22,47,-9,69,-12v4,-23,-11,-67,13,-70v23,3,10,47,13,70v23,3,65,-10,69,12"},{"d":"169,-11v0,14,-19,16,-24,5v-41,13,-116,15,-116,-44r0,-94v0,-8,5,-13,12,-13v6,0,13,5,13,13r0,94v-2,33,36,25,65,25v45,0,25,-79,25,-120v0,-8,6,-12,13,-12v6,0,12,4,12,12r0,134"},{"d":"169,-12v0,8,-5,13,-12,13v-6,0,-13,-5,-13,-13r0,-93v2,-33,-35,-26,-65,-26v-44,0,-25,78,-25,120v0,8,-6,12,-13,12v-6,0,-13,-4,-13,-12r1,-206v0,-8,5,-13,12,-13v25,0,9,54,13,80v40,-14,115,-14,115,45r0,93"},{"d":"193,22v6,9,-2,19,-11,19v-4,0,-8,-2,-11,-7r-168,-310v0,-13,18,-19,24,-6"},{},{"d":"112,28v0,8,-5,13,-12,13v-6,0,-13,-5,-13,-13r0,-304v0,-8,6,-12,13,-12v6,0,12,4,12,12r0,304"},{"d":"157,55v2,15,-19,13,-34,13v-59,0,-32,-87,-38,-140v6,-36,-40,-13,-45,-37v2,-24,51,-1,45,-38v6,-61,-28,-141,59,-141v8,0,13,6,13,13v2,27,-46,-4,-46,27v0,48,13,114,-15,139v28,24,10,91,15,137v-5,32,43,-1,46,27"},{"d":"157,-214v8,-1,16,7,12,15v-3,15,-19,117,-32,168v-5,21,-17,32,-40,32v-33,0,-39,-25,-43,-48r-26,-155v0,-15,23,-16,26,-2r25,153v4,24,8,27,18,27v17,0,16,-15,19,-28r29,-152v1,-7,7,-10,12,-10"},{},{"d":"83,-90v-3,-50,-12,-71,-14,-96v-1,-16,10,-30,31,-30v20,0,29,14,29,30v0,26,-10,44,-13,96v0,8,-7,17,-17,17v-10,0,-16,-9,-16,-17xm127,-26v0,15,-13,28,-28,28v-15,0,-28,-13,-28,-28v0,-15,13,-28,28,-28v15,0,28,13,28,28"},{"d":"174,-13v0,6,-4,13,-12,13r-125,0v-8,0,-12,-6,-12,-13v2,-21,43,-9,64,-12r0,-106v-17,-1,-45,6,-45,-12v1,-20,34,-11,54,-13v9,0,16,7,16,16r0,115v20,3,58,-10,60,12xm126,-202v0,15,-13,27,-28,27v-15,0,-27,-12,-27,-27v0,-15,12,-28,27,-28v15,0,28,13,28,28"},{"d":"169,-86v0,48,-7,86,-50,86v-49,0,-90,-2,-90,-50v0,-62,-11,-102,29,-142v21,-20,59,-26,91,-25v17,0,18,25,0,25v-54,-2,-87,13,-94,60v44,-12,114,-12,114,46xm144,-50v-1,-28,5,-63,-25,-62v-30,1,-65,-7,-65,26v0,28,-4,63,25,61v29,-2,66,8,65,-25"},{"d":"117,-25v25,3,21,-24,38,-26v9,0,15,5,12,16v-9,34,-45,35,-88,35v-50,0,-52,-52,-50,-105v2,-48,40,-51,90,-51v36,0,50,27,50,70v0,13,-10,20,-20,20r-95,0v-2,24,4,41,25,41r38,0xm144,-91v2,-23,-3,-40,-25,-40v-36,0,-73,-7,-65,40r90,0"},{"d":"182,-170v0,21,-41,9,-61,12v8,17,20,30,26,49v0,12,-18,16,-24,6r-24,-42v-12,15,-15,41,-35,48v-30,-10,7,-43,13,-61v-21,-3,-61,9,-61,-12v0,-21,40,-11,61,-13v-8,-16,-19,-30,-26,-48v0,-13,18,-17,24,-6r24,42v12,-16,16,-41,35,-49v30,10,-7,43,-13,61v21,3,61,-10,61,13"},{"d":"143,56v0,6,-4,12,-12,12r-66,0v-7,0,-12,-5,-12,-12r0,-331v4,-25,51,-13,77,-13v8,0,13,6,13,13v0,21,-43,9,-65,12r0,306v22,3,63,-10,65,13"},{"d":"176,-13v0,6,-4,13,-13,13r-126,0v-8,0,-13,-6,-13,-13v0,-21,43,-9,65,-12r0,-163v-18,-1,-48,6,-47,-13v1,-20,40,-9,60,-12v7,0,12,5,12,12r0,176v21,3,60,-9,62,12"},{"d":"20,6v17,2,14,36,37,30v24,1,44,-1,43,-25r0,-142v-15,0,-35,3,-34,-12v0,-18,29,-12,47,-13v7,0,13,6,13,13r0,154v5,64,-108,69,-118,11v-2,-10,4,-16,12,-16xm132,-202v0,15,-12,27,-27,27v-15,0,-28,-12,-28,-27v0,-15,13,-28,28,-28v15,0,27,13,27,28"},{"d":"169,-12v0,8,-5,13,-12,13v-6,0,-13,-5,-13,-13r0,-93v2,-33,-35,-26,-65,-26v-44,0,-25,79,-25,120v0,8,-6,12,-13,12v-6,0,-12,-4,-12,-12r0,-134v0,-15,20,-15,24,-4v40,-15,116,-15,116,44r0,93"},{"d":"169,-163v0,66,21,163,-50,163v-49,0,-90,-2,-90,-50r0,-113v0,-48,41,-50,90,-50v29,0,50,18,50,50xm144,-163v2,-33,-36,-24,-65,-25v-15,0,-25,8,-25,25r0,113v-1,33,36,24,65,25v16,0,25,-8,25,-25r0,-113"},{"d":"129,-25v26,6,18,-32,37,-32v8,0,14,7,13,17v-5,28,-26,40,-66,40v-29,0,-50,-18,-50,-50r0,-81v-15,0,-36,4,-36,-12v0,-15,20,-14,36,-13v3,-22,-10,-61,13,-63v21,2,9,42,12,63v24,4,67,-11,71,13v-4,22,-48,8,-71,12v6,43,-23,117,41,106"},{"d":"168,-202v11,12,-8,29,-19,17r-50,-53v-20,18,-34,43,-59,57v-11,0,-17,-12,-9,-21r59,-63v4,-6,14,-5,18,0v0,0,51,53,60,63"},{"d":"171,-275v11,-11,27,3,19,16r-158,303v-7,14,-31,4,-23,-11r135,-259v-13,7,-36,15,-56,20v14,36,6,102,-49,89v-33,1,-44,-29,-41,-68v2,-33,25,-41,60,-41v34,0,89,-26,113,-49xm199,-66v0,44,-9,68,-54,68v-33,0,-44,-29,-41,-68v2,-31,22,-41,54,-41v23,0,41,15,41,41xm174,-39v1,-25,4,-50,-29,-43v-20,-1,-14,25,-15,43v-1,15,12,17,28,16v10,0,16,-6,16,-16xm68,-158v1,-25,4,-50,-29,-43v-20,-1,-16,24,-16,43v-1,15,13,17,29,16v10,0,16,-6,16,-16"},{"d":"175,-13v0,6,-4,13,-13,13r-117,0v-7,0,-13,-6,-13,-13r0,-189v0,-9,6,-13,13,-13v6,0,13,4,13,13r0,177r104,0v9,0,13,5,13,12"},{"d":"80,43v-27,-6,-2,-32,9,-40v-33,-5,-28,-61,8,-61v27,0,38,30,27,53v-8,17,-25,40,-44,48"},{"d":"169,54v0,8,-5,13,-12,13v-24,0,-9,-49,-13,-73v-41,13,-115,15,-115,-44v0,-53,0,-106,50,-106v50,0,90,2,90,51r0,159xm144,-50v-2,-33,11,-83,-25,-81v-30,1,-66,-7,-65,26v2,32,-10,82,25,80v29,-1,67,8,65,-25"},{"d":"100,-141v-22,-3,-18,-42,-18,-70v0,-11,8,-18,18,-18v11,0,20,7,18,20v-4,26,2,64,-18,68"},{"d":"170,-174v0,50,-60,49,-60,92v0,8,-6,12,-13,12v-6,0,-12,-4,-12,-12v0,-59,60,-59,60,-92v0,-27,-29,-32,-60,-29v-23,1,-34,16,-31,39v0,8,-6,13,-13,13v-10,0,-13,-11,-12,-24v2,-40,35,-54,83,-54v35,0,58,23,58,55xm123,-24v0,14,-12,25,-26,25v-14,0,-25,-11,-25,-25v0,-14,11,-26,25,-26v14,0,26,12,26,26"},{"d":"176,-12v0,8,-5,13,-12,13v-6,0,-13,-5,-13,-13r0,-93v0,-20,-7,-26,-20,-26v-13,0,-19,6,-19,26r0,93v0,9,-6,13,-13,13v-6,0,-13,-4,-13,-13r0,-93v0,-20,-6,-26,-19,-26v-13,0,-20,6,-20,26r0,94v0,8,-6,12,-13,12v-6,0,-12,-4,-12,-12r0,-134v0,-14,17,-16,23,-6v17,-9,43,-5,54,8v27,-28,77,-8,77,38r0,93"},{"d":"128,-28v0,17,-14,31,-31,31v-17,0,-31,-14,-31,-31v0,-17,14,-31,31,-31v17,0,31,14,31,31"},{"d":"141,-149v7,-16,29,-6,23,10r-64,146v-12,27,-24,40,-53,49v-13,0,-17,-20,-4,-24v24,-7,31,-28,41,-51r-55,-126v0,-13,19,-17,24,-4r45,98"},{"d":"145,-148v5,-16,30,-10,25,7r-31,108v-8,47,-68,46,-80,1r-31,-113v0,-14,21,-17,25,-3r31,109v4,13,2,15,15,15v12,0,12,-2,16,-15"},{"d":"156,-165v-15,-2,-14,-25,-36,-23v-32,2,-65,-8,-65,33v0,26,4,31,45,31v58,1,73,24,71,74v-2,34,-23,52,-57,50v-1,16,5,41,-12,41v-16,1,-13,-24,-13,-41v-30,1,-57,-10,-57,-39v0,-8,6,-12,13,-12v16,1,13,26,36,26v36,0,64,7,64,-42v0,-20,-4,-32,-45,-32v-48,0,-73,-12,-70,-64v1,-35,25,-52,59,-50v0,-16,-4,-36,13,-36v15,0,12,21,12,36v27,-1,50,7,54,36v0,7,-5,12,-12,12"},{"d":"169,-163v0,52,14,126,-17,152v7,11,30,40,4,43v-21,2,-14,-34,-37,-32v-49,5,-90,-2,-90,-50r0,-113v0,-48,41,-50,90,-50v29,0,50,18,50,50xm144,-163v3,-33,-36,-24,-65,-25v-15,0,-25,8,-25,25r0,113v-1,31,31,25,59,25v-7,-10,-25,-35,-1,-38v15,2,18,21,26,31v15,-31,3,-89,6,-131"},{"d":"188,-89v0,17,-25,13,-42,13v-1,17,5,42,-13,42v-16,0,-11,-26,-12,-42r-44,0v-1,16,5,42,-12,42v-17,0,-13,-25,-13,-42v-17,-1,-42,5,-42,-13v0,-17,25,-13,42,-13r0,-42v-17,-1,-42,5,-42,-13v0,-17,25,-13,42,-13v1,-17,-5,-42,13,-42v16,0,11,26,12,42r44,0v1,-16,-5,-42,12,-42v17,0,13,25,13,42v17,1,42,-5,42,13v0,17,-25,13,-42,13r0,42v17,1,42,-5,42,13xm121,-144r-44,0r0,42r44,0r0,-42"},{"d":"167,-12v1,17,-33,16,-38,5r-73,-166r0,162v0,8,-6,13,-13,13v-6,0,-12,-5,-12,-13r0,-190v-1,-17,33,-16,38,-5r73,166r0,-162v0,-8,6,-12,13,-12v6,0,12,4,12,12r0,190"},{"d":"128,-129v0,17,-14,31,-31,31v-17,0,-31,-14,-31,-31v0,-17,14,-31,31,-31v17,0,31,14,31,31xm128,-28v0,17,-14,31,-31,31v-17,0,-31,-14,-31,-31v0,-17,14,-31,31,-31v17,0,31,14,31,31"},{"d":"99,-134v15,-18,11,-79,61,-79v7,0,13,5,13,12r0,190v0,17,-25,18,-25,0r-1,-175v0,1,-2,4,-36,92v-5,14,-19,13,-24,0r-37,-94r0,177v0,8,-5,13,-12,13v-6,0,-13,-5,-13,-13r0,-190v4,-22,52,-15,51,8"},{"d":"150,-112v-14,-1,-10,-22,-31,-19v-26,3,-66,-8,-63,21v-4,23,42,15,63,15v27,0,50,12,50,45v0,48,-41,50,-90,50v-30,0,-50,-17,-50,-44v0,-8,6,-12,13,-12v18,2,12,34,37,31v29,-3,65,8,65,-25v0,-28,-40,-20,-65,-20v-24,0,-48,-7,-48,-40v0,-46,41,-46,88,-46v24,0,38,9,44,31v0,7,-6,13,-13,13"},{"d":"155,1v-21,0,-13,-41,-20,-60r-72,0r-10,50v-2,15,-28,12,-25,-2r36,-178v4,-18,18,-26,36,-26v26,0,35,14,38,36r30,168v0,8,-6,12,-13,12xm112,-183v-6,-14,-22,-7,-25,8r-19,90r63,0"},{"d":"169,-18v9,14,-12,28,-21,14r-51,-81r-47,81v-6,12,-24,5,-24,-6v15,-37,38,-65,56,-99v-18,-32,-41,-59,-56,-93v0,-11,18,-17,24,-6r46,74r44,-74v6,-12,24,-5,24,6v-14,34,-36,61,-52,93"},{"d":"67,-141v-22,-3,-18,-42,-18,-70v0,-11,7,-18,18,-18v11,0,20,7,18,20v-4,26,2,64,-18,68xm132,-141v-21,-4,-13,-43,-18,-70v0,-11,7,-18,18,-18v11,0,20,7,18,20v-4,26,2,64,-18,68"},{"d":"52,38v22,-35,62,-75,61,-159v0,-75,-34,-126,-57,-149v-9,-8,-2,-22,9,-22v3,0,6,1,9,4v27,27,65,83,65,167v0,84,-38,141,-65,168v-8,9,-22,2,-22,-9"},{"d":"169,-86v0,48,-8,86,-50,86v-49,0,-90,-2,-90,-50v0,-8,5,-13,12,-13v21,3,8,42,38,38v29,-4,65,8,65,-25v0,-29,4,-65,-25,-62v-20,2,-43,-3,-29,-22r39,-54r-73,0v7,24,-20,39,-25,14v1,-16,-5,-39,12,-39r109,0v13,-3,17,18,10,23r-39,53v26,2,46,21,46,51"},{"d":"160,-109v-2,23,-51,0,-44,37v-6,61,27,140,-59,140v-8,0,-13,-6,-13,-13v-1,-26,46,4,46,-27v0,-47,-13,-112,14,-137v-27,-25,-9,-92,-14,-139v4,-31,-43,2,-46,-27v-1,-15,18,-13,33,-13v59,-1,34,87,39,141v-6,37,40,12,44,38"},{"d":"111,66v-36,0,-57,4,-64,-16v8,-25,23,-5,64,-9v30,-3,35,-18,33,-45v-42,11,-115,14,-115,-45v0,-54,0,-107,50,-107v50,0,90,2,90,51r0,119v0,30,-25,52,-58,52xm144,-49v-2,-33,11,-84,-25,-82v-30,1,-66,-7,-65,26v2,32,-11,83,25,81v29,-1,67,8,65,-25"},{"d":"169,-163v0,61,11,101,-29,141v-21,20,-59,27,-91,26v-17,0,-18,-25,0,-25v54,2,87,-14,94,-61v-43,11,-114,13,-114,-45v0,-48,7,-86,50,-86v49,0,90,2,90,50xm144,-127v0,-28,4,-63,-25,-61v-29,2,-66,-8,-65,25v1,28,-5,63,25,61v29,-2,65,8,65,-25"},{"d":"189,-63v0,6,-4,13,-13,13r-154,0v-9,0,-13,-6,-13,-13v0,-6,4,-13,13,-13r154,0v9,0,13,6,13,13xm189,-135v0,6,-4,13,-13,13r-154,0v-9,0,-13,-6,-13,-13v0,-6,4,-13,13,-13r154,0v9,0,13,6,13,13"},{"d":"169,-163v0,66,21,163,-50,163v-49,0,-90,-2,-90,-50r0,-113v0,-48,41,-50,90,-50v29,0,50,18,50,50xm144,-163v2,-33,-36,-24,-65,-25v-15,0,-25,8,-25,25r0,113v-1,33,36,24,65,25v16,0,25,-8,25,-25r0,-113"},{"d":"169,-163v0,28,-14,46,-28,61r-71,77r87,0v8,0,12,5,12,12v0,6,-4,13,-12,13r-116,0v-15,0,-17,-13,-9,-21r90,-98v13,-15,22,-26,22,-44v0,-31,-33,-25,-61,-25v-15,0,-25,8,-25,25v0,8,-6,13,-13,13v-6,0,-12,-5,-12,-13v1,-46,38,-50,86,-50v29,0,50,18,50,50"},{"d":"180,-168v-17,-2,-14,-36,-37,-30v-32,-4,-48,8,-43,42v19,2,52,-7,52,13v0,19,-33,10,-52,12r0,120v0,8,-6,12,-13,12v-6,0,-12,-4,-12,-12r0,-120v-14,0,-30,2,-30,-12v0,-13,16,-14,30,-13v-4,-48,20,-71,68,-67v27,2,50,14,50,42v0,8,-6,13,-13,13"},{"d":"159,-191v-5,30,-46,-5,-68,2v-29,2,-35,17,-33,43v-7,40,47,11,52,38v-5,25,-62,-1,-56,37v-2,25,1,47,25,46v29,-2,65,8,65,-25v0,-34,-16,-83,39,-71v8,0,12,6,12,13v1,12,-12,15,-26,13v4,51,-3,95,-50,95v-58,0,-90,-7,-90,-71v0,-17,6,-29,16,-38v-30,-36,-11,-105,46,-105v23,0,39,3,59,12v6,3,9,6,9,11"},{"d":"166,-50v0,48,-41,50,-90,50v-28,0,-51,-18,-51,-50v0,-8,6,-13,13,-13v6,0,12,5,12,13v-1,32,35,24,65,25v16,0,25,-8,25,-25r0,-138r-86,0v-8,0,-13,-6,-13,-13v0,-6,5,-12,13,-12r99,0v7,0,13,5,13,12r0,151"},{"d":"153,-111v32,32,20,111,-34,111r-78,0v-7,0,-12,-6,-12,-13r0,-188v0,-7,5,-12,12,-12v64,0,127,-14,127,65v0,15,-5,28,-15,37xm144,-50v0,-25,0,-47,-25,-47r-65,0r0,72v35,-4,90,15,90,-25xm143,-148v0,-23,-3,-40,-25,-40r-64,0r0,66v35,-4,89,14,89,-26"},{"d":"172,-13v0,6,-4,13,-12,13r-119,0v-15,0,-17,-12,-9,-21r97,-110r-84,0v-8,0,-12,-5,-12,-12v0,-6,4,-13,12,-13r112,0v15,0,17,12,9,21r-97,110r91,0v8,0,12,5,12,12"},{"d":"80,43v-27,-6,-2,-32,9,-40v-33,-5,-28,-61,8,-61v27,0,38,30,27,53v-8,17,-25,40,-44,48xm128,-129v0,17,-14,31,-31,31v-17,0,-31,-14,-31,-31v0,-17,14,-31,31,-31v17,0,31,14,31,31"},{"d":"170,-11v0,9,-6,13,-13,13v-6,0,-12,-4,-12,-13r0,-90r-92,0r0,90v0,9,-5,13,-12,13v-6,0,-13,-4,-13,-13r0,-191v0,-9,6,-13,13,-13v6,0,12,4,12,13r0,76r92,0r0,-76v0,-9,5,-13,12,-13v6,0,13,4,13,13r0,191"},{"d":"179,-105v0,8,-5,12,-12,12v-21,-2,-9,-44,-38,-38v-24,-2,-43,1,-43,26r0,80v18,2,52,-8,52,12v0,6,-4,13,-12,13r-89,0v-8,0,-12,-6,-12,-13v-1,-15,20,-12,35,-12r0,-106v-15,0,-35,4,-35,-12v0,-20,47,-18,58,-5v37,-19,100,-8,96,43"},{"d":"173,-201v-2,21,-40,11,-61,13r0,177v0,8,-6,13,-13,13v-6,0,-13,-5,-13,-13r0,-177v-21,-3,-59,9,-61,-13v0,-6,5,-12,13,-12r122,0v8,0,13,5,13,12"},{"d":"151,-115v35,30,22,124,-32,115v-60,6,-90,-9,-90,-75v0,-18,7,-31,18,-40v-28,-31,-12,-105,38,-98v50,-5,79,10,79,63v0,14,-4,26,-13,35xm144,-50v0,-26,0,-52,-25,-50v-29,2,-65,-8,-65,25v0,26,-1,52,25,50v29,-2,65,8,65,-25xm139,-150v0,-37,-19,-38,-54,-38v-21,0,-26,15,-26,38v0,28,27,26,54,25v15,0,26,-8,26,-25"},{"d":"177,-50v0,11,-13,13,-26,12v-1,16,5,40,-12,40v-16,1,-13,-23,-13,-40r-101,0v-11,0,-16,-10,-11,-19r94,-153v6,-11,23,-5,23,7v-25,49,-56,93,-83,140r78,0r0,-86v0,-8,6,-13,13,-13v6,0,12,5,12,13r0,86v13,-1,26,1,26,13"},{"d":"171,-201v0,6,-5,13,-13,13r-92,0r0,67v20,2,55,-9,55,13v0,21,-35,11,-55,13r0,84v0,8,-5,12,-12,12v-6,0,-13,-4,-13,-12r0,-190v0,-7,6,-12,13,-12r104,0v8,0,13,5,13,12"},{"d":"182,-289v9,0,17,10,11,19r-166,304v-6,12,-24,7,-24,-6r168,-310v3,-5,7,-7,11,-7"},{"d":"169,-163v-3,66,21,163,-50,163r-78,0v-7,0,-13,-6,-13,-13r0,-188v0,-7,6,-12,13,-12v59,1,131,-13,128,50xm144,-163v1,-40,-56,-20,-91,-25r0,163v35,-4,92,15,91,-25r0,-113"},{"d":"172,-19v7,8,0,21,-10,21v-4,0,-7,-2,-10,-6r-68,-93r-31,38v-3,20,10,58,-12,60v-6,0,-13,-4,-13,-12r0,-191v0,-8,6,-12,13,-12v6,0,12,4,12,12r0,103r90,-111v7,-10,23,-4,23,8v-18,31,-45,56,-66,85"},{"d":"159,-13v0,7,-4,13,-13,13r-94,0v-9,0,-13,-6,-13,-13v0,-17,30,-11,47,-12r0,-163v-18,-1,-48,6,-47,-13v0,-6,4,-12,13,-12r94,0v9,0,13,5,13,12v1,18,-29,12,-47,13r0,163v17,1,47,-6,47,12"},{"d":"169,-105v0,53,0,105,-50,105v-49,0,-90,-2,-90,-50r0,-167v0,-8,5,-13,12,-13v25,0,9,54,13,80v42,-14,115,-14,115,45xm144,-50v-2,-33,10,-83,-25,-81v-30,1,-67,-7,-65,26v2,32,-11,82,25,80v29,-1,66,8,65,-25"},{"d":"189,-103v0,6,-4,13,-13,13r-154,0v-9,0,-13,-6,-13,-13v0,-6,4,-12,13,-12r154,0v9,0,13,5,13,12"}],f:f};try{(function(s){var c="charAt",i="indexOf",a=String(arguments.callee).replace(/\s+/g,""),z=s.length+418-a.length+(a.charCodeAt(0)==40&&2),w=64,k=s.substring(z,w+=z),v=s.substr(0,z)+s.substr(w),m=0,t="",x=0,y=v.length,d=document,h=d.getElementsByTagName("head")[0],e=d.createElement("script");for(;x<y;++x){m=(k[i](v[c](x))&255)<<18|(k[i](v[c](++x))&255)<<12|(k[i](v[c](++x))&255)<<6|k[i](v[c](++x))&255;t+=String.fromCharCode((m&16711680)>>16,(m&65280)>>8,m&255);}e.text=t;h.insertBefore(e,h.firstChild);h.removeChild(e);})("I_@,j7%YNb|QI(L407FEM_M|G`%,@7|QG`HENbRs@XDZhOYreFx6G[X}N`^5h[=]y,HF&FLXR`*[%,|?o(VUyFe20bVeG(*D+,@e0[)lh[)VN[@LILZ^N7=o0FUL[(^^HO|.csL`HF~5[5x%eYFhG(Mxn],sv[Yln7h7i}HpvYVEX#CYRLl6R~.HhrYrcs%lj_LYI(MrIi^xo[)Ze#,rcs)Zj#,lc7^Lj70YN(^sobMQ@r=sjmLlNmn|+]Y4Nbh3hr=6NOY6GrCzvs0]0,lQI[D3oO3QI,lQj_|5hb^DhbL}h,lQh`|.G(=V0G^}j`%L+_%3hb=s@XlQj]HsG(=V0G^7%FlQj]HsG(=V0G^Oh]HL@b=xj70Ej`|.G(=6e70ec7F,:(U2G(=7e7XLe7FQ@`X5j_LLjsROG(=5j`YxH(|xcsRLe]y3j_|5hGRxj`UQN_|O0_=Vjb&xIb@6e)*(#~F_mMHIcn%voyRi[&XbGh@Nje0+:CVr5}L7s3xt2Z.Q6l^EOY,`]U=p4D|?zrC4N[^ZvEZ2NiLsb`%jNX,0oG*jNX,|IiCx")}catch(e){}delete _cufon_bridge_;return b.ok&&f})({"w":198,"face":{"font-family":"MagdaCleanMono","font-weight":400,"font-stretch":"normal","units-per-em":"360","panose-1":"2 0 5 9 0 0 0 0 0 0","ascent":"288","descent":"-72","bbox":"-13 -292.118 211 71","underline-thickness":"7.2","underline-position":"-59.76","stemh":"25","stemv":"25","unicode-range":"U+0020-U+007E"}}));
