function getPosition(obj)
{
  var topValue= 0,leftValue= 0;
  while(obj)
  {
    leftValue+= obj.offsetLeft;
    topValue+= obj.offsetTop;
    obj= obj.offsetParent;
  }
  finalvalue = [topValue, leftValue];
  return finalvalue;
}

function getBrowserSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  finalvalue = [myWidth, myHeight];
  return finalvalue;
}

function scrollX()
{
  return window.pageXOffset ? window.pageXOffset : document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
}

function scrollY()
{
  return window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
}

(function($){
  jQuery.fn.alignCentre = function() {
    var div_top;
    var div_left;
    var popup_id = this.attr('id');

    if($(popup_id).height() > $(window).height()) {
      if(!$.browser.msie) {
        div_top = $(window).scrollTop() + 20 + 'px';
      }
      else {
        div_top = '20%'
      }
    }
    else {
      div_top = (($(window).height() - $(popup_id).height()) / 2) + $(window).scrollTop() + "px";
    }

    if($(popup_id).width() > $(window).width()) {
      div_left = $(window).scrollLeft() + 20 + 'px';
    }
    else {
      div_left = (($(window).width() - $(popup_id).width()) / 2) + $(window).scrollLeft() + "px";
    }
    this.css('top', div_top);
    this.css('left', div_left);
  };
})(jQuery);

(function($){
  jQuery.fn.fillPopup = function(html) {
    this.html(html);
    this.width(this.find('div:first').css('width'));
    this.height(this.find('div:first').css('height'));
    var div_id = "#" + this.attr('id');
    showPopup(div_id);
  };
})(jQuery);

(function($){
  jQuery.fn.replacePopup = function(html){
    var div_id_with_hash = '#' + this.attr('id');
    var div_styles = $(div_id_with_hash).attr('style').split(';');

    for(var i=0; i<div_styles.length; i++){
      var div_style_temp = div_styles[i].split(':');
      var div_style = div_style_temp[0].toLowerCase();
      div_style = $.trim(div_style);

      if(div_style.toLowerCase() != 'id'){
        $(div_id_with_hash).css(div_style, $(html).css(div_style));
      }
    }
    $(div_id_with_hash).html($(html).html());
    showPopup(div_id_with_hash);
  };
})(jQuery);

(function($){
  jQuery.fn.blockMe = function() {
    this.block( {
      message: $("#ajax_loader"),
      css: {
        border:'0px none',
        background:'none'
      }
    } );
  };
})(jQuery);

function alignCenterWithFixed(object)
{
  var browserSize = getBrowserSize();
  var IpopTop = ((browserSize[1] - object.offsetHeight) / 2) - 40;
  var IpopLeft = ((browserSize[0] - object.offsetWidth) / 2) - 70;
  var x = scrollX();
  var y = scrollY();

  if(IpopTop < 0)
  {
    IpopTop = 0;
  }
  if(IpopLeft < 0)
  {
    IpopLeft = 0;
  }
  object.style.left = x + IpopLeft + "px";
  object.style.top = (y + IpopTop) - 15 + "px";
}

function getScreenSize(){
  if (window.innerHeight != null && window.scrollMaxY != null) {// Firefox
    yWithScroll = window.innerHeight + window.scrollMaxY;
    xWithScroll = window.innerWidth + window.scrollMaxX;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    yWithScroll = document.body.scrollHeight;
    xWithScroll = document.body.scrollWidth;
  } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    yWithScroll = document.body.offsetHeight;
    xWithScroll = document.body.offsetWidth;
  }
  arrayPageSizeWithScroll = [xWithScroll,yWithScroll];
  return arrayPageSizeWithScroll;
}

function getViewportDimensions() {
  var intH = 0, intW = 0;

  if(self.innerHeight) {
    intH = window.innerHeight;
    intW = window.innerWidth;
  }
  else {
    if(document.documentElement && document.documentElement.clientHeight) {
      intH = document.documentElement.clientHeight;
      intW = document.documentElement.clientWidth;
    }
    else {
      if(document.body) {
        intH = document.body.clientHeight;
        intW = document.body.clientWidth;
      }
    }
  }

  return {
    height: parseInt(intH, 10),
    width: parseInt(intW, 10)
  };
}

function strcmp ( str1, str2 ) {
    return ( ( str1 == str2 ) ? 0 : ( ( str1 > str2 ) ? 1 : -1 ) );
}