﻿// JScript File

  //script for flyout email form
 
              function Cover(bottom, top, ignoreSize) {
                var location = Sys.UI.Control.getLocation(bottom);
                top.style.position = 'absolute';
              
                top.style.top = location.y+ 70+'px';
                top.style.left = location.x +550+ 'px';
               
              
                if (!ignoreSize) {
                top.style.height = bottom.offsetHeight + 'px';
                top.style.width = bottom.offsetWidth + 'px';
                }
            }
            
             function Cover1(bottom, top, ignoreSize) {
                var location = Sys.UI.Control.getLocation(bottom);
                top.style.position = 'absolute';
                top.style.top = location.y-10+ 'px';
                top.style.left = location.x-270 + 'px';
                  
                  
                if (!ignoreSize) {
                top.style.height = bottom.offsetHeight + 'px';
                top.style.width = bottom.offsetWidth + 'px';
                }
            }
            
            
  
            
            
      var text1;
      var text2;
      var text3;
      var eForm;
      var submit;
           
     function pageLoad()
     {
   
     
       var myLink=document.getElementById ("links");
     myLink.style.position="absolute";
     
     myLink.style.top=78+"px";
     myLink.style.left=480+"px";

     text1=new Sys.UI.TextBox($('Text1'));
     text1.initialize();
     
     text2=new Sys.UI.TextBox($('Text2'));
     text2.initialize();
     text3=new Sys.UI.TextBox($('Text3'));
     text3.initialize();
     eForm= new Sys.UI.Control($('emailForm'));
     eForm.initialize();
     submit =new Sys.UI.Label($('submitButton'));
     submit.initialize();
   
     
      }
      //get form fields for email and disables submit button
      function getInfo()
      {
          document.getElementById ("validator1").innerHTML ="";
          document.getElementById ("validator2").innerHTML ="";
          document.getElementById ("validator3").innerHTML ="";
       if (text1.get_text()==""||text2.get_text()==""||text3.get_text()=="")
       {
          if (text1.get_text() =="")
            {
             document.getElementById ("validator1").innerHTML ="Required Field";
              }
          if (text2.get_text() =="")
           {
            document.getElementById ("validator2").innerHTML ="Required Field";
            }
          if (text3.get_text() =="")
           {
           document.getElementById ("validator3").innerHTML ="<br/>Required Field";
            }
      }
      else
      {
      
       submit.set_enabled(false);
       var to=text1.get_text();
       var from=text3.get_text();
       var body=text2.get_text();
       var link=document.URL ;
      if (link.toLowerCase().search("exercises.aspx")==-1)
      {
    
       email(to,from,body,link);
       }
       else
       {
       
       var id=document.getElementById("Hidden1");
       link=id.value;
       email(to,from,body,link);
       }
       
       
     
     }
      
    }
  
      
      
     //performs email of link via webservice
      function email(to, from, body,link)
      {
  
      EmailFriend.Email(to,from,body,link,OnComplete1,OnTimeout1);
     
     }
    
     
     function OnComplete1(result)
     {
   
     var label=result;
     if(result=="true")
     {
     label="Thanks, Your email has been sent!";
     }
     else
     {
     label=result;
     }
    
     document.getElementById ('emailForm').innerHTML ="<div align='center' style='background-color:#ffffff; border-color:purple; font-size:20px; font-weight:bold;  color:purple; font-family:verdana;'>"+label+"</div>";

     var timer=window.setTimeout ( "fadeout()" ,2000);
      
 }
     
     function OnTimeout1(result)
     {
     alert("Sorry, This function has timed out.");
     
     }
     
     
     function fadeout()
     {
    
     var a=new Sys.UI.FadeAnimation();
     a.set_target(eForm);
     a.set_effect(Sys.UI.FadeEffect.FadeOut);
     a.play();
     }
    
    
    //function to transfer to page which displays printable content
     function Printable()
      {
      var myId=document.getElementById ("Hidden1").value;
      window.location .href="Printable.aspx?id="+myId;
      }
     