
function addBookmark(title,url) {
	if (window.sidebar) {
  		window.sidebar.addPanel(title, url,"");
 	} else if( document.all ) {
 		window.external.AddFavorite( url, title);
 	} else if( window.opera && window.print ) {
 		return true;
	}
}

function printPopup() {
		var printUrl=document.location.href;
		if (printUrl.indexOf('#') > 0) printUrl = printUrl.substring(0,printUrl.indexOf('#'));
		if (printUrl.indexOf('?') > 0) printpop(printUrl + "&print=1");

		else printpop(printUrl + "?print=1");
	}

function winPromoOpen(url)
{
	var Win;
	if (Win) Win.close();
	Win = window.open("/js/promo-view.html?"+url,"photo","width=800, height=600, scrollbars=yes,resizable=yes,menubar=no,status=no");
}



function openNewWindow(url)
{
	openNewWindow(url, 480, 120, 'no', 'no');
}

function openNewWindow(url, x, y, scrollbars, resizable)
{
 	 aPopUp = window.open('','VALLIST');
 	 aPopUp.close();
 	 var left = (screen.availWidth/2) - (x/2);
	 var top = (screen.availHeight/2) - (y/2);

    aPopUp= self.window.open(url,'VALLIST','toolbar=no,location=no,directories=no,status=yes,scrollbars='+scrollbars+',resizable='+resizable+', copyhistory=no,width='+x+',height='+y+',top='+top+',left='+left);
    self.aNoteWin = aPopUp;
}


function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function createCookie(name,value)
{
	var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}



function addToCard(productId,nodeId) {
			document.location.href = '/add-to-cart.bhtml?product_id='+productId+'&nodeid='+nodeId;
			return false;
}
/* warstwa z dedykacj */

function showOverlay () {
	var overlay =document.createElement('div');
	overlay.id="overlay";
	document.getElementsByTagName('BODY')[0].appendChild(overlay);
	
}

function addDedText(id, obj, textValue, evt, helpText) {
	if (obj.checked) {
		if (window.event) {
			window.event.cancelBubble = true;
		}
		else {
			evt.cancelBubble = true;
		}

		showOverlay ();
		/*if (IEversion() ==6) {
			ifr = document.createElement('iframe');
			ifr.id = "alertIfr";
			ifr.frameBorder = "10";
			//ifr.setAttribute('allowtransparency',true);
			ifr.style.zIndex=30;		
			document.getElementsByTagName('BODY')[0].appendChild(ifr);
		}*/
		var notifyLayer = document.createElement('div');
		notifyLayer.id = "alertLayer";

		var dedykacja = document.createElement('div');
		dedykacja.id = 'ded' + id;
		dedykacja.className = 'ded';
		dedykacja.innerHTML = '<div class="title"></div>' +
				'<div class="content clearfix"><img src="/images/www/bg_dedPackage.png" alt="" class="fleft"/>'+
				'<div class="dedText fleft"><textarea id="dedicationText' + id + '">' + textValue + '</textarea><br>'+
				'<span onclick="removeDedication(' + id + ')" class="button cancel" style="background:url(/images/www/btnRemove1.png);">Anuluj</span>'+
				'<span onclick="addDedication(' + id + ');" class="button remove" style="background:url(/images/www/btnRemove1.png); margin-top:0px">Zapisz</span>' +
				'<div class="clear"></div>'+
				'</div><div class="fright grayText">' + helpText + '</div></div>';
		dedykacja.style.top = document.getElementById('cartTable').offsetTop + document.getElementById('td'+id).offsetTop +50+"px";
		dedykacja.style.left = document.getElementById('td'+id).offsetLeft - 160+"px";
		notifyLayer.appendChild(dedykacja);
		var cont =document.getElementById("container");
		document.getElementById('overlay').style.height=cont.clientHeight+'px';
		document.getElementsByTagName('BODY')[0].appendChild(notifyLayer);
	}
	else {
			
		if ($('grayText'+id))
			$('grayText'+id).style.display='none';
		$('dedykacja_' + id).checked = false;		
	}
}


function hideNotify() {
	var node = $('alertLayer');
	if (node)
		try {
			 $('container').removeChild(node);}
		catch (e)
	         {
			node.parentNode.removeChild(node);
	     }
	var node = $('overlay');
	if (node)
		try {
			 $('container').removeChild(node);}
		catch (e)
	         {
			node.parentNode.removeChild(node);
	     }
	/*	if (IEversion() ==6) 
			document.getElementById('alertIfr').style.display='none';*/
			
}

function showNotify(prodTitle, msg) {
	
	height = (navigator.appName.indexOf("Netscape") != -1) ? pageYOffset + (innerHeight/2) - 100 : (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop) + ((window.screen.height-200)/2) - 100;

	hideNotify();
	notifyLayer = document.createElement('div')
	notifyLayer.id = "alertLayer";
	notifyLayer.onclick = function () {hideNotify();};
	notifyLayer.style.height =((navigator.appName.indexOf("Netscape") != -1) ? pageYOffset + innerHeight: (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop) + window.screen.height-200) +'px';

	notify = document.createElement('div')
	notify.id = "addToCartAlert";


	ifr = document.createElement('iframe');
	ifr.id = "alertIfr";
	ifr.frameBorder = "0";
	ifr.style.marginTop = height+'px';
	ifr.setAttribute('allowtransparency',true);

	pClose = document.createElement('img');
	pClose.src="/images/www/spacer.gif"
	pClose.id = "closeAlert";
	pClose.onclick = function() {hideNotify();};


	pIntro = document.createElement('p');
	pIntroText = document.createTextNode('Added to your basket:');
	pIntro.appendChild(pIntroText);

	pContener = document.createElement('div');
	pContener.id="alertContener";

	pProd = document.createElement('h2');
	pProd.id = "alertProdTitle"
	pProd.innerHTML = prodTitle;

	pInputCont = document.createElement('span');
	pInputCont.className = 'more';
	pInputCont.onclick=function() {hideNotify();};
	pInputText = document.createTextNode('Back to store');
	pInputCont.appendChild(pInputText);

	pCartLink = document.createElement('a');
	pCartLink.className = 'more more_red';
	pCartLink.href = '/cart.bhtml';
	pCartText = document.createTextNode('Order now!');
	pCartLink.appendChild(pCartText);

	notify.appendChild(pClose);
	notify.appendChild(pIntro);
//	notify.appendChild(pProd);
	pContener.appendChild(pProd);
	for(var j=0; j < msg.length; j++) {
		pService = document.createElement('h2');
		pService.id = "alertProdTitle"
		pServiceText = document.createTextNode(msg[j]);
		pService.appendChild(pServiceText);
		pContener.appendChild(pService);
	}
	notify.appendChild(pContener);
	notify.appendChild(pInputCont);
	notify.appendChild(pCartLink);
	notifyLayer.appendChild(ifr);
	notifyLayer.appendChild(notify);


	document.getElementById("top").appendChild(notifyLayer);
	document.getElementById("container").onclick = function() {hideNotify();};
}

function showPhoto(midi, maxi, el) {

	ml = document.getElementById('medium-link');
	ml.onclick=function() { return winGalleryOpen('/photo/'+maxi);};

	mp = document.getElementById('medium-photo');
	mp.src='/photo/'+midi;
	mp.onclick=function() {winGalleryOpen('/photo/'+maxi);};

	thumbs = document.getElementById('add-photos').childNodes;
	for (i=0; i<thumbs.length; i++) {
		if(thumbs[i]==el) thumbs[i].className='photoswitch  photoactive';
		else thumbs[i].className='photoswitch';
	}

	return false;

}

function get_cookie ( cookie_name )
{
	 var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

	 if ( results )
	return ( unescape ( results[2] ) );
	 else
	 return null;
	}

function generateSendNotify (obj) {
	var state =true;
	var wyrazenie=/^[a-zA-Z0-9\u0105\u0107\u0119\u0142\u0144\u00F3\u015B\u017A\u017C\u0104\u0106\u0118\u0141\u0143\u00D3\u015A\u0179\u017B._-]{1,50}@[a-zA-Z0-9\u0105\u0107\u0119\u0142\u0144\u00F3\u015B\u017A\u017C\u0104\u0106\u0118\u0141\u0143\u00D3\u015A\u0179\u017B.-]+(\.[a-zA-Z0-9\u0105\u0107\u0119\u0142\u0144\u00F3\u015B\u017A\u017C\u0104\u0106\u0118\u0141\u0143\u00D3\u015A\u0179\u017B]{2,})+$/;
	if(wyrazenie.test($('email1').value) ==false){
		$('email1_error').style.display='block';
		state = false;
	}else
		$('email1_error').style.display='none';
	if(wyrazenie.test($('email2').value) ==false){
		$('email2_error').style.display='block';
		state = false;
	}else
		$('email2_error').style.display='none';
	if (state)
		FriendNotificationDwrManager.notifyFriend($('email2').value, $('email1').value, $('comment').value, $('podpis').value, document.location.href, {
			callback:function(data) {
		  	  	if (data=='ok'){
		  	  		obj.innerHTML ='<h2>Poleć znajomemu</h2><p class="tcenter"> Powiadomienie zostało wysłane</p><p>'+
		  	  		'<input type="button" onclick="hideNotify();" class="button" value="ok"></p>';
		  	  	} else {

		  	  	}
			},
		async:false
		});
}

function topMargin() {
	var margin ='';
	if (document.documentElement && !document.documentElement.scrollTop)
	 	margin=200;
	else if (document.documentElement && document.documentElement.scrollTop)
		margin=100+document.documentElement.scrollTop;
	return margin;
}
function gogle_notify(){
	var t=google_product + "?akcja=powiadom";
	pageTracker._trackPageview(t);
}
function IEversion () {
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 	var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 	if (ieversion<7)
  		return 6;
 	else
 		return null;
	}
}

	function notify (evt){
		if (window.event)
	        window.event.cancelBubble = true;
	    else
	        evt.cancelBubble = true;
		
		var marginTop =topMargin();
		var ieVer=IEversion();
		var location=document.location.href;
		var notifyLayer = document.createElement('div')
		var	height = (navigator.appName.indexOf("Netscape") != -1) ? pageYOffset + (innerHeight/2) - 100 : marginTop + (document.body.clientHeight/2) - 100;

		showOverlay ();
		
		notifyLayer.id = "alertLayer";
		//notifyLayer.className="alertLayer"
		notifyLayer.style.height =((navigator.appName.indexOf("Netscape") != -1) ? pageYOffset + innerHeight: marginTop + document.body.clientHeight) +'px';

		if (ieVer ==6){
			ifr = document.createElement('iframe');
			ifr.id = "alertIfr";
			ifr.frameBorder = "0";
			ifr.style.top = marginTop;
			ifr.setAttribute('allowtransparency',true);
			ifr.style.zIndex=0;
		}

		var dedykacja = document.createElement('div');
		dedykacja.id="notify";
		dedykacja.style.marginTop=marginTop+'px';


		dedykacja.innerHTML ='<h2>Poleć znajomemu</h2><form method="post" onsubmit="gogle_notify();generateSendNotify(document.getElementById(\'notify\')); return false">'+
				'<table><tr><td class="label">Adres e-mail znajomego<span class="red">*</span>:</td><td><input type="text" id="email1" name="email1"/>'+
				'<div class="messageError" id="email1_error">Nieprawidłowy adres email</div></td></tr>'+
				'<tr><td class="label">Twój komentarz:</td><td><textarea id="comment" name="comment"></textarea></td></tr>'+
				'<tr><td class="label">Twój adres e-mail<span class="red">*</span>:</td><td><input type="text" id="email2" name="email2"/>'+
				'<div class="messageError" id="email2_error">Nieprawidłowy adres email</div></td></tr>'+
				'<tr><td class="label">Twój podpis:</td><td><input type="text" id="podpis" name="podpis"/></td></tr>'+
				'<tr><td></td><td class="tleft grayText"><span class="red">&nbsp;*</span> - Pola obowiązkowe</td></tr>'+
				'<tr><td colspan="2" class="grayText"><input type="button" class="button fleft" value="Anuluj" onclick="hideNotify();">'+
				'<input type="submit" class="button fright" value="Wyślij"></td></tr>'+
				'</table></form>';

		var container=document.getElementById("container");
		notifyLayer.appendChild(dedykacja);

		if (ieVer==6)
			container.appendChild(ifr);
		var overlay = document.getElementById("overlay");
		overlay.style.height=container.clientHeight+'px';
		overlay.style.background='#aaaaaa';
		
		document.getElementsByTagName('BODY')[0].appendChild(notifyLayer);
		if (ieVer ==6) {
			dedykacja.style.marginLeft='-' + dedykacja.clientWidth/2 + 'px';
			ifr.style.marginLeft='-' + dedykacja.clientWidth/2 + 'px';
			ifr.style.height=dedykacja.clientHeight;
			ifr.style.width=dedykacja.clientWidth;
		}

 	}

	function moveCart () {
		var cart = $('basket-small');
		if (cart) {
			try {
				 $('container').removeChild(cart);}
			catch (e)
		         {
				cart.parentNode.removeChild(cart);
		     }
		     $('cartPlace').appendChild(cart);
		}
	}

	function resizeImageForRightBlock(image) {
		if (image == null) {
			return;
		}
		var container = image.parentNode.parentNode;
		if (container != null) {
			image.className = image.width > container.clientWidth ? 'fitToWidth' : 'fitToHeight';
		}
	}

