﻿// Copyright 2006-2007 javascript-array.com

var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

// open hidden layer
function mopen(id,parent) {
    // cancel close timer
    mcancelclosetime();
    // close old layer
    if (ddmenuitem) ddmenuitem.style.visibility = 'hidden';
    // get new layer and show it
    ddmenuitem = document.getElementById(id);
    ddmenuitem.style.visibility = 'visible';
    $(ddmenuitem).fadeIn('slow');
    ddmenuitem.style.left = getX(parent)+'px'; 
    ddmenuitem.style.top = (getY(parent) + 25)+'px';
}
// close showed layer
function mclose() {
    
    if (ddmenuitem) {
        $(ddmenuitem).fadeOut('slow', function() { ddmenuitem.style.visibility = 'hidden' });
        
    }
}

// go close timer
function mclosetime() {
    closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}

// close layer when click-out
document.onclick = mclose;


function getY(oElement) {
    var iReturnValue = 0;
    while (oElement != null) {
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

 function getX(oElement) {
    var iReturnValue = 0;
    while (oElement != null) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}
function openWindow(url, parS,w,h) {
    if (url != '')
        popUp(url + "?" + parS, w, h);
}
 function centeredPopup(url, winName, w, h, scroll) {
            LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
            TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
            settings =
'height=' + h + ',width=' + w + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',resizable'
            popupWindow = window.open(url, winName, settings)
        }
function popUp(URL,w,h) {
    day = new Date();
    id = day.getTime();
    var screenLeft = (screen.width - 600) / 2;
    var screenTop = (screen.height - 600) / 2;
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+w+",height="+h+",left = " + screenLeft + ",top = " + screenTop + "');");

}


function toggleDisplay() {

    var frame = document.getElementById('umAlQura');
    if (frame == null)
        return
    if (frame && frame.style.visibility == 'hidden') {
        frame.style.visibility = 'visible';
        $('#umAlQura').slideDown('slow');
    } else if (frame && frame.style.visibility == 'visible') {
        $('#umAlQura').slideUp('fast');
        frame.style.visibility = 'hidden';
    }
}

function navigate(obj) {
    var con = document.getElementById('allnews')
    if (obj.parentNode != null)
        var parent = obj.parentNode;
    {
        for (var i = 0; i < parent.childNodes.length; i++) {
            con.childNodes[i].style.display = 'none';
            parent.childNodes[i].className = "notSelectedNode";
        }
        document.getElementById(obj.attributes('info').value).style.display = '';
        obj.className = "selectedNode"
    }
}
function hoverImage(obj) {
    if (obj.tagName == "IMG") {
        obj.src = obj.src.split(".")[0] + "[Hover].png";
    }
}
function originalImage(obj) {
    if (obj.tagName == "IMG") {
        obj.src = obj.src.split("[")[0] + ".png";
    }
}
/* from m-abbas Emp-services*/

//Employee Services Scripts

var dtCh = "-";
var minYear = 1900;
var modDate = new Date();
var maxYear = modDate.getYear();
if (maxYear < 1000)
    maxYear += 1900;
/****************************************************************************/
///////////////////////////////////ajax related functions
//this array to save links when disable it and then return from it 
//when enable links of page in order to avoid user clicks for links
var linkArray = new Array();
//the function loop for page links and set it's value for the array and disable them
//and cancel the action of onclick for the link
/****************************************************************************/
function disablelinks() {
    var objLink = document.links;
    for (var i = 0; i < objLink.length; i++) {
        linkArray[i] = objLink[i].href.toString();
        if (objLink[i].id == 'dwA1') {
            //this just allows me to skip some
        }
        else {
            objLink[i].disabled = true;
            objLink[i].onclick = new Function("return false;");
        }
    }
}
/****************************************************************************/
//the function used to restore page links and set their href values and enable them all
function enablelinks() {
    var objLink = document.links;
    for (var i = 0; i < objLink.length; i++) {
        objLink[i].disabled = false;
        objLink[i].href = linkArray[i];
        objLink[i].onclick = linkArray[i];
    }
}
/****************************************************************************/
//the function used to disable all page control used for ajax in pages
//it calls disablelinks to disable page links and then loop for other controls 
//and set it's disable attributes to true
function DisableControls() {
    disablelinks();
    var count = document.forms[0].elements.length;
    for (i = 0; i < count; i++) {
        var element = document.forms[0].elements[i];
        element.disabled = true;
    }
}
/****************************************************************************/
//the function used to enable all page control used after  ajax request finishes in pages
//it calls enablelinks to enable page links and then loop for other controls 
//and set it's disable attributes to false
function EnableControls() {
    enablelinks();
    var count = document.forms[0].elements.length;
    for (i = 0; i < count; i++) {
        var element = document.forms[0].elements[i];
        element.disabled = false;
    }
}
/*****************************************************************************/
//////////////////////////////////////////////////////////////////////////////////////////////////////
//the function Make window as full screen
function ConfirmMe(message) {
    if (Page_ClientValidate()) {
        if (confirm(message)) {
            form1.submit();
            return true;

        }
        else
            return false;
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
function FullScreenWindow() {
    //window.moveTo(0,0);
    //resizeTo(screen.availWidth,screen.availHeight);

    window.moveTo(0, 0);
    if (document.layers) // navigator 4+
    {
        var deltaX = screen.availWidth - window.outerWidth;
        var deltaY = screen.availHeight - window.outerHeight;
        window.resizeBy(deltaX, deltaY);
    } else if (document.all) // exploder 4+
    { resizeTo(screen.availWidth, screen.availHeight); }

}

//this function to handle enter action to the  textBox it take the textboxid and button ID needed
//to set the default button for the text box 
//في حاله لو عندي تكست وعايز أحدد زر عليه عند الضغط علي مفتاح الإنتر
function clickButton(e, buttonid) {
    var evt = e ? e : window.event;
    var bt = document.getElementById(buttonid);
    if (bt) {
        if (evt.keyCode == 13) {
            bt.click();
            return false;
        }

    }

}
////////////////////////////////////////////////////////////////////////////////////////////
// the function convert enter button to tag
//مستخدمه في صفحة الlogin عند إدخال اسم المستخدم والضغط علي انتر يتم تحوليها لتاب للإنتقال لكلمة المرور وهكذا 
//ويتم استدعاء الداله علي onkeypress للحقل المراد الإنتقال لتاليه بعد الضغط علي الإنتر
////////////////////////////////////////////////////////////////////////////////////////////
function enterToTab() {
    if (event.keyCode == 13) event.keyCode = 9;
}

/////////////////////////////////////////////////////////////////////////////////////////////
//this function check the extensions of file passed to it if it is image or compressed 
//doc file or pdf it returns true else it returns false 
//used for checking file upload image files 
////////////////////////////////////////////////////////////////////////////////////////////
function checkExtension(ext) {
    ext = ext.substring(ext.length - 3, ext.length);
    ext = ext.toLowerCase();
    if (ext == 'jpg' || ext == 'jpeg' || ext == 'bmp' || ext == 'gif' || ext == 'rar' || ext == 'zip' || ext == 'ace' || ext == 'doc' || ext == 'pdf') {
        return true;
    }
    else
        return false;
}
//////////////////////////////////////////////////////////////////////////////////////////
//this function check Mail String take control to validate and message to show to user 
/////////////////////////////////////////////////////////////////////////////////////////
function ValidateMail(control, message) {
    var ctr = document.getElementById(control);
    var str = ctr.value;
    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.length > 0) {
        if (str.indexOf(at) == -1) {
            alert(message);
            ctr.value = "";
            ctr.style.backgroundColor = "#ff6699";
            ctr.focus();
            return false;
        }
        if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
            alert(message);
            ctr.value = "";
            ctr.style.backgroundColor = "#ff6699";
            ctr.focus();
            return false
        }

        if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
            alert(message);
            ctr.value = "";
            ctr.style.backgroundColor = "#ff6699";
            ctr.focus();
            return false
        }

        if (str.indexOf(at, (lat + 1)) != -1) {
            alert(message);
            ctr.value = "";
            ctr.style.backgroundColor = "#ff6699";
            ctr.focus();
            return false
        }

        if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
            alert(message);
            ctr.value = "";
            ctr.style.backgroundColor = "#ff6699";
            ctr.focus();
            return false
        }

        if (str.indexOf(dot, (lat + 2)) == -1) {
            alert(message);
            ctr.value = "";
            ctr.style.backgroundColor = "#ff6699";
            ctr.focus();
            return false
        }

        if (str.indexOf(" ") != -1) {
            alert(message);
            ctr.value = "";
            ctr.style.backgroundColor = "#ff6699";
            ctr.focus();
            return false
        }
    }
    ctr.style.backgroundColor = "#FFFFFF"
    return true
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
function ValidateNumberLegnth(control, message, Ctrlength) {
    var MyNumber = document.getElementById(control);
    var PassedControlLength = MyNumber.value.length;
    if (PassedControlLength > 0) {
        if (parseInt(PassedControlLength) != parseInt(Ctrlength)) {
            alert(message);
            MyNumber.value = "";
            MyNumber.style.backgroundColor = "#ff6699";
            MyNumber.focus();
            return false;
        }
        else {
            MyNumber.style.backgroundColor = "#FFFFFF";
        }
    }


}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//this function return message if passed control value is not number
function ValidateNumber(control, message) {
    var No = document.getElementById(control);
    if (isNaN(No.value)) {
        alert(message);
        No.value = "";
        No.style.backgroundColor = "#ff6699";
        No.focus();
        return false;
    }
    else {
        No.style.backgroundColor = "#FFFFFF";
    }

}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//this function return message if passed control value is not number
function ValidateString(control, message) {
    var No = document.getElementById(control);
    if (!isNaN(No.value)) {
        if (No.value.length > 0) {
            alert(message);
            No.value = "";
            No.style.backgroundColor = "#ff6699";
            No.focus();
            return false;
        }
    }
    else {
        No.style.backgroundColor = "#FFFFFF";
    }

}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function daysInFebruary(year) {
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i == 4 || i == 6 || i == 9 || i == 11) { this[i] = 30 }
        if (i == 2) { this[i] = 29 }
    }
    return this
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isDate(dtStr) {
    if (dtStr.length < 10) {
        return true;
    }
    var daysInMonth = DaysArray(12)
    var pos1 = dtStr.indexOf(dtCh)
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
    var strYear = dtStr.substring(0, pos1)
    var strMonth = dtStr.substring(pos1 + 1, pos2)
    var strDay = dtStr.substring(pos2 + 1)
    strYr = strYear
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
    if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
    }
    month = parseInt(strMonth)
    day = parseInt(strDay)
    year = parseInt(strYr)
    if (pos1 == -1 || pos2 == -1) {
        return true;
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {
        alert("Please enter a valid month")
        return false
    }
    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
        alert("Please enter a valid day")
        return false
    }
    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
        alert("Please enter a valid 4 digit year between " + minYear + " and " + maxYear)
        return false
    }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
        alert("Please enter a valid date")
        return false
    }
    return true
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isEmpty(control) {
    if (control != null) {
        if (control.value == "") {
            return false;
        }
    }
    return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that validateDaterent character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//the function check the date to be on the style 22021430
function ValidateDateFormat(date) {
    var Cur = document.getElementById(date);
    if (Cur != null) {
        if (!IsNumberOnly(Cur.value)) {
            Cur.value = '';
            Cur.focus();
            return false;
        }
        if (Valid(Cur.value)) {
            var n = FormatString(Cur.value);
            Cur.value = n;
            var mm = CheckDateInterval(Cur.value);
            if (!mm) {
                Cur.value = '';
                Cur.focus();
                return false;
            }
            return true;

        }

    }


    function CheckDateInterval(Current) {

        var dt1 = new Array();
        dt1 = Current.split("/");

        var day1 = parseInt(dt1[0]);
        var month1 = parseInt(dt1[1]);
        var year1 = parseInt(dt1[2]);
        if (day1 > 30) {
            alert("التاريخ غير مقبول لأن اليوم أكبر من 30");
            return false;
        }
        if (month1 > 12) {
            alert("التاريخ غير مقبول لأن الشهر أكبر من 12");
            return false;
        }
        return true;

    }

} //end function	

function IsNumberOnly(string) {
    if (string.length < 8) {
        alert("عفوا التاريخ يجب أن يكون على هذة الطريقة 03121428");
        return false;
    }
    if (isNaN(string)) {
        alert("عفوا التاريخ يجب أن يكون على هذة الطريقة 03121428");
        return false;
    }
    return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// function to check if the date inserted is less than or equal current day 
function ValidateDateLessThanCurrentDate(CurrentDate, CheckedDate) {
    var x = document.getElementById(CurrentDate); //تاريخ اليوم 
    var Cur = document.getElementById(CheckedDate); // التاريخ المراد فحصه

    if (Cur != null & x != null) {
        if (!IsNumberOnly(Cur.value)) {
            Cur.value = '';
            Cur.focus();
            return false;
        }
        if (Valid(Cur.value)) {
            var n = FormatString(Cur.value);
            Cur.value = n;
            var mm = comparedates(Cur.value, x.value);
            if (!mm) {
                Cur.value = '';
                Cur.focus();
                return false;
            }
        }

    }
}
//-----------------------------------------compare twor date the date2 must be less than current
function comparedates(Current, date2) {
    var dt1 = new Array();
    dt1 = Current.split("/");
    var dt2 = new Array();
    dt2 = date2.split("/");
    var day1 = parseFloat(dt1[0]);
    var month1 = parseFloat(dt1[1]);
    var year1 = parseFloat(dt1[2]);
    //''''''''''''''''''''''''''''''''''''
    var day2 = parseFloat(dt2[0]);
    var month2 = parseFloat(dt2[1]);
    //alert(month2);
    var year2 = parseFloat(dt2[2]);
    if (day1 > 30) {
        alert("التاريخ غير مقبول لأن اليوم أكبر من 30");
        return false;
    }
    if (month1 > 12) {
        alert("التاريخ غير مقبول لأن الشهر أكبر من 12");
        return false;
    }

    if (year2 < year1) {
        alert("التاريخ غير مقبول لأن السنة أكبر من السنة الحالية");
        return false;

    }
    else {
        if (year2 == year1) {

            if (month2 < month1) {
                alert("التاريخ غير مقبو ل لأن الشهر  أكبر من الشهر الحالى");
                return false;
            }
            else {
                if (month2 == month1) {
                    if (day2 < day1) {
                        alert("التاريخ غير مقبول لأن اليوم أكبر  من تاريخ اليوم");
                        return false;
                        alert("أحد التواريخ غير صالح تأكد من البيانات");
                    }
                }
            }
        }
        return true;

    }

} //end function	
function FormatString(x) {
    var day = x.substring(0, 2);
    var month = x.substring(2, 4);
    var year = x.substring(4, 8);
    var last = day + "/" + month + "/" + year;
    return last;
}

function Valid(string) {

    if (string == "")
        return false;
    if (string.indexOf('/') > 0)
        return false;
    return true;


}
////////////////////////////////////////////////////////////////////////////////////////////////
//this function compare two dates with the format(dd/MM/YYYY) to compare the first date to be less
//than the second date to compare interval 
function comparedatesInterval(Current, date2) {
    var dt1 = new Array();
    dt1 = Current.split("/");

    var dt2 = new Array();
    dt2 = date2.split("/");

    var day1 = parseFloat(dt1[0]);
    var month1 = parseFloat(dt1[1]);
    var year1 = parseFloat(dt1[2]);

    var day2 = parseFloat(dt2[0]);
    var month2 = parseFloat(dt2[1]);
    var year2 = parseFloat(dt2[2]);
    if (day1 > 30) {
        alert("التاريخ غير مقبول لأن اليوم أكبر من 30");
        return false;
    }
    if (month1 > 12) {
        alert("التاريخ غير مقبول لأن الشهر أكبر من 12");
        return false;
    }

    if (year2 < year1) {
        alert("تاريخ الفترة غير صالح يجب أن يكون تاريخ النهاية أكبر من تاريخ البداية");
        return false;

    }
    else {
        if (year2 == year1) {

            if (month2 < month1) {
                alert("تاريخ الفترة غير صالح يجب أن يكون تاريخ النهاية أكبر من تاريخ البداية");
                return false;

            }
            else {
                if (month2 == month1) {
                    if (day2 < day1) {
                        alert("تاريخ الفترة غير صالح يجب أن يكون تاريخ النهاية أكبر من تاريخ البداية");
                        return false;
                    }

                }
            }
        }
        return true;

    }

} //end function	
///////////////////////////////////////////////////////////////////////////////////////////////
//this function used to prevent user to write english chracters
function isArabicOnly(evt) {
    var bool = true;
    var charCode = (evt.which) ? evt.which : event.keyCode
    if ((charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122)) {
        alert("أكتب باللغه العربية من فضلك");
        bool = false;
    }
    return bool;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//this function used to write numbers only and prevent user to write any other characters
function isNumberKey(evt) {
    var bool = true;
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        alert("لا يسمح بغير الأرقام !");
        bool = false;
    }
    return bool;
}
// the function convert enter button to tag
//مستخدمه في صفحة الlogin عند إدخال اسم المستخدم والضغط علي انتر يتم تحوليها لتاب للإنتقال لكلمة المرور وهكذا 
//ويتم استدعاء الداله علي onkeypress للحقل المراد الإنتقال لتاليه بعد الضغط علي الإنتر
// for ex: textbox to goto next control when press enter: onkeydown="javascript:enterToTab();"
////////////////////////////////////////////////////////////////////////////////////////////
function enterToTab() {
    if (event.keyCode == 13) event.keyCode = 9;
}

/////////////////////////////////////////////////////////////////////////////////////////////  
function preventBack() {
    if (history.length > 0) {
        history.go(+1);

    }
}
////////////////////////////////////////////////////////////////////////////////////
////////////////////////this funciton to disable buttons when user press it in order to 
//prevent him to submit the form twice
function DisableButton(b) {
    alert("now in disablebutton");
    b.disabled = true;
    b.value = 'Submitting';
    b.form.submit();
}
//////////////////////////////////////////////////////////////////////////////////////
function hoverMouse(obj) {
    if (obj.src.split(".").length > 1) {
        obj.src = obj.src.split(".")[0] + "-H.png";
    }

}

function outMouse(obj) {
    if (obj.src.split("-").length > 1) {
        obj.src = obj.src.split("-")[0] + ".png"
    }
}

function enterToTab() {
    if (event.keyCode == 13) event.keyCode = 9;
}
function CeneterPopup(link,width,height)
{
var winl = (screen.width-width)/2;
var wint = (screen.height-height)/2;
window.open(link , 'Converter', 'top=' +wint+ ',left='+ winl+'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=no,width='+ width +',height='+ height);
}
 function preventBack()
        {
         if(history.length>0)
         {
            history.go(+1);
            
         }
        }
