
function getLightboxCookie(c_name) {
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function setLightboxCookie(c_name,value,expiredays) {
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function showLightbox() {
var display;    
var lightbox;
lightbox=getLightboxCookie('lightbox');
if (lightbox!=null && lightbox!="")
  {
       display='none';

  }
  else 
  {
    display='block';
    setLightboxCookie('lightbox',display,365);
  }
  document.getElementById('lightbox').style.display=display;    
}

function ClickPopup(markupHead, modelTrigger) {
    this.savedPopup = jQuery(markupHead).remove();
    this.parentTag = jQuery(modelTrigger);
    var thisObject = this;

    this.mouseClick = function() {
        thisObject.savedPopup.clone().appendTo("body");
        thisObject.setPosition(jQuery(this));
        jQuery(markupHead).show();
        return false;
    };
    
    this.hide = function() {
        jQuery(markupHead).remove();
    };
    
    this.getRequiredTooltipPosition = function(parentElem) {
        return {
            left: parentElem.offset().left + parentElem.outerWidth(),
            top: parentElem.offset().top + parentElem.outerHeight()
        };
    };
    
    this.setPosition = function(parentElem) {
        var requiredPosition = thisObject.getRequiredTooltipPosition(parentElem);
        var mainWindow = jQuery(window);
        var currentPopup = jQuery(markupHead);
        
        if (requiredPosition.top + currentPopup.outerHeight() > mainWindow.scrollTop() + mainWindow.height()) {
            requiredPosition.top -= currentPopup.outerHeight() + parentElem.outerHeight();
        }
        
        if (requiredPosition.top < 25) {
            requiredPosition.top = 25;
        }
        
        if (requiredPosition.left + currentPopup.outerWidth() > mainWindow.scrollLeft() + mainWindow.width()) {
            requiredPosition.left -= currentPopup.outerWidth() + parentElem.outerWidth();
        }
        
        currentPopup.css({
            'left': requiredPosition.left + 'px',
            'top': requiredPosition.top + 'px'
        });
    };
    
    this.parentTag.click(this.mouseClick);
}


var qfhost = 'http://qualifiedfirst.verifiedcredentials.com';

function getWindowHeight() {
	return { windowHeight: $(window).height(), iframeTop: jQuery("#qualifiedfirst_frame").offset().top, scrollTop: $(window).scrollTop() };
}

function searchHint(e,o){
    if(o.firstTime){return}
       o.firstTime=true
       o.value=""
}

    jQuery(document).ready(function() {
//        jQuery('#qualifiedfirst_frame').attr('src', qfhost + '/External'); //

jQuery('#topBarGo').click(function() {
    var code = jQuery('#enterCode').find(':text:eq(0)').val() + '-' + jQuery('#enterCode').find(':text:eq(1)').val();

    jQuery.ajax(
    {
        type: "GET",
        url: qfhost + "/External/ValidateCode/" + code,
        dataType: "jsonp",
        cache: false,
        success: function(data) {
            if (data["CodeType"] == 'SHC') {
                if (data.Valid == "True") {
                    parent.location = qfhost + '/Share/' + code;
                }
                else {
                    $("#InvalidCode").show();
                }
            }
            else if (data["CodeType"] == 'PSC') {
                if (data.Valid == "True") {
                    parent.location = qfhost + "/BackgroundCenter/CreateNewReport?PSetCode=" + code;
                }
                else {
                    $("#InvalidCode").show();
                }
            }
            else {
                $("#InvalidCode").show();
            }

        },
        error: function(xhr, ajaxOptions, thrownError)
        { alert("Sorry, unexpected error."); }
    });
    
    return false;
});


jQuery('#footerGo').click(function() {
    var code = jQuery('.ident').find(':text:eq(0)').val() + '-' + jQuery('.ident').find(':text:eq(1)').val();

    jQuery.ajax(
    {
        type: "GET",
        url: qfhost + "/External/ValidateCode/" + code,
        dataType: "jsonp",
        cache: false,
        success: function(data) {
            if (data["CodeType"] == 'SHC') {
                if (data.Valid == "True") {
                    parent.location = qfhost + '/Share/' + code;
                }
                else {
                    $("#InvalidCode").show();
                }
            }
            else if (data["CodeType"] == 'PSC') {
                if (data.Valid == "True") {
                    parent.location = qfhost + "/BackgroundCenter/CreateNewReport?PSetCode=" + code;
                }
                else {
                    $("#InvalidCode").show();
                }
            }
            else {
                $("#InvalidCode").show();
            }

        },
        error: function(xhr, ajaxOptions, thrownError)
        { alert("Sorry, unexpected error."); }
    });
    
    return false;
});


jQuery('#formGo').click(function() {
    var code = jQuery('#STP_R').find(':text:eq(0)').val() + '-' + jQuery('#STP_R').find(':text:eq(1)').val();

    jQuery.ajax(
    {
        type: "GET",
        url: qfhost + "/External/ValidateCode/" + code,
        dataType: "jsonp",
        cache: false,
        success: function(data) {
            if (data["CodeType"] == 'SHC') {
                if (data.Valid == "True") {
                    parent.location = qfhost + '/Share/' + code;
                }
                else {
                    $("#InvalidCode").show();
                }
            }
            else if (data["CodeType"] == 'PSC') {
                if (data.Valid == "True") {
                    parent.location = qfhost + "/BackgroundCenter/CreateNewReport?PSetCode=" + code;
                }
                else {
                    $("#InvalidCode").show();
                }
            }
            else {
                $("#InvalidCode").show();
            }

        },
        error: function(xhr, ajaxOptions, thrownError)
        { alert("Sorry, unexpected error."); }
    });
    
    return false;
});


    });
function ClientSidePopup(content, parentE) {

    this.rnd = null;
    this.content = content;
    this.parentE = parentE;
    this.currentPopup = null;
    
    var thisObject = this;

    this.init = function() {
        //debugger;
        this.rnd = parseInt(Math.random() * 10000);
        this.currentPopup = '\
<div id="popupElement' + this.rnd + '" class="hint" style="display: none; position:absolute;"> \
    <div class="hint-top">&nbsp;</div> \
    <div class="hint-bottom">&nbsp;</div> \
    <div> \
        <a href="#" style="float:right" onclick="$(\'#popupElement' + this.rnd + '\').hide(); return false;"> \
            <img src="/Websites/verifiedcredentials/templates/verifiedcredentials/Img/closePopUp.png" align="left" style="position:absolute; right:33px; top:-7px" alt=""/> \
        </a> \
        <img src="/Websites/verifiedcredentials/templates/verifiedcredentials/Img/icon-help.png" align="left" width="51" height="38" alt=""/> \
        ' + this.content + ' \
    </div> \
</div> \
    ';

        $("body").append(this.currentPopup);

        $(this.parentE).click(this.mouseClick);
    };

    this.mouseClick = function() {
        thisObject.open();
        return false;
    };

    this.open = function() {
        //debugger;
		$("div[id^=popupElement]").hide();
        var e = $("#popupElement" + this.rnd);
        var p = $(this.parentE);
        this.setPosition(p);
        e.show();
    };

    this.close = function() {
        $("#popupElement" + this.rnd).hide();
    };

    this.getRequiredTooltipPosition = function(parentElem) {
        return {
            left: parentElem.offset().left + parentElem.outerWidth(),
            top: parentElem.offset().top + parentElem.outerHeight()
        };
    };

    this.setPosition = function(parentElem) {
        var requiredPosition = this.getRequiredTooltipPosition(parentElem);
        var mainWindow = $(window);
        var currentPopup = $("#popupElement" + this.rnd);

        if (requiredPosition.top + currentPopup.outerHeight() > mainWindow.scrollTop() + mainWindow.height()) {
            requiredPosition.top -= currentPopup.outerHeight() + parentElem.outerHeight();
        }

        if (requiredPosition.top < 25) {
            requiredPosition.top = 25;
        }

        if (requiredPosition.left + currentPopup.outerWidth() > mainWindow.scrollLeft() + mainWindow.width()) {
            requiredPosition.left -= currentPopup.outerWidth() + parentElem.outerWidth();
        }

        currentPopup.css({
            'left': requiredPosition.left + 'px',
            'top': requiredPosition.top + 'px'
        });
    };

};

$(document).ready(function() {
        var popupElementc1 = new ClientSidePopup('<h2>&nbsp;&nbsp;What is a code?</h2><br><br><p><strong>There are two types of codes:</strong><br><br><strong>Requirements Code:</strong><br>This code is given to a user by an organization or person who has asked the user to complete a series of requirements for a given qualification process. Each qualification process is assigned a unique code. Users enter the code and are guided through an easy, step-by-step process to help them complete the mandatory requirements established by the requestor.<br><br><strong>Sharing Code:</strong><br>            This code is typically given to a user by another person in effort to share information contained in their personal QualifiedFirst portfolio, such as their background report, professional qualifications, and more. The Users enter the code and can view the shared information securely within their QualifiedFirst account. If the user does not have a QualifiedFirst account, they can open a FREE account in a matter of minutes.<br></p>', '#what_is_this_link');
        popupElementc1.init();
        var popupElementc2 = new ClientSidePopup('<h2>&nbsp;&nbsp;Forgot your code?</h2><br><br><p>In effort to safeguard our customer&#39;s confidential information, codes can only be recovered from the source that originally supplied them. To obtain your code, check your records or contact the person or organization that gave you the code.</p>', '#forgotten_code_link');
        popupElementc2.init();
        var popupElementc3 = new ClientSidePopup('<h2>&nbsp;&nbsp;What is a code?</h2><br><br><p><strong>There are two types of codes:</strong><br><br><strong>Requirements Code:</strong><br>This code is given to a user by an organization or person who has asked the user to complete a series of requirements for a given qualification process. Each qualification process is assigned a unique code. Users enter the code and are guided through an easy, step-by-step process to help them complete the mandatory requirements established by the requestor.<br><br><strong>Sharing Code:</strong><br>            This code is typically given to a user by another person in effort to share information contained in their personal QualifiedFirst portfolio, such as their background report, professional qualifications, and more. The Users enter the code and can view the shared information securely within their QualifiedFirst account. If the user does not have a QualifiedFirst account, they can open a FREE account in a matter of minutes.<br></p>', '#what_is_this_link_side');
        popupElementc3.init();
        var popupElementc4 = new ClientSidePopup('<h2>&nbsp;&nbsp;Forgot your code?</h2><br><br><p>In effort to safeguard our customer&#39;s confidential information, codes can only be recovered from the source that originally supplied them. To obtain your code, check your records or contact the person or organization that gave you the code.</p>', '#forgotten_code_link_side');
        popupElementc4.init();
        var popupElementc5 = new ClientSidePopup('<h2>&nbsp;&nbsp;What is a code?</h2><br><br><p><strong>There are two types of codes:</strong><br><br><strong>Requirements Code:</strong><br>This code is given to a user by an organization or person who has asked the user to complete a series of requirements for a given qualification process. Each qualification process is assigned a unique code. Users enter the code and are guided through an easy, step-by-step process to help them complete the mandatory requirements established by the requestor.<br><br><strong>Sharing Code:</strong><br>            This code is typically given to a user by another person in effort to share information contained in their personal QualifiedFirst portfolio, such as their background report, professional qualifications, and more. The Users enter the code and can view the shared information securely within their QualifiedFirst account. If the user does not have a QualifiedFirst account, they can open a FREE account in a matter of minutes.<br></p>', '#what_is_this_link_ftr');
        popupElementc5.init();
        var popupElementc6 = new ClientSidePopup('<h2>&nbsp;&nbsp;Forgot your code?</h2><br><br><p>In effort to safeguard our customer&#39;s confidential information, codes can only be recovered from the source that originally supplied them. To obtain your code, check your records or contact the person or organization that gave you the code.</p>', '#forgotten_code_link_ftr');
        popupElementc6.init();
});

$(document).ready(function() {
    $('.codeinput').keydown(function(e) {        
        if (e.keyCode === 13) {
            e.preventDefault();
            if ($('.codeinput:eq(0)').val !== '' || $('.codeinput:eq(1)').val !== '')
                $('#topBarGo').click();
            else
                $('#footerGo').click();
        }
    });
});

/*
$(document).ready(function() {
        $('#enterCode.codeinput').keydown(function(e) {
            var code = (e.keyCode ? e.keyCode : e.which);
            if (code == 13) {
                if ($('#enterCode.codeinput:eq(0)').val != '' || $('#enterCode.codeinput:eq(1)').val != '')
                    $('topBarGo').click();
            }
        });
        $('#STP_R.codeinput').keydown(function(e) {
            if (e.keyCode == '13') {
                if ($('#STP_R.codeinput:eq(0)').val != '' || $('#STP_R.codeinput:eq(1)').val != '')
                    $('#formGo').click();
            }
        });
        $('#footer.codeinput').keydown(function(e) {
            if (e.keyCode == '13') {
                if ($('#footer.codeinput:eq(0)').val != '' || $('#footer.codeinput:eq(1)').val != '')
                    $('#footerGo').click();
            }
        });
});
*/
/*
$(document).ready(function() {

                $('#enterCode.codeinput:eq(0)').keydown(function(e) {
                    if (e.keyCode == '13')
            e.preventDefault();
                });
    
                $('#enterCode.codeinput:eq(1)').keydown(function(e) {
                                if (e.keyCode == '13')
            e.preventDefault();
                });

                $('#enterCode.codeinput:eq(2)').keydown(function(e) {
                                if (e.keyCode == '13')
            e.preventDefault();
                });

                $('#enterCode.codeinput:eq(3)').keydown(function(e) {
                                if (e.keyCode == '13')
            e.preventDefault();
                });

                $('#enterCode.codeinput:eq(2)').keyup(function(e) {
                                if (e.keyCode != '13')
            $('#enterCode.codeinput:eq(0)').val($(this).val());
                });

                $('#enterCode.codeinput:eq(3)').keyup(function(e) {
                                if (e.keyCode != '13')
            $('#enterCode.codeinput:eq(1)').val($(this).val());
                });
});
*/

