﻿// validateValidators
function Validate(validatorsArray) {
    var isvalid = true;
    for (var i = 0; i < validatorsArray.length; i++) {
        ValidatorEnable(document.getElementById(validatorsArray[i]), true);
        if (!document.getElementById(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(document.getElementById($(this).attr('id')), true);
        if (!document.getElementById($(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
    });

}

// 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);
});

});

}
// 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], textarea').each(function () {
        var attr = $(this).attr('watertitle');
        if (typeof attr !== 'undefined' && attr !== false) {
            $(this).val('');
            $(this).watermark($(this).attr('watertitle'));
        }

        $.watermark.options.hideBeforeUnload = false;
    });
}

function insertStatistic(customerid) {
    var url = window.location;
    var referrer = document.referrer;
    $.ajax({
        cache: false,
        type: 'post',
        url: '/handlers/statistichandler.ashx',
        data: "url=" + unescape(url)
       + "&urlreferr=" + unescape(referrer)
       + "&customerid=" + customerid,
        context: document.body,
        success: null, error: null
    });
};

function getUrlParameterByName(name) {

    var match = RegExp('[?&]' + name + '=([^&]*)')
    .exec(window.location.search);

    return match && decodeURIComponent(match[1].replace(/\+/g, ' '));

}

// 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);
//                        })
//})

 
