﻿function clearText(textbox) {
    var x = textbox.value;
    var y = textbox.id;
    textbox.value = '';
    textbox.focus();
}

function expandDiv(width, left, top, height, method) {
    $("#ajaxDiv").animate({ "left": left, "width": width, "height": height, "top": top }, method); 
  
}
function setPopupDivPosition(top, left) {
    $("#ajaxDiv").width("1px");
    $("#ajaxDiv").height("1px");
    $("#ajaxDiv").show();
    $("#ajaxDiv").css("top", top);
    $("#ajaxDiv").css("left", left);
    $("#light").width("1px");
    $("#light").height("1px");
    $("#light").css("top", top);
    $("#light").css("left", left);
}

function search() {
    var regionId = 0;
    var practiceAreaId = 0;
    var minimumTrainees = 0;
    var maximumTrainees = 0;
    var firmName;

    var regionSelectedVal = $get('ddlRegion').options[$get('ddlRegion').selectedIndex].value;
    if (regionSelectedVal != "*") {
        regionId = regionSelectedVal;
    }
    var practiceAreasSelectedVal = $get('ddlPracticeAreas').options[$get('ddlPracticeAreas').selectedIndex].value;
    if (practiceAreasSelectedVal != "*") {
        practiceAreaId = practiceAreasSelectedVal;
    }

    var traineesSelectedVal = $get('ddlTrainees').options[$get('ddlTrainees').selectedIndex].value;
    if (traineesSelectedVal != "*") {
        switch (traineesSelectedVal) {
            case "10":
                minimumTrainees = 0;
                maximumTrainees = 10;
                break;
            case "11":
                minimumTrainees = 11;
                maximumTrainees = 50;
                break;
            case "51":
                minimumTrainees = 51;
                maximumTrainees = 1000;
                break;
            default:
                minimumTrainees = 0;
                maximumTrainees = 0;
                break;
        }
    }
    if ($("#tbFirm").val() != null) {
        firmName = $("#tbFirm").val();
    }
    else if ($("#testinput_xml").val() != null)
    {
        firmName = $("#testinput_xml").val();
    }
    else {
        firmName = '';
    }
    window.location = "SearchResults.aspx?Type=TruePicture&min=" + minimumTrainees + "&max=" + maximumTrainees + "&paid=" + practiceAreaId + "&regionid=" + regionId + "&firmname=" + escape(firmName);
}

function GetControlToLoad(type) {
    if (type == "Search") {
        return "/Controls/Ajax/SearchControl.aspx"
    }
    else {
        return "/Controls/Ajax/PopupControl.aspx"
    }
}


function popup(sectionId, type, direction, divname) {
    var controlToLoad = ""
    controlToLoad = GetControlToLoad(type);
    $(".black_overlay").hide();
    $("#contentArea").css("width", "0px");
    $("#contentArea").css("height", "0px");
    $("#contentArea").show();
    $("#ajaxDiv").stop();
    $("#ajaxDiv").load(controlToLoad, { SectionId: sectionId }, function() {
        $("#ajaxDiv").show();
        var height = $("#popupControlWrapper").height() + 20;
        if (height < 260) {
            height = 260;
        }
        var offset = $("#" + divname).offset();

        var left = offset.left;
        var top = offset.top;
        var width = "440";
        switch (direction) {
            case "TopLeft":
                top = top;
                setPopupDivPosition(top, left);
                break;
            case "TopRight":
                top = top;
                setPopupDivPosition(top, left + $("#" + divname).width());
                left = ((left + $("#" + divname).width()) - width);
                left = left + 1;
                break;
            case "BottomLeft":
                setPopupDivPosition(top + $("#" + divname).height(), left);
                top = (top + $("#" + divname).height() - height);
                break;
            case "BottomRight":
                setPopupDivPosition(top + $("#" + divname).height(), left + $("#" + divname).width());
                top = (top + $("#" + divname).height() - height);
                left = ((left + $("#" + divname).width()) - width);
                left = left + 1;
                break;
        }
        $('#btnClose').click(function() {
            closePopup(sectionId, type, direction, divname); return false;
        });
        if (type == "Search") {
            $('#btnCloseSearch').click(function() {
                closePopup(sectionId, type, direction, divname); return false;
            });
        }
        expandDiv(width, left, top, height, "slow");
        var backgroundColor = $("#" + divname).css("background-color");

        $(".searchBoxesWrapper").css("background-color", backgroundColor);
        $("#ajaxDiv").css("background-color", backgroundColor);
        $(".buttons").corner("round");
        $("#ajaxDiv").corner("round");        
    });
}

function closePopup(sectionId, type, direction, divname) {
    $("contentArea").hide();
    $(".black_overlay").hide();
    var width = 440
    var height = 0;
    var offset = $("#" + divname).offset();
    var left = offset.left;
    var top = offset.top;
    switch (direction) {
        case "TopLeft":
            top = top;
            width = 0;
            break;
        case "TopRight":
            top = top;
            left = (left + $("#" + divname).width());
            width = 0;
            break;
        case "BottomLeft":
            top = top + $("#" + divname).height();
            width = 0;
            break;
        case "BottomRight":
            top = top + $("#" + divname).height();
            left = left + $("#" + divname).width();
            width = 0;
            break;
        default:
            break;
    }
    expandDiv(width, left, top, height, "slow");
    $("#ajaxDiv").empty();
}

function showEditorial(div) {
    $("#pnlSearchResults").hide();
    $("#pnlViewRecord").show();
    $("#" + div).show();
}

function hideMe(totalDiv) {
    var totalRecords = $("#" + totalDiv).val();
    var i = 0;
    while (i <= totalRecords) {
        $("#" + i).hide();
        i = i + 1;
    }
    $("#pnlSearchResults").show();
    $("#pnlViewRecord").hide();
}


function showmenu(sectionId, type, backgroundcolor) {
    var controlToLoad = ""
    controlToLoad = GetControlToLoad(type);
    var _height = $("body").height();
    var _width = $("body").width();
    _height = _height + 100;
    $(".black_overlay").css("height", _height);
    $(".black_overlay").css("width", _width);
    $(".black_overlay").show(); 
    $("#contentArea").css("width", _width);    
    $("#contentArea").show();
    var transBorder = RUZEE.ShadedBorder.create({ corner: 15, border: 8, borderOpacity: 0.5 }); 
    var innerWrapper = $(".leftSideWrapper");
    if (innerWrapper.offset() == null) {
        innerWrapper = $(".homepagetopleft");
    }
    $("#ajaxDiv").load(controlToLoad, { SectionId: sectionId }, function() {

        $("#ajaxDiv").show();

        var height = $("#popupControlWrapper").height() + 20;
        if (height < 260) {
            height = 260;
        }
        var offset = innerWrapper.offset();
        var left = offset.left + 50;
        var top = offset.top + 50;
        var width = 440;
        setPopupDivPosition(top, left);
        $('#btnClose').click(function() {
            closePopup(sectionId, type, "CloseExpanded", "ajaxDiv"); return false;
        });
        if (type == "Search") {
            $('#btnCloseSearch').click(function() {
                closePopup(sectionId, type, "CloseExpanded", divname); return false;
            });
        }
        $("#ajaxDiv").width(width)
        $("#ajaxDiv").height(height)
        expandDiv(width, left, top, height, "slow");
        transBorder.render('ajaxDiv');
        $(".sb-inner").css("background-color", backgroundcolor);
        $(".repeaterContainer").css("margin-left", "30px");
        $(".searchBoxesWrapper").css("background-color", backgroundcolor);
        $(".buttons").corner("round");
    });
}


$(document).ready(function() {
    $(".outerExtrasWrapper").corner("round br bl");
    $(".extrasOuterHeader").corner("round tr tl");
    $(".TopTipsOuterHeaderWrapper").corner("round tr tl");
    $(".TopTipsOuterWrapper").corner("round br bl");
    $("#blogBlobWrapper").corner("round");
    $(".chapterControl").corner("round");
    $("#buyCopyWrapper").corner("round");
    $(".TheFactsTop").corner("round tr tl");
    $(".TheFactsBottom").corner("round br bl");
    $(".AZProfileWrapper").corner("round");
    $(".SmallBoxes").corner("round");
    $(".bulletList").corner("round");
    $(".buttons").corner("round");
    $("#findtraining .sectioncontrolwrapper").corner("round");
    $(".searchBarRight .SmallBoxes").corner("round");
    $("#searchBarWrapper").corner("round");
}); 
