
var conftext = "Aby zweryfikować poprawność adresu e-mail oraz potwierdzić Państwa tożsamość nasz system zaraz wyśle na podany adres specjalny e-mail. Wysyłka taka ma na celu zabezpieczenie przed nieuprawnionym zapisaniem Państwa na newsletter naszej firmy przez osoby trzecie. W celu aktywacji subskrypcji prosimy o kliknięcie w link umieszczony w e-mailu potwierdzającym.<br /><br />Dziękujemy.";

function switchLang(lang,location) {
	
	expiredays = 100;
    var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);

	document.cookie = 'lang' + "=" +escape(lang)+";expires="+exdate.toGMTString()+";path=/";
    window.location.href="/";
}


function confirm(message, callback, height) {
	$('#confirm').modal({
		closeHTML:"<a href='#' title='Close' class='modal-close'>x</a>",
		position: ["20%",],
		overlayId:'confirm-overlay',
		containerId:'confirm-container', 
		onShow: function (dialog) {
            $('#confirm').height = height;
			$('.message', dialog.data[0]).append(message);

			// if the user clicks "yes"
			$('.yes', dialog.data[0]).click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				$.modal.close();
			});
		}
	});
}

function doAlert(message, callback,width,height) {
	$('#doalert').modal({
		closeHTML:"<a href='#' title='Close' class='modal-close'>x</a>",
		position: ["20%",],
		overlayId:'confirm-overlay',
		containerId:'confirm-container', 
        minHeight: height,
        minWidth: width,
		onShow: function (dialog) {
			$('.message', dialog.data[0]).append(message);
			// if the user clicks "yes"
			$('.yes', dialog.data[0]).click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				$.modal.close();
			});
		}
	});
}

function checkEnter(evt) {
    evt.cancelBubble = true;
	if (evt.stopPropagation) evt.stopPropagation();
    characterCode = evt.keyCode;
    if (characterCode==13) {
        if (document.all) 
        { 
            trg = evt.srcElement; 
        } 
        else 
        { 
            trg = evt.target; 
        }   
        
        if(trg.id=="search")
            checkForm();
        else
            checkEmail();
    }
}

function checkForm() {
    var co = document.getElementById('search').value;
    if (co.length>=3) {
        SearchThis();
    }
    else {
        doAlert("Wpisz przynajmniej 3 znaki!", function () {},420,140);
        //alert("Wpisz przynajmniej 3 znaki!");
    }
}

function checkEmail() {
    var co = document.getElementById('newsletter');
    var pattern=/^.+@.+\..{2,3}$/
    if (pattern.test(co.value)) {
        var cmd = "email="+co.value;
        DoIt("/newsletter/",cmd,0);
    }
    else {
        //alert("Wpisany tekst nie jest adresem e-mail!");
        doAlert("Wpisany tekst nie jest adresem e-mail!", function () {},420,140);
    }
}

function SearchThis() {
    var co = document.getElementById('search').value;
    window.location.href = '/szukaj/'+co;
}

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}

function DoIt(file,cmd,idek) {
xmlhttp.abort();
//alert(cmd);
xmlhttp.open("POST", file,true);
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
     if(xmlhttp.responseText==1){
        
        doAlert("<span>"+conftext+"</span>", function () {},470,240);
        
     }
     else {
        doAlert(xmlhttp.responseText, function () {},450,140);
        //alert(xmlhttp.responseText);
     }
  }
 }
 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
 xmlhttp.send(cmd)
}

var lnk_arr = new Array();

lnk_arr[0] = "/rozwiazania/magazyny";
lnk_arr[1] = "/sprzet/etykieciarki/moduly-drukujace";
lnk_arr[2] = "/znakowanie/materialy/etykiety";
lnk_arr[3] = "/ofirmie/promocje";

function GoTo(poz) {
    if(poz>-1)
        window.location.href = lnk_arr[poz];
}

function checkAWform() {
    var pattern=/^.+@.+\..{2,3}$/
    var imie = document.getElementById('imie').value;
    var nazwisko = document.getElementById('nazwisko').value;
    var firma = document.getElementById('firma').value;
    var telefon = document.getElementById('telefon').value;
    var email = document.getElementById('email').value;
    var producent = document.getElementById('producent').value;
    var model = document.getElementById('model').value;
    var serial = document.getElementById('serial').value;
    var opis = document.getElementById('opis').value;
    var kod = document.getElementById('kod').value;
    var awform = document.getElementById('awform');
    
    if(!imie || !nazwisko || !firma || !telefon || !email || !producent || !model || !serial || !opis || !kod) {
        doAlert("Pola oznaczone gwiazdką są wymagane!", function () {},420,140);
    }
    else if (!pattern.test(email)) {
        doAlert("Wpisany tekst nie jest adresem e-mail!", function () {},420,140);
    }
    else {
        awform.submit();
    }
    
}

function MessageAfterForm(msg) {
    doAlert(msg, function () {},420,140);
    setTimeout(GoToSerwis, 3000);
}

function MessageAfterWrongForm(msg) {
    doAlert(msg, function () {},420,140);
}

function GoToSerwis() {
    window.location.href = "/uslugi/serwis";
}

