var sessionName, sessionId;
var mailboxQuerysInterval;
var closeMessageBoxesInterval;
var webRoot,langCode;
var booUseAjax = true;
var booShowAds = true;
var strContent = '';

/**
 * Cookie function
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/**
 * Set special values for using in javascript
 */
function setValues(arrValues) {
    // Session
    sessionName = arrValues[0];
    sessionId = arrValues[1];
    // Path        
    webRoot = arrValues[2];
    // Language
    langCode = arrValues[3];
    // Content
    strContent = arrValues[4];
    // Ads
    booShowAds = arrValues[5];
}

/**
 * When document full loaded and ready
 */
$(document).ready(function() {
    // Hide login formular and slide in
    $('#divLogin').show(1, function() {
        $('#divLogin').css('top', '-110px');
        $('#divLogin').animate({'top': '0px'}, 'slow');    
    });
    // Refresh overview of mailbox querys every 30 seconds
    mailboxQuerysInterval = window.setInterval('reloadMailboxQuerys()',30000);
    // Close message boxes after 5 seconbds
    //closeMessageBoxes();
    // Set copy and paste field for the generated address 
    setGeneratedAddress();
    // Check cookies
    if (!checkCookies()) {
        showSystemError('Cookies müssen aktivert sein, um auf spambog.com navigieren zu können!<br />You need cookies to navigate on spambog.com!')
    }    
    // Set ajax support
    if ($.cookie("ajaxSupport")) {  
        if ($.cookie("ajaxSupport") == 'false') {
            booUseAjax = false;  
            $('#booAjaxSupport').removeAttr('checked');
        }
    }
 	$('[rel=external]').each(function() {
  		$(this).attr('target','_blank');
  	});           
});

/**
 * Unload
 */
/*
$(document).unload(function() {
    popDown('http://www.profiseller.de/shop1/index.php3?ps_id=p26088309',1020,800);
});
*/

/**
 * Show footer error message
 */
function showSystemError(strMessage) {
    if ($('#divSysError').length > 0) {
        $('#divSysError').html(strMessage);
        $('#divSysError').fadeIn('slow');    
    }            
}

/**
 * Close message boxes automaticly
 */
function closeMessageBoxes() {
    // Close message boxes after 5 seconds
    window.setTimeout(function() {
        if ($('#boxMessageOk').length > 0) {
            $('#boxMessageOk').slideUp('slow',function() { $('#boxMessageOk').remove(); })    
        }
    },5000); 
}

/**
 * Loading information
 */
function isLoaded(isActive) {
    if ($('#divLoading').length == 0) {
        $('body').append('<div id="divLoading">&nbsp;</div>');
        var arrPosition = $('#divContent').offset();
        $('#divLoading').css('position','absolute');
        $('#divLoading').css('left','50%');
        $('#divLoading').css('top','200px');
    }
    if (isActive) {
        $('#divLoading').css('display','block');    
    } else {    
        $('#divLoading').fadeOut('slow');
    }    
}

/**
 * Set Messages box
 */
function setMessage(strType,strMessage,strTarget,intDelay) {
    if (strType == 'ok') strBoxId = 'boxMessageOk'
    if (strType == 'error') strBoxId = 'boxMessageError';
    if ($('#'+strBoxId).length == 0) {
        $(strTarget).prepend('<div id="'+strBoxId+'"></div>');
    } else {
        $('#'+strBoxId).css('display','block');    
    }
    $('#'+strBoxId).html(strMessage);
    window.setTimeout(function() {
        $('#'+strBoxId).slideUp('slow'); 
    },intDelay);     
}

/**
 * Set document title
 */
function setDocumentTitle(strTitle) {
    if (!booUseAjax) {
        return;
    }
    document.title = strTitle;    
} 

/**
 * Set copy and paste field for the generated address
 */
function setGeneratedAddress() {
    if (($('#divMenuGenerate').css('display') != 'block') && $('#strLoginUsername').val()) {
        $('#divMenuGenerate').fadeIn('slow');    
    }
    if ($('#strGeneratedAddress').length && $('#strLoginUsername').length && $('#intLoginDomainId').length) {
        strAddress = $('#strLoginUsername').val()+'@'+$('#intLoginDomainId option:selected').text();
        if (strAddress.match(/ \(PW\)/gi)) {
            $('#divPasswordInput').fadeIn('normal');
        } else {
            $('#divPasswordInput').fadeOut('normal');
        }
        strAddress = strAddress.replace(/ \(PW\)/,'');
        $('#strGeneratedAddress').val(strAddress);
    }    
    
}

/**
 * Generate a random email alias
 */
function getRandomAddress() {
	var arrCo      = new Array("b","c","d","f","g","h","j","k","l","m","n","p","r","s","t","v","w","x","y","z","1","2","3","4","5","6","7","8","9");
 	var arrVo      = new Array("a","e","i","o","u");
 	var intC,intV;
    var strRetVal  = '';
 	for (var i=0; i<5; i++) {
        intC = Math.ceil(Math.random() * 1000) % 20;
        intV = Math.ceil(Math.random() * 1000) % 5;
        strRetVal+= arrCo[intC] + arrVo[intV];
	}
    $('#strLoginUsername').val(strRetVal); 
    setGeneratedAddress();
}

/**
 * Open file in div
 */
function loadFile(strType,strUrl,strTarget,strData,strInsertWhere,$booWithoutLoading) {
    if ($(strTarget).length > 0) {
        if (strUrl.match(/\?/i)) {
            strUrl+= '&ajaxRequest=true';
        } else {
            strUrl+= '?ajaxRequest=true';
        }
        if (!$booWithoutLoading) isLoaded(true);
        $('#divSysError').fadeOut('fast');          
        $.ajax({
            type: strType,
            timeout: 10000,
            async: false,
            url: strUrl,
            data: strData,
            success: function(data) {
                if (strInsertWhere == 'append') {
                    $(strTarget).append(data);    
                } else if (strInsertWhere == 'prepend') {
                    $(strTarget).prepend(data);    
                } else {
                    $(strTarget).html(data);
                }
                if (!$booWithoutLoading) isLoaded(false);
                if (strUrl.match(/content\/inbox/) || strUrl.match(/content\/message/)) {
                    $('#divLogin').animate({'top': '-110px'}, 'slow', function() {
                        if (booShowAds) {
                            $('#divHeaderBanner').fadeIn('slow');    
                        }                    
                    });
                }
                if (strUrl.match(/content\/home/) || strUrl.match(/content\/home/)) {
                    $('#divHeaderBanner').fadeOut('normal',function() {
                        $('#divLogin').animate({'top': '0px'}, 'slow');
                    });
                }     
                //pageTracker._trackPageview(strUrl);  
             	$('[rel=external]').each(function() {
              		$(this).attr('target','_blank');
              	});  
                return true;
            },
            error: function(data,errorText,errorCode) {
                showSystemError('Error on loading: '+errorText+' ('+errorCode+') - PLEASE TRY AGAIN!');
                if (!$booWithoutLoading) isLoaded(false);
                return false;
            }                
        });
    }
    return true;
}

/**
 * Open sites 
 */
function openSite(strSite) {
    if (!booUseAjax) {
        return true;
    }    
    if (!loadFile('POST',webRoot+'content/'+strSite+'.inc.php','#divContent',sessionName+'='+sessionId)) {
        return true;
    }   
    return false;
}

/**
 * Submit login form
 */
function login_submitForm(objForm) {
    if (!booUseAjax) {
        return true;
    }
    // Set info for using ajax
    $(objForm).find("input:hidden[name='ajaxRequest']").val('true');
    // Submit form
    isLoaded(true);
    $.post($(objForm).attr('action'),$(objForm).serialize(),function (data) {
        // If login ok
        if (data == 'LOGIN OK') {
            // Include inbox
            if (!loadFile('POST',webRoot+'content/inbox.inc.php','#divContent',$(objForm).serialize())) {
                return true;
            }
            // Include menu
            if (!loadFile('POST',webRoot+'content/menu.inc.php','#divMenu',$(objForm).serialize())) {            
                return true;
            }
            // Show ad box
            if (booShowAds) {
                $('#divMenuAds').css('display','block');
                //$('#divMenuAds iframe').attr('src',$('#divMenuAds iframe').attr('src'));
                $('#divMenuAds iframe').attr('src',webRoot+'/api/banner.php?adSize=125x125');                
            }
        } else {
            data = data.substring(12,data.length);
            setMessage('error',data,'#divContent',5000);           
            isLoaded(false);
            return true;
        }
    });
    return false;   
}

/**
 * Reload overview of mailbox querys
 */
function reloadMailboxQuerys() {
    if (!booUseAjax) {
        return true;
    }    
    if (!loadFile('POST',webRoot+'content/menuQuerys.inc.php','#divMailboxQuerys',sessionName+'='+sessionId,'',true)) {
        return true;
    }       
    return false;
}

/**
 * Reload inbox
 */
function inbox_open() {
    if (!booUseAjax) {
        return true;
    }
    // Load inbox
    if (!loadFile('POST',webRoot+'content/inbox.inc.php','#divContent','&content=inbox&'+sessionName+'='+sessionId)) {
        return true;
    }
    // Load inbox menu
    if ($('#divMenuInbox').length == 0) {    
        if (!loadFile('POST',webRoot+'content/menuInbox.inc.php','#divMenu','&content=inbox&'+sessionName+'='+sessionId,'prepend')) {
            return true;
        }
    }       
    // Remove message menu
    if ($('#divMenuMessage').length > 0) {
        $('#divMenuMessage').remove();
    }    
    // Show ad box
    if (booShowAds) {
        $('#divMenuAds').css('display','block');
        $('#divMenuAds iframe').attr('src',$('#divMenuAds iframe').attr('src'));
    }
    // Scroll to top
    window.scrollTo(0,0);    
    return false;    
}

/**
 * Select all/read/unread/none in inbox
 */
function inbox_selectMessages(type) {
    $("input[name='chkMessage[]']").each(function(index) {
        if (type == 'all') {
            $(this).attr('checked','checked');
        }
        if (type == 'none') {
            $(this).attr('checked','');
        }
        if (type == 'read') {
            if ($(this).attr('rel') == 'read') {
                $(this).attr('checked','checked');
            }
            if ($(this).attr('rel') == 'unread') {
                $(this).attr('checked','');
            }
        }
        if (type == 'unread') {
            if ($(this).attr('rel') == 'unread') {
                $(this).attr('checked','checked');
            }
            if ($(this).attr('rel') == 'read') {
                $(this).attr('checked','');
            }
        }
  });
}

/**
 * Submit inbox operation form
 */
function inbox_submitOperation(objForm) {    
    if (!booUseAjax) {
        return true;
    }    
    // Set info for using ajax
    $(objForm).find("input:hidden[name='ajaxRequest']").val('true');
    // Submit form
    isLoaded(true);
    $.post($(objForm).attr('action'),$(objForm).serialize(),function (data) {
        // If login ok
        if (data == 'LOGIN OK') {
            // Include inbox
            if (!loadFile('POST',webRoot+'content/inbox.inc.php','#divContent',$(objForm).serialize())) {
                return true;    
            }
        } else {
            data = data.substring(12,data.length);
            setMessage('error',data,'#divContent',5000);
            return true;                       
        }
    });
    isLoaded(false);    
    return false;          
}

/**
 * Open password settings
 */
function inbox_setPassword() {
    if (!booUseAjax) {
        return true;
    }      
    // Load inbox
    if (!loadFile('POST',webRoot+'content/password.inc.php','#divContent','&content=password&'+sessionName+'='+sessionId)) {
        return true;
    }
    // Load inbox menu
    if ($('#divMenuInbox').length == 0) {    
        if (!loadFile('POST',webRoot+'content/menuInbox.inc.php','#divMenu','&content=inbox&'+sessionName+'='+sessionId,'prepend')) {
            return true;
        }
    }           
    return false;     
}

/**
 * Submit password form
 */
function inbox_submitPassword(objForm) {
    if (!booUseAjax) {
        return true;
    }
    isLoaded(true);
    // Set info for using ajax
    $(objForm).find("input:hidden[name='ajaxRequest']").val('true');
    if (!loadFile('POST',webRoot+'content/password.inc.php','#divContent',$(objForm).serialize()+'&btnSetPassword=true&'+sessionName+'='+sessionId)) {
        return true;    
    }
    // Load inbox menu
    if ($('#divMenuInbox').length > 0) {    
        $('#divMenuInbox').remove();
    }           
    if (!loadFile('POST',webRoot+'content/menuInbox.inc.php','#divMenu','&content=inbox&'+sessionName+'='+sessionId,'prepend')) {
        return true;
    }
    isLoaded(false);       
    closeMessageBoxes();         
    return false;     
}

/**
 * Remove inbox password
 */
function inbox_removePassword(strPassword) {
    if (!booUseAjax) {
        return true;
    }      
    // Load inbox
    if (!loadFile('POST',webRoot+'content/inbox.inc.php','#divContent','&content=inbox&removePassword='+strPassword+'&'+sessionName+'='+sessionId)) {
        return true;
    }
    // Load inbox menu
    if ($('#divMenuInbox').length > 0) {    
        $('#divMenuInbox').remove();
    }           
    if (!loadFile('POST',webRoot+'content/menuInbox.inc.php','#divMenu','&content=inbox&'+sessionName+'='+sessionId,'prepend')) {
        return true;
    }
    return false;     
}


/**
 * Open message
 */
function message_open(openMessage,emailIdHash) {
    if (!booUseAjax) {
        return true;
    }
    // Load message
    if (!loadFile('POST',webRoot+'content/message.inc.php','#divContent','&content=message&openMessage='+openMessage+'&emailIdHash='+emailIdHash+'&'+sessionName+'='+sessionId)) {
        return true;
    }
    // Load message menu
    if ($('#divMenuMessage').length == 0) {       
        if (!loadFile('POST',webRoot+'content/menuMessage.inc.php','#divMenu','&content=message&openMessage='+openMessage+'&emailIdHash='+emailIdHash+'&'+sessionName+'='+sessionId,'prepend')) {
            return true;
        }
    }       
    // Remove inbox menu
    if ($('#divMenuInbox').length > 0) {
        $('#divMenuInbox').remove();
    }
    // Show ad box
    if (booShowAds) {    
        $('#divMenuAds').css('display','block');
        $('#divMenuAds iframe').attr('src',$('#divMenuAds iframe').attr('src'));
    }
    // Scroll to top
    window.scrollTo(0,0);
    // Open popDown
    if (booShowAds) {    
        if ($.browser.msie || $.browser.mozilla) {
            popDown('http://www.profiseller.de/shop1/index.php3?ps_id=p26088309',1020,800);
        }
    }    
    return false;    
}

/**
 * Remove message
 */
function message_remove(inboxId,emailIdHash) {
    if (!booUseAjax) {
        return true;
    }    
    // Load inbox
    if (!loadFile('POST',webRoot+'content/inbox.inc.php','#divContent','&content=inbox&remove='+inboxId+'&emailIdHash='+emailIdHash+'&'+sessionName+'='+sessionId)) {
        return true;
    }
    // Load inbox menu
    if ($('#divMenuInbox').length == 0) {    
        loadFile('POST',webRoot+'content/menuInbox.inc.php','#divMenu','&content=inbox&'+sessionName+'='+sessionId,'prepend');
    }       
    // Remove message menu
    if ($('#divMenuMessage').length > 0) {
        $('#divMenuMessage').remove();
    }
    // Close message box
    closeMessageBoxes();
    return false;
}

/**
 * Go to next message
 */
function message_next(openMessage,emailIdHash) {
    if (!booUseAjax) {
        strUrl = webRoot+langCode+'/message/view-'+openMessage+'-'+emailIdHash+'.htm';
        //strUrl = strUrl.replace(/NaN\/message\//g,strUrl);
        window.location.href = strUrl;
        return true;
    } else {
        return message_open(openMessage,emailIdHash)
    }
}

/**
 * Go to previous message
 */
function message_prev(openMessage,emailIdHash) {
    if (!booUseAjax) {
        strUrl = webRoot+langCode+'/message/view-'+openMessage+'-'+emailIdHash+'.htm';
        //strUrl = strUrl.replace(/NaN\/message\//g,strUrl);
        window.location.href = strUrl;
        return true;
    } else {
        return message_open(openMessage,emailIdHash)
    }
}

/**
 * Switch message between plainText and html
 */
function message_viewType(strType) {
    if (strType == 'plain') {
        $('#messageNavigationPlain a').attr('id','current');        
        $('#messageNavigationHtml a').attr('id','');        
        $('#divPlainMessage').css('display','block');
        $('#divHTMLMessage').css('display','none');
    } else {
        $('#messageNavigationHtml a').attr('id','current');        
        $('#messageNavigationPlain a').attr('id','');        
        $('#divHTMLMessage').css('display','block');
        $('#divPlainMessage').css('display','none');
    }
    return false;
}

/**
 * Show message header
 */
function message_showInfos(strTargetIframe,strIPParameter) {
    if ($('#divMessageInfos').css('display') != 'block') {
        $('#divMessageInfos').css('display','block');
        if ($(strTargetIframe).css('display') != 'block') {
            $(strTargetIframe).attr('src',webRoot+'content/messageInfo.inc.php?arrIPs='+strIPParameter+'&'+sessionName+'='+sessionId);
            $(strTargetIframe).css('display','block'); 
        }    
    } else {
        $('#divMessageInfos').css('display','none');    
    }
}

/**
 * Print message
 */
function message_print(booEnable) {
    if (booEnable==1) {
        $('#divMain').css('display','none'); 
        $('#divPrint').css('display','block');
        $('#divPrintContent').append($('#divMessageHeader').html());
        if ($('#divPlainMessage').css('display') == 'block') {
            $('#divPrintContent').append('<br /><br />'+$('#divPlainMessage').html());
            $("#divPrintContent table").css('width','100%');
            $("#divPrintContent h1").css('margin','0');
        } 
        if ($('#divHTMLMessage').css('display') == 'block') {
            $('#divPrintContent').append('<br /><br />'+$("#iframeHtmlMessage").contents().find("body").html());
            $("#divPrintContent table").css('width','100%');
            $("#divPrintContent h1").css('margin','0');
        }         
    } else {
        $('#divPrint').css('display','none');
        $('#divMain').css('display','block'); 
        $('#divPrintContent').html('');
    } 
    return false;        
}

/**
 * Open message reply
 */
function message_reply(openMessage,emailIdHash) {
    if (!booUseAjax) {
        return true;
    }
    // Load message
    if (!loadFile('GET',webRoot+'content/message.inc.php','#divContent','&content=message&openMessage='+openMessage+'&reply='+openMessage+'&emailIdHash='+emailIdHash+'&'+sessionName+'='+sessionId)) {
        return true;
    }
    return false;    
}

/**
 * Send message reply
 */
function message_replySubmit(objForm) {
    if (!booUseAjax) {
        return true;
    }    
    // Set info for using ajax
    $(objForm).find("input:hidden[name='ajaxRequest']").val('true');
    // Submit form
    isLoaded(true);
    if (!loadFile('POST',webRoot+'content/message.inc.php','#divContent',$(objForm).serialize()+'&btnSendReply=true')) {
        return true;    
    }
    isLoaded(false);
    closeMessageBoxes();         
    return false;        
}

/**
 * Open message forward
 */
function message_forward(openMessage,emailIdHash) {
    if (!booUseAjax) {
        return true;
    }
    // Load message
    if (!loadFile('GET',webRoot+'content/message.inc.php','#divContent','&content=message&openMessage='+openMessage+'&forward='+openMessage+'&emailIdHash='+emailIdHash+'&'+sessionName+'='+sessionId)) {
        return true;
    }
    return false;    
}
 
/**
 * Send message forward
 */ 
function message_forwardSubmit(objForm) {
    if (!booUseAjax) {
        return true;
    }    
    // Set info for using ajax
    $(objForm).find("input:hidden[name='ajaxRequest']").val('true');
    // Submit form
    isLoaded(true);
    if (!loadFile('POST',webRoot+'content/message.inc.php','#divContent',$(objForm).serialize()+'&btnSendForward=true')) {
        return true;    
    }
    isLoaded(false);
    closeMessageBoxes();         
    return false;        
}

/**
 * Send "delivery failed" message
 */ 
function message_deliveryFailed(openMessage,emailIdHash) {
    if (!booUseAjax) {
        return true;
    }
    // Load message
    if (!loadFile('GET',webRoot+'content/message.inc.php','#divContent','&content=message&openMessage='+openMessage+'&deliveryfailed='+openMessage+'&emailIdHash='+emailIdHash+'&'+sessionName+'='+sessionId)) {
        return true;
    }
    return false;    
}

/**
 * Add message to spamlist
 */ 
function message_addToSpamlist(openMessage,emailIdHash) {
    if (!booUseAjax) {
        return true;
    }
    // Load message
    if (!loadFile('GET',webRoot+'content/message.inc.php','#divContent','&content=message&addMessageToSpamlist='+openMessage+'&openMessage='+openMessage+'&emailIdHash='+emailIdHash+'&'+sessionName+'='+sessionId)) {
        return true;
    }
    return false;    
}


/**
 * Open spam list
 */ 
function spamlist_open() {
    if (!booUseAjax) {
        return true;
    }
    // Load inbox
    if (!loadFile('POST',webRoot+'content/spamlist.inc.php','#divContent','&content=spamlist&'+sessionName+'='+sessionId)) {
        return true;
    }
    // Load inbox menu
    if ($('#divMenuInbox').length == 0) {    
        if (!loadFile('POST',webRoot+'content/menuInbox.inc.php','#divMenu','&content=inbox&'+sessionName+'='+sessionId,'prepend')) {
            return true;
        }
    }       
    // Remove message menu
    if ($('#divMenuMessage').length > 0) {
        $('#divMenuMessage').remove();
    }
    return false;    
}

/**
 * Add value to spam list
 */ 
function spamlist_addValue(objForm) {
    if (!booUseAjax) {
        return true;
    }
    // Set info for using ajax
    $(objForm).find("input:hidden[name='ajaxRequest']").val('true');
    // Submit form
    isLoaded(true);
    if (!loadFile('POST',webRoot+'content/spamlist.inc.php','#divContent',$(objForm).serialize())) {
        return true;    
    }
    isLoaded(false);
    closeMessageBoxes();         
    return false;        
}

/**
 * Add value to spam list
 */ 
function spamlist_removeValue(removeValue) {
    if (!booUseAjax) {
        return true;
    }
    // Load inbox
    if (!loadFile('POST',webRoot+'content/spamlist.inc.php','#divContent','&content=spamlist&removeValue='+removeValue+'&'+sessionName+'='+sessionId)) {
        return true;
    }
    isLoaded(false);
    closeMessageBoxes();         
    return false;        
}

/**
 * Open bookmark info
 */ 
function bookmark_open() {
    if (!booUseAjax) {
        return true;
    }
    // Load inbox
    if (!loadFile('POST',webRoot+'content/bookmark.inc.php','#divContent','&content=bookmark&'+sessionName+'='+sessionId)) {
        return true;
    }
    // Load inbox menu
    if ($('#divMenuInbox').length == 0) {    
        if (!loadFile('POST',webRoot+'content/menuInbox.inc.php','#divMenu','&content=inbox&'+sessionName+'='+sessionId,'prepend')) {
            return true;
        }
    }       
    // Remove message menu
    if ($('#divMenuMessage').length > 0) {
        $('#divMenuMessage').remove();
    }
    return false;    
}

/**
 * Insert text at the current cursor position
 */ 
$.fn.extend({
    insertAtCaret: function(myValue){
    		if (document.selection) {
        this.focus();
        sel = document.selection.createRange();
        sel.text = myValue;
        this.focus();
    		}
      else if (this.selectionStart || this.selectionStart == '0') {
        var startPos = this.selectionStart;
        var endPos = this.selectionEnd;
        var scrollTop = this.scrollTop;
        this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length);
        this.focus();
        this.selectionStart = startPos + myValue.length;
        this.selectionEnd = startPos + myValue.length;
        this.scrollTop = scrollTop;
      } else {
        this.value += myValue;
        this.focus();
      }
    }
})


/**
 * Translate text from a input field to a other
 */ 
function language_translateInput(strFromLanguage,strToLanguage,strFromInputId,strToInputId) {
    var strText = $('#'+strFromInputId).val();

    var tmpInputFrom = document.getElementById(strFromInputId);
    var intInputFromLen = tmpInputFrom.value.length;
    var intInputFromStart = tmpInputFrom.selectionStart;
    var intInputFromEnd = tmpInputFrom.selectionEnd;
    var strSelectedText = tmpInputFrom.value.substring(intInputFromStart, intInputFromEnd);
    if (strSelectedText) {
        strText = strSelectedText;
    }
    if (strText) {
        google.language.translate(strText,strFromLanguage,strToLanguage, function(result) {
            $('#'+strToInputId).val($('#'+strToInputId).val()+result.translation);
        });
    }    
}

/**
 * Submit contact form
 */
function contact_submitForm(objForm) {    
    if (!booUseAjax) {
        return true;
    }    
    // Set info for using ajax
    $(objForm).find("input:hidden[name='ajaxRequest']").val('true');
    // Submit form
    isLoaded(true);
    if (!loadFile('POST',webRoot+'content/contact.inc.php','#divContent',$(objForm).serialize()+'&btnSend=true')) {
        return true;    
    }
    isLoaded(false);
    closeMessageBoxes();         
    return false;       
}

/**
 * Check cookie using
 */
function checkCookies() {
	// Cookie setzen
	var datetime = new Date();
	datetime = new Date(datetime.getTime()+1000*60*60*24);
	document.cookie = 'testCookies=true; expires='+datetime.toGMTString()+';'; 
	// Cookie lesen
	var cookie = document.cookie;
	cookiename = cookie.substr(0,cookie.search('='));
	cookiewert = cookie.substr(cookie.search('=')+1,cookie.search(';'));
	if(cookiewert == '') {
		cookiewert = cookie.substr(cookie.search('=')+1,cookie.length);
	} 	
	if (cookiewert) {
		return true;
    }
	return false;
}

/**
 * Enable/Disable ajax support
 */
function ajaxSupport(booAjaxSupport) {
    if ($('#booAjaxSupport').attr('checked') == false) {
        booUseAjax = false;
        $.cookie("ajaxSupport", 'false', { expires: 7 });                
    } else {
        booUseAjax = true;        
        $.cookie("ajaxSupport", 'true', { expires: 7 });                
    }
}

/**
 * PopDown
 */
function popDown(strUrl,intWidth,intHeight) {
    if (!$.cookie("popupBlock")) {
        // Set cookie
        $.cookie("popupBlock", 'true', { expires: 0.04 });                

    	intLeft = (screen.width) ? (screen.width-intWidth)/2 : 100;
        intTop  = (screen.height) ? (screen.height-intHeight)/2 : 100;
    	strParameter = 'width='+intWidth+',height='+intHeight+',top='+intTop+',left='+intLeft+',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,dependent=no';
    	objWindow = window.open(strUrl,'',strParameter);
    	objWindow.blur();
    }    
 
}