/**
 * @author Guillaume Martin
 * 
 * This javascript utility class manage the profile behavior on professions 
 * 
 * Date : 28/03/2008
 * Version 1.0
 */

/*
    TODO: make the display: none sections of the CSS display: block via JS, make them display: none; so that if JS is not on, will still work
*/

$(document).ready( function () {
    $("#professionSection input[type='radio']").click(function () {
        initProfessions($(this).attr('id'));
    });

    $("#select_physicians, #select_healthcare").change( function () {
        initProfessionSelects();
    });

    var initialProfession = $("input[name='userType']:checked").attr('id');
    initProfessions(initialProfession);
    initProfessionSelects();
});

function initProfessions(professionID) {
    $("#professionSection td").removeClass("open");

    if (professionID == 'profession_physicians' || professionID == 'profession_healthcare') {
        $("#" + professionID).parent().parent().addClass("open");
    }


    $(".expandedSection").each(function() {
        if ($(this).parent().hasClass("open")) {
            $(this).slideDown();
        } else {
            $(this).slideUp();
        }
    });

    //setProfessionId();
}

function initProfessionSelects() {
    //setProfessionId();

    if ($("#select_physicians").val() == '120') {
        $("#select_physicians").parent().find(".other").slideDown();
    } else {
        $("#select_physicians").parent().find(".other").slideUp();
    }

    if ($("#select_healthcare").val() == '186') {
        $("#select_healthcare").parent().find(".other").slideDown();
    } else {
        $("#select_healthcare").parent().find(".other").slideUp();
    }
}

function setProfessionId() {
    var selectedRadio = $("input[name='userType']:checked").val();

    if ((selectedRadio == 'PHYS') || (selectedRadio == 'HEPR')) {
        var professionIdValue = 0;
        if ( selectedRadio == 'PHYS' ) { // the input is from the first selection
            professionIdValue = $("#select_physicians").val();
        } else { // the input is from the second selection
            professionIdValue = $("#select_healthcare").val();
        }
        $("input[type='hidden'][name='professionId']").val(professionIdValue);
    } else {
        $("input[type='hidden'][name='professionId']").val(134);
    }

    //alert ( $("input[type='hidden'][name='professionId']").val() );
}


 /*$(document).ready(function() {

	 if (typeof variation == 'undefined' || !variation) {
         if ($("input:radio[name='userType']:checked").val()!="HEPR") {
            $("select[name='professionId']").attr("disabled", "disabled");
            $("input[name='professionId']").removeAttr("disabled");
         }

         $("input:radio[name='userType']").click(function () {

             if ($(this).val()=="HEPR"){
                 $("select[name='professionId']").removeAttr("disabled");
                 $("input[name='professionId']").attr("disabled","disabled");
             } else {
                 $("select[name='professionId']").attr("disabled", "disabled");
                 $("input[name='professionId']").removeAttr("disabled");
             }

        });
     }
 });*/

function emptyIfContent3(lang) {
		
        var valTest_username = $("#usernamePage").val();
        if(valTest_username!="") {
            $("#usernamePage").css("backgroundImage","url(/documents/sitestructure/" + lang + "/resources/images/loginregister/loginfield.jpg)");  
        }
        
        var valTest_password = $("#passwordPage").val();
        if(valTest_password!="") {
            $("#passwordPage").css("backgroundImage","url(/documents/sitestructure/" + lang + "/resources/images/loginregister/loginfield.jpg)");    
        }
        
}

 
 function submitForm(selectedForm) {
	 
	 document.getElementById(selectedForm).submit();
	 return false;
	 
 }
 
 function onloadPageCall(lang) {
	 	var timerPage=setTimeout('emptyIfContent3(\"'+lang+'\")', 500);
	 
	    $("#usernamePage").focus(function () {
	        $(this).css("backgroundImage","url(/documents/sitestructure/" + lang + "/resources/images/loginregister/loginfield.jpg)");
	    });
	    
	    $("#usernamePage").blur(function () {
	        valuetest = $(this).val();
	        if(valuetest=="")
	              $(this).css("backgroundImage","url(/documents/sitestructure/" + lang + "/resources/images/loginregister/loginfield_username.jpg)");    
	        var timer_username=setTimeout("emptyIfContent3('"+lang+"')", 200);
	    }); 
	    
	    $("#passwordPage").focus(function () {
	        $(this).css("backgroundImage","url(/documents/sitestructure/" + lang + "/resources/images/loginregister/loginfield.jpg)");
	    });
	    
	    $("#passwordPage").blur(function () {
	        valuetest = $(this).val();
	        if(valuetest=="")
	              $(this).css("backgroundImage","url(/documents/sitestructure/" + lang + "/resources/images/loginregister/loginfield_password.jpg)");    
	        var timer_username=setTimeout("emptyIfContent3('"+lang+"')", 200);
	    }); 
}
