﻿function mailReverse(str) {if (str.substr(0, 7) != 'mailto:') return str; var res = 'mailto:'; for(var i=1; i<=str.length-7;i++) res+=str.charAt(str.length-i);	return res;}
function Left(str, n){if (n <= 0) return ""; else if (n > String(str).length) return str; else return String(str).substring(0,n);}
function Right(str, n){if (n <= 0) return "";else if (n > String(str).length)return str;else {var iLen = String(str).length;return String(str).substring(iLen, iLen - n);}}
function isZeroToNine(numStr) {var numPat = /^([0-9]+)$/; var matchArray = numStr.match(numPat); if (matchArray == null) {return false;} else {return true;}}
function isEmail(emailStr) {var emailPat = /^([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})$/; var matchArray = emailStr.match(emailPat); if (matchArray == null) {return false;} else {return true;}}
function trim(str, chars) {return ltrim(rtrim(str, chars), chars);}
function ltrim(str, chars) {chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), "");}
function rtrim(str, chars) {chars = chars || "\\s"; return str.replace(new RegExp("[" + chars + "]+$", "g"), "");}
function isDate(dateStr) {var datePat = /^(\d{1,2})(\.)(\d{1,2})(\.)(\d{4})$/; var matchArray = dateStr.match(datePat); if (matchArray == null) {return false;} month = matchArray[3]; day = matchArray[1]; year = matchArray[5]; if (month < 1 || month > 12) {return false;} if (day < 1 || day > 31) {return false;} if ((month==4 || month==6 || month==9 || month==11) && day==31) {return false;} if (month == 2) {var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day > 29 || (day==29 && !isleap)) {return false;}} return true;}
function isDateTime(dateStr) {var sDate;var sTime;var sHour;var sMinute;var iHour;var iMinute;var sDateTimeDelimiter  = " "; var sHourMinuteDelimiter = ":";var iDTDelimiterPosition;var iHMDelimiterPosition;iDTDelimiterPosition = dateStr.indexOf(sDateTimeDelimiter); if (iDTDelimiterPosition  < 8 || iDTDelimiterPosition > 10) {  return false;}else {  sDate = dateStr.substr(0,iDTDelimiterPosition);  sTime = dateStr.substr(iDTDelimiterPosition+sDateTimeDelimiter.length);  if (!isDate(sDate)) {    return false;  }  else {    if (sTime.length < 3 || sTime.length > 5) {      return false;    }    else {      iHMDelimiterPosition = sTime.indexOf(sHourMinuteDelimiter);      if (iHMDelimiterPosition < 1 || iHMDelimiterPosition > 2) {        return false;      }      else {        sHour = sTime.substr(0,iHMDelimiterPosition);        sMinute = sTime.substr(iHMDelimiterPosition+1);        iHour = parseInt(sHour);        iMinute = parseInt(sMinute);        if (isNaN(iHour) || isNaN(iMinute )) {          return false;        }        else {          if (iHour < 0 || iHour > 23) {            return false;          }          if (iMinute < 0 || iMinute > 59) {            return false;          }        }      }    }  }return true;}}
function changeInputType(str){var ele = document.getElementById(str); if (ele.getAttribute('type') == 'text'){ele.setAttribute('type', 'password')}else{ele.setAttribute('type', 'text')}}
function getCheckedValue(radioObj) {if(!radioObj) return ""; var radioLength = radioObj.length; if(radioLength == undefined) if(radioObj.checked) return radioObj.value; else return "";for(var i = 0; i < radioLength; i++) {if(radioObj[i].checked) {return radioObj[i].value;}}return "";}
function getSelectedValue(selectObj) {if(!selectObj) return "";var selectLength = selectObj.length;for(var i = 0; i < selectLength; i++) {if(selectObj[i].selected) {return selectObj[i].value;}}return "";}
function submitForm(form1){if (!isFormValid(form1)) {return false;}else {return true;}}

function changeInputBckgrnd(toto,onoff) {
  if (onoff == 'on') {
    toto.style.backgroundPosition = "0px -40px";
  }
  else {
    toto.style.backgroundPosition = "0px 0px";
  }
}

Date.prototype.setISO8601 = function(dString){
   var regexp = /(\d\d\d\d)(-)?(\d\d)(-)?(\d\d)(T)?(\d\d)(:)?(\d\d)(:)?(\d\d)(\.\d+)?(Z|([+-])(\d\d)(:)?(\d\d))/;
   if (dString.toString().match(new RegExp(regexp))) {
      var d = dString.match(new RegExp(regexp));
      var offset = 0;

      this.setUTCFullYear(parseInt(d[1]));
      this.setUTCMonth(d[3] - 1);
      this.setUTCDate(d[5]);
      this.setUTCHours(d[7]);
      this.setUTCMinutes(d[9]);
      this.setUTCSeconds(d[11]);
      if (d[12])
         this.setUTCMilliseconds(parseFloat(d[12]) * 1000);
      else
         this.setUTCMilliseconds(0);
      if (d[13] != 'Z') {
         offset = (d[15] * 60) + parseInt(d[17]);
         offset *= ((d[14] == '-') ? -1 : 1);
         this.setTime(this.getTime() - offset * 60 * 1000);
      }
   }
   else {
      this.setTime(Date.parse(dString));
   }
   return this;
}

function parseFeed(sUrl, iItems, iChars, sDiv){
  jQuery.getFeed({
    url: sUrl + "&rand=" + Math.round(10000*Math.random()),
    cache: false,
    success: function(feed) {
      var datum = new Date();
      var den = new Date()
      var vlozeno;
      for(var i = 0; i < feed.items.length && i < iItems; i++) {

        var item = feed.items[i];
        var polozka = new Array(8);
        den = datum.setISO8601(item.updated)
        vlozeno = false;

        polozka[0] = Date.parse(den);
        polozka[1] = feed.title;
        polozka[2] = feed.link;
        polozka[3] = feed.logo;
        polozka[4] = den.getDate() + "." + (den.getMonth()+1) + ".";
        polozka[5] = item.title;
        polozka[6] = item.link;
        polozka[7] = item.description;
        polozka[8] = Math.round(polozka[0]*Math.random());

        if (polozka[4] == "NaN.NaN.") {polozka[4] = "";}

        if (polozka[7].length >= iChars) {
          intLastDelimPos = Left(polozka[7], iChars).lastIndexOf(" ")
          if (intLastDelimPos <= 0) {
            intLastDelimPos = iChars;
          }
          polozka[7] = Left(polozka[7], intLastDelimPos) + "..."
        }

        jQuery(".feedpolozka").each(function (i, v) {
          if (polozka[0] >= jQuery(v).attr("class").replace("feedpolozka ", "")) {
            jQuery(v).before("<div id=\"" + polozka[8] + "\" class=\"feedpolozka " + polozka[0] + "\"><span>" + polozka[4] + "</span><a href=\"" + polozka[2] + "\"><img src=\"" + polozka[3] + "\" alt=\"" + polozka[1] + "\" /></a> <a href=\"" + polozka[6] + "\">" + polozka[5] + "</a> <p>" + polozka[7] + "</p></div>");
            vlozeno = true;
            return false;
          }
        })
        if (!vlozeno) {
          jQuery(sDiv).append("<div id=\"" + polozka[8] + "\" class=\"feedpolozka " + polozka[0] + "\"><span>" + polozka[4] + "</span><a href=\"" + polozka[2] + "\"><img src=\"" + polozka[3] + "\" alt=\"" + polozka[1] + "\" /></a> <a href=\"" + polozka[6] + "\">" + polozka[5] + "</a> <p>" + polozka[7] + "</p></div>");
        }
      }
    }
  });
}

var name = "#skyscraperfloater";
var menuYloc = null;
$(document).ready(function(){
  if ($(name).length > 0) {
    menuYloc = parseInt(($(name).css("top").substring(0,$(name).css("top").indexOf("px")))/3)
    $(window).scroll(function () {
      var offset = menuYloc+$(document).scrollTop()+"px";
      $(name).animate({top:offset},{duration:500,queue:false});
    });
  }
});

function fineTuneGraphics(isHomePage)
{
  var A0Height = $(".A0").height();
  if (A0Height != null) {
    var A1Height =  $(".A1").height();
    var A2Height =  $(".A2").height()-6;
    var A3Height =  $(".A3").height()-6;
    var A4Height =  $(".A4").height()-6;
    $(".A1 > div.textbox:last").css("height", Math.abs(A0Height)-16);
    $(".A2 > div.textbox:last").css("padding-bottom", Math.abs(A0Height-A2Height));
    $(".A3 > div.textbox:last").css("padding-bottom", Math.abs(A0Height-A3Height));
    $(".A4 > div.textbox:last").css("padding-bottom", Math.abs(A0Height-A4Height));
  }

  var B0Height = $(".B0").innerHeight();
  if (B0Height != null) {
    var B1Height =  $(".B1").height();
    var B2Height =  $(".B2").height()-6;
    var B3Height =  $(".B3").height()-6;
    $(".B1 > div.textbox:last").css("padding-bottom", Math.abs(B0Height-B1Height));
    $(".B2 > div.textbox:last").css("padding-bottom", Math.abs(B0Height-B2Height));
    if (!isHomePage) {
      $(".B3 > div.textbox:last").css("padding-bottom", Math.abs(B0Height-B3Height));
    }
  }

  var C0Height = $(".C0").innerHeight();
  if (C0Height != null) {
    $(".C1 > div.textbox:last").css("padding", 0);
    $(".C1 > div.textbox:last").css("margin", 0);
    var C1Height =  $(".C1").height();
    var C2Height =  $(".C2").height()-6;
    var C3Height =  $(".C3").height()-6;
    var C4Height =  $(".C4").height()-6;

    $(".C2 > div.textbox:last").css("padding-bottom", Math.abs(C0Height-C2Height));
    $(".C3 > div.textbox:last").css("padding-bottom", Math.abs(C0Height-C3Height));
    $(".C4 > div.textbox:last").css("padding-bottom", Math.abs(C0Height-C4Height));
    var mezeraNahore = Math.abs(Math.floor((C0Height-C1Height)/2))
    var mezeraDole = Math.abs(Math.floor((C0Height-C1Height)/2))
    $(".C1 > div.textbox:last").css("padding-top", mezeraNahore-5);
    $(".C1 > div.textbox:last").css("padding-bottom", mezeraDole+5);
  }

  var D0Height = $(".D0").innerHeight();
  if (D0Height != null) {
    var D1Height =  $(".D1").height();
    var D2Height =  $(".D2").height();
    var D3Height =  $(".D3").height();
    var D4Height =  $(".D4").height();
    $(".D1 > div.textbox:last").css("padding-bottom", Math.abs(D0Height-D1Height));
    $(".D2 > div.textbox:last").css("padding-bottom", Math.abs(D0Height-D2Height));
    $(".D3 > div.textbox:last").css("padding-bottom", Math.abs(D0Height-D3Height));
    $(".D4 > div.textbox:last").css("padding-bottom", Math.abs(D0Height-D4Height));
  }

  //var E0Height = $(".E0").innerHeight();
  
  var F0Height = $(".F0").innerHeight();
  if (F0Height != null) {
    var F1Height =  $(".F1").height()-6;
    var F2Height =  $(".F2").height()-6;
    var F3Height =  $(".F3").height()-6;
    $(".F1 > div.textbox:last").css("padding-bottom", Math.abs(F0Height-F1Height));
    $(".F2 > div.textbox:last").css("padding-bottom", Math.abs(F0Height-F2Height));
    $(".F3 > div.textbox:last").css("padding-bottom", Math.abs(F0Height-F3Height));
  }
  
  var G0Height = $(".G0").innerHeight();
  if (G0Height != null) {
    var G1Height =  $(".G1").height()-6;
    var G2Height =  $(".G2").height()-6;
    var G3Height =  $(".G3").height()-6;
    $(".G1 > div.textbox:last").css("padding-bottom", Math.abs(G0Height-G1Height));
    $(".G2 > div.textbox:last").css("padding-bottom", Math.abs(G0Height-G2Height));
    $(".G3 > div.textbox:last").css("padding-bottom", Math.abs(G0Height-G3Height));
  }
}
