//
// (c) 2006 webActive group


function $(sID)
{
    return document.getElementById(sID);
}

function isset(s_VarName)
{
    return (typeof(window[s_VarName]) != 'undefined');
}

function isIE()
{
    var s_Browser = navigator.userAgent.toLowerCase();
    return (s_Browser.indexOf('msie') != -1 && s_Browser.indexOf('opera') == -1); 
}

function isOpera()
{
    var s_Browser = navigator.userAgent.toLowerCase();
    return s_Browser.indexOf('opera') != -1; 
}

function include(sFilename)
{
    var oHeader = document.getElementsByTagName('head').item(0);
    var oScript = document.createElement('script');
    oScript.src = sFilename;
    oScript.type = 'text/javascript';
    oHeader.appendChild(oScript);
}

function addEvent(target, event, func)
{
    if (target.addEventListener)
    {
        if (event == 'mousewheel')
            event = 'DOMMouseScroll';
        target.addEventListener(event, func, false);
    }
    else
    {
        target.attachEvent('on' + event, func);
    }
}

function delegate(that, thatMethod)
{
	if (arguments.length > 2)
	{
		var _params = new Array();
		for (var n = 2; n < arguments.length; ++n)
			_params.push(arguments[n]);
		
		return function() { return thatMethod.apply(that, _params); }
	}
	else
	{
		return function(e) { return thatMethod.call(that, e); }
	}
}

function winOpen(file,title,w,h)
{
     
	var look = '';
	var sbars = 0;
	var resize = 0;

	if(w > screen.availWidth)
	{
		w = screen.availWidth-30;
		sbars = 0;
		resize = 1;
	}
	if(h > screen.availHeight)
	{
		h = screen.availHeight-60;
		sbars = 0;
		resize = 1;
	}

	if(typeof(newWin)=='object')
	{
		if(newWin.closed);
		else
		{
			newWin.resizeTo(w, h);
		}
	}
	
	xpos = (screen.availWidth / 2)-(w / 2);
  	ypos = (screen.availHeight / 2)-(h / 2);

 	look = 'scrollbars='+sbars+', resizable='+resize+', width='+w+',height='+h+', left='+xpos+', top='+ypos;
    newWin = window.open(file,'newWinodow','toolbar=0,statusbar=0,location=0,'+look);
	newWin.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html><head><title>"+title+"</title><style type = \"text/css\">body, html { margin: 0; padding: 0; border: 0; background-color: #F2F1F1 }</style></head>");
	newWin.document.write("<body><img src='" +file+ "' onClick='window.close();' border=0 alt='"+title+"' />");
	newWin.document.write("</body></html>");
	newWin.focus();
	newWin.document.close();
}

function echeck(str) 
{

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){

		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){

		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){

		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){

		    return false
		 }

 		 return true					
}

function checkform(form)
{
	if (echeck(form.Email.value) == false)
	{
		alert("Proszę poprawnie wypełnić pole: Email");
		return false;
	}
	if (form.ImieNazwisko.value.length < 5)
	{
		alert("Proszę poprawnie wypełnić pole: Imię i nazwisko!");
		return false;
	}	
	if (form.NazwaFirmy.value.length < 3)
	{
		alert("Proszę poprawnie wypełnić pole: Nazwa firmy");
		return false;
	}

	if (form.Pytanie.value.length < 5)
	{
		alert("Proszę poprawnie wypełnić pole: Pytanie");
		return false;
	}

	form.submit();

}

function checkform2(form)
{
	if (form.ImieNazwisko.value.length < 5)
	{
		alert("Proszę poprawnie wypełnić pole: Imię i nazwisko!");
		return false;
	}	
	if (form.NazwaFirmy.value.length < 3)
	{
		alert("Proszę poprawnie wypełnić pole: Nazwa firmy");
		return false;
	}

	if (form.UlicaNumer.value.length < 5)
	{
		alert("Proszę poprawnie wypełnić pole: Ulica i numer budynku");
		return false;
	}

	if (form.KodPocztowy.value.length != 6)
	{
		alert("Proszę poprawnie wypełnić pole: Kod pocztowy w formacie XX-XXX");
		return false;
	}

	if (form.Miejscowosc.value.length < 5)
	{
		alert("Proszę poprawnie wypełnić pole: Miejscowość");
		return false;
	}
	
	form.submit();
}

function checkform3(form)
{
	if (echeck(form.Email.value) == false)
	{
		alert("Proszę poprawnie wypełnić pole: Email");
		return false;
	}
	if (form.ImieNazwisko.value.length < 5)
	{
		alert("Proszę poprawnie wypełnić pole: Imię i nazwisko!");
		return false;
	}	
	if (form.NazwaFirmy.value.length < 3)
	{
		alert("Proszę poprawnie wypełnić pole: Nazwa firmy");
		return false;
	}

	if (form.Telefon.value.length < 5)
	{
		alert("Proszę poprawnie wypełnić pole: Telefon");
		return false;
	}
	if (form.Producent.value.length < 3)
	{
		alert("Proszę poprawnie wypełnić pole: Producent");
		return false;
	}	
	if (form.Model.value.length < 3)
	{
		alert("Proszę poprawnie wypełnić pole: Model");
		return false;
	}	

	if (form.Typ.value.length < 2)
	{
		alert("Proszę poprawnie wypełnić pole: Typ");
		return false;
	}	

	if (form.NumerSeryjny.value.length < 5)
	{
		alert("Proszę poprawnie wypełnić pole: Numer seryjny");
		return false;
	}		

	if (form.SzczegolowyOpisUsterki.value.length < 10)
	{
		alert("Proszę poprawnie wypełnić pole: Szczegółowy opis usterki");
		return false;
	}	
	form.submit();
}

function getOffset(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return {left: curleft, top: curtop};
}

function printWindow(productid)
{
	win = window.open('productprint.php?ProductID='+productid, 'printWindow', 'HEIGHT=500, WIDTH=560, toolbar=no, menubar=no, scrollbars=yes,  status=no, resizable=no, location=no, directories=no');
}
