/* begin Page */

var artEventHelper = {
  'bind' : function (obj, evt, fn) {
    if (obj.addEventListener)
      obj.addEventListener(evt, fn, false);
    else if (obj.attachEvent)
      obj.attachEvent('on' + evt, fn);
    else
      obj['on' + evt] = fn;
  }
};

var artLoadEvent = (function() {
  var userAgent = navigator.userAgent.toLowerCase();
  var browser = {
    version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
    safari: /webkit/.test(userAgent),
    opera: /opera/.test(userAgent),
    msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
    mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
  };

  var list = [];

  var done = false;
  var ready = function () {
    if (done) return;
    done = true;
    for (var i = 0; i < list.length; i++)
      list[i]();
  };
  
  if (document.addEventListener && !browser.opera)
    document.addEventListener('DOMContentLoaded', ready, false);
  
  if (browser.msie && window == top) {
    (function () {
      try {
        document.documentElement.doScroll('left');
      } catch (e) {
        setTimeout(arguments.callee, 10);
        return;
      }
      ready();
    })();
  }
  
  if (browser.opera) {
    document.addEventListener('DOMContentLoaded', function () {
      for (var i = 0; i < document.styleSheets.length; i++) {
        if (document.styleSheets[i].disabled) {
          setTimeout(arguments.callee, 10);
          return;
        }
      }
      ready();
    }, false);
  }
  
  if (browser.safari) {
    var numStyles;
    (function(){
      if (document.readyState != 'loaded' && document.readyState != 'complete') {
        setTimeout(arguments.callee, 10);
        return;
      }
      if ('undefined' == typeof numStyles) {
        numStyles = document.getElementsByTagName('style').length;
        var links = document.getElementsByTagName('link');
        for (var i = 0; i < links.length; i++) {
          numStyles += (links[i].getAttribute('rel') == 'stylesheet') ? 1 : 0;
        }
        if (document.styleSheets.length != numStyles) {
          setTimeout(arguments.callee, 0);
          return;
        }
      }
      ready();
    })();
  }

  artEventHelper.bind(window, 'load', ready);

  return ({
    add: function(f) {
      list.push(f);
    }
  })
})();

(function () {
  // fix ie blinking
  var m = document.uniqueID && document.compatMode && !window.XMLHttpRequest && document.execCommand;
  try{ if(!!m) { m("BackgroundImageCache", false, true); } }
  catch(oh){};
})();

function xGetElementsByClassName(clsName, parentEle, tagName) {
  var elements = null;
  var found = [];
  var slash = String.fromCharCode(92);
  var re = new RegExp(slash + "b" + clsName + slash + "b");
  if (!parentEle) parentEle = document;
  if (!tagName) tagName = '*';
  elements = parentEle.getElementsByTagName(tagName);
  if (elements) {
    for (var i = 0; i < elements.length; ++i) {
      if (elements[i].className.search(re) != -1) {
        found[found.length] = elements[i];
      }
    }
  }
  return found;
}

var styleUrlCached = null;
function GetStyleUrl() {
  if (null == styleUrlCached) {
    var ns;
    styleUrlCached = '';
    ns = document.getElementsByTagName('link');
    for (var i = 0; i < ns.length; i++) {
      var l = ns[i];
      if (l.href && /style\.css(\?.*)?$/.test(l.href)){
        return styleUrlCached = l.href.replace(/style\.css(\?.*)?$/,'');
      }
    }
    
    ns = document.getElementsByTagName('style');
    for (var i = 0; i < ns.length; i++) {
      var matches = new RegExp('import\\s+"([^"]+\\/)style\\.css"').exec(ns[i].innerHTML);
      if (null != matches && matches.length > 0)
        return styleUrlCached = matches[1];
    }
  }
  return styleUrlCached;
}


function artButtonSetupJsHover(btn)
{
    artEventHelper.bind(btn, 'mouseover', function() {
        var spans = btn.getElementsByTagName("span");
        if (spans.length > 0)
            spans[0].className += " hover";
    });
    artEventHelper.bind(btn, 'mouseout', function() {
        var spans = btn.getElementsByTagName("span");
        if (spans.length > 0)
            spans[0].className = spans[0].className.replace(/hover/, "").replace(/active/, "");
    });
    artEventHelper.bind(btn, 'mousedown', function() {
        var spans = btn.getElementsByTagName("span");
        if (spans.length > 0)
            spans[0].className += " active";
    });
    artEventHelper.bind(btn, 'mouseup', function() {
        var spans = btn.getElementsByTagName("span");
        if (spans.length > 0)
            spans[0].className = spans[0].className.replace(/active/, "");
    });
}

function artButtonsSetupJsHover() {
  var elements = xGetElementsByClassName("btn", document, "span");
  for (var i = 0; i < elements.length; i++) {
    if (!elements[i].tagName) continue;
    artButtonSetupJsHover(elements[i].parentNode);
  }
}
artLoadEvent.add(artButtonsSetupJsHover);

/* end Page */

/* begin Menu */
function Insert_Separators()
{
  var menus = xGetElementsByClassName("artmenu", document);
  for (var i = 0; i < menus.length; i++) {
    var menu = menus[i];
    var childs = menu.childNodes;
    var listItems = [];
    for (var j = 0; j < childs.length; j++){
      var el = childs[j];
      if (String(el.tagName).toLowerCase() == "li")listItems.push(el);
    }
    for (var j = 0; j < listItems.length - 1; j++){
      var span = document.createElement('span');
      span.className = 'separator';
      var li = document.createElement('li');
      li.appendChild(span);
      listItems[j].parentNode.insertBefore(li, listItems[j].nextSibling);
    }
  }
}
artLoadEvent.add(Insert_Separators);

function Menu_IE6Setup() {
  var isIE6 = navigator.userAgent.toLowerCase().indexOf("msie") != -1 
    && navigator.userAgent.toLowerCase().indexOf("msie 7") == -1;
  if (!isIE6) return;
  var aTmp2, i, j, oLI, aUL, aA;
  var aTmp = xGetElementsByClassName("artmenu", document, "ul");
  for (i=0;i<aTmp.length;i++) {
    aTmp2 = aTmp[i].getElementsByTagName("li");
    for (j=0;j<aTmp2.length;j++) {
      oLI = aTmp2[j];
      aUL = oLI.getElementsByTagName("ul");
      if (aUL && aUL.length) {
        oLI.UL = aUL[0];
        aA = oLI.getElementsByTagName("a");
        if (aA && aA.length)
        	oLI.A = aA[0];
         oLI.onmouseenter = function() {
         	this.className += " artmenuhover";
         	this.UL.className += " artmenuhoverUL";
         	if (this.A) this.A.className += " artmenuhoverA";
         };
        oLI.onmouseleave = function() {
          this.className = this.className.replace(/artmenuhover/,"");
          this.UL.className = this.UL.className.replace(/artmenuhoverUL/,"");
          if (this.A) this.A.className = this.A.className.replace(/artmenuhoverA/, "");
        };
      }
    }
  }
}
artLoadEvent.add(Menu_IE6Setup);
/* end Menu */

function replace(tekst,w1,w2) 
{
	tekst=tekst+"";
	while(tekst.indexOf(w1)>-1)
{
	tekst=tekst.substring(0,tekst.indexOf(w1))+w2+tekst.substring(tekst.indexOf(w1)+w1.length);
}
	return tekst;
}
function removeDashes(){

	var str = document.form1.nip.value;
	str2 = str.replace(/-/gi,"");
	document.form1.nip.value = str2;
}
function chkdane() 

{
	nip=document.form1.nip.value;
	nip=replace(nip,"-","");
	nip=replace(nip," ","");
	document.form1.nip.value = nip;

	if (document.form1.ilosc.value==0) 
      {
		alert('Wybierz ilosc publikacji!');
		document.form1.ilosc.focus();
		return false;
	} 
      else if (document.form1.nip.value.length!=10) 
      {
		alert('Podaj poprawny NIP! ');
		document.form1.nip.focus();
		return false;
	} 
      else if (document.form1.firma.value.length < 3) 
      {
		alert('Podaj nazwe firmy! ');
		document.form1.firma.focus();
		return false;
	} 
      else if (document.form1.ulica.value.length< 3) 
      {
		alert('Podaj ulice! ');
		document.form1.ulica.focus();
		return false;
	} 
      else if (document.form1.lokal.value.length < 1) 
      {
		alert('Podaj numer lokalu! ');
		document.form1.lokal.focus();
		return false;
	} 
      else if (document.form1.kod.value.length < 3) 
      {
		alert('Podaj kod pocztowy! ');
		document.form1.kod.focus();
		return false;
	} 
      else if (document.form1.miasto.value.length < 3) 
      {
		alert('Podaj miasto! ');
		document.form1.miasto.focus();
		return false;
	} 
      else if (document.form1.wojewodztwo.value == 0) 
      {
		alert('Wybierz wojewodztwo! ');
		document.form1.wojewodztwo.focus();
		return false;
	}
      else if (document.form1.osoba.value.length < 5) 
      {
		alert('Podaj osobe korzystajÄ…cÄ… z publikacji! ');
		document.form1.osoba.focus();
		return false;
	} 
	else if (document.form1.tel.value.length < 7) 
      {
		alert('Podaj poprawny numer telefonu! ');
		document.form1.osoba.focus();
		return false;
	} 
      else if (document.form1.email.value.length < 2) 
      {
		alert('Podaj email ! ');
		document.form1.email.focus();
		return false;
	}  
	/*
	else if (!document.form1.zgoda1.checked) 
      {
		alert('ProszÄ™ wyraziÄ‡ zgodÄ™ na przetwarzanie danych osobowych !');
		document.form1.zgoda1.focus();
		return false;
	}
*/
	else if (!document.form1.podmiot_gospodarczy.checked) 
      {
		alert('Wydawnictwo realizuje zamÃ³wienia tylko dla przedsiÄ™biorcÃ³w.');
		document.form1.podmiot_gospodarczy.focus();
		return false;	
	}
      else if (!document.form1.zgoda2.checked) 
      {
		alert('ProszÄ™ wyraziÄ‡ zgodÄ™ na wystawienie faktury bez podpisu odbiorcy ! ');
		document.form1.zgoda2.focus();
		return false;	
	}
		/*else if (document.form1.password.value !='' && document.form1.password.value.length <6) 
      {
		alert('HasÅ‚o powinno zawieraÄ‡ co najmniej 6 znakÃ³w !');
		document.form1.password.focus();
		return false;
	}
		else if (document.form1.password.value != document.form1.password_confirm.value) 
      {
		alert('PowtÃ³rzone hasÅ‚o nie odpowiada podanemu wyÅ¼ej ! ');
		document.form1.password.focus();
		return false;
	}*/
		
	
       
      else 
      {
		return true;
		this.disabled=true;
	}
}

function testuj_nip() 
{
	document.form1.nip.value=replace(document.form1.nip.value," ","");
	document.form1.nip.value=replace(document.form1.nip.value,"-","");
	document.form1.nip.value=replace(document.form1.nip.value,".","");
	document.form1.nip.value=replace(document.form1.nip.value,",","");
	if (isNaN(document.form1.nip.value)) 
	{
		alert ('BÅ‚Ä™dny NIP');
		return false;
	} 
else if (document.form1.nip.value.length!=10) 
	{
		alert ('BÅ‚Ä™dny NIP');
		return false;
	} 
else 
	{
		return true;
	}
}
function taxNumberCheck(){
	var taxNumber = document.form1.nip.value;
	if(taxNumber.match(/[^0-9]{1,}/)){
		
		alert("NIP powinien zawieraæ same cyfry!");
		document.form1.nip.value = taxNumber.replace(/[^0-9]{1,}/,'');
	}
}
function emailCheck2(){
txt = document.form1.email.value;
var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
if(!regex.test(txt)){
alert('Podano zÅ‚y mail');
document.form1.email.focus();
return false;
}
}
function emailCheck() 
{

txt=document.form1.email.value;
if (txt.indexOf("@")<2)
{
alert("Adres email niepoprawny. ProszÄ™,"
+" sprawdÅº prefiks przed znakiem '@'.");
return false;
}
if ((txt.indexOf(".com")<5)&&(txt.indexOf(".org")<5)
&&(txt.indexOf(".gov")<5)&&(txt.indexOf(".net")<5)
&&(txt.indexOf(".mil")<5)&&(txt.indexOf(".edu")<5)&&(txt.indexOf(".biz")<5)&&(txt.indexOf(".pl")<5)&&(txt.indexOf(".eu")<5)&&(txt.indexOf(".info")<5)&&(txt.indexOf(".fm")<5)){
alert("Adres email niepoprawny.\nProszÄ™,"
+" sprawdÅº sufiks. (powinien zawieraÄ‡ "


+".com, .biz, .edu, .net, .org, .gov, .mil lub .pl)");
return false; 
}

}

var ObiektXMLHttp = false; 
if (window.XMLHttpRequest){ 
	ObiektXMLHttp = new XMLHttpRequest(); 
	}else if(window.ActiveXObject){ 
           ObiektXMLHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
           } 
 
function email_check(adres){ 		
document.getElementById('check').innerHTML = '';
document.getElementById('check_info').innerHTML = '';
document.getElementById('zly_mail').value = '0';
	if(ObiektXMLHttp){ 
   //pobieranie danych 
   ObiektXMLHttp.open("GET", "check/is_host.php?email="+adres+""); 
   
   ObiektXMLHttp.onreadystatechange = function(){ 
                       if(ObiektXMLHttp.readyState == 4){ 
									 var info = ObiektXMLHttp.responseText; 
									 if(info == 'brak' || info == 'zle' || info == 'quota' || info == 'no_user'){
									 document.getElementById('check').innerHTML = "Prosimy sprawdziÄ‡ poprawnoÅ›Ä‡ podanego adresu*";
									 var komunikat = "*Prawdopodobny problem z adresem e-mail:<br>";
									 	if(info == 'brak' || info == 'zle'){
										komunikat += " - domena nie istnieje lub nastÄ…piÅ‚ bÅ‚Ä…d skÅ‚adniowy.";
										}
										if(info == 'no_user'){
										komunikat += " - bÅ‚Ä™dnie podana nazwa uÅ¼ytkownika.";
										}
										if(info == 'quota'){
										komunikat += " - przepeÅ‚niona skrzynka - proszÄ™ usunÄ…c zbÄ™dne wiadomoÅ›ci.";
										}
									 komunikat += "<br>JeÅ¼eli sÄ… PaÅ„stwo pewni poprawnoÅ›ci podanego adresu, prosimy o wysÅ‚anie formularza pomimo wystÄ…pienia tego komunikatu.";	
									 document.getElementById('check_info').innerHTML =	komunikat;
									 document.getElementById('zly_mail').value = '1';
									 }else{
									 document.getElementById('check').innerHTML = '';
									 }
                       } 
                 } 
                 ObiektXMLHttp.send(null); 		
					  	
   }
	

}	

