function popImage(image,title) {
	title=title || 'Poland Optical';
	tcp=window.open('','tc','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=100,height=100');
	tcp.document.open();
	tcp.document.write('<html><head><title>'+title+'</title><script src="js/prototype.js"></script><script language="JavaScript">var __noframe=true;</script><script src="js/common.js"></script></head><body onLoad="resizeWin(self,$(\'pic\').width,$(\'pic\').height)" style="padding: 0px; margin: 0px; background-color: white;"><img id="pic" src="'+image+'" onClick="self.close()" style="cursor: hand"></body></html>')
	tcp.document.close();
}

function resizeWin(win,w,h) {
	iWidth = win.innerWidth?win.innerWidth:win.document.body.clientWidth;
	iHeight = win.innerHeight?win.innerHeight:win.document.body.clientHeight;
	iWidth = w - iWidth;
	iHeight = h - iHeight;
	win.resizeBy(iWidth, iHeight);
	win.focus();
}

function isValidEmail(email) {
	var splitted = email.match("^(.+)@(.+)$");
	if(splitted == null) return false;
	if(splitted[1] != null ) {
		var regexp_user=/^\"?[\w-_\.]*\"?$/;
		if(splitted[1].match(regexp_user) == null) return false;
	}
	if(splitted[2] != null) {
		var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
		if(splitted[2].match(regexp_domain) == null) {
			var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
			if(splitted[2].match(regexp_ip) == null) return false;
		}
		return true;
	}
	return false;
}

function isEmpty(str,message) {
	if (str.replace(/ /g,'')=='') {
		if (typeof(message)!='undefined') {
			alert(message);
		}
		return true;
	}
	return false;
}

function numCheck(eventObj) {
	var keyCode;
	if (document.all) {
		keyCode=eventObj.keyCode;
	} else {
		keyCode=eventObj.which;
	}
	if (keyCode==0) return true;
	if (keyCode==8) return true;
	if (keyCode==47) return false;
	if (keyCode<44 || keyCode >58) return false;
	return true;
}

function newsletterAdd(email) {
	if (!isValidEmail(email)) {
		alert(messages[0]);
		return false;
	}

	$('sp').src="?p=Newsletter&do=add&email="+email+"&x="+Math.random();
}

function newsletterDelete(email) {
	if (!isValidEmail(email)) {
		alert(messages[0]);
		return false;
	}
	$('sp').src="?p=Newsletter&do=delete&email="+email+"&x="+Math.random();
}

if (typeof(__noframe)=='undefined') {
	document.write('<iframe id="sp" name="sp" src="" style="height: 1px; width: 1px" scrolling="no" frameborder="0"></iframe>');
}

function toggleUsedItem(itemId)
{
	sender = $('usedH' + itemId);
	usedItem = $('used' + itemId);
	if (usedItem.visible()) {
		Effect.SlideUp(usedItem, {duration: 0.5});
		sender.removeClassName('opened');
	} else {
		Effect.SlideDown(usedItem, {duration: 0.5, queue: "end"});
		sender.addClassName('opened');
	}
}
