﻿var animateEl = null;
var focusEl = null;

function FocusInput(id, isControl)
{
    if (isControl)
    {
        var control = ISGetObject(id);
        control.SetFocus();
    }
    else
    {
        document.getElementById(id).focus();
    }
}

function ValidateFocus(el, focus)
{
    animateEl = el;
    focusEl = focus;
    Animation.Do(el, "AnimateColor", null, function()
    {
        OnCompleteFocus();
    },
        { "FromColor": "#FDAAAA", "ToColor": "#FFFFFF", "MaxStep": 20, "Speed": "VerySlow" });
}

function OnCompleteFocus()
{
    Animation.Do(animateEl, "AnimateColor", null, function() { },
        { "FromColor": "#FFFFFF", "ToColor": "#FDAAAA", "MaxStep": 20, "Speed": "VerySlow" });
      
    if (typeof(focusEl.tagName) != "undefined")
    {
        if (focusEl.tagName == "INPUT")
            focusEl.focus();
    }
    else
        focusEl.SetFocus();
}

function ValidateAnimation(el)
{
    animateEl = el;
    Animation.Do(el, "AnimateColor", null, function()
    {
        OnComplete();
    },
        { "FromColor": "#FDAAAA", "ToColor": "#FFFFFF", "MaxStep": 20, "Speed": "VerySlow" });
}

function OnComplete()
{
    Animation.Do(animateEl, "AnimateColor", null, function() { },
        { "FromColor": "#FFFFFF", "ToColor": "#FDAAAA", "MaxStep": 20, "Speed": "VerySlow" });
    
    if (animateEl != null && animateEl.tagName == "INPUT")
        animateEl.focus();
}

function ChangeColorNormal(el)
{
    if (el.style.backgroundColor != "#FFFFFF")
        el.style.backgroundColor = "#FFFFFF";
}

function RegexCheck(txt)
{
    var pattern = "";
    var complexity;

    if (txt.length > 5)
        pattern += "L";

    if (txt.match(/\d/))
        pattern += "C";

    if (txt.match(/[a-z]/))
        pattern += "C";

    if (txt.match(/[A-Z]/))
        pattern += "C";

    if (txt.match(/\W/))
        pattern += "C";

    if (pattern == "LCC" || pattern == "LCCC")
        complexity = "medium";
    else if (pattern == "LCCCC")
        complexity = "strong";
    else
        complexity = "weak";

    return complexity;
}

function RetypepassCheck(pass1, pass2)
{
    if (pass1 == pass2)
        return true;

    return false;
}

function ValidateEmail(str)
{
    var filter = /^.+@.+\..{2,3}$/

    if (!str.match(/\s+/g))
    {
        if (filter.test(str))
            testresults = true;
        else
            testresults = false;
    }
    else
        testresults = false;

    return testresults;
}

function ValidationMessage(type, message)
{
    var builder = new StringBuilder();

    if (type != "error")
        builder.Append("<div class='statusbox'>");
    else
        builder.Append("<div class='statuserrorbox'>");

    builder.Append(message);
    builder.Append("</div>");

    return builder.ToString();
}

function ShowMessage(id, type, message)
{
    var message = ValidationMessage(type, message)
    var status = document.getElementById(id);

    status.innerHTML = message;
    status.style.display = "";
}


var selectedTopic = "";

var activeManual;

if (document.getElementById('hdnManualID') == null || document.getElementById('hdnManualID').value == "")
    activeManual = "Introduction";
else
{
    if (document.getElementById('hdnManualID').value != "")
        activeManual = document.getElementById('hdnManualID').value;
}

var activeTopic;
if (document.getElementById('hdnTopicID') != null)
    activeTopic = document.getElementById('hdnTopicID').value;
else
    activeTopic = "";


function ShowManual(manualID, topicID)
{
    event.returnValue = false;
    event.cancelBubble = true;

    var fpb = ISGetObject("WebFlyPostBackManager1");
    fpb.ClientSideEvents.OnResponseCompleted = FPBMManual_OnResponseCompleted;
    fpb.FPMBShowManual(manualID, topicID);
    selectedTopic = topicID;
    document.getElementById("loader").style.display = "";

    var manualListContainer = document.getElementById("manualList");

    var styleName;
    //debugger
    if (topicID == "")
    {
        if (activeManual != manualID)
        {
            document.getElementById("man_" + manualID).className = "manual1 over";
            styleName = document.getElementById("man_" + activeManual).className;
            var styleName = styleName.replace("over", "");
            document.getElementById("man_" + activeManual).className = styleName;
            activeManual = manualID;
        }
    }
    else
    {
        if (activeManual != topicID)
        {
            document.getElementById("man_" + topicID).className = "manual2 over";
            styleName = document.getElementById("man_" + activeManual).className;
            var styleName = styleName.replace("over", "");
            document.getElementById("man_" + activeManual).className = styleName;
            activeManual = topicID;
        }
        if (activeTopic != topicID && activeTopic != "")
        {
            document.getElementById("man_" + topicID).className = "manual2 over";
            styleName = document.getElementById("man_" + activeTopic).className;
            var styleName = styleName.replace("over", "");
            document.getElementById("man_" + activeTopic).className = styleName;
            //activeManual = topicID;
        }
    }
    activeTopic = topicID;
}

function FPBMManual_OnResponseCompleted(controlId, method, returnValue)
{
    //Animation.Do(document.getElementById('MultiView1'), "FadeIn", 7, null);
    if (selectedTopic != "")
    {
        SetFocusToTopic(selectedTopic);
    }
    document.getElementById("loader").style.display = "none";

    return true;
}
