﻿function ShowSocialSettings()
{
   //document.getElementById("socialsettingcontrol_txtTweetUname").value="";
   //document.getElementById("socialsettingcontrol_txtTweetPwd").value="";
   
   ShowModalPopup('dsocialsettings','Social Networking Set Up','m');
   
   var objValue=document.getElementById("socialsettingcontrol_hidSocialSettings").value;
   var ListBoxObj = document.getElementById('socialsettingcontrol_ListShareItems');
   
   document.getElementById("socialsettingcontrol_chkSendTweet").checked=false;
   document.getElementById("socialsettingcontrol_chkSendFacebook").checked=false;
   document.getElementById("socialsettingcontrol_txtTweetUname").disabled=false;
   document.getElementById("socialsettingcontrol_txtTweetUname").value="";
   document.getElementById("socialsettingcontrol_txtTweetPwd").disabled=true;
   document.getElementById("socialsettingcontrol_txtTweetPwd").value="";
   
   var lstLength = ListBoxObj.options.length;         
   for(i=0;i<lstLength;i++)
   {
      ListBoxObj.options[i].selected = false;
   }  
   if(objValue!="")
   {   
        var splitResult = objValue.split("$");     

        if(splitResult[0]=="True")
        {
           document.getElementById("socialsettingcontrol_chkSendTweet").checked=true;
        }
        
        if(splitResult[1]=="True")
        {
           document.getElementById("socialsettingcontrol_chkSendFacebook").checked=true;
        }
        
        document.getElementById("socialsettingcontrol_txtTweetUname").value=splitResult[2];
        
        var splitCommaResult=splitResult[3].split(",");
        for(i=0;i<splitCommaResult.length;i++)
        {
           if(splitCommaResult[i]!="")
           {
              ListBoxObj.options[splitCommaResult[i]].selected = true;
           }
        } 
   }
   
   document.getElementById("socialsettingcontrol_ListShareItems").style.display ="block";
   document.getElementById("socialsettingcontrol_divWarningMsg").style.display ="none";
   
   document.getElementById("socialsettingcontrol_divTwitterDetails").style.display ="block";
   document.getElementById("socialsettingcontrol_divTwitterMsg").style.display="block";
   if(document.getElementById("socialsettingcontrol_hidTweetPwd").value=="")
   {
       document.getElementById("socialsettingcontrol_divTwitterDetails").style.display ="none";
       //document.getElementById("dsocialsettings").style.height="410px";
   }
   else
   {
       document.getElementById("socialsettingcontrol_divTwitterMsg").style.display ="none";
      // document.getElementById("dsocialsettings").style.height="300px";
   }
   CheckTweetClick();
   var registrationErrorsDiv = document.getElementById("socialsettingcontrol_WarningMsgs_RegistrationErrors");
           
   registrationErrorsDiv.style.display = "none";
   document.getElementById("socialsettingcontrol_WarningMsgs_divWarningInfo").style.display = "none";  
   
   var Path = self.location.href;
   var PageName = Path.substring(Path.lastIndexOf("/")+1 ,Path.length);
   if(PageName.indexOf("AddGoal.aspx")>=0)
   {  
        HighlightSocialSettingsMenu();
   }
   return false;
}
function hidePasswordGuidelinesTip()
{
    var objpopup; 
    objpopup=document.getElementById("divCompletedWorkoutTip");  
    
    if(objpopup!=null)
    {
        objpopup.style.display="none";
    }    
     var arrobj=document.getElementById("ddlTimeOfDay");
	
	 if(arrobj != null)
	 {
	    arrobj.style.visibility="visible";
	 }
}
function showPasswordGuidelinesTip(e)
{
    objX=(document.all)?document.documentElement.scrollLeft:window.pageXOffset;
    objY=(document.all)?document.documentElement.scrollTop:window.pageYOffset;
    
    objX=e.clientX+objX; //document.body.scrollLeft;
    objY=e.clientY+objY-40; //document.body.scrollTop;
  
   objpopup=document.getElementById("divCompletedWorkoutTip");
   
    if(objpopup!=null)
    {
        if(document.getElementById("lblCompletedWorkoutTip")!=null)
        {   
            document.getElementById("lblCompletedWorkoutTip").innerHTML="To make your password more secure - Use letters and numbers - Use special characters (e.g : @) - Mix lower and upper case.";
        }
     
        if(document.getElementById("lblCompletedWorkoutPopupTitle")!=null)
        {  
            document.getElementById("lblCompletedWorkoutPopupTitle").innerHTML="Help";
        }     
        objX = parseInt(objX) - 25;
        objY = parseInt(objY) - 20;
        
        objpopup.style.left=objX+"px";
        objpopup.style.top=objY+"px";        
        objpopup.style.display="block";
        
		//To hide time of day dropdownlist because sometimes dropdownlist appears over calendar extender control
        var arrobj=document.getElementById("ddlTimeOfDay");
	
	    if(arrobj != null)
	    {
	         arrobj.style.visibility="hidden";
	    }
    }   
}

function moveCompletedWorkoutTip(e)
{
    var objpopup;        
    objpopup=document.getElementById("divCompletedWorkoutTip");            
    if(objpopup)
    {      
        if(objpopup.style.display=="block")
        { 
			objX=(document.all)?document.documentElement.scrollLeft:window.pageXOffset;
			objY=(document.all)?document.documentElement.scrollTop:window.pageYOffset;
    
			objX=e.clientX+objX + 10; //document.body.scrollLeft;
			objY=e.clientY+objY + 10; //document.body.scrollTop;
    
        objX = parseInt(objX) - 25;
        objY = parseInt(objY) - 20;
			objpopup.style.left=objX+"px";
			objpopup.style.top=objY+"px";
        
			objpopup.style.display="block";
			
			//To hide time of day dropdownlist because sometimes dropdownlist appears over calendar extender control
			var arrobj=document.getElementById("ddlTimeOfDay");
	
	        if(arrobj != null)
	        {
	            arrobj.style.visibility="hidden";
	        }
        }
    }      
}

function CloseSocialSettings()
{
   closepopup('dsocialsettings');
   var Path = self.location.href;
   var PageName = Path.substring(Path.lastIndexOf("/")+1 ,Path.length);
   if(PageName.indexOf("AddGoal.aspx")>=0)
   {  
        SocialSettingsToDefaultMenu();
   }
    return false;
}
 
function ValidateSocialSettings()
{
   var status=ValidateSocialSettingsData();
   if(status == false)
   {
        document.getElementById("socialsettingcontrol_divWarningMsg").style.display ="none";
        var registrationErrorsDiv = document.getElementById("socialsettingcontrol_WarningMsgs_RegistrationErrors");
        registrationErrorsDiv.style.display = "block";
        registrationErrorsDiv.innerHTML = "";
        document.getElementById("socialsettingcontrol_WarningMsgs_divWarningInfo").style.display = "block";
     
       
        registrationErrorsDiv.innerHTML = errors; 
        return false;   
    }
    else
    {
        var registrationErrorsDiv = document.getElementById("socialsettingcontrol_WarningMsgs_RegistrationErrors");          
        registrationErrorsDiv.style.display = "none";
        document.getElementById("socialsettingcontrol_WarningMsgs_divWarningInfo").style.display = "none";
        
        return true;          
    }  
}

function ValidateSocialSettingsData()
{
    var status = true;
    var varTemp;
    var isMandatory = 'True';
    errors = "";
    
    if(document.getElementById("socialsettingcontrol_chkSendFacebook").checked==false && document.getElementById("socialsettingcontrol_chkSendTweet").checked==false)
    {
        errors = "Select the relevant checkbox to share the updates on twitter and facebook.";
//        return false;
    }
 
    var chkSendTweet = document.getElementById("socialsettingcontrol_chkSendTweet");
    return true;
    
//    if(chkSendTweet.checked==true)
//    {
//        varTemp = document.getElementById("socialsettingcontrol_txtTweetUname");  
//        alertName = "Twitter Username";       
//        if (varTemp.value == "" ) 
//        {
//            errors  = 'Please enter '+ alertName + '.' ; 
//            varTemp.focus();
//            return false;       
//        }

//        if(document.getElementById("socialsettingcontrol_hidTweetPwd").value=="")
//        {
//            alertName = "Twitter Password";
//           
//            var newPassword = document.getElementById("socialsettingcontrol_txtTweetPwd");
//            errors  = "";

//            if (newPassword.value == "" ) 
//            {
//                errors  = 'Please enter '+ alertName + '.' ; 
//                newPassword.focus();
//                return false;       
//            }
//            //To validate No Space Allowed In Password.
//            if(bValidate(newPassword, "PasswordWithoutSpace" ,isMandatory , alertName) != true)
//            {
//                return false;
//            }  
//        }
//    }
    
    return status;
}

function ShowTwitterDetails()
{  
    document.getElementById("socialsettingcontrol_divTwitterDetails").style.display ="block";
   
    document.getElementById("socialsettingcontrol_divTwitterMsg").style.display ="none";
}

function CheckTweetClick()
{
    if(document.getElementById("socialsettingcontrol_txtTweetUname")!=null)
    {  
        document.getElementById("socialsettingcontrol_txtTweetPwd").value="";
        document.getElementById("socialsettingcontrol_txtTweetUname").disabled=false;
        document.getElementById("socialsettingcontrol_txtTweetPwd").disabled=false;
    }
    
    var chkSendTweet = document.getElementById("socialsettingcontrol_chkSendTweet");
    
    if(chkSendTweet.checked==true)
    {
        if(document.getElementById("socialsettingcontrol_txtTweetUname")!=null)
        {
            //document.getElementById("socialsettingcontrol_txtTweetUname").value=""
            //document.getElementById("socialsettingcontrol_txtTweetPwd").value="";
            document.getElementById("socialsettingcontrol_txtTweetUname").disabled=false;
//            document.getElementById("socialsettingcontrol_txtTweetPwd").disabled=false;
        }
    }
    
    checkListboxStatus();
}

function CheckFacebookClick()
{
   checkListboxStatus();
}


function checkListboxStatus()
{ 
   var ListBoxObj = document.getElementById('socialsettingcontrol_ListShareItems');
   var chkSendTweet = document.getElementById("socialsettingcontrol_chkSendTweet");
   var chkSendFacebook = document.getElementById("socialsettingcontrol_chkSendFacebook");
  
   if(ListBoxObj != null && ListBoxObj != "")
   {
        var lstLength = ListBoxObj.options.length;        
        var i;
        var isSelected=false;
        for(i=0;i<lstLength;i++)
        {
            if(ListBoxObj.options[i].selected == true)
            {
               isSelected=true;
               break;
            }
        } 
        
        if((isSelected==true)&&(chkSendTweet.checked==false)&&(chkSendFacebook.checked==false))
        {  document.getElementById("socialsettingcontrol_divWarningMsg").style.display ="none";
           var registrationErrorsDiv = document.getElementById("socialsettingcontrol_WarningMsgs_RegistrationErrors");
           registrationErrorsDiv.style.display = "block";
           document.getElementById("socialsettingcontrol_WarningMsgs_divWarningInfo").style.display = "block";   
           
           registrationErrorsDiv.innerHTML = "Select the relevant checkbox to share the updates on twitter and facebook."; 
        
        }  
        else
        {
           var registrationErrorsDiv = document.getElementById("socialsettingcontrol_WarningMsgs_RegistrationErrors");
           registrationErrorsDiv.style.display = "none";
           document.getElementById("socialsettingcontrol_WarningMsgs_divWarningInfo").style.display = "none";   
           registrationErrorsDiv.innerHTML = "";     
      
                
        }         
    }   
}

