var ns = (document.layers) ? 1 : 0;
var ie = (document.all) ? 1 : 0;
var ns6= (!document.all && document.getElementById) ? 1 : 0;

var jest_flash = 0;
if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
    if (navigator.plugins && navigator.plugins["Shockwave Flash"])
        jest_flash = 1;
} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.userAgent.indexOf("Windows 95")>=0 || navigator.userAgent.indexOf("Windows 98")>=0 || navigator.userAgent.indexOf("Windows NT")>=0)) {
    document.write('<SCRIPT LANGUAGE=VBScript\> \n');
    document.write('on error resume next \n');
    document.write('jest_flash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3")))\n');
    document.write('if ( jest_flash <= 0 ) then jest_flash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4")))\n');
    document.write('if ( jest_flash <= 0 ) then jest_flash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")))\n');
    document.write('if ( jest_flash <= 0 ) then jest_flash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")))\n');
    document.write('</SCRIPT\> \n');
}
function showLayer(id) {
  if(ie) { document.all[id].style.visibility = 'visible';}
  else if (ns) { document.layers[id].visibility = 'visible';}
  else if(ns6) {document.getElementById(id).style.visibility = 'visible';}
}
function hideLayer(id) {
  if(ie) { document.all[id].style.visibility = 'hidden';}
  else if (ns) { document.layers[id].visibility = 'hide';}
  else if(ns6) {document.getElementById(id).style.visibility = 'hidden';}
}
function positionLayer(id,left,top) {
  if(ie) { 
	document.all[id].style.left = left;	
	document.all[id].style.top = top;	
  } else if (ns) { 
	document.layers[id].left = left;
	document.layers[id].top = top;
  } else {
	document.getElementById(id).style.left = left;
	document.getElementById(id).style.top = top;
  }
}
function change(id,img,warstwa)
{
 if(document.images)
 {
  if(ns) {
      warstwa ? document.layers[warstwa].document.images[id].src=img : document.images[id].src=img;
  } else {
  document.images[id].src=img;
  }
 }
}
function show(url,title,w,h) {
	var url='window.php?img='+url+'&title='+title;
	var showWindow = window.open(url,"ShowWindow",'top=20,left=40,width='+w+',height='+h+',scrollbars=no');
	showWindow.focus();
}
function showWindow(url,w,h) {
	var showWindow = window.open(url,"ShowWindow",'top=20,left=40,width='+w+',height='+h+',scrollbars=no');
	showWindow.focus();
}
function position_logo() {
	if(ns) w = self.innerWidth;
	else if(ns6) w = document.getElementById('checkWidth').offsetLeft;
	else w = document.body.clientWidth;
	w = w/2 - 70;
	positionLayer('logo',w,40);
	showLayer('logo');
}
function addToFav(){
 if (navigator.appName =="Microsoft Internet Explorer") {
   window.external.AddFavorite(location.href, document.title);
 }
}
function addHP(othis) {
 var ms = navigator.appVersion.indexOf("MSIE");
 var ie5 = (ms>0) && (parseInt(navigator.appVersion.substring(ms+5, ms+7)) >= 5);
 if(ie5) {
   othis.style.behavior='url(#default#homepage)';
   othis.setHomePage(location.href);
 }
}
//top menu
i1 = new Image(); i1.src="images/m_home_off.gif";
i2 = new Image(); i2.src="images/m_kontakt_on.gif";
i3 = new Image(); i3.src="images/m_oferta_on.gif";
i6 = new Image(); i6.src="images/m_mapa_on.gif";
function checkForm()
{
	var f = document.kontakt_form;
	var error1, error2;
	var errorInfo1="Wymagane pola:";	
	if(f.name.value=="") { errorInfo1+="\n- imię"; error1=1;}
	if(f.surname.value=="") {errorInfo1+="\n- nazwisko"; error1=1;}
	if(f.tel.value=="") {errorInfo1+="\n- telefon"; error1=1;}
	if(f.info.value=="") {errorInfo1+="\n- informacja"; error1=1;}
	var errorInfo2="\n\nNieprawidłowo wypełnione pola:";	
	if(f.email.value!="" && !isEmailAddr(f.email.value)) {errorInfo2+="\n- e-mail"; error2=1;}
//	if(f.tel.value!="" && !inValidCharSet(f.tel.value,"0123456789-+")) {errorInfo2+="\n- telefon"; error2=1;}
//	if(f.fax.value!="" && !inValidCharSet(f.fax.value,"0123456789-+")) {errorInfo2+="\n- fax"; error2=1;}
	if((f.code1.value!="" && !isCode1(f.code1.value)) || (f.code2.value!="" && !isCode2(f.code2.value))) {errorInfo2+="\n- kod"; error2=1;}
	var Info = "";
	if(error1==1) Info+=errorInfo1;
	if(error2==1) Info+=errorInfo2;
	if(error1==1 || error2==1) alert(Info);
	else f.submit();
}
function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}
function isCode1(str)
{
	var anum=/^(\d){2}$/;
	if (anum.test(str)) return true;
	else return false;
}
function isCode2(str)
{
	var anum=/^(\d){3}$/;
	if (anum.test(str)) return true;
	else return false;
}
function inValidCharSet(str,charset)
{
	var result = true;
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	return result;
}
