jQuery.fn.uicornerfix = function (options) {
	return this.each(function() {
		var config = jQuery.extend( {
			radius: '5px'
		}, options);
		
		DD_roundies.addRule('.ui-corner-all', config.radius);
		DD_roundies.addRule('.ui-corner-top', config.radius + ' ' + config.radius + ' 0 0');
		DD_roundies.addRule('.ui-corner-bottom', '0 0 ' + config.radius + ' ' + config.radius);
		DD_roundies.addRule('.ui-corner-right', '0 ' + config.radius + ' ' + config.radius + ' 0');
		DD_roundies.addRule('.ui-corner-left', config.radius + ' 0 0 ' + config.radius);
		DD_roundies.addRule('.ui-corner-tl', config.radius + ' 0 0 0');
		DD_roundies.addRule('.ui-corner-tr', '0 ' + config.radius + ' 0 0');
		DD_roundies.addRule('.ui-corner-br', '0 0 ' + config.radius + ' 0');
		DD_roundies.addRule('.ui-corner-bl', '0 0 0 ' + config.radius);
	});
};

function ajaxError(textStatus)
{
	var msg = "A aparut o eroare in timpul incarcarii datelor.";
	
	switch (textStatus) {
		case "timeout":
			msg += "\nServerul nu a raspuns intr-un timp scurt cererii.";
		break;
		default:
			msg += "\n" + textStatus;
		break;
	}
	
	alert(msg);
}

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function parseXML(xml)
{
	if (jQuery.browser.msie) {
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.loadXML(xml);
		xml = xmlDoc;
	}
	return xml;
}

function displayMessage (msg) {
	$('#messagedlg')
		.html(msg)
		.dialog({
			title: 'Info',
			buttons: {
				'OK': function() {
					$(this).dialog('close');
				}
			},
			width: 'auto',
			height: 'auto',
			modal: true,
			resizable: false
		});
}

function displayError(msg) {
	$('#errordlg')
		.html(msg)
		.dialog({
			title: 'Eroare',
			buttons: {
				'OK': function() {
					$(this).dialog('close');
				}
			},
			width: 'auto',
			height: 'auto',
			modal: true,
			resizable: false
		});
}

function redirect(url) {
	window.location = ajaxroot + url;
}

$.fn.clearForm = function() {
	// iterate each matching form
	return this.each(function() {
		// iterate the elements within the form
		$(':input', this).each(function() {
			var type = this.type, tag = this.tagName.toLowerCase();
			if (type == 'text' || type == 'password' || tag == 'textarea')
				this.value = '';
			else if (type == 'checkbox' || type == 'radio')
				this.checked = false;
			else if (tag == 'select')
				this.selectedIndex = -1;
		});
	});
};

function showGoogleMaps (element, latitude, longitude) {
	var myLatlng = new google.maps.LatLng(latitude, longitude);
	var myOptions = {
		zoom : 16,
		center : myLatlng,
		mapTypeId : google.maps.MapTypeId.ROADMAP
	};
	var gmap = new google.maps.Map($(element)[0], myOptions);

	var markerposition = new google.maps.LatLng(latitude, longitude);
	marker = new google.maps.Marker({
		map : gmap,
		title : 'Student Print\nstr. Mihail Moxa, nr. 20',
		position : markerposition,
		draggable : false
	});
}

function displayNotification (position, duration, msg) {
	arr = position.split(' ');
	var left = arr[1];
	var top = arr[0];
	
	var el = $('<div id="customNotification">' + msg + '</div>');
	$('body').append(el);
	el.css({
		'display': 'none',
		'position': 'absolute',
		'width': 'auto',
		'height': 'auto',
		'padding': '10px',
		'color': '#fff',
		'z-index': '30000'
	});
	if (navigator.appName == 'Microsoft Internet Explorer') {
		el.css({'background-color': '#000'});
	} else {
		el.css({'background-color': 'rgba(0, 0, 0, 0.7)'});
	}
	el.addClass('ui-corner-all');
	
	switch (left) {
		case 'left':
			el.css({'left': '20px'});
		break;
		case 'center':
			var margin = Math.round(el.width() / 2);
			el.css({'left': '50%', 'margin-left': '-' + margin + 'px'});
		break;
		case 'right':
			el.css({'right': '20px'});
		break;
	}
	
	switch (top) {
		case 'top':
			el.css({'top': '20px'});
		break;
		case 'middle':
			var margin = Math.round(el.height() / 2);
			el.css({'top': '50%', 'margin-top': '-' + margin + 'px'});
		break;
		case 'bottom':
			el.css({'bottom': '20px'});
		break;
	}
	
	el.fadeIn('slow');
	setTimeout('hideNotification()', duration);
}

function hideNotification () {
	var el = $('#customNotification');
	el.fadeOut('slow');
	el.remove();
}
