﻿// JScript File

function inpFocus(inpId)
{
    var inpLabel = document.getElementById(inpId+"_label").innerHTML;
    if (inpEmpty(inpId))
        document.getElementById(inpId).select();
        //document.getElementById(inpId).value = '';
    $('#'+inpId).removeClass("default-val");
    $('#'+inpId).addClass("user-val");
}

function inpClear(inpId)
{
    var inpLabel = document.getElementById(inpId+"_label").innerHTML;
    if (inpEmpty(inpId))
        document.getElementById(inpId).value = '';
}

function inpBlur(inpId)
{
    var inpLabel = document.getElementById(inpId+"_label").innerHTML;
    document.getElementById(inpId+"_label").style.display = "none";
    if (inpEmpty(inpId))
    {
        $('#'+inpId).removeClass("user-val");
        $('#'+inpId).addClass("default-val");
        document.getElementById(inpId).value = inpLabel;
    }
    else
    {
        $('#'+inpId).removeClass("default-val");
        $('#'+inpId).addClass("user-val");
    }
}

function inpEmpty(inpId)
{
    var inpLabel = document.getElementById(inpId+"_label").innerHTML;
    var inpValue = document.getElementById(inpId).value;
    return (inpValue == '' || inpValue == inpLabel);
}

jQuery.fn.labelTextbox = function() {
return this.each(function()
  {
    inpBlur($(this).attr("id"));
    $(this).focus(function() {
        inpFocus($(this).attr("id"))
        //$(this).labeledTextboxFocus();
    });
    
    $(this).blur(function() {
        inpBlur($(this).attr("id"))
    });
  });
};

jQuery.fn.labelClearBeforeSubmit = function() {
  return this.each(function(){
    inpClear($(this).attr("id"));
  });
};

/*
jQuery.fn.labeledTextboxFocus = function() {
  return this.each(function(){
    //alert('hey');
    var inpLabel = $($(this).attr("id")+"_label").html();
    alert(inpLabel);
    if ($(this).value == inpLabel)
        $(this).value = '';
//    document.getElementById(inpId).style.fontWeight = 'bold';
  });
}*/
