﻿// validateValidators
function Validate(validatorsArray) {
    var isvalid = true;
    for (var i = 0; i < validatorsArray.length; i++) {
        ValidatorEnable($get(validatorsArray[i]), true);
        if (!$get(validatorsArray[i]).isvalid)
            isvalid = false;
      
    }
    return isvalid;
};
//validate all asp.net validators with specified css class
function ValidateCss(cssName) {
    var isvalid = true;
    $('.' + cssName).each(function () {
        ValidatorEnable($get($(this).attr('id')), true);
        if (!$get($(this).attr('id')).isvalid)
            isvalid = false;
    });
    return isvalid;
};
/* set date time funcionality to html input element
   Example: setDateTimeToTextBox('textboxid', 'dd-mm-yy','he');
*/
 var calander_icon_url = "graphics/images/Calendar.png";
function setDateTimeToTextBox(textboxid, dateformat) {
$("#" + textboxid).datepicker({
showOn: "button",
 buttonImage: calander_icon_url,
buttonImageOnly: false,
dateFormat: dateformat
});

};
//region datepicker overload
function setDateTimeToTextBox(textboxid, dateformat, region) {
    $("#" + textboxid).datepicker({
        showOn: "button",
        regional: region,
        buttonImage: calander_icon_url,
        buttonImageOnly: false,
        isRTL: true,
        showButtonPanel: true,
        dateFormat: dateformat
    });

}
//region datepicker overload
function setDateTimeToTextBox(textboxid, dateformat, region, noimage) {
    $("#" + textboxid).datepicker({
        regional: region,
        isRTL: true,
        showButtonPanel: true,
        dateFormat: dateformat
    });

}
//region datepicker overload with mindate
function setDateTimeToTextBox(textboxid, dateformat, region, mindate, noimage) {
    $("#" + textboxid).datepicker({
        regional: region,
        isRTL: true,
        showButtonPanel: true,
        minDate: mindate,
        dateFormat: dateformat
    });

}

// set only one checkbox selected at time   
function setOnlyOneCheckBox(containerid) {
var container = $("#" + containerid + " [type=checkbox]");
container.attr('checked', false);  //reset tradelist checkboxes
container.each(function () {
$(this).click(function () {

OnlyOneCheckBoxClickHandler($(this), containerid);
});

});

}

//reset container
function resetContainerById(containerid) {
    var container = $('#' + containerid);
    container.find('checkbox').removeAttr('checked'); //reset checkbox
    container.find('textarea').text('');
    container.find('[type=text]').val('');
    container.find('select').attr('selectedIndex', 0);
};


// TextBoxExtender - jquery -only number
function filterTextBoxOnlyNumbers(textbox_classid) {
$("." + textbox_classid).keypress(function (event) {
var keyVal = (event.charCode ? event.charCode : ((event.keyCode) ? event.keyCode : event.which));
if ((keyVal > 48 && keyVal < 57))// Numbers
{
return true;
}
else
return false;
});

};

//Populate DropDownList
function populateDropDownList(ddl_id, handler_url) {
var options = $("#" + ddl_id);
$("#" + ddl_id + "> option").remove(); //remove all items

$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: handler_url,
dataType: "json",
success: function (data) {

$.each(data, function (i, data, key) {
options.append('<option value="' + i + '">' + data + '</option>');
});


}
});

};
//Populate DropDownList Array
function populateDropDownListArray(ddl_ids, handler_url) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: handler_url,
dataType: "json",
success: function (data) {
for (var i = 0; i < ddl_ids.length; i++) {

var options = $("#" + ddl_ids[i]);
$("#" + ddl_ids[i] + "> option").remove(); //remove all items
$.each(data, function (i, data, key) {
options.append('<option value="' + i + '">' + data + '</option>');
});

}

}
});

};
/* WATERMARK JQ PLUGIN  - get container id and load internal text box watermark text 
should supply title attribute to each watermarked textbox requierd for example : title="First Name" */
function loadWaterMark(contianercss) {
    $('.' + contianercss).find('input[type=text]').each(function () {
        var attr = $(this).attr('watertitle');
        if (typeof attr !== 'undefined' && attr !== false) {
            $(this).val('');
            $(this).watermark($(this).attr('watertitle'));
        }
      $.watermark.options.hideBeforeUnload = false;
    });
}
 

// AJAX JQ EXAMPLE SCRIPT:
//$.ajax({
//    cache: false,
//    url: handlerUrl,
//    data: "&itemtype=" + unescape(item_type)
//                              + "&itemdescription=" + unescape(item_description)
//                              + "&itemname=" + unescape(item_name),
//    context: document.body,
//    success: function (data, textStatus, jqxhr) {
//        MessageBox(changesSuccessfullySaved, expoMessageTitle, promptMessageBoxTimeOut);
//    }
//                        , error: (function () {
//                            MessageBox(changesSuccessfullySaved + "0044", 'message', promptMessageBoxTimeOut);
//                        })
//})

 
