﻿// JScript File

var is_Safari = navigator.userAgent.indexOf('Safari');
//Constants Defined as per tblUnits MetaData table
var isMiles=1;
var isKm=2;
var isMeters=3;
var isYards=4;

var _addTPErrorMessage = "";

function DisplayDateCategory()
{   
    //var rdo = document.getElementsByName("optStartDate");
    
    var lblStartDate;
    var lblRaceDate;
    
    lblStartDate=document.getElementById("divlblStartDate");
    lblRaceDate=document.getElementById("divlblRaceDate");
    
    lblStartDate.style.display="none";
    lblRaceDate.style.display="none";
    
    if (document.all)
	{
		// IE
		 if(rdo[1].checked)
         {   
             lblStartDate.style.display="block";
                       
        }
        if(rdo[2].checked)
        {    
            lblRaceDate.style.display="block";
        }
   }
   else
   {
		// FireFox 
		 if(rdo[0].checked)
         {  
            lblStartDate.style.display="block";
                
         }
        if(rdo[1].checked)
        {
            lblRaceDate.style.display="block";
            
        }		
		
   }
 }
 
 
//Function To Resest all opinion Form field values.
function ResetAll()
{
    document.getElementById('txtTrainingName').value ="";
    document.getElementById('txtTrainingDuration').value ="";
    document.getElementById('txtPrice').value =""; 
    document.getElementById('txtTrainingDescription').value =""; 
    //document.getElementById('lblMessage').style.visibility ="hidden";
    
    return(false); 
   
}

function ShowOtherActivity()
{

    if(document.getElementById('ddlActivityType')!=null)
    {
        if(document.getElementById('ddlActivityType').value=="Other")
        { 
             document.getElementById('divlblOtherActivity').style.display="block";
             document.getElementById('divtxtOtherActivity').style.display="block";
        }
        else
        {
            document.getElementById('divlblOtherActivity').style.display="none";
            document.getElementById('divtxtOtherActivity').style.display="none";   
        }
   }

}


function ShowFixedDuration()
{     
    if(document.getElementById('chkDuration')!=null)
    {
    
         if(document.getElementById('chkDuration').checked == true)
         {
            document.getElementById('divlblStartDate').style.display="block";
            document.getElementById('divtxtStartDate').style.display="block";  
            document.getElementById('divlblEndDate').style.display="block";
            document.getElementById('divtxtEndDate').style.display="block";  
                
            document.getElementById('divlblPlanDuration').style.display="none";
            document.getElementById('divtxtPlanDuration').style.display="none"; 
         }
         else if(document.getElementById('chkDuration').checked == false)
         {
            document.getElementById('divlblStartDate').style.display="none";
            document.getElementById('divtxtStartDate').style.display="none";  
            document.getElementById('divlblEndDate').style.display="none";
            document.getElementById('divtxtEndDate').style.display="none";  
                
            document.getElementById('divlblPlanDuration').style.display="block";
            document.getElementById('divtxtPlanDuration').style.display="block"; 
         }
         ShowPlanWeeks();
     
     }
      
}

function ShowFixedDurations()
{     
    if(document.getElementById('chkDuration')!=null)
    {
    
         if(document.getElementById('rdBasedOnDate').checked == true)
         {
            document.getElementById('divlblStartDate').style.display="block";
            document.getElementById('divtxtStartDate').style.display="block";  
            document.getElementById('divlblEndDate').style.display="block";
            document.getElementById('divtxtEndDate').style.display="block";  
                
            document.getElementById('divlblPlanDuration').style.display="none";
            document.getElementById('divtxtPlanDuration').style.display="none"; 
         }
         else if(document.getElementById('chkDuration').checked == true)
         {
            document.getElementById('divlblStartDate').style.display="none";
            document.getElementById('divtxtStartDate').style.display="none";  
            document.getElementById('divlblEndDate').style.display="none";
            document.getElementById('divtxtEndDate').style.display="none";  
                
            document.getElementById('divlblPlanDuration').style.display="block";
            document.getElementById('divtxtPlanDuration').style.display="block"; 
         }
         ShowPlanWeeks();
     
     }
      
}



function ShowTermDesc(e,termDesc)
{

    
    objX=(document.all)?document.documentElement.scrollLeft:window.pageXOffset;
    objY=(document.all)?document.documentElement.scrollTop:window.pageYOffset;

   
   // Commented today - Swaraj
   if((is_Safari >0)||(is_chrome==true))
    {     
          
         objX= window.event.clientX+objX-10;
         objY=window.event.clientY+objY+10;
    }
    else
    {
        objX=e.clientX+objX; //document.body.scrollLeft;
        objY=e.clientY+objY; //document.body.scrollTop;
    }
  
   var objpopup_left;
   objpopup_left = document.getElementById("divLeftArrowPopup");
    //Check if the popup is already created
    if(objpopup_left!= null)
    {
     
         var topPos=parseInt(objY);
            var topLeft=parseInt(objX)+ 15;
            topPos=parseInt(topPos)-140;
            objpopup_left.style.left=topLeft+"px";
            objpopup_left.style.top=topPos+"px";
            objpopup_left.style.display="block"; 
            
    
        if(document.getElementById("logcalendarpopup_lblTitle")!=null)
        {   
			document.getElementById("logcalendarpopup_lblTitle").innerHTML="&nbsp;&nbsp;"+"Term Description";
        }
         if(document.getElementById("logcalendarpopup_lblLeftEventDetails")!=null)
        {  			
			document.getElementById("logcalendarpopup_lblLeftEventDetails").innerHTML=termDesc;
			document.getElementById("calendarpopupLeftHeader").style.display="none";    
        } 
     }
   
  
   
}

function HideTermDesc(e)
{
    var objpopup; 
    objpopup=document.getElementById("divLeftArrowPopup");
   
    if(objpopup!=null)
    {
        objpopup.style.display="none";
    }
    
}

function MoveTermDescPopup(e)
{
    var objpopup; 
    
    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;
  
  
    objpopup=document.getElementById("divLeftArrowPopup");
   
    objpopup.style.left=objX+"px";
    objpopup.style.top=objY+"px";
        
        
    if(objpopup!=null)
    {
        objpopup.style.display="block";
    }
    
}

function DeleteActivityRecordConfirmation(RecordId,btnId)
{
//    var choice = false;

//    choice = confirm('Are you sure you want to delete the selected activity record?');
//    return choice;
    
    document.getElementById("confirmBox_hidButtonId").value=btnId;
    document.getElementById("hidRecordId").value=RecordId;
    ShowConfirmBox('Are you sure you want to delete the selected activity record?');
    return false;
}

function ValidateAddExcercise()
{
    errors = " ";
    mandatoryFieldsErrorFlag = false;
    var status = ValidateAddExcerciseRoutines();  
    
    if(status == false)
    {
          
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");
            
		registrationErrorsDiv.style.display = "block";
		document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";
        //errors +='</ul>';
        registrationErrorsDiv.innerHTML = "";
            
        registrationErrorsDiv.innerHTML = errors; 
        
        return false;   
     }
     else
     {
         var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");
         document.getElementById("WarningMsgs3_divWarningInfo").style.display = "none";   
		 registrationErrorsDiv.style.display = "none";
		 
        return true;          
     }  

}

function ValidateAddExcerciseRoutines()
{   
    var userControl = "";
    var status = true;
    var tempWorkoutType = document.getElementById("ddlWorkoutType").value;
 
   //If workout type is Brick
    if(tempWorkoutType=="7")
    {
            
        var activity = document.getElementById("ddlExcerciseType").value;
     
     
       //If Activity is Other
        if(activity == "Other")
        {   var varTemp = document.getElementById("txtOtherExcercise");  
            var alertName = " Other Excercise ";
            var isMandatory = 'True';
            if(bValidate(varTemp, "AlphaWithSpaceAnd" ,isMandatory , alertName) != true)
            {
                varTemp.focus();
		  status = false;
		  return false; 
            }
        }  
        
        
        var varTemp = document.getElementById(userControl + "txtExcerciseHr");  
        var alertName = " Hours ";
        var isMandatory = 'false';
        if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
        {
            varTemp.focus();
		  status = false;
		  return false;     
        } 
       
        if(varTemp.value > 24)
        {
		    errors +=alertName+ " should be between 0 to 24." +'<br/>'; 
            varTemp.focus();
		  status = false;
		  return false; 
        }  
    
    
        var varTemp = document.getElementById(userControl + "txtExcerciseMin");  
        var alertName = " Minutes ";
        var isMandatory = 'false';
        if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
        {
           varTemp.focus();
		  status = false;
		  return false; 
        }
        
        if(varTemp.value > 59)
        {
		    errors +=alertName+ " should be between 0 to 59." +'<br/>'; 
             varTemp.focus();
		  status = false;
		  return false; 
        }       
        
     
        var varTemp = document.getElementById(userControl + "txtExcerciseSec");  
        var alertName = " Seconds ";
        var isMandatory = 'false';
        if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
        {
           varTemp.focus();
		  status = false;
		  return false; 
        }
    	
        if(varTemp.value > 59)
        {
            errors +=alertName+ " should be between 0 to 59." +'<br/>'; 
            varTemp.focus();
		  status = false;
		  return false; 
        }  
    
        
        if((varTemp.value == 24)&& ((varTemp1.value > 0) || (varTemp2.value > 0)) )
        {
		    errors +=alertName+ " cannot be more than 24 hours, Please enter again." +'<br/>'; 
            varTemp.focus();
		  status = false;
		  return false; 
        }
        
        
        var varTemp = document.getElementById("txtExerciseNoOfSets");  
        var alertName = " No. of sets ";
        var isMandatory = 'false';
        if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
        {
            varTemp.focus();
		  status = false;
		  return false;  
        }
        
        if(varTemp.value > 10)
        {
            errors +=alertName+ " cannot be more than 10." +'<br/>'; 
             varTemp.focus();
		  status = false;
		  return false;    
        }
        
        //if no of sets <= 10
        if(varTemp.value <= 10)
        {
            var strRepetitions=document.getElementById("hidGridRepetitions").value;
           
            if(strRepetitions!="")
            { 
                var arrRepetitions = strRepetitions.split(" "); 
                
                var iCount;
                
               
                for(iCount=0;iCount < arrRepetitions.length;iCount++)
                {
                     var strFloatExp = "^(([0-9])+([\.]([0-9])*)?)$";
            
                    var status;
                    objRegExp = new RegExp(strFloatExp);
                    
                  
                    
                    var varTemp = document.getElementById(arrRepetitions[iCount]);  
                    var alertName = " Repetitions ";
                       
                    //alert(strCtrlId);
                    
                    if(varTemp!=null)
                    {
                        if(varTemp.value == "")
                        {   // alert("2");
                            errors +='<li>'+alertName+ " should not be empty." +'<br/></li>'; 
                            status = false;
                            break;
                        }
                        
                        if(varTemp.value == "0")
                        {   // alert("2");
                            errors +='<li>'+alertName+ " should not be 0." +'<br/></li>'; 
                            status = false;
                            break;
                        }
                        
                        if(objRegExp.test(varTemp.value)==false)
                        {   //alert("1");
                            errors +='<li>'+alertName+ " should be numeric." +'<br/></li>'; 
                            status = false;  
                            break;
                        }
                        
                        
                        if(varTemp.value > 100)
                        {   // alert("2");
                            errors +='<li>'+alertName+ " cannot be more than 100." +'<br/></li>'; 
                            status = false;
                            break;
                        }
                    }
                
                } 
            }
            
            
            var strWeight=document.getElementById("hidGridWeight").value;
           
            if(strWeight!="")
            {
            
                var arrWeight = strWeight.split(" "); 
                
                var iCount;
                
                for(iCount=0;iCount < arrWeight.length;iCount++)
                {
                    
                    var strFloatExp = "^(([0-9])+([\.]([0-9])*)?)$";
            
                    var status;
                    objRegExp = new RegExp(strFloatExp);
                    
                   
                    
                    var varTemp = document.getElementById(arrWeight[iCount]);  
                    var alertName = " Weight ";
                       
                    //alert(strCtrlId);
                    
                    if(varTemp!=null)
                    {
                        if(varTemp.value == "")
                        {   // alert("2");
                            errors +='<li>'+alertName+ " should not be empty." +'<br/></li>'; 
                            status = false;
                            break;
                        }
                        
                        if(objRegExp.test(varTemp.value)==false)
                        {   //alert("1");
                            errors +='<li>'+alertName+ " should be numeric." +'<br/></li>'; 
                            status = false;  
                            break;
                        }
                        
                        
                        if(varTemp.value > 1000)
                        {   // alert("2");
                            errors +='<li>'+alertName+ " cannot be more than 1000." +'<br/></li>'; 
                            status = false;
                            break;
                        }
                    }
                
                } 
            }            
        }             
    }    
    return status;
}

function NoOfSetsChange()
{    

    errors = " ";
    
    var varTemp = document.getElementById("txtExerciseNoOfSets");  
    var alertName = " No. of sets ";
    if(varTemp.value > 10)
    {
        errors +=alertName+ " cannot be more than 10 " +'<br/>'; 
        status = false;
        
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");
        document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";
            
		registrationErrorsDiv.style.display = "block";
        //errors +='</ul>';
        registrationErrorsDiv.innerHTML = "";
            
        registrationErrorsDiv.innerHTML = errors; 
        
        return false;                    
    }
    else
    {
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");            
	    registrationErrorsDiv.style.display = "none";
	     document.getElementById("WarningMsgs3_divWarningInfo").style.display = "none";
        return true; 
    }
    
 
     
}

function GridNoOfSetsChange()
{

    var txtNoOfSets=document.getElementById("hidGridNoOfSets").value;
     
    errors = " ";
    
    var varTemp = document.getElementById(txtNoOfSets);  
    var alertName = " No. of sets ";
    if(varTemp.value > 10)
    {
        errors +=alertName+ " cannot be more than 10 " +'<br/>'; 
        status = false;
        
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");
           document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";   
		registrationErrorsDiv.style.display = "block";
        //errors +='</ul>';
        registrationErrorsDiv.innerHTML = "";
            
        registrationErrorsDiv.innerHTML = errors; 
        
        return false;                    
    }
    else
    {
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");            
	    registrationErrorsDiv.style.display = "none";
	    document.getElementById("WarningMsgs3_divWarningInfo").style.display = "none"; 
        return true; 
    }
}

function RepetitionDataChange(strCtrlId)
{
    var strFloatExp = "^(([0-9])+([\.]([0-9])*)?)$";
    
    var status;
    objRegExp = new RegExp(strFloatExp);
    
    errors = "<ul>";
    
    var varTemp = document.getElementById(strCtrlId);  
    var alertName = " Repetitions ";
       
    //alert(strCtrlId);
    
    if(varTemp.value!="")
    {   if(objRegExp.test(varTemp.value)==false)
        {   //alert("1");
            errors +='<li>'+alertName+ " should be numeric." +'<br/></li>'; 
            status = false;    
        }
    }
    
    if(varTemp.value > 100)
    {   // alert("2");
        errors +='<li>'+alertName+ " cannot be more than 100." +'<br/></li>'; 
        status = false;
        
    }
    
    //alert(status);
    if(status == false)
    {   // alert("3");
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");
        document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";    
		registrationErrorsDiv.style.display = "block";
        errors +='</ul>';
        registrationErrorsDiv.innerHTML = "";
            
        registrationErrorsDiv.innerHTML = errors; 
        
        return false;                    
    }
    else
    {
        //alert("4");
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");            
	    registrationErrorsDiv.style.display = "none";
	    document.getElementById("WarningMsgs3_divWarningInfo").style.display = "none"; 
        return true; 
    
    }
}

function GridRepetitionDataChange(strCtrlId)
{
    var status;
    var strFloatExp = "^(([0-9])+([\.]([0-9])*)?)$";
    
    objRegExp = new RegExp(strFloatExp);
    
    errors = "<ul>";
    
    var varTemp = document.getElementById(strCtrlId);  
    var alertName = " Repetitions ";
       
    if(varTemp.value!="")
    { 
        if(objRegExp.test(varTemp.value)==false)
        {
            errors +='<li>'+alertName+ " should be numeric." +'<br/></li>'; 
            status = false;    
        }
    }
    
    
    if(varTemp.value > 100)
    {
        errors +='<li>'+alertName+ " cannot be more than 100." +'<br/></li>'; 
        status = false;
        
    }
    
    if(status == false)
    {   
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");
       document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";      
		registrationErrorsDiv.style.display = "block";
        errors +='</ul>';
        registrationErrorsDiv.innerHTML = "";
            
        registrationErrorsDiv.innerHTML = errors; 
        
        return false;                    
    }
    else
    {
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");            
	    registrationErrorsDiv.style.display = "none";
	    document.getElementById("WarningMsgs3_divWarningInfo").style.display = "none";
        return true; 
    
    }
}


function WeightDataChange(strCtrlId)
{   
    var status;
    var strFloatExp = "^(([0-9])+([\.]([0-9])*)?)$";
    
    objRegExp = new RegExp(strFloatExp);
    
    errors = "<ul>";
     
    var varTemp = document.getElementById(strCtrlId);  
    var alertName = " Weight ";
    
    if(varTemp.value!="")
    { 
        if(objRegExp.test(varTemp.value)==false)
        {
            errors +='<li>'+alertName+ " should be numeric." +'<br/></li>'; 
            status = false;    
        }
    }
    
//    var isMandatory = 'false';
//    if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
//    status = false;    
    
    if(varTemp.value > 1000)
    {
        errors +='<li>'+alertName+ " cannot be more than 1000." +'<br/></li>'; 
        status = false;
        
    }
        
    if(status == false)
    { 
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");
        document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";        
		registrationErrorsDiv.style.display = "block";
        errors +='</ul>';
        registrationErrorsDiv.innerHTML = "";
            
        registrationErrorsDiv.innerHTML = errors; 
        
        return false;                    
    }
    else
    {
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");            
	    registrationErrorsDiv.style.display = "none";
	     document.getElementById("WarningMsgs3_divWarningInfo").style.display = "none";
        return true; 
    
    }
}


function GridWeightDataChange(strCtrlId)
{
   var status;
   var strFloatExp = "^(([0-9])+([\.]([0-9])*)?)$";
    
    objRegExp = new RegExp(strFloatExp);
    
    errors = "<ul>";
     
    var varTemp = document.getElementById(strCtrlId);  
    var alertName = " Weight ";
    
    if(varTemp.value!="")
    { 
        if(objRegExp.test(varTemp.value)==false)
        {
            errors +='<li>'+alertName+ " should be numeric." +'<br/></li>'; 
            status = false;    
        }
    }
    
//    var isMandatory = 'false';
//    if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
//    status = false;    
    
    if(varTemp.value > 1000)
    {
        errors +='<li>'+alertName+ " cannot be more than 1000." +'<br/></li>'; 
        status = false;
        
    }
        
    if(status == false)
    { 
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");
       document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";       
		registrationErrorsDiv.style.display = "block";
        errors +='</ul>';
        registrationErrorsDiv.innerHTML = "";
            
        registrationErrorsDiv.innerHTML = errors; 
        
        return false;                    
    }
    else
    {
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");            
	    registrationErrorsDiv.style.display = "none";
	    document.getElementById("WarningMsgs3_divWarningInfo").style.display = "none";  
        return true; 
    
    }

}

function ValidateTrainingDates()
{
    //var status;
    var _strMessage;
    
    varTemp = document.getElementById("txtStartDate"); 

    if(varTemp.value == ""||varTemp.value==null)
    {
   
       _strMessage="Start Date should not be empty.";  
       if(_addTPErrorMessage == "")
       {
            _addTPErrorMessage = _strMessage;
       }
       else
       {
            _addTPErrorMessage =_addTPErrorMessage+" <br>"+ _strMessage;
       }
	    document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
        document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = _strMessage;
        document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
        document.getElementById('txtStartDate').style.backgroundColor = "Yellow";
	    window.scrollBy(0,-10000);
        
        
	  	return(false); 
        
    }   
    
    varTemp = document.getElementById("txtEndDate"); 

    if(varTemp.value == ""||varTemp.value==null)
    {
   
       _strMessage="End Date should not be empty";  
       if(_addTPErrorMessage == "")
       {
            _addTPErrorMessage = _strMessage;
       }
       else
       {
            _addTPErrorMessage =_addTPErrorMessage+" <br>"+ _strMessage;
       }
	   document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
        document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = _strMessage;
        document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
        document.getElementById('txtEndDate').style.backgroundColor = "Yellow";
	    window.scrollBy(0,-10000);
    return(false); 
        
    }   
    var today = new Date();
    var startdate = new Date(document.getElementById("txtStartDate").value);
    
    var enddate = new Date(document.getElementById("txtEndDate").value);

    if(startdate < today)
    {
         _strMessage="Start Date should not be less than Today's Date.";  
         if(_addTPErrorMessage == "")
       {
            _addTPErrorMessage = _strMessage;
       }
       else
       {
            _addTPErrorMessage =_addTPErrorMessage+" <br>"+ _strMessage;
       }
           document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
            document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = _strMessage;
            document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
             document.getElementById('txtStartDate').style.backgroundColor = "Yellow";
	    window.scrollBy(0,-10000);
        return(false); 
    }
    else if(enddate < today)
    {
         _strMessage="End Date should not be less than Today's Date.";  
         if(_addTPErrorMessage == "")
       {
            _addTPErrorMessage = _strMessage;
       }
       else
       {
            _addTPErrorMessage =_addTPErrorMessage+" <br>"+ _strMessage;
       }
           document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
            document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = _strMessage;
            document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
            document.getElementById('txtEndDate').style.backgroundColor = "Yellow";
	    window.scrollBy(0,-10000);
        return(false); 
    }
    else
    {
    
        var DateDiff = enddate - startdate;
                   
        day=startdate.getDate();
        month=startdate.getMonth() + 1;
        year=startdate.getFullYear();

        startdate =month+"/"+day+"/"+year;
              
        day=enddate.getDate();
        month=enddate.getMonth() + 1;
        year=enddate.getFullYear();

        enddate=month+"/"+day+"/"+year;
    	      
        if(startdate==enddate)
        {
               
        }
        else if(DateDiff<0)
        {
            _strMessage="Start Date should not be greater than End Date";  
            if(_addTPErrorMessage == "")
       {
            _addTPErrorMessage = _strMessage;
       }
       else
       {
            _addTPErrorMessage =_addTPErrorMessage+" <br>"+ _strMessage;
       }
           document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
            document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = _strMessage;
            document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
            document.getElementById('txtStartDate').style.backgroundColor = "Yellow";
	    window.scrollBy(0,-10000);
        return(false); 
      }
             
    }
    
    
    return(true);
}


//This function validates all field values of the form AddOpinionPoll
function ValidateFields()
{ 			
    var _strMessage;
    //var  status;
    
    
    document.getElementById('divWarningInfo1').value = "";
	document.getElementById('divWarningInfo1').style.display ="none";
	
    if (!ValidateTrainingName())
    {
//	    return(false);
	}
			
     if(document.getElementById('ddlActivityType').value=="Other")
     {
        if(document.getElementById('txtOtherActivity').value=="")
        {
            _strMessage="Other Activity Type should not be empty.";  
            if(_addTPErrorMessage == "")
            {
                _addTPErrorMessage = _strMessage;
            }
            else
            {
                _addTPErrorMessage = _addTPErrorMessage+" <br>"+_strMessage;
            }
           document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
        document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = _strMessage;
        document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
          document.getElementById('txtOtherActivity').focus();
          
          
//     return(false); 
             
        }
     }
     
     if(document.getElementById('rdBasedOnDate').checked == true)
     {        
         if(!ValidateTrainingDates())
         {
//	        return(false);
	     }
	                    		  	
     }
     else
     {
	      if(!ValidateTrainingDuration())
	      {
//	         return(false);
	      }
	 }
		
    if(!ValidatePrice())
    {
//	    return(false); 	  
	}  
//	if(document.getElementById("chkIsPasswordProtected").checked ==1)
//	{
//	  
//	    if(!ValidatePassword())
//	    {
//	        return(false); 	
//	    }
//	 }   
	 
  
    if(!ValidateDescription())
    {
//	    return(false); 	   
	} 

	
	 
    //validating uploading filename field
   varTemp = document.getElementById("PhotoUpload");
   alertName = " Logo Image ";
   
   if(varTemp!= null && varTemp!= "")
   {
      //Get the filename
      varTemp = varTemp.value;
      if(varTemp!= null && varTemp!= "")
      {
           //Get extension of filename
           var extension =   varTemp.substring(varTemp.length-3);
     
           var ValidImage = CheckImageFileType(varTemp);
           if(!ValidImage)
           {
                document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
                document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = '<ul><li>'+" Please Re-Enter " +alertName+ '<br/></li></ul>';
                document.getElementById("PhotoUpload").focus();
                document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
                document.getElementById("PhotoUpload").focus();
               // errors += " Please Re-Enter " +alertName+ '<br/></li>'
               if(_addTPErrorMessage == "")
               {
                    _addTPErrorMessage = document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
               }
               else
               {
                    _addTPErrorMessage =_addTPErrorMessage+" <br>"+ document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
               }
//                return(false); 	
           }
      }
   }
   if(_addTPErrorMessage != "")
   {
        document.getElementById("RegistrationErrors_CreatePlan").style.display = "block";
        document.getElementById("RegistrationErrorMessage_CreatePlan").innerHTML = _addTPErrorMessage;
        document.getElementById('WarningMsgs_RegistrationErrors').style.display ="none";
        document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = "";
        document.getElementById("WarningMsgs_divWarningInfo").style.display = "none";
        _addTPErrorMessage = "";
        return false;
   }
   else
   {
        document.getElementById("RegistrationErrors_CreatePlan").style.display = "none";
        document.getElementById("RegistrationErrorMessage_CreatePlan").innerHTML = "";
        document.getElementById('WarningMsgs_RegistrationErrors').style.display ="none";
        document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = "";
        document.getElementById("WarningMsgs_divWarningInfo").style.display = "none";
       if(document.getElementById("divSubmit") != null)
       {
        showdeadcenterdiv();
        document.getElementById("divSubmit").style.display="block";
       }
       return true;
   }
}	


// Function To Validate Training Name 
function ValidateTrainingName()
	{
		var Name ="Training Plan Name";
		var Value = document.getElementById('txtTrainingName').value;
	    
		
		if(!( ValidateMandatory(Name,Value)&&  ValidateLength(Name,Value,255) ) )
		{
			//document.getElementById('txtTrainingName').focus();
			//document.getElementById('txtTrainingName').focus();
			document.getElementById('txtTrainingName').style.backgroundColor = "Yellow";
			window.scrollBy(0,-10000);
            if(_addTPErrorMessage == "")
            {
                _addTPErrorMessage = document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
            }
            else
            {
                _addTPErrorMessage = _addTPErrorMessage+" <br>"+document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
            }
			return(false);
			
		}
		
		//////////
        var sExp;
        sExp = "^[0-9a-z(),\.\/ & ';\:-]+$";
        objRegExp = new RegExp(sExp, 'gi');

        if (objRegExp.test(Value.trim()) == false) 
        {
            document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
		    document.getElementById('WarningMsgs_RegistrationErrors').innerHTML ="Training Plan Name should contain only letters, numbers, space, comma, colon, dot, semicolon, single quote, forward slash, hyphen and ampersand.";
		    document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
            
            document.getElementById('txtTrainingName').focus();
            document.getElementById('txtTrainingName').style.backgroundColor = "Yellow";
            if(_addTPErrorMessage == "")
            {
                _addTPErrorMessage = document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
            }
            else
            {
                _addTPErrorMessage = _addTPErrorMessage+" <br>"+document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
            }
            return false;
        }
        //////////
		
		return(true);	
		
		
		
	}


// Function To Validate Training Duration 
function ValidateTrainingDuration()
	{
		var Name ="Training Duration";
		var Value = document.getElementById('txtTrainingDuration').value;
		if(Value == 0)
		{
		   // alert(Name + " Can not be NULL Value");
		    document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
            document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = Name + " cannot be blank.";
                document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
//            document.getElementById('txtTrainingDuration').focus();
document.getElementById('txtTrainingDuration').style.backgroundColor = "Yellow";
			window.scrollBy(0,-10000);
			if(_addTPErrorMessage == "")
           {
                _addTPErrorMessage = document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
           }
           else
           {
                _addTPErrorMessage =_addTPErrorMessage+" <br>"+ document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
           }
		  	return(false);  
		}
	
		
		if(!( ValidateMandatory(Name,Value) &&  ValidateLength(Name,Value,4)  && ValidateNumericFormat(Name,Value)))
		{
			document.getElementById('txtTrainingDuration').focus();
			document.getElementById('txtTrainingDuration').value="";
			if(_addTPErrorMessage == "")
           {
                _addTPErrorMessage = document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
           }
           else
           {
                _addTPErrorMessage =_addTPErrorMessage+" <br>"+ document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
           }
			return(false);
			
		}
		return(true);	
	}

// Function To Validate Price 
function ValidatePrice()
	{
		var Name ="Training Fee";
		var Value;
		if(document.getElementById('txtPrice').value == "")
		{
		    Value   = 0;
		}
		else
		{
		    Value = document.getElementById('txtPrice').value;
		}
				
		if(!( ValidateLength(Name,Value,255)  && ValidateRealFormat(Name,Value)) )
		{
			 document.getElementById('txtPrice').value="";
			 document.getElementById('txtPrice').style.backgroundColor = "Yellow";
			window.scrollBy(0,-10000);
			if(_addTPErrorMessage == "")
           {
                _addTPErrorMessage = document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
           }
           else
           {
                _addTPErrorMessage =_addTPErrorMessage+" <br>"+ document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
           }
//			document.getElementById('txtPrice').focus();
			return(false);			
		}
		return(true);	
	}


// Function To Validate Description 
function ValidateDescription()
	{
		var Name ="Description";
		var Value = document.getElementById('txtTrainingDescription').value;
		if(!( ValidateMandatory(Name,Value) ) )
		{
			//document.getElementById('txtTrainingDescription').focus();
			document.getElementById('txtTrainingDescription').style.backgroundColor = "Yellow";
			window.scrollBy(0,-10000);
			if(_addTPErrorMessage == "")
           {
                _addTPErrorMessage = document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
           }
           else
           {
                _addTPErrorMessage =_addTPErrorMessage+" <br>"+ document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
           }
			return(false);
			
		}
		else if(!ValidateLength("Description",Value,500))
		{
		    document.getElementById('txtTrainingDescription').focus();
		    document.getElementById('txtTrainingDescription').style.backgroundColor = "Yellow";
			window.scrollBy(0,-10000);
			if(_addTPErrorMessage == "")
           {
                _addTPErrorMessage = document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
           }
           else
           {
                _addTPErrorMessage =_addTPErrorMessage+" <br>"+ document.getElementById('WarningMsgs_RegistrationErrors').innerHTML;
           }
			return(false);
		}
		return(true);	
	}

// Function To Validate Training Plan Password. 
function ValidatePlanPassword()
	{
		var Name ="Password";
		var Value = document.getElementById('txtPassword').value;
	    
		
		if(!( ValidateMandatory(Name,Value) ) )
		{
			document.getElementById('txtPassword').focus();
			return(false);
			
		}
		return(true);	
	}


// Function To Validate Training Plan Password. 
function ValidatePassword()
	{
		var Name ="Password";
		var Value = document.getElementById('txtPassword').value;
	    Value = trim(Value);
		
		if(!( ValidateMandatory(Name,Value)&&  ValidateLengthLimit(Name,Value,6) && ValidatePasswordType(Name,Value)) )
		{
			document.getElementById('txtPassword').focus();
			return(false);
			
		}
		return(true);	
	}


//Function To Validate Length of Field
function ValidateLength(vFldName, vFieldVal,vFieldSize)
{
	if(vFieldVal.length > vFieldSize )
	{
		//alert(vFldName.length + ' cannot exceed than '+ vFieldSize );
		document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
        document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = vFldName + " cannot contain more than " + vFieldSize + " characters" ; 
        document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
		return(false);
	}
	else
	{
		return(true);	
    }
}


//Function To Validate Length of Field
function ValidateLengthLimit(vFldName, vFieldVal,vFieldSize)
{    
	if(vFieldVal.length < vFieldSize )
	{
		//alert(vFldName.length + ' cannot exceed than '+ vFieldSize );
		
		 document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
         document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = vFldName + " cannot be less than " + vFieldSize  + " characters" ;
         
          document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
    
           
		return(false);
	}
	else
	{
		return(true);	
    }
}

function ValidatePasswordType(vFldName,vFieldVal)
{
      
    //var objRegExp  = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
    var objRegExp = "^[^\ ]*$";
    //^\$[0-9]+(\.[0-9][0-9])?$
   
    if(vFieldVal == 0)
    {
     	return(true);
    }
    else if(vFieldVal.match(objRegExp)==null)
	{
			//alert(vFldName + ' is in invalid format. Please try again.');		
			document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
            document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = vFldName + " is in invalid format.";	
            document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
    
			return(false);	
	}
    else
    {
        return(true);  
    }
}


//Function To Validate Mandatory Value
function ValidateMandatory(vFldName, vFieldVal)
{
	if(vFieldVal == '')
	{
		//alert(vFldName + ' cannot be empty.');
		 document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
		 document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = vFldName + " cannot be empty.";
		document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
    
			
		return(false);
	}
	else
	{
		return(true);
    }
	
}

//Function To Validate Real Value
function ValidateRealFormat(vFldName,vFieldVal)
{
     
    //var objRegExp  = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
    var objRegExp = "^(([0-9])+([\.]([0-9][0-9]))?)$";
    //^\$[0-9]+(\.[0-9][0-9])?$
   
    if(vFieldVal == 0)
    {
     	return(true);
    }
    else if(vFieldVal.match(objRegExp)==null)
	{
			//alert(vFldName + ' is in invalid format. Please try again.');		
			document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
            document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = vFldName + " is in invalid format.";	
            document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
            
			
    
			return(false);	
	}
    else
    {
        return(true);  
    }
}

//Function To Validate Numeric Value
function ValidateNumericFormat(vFldName,vFieldVal)
{
   var sNumericExp = "^[\\s]*[0-9]+[\\s]*$";   
   
    //if(isNaN(vFieldVal) == true)
    if(vFieldVal == 0)
    {
     	return(true);
    }
    else if(vFieldVal.match(sNumericExp)==null)
	{
			//alert(vFldName + ' is in invalid format. Please try again.');
			
		    document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
            document.getElementById('WarningMsgs_RegistrationErrors').innerHTML ="Please enter valid "+ vFldName + ".";
             document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
    
			return(false);	
			
	}	 
    else
    {
         return(true);
    }  
}


//Function to validate that StartDate is always greater than or equal to Today's Date.
function ValidateDatevalue(vFldName,vFieldVal)
{
    var TodayDate = new Date();
    var StartDate = new Date(vFieldVal);    
    if( (StartDate.getDate() == TodayDate.getDate() )&& (StartDate.getMonth() == TodayDate.getMonth()) && (StartDate.getFullYear() == TodayDate.getFullYear()))
    {
        return(true);
    }
    else
    {
        if(StartDate < TodayDate == true)
        {
           // alert("Start date can not be less than current date.");
           document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
           document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = "Training start date must be equal to today’s date or a future date.";
           document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
    
            return(false);
        }
        else
        {
            return(true);
        }
   }
   
}

//This function validates all field values of the form Get Plan
function ValidateGetPlan()
{
    
    var objCtrl=document.getElementById('hidStartDate').value;
    
    
    if(document.getElementById('hidFixedDuration')!=null)
    {
        if(document.getElementById('hidFixedDuration').value=="0")
        {
            if (!ValidateTrainingStartDate())    
            {    
	           return(false);
	        }
        }
    }
    
    if(objCtrl.indexOf("1/1/1900")>=0)
    {   if (!ValidateTrainingStartDate())   
        {     
	       return(false);
	    }
	}
			
//	if(!ValidateTrainingMessage())
//	{
//	    return(false);	
//	}
	   
//	if(document.getElementById('hidIsPasswordProtected').value =="1")
//	   {
//	        if(!ValidatePlanPassword())
//	        {
//	            return(false);
//	        }	 
//	   } 
	   
	   
	    //Check terms of use
	     if (document.getElementById("chkAcceptTerms") != null)
	     {
	         if (document.getElementById("chkAcceptTerms").checked == false )
             {
                  document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
	              document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = "Please accept the Terms Of Use to enroll this plan.";
	              document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
    
            	  document.getElementById("chkAcceptTerms").focus();
                  return false;
             }
         }
         
//         document.getElementById('btnSubmit').style.display = "none";
//         document.getElementById('btnCancel').style.display = "none";
//        closepopup('divSubscribe');
  	     return true;
}	


//This function validates all field values of the form Coach Subscribe
function ValidateCoachSubscribe()
{
 			
        var Name ="Message";
		var Value = document.getElementById('txtCoachSubscribeMessage').value;
	    
		
		if(!( ValidateMandatoryCoachSubscribe(Name,Value)) )
		{
			document.getElementById('txtCoachSubscribeMessage').focus();
			return(false);
			
		}
		return(true);	
}	
//Function To Validate Mandatory Coach Subscribe Value
function ValidateMandatoryCoachSubscribe(vFldName, vFieldVal)
{
	if(vFieldVal == '')
	{
		  document.getElementById("WarningMsg1_divWarningInfo").style.display = "block";
		 document.getElementById('WarningMsg1_RegistrationErrors').style.display ="block";
		 document.getElementById('WarningMsg1_RegistrationErrors').innerHTML = vFldName + " cannot be empty.";
		
		return(false);
	}
	else
	{
		return(true);
    }

}


// Function To Validate Start Date
function ValidateTrainingStartDate()
	{
		var Name ="Training Start Date";
		var Value = document.getElementById('txtTrainingStartDate').value;
				
		if(!( ValidateMandatory(Name,Value) &&  ValidateDatevalue(Name,Value)  ))
		{
			document.getElementById('txtTrainingStartDate').focus();
			return(false);
			
		}
		return(true);	
	}
	

// Function To Validate Training Message. 
function ValidateTrainingMessage()
	{
		var Name ="Message";
		var Value = trim(document.getElementById('txtMessage').value);
		document.getElementById('txtMessage').innerHTML= trim(document.getElementById('txtMessage').value);
		if(!( ValidateMandatory(Name,Value)) )
		{
		    //document.getElementById('txtMessage').innerHTML="";
			document.getElementById('txtMessage').focus();
			return(false);
			
		}
		return(true);	
	}



// Function To Validate Training Message. 
function ValidateMessage()
	{
		var Name ="Message";
		var Value = document.getElementById('txtSubscribeMessage').value;
	    
		
		if(!( ValidateMessageMandatory(Name,Value)) )
		{
			document.getElementById('txtMessage').focus();
			return(false);
			
		}
		return(true);	
	}
	
	function ValidateMessageMandatory(vFldName, vFieldVal)
	{
	    if(vFieldVal == '')
	    {
		    //alert(vFldName + ' cannot be empty.');
		    if(document.getElementById('WarningMsgs_RegistrationErrors')!=null)
		    {
		         document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
		         document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = vFldName + " cannot be empty.";
		         document.getElementById('WarningMsgs_divWarningInfo').style.display ="block";
		    }
		    if(document.getElementById('WarningMsgs2_RegistrationErrors')!=null)
		    {
		         document.getElementById('WarningMsgs2_RegistrationErrors').style.display ="block";
		         document.getElementById('WarningMsgs2_RegistrationErrors').innerHTML = vFldName + " cannot be empty.";
		         document.getElementById('WarningMsgs2_divWarningInfo').style.display ="block";
		    }
    		
		    return(false);
	    }
	    else
	    {
		    return(true);
		}
	}

// Function To Validate Training Message. 
function ValidateThresholdMessage()
{
	var Name ="Comment";
	var Value = document.getElementById('txtComment').value;
    
	
	if(!( ValidateMandatory(Name,Value)) )
	{
		document.getElementById('txtComment').focus();
		return(false);
		
	}
	return(true);	
}


function DurationInSec(HourObj,MinuteObj,SecondObj)
{ 
    var temp = null;

	var hr1 = HourObj.value;
	var min1 = MinuteObj.value;
	var sec1 = SecondObj.value;
	 
	var duration = 0;
	
	if((hr1=="NaN")||(hr1==""))
	{   
	    hr1=0;
	}
    if((min1=="NaN")||(min1==""))
	{   
	    min1=0;
	}
    if((sec1=="NaN")||(sec1==""))
	{   
	    sec1=0;
	}
	
	hr1= parseFloat(hr1);
	
	duration = (hr1*3600) + (min1*60) + (sec1*1);
	
	return(duration);
   
}

function convertPaceOnUnitType(pace,unitType,workout)
{
    
	if(workout=="1" || workout=="11" || workout=="12")
	{   //For cycling workout
        if(unitType==isKm)
        { 
            pace=parseFloat(pace*(3600/1000));
        }
        else
        if(unitType==isMiles)
        {  
            pace=parseFloat(pace*(3600/1609.344));
        } 
    }
    else
    {   //For swimming or other workout
        if(unitType==isKm)
        { 
            pace=pace*1000;
        }
        else if(unitType==isMiles)
        {  
            pace=pace*1609.344;
        }
        else if(unitType==isMeters)
        {            
            pace=pace*1;
                   
        }
        else if(unitType==isYards)
        {  
            pace=pace*0.9144;
        }
    }
    
    if((workout=="3")&&((unitType==isMeters)||(unitType==isYards)))
    {   //For swimming pace should be duration/100 meters or duration/100 yards
        pace=pace*100;
    }
    
    return(parseFloat(pace));
}


function calculatePace(DistanceObj,UnitObj,WorkoutObj,duration,PaceObj)
{   
	var temp = null;  
    
	var dist = DistanceObj.value;
	 
	dist = parseFloat(dist);
	
    var unitType=UnitObj.value;
    
    var unitName=GetUnitName(unitType);
      
    if(unitType==isKm)
    {
		dist=dist*1000;
    }
    else
    if(unitType==isMiles)
    {  
        dist=dist*1609.344;
    }
    else
    if(unitType==isMeters)
    { 
        dist=dist*1;
    }
    else
    if(unitType==isYards)
    {  
        dist=dist*0.9144;
    }
    
	var pace = 0;
	dist = parseFloat(dist);
	
	pace = parseFloat(pace);
	
    var sport = WorkoutObj.value;
    var totalPace = 0;
    if(sport=="1" || sport=="11" || sport=="12")
    {
        if( dist != 0 && duration != 0)
	    {
            pace = parseFloat(dist/duration);
            
            pace = convertPaceOnUnitType(pace,unitType,sport);
             
            if(pace.toString()=="NaN")
            {
                pace=0;
            }
            totalPace = parseFloat(Math.round(pace*100)/100);
        } 
        else
        {
           pace = 0;
           totalPace = 0;
        }
        if(PaceObj!=null)
        {  
            PaceObj.value = totalPace + " "+ unitName + "/hour";         
        }
    }
    else
    {   if( dist != 0 && duration != 0)
	    {	   
	        pace = parseFloat(duration/dist);
	        
	        pace = convertPaceOnUnitType(pace,unitType,sport);
	         
            if(pace.toString()=="NaN")
            {
                pace=0;
            }
            
            var totalPace = parseFloat(Math.round(pace));
         
            var hr = 0;
            var min = 0;
            var sec = 0;
            var strPace="";
             
            hr = parseInt(totalPace / 3600);
            totalPace = totalPace % 3600;
            min = parseInt(totalPace / 60);
            totalPace = totalPace % 60;
            sec = parseInt(totalPace);

            strPace = hr + ":" + min + ":" + sec;
        }
        else
        {
            pace = 0;
            strPace =  "0:0:0";
        }    
        if(PaceObj!=null)
        {  
            if((sport=="3")&&((unitType==isMeters)||(unitType==isYards)))
            {  //For swimming pace should be duration/100 meters or duration/100 yards
               unitName = "100 "+unitName;
            }
            PaceObj.value = strPace + " / " + unitName;         
        }
  }
     
    return true;
}


function GetUnitName(unitType)
{    
    var unitName="";
   
     switch(parseInt(unitType))
     {
        case 1:unitName="miles";break;
        case 2:unitName="km";break;
        case 3:unitName="meters";break;
        case 4:unitName="yards";break; 
     }
     
     return(unitName);
}

//Function To Calculate The Pace Value.	
function CalculatePaceValue()
{    
    //if workout not weight training
    if(document.getElementById('ddlWorkoutType').value!="7")
    {
        var HourObj = document.getElementById("txtHrDuration");
        var MinuteObj = document.getElementById("txtMinDuration");
        var SecondObj = document.getElementById("txtSecDuration");
        
        var duration=DurationInSec(HourObj,MinuteObj,SecondObj);
        
        var DistanceObj = document.getElementById("txtDistance");
        var UnitObj = document.getElementById("ddlDistanceUnits");
        var WorkoutObj = document.getElementById("ddlWorkoutType");
        var PaceObj = document.getElementById("txtPace");
        
        calculatePace(DistanceObj,UnitObj,WorkoutObj,duration,PaceObj);
    }
    
    return(true);
}


//To Get the plan from CoachDetails information.
function GetTrainingPlan(PlanId, PlanName,CoachId,CoachName,Price,IsPasswordProtected,StartDate,PlanDuration)
{  

if(document.getElementById("hidCurrentPlanId") != null)
{
    document.getElementById("hidCurrentPlanId").value = PlanId;
}
if(document.getElementById("hidCurrentPlanName") != null)
{
    document.getElementById("hidCurrentPlanName").value = PlanName;
}
if(document.getElementById("hidCurrentCoachId") != null)
{
    document.getElementById("hidCurrentCoachId").value = CoachId;
}
if(document.getElementById("hidCurrentCoachName") != null)
{
    document.getElementById("hidCurrentCoachName").value = CoachName;
}
if(document.getElementById("hidCurrentPrice") != null)
{
    document.getElementById("hidCurrentPrice").value = Price;
}
if(document.getElementById("hidCurrentIsPasswordProtected") != null)
{
    document.getElementById("hidCurrentIsPasswordProtected").value = IsPasswordProtected;
}
if(document.getElementById("hidCurrentStartDate") != null)
{
    document.getElementById("hidCurrentStartDate").value = StartDate;
}
if(document.getElementById("hidCurrentPlanDuration") != null)
{
    document.getElementById("hidCurrentPlanDuration").value = PlanDuration;
}
 var ddlSport;
 ddlSport   = document.getElementById('ddlSport');
    
  if( document.getElementById('hidUserId').value ==0)
  {
   //ShowInformationMessageBox("Please Login to the system to Get Plan.");   
    OpenLoginPopup(document.getElementById('hidUserId').value);
    window.scrollBy(0,-10000);
    if(ddlSport != null)
   {
    ddlSport.style.display = "";
   }
    return(false);
  }
  else if(document.getElementById('hidUserId').value == CoachId)
  {
    ShowInformationMessageBox("Coach cannot enroll for his own plan.");   
    
    
   if(ddlSport != null)
   {
    ddlSport.style.display = "";
   }
    return(false);
  }
   
  else
  {
  
   document.getElementById('hidStartDate').value = StartDate;
   document.getElementById('hidPlanId').value = PlanId; 
   document.getElementById('hidPlanName').value =PlanName; 
   document.getElementById('hidCoachId').value  = CoachId;
   document.getElementById('hidCoachName').value  = CoachName;
   document.getElementById('hidPlanDuration').value  = PlanDuration;
   
    var btnObj=document.getElementById("btnCheckSubscription");
	
	if ((document.all)||(is_Safari > 0))
	{
		// IE		
		btnObj.click();		
	}
	else
	{
		// FireFox 		
		var e = document.createEvent("MouseEvents");
		e.initEvent("click", true, true);
		btnObj.dispatchEvent(e);
	} 
  
    
     document.getElementById('WarningMsgs_RegistrationErrors').style.display ="none";
     document.getElementById("WarningMsgs_divWarningInfo").style.display = "none";
    
   
   //Added by Amit on 28th March for password checking.  
//      document.getElementById('hidIsPasswordProtected').value = IsPasswordProtected;    
//      if(IsPasswordProtected =="1")
//      {
//        document.getElementById('divProtectPassword').style.display = "block";
//      }
//      else
//      {
//       document.getElementById('divProtectPassword').style.display = "none"; 
//      }
   //End of changes.
 
 
  // New implementation : now FREE and PAID both plans go to approval.  
   if(Price =="Free")
   {
     document.getElementById('hidPrice').value = "0";  
   }
   else
   {
        document.getElementById('hidPrice').value = "0";  
   }
        
   var valMessage = document.getElementById("lblPlanName");         
   valMessage.innerHTML =PlanName;
      
   //alert(StartDate);
   //alert(StartDate.indexOf("1/1/1900"));
   
   
   document.getElementById('divlblStartDate').style.display="none";
   document.getElementById('divlblRaceDate').style.display="none";
   document.getElementById('divtxtStartDate').style.display="none";
   //document.getElementById('divlblDate').style.display="none"; 
   //document.getElementById('divlblDateOption').style.display="none"; 
        
      
   if(StartDate.indexOf("1/1/1900")>=0)
   {
       
       document.getElementById('divlblStartDate').style.display="block";
       //document.getElementById('divlblRaceDate').style.display="block";
       document.getElementById('divtxtStartDate').style.display="block";
       //document.getElementById('divlblDate').style.display="block"; 
       //document.getElementById('divlblDateOption').style.display="block";
       //var rdo = document.getElementsByName("optStartDate");
    
//        if (document.all)
//	    {
//		    // IE
//		    rdo[1].checked=true;        
//       }
//       else
//       {
//		    // FireFox 
//		    rdo[0].checked=true;	
//       }
    
    
   }
   else
   {
       
   }
   
   document.getElementById('txtTrainingStartDate').value = "";      
   document.getElementById('txtMessage').value = "";
   document.getElementById('txtPassword').value = "";
    
    //document.getElementById("optStartDate").style.display
    
    document.getElementById('chkAcceptTerms').checked=false;
     if(ddlSport != null)
   {
    ddlSport.style.display = "";
   }
    
   // ShowModalPopup('divSubscribe','Get Training Plan');
  }    
}



// To Get the Plan from TrainingPlanDetails Information.
function GetPlan()
{      
      
  if( document.getElementById('hidUserId').value ==0)
  {
    //ShowInformationMessageBox("Please Login to the system to Get Plan."); 
    OpenLoginPopup(document.getElementById('hidUserId').value);  
    window.scrollBy(0,-10000);
    return(false);
  }  
  else if(document.getElementById('hidUserId').value == document.getElementById('hidCoachId').value )
  {
    ShowInformationMessageBox("Coach cannot enroll his own plan.");   
    return(false);
  }
  else
  {  
     var btnObj=document.getElementById("btnCheckSubscription");
	
	if ((document.all)||(is_Safari > 0))
	{
		// IE		
		btnObj.click();		
	}
	else
	{
		// FireFox 		
		var e = document.createEvent("MouseEvents");
		e.initEvent("click", true, true);
		btnObj.dispatchEvent(e);
	} 
  
  
  
//    var IsPasswordProtected = document.getElementById('hidIsPasswordProtected').value ;
//    if(IsPasswordProtected =="1")
//      {
//        document.getElementById('divProtectPassword').style.display = "block";
//      }
//      else
//      {
//       document.getElementById('divProtectPassword').style.display = "none"; 
//      }
    
     document.getElementById('WarningMsgs_RegistrationErrors').style.display ="none";
     document.getElementById("WarningMsgs_divWarningInfo").style.display = "none";
    
         
      
      document.getElementById('divlblStartDate').style.display="none";
      document.getElementById('divlblRaceDate').style.display="none";
      document.getElementById('divtxtStartDate').style.display="none"; 
      //document.getElementById('divlblDate').style.display="none"; 
      //document.getElementById('divlblDateOption').style.display="none"; 
        
      if(document.getElementById('hidFixedDuration').value=="1")
      {
         
         
          
      }
      else
      {
          document.getElementById('divlblStartDate').style.display="block";
          //document.getElementById('divlblRaceDate').style.display="block";
          document.getElementById('divtxtStartDate').style.display="block";
          //document.getElementById('divlblDate').style.display="block"; 
          //document.getElementById('divlblDateOption').style.display="block"; 
//          var rdo = document.getElementsByName("optStartDate");
//    
//          if (document.all)
//          {    // IE
//	            rdo[1].checked=true;        
//          }
//          else
//          {    // FireFox 
//	            rdo[0].checked=true;	
//          }
       
      }

      
     document.getElementById('txtTrainingStartDate').value = "";      
     document.getElementById('txtMessage').value = ""; 
     document.getElementById('txtPassword').value = "";
     
     var PlanName = document.getElementById('hidPlanName').value ;
     
     var valMessage = document.getElementById("lblTrPlanName");         
     valMessage.innerHTML =PlanName;   
    
    document.getElementById('chkAcceptTerms').checked=false;
     
    //ShowModalPopup('divSubscribe','Get Training Plan');
  }    
}

function GetCoachSubscribe()
{   
   
   if( document.getElementById('hidUserId').value ==0   )
                      {
                         //ShowInformationMessageBox("Please login to the system for coach following.");   
                        OpenLoginPopup(document.getElementById('hidUserId').value);
                        window.scrollBy(0,-10000);
                        return(false);
                      }
                  else
                  {
                        if(document.getElementById('hidUserId').value == document.getElementById('hidCoachId').value)
                        {
                             ShowInformationMessageBox("Coach cannot follow himself.");   
                            return(false);
                        }
                        else
                        {         
                            if( document.getElementById('WarningMsgs_RegistrationErrors')!=null)
                            {
                                document.getElementById('WarningMsgs_RegistrationErrors').style.display ="none";
                                document.getElementById("WarningMsgs_divWarningInfo").style.display = "none";
                            }
                            if( document.getElementById('WarningMsg1_RegistrationErrors')!=null)
                            {
                                document.getElementById('WarningMsg1_RegistrationErrors').style.display ="none";
                                document.getElementById("WarningMsg1_divWarningInfo").style.display = "none";
                                
                             }
                            var _btnId = document.getElementById("btnSubmitCoachSubscription");
                            var _RecordId;
                            document.getElementById("confirmBox_hidButtonId").value ="btnSubmitCoachSubscription";  // hidden button id assigned
                            
                            document.getElementById("hidRecordId").value=_RecordId; // record Id can be any ,in case of non JS oprations.
                            ShowConfirmBox('Would you like to follow the Coach?'); 
                            return false;
                        
                        }
                  }
    
}

function ValidateImport()
{
    var value =   document.getElementById('WorkoutFileUpload');
    if(value!= null)
    {
//       // alert("Please select the file");
//      document.getElementById('WarningImportMsgs_RegistrationErrors').style.display ="block";
//      document.getElementById('WarningImportMsgs_divWarningInfo').style.display ="block";
//	  document.getElementById('WarningImportMsgs_RegistrationErrors').innerHTML = "Please select the file.";
//       
//        return(false);
//    }
//    else
//    {
        var FileName = document.getElementById("WorkoutFileUpload").value;
        var extension =   FileName.substring(FileName.length-3);
        var validFileStatus = false;
        var errors = "" ;
        if(!FileName)
        {
            validFileStatus = false;
            errors = "Please select file to upload.";
            
        }
        else
        {
            if(extension == "xls" || extension == "XLS")
            {
                validFileStatus = true;
            }
            else
            {
               errors = "Only excel .xls file type is allowed. "; 
               validFileStatus = false;
            }
        }  
        if(validFileStatus == false)
        {
            document.getElementById('WarningImportMsgs_RegistrationErrors').style.display ="block";
            document.getElementById('WarningImportMsgs_divWarningInfo').style.display ="block";
            document.getElementById('WarningImportMsgs_RegistrationErrors').innerHTML = errors;
            document.getElementById('WorkoutFileUpload').style.backgroundColor = "Yellow";
	        window.scrollBy(0,-10000);
            return false;
        }
        else
        {
            return true;
        }
    }
    return(true);
}

//Function to Add Workouttype.
function AddWorkType(PlanId,DayId)
{ 
    //To clear or reset the activitylist datagrid 
    if(document.getElementById('WarningMsgs3_RegistrationErrors')!= null)
    {
        document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="none";
    }
    if(document.getElementById("WarningMsgs3_divWarningInfo")!= null)
    {
       document.getElementById("WarningMsgs3_divWarningInfo").style.display = "none";
    }
    document.getElementById("lblCharactersLeft1").innerHTML = "500"; 
    var btnObj=document.getElementById("btnHidAddWorkout");
	
	if ((document.all)||(is_Safari > 0))
	{
		// IE
		
		btnObj.click();
		
	}
	else
	{
		// FireFox 
		
		var e = document.createEvent("MouseEvents");
		e.initEvent("click", true, true);
		btnObj.dispatchEvent(e);
	}   
	
	//alert("AddWorkType");
    
    SetVisibleControlForWorkoutType();
    //showOtherWorkoutType();
    
    var arrobj;
    document.getElementById('hidDayValue').value = DayId;
    document.getElementById('hidPlanId').value = PlanId; 
    document.getElementById('hidWorkTypeValue').value = 0;  
     
    ResetPlanPreview();
    if(document.getElementById("divBrickUI")!=null)
    {
        document.getElementById("divBrickUI").style.display="none";
    }
    
   if(document.getElementById("divExcerciseUI")!=null)
    {
		arrobj=document.getElementById("divExcerciseUI");
		arrobj.style.display = "none";   
	}  
		
    if(document.getElementById("divWorkoutUI")!=null)
    {
        document.getElementById("divWorkoutUI").style.display="block";
    } 

        
    ShowModalPopup('divWorkoutPreview','Workout Preview','l');
    
 
   document.getElementById("ddlWorkoutType").style.display ="inline"; 
   document.getElementById("ddlDistanceUnits").style.display ="inline";    
   
    document.getElementById("ddlWorkoutType").value="1";
    
   
   if(document.getElementById("ddlExcerciseType")!=null)
   {
       arrobj=document.getElementById("ddlExcerciseType");
       arrobj.style.display = "inline";   
   }
   if(document.getElementById("ddlActivityName")!=null)
   {
      document.getElementById("ddlActivityName").style.display="inline";
   }
   if(document.getElementById("ddlActivityUnit")!=null)
   {
      document.getElementById("ddlActivityUnit").style.display="inline";
   }
        
         ShowCreatePlanDDL();
        
    return false;
}

function GetWeeklyDetails(WeekId)
{
    document.getElementById('hidWeekId').value = WeekId;
    ShowModalPopup('divweeklyPreview','Weekly workout details');    
}

function AcceptPlanConfirmation(RecordId,btnId)
{
    //return confirm('Would you like to delete this record?');
    document.getElementById("confirmBox_hidButtonId").value=btnId;
    document.getElementById("hidRecordId").value=RecordId;
    ShowConfirmBox('Do you want to accept the plan enrollment?');
    return false;
}

function AcceptPlanSuccess()
{
    
     document.getElementById('WarningMsgs_RegistrationErrors').style.display ="none";
     document.getElementById("WarningMsgs_divWarningInfo").style.display = "none";
     var valPlanName = document.getElementById("lblTrPlanName");         
     valPlanName.innerHTML =document.getElementById('hidPlanName').value; 
     document.getElementById('txtMessage').value = "";  
     ShowModalPopup('divSubscribe','Training Plan Enrollment','m');
}

function  AcceptPlanFail()
{
    document.getElementById('hidPlanId').value  = "";
    document.getElementById('hidPlanName').value  =  "";
    document.getElementById('hidStartDate').value  =  "";
    document.getElementById('hidUserId').value  =  "";
    document.getElementById('hidPlanSubscribeId').value =  "";

}
    
//This function is used to call Modal box to Accept the Plan Subscription 
function AcceptPlan(PlanSubscribeId,PlanId,PlanName,StartDate,UserId,Priceval)
{   
     var result=false;       
     
     if(Priceval =="0")
     {
        result = true;
     }
     else
     {             
        //result = confirm('Do you want to accept the plan subscription?');
        document.getElementById('hidPlanId').value  = PlanId;
        document.getElementById('hidPlanName').value  = PlanName;
        document.getElementById('hidStartDate').value  = StartDate;
        document.getElementById('hidUserId').value  = UserId;
        document.getElementById('hidPlanSubscribeId').value = PlanSubscribeId;
   
        AcceptPlanConfirmation('JSOperation','AcceptPlanSuccess');
     }
      
     if(result ==true)
     {           
      
       document.getElementById('WarningMsgs_RegistrationErrors').style.display ="none";
       document.getElementById("WarningMsgs_divWarningInfo").style.display = "none";
    
       document.getElementById('hidPlanId').value  = PlanId;
       document.getElementById('hidPlanName').value  = PlanName;
       document.getElementById('hidStartDate').value  = StartDate;
       document.getElementById('hidUserId').value  = UserId;
       
      
       var valPlanName = document.getElementById("lblTrPlanName");         
       valPlanName.innerHTML =PlanName;  
      
       
       document.getElementById('txtMessage').value = "";         
       document.getElementById('hidPlanSubscribeId').value = PlanSubscribeId;
        
       ShowModalPopup('divSubscribe','Training Plan Enrollment','m');
    }   
}

function DenyPlanConfirmation(RecordId,btnId)
{
    //return confirm('Would you like to delete this record?');
    document.getElementById("confirmBox_hidButtonId").value=btnId;
    document.getElementById('hidPlanSubscribeId').value=RecordId;
    ShowConfirmBox('Do you want to deny the plan Enrollment?');
    return false;
}

// This function is used to Deny the Training Plan
function DenyPlan(PlanSubscribeId) 
{   
   //var result = confirm('Do you want to deny the plan subscription?');
   
   DenyPlanConfirmation(PlanSubscribeId,'btnhiddenDenyplan');
   
//   if( result == true)
//   {
//    
//     document.getElementById('hidPlanSubscribeId').value = PlanSubscribeId;
//    
//     var btnObj = document.getElementById("btnhiddenDenyplan");
//        if(btnObj != null && btnObj != "")
//        {
//                
//                if ((document.all)||(is_Safari > 0))
//                {
//                    // IE
//                        btnObj.click();
//        
//                }
//                else
//                {
//                    // FireFox 
//        
//                    var e = document.createEvent("MouseEvents");
//                    e.initEvent("click", true, true);
//                    btnObj.dispatchEvent(e);        
//                }
//        }  
//   } 
//   
   // return(true);
   
   return false;
}

function UnsubscribePlanConfirmation(RecordId,btnId)
{
    //return confirm('Would you like to delete this record?');
    document.getElementById("confirmBox_hidButtonId").value=btnId;
    document.getElementById('hidPlanSubscribeId').value=RecordId;
    ShowConfirmBox('Are you sure you want to withdraw your enrollment from the training plan?');
    return false;
}

function UnsubscribePlan(PlanSubscribeId) 
{   
   //var result = confirm('Do you want to unsubscribe the plan?');
   
   UnsubscribePlanConfirmation(PlanSubscribeId,'btnhiddenDeleteplan');
     
//   if( result == true)
//   {
//    
//     document.getElementById('hidPlanSubscribeId').value = PlanSubscribeId;
//    
//     var btnObj = document.getElementById("btnhiddenDeleteplan");
//        if(btnObj != null && btnObj != "")
//        {
//                
//                if ((document.all)||(is_Safari > 0))
//                {
//                    // IE
//                        btnObj.click();
//        
//                }
//                else
//                {
//                    // FireFox 
//        
//                    var e = document.createEvent("MouseEvents");
//                    e.initEvent("click", true, true);
//                    btnObj.dispatchEvent(e);        
//                }
//        }  
//   } 
   
    //return(true);
    return false;
}

function UnsubscribeFreePlanConfirmation(RecordId,btnId)
{
    //return confirm('Would you like to delete this record?');
    document.getElementById("confirmBox_hidButtonId").value=btnId;
    document.getElementById('hidPlanSubscribeId').value=RecordId;
    ShowConfirmBox('Are you sure you want to withdraw your enrollment from the training plan?');
    return false;
}

function UnsubscribeFreePlan(PlanSubscribeId) 
{   
   //var result = confirm('Do you want to unsubscribe the plan?');
   
   UnsubscribeFreePlanConfirmation(PlanSubscribeId,'btnhiddenDeleteFreeplan');
//   if( result == true)
//   {
//    
//     document.getElementById('hidPlanSubscribeId').value = PlanSubscribeId;
//    
//     var btnObj = document.getElementById("btnhiddenDeleteFreeplan");
//        if(btnObj != null && btnObj != "")
//        {
//                
//                if ((document.all)||(is_Safari > 0))
//                {
//                    // IE
//                        btnObj.click();
//        
//                }
//                else
//                {
//                    // FireFox 
//        
//                    var e = document.createEvent("MouseEvents");
//                    e.initEvent("click", true, true);
//                    btnObj.dispatchEvent(e);        
//                }
//        }  
//   } 
   
   // return(true);
   
   return false;
}

function AcceptCoachConfirmation(RecordId,btnId)
{
    //return confirm('Would you like to delete this record?');
    document.getElementById("confirmBox_hidButtonId").value=btnId;
    document.getElementById("hidRecordId").value=RecordId;
    ShowConfirmBox('Do you want to accept the Follower Request?');
    return false;
}

function AcceptCoachSuccess()
{
     ShowModalPopup('divUserSubscribe','User Subscription');   
}

function AcceptCoachFail()
{
   document.getElementById('hidCoachSubscribeId').value = "";
   document.getElementById('hidUserSubscribeId').value = "";
   document.getElementById('hidUserName').value = "";  
}

// This Function is used to call Coach Subscription Modal box for Subscription.
function AcceptCoach(CoachSubscribeId,UserId,UserName)
{   
   //var result = confirm('Do you want to Accept the Subscription?');
   
   document.getElementById('hidCoachSubscribeId').value = CoachSubscribeId;
   document.getElementById('hidUserSubscribeId').value = UserId;
   document.getElementById('hidUserName').value = UserName;  
     
   AcceptCoachConfirmation('JSOperation','AcceptCoachSuccess');
        
//   if( result == true)
//   {
//     
//     document.getElementById('hidCoachSubscribeId').value = CoachSubscribeId;
//     document.getElementById('hidUserSubscribeId').value = UserId;
//     document.getElementById('hidUserName').value = UserName;  
//          
//     ShowModalPopup('divUserSubscribe','User Subscription');   

//    }
}

function DenyCoachConfirmation(RecordId,btnId)
{
    //return confirm('Would you like to delete this record?');
    document.getElementById("confirmBox_hidButtonId").value=btnId;
    document.getElementById("hidCoachSubscribeId").value=RecordId;
    ShowConfirmBox('Do you want to deny the Coach following?');
    return false;
}

// This Function is used to Deny Coach Subscription.
function DenyCoach(CoachSubscribeId)
{   
   //var result = confirm('Do you want to deny the Coach Subscription?');
   DenyCoachConfirmation(CoachSubscribeId,'btnHiddenDenyCoach');
//   if( result == true)
//   {
//    
//     document.getElementById('hidCoachSubscribeId').value = CoachSubscribeId;
//    
//     var btnObj = document.getElementById("btnHiddenDenyCoach");
//        if(btnObj != null && btnObj != "")
//        {
//                if ((document.all)||(is_Safari > 0))
//                {
//                    // IE
//                        btnObj.click();
//        
//                }
//                else
//                {
//                    // FireFox 
//        
//                    var e = document.createEvent("MouseEvents");
//                    e.initEvent("click", true, true);
//                    btnObj.dispatchEvent(e);        
//                }
//        }  
//   } 
   
    //return(true);
    
    return false;
}



function GetThreshold(SubscribeId,CoachName,TotalPlanSold,TotalUserSubscribe,CoachId)
{    
      // document.getElementById('divTrainingPlanMessage').style.display ="none";      
       document.getElementById('WarningMsgs_RegistrationErrors').style.display ="none";
         document.getElementById("WarningMsgs_divWarningInfo").style.display = "none";
    
       document.getElementById('hidCoachId').value = CoachId;
       document.getElementById('hidCoachName').value = CoachName;
       document.getElementById('hidSubscribeId').value  = SubscribeId;  
       document.getElementById('hidTotalPlansold').value  = TotalPlanSold; 
       document.getElementById('hidTotalUserSubscribe').value  = TotalUserSubscribe; 
       
       document.getElementById('txtUserSubscribeLimit').value = "";
       document.getElementById('txtPlanAmountLimit').value = "";
       document.getElementById('txtComment').value  = ""; 
                
        var valCoachName = document.getElementById("lblCoachName");         
        valCoachName.innerHTML =CoachName;   
      
      
      var btnObj = document.getElementById("btnHiddenEditThresholdLimit");
        if(btnObj != null && btnObj != "")
        {
                if ((document.all)||(is_Safari > 0))
                {
                    // IE
                        btnObj.click();
        
                }
                else
                {
                    // FireFox 
        
                    var e = document.createEvent("MouseEvents");
                    e.initEvent("click", true, true);
                    btnObj.dispatchEvent(e);        
                }
        }  
          
         
       ShowModalPopup('divSubscriptionLimit','Coach Enrollment Threshold','m');
       

}



//This function is used to Reset the Fields for Plan Preview.
function ResetPlanPreview()
{
    document.getElementById('txtDistance').value ="";
    document.getElementById('txtHrDuration').value ="";
    document.getElementById('txtMinDuration').value ="";
    document.getElementById('txtSecDuration').value ="";
    document.getElementById('txtPace').value ="";
    document.getElementById('txtWorkoutInstructions').value ="";
    //document.getElementById('txtNotes').value ="";
       
    if(document.getElementById("txtActivityDistance")!=null)
    {
       document.getElementById("txtActivityDistance").value="";
    }
    if(document.getElementById("txtActivityHr")!=null)
    {
        document.getElementById("txtActivityHr").value="";
    }
    if(document.getElementById("txtActivityMin")!=null)
    {
        document.getElementById("txtActivityMin").value="";
    }
    if(document.getElementById("txtActivitySec")!=null)
    {
        document.getElementById("txtActivitySec").value="";
    }
    
    if(document.getElementById("txtActivityPace")!=null)
    {
       document.getElementById("txtActivityPace").value="";
    }
    
    if(document.getElementById("lblTotalActivityDistance")!=null)
    {
        document.getElementById("lblTotalActivityDistance").innerHTML="";       
    }
    
    if(document.getElementById("lblTotalActivityDuration")!=null)
    {
        document.getElementById("lblTotalActivityDuration").innerHTML="";       
    }
    
    if(document.getElementById("lblAvgActivityPace")!=null)
    {
        document.getElementById("lblAvgActivityPace").innerHTML="";       
    }
    
    if(document.getElementById("ddlActivityName")!=null)
    {
        document.getElementById("ddlActivityName").value="1";       
    }
   
    if(document.getElementById("ddlActivityUnit")!=null)
    {
        document.getElementById("ddlActivityUnit").value="1";       
    }
    if(document.getElementById("lblCycleActivityDistance")!=null)
    {
        
        document.getElementById("lblCycleActivityDistance").innerHTML="";       
    }
    if(document.getElementById("lblCycleActivityDuration")!=null)
    {
        document.getElementById("lblCycleActivityDuration").innerHTML="";       
    }
    if(document.getElementById("lblCycleActivityPace")!=null)
    {
        document.getElementById("lblCycleActivityPace").innerHTML="";       
    }
    
    
}

function EditWorkType(WorkTypeId,DayId)
{   
    if(document.getElementById('hidWorkTypeValue')!=null)
    {
        document.getElementById('hidWorkTypeValue').value = WorkTypeId; 
        document.getElementById('hidDayValue').value = DayId;
         
     
         ResetPlanPreview();
        
         var btnObj = document.getElementById("btnHiddenEditWorkType");
            if(btnObj != null && btnObj != "")
            {
                    if ((document.all)||(is_Safari > 0))
                    {
                        // IE
                            btnObj.click();
            
                    }
                    else
                    {
                        // FireFox 
            
                        var e = document.createEvent("MouseEvents");
                        e.initEvent("click", true, true);
                        btnObj.dispatchEvent(e);        
                    }
            }  
            
             
            
        ShowModalPopup('divWorkoutPreview','Workout Preview','l');
           
       
        
        document.getElementById("ddlWorkoutType").style.display ="inline"; 
        document.getElementById("ddlDistanceUnits").style.display ="inline"; 
        
        SetVisibleControlForWorkoutType();
        
        ShowCreatePlanDDL();
     
    }
    return(true);
}

function DeleteWorkTypeConfirmation(RecordId,btnId)
{
    document.getElementById("confirmBox_hidButtonId").value=btnId;
    document.getElementById("hidWorkTypeValue").value=RecordId;
    ShowConfirmBox('Do you want to delete the workout?');
    
    ShowCreatePlanDDL();
    return false;
}

function DeleteWorkType(WorkTypeId,DayId)
{
   document.getElementById('hidDayValue').value = DayId;
   DeleteWorkTypeConfirmation(WorkTypeId,'btnHiddenDeleteWorkType');
   
  // var result = confirm('Do you want to delete the workouttype?');
//   if( result == true)
//   {
//   
//     document.getElementById('hidWorkTypeValue').value = WorkTypeId; 
//     document.getElementById('hidDayValue').value = DayId;
//     
//        var btnObj = document.getElementById("btnHiddenDeleteWorkType");
//        if(btnObj != null && btnObj != "")
//        {
//                if ((document.all)||(is_Safari > 0))
//                {
//                    // IE
//                        btnObj.click();
//        
//                }
//                else
//                {
//                    // FireFox 
//        
//                    var e = document.createEvent("MouseEvents");
//                    e.initEvent("click", true, true);
//                    btnObj.dispatchEvent(e);        
//                }
//        }      
//  
//   }
}

function DispWorkTypeDetails(WorkTypeId,DayId)
{   
     document.getElementById('hidWorkTypeValue').value = WorkTypeId; 
     document.getElementById('hidDayValue').value = DayId;  
     
     
     document.getElementById('lblWorloutType').innerHTML="";
     document.getElementById('lblInstructions').innerHTML=""; 
     document.getElementById('lblNotes').innerHTML="";
     document.getElementById('divExcerciseUI').style.display="none";
     document.getElementById('divBrickUI').style.display="none";
     document.getElementById('divWorkoutUI').style.display="none";
     
      
     var btnObj = document.getElementById("btnHiddenEditWorkType");
     
        if(btnObj != null && btnObj != "")
        {
                if ((document.all)||(is_Safari > 0))
                {
                    // IE
                        btnObj.click();
        
                }
                else
                {
                    // FireFox 
        
                    var e = document.createEvent("MouseEvents");
                    e.initEvent("click", true, true);
                    btnObj.dispatchEvent(e);        
                }
        }          
         
   
  // ShowModalPopup('divWorkoutPreview','Workout Details','c');
   return(true);
}

function DispWorkTypeDetailsForTemplate(WorkTypeId,DayId)
{   
     document.getElementById('ctl00_ContentPlaceHolder1_hidWorkTypeValue').value = WorkTypeId; 
     document.getElementById('ctl00_ContentPlaceHolder1_hidDayValue').value = DayId;  
     
     
     document.getElementById('ctl00_ContentPlaceHolder1_lblWorloutType').innerHTML="";
     document.getElementById('ctl00_ContentPlaceHolder1_lblInstructions').innerHTML=""; 
     //document.getElementById('ctl00_ContentPlaceHolder1_lblNotes').innerHTML="";
     document.getElementById('ctl00_ContentPlaceHolder1_divExcerciseUI').style.display="none";
     document.getElementById('ctl00_ContentPlaceHolder1_divBrickUI').style.display="none";
     document.getElementById('divWorkoutUI').style.display="none";
     
      
     var btnObj = document.getElementById("ctl00_ContentPlaceHolder1_btnHiddenEditWorkType");
     
        if(btnObj != null && btnObj != "")
        {
                if ((document.all)||(is_Safari > 0))
                {
                    // IE
                        btnObj.click();
        
                }
                else
                {
                    // FireFox 
        
                    var e = document.createEvent("MouseEvents");
                    e.initEvent("click", true, true);
                    btnObj.dispatchEvent(e);        
                }
        }          
         
   ShowWebsiteModalPopup('divWorkoutPreview','Workout Details','m');
   return(true);
}
function ImportWorkout()
{
   document.getElementById('dwindowimportworkouttype').style.display ="block"; 
   document.getElementById('pnlplanPreview').style.display ="none"; 
   return false;
}

function CancelImport()
{
      document.getElementById('dwindowimportworkouttype').style.display ="none"; 
     document.getElementById('pnlplanPreview').style.display ="block"; 
     return(false);
}

function CloseImport()
{
     document.getElementById('dwindowimportworkouttype').style.display ="none";
     //CheckPassword(); 
     return(true);
}

function ValidateWorkTypePreview()
{   
     document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="none";
      document.getElementById("WarningMsgs3_divWarningInfo").style.display = "none";
     
     var tempWorkoutType = document.getElementById("ddlWorkoutType").value;
    
     if(tempWorkoutType=="0")
     {
        if(document.getElementById("txtOtherWorkoutType")!=null)
        {
            if(document.getElementById("txtOtherWorkoutType").value =="")
            {
                document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="block";
              document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";
                 document.getElementById('WarningMsgs3_RegistrationErrors').innerHTML="Please enter all the mandatory fields.";
               document.getElementById("txtOtherWorkoutType").focus();
                return(false);
            }
        }
     }
    
   //If workoutype is not weight training
     if((tempWorkoutType!="7")&&(tempWorkoutType!="8"))
     {
        if (!ValidateDistance())
        {
	       return(false);   
	    } 
	 }
	  
	 
	  
	 if((tempWorkoutType!="8")&&(tempWorkoutType!="7"))
	 { 
	    var _hr = document.getElementById("txtHrDuration").value;
	     var _min = document.getElementById("txtMinDuration").value;
	     var _sec = document.getElementById("txtSecDuration").value;
	     if(_hr=="" && _min=="" && _sec=="")
	     {
	        document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="block";
            document.getElementById('WarningMsgs3_RegistrationErrors').innerHTML = "Enter Duration" ;
            document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";
            document.getElementById("txtHrDuration").focus();
            return false;
	     }
	     else if((_hr=="0" || _hr=="00" || _hr=="000" || _hr=="0000" || _hr=="00000" || _hr=="" ) && ( _min=="0" || _min=="00" || _min=="") && ( _sec=="0" || _sec=="00" || _sec==""))
	     {
	        document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="block";
            document.getElementById('WarningMsgs3_RegistrationErrors').innerHTML = "Duration should be greater than 0." ;
            document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";
            document.getElementById("txtHrDuration").focus();
            return false;
	     }
        // if(!ValidateDuration())
        //	    return(false); 	  
			
	    if(!ValidateHrDuration())
	    {
	       return(false);
	    }
	    
	    if(!ValidateMinDuration())
	    {
	       return(false);
	    }
	    
	    if(!ValidateSecDuration())
	    {
	       return(false);  
	    }
	    if(document.getElementById('txtWorkoutInstructions').value.length > 5000)
	    {
	        document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="block";
            document.getElementById('WarningMsgs3_RegistrationErrors').innerHTML = "Instructions should be less than 5000 characters." ;
            document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";
            document.getElementById("txtWorkoutInstructions").focus();
            return false;
	    }
	    document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="none";
        document.getElementById('WarningMsgs3_RegistrationErrors').innerHTML = "" ;
        document.getElementById("WarningMsgs3_divWarningInfo").style.display = "none";
        document.getElementById("txtHrDuration").focus();
        return true;
	}
	
	//If workoutype is not weight training
//     if((tempWorkoutType!="7")&&(tempWorkoutType!="8"))
//     {
//        if(!ValidatePace())
//	    return(false); 	   
//	 }
    
        
    var WorkTypeValue = document.getElementById('hidWorkTypeValue').value ;
   
    var objdivDay =  document.getElementById('divDay'); 
    //alert(divDay.innerHTML);
   // divDay.innerHTML = WorkTypeValue;
}

function ValidateDistance()
{
    	
         var Name ="Distance"  ; 
		 var Value = document.getElementById('txtDistance').value ;
		 
		 if(Value == "")
		 {
		    document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="block";
            document.getElementById('WarningMsgs3_RegistrationErrors').innerHTML = "Enter "+ Name;
            document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";
            document.getElementById('txtDistance').focus();
            return false;
		 }
		 if(Value=="0" || Value=="00" || Value=="000" || Value=="0000")
		 {
		    document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="block";
            document.getElementById('WarningMsgs3_RegistrationErrors').innerHTML = Name+" should be greater than 0.";
            document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";
            document.getElementById('txtDistance').focus();
            return false;
		 }
		
//		if(!( ValidateWorkoutMandatory(Name,Value) &&  ValidateWorkoutLength(Name,Value,4)  && ValidateWorkoutRealFormat(Name,Value)) )
//		{
//			document.getElementById('txtDistance').setfocus;
//			return(false);
//			
//		}

		if(!(ValidateWorkoutLength(Name,Value,4)&& ValidateWorkoutRealFormat(Name,Value)))
		{
			document.getElementById('txtDistance').focus();
			return(false);
			
		}
		return(true);	
}

function ValidateHrDuration()
{
    	
         var Name ="Hour Duration"  ;
         var Value; 
         
       if(document.getElementById('txtHrDuration').value =="")
       {
           Value = 0;
       }
       else
       {            
		     Value = document.getElementById('txtHrDuration').value ;
	   }
	
		
		if(!(  ValidateWorkoutLength(Name,Value,4)  && ValidateWorkoutNumericFormat(Name,Value)) )
		{
			document.getElementById('txtHrDuration').focus();
			return(false);
			
		}
		return(true);	
}

function ValidateMinDuration()
{
    	
         var Name ="Minute Duration"  ; 
		 var Value;
		 if(document.getElementById('txtMinDuration').value =="")
		 {
		    Value =0;
		 }
		 else
		 {
		    Value = document.getElementById('txtMinDuration').value ;
		 }	
	
		
		if(!(  ValidateWorkoutLength(Name,Value,4)  && ValidateWorkoutNumericFormat(Name,Value)) )
		{
			document.getElementById('txtMinDuration').focus();
			return(false);
			
		}
		else if(ValidateWorkoutNumericFormat(Name,Value))
		{
		        if(Value > 59)
		        {
		            document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="block";
                    document.getElementById('WarningMsgs3_RegistrationErrors').innerHTML = Name + " should be less than 60.";
                     document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";
		            document.getElementById('txtMinDuration').focus();
			        return(false);
		        }
		}
		
		return(true);	
}

function ValidateSecDuration()
{
    	
         var Name =  "Sec Duration"  ;
		 var Value;
		 if(document.getElementById('txtSecDuration').value == "")
		 {
		    Value = 0;		 
		 }
		 else
		 {
		    Value = document.getElementById('txtSecDuration').value;
		 }
	
		
		if(!(   ValidateWorkoutLength(Name,Value,4)  && ValidateWorkoutNumericFormat(Name,Value)) )
		{
			document.getElementById('txtSecDuration').focus();
			return(false);
			
		}
		else if(ValidateWorkoutNumericFormat(Name,Value))
		{
		        if(Value > 59)
		        {
		            document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="block";
                    document.getElementById('WarningMsgs3_RegistrationErrors').innerHTML = Name + " should be less than 60.";
                     document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";
		            document.getElementById('txtSecDuration').focus();
			        return(false);
		        }
		}
		return(true);	
}  

function ValidateDuration()
{    	
       
		var HrValue =document.getElementById('txtHrDuration').value;
		var MinVale =  document.getElementById('txtMinDuration').value ;
		var SecValue = document.getElementById('txtSecDuration').value ;
		 
		 if( (HrValue =="" || HrValue =="0") && (MinVale =="" || MinVale =="0") && (SecValue =="" || SecValue =="0") )
		 {
		    //alert("Duration can not be Empty");
		    document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="block";
		    document.getElementById('WarningMsgs3_RegistrationErrors').innerHTML = "Duration cannot be empty.";
		    document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";
		
		    return(false);
		 }
		 
		 return(true);	
}

function ValidatePace()
{
    	
         var Name =  "Pace"  ;
		 var Value =  document.getElementById('txtPace').value ;
        		
		if(!(ValidateWorkoutLength(Name,Value,8)))
		{
			document.getElementById('txtPace').focus();
			return(false);
			
		}
		return(true);	
}   


//Function To Validate Mandatory Value
function ValidateWorkoutMandatory(vFldName, vFieldVal)
{
	if(vFieldVal == '')
	{
		//alert(vFldName + ' cannot be empty.');
		 document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="block";
		 document.getElementById('WarningMsgs3_RegistrationErrors').innerHTML = vFldName + " cannot be empty.";
		 document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";
		
		return(false);
	}
	else
	{
		return(true);
    }
	
}

//Function To Validate Length of Field
function ValidateWorkoutLength(vFldName, vFieldVal,vFieldSize)
{
	if(vFieldVal.length > vFieldSize )
	{
		//alert(vFldName + ' cannot exceed than '+ vFieldSize );
		
		 document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="block";
         document.getElementById('WarningMsgs3_RegistrationErrors').innerHTML = vFldName + " cannot contain more than " + vFieldSize + " digits" ;
          document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";
           
		return(false);
	}
	else
	{
		return(true);	
    }
}

//Function To Validate Numeric Value
function ValidateWorkoutNumericFormat(vFldName,vFieldVal)
{
   var sNumericExp = "^[\\s]*[0-9]+[\\s]*$";   
   
    //if(isNaN(vFieldVal) == true)
    if(vFieldVal == 0)
    {
     	return(true);
    }
    else if(vFieldVal.match(sNumericExp)==null)
	{
			//alert(vFldName + ' is in invalid format. Please try again.');
			
		    document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="block";
            document.getElementById('WarningMsgs3_RegistrationErrors').innerHTML = vFldName + " is in invalid format.";
             document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";
			return(false);	
			
	}	 
    else
    {
       return(true);  
    }
}

function ValidateWorkoutRealFormat(vFldName,vFieldVal)
{
    var objRegExp  = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
   // var objRegExp = "^(([0-9])+([\.]([0-9][0-9]))?)$";
    
    //^\$[0-9]+(\.[0-9][0-9])?$
   
    if(vFieldVal == 0)
    {
     	return(true);
    }
    else if(vFieldVal.match(objRegExp)==null)
	{
			//alert(vFldName + ' is in invalid format. Please try again.');		
			document.getElementById('WarningMsgs3_RegistrationErrors').style.display ="block";
            document.getElementById('WarningMsgs3_RegistrationErrors').innerHTML = vFldName + " is in invalid format.";	
             document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";
			return(false);	
	}
    else
    {
        return(true);  
    }
}



function ValidateInstructions()
{
    	
         var Name =  "Workout Instructions"  ;
		 var Value = document.getElementById('txtWorkoutInstructions').value ;
	
		
		if(!( ValidateMandatory(Name,Value)  ) )
		{
			document.getElementById('txtWorkoutInstructions').focus();
			return(false);
			
		}
		return(true);	
}    


function ValidateNotes()
{
    	
         var Name =  "Notes"  ;
		 var Value = document.getElementById('txtNotes').value ;
	
		
		if(!( ValidateMandatory(Name,Value) ) )
		{
			document.getElementById('txtNotes').focus();
			return(false);
			
		}
		return(true);	
}   

function ExcerciseTypeChange()
{
     var excercise = document.getElementById("ddlExcerciseType").value;
    
     if(excercise=="Other")
     {	
        if(document.getElementById("divlblOtherExcercise")!=null)
        {  
             document.getElementById("divlblOtherExcercise").style.display="block";
        }
        
        if(document.getElementById("divtxtOtherExcercise")!=null)
        {  
            document.getElementById("divtxtOtherExcercise").style.display="block";
        }
     }
     else
     {
        
        if(document.getElementById("divlblOtherExcercise")!=null)
        {  
             document.getElementById("divlblOtherExcercise").style.display="none";
        }
        
        if(document.getElementById("divtxtOtherExcercise")!=null)
        {  
            document.getElementById("divtxtOtherExcercise").style.display="none";
        }
     }
}

function GridExcerciseTypeChange()
{
    
    var txtExcerciseType=document.getElementById("hidGridExcerciseType").value;
    
    SetVisibleControlForExcercise();
    
}

function SetVisibleControlForExcercise()
{
    
     var txtExcerciseType=document.getElementById("hidGridExcerciseType").value;
     
     var lblOtherExcercise=document.getElementById("hidGridlblOtherExcercise").value;
    
     var txtOtherExcercise=document.getElementById("hidGridtxtOtherExcercise").value;
    
    if(document.getElementById(txtExcerciseType).value=="Other")
    {	
        document.getElementById(lblOtherExcercise).style.display="block";
        //document.getElementById(txtOtherExcercise).value="";
        document.getElementById(txtOtherExcercise).style.display="block";
       
    }
    else
    {
        document.getElementById(lblOtherExcercise).style.display="none";
        document.getElementById(txtOtherExcercise).style.display="none";
    }
   
}

 
function loadUPEventHandler()
{

    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(UPEndRequestHandler);
    //prm.add_beginRequest(BeginRequestHandler);
}

function UPEndRequestHandler(sender, args) 
{
//    if (args.get_error() == undefined)
//        alert("updated successfully!!");
//    else
//        alert("There was an error" + args.get_error().message);
    var err = args.get_error();
    if (err)
    {
      if (err.name == "Sys.WebForms.PageRequestManagerServerErrorException")
       {
             args.set_errorHandled(true);
        }
        if (err.name == "Sys.WebForms.PageRequestManagerParserErrorException") 
              {
                e.set_errorHandled(true);
              }
    }
    var UserMessage = null;
    var EditMessage = null;
    UserMessage = document.getElementById("hidUserMessage"); 
 //   alert("end req");
    
  // alert(UserMessage.value);
    if(UserMessage != null && UserMessage != "")
    {
       var UserMessageVal = UserMessage.value;
    }
    switch(UserMessageVal)
    {
    
         
       case "WorkoutDDLChanged":
              UserMessage.value = "";
              CalculatePaceValue();
              SetVisibleControlForWorkoutType();
              break;
              
        case "PlanBackSuccess":
            UserMessage.value = "";
         
            CheckPassword();
            ShowFixedDuration();
            ShowOtherActivity();
           break; 
    
        case "ddlSportsChanged":
            UserMessage.value = ""; 
            ShowFixedDuration();
            ShowOtherActivity();
             break;  
        
        case "AddTermSuccessful": 
            UserMessage.value = "";  
            closepopup('pnlAddTerm');
            //alert("Congratulations! Term saved successfully");
            var msg="Term saved successfully";
            ShowMessageBox(msg); 
            break;  
           
       case "TermAlreadyExist": 
            UserMessage.value = "";  
            
            //alert("Congratulations! Term saved successfully");
            ShowInformationMessageBox("Term already exists.");
            break;  
            
        case "DeleteExcerciseSuccess":
                UserMessage.value = "";
                if(document.getElementById("divlblOtherExcercise")!=null)
                {  
                     document.getElementById("divlblOtherExcercise").style.display="none";
                }  
                if(document.getElementById("divtxtOtherExcercise")!=null)
                {  
                    document.getElementById("divtxtOtherExcercise").style.display="none";
                }
        
                break;
        
        case "ExcerciseEditSaved":
                UserMessage.value = "";
                if(document.getElementById("divlblOtherExcercise")!=null)
                {  
                     document.getElementById("divlblOtherExcercise").style.display="none";
                }  
                if(document.getElementById("divtxtOtherExcercise")!=null)
                {  
                    document.getElementById("divtxtOtherExcercise").style.display="none";
                }
        
                break;
                
        case "AddExcerciseSuccess":
                UserMessage.value = "";
                if(document.getElementById("divlblOtherExcercise")!=null)
                {  
                     document.getElementById("divlblOtherExcercise").style.display="none";
                }  
                if(document.getElementById("divtxtOtherExcercise")!=null)
                {  
                    document.getElementById("divtxtOtherExcercise").style.display="none";
                }
        
                break;
        
        case "ExcerciseEdited":
            UserMessage.value = "";
            SetVisibleControlForExcercise();
            break;
    
        case "ShowAddWorkout":
                UserMessage.value = "";
                document.getElementById("lblCharactersLeft1").innerHTML = "500"; 
				if(document.getElementById("divlblOtherExcercise")!=null)
	            { 
		            document.getElementById("divlblOtherExcercise").style.display="none";
	            }
	
	            if(document.getElementById("divtxtOtherExcercise")!=null)
	            { 
		            document.getElementById("divtxtOtherExcercise").style.display="none";
	            }
	            
             break;
             
         case "ActivityEdited":
            UserMessage.value = "";
            SetVisibleControlForActivity();
             UserMessage.value = "";
            break;
            
        case "WorkoutAddedSuccessfully":
            closepopup();
            
            var msg = "Workout added successfully.";
               
            ShowMessageBox(msg);
             UserMessage.value = "";
            //alert("Workout is saved successfully.");
               break;
               
       case "WorkoutUpdateSuccessfully":
            closepopup();
            
            var msg = "Workout updated successfully.";
               
            ShowMessageBox(msg);
             UserMessage.value = "";
            //alert("Workout is saved successfully.");
               break;
               
        case "ErrorAddWorkout":
            alert("Error occurred while adding the Workout. Please try again.");
             UserMessage.value = "";
            break;
            
        case "EditWorkoutSuccessfully":
         
            ShowModalPopup('divWorkoutPreview','Workout Preview','l');  
            
            if(document.getElementById("divlblOtherExcercise")!=null)
            {  
                document.getElementById("divlblOtherExcercise").style.display="none";
            }
        
            if(document.getElementById("divtxtOtherExcercise")!=null)
            {  
                document.getElementById("divtxtOtherExcercise").style.display="none";
            }
            
            SetVisibleControlForWorkoutType();
             
            document.getElementById("ddlWorkoutType").style.display ="inline"; 
            document.getElementById("ddlDistanceUnits").style.display ="inline"; 
            if(document.getElementById("ddlActivityName")!=null)
            {  
                document.getElementById("ddlActivityName").style.display ="inline";
            }  
            document.getElementById("ddlExcerciseType").style.display ="inline";    
            document.getElementById("ddlActivityUnit").style.display ="inline"; 
            
            CalculatePaceValue();   
            UserMessage.value = "";      
            break;
             //closepopup();
            
        case "ErrorEditWorkout":
            alert("Error occurred while editing the Workout. Please try again.");
             UserMessage.value = "";
            break;
            
        case "PlanSubscribeAddedSuccessfully":
                closepopup('divSubscribe');
                var msg="Congratulations! Plan enrolled successfully";
                document.getElementById("messageBox_hidButtonId").value = "EnrollSuccess";
                ShowMessageBox(msg);
                break;
        case "PlanSubscribeAddedSharedWithFB":              
              closepopup('divSubscribe');
              var msg="Congratulations! Plan enrolled successfully";
              ShowMessageBox(msg);
              ShowFBText();
              CallFBRequireFeatures();
              ShowFBPublish(); 
              break;       
        case "OpenTwitterWindow":
            closepopup('divSubscribe');
              var msg="Plan enrolled successfully.";
              ShowMessageBox(msg);
            if(document.getElementById("hidRequestToken").value != "")
            {
                window.open("http://twitter.com/oauth/authorize?oauth_token=" + document.getElementById("hidRequestToken").value,"_new","height=500,width=850,status=yes,resizable=yes");
            }
            document.getElementById("hidRequestToken").value = "";
            break;
           
        case "PlanSubscribeAddedSuccessfullyTwitted":
            closepopup('divSubscribe');
             //alert("Plan subscription is successful.");
             
              var msg="Plan enrolled successfully and shared with twitter.";
      
              ShowMessageBox(msg);
               break;
        case "PlanUnsubscribeDone":
              var msg="Enrollment successfully withdrawn.";
      
              ShowMessageBox(msg);
               UserMessage.value = "";
               break;
        
        case "ErrorPlanSubscribe":
            alert("Error occurred while adding the Workout. Please try again.");
             UserMessage.value = "";
            break;
            
        case "DispWorkoutSuccessfully":
             document.getElementById("divWorkoutUI").style.display="none";
             document.getElementById("divBrickUI").style.display="none";
             document.getElementById("divExcerciseUI").style.display="none";
              
             if(document.getElementById("lblWorloutType").innerHTML=="Brick")
             {
                 document.getElementById("divBrickUI").style.display="block";
             }
             else
             if(document.getElementById("lblWorloutType").innerHTML=="Weight Training")
             {
                 document.getElementById("divExcerciseUI").style.display="block";
             }
             else
             {
                 document.getElementById("divWorkoutUI").style.display="block";
             }
             
             ShowModalPopup('divWorkoutPreview','Workout Details','l');
              UserMessage.value = "";
           
             
             break;
             
             case "DispWorkoutSuccessfully3" :
       
             document.getElementById("divWorkoutUI").style.display="none";
             document.getElementById("divBrickUI").style.display="none";
             document.getElementById("divExcerciseUI").style.display="none";
              
             if(document.getElementById("lblWorloutType").innerHTML=="Brick")
             {
                 document.getElementById("divBrickUI").style.display="block";
             }
             else
             if(document.getElementById("lblWorloutType").innerHTML=="Weight Training")
             {
                 document.getElementById("divExcerciseUI").style.display="block";
             }
             else
             {
                 document.getElementById("divWorkoutUI").style.display="block";
             }
             ShowModalPopup('divWorkoutPreview','Workout Details','c');
              UserMessage.value = "";
           
             
             break;
             
             case "DispWorkoutSuccessfully1" :
       
             document.getElementById("divWorkoutUI").style.display="none";
             document.getElementById("divBrickUI").style.display="none";
             document.getElementById("divExcerciseUI").style.display="none";
              
             if(document.getElementById("lblWorloutType").innerHTML=="Brick")
             {
                 document.getElementById("divBrickUI").style.display="block";
             }
             else
             if(document.getElementById("lblWorloutType").innerHTML=="Weight Training")
             {
                 document.getElementById("divExcerciseUI").style.display="block";
             }
             else
             {
                 document.getElementById("divWorkoutUI").style.display="block";
             }
             ShowModalPopup('divWorkoutPreview','Workout Details','');
              UserMessage.value = "";
           
             
             break;
        
        case "ErrorDispWorkout":
             alert("Error occurred while editing the New Workout. Please try again.");
              UserMessage.value = "";
             break;   
             
        case "CoachSubscribeAddedSuccessfully":
             closepopup('divCoachSubscribe');
             //alert("Coach subscription is successful.");
             //var msg="Coach subscription is successful.";
             // Changed the message as per bug id - 396 from bugzilla
             var msg="You request has been sent to the coach for approval";
             ShowMessageBox(msg);  
             UserMessage.value = "";
                  var ddlSport = document.getElementById("ddlSport");
    	         if(ddlSport != null)
    	         {
    	            ddlSport.style.display = '';
    	         }
              break;
              
        case "CoachUnSubscribeAddedSuccessfully":
             var msg="Now you are not following this coach.";
             ShowMessageBox(msg);  
             UserMessage.value = "";
              var ddlSport = document.getElementById("ddlSport");
    	         if(ddlSport != null)
    	         {
    	            ddlSport.style.display = '';
    	         }
              break;
        case "ErrorCoachUnSubscribe":
             alert("Error occurred while following the coach. Please try again.");
             UserMessage.value = "";
             
             break;   
              
              
        case "ErrorCoachSubscribe":
             alert("Error occurred while not following for this coach. Please try again.");
             UserMessage.value = "";
             break;   
             
       case "PlanAcceptSuccessfully":            
             closepopup();
             //alert("Plan is successfully accepted.");
             var msg="Congratulations! Plan has been successfully accepted.";
//             ShowMessageBox(msg);   
             UserMessage.value = ""; 
             break;   
             
       case "TrainingPlanExpired":
            ShowInformationMessageBox("Training plan has expired.");
            UserMessage.value = ""; 
             break;  
             
       case "ErrorPlanAccept":
             alert("Error occurred while Plan Enrollment. Please try again.");
             UserMessage.value = "";
             break;  
             
       case "UserSubscribeSuccessfully":
             closepopup();
             //alert("User subscription is successful.");
             var msg="User enrollment is successful.";
//             ShowMessageBox(msg);   
             UserMessage.value = ""; 
             break;   
             
       case "ErrorUserSubscribe":
             alert("Error occurred while Plan Enrollment. Please try again.");
             UserMessage.value = "";
             break;
             
       case "CoachAlreadySubscribe":
              closepopup();
            // alert("You have already subscribe for this coach.");
              var msg="You are already following this coach.";
             ShowInformationMessageBox(msg);  
             UserMessage.value = "";
             break;
             
       case "PlanAlreadySubscribe": 
             closepopup();           
             //alert("You have already subscribe for this Plan.");
              var msg="You have already enrolled for this Plan.";
             ShowInformationMessageBox(msg);  
             UserMessage.value = "";
             break;
             
       case "CoachSubscribehisPlan":
            closepopup();             
             //alert("You have tried to subscribe your own plan.");
              var msg="You have tried to enroll your own plan.";
             ShowInformationMessageBox(msg);  
             UserMessage.value = "";
             break;             
             
             
       case "EditThresholdDetailsSuccessfully":
             ShowModalPopup('divSubscriptionLimit','Coach Subscription Threshold');   
             UserMessage.value = "";                    
             break;
             
       case "EditThresholdError":
            closepopup();             
             alert("Error occurred while editing Threshold details. Please try again.");
             UserMessage.value = "";
             break;
             
       case "ThresholdUpdatedSuccessfully":
            closepopup();             
             //alert("Threshold subscription details are updated successfully.");
             var msg="Threshold enrollment details are updated successfully.";
             ShowMessageBox(msg);  
             UserMessage.value = "";       
             break;
              
       case "ErrorThresholdUpdate":
            closepopup();             
             alert("Error occurred while updating the Threshold Limit. Please try again."); 
             UserMessage.value = "";
              break;           
              
       case "LessThresholdLimit":
            closepopup();             
             //alert("Threshold limit is less than actual value."); 
             var msg="Threshold limit is less than actual value.";
             ShowInformationMessageBox(msg);   
             UserMessage.value = "";
              break;   
             
       case "ExceedThresholdLimit":
            closepopup();             
            ShowInformationMessageBox("Exceed than threshold limit.");  
            UserMessage.value = "";
              break;   
              
       case "ValidatePassword":
            closepopup('divCheckPassword');
//            document.getElementById('btnSubmit').style.display = "block";
//            document.getElementById('btnCancel').style.display = "block";
            ShowModalPopup('divSubscribe','Enroll for Training Plan','m');  
            UserMessage.value = "";
            break; 
            
       case "IncorrectPassword":
            
            DisplayMessage();
            UserMessage.value = "";
            break;
       
       case "CheckPassword":
            DisplayPasswordMessage();   
            UserMessage.value = "";  
            break;
            
       case "DisplayPassword":   
            CheckPassword();
            UserMessage.value = "";
            break; 
       
       case "CheckUserSubscription":
            UserMessage.value = "";
            if (document.getElementById("hidSubscriptionMsg").value == "TRUE")
            {
               
                ShowInformationMessageBox("You have already enrolled for this training plan.");
                 var ddlSport  = document.getElementById("ddlSport");
                 if(ddlSport != null)
                   {
                    ddlSport.style.display = "";
                   }
                return;
            }
            else
            {
//                document.getElementById('btnSubmit').style.display = "block";
//                document.getElementById('btnCancel').style.display = "block";
                ShowModalPopup('divSubscribe','Enroll for Training Plan','m');
            }
            break;          
       
      case "CheckEnrollThresholdLimit":
            UserMessage.value = "";
            if (document.getElementById("hidSubscriptionMsg").value == "TRUE")
            {
               
                ShowInformationMessageBox("Enrollment limit exceeded for this training plan.");
                 var ddlSport  = document.getElementById("ddlSport");
                 if(ddlSport != null)
                   {
                    ddlSport.style.display = "";
                   }
                return;
            }
            else
            {
//                document.getElementById('btnSubmit').style.display = "block";
//                document.getElementById('btnCancel').style.display = "block";
                ShowModalPopup('divSubscribe','Enroll for Training Plan','m');
            }
            break;       
                  
       case "PlanSaveSuccess":
             UserMessage.value = "";
             var msg="Your plan has been successfully created.";
             ShowMessageBox(msg);
             break;
      case "CopyWorkoutSuccess":
             closepopup('divCopyWorkout');
             UserMessage.value = "";
             
             var msg;
             var myString = document.getElementById("hidWorkoutCategoryId").value;
            
             var mySplitResult = myString.split(",");
             if(mySplitResult.length > 1)
             {   
                msg="Workouts have been copied successfully.";
             }
             else
             {
                msg="Workout has been copied successfully.";
             }
             document.getElementById("hidWorkoutCategoryId").value = '';
             ShowMessageBox(msg);
             break;
             
      case "MoveWorkoutSuccess":
             closepopup('divCopyWorkout');
             UserMessage.value = "";
             var msg;
             var myString = document.getElementById("hidWorkoutCategoryId").value;
            
             var mySplitResult = myString.split(",");
             if(mySplitResult.length > 1)
             {   
                msg="Workouts have been moved successfully.";
             }
             else
             {
                msg="Workout has been moved successfully.";
             }
             document.getElementById("hidWorkoutCategoryId").value = '';
             ShowMessageBox(msg);
             break;
      case "UploadLogoSuccess":
             closepopup('divUploadLogo');
             UserMessage.value = "";
             var msg="Training Plan Logo has been uploaded successfully.";
             ShowMessageBox(msg);
             ShowCreatePlanDDL();
             break; 
             
       case "FriendsEmailSent": 
            UserMessage.value = "";  
            closepopup('divTellAFriend');
            //alert("Congratulations! Term saved successfully");
            var msg="Plan details have been sent successfully to your friend(s).";
            ShowMessageBox(msg); 
            break;    
       case "PlanRemovedSuccess" :
            UserMessage.value = "";  
            ShowMessageBox("Enrollment successfully withdrawn.");
       break;
       
       case "PlanRemovedUnsuccess" :
            UserMessage.value = "";  
            ShowInformationMessageBox("Error occured while leaving training plan. Please try again later.");
       break;
       case "ShowTellAFriend" :
            if(document.getElementById("divTellAFriend")!=null)
            {
                document.getElementById("divTellAFriend").style.display="";
            }
            ShowModalPopup('divTellAFriend','Tell A Friend','m');
       break;
             
        default:
            return;
         
    }
    ShowCreatePlanDDL();
     var ddlSport = document.getElementById("ddlSport");
    	         if(ddlSport != null)
    	         {
    	            ddlSport.style.display = '';
    	         }
    
    //UserMessage.value = "";
    
}


function SetVisibleControlForWorkoutType()
{
     
    var sport = document.getElementById("ddlWorkoutType").value;
    var e = document.getElementById("ddlDistanceUnits"); 
    var unitType = e.options[e.selectedIndex].text;  

    
    if(sport=="7")
    {
       var arrobj;
       
	   if(document.getElementById("divlblDistance")!=null)
       {
           arrobj=document.getElementById("divlblDistance");
           arrobj.style.display = "none";   
       }
       
       if(document.getElementById("divtxtDistance")!=null)
       {
           arrobj=document.getElementById("divtxtDistance");
           arrobj.style.display = "none";   
       }
       
       if(document.getElementById("divlblPace")!=null)
       {
           arrobj=document.getElementById("divlblPace");
           arrobj.style.display = "none";   
       }      
         
       if(document.getElementById("divtxtPace")!=null)
       {
           arrobj=document.getElementById("divtxtPace");
           arrobj.style.display = "none";   
       }
       
       if(document.getElementById("divlblOtherWorkoutType")!=null)
       {
           arrobj=document.getElementById("divlblOtherWorkoutType");
           arrobj.style.display = "none";   
       }
     
       if(document.getElementById("divtxtOtherWorkoutType")!=null)
       {
           arrobj=document.getElementById("divtxtOtherWorkoutType");
           arrobj.style.display = "none";   
       }     
       
		
        if(document.getElementById("divBrickUI")!=null)
        {
           document.getElementById("divBrickUI").style.display="none";
        }
        
        if(document.getElementById("divExcerciseUI")!=null)
		{
			arrobj=document.getElementById("divExcerciseUI");
			arrobj.style.display = "block";   
		}  
		
        if(document.getElementById("divWorkoutUI")!=null)
        {
           document.getElementById("divWorkoutUI").style.display="none";
        } 
    }
    else
    if(sport=="8")
    {   
		
         if(document.getElementById("divBrickUI")!=null)
         {
            document.getElementById("divBrickUI").style.display="block";
         }
         
        if(document.getElementById("divExcerciseUI")!=null)
		{
			arrobj=document.getElementById("divExcerciseUI");
			arrobj.style.display = "none";   
		}  
		
         if(document.getElementById("divWorkoutUI")!=null)
         {
            document.getElementById("divWorkoutUI").style.display="none";
         }
         
      
         
        if(document.getElementById("divlblOtherWorkoutType")!=null)
        {
           arrobj=document.getElementById("divlblOtherWorkoutType");
           arrobj.style.display = "none";   
        }
     
        if(document.getElementById("divtxtOtherWorkoutType")!=null)
        {
           arrobj=document.getElementById("divtxtOtherWorkoutType");
           arrobj.style.display = "none";   
        }     
    
    }
    else
    if(sport=="0")
    {       
       var arrobj;
       
       if(document.getElementById("divlblDistance")!=null)
       {
           arrobj=document.getElementById("divlblDistance");
           arrobj.style.display = "block";   
       }
       
       if(document.getElementById("divtxtDistance")!=null)
       {
           arrobj=document.getElementById("divtxtDistance");
           arrobj.style.display = "block";   
       }
       
       if(document.getElementById("divlblPace")!=null)
       {
           arrobj=document.getElementById("divlblPace");
           arrobj.style.display = "block";   
       }      
         
       if(document.getElementById("divtxtPace")!=null)
       {
           arrobj=document.getElementById("divtxtPace");
           arrobj.style.display = "block";   
       }
       
	   if(document.getElementById("divlblOtherWorkoutType")!=null)
       {
           arrobj=document.getElementById("divlblOtherWorkoutType");
           arrobj.style.display = "block";   
       }
     
       if(document.getElementById("divtxtOtherWorkoutType")!=null)
       {
           arrobj=document.getElementById("divtxtOtherWorkoutType");
           if(document.getElementById("hidUserMessage").value != "EditWorkoutSuccessfully")
           {
                document.getElementById("txtOtherWorkoutType").value="";
             }
           arrobj.style.display = "block";   
       }      
       

		
       if(document.getElementById("divBrickUI")!=null)
       {
           document.getElementById("divBrickUI").style.display="none";
       }
       if(document.getElementById("divWorkoutUI")!=null)
       {
           document.getElementById("divWorkoutUI").style.display="block";
       } 
       
       if(document.getElementById("divExcerciseUI")!=null)
	   {
			arrobj=document.getElementById("divExcerciseUI");
			arrobj.style.display = "none";   
	   }  
    }
    else
    {  
       var arrobj;
       
       if(document.getElementById("divlblDistance")!=null)
       {
           arrobj=document.getElementById("divlblDistance");
           arrobj.style.display = "block";   
       }
       
       if(document.getElementById("divtxtDistance")!=null)
       {
           arrobj=document.getElementById("divtxtDistance");
           arrobj.style.display = "block";   
       }
       
       if(document.getElementById("divlblPace")!=null)
       {
           arrobj=document.getElementById("divlblPace");
           arrobj.style.display = "block";   
       }      
         
       if(document.getElementById("divtxtPace")!=null)
       {
           arrobj=document.getElementById("divtxtPace");
           arrobj.style.display = "block";   
       }
       
       
       if(document.getElementById("divlblOtherWorkoutType")!=null)
       {
           arrobj=document.getElementById("divlblOtherWorkoutType");
           arrobj.style.display = "none";   
       }
     
       if(document.getElementById("divtxtOtherWorkoutType")!=null)
       {
           arrobj=document.getElementById("divtxtOtherWorkoutType");
           arrobj.style.display = "none";   
       }   
       
  
		
       if(document.getElementById("divBrickUI")!=null)
       {
           document.getElementById("divBrickUI").style.display="none";
       }
       if(document.getElementById("divWorkoutUI")!=null)
       {
           document.getElementById("divWorkoutUI").style.display="block";
       } 
        
       if(document.getElementById("divExcerciseUI")!=null)
	   {
			arrobj=document.getElementById("divExcerciseUI");
			arrobj.style.display = "none";   
	   }  
    }
    
}

function CheckPassword()
{ 
    var Status = document.getElementById("chkIsPasswordProtected");    
 
    if(Status!=null)
    {    
        if(Status.checked==true)    
        {       
         
            document.getElementById('divProtectPassword').style.display ="block";                   
        }
        else
        {      
            document.getElementById('divProtectPassword').style.display ="none";       
        }
    }
}

function DisplayMessage()
{
   
    var valMessage = document.getElementById("lblPlanName");         
    valMessage.innerHTML = document.getElementById('hidPlanName').value;
     document.getElementById('divProtectPassword').style.display = "block";
     
    
     document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
     document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = "Password is incorrect.";
         document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
    
     
}

function DisplayPasswordMessage()
{
   
    var valMessage = document.getElementById("lblTrPlanName");         
    valMessage.innerHTML = document.getElementById('hidPlanName').value;
     document.getElementById('divProtectPassword').style.display = "block";
     //lblTrPlanName
    
     document.getElementById('WarningMsgs_RegistrationErrors').style.display ="block";
     document.getElementById('WarningMsgs_RegistrationErrors').innerHTML = "Password is incorrect.";
         document.getElementById("WarningMsgs_divWarningInfo").style.display = "block";
    
     
}
function calculateActivityData()
{
     var activity = document.getElementById("ddlActivityName").value;
         
     if(activity=="4")
     {
          document.getElementById("divActivityDistance").style.display="none";      
          document.getElementById("divActivityPace").style.display="none";      
            
     }
     else
     {
          document.getElementById("divActivityDistance").style.display="block";      
          document.getElementById("divActivityPace").style.display="block";     
     }
     
     if(activity!="4")
     {
        var HourObj = document.getElementById("txtActivityHr");
        var MinuteObj = document.getElementById("txtActivityMin");
        var SecondObj = document.getElementById("txtActivitySec");
        
        var duration = DurationInSec(HourObj,MinuteObj,SecondObj);
        
        var DistanceObj = document.getElementById("txtActivityDistance");
        var UnitObj = document.getElementById("ddlActivityUnit");
        var WorkoutObj = document.getElementById("ddlActivityName");
        var PaceObj = document.getElementById("txtActivityPace");

        calculatePace(DistanceObj,UnitObj,WorkoutObj,duration,PaceObj);
        //calculateActivityPace();
     }       
}

function ValidateAddActivity()
{
    
    errors = "<ul>";
    mandatoryFieldsErrorFlag = false;
    var status = ValidateAddActivityRoutines();  
    
    if(status == false)
    {
          
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");
         document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";    
		registrationErrorsDiv.style.display = "block";
        errors +='</ul>';
        registrationErrorsDiv.innerHTML = "";
            
        registrationErrorsDiv.innerHTML = errors; 
        
        return false;   
     }
     else
     {
         var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");
           document.getElementById("WarningMsgs3_divWarningInfo").style.display = "none";  
		 registrationErrorsDiv.style.display = "none";
		 
         return true;          
     }  
}

function ValidateAddActivityRoutines()
{   
    var userControl = "";
    var status = true;
    var tempWorkoutType = document.getElementById("ddlWorkoutType").value;
 
   //If workout type is Brick
    if(tempWorkoutType=="8")
    {
         var activity = document.getElementById("ddlActivityName").value;
     
        
        if(activity!="4")
        {
            var varTemp = document.getElementById('txtActivityDistance'); 
           
            var alertName = " Distance ";
            var isMandatory = 'false';
         
            if(bValidate(varTemp, "Float" ,isMandatory , alertName) != true)
            {
                status = false;  
                varTemp.focus();
                return false;
            }
       
            if(varTemp.value == "")
            {
                errors +='<li>'+"Enter"+ alertName+'.<br/></li>'; 
                status = false;
                varTemp.focus();
                return false;
            }
        }
        
        var _hr= document.getElementById("txtActivityHr").value;
        var _min= document.getElementById("txtActivityMin").value;
        var _sec= document.getElementById("txtActivitySec").value;
        
        if(_hr == "" && _min=="" && _sec=="")
        {
            errors +='<li>'+"Enter duration." +'<br/></li>'; 
            status = false;
            document.getElementById("txtActivityHr").focus();
            return false;
        }
        
        else if((_hr == "" || _hr=="0" || _hr=="00") && (_min=="" || _min=="00" || _min=="0") && (_sec=="" || _sec=="0" || _sec=="00"))
        {
            errors +='<li>'+"Duration should be greater than 0." +'<br/></li>'; 
            status = false;
            document.getElementById("txtActivityHr").focus();
            return false;
        }
        
        var varTemp = document.getElementById(userControl + "txtActivityHr");  
        var alertName = " Hours ";
        var isMandatory = 'false';
        if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
        {
            varTemp.focus();
            status = false;     
        }
       
        if(varTemp.value > 24)
        {
		    errors +='<li>'+alertName+ " should be between 0 to 24." +'<br/></li>'; 
            status = false;
            varTemp.focus();
            return false;
        }  
    
    
        var varTemp = document.getElementById(userControl + "txtActivityMin");  
        var alertName = " Minutes ";
        var isMandatory = 'false';
        if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
        {
           status = false; 
           varTemp.focus();
           return false;
        }
        
        if(varTemp.value > 59)
        {
		    errors +='<li>'+alertName+ " should be between 0 to 59." +'<br/></li>'; 
            status = false;
            varTemp.focus();
            return false;
        }       
        
     
        var varTemp = document.getElementById(userControl + "txtActivitySec");  
        var alertName = " Seconds ";
        var isMandatory = 'false';
        if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
        {
            status = false;  
            varTemp.focus();
            return false;
        }
    	
        if(varTemp.value > 59)
        {
            errors +='<li>'+alertName+ " should be between 0 to 59." +'<br/></li>'; 
            status = false;
            varTemp.focus();
            return false;
        }  
    
        
        if((varTemp.value == 24)&& ((varTemp1.value > 0) || (varTemp2.value > 0)) )
        {
		    errors +='<li>'+alertName+ " cannot be more than 24 hours, Please enter again." +'<br/></li>'; 
            status = false;
            varTemp.focus();
            return false;
        }
    }
    
    return status;
}

function calculateGridActivityData()
{
    var txtActivityType=document.getElementById("hidGridActivityType").value;
      
    SetVisibleControlForActivity();
    if(document.getElementById(txtActivityType) != null)
    {
        if(document.getElementById(txtActivityType).value!="4")
        {  
            var txtHour = document.getElementById("hidGridHourId").value;
            var txtMinute = document.getElementById("hidGridMinuteId").value;
            var txtSecond = document.getElementById("hidGridSecondId").value;
            
            var HourObj=document.getElementById(txtHour);
            var MinuteObj=document.getElementById(txtMinute);
            var SecondObj=document.getElementById(txtSecond);
            
            var duration = DurationInSec(HourObj,MinuteObj,SecondObj);
            
            var txtDistance = document.getElementById("hidGridDistanceId").value;
            var txtUnit = document.getElementById("hidGridUnitId").value;
            var txtWorkout = document.getElementById("hidGridActivityType").value;
            var txtPace = document.getElementById("hidGridPaceId").value;
            
            var DistanceObj=document.getElementById(txtDistance);
            var UnitObj=document.getElementById(txtUnit);
            var WorkoutObj=document.getElementById(txtWorkout);
            var PaceObj=document.getElementById(txtPace);

            calculatePace(DistanceObj,UnitObj,WorkoutObj,duration,PaceObj); 
        }
    }
   
}

function SetVisibleControlForActivity()
{ 
    var txtActivityType=document.getElementById("hidGridActivityType");
    var txtDistanceId=document.getElementById("hidGridDistanceId").value;
    var txtUnitId=document.getElementById("hidGridUnitId").value;
    var txtHourId=document.getElementById("hidGridHourId").value;
    var txtMinuteId=document.getElementById("hidGridMinuteId").value;
    var txtSecondId=document.getElementById("hidGridSecondId").value;
    var txtPaceId=document.getElementById("hidGridPaceId").value;
   
    if(document.getElementById("txtActivityType") != null)
    {
        if(document.getElementById("txtActivityType").value=="4")
        {
            document.getElementById("txtDistanceId").style.display="none";
            document.getElementById("txtUnitId").style.display="none";
            document.getElementById("txtPaceId").style.display="none";
        }
        else
        {
            document.getElementById("txtDistanceId").style.display="block";
            document.getElementById("txtUnitId").style.display="block";
            document.getElementById("txtPaceId").style.display="block";
        }
    }
     
}

function ValidateGridActivityRecord()
{
    errors = "<ul>";
    mandatoryFieldsErrorFlag = false;
    var status = ValidateGridActivityRoutines();  
    
    if(status == false)
    {
          
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");
        document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";    
		registrationErrorsDiv.style.display = "block";
        errors +='</ul>';
        registrationErrorsDiv.innerHTML = "";
            
        registrationErrorsDiv.innerHTML = errors; 
        
        return false;   
     }
     else
     {
         var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");
         document.getElementById("WarningMsgs3_divWarningInfo").style.display = "none";   
		 registrationErrorsDiv.style.display = "none";
		 
        return true;          
     }  

    
}


function ValidateGridExcerciseRecord()
{
    errors = "<ul>";
    mandatoryFieldsErrorFlag = false;
    var status = ValidateGridExcerciseRoutines();  
    
    if(status == false)
    {
          
        var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");
        document.getElementById("WarningMsgs3_divWarningInfo").style.display = "block";    
		registrationErrorsDiv.style.display = "block";
        errors +='</ul>';
        registrationErrorsDiv.innerHTML = "";
            
        registrationErrorsDiv.innerHTML = errors; 
        
        return false;   
     }
     else
     {
         var registrationErrorsDiv = document.getElementById("WarningMsgs3_RegistrationErrors");
          document.getElementById("WarningMsgs3_divWarningInfo").style.display = "none";  
		 registrationErrorsDiv.style.display = "none";
		 
        return true;          
     }  

    
}

function ValidateGridActivityRoutines()
{
    var txtActivityType=document.getElementById("hidGridActivityType").value;
    var txtDistanceId=document.getElementById("hidGridDistanceId").value;
    var txtUnitId=document.getElementById("hidGridUnitId").value;
    var txtHourId=document.getElementById("hidGridHourId").value;
    var txtMinuteId=document.getElementById("hidGridMinuteId").value;
    var txtSecondId=document.getElementById("hidGridSecondId").value;
    var txtPaceId=document.getElementById("hidGridPaceId").value;
    
    var userControl = "";
    var status = true;
    //var tempWorkoutType = document.getElementById(txtActivityType).value;
 
   //If workout type is Brick
  
       if(document.getElementById(txtActivityType).value!="4")
       {
            var varTemp = document.getElementById(txtDistanceId); 
           
            var alertName = " Distance ";
            var isMandatory = 'false';
         
            if(bValidate(varTemp, "Float" ,isMandatory , alertName) != true)
            {
                status = false;
            }  
       
         
            
//            if(varTemp.value == 0 || varTemp.value == "")
//            {
//                if(mandatoryFieldsErrorFlag == false) 
//	            {
//			        errors +='<li>'+sFillMandatoryFields_Message+'<br/></li>';  
//		            mandatoryFieldsErrorFlag = true;
//    		    
//	            }
//           
//                status = false;
//            }   
        }
        
        var varTemp = document.getElementById(userControl + txtHourId);  
        var alertName = " Hours ";
        var isMandatory = 'false';
        if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
        {
            status = false;   
        }  
       
        if(varTemp.value > 24)
        {
		    errors +='<li>'+alertName+ " should be between 0 to 24." +'<br/></li>'; 
            status = false;
        }  
    
    
        var varTemp = document.getElementById(userControl + txtMinuteId);  
        var alertName = " Minutes ";
        var isMandatory = 'false';
        if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
        {
            status = false; 
        }
        
        if(varTemp.value > 59)
        {
		    errors +='<li>'+alertName+ " should be between 0 to 59." +'<br/></li>'; 
            status = false;
        }       
        
     
        var varTemp = document.getElementById(userControl + txtSecondId);  
        var alertName = " Seconds ";
        var isMandatory = 'false';
        if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
        {
            status = false;  
        }
    	
        if(varTemp.value > 59)
        {
            errors +='<li>'+alertName+ " should be between 0 to 59." +'<br/></li>'; 
            status = false;
        }  
    
        
        if((varTemp.value == 24)&& ((varTemp1.value > 0) || (varTemp2.value > 0)) )
        {
		    errors +='<li>'+alertName+ " cannot be more than 24 hours, Please enter again." +'<br/></li>'; 
            status = false;
        }
    
    
    return status;
}


function ValidateGridExcerciseRoutines()
{
    var txtActivityType=document.getElementById("hidGridExcerciseType").value;
    var txtHourId=document.getElementById("hidGridExceriseHourId").value;
    var txtMinuteId=document.getElementById("hidGridExcerciseMinuteId").value;
    var txtSecondId=document.getElementById("hidGridExcerciseSecondId").value;
    var txtOtherExcercise=document.getElementById("hidGridtxtOtherExcercise").value;
    var txtNoOfSets=document.getElementById("hidGridNoOfSets").value;
        
    //var txtPaceId=document.getElementById("hidGridPaceId").value;
    
    var userControl = "";
    var status = true;
   
         var activity = document.getElementById(txtActivityType).value;
     
     
        //If Activity is Other
         if(activity == "Other")
         {   var varTemp = document.getElementById(txtOtherExcercise);  
             var alertName = " Other Excercise ";
             var isMandatory = 'True';
             if(bValidate(varTemp, "AlphaWithSpaceAnd" ,isMandatory , alertName) != true)
             {
                status = false;
             }
         }  
        
               
        var varTemp = document.getElementById(userControl + txtHourId);  
        var alertName = " Hours ";
        var isMandatory = 'false';
        if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
        {
           status = false;     
        }
       
        if(varTemp.value > 24)
        {
		    errors +='<li>'+alertName+ " should be between 0 to 24." +'<br/></li>'; 
            status = false;
        }  
    
    
        var varTemp = document.getElementById(userControl + txtMinuteId);  
        var alertName = " Minutes ";
        var isMandatory = 'false';
        if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
        {
           status = false; 
        }
        
        if(varTemp.value > 59)
        {
		    errors +='<li>'+alertName+ " should be between 0 to 59." +'<br/></li>'; 
            status = false;
        }       
        
     
        var varTemp = document.getElementById(userControl + txtSecondId);  
        var alertName = " Seconds ";
        var isMandatory = 'false';
        if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
        {
            status = false;  
        }
    	
        if(varTemp.value > 59)
        {
            errors +='<li>'+alertName+ " should be between 0 to 59." +'<br/></li>'; 
            status = false;
        }  
    
        
        if((varTemp.value == 24)&& ((varTemp1.value > 0) || (varTemp2.value > 0)) )
        {
		    errors +='<li>'+alertName+ " cannot be more than 24 hours, Please enter again." +'<br/></li>'; 
            status = false;
        }
        
        
        var varTemp = document.getElementById(txtNoOfSets);  
        var alertName = " No. of sets ";
        var isMandatory = 'false';
        if(bValidate(varTemp, "Numeric" ,isMandatory , alertName) != true)
        {
           status = false;
        }
        
        if(varTemp.value > 10)
        {
            errors +='<li>'+alertName+ " cannot be more than 10." +'<br/></li>'; 
            status = false;   
        }
        
        
        //if no of sets <= 10
        if(varTemp.value <= 10)
        {
            var strRepetitions=document.getElementById("hidGridRepetitions").value;
           
            if(strRepetitions!="")
            {
                var arrRepetitions = strRepetitions.split(" "); 
                
                var iCount;
                
                for(iCount=0;iCount < arrRepetitions.length;iCount++)
                {
                     var strFloatExp = "^(([0-9])+([\.]([0-9])*)?)$";
            
                    var status;
                    objRegExp = new RegExp(strFloatExp);
                    
                  
                    
                    var varTemp = document.getElementById(arrRepetitions[iCount]);  
                    var alertName = " Repetitions ";
                       
                    //alert(strCtrlId);
                    
                    if(varTemp!=null)
                    {
                        if(varTemp.value == "")
                        {   // alert("2");
                            errors +='<li>'+alertName+ " should not be empty." +'<br/></li>'; 
                            status = false;
                            break;
                        }
                        
                        if(varTemp.value == "0")
                        {   // alert("2");
                            errors +='<li>'+alertName+ " should not be 0." +'<br/></li>'; 
                            status = false;
                            break;
                        }
                        
                        if(objRegExp.test(varTemp.value)==false)
                        {   //alert("1");
                            errors +='<li>'+alertName+ " should be numeric." +'<br/></li>'; 
                            status = false;  
                            break;
                        }
                        
                        
                        if(varTemp.value > 100)
                        {   // alert("2");
                            errors +='<li>'+alertName+ " cannot be more than 100." +'<br/></li>'; 
                            status = false;
                            break;
                        }
                    }
                
                } 
            }
            
            
            var strWeight=document.getElementById("hidGridWeight").value;
           
            if(strWeight!="")
            {
                var arrWeight = strWeight.split(" "); 
                
                var iCount;
                
                for(iCount=0;iCount < arrWeight.length;iCount++)
                {
                    
                    var strFloatExp = "^(([0-9])+([\.]([0-9])*)?)$";
            
                    var status;
                    objRegExp = new RegExp(strFloatExp);
                    
                   
                    
                    var varTemp = document.getElementById(arrWeight[iCount]);  
                    var alertName = " Weight ";
                       
                    //alert(strCtrlId);
                    
                    if(varTemp!=null)
                    {
                        if(varTemp.value == "")
                        {   // alert("2");
                            errors +='<li>'+alertName+ " should not be empty." +'<br/></li>'; 
                            status = false;
                            break;
                        }
                        
                        if(objRegExp.test(varTemp.value)==false)
                        {   //alert("1");
                            errors +='<li>'+alertName+ " should be numeric." +'<br/></li>'; 
                            status = false;  
                            break;
                        }
                        
                        
                        if(varTemp.value > 1000)
                        {   // alert("2");
                            errors +='<li>'+alertName+ " cannot be more than 1000." +'<br/></li>'; 
                            status = false;
                            break;
                        }  
                    }              
                } 
            }
        }
    
    return status;
}

function ValidateTerms()
{
    var objCtrl;
     
    objCtrl=document.getElementById("txtTermName");
    
    if(objCtrl.value.trim()=="")
    {  
        document.getElementById("WarningMsgs2_RegistrationErrors").style.display='block';
        document.getElementById("WarningMsgs2_RegistrationErrors").innerHTML="Please enter all mandatory data";
        document.getElementById("WarningMsgs2_divWarningInfo").style.display='block';
         return false;
    }
    
    //Validate term name
    //////////
    var sExp;
    sExp =  "^[0-9a-z(),\.\/ & ';\:-]+$";
    objRegExp = new RegExp(sExp, 'gi');

    if (objRegExp.test(objCtrl.value.trim()) == false) 
    {
        document.getElementById("WarningMsgs2_RegistrationErrors").style.display='block';
        document.getElementById("WarningMsgs2_RegistrationErrors").innerHTML="Term should contain only letters, numbers, space, comma, colon, dot, semicolon, single quote, forward slash, hyphen and ampersand.";
        document.getElementById("WarningMsgs2_divWarningInfo").style.display='block';
        return false;
    }
    //////////
    
    objCtrl=document.getElementById("txtTermDescription");
    
    if(objCtrl.value.trim()=="")
    {   
        document.getElementById("WarningMsgs2_RegistrationErrors").style.display='block';
        document.getElementById("WarningMsgs2_RegistrationErrors").innerHTML="Please enter all mandatory data"; 
         document.getElementById("WarningMsgs2_divWarningInfo").style.display='block';
         return false;
    }
    return true;
}
function ShowAddTermPopup()
{   var objCtrl;
      
    objCtrl=document.getElementById("hidTermId");
    
    if(objCtrl!=null)
    {  
         objCtrl.value="";
    }
    
    objCtrl=document.getElementById("txtTermName");
    
    if(objCtrl!=null)
    {  
         objCtrl.value="";
    }
    
    objCtrl=document.getElementById("txtTermDescription");
    
    if(objCtrl!=null)
    {  
        objCtrl.value="";
    }
    
    var registrationErrorsDiv = document.getElementById("WarningMsgs2_RegistrationErrors");
            
    registrationErrorsDiv.style.display = "none";
   document.getElementById("WarningMsgs2_divWarningInfo").style.display = "none";
    ShowModalPopup('pnlAddTerm','Training Plans - Add New Term','m');   
    
    ShowCreatePlanDDL();
    return false;
}

function DeletePlanConfirmation(RecordId,btnId)
{
    document.getElementById("confirmBox_hidButtonId").value=btnId;
    document.getElementById("hidRecordId").value=RecordId;
    ShowConfirmBox('Would you like to delete the Plan?');
    return false;
}

function DeleteTrainingPlanConfirmation(RecordId,btnId)
{
    document.getElementById("confirmBox_hidButtonId").value=btnId;
    document.getElementById("hidRecordId").value=RecordId;
    ShowConfirmBox('Would you like to delete the Plan?');
    return false;
}


function ShowPlanCreatedMessageBox(facebookMessage,SendTweet,SendFacebook,logoutStatus,OperType)
{
    var msg ="";
        if(SendTweet=="False")
           {  
              if(OperType==0)
              {
                  msg = "Congratulations! Your plan has been successfully created.";
              }
              else
              {
                 msg = "Congratulations! Your plan has been successfully updated.";
              }
           }
           else
           {
              if(OperType==0)
              {
                 msg="Congratulations! Your plan has been successfully created and shared with Twitter.";
              }
              else
              {
                  msg="Congratulations! Your plan has been successfully updated and shared with Twitter.";
              }
           }
              
          if(SendFacebook=="True")
          {  
             ShowCreatePlanDDL();
             ShowMessagewithData(msg,facebookMessage,logoutStatus);
          }
          else
          {  
             ShowCreatePlanDDL();
            document.getElementById("msgData").value="";
             ShowMessageBox(msg);     
          }
          return true;
}

function ShowFBPublishData()
{  

      if(document.getElementById("hidSendFacebook").value=="True")
      {     var Path = self.location.href;
            var PageName = Path.substring(Path.lastIndexOf("/")+1 ,Path.length);
            PageName = PageName.toLowerCase();
            if (PageName.indexOf("createplan.aspx") >=0 || PageName.indexOf("trainingplans.aspx") >=0 || PageName.indexOf("trainingplandetails.aspx") >=0 || PageName.indexOf("coachdetails.aspx") >=0)
            { 
                 var FBMessage = document.getElementById("hidFBMessage").value;
            }
            
            FBPublishData(FBMessage);
      }
}

function ShowFBPublish()
{

    setTimeout("ShowFBPublishData()",500);
}

function nextClaimantClick()
{
     var btnObj=document.getElementById('hidClaimNextButton');
    // alert(btnObj);
     if (btnObj != null)
     { 
        if ((document.all)||(is_Safari > 0))
        {   
            btnObj.click();
            
        }
        else
        {   

            var e = document.createEvent("MouseEvents");
            e.initEvent("click", true, true);
            btnObj.dispatchEvent(e);
        }
     } 
     return false;   
    
}



function prevClaimantClick()
{
  
     var btnObj=document.getElementById('hidClaimPrevButton');
    
     if (btnObj != null)
     { 
        if ((document.all)||(is_Safari > 0))
        {   
            btnObj.click();
            
        }
        else
        {   

            var e = document.createEvent("MouseEvents");
            e.initEvent("click", true, true);
            btnObj.dispatchEvent(e);
        }
     } 
     return false;   
    
}
  //Help popup
    function showHelpPopup(e,controlName)
    { 
    
   
  
          objX=(document.all)?document.documentElement.scrollLeft:window.pageXOffset;
    objY=(document.all)?document.documentElement.scrollTop:window.pageYOffset;
//    if((is_Safari >0)||(is_chrome==true))
//    {     
//          objX= window.event.clientX-10;
//          objY=window.event.clientY+document.body.scrollTop+10;       
//    }
//    else
//    {
//        objX=e.clientX+objX-10; //document.body.scrollLeft;
//        objY=e.clientY+objY+10; //document.body.scrollTop;
//    }
   
   // Commented today - Swaraj
   if((is_Safari >0)||(is_chrome==true))
    {     
          
         objX= window.event.clientX+objX-10;
         objY=window.event.clientY+objY+10;
    }
    else
    {
        objX=e.clientX+objX; //document.body.scrollLeft;
        objY=e.clientY+objY; //document.body.scrollTop;
    }
    
    var topPos=parseInt(objY);
            var topLeft=parseInt(objX)+ 15;
            topPos=parseInt(topPos)-60;
      
        if(controlName=="UploadTPLogoImages")
        {
            objpopup=document.getElementById("divCalendarpopup");
            document.getElementById("lblEventDetails").innerHTML="Coach can upload training plan logo. GoUltraSports members can able to view logo on the training plan detail page.";
            objpopup.style.left = topLeft + "px";
            objpopup.style.top = topPos + "px";
            
            objpopup.style.display = "block";
        }
          if(controlName=="AddPlanInfo")
        {
            objpopup=document.getElementById("divCalendarpopup");
            document.getElementById("lblEventDetails").innerHTML="Coach can enter Training Plan name and select categories in which that training will be available.";
            objpopup.style.left = (topLeft - 310) + "px";
            objpopup.style.top = topPos + "px";
            
            objpopup.style.display = "block";
        }
          if(controlName=="AddPlanCost")
        {
            objpopup=document.getElementById("divCalendarpopup");
            document.getElementById("lblEventDetails").innerHTML="Coach can enter training plan duration and make the plan password protected.Again he can specify that training plan will be displayed to user or not.";
            objpopup.style.left = (topLeft - 310) + "px";
            objpopup.style.top = topPos + "px";
            
            objpopup.style.display = "block";
        }
        
    }

    function hideHelpPopup()
    {
        
        var objpopup; 
        objpopup=document.getElementById("divCalendarpopup");  
        
        if(objpopup!=null)
        {
            objpopup.style.display="none";
        }    
    }
    
    function hideHelpPopupLeft()
    {
        var objpopup; 
        objpopup=document.getElementById("divCalendarpopup");  
        
        if(objpopup!=null)
        {
            objpopup.style.display="none";
        }    
    }
    
    function moveHelpPopupLeft(e)
    {
        var objpopup;        
        objpopup=document.getElementById("divCalendarpopup");            
        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 + 5; //document.body.scrollLeft;
			    objY = e.clientY + objY - 40; //document.body.scrollTop;
        
                //objX = parseInt(objX) - 25;
                //objY = parseInt(objY) - 30;
                
                objpopup.style.left = e.clientX -304+ "px";
                objpopup.style.top = objY + "px";
            
			    objpopup.style.display="block";
            }
        }  
    }

    function moveHelpPopup(e)
    {
        var objpopup;        
        objpopup=document.getElementById("divHelpPopup");            
        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 + 5; //document.body.scrollLeft;
			    objY = e.clientY + objY - 40; //document.body.scrollTop;
        
                //objX = parseInt(objX) - 25;
                //objY = parseInt(objY) - 30;
                
                objpopup.style.left = objX + "px";
                objpopup.style.top = objY + "px";
            
			    objpopup.style.display="block";
            }
        }  
    }
    
function ChangeStyle(args1,args2)
{
    if(document.getElementById("ChkMYTP") != null)
    {
        if(document.getElementById("ChkMYTP").checked == true)
        {
           
           args2 = "Training Plan";
        }
    }
    if(args1 != null)
    {
        if(args1.value == args2)
        {
            args1.value = "";
            args1.className = "clsTextBoxYellow";
        }
    }
}
   
function SetDefault(args1,args2)
{
    if(document.getElementById("ChkMYTP") != null)
    {
       if(document.getElementById("ChkMYTP").checked == true)
        {
          
           args2 = "Training Plan";
        }
    }
    if(args1 != null)
    {
        if(args1.value == "")
        {
            args1.value = args2;
            args1.className = "clsTextBoxDefault";
        }
    }
}


//*******LogCalendar.js file*******************
var rolloverobject;
var objX=0;
var objY=0;
var Popupdata="";

var is_Safari = navigator.userAgent.indexOf('Safari');
var is_Firefox = navigator.userAgent.indexOf('Firefox');
// JScript File

/*
function CloseLogPagePopup(logDate)
{  
}

function MoveLogPagePopup(e,logDate)
{

}*/

    
function CloseLogPagePopup()
{   	
     var objpopup_left;       
    objpopup_left=document.getElementById("divLeftArrowPopup");  
    
    if(objpopup_left!=null)
    {
        if(objpopup_left.style.display=="block")
        {
            objpopup_left.style.display="none";
         }
    }
    
   var objpopup;   
	 objpopup=document.getElementById("divCalendarpopup");  
    
    if(objpopup!=null)
    {  
        if(objpopup.style.display=="block")
        {
            objpopup.style.display="none";
          }
    }
   
     
}



function MoveLogPagePopup(e,logDate)
{
    var objpopup;            
    objpopup=document.getElementById("divCalendarpopup");   
    var objpopup_left;
    objpopup_left = document.getElementById("divLeftArrowPopup");   
	if(objpopup!=null || objpopup_left!=null)
	{  
		if(objpopup.style.display=="block" || objpopup_left.style.display=="block" )
		{   
		    objX=(document.all)?document.documentElement.scrollLeft:window.pageXOffset;
			objY=(document.all)?document.documentElement.scrollTop:window.pageYOffset;
        
            if((is_Safari >0)||(is_chrome==true))
            {     
                  
                 objX= window.event.clientX+objX-10;
                 objY=window.event.clientY+objY+10;
            }
            else
            {
                objX=e.clientX+objX; //document.body.scrollLeft;
                objY=e.clientY+objY; //document.body.scrollTop;
            }

            var arrWeekDays;

            var tempDate=new Date(logDate);
            var startDay=parseInt("0");
            if(document.getElementById("hidDefaultDay").value!="")
            {
                startDay =parseInt(document.getElementById("hidDefaultDay").value);
            }
             var currentDay =tempDate.getDay();
            // var arrDays =[ 0, 1, 2, 3, 4, 5, 6 ];
             switch (startDay)
                {
                    case 0:
                        arrWeekDays =[ 0, 1, 2, 3, 4, 5, 6 ];//[ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ];
                        break;
                    case 1:
                        arrWeekDays = [1, 2, 3, 4, 5, 6,0 ];//[ "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday" ];
                        break;
                    case 2:
                        arrWeekDays =[ 2, 3, 4, 5, 6,0,1 ]; //[ "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday" ];
                       
                        break;
                    case 3:
                        arrWeekDays =[ 3, 4, 5, 6,0,1, 2];//[ "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday" ];
                      
                        break;
                    case 4:
                        arrWeekDays =[ 4, 5, 6,0,1, 2, 3];// ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday" ];
                      
                        break;
                    case 5:
                        arrWeekDays = [ 5, 6,0,1, 2, 3, 4 ];//[ "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" ];
                       
                        break;
                    case 6:
                        arrWeekDays = [ 6,0,1, 2, 3, 4, 5 ];//["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
                        //calLogCalendar.FirstDayOfWeek = (FirstDayOfWeek)0;
                        break;
                    default: break;
                }
            var total;
            var i;
               if(parseInt(currentDay)!=0)
               {
                    currentDay=parseInt(currentDay)-parseInt('1');
                }
                else
                {
                     currentDay=parseInt('6');
                }
              
                 for(i=0;i<8;i++)
                 {
                    if(arrWeekDays[i]==currentDay)
                    {
                      break;
                    }
                 }
                if(i<3)
                 { 
                    var topPos=parseInt(objY);
                    var topLeft=parseInt(objX)+ 15;
                    topPos=parseInt(topPos)-60;
                    objpopup_left.style.left=topLeft+"px";
                    objpopup_left.style.top=topPos+"px";
                    objpopup.style.display="none";
                    objpopup_left.style.display="block";
                 }
                 else
                 {   
                   total=parseInt(objX)-parseInt(objpopup.style.width)+parseInt('15');
                   var topPos=parseInt(objY);
                   var topLeft=parseInt(total)-35;
                   var topPos=parseInt(topPos)-60;
                   objpopup.style.left=topLeft+"px";
                   objpopup.style.top=topPos+"px";
                   objpopup_left.style.display="none";
                   objpopup.style.display="block";
                 }

                 
    		}
	}       
}
//By Ritesh
//This function is used to display the event details
function ShowLogPagePopup(e,logID)
{   

    
    
    Popupdata="";
    xmlHttpEvent= null;
    xmlHttpEvent=GetXmlHttpEventObject();
    objX=(document.all)?document.documentElement.scrollLeft:window.pageXOffset;
    objY=(document.all)?document.documentElement.scrollTop:window.pageYOffset;
//    if((is_Safari >0)||(is_chrome==true))
//    {     
//          objX= window.event.clientX-10;
//          objY=window.event.clientY+document.body.scrollTop+10;       
//    }
//    else
//    {
//        objX=e.clientX+objX-10; //document.body.scrollLeft;
//        objY=e.clientY+objY+10; //document.body.scrollTop;
//    }
   
   // Commented today - Swaraj
   if((is_Safari >0)||(is_chrome==true))
    {     
          
         objX= window.event.clientX+objX-10;
         objY=window.event.clientY+objY+10;
    }
    else
    {
        objX=e.clientX+objX; //document.body.scrollLeft;
        objY=e.clientY+objY; //document.body.scrollTop;
    }
    
   // rolloverobject=strID;
  
   var objpopup=document.getElementById("divCalendarpopup");
   var objpopup_left;
   objpopup_left = document.getElementById("divLeftArrowPopup");
    //Check if the popup is already created
    if(objpopup!=null || objpopup_left!= null)
    {
     
        if(document.getElementById("logcalendarpopup_lblPopupTitle")!=null)
        {   
			document.getElementById("logcalendarpopup_lblPopupTitle").innerHTML="&nbsp;&nbsp;"+"Workout Details";
        }
        
        if(document.getElementById("logcalendarpopup_lblTitle")!=null)
        {   
			document.getElementById("logcalendarpopup_lblTitle").innerHTML="&nbsp;&nbsp;"+"Workout Details";
        }
                     
       if(document.getElementById("popupLoadingImage")!=null)
       {   
		   document.getElementById("popupLoadingImage").src="../../Images/home page/loading.gif";
       }
       
       if(document.getElementById("popupLeftLoadingImage")!=null)
       {   
		document.getElementById("popupLeftLoadingImage").src="../../Images/home page/loading.gif";
       }
       var tempDate=new Date();
       var arrWeekDays=new Array();
       var startDay=parseInt("0");
       if(document.getElementById("hidDefaultDay").value!="")
        {
            startDay =parseInt(document.getElementById("hidDefaultDay").value);
        }
       var currentDay =tempDate.getDay(); 
       
       switch (startDay)
       {
           case 0:
                arrWeekDays =[ 0, 1, 2, 3, 4, 5, 6 ];//[ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ];
                break;
           case 1:
                 arrWeekDays = [1, 2, 3, 4, 5, 6,0 ];//[ "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday" ];
                 break;
            case 2:
                 arrWeekDays =[ 2, 3, 4, 5, 6,0,1 ]; //[ "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday" ];           
                 break;
            case 3:
                 arrWeekDays =[ 3, 4, 5, 6,0,1, 2];//[ "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday" ];      
                 break;
            case 4:
                arrWeekDays =[ 4, 5, 6,0,1, 2, 3];// ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday" ];
                break;
            case 5:
                arrWeekDays = [ 5, 6,0,1, 2, 3, 4 ];//[ "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" ];
                break;
            case 6:
                arrWeekDays = [ 6,0,1, 2, 3, 4, 5 ];//["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
                 break;
                default: break;
            }
            var total,i;            
            if(parseInt(currentDay)!=0)
           {
                currentDay=parseInt(currentDay)-parseInt('1');
            }
            else
            {
                 currentDay=parseInt('6');
            }             
             for(i=0;i<8;i++)
             {
                if(arrWeekDays[i]==currentDay)
                {
                  break;
                }
             }
       
            var topPos=parseInt(objY);
            var topLeft=parseInt(objX)+ 15;
            topPos=parseInt(topPos)-60;
            objpopup_left.style.left=topLeft+"px";
            objpopup_left.style.top=topPos+"px";
            objpopup_left.style.display="block";     
       

          if(document.getElementById("calendarpopupHeader")!=null)
        {    
		    document.getElementById("calendarpopupHeader").style.display="block";
        }
         if(document.getElementById("calendarpopupLeftHeader")!=null)
        {     
            document.getElementById("calendarpopupLeftHeader").style.display="block";
		}
        if(document.getElementById("logcalendarpopup_lblEventDetails")!=null)
        {
            document.getElementById("logcalendarpopup_lblEventDetails").innerHTML="";
        }       
        if(document.getElementById("logcalendarpopup_lblLeftEventDetails")!=null)
        {
            document.getElementById("logcalendarpopup_lblLeftEventDetails").innerHTML="";
        }         
    }       
    
    if (xmlHttpEvent==null)
    {
        alert("Browser does not support HTTP Request.");
        return;
    }
    
    
   
    var url="LogCalendarpopup.aspx";
    url=url+"?logID=" + logID; 
    //url=url+"?date="+date; 
//    url=url+"?logDate=" + logDate; 
//    url=url+"&logID=" + logID; 
//    url=url+"&logType=" + logType; 
//    url=url+"&userID=" + 0; 
//    url=url+"&defaultUnit=" + DefaultUnit; 
//    url=url+"&workoutType=" + WorkoutType;   
//    url=url+"&defaultPaceUnit=" + DefaultPaceUnit;  
      
    xmlHttpEvent.onreadystatechange=stateChangedShowLogPagePopup;
    xmlHttpEvent.open("GET",url,true);
    xmlHttpEvent.send(null);    
}

function stateChangedShowLogPagePopup() 
{ 
   if (xmlHttpEvent.readyState==4 )
    { 	          
        Popupdata=xmlHttpEvent.responseText;   
       if(document.getElementById("logcalendarpopup_lblEventDetails")!=null)
        {  			
			document.getElementById("logcalendarpopup_lblEventDetails").innerHTML=Popupdata;
			document.getElementById("calendarpopupLeftHeader").style.display="none";
        }  
        if(document.getElementById("logcalendarpopup_lblLeftEventDetails")!=null)
        {  			
			document.getElementById("logcalendarpopup_lblLeftEventDetails").innerHTML=Popupdata;
			document.getElementById("calendarpopupLeftHeader").style.display="none";    
        } 
    }   
}    

function GetXmlHttpEventObject()
{ 
    var objXMLHttp=null;
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp;
}

function CreatePopup()
{
    var objpopup;
    objpopup=document.getElementById("divLogCalendarpopup");
    
    //Check if the popup is already created
    if(objpopup==null)
    {
        try
        {
            //For IE
            objpopup=document.createElement("<div id=\"divLogCalendarpopup\" style=\"z-index: 1000; position: absolute; display: none;left:0px; top:0px; \">");
        }
        catch(e)
        {
            //for firefox
            objpopup=document.createElement("div");
            objpopup.setAttribute("id", "divLogCalendarpopup");
            objpopup.setAttribute("style", "z-index: 1000; position: absolute; display: none; left:0px; top:0px; ");
        }            
    }
    document.body.appendChild(objpopup);
    return(objpopup);
}

function TellAFriend()
{
   //alert(document.getElementById("hidisDisplayToUsers").value);
   if(document.getElementById("ValidationWarning1_divWarningInfo") != null)
   {
        document.getElementById("ValidationWarning1_divWarningInfo").style.display = "none";
   }
    
      var txtEmailAddress = document.getElementById("txtEmailAddress")
      txtEmailAddress.value = "";
    var btnObj = document.getElementById("hidlnkTellAFriend");
	
	if ((document.all)||(is_Safari > 0))
	{
		// IE
		btnObj.click();
	}
	else
	{
		// FireFox 
		var e = document.createEvent("MouseEvents");
		e.initEvent("click", true, true);
		btnObj.dispatchEvent(e);
	}   
	
	if(document.getElementById("hidisDisplayToUsers")!= null)
	{
	    if(document.getElementById("hidisDisplayToUsers").value == "0")
	    {
	     ShowInformationMessageBox("'Publish Training Plan' option is not checked while creating the plan, due to which the invitation cannot be sent to friend(s).");
	    }
        
    }
    
    return false;
}

function ShowWorkTypeDetails(WorkTypeId,DayId)
{   
     document.getElementById('hidWorkTypeValue').value = WorkTypeId; 
     document.getElementById('hidDayValue').value = DayId;  
     
     
     document.getElementById('lblWorloutType').innerHTML="";
     document.getElementById('lblInstructions').innerHTML=""; 
     document.getElementById('lblNotes').innerHTML="";
     document.getElementById('divExcerciseUI').style.display="none";
     document.getElementById('divBrickUI').style.display="none";
     document.getElementById('divWorkoutUI').style.display="none";
     
      
     var btnObj = document.getElementById("btnHiddenEditWorkType");
     
        if(btnObj != null && btnObj != "")
        {
                if ((document.all)||(is_Safari > 0))
                {
                    // IE
                        btnObj.click();
        
                }
                else
                {
                    // FireFox 
        
                    var e = document.createEvent("MouseEvents");
                    e.initEvent("click", true, true);
                    btnObj.dispatchEvent(e);        
                }
        }          
         
 }
 
    
function loadUPEventStartRequestHandler()
{
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_initializeRequest(UPStartRequestHandler);

}
function UPStartRequestHandler()
{
////    document.getElementById("divMySetupEvent").style.paddingTop= window.screen.height /2;
////    document.getElementById("divMySetupEvent").style.paddingLeft = (window.screen.width /2 ) - 500;
//    //document.getElementById("divMySetupEvent").style.paddingTop= "80%";
//    var arrDivLoading = document.getElementsByTagName("div");
//    for (i = 0; i < arrDivLoading.length; i++) 
//    {
//        if(arrDivLoading[i].className =="InnerTableDivLoading")
//        {
//            alert(arrDivLoading);
//            arrDivLoading[i].style.width = window.screen.width;
//            arrDivLoading[i].style.height = window.screen.height;
////            arrDivLoading[i].style.paddingTop= window.screen.height /2;
////            arrDivLoading[i].style.paddingLeft = (window.screen.width /2 ) - 500;
//arrDivLoading[i].style.top = "50%";
//arrDivLoading[i].style.left = "50%";

//        }
//    }
 showdeadcenterdiv();
}
function showdeadcenterdiv() 
{ 
// First, determine how much the visitor has scrolled
    var scrolledX, scrolledY; 
    if( self.pageYoffset ) 
    { 
        scrolledX = self.pageXoffset; 
        scrolledY = self.pageYoffset; 
    } 
    else if( document.documentElement && document.documentElement.scrollTop ) 
    { 
        scrolledX = document.documentElement.scrollLeft; 
        scrolledY = document.documentElement.scrollTop; 
    } 
    else if( document.body ) 
    { 
        scrolledX = document.body.scrollLeft; 
        scrolledY = document.body.scrollTop; 
    }

// Next, determine the coordinates of the center of browser's window

    var centerX, centerY; 
    if( self.innerHeight ) 
    { 
        centerX = self.innerWidth; 
        centerY = self.innerHeight; 
    } 
    else if( document.documentElement && document.documentElement.clientHeight ) 
    { 
    centerX = document.documentElement.clientWidth; 
    centerY = document.documentElement.clientHeight; 
    } 
    else if( document.body ) 
    { 
        centerX = document.body.clientWidth; 
        centerY = document.body.clientHeight; 
    }
// Xwidth is the width of the div, Yheight is the height of the 
// div passed as arguments to the function: 
    var leftoffset = scrolledX + (centerX ) / 2; 
    var topoffset = scrolledY + (centerY) / 2; 
// The initial width and height of the div can be set in the 
// style sheet with display:none; divid is passed as an argument to // the function 
    
    var arrDivLoading = document.getElementsByTagName("div");
    for (i = 0; i < arrDivLoading.length; i++) 
    {
        if(arrDivLoading[i].className =="OuterTableDivLoading")
        {
            arrDivLoading[i].style.width = window.screen.width + 250;
            arrDivLoading[i].style.height = window.screen.height + 3500 ;
        }
        
            
        if(arrDivLoading[i].className =="InnerTableDivLoading")
        {
              var o=arrDivLoading[i]; 
              var r=o.style; 
              r.position='absolute'; 
              r.top = topoffset ; 
              r.left = leftoffset + 150 +  'px'; 
              r.display = "block"; 
        }
    }
  
} 

function ShowCreatePlanDDL()
{
            var ddlSport = document.getElementById("ddlSport");
    	     if(ddlSport != null)
    	     {
    	        ddlSport.style.display = '';
    	     }
    	     
    	     var ddlActivityType = document.getElementById("ddlActivityType");
    	     if(ddlActivityType != null)
    	     {
    	        ddlActivityType.style.display = '';
    	     }
    	     
    	     var ddlAtheleteProfile = document.getElementById("ddlAtheleteProfile");
    	     if(ddlAtheleteProfile != null)
    	     {
    	        ddlAtheleteProfile.style.display = '';
    	     }
}



function ValidateTellAFriend()
{
    var txtEmailAddress = document.getElementById("txtEmailAddress");
    var txtYourName = document.getElementById("txtYourName");
    var txtYourEmailId = document.getElementById("txtYourEmailId");
    var hidUserId = document.getElementById("hidUserId");
    
    var tellfriendErrorsDiv = document.getElementById("ValidationWarning1_RegistrationErrors");
    var count = 0;
   
    if(txtYourName.value == '' && (hidUserId.value == '' || hidUserId.value == '0'))
    {
        tellfriendErrorsDiv.style.display = "block";
		document.getElementById("ValidationWarning1_divWarningInfo").style.display = "block";
        //errors +='</ul>';
        tellfriendErrorsDiv.innerHTML = "";
            
        tellfriendErrorsDiv.innerHTML = "Please enter your name."; 
        return false;
    }
    else if(txtYourEmailId.value == '' && (hidUserId.value == '' || hidUserId.value == '0'))
    {
        tellfriendErrorsDiv.style.display = "block";
		document.getElementById("ValidationWarning1_divWarningInfo").style.display = "block";
        //errors +='</ul>';
        tellfriendErrorsDiv.innerHTML = "";
            
        tellfriendErrorsDiv.innerHTML = "Please enter your Email ID."; 
        return false;
    }
    else if(emailCheck(txtYourEmailId.value) == false && (hidUserId.value == '' || hidUserId.value == '0'))
    {
        tellfriendErrorsDiv.style.display = "block";
		document.getElementById("ValidationWarning1_divWarningInfo").style.display = "block";
        //errors +='</ul>';
        tellfriendErrorsDiv.innerHTML = "";
            
        tellfriendErrorsDiv.innerHTML = "Please enter your valid Email ID."; 
        return false;
    }
    else if(txtEmailAddress.value == '')
    {
        tellfriendErrorsDiv.style.display = "block";
		document.getElementById("ValidationWarning1_divWarningInfo").style.display = "block";
        //errors +='</ul>';
        tellfriendErrorsDiv.innerHTML = "";
            
        tellfriendErrorsDiv.innerHTML = "Please enter your friend's Email ID."; 
        return false;
    }
    
    else
    {
        document.getElementById("ValidationWarning1_divWarningInfo").style.display = "none";
    }
    
    
    
   
    
   var  EmailIds = txtEmailAddress.value.split(";");
    
    for(i=0 ; i < EmailIds.length; i++ )
    {
        var res = emailCheck(EmailIds[i]);
        if(!res)
        {
          var tellfriendErrorsDiv = document.getElementById("ValidationWarning1_RegistrationErrors");
            
		tellfriendErrorsDiv.style.display = "block";
		document.getElementById("ValidationWarning1_divWarningInfo").style.display = "block";
        //errors +='</ul>';
        tellfriendErrorsDiv.innerHTML = "";
            
        tellfriendErrorsDiv.innerHTML = "Please enter a valid Email ID of your friend(s)."; 
        count = count + 1;
           return false;
        }
      
    }
    
    if(count == 0)
    {
        document.getElementById("ValidationWarning1_divWarningInfo").style.display = "none";
        return true;
    }
    
    
}

/* functions for new EventList Page*/
function ExapndSetupEventSerach(expandedDiv)
{
    document.getElementById(expandedDiv).style.display="block";
    document.getElementById("hidPanelType").value = "Expand";
    if(expandedDiv == "divExpandedSetupSearch")
    {
         document.getElementById("divCollapsedSetupSearch").style.display="none";
//         document.getElementById("tdSetupTopRight").className="clsTopRightBigCorner";
//         document.getElementById("tblSetupEvents").className="clsSetupEventsHeaderBig";
         if(document.getElementById("tdTopLine")!=null)
         {
            document.getElementById("tdTopLine").style.paddingTop= "0px";
         }
         
         document.getElementById("txtExpandedSetupSearchInput").value = document.getElementById("txtSetupSearchInput").value;
        
        if ( document.getElementById("txtExpandedSetupSearchInput").value != "Search Plan")
        {
             document.getElementById("txtExpandedSetupSearchInput").className = "clsFontSearchSelected";
        }
        else
        {
              document.getElementById("txtExpandedSetupSearchInput").className = "clsFontSearchDefault";
        }
         
         
    }
    else
    {
        document.getElementById("divCollapsedGlobalEventSearch").style.display="none";
//         document.getElementById("tdSearchTopRight").className="clsTopRightBigCorner";
//         document.getElementById("tblEventList").className="clsGlobalEventsHeaderBig";
         document.getElementById("tdTopLine").style.paddingTop= "0px";
        
        document.getElementById("txtExpandedGlobalEventSearchInput").value = document.getElementById("txtGlobalEventSearchInput").value;
        
        if ( document.getElementById("txtExpandedGlobalEventSearchInput").value != "Search Plan")
        {
             document.getElementById("txtExpandedGlobalEventSearchInput").className = "clsFontSearchSelected";
        }
        else
        {
              document.getElementById("txtExpandedGlobalEventSearchInput").className = "clsFontSearchDefault";
        }
       
        
    }
    return false;
}

function CollapseSetupEventSerach(collapsedDiv)
{
//    document.getElementById("divCollapsedSetupSearch").style.display="block";
//    document.getElementById("divExpandedSetupSearch").style.display="none";
    document.getElementById(collapsedDiv).style.display="block";
    document.getElementById("hidPanelType").value = "Collapse";
    if(collapsedDiv == "divCollapsedSetupSearch")
    {
         document.getElementById("divExpandedSetupSearch").style.display="none";
//         document.getElementById("tdSetupTopRight").className="clsTopRightSmallCorner";
//         document.getElementById("tblSetupEvents").className="clsSetupEventsHeaderSmall";
         
           document.getElementById("txtSetupSearchInput").value = document.getElementById("txtExpandedSetupSearchInput").value;
        
        if ( document.getElementById("txtSetupSearchInput").value != "Search Plan")
        {
             document.getElementById("txtSetupSearchInput").className = "clsFontSearchSelected";
        }
        else
        {
              document.getElementById("txtSetupSearchInput").className = "clsFontSearchDefault";
        }
         
    }
    else
    {
        document.getElementById("divExpandedGlobalEventSearch").style.display="none";
//        document.getElementById("tdSearchTopRight").className="clsTopRightSmallCorner";
//        document.getElementById("tblEventList").className="clsGlobalEventsHeaderSmall";
         document.getElementById("tdTopLine").style.paddingTop= "2px";
         
            document.getElementById("txtGlobalEventSearchInput").value = document.getElementById("txtExpandedGlobalEventSearchInput").value;
        
        if ( document.getElementById("txtGlobalEventSearchInput").value != "Search Plan")
        {
             document.getElementById("txtGlobalEventSearchInput").className = "clsFontSearchSelected";
        }
        else
        {
              document.getElementById("txtGlobalEventSearchInput").className = "clsFontSearchDefault";
        }
         
    }
    return false;
}
function ChangeSearchText(inputValue,inputName)
{
  var txtObj ;
  if(inputName == "SetupCollapsed")
  {
    
    txtObj = document.getElementById("txtSetupSearchInput");
  }
  else  if(inputName == "SetupExpanded")
  {
    txtObj = document.getElementById("txtExpandedSetupSearchInput");
  }
  if(inputValue == "blur")
  {
    if(txtObj.value == "")
    {
        txtObj.value = "Search Plan";
        txtObj.className = "clsFontSearchDefault";
    }
    else
    {
        txtObj.className = "clsFontSearchSelected";
    }
    
  }
   else if(inputValue == "focus")
  {
    if(txtObj.value == "Search Plan")
    {
        txtObj.value = "";
        txtObj.className = "clsFontSearchSelected";
    }
    else
    {
        txtObj.className = "clsFontSearchSelected";
    }
  }
     
    return false;
}

//added to make email validation more perfect.
function emailCheck (emailStr) 
{
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) 
	{
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// See if "user" is valid 
	if (user.match(userPat)==null) 
	{
		return false;
	}

	//if domain is ip address.
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) 
	{
		// this is an IP address
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
			   return false;
			}
		}
		return true;
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat);
	if (domainArray==null) 
	{
		return false;
	}

	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3)
    {
	     return false;
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
}
function DisplaySaveMessage(status,PlanId,FBMessage,logStatus,TweetStatus)
{
   var msg = "";

   if(status=="True")
   {
      if(PlanId=="0")
      {
         msg = "Congratulations! Training plan added successfully";
         document.getElementById("messageBox_hidButtonId").value = "AddTainingPlanSuccess";  
      }
      else
      {
         msg = "Congratulations! Training plan updated successfully";
         document.getElementById("messageBox_hidButtonId").value = "AddTainingPlanSuccess";  
      }
      
      if(TweetStatus=="True")
      {
          msg= msg + " and shared with Twitter";
          document.getElementById("messageBox_hidButtonId").value = "AddTainingPlanSuccess";  
      }
      
       if(document.getElementById("hidSendFacebook").value=="True")
       {  
          ShowMessagewithData(msg,FBMessage,logStatus);
          //location.href = 'GlobalChallenges.aspx';
            
       }
       else
       {  document.getElementById("msgData").value="";
          ShowMessageBox(msg);
          
       }
       
       
       
   }
   else
   if(status=="False")
   {
      msg = "Error occured while saving the training plan. Please try again.";
      alert(msg);  
   }
   
}
