﻿function ValidateIncludeService(sender, arguments) {
    arguments.IsValid = ValidateCheckBoxList("include");
}


function ValidateCheckBoxList(key) {
    var result = false;
    $("table[key='" + key + "']").find(":checkbox").each(function() {
        if ($(this).attr("checked") == true) {
            result = true;
            return;
        }
    });
    return result;
}
function ProgramValidate(sender, arguments) {

    var content = tinyMCE.activeEditor.getContent();
    if (content == "<html />" || content == "")  {
        arguments.IsValid = false;
    }
    else {
        arguments.IsValid = true;
    }
}
function ValidateCountryResort(sender, arguments) {
    var ctrl = $("input[id$='hfCRHidden']");
    arguments.IsValid = $(ctrl).val() != "0";
}

function ValidateDate(sender, arguments) {
    var value = $("input[id$='txtDateStart']").val();
    if (value == "" || value == undefined)
    {
        arguments.IsValid = true;
    }
    else
    {
        var date  = StrToDate(value);
        var currDate = new Date();
        arguments.IsValid = date > currDate;
    }  
}

function StrToDate(Dat) {
    var year = Number(Dat.split(".")[2])
    var month = Number(Dat.split(".")[1] - 1)
    var day = Number(Dat.split(".")[0])
    var dat = new Date(year, month, day)
    return dat
}

function SetActiveTour(control, id) {
    var checked = $(control).attr('checked');
    var dataParams = '{"isChecked" : "' + $(control).attr('checked') + '", "tourOfferId" : "' + id + '"}';
    $.ajax({
        type: "POST",
        url: "/site/WebServices/Tour.asmx/SetActiveTour",
        contentType: "application/json; charset=utf-8",
        data: dataParams,
        dataType: "json",
        success: function(dataObj) {
            var result = dataObj.d;
            if (result != "") {
                alert(result);
                $(control).attr('checked', !checked);
            }
        },
        error: function() { alert('Server Error') }
    });
}
