﻿function showDarkBackground() {
    $('#divBody').show();
    $('#divBody').css({
        height: $(document).height(),
        width: $(window).width()
    });
}
function hideDarkBackground() {
    $('#divBody').hide();
}
function OnUpdatePanelUpdating() {
    showDarkBackground();
    locateToCenter($('#updateProgressDiv'));
    $('#updateProgressDiv').show();
}
function OnUpdatePanelUpdated() {
    hideDarkBackground();
    $('#updateProgressDiv').hide();
}


function locateToCenter(obj) {
    var width = $('#divBody').width();
    var height = $('#divBody').height();
    var left = (width / 2) - (obj.width() / 2);
    if (left <= 10) {
        left = 10;
    }
    var top = (height / 2) - (obj.height() / 2);
    if (top < 5 || top > 20) {
        top = 5;
    }
    if (obj.height() > $(window).height() - 10) {
        obj.css({ "height": ($(window).height() - 10) + "px" });
    }
    obj.css({ "left": left + "px", "top": top + "px" });
}

function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
        xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
        xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
        xScroll = document.body.scrollLeft;
    }
    return new Array(xScroll, yScroll)
}

// Adapted from getPageSize() by quirksmode.com
function getPageHeight() {
    var windowHeight
    if (self.innerHeight) {	// all except Explorer
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowHeight = document.body.clientHeight;
    }
    return windowHeight
}

//Close button:
$(".close_notification").click(function () {
    $(this).hide();
    $(this).parent().fadeTo('fast', 0, function () {
        $(this).slideUp('fast');
    });
    return false;
});


// Reset Font Size    
var originalFontSize = $('.post-body').css('font-size');

$(".resetFont").click(function () {
    $('.post-body').css('font-size', originalFontSize);
});
// Increase Font Size
$(".increaseFont").click(function () {
    var currentFontSize = $('.post-body').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum * 1.2;
    $('.post-body').css('font-size', newFontSize);
    return false;
});
// Decrease Font Size
$(".decreaseFont").click(function () {
    var currentFontSize = $('.post-body').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum * 0.8;
    $('.post-body').css('font-size', newFontSize);
    return false;
});

var isSeoNameEmpty = 0;
var isMetaTitleEmpty = 0;
var isMetaKeywordsEmpty = 0;
var isMetaDescriptionEmpty = 0;
function ConvertToSeoname(phrase) {
    var maxLength = 255;

    var returnString = phrase.toLowerCase();
    //Convert Characters
    returnString = returnString.replace(/ö/g, 'o');
    returnString = returnString.replace(/ç/g, 'c');
    returnString = returnString.replace(/ş/g, 's');
    returnString = returnString.replace(/ı/g, 'i');
    returnString = returnString.replace(/ğ/g, 'g');
    returnString = returnString.replace(/ü/g, 'u');

    // if there are other invalid chars, convert them into blank spaces
    returnString = returnString.replace(/[^a-z0-9\s-]/g, " ");
    // convert multiple spaces and hyphens into one space       
    returnString = returnString.replace(/[\s-]+/g, " ");
    // trims current string
    returnString = returnString.replace(/^\s+|\s+$/g, "-");
    // cuts string (if too long)
    if (returnString.length > maxLength)
        returnString = returnString.substring(0, maxLength);
    // add hyphens
    returnString = returnString.replace(/\s/g, "-"); 

    return returnString;
}

var seoname = "";
var metatitle = "";
var metakeywords = "";
var metadescription = "";

function copyControlValTo(copyFromObj, copyToObj1, copyToObjLegth1, copyToObj2, copyToObjLegth2) {
    if (copyToObj1 != null && copyToObj1 != '') {
        if (copyToObj1.val().trim().length < 3) {
            isSeoNameEmpty = 1;
        }
        if (isSeoNameEmpty == 1) {
            seoname = copyFromObj.val();
            seoname = ConvertToSeoname(seoname);
            copyToObj1.val(seoname);
        }
    }
    if (copyToObj2 != null && copyToObj2 != '') {
        if (copyToObj2.val().trim().length < 4) {
            isMetaTitleEmpty = 1;
        }
        if (isMetaTitleEmpty == 1) {
            metatitle = copyFromObj.val();
        }
        copyToObj2.val(metatitle);
        if (copyToObjLegth2 != null && copyToObjLegth2 != '') {
            copyToObjLegth2.text(copyToObj2.val().length);

        }
    }
}

function ConvertToUserName(phrase) {
    var maxLength = 255;

    var returnString = phrase;
    //Convert Characters
//    returnString = returnString.replace(/ö/g, 'o');
//    returnString = returnString.replace(/ç/g, 'c');
//    returnString = returnString.replace(/ş/g, 's');
//    returnString = returnString.replace(/ı/g, 'i');
//    returnString = returnString.replace(/ğ/g, 'g');
//    returnString = returnString.replace(/ü/g, 'u');

    // if there are other invalid chars, convert them into blank spaces
    returnString = returnString.replace(/[^a-zA-Z0-9ÇçĞğİıÖöŞşÜü\s]/g, " ");
    // convert multiple spaces and hyphens into one space       
    returnString = returnString.replace(/[\s-]+/g, " ");
    // trims current string
    //returnString = returnString.replace(/^\s+|\s+$/g, "-");
    // cuts string (if too long)
    if (returnString.length > maxLength)
        returnString = returnString.substring(0, maxLength);
    // add hyphens
    //returnString = returnString.replace(/\s/g, "-");

    return returnString;
}

function stringToBoolean(string) {
    switch (string.toLowerCase()) {
        case "true": case "yes": case "1": return true;
        case "false": case "no": case "0": case null: return false;
        default: return Boolean(string);
    }
}






