var cMain = new function () {
	this.defSearch = "Sök produkt";
	this.defSearchEmpty = "Ange ett sökord";

	this.openWindow = function(url, width, height) {
		window.open(url, "Popup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height + ",top=100,left=100");
	};

    this.searchBehaviour = function(e) {
		if (e.type == "focus") {
			//$(this).parent().find("input.submit").show();
			if ($(this).val() == cMain.defSearch || $(this).val() == cMain.defSearchEmpty) {
				$(this).val("");
			}
			$(this).addClass("active");
		}
		else if (e.type = "blur") {
			if ($(this).val() === "") {
				$(this).val(cMain.defSearch);
			}
			$(this).removeClass("active");
		}
    };

    this.validateSearch = function() {
		var keyword = $(this).find("input.text");

		if (keyword.val() === "" || keyword.val() == cMain.defSearch || keyword.val() == cMain.defSearchEmpty) {
			keyword.val(cMain.defSearchEmpty);
			return false;
		}
    };

	this.toggleOnlyStockItems = function() {
		$("form.sortOptions").submit();
	};
	
	this.changeSortBy = function() {
		$("form.sortOptions").submit();
	};
	
	this.changeSortOrder = function() {
		$("form.sortOptions").submit();
	};
	
	this.scriptTimer = function() {
		this.scriptRunTime = 0;
		this.startTime = 0;
		this.stopTime = 0;

		this.startTimer = function() {
			var time = new Date();
			cMain.scriptTimer.startTime = time.getTime();
		}

		this.stopTimer = function() {
			var time = new Date();
			cMain.scriptTimer.stopTime = time.getTime();
			cMain.scriptTimer.scriptRunTime = (cMain.scriptTimer.stopTime - cMain.scriptTimer.startTime) / 1000;
		}
	};

    this.trim = function(str) {
        return str.replace(new RegExp("^[\\s]+", "g"), "");
    };
}
