function parseUri(sourceUri){
	var uriPartNames = ["source","protocol","authority","domain","port","path","directoryPath","fileName","query","anchor"],
		uriParts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(sourceUri),
		uri = {};	
	for(var i = 0; i < 10; i++){
		uri[uriPartNames[i]] = (uriParts[i] ? uriParts[i] : "");
	}	
	/* Always end directoryPath with a trailing backslash if a path was present in the source URI
	Note that a trailing backslash is NOT automatically inserted within or appended to the "path" key */
	if(uri.directoryPath.length > 0){
		uri.directoryPath = uri.directoryPath.replace(/\/?$/, "/");
	}	
	return uri;
};
function getPar(name) {
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
};

$(function() {
  
  //var ref = 'http://www.gelateria-store.it:8080/';	
  //var url = parseUrl(document.referrer);	
  var ref = unescape(getPar('ref'));  
  var url = parseUri(ref);
	var urlEShop = url.protocol + '://eshop' + url.domain.substring(url.domain.indexOf('.'));	
	//alert('ref:' + ref + ', host:' + url.domain + ', urlEShop:' + urlEShop);	
	
	$.ajax({
		url: urlEShop,
		timout: 5000,
		type: 'GET',
		dataType: 'text',
		crossDomain: true,
		success: function() {
			//alert('success');			
			window.location = urlEShop;
		},
		error: function(jqXHR, textStatus, errorThrown) {
  		//alert('error');
			$('.under_costruction').show();
		}
	});	

});
