/*****************************************/
/*       Created by Piotr Kaluzynski     */
/*              Prostin                  */
/*       www.prostin.w.inds.pl           */
/*       email: prostin@inds.pl          */
/*****************************************/

var globalCzyIE6 = 'null';
var globalCzyIE = 'null';

function czyIE6 () {
   if (globalCzyIE6 == 'null') { 
      var userAgent = navigator.userAgent;
         
      var isIE = userAgent.indexOf ("compatible") > -1 && userAgent.indexOf("MSIE");
      var czyIE6 = false;
      
      if (isIE) {
         var reIE = new RegExp ("MSIE (\\d+\\.\\d+);");
         reIE.test (userAgent);
         var ieVer = parseFloat (RegExp["$1"]);
   /* Jesli by sie okazalo ze IE 7.0 tez ma z tym problem to wystarczy zmienic nr versji */      
         czyIE6 = ieVer <= 6.0;
      }
      globalCzyIE6 = czyIE6;
      return czyIE6;
   } else {   
      return globalCzyIE6;
   }
}

function czyIE () {
   if (globalCzyIE == 'null') { 
      var userAgent = navigator.userAgent;
         
      var isIE = userAgent.indexOf ("compatible") > -1 && userAgent.indexOf("MSIE");
      var czyIE = false;
      
      if (isIE) {
         czyIE = true;
      }
      globalCzyIE = czyIE;
      return czyIE;
   } else {   
      return globalCzyIE;
   }
}

function overImageBG (img, imgSrc) {
   if (czyIE()) {
      img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', src='" + imgSrc + "', sizingMethod='scale');"
   } else {
      img.style.backgroundImage = 'url(' + imgSrc + ')';
   }
   img.style.cursor = 'pointer';
}

function outImageBG (img, imgSrc) {
   if (czyIE()) {
      img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', src='" + imgSrc + "', sizingMethod='scale');"   
   } else {
      img.style.backgroundImage = 'url(' + imgSrc + ')';
   }
   img.style.cursor = 'default';   
}


function setSmile(myField, myValue, ilosc) {

   if (document.selection) {
   // IE support
      myField.focus();
      sel = document.selection.createRange();
      sel.text = myValue;
   } else if (myField.selectionStart || myField.selectionStart == '0') {
      // MOZILLA/NETSCAPE support
      var startPos = myField.selectionStart;
      var endPos = myField.selectionEnd;
      myField.value = myField.value.substring(0, startPos)+ myValue + myField.value.substring(endPos, myField.value.length);
   } else {
      myField.value += myValue;
   }
   
   //sprawdz ilosc znakow
   countChar(myField, ilosc)
}


function countChar(myField, ilosc) {

   var pozostalo = ilosc - myField.value.length;
   var trescDiv = $('pozostalo');
   
   if (pozostalo >= 0) { 
      trescDiv.innerHTML = 'Pozostało znaków: ' + pozostalo;
   } else {
      trescDiv.innerHTML = 'Pozostało znaków: 0';
      myField.value = myField.value.substr(0, ilosc);
      alert('Niestety, wpis może zawierać tylko ' + ilosc + ' znakow');
      //utnij tresc wpisu tak aby zostalo tylko pierwsze 1000 znakow
      
   } 
}

busy = false;
function closeWindow (div) {
   if (!busy) {
      $(div).innerHTML = "";
      url = 'baner.php';   
      
      param = 'action=disableBaner'
      var myAjax = new Ajax.Request(
                              url,
                              {
                                 method: 'post',
                                 parameters: param,
                                 onComplete: this.handleResponse,
                                 onCreate: function () {busy = true}
                              });       
   }
}


function handleResponse () {
   busy = false;
}

