   var zodiacInfo = new Array(
   "Rat: 1936, 1948, 1960, 1972, 1984, 1996, 2008<br><br>Characteristics: People born in the year of Rat are charming, bright, creative, and thrifty but generous;  They work hard to achieve their goals and acquire possessions;  Rat people are easily excited and angered but they can control themselves;  They long for romantic and show strong curiosity to opposite sex;  They are chariness and considerate to opposite sex and will never let opposite sex feel boring and vapidity.<br><br>Best Career: sales, writer, critic, publicist, or doctor<br><br>Marriage: most compatible with Dragon, Monkey, and Ox people but not compatible with Horse people.",
   "Ox: 1937, 1949, 1961, 1973, 1985, 1997, 2009<br><br>Characteristics:  People born in the year of Ox are easy-going, steadfast, dependable and methodical; They are a born leader and they inspire confidence from all around them;  Ox people are actualist and lack romantism;  Generally speaking, they speak little but have fierce tempers and can angry easily;  Their eccentric and bigoted characteristics will result in losing good friends.<br><br>Best Career: surgeon, attorney, hairdresser, farmer, or artist<br><br>Marriage: most compatible with Snake, Rooster, and Rat people but not compatible with Sheep people.",
   "Tiger:  1938, 1950, 1962, 1974, 1986, 1998, 2010<br><br>Characteristics: People born in the year of Tiger are dynamic, warm, sincere, sensitive and emotional;  However, some of Tiger people are very short-tempered and stubborn; Tiger people are independent and they like stay alone, and usually have hard time to get along with other people.<br><br>Best Career: manager, taxi driver, sales person<br><br>Marriage: most compatible with Horse, Dragon and Dog people but not compatible with Snake, Monkey and Pig people.",
   "Rabbit:  1939, 1951, 1963, 1975, 1987, 1999, 2011<br><br>Characteristics: Rabbit people are talented, ambitious, honest and humble;   They are very romantic and tender but sometimes sentimental;  Usually, Rabbit people are meticulosity, cautious and conscientious for their jobs and they never break a contract;  They are fond of gossip but are tactful and generally kind;  Rabbit people are affectionate, obliging, always pleasant and seldom lose their temper. <br><br>Best Career: lawyer, farmer and diplomat <br><br>Marriage: most compatible with Sheep, Pig and Dog people, but not compatible with Rooster people.",
   "Dragon:  1940, 1952, 1964, 1976, 1988, 2000, 2012<br><br>Characteristics: People born in the year of Dragon are full of vitality and enthusiasm, they are gifted and intelligent but are very stubborn and short-tempered;  Dragon people are ambitious and most of them are risk takers, but they can easily give up once they suffer any frustrations.<br><br>Best Career:  Dragon people are suitable for any careers, but artist, priest and politician are among the best.<br><br>Marriage: most compatible with Rat, Tiger, Snake, Monkey and Rooster people, but not compatible with Dog people.",
   "Snake:  1941, 1953, 1965, 1977, 1989, 2001, 2013<br><br>Characteristics: People born in the year of Snake are discreet, rich in wisdom and charm;  They say little but think deeply;  Snake people are very vain, selfish and quite stingy, however, they are passionate and like to help others;  Usually they do not trust other people but would rather rely on themselves.<br><br>Best Career: teacher, writer, psychiatrist and philosopher<br><br>Marriage: most compatible with the Ox, Dragon and Rooster, but not compatible with Tiger and Pig people.",
   "Horse:  1942, 1954, 1966, 1978, 1990, 2002, 2014<br><br>Characteristics: People born in the year of Horse are wise, talented and very competitive; they are social people and are friendly and very popular among their peers; Horse people are independent but, on the other hand, they are very stubborn and rarely listen to advices.<br><br>Best Career: scientist, entrepreneur, poet and politician.<br><br>Marriage: most compatible with Tiger, Dog and Sheep people but not compatible with Rat people.",
   "Sheep:  1943, 1955, 1967, 1979, 1991, 2003, 2015<br><br>Characteristics: People born in the year of Sheep are artistic and elegant, and they are highly accomplished in the arts;  Most of Sheep people are timid, shy and pessimistic, and they worry about their future sometimes;  Sheep people are warmhearted and compassionate and they enjoy helping other people;  Sheep people are clumsy in speech thus they do not like to deliver public speech;  They can easily trust other people and are passionate about what they believe in.<br><br>Best Career: doctor, artist and beautician.<br><br>Marriage: most compatible with Rabbit, Pig, and Horse people but not compatible with Ox people.",
   "Monkey:  1944, 1956, 1968, 1980, 1992, 2004, 2016<br><br>Characteristics: People born in the year of Monkey are intelligent and witty;  They are very popular because of their remarkable nature and magnetic personality; Monkey people are versatile and extraordinary inventive, they can easily solve most of tough problems, and they can success in almost any fields;  Sometimes, Monkey people are opportunist and they distrust other people.<br><br>Best Career: good in any field.<br><br>Marriage: most compatible with Dragon and Rat people but not compatible with Tiger and Pig people.",
   "Rooster:  1945, 1957, 1969, 1981, 1993, 2005, 2017<br><br>Characteristics: People born in the year of Rooster are smart, capable and shrewd; they like to be busy so usually they work very hard; Rooster people are quite arrogant and often eccentric, they have difficulties to get along with other people; Rooster people are aggressive and perfectionist, they usually are devoted beyond their capabilities and will be deeply disappointed if they fail but will boast to others if they success.<br><br>Best Career: restaurateur, doctor, publicist.<br><br>Marriage: most compatible with Ox, Snake and Dragon people but not compatible with Rabbit people.",
   "Dog:  1946, 1958, 1970, 1982, 1994, 2006, 2018<br><br>Characteristics: People born in the year of Dog are honest and faithful to those people they love;  Dog people are conservative and sometimes selfish and rather stubborn;  They are sympathetic and like to help other people;  Usually Dog people are good leaders;<br><br>Best Career: teacher, doctor and businessman.<br><br>Marriage: most compatible with Horse, Tiger and Rabbit people but not compatible with Dragon.",
   "Pig:  1947, 1959, 1971, 1983, 1995, 2007, 2019<br><br>Characteristics: People born in the year of Pig are loyal, honest and sincere; Usually they are taciturn, do not talk much and hate arguments and quarreling, and they do not make many friends but have a few life-long friends;  Pig people are fortitudinous and they will try to work out whatever tough problems they meet; Sometimes Pig people are quite naive and they can easily trust other people.<br><br>Best Career: entertainer and lawyer.<br><br>Marriage: most compatible with Rabbit and Sheep people but not compatible with Snake, Monkey and Tiger people."
   );
   
   var zodiacImg = new Array(
           "Rat",
           "Ox",
           "Tiger",
           "Rabbit",
           "Dragon",
           "Snake",
           "Horse",
           "Sheep",
           "Monkey",
           "Rooster",
           "Dog",
           "Pig"
       );   
   
   //view friend's zodiac    
   function getfriend(){
     if( checkage())
         {
          var oindex = document.getElementById("fidselect").value;
          document.getElementById("myname").innerHTML = document.getElementById("fidselect")[oindex].text + " 's " ;       
         }   
         getzodiac();
    }   
    
    //view selected year zodiac May 19,2008 view year in title
    function getzodiacyear()
        {
         var birthyear = document.getElementById("YYYY").value;
         var birthmonth = document.getElementById("MM").value;
         var birthday = document.getElementById("DD").value;
       
         var dateselect = birthyear + "-" + birthmonth + "-" + birthday;
         document.getElementById("myname").innerHTML = dateselect +" 's ";
         getzodiac();
        }   
    
    //get the content of zodiac
    function getzodiac(){
       var viewzodiac = document.getElementById("viewzodiac");
       var zodiacyear = document.getElementById("zodiacdate");
       var toyear = 1901;
       var birthyear = document.getElementById("YYYY").value;
       var birthmonth = document.getElementById("MM").value;
       var birthday = document.getElementById("DD").value;       
       
       var birthpet = 1;
       
       //get img of zodiac
       var imgurl = "http://www.antsbase.com/facebook/chinesezodiac/imgs/";
       
       //get LunarCalendar by give parament
       var objCal = new calendar(birthyear, (parseInt(birthmonth) - 1),birthday);
       birthyear = objCal[0].lYear;       
       zodiacyear.value = birthyear;
       var x = (toyear - birthyear) % 12;
       if ((x == 1) || (x == -11)) 
           {
             birthpet = 0;
           }
       if (x == 0) 
          {
           birthpet = 1;
          }
       if ((x == 11) || (x == -1)) 
          {
           birthpet = 2;
          }
       if ((x == 10) || (x == -2)) 
          {
           birthpet = 3;
          }
       if ((x == 9) || (x == -3)) 
           {
            birthpet = 4;
           }
       if ((x == 8) || (x == -4)) 
           {
            birthpet = 5;
           }
       if ((x == 7) || (x == -5)) 
           {     
            birthpet = 6;
           }
       if ((x == 6) || (x == -6)) 
          {
            birthpet = 7; 
           }
       if ((x == 5) || (x == -7)) 
          {
           birthpet = 8; 
          }
       if ((x == 4) || (x == -8)) 
          {
           birthpet = 9;
          }
       if ((x == 3) || (x == -9)) 
          {
           birthpet = 10;
          }
       if ((x == 2) || (x == -10)) 
          {
            birthpet=11;
           }
           
       viewzodiac.innerHTML = zodiacInfo[birthpet];
       document.getElementById("pic1").src = imgurl + zodiacImg[birthpet] + "_Chiese.gif";
       document.getElementById("pic2").src = imgurl + zodiacImg[birthpet] + ".gif";
       document.getElementById("pic3").src = imgurl + zodiacImg[birthpet] + "_English.gif";
    }
    
    //get friend info     
    function init() {
       MYOS_TRACE = true;
       var os = opensocial.Container.get();
       var dataReqObj = os.newDataRequest();
       var param = {};

       param[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [opensocial.Person.Field.ID,opensocial.Person.Field.NAME,opensocial.Person.Field.AGE];

       var viewerReq = os.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER,param);  
       dataReqObj.add(viewerReq,'viewer'); 
     
       param = {};

       param[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [opensocial.Person.Field.ID,opensocial.Person.Field.NAME,opensocial.Person.Field.THUMBNAIL_URL,opensocial.Person.Field.AGE];
       param[opensocial.DataRequest.PeopleRequestFields.MAX] = 5000;

       var viewerFriendsReq = os.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS,param);  
       dataReqObj.add(viewerFriendsReq,'viewerfriend');   
       dataReqObj.send(dataCallbackzodiac);
    }     
  
    function dataCallbackzodiac(dataResponse) {  
        if (dataResponse.hadError()) {
            var data = dataResponse.get('viewerfriend');    
            trace(data.getErrorMessage() + ", Error happen when to get your friends!");
        
         } else {   
            var viewerData = dataResponse.get('viewer').getData();    
            var viewerName = viewerData.getField(opensocial.Person.Field.NAME);    
            var viewerAge = viewerData.getField(opensocial.Person.Field.AGE);   
                        
            var friendsData = dataResponse.get('viewerfriend').getData();   
            //(friendsData.size() >= 1); may has one friend of Tom or more
            friendsData.each(     
            function(friendData) {        
                var friendName = friendData.getField(opensocial.Person.Field.NAME);  
                var friendId = friendData.getField(opensocial.Person.Field.ID); 
                var friendAge = friendData.getField(opensocial.Person.Field.AGE);
                var friendPic = friendData.getField(opensocial.Person.Field.THUMBNAIL_URL);
                trace2 (friendName ); 
                trace3(friendAge);
                //append invite friends' div
                tracediv (friendId,friendName, friendPic); 
            } );
            
        }
     
     }//end function
     
   //append error code to div     
   function trace(msg) {   
       //May 29, 2008  yangkunlin, do not print message
      document.getElementById('message').innerHTML = '<div style="width:600px;color:red;font-size:13px;text-align:center;margin:0 auto;">' + msg + '</div>';

      if(msg != '')
         {
          var funStr = 'trace("")';
          window.setTimeout(funStr, 5000);
         }
   }
   
   //append friendlist to select list
   var fnum = 0;
   function trace2(name) { 
      document.getElementById("fidselect").options.add(new Option(name,fnum));
      fnum ++;
   }
   
   function trace3(msg) {
      if( document.getElementById("fage").value.replace(/(^\s*)|(\s*$)/g,"") == '' )
         {
           document.getElementById("fage").value = msg;
         }
      else
         {
          document.getElementById("fage").value = document.getElementById("fage").value 
              + ',' +msg;
         }
      
   }
   
   //appace friend info to invite div
   function tracediv(id,name,pic) {   
      var indiv = document.getElementById('invitediv');
      indiv.style.width = "600px";

      var divFriendHTML = "<div id='"+id+"' style='width:76px;height:91px;border:1px solid #ff2061;margin:4px;text-align:center; float:left;background-color:#ffffff;cursor:pointer;overflow:hidden;' align='center' onclick='javascript:selectUser("+ id +")'><div style='width:70px;height:70px;margin-top:2px;margin-left:1px;border:1px solid #ff2061;overflow:hidden;'><img src='" + pic + "' width='70px'/></div><div style='font-size:12px;'>"+name+"</div></div>";

      indiv.innerHTML = indiv.innerHTML + divFriendHTML;
      
      //var childappend =  document.createElement("div");
      //indiv.appendChild(childappend);
      //childappend.id = id;
      //childappend.attachEvent("onclick",function(){ selectUser(childappend.id);});
      
      // new Button(childappend,"test",function(){selectUser(childappend.id);}); 
      
      //childappend.style.width = "76px";
      //childappend.style.height = "91px";
      //childappend.style.border = "1px solid #ff2061";
      //childappend.style.textAlign = "center";
      //childappend.style.styleFloat = "left";
      //childappend.style.margin = "4px";
      //childappend.style.backgroundColor = "#ffffff";
      //childappend.style.cursor = "pointer";
      //childappend.style.overflow = "hidden";
      //childappend.style.align = "center";
      
      //add img
      //var imgdiv = document.createElement("div");
      //childappend.appendChild(imgdiv);
      //imgdiv.style.width = "70px";
      //imgdiv.style.height = "70px";
      //imgdiv.style.marginTop = "2px";
      //imgdiv.style.marginLeft = "1px";
      //imgdiv.style.border = "1px solid #ff2061";
      //imgdiv.style.overflow = "hidden";      
      //imgdiv.innerHTML = "<img src='" + pic + "'>";
      
      
      //add name
      //var textdiv = document.createElement("div");
      //childappend.appendChild(textdiv);      
      //textdiv.style.fontSize = "12px";
      //textdiv.innerHTML = name;      
      
      //trace id to hidden 
      var friendid = document.getElementById('all_friend_ids').value;
      document.getElementById('all_friend_ids').value = friendid + id + ",";     
      
   }
   
   //check friend selected 's age is correct
   function checkage()
    {
      var fid = document.getElementById("fidselect").value;
      var fage;

      if( document.getElementById("fage").value.replace(/(^\s*)|(\s*$)/g,"") != '')
         {
          fage = document.getElementById("fage").value.split(',')[fid];
         }

      if(fage.replace(/(^\s*)|(\s*$)/g,"") == 'undefined' || fage == null || fage.replace(/(^\s*)|(\s*$)/g,"") == '')
         {
          var oindex = document.getElementById("fidselect").value;          
          trace("Unable to get " + document.getElementById("fidselect")[oindex].text + "'s complete birthday! If you know his/her birthday, you can check Chinese Zodiac for that date." );
          return false;
         }
      else
         {
          document.getElementById("YYYY").value = new Date().getFullYear() - parseInt(fage);
          return true;
         }
   }
  
  //check invite friend botten 
  function iviteFriend()
     {
      document.getElementById("invitefriend").style.display = "";  
      document.getElementById("zodiacdiv").style.display = "none"; 
      document.getElementById("myname").innerHTML = "";
     }
   
   //fire when user select a friend to send notification or invitation  
   function selectUser(id) { 
    var friend_id_input = document.getElementById('friend_ids');  
    var allFriendsInput = document.getElementById('all_friend_ids');    
    var strAllFriendIds = allFriendsInput.value;
    
    //delete the last char ','
    strAllFriendIds = strAllFriendIds.substring(0,strAllFriendIds.length-1);    
    
    var arrAllFriendIds = strAllFriendIds.split(','); 
    
    for(i=0; i< arrAllFriendIds.length;i++)
        {
         var obj = document.getElementById(arrAllFriendIds[i]);           
         obj.style.backgroundColor = '#ffffff';
        }
    
    friend_id_input.value = id;
    var obj = document.getElementById(id);           
    obj.style.backgroundColor = '#fe89ad'; 
    
    //disable the botton
    if(document.getElementById('friend_ids').value == "")
        {
         document.getElementById("ivitefriend").disabled = "disabled";
        }
     else
       {
        document.getElementById("ivitefriend").disabled = "";
       }
  } 
  
  //send invitation to friends
  function tosendinvite(){
     var friend_id_input = document.getElementById('friend_ids');  
     var friend_id_value = friend_id_input.value;    
     var friend_ids = friend_id_value;
      sendMessage(friend_ids);
  }
  
  //send message to user
  function sendMessage(id){
        //alert(id);
        var req = opensocial.newDataRequest();
        req.add(req.newFetchPeopleRequest('VIEWER_FRIENDS'),'viewer_friends');
        req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER));
        req.send(function(dataResponse){
            if (dataResponse.hadError()) {
                var data = dataResponse.get('viewer_friends');    
                trace(data.getErrorMessage());
        
            } else {   
                var viewerData = dataResponse.get(opensocial.DataRequest.PersonId.VIEWER).getData();
                var viewerName = viewerData.getField(opensocial.Person.Field.NAME);
                //var viewerUrl = viewerData.getField(opensocial.Person.Field.PROFILE_URL);

                var friendsData = dataResponse.get('viewer_friends').getData();
                friendsData.each(function(data){
                    var friendID = data.getField(opensocial.Person.Field.ID);
                    var friendName = data.getDisplayName();
                    if(friendID == id){
                        var os_token = MyOpenSpace.MySpaceContainer.OSToken;
                        var osContainer = opensocial.Container.get();
                        var message = opensocial.newMessage(msgtxt);
                         message.setField(opensocial.Message.Field.TITLE,viewerName + " " + msghead);
                         message.setField(opensocial.Message.Field.TYPE, 'SEND_MESSAGE');
                         //os_token, opensocial.Message, opensocial.Person ,callback
                         osContainer.postTo(os_token, message,data);
                     }
                });
            }   
        });
  }
  
   //save app data function
   function updateData(data)
      {
       var rs = opensocial.newDataRequest();
       rs.add(rs.newUpdatePersonAppDataRequest(opensocial.DataRequest.PersonId.VIEWER,"zodiacyear", data), 'zodiacyear');
       rs.send(updateSent);
      }
    
   //updateData callback function
   function updateSent(response)
      {
       if(response.hadError())
          {
           var data = response.get('zodiacyear');    
           trace(data.getErrorMessage() + ", " + "You unsuccessfully set Chinese Zodiac into your Profile!");
           }
       else
           {
            trace("You successfully set My Chinese Zodiac into your Profile!");
           }
      }
    
    //view  zodiac info, hidden invite div
   function toviewzodiac()
      {
       document.getElementById("invitefriend").style.display = "none";  
       document.getElementById("zodiacdiv").style.display = ""; 
      } 
   
   //view set profile div, hidden zodiac info
   function viewsetprofile()
      {
       document.getElementById("tview1").style.display = "none";  
       document.getElementById("tprofile1").style.display = ""; 
       document.getElementById("tview2").style.display = "none";  
       document.getElementById("tprofile2").style.display = "";
       document.getElementById("selectfdiv").style.display = "none";
       document.getElementById("viewchar").innerHTML = "Confirm your birthday:";
      }    
    
    //set viewer age to application data, and tip successfully set
   function setprofile()
      {
       getzodiac();
       var zodiacyear = document.getElementById("zodiacdate");
       updateData(zodiacyear.value);
       tocancel();
      }   
    
   //go to zodiac info page 
   function tocancel()
      {
       document.getElementById("tview1").style.display = "";  
       document.getElementById("tprofile1").style.display = "none"; 
       document.getElementById("tview2").style.display = "";  
       document.getElementById("tprofile2").style.display = "none";
       document.getElementById("selectfdiv").style.display = "";
       document.getElementById("viewchar").innerHTML = "What's the Chinese Zodiac for:";
      }       
   init();