﻿/// <reference path='jquery-1.2.6-vsdoc.js' />

var Side_Column_Offset = -10;
var li_has_click = false;
var id_active_mem;
var id_active = '';
var activeElem = null;
var is_first = false;
var select_in_Line = false;
var clicked_input = false;

$("document").ready(function() {
    $('#frmExpertReg').showErrorMessages({});
    
    $(".controlSet :input").blur(function() {
        $(this).parents("li").removeClass("activeControlLine");
        $('.focusOn').removeClass("focusOn");
    }).focus(function() {
        var focused_li = $(this).parents("li.ControlLine").attr("id");
        var id = getNrFromId(focused_li);
        var $this = $(this);

        id_active_mem = id;
        if (0 != $("*[id='frmMsg__" + id + "']").length) {
            showTooltipBox(id);
            id_active = id;
        }
        else {
            showTooltipBox("none");
        }
        $(".controlSet li.ControlLine").removeClass("activeControlLine");
        $(this).parents("li.ControlLine").addClass("activeControlLine");
        $(".focusOn").removeClass("focusOn");
        $(this).parents("li.ControlLine").addClass("focusOn");
        $(this).addClass("txtBox");
    });

    $(".ControlLine input").bind("click", function() {
        clicked_input = true;
    });

    $(".controlSet li[id^='ln__']").mouseover(function(e) {
        $(".tip").hide();
        if ($(this).hasClass('errorTxt')) {
            showTooltipBox("none");
        }
        else {
            var id = getNrFromId($(this).attr("id"));
            if (undefined == id) {
                return;
            }
            $(this).addClass("activeControlLine");
            if (0 == $("*[id='frmMsg__" + id + "']").length) {
                showTooltipBox("none");
                return;
            }
            else {
                showTooltipBox(id);
                id_active = id;
            }
        };
    }).mouseout(function() {
        $(".tip").hide();
        showTooltipBox("none");
        $(this).removeClass("activeControlLine");
        li_has_click = false;
        id_active = '';
        var t2;
        clearTimeout(t2);
        t2 = setTimeout(function() { if ('' == id_active) { showTooltipBox(id_active_mem); }; }, 600);
    });

    $("body").click(function() {
        if (false == li_has_click) {
            $(".controlSet li").removeClass("activeControlLine");
            $(".controlSet li span").removeClass("focused");
            $(".tip").hide();
            showTooltipBox("none");
            id_active_mem = "";
        };
    });

    $("#firstColumn").find("form").each(function() {
        $(this).find("li[id^='ln__']").each(function() {
            if (false == is_first) {
                $(this).click();
                is_first = true;
            }
        });
    });

    $(".commonButton").hover(
        function() { $(this).addClass("commonButtonhover"); },
        function() { $(this).removeClass("commonButtonhover"); }
    );

   
});

function showTooltipBox(id) {
    if (id == "none") {
        $(".tip").hide();
        return;
    };
    $(".tip .tipContainer").hide();
    if (0 != $("*[id='frmMsg__" + id + "']").length) {
        $("*[id='frmMsg__" + id + "']").show();
        var el = $("li[id='ln__" + id + "']");
        if (el) {
            var coords = getElementCoordinate(el);
            if (coords) {
                $(".tip").css("margin-top", coords[1] - Side_Column_Offset + "px");
                $(".tip").show();
            };
        };
    };
};
function getNrFromId(mystring) {
    if (mystring) {
        var myarray = mystring.split(/__/);
        return myarray[1];
    }
    else {
        return "";
    };
};

function getElementCoordinate(element) {
    if (null == $(element).html()) {
        return;
    };
    var coords = [];
    if ($("#firstColumn").size() >= 1) {
        var mainLeft = Math.round(($("#firstColumn").position().left));
        var mainTop = Math.round(($("#firstColumn").position().top));
        coords[0] = Math.round(($(element).position().left) - mainLeft);
        coords[1] = Math.round(($(element).position().top) - mainTop);
    };
    return coords;
};

$.fn.showErrorMessages = function() {
    showErrorMessages = function(objID, errMsgID) {
        $(objID).parents("li").removeClass('ControlLine').addClass("errorRow");
        alert($(errMsgID).attr('id'));
        $(errMsgID).addClass('errorTxt').fadeIn('slow');
        $(errMsgID).css('display', 'block');
    }

    hideErrorMessages = function(objID, errMsgID) {
        alert('HIDE :' + errMsgID);
        $(objID).parents("li").removeClass('errorRow').addClass("ControlLine");
        $(errMsgID).addClass('errorTxt').fadeOut('slow');
        $(errMsgID).css('display', 'none');
    }
};




