var WebTicket = new function() {
    var appName = "WebTicket";
    var rootPath = "/" + appName;
    var serviceBase = "Services";
    var productService = "products.ashx";
    var browseService = "browse.ashx";
	var searchService = "search.ashx";
	var usersService = "users.ashx";
	var accountService = "account.ashx";
	var displaySolutionUrl = "/ProductSupport/solution.aspx";
	var productSupport = "/ProductSupport";
	var answers = "/answers";
	
    return {
        
		getAppName: function() { return appName; },
		
		getProductServiceUrl: function() {
			var currentPath = window.location.pathname;
			var currentPathParts = currentPath.split("/");
			var path = "";
			if(currentPathParts[1] == WebTicket.getAppName()) {
				for(var i = 2;i < currentPathParts.length;i++) {
					var c = currentPathParts[i];
					if(!c.match(/aspx/)) {
						path += "../";
					}
				}
			}	
			return path + serviceBase + "/" + productService;
		},
		
		getBrowseServiceUrl: function() {
			var currentPath = window.location.pathname;
			var currentPathParts = currentPath.split("/");
			var path = "";
			if(currentPathParts[1] == WebTicket.getAppName()) {
				for(var i = 2;i < currentPathParts.length;i++) {
					var c = currentPathParts[i];
					if(!c.match(/aspx/)) {
						path += "../";
					}
				}
			}
			return path + serviceBase + "/" + browseService;
		},
		
		getSearchServiceUrl: function() {
			var currentPath = window.location.pathname;
			var currentPathParts = currentPath.split("/");
			var path = "";
			if(currentPathParts[1] == WebTicket.getAppName()) {
				for(var i = 2;i < currentPathParts.length;i++) {
					var c = currentPathParts[i];
					if(!c.match(/aspx/)) {
						path += "../";
					}
				}
			}
			return path + serviceBase + "/" + searchService;
		},
		
		getUsersServiceUrl: function() {
			var currentPath = window.location.pathname;
			var currentPathParts = currentPath.split("/");
			var path = "";
			if(currentPathParts[1] == WebTicket.getAppName()) {
				for(var i = 2;i < currentPathParts.length;i++) {
					var c = currentPathParts[i];
					if(!c.match(/aspx/)) {
						path += "../";
					}
				}
			}
			return path + serviceBase + "/" + usersService;
		},
		
		getAccountServiceUrl: function() {
			var currentPath = window.location.pathname;
			var currentPathParts = currentPath.split("/");
			var path = "";
			if(currentPathParts[1] == WebTicket.getAppName()) {
				for(var i = 2;i < currentPathParts.length;i++) {
					var c = currentPathParts[i];
					if(!c.match(/aspx/)) {
						path += "../";
					}
				}
			}
			return path + serviceBase + "/" + accountService;
		},
		
		getSolutionUrl: function(solutionId) {
		    return displaySolutionUrl + "?id=" + solutionId;
		},
		
		getProductSupportUrl: function() {
		    return productSupport;
		},
		
        getAnswersUrl: function() {
            return answers;
        },
		
		validateEmailFormat: function(e, name) {
		    var regExpression = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/;
			var emailRegEx = new RegExp(regExpression);
			if( !( emailRegEx.test($(e).val()) ) ) {
			    if( $("#validateMsg") != undefined ) {
				    $("#validateMsg").append("<p><strong>" + name + "</strong> field must be in e-mail format eg. user@wolterskluwer.com.</p>");
				}
				return false;
			} else {
				return true;
			}
		},
		
		validateLength : function(e,n,min,max) {
			if($(e).val().length > max || $(e).val() < min) {
				$("#validate").html("<strong>" + n + "</strong> field must be between " + min + " and " + max + "characters long.");	
				return false;
			} else {
				return true;
			}
		}
    };
}();

