
/******************************************************************************
     File Name :   homepage.js
    Created By:    Muthu Vijayan
       Created on:    11-18-2008
    Modified on:    NA
    Description:    Has all the common functions of home page..
/******************************************************************************/
                                                            
                                                            
/************************************************************************************************
     @Name : proceedLogin
     @params:  None
     @return: None. 
     purpose: To login the user.
     Created by: PrasannaKumari B
************************************************************************************************/                           

function proceedLogin()
{               
    var username = document.getElementById('username').value;
    var password = document.getElementById('password').value;
    
    var md5pass = "<? echo md5(password)?>";
    
    alert(md5pass);
    var queryStr = "vb_login_username="+username+"&vb_login_password="+password+"do=wmlogin";



}                                 
                                                            

function check()
{
    var now = new Date();
	var monthday    = now.getDate();
    //alert(monthday);
     
	if(document.form_addpackage.package_name.value=="")
	{
		alert("Please Enter Package Name");
		document.form_addpackage.package_name.focus();
		return false;
	}
    if(document.form_addpackage.sdate.value >document.form_addpackage.edate.value)
    {
     alert("Please select the proper End Date");
     return false;
    }
	if(document.form_addpackage.amt.value=="")
	{
		alert("Please Enter Amount");
		document.form_addpackage.amt.focus();
		return false;
	} else if(isNaN(document.form_addpackage.amt.value))
   	{
     	alert("Invalid data format.\n\nOnly numbers are allowed in the Amount field");
     	document.form_addpackage.amt.focus();
    	return (false);
   	}
    
  
}

    /************************************************************************************************
     @Name : fnOpenQuery
     @params:  None
     @return: None, open a popup window
     purpose: To display calender options to user when he clicks on a day numbere
     Created by: PrasannaKumari B
    ************************************************************************************************/
 
    function fnOpenQuery(Val)
    {
      window.open('../user/taskList.php?dateVal='+Val,'','status=0,toolbar=0,scrollbars=0,resizable=0,height=145,width=330,top=300,left=300');
    }
    function fnOpens(Val)
    {
      window.open('workout_list.php?sdate='+Val,'','status=0,toolbar=0,scrollbars=1,resizable=1,height=600,width=700,top=300,left=300');
    }
    /************************************************************************************************
     @Name : fnOpenUrl
     @params:  None
     @return: None, open a popup window
     purpose: To display calender options to user when he clicks on a day numbere
     Created by: PrasannaKumari B
    ************************************************************************************************/
 
    function fnOpenUrl(Val)
    {
        window.open(Val,'','status=0,toolbar=0,scrollbars=yes,resizable=yes,top=150,left=350,height=750,width=750');
    }
    
    /************************************************************************************************
     @Name : fnChangeMonth
     @params:  Value -monthe name either previous or next month
     @return: None
     purpose: To send a XMLHTTP request to display calender for selected month and year (either previous or next month)
     Created by: PrasannaKumari B
    ************************************************************************************************/
    function fnChangeMonth(Val)
    {
        var url="getCalender.php?val="+Val;
        xmlHttp=GetXmlHttpObject(fnGetMonth);
        xmlHttp.open("GET", url , true);
        xmlHttp.send(null);
    }
    
    /************************************************************************************************
     @Name : fnGetMonth
     @params:  None
     @return: None
     purpose: To assign the received response form server to current page
     Created by: PrasannaKumari B
    ************************************************************************************************/
    function fnGetMonth()
    {
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {      
            var result=xmlHttp.responseText;
            alert(result)
        }
        document.getElementById('calender').innerHTML=result;
        alert(document.getElementById('calender').innerHTML)
    }
    
    /************************************************************************************************
     @Name : fnGetCalender
     @params:  None
     @return: None
     purpose: To return to calender from agends
     Created by: PrasannaKumari B
    ************************************************************************************************/
    function fnGetCalender(val)
    {
        var url="getCalender.php?val="+val;
        document.getElementById('calender').innerHTML = "<img src='../images/loading2.gif'>"; 
        xmlHttp=GetXmlHttpObject(fnGetMonth);
        xmlHttp.open("GET", url , true);
        xmlHttp.send(null); 
    }
    
    /************************************************************************************************
     @Name : getAgenda
     @params:  date value
     @return: None
     purpose: To display the agenda in calender place
     Created by: PrasannaKumari B
    ************************************************************************************************/
    
    function getAgenda(dayval)
    {                        
        var url="workout_list.php?sdate="+dayval;
        alert(url)
        document.getElementById('calender').innerHTML = "<img src='../images/loading2.gif'>"; 
        xmlHttp=GetXmlHttpObject(fnGetMonth);
        xmlHttp.open("GET", url , true);
        xmlHttp.send(null); 
    }
    

     /*************************************************************************************************
     Name   : GetXmlHttpObject
     @params : handler
     Result : XMLHTTP object
     Purpose : To create  XMLHTTP object
      Created by: PrasannaKumari B  
     ***************************************************************************************************/          
    function GetXmlHttpObject(handler)
        {
            var objXmlHttp=null

            if (navigator.userAgent.indexOf("Opera")>=0)
            {
                alert("This example doesn't work in Opera")
                return
            }
            if (navigator.userAgent.indexOf("MSIE")>=0)
            {
                var strName="Msxml2.XMLHTTP"
                if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
                {
                    strName="Microsoft.XMLHTTP"
                }
                try
                {
                    objXmlHttp=new ActiveXObject(strName)
                    objXmlHttp.onreadystatechange=handler
                    return objXmlHttp
                }
                catch(e)
                {
                    alert("Error. Scripting for ActiveX might be disabled")
                    return
                }
            }
                if (navigator.userAgent.indexOf("Mozilla")>=0)
                {
                    objXmlHttp=new XMLHttpRequest()
                    objXmlHttp.onload=handler
                    objXmlHttp.onerror=handler
                    return objXmlHttp
                }
        }
        
     function fnOpenPopUp(task)
    {  
   //  var cdate = document.getElementById('cdate').value;
        switch(task)
        {
            case "Goal" :
                        window.open('workout/user/Mygoal.php','','toolbar=0,status=0,menubar=0,fullscreen=no,resizable=1,height=300,width=580,scrollbars=1,top=300,left=150');
                        break;
            case "WNew" :
                        window.open('workout/user/create_workout.php?task=WNew','','toolbar=0,status=0,menubar=0,width=800,height=600,resizable=1,scrollbars=1,left=100,top=50');
                        break;
            case "Cal" :   
                        //window.open('../webcal/edit_entry.php?date='+cdate,'','toolbar=0,status=0,menubar=0,fullscreen=0,resizable=1,scrollbars=1');
                        //changed on 18th Mar
                        window.open('workout/webcal/login.php','','toolbar=0,status=0,menubar=0,fullscreen=no,resizable=1,height=650,width=770,scrollbars=1');
                        break;
            case "record" :
                        //window.open('../user/record.php','','toolbar=0,status=0,menubar=0,fullscreen=no,resizable=1,height=340,width=580');
                        window.open('workout/user/newrecord.php','','toolbar=0,status=0,menubar=0,fullscreen=no,resizable=1,height=340,width=580,scrollbars=1');
                        break;
            case "Card" :
                        window.open('../user/workout_card.php','','toolbar=0,status=0,menubar=0,fullscreen=no,resizable=1,height=340,width=580,scrollbars=1');
                        break;
            case "1RM" :
                        window.open('workout/user/cal_OneRM.php','','toolbar=0,status=0,menubar=0,fullscreen=no,resizable=1,height=600,width=900,scrollbars=1');
                        break;
            case "BMI" :
                        window.open('workout/user/cal_BMI.php','','toolbar=0,status=0,menubar=0,fullscreen=no,resizable=1,height=340,width=580');
                        break;
             case "Package":
             //         window.open('../user/package.php','','toolbar=0,status=0,menubar=0,fullscreen=no,resizable=1,height=340,width=580,scrollbars=1,top=380,left=200');
                    //  window.open('../user/nutrition.php','','toolbar=0,status=0,menubar=0,fullscreen=no,resizable=1,height=340,width=580,scrollbars=1,top=380,left=200');
                    
                    RedirectUser();
                        break; 
             case "FEV" :
                        window.open('workout/user/favorite_list.php','','toolbar=0,status=0,menubar=0,fullscreen=no,scrollbars=1,resizable=1,height=400,width=850, top=250, left=300');
                        break; 
             case "Schedule" :
                        window.open('workout/user/workout_schedule.php?task=schedule','','toolbar=0,status=0,menubar=0,fullscreen=no,scrollbars=1,resizable=1,height=250,width=320, top=250, left=300');
                        break; 
        }
        
    }
    
   /*    function Openworkout(dayval,eid)
    {    
    
          window.open('workout_list.php?sdate='+dayval,'','status=0,toolbar=0,scrollbars=1,resizable=1,height=600,width=700,top=300,left=300');   
        /* switch(eid)
        {
            case 1 :
                       //document.getElementById('test').innerHTML='Nilam';
                        window.open('testRecYoga.php?sdate='+dayval+'&eid='+eid,'mywindow','status=0,toolbar=0,scrollbars=1,resizable=1,height=500,width=460,top=500,left=300');
                        break;
            case 2 :
                        window.open('RecCardio.php?sdate='+dayval+'&eid='+eid,'mywindow','status=0,toolbar=0,scrollbars=1,resizable=1,height=500,width=460,top=500,left=300');
                        break;
            case 3 :
                        window.open('RecWt.php?sdate='+dayval+'&eid='+eid,'mywindow','status=0,toolbar=0,scrollbars=1,resizable=1,height=500,width=460,top=500,left=300');
                        break;
            case 4 :
                        window.open('RecDVD.php?sdate='+dayval+'&eid='+eid,'mywindow','status=0,toolbar=0,scrollbars=1,resizable=1,height=500,width=460,top=500,left=300');
                        break;
            case 5 :
                       // window.open('RecSTS.php?sdate='+dayval+'&eid='+eid,'mywindow','status=0,toolbar=0,scrollbars=1,resizable=1,height=500,width=460,top=500,left=300');
                       // window.open('check_sts.php?sdate='+dayval+'&eid='+eid,'mywindow','status=0,toolbar=0,scrollbars=1,resizable=0');
               /* if(confirm('What do you want to do?'))
                {
                       window.open('reschedule_sts.php?sdate='+dayval,'mywindow','status=0,toolbar=0,scrollbars=1,resizable=1,height=500,width=750,top=500,left=300');
                }else
                {
                    window.open('record_sts.php?sdate='+dayval,'mywindow','status=0,toolbar=0,scrollbars=1,resizable=1,height=500,width=750,top=500,left=300');
                
                }      */
               /* window.open('confirmBox.php?sdate='+dayval,'mywindow','status=0,toolbar=0,scrollbars=1,resizable=1,height=150,width=500,top=300,left=300');
                
                
                        break;
        }     */ 
    /* } 
     
      function OpenRecworkout(dayval,eid)
     {
        window.open('workout_list.php?sdate='+dayval,'','status=0,toolbar=0,scrollbars=1,resizable=1,height=600,width=700,top=300,left=300');
        /*
        switch(eid)
        {
            case 1 :
                        window.open('EditRecYoga.php?sdate='+dayval+'&eid='+eid,'mywindow','status=0,toolbar=0,scrollbars=1,resizable=1,,height=500,width=460,top=500,left=300');
                        break;
            case 2 :
                        window.open('EditRecCardio.php?sdate='+dayval+'&eid='+eid,'mywindow','status=0,toolbar=0,scrollbars=1,resizable=1,,height=500,width=460,top=500,left=300');
                        break;
            case 3 :
                        window.open('EditRecWt.php?sdate='+dayval+'&eid='+eid,'mywindow','status=0,toolbar=0,scrollbars=1,resizable=1,,height=500,width=460,top=500,left=300');
                        break;
            case 4 :
                        window.open('EditRecDVD.php?sdate='+dayval+'&eid='+eid,'mywindow','status=0,toolbar=0,scrollbars=1,resizable=1,,height=500,width=460,top=500,left=300');
                        break;
            case 5 :
                       window.open('edit_recorded_sts.php?sdate='+dayval+'&eid='+eid,'mywindow','status=0,toolbar=0,scrollbars=1,resizable=1,,height=600,width=700,top=200,left=300');
                        break;
        }     */ 
   //  }     
     
     
    function OpenRecWt(dayval,eid)
    {
        window.open('tasklist.php?sdate='+dayval+'&eid='+eid+'&task=WT','mywindow','status=0,toolbar=0,scrollbars=1,resizable=1,,height=500,width=460,top=500,left=300');
    }
    
    
    function RedirectUser()
    {
        var url="workout/user/check_package.php";
        xmlHttp=GetXmlHttpObject(proceed);
        xmlHttp.open("GET", url , true);
        xmlHttp.send(null);
    }
    
    
    function proceed()
    {
    
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {      
            var result=xmlHttp.responseText;
            
            if(result == 0)
            {
                // Not an active user
                 window.open('https://cathe.com/workout/user/purchase.php','blank');
            
            }else
            {
                //window.open(result,'','toolbar=0,status=0,menubar=0,fullscreen=no,resizable=1,height=340,width=580,scrollbars=1,top=380,left=200');
                window.open(result,'blank');
//                window.location = result;
            }
            
        }
        //document.getElementById('calender').innerHTML=result;
    
    }
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
