jQuery.noConflict();
jQuery(document).ready(function() {
    Init();
});


//****************************************************************************************************************************************


function Init() {


    //****** contact form validation ******

    /// Save default values from textfields
    jQuery(".contactformcontactinput.contactform.contactinput").find("input:text").each(function(i) {
        eval("inputTypeTextDefVal_" + i + "=this.value;");
    });

    /// Set listeners on radio buttons
    jQuery(".contactformcontactselectors.contactform.contactselectors").find("input:radio").click(function() {
        highlightRequiredInputTypeText();
    });

    jQuery(".validationerrormessage").each(function() {
        jQuery(this).hide();
    });

    /// Lav første check ar RADIOS
    //highlightRequiredInputTypeText();


}

function ShowSelectedReasonDescription(idprefix, cssclass, dropdownlist) {

    var value = dropdownlist.value;
    var id = idprefix + value;

    var selector = '.' + cssclass;

    // hide all
    jQuery('.reasondescription').each(function() {
        jQuery(this).hide();
    });
    
    // show selected
    jQuery('.' + id).show();
}


function highlightRequiredInputTypeText() {
    jQuery(".contactformcontactselectors.contactform.contactselectors").find("input:radio").each(function(i) {
        var ele = jQuery(".contactformcontactinput.contactform.contactinput").find(".validationerrormessage")[i];
        ValidatorEnable(ele, this.checked);
//        if (this.checked) {
//            //jQuery(".contactformcontactinput.contactform.contactinput").find('input:text')[i].value = 'REQUIRED';
//            //jQuery(ele).css("color", "#FF0000");
//            jQuery(ele).show();
//        } else {
//            jQuery(ele).hide();
//        }
    });
}

function validateRequiredInputTypeText() {
    var returnValue = false;

    jQuery(".contactformcontactselectors.contactform.contactselectors").find("input:radio").each(function(i) {
        var ele = jQuery(".contactformcontactinput.contactform.contactinput").find("input:text")[i];
        if (this.checked) {
            if (ele.value != eval("inputTypeTextDefVal_" + i) && ele.value != "") {
                //jQuery(ele).css("color", "#000000");

                var span = jQuery(ele).next(".validationerrormessage");
                jQuery(span).hide();

                returnValue = true;
            }
        }
    });

    if (returnValue == false) {
        highlightRequiredInputTypeText();
    }

    return returnValue;
}
