//helper
//this remove the img layout and add a <p> in the parent <div>
function OnErrorDontShowBrockenLinkForImg(object,lang) 
{
	object.parentNode.appendChild(document.createTextNode(lang));
	object.style.display = 'none';
}

function goTo(url){
	window.location.href = url;
}

function empty(val){
	if(val == null || val == undefined)
		return true;
		
	switch(typeof val){
		case 'string':
			if(val.length != 0)
				return false;
			break;
		case 'number':
			if(val != 0)
				return false;
			break;
		case 'boolean':
			if(val == true)
				return false;
			break;
		case 'object':
			var hasProps = false;
			for(var i in val) { hasProps = true; }
			if(hasProps){
				if(val['length'] != 0)
					return false;
			}
			break;
		default:
			return false;
			break;
	}
	return true;
}

function showId(elId, speed){
	$("#"+elId).show(speed);
}

function S4() {
   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}

function uniqid(){
	return S4()+S4()+S4();
}

function popupWindow(url, width, height, toolbar, status){
	var toolbar = empty(toolbar) 	? 0 : 1;
	var status 	= empty(status) 	? 0 : 1;
	var width 	= empty(width) 		? 1024 : width;
	var height 	= empty(height) 	? 768 : height;
	return window.open(url,'','scrollbars=1,resizable=1,toolbar='+toolbar+',status='+status+',width='+width+',height='+height);
}

function moveToOffset(options, wkmsTop, wkmsLeft, otherTop, otherLeft){
	if($.browser.msie || $.browser.webkit){
		options.left += wkmsLeft;
		options.top += wkmsTop;
	}else{
		options.left += otherLeft;
		options.top += otherTop;
	}
	return options;
}

(function($) {
    /* use jQuery as container for more convenience */
    $.popunder = function(sUrl) {
        var _parent = self;
    var bPopunder = ($.browser.msie && parseInt($.browser.version, 10) < 9);

    if (top != self) {
        try {
            if (top.document.location.toString()) {
                _parent = top;
            }
        }
        catch(err) { }
    }

    /* popunder options */
    var sOptions = 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=' + (screen.availWidth - 10).toString();
    sOptions += ',height=' + (screen.availHeight - 122).toString() + ',screenX=0,screenY=0,left=0,top=0';

    /* create pop-up from parent context */
    var popunder = _parent.window.open(sUrl, 'pu_' + Math.floor(89999999*Math.random()+10000000), sOptions);
        if (popunder) {
            popunder.blur();
            if (bPopunder) {
                /* classic popunder, used for old ie*/
                window.focus();
                try { opener.window.focus(); }
                catch (err) { }
            }
            else {
                /* popunder for e.g. ff4+, chrome, ie9 */
                popunder.init = function(e) {
                    with (e) {
                        (function() {
                            if (typeof window.mozPaintCount != 'undefined') {
                                var x = window.open('about:blank');
                                x.close();
                            }

                            try { opener.window.focus(); }
                            catch (err) { }
                        })();
                    }
                };
                popunder.params = {
                    url: sUrl
                };
                popunder.init(popunder);
            }
        }
        
        return this;
    }
})(jQuery);

