if (Drupal.jsEnabled) {
  $(document).ready(function() {
    FlashChecker.displayInfo();
    $("a.makeme-download").click(function() {
      var href = $(this).attr("href").split("#");
      var url = href[0];
      var filepath = href[1];

      $.post(
        url,
        {"filepath": filepath},
        function() {

        }
      );

      //return false;

    });
  });
}

var FlashChecker = FlashChecker || {};
FlashChecker.leastVersion = 9.0;
FlashChecker.leastRevistion = 28;

FlashChecker.getFlashVer = function() {
  var versionArray = $.fn.flash.hasFlash.playerVersion().split(",");
  return versionArray;
};

FlashChecker.isEnough = function() {
  var versionArray = this.getFlashVer();
//  if(!$.browser.safari){
    if (versionArray) {
      var version = versionArray[0] + '.' + versionArray[1];
      var revistion = versionArray[2];
      // todo if IE, cannot get revistion info

      if(version > this.leastVersion || (version == this.leastVersion && revistion >= this.leastRevistion)) {
        return true;
      }
    }
    return false;
//  }
//  return true;
}

FlashChecker.displayInfo = function() {
  var versionArray = this.getFlashVer();

  if (versionArray) {
    var version = versionArray[0] + '.' + versionArray[1];
    var revistion = versionArray[2];
    if(version > this.leastVersion || (version == this.leastVersion && revistion >= this.leastRevistion)) {
        return true;
    }
    else {
      var form = $('#wrapper');
      //console.log(form);
      var link = '<a href = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">Update </a>';
      var adjust = "Your flash version is too old, please update the newest one by click this link;" + link;
      $('<div class="notice">' + adjust + '</div>').insertBefore(form);
    }
  }
  else{
    var form = $('#wrapper');
    var link = '<a href = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">Update </a>';
    var adjust = "Your don't have flash player, please download the newest one by click this link;" + link;
    $('<div class="notice">'+adjust+'</div>').insertBefore(form);
  }
};


function popCoverDiv(e){
    if (G("cover_div")) {
      G("cover_div").style.display = '';
    } else {
      var coverDiv = GC('div');
      document.body.appendChild(coverDiv);
      coverDiv.id = 'cover_div';
      with (coverDiv.style) {
        position = 'absolute';//absolute
        background = '#CCCCCC';
        if (!G(e)) {
          var coverSize = getCoverSize();
          left = '0px';
          top = '0px';
          width = coverSize[0] + 'px'
          height = coverSize[1] + 'px';
        } else {
          var coverSize = getLTWH(G(e));
          left = coverSize.left + 'px';
          top = coverSize.top + 'px';
          width = coverSize.width + 'px'
          height = coverSize.height + 'px';
        }
        zIndex = 50;
        var isIE = navigator.appName.indexOf("Microsoft") != -1;
        if (isIE) {
          filter = "alpha(opacity=50)";
        } else {
          opacity = 0.5;
        }

      }
    }
}

function G(id){
    return document.getElementById(id);
}

function GC(t){
    return document.createElement(t);
}
function getCoverSize(){
    var coverSize = [];
    with(document.documentElement) {
      coverSize[0] = (scrollWidth>clientWidth)?scrollWidth:clientWidth;
      coverSize[1] = (scrollHeight>clientHeight)?scrollHeight:clientHeight;
    }
    return coverSize;
}

function TrimString(sInString) {
    if (sInString) {
        sInString = sInString.replace( /^\s+/g, "" );
        return sInString.replace( /\s+$/g, "" );
    }
}

function checkEmail(elem) {
// Make sure that something was entered and that it looks like
// a valid email address
//  -+^!#\$%&*+\/\=\?\`\|\{\}~\
//  var myReg = /^[._A-Za-z0-9_-_+-]+@([a-zA-Z0-9_åøæÅØÆ-])+(.[a-zA-Z0-9_-])+/;
  var myReg = /^[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|~]+@([a-zA-Z0-9_åøæÅØÆ-])+(\.[a-zA-Z0-9_-])+/;
  return myReg.test(elem);
}


