// To fix placeholders in IE and other shitty browsers.
// Set the color of your 'edited' inputs in their own tag, use .placeholder for them before hand.
//  .placeholder {
//    color: #777 !important;
//  }
function placehold_IE_r() {
  $('[placeholder]').focus(function() {
    var input = $(this);
    if (input.val() === input.attr('placeholder')) {
      input.val('');
      input.removeClass('placeholder');
    }
  }).blur(function() {
    var input = $(this);
    if (input.val() === '' || input.val() === input.attr('placeholder')) {
      input.addClass('placeholder');
      input.val(input.attr('placeholder'));
    }
  }).blur().parents('form').submit(function() {
    $(this).find('[placeholder]').each(function() {
      var input = $(this);
      if (input.val() === input.attr('placeholder')) {
        input.val('');
      }
    });
  });
}

// Checks the browser width and hides the feedback form if it's less than *amount*
var vis = true;
var viewportwidth;
var amount = 1040;

function getWidth() {
  if (typeof window.innerWidth != 'undefined') {
    viewportwidth = window.innerWidth
  } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
    viewportwidth = document.documentElement.clientWidth
  } else {
    viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
  }
  
  if (viewportwidth < amount && vis == true) {
    $('#feedbackPlugin').css('display','none');
    vis = false;
  } 
  
  if (viewportwidth > amount && vis == false) {
    $('#feedbackPlugin').css('display','block');
    vis = true;
  }
} getWidth();

var id;
$(window).resize(function() {
  clearTimeout(id);
  id = setTimeout(getWidth, 500);
});


// Catches IE and throws panda poo at it.
function SadPanda(){
  if($.browser.msie && parseInt($.browser.version) <= 6){ return true;}
  return false;
}

function getSadPanda(c_name)
{
  if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
  return "";
}  

function setSadPanda(c_name,value,expiredays)
{
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

if(SadPanda() && getSadPanda('browserWarning') != 'seen' ){
  $(function(){
    $("<div id='browserWarning'>You are using an unsupported and very outdated browser. Please switch to <a href='https://www.google.com/chrome'>Google Chrome</a>. Thanks!&nbsp;&nbsp;&nbsp;<small>[<a href='#' id='warningClose'>close</a>]</small></div> ")
      .css({
        backgroundColor: '#fcfdde',
        'width': '100%',
        'border-top': 'solid 1px #000',
        'border-bottom': 'solid 1px #000',
        'text-align': 'center',
        'margin-top': '5px',
        padding:'5px 0px 5px 0px'
      })
      .prependTo("body");
    
    $('#warningClose').click(function(){
      setSadPanda('browserWarning','seen');
      $('#browserWarning').slideUp('fast');
      return false;
    });
  });  
}

