
// Original code written by Natalie V. Zubar
// Author claims no responsibility for esoteric method of past-life calculations and its results.
// Adpated for thebigview.com by Thomas Knierim and Wanchai Chaisri

function mod(x, x_div){
    for (var i=x; i>=x_div; i -= x_div);
    return i;
}

function checkNum(str, min, max) {
    if (str == "") {
        alert("Please don't leave the birth date blank!");
        return false;
    }
    for (var i = 0; i < str.length; i++) {
        var ch = str.substring(i, i + 1);
        if (ch < "0" || ch > "9") {
            alert("Enter a number, please!");
            return false;
        }
    }
    var val = parseInt(str, 10);
    if ((val < min) || (val > max)) {
        alert("Please type in a number from "+min+" to "+max+".");
        return false;
    }
    return true;
}

function pastlife(form){

    var sex;

//Check for a valid date

    if ((checkNum(form.day.value,1,31)) && (checkNum(form.month.value,1,12)) &&
        (checkNum(form.year.value,1922,9999)))  {
        var day = parseInt(form.day.value,10);
        var cur_month = parseInt(form.month.value,10);
        var cur_year = parseInt(form.year.value,10);

// define past life sex
        cur_year = cur_year % 100;

        if (cur_month-2*(parseInt(cur_month/2)) == 0){
            if (cur_year - 4*(parseInt(cur_year/4)) == 0)
               sex = 1;
            else
               sex = 2
        } else if (cur_year - 4*(parseInt(cur_year/4)) == 0)
               sex = 0;
          else
               sex = 1
        };

        msgWindow=window.open("","diagnosis","width=600,height=400,screenX=100,screenY=100,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,copyhistory=no");
        msgWindow.document.open();
        msgWindow.document.bgColor="black";
        msgWindow.document.fgColor="white";
        msgWindow.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
        msgWindow.document.writeln('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">');
        msgWindow.document.writeln('<head>');
        msgWindow.document.writeln('<title>Past Life Analysis</title>');
        msgWindow.document.writeln('<meta name="Author" content="Natalie V. Zubar" />');
        msgWindow.document.writeln('<meta name="Description" content="Find out what you were in your last life." />');
        msgWindow.document.writeln('<meta name="Keywords" content="past, life, past-life, pastlife, analysis, evaluation, fortune, destiny, esoteric, mystic, mystery, occult" />');
        msgWindow.document.writeln('<link rel="stylesheet" href="../istyles.css" type="text/css" />');
        msgWindow.document.writeln('</head>');
        msgWindow.document.writeln('<body style="padding: 20px">');
        msgWindow.document.writeln("<font size=\"+2\">Your past life diagnosis:</font><hr />");
        msgWindow.document.write("I don't know how you feel about it, but you were ");

        var yearString = "ZYXWOTZYQVUTSXWVNZYXPQTZRWVUMYXWOTZYQVUTSXWVNZYXPUTZRWVUMYXWOTZYQVUTSXWVNZYXPUTZRWVUMYXWOTZYQVUTSXWV";
        var ys; ys = yearString.charAt(cur_year);
        var p1; var p2; var place;

        if (sex == 1){
            msgWindow.document.write("male");

        //for males

            var indexString = "VTWZXYURPSOMNQYWZVTUXOMPSQRNWUXTYZVMRNQOPSUZVYWXTRPSOMNQTYUXVWZPNQMRSOYWZVTUXNSORPQM";
            var profString = "CDBADCABBACD";
            p1 = profString.charAt(cur_month-1);
            for (i=0;i<=6;i++){
                if (ys == indexString.charAt((cur_month-1)*7+i))
                    break

                }
                p2 = i+1;

                //PLACE OF BIRTH Male
                if (p2 == 1){
                        if (day < 3) place=5;
                        else if (day < 10) place=46;
                        else if (day < 17) place=37;
                        else if (day < 24) place=48;
                        else if (day < 31) place=65;
                        else place=6
                };

                if (p2 == 2){
                        if (day < 8) place=28;
                        else if (day < 15)
                                place=58;
                        else if (day < 22)
                                place=10;
                        else if (day < 29)
                                place=38;
                        else place=11
                };

                if (p2 == 3){
                        if (day < 4) place=29;
                        else if (day < 11) place=53;
                        else if (day < 18) place=30;
                        else if (day < 25) place=69;
                        else place=1
                };

                if (p2 == 4){
                        if (day < 7) place=74;
                        else if (day < 14) place=4;
                        else if (day < 21) place=47;
                        else if (day < 28) place=20;
                        else place=26
                };

                if (p2 == 5){
                        if (day < 5) place=23;
                        else if (day < 12) place=21;
                        else if (day < 19) place=44;
                        else if (day < 26) place=16;
                        else place=43
                };

                if (p2 == 6){
                        if (day < 6) place=34;
                        else if (day < 13) place=27;
                        else if (day < 20) place=14;
                        else if (day < 27) place=41;
                        else place=50
                };

                if (p2 == 7){
                        if (day < 2) place=73;
                        else if (day < 9) place=63;
                        else if (day < 16) place=66;
                        else if (day < 23) place=54;
                        else if (day < 30) place=61;
                        else place=72
                }

        } else {
                //for females
                msgWindow.document.write("female");
                var indexString = "OMPSQRNYWZVTUXSQMPNORUZVYWXTQORNSMPZXTWUVYOMPSQRNXVYUZTWNSORPQMVTWZXYUSQMPNORTYUXVWZ";
                var profString = "ACDBCABDDBCA";
                p1 = profString.charAt(cur_month-1);
                for (i=0;i<=6;i++){
                        if (ys == indexString.charAt((cur_month-1)*7+i))
                                break
                }
                p2 = i+1;

                //PLACE OF BIRTH Female

                if (p2 == 1){
                        if (day < 3) place=22;
                        else if (day < 10) place=17;
                        else if (day < 17) place=36;
                        else if (day < 24) place=59;
                        else if (day < 31) place=51;
                        else place=9
                };

                if (p2 == 2){
                        if (day < 8) place=40;
                        else if (day < 15) place=2;
                        else if (day < 22) place=64;
                        else if (day < 29) place=56;
                        else place=35
                };

                if (p2 == 3){
                        if (day < 4) place=19;
                        else if (day < 11) place=67;
                        else if (day < 18) place=13;
                        else if (day < 25) place=32;
                        else place=31
                };

                if (p2 == 4){
                        if (day < 7) place=15;
                        else if (day < 14) place=49;
                        else if (day < 21) place=12;
                        else if (day < 28) place=39;
                        else place=33
                };

                if (p2 == 5){
                        if (day < 5) place=42;
                        else if (day < 12) place=60;
                        else if (day < 19) place=24;
                        else if (day < 26) place=3;
                        else place=52
                };

                if (p2 == 6){
                        if (day < 6) place=18;
                        else if (day < 13) place=25;
                        else if (day < 20) place=57;
                        else if (day < 27) place=45;
                        else place=62
                };

                if (p2 == 7){
                        if (day < 2) place=8;
                        else if (day < 9) place=55;
                        else if (day < 16) place=70;
                        else if (day < 23) place=68;
                        else if (day < 30) place=71;
                        else place=7
                }

        }

        var pro; pro=p1+p2;
        msgWindow.document.write(" in your last earthly incarnation.");
        //msgWindow.document.write("month=" + cur_month + " place=" + place + " ys=" + ys + " pro=" + pro + "<br />");

        //country data

        var countryString="";

        if (place == 1) countryString="Alaska";
        else if (place == 2) countryString="Yukon";
        else if (place == 3) countryString="North Canada";
        else if (place == 4) countryString="Ontario";
        else if (place == 5) countryString="Quebec";
        else if (place == 6) countryString="Labrador";
        else if (place == 7) countryString="Newfoundland";
        else if (place == 8) countryString="Greenland";
        else if (place == 9) countryString="USA North-West";
        else if (place == 10) countryString="USA South-West";
        else if (place == 11) countryString="USA North-Center";
        else if (place == 12) countryString="USA South-Center";
        else if (place == 13) countryString="USA North-East";
        else if (place == 14) countryString="USA South-East";
        else if (place == 15) countryString="Arctic";
        else if (place == 16) countryString="Scotland";
        else if (place == 17) countryString="Northern England";
        else if (place == 18) countryString="Central England";
        else if (place == 19) countryString="Southern England";
        else if (place == 20) countryString="Wales";
        else if (place == 21) countryString="Ireland";
        else if (place == 22) countryString="North Europe";
        else if (place == 23) countryString="France";
        else if (place == 24) countryString="Spain";
        else if (place == 25) countryString="Portugal";
        else if (place == 26) countryString="Austria";
        else if (place == 27) countryString="Germany";
        else if (place == 28) countryString="Ukraine";
        else if (place == 29) countryString="Italy";
        else if (place == 30) countryString="Turkey";
        else if (place == 31) countryString="West Russia";
        else if (place == 32) countryString="Siberia";
        else if (place == 33) countryString="Center Russia";
        else if (place == 34) countryString="Greece";
        else if (place == 35) countryString="Iran";
        else if (place == 36) countryString="Saudi Arabia";
        else if (place == 37) countryString="Poland";
        else if (place == 38) countryString="Hungary";
        else if (place == 39) countryString="Yugoslavia";
        else if (place == 40) countryString="Romania";
        else if (place == 41) countryString="Bulgaria";
        else if (place == 42) countryString="Israel";
        else if (place == 43) countryString="Tibet";
        else if (place == 44) countryString="Burma";
        else if (place == 45) countryString="Thailand";
        else if (place == 46) countryString="South China";
        else if (place == 47) countryString="Mongolia";
        else if (place == 48) countryString="North China";
        else if (place == 49) countryString="Korea";
        else if (place == 50) countryString="North Japan";
        else if (place == 51) countryString="South Japan";
        else if (place == 52) countryString="Sumatra";
        else if (place == 53) countryString="Borneo";
        else if (place == 54) countryString="Phillippines";
        else if (place == 55) countryString="New Guinea";
        else if (place == 56) countryString="North Australia";
        else if (place == 57) countryString="West Australia";
        else if (place == 58) countryString="East Australia";
        else if (place == 59) countryString="South Australia";
        else if (place == 60) countryString="North New Zealand";
        else if (place == 61) countryString="South New Zealand";
        else if (place == 62) countryString="Oceania";
        else if (place == 63) countryString="North India";
        else if (place == 64) countryString="Central India";
        else if (place == 65) countryString="South India";
        else if (place == 66) countryString="Egypt";
        else if (place == 67) countryString="North Africa";
        else if (place == 68) countryString="West Africa";
        else if (place == 69) countryString="Central Africa";
        else if (place == 70) countryString="South Africa";
        else if (place == 71) countryString="Mexico";
        else if (place == 72) countryString="Cyprus";
        else if (place == 73) countryString="North of Latin America";
        else countryString="South of Latin America";

        //year of past life calculation

        var ys1;

    if (ys == "M") var mString = "185014001125102507000700180014751800130011751100";
        else if (ys == "N") var mString = "092518750425185017501350080006750825182515250875";
        else if (ys == "O") var mString = "172516750875070013251825177508001075165009001625";
        else if (ys == "P") var mString = "145005001800100008000550165017001325072511001550";
        else if (ys == "Q") var mString = "100014500950042517001525135011001625122517251025";
        else if (ys == "R") var mString = "097513751200127504500825137513500700092509250725";
        else if (ys == "S") var mString = "122506251250142509251150147507501300157506001125";
        else if (ys == "T") var mString = "117514001825127517500975185011501600187515251850";
        else if (ys == "U") var mString = "090009000775105013751675107515000825072510251500";
        else if (ys == "V") var mString = "122507501825140011501325167512751475160009501200";
        else if (ys == "W") var mString = "057516750775047517001450085017251775102517750400";
        else if (ys == "X") var mString = "180015751425157515501200160012001300037507751250";
        else if (ys == "Y") var mString = "107512501000165009501825155014250800175010750875";
        else                    var mString = "097505251175085015751125177513500700065013501050";

        ys1 = mString.charAt((cur_month-1)*4);

        if (ys1 == "0") ys1 = ""; {

        ys1 += mString.charAt((cur_month-1)*4+1);
        ys1 += mString.charAt((cur_month-1)*4+2);
        ys1 += mString.charAt((cur_month-1)*4+3)

        } ;

        //past life profession

        if (pro == "A1") var proString = "digger, undertaker";
        else if (pro == "A2") var proString = "philosopher and thinker";
        else if (pro == "A3") var proString = "designer, engineer or craftsman";
        else if (pro == "A4") var proString = "chemist, alchemist or poison manufacturer";
        else if (pro == "A5") var proString = "seaman, cook or carpenter";
        else if (pro == "A6") var proString = "jeweler or watch-maker";
        else if (pro == "A7") var proString = "medic, surgeon or herbalist";
        else if (pro == "C1") var proString = "shepherd, horseman or forester";
        else if (pro == "C2") var proString = "leader, major or captain";
        else if (pro == "C3") var proString = "librarian, priest or keeper of tribal relics";
        else if (pro == "C4") var proString = "entertainer, musician, poet or temple-dancer";
        else if (pro == "C5") var proString = "seaman, dealer, businessman or broker";
        else if (pro == "C6") var proString = "monk (nun), bee-keeper or lone gunman";
        else if (pro == "C7") var proString = "writer, dramatist or organiser of rituals";
        else if (pro == "B1") var proString = "builder of roads, bridges and docks";
        else if (pro == "B2") var proString = "map maker, astrologer, astronomer";
        else if (pro == "B3") var proString = "handicraftsman or mechanic";
        else if (pro == "B4") var proString = "warrior, hunter, fisherman or executor of sacrifices";
        else if (pro == "B5") var proString = "artist, magician or fortune teller";
        else if (pro == "B6") var proString = "sailor or shoemaker";
        else if (pro == "B7") var proString = "builder of houses, temples and cathedrals";
        else if (pro == "D1") var proString = "trainer or holder of fine animals, such as birds.";
        else if (pro == "D2") var proString = "preacher, publisher or writer of ancient inscriptions";
        else if (pro == "D3") var proString = "farmer, weaver or tailor";
        else if (pro == "D4") var proString = "dramatist, director, musician or bard";
        else if (pro == "D5") var proString = "banker, usurer, moneylender or judge";
        else if (pro == "D6") var proString = "teacher, mathematician or geologist";
        else var proString = "dancer, singer or actor";

        //characteristics

        if (p2 == 1) {
                if (place-2*(parseInt(place/2)) > 0) var charString = "Person with huge energy, good in planning and supervising. If you were just garbage-man, you were chief garbage-man.";
                else var charString = "Revolutionary type. You inspired changes in any sphere - politics, business, religion, housekeeping. You could have been a leader."
                }
        else if (p2 == 2) {
                if (place-2*(parseInt(place/2)) > 0) var charString = "Artistic personality, always transforming the ugly into the beautiful, gray into bright colors. You would find an opportunity of creative self-expression in any situation.";
                else var charString = "Timid, constrained, quiet person. You had creative talents, which waited until this life to be liberated. Sometimes your environment considered you strange."
                }
        else if (p2 == 3) {
                if (place-2*(parseInt(place/2)) > 0) var charString = "Seeker of truth and wisdom. You could have seen your future lives. Others perceived you as an idealist illuminating path to future.";
                else var charString = "You always liked to travel and to investigate. You could have been a detective or a spy."
                }
        else if (p2 == 4) {
                if (place-2*(parseInt(place/2)) > 0) var charString = "You were a sane, practical person, a materialist with no spiritual consciousness. Your simple wisdom helped the weaker and the poor.";
                else var charString = "You always liked to travel and to investigate. You could have been a detective or a spy."
                }
        else if (p2 == 5) {
                if (place-2*(parseInt(place/2)) > 0) var charString = "Bohemian personality, mysterious, highly gifted, capable to understand ancient books. With a magician's abilities, you could have been a servant of dark forces.";
                else var charString = "As a natural talent in psychology, you knew how to use your opportunities. Cold-blooded and calm in any situation."
                }
        else if (p2 == 6) {
                if (place-2*(parseInt(place/2)) > 0) var charString = "Inquisitive, inventive, you liked to get to the very bottom of things and to rummage in books. Talent for drama, natural born actor."
                else var charString = "Such people are always involved with all new. You have always loved changes, especially in art, music, cooking."
                }
        else if (p2 == 7) {
                if (place-2*(parseInt(place/2)) > 0) var charString = "You had the mind of a scientist, always seeking new explanations. Your environment often misunderstood you, but respected your knowledge.";
                else var charString = "Ruthless character, carefully weighing his decisions in critical situations, with excellent self-control and strong will. Such people are generally liked, but not always loved."
                };

        // past life lesson
        
        if (p2 == 1){
            if (day < 12) var lesString = "You are bound  to solve problems of pollution of environment, recycling, misuse of raw materials, elimination of radioactivity by all means including psychological methods.";
                else if (day < 22) var lesString = "Your lesson is to learn humility and faith in spiritual principles. You should believe in higher reasons.";
        else  var lesString = "You are bound  to learn to understand other people and to meet all difficulties of life with a joyful heart. You should help others by bringing them a spirit of joy."
                }
        else if (p2 == 2) {
                 if (day < 12) var lesString = "It always seemed to you that your perceptions of the world are somewhat different. Your lesson is to trust your intuition as your best guide in your present life.";
                 else if (day < 22) var lesString = "Your main task is to make the world more beautiful. Physical and spiritual deserts are just waiting for your touch. Keep smiling!";
         else var lesString = "Your main lesson is to develop magnanimity and a feeling of brotherhood. Try to become less adhered to material property and learn to take only as much, as you can give back."
                }
        else if (p2 == 3) {
            if (day < 12) var lesString = "Your lesson is to develop a kind attitude towards people, and to acquire the gift of understanding and compassion.";
                else if (day < 22) var lesString = "Your lesson is the development and expansion of your mental consciousness. Find a good teacher and spend a good part of your time and energy on learning from his wisdom.";
        else var lesString = "You fulfill your lesson by helping old folks and children. You came to this life to learn to care about the weak and the helpless."
                }
        else if (p2 == 4) {
                if (day < 12) var lesString = "You should develop your talent for love, happiness and enthusiasm and you should distribute these feelings to all people.";
                else if (day < 22) var lesString = "You should develop self-love and ability to implant hope into hearts of people. Ambition is not everything. True wealth is buried in your soul.";
        else var lesString = "Your lesson is to conquer jealousy and anger in yourself and then in those who will select you as their guide. You should understand that these weaknesses are caused by fear and self-regret."
                }
        else if (p2 == 5) {
            if (day < 12) var lesString = "Your task is to learn, to love and to trust the universe. You are bound to think, study, reflect, and to develop inner wisdom.";
                else if (day < 22) var lesString = "Your task is to learn determination and persistency. Youd should not allow to let misfortunes take influence on your strong will.";
                else var lesString = "The timid, lonely and self-confident people are everywhere, and your task is to overcome these tendencies in yourself and then to help other people."
                }
        else if (p2 == 6) {
                if (day < 12) var lesString = "The world is full of ill and lonely people. You should help those, who are less fortunate than you are.";
                else if (day < 22) var lesString = "There is an invisible connection between the material and the spiritual world. Your lesson is to search, find and use this magical bridge.";
        else var lesString = "Your lesson is to learn discretion and moderation and then to teach others to do the same. Your life will be happier if you help those who lack reasoning."
                }
        else if (p2 == 7) {
            if (day < 12) var lesString = "Your lesson is to study, to practice and to use the wisdom that lies within the psychological sciences and in ancient manuscripts. With strong faith and hard work you will reach your real destiny in your present life.";
                else if (day < 22) var lesString = "Your lesson is to combat violence and disharmony in our world, to understand its roots and origins. All global problems have similar origins.";
        else var lesString = "Magic is everywhere around you, even in the most usual, most ordinary situations. Your lesson is to understand this magic and to help other people to see it, too. You are a magician!"
                };

        //message composition

        msgWindow.document.writeln("You were born somewhere in the territory of modern " + countryString);
        msgWindow.document.writeln(" around the year " + ys1 + ".");
        msgWindow.document.writeln("Your profession was that of a " + proString + ".<hr>");
        msgWindow.document.writeln("Your brief psychological profile in your past life:<br />" + charString.fontcolor("silver") + "<hr />");
        msgWindow.document.writeln("The lesson that your last past life brought to your present incarnation:<br />" + lesString.fontcolor("silver") + "<hr />");
        msgWindow.document.writeln("Do you remember now?");
        msgWindow.document.writeln("<p align=center><input name=\"closebutton\" onClick=\"window.close()\" type=\"button\" value=\"Close\"></p>");
        msgWindow.document.writeln("</body></html>");

}
