﻿function DeleteConfirm() {
    return confirm('هل تريد حذف هذا العنصر؟');
}
function clearTextFields() {
    var fields = document.getElementsByTagName("input");
    for (var i = 0; i < fields.length; i++) {
        var field = fields[i];
        if (field != undefined && field.type == 'text') {
            field.value = '';
        }
    }
}
function validateDangerousTags() {
    if (dangerousTextWasFound()) {
        alert('يرجى التأكد من صحة القيم المدخلة داخل الحقول النصية');
        return false;
    }
}
function dangerousTextWasFound() {
    var fields = document.getElementsByTagName("input");
    for (var i = 0; i < fields.length; i++) {
        var field = fields[i];
        if (field != undefined && field.type == 'text') {
            if (isDangerousText(field.value))
                return true;
        }
    }
    return false;
}
function isDangerousText(txt) {
    var regex = new RegExp('<[^>]*>');
    var result = regex.exec(txt);
    if (result != null)
        return true;
    return false;
}
function someValuesAreNotEmpty(fields) {
    for (var i = 0; i < fields.length; i++) {
        var field = fields[i];
        if (field != undefined) {
            if (field.type == 'text' || field.type == 'file' || field.type == 'radio') {
                if (field.type == 'text' || field.type == 'file') {
                    if (field.value != undefined && field.value.length > 0)
                        return true;
                }
                else {
                    if (field.checked != undefined && field.checked)
                        return true;
                }
            }
        }
    }
    return false;
}
function someOptionsAreSelected(fields) {
    for (var i = 0; i < fields.length; i++)
        if (fields[i] != undefined && fields[i].selectedIndex != 0)
        return true;
    return false;
}
function confirmSkip(fieldsAreNotEmpty, optionsAreSelected) {
    if (fieldsAreNotEmpty == true || optionsAreSelected == true)
        return confirm('هل تريد المتابعة؟ يوجد بعض القيم التي لم تحفظ بعد. للحفظ يرجى النقر على زر \'حفظ\'. شكرا');
    return true;
}

function Confirm(msg) {
    return confirm(msg);
}

function DeleteConfirm(msg) {
    if (msg == null)
        msg = 'هل تريد حذف هذا العنصر؟';

    // $.blockUI({ 'timeout': 3000 });
    //confirm(msg)
    return confirm(msg);  //confirm(msg);
}

function ShowHide(index, image, path) {
    var row = document.getElementById('div' + index);
    row.className = (row.className == 'Visible' ? 'Hidden' : 'Visible');
    image.src = row.className == 'Hidden' ? path + 'plus.gif' : path + 'minus.gif';
}

function fillEmpty() {

    $(function() {
        $('span.label_txt, span.txt_head').each(function() {
            if ($(this).text() == '') {
                $(this).text('-');
            }
        });
    });
}

function selectAll(involker) {

    var inputElements = document.getElementsByTagName('input');

    for (var i = 0; i < inputElements.length; i++) {

        var myElement = inputElements[i];

        if (myElement.type === "checkbox") {

            myElement.checked = involker.checked;

        }

    }

}

function RefreshPage() {
    document.location = document.location.href;
}

var gAutoPrint = true; // Call print function
function printxt() {
    if (document.getElementById != null) {
        var html = '<html>\n<head><link rel="stylesheet" type="text/css" href="/Style Library/ar-sa/style.css">';


        if (document.getElementsByTagName != null) {
            var headTags = document.getElementsByTagName('head');
            if (headTags.length > 0)
                html += headTags[0].innerHTML;
        }

        html += '\n</head>\n<body style="background-color:#ffffff;background-image:none;">\n';
        html += '\n<table border="0" class="PrintTable" align="center"><tr><td style="text-align:center;display:none;"><img src="/images/main/logo.gif" /></td></tr><tr><td>&nbsp;</td></tr>';
        html += '<tr><td style="width:100%;">\n';

        var printReadyElem = document.getElementById("printContent");

        if (printReadyElem != null) {
            html += printReadyElem.innerHTML;
        }
        else {
            alert('There is nothing to Print');
            return;
        }
        html += '\n</td></tr><tr><td><hr /></td></tr>';
        html += '<tr><td class="PrintCopyRight"> </td></tr></table>';

        html += '\n</body>\n</html>';

        var printWin = window.open('', 'printxt');
        printWin.document.open();
        printWin.document.write(html);
        printWin.document.close();
        if (gAutoPrint)
            printWin.print();
    }
    else {
        alert("Your Browser Doesn't Support This Feature");
    }
}

// use this function to open send to friend window
function SendToFriend(PathSentPage) {
    var pageTitle = document.title;
    var pageURL = document.location.href;
    window.open(PathSentPage + '?title=' + pageTitle + '&link=' + pageURL, '_blank', 'menubar=0,toolbar=0,resizable=0,location=0,status=0,scrollbars=0,width=600,height=245')
}

function AddToFavorite() {
    var title = document.title;
    var url = document.location.href;
    var msg = "لاضافة الصفحة الى المفضلة اضغط على ctrl+D";
    if (window.sidebar) // firefox
        alert(msg);
    else if (window.opera && window.print) {              // opera
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
    else if (document.all) // ie
    {
        window.external.AddFavorite(url, title);
    }
    else if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
        alert(msg);
    }
    else
        alert(msg);

}


/// begin  ////Filter and Search ASP.Net DropDownList items using JavaScript

var ddlText, ddlValue, ddl, lblMesg;

function CacheItems(ddlItem) {

    ddlText = new Array();

    ddlValue = new Array();

    ddl = document.getElementById(ddlItem);

    //lblMesg = document.getElementById(lblMessage);

    for (var i = 0; i < ddl.options.length; i++) {

        ddlText[ddlText.length] = ddl.options[i].text;

        ddlValue[ddlValue.length] = ddl.options[i].value;
    }

}

function FilterItems(value) {

    ddl.options.length = 0;

    if (value != '')
        AddItem(ddlText[0], ddlValue[0]);

    for (var i = 0; i < ddlText.length; i++) {

        if (ddlText[i].toLowerCase().indexOf(value) != -1) {

            AddItem(ddlText[i], ddlValue[i]);

        }

    }

    //lblMesg.innerHTML = ddl.options.length + "عدد العناصر";

    //    if (ddl.options.length == 0) {

    //        AddItem("لايوجد عناصر.", "");

    //    }

}

function AddItem(text, value) {

    var opt = document.createElement("option");

    opt.text = text;

    opt.value = value;

    ddl.options.add(opt);

}


function SelectAllCheckboxes(chkHeaderId, gvClientID) {


    $('.gridViewCSS').find('input:checkbox').each(function() {
        if ($(this).id != chkHeaderId) {
            this.checked = $('#' + chkHeaderId).attr('checked');           
        }
    });
}

function ChangeTheHeader(partOfId, chkHeaderId) {
    var allCheckBox = document.getElementById(chkHeaderId);
    var allChecked = true;
    $('input[type=checkbox][id*=' + partOfId + ']').each(function() {
        allChecked = allChecked & this.checked;
    });
    allCheckBox.checked = allChecked;
}


//window.onload = CacheItems;

/// end  ////Filter and Search ASP.Net DropDownList items using JavaScript

function ShowControl(id) {

    document.getElementById(id).style.visibility = 'visible';
}

function HideControl(id) {

    document.getElementById(id).style.visibility = 'hidden';
}


/* Begin Tree Tools */

function ShowTreeSpan(id) {
    document.getElementById(id).style.display = 'inline';
}

function HideTreeSpan(id) {
    document.getElementById(id).style.display = 'none';
}

/* Begin Tree Tools */






