﻿function FlashTag(src, uid, param, wmode, width, height)
{
    this.src       = src;
    this.uid       = uid;
    this.param     = param;
    this.width     = width;
    this.height    = height;
    this.version   = '7,0,14,0';
    this.id        = null;
    this.bgcolor   = 'ffffff';
    this.wmode     = wmode;
    this.flashVars = null;
}

FlashTag.prototype.setVersion = function(v)
{
    this.version = v;
}

FlashTag.prototype.setId = function(id)
{
    this.id = id;
}


FlashTag.prototype.setFlashvars = function(fv)
{
    this.flashVars = fv;
}

FlashTag.prototype.toString = function()
{
    var ie = (navigator.appName.indexOf ("Microsoft") != -1) ? 1 : 0;
    var flashTag = new String();
    if (ie)
    {
        flashTag += '<object id="' + this.uid + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
        if (this.id != null)
        {
            flashTag += 'id="'+this.id+'" ';
        }
        flashTag += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
        flashTag += 'width="'+this.width+'" ';
        flashTag += 'height="'+this.height+'">';
        flashTag += '<param name="movie" value="'+this.src+'"/>';
        flashTag += '<param name="quality" value="high"/>';
		flashTag += '<param name="wmode" value="'+this.wmode+'"/>';
        flashTag += '<param name="bgcolor" value="#'+this.bgcolor+'"/>';
        //flashTag += '<param name="allowScriptAccess" value="sameDomain"/>';
        if (this.flashVars != null)
        {
            flashTag += '<param name="flashvars" value="'+this.flashVars+'&'+this.param+'"/>';
        }
        flashTag += '</object>';
    }
    else
    {
        flashTag += '<embed id="' + this.uid + '" src="'+this.src+'" ';
        flashTag += 'quality="high" '; 
        flashTag += 'bgcolor="#'+this.bgcolor+'" ';
        flashTag += 'width="'+this.width+'" ';
        flashTag += 'height="'+this.height+'" ';
		flashTag += 'wmode="'+this.wmode+'" ';
	//	flashTag += 'allowScriptAccess="sameDomain" ';
        flashTag += 'type="application/x-shockwave-flash" ';
        if (this.flashVars != null)
        {
            flashTag += 'flashvars="'+this.flashVars+'&'+this.param+'" ';
        }
        if (this.id != null)
        {
            flashTag += 'name="'+this.id+'" ';
        }
        flashTag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
        flashTag += '</embed>';
    }
	op_n=1;

    return flashTag;
    alert(flashTag);
}

FlashTag.prototype.fetch = function()
{
    return this.toString();
}

function o(id)
{
	return document.getElementById(id);
}

function validateEmail(email){
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(email.match(emailRegEx)){
		return true;
	}else{
		return false;
	}
}

function trim(str) {
	if(str=="")
	return "";
	else
	return str.replace(/^\s+|\s+$/g, '') ;
}
	
	
//============= Radosna tworczosc===========
function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

//====koniec radosnej tworczosci=======





function przyciemnienie() {

	var wymiary = getPageSize();
	document.getElementById('przyciemnienie').style.height =  wymiary[1] + "px";
	document.getElementById('przyciemnienie').style.display = "block";
}

function zamknij_okienko(div) {
	if (div == "zgloszenie_serwisowe") {
		o('zlecenie_serwisowe').reset();
		resetZgloszenie();	
	}
	
	okienko_wybrane = "none";
	o("przyciemnienie").style.display = "none";
	o(div).style.display = "none";
}

function resetZgloszenie() {
	var style1 = "1px solid #a5acb2";
	var style2 = "1px solid #e20000";


	o('adres_nazwa_firmy').style.border = style1;

	o('adres_imie_nazwisko').style.border = style1;

	o('adres_ulica').style.border = style1;

	o('adres_kod1').style.border = style1;

	o('adres_kod2').style.border = style1;

	o('adres_miejscowosc').style.border = style1;

	o('dane_nr_faktury').style.border = style1;

	o('dane_data_dzien').style.border = style1;

	o('dane_data_miesiac').style.border = style1;

	o('dane_data_rok').style.border = style1;

	o('dane_nazwa_firmy').style.border = style1;

	o('dane_osoba').style.border = style1;

	o('dane_nr').style.border = style1;

	o('dane_email').style.border = style1;

	o('opis_uszkodzenia').style.border = style1;

}

var okienko_wybrane = "none";
function pokaz_okienko(div) {
	
	okienko_wybrane = div;
	
	pozycja(div);
	o(div).style.display = "block";
	przyciemnienie();
}

function pozycja(id) {
var div = o(id);

var wymiary = getPageSize();


  div.style.marginLeft = parseInt((wymiary[2] / 2) - ($('#'+id).width()/2)) + "px";
  div.style.marginTop =  parseInt(wymiary[3] / 2) - ($('#'+id).height()/2) + "px";
  
}	


function przelacz_okienka(div1, div2) {
	pozycja(div2);
	
	o(div1).style.display = "none";
	o(div2).style.display = "block";
	okienko_wybrane = div2;
}

function logowanie_user() {
	
	xajax_logowanie_user(o('log_login').value, o('log_pass').value);
	
}

function wyslijZgloszenie() {
	var rodzaj;
	
	if (o('rodzaj1').checked) {
		rodzaj = 1;
	} else if (o('rodzaj2').checked) {
		rodzaj = 2;
	}
	
	var bErr = false;
	
	var style1 = "1px solid #a5acb2";
	var style2 = "1px solid #e20000";
	
	var adres_nazwa_firmy = o('adres_nazwa_firmy').value;
	var adres_imie_nazwisko = o('adres_imie_nazwisko').value;
	var adres_ulica = o('adres_ulica').value;
	var adres_kod1 = o('adres_kod1').value;
	var adres_kod2 = o('adres_kod2').value;
	var adres_miejscowosc = o('adres_miejscowosc').value;
	var dane_nr_faktury = o('dane_nr_faktury').value;
	var dane_data_dzien = o('dane_data_dzien').value;
	var dane_data_miesiac = o('dane_data_miesiac').value;
	var dane_data_rok = o('dane_data_rok').value;
	var dane_nazwa_firmy = o('dane_nazwa_firmy').value;
	var dane_osoba = o('dane_osoba').value;
	var dane_nr = o('dane_nr').value;
	var dane_email = o('dane_email').value;
	var opis_uszkodzenia = o('opis_uszkodzenia').value;
	
	
	if (rodzaj != 1 && rodzaj !=2) {
		bErr = true;
	}
	if (adres_imie_nazwisko == '') {
		o('adres_imie_nazwisko').style.border = style2;
		bErr = true;
	} else {
		o('adres_imie_nazwisko').style.border = style1;
	}
	if (adres_ulica == '') {
		o('adres_ulica').style.border = style2;
		bErr = true;
	} else {
		o('adres_ulica').style.border = style1;
	}
	if (adres_kod1 == '' || !adres_kod1.match(/^[0-9]{2}$/)) {
		o('adres_kod1').style.border = style2;
		bErr = true;
	} else {
		o('adres_kod1').style.border = style1;
	}
	if (adres_kod2 == '' || !adres_kod2.match(/^[0-9]{3}$/)) {
		o('adres_kod2').style.border = style2;
		bErr = true;
	} else {
		o('adres_kod2').style.border = style1;
	}
	if (adres_miejscowosc == '') {
		o('adres_miejscowosc').style.border = style2;
		bErr = true;
	} else {
		o('adres_miejscowosc').style.border = style1;
	}
	
	if (dane_nr == '') {
		o('dane_nr').style.border = style2;
		bErr = true;
	} else {
		o('dane_nr').style.border = style1;
	}
	if (dane_email == '' || !validateEmail(dane_email)) {
		o('dane_email').style.border = style2;
		bErr = true;
	} else {
		o('dane_email').style.border = style1;
	}
	
	if (!bErr) {
		o('zlecenie_serwisowe').action = "wyslij_zgloszenie.php";
		o('zlecenie_serwisowe').submit();
	}
	
}


function showPodobneProdukty(iPage, iKat, iProd) {
	xajax_showPodobneProdukty(iPage, iKat, iProd);
}

function wyslij_mail() {
	var tresc = o('kontakt_tresc').value;
	var mail = o('kontakt_mail').value;
	var blad =0;
	
	o('kontakt_tresc').className = "inp2";
	o('kontakt_mail').className = "inp2";

		
	if(validateEmail(mail) == false) {
		o('kontakt_mail').className = "inp2_red";
		blad = 1;
	}
	
	if(tresc.length < 2) {
		o('kontakt_tresc').className = "inp2_red";
		blad = 1;
	}
	
	
	if(blad == 0) xajax_sendMail2(mail, tresc);
	
	
}


function checkIfEnter(e)
{
	var iCode;
	if (e.keyCode) iCode = e.keyCode;
	else if (e.which) iCode = e.which;
	var keyChar = String.fromCharCode(iCode);
	if(keyChar == "\r")
	{
		logowanie_user();
	}
}


function init()
{

	if(strona != "kserosystem") {
		try {  o('banner').innerHTML = baner.fetch(); } catch(e) { }
		try {  o('banner2').innerHTML = baner2.fetch(); } catch(e) { }
	}
Shadowbox.init();

}

(window.attachEvent)?attachEvent('onload', init) : addEventListener('load', init, false);



document.onkeydown = checkKeycode

function checkKeycode(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
if(keycode == 27 && okienko_wybrane != "none") {
	if(okienko_wybrane == "profil" || okienko_wybrane == "awatar") setTimeout("location.reload()",1);
	else zamknij_okienko(okienko_wybrane);
}
}

function zgloszenieSerwisowe() {
	przyciemnienie();
	o('zgloszenie_serwisowe').style.display = "block";
}


function wyslijKontakt() {
	var imie = o('kontakt_imie').value;
	var naz = o('kontakt_nazwisko').value;
	var firma = o('kontakt_firma').value;
	var email = o('kontakt_email').value;
	var wiadomosc = o('kontakt_wiadomosc').value;
	

	o('kontakt_imie').className = "input";
	o('kontakt_email').className = "input";
	o('kontakt_wiadomosc').className = "textarea";

		
	var blad = 0;	
	
	if(validateEmail(email) == false) {
		o('kontakt_email').className = "input_red";
		blad = 1;
	}
	if(imie.length < 3) {
		o('kontakt_imie').className = "input_red";
		blad = 1;
	}
	if(wiadomosc.length <3) {
		o('kontakt_wiadomosc').className = "textarea_red";
		blad = 1;
	}
	
	if(blad == 0) xajax_wyslijKontakt(imie, naz, firma, email, wiadomosc);
	
	
}

function szukaj() {

	if(trim(o('fraza').value).length < 3) o('fraza').style.color = "#e20000";
	else o('szukaj_form').submit();
	
}
var sb = 0;
function szukaj_kc() {

	if(trim(o('fraza').value).length < 3) {
		o('fraza').style.color = "#9c0818";
		o('fraza').style.border = "1px solid #9c0818";
		sb = 1;
	}
	else o('szukaj_form').submit();
}

function szukaj_ks() {

	if(trim(o('fraza').value).length < 3) {
		o('fraza').style.border = "1px solid #e20000";
	} else if(o('fraza').value  == "Wpisz szukaną frazę") {
		o('fraza').style.border = "1px solid #e20000";
	}
	else o('szukaj_form').submit();
	
	return false;
}


function spr_szukaj_kc() {
	if(sb == 1) {
		if(trim(o('fraza').value).length > 3) {
			sb=0;
			o('fraza').style.color = "#6a6a6a";
			o('fraza').style.border = "1px solid #ccc";
		
		}
	}
}

function clearInp(obj, tekst) {
	if(obj.value == tekst) obj.value = "";
}

function insertInp(obj, tekst) {
	if(obj.value == "") obj.value = tekst;
}