function openWin(URL,width,height,scroll,resize, status, menubar, toolbar, location, directories) {
	noUrl = false	
	if (URL == "" || URL == null) { URL="about:blank"; noUrl=true }
	if (width == "" || width == null ) { width = 640 }
	if (height == "" || height == null ) { height = 480 }
	if ((scroll == "" || scroll == null) && scroll != 0) { scroll = 1 }
	if ((resize == "" || resize == null) && resize != 0) { resize = 1 }
	if ( (status == "" || status == null)  && status != 0) { status = 1 }
	if (menubar == "" || menubar == null) {menubar=0}
	if (toolbar == "" || toolbar == null) {toolbar=0}
	if (location == "" || location == null) {location=0}
	if (directories == "" || directories == null) {directories=0}
	
	PARMS = 'left=10,top=10,toolbar='+toolbar +',location='+location +',directories='+directories +',status='+status +',menubar='+menubar +',scrollbars=' + scroll + ',resizable=' + resize + ',width=' + width + ',height=' + height
  var newWin = window.open(URL,"NEW",PARMS)
  newWin.focus();  
  
	if (noUrl) {
		newWin.document.writeln("<BR><BR><FONT color='red'>It seems like you forgot to put in a value for URL when you called for <I>openWin()</I></FONT>")
		newWin.document.close()
	}
	return;
}

function openFullScreenWin(u) {
	var w = screen.availWidth * (99/100);
	var h = screen.availHeight * (99/100);
	var parms = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+w+',height='+h+',top=0,left=0';
	var windowname = 'fullscreenpop';
	
	window.open(u,windowname,parms);
}

function okno(o,w_p,h_p,tytul,w_o,h_o) { //o - obraz, w_o/h_o - szerokość/wysokość okna, w_p/h_p - szerokość/wysokość obrazka
	scrollbars1 = 0;
	if (w_o == undefined) w_o = w_p + 20; else w_o += 20;
	if (h_o == undefined) h_o = h_p + 64; else h_o += 64;
	left1 = (screen.width - w_o)/2;
	top1 = (screen.height - h_o)/2

;		
	windowprops = "toolbar=no,location=no,status=no,menubar=no,scrollbars="+scrollbars1+",resizable=no,left="+left1+",top="+top1+",width="+w_p+",height="+h_p+",scrolling=1";
	text = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-2'><title>"+tytul+"</title></head><body style='background: #ffffff; margin:0; text-align:center'><img border='0' src='"+o+"' width='"+w_p+"' height='"+h_p+"'></body></html>";
	preview = window.open('', 'preview', windowprops);
	
	if (scrollbars1) {
		preview.resizeTo((w_o+28),(h_o));
	}
	else {
		preview.resizeTo(w_o,h_o);
	}
	
	preview.document.open();
	preview.document.write(text);
	preview.document.close();
	preview.focus();
}

function getCleanUrl() {
	URL = document.URL
	myParamStartPos = URL.indexOf("?",0)
	if(myParamStartPos>0){
		URL = document.URL.substr(0,myParamStartPos)
		return URL
	}
	else return URL
}

function getParam(name) 
{
	var param;
	var idxStart = document.URL.indexOf('?');
	
	if (idxStart >= 0) {
		// get the query string, prepend and append & to make searching easier
		idxStart += 1;
		var url = "&"+document.URL.substring(idxStart, document.URL.length)+"&";
		
		// found the param?
		idxStart = url.indexOf("&"+name+"=");
		if (idxStart >= 0) {
			idxStart += name.length+2;
			var idxEnd = url.indexOf("&", idxStart);
			param = url.substring(idxStart, idxEnd);
		} else debug("Couldn't find param: "+name, "DEBUG");
	}
	
	debug("getParam('"+name+"') = "+param, "DEBUG");
	return param;
} // getParam(name)


function changeUrlParams(params){
	currentCleanUrl = getCleanUrl()
	newUrl = currentCleanUrl + "?" +params
	document.location = newUrl
}

function getServerInfo() {
 return document.location.host
 //alert(document.location.port)
}
//Swaps image
// LAF: this doesn't look netscape compatible, especitially with layers
function swapImage(imgName,imgSrc) {
	document.images[imgName].src=imgSrc
}


// debug level setting for displaying debug messages with the debug() function
// this can be set in any javascript file or block
var DEBUG; // 'DEBUG', 'ERROR', 'WARNING'

// debug message alerts
// uses the global variable DEBUG 
// msg = the message to display in the alert
// logLevel = only displays the msg if the current log level, or higher, is being used
// where log levels are: debug, warning, info
// if DEBUG='DEBUG' all messages are shown, i.e. debug, error, and warning messages
// if DEBUG='WARNING' only warning and error messages are shown
// if DEBUG='ERROR' only error messages are shown
function debug(msg, logLevel) {
	//if (!DEBUG) DEBUG = getParam("DEBUG");
	if (!DEBUG || (DEBUG=='')) return; // debugging is turned off
	if (!logLevel) logLevel = 'DEBUG'; // default
	if (DEBUG != 'DEBUG') {
		if ((DEBUG == 'ERROR') && (logLevel != 'ERROR')) return;
		if ((DEBUG == 'WARNING') && (logLevel == 'DEBUG')) return;
	}
	alert('Debug level: '+DEBUG+'\nMessage level: '+logLevel+'\n'+msg);
}

// Funkcje ONYX
// by bukwa, m.bukowski@onyx.pl
function wydruk(plik,tytul){
	adres = "wydruk.asp?plik=" + plik + "&tytul=" + tytul;
	window.open(adres,"Wydruk","location=0,toolbar=1,status=1,directories=0,menubar=1,resizable=1,scrollbars=1,left=10,top=10");
}

function wydruk_1(plik,tytul){
	adres = "http://www.saab.pl/docs/pl/wydruk.asp?plik=" + plik + "&tytul=" + tytul;
	window.open(adres,"Wydruk","location=0,toolbar=1,status=1,directories=0,menubar=1,resizable=1,scrollbars=1,left=10,top=10");
}

function wydruk_wyp(model,tytul){
	adres = "wydruk_wyposazenie.asp?model=" + model + "&tytul=" + tytul;
	window.open(adres,"Wydruk","location=0,toolbar=1,status=1,directories=0,menubar=1,resizable=1,scrollbars=1,left=10,top=10");
}

function otworz_cennik(){
	//openWin('http://cennik.saab.pl/index.asp?licz=1',770,430,1,1,1,1,1);
	top.location.href = "http://www.saab.pl/docs/pl/modele.asp";
}

function otworz_uzywane(){
//	openWin('http://uzywane.saab.pl/index.asp?licz=1',770,430,1,1,1,1,1)
	openWin('http://uzywane.saab.pl/index.html',770,430,1,1,1,1,1)
}

function otworz_odreki(){
	openWin('http://odreki.saab.pl/index.asp',770,430,1,1,1,1,1)
//	openWin('http://odreki.saab.pl/index.asp?licz=1',770,430,1,1,1,1,1)
//	openWin('http://odreki.saab.pl/index.html',770,430,1,1,1,1,1)
}

function otworz_expressions(){
//	openWin('http://gadzety.saab.pl/index.asp?licz=1',770,430,1,1,1,1,1)
	window.open("http://www.saabexpressions.com");
}

function otworz_saab_newsletter(){
	//openWin('http://www.saab.pl/docs/pl/zamow_biuletyn.html',370,476,1,0,0,0,0)
	top.location.href = "http://www.saab.pl/docs/pl/newsletter.asp";
}

function nowy_kabriolet(){
	openFullScreenWin('http://www.saab.pl/docs/pl/microsite/93_kabriolet/index.html')
}

function saab_93_aero(){
	openFullScreenWin('http://www.saab.pl/docs/pl/microsite/93_aero/index.asp')
}

function niepohamowane_uczucie(){
	openFullScreenWin('http://www.saab.com/microsites/imap04/main2.xml?market=GLOBAL&language=en')
}

function nowy_kabriolet2(){
	openFullScreenWin('http://www.saab.com/microsites/93convertible_2/main2.xml?market=GLOBAL&language=en')
}

function warunki(){
	msg=open('warunki_korzystania.html','','toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=no,width=450,height=450,top=20,left=20')
}

function ochrona_danych(){
	msg=open('ochrona_danych_osobowych.html','ochrona','toolbar=no,directories=no,menubar=no,scrollbars=no,resizable=no,width=450,height=260,top='+(screen.height-260)/2+',left='+(screen.width-450)/2);
   msg.focus();
}

//dla prezentacji 9-3 SK
function warunki_1(){
	msg=open('../../warunki_korzystania.html','','toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=no,width=450,height=450,top=20,left=20')
}
//dla cennika
function warunki_2(){
	msg=open('http://www.saab.pl/docs/pl/warunki_korzystania.html','','toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=no,width=450,height=450,top=20,left=20')
}
function otworz_IDS(){
	//window.open("http://www.saab.com/main/GLOBAL/en/ids/index.shtml");
	window.open("http://www.saab.com/global/en/start#/buy-own/sales/international-sales/info/");
}
function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	/* script from http://techpatterns.com/ */
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
function ukryjBaner() {
	document.getElementById('banerDolny').style.display = "none";
	Set_Cookie('bD', '1', '3');
}

function pokaz(id) {
	document.getElementById(id).style.display = "block";
}

function ukryj(id) {
	document.getElementById(id).style.display = "none";
}

function pokazTop(zawartosc,cel) {
	$(cel).innerHTML = $(zawartosc).innerHTML;
}

function ukryjTop(cel) {
	$(cel).innerHTML = '';
}

var doc = document;
var $ = function (id) {
	return doc.getElementById(id);
}
function dodajZdarzenie(odnosnik, zdarzenie, funkcja) {
	if (odnosnik.addEventListener) odnosnik.addEventListener(zdarzenie, funkcja, false);
	else odnosnik.attachEvent("on" + zdarzenie, funkcja);
}
function usunZdarzenie(odnosnik, zdarzenie, funkcja) {
	if (odnosnik.removeEventListener) odnosnik.removeEventListener(zdarzenie, funkcja, false);
	else odnosnik.detachEvent("on" + zdarzenie, funkcja);
}
function initTopMenu() {
	//zmienna paramMenuJs jest zdefiniowana w funkcji tworzącej menu
	for (i=0; i<parseInt(paramMenuJs.numBut); i++) {
		dodajZdarzenie($(paramMenuJs.preID + i + paramMenuJs.menuEndStrId), "mouseover", showSubMenu);
		dodajZdarzenie($(paramMenuJs.preID + i + paramMenuJs.menuEndStrId), "mouseout", hideSubMenu);
		licz = 0;
		while ($(paramMenuJs.preID + licz + "_" + i + paramMenuJs.menuSubItemEndStrId) != undefined) {
			dodajZdarzenie($(paramMenuJs.preID + licz + "_" + i + paramMenuJs.menuSubItemEndStrId), "mouseover", subMenuLinksIn);
			dodajZdarzenie($(paramMenuJs.preID + licz + "_" + i + paramMenuJs.menuSubItemEndStrId), "mouseclick", subMenuLinksDeactive);
			dodajZdarzenie($(paramMenuJs.preID + licz++ + "_" + i + paramMenuJs.menuSubItemEndStrId), "mouseout", subMenuLinksOut);
		}
	}
}
function subMenuLinksIn(e) {
	var elem;
	if (!e) var e = window.event;
	elem = e.target || e.srcElement;
	showSubMenuItemActiveFlag = false;
	showSubMenuActiveFlag = false;
	subMenuItemLinkIn(elem.id.replace(paramMenuJs.preID, ''));
}
function subMenuItemLinkIn(item) {
	subMenuLinkOut();
	if (item != undefined) $(paramMenuJs.preID + item).className = 'topMenuSubItemLinkOn';
	paramMenuJs.menuSubItemIdCurr = item;
}
function subMenuLinksOut() {
	showSubMenuItemActiveFlag = true;
	//showSubMenuActiveFlag = true;
	countHideSub++;
	setTimeout("subMenuLinksOutTime()", timeToShowHide);
}
function subMenuLinksOutTime() {
	if (showSubMenuItemActiveFlag == true)
		if (countHideSub <= 1) {
			if (paramMenuJs.menuSubItemIdActive != -1 && paramMenuJs.menuItemIdCurr == paramMenuJs.menuItemIdActive) {
				showSubMenuItemActiveFlag = false;
				subMenuItemLinkIn(paramMenuJs.menuSubItemIdActive + "_" + paramMenuJs.menuItemIdCurr + paramMenuJs.menuSubItemEndStrId);
			}
			else subMenuLinkOut();
			
			showSubMenuActiveFlag = true;
			hideSubMenuTime();
		}
	countHideSub = countHideSub > 0 ? countHideSub - 1 : countHideSub;
}
function subMenuLinkOut() {
	if (parseInt(paramMenuJs.menuSubItemIdCurr) != -1)
		$(paramMenuJs.preID + paramMenuJs.menuSubItemIdCurr).className = 'topMenuSubItemLink';
}
function subMenuLinksDeactive() {
	//powinno zapobiec przeskoczeniu menu przy wolnym łączu
	countHide = 100;
}
var countHide = 0;
var countHideSub = 0;
var showSubMenuActiveFlag = true;
var showSubMenuItemActiveFlag = true;
var timeToShowHide = 2000;
function showSubMenu(e) {
	var elem;
	if (!e) var e = window.event;
	elem = e.target || e.srcElement;
	showSubMenuItem(parseInt(elem.id.replace(paramMenuJs.preID, '')));
	showSubMenuActiveFlag = false;
	showSubMenuItemActiveFlag = false;
}
function showSubMenuItem(item) {
	hideSubMenuItem();
	$(paramMenuJs.preID + item + paramMenuJs.menuSubEndStrId).className = '';
	$(paramMenuJs.preID + item + paramMenuJs.menuEndStrId).className = 'topMenuItemOn';
	paramMenuJs.menuItemIdCurr = item;
}
function hideSubMenu() {
	showSubMenuActiveFlag = true;
	countHide++;
	subMenuLinkOut();
	setTimeout("hideSubMenuTime()", timeToShowHide);
}
function hideSubMenuTime() {
	if (showSubMenuActiveFlag == true)
		if (countHide <= 1) {
			if (paramMenuJs.menuItemIdActive != -1) {
				showSubMenuActiveFlag = false;
				showSubMenuItem(paramMenuJs.menuItemIdActive);
				if (paramMenuJs.menuSubItemIdActive != -1 && paramMenuJs.menuItemIdCurr == paramMenuJs.menuItemIdActive)
					subMenuItemLinkIn(paramMenuJs.menuSubItemIdActive + "_" + paramMenuJs.menuItemIdCurr + paramMenuJs.menuSubItemEndStrId);
			}
			else {
				hideSubMenuItem();
				subMenuLinkOut();
			}
		}
	countHide = countHide > 0 ? countHide - 1 : countHide;
}
function hideSubMenuItem() {
	if (paramMenuJs.menuItemIdCurr != -1) {
		$(paramMenuJs.preID + paramMenuJs.menuItemIdCurr + paramMenuJs.menuSubEndStrId).className = 'ukryjD';
		$(paramMenuJs.preID + paramMenuJs.menuItemIdCurr + paramMenuJs.menuEndStrId).className = 'topMenuItem';
	}
}

// Menu KONIEC

// Oferta specjalna - TX edition
function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
	//return $(movieName);
}
function stF(text) {
	getFlashMovie("Baner93").sendTextToFlash(text);
}
function setOpacity(id, value) {
	if (document.all && !window.opera) $(id).style.filter='alpha(opacity='+value*100+')';
	else $(id).style.opacity=value;
}

function getOpacity(id) {
	if (document.all && !window.opera) {
		$(id).style.filter.match(/opacity=(\d+)/);
		return RegExp.$1;
	}
	else return $(id).style.opacity;
}

function hideEffect() {
	$('txLayer').style.display = 'none';
	stF('play');
}

var showEffectTimer = "";
var licznik = 0;
var hideEffectTimer = "";
function showEffect() {
	setOpacity("txDetail", licznik++/10);
	if (licznik > 10) {
		licznik = 0;
		clearInterval(showEffectTimer);
		showEffectTimer = "";
		if (hideEffectTimer == "")
			hideEffectTimer = setTimeout("hideEffect()", 4000);
		else {
			clearInterval(hideEffectTimer);
			hideEffectTimer = setTimeout("hideEffect()", 4000);
		}
	}
}

function txEffect(photo) {
	if (showEffectTimer == "") {
		time = new Date();
		clicktime = time.getTime();
		banner = $('txLayer');
		banner.style.display = 'block';
		detail = $('txDetail');
		setOpacity(detail.id, 0);
		//alert("opa: " + getOpacity('txDetail'));
		var imgTmp = new Image();
		imgTmp.onload = function () {
			detail.src = imgTmp.src;
			//showEffect();
			//for (i=0; i<11; i++) setTimeout('setOpacity("txDetail", '+i/10+')', i*100);
			stF('stop');
				showEffectTimer = setInterval("showEffect()", 40)
		}
		imgTmp.src = photo;
	}
}

window.onload = function() {
	initTopMenu();
}
