function isEmpty(inputStr) {

        if (inputStr == "" || inputStr == null) {

                return true

        }

        return false

}

function isNumber(inputStr) {

        for (var i = 0; i < inputStr.length; i++) {

                var oneChar = inputStr.charAt(i)

                if (oneChar < "0" || oneChar > "9") {

                        return false

                }

        }

        return true

}


function inRangeDay(inputStr) {

        num = parseInt(inputStr)

        if (num < 1 || num > 31) {

                return false

        }

        return true

}


function inRangeYear(inputStr) {

        num = parseInt(inputStr)

        if (num < 1900 || num > 3000) {

                return false

        }

        return true

}


function isValidDay(inputStr) {

        if (isEmpty(inputStr)) {

                alert("Lütfen geçerli bir değer giriniz.")

                return false

        } else {

                if (!isNumber(inputStr)) {

                        alert("Lütfen geçerli bir değer giriniz.")

                        return false

                } else {

                        if (!inRangeDay(inputStr)) {

                                alert("Lütfen geçerli bir değer giriniz.")

                                return false

                        }

                }

        }

        return true

}


function isValidYear(inputStr) {

        if (isEmpty(inputStr)) {

                alert("Lütfen geçerli bir değer giriniz.")

                return false

        } else {

                if (!isNumber(inputStr)) {

                        alert("Please be sure the year is a number only.")

                        return false

                } else {

                        if (!inRangeYear(inputStr)) {

                                alert("Please be sure the year is a number only.")

                                return false

                        }

                }

        }

        return true

}



function makeArray(n) {

        this.length = n

        for (var i=1; i <= n; i++)

                this[i] = null

                return this

}



var monthtotal = new makeArray(12)

monthtotal[1] = 31

monthtotal[2] = 28

monthtotal[3] = 31

monthtotal[4] = 30

monthtotal[5] = 31

monthtotal[6] = 30

monthtotal[7] = 31

monthtotal[8] = 31

monthtotal[9] = 30

monthtotal[10] = 31

monthtotal[11] = 30

monthtotal[12] = 31



var moname = new makeArray(12)

moname[1] = "Ocak"

moname[2] = "Şubat"

moname[3] = "Mart"

moname[4] = "Nisan"

moname[5] = "Mayıs"

moname[6] = "Haziran"

moname[7] = "Temmuz"

moname[8] = "Ağustos"

moname[9] = "Eylül"

moname[10] = "Ekim"

moname[11] = "Kasım"

moname[12] = "Aralık"



var daystoadd = new makeArray(7)

daystoadd[1] = 13

daystoadd[2] = 279



// Calculate the date string

function calcNewDate(month,day,year,daystoadd) {

        newday = eval(day) + daystoadd

        newmonth = month + 1

        newyear = eval(year)

        var max



        for (var i = 0; i < 12; i++) {

          if (newmonth == 2 && (newyear % 4) == 0) {

            max = 29

          } else

            max = monthtotal[newmonth]



          if (newday > max) {

            newday = newday - max

            newmonth = newmonth + 1

            if (newmonth > 12) {

              newyear = newyear + 1

              newmonth = 1

            }

          }

          else

            break

        }



        var datestring = newday + " " + moname[newmonth] + " " + newyear

        return datestring

}



// Get the date entered and calculate the rest of the dates

function calc(form) {



        day = form.day.value

        year = form.year.value

        monthnum = form.month.selectedIndex



        if (isValidDay(day)) {

          if (isValidYear(year)){

            form.concdate.value = calcNewDate(monthnum,day,year,daystoadd[1])

            form.duedate.value = calcNewDate(monthnum,day,year,daystoadd[2])

          }

        }


}
