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


Effect.OpenUp = function(element) {
     element = $(element);
     new Effect.BlindDown(element, arguments[1] || {});
 }

 Effect.CloseDown = function(element) {
     element = $(element);
     new Effect.BlindUp(element, arguments[1] || {});
 }

 Effect.Combo = function(element) {
     element = $(element);
     if(element.style.display == 'none') { 
          new Effect.OpenUp(element, arguments[1] || {}); 
     }else { 
          new Effect.CloseDown(element, arguments[1] || {}); 
     }
 }
 
 
function setEveryDayForSubscription (subscription_id) {
  for (var i=0; i < 7; i++) {
    $("week_days_" + subscription_id + "_" + i).checked = true
  };
  
  return false;
}

function setEveryDayForFeed (feed_id) {
  
  if( $("every_day_" + feed_id + "_check").checked ){
    for (var i=0; i < 7; i++) {
      $("week_days_" + feed_id + "_" + i).checked = true
    };
  };
  
  return false;
}

function updateWeekDayCheckBox (feed_id, day) {
  if(!($("week_days_" + feed_id + "_" + day).checked)){
    $("every_day_" + feed_id + "_check").checked = false
  };
  
  var allChecked = true;
  
  for (var i=0; i < 7; i++) {
    if(!($("week_days_" + feed_id + "_" + i).checked)){
      allChecked = false;
    };
  };
  
  if (allChecked) {$("every_day_" + feed_id + "_check").checked = true};
}

function ensureEqualHeight(colList) {
  $("col1").height("auto");
  $('col2').height("auto");  
  
  var topHeight = 0;
  var staticTop = -1;
  

  // col1
  if ($('col1').height() >= topHeight) {
    topHeight = $('col1').height();
  }

  if ($('col1').css("position") == "static") {
    staticTop = findPos(document.getElementById($('col1').attr("id"))).y;
  }
  
  // col2
  if ($('col2').height() >= topHeight) {
    topHeight = $('col2').height();
  }

  if ($('col2').css("position") == "static") {
    staticTop = findPos(document.getElementById($('col2').attr("id"))).y;
  }
  
  topHeight = topHeight + "px";
  
  staticTop = staticTop + "px"

  $('col1').height(topHeight);
    if (staticTop != -1) $('col1').css("top",staticTop);

  $('col2').height(topHeight);
    if (staticTop != -1) $('col2').css("top",staticTop);    

};

function changeToMobileEditionAd () {
  // Show the field to add an image for an ad
  Element.show('mobile_edition_ad_container');
  
  // Set the menu links' classes
  $('mobile_alert_ad').removeClassName('active');  
  $('mobile_edition_ad').addClassName('active');
  
  // Change the nature of the add appropriately
  $('ad_nature').value = 'mobile_edition';
    
  return false;
}
 
function changeToMobileAlertAd () {
  // Hide the field to add an image for an ad  
  Element.hide('mobile_edition_ad_container');
  
  // Set the menu links' classes
  $('mobile_edition_ad').removeClassName('active');
  $('mobile_alert_ad').addClassName('active');
  
  // Change the nature of the add appropriately  
  $('ad_nature').value = 'mobile_alert';
  
  return false;
}

function initializeLandingPageCreator () {
  $('landing_page_creator').replace("")
  //$('landing_page_creator').replace("<script language=\"javascript\" type=\"text/javascript\" src=\"/javascripts/tiny_mce/tiny_mce.js\"></script>  <script language=\"javascript\" type=\"text/javascript\">alert(\"whoa\") </script>")
};

function switchLandingPageToURL () {
  $('landing_page_creator').innerHTML = '<input type=\"text\" />'
}