﻿var showHideTimer=null;
var currntDivID= null;

$(document).ready(function(){
    if ($("#cms").length != 0) {
        $("#cms").load("/ControlContainers/ToolbarContainer.aspx");
        
        $('.contentDiv').each(function()
        {
            var onClickID = $(this).attr('id');
            var onClickString = "$('#" + onClickID + "').click();";
            var contentString = "<a href=\"javascript:void(0);\" onclick=\"" + onClickString + "\"><img src='/Images/edit.png' border='0' alt='Click to Edit' /></a>";
            
            $(this).qtip(
            {
                content: contentString, // Give it some content
                position: 'topRight', // Set its position
                hide: {
                    fixed: true // Make it fixed so it can be hovered over
                },
                style: {
                    padding: '5px 5px',
                    border: {
                        width: 0,
                        radius: 0,
                        color: 'Transparent'
                        
                    },
                    background: 'Transparent'
                }
            });
        });
    }
    
    var sectionID = $('.SectionID').text();
    
    if($(".keyAreaItem_" + sectionID).length != 0) {
        $(".keyAreaItem_" + sectionID).css('background-image', 'url(/Resources/FileBrowser/Images/cellover.png)');
        $(".keyAreaItem_" + sectionID).css('color', '#000');
        $(".keyAreaItem_" + sectionID).attr('onmouseout', '');
    }
    
    if ($(".topMenuItem_" + sectionID).length != 0) {
        $(".topMenuItem_" + sectionID).css('background-color', '#F8C126');
        $(".topMenuItem_" + sectionID).css('color', '#000');
        $(".topMenuItem_" + sectionID).attr('onmouseout', '');
    }
        
    if ($(".SubSectionMenuItem_" + sectionID).length != 0) {
          $(".SubSectionMenuItem_" + sectionID).css('color', '#D72E43');
          $(".SubSectionMenuItem_" + sectionID).addClass('subMenuLeftOn');
    }
        
    var parentSectionID = $('.ParentSectionID').text();

    if($(".keyAreaItem_" + parentSectionID).length != 0) {
        $(".keyAreaItem_" + parentSectionID).css('background-image', 'url(/Resources/FileBrowser/Images/cellover.png)');
        $(".keyAreaItem_" + parentSectionID).css('color', '#000');
        $(".keyAreaItem_" + parentSectionID).attr('onmouseout', '');
    }

    if ($("#emptyArea_" + "1").length != 0) {
        $(".cmsFilledArea_1").css('background-color', $('#emptyArea_' + '1').css('background-color'));
    }
    
    if ($("#emptyArea_" + "2").length != 0) {
        $(".cmsFilledArea_2").css('background-color', $('#emptyArea_' + '2').css('background-color'));
    }


    if ($("#emptyArea_" + "3").length != 0) {
        $(".cmsFilledArea_3").css('background-color', $('#emptyArea_' + '3').css('background-color'));
    }
    
    $('body').supersleight({shim: '/images/blank.gif'});
    $.updnValidatorCallout.attachAll();
});

function reallyHide(divID) {
	// Do your hide code
	var er = $('#shim_' + divID);
	
}

function SetCellOverStyle(divID){    
    var shimDiv = document.createElement('div');    
    var top =$("#" + divID).position().top;
    var left = $("#" + divID).position().left;
    
    shimDiv.id = "shim_" + divID;   
    shimDiv.style.position = 'absolute'; 
    shimDiv.style.margin = 0;  
    shimDiv.style.top = top;   
    shimDiv.style.width = 237;   
    shimDiv.style.height = 155;   
    shimDiv.style.backgroundColor = '#000';  
    shimDiv.style.zIndex = 100; 
    $("#" + divID).append(shimDiv);
}
    
function SetSubSectionIDLabel(subSectionID) {
    $('.OverlaySelected').val(subSectionID);
}

function OnCloseDown(imgID) {
    switch ($(imgID).attr("id")) {
    
    case "sitemapButton":             
        $("#sitemap").toggle();
        break;
    case "newsButton":
        $("#news").toggle();
        break;
    default:
        break;
    }
}

function OnCloseOver(img) {
    $(img).attr("src", "../App_Themes/Default/images/CloseOver.gif");
}

function OnCloseOut(img) {
    $(img).attr("src", "../App_Themes/Default/images/CloseOut.gif");
}

function saveMainChanges(editor) {
    var editorContent = editor.getContent();
    
    $('.HtmlContent').val(editorContent);
    CMSService.UpdateContent($('.SectionID').val(), $('.SectionElementID').val(), editorContent, $('.PositionIndex').val(), OnSucceeded, OnFailure); 
}

function OnSucceeded(msg) {
    $("#ltrHoverOverlay" +  $('.PositionIndex').val()).html($('.HtmlContent').val());  
}

function OnFailure(msg) {
     $(".overlay" +  $('.PositionIndex').val()).html(msg);
}

function GoToLive() {
    var nLocation = window.location.pathname;
    nLocation = nLocation.replace('/edit/', '/');
    window.location = nLocation;
}

function Logout() {
    window.location = "/logout";
}

function SubmitQuery() {
    if (Page_ClientValidate("contact")) { 
        var name = $('input[type=text][id*=txtName]:value').val();
        var company = $('input[type=text][id*=txtCompany]:value').val();
        var email = $('input[type=text][id*=txtEmail]:value').val();
        var telephone = $('input[type=text][id*=txtTel]:value').val();
        var address = $('.txtAddress').val();
        var message = $('.txtQuery').val();
        
        CMSService.SubmitQuery(name, company, email, telephone, address, message, OnMessageSucceeded, OnMessageFailure); 
    }
}

function ClearForm() {
    $('input[type=text][id*=txtName]:value').val("");
    $('input[type=text][id*=txtCompany]:value').val("");
    $('input[type=text][id*=txtEmail]:value').val("");
    $('input[type=text][id*=txtTel]:value').val("");
    $('.txtAddress').val("");
    $('.txtQuery').val("");
    $('.error').text("");
}

function OnMessageSucceeded(msg) {
    if(msg == "")  {
        $('.Input').toggle();
        $('.Output').toggle();
        $('.error').text("");
    }
    else {
        $('.error').text(msg);
    }
}

function OnMessageFailure(msg) {

}

function SetCellNormalStyle(divID){

}
