/******************************************************************************************************
    File							: 	__login.Pagedetails.js
	Description						:	Login Validation Javascript File
	Project 						:	DAMS
    Date							:	01-05-2009
    Language 						: 	PHP 5
    Database 						: 	Mysql
    Author							:	Jineesh M.G.
    Modified On (By)                :   		
    ******************************************************************************************************/


function __fncViewDoctorLogin()
{
        
    thisForm.txtWhat2Do.value='VIEW_PRACT_LOGIN';
	thisForm.action='login.php';
	thisForm.submit();
    return true;
}



function __fncCheckDoctorLogin()
{

    var username = $('txtUserName').value;
    var password = $('txtUserPasswd').value;

    $('divDoctorLoginError').style.display = 'none';
    
	if(trim(username) == ''){
		$('divDoctorLoginError').style.display = 'block';
		$('divDoctorLoginError').innerHTML = _NO_USER_NAME;
		$('txtUserName').focus();
		return false;
	}else if(trim(password) == ''){
		$('divDoctorLoginError').style.display = 'block';
		$('divDoctorLoginError').innerHTML =  _NO_PASSWORD;
		$('txtUserPasswd').focus();
		return false;
	}

     var url = 'ajaxpost.php';

     
    new Ajax.Request(url, {
                      method: 'get',
                      parameters: {action: 'checkLogin', username: username, password: password },
                      onLoading : function(){$('imgAjaxLoader').style.display='block';},
                      onSuccess : fncLoginResult,
                      onError   : fncError
                      });


    $('txtUserName').focus();
    return false;
}



function fncLoginResult(reqObj)
{

   
    $('imgAjaxLoader').style.display    =   'none';

    resultSet = reqObj.responseText.split(_SEPERATOR);

  
    
    if(resultSet[1]!='OK')
        {
        $('divDoctorLoginError').style.display = 'block';
        $('divDoctorLoginError').innerHTML     = _INVALID_LOGIN;
        $('txtUserName').value      ='';
        $('txtUserPasswd').value    ='';
        return false;
        }
     else
        {

        window.location ='practitioner_cp.php';
        
        return true;
        }
    return true;

}

function fncError()
{
    alert("Ajax Error..");

}










function fncViewHospitalLogin()
{
    thisForm.txtWhat2Do.value='VIEW_HOSPITAL_LOGIN';
	thisForm.action='login.php';
	thisForm.submit();
    return true;
}

function __fncCheckHospital_LoginDetails(){

  	if(trim($('txtHospitalUserName').value) == ''){
		$('divHospitalLoginError').style.display = 'block';
		$('divHospitalLoginError').innerHTML = 'Please enter User Name';
		$('txtHospitalUserName').focus();
		return false;
	}
	if(trim($('txtHospitalUserPasswd').value) == ''){
		$('divHospitalLoginError').style.display = 'block';
		$('divHospitalLoginError').innerHTML = 'Please enter Password';
		$('txtHospitalUserPasswd').focus();
		return false;
	}

    thisForm.txtWhat2Do.value='HOSPITAL_LOGIN';
	thisForm.submit();
    return true;
}

function fncViewPatientLogin()
{
     thisForm.txtWhat2Do.value='VIEW_PATIENT_LOGIN';
	thisForm.action='login.php';
	

	thisForm.submit();
    return true;
}


function __fncCheckPatientLogin(){


    $('divPatientLoginError').style.display = 'none';

    if(trim($('txtPatientName').value) == ''){
		$('divPatientLoginError').style.display = 'block';
		$('divPatientLoginError').innerHTML = 'Please enter User Name';
		$('txtPatientName').focus();
		return false;
	}
	if(trim($('txtPatientPasswd').value) == ''){
		$('divPatientLoginError').style.display = 'block';
		$('divPatientLoginError').innerHTML = 'Please enter Password';
		$('txtPatientPasswd').focus();
		return false;
	}


     var username = $('txtPatientName').value;
    var password = $('txtPatientPasswd').value;

     var url = 'ajaxpost.php';


    new Ajax.Request(url, {
                      method: 'get',
                      parameters: {action: 'checkPatientLogin', username: username, password: password },
                      onLoading : function(){$('imgAjaxLoader').style.display='block';},
                      onSuccess : fncLoginPatientResult,
                      onError   : fncError
                      });

    
    return true;
}

function fncLoginPatientResult(reqObj)
{
    
      

    $('imgAjaxLoader').style.display    =   'none';


    resultSet = reqObj.responseText.split(_SEPERATOR);



    if(resultSet[1]!='OK')
        {
        $('divPatientLoginError').style.display = 'block';
        $('divPatientLoginError').innerHTML     = _INVALID_LOGIN;
        $('txtUserName').value      ='';
        $('txtUserPasswd').value    ='';
        return false;
        }
     else
        {

        window.location ='patient_cp.php';

        return true;
        }
    return true;

    
}
function fncViewPharmaLogin()
{
    thisForm.txtWhat2Do.value='VIEW_PHARMA_LOGIN';
	thisForm.action='login.php';
	thisForm.submit();
    return true;
}

function fncIsEnter(eventvar,usertype)
{
    if (eventvar.which == 13)
    {

     if(usertype=='DRLOGIN')
     {
      __fncCheckDoctorLogin();
     }
     else if(usertype=='PNTLOGIN')
     {
        __fncCheckPatientLogin();
     }


    }
        
}

function submitenter(myfield,e,usertype)
{
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
   // alert('Event'+event.which); return false;
    if (keycode == 13)
    {
    thisForm.txtWhat2Do.value = usertype;
	thisForm.submit();
    }
    else
    return true;
}



function __fncCheckMR_LoginDetails()
{

$('divMRLoginError').style.display = 'none';

if(trim($('txtRepUserName').value) == ''){
		$('divMRLoginError').style.display = 'block';
		$('divMRLoginError').innerHTML = 'Please enter User Name';
		$('txtRepUserName').focus();
		return false;
	}
	if(trim($('txtRepUserPasswd').value) == ''){
		$('divMRLoginError').style.display = 'block';
		$('divMRLoginError').innerHTML = 'Please enter Password';
		$('txtRepUserPasswd').focus();
		return false;
	}

	thisForm.txtWhat2Do.value='MR_LOGIN';
	thisForm.submit();
    return true;
}

function __fncCheckPharmaAdminLoginDetails()
{

$('divPharmaLoginError').style.display = 'none';

if(trim($('txtPharmaUserName').value) == ''){
		$('divPharmaLoginError').style.display = 'block';
		$('divPharmaLoginError').innerHTML = 'Please enter User Name';
		$('txtPharmaUserName').focus();
		return false;
	}
	if(trim($('txtPharmaUserPasswd').value) == ''){
		$('divPharmaLoginError').style.display = 'block';
		$('divPharmaLoginError').innerHTML = 'Please enter Password';
		$('txtPharmaUserPasswd').focus();
		return false;
	}

	thisForm.txtWhat2Do.value='PHARMA_LOGIN';
	thisForm.submit();
    return true;
}

function __fncShowHideAcceptForgotPassword(){
	if(getDivByID('divForgotPassword').style.display == 'none'){
		getDivByID('divForgotPassword').style.display = 'block';
	}else{
		getDivByID('divForgotPassword').style.display = 'none';
	}
}

function __fncShowHideAcceptForgotPasswordPatient(){
	if(getDivByID('divPatientForgotPassword').style.display == 'none'){
		getDivByID('divPatientForgotPassword').style.display = 'block';
	}else{
		getDivByID('divPatientForgotPassword').style.display = 'none';
	}
}

/* Function for sending mail */
function __fncSendMail(){
	if(trim(getDivByID('txtemail').value) == ''){
		getDivByID('divAdminLoginError').innerHTML = 'Please enter Email-id';
		getDivByID('divAdminLoginError').style.display = 'block';
		getDivByID('txtemail').focus();
		return;
	}
	if(!isValidEmail(getDivByID('txtemail').value)){
		getDivByID('divAdminLoginError').innerHTML = 'Please enter a valid Email-id';
		getDivByID('divAdminLoginError').style.display = 'block';
		getDivByID('txtemail').focus();
		return;
	}
	thisForm.txtWhat2Do.value='FORGOTPASSWORD';
	thisForm.submit();
}

function __fncSendMailPatient(){
	if(trim(getDivByID('txtPatientEmail').value) == ''){
		getDivByID('divAdminLoginError').innerHTML = 'Please enter Email-id';
		getDivByID('divAdminLoginError').style.display = 'block';
		getDivByID('txtemail').focus();
		return;
	}
	if(!isValidEmail(getDivByID('txtemail').value)){
		getDivByID('divAdminLoginError').innerHTML = 'Please enter a valid Email-id';
		getDivByID('divAdminLoginError').style.display = 'block';
		getDivByID('txtemail').focus();
		return;
	}
	thisForm.txtWhat2Do.value='FORGOTPASSWORD';
	thisForm.submit();
}



/*New Login Section*/

function __fncSelectPractitionerTab(tabbed){

    

	$('div_Id_LoginTab_Top_Right1').style.display = "block";
	$('div_Id_LoginTab_Top_Left1').style.display = "block";
	$('div_Id_LoginTab_Top_Right1').style.backgroundImage = "url("+thisForm.imgFolder.value+"login_tab_05.jpg)";
	$('div_Id_LoginTab_Top_Left1').style.backgroundImage = "url("+thisForm.imgFolder.value+"login_tab_03.jpg)";
	$('div_Id_LoginTab_Top_Center1').style.backgroundImage = "url("+thisForm.imgFolder.value+"login_tab_04.jpg)";
	
	
	$('div_Id_LoginTab_Top_Right2').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center2').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left2').style.backgroundImage = "none";
	
	$('div_Id_LoginTab_Top_Right3').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left3').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center3').style.backgroundImage = "none";

	$('div_Id_LoginTab_Top_Right4').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left4').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center4').style.backgroundImage = "none";
	
	$('div_Id_LoginTab_Top_Right5').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left5').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center5').style.backgroundImage = "none";

    
    
    if(tabbed=='PRACTITIONER')
        {
        $('divPractLoginBox').style.display = 'none';
        $('divPractLoginBox').style.display = 'block';
        $('divPatientLoginBox').style.display = "none";
        $('divHospitalLoginBox').style.display = "none";
        $('divRepsLoginBox').style.display = "none";

        $('txtUserName').focus();
        $('divPharmaLoginBox').style.display = "none";
        
        $('txtUserName').tabIndex = 1;
        $('txtUserPasswd').tabIndex = 2;
        $('btnLogin').tabIndex = 3;
        $('linkSignup').tabIndex = 4;
        $('linkForgot').tabIndex = 5;
        

        }
        
   
 return true;
	
}

function __fncSelectClientTab(tabbed)
{

	$('div_Id_LoginTab_Top_Right1').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left1').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center1').style.backgroundImage = "none";
	
	$('div_Id_LoginTab_Top_Right2').style.display = "block";
	$('div_Id_LoginTab_Top_Left2').style.display = "block";
	$('div_Id_LoginTab_Top_Right2').style.backgroundImage = "url("+thisForm.imgFolder.value+"login_tab_05.jpg)";
	$('div_Id_LoginTab_Top_Left2').style.backgroundImage = "url("+thisForm.imgFolder.value+"login_tab_03.jpg)";
	$('div_Id_LoginTab_Top_Center2').style.backgroundImage = "url("+thisForm.imgFolder.value+"login_tab_04.jpg)";
	
	$('div_Id_LoginTab_Top_Right3').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left3').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center3').style.backgroundImage = "none";

	$('div_Id_LoginTab_Top_Right4').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left4').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center4').style.backgroundImage = "none";
	
	$('div_Id_LoginTab_Top_Right5').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left5').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center5').style.backgroundImage = "none";


    if(tabbed=='PATIENTS')
    {
    $('divPractLoginBox').style.display = "none";
    $('divPatientLoginBox').style.display = "block";
    $('txtPatientName').focus();
    $('divHospitalLoginBox').style.display = "none";
    $('divRepsLoginBox').style.display = "none";
    $('divPharmaLoginBox').style.display = "none";

    $('txtPatientName').tabIndex = 4;
    $('txtPatientPasswd').tabIndex = 5;
    $('btnLoginPatient').tabIndex = 6;
    }

    return true;
}

function __fncSelectHospitalTab(tabbed){

   
	$('div_Id_LoginTab_Top_Right1').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left1').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center1').style.backgroundImage = "none";
	
	$('div_Id_LoginTab_Top_Right2').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left2').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center2').style.backgroundImage = "none";
	
	$('div_Id_LoginTab_Top_Right3').style.display = "block";
	$('div_Id_LoginTab_Top_Left3').style.display = "block";
	$('div_Id_LoginTab_Top_Right3').style.backgroundImage = "url("+thisForm.imgFolder.value+"login_tab_05.jpg)";
	$('div_Id_LoginTab_Top_Left3').style.backgroundImage = "url("+thisForm.imgFolder.value+"login_tab_03.jpg)";
	$('div_Id_LoginTab_Top_Center3').style.backgroundImage = "url("+thisForm.imgFolder.value+"login_tab_04.jpg)";
	
	$('div_Id_LoginTab_Top_Right4').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left4').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center4').style.backgroundImage = "none";
	
	$('div_Id_LoginTab_Top_Right5').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left5').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center5').style.backgroundImage = "none";

    if(tabbed=='HOSPITALS')
     {

        $('divPractLoginBox').style.display = "none";
        $('divPatientLoginBox').style.display = "none";
        $('divHospitalLoginBox').style.display = "block";
        $('txtHospitalUserName').focus();
        $('divRepsLoginBox').style.display = "none";
         $('divPharmaLoginBox').style.display = "none";
        
        $('txtHospitalUserName').tabIndex = 7;
        $('txtHospitalUserPasswd').tabIndex = 8;
        $('btnLoginHospital').tabIndex = 9;
     }

     return true;
}

function __fncSelectMedicalRepTab(tabbed){

	$('div_Id_LoginTab_Top_Right1').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left1').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center1').style.backgroundImage = "none";
	
	$('div_Id_LoginTab_Top_Right2').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left2').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center2').style.backgroundImage = "none";
	
	$('div_Id_LoginTab_Top_Right3').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left3').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center3').style.backgroundImage = "none";

	$('div_Id_LoginTab_Top_Right4').style.display = "block";
	$('div_Id_LoginTab_Top_Left4').style.display = "block";
	$('div_Id_LoginTab_Top_Right4').style.backgroundImage = "url("+thisForm.imgFolder.value+"login_tab_05.jpg)";
	$('div_Id_LoginTab_Top_Left4').style.backgroundImage = "url("+thisForm.imgFolder.value+"login_tab_03.jpg)";
	$('div_Id_LoginTab_Top_Center4').style.backgroundImage = "url("+thisForm.imgFolder.value+"login_tab_04.jpg)";
	
	$('div_Id_LoginTab_Top_Right5').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left5').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center5').style.backgroundImage = "none";

    if(tabbed=='MEDIREP')
     {
	$('divPractLoginBox').style.display = "none";
    $('divPatientLoginBox').style.display = "none";
    $('divHospitalLoginBox').style.display = "none";
    $('divRepsLoginBox').style.display = "block";
    $('txtRepUserName').focus();
     $('divPharmaLoginBox').style.display = "none";
     }
}

function __fncSelectPharmacyTab(tabbed){

	$('div_Id_LoginTab_Top_Right1').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left1').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center1').style.backgroundImage = "none";
	
	$('div_Id_LoginTab_Top_Right2').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left2').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center2').style.backgroundImage = "none";
	
	$('div_Id_LoginTab_Top_Right3').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left3').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center3').style.backgroundImage = "none";

	$('div_Id_LoginTab_Top_Right4').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Left4').style.backgroundImage = "none";
	$('div_Id_LoginTab_Top_Center4').style.backgroundImage = "none";
	
	$('div_Id_LoginTab_Top_Right5').style.display = "block";
	$('div_Id_LoginTab_Top_Left5').style.display = "block";
	$('div_Id_LoginTab_Top_Right5').style.backgroundImage = "url("+thisForm.imgFolder.value+"login_tab_05.jpg)";
	$('div_Id_LoginTab_Top_Left5').style.backgroundImage = "url("+thisForm.imgFolder.value+"login_tab_03.jpg)";
	$('div_Id_LoginTab_Top_Center5').style.backgroundImage = "url("+thisForm.imgFolder.value+"login_tab_04.jpg)";	

    if(tabbed=='PHARMA')
    {
        $('divPractLoginBox').style.display = "none";
        $('divPatientLoginBox').style.display = "none";
        $('divHospitalLoginBox').style.display = "none";
        $('divRepsLoginBox').style.display = "none";
        $('divPharmaLoginBox').style.display = "block";
        $('txtPharmaUserName').focus();


    }
}



//Added By Prasad On 17-11-2009

function __fncCheckPharma_LoginDetails()
{
   
    $('divPharmaLoginError').style.display = 'none';

    if(trim($('txtPharmaUserName').value) == ''){
        $('divPharmaLoginError').style.display = 'block';
        $('divPharmaLoginError').innerHTML = 'Please enter User Name';
        $('txtPharmaUserName').focus();
        return false;
    }else if(trim($('txtPharmaUserPasswd').value) == ''){
        $('divPharmaLoginError').style.display = 'block';
        $('divPharmaLoginError').innerHTML = 'Please enter Password';
        $('txtPharmaUserPasswd').focus();
        return false;
    }else if(($("cboAuthentication").value)=='exe')
    {

      
        thisForm.txtWhat2Do.value='EXECUTIVE_LOGIN';
        thisForm.submit();
        
    }
    else if(($("cboAuthentication").value)=='comp')
    {

        thisForm.txtWhat2Do.value='COMPANY_LOGIN';
        thisForm.submit();
        
    }

return true;

}



