var ckNameShop = "dermikaShop";

try {
  var test = inShop;
} catch(ex) {
  if(getCookie(ckNameShop) != null) {
    var currentEvent = window.onload==undefined?null:window.onload.toString();
    if(currentEvent == undefined) {
      window.onload = showShopLink;
    } else {
      if(currentEvent.lastIndexOf("}") != -1)
        window.onload = new Function("event", currentEvent.substring(currentEvent.indexOf("{")+1, currentEvent.lastIndexOf("}")-1)+"\nshowShopLink();\n");
      else
        window.onload = showShopLink;
    }
  }
}

function menuGo(n) {
	switch(n) {
		case 1 :
			window.location="/engine/index.php?page=dla_kobiet";
			break;
		case 2 :
			window.location="/engine/index.php?page=seria&seria=6";
			break;
		case 3 :
			window.location="/engine/index.php?page=porady";
			break;
		case 4 :
			window.location="/engine/index.php?page=o_firmie_list";
			break;
		case 5 :
			window.location="/engine/index.php?page=kontakt";
			break;
		case 6 :
			window.location="/engine/index.php?page=p_glowna";
			break;
		case 7 :
			window.location="/engine/index.php?page=s_glowna";
			break;
	}
}

function menuProGo(n) {
	switch(n) {
		case 1 :
			window.location="/engine/index.php?page=pa_zabiegi";
			break;
		case 2 :
			window.location="/engine/index.php?page=p_kalkulacje";
			break;
		case 3 :
			window.location="/engine/index.php?page=p_preparaty";
			break;
		case 4 :
			window.location="/engine/index.php?page=p_cennik";
			break;
		case 5 :
			window.location="/engine/index.php?page=p_zamowienia_info";
			break;
		case 6 :
			window.location="/engine/index.php?page=p_gabinety";
			break;
		case 7 :
			window.location="/engine/index.php?page=p_oferta";
			break;
		case 8 :
			window.location="/engine/index.php?page=pa_seria&seria=16";
			break;
		case 9 :
			window.location="/engine/index.php?page=p_kontakt";
			break;
		case 10 :
			window.location="/engine/index.php?page=p_targi";
			break;
		case 11 :
			window.location="/engine/index.php?page=p_witaj";
			break;
		case 12 :
			window.location="/engine/index.php?page=pa_dystrybucja_mapa";
			break;
		case 13 :
			window.location="/engine/index.php?page=pa_produkt&produkt=126";
			break;
		case 14 :
			window.location="/engine/index.php?page=pa_katalogi";
			break;
		case 15 :
			window.location="/engine/index.php?page=pa_seria&seria=33";
			break;
		case 16 :
			window.location="/engine/index.php";
			break;
	}
}

function menuProAllGo(n) {
	switch(n) {
		case 1 :
			window.location="/engine/index.php?page=pa_zabiegi";
			break;
		case 2 :
			window.location="/engine/index.php?page=pa_seria&seria=16";
			break;
		case 3 :
			window.location="/engine/index.php?page=pa_gabinety";
			break;
		case 4 :
			window.location="/engine/index.php?page=pa_rejestracja_zacheta";
			break;
		case 5 :
			window.location="/engine/index.php?page=p_glowna";
			break;
		case 6 :
			window.location="/engine/index.php?page=pa_kontakt";
			break;
		case 7 :
			window.location="/engine/index.php?page=pa_produkt&produkt=126";
			break;
		case 8 :
			window.location="/engine/index.php?page=pa_seria&seria=33";
			break;
		case 9 :
			window.location="/engine/index.php";
			break;
		case 10 :
			window.location="/engine/index.php?page=pa_dystrybucja_mapa";
			break;
	}
}

function selectGo(o) {
	if(o.value!="") window.open(o.value, "_blank");
}

function selectGo2(o) {
	if(o.value!="") window.open(o.value, "_self");
}

function popImage(l) {
var popImage=window.open('',"popImage", (document.all?"width=150,height=150,":"")+"scrollbars=no,resizable=yes,toolbar=no,userbar=no,location=no,status=no,menubar=no,screenX=100,screenY=100");
	popImage.document.writeln('<HTML><HEAD><TITLE>Obrazek</TITLE></HEAD>');
	popImage.document.writeln('<BODY bgcolor="#ffffff" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" onLoad="autoSize();">');
	popImage.document.writeln('<div style="vertical-align: middle; text-align: center; width: 100%; height: 100%;"><a href="javascript:self.close();"><img id="image" border="0" src="'+l+'"></a></div>');
	popImage.document.writeln('<script language="JavaScript"><!--');
	popImage.document.writeln('function autoSize(o,l) {');
	if(document.all) {
	  popImage.document.writeln('window.resizeTo(document.getElementById("image").width+12,document.getElementById("image").height+53);');
  } else {
  	popImage.document.writeln('window.innerWidth=document.getElementById("image").width+4;');
	  popImage.document.writeln('window.innerHeight=document.getElementById("image").height+5;');
  }
	popImage.document.writeln('}');
	popImage.document.writeln('/'+'/-'+'-></script>');
	popImage.document.writeln('</BODY></HTML>');
	popImage.document.close();
	popImage.focus();
}

function popUp(l,w,h,s) {
var popUp=window.open(l,"popUp", "width="+w+",height="+h+",scrollbars="+(s==1?"yes":"no")+",resizable=yes,toolbar=no,userbar=no,location=no,status=no,menubar=no");
	popUp.document.close();
	popUp.focus();
}

function fixDate(date) {
  base = new Date(0);
  skew = base.getTime();
  if(skew > 0) date.setTime(date.getTime() - skew);
}

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookiesNames(prefix) {
  var dc = document.cookie;
  var cookieName;
  var stack = new Array();
  var offset = 0;
  while(dc.indexOf(prefix, offset) != -1) {
    cookieName = prefix;
    offset = dc.indexOf(prefix, offset)+prefix.length;
    while(dc.charAt(offset)>='0' && dc.charAt(offset)<='9')
      cookieName += dc.charAt(offset++);
    if(dc.charAt(offset)=='=')
      stack.push(cookieName);
  }
  return stack.length!=0?stack:null;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function showShopLink(e) {
  var linker = document.createElement("div");
  linker.id = "shopLinker";
  linker.innerHTML = '<a href="'+getCookie(ckNameShop)+'">powrót do sklepu</a>';
  document.body.appendChild(linker);
}

function changeShopsListProvince(id) {
  var s = document.forms['formShopList'].elements['province'];
  for(var i = 0; i < s.options.length; i++)
    if(s.options[i].value == id)
      s.selectedIndex = i;
  if(id) {
    advAJAX.get({
      url : '/engine/index.php?page=miasta_ze_sklepow'
      , parameters : {
        'province' : id
      },
      onSuccess : function(obj) {
        document.getElementById('citiesList').innerHTML = obj.responseText;
        document.getElementById('shopList').innerHTML = '';
      },
      onError : function(obj) { try { alert('Błąd: ' + obj.status); } catch(ex) {} }
    });
  } else {
    document.getElementById('citiesList').innerHTML = '';
    document.getElementById('shopList').innerHTML = '';
  }
}

function changeShopsListCity(o) {
  if(o.options[o.selectedIndex].value) {
    advAJAX.post({
      url : '/engine/index.php?page=lista_sklepow'
      , parameters : {
        'city' : o.options[o.selectedIndex].value
      },
      onSuccess : function(obj) {
        document.getElementById('shopList').innerHTML = obj.responseText;
      },
      onError : function(obj) { try { alert('Błąd: ' + obj.status); } catch(ex) {} }
    });
  } else {
    document.getElementById('shopList').innerHTML = '';
  }
}

