/******************************************************************************************************
    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 __fncCheckDoctorLogin()
{

    var username = $('#txtUserName').val();
    var password = $('#txtUserPasswd').val();

    $('#divDoctorLoginError').hide();

	if(trim(username) == ''){
		$('#divDoctorLoginError').show();
		$('#divDoctorLoginError').html(_NO_USER_NAME);
		$('#txtUserName').focus();
		return false;
	}else if(trim(password) == ''){
		$('#divDoctorLoginError').show();
		$('#divDoctorLoginError').show(_NO_PASSWORD);
		$('#txtUserPasswd').focus();
		return false;
	}

     $('#imgAjaxLoader').show();
     
     $.ajax({
			type : 'POST',
			url : 'ajaxpost.php',
			dataType : 'json',
			data: {
				action: 'CHECK_DR_LOGIN', username: username, password: password
			},
			success : function(data){

                $('#imgAjaxLoader').hide();



  				if(data.status==true && data.msg.toLowerCase()==="ok")
				{

                    self.location = _http_root+'doctor_dashboard.php';
                    
					return true;
				}
				else
				{

			
                    $('#divDoctorLoginError').show();
                    $('#divDoctorLoginError').html(_INVALID_LOGIN);
                    $('#txtUserName').val("")
                    $('#txtUserPasswd').val("");
                    $('#txtUserName').focus();
                    return false;

				}



			},
			error : function(XMLHttpRequest, textStatus, errorThrown)
            {

                alert(textStatus);
				alert(XMLHttpRequest.responseText);
          
			}
		});

        
   
    return false;
}

function __fncCheckPatientLogin(){


    $('#divPatientLoginError').hide();

    if(trim($('#txtPatientName').val()) == ''){
		$('#divPatientLoginError').show();
		$('#divPatientLoginError').html('Please enter User Name');
		$('#txtPatientName').focus();
		return false;
	}
	if(trim($('#txtPatientPasswd').val()) == ''){
		$('#divPatientLoginError').show();
		$('#divPatientLoginError').html('Please enter Password');
		$('#txtPatientPasswd').focus();
		return false;
	}

 var username = $('#txtPatientName').val();
    var password = $('#txtPatientPasswd').val();
   

    $('#imgAjaxLoader').show();

    $.ajax({
			type : 'POST',
			url : 'ajaxpost.php',
			dataType : 'json',
			data: {
				action: 'CHECK_PATIENT_LOGIN', username: username, password: password
			},
			success : function(data){

                $('#imgAjaxLoader').hide();



  				if(data.status==true && data.msg.toLowerCase()==="ok")
				{

                    self.location = _http_root+'patient_dashboard.php';
                    
					return true;
                    
				}
				else
				{


                    $('#divPatientLoginError').show();
                    $('#divPatientLoginError').html(_INVALID_LOGIN);
                    $('#txtPatientName').val("")
                    $('#txtPatientPasswd').val("");
                    $('#txtPatientName').focus();

    

                    return false;

				}



			},
			error : function(XMLHttpRequest, textStatus, errorThrown)
            {

                alert(textStatus);
				alert(XMLHttpRequest.responseText);

			}
		});


        
  


    return true;
}

function __fncCheckMrLogin(){


    $('#divMrLoginError').hide();

    if(trim($('#txtMrName').val()) == ''){
		$('#divMrLoginError').show();
		$('#divMrLoginError').html('Please enter User Name');
		$('#txtMrName').focus();
		return false;
	}
	if(trim($('#txtMrPassword').val()) == ''){
		$('#divMrLoginError').show();
		$('#divMrLoginError').html('Please enter Password');
		$('#txtMrPassword').focus();
		return false;
	}

 var username = $('#txtMrName').val();
    var password = $('#txtMrPassword').val();


    $('#imgAjaxLoader').show();

    $.ajax({
			type : 'POST',
			url : 'ajaxpost.php',
			dataType : 'json',
			data: {
				action: 'CHECK_MR_LOGIN', username: username, password: password
			},
			success : function(data){

                $('#imgAjaxLoader').hide();

  				if(data.status==true && data.msg.toLowerCase()==="ok")
				{
                    //window.location ='pharmasales_cp.php';

                    self.location = _http_root+'pharmasales_cp.php';
                    
					return true;
				}
				else
				{

                    $('#divMrLoginError').show();
                    $('#divMrLoginError').html(_INVALID_LOGIN);
                    $('#txtMrName').val("")
                    $('#txtMrPassword').val("");
                    $('#txtMrName').focus();

                    return false;

				}



			},
			error : function(XMLHttpRequest, textStatus, errorThrown)
            {

                alert(textStatus);
				alert(XMLHttpRequest.responseText);

			}
		});






    return true;
}

function fncIsEnter(eventvar,usertype)
{
    if (eventvar.which == 13)
    {

     if(usertype=='DRLOGIN')
     {
      __fncCheckDoctorLogin();
     }
     else if(usertype=='PNTLOGIN')
     {
        __fncCheckPatientLogin();
     }
     else if(usertype=='MRLOGIN')
     {
        __fncCheckMrLogin();
     }


    }

}







































function __fncViewDoctorLogin()
{
        
    thisForm.txtWhat2Do.value='VIEW_PRACT_LOGIN';
	thisForm.action='login.php';
	thisForm.submit();
    return true;
}








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 fncViewPharmaLogin()
{
    thisForm.txtWhat2Do.value='VIEW_PHARMA_LOGIN';
	thisForm.action='login.php';
	thisForm.submit();
    return true;
}



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;

}




