var isNav4 = false;
var isIE = false;
var isDom = false;

var foropera = window.navigator.userAgent.toLowerCase();
var itsopera = foropera.indexOf("opera", 0) + 1;
var itsgecko = foropera.indexOf("gecko", 0) + 1;
var itsmozillacompat = foropera.indexOf("mozilla", 0) + 1;
var itsmsie = foropera.indexOf("msie", 0) + 1;
var farsiKeyCodes = new Array(1662, 1670, 1580, 1581, 1582, 1607, 1593, 1594, 1601, 1602, 1603,
        1572,
        1579, //   �  for firefox
        1589, 1590, 1711, 1705, 1605, 1606, 1578, 1575, 1604, 1576, 1740, 1587,
        1588, 1608, 1574, 1571, 1583, 1584, 1585, 1585, 1586, 1591, 1592, 1570, 17281569, 1571, 1573, 1572, 1688, 1610, 1577,
        1611, 1612, 1613, 1614, 1615, 1617);
if (itsopera > 0) {
    isNav4 = true;
}

if (itsmozillacompat > 0) {
    if (itsgecko > 0) {
        isIE = true;
        isDom = true;
        document.all = document.getElementsByTagName("*");

    } else if (itsmsie > 0) {
        isIE = true;

    } else {
        if (parseInt(navigator.appVersion) < 5) {
            isNav4 = true;
        } else {
            isIE = true;
        }
    }

}

/*----------------------------------------------------------------
 * get select object value SELECT				                 *
 * parameters : cmbId is select id                               *
 ----------------------------------------------------------------*/
function getSelectValue(cmbId) {
    var el;
    if (document.getElementsByTagName)
        el = document.getElementsByName(cmbId);
    else
        el = document.all[cmbId];

    if (el.length == 0) return "";
    var count = 0;
    var el2 = el[0];
    if (el2.selectedIndex != -1) {
        return el2.options[el2.selectedIndex].value;
    }
    return "";
}

function getRadioOptionValue(optId) {
    var el;
    if (document.getElementsByTagName)
        el = document.getElementsByName(optId);
    else
        el = document.all[optId];

    if (el.length == 0) return "";
    for (var i = 0; i < el.length; i++) {
        if (el[i].checked)
            return el[i].value;
    }
    return "";
}

/*----------------------------------------------------------------
 * change selectedIndex of select object                         *
 * parameters : cmbId is select id  , newValue                   *
 -----------------------------------------------------------------*/
function changeSelectIndex(cmbId, newValue) {
    if (newValue == null) return;
    var el;
    if (document.getElementsByTagName)
        el = document.getElementsByName(cmbId);
    else
        el = document.all[cmbId];

    if (el.length == 0) return;

    var inps = el[0];
    for (var i = 0; i < inps.length; i++) {
        if (inps.options[i].value == newValue) {
            inps.selectedIndex = i;
            break;
        }
    }
}

/*----------------------------------------------------------------
 * check radio option object   INPUT TYPE=Radio                  *
 * parameters : optId name option name , optvalue                *
 -----------------------------------------------------------------*/
function checkRadioOption(optName, optvalue) {
    var inps;
    if (document.getElementsByTagName)
        inps = document.getElementsByName(optName);
    else
        inps = document.all[optName];
    for (var i = 0; i < inps.length; i++) {
        if (inps[i].value == optvalue)
            inps[i].checked = true;
    }
}

function getEventKeyCode(e) {
    var key;
    if (window.event)
        key = event.keyCode;
    else
        key = e.which;

    return key;
}


// add option to select lis t
function appendOptionLast(elSelectObject, label ,value)
{
  var elOptNew = document.createElement('option');
  elOptNew.text = label;
  elOptNew.value = value;

  try {
    elSelectObject.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    elSelectObject.add(elOptNew); // IE only
  }
}


//removed last item from a select element
function removeOptionLast(elSelectObject)
{
  if (elSelectObject.length > 0)
  {
    elSelectObject.remove(elSelectObject.length - 1);
  }
}


//remove an option from specific position
function removeOptionSelected(elSelectObject)
{
  var i;
  for (i = elSelectObject.length - 1; i>=0; i--) {
    if (elSelectObject.options[i].selected) {
      elSelectObject.remove(i);
    }
  }
}


/*-----------------------------------------------------------------------------------------
 * handle keydown event and avoid for character inputs in Current input text              *
 * e : window.event                                                                       *
 ------------------------------------------------------------------------------------------*/
function numbericOnKeypress(e) {

    if (isCopyPressed(e) || isPastePressed(e))
        return;
    var key = getEventKeyCode(e);

    if (key == 45 || key == 44 || key == 46) return true;// ',' '.' '-'
    if (ignoreKeys(key)) return true;
    if (isNumericKeysPressed(key)) { // Numbers
        return true;
    }
    if (window.event) //IE
        window.event.returnValue = false;
    else              //other browser
        e.preventDefault();
}

function farsinumbericOnKeypress(e) {

    if (isCopyPressed(e) || isPastePressed(e))
        return;
    var key = getEventKeyCode(e);

    if (key == 45 || key == 44 || key == 46) return true;// ',' '.' '-'
    if (ignoreKeys(key)) return true;
    if (isNumericKeysPressed(key)) { // Numbers
        return true;
    }
    if (isFarsiKeysPressed(e)) {
        return true;
    }
    if (window.event) //IE
        window.event.returnValue = false;
    else              //other browser
        e.preventDefault();
}

/*-----------------------------------------------------------------------------------------
 * handle keydown event and avoid for all characters except / for date Current input text *
 * e : window.event                                                                       *
 ------------------------------------------------------------------------------------------*/
function dateOnKeypress(e) {

    if (isCopyPressed(e) || isPastePressed(e))
        return;

    var key = getEventKeyCode(e);
    if (ignoreKeys(key)) return true;
    if (isNumericKeysPressed(key)) { // Numbers
        return true;
    }
    if (key == 47)// '/' character
        return;

    if ((key < 48 ) || (key > 57 )) {
        if (window.event) //IE
            window.event.returnValue = false;
        else              //other browser
            e.preventDefault();
    }
}

/*-----------------------------------------------------------------------------------------
 * handle keydown event for email fields                                                  *
 * e : window.event                                                                       *
 ------------------------------------------------------------------------------------------*/
function emailOnKeypress(e) {
    if (isCopyPressed(e) || isPastePressed(e))
        return;

    var key = getEventKeyCode(e);

    if (ignoreKeys(key))return true;

    if (isNumericKeysPressed(key)) { // Numbers
        return true;
    }
    if (key == 64) { // '@'
        return true;
    }
    else if (key == 45 || key == 46) {
        return true;// '.' '-'
    }

    else if (key == 95) { // '_'
            return true;
        }
        else if (key >= 65 && key <= 90) { // Large characters
                return true;
            }
            else if (key >= 97 && key <= 122) { // Small characters
                    return true;
                }

    if (window.event) //IE
        window.event.returnValue = false;
    else            //other browser
        e.preventDefault();
    return false;
}
/*----------------------------------*/
function farsiOnkeypress(e) {
    var key = getEventKeyCode(e);
    if (key == 1705) {
        event.keyCode = 1603;
    }
    if (key == 1740) {
        event.keyCode = 1610;
    }
}
/*-----------------------------------------------------------------------------------------
 * Allows only farsi characters to be typed                                                  *
 * e : window.event                                                                       *
 ------------------------------------------------------------------------------------------*/
function isFarsiKeysPressed(e) {
    var key = getEventKeyCode(e);
    for (var i = 0; i < farsiKeyCodes.length; i++) {
        if (key == farsiKeyCodes[i]) {
            return true;
        }
    }
    return false;
}
function isEnglishKeysPressed(e) {
    var key = getEventKeyCode(e);
    if (key >= 65 && key <= 90) {
        return true;
    }
    if (key >= 97 && key <= 122) {
        return true;
    }

    return false;
}
function justFarsiPress(e){
    if (isCopyPressed(e) || isPastePressed(e))
        return;
    var key = getEventKeyCode(e);
    if(key == 32)return true;//space
//    if (key == 45 || key == 44 || key == 46) return true;// ',' '.' '-'
    if (ignoreKeys(key)) return true;
    if (isFarsiKeysPressed(e)) { // farsi
        return true;
    }
    if (window.event) //IE
        window.event.returnValue = false;
    else              //other browser
        e.preventDefault();
}

function justPress(e, en, fa, num, space){
    if (isCopyPressed(e) || isPastePressed(e))
        return;
    var key = getEventKeyCode(e);
    if (ignoreKeys(key)) return true;
    if(space && key == 32)return true;//space
//    if (key == 45 || key == 44 || key == 46) return true;// ',' '.' '-'
     if(en && isEnglishKeysPressed(e)) {
        return true;
    }
    if (fa && isFarsiKeysPressed(e)){
        return true;
    }

    if(num && isNumericKeysPressed(key))return true;

    if (window.event) //IE
        window.event.returnValue = false;
    else              //other browser
        e.preventDefault();
}

function justFarsiEnglishSpacePress(e){
    if (isCopyPressed(e) || isPastePressed(e))
        return;
    var key = getEventKeyCode(e);
    if(key == 32)return true;//space
//    if (key == 45 || key == 44 || key == 46) return true;// ',' '.' '-'
    if (ignoreKeys(key)) return true;
    if (isFarsiKeysPressed(e) || isEnglishKeysPressed(e)) { // farsi & english
        return true;
    }
    if (window.event) //IE
        window.event.returnValue = false;
    else              //other browser
        e.preventDefault();
}

function justFarsiNumberSpacePress(e){
    if (isCopyPressed(e) || isPastePressed(e))
        return;
    var key = getEventKeyCode(e);
    if(key == 32)return true;//space
//    if (key == 45 || key == 44 || key == 46) return true;// ',' '.' '-'
    if (ignoreKeys(key)) return true;
    if (isFarsiKeysPressed(e) || isNumericKeysPressed(key)) { // farsi
        return true;
    }
    if (window.event) //IE
        window.event.returnValue = false;
    else              //other browser
        e.preventDefault();
}

function isCtrlPressed(e)
{
    return e.ctrlKey;
}

function isAltPressed(e)
{
    return e.altKey;
}

function isShiftPressed(e)
{
    return e.shiftKey;
}

function isCopyPressed(e)
{
    return e.ctrlKey && getEventKeyCode(e) == 99;
}

function isPastePressed(e)
{
    return e.ctrlKey && getEventKeyCode(e) == 118;
}

/*-----------------------------------------------------------------------------------------
 * handle keys that should be ignored
 * e : window.event                                        *
 ------------------------------------------------------------------------------------------*/
function ignoreKeys(key) {
    if (key == 0) { //function keys and arrow keys
        return true;
    }
    if (key == 13) { //return
        return true;
    }
    if (key == 8) { //backspace
        return true;
    }
    if (key == 9) { // tab
        return true;
    }

    return false;
}
/*-----------------------------------------------------------------------------------------
 * handle keys that should be ignored
 * e : window.event                                        *
 ------------------------------------------------------------------------------------------*/
function isNumericKeysPressed(key) {

    if (key >= 48 && key <= 57) { // Numbers
        return true;
    }

    return false;
}
/*-----------------------------------------------------------------------------------------
 * Count / character in strDate                                                           *
 * parameters  :strDate is string entered by user                                         *
 ------------------------------------------------------------------------------------------*/
function countTokens(strDate) {
    var slashCount = 0;
    var i,j;
    i = strDate.indexOf("/", 0);
    j = i;
    while ((j != -1) && (i < strDate.length))
    {
        slashCount++;
        j = strDate.indexOf("/", i + 1);
        i = j;

    }
    return(slashCount);
}

/*-----------------------------------------------------------------------------------------
 * check strDate for valid date Format                                                    *
 * parameters  :strDate is string entered by user                                         *
 ------------------------------------------------------------------------------------------*/
function checkDate(strDate) {

    //alert(strDate)
    var i,j;
    var tYear = "";
    var tMonth = "";
    var tDay = "";
    var slashCount = 0;
    if (strDate == "")
        return(false);
    else
    {
        for (i = 0; i < strDate.length; i++)
        {
            if ((strDate.charCodeAt(i) < 48 || strDate.charCodeAt(i) > 57) && strDate.charAt(i) != "/")
                return(false);
        }
        slashCount = countTokens(strDate);
        if (slashCount != 2)
        {
            return(false);
        }
        i = strDate.indexOf("/", 0);
        tYear = strDate.substring(0, i);
        if ((parseInt(tYear) < 1) || (tYear.length < 2) || (tYear.length == 3))
            return(false);
        else
        {
            j = strDate.indexOf("/", i + 1);
            tMonth = strDate.substring(i + 1, j);
            if (( tMonth < 1) || (tMonth > 12))
                return(false);
            else {
                tDay = strDate.substring(j + 1, strDate.length);
                if (((tMonth < 7) && (tDay > 31)) || (tDay < 1))
                    return(false);
                else if ((tMonth > 6) && (tMonth < 12) && (tDay > 30))
                    return(false);
                else if ((tMonth == 12) && (tDay > 30))
                        return(false);
            }
        }
    }
    return(true);
}

function isValidDate(dateStr) {

    if (dateStr.length == 10 && dateStr.charAt(4) == '/' && dateStr.charAt(7) == '/')
    {
        var year = dateStr.substring(0, 4);
        var month = dateStr.substring(5, 7);
        var day = dateStr.substring(8, 10);
        if (!isNumeric(year) || !isNumeric(month) || !isNumeric(day))
            return false;

        if (!(month > 0 && month < 13) || !(day > 0 && day < 31))
            return false;
    } else {
        return false;
    }
    return true;
}

function isNumeric(val) {
    var chkExp = /^\d+$/;
    return chkExp.test(val);
}

/*-----------------------------------------------------------------------------------------
 * complete valid Date add 13 or 14 to year and 0 to month and day if required            *
 * parameters  : oDate is string entered by user                                          *
 ------------------------------------------------------------------------------------------*/
function completeDate(oDate) {
    var i,j;
    var tYear,nYear;
    var tMonth,nMonth;
    var tDay,nDay;
    var nDate = "";
    var lDate;

    if (oDate.length == "")
        return "";


    i = oDate.indexOf("/", 0);
    tYear = oDate.substring(0, i);
    if (tYear.length == 2)
    {
        lDate = new Date();
        if (lDate.getFullYear() < 2021)
            nYear = "13" + tYear;
        else
            nYear = "14" + tYear;
    }
    else
        nYear = tYear
    j = oDate.indexOf("/", i + 1);
    tMonth = oDate.substring(i + 1, j);
    if (tMonth.length == 1)
        nMonth = "0" + tMonth;
    else
        nMonth = tMonth;
    tDay = oDate.substring(j + 1, oDate.length);
    if (tDay.length == 1)
        nDay = "0" + tDay;
    else
        nDay = tDay;
    nDate = nYear + "/" + nMonth + "/" + nDay;
    return(nDate);
}

/*-----------------------------------------------------------------------------------------------
 * counts days between two dates
 -----------------------------------------------------------------------------------------------*/
function getDayBetweenDate(date1, date2) {
    var days = 0;
    days = parseInt(date1.substring(2, 4)) * 12 * 30;
    days += parseInt(date1.substring(5, 7)) * 30;
    days += parseInt(date1.substring(8, 10));
    days -= parseInt(date2.substring(2, 4)) * 12 * 30;
    days -= parseInt(date2.substring(5, 7)) * 30;
    days -= parseInt(date2.substring(8, 10));
    return(-1 * days);
}

/*-----------------------------------------------------------------------------------------------
 * check email address validation
 -----------------------------------------------------------------------------------------------*/
function isValidEmailAddr(emailStr) {
    var matchArray = emailStr.match(/^(.+)@(.+)\.(.+)$/)
    return matchArray != null;

}

/*-----------------------------------------------------------------------------------------------
 * check number validation
 -----------------------------------------------------------------------------------------------*/
function isValidNumber(numbStr, start, stop) {
    var matchArray = numbStr.match(/^[0-9]+$/)
    if (matchArray == null) {
        return false;
    }
    return !(numbStr < start || numbStr > stop);

}

/*-----------------------------------------------------------------------------------------------
 * check string is empty or not
 -----------------------------------------------------------------------------------------------*/
function isEmpty(aStr) {
    return aStr == null || aStr.length == 0 || trim(aStr) == '';


}

function trim(str) {
    var temp = "";
    for (var j = 0; j < str.length; j++)
        if (str.substring(j, j + 1) != " ")
            temp += str.substring(j, j + 1);
    return temp;
}

function isContain(str, char1) {
    var temp = "";
    for (var j = 0; j < str.length; j++)
        if (str.substring(j, j + 1) == char1)
            return true;

    return false;
}
//split character is a character that is used, as the sperator of the set of characters passed here.
//example: if {@,#} is character set and ',' is the seperator, then @ and # are seperated and passed to characterArray
function isContainSet(str, CharactersArray, splitCharacter) {
    var CharactersArray = CharactersArray.split(splitCharacter);
    var temp = "";
    for (var i = 0; i < str.length; i++)
        for (var j = 0; j < CharactersArray.length; j++)
            if (str.substring(i, i + 1) == CharactersArray[j])
                return true;

    return false;
}


function hasInvalidCharacters(str) {
    return isContainSet(str, "!s@s#s$s%s^s&s*s(s)s-s+s=s[s]s{s}s's:s;s.s<s>s\\s/s?s\"s|s,", "s");
}

function isValidUserId(userID) {

    for (var i = 0; i < userID.length; i++) {
        charAt = userID.charCodeAt(i);
        if (!((48 <= charAt && charAt <= 57) || (65 <= charAt && charAt <= 90) || (97 <= charAt && charAt <= 122) ||
              (charAt == 95) || (charAt == 45))) // numbers ,english alphabet, _ , -
            return false;
    }
    return true;
}

/*-----------------------------------------------------------------------------------------------
 * check number validation
 -----------------------------------------------------------------------------------------------*/
function replaceString(base, find, replace) {
    var temp = "";
    for (var j = 0; j < base.length; j++)
    {
        var character = base.substring(j, j + 1);
        if (character == find)
            temp += replace;
        else
            temp += character;
    }
    return temp;
}

/*-----------------------------------------------------------------------------------------------
 * check a pattern recurrence in selected password
 -----------------------------------------------------------------------------------------------*/
function haveReccurrencePattern(exp, count) {

    var expLen = exp.length;
    if ((expLen % count) != 0) {
        return true;
    }

    var pattern = exp.substring(0, count);
    var counter = expLen / count;

    for (var i = 1; i < counter; i++) {
        var begin = i * count;
        var end = (i + 1) * count;
        var chars = exp.substring(begin, end);
        //        alert("begin:" + begin + "  end:" + end +  "chars:" + chars + " pattern" + pattern);
        if (chars != pattern) {
            return true;
        }
    }
    return false;
}

/*-----------------------------------------------------------------------------------------------
 * for comma and formating currency just number!
 -----------------------------------------------------------------------------------------------*/
function placeCurrencyMask(ctrl) {
    var kaonumber = ctrl.value
    for (var i = 0; i < kaonumber.length; i++) {
        while (kaonumber.indexOf(',') != -1) {
            kaonumber = kaonumber.substring(0, kaonumber.indexOf(',')) + kaonumber.substring(kaonumber.indexOf(',') + 1);
        }
    }
    var kaos4 = "";
    var kaos0 = "";
    if (kaonumber.indexOf("-") != -1) {
        kaos0 = "-";
        for (var i = 0; i < kaonumber.length; i++) {
            if (kaonumber.indexOf("-") != -1)
                kaonumber = kaonumber.substring(0, kaonumber.indexOf("-")) + kaonumber.substring(kaonumber.indexOf("-") + 1);
        }
    }

    if (kaonumber.indexOf("0") == 0) {
        kaonumber = kaonumber.substring(1);
    }
    var kaoa;
    var kaob;

    if ((kaoa = kaonumber.indexOf('/')) != -1) {
        kaos4 = kaonumber.substring(kaoa);

        while (kaos4.indexOf('/') != -1) {
            kaos4 = kaos4.substring(0, kaos4.indexOf('/')) + kaos4.substring(kaos4.indexOf('/') + 1);
        }
        while (kaos4.indexOf(".") != -1) {
            kaos4 = kaos4.substring(0, kaos4.indexOf(".")) + kaos4.substring(kaos4.indexOf(".") + 1);
        }
        kaos4 = '/' + kaos4;
        kaonumber = kaonumber.substring(0, kaoa);
    } else if ((kaob = kaonumber.indexOf(".")) != -1) {
        kaos4 = kaonumber.substring(kaob);
        while (kaos4.indexOf(".") != -1) {
            kaos4 = kaos4.substring(0, kaos4.indexOf(".")) + kaos4.substring(kaos4.indexOf(".") + 1);
        }
        while (kaos4.indexOf('/') != -1) {
            kaos4 = kaos4.substring(0, kaos4.indexOf('/')) + kaos4.substring(kaos4.indexOf('/') + 1);
        }
        kaos4 = "." + kaos4;
        kaonumber = kaonumber.substring(0, kaob);
    }
    if ((kaonumber + kaos4).indexOf(".") == 0) {
        kaonumber = "0" + kaonumber;
    } else if ((kaonumber + kaos4).indexOf('/') == 0) {
        kaonumber = kaonumber + '0';
    }
    if (kaonumber.length <= 3) {
        ctrl.value = kaos0 + kaonumber + kaos4;
    } else {
        var kaos1 = kaonumber.substring(0, (kaonumber.length) % 3);
        var kaos2 = kaonumber.substring((kaonumber.length) % 3);
        var kaos3 = "";
        for (var i = 0; i < kaos2.length; i = i + 3) {
            kaos3 = kaos3 + ',' + kaos2.substring(i, i + 3);
        }
        if (kaonumber.length % 3 == 0) kaos3 = kaos3.substring(1);
        ctrl.value = kaos0 + kaos1 + kaos3 + kaos4;
    }
}

/*-----------------------------------------------------------------------------------------------
 * get element by name or id
 -----------------------------------------------------------------------------------------------*/
function getElement(el) {
    var element = document.getElementById(el);

    if (element == null)
        element = document.getElementsByName(el);

    if (element == null)
        element = document.all[el]

    return element;
}

/*-----------------------------------------------------------------------------------------------
 * makes value of two element equal
 -----------------------------------------------------------------------------------------------*/
function sysncElementsValue(sourceEl, distEl) {
    var srcElement = getElement(sourceEl);
    var discElement = getElement(distEl);
    if (srcElement != null && discElement != null)
        discElement.value = srcElement.value;
}

/*-----------------------------------------------------------------------------------------------
 * makes value of two element equal
 -----------------------------------------------------------------------------------------------*/
function sysncMoneyValue(sourceEl, distEl) {
    var srcElement = getElement(sourceEl);
    var discElement = getElement(distEl);
    if (srcElement != null && discElement != null)
        discElement.value = replaceString(srcElement.value, ',', '');
}

function appInstallWaitShow() {
    if (isDom) {
        document.all["progress"].style.display = "block";

    } else if (isNav4) {
        document.layers["progress"].visibility = "show";

    } else {
        document.all["progress"].style.display = "block";
    }
}

function appInstallWaitHide() {
    if (isDom) {
        document.all["progress"].style.display = "none";

    } else if (isNav4) {
        document.layers["progress"].visibility = "hide";

    } else {
        document.all["progress"].style.display = "none";
    }

}

/*-----------------------------------------------------------------------------------------
 * set focus to the specific element                                                      *
 * parameters  : element ID                                                               *
 ------------------------------------------------------------------------------------------*/
function setFocus(elementId) {
    var element = document.getElementById(elementId);
    if (element != null)
        element.focus();
}

function isValidLength(value, minLength, maxLength, containMin, containMax) {
    if (minLength > maxLength) {
        var tmp = minLength;
        minLength = maxLength;
        maxLength = tmp;
    }
    var length = value.length;
    var minResult, maxResult;

    if (containMin)
        minResult = length >= minLength;
    else
        minResult = length > minLength;

    if (containMax)
        maxResult = length <= maxLength;
    else
        maxResult = length < maxLength;

    return (minResult && maxResult);
}

/*-----------------------------------------------------------------------------------------
 * returns coordination of a specific element                                                      *
 * parameters  : object o                                                              *
 ------------------------------------------------------------------------------------------*/
var __isIE =  navigator.appVersion.match(/MSIE/);
var __userAgent = navigator.userAgent;
var __isFireFox = __userAgent.match(/firefox/i);
var __isFireFoxOld = __isFireFox && (__userAgent.match(/firefox\/2./i) || __userAgent.match(/firefox\/1./i));
var __isFireFoxNew = __isFireFox && !__isFireFoxOld;


function __parseBorderWidth(width) {
    var res = 0;
    if (typeof(width) == "string" && width != null && width != "" ) {
        var p = width.indexOf("px");
        if (p >= 0) {
            res = parseInt(width.substring(0, p));
        }
        else {
            //do not know how to calculate other values (such as 0.5em or 0.1cm) correctly now
            //so just set the width to 1 pixel
            res = 1;
        }
    }
    return res;
}


//returns border width for some element
function __getBorderWidth(element) {
    var res = new Object();
    res.left = 0; res.top = 0; res.right = 0; res.bottom = 0;
    if (window.getComputedStyle) {
        //for Firefox
        var elStyle = window.getComputedStyle(element, null);
        res.left = parseInt(elStyle.borderLeftWidth.slice(0, -2));
        res.top = parseInt(elStyle.borderTopWidth.slice(0, -2));
        res.right = parseInt(elStyle.borderRightWidth.slice(0, -2));
        res.bottom = parseInt(elStyle.borderBottomWidth.slice(0, -2));
    }
    else {
        //for other browsers
        res.left = __parseBorderWidth(element.style.borderLeftWidth);
        res.top = __parseBorderWidth(element.style.borderTopWidth);
        res.right = __parseBorderWidth(element.style.borderRightWidth);
        res.bottom = __parseBorderWidth(element.style.borderBottomWidth);
    }

    return res;
}

//returns absolute position of some element within document
function getAbsolutePos(element) {
    var res = new Object();
    res.x = 0; res.y = 0;
    if (element !== null) {
        res.x = element.offsetLeft;
        res.y = element.offsetTop;

        var offsetParent = element.offsetParent;
        var parentNode = element.parentNode;
        var borderWidth = null;

        while (offsetParent != null) {
            res.x += offsetParent.offsetLeft;
            res.y += offsetParent.offsetTop;

            var parentTagName = offsetParent.tagName.toLowerCase();

            if ((__isIE && parentTagName != "table") || (__isFireFoxNew && parentTagName == "td")) {
                borderWidth = __getBorderWidth(offsetParent);
                res.x += borderWidth.left;
                res.y += borderWidth.top;
            }

            if (offsetParent != document.body && offsetParent != document.documentElement) {
                res.x -= offsetParent.scrollLeft;
                res.y -= offsetParent.scrollTop;
            }

            //next lines are necessary to support FireFox problem with offsetParent
            if (!__isIE) {
                while (offsetParent != parentNode && parentNode !== null) {
                    res.x -= parentNode.scrollLeft;
                    res.y -= parentNode.scrollTop;

                    if (__isFireFoxOld) {
                        borderWidth = _getBorderWidth(parentNode);
                        res.x += borderWidth.left;
                        res.y += borderWidth.top;
                    }
                    parentNode = parentNode.parentNode;
                }
            }

            parentNode = offsetParent.parentNode;
            offsetParent = offsetParent.offsetParent;
        }
    }
    return res;
}


/*-----------------------------------------------------------------------------------------
 * Browser Window Size and Position                                                     *                                                            *
 ------------------------------------------------------------------------------------------*/

function pageWidth() {return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;}
function pageHeight() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;}
function posRight() {return posLeft()+pageWidth();}
function posBottom() {return posTop()+pageHeight();}

/*-----------------------------------------------------------------------------------------
 * check account is mellatcard                                                            *
 * parameters  : AccountNumber , mellatCardPreFix                                         *
 ------------------------------------------------------------------------------------------*/
function isMellatCardAccount(accountNo, mellatCardPrefix) {
    return !isEmpty(accountNo) && (accountNo.length == 16 && accountNo.substring(0, mellatCardPrefix.length) == mellatCardPrefix) && !isAccessCardAccount(accountNo,'6104337');
}

/*-----------------------------------------------------------------------------------------
 * check account is accesscard                                                            *
 * parameters  : AccountNumber , mellatCardPreFix                                         *
 ------------------------------------------------------------------------------------------*/
function isAccessCardAccount(accountNo, accessCardPrefix) {
    return !isEmpty(accountNo) && (accountNo.length == 16 && accountNo.substring(0, accessCardPrefix.length) == accessCardPrefix );
}


/*-----------------------------------------------------------------------------------------
 * check account is saving                                                            *
 * parameters  : AccountType                                                            *
 ------------------------------------------------------------------------------------------*/

function isSavingAccount(accountType) {
    return !isEmpty(accountType) && accountType > 107;
}

/*-----------------------------------------------------------------------------------------
 * check account is checking                                                              *
 * parameters  : AccountType                                                            *
 ------------------------------------------------------------------------------------------*/
function isCheckingAccount(accountType) {
    return !isEmpty(accountType) && accountType <= 107;
}

/* AJAX section*/

/*-----------------------------------------------------------------------------------------
 * get ajax request object                                       *
 ------------------------------------------------------------------------------------------*/

function getRequestObject() {
    if (window.ActiveXObject) {
        return(new ActiveXObject("Microsoft.XMLHTTP"));
    } else if (window.XMLHttpRequest) {
        return(new XMLHttpRequest());
    } else {
        return(null);
    }
}

function alertResponseData() {
    if ((request.readyState == 4) && request.status == 200) {
        alert(request.responseText);
        alert(request.responseXML);
    }
}


/*-----------------------------------------------------------------------------------------
 * send ajax request
 * parameter  : method => "GET" , "POST"
 * parameter  : handleResponseFunctionName => handler function
 * parameter  : URL => URL of server-side resource
 * parameter  : waitForResponse => Send request asynchronously
 * parameter  : data => always null for GET
 ------------------------------------------------------------------------------------------*/

function sendRequest(method, URL, responseHandlerFunction, waitForResponse, data) {
    request = getRequestObject();
    request.onreadystatechange = responseHandlerFunction;
    request.open(method, URL, waitForResponse);
    switch (method) {
        case "POST":
            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            request.send(data);
            break;

        case "GET":
            request.send(null);
            break;
    }
}

/*-----------------------------------------------------------------------------------------
 * OBJECTS
 ------------------------------------------------------------------------------------------*/




