﻿
function ControlState(TheCase) {

    if (TheCase == 'LIST') {
        document.getElementById('ctl00_ContentPlaceHolder_UpdateCat').disabled = false;
        document.getElementById('ctl00_ContentPlaceHolder_DelCat').disabled = false;
        document.getElementById('ctl00_ContentPlaceHolder_CatTextBox').value = document.getElementById('ctl00_ContentPlaceHolder_CatList').options[document.getElementById('ctl00_ContentPlaceHolder_CatList').selectedIndex].value;

    } else if (TheCase == 'TEXT') {
        if (document.getElementById('ctl00_ContentPlaceHolder_CatTextBox').value == '') document.getElementById('ctl00_ContentPlaceHolder_SaveNewCat').disabled = true;
        else document.getElementById('ctl00_ContentPlaceHolder_SaveNewCat').disabled = false;
    }
}

function CheckNewCat() {
    var IsFound = false;
    for (x = 0; x < document.getElementById('ctl00_ContentPlaceHolder_CatList').options.length; x++) {
        if (document.getElementById('ctl00_ContentPlaceHolder_CatList').options[x].value == document.getElementById('ctl00_ContentPlaceHolder_CatTextBox').value) {
            IsFound = true;
        }
    }

    if (IsFound) alert('تنبيه: التصنيف موجود مسبقا!');
    return !IsFound;
}

function CheckUpdateCat() {
    var IsFound = false;
    for (x = 0; x < document.getElementById('ctl00_ContentPlaceHolder_CatList').options.length; x++) {
        if (document.getElementById('ctl00_ContentPlaceHolder_CatList').options[x].value == document.getElementById('ctl00_ContentPlaceHolder_CatTextBox').value) {
            IsFound = true;
        }
    }

    if (IsFound) {
        aalert('تنبيه: التصنيف موجود مسبقا!');
        document.getElementById('ctl00_ContentPlaceHolder_CatTextBox').value = document.getElementById('ctl00_ContentPlaceHolder_CatList').options[document.getElementById('ctl00_ContentPlaceHolder_CatList').selectedIndex].value;
    }
    return !IsFound;
}

function CheckDelCat() {
    return confirm("Delete [" + document.getElementById('ctl00_ContentPlaceHolder_CatList').options[document.getElementById('ctl00_ContentPlaceHolder_CatList').selectedIndex].value + "], are you sure?");
}

function CheckItemForm() {
    if (document.getElementById('ctl00_ContentPlaceHolder_TitleBox').value == '') {
        alert('خـطأ: يرجى تعبئة جميع الحقول');
        return false;
    } else if (document.getElementById('ctl00_ContentPlaceHolder_CatList').selectedIndex <= 0) {
        alert('خـطأ: يرجى تعبئة جميع الحقول');
        return false;
    } else if (document.getElementById('ctl00_ContentPlaceHolder_DescBox').value == '') {
        alert('خـطأ: يرجى تعبئة جميع الحقول');
        return false;
    } else if (document.getElementById('ctl00_ContentPlaceHolder_PhotoUploader').value == '' && document.getElementById('ctl00_ContentPlaceHolder_SaveBtn').value == 'Save Item') {
        alert('خـطأ: يرجى تعبئة جميع الحقول');
        return false;
    } else return true;
}

function ValidateSearchkey() {
    if (document.getElementById('ctl00_SearchTextBox').value == '') {
        alert('خـطـأ: يرجى ادخال مفتاح البحث');
        document.getElementById('ctl00_SearchTextBox').focus();
    }
    else location = 'search.aspx?KEY=' + escape(document.getElementById('ctl00_SearchTextBox').value);

    return false;
}

function CheckBannersForm() {
    if (document.getElementById('ctl00_ContentPlaceHolder_MainBanner').value == '' && document.getElementById('ctl00_ContentPlaceHolder_RightBanner').value == '' && document.getElementById('ctl00_ContentPlaceHolder_LeftBanner').value == '') {
        alert('Error: Select at least one banner file!');
        return false;
    } else return true;
}

function ShowImage(ImagePath) {
    var theImg = new Image();
    theImg.src = ImagePath;
    var imgw = theImg.width + 100;
    var imgh = theImg.height + 100;

    //    if (imgw < 100) { imgw = 100 };
    //    if (imgh < 100) { imgh = 100 };

    var left = parseInt((screen.availWidth / 2) - (imgw / 2));
    var top = parseInt((screen.availHeight / 2) - (imgh / 2));

    var ImgWin = window.open('', 'imgwin', config = 'height=' + imgh + ',width=' + imgw + ',top=' + top + ',left=' + left);
    with (ImgWin.document) {
        writeln('<html><head><title>أورينت | عارض الصور</title></head>');
        writeln('<body onload="self.focus()" onblur="self.close()">');
        writeln('<div style="text-align:center; margin-top: 50px">');
        writeln('<img src=' + ImagePath + '></div>');
        writeln('</body></html>');
        close();
    }
}

