﻿var currentZIndex = 1000;
var themesLoaded = false;
var emailsLoaded = false;
var profileLoaded = false;
var pagesLoaded = false;
var textEditLoaded = false;

$(document).ready(function() {
    $('.boxgrid200.peek').hover(function() {
        $(".cover", this).stop().animate({ top: '80px' }, { queue: false, duration: 160 });
    }, function() {
        $(".cover", this).stop().animate({ top: '0px' }, { queue: false, duration: 160 });
    });
    $('.boxgrid100.peek').hover(function() {
        $(".cover", this).stop().animate({ top: '80px' }, { queue: false, duration: 160 });
    }, function() {
        $(".cover", this).stop().animate({ top: '0px' }, { queue: false, duration: 160 });
    });

    $("#helpWizardMainDiv").draggable({ grid: [10, 10], containment: document.body,
        stop: function() { setTimeout("setWizardPosition();", 2000); }
    });
    if (document.getElementById('hfWizardVisible').value == "1") {
        setTimeout("showHideWizard()", 5000);
    }
    document.getElementById('helpBigBubbleMainDiv').style.left = ((GetWidth() - 796) / 2).toString() + "px";
    if (document.getElementById('hfShowBigBubble').value == "1") {
        setTimeout("showHideBigBubble()", 4000);
    }
    else {
        document.getElementById('helpBigBubbleMainDiv').style.top = "-800px";
    }
    setBigHelpBubbleText("15");
    document.getElementById('dashboardFrame').src = "dashboard.aspx?compID=" + document.getElementById('hfCompanyID').value +
                "&userID=" + document.getElementById('hfUserID').value;
    document.getElementById('emailFrame').src = "newEmail.aspx";
    document.getElementById('profileFrame').src = "profileEditor.aspx?compID=" + document.getElementById('hfCompanyID').value +
                "&userID=" + document.getElementById('hfUserID').value;
    document.getElementById('pagesFrame').src = "pageView.aspx?siteID=" + document.getElementById('hfSiteID').value;
    document.getElementById('themesFrame').src = "themes.aspx?siteID=" + document.getElementById('hfSiteID').value;
    document.getElementById('textEditFrame').style.width = "860px";
    document.getElementById('textEditFrame').style.height = "435px";
    document.getElementById('textEditFrame').style.position = "absolute";
    document.getElementById('textEditFrame').style.top = ((GetHeight() - 435) / 2).toString() + "px";
    document.getElementById('textEditFrame').style.left = ((GetWidth() - 860) / 2).toString() + "px";
    document.getElementById('textEditFrame').src = "textEdit.aspx?username=" + document.getElementById('hfUsername').value +
                "&compID=" + document.getElementById('hfCompanyID').value + "&siteID=" + document.getElementById('hfSiteID').value;
    document.getElementById('viewMailFrame').src = "mailViewer.aspx";
    document.getElementById('galleryImageViewerFrame').src = "galleryImageViewer.aspx";
});

function openProfile(id) {
    slide('profilePanel');
    if (id == "advert") {
        setTimeout("", 1000);
    }
    if (id == "adbox") {
        setTimeout("", 1000);
    }
    if (id == "categories") {
        setTimeout("", 1000);
    }
    if (id == "locations") {
        setTimeout("", 1000);
    }
}

function slide(id) {
    if (id == "all") {
        var element = document.getElementById('emailPanel');
        for (var p = 0; p < element.parentNode.childNodes.length; p++) {
            var node3 = element.parentNode.childNodes[p];
            if (node3.offsetLeft == 0 | node3.offsetLeft == -1 | node3.offsetLeft == 1) {
                closeDiv(node3);
            }
        }
    }
    else {
        var element = document.getElementById(id);
        if (element.offsetLeft == -947 | element.offsetLeft == -948 | element.offsetLeft == -949) {
            for (var p = 0; p < element.parentNode.childNodes.length; p++) {
                var node3 = element.parentNode.childNodes[p];
                if (node3.offsetLeft == 0 | node3.offsetLeft == -1 | node3.offsetLeft == 1) {
                    closeDiv(node3);
                }
            }
            openDiv(element);
            for (var k = 0; k < element.parentNode.childNodes.length; k++) {
                var node4 = element.parentNode.childNodes[k];
                if (node4 != element) {
                    try {
                        node4.style.zIndex = k + 2;
                    }
                    catch (Err) {
                    }
                }
            }
            element.style.zIndex = 1;
            document.getElementById('dashContainer').style.zIndex = 0;
        }
        if (element.offsetLeft == 0 | element.offsetLeft == -1 | element.offsetLeft == 1) {
            closeDiv(element);
        }
    }
}

function openDiv(element) {
    var timer = 0;
    $(element).each(function(i) {
        timer = (timer * .8 + 400);
        $(this).animate({ marginLeft: "948px" }, timer);
    });
    if (element.id == "emailPanel") {
        document.getElementById('emailPanelTab').style.backgroundImage = "url(Images/email_tab_on.png)";
        document.getElementById('emailCloseTab').style.display = "inline";
    }
    if (element.id == "themesPanel") {
        document.getElementById('themesPanelTab').style.backgroundImage = "url(Images/them_tab_on.png)";
        document.getElementById('themesCloseTab').style.display = "inline";
    }
    if (element.id == "pagesPanel") {
        document.getElementById('pagesPanelTab').style.backgroundImage = "url(Images/page_tab_on.png)";
        document.getElementById('pagesCloseTab').style.display = "inline";
    }
    if (element.id == "profilePanel") {
        document.getElementById('profilePanelTab').style.backgroundImage = "url(Images/prof_tab_on.png)";
        document.getElementById('profileCloseTab').style.display = "inline";
    }
}

function closeDiv(element) {
    var timer = 0;
    $(element).each(function(i) {
        timer = (timer * .8 + 400);
        $(this).animate({ marginLeft: "0px" }, timer);
    });
    timer = 0;
    $(element).each(function(i) {
        timer = (timer * .8 + 500);
        $(this).animate({ marginLeft: "15px" }, timer);
        $(this).animate({ marginLeft: "0px" }, timer);
    });
    if (element.id == "emailPanel") {
        document.getElementById('emailPanelTab').style.backgroundImage = "url(Images/email_tab_off.png)";
        document.getElementById('emailCloseTab').style.display = "none";
    }
    if (element.id == "themesPanel") {
        document.getElementById('themesPanelTab').style.backgroundImage = "url(Images/them_tab_off.png)";
        document.getElementById('themesCloseTab').style.display = "none";
    }
    if (element.id == "pagesPanel") {
        document.getElementById('pagesPanelTab').style.backgroundImage = "url(Images/page_tab_off.png)";
        document.getElementById('pagesCloseTab').style.display = "none";
    }
    if (element.id == "profilePanel") {
        document.getElementById('profilePanelTab').style.backgroundImage = "url(Images/prof_tab_off.png)";
        document.getElementById('profileCloseTab').style.display = "none";
    }
}

function resetPage(elem, page) {
    document.getElementById(elem).src = page;
}

function GetHeight() {
    var y = 0;
    if (self.innerHeight) {
        y = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        y = document.documentElement.clientHeight;
    }
    else if (document.body) {
        y = document.body.clientHeight;
    }
    return y;
}

function GetWidth() {
    var x = 0;
    if (self.clientWidth) {
        x = self.clientWidth;
    }
    else if (document.documentElement && document.documentElement.clientWidth) {
        x = document.documentElement.clientWidth;
    }
    else if (document.body) {
        x = document.body.clientWidth;
    }
    return x;
}

function setModalSize(modalDivID) {
    document.getElementById(modalDivID).style.width = GetWidth().toString() + "px";
    document.getElementById(modalDivID).style.height = GetHeight().toString() + "px";
    document.getElementById(modalDivID).style.zIndex = currentZIndex;
    currentZIndex++;
}

function showModalWindow(modalDivID) {
    var timer = 0;
    var element = document.getElementById(modalDivID);
    $(element).each(function(i) {
        timer = (timer * .8 + 1200);
        $(this).animate({ top: "0px" }, timer);
    });
}

function hideModalWindow(modalDivID) {
    var timer = 0;
    var element = document.getElementById(modalDivID);
    $(element).each(function(i) {
        timer = (timer * .8 + 1200);
        $(this).animate({ top: "-1300px" }, timer);
    });
    if (modalDivID == "pagePreviewModal") {
        document.getElementById('pagePreviewFrame').src = "";
    }
    if (modalDivID == "viewPlinkModal") {
        document.getElementById('viewPlinkFrame').src = "";
    }
    if (modalDivID == "editDescriptionModal" || modalDivID == "editContactsModal") {

    }
    if (modalDivID == "editNewsModal") {
        document.getElementById('profileFrame').contentWindow.getBlogList();
    }
}

var setImageType = "";
var galRowID;

function showImagegallery(pageID, imageID, height, width, buttonID, galleryRowID) {
    galRowID = galleryRowID;
    setModalSize('imageGalleryModal');
    document.getElementById('imageGalleryFrame').style.width = "960px";
    document.getElementById('imageGalleryFrame').style.height = "690px";
    document.getElementById('imageGalleryFrame').style.position = "absolute";
    document.getElementById('imageGalleryFrame').style.top = ((GetHeight() - 690) / 2).toString() + "px";
    document.getElementById('imageGalleryFrame').style.left = ((GetWidth() - 960) / 2).toString() + "px";
    if (pageID != "") {
        setImageType = "page";
        document.getElementById('imageGalleryFrame').src = "images.aspx?dID=" + imageID + "&h=" + height + "&w=" + width;
    }
    if (buttonID != "") {
        setImageType = "button";
        document.getElementById('imageGalleryFrame').src = "images.aspx?bID=" + buttonID + "&h=" + height + "&w=" + width;
    }
    if (galleryRowID != "") {
        setImageType = "gallery";
        document.getElementById('imageGalleryFrame').src = "images.aspx?grID=" + galleryRowID;
    }
    showModalWindow('imageGalleryModal');
}

var divDetails;

function showImageUpload(divInf) {
    divDetails = divInf;
    setModalSize('imageUploadModal');
    document.getElementById('imageUploadFrame').style.width = "580px";
    document.getElementById('imageUploadFrame').style.height = "360px";
    document.getElementById('imageUploadFrame').style.position = "absolute";
    document.getElementById('imageUploadFrame').style.top = ((GetHeight() - 360) / 2).toString() + "px";
    document.getElementById('imageUploadFrame').style.left = ((GetWidth() - 580) / 2).toString() + "px";
    document.getElementById('imageUploadFrame').src = "imageUpload.aspx?userDom=" + document.getElementById('hfUserDomain').value;
    showModalWindow('imageUploadModal');
}

function closeAfterImageUpload(imageID) {
    if (setImageType == "gallery") {
        document.getElementById('imageGalleryFrame').src = "images.aspx?iID=" + imageID + "&grID=" + galRowID;
    }
    else {
        document.getElementById('imageGalleryFrame').src = "images.aspx" + divDetails + "&iID=" + imageID;
    }
}

var imageNum = "";

function showPlinkImageUpload(num) {
    imageNum = num;
    setModalSize('imageUploadModal');
    document.getElementById('imageUploadFrame').style.width = "580px";
    document.getElementById('imageUploadFrame').style.height = "360px";
    document.getElementById('imageUploadFrame').style.position = "absolute";
    document.getElementById('imageUploadFrame').style.top = ((GetHeight() - 360) / 2).toString() + "px";
    document.getElementById('imageUploadFrame').style.left = ((GetWidth() - 580) / 2).toString() + "px";
    document.getElementById('imageUploadFrame').src = "imageUpload.aspx?userDom=" + document.getElementById('hfPlinkAddress').value +
            "&plink=true";
    showModalWindow('imageUploadModal');
}

function closeAfterPlinkImageUpload(fileName) {
    showPlinkImageEditor(fileName);
}

function showPlinkImageEditor(fileName) {
    setModalSize('plinkImageEditorModal');
    document.getElementById('plinkImageEditorFrame').style.width = "1020px";
    document.getElementById('plinkImageEditorFrame').style.height = "700px";
    document.getElementById('plinkImageEditorFrame').style.position = "absolute";
    document.getElementById('plinkImageEditorFrame').style.top = ((GetHeight() - 700) / 2).toString() + "px";
    document.getElementById('plinkImageEditorFrame').style.left = ((GetWidth() - 1020) / 2).toString() + "px";
    document.getElementById('plinkImageEditorFrame').src = "plinkImageEditor.aspx?userDom=" + document.getElementById('hfPlinkAddress').value +
                "&fileName=" + fileName + "&width=" + GetWidth() + "&height=" + GetHeight() + "&plinkID=" + document.getElementById('hfPlinkID').value +
                "&num=" + imageNum;
    showModalWindow('plinkImageEditorModal');
}

function setPlinkImage(retVal) {
    document.getElementById('profileFrame').contentWindow.setPlinkImage(retVal);
}

function showAttachUpload() {
    setModalSize('attachUploadModal');
    document.getElementById('attachUploadFrame').style.width = "580px";
    document.getElementById('attachUploadFrame').style.height = "350px";
    document.getElementById('attachUploadFrame').style.position = "absolute";
    document.getElementById('attachUploadFrame').style.top = ((GetHeight() - 350) / 2).toString() + "px";
    document.getElementById('attachUploadFrame').style.left = ((GetWidth() - 580) / 2).toString() + "px";
    document.getElementById('attachUploadFrame').src = "ulpoadAttachment.aspx";
    showModalWindow('attachUploadModal');
}

function closeAfterAttachUpload(fileName) {
    hideModalWindow('attachUploadModal');
    document.getElementById('emailFrame').contentWindow.addAttachment(fileName)
}

function showImageView(imageID, imageSize, imageURL, type) {
    if (imageID != "") {
        var width = parseFloat(imageSize.split(';')[0]);
        var height = parseFloat(imageSize.split(';')[1]);
        setModalSize('imageViewModal');
        document.getElementById('imageBox1').style.position = "absolute";
        if (width > GetWidth()) {
            document.getElementById('imageBox1').style.width = (GetWidth() - 20).toString() + "px";
            var newHeight = Math.round(height * ((GetWidth() - 20) / width));
            document.getElementById('imageBox1').style.height = newHeight.toString() + "px";
            document.getElementById('imageBox1').style.top = ((GetHeight() - newHeight) / 2).toString() + "px";
            document.getElementById('imageBox1').style.left = "10px";
            document.getElementById('closeImageViewButton').style.left = ((GetWidth() - 75) / 2).toString() + "px";
        }
        else {
            document.getElementById('imageBox1').style.width = width.toString() + "px";
            document.getElementById('imageBox1').style.height = height.toString() + "px";
            document.getElementById('imageBox1').style.top = ((GetHeight() - height) / 2).toString() + "px";
            document.getElementById('imageBox1').style.left = ((GetWidth() - width) / 2).toString() + "px";
            document.getElementById('closeImageViewButton').style.left = ((GetWidth() - 75) / 2).toString() + "px";
        }
        if (type == "theme") {

            document.getElementById('imageBox1').setAttribute("onmouseover", "setWizardText('58')");
        }
        else {
            document.getElementById('imageBox1').setAttribute("onmouseover", "setWizardText('59')");
        }
        document.getElementById('imageBox1').src = imageURL;
        setTimeout("showModalWindow('imageViewModal')", 1000);
    }
}

var newQueryString;

function setQueryAndShowImageConfirm(query) {
    newQueryString = query;
    showImageConfirm();
}

function showImageConfirm() {
    setModalSize('imageConfirmModal');
    document.getElementById('imageConfirmFrame').style.width = "750px";
    document.getElementById('imageConfirmFrame').style.height = "500px";
    document.getElementById('imageConfirmFrame').style.position = "absolute";
    document.getElementById('imageConfirmFrame').style.top = ((GetHeight() - 500) / 2).toString() + "px";
    document.getElementById('imageConfirmFrame').style.left = ((GetWidth() - 767) / 2).toString() + "px";
    document.getElementById('imageConfirmFrame').src = "imageConfirm.aspx" + newQueryString;
    showModalWindow('imageConfirmModal')
}

function hideImageGallConfirm(queryString) {
    newQueryString = queryString;
    hideModalWindow('imageGalleryModal');
    showImageConfirm();
}

function hideImageGallApply(divID, imageURL, imageWidth, imageHeight) {
    hideModalWindow('imageGalleryModal');
    if (setImageType == "page") {
        document.getElementById('pageEditorFrame').contentWindow.assignNewImage(divID, imageURL);
    }
    if (setImageType == "button") {
        document.getElementById('formBuilderFrame').contentWindow.setImage(imageURL);
    }
}

function showGalleryImageEditor(galID, imageID, imageName, imageURL, imageWidth, imageHeight) {
    var d = new Date();
    var time = d.getTime();
    setModalSize('galleryImageEditorModal');
    document.getElementById('galleryImageEditorFrame').style.width = "960px";
    document.getElementById('galleryImageEditorFrame').style.height = "550px";
    document.getElementById('galleryImageEditorFrame').style.position = "absolute";
    document.getElementById('galleryImageEditorFrame').style.top = ((GetHeight() - 550) / 2).toString() + "px";
    document.getElementById('galleryImageEditorFrame').style.left = ((GetWidth() - 960) / 2).toString() + "px";
    document.getElementById('galleryImageEditorFrame').src = "galleryImageEditor.aspx?userDom=" + document.getElementById('hfUserDomain').value +
             "&grID=" + galRowID +
             "&imgID=" + imageID +
             "&imgName=" + imageName +
             "&imgURL=" + imageURL +
             "&imgW=" + imageWidth +
             "&imgH=" + imageHeight +
             "&d=" + time;
    showModalWindow('galleryImageEditorModal');
}

function hideImageGallShowGallEditor(divID, imageID, imageName, imageURL, imageWidth, imageHeight) {
    hideModalWindow('imageGalleryModal');
    showGalleryImageEditor(divID, imageID, imageName, imageURL, imageWidth, imageHeight);
}

function setGalleryImage(retVal) {
    document.getElementById('galleryImagesFrame').contentWindow.setGalleryImage(retVal);
}

var newGallery;

function showGalleryPicker(galID) {
    newGallery = galID;
    setModalSize('galleryPickerModal');
    document.getElementById('galleryPickerFrame').style.width = "920px";
    document.getElementById('galleryPickerFrame').style.height = "620px";
    document.getElementById('galleryPickerFrame').style.position = "absolute";
    document.getElementById('galleryPickerFrame').style.top = ((GetHeight() - 620) / 2).toString() + "px";
    document.getElementById('galleryPickerFrame').style.left = ((GetWidth() - 920) / 2).toString() + "px";
    document.getElementById('galleryPickerFrame').src = "galleryPicker.aspx?siteID=" + document.getElementById('hfSiteID').value;
    showModalWindow('galleryPickerModal');
}

function showGalleryBuilder(galType, galID, width, height) {
    setModalSize('galleryBuilderModal');
    document.getElementById('galleryBuilderFrame').style.width = "910px";
    document.getElementById('galleryBuilderFrame').style.height = "620px";
    document.getElementById('galleryBuilderFrame').style.position = "absolute";
    document.getElementById('galleryBuilderFrame').style.top = ((GetHeight() - 620) / 2).toString() + "px";
    document.getElementById('galleryBuilderFrame').style.left = ((GetWidth() - 910) / 2).toString() + "px";
    document.getElementById('galleryBuilderFrame').src = "galleryBuilder.aspx?galID=" + galID + "&siteID=" + document.getElementById('hfSiteID').value + "&w=" + width + "&h=" + height +
                "&galType=" + galType;
    showModalWindow('galleryBuilderModal');
}

function showGalleryImages(galID, width, height) {
    setModalSize('galleryImagesModal');
    document.getElementById('galleryImagesFrame').style.width = "920px";
    document.getElementById('galleryImagesFrame').style.height = "620px";
    document.getElementById('galleryImagesFrame').style.position = "absolute";
    document.getElementById('galleryImagesFrame').style.top = ((GetHeight() - 620) / 2).toString() + "px";
    document.getElementById('galleryImagesFrame').style.left = ((GetWidth() - 920) / 2).toString() + "px";
    document.getElementById('galleryImagesFrame').src = "galleryImages.aspx?galID=" + galID + "&siteID=" + document.getElementById('hfSiteID').value + "&w=" + width + "&h=" + height;
    showModalWindow('galleryImagesModal');
}

function setImageAfterConfirm(type, divID, imageURL, size) {
    hideModalWindow('imageConfirmModal');
    if (type == "resi") {
        if (setImageType == "page") {
            document.getElementById('pageEditorFrame').contentWindow.assignNewImageResize(divID, imageURL, size);
        }
        if (setImageType == "button") {
            document.getElementById('formBuilderFrame').contentWindow.setImageResize(imageURL, size);
        }
    }
    else {
        if (setImageType == "page") {
            document.getElementById('pageEditorFrame').contentWindow.assignNewImage(divID, imageURL);
        }
        if (setImageType == "button") {
            document.getElementById('formBuilderFrame').contentWindow.setImage(imageURL);
        }
    }
}

var textType = "";

function showTextEdit(strText, type) {
    textType = type;
    setModalSize('textEditModal');
    showModalWindow('textEditModal');
    document.getElementById('textEditFrame').contentWindow.setText(strText);
}

function closeTextEditSetText(text) {
    hideModalWindow('textEditModal');
    if (textType == "page") {
        document.getElementById('pageEditorFrame').contentWindow.setNewText(text);
    }
    if (textType == "gall") {
        document.getElementById('galleryBuilderFrame').contentWindow.setNewText(text);
    }
}

function editHeaderDetails(pageID, type) {
    var d = new Date();
    var time = d.getTime();
    setModalSize('pageDetailsModal');
    document.getElementById('pageDetailsFrame').style.width = "530px";
    document.getElementById('pageDetailsFrame').style.height = "430px";
    document.getElementById('pageDetailsFrame').style.position = "absolute";
    document.getElementById('pageDetailsFrame').style.top = ((GetHeight() - 430) / 2).toString() + "px";
    document.getElementById('pageDetailsFrame').style.left = ((GetWidth() - 530) / 2).toString() + "px";
    document.getElementById('pageDetailsFrame').src = "editHeaders.aspx?siteID=" + document.getElementById('hfSiteID').value +
                "&type=" + type + "&pageID=" + pageID + "&d=" + time;
    showModalWindow('pageDetailsModal');
}

function newPageDetails(parentID, textLength) {
    var d = new Date();
    var time = d.getTime();
    setModalSize('pageDetailsModal');
    document.getElementById('pageDetailsFrame').style.width = "530px";
    document.getElementById('pageDetailsFrame').style.height = "570px";
    document.getElementById('pageDetailsFrame').style.position = "absolute";
    document.getElementById('pageDetailsFrame').style.top = ((GetHeight() - 570) / 2).toString() + "px";
    document.getElementById('pageDetailsFrame').style.left = ((GetWidth() - 530) / 2).toString() + "px";
    document.getElementById('pageDetailsFrame').src = "editPageDetails.aspx?parentID=" + parentID + "&type=new" +
                 "&textLength=" + textLength + "&d=" + time;
    showModalWindow('pageDetailsModal');
}

function editPageDetails(pageID, textLength) {
    var d = new Date();
    var time = d.getTime();
    setModalSize('pageDetailsModal');
    document.getElementById('pageDetailsFrame').style.width = "530px";
    document.getElementById('pageDetailsFrame').style.height = "570px";
    document.getElementById('pageDetailsFrame').style.position = "absolute";
    document.getElementById('pageDetailsFrame').style.top = ((GetHeight() - 570) / 2).toString() + "px";
    document.getElementById('pageDetailsFrame').style.left = ((GetWidth() - 530) / 2).toString() + "px";
    document.getElementById('pageDetailsFrame').src = "editPageDetails.aspx?pageID=" + pageID + "&type=view" +
                 "&textLength=" + textLength + "&d=" + time;
    showModalWindow('pageDetailsModal');
}

function closePageDetailsShowPageTemplates(pageName, pageTitle, summary, keywords, parentID) {
    hideModalWindow('pageDetailsModal');
    setModalSize('pageTemplatesModal');
    document.getElementById('pageTemplatesFrame').style.width = "820px";
    document.getElementById('pageTemplatesFrame').style.height = "640px";
    document.getElementById('pageTemplatesFrame').style.position = "absolute";
    document.getElementById('pageTemplatesFrame').style.top = ((GetHeight() - 640) / 2).toString() + "px";
    document.getElementById('pageTemplatesFrame').style.left = ((GetWidth() - 820) / 2).toString() + "px";
    document.getElementById('pageTemplatesFrame').src = "pageLayoutGallery.aspx?name=" + pageName + "&title=" + pageTitle +
            "&summary=" + summary + "&keywords=" + keywords + "&parentID=" + parentID + "&siteID=" + document.getElementById('hfSiteID').value;
    showModalWindow('pageTemplatesModal');
}

function showNewPageInPageEditor(pageID) {
    hideModalWindow('pageTemplatesModal');
    showPageEditor(pageID);
}

function showPageEditor(pageID) {
    setModalSize('pageEditorModal');
    document.getElementById('pageEditorFrame').style.width = (GetWidth() - 20) + "px";
    document.getElementById('pageEditorFrame').style.height = (GetHeight() - 20).toString() + "px";
    document.getElementById('pageEditorFrame').style.position = "absolute";
    document.getElementById('pageEditorFrame').style.top = "10px";
    document.getElementById('pageEditorFrame').style.left = "10px";
    document.getElementById('pageEditorFrame').src = "pageEditor.aspx?pageID=" + pageID +
                "&compID=" + document.getElementById('hfCompanyID').value + "&siteID=" + document.getElementById('hfSiteID').value;
    showModalWindow('pageEditorModal');
}

function closeRefreshPageEditor(pageID) {
    hideModalWindow('pageDetailsModal');
    document.getElementById('pageEditorFrame').src = "pageEditor.aspx?pageID=" + pageID + "&compID=" + document.getElementById('hfCompanyID').value;
}

function refreshPageView() {
    document.getElementById('pagesFrame').src = "pageView.aspx?compID=" + document.getElementById('hfCompanyID').value +
                "&userID=" + document.getElementById('hfUserID').value + "&siteID=" + document.getElementById('hfSiteID').value;
}

function showPagePreview() {
    var options = "scrollbars=yes,menubar=yes,height=" + GetHeight() + ",width=" + GetWidth() + ",resizable=yes,toolbar=yes,location=yes,status=yes";
    window.open(document.getElementById('hfWebUrl').value);
}

function viewMailPreview(mailDate, mailFrom, mailSubj, mailCont) {
    document.getElementById('viewMailFrame').contentWindow.setData(mailDate, mailFrom, mailSubj, mailCont);
    setModalSize('viewMailModal');
    document.getElementById('viewMailFrame').style.width = "720px";
    document.getElementById('viewMailFrame').style.height = "690px";
    document.getElementById('viewMailFrame').style.position = "absolute";
    document.getElementById('viewMailFrame').style.top = ((GetHeight() - 690) / 2).toString() + "px";
    document.getElementById('viewMailFrame').style.left = ((GetWidth() - 720) / 2).toString() + "px";
    showModalWindow('viewMailModal');
}

var currMessage;

function setMessageStartPosition() {
    var messageDiv = document.getElementById(currMessage);
    document.getElementById(currMessage).style.left = ((GetWidth() - messageDiv.offsetWidth) / 2).toString() + "px";
}

function showMessageNoClose(messageID) {
    currMessage = messageID;
    setMessageStartPosition();
    var messageDiv = document.getElementById(currMessage);
    var newPos = ((GetHeight() - messageDiv.offsetHeight) / 2).toString() + "px";
    var timer = 0;
    $("#" + currMessage).each(function(i) {
        timer = (timer * .8 + 800);
        $(this).animate({ top: newPos }, timer);
    });
}

function showMessage(messageID, time, size) {
    var messageDiv;
    if (size == "small") {
        messageDiv = document.getElementById("messageDivSmall");
        currMessage = "messageDivSmall";
    }
    if (size == "large") {
        messageDiv = document.getElementById("messageDivLarge");
        currMessage = "messageDivLarge";
    }
    messageDiv.style.backgroundImage = "url(Images/" + messageID + ".png)";
    messageDiv.style.zIndex = currentZIndex;
    currentZIndex++;
    var newPos = ((GetHeight() - messageDiv.offsetHeight) / 2).toString() + "px";
    var bounce1 = (((GetHeight() - messageDiv.offsetHeight) / 2) - 20).toString() + "px";
    var bounce2 = (((GetHeight() - messageDiv.offsetHeight) / 2) - 10).toString() + "px";
    var timer = 0;
    $("#" + currMessage).each(function(i) {
        timer = (timer * .8 + 800);
        $(this).animate({ top: newPos }, timer);
    });
    timer = 0;
    $("#" + currMessage).each(function(i) {
        timer = (timer * .8 + 400);
        $(this).animate({ top: bounce1 }, timer);
        $(this).animate({ top: newPos }, timer);
    });
    timer = 0;
    $("#" + currMessage).each(function(i) {
        timer = (timer * .8 + 400);
        $(this).animate({ top: bounce2 }, timer);
        $(this).animate({ top: newPos }, timer);
    });
    setTimeout("hideMessage()", time);
}

function hideMessage() {
    var timer = 0;
    $("#" + currMessage).each(function(i) {
        timer = (timer * .8 + 1200);
        $(this).animate({ top: "-400px" }, timer);
    });
}

function hideMessageDiv() {
    var timer = 0;
    $("#" + currMessage).each(function(i) {
        timer = (timer * .8 + 1200);
        $(this).animate({ top: "-400px" }, timer);
    });
}

function showHideWizard() {
    var timer = 0;
    var element = document.getElementById('helpWizardMainDiv');
    if (element.offsetTop < 0) {
        var pos = document.getElementById('hfWizardTop').value;
        var newPos = pos + "px";
        var bounce1 = (pos - 20).toString() + "px";
        var bounce2 = (pos - 10).toString() + "px";
        $(element).each(function(i) {
            timer = (timer * .8 + 1200);
            $(this).animate({ top: newPos }, timer);
        });
        timer = 0;
        $(element).each(function(i) {
            timer = (timer * .8 + 400);
            $(this).animate({ top: bounce1 }, timer);
            $(this).animate({ top: newPos }, timer);
        });
        timer = 0;
        $(element).each(function(i) {
            timer = (timer * .8 + 400);
            $(this).animate({ top: bounce2 }, timer);
            $(this).animate({ top: newPos }, timer);
        });
        if (document.getElementById('hfWizardVisible').value == "0") {
            setTimeout("setWizardVisible(1);", 2000);
        }
        document.getElementById('helpIcon').style.backgroundImage = "url(Images/help_on.png)";
    }
    else {
        document.getElementById('hfWizardTop').value = element.offsetTop;
        $(element).each(function(i) {
            timer = (timer * .8 + 1200);
            $(this).animate({ top: "-800px" }, timer);
        });
        setTimeout("setWizardVisible(0);", 2000);
        document.getElementById('helpIcon').style.backgroundImage = "url(Images/help_off.png)";
    }

}

function setWizardPosition() {
    var strURL = document.getElementById('hfHandlerURL').value + "/setWizardPosHandler.ashx";
    $.post(strURL, {
        comp: document.getElementById('hfCompanyID').value,
        top: document.getElementById('helpWizardMainDiv').offsetTop,
        right: GetWidth() - document.getElementById('helpWizardMainDiv').offsetLeft - document.getElementById('helpWizardMainDiv').offsetWidth
    }, function(data) { });
}

function setWizardVisible(onOff) {
    var d = new Date();
    var time = d.getTime();
    var strURL = document.getElementById('hfHandlerURL').value + "/setWizardVisibleHandler.ashx?comp=" +
                document.getElementById('hfCompanyID').value + "&onOff=" + onOff + "&d=" + time;
    $.get(strURL, function(data) { });
}

function setWizardText(id) {
    if (document.getElementById('helpWizardMainDiv').offsetTop > -790) {
        if (id == "0") {
            document.getElementById('helpWizardContent').innerHTML = "";
        }
        else {
            var d = new Date();
            var time = d.getTime();
            var strURL = document.getElementById('hfHandlerURL').value + "/helpServer.ashx?HelpID=" + id + "&d=" + time;
            $.get(strURL, function(data) { document.getElementById('helpWizardContent').innerHTML = data; });
        }
    }
}

function showAdboxPopup() {
    var d = new Date();
    var time = d.getTime();
    setModalSize('adBoxCodeModal');
    document.getElementById('adBoxCodeFrame').style.width = "900px";
    document.getElementById('adBoxCodeFrame').style.height = "590px";
    document.getElementById('adBoxCodeFrame').style.position = "absolute";
    document.getElementById('adBoxCodeFrame').style.top = ((GetHeight() - 590) / 2).toString() + "px";
    document.getElementById('adBoxCodeFrame').style.left = ((GetWidth() - 900) / 2).toString() + "px";
    document.getElementById('adBoxCodeFrame').src = "adcode.aspx?compID=" + document.getElementById('hfCompanyID').value + "&d=" + time;
    showModalWindow('adBoxCodeModal');
}

function showHideBigBubble() {
    var timer = 0;
    var element = document.getElementById('helpBigBubbleMainDiv');
    if (element.offsetTop < 0) {
        $(element).each(function(i) {
            timer = (timer * .8 + 1200);
            $(this).animate({ top: "70px" }, timer);
        });
        timer = 0;
        $(element).each(function(i) {
            timer = (timer * .8 + 400);
            $(this).animate({ top: "50px" }, timer);
            $(this).animate({ top: "70px" }, timer);
        });
        timer = 0;
        $(element).each(function(i) {
            timer = (timer * .8 + 400);
            $(this).animate({ top: "60px" }, timer);
            $(this).animate({ top: "70px" }, timer);
        });
    }
    else {
        wizardTop = element.offsetTop;
        $(element).each(function(i) {
            timer = (timer * .8 + 1200);
            $(this).animate({ top: "-800px" }, timer);
        });
        var d = new Date();
        var time = d.getTime();
        var strURL = document.getElementById('hfHandlerURL').value + "/setHelpEnabledHandler.ashx?comp=" +
                document.getElementById('hfCompanyID').value + "&onOff=" + document.getElementById('helpOnOff').checked + "&d=" + time;
        $.get(strURL, function(data) { });
    }
}

function showDescriptionEditor() {
    var d = new Date();
    var time = d.getTime();
    setModalSize('editDescriptionModal');
    document.getElementById('editDescriptionFrame').style.width = "880px";
    document.getElementById('editDescriptionFrame').style.height = "530px";
    document.getElementById('editDescriptionFrame').style.position = "absolute";
    document.getElementById('editDescriptionFrame').style.top = ((GetHeight() - 530) / 2).toString() + "px";
    document.getElementById('editDescriptionFrame').style.left = ((GetWidth() - 880) / 2).toString() + "px";
    document.getElementById('editDescriptionFrame').src = "descriptionEditor.aspx?compID=" + document.getElementById('hfCompanyID').value + "&d=" + time;
    showModalWindow('editDescriptionModal');
}

function setNewDescription(text) {
    document.getElementById('profileFrame').contentWindow.setNewDescription(text);
}

function showContactsEditor() {
    var d = new Date();
    var time = d.getTime();
    setModalSize('editContactsModal');
    document.getElementById('editContactsFrame').style.width = "850px";
    document.getElementById('editContactsFrame').style.height = "440px";
    document.getElementById('editContactsFrame').style.position = "absolute";
    document.getElementById('editContactsFrame').style.top = ((GetHeight() - 440) / 2).toString() + "px";
    document.getElementById('editContactsFrame').style.left = ((GetWidth() - 850) / 2).toString() + "px";
    document.getElementById('editContactsFrame').src = "contactsEditor.aspx?compID=" + document.getElementById('hfCompanyID').value +
                "&userID=" + document.getElementById('hfUserID').value + "&d=" + time;
    showModalWindow('editContactsModal');
}

function setNewContacts(text) {
    document.getElementById('profileFrame').contentWindow.setNewContacts(text);
}

function viewPlinkPreview() {
    hideMessageDiv();
    var options = "scrollbars=yes,menubar=yes,height=" + GetHeight() + ",width=" + GetWidth() + ",resizable=yes,toolbar=yes,location=yes,status=yes";
    window.open(document.getElementById('hfPlinkAddress').value, '', options.toString());
}

function openDescr() {
    hideMessageDiv();
    setTimeout("slide('profilePanel')", 1000);
    setTimeout("openDescrPanel();", 1500);
    setTimeout("showDescriptionEditor();", 2000);
}

function openDescrPanel() {
    document.getElementById('profileFrame').contentWindow.slide('profile');
}

function openProfile() {
    hideMessageDiv();
    setTimeout("slide('profilePanel')", 1000);
    setTimeout("openAdvert();", 1500);
    setTimeout("showAdvertEditor();", 2000);
}

function openAdvert() {
    document.getElementById('profileFrame').contentWindow.slide('updaters');
}

function showNewsEditor(blogID) {
    var d = new Date();
    var time = d.getTime();
    setModalSize('editNewsModal');
    document.getElementById('editNewsFrame').style.width = "650px";
    document.getElementById('editNewsFrame').style.height = "520px";
    document.getElementById('editNewsFrame').style.position = "absolute";
    document.getElementById('editNewsFrame').style.top = ((GetHeight() - 520) / 2).toString() + "px";
    document.getElementById('editNewsFrame').style.left = ((GetWidth() - 650) / 2).toString() + "px";
    document.getElementById('editNewsFrame').src = "editNews.aspx?blogID=" + blogID + "&d=" + time;
    showModalWindow('editNewsModal');
}

var formData = "";
var currentForm = "";
var formElement;

function showFormBuilder(id, width, height, element, count, maxWidth) {
    currentForm = id;
    setModalSize('formBuilderModal');
    document.getElementById('formBuilderFrame').style.width = "910px";
    document.getElementById('formBuilderFrame').style.height = "610px";
    document.getElementById('formBuilderFrame').style.position = "absolute";
    document.getElementById('formBuilderFrame').style.top = ((GetHeight() - 610) / 2).toString() + "px";
    document.getElementById('formBuilderFrame').style.left = ((GetWidth() - 910) / 2).toString() + "px";

    if (element.innerHTML.indexOf("submitButton") > -1) {
        formData = width + "^^" + height + "^^" + count + "^^" + maxWidth;
        formElement = element;
        document.getElementById('formBuilderFrame').src = "formBuilder.aspx?maxWidth=" + maxWidth + "&width=" + width + "&height=" + height;
        setTimeout("setFormBuilderContent();", 2000);
    }
    else {
        document.getElementById('formBuilderFrame').src = "formBuilder.aspx?width=" + width + "&height=" + height + "&count=" + count + "&maxWidth=" + maxWidth;
    }
    showModalWindow('formBuilderModal');
}

function setFormBuilderContent() {
    document.getElementById('formBuilderFrame').contentWindow.setContent(formData, formElement);
}

function setForm(width, height, newFormContent) {
    document.getElementById('pageEditorFrame').contentWindow.setNewContent(currentForm, width, height, newFormContent);
}

var colourID;

function showColourPicker(id) {
    colourID = id;
    setModalSize('colourPickerModal');
    document.getElementById('colourPickerFrame').style.width = "670px";
    document.getElementById('colourPickerFrame').style.height = "420px";
    document.getElementById('colourPickerFrame').style.position = "absolute";
    document.getElementById('colourPickerFrame').style.top = ((GetHeight() - 420) / 2).toString() + "px";
    document.getElementById('colourPickerFrame').style.left = ((GetWidth() - 670) / 2).toString() + "px";
    document.getElementById('colourPickerFrame').src = "colourPicker.aspx";
    showModalWindow('colourPickerModal');
}

function setColour(hash) {
    if (colourID == "form") {
        document.getElementById('formBuilderFrame').contentWindow.setFontColour(hash);
    }
    if (colourID == "gall") {
        document.getElementById('galleryBuilderFrame').contentWindow.setFontColour(hash);
    }
    if (colourID == "text") {
        document.getElementById('textEditFrame').contentWindow.doRichEditCommand('forecolor', hash);
    }
}

function setBigHelpBubbleText(id) {
    var d = new Date();
    var time = d.getTime();
    var strURL = document.getElementById('hfHandlerURL').value + "/helpServer.ashx?HelpID=" + id + "&d=" + time;
    $.get(strURL, function(data) { document.getElementById('helpBigContent').innerHTML = data; });
}

function setDashEmails(all, llu) {
    document.getElementById('dashboardFrame').contentWindow.setEmails(all, llu);
}

var delBlog = "0";

function showNewsDeleteDiv() {
    var newPos = ((GetHeight() - 200) / 2).toString() + "px";
    var timer = 0;
    $("#newsDeleteDiv").each(function(i) {
        timer = (timer * .8 + 800);
        $(this).animate({ top: newPos }, timer);
    });
}

function confirmDeleteNews(id) {
    delBlogID = id;
    setNewsDeleteStartPosition();
    showNewsDeleteDiv();
}

function setNewsDeleteStartPosition() {
    document.getElementById('newsDeleteDiv').style.top = "-300px";
    document.getElementById('newsDeleteDiv').style.left = ((GetWidth() - 400) / 2).toString() + "px";
}

function hideNewsDeleteDiv() {
    var timer = 0;
    $("#newsDeleteDiv").each(function(i) {
        timer = (timer * .8 + 1200);
        $(this).animate({ top: "-400px" }, timer);
    });
}

function deleteBlog() {
    hideNewsDeleteDiv();
    var d = new Date();
    var time = d.getTime();
    var strURL = document.getElementById('hfHandlerURL').value + "/delBlogHandler.ashx?blogID=" + delBlogID +
                "&plinkID=" + document.getElementById('hfPlinkID').value + "&d=" + time;
    $.get(strURL, function(data) {
        if (data == "success") {
            delBlogID = "0";
            hideModalWindow("editNewsModal");
        }
    });
}

function showGalleryImageViewer(id, imageUrls, imageNames, imageDescs, imageSizes) {
    setModalSize('galleryImageViewerModal');
    document.getElementById('galleryImageViewerFrame').style.position = "relative";
    document.getElementById('galleryImageViewerFrame').style.top = "10px";
    document.getElementById('galleryImageViewerFrame').contentWindow.setImages(id, imageUrls, imageNames, imageDescs, imageSizes);
    showModalWindow('galleryImageViewerModal');
}

function setGalleryViewerSize(width, height) {
    document.getElementById('galleryImageViewerFrame').style.width = width + "px";
    document.getElementById('galleryImageViewerFrame').style.height = height + "px";
    if (height < GetHeight()) {
        document.getElementById('galleryImageViewerFrame').style.top = parseInt(((GetHeight() - height) / 2)).toString() + "px";
    }
    else {
        document.getElementById('galleryImageViewerFrame').style.top = "10px";
    }
}

function showEditUsernameModal() {
    setModalSize('editUsernameModal');
    document.getElementById('editUsernameframe').style.width = "452px";
    document.getElementById('editUsernameframe').style.height = "538px";
    document.getElementById('editUsernameframe').style.position = "absolute";
    document.getElementById('editUsernameframe').style.top = ((GetHeight() - 538) / 2).toString() + "px";
    document.getElementById('editUsernameframe').style.left = ((GetWidth() - 452) / 2).toString() + "px";
    document.getElementById('editUsernameframe').src = "editUsername.aspx?userID=" + document.getElementById('hfUserID').value;
    showModalWindow('editUsernameModal');
}

function showEditPasswordModal() {
    setModalSize('editPasswordModal');
    document.getElementById('editPasswordframe').style.width = "452px";
    document.getElementById('editPasswordframe').style.height = "354px";
    document.getElementById('editPasswordframe').style.position = "absolute";
    document.getElementById('editPasswordframe').style.top = ((GetHeight() - 354) / 2).toString() + "px";
    document.getElementById('editPasswordframe').style.left = ((GetWidth() - 452) / 2).toString() + "px";
    document.getElementById('editPasswordframe').src = "editPassword.aspx?userID=" + document.getElementById('hfUserID').value;
    showModalWindow('editPasswordModal');
}
