var site_url = 'http://192.168.0.106/';
var barcodeDetect = 0;
var barcodeText = '';

Object.extend(String.prototype, {
	
	isValidEmail: function()
	{
		var filter = /^[_\w-]+(\.[_\w-]+)*@[\w-]+(\.[\w-]+)+$/;
		return filter.test(this);
	},
	
	isImage: function()
	{
		
		var ext = this.substring(this.length-5).toLowerCase();
		if (ext == '.jpeg') return true;
		
		ext = this.substring(this.length-4).toLowerCase();
		if (['.jpg', '.gif', '.png'].indexOf(ext) >= 0) return true;
		
		return false;
	},
	
	escapeAlert: function()
	{
		var text = this.replace(/\n/, "::n::");
		return text.unescapeHTML().replace(/::n::/, "\n");
	}
});

Object.extend(Object, {
	
	selectAll: function(sel)
	{
		if (this.options) {
			if (sel != true) sel = false;
			$A(this.options).each(function(item)
			{
				item.selected = sel;
			});
		}
	}
});

showWait = function()
{
	$('waiting').setStyle({
		left: (document.viewport.getScrollOffsets().left+(document.viewport.getWidth()-30)/2)+'px',
		top: (document.viewport.getScrollOffsets().top+(document.viewport.getHeight()-30)/2)+'px',
		display: 'block'
	});
}

hideWait = function()
{
	$('waiting').hide();
}

alertBox = function(msg)
{
	alert(msg);
}

winPopup = function(url, win, features)
{
	var newWindow = window.open(url, win, features);
	newWindow.focus();
	return newWindow;
}

imgPopup = function(image, win, title)
{
	var tmp = new Image();
	tmp.title = title;
	tmp.newWin = window.open('', win, "width=100, height=100");
	tmp.onload = function()
	{
		this.newWin.document.open();
		this.newWin.document.write('<html><title>'+this.title+'</title>'
			+ '<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'
			+ '<center><img name="myImg" src='+this.src+'></center></body></html>');
		this.newWin.document.close();
		alert(screen.width+' '+this.width);
		this.newWin.moveTo(Math.round((screen.width-this.width)/2), Math.round((screen.height-this.width)/2));
		this.newWin.resizeBy(this.width-this.newWin.document.viewport.getWidth(), this.height-this.newWin.document.viewport.getHeight());
		this.newWin.focus();
	}
	tmp.src = image;
}

popupVisuel = function(code)
{
	imgPopup('/pub/visuels/'+code+'.jpg', 'visuel_'+code, 'Visuel');
}

