var common = new Object();

/*
	TODO: On all click events, try to get rid of all dotted markings !!
*/
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }

common.miscServiceUrl = '/Templates/ElitfonsterWebV2/WebServices/MiscServices.asmx';
common.ajaxTimout = 40000;
common.gmapsImagesUrl = '/Templates/ElitfonsterWebV2/_images/design/gmaps/';
common.flashExpressInstallUrl = '/Templates/ElitfonsterWebV2/_flash/expressInstall.swf';

// create a cookie, only needs to supply name and value
common.setCookie = function(name, value, days, path, domain, secure) {
    var date;
    if(days) {
		date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
    }
    var curCookie = name + "=" + escape(value) +
					((date) ? "; expires=" + date.toGMTString() : "") + //((expires) ? "; expires=" + expires.toGMTString() : "") +
					((path) ? "; path=" + path : "; path=/") +
					((domain) ? "; domain=" + domain : "") +
					((secure) ? "; secure" : "");
    document.cookie = curCookie;
}
// get a cookie-value by its name, returns null if the name isnt found
common.getCookieValue = function(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    
    if (end == -1) end = dc.length;

    return unescape(dc.substring(begin + prefix.length, end));
}
common.removeCookie = function(name) {
    common.setCookie(name, '', -1);
}
common.isValue = function(v) {
    var bIsNotValue = (v == null || v == 'null' || (v == "") || (v == undefined || v == 'undefined'));
    return !bIsNotValue;
}
//common.setupSearchInput = function(objBox) {
//    objBox.attr('value', DEFAULT_FINDER_TEXT);
//    objBox
//	.bind('focus', function() {
//	    if ($(this).attr('value') == DEFAULT_FINDER_TEXT) {
//	        $(this).attr('value', '');
//	    }
//	})
//	.bind('blur', function() {
//	    if ($(this).attr('value') == '') {
//	        $(this).attr('value', DEFAULT_FINDER_TEXT);
//	    }
//	})

//    objBox.parent().parent().children('.btn').bind('click', function() {
//        if (objBox.attr('value') == DEFAULT_FINDER_TEXT) {
//            objBox.attr('value', '');
//        }
//        return true;
//    });
//}

common.openWin = function(e) {
    var strProp = 'toolbar=no,resizable=yes,copyhistory=no,directories=no,menubar=no,' + e.addprop;
    var win;
    if (e.skipprop) {
        win = window.open(e.url, e.name.replace(new RegExp('[^a-z0-9]', 'g'), ''));
    }
    else {
        win = window.open(e.url, e.name.replace(new RegExp('[^a-z0-9]', 'g'), ''), strProp); // seems like the name 'ext-docs' does not work as a windows name, do replace
    }
    win.focus();
    return false;
}

common.params = [];
common.getParamValue = function(strName) {
    if (common.params == null || common.params.length == 0) {
        var e,
	    a = /\+/g,  // Regex for replacing addition symbol with a space 
	    r = /([^&;=]+)=?([^&;]*)/g,
	    d = function(s) { return decodeURIComponent(s.replace(a, " ")); },
	    q = window.location.search.substring(1);

        while (e = r.exec(q)) {
            common.params[d(e[1])] = d(e[2]);
        }
    }
    return common.params[strName];
}

/*
var qsParams = {};
(function() {
    var e,
		a = /\+/g,  // Regex for replacing addition symbol with a space 
		r = /([^&;=]+)=?([^&;]*)/g,
		d = function(s) { return decodeURIComponent(s.replace(a, " ")); },
		q = window.location.search.substring(1);

    while (e = r.exec(q))
        qsParams[d(e[1])] = d(e[2]);
})();	
*/
