﻿$(document).ready(function () {
    $(".watermark").focus(function () {
        if ($(this).val() == this.defaultValue) {
            $(this).val("");
            $(this).removeClass("watermark");
        }
    });

    $(".input-field").blur(function () {
        if ($.trim($(this).val()) == "") {
            $(this).val(this.defaultValue);
            $(this).addClass("watermark");
        }
    });
});

function limitChars(textid, limit) {
    var text = $('#' + textid).val();
    var textlength = text.length;
    if (textlength > limit) {
        $('#' + textid).val(text.substr(0, limit)); return false;
    }
    else {
        return true;
    }
}

function popup(url, width, height) {
    var windowCoordinates = getCenterWindowCoordinates(width, height);
    menuWindow = window.open(url, "edit", "toolbar=0,scrollbars=1,location=0,left=" + windowCoordinates.left + ",top=" + windowCoordinates.top + ",status=0,resizable=1,menubar=0,width=" + width + ",height=" + height)
    setTimeout("menuWindow.focus();", 100);
}

function getCenterWindowCoordinates(windowWidth, windowHeight) {
    var windowLeft = 0;
    var windowTop = 0;

    if (window.screenX) {
        windowLeft = window.screenX + ((window.outerWidth - windowWidth) / 2);
    }
    else if (window.screenLeft) {
        var isCompatMode = ((document.compatMode) && (document.compatMode != 'BackCompat'));
        window.outerWidth = (isCompatMode) ? document.body.parentElement.clientWidth : document.body.clientWidth;
        window.outerHeight = (isCompatMode) ? document.body.parentElement.clientHeight : document.body.clientHeight;
        window.outerHeight -= 80;
        windowLeft = (window.screenLeft + ((window.outerWidth - windowWidth) / 2));
    }
    else {
        windowLeft = ((screen.width - windowWidth) / 2);
    }

    if (window.screenY) {
        windowTop = window.screenY + ((window.outerHeight - windowHeight) / 2);
    }
    else if (window.screenLeft) {
        var isCompatMode = ((document.compatMode) && (document.compatMode != 'BackCompat'));
        window.outerWidth = (isCompatMode) ? document.body.parentElement.clientWidth : document.body.clientWidth;
        window.outerHeight = (isCompatMode) ? document.body.parentElement.clientHeight : document.body.clientHeight;
        window.outerHeight -= 80;
        windowTop = (window.screenTop + ((window.outerHeight - windowHeight) / 2));
    }
    else {
        windowTop = ((screen.height - windowHeight) / 2);
    }

    if ((windowTop - 10) > 0)
        windowTop -= 10;

    return { left: windowLeft, top: windowTop };
}

