/*
 * label2value
 * jquery based script for using form labels as text field values
 * more info on http://cssglobe.com/post/1500/using-labels- 
 *
 * Copyright (c) 2008 Alen Grakalic (cssglobe.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 */
 
 this.label2value = function(){ 

    var inactive = "inactive";
    var active = "active";
    var focused = "focused";
    
    $("label").each(function(){     
        obj = document.getElementById($(this).attr("for"));
        if(($(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){           
            var text = $(this).text();
            $(this).css("display","none");  
                    
            if($(obj).val() == "") {          
                $(obj).val(text);
            }
            $(obj).addClass(inactive);          
            if($(obj).val() != text) {          
                $(obj).removeClass(inactive);
            }
            
            $(obj).focus(function(){    
                $(this).addClass(focused);
                $(this).removeClass(inactive);
                $(this).removeClass(active);                                  
                if($(this).val() == text) $(this).val("");
            }); 
            $(obj).blur(function(){ 
                $(this).removeClass(focused);                                                    
                if($(this).val() == "") {
                    $(this).val(text);
                    $(this).addClass(inactive);
                } else {
                    $(this).addClass(active);       
                };              
            });             
        };  
    });     
};
$(document).ready(function(){   
    label2value();  
});



function validate(f) {
    for(i=0;i<f.elements.length;i++) {
        var v=f.elements[i].value;
        var c=f.elements[i].className;
        if(c.indexOf("inactive")!="-1") {
            f.elements[i].value="";
            }
        }
};