﻿$(document).ready(function() {

    // ****************************************
    // *Style for table of formOneColumn class*
    // ****************************************
    var $table1 = $("table.formOneColumn");
    $('tr', $table1).each(function() {
        //$('td:first', this).css("background-color", "gray");
        $('td:first', this).css("text-align", "right");
    });


    // ****************************************
    // *Style for table of formTwoColumns class*
    // ****************************************
    var $table2 = $("table.formTwoColumns");
        $('tr', $table2).each(function() {
        // Column of label
        //$('td:first', this).css("background-color", "gray");
        $('td:first', this).css("text-align", "right");
        
        // Column of separator
        //$('td:first', this).next().next().css("background-color", "red");
        $('td:first', this).next().next().css("width", "10%");

        // Column of label
        $('td:last', this).prev().css("text-align", "right");
        //$('td:last', this).prev().css("background-color", "yellow");

    });


});
/********************************************************/
/*Global variables declaration***************************/
/********************************************************/
var prefixForMasterPage = "ctl00_";
var prefixForPage = prefixForMasterPage + "cphContent_";

function SetActiveItemForMainMenu(itemId) {
    $("a#" + prefixForMasterPage + itemId).addClass("activeItem");
}
function SetActiveItemForSubMenu(itemId) {
    $("a#" + prefixForPage + itemId).addClass("activeLink");
}
/********************************************************/
/*Script for Organization General Info page/user control*/
/********************************************************/

function EnableDisableForsytheBusinessUnitList()
{
   var c = document.getElementById("ctl00_cphContent_rbtnForsytheCustYes");
   if(c.checked == 'true')
       $("#" + prefixForPage + "ddlForsytheBizUnit").removeAttr("disabled");
   else
      $("#" + prefixForPage + "ddlForsytheBizUnit").attr("disabled", true);
   
   $("#" + prefixForPage + "rbtnForsytheCustYes").click(function (){
   $("#" + prefixForPage + "ddlForsytheBizUnit").removeAttr("disabled");
   });
   $("#" + prefixForPage + "rbtnForsytheCustNo").click(function(){
   $("#" + prefixForPage + "ddlForsytheBizUnit").attr("disabled", true);
   });
}
function EnableDisablePropspectLevelList()
{
   var c = document.getElementById("ctl00_cphContent_rbtnIsProspectYes");
   if(c.checked == 'true')
       $("#" + prefixForPage + "ddlProspectLevel").removeAttr("disabled");
   else
      $("#" + prefixForPage + "ddlProspectLevel").attr("disabled", true);
      
   $("#" + prefixForPage + "rbtnIsProspectYes").click(function (){
   $("#" + prefixForPage + "ddlProspectLevel").removeAttr("disabled");
   });
   $("#" + prefixForPage + "rbtnIsProspectNo").click(function(){
   $("#" + prefixForPage + "ddlProspectLevel").attr("disabled", true);
   });
}
function ShowHideCommunicationMilestones()
{
    //commMilestonesSection
        //ctl00_cphContent_ddlCommunicationMethod
        var c = document.getElementById("ctl00_cphContent_ddlCommunicationMethod");
        var listControl = "#commMilestonesSection";
        if(c.value == 1)
            $("div#commMilestonesSection").css("display","block");
        else
            $("div#commMilestonesSection").css("display","none");
        $("select#" + prefixForPage + "ddlCommunicationMethod").change(function () {
          if(this.value == 1)
            $("div#commMilestonesSection").css("display","block");
          else
            $("div#commMilestonesSection").css("display","none");
        })
        .change();

    }
    // Fixes dialog under combobox in IE6
    $.ui.dialog.defaults.bgiframe = true;

    function initializeRequestHandler(sender, args) {
        // Disables control which causes partial post-back
//        if ($get(args._postBackElement.id) != null)
        //            $get(args._postBackElement.id).disabled = true;
        blockPage();
    }

    // This function will handle the end request event
    function endRequestHandler(sender, args) {

        if (args.get_error() != undefined) {
            var errorMessage;
            if (args.get_response().get_statusCode() == '200') {
                errorMessage = args.get_error().message;
            }
            else {
                // Error occurred somewhere other than the server page.
                errorMessage = 'An unspecified error occurred. ';
            }
            args.set_errorHandled(true);

            //Shows message
            alert(errorMessage);
            //ToggleAlertDiv('visible');
            //$get(messageElem).innerHTML = errorMessage;
        }

       // SetCommonStyles();

        // Enables control which causes partial post-back
//        if ($get(sender._postBackSettings.sourceElement.id) != null)
//            $get(sender._postBackSettings.sourceElement.id).disabled = false;

        unblockPage();
        //    var needToConfirm = false;

        //    function setDirtyFlag()
        //    { needToConfirm = true; //Function to made changes // add or change webpage }

        //    function releaseDirtyFlag()
        //    {needToConfirm = false; //Function when no alert is required//Called when Save button is clicked}

        //    window.onbeforeunload = confirmExit;
        //    function confirmExit()
        //    {if (needToConfirm) return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?"; }  

    }

    $(document).ready(function() {

        //jQuery.noConflict();
//        SetInputFormStyle();
//        ActivateShowHideLeftMenu();
        //SetBoxStyle();

        // Handles partial post-back
        Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initializeRequestHandler);
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
    });
