function printContents() {
	iWidth = window.screen.width;
	iHeight = window.screen.height;
    wt = 630;
    ht = 460;
    lt = (iWidth - wt) / 2;
    tp = (iHeight - ht) / 2;
    window.open("print.php", '', 'height='+ht+',width='+wt+',top='+tp+',left='+lt+',toolbar=no,resizable=no,scrollbars=yes'); 
}

function popupImage(file, desc, width, height) {
	preview(file, desc, width, height);
}

function preview(file, desc, width, height) {
 if (desc == null) {
   desc = '';
 }
 var left = (screen.width - width) / 2;
 var top = (screen.height - height + 20) / 2;
 window.open("preview.php?file="+file+"&desc="+desc, "_preview_", "width="+width+",height="+height+",top="+top+",left="+left);
}

function techpreview(file1, file2, desc, width, height) {
 if (desc == null) {
   desc = '';
 }
 height = height + 40;
 var left = (screen.width - width) / 2;
 var top = (screen.height - height + 20) / 2;
 window.open("techpreview.php?file1="+file1+"&file2="+file2+"&desc="+desc, "_preview_", "width="+width+",height="+height+",top="+top+",left="+left);
}

function prices(typeId, id) {
 var width = 630;
 var height = 450;
 var left = (screen.width - width) / 2;
 var top = (screen.height - height + 20) / 2;
 window.open("prices.php?typeId="+typeId+"&id="+id, "_preview_", "width="+width+",height="+height+",top="+top+",left="+left+",scrollbars=yes");
}

var lastOne;
function highlight(id) {
    dehighlight();
    document.getElementById('td' + id).style.backgroundColor = "#c7c8da";
    lastOne = 'td' + id;
}
function dehighlight() {
    if (lastOne) {
        document.getElementById(lastOne).style.backgroundColor = "";
    }
    scrollTo(0,0);
}

function colorpreview(file, box) {
	document.getElementById(box).src = file;
}

function colorhide(box) {
	document.getElementById(box).src = 'images/empty.gif';
}

function CheckDate(data) {
	var a = new Array();
	a = data.split("-");
	if(a.length==3) {
		var day = a[0]*1;
		var mon = a[1]*1;
		var yer = a[2]*1;
		
		if (day>31) {
			return -2;
		}
		
		if((mon==0)||(mon>12)) {
			return -6;
		}
		if ((mon==4)||(mon==6)||(mon==9)||(mon==11)) {
			if(day==31) {
				return -3;
			}
		}
		if(mon==2) {
			if((day == 31)||(day==30)) {
				return -5;
			}
			if((yer%4 > 0)&&(day==29)) {
				return -4;
			}
		} 		
	} else {
		return -1;
	}
	
	return 1;
}

function CompareDates(datestring1,datestring2)
{
	var a = new Array();
	var b = new Array();
	a = datestring1.split("-");
	b = datestring2.split("-");
	
	var daya = a[0]*1;
	var mona = a[1]*1;
	var yera = a[2]*1;
	
	var dayb = b[0]*1;
	var monb = b[1]*1;
	var yerb = b[2]*1;
	
	if(yerb < yera) {
		return false;
	} else {
		if(yera==yerb) {
			if(monb < mona) {
				return false;
			} else {
				if(monb == mona) {
					if(dayb > daya) {
						return true;
					} else {
						return false;
					}
				} else {
					return true;
				}
			}
		} else {
			return true;
		}
		
	}	
}

with (navigator) if (appName.indexOf('Microsoft')!=-1 && appVersion.indexOf('Mac')==-1) {
	document.write('<scr'+'ipt language="VBScript">\nMM_flash = NOT IsNull(CreateObject("ShockwaveFlash.ShockwaveFlash"))\n</scr'+'ipt>');
}

function MM_checkPlugin(plgIn) {
  	var result = false;
//  	var objRegExp = /Opera/
// 	if(objRegExp.test(navigator.userAgent)) {
//  		return false;
//  	}
 	if (navigator.appName.indexOf('Microsoft')==-1 || (navigator.plugins && navigator.plugins.length)) {
  		result = navigator.plugins[plgIn] != null ? true : false;
	} else {
  		if (navigator.appName.indexOf('Microsoft')!=-1 && navigator.appVersion.indexOf('Mac')==-1) {
				result = MM_flash;
			}
	}
	result = result == true ? true : false;
	return result;  		
}

var flashExists = MM_checkPlugin("Shockwave Flash");
//var flashExists = false;

function updatePartSearch() {
	var prodCombo = document.getElementById('sproduct');
	var typeValue = document.getElementById('scategory').value;
	var prodCounter = 0;
	prodCombo.options.length = 1;
	for (var kind in products[typeValue]) {
		prodCombo.options[prodCounter++] = new Option(products[typeValue][kind][0], kind+"_", false, false);
		for (var prod in products[typeValue][kind][1]) {
			prodCombo.options[prodCounter++] = new Option('...' + products[typeValue][kind][1][prod], prod, false, false);
		}
	}
}

function updatePartSearch2(type, product, welcome) {
	var prodCombo = document.getElementById(product);
	var typeValue = document.getElementById(type).value;
	var prodCounter = 0;
	prodCombo.options.length = 1;
	prodCombo.options[prodCounter++] = new Option(welcome, -1, false, false);
	for (var kind in products[typeValue]) {
		prodCombo.options[prodCounter++] = new Option(products[typeValue][kind][0], -1, false, false);
		for (var prod in products[typeValue][kind][1]) {
			prodCombo.options[prodCounter++] = new Option('...' + products[typeValue][kind][1][prod], prod, false, false);
		}
	}
}

function checkParts(form) {
	var err = '';
	if(form.typeId.value == -1) {
		err = err + "Nie wybrano grupy produkt??w.\n";					
	}
	if(form.productId.value == -1) {
		err = err + "Nie wybrano produktu.\n";
	}
	if (err != '') {
    	alert(err);
		return false;
    }
	return true;
}

function checkfinder(form) {
	var err = '';
	if(form.searchCat.value == -2) {
		err = err + "Nie wybrano kategorii.\n";					
	}
	if(form.searchText.value.length == 0) {
		err = err + "Nie wpisano tekstu do wyszukania.\n";
	}
	if (err != '') {
    	alert(err);
		return false;
    }
	return true;
}

function rollover(obj, img) {
	obj.src = 'images/' + img + '_on.gif';
}

function rollout(obj, img) {
	obj.src = 'images/' + img + '.gif';
}

var reportTimerID = null;
var reportShown = new Array();
var lastShown = '';

function serviceOn(id) {
	if (id == lastShown) {
		clearReportTimer();
	} else if (lastShown != '') {
		reportDivHide(lastShown);
		clearReportTimer();
	}
	lastShown = id;
	obj = document.getElementById(id + '_class');
	var r1 = new RegExp("_off","g");
	if (obj != null) {
		obj.className = obj.className.replace(r1, "_on");
	}
}

function serviceOut(id) {
	func = 'reportDivHide(\'' + id + '\')';
	reportTimerID = setTimeout(func, 800);
}

function reportDivHide(id) {
	obj = document.getElementById(id + '_class');
	var r1 = new RegExp("_on","g");
	if (obj != null) {
		obj.className = obj.className.replace(r1, "_off");
	}
}

function clearReportTimer() {
    if (reportTimerID != null) {
       clearTimeout(reportTimerID);
       reportTimerID = null;
    }
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}	else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent)	{
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}	else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

function updateServiceHint(id) {
	obj = document.getElementById(id + '_class');
	offset = document.getElementById('mapHint');
	obj.style.top = (findPosY(offset) - 30) + 'px';
	obj.style.left = (findPosX(offset) + 235) + 'px';
}
function updateShopHint(id) {
	obj = document.getElementById(id + '_class');
	if (obj){
		offset = document.getElementById('mapHint');
		obj.style.top = (findPosY(offset) - 30) + 'px';
		obj.style.left = (findPosX(offset) + 235) + 'px';
	}
}