// JavaScript Document
function sam()
{
    alert("asdf");
}
function setWarning(errId,boxId,errmsg)
{
    $(errId).innerHTML=errmsg;
    $(errId).style.display="block";
    $(boxId).style.border="1px solid #FF0000";
    $(boxId).style.background="#FFF2F2";
}

function removeWarning(errId,boxId)
{
    if($(boxId).value!="")
    {
        $(errId).innerHTML="";
        $(errId).style.display="none";
        $(boxId).style.border="1px solid #0080C0";
        $(boxId).style.background="#FFFFFF";
    }
}
function setWarning1(errId,boxId,errmsg)
{
    
    $("#"+errId).html(errmsg);
    $("#"+errId).show();
    
    //$(boxId).css("border","1px solid #FF0000");
    //$(boxId).css("background","#FFF2F2");
}

function removeWarning1(errId,boxId)
{
    //alert(errId);
    if($(boxId).value!="")
    {
        $(errId).html("");
        $(errId).hide()
        //$(boxId).css("border","1px solid #0080C0");
        //$(boxId).css("background","#FFFFFF");
    }
}


function checkLogin(frmlogin)
{
//alert(2);
    var Empty=false;
    var errNo=0;

    //frmlogin=document.frmlogin;
    if(isEmpty(frmlogin.txtmobile))
    {

        setWarning1('errmsg_txtmobile','mobileid','Please enter your  mobile no');
        errNo++;
    }
    else
    {

        mobile=($('#mobileid').val());
        l=mobile.length;
        if(l<10)
        {
            setWarning1('errmsg_txtmobile','mobileid','Enter valid mobile no & must be 10 digit.');
            errNo++;
        }
        else
        {
            fm=(mobile.substr(0,1));
            if(fm=='9' || fm=='8' || fm=='7')
            {
				 removeWarning1('errmsg_txtmobile','mobileid')
               
            }
            else
            {
                setWarning1('errmsg_txtmobile','mobileid','Enter valid mobile no .');
                errNo++;
            }
        }

    }


    if( isEmpty(frmlogin.txtpassword))
    {

        setWarning1('errmsg_txtpassword','passwordid','Please Enter Your Password');
        errNo++;
    }
    else
    {
        removeWarning1('errmsg_txtpassword','passwordid')
    }

    if(errNo>0){
        return false;
    } else {
        
        checkUserLoginValid();
    //return true;
    }
}

function checkUserLoginValid()
{

    $('#saveid').attr("disabled",true);
    $("#newid").hide();

     $.post("checkUserLogin.php",{
            mobileid: $('#mobileid').val(),
            passwordid:$('#passwordid').val()
            },
            function(data)
            {
                //alert(data)
                    $('#saveid').attr("disabled",false);

                    n=trim(data);
                   // alert(n);
                    n=n*1;

                    if(n==2)
                    {

                        document.frmlogin.txtpassword.value="";
                        document.frmlogin.txtpassword.focus();
                        $('#warningid1').show();
                        $('#warningid1').html("Invalid Password");

                    }
                    else if(n==0)
                    {

                        $('#newid').show();
                        $('#warningid1').show();
                        $('#warningid1').html("Invalid Mobileno and Password");
                    }
                    else
                    {
                        //alert("Login successfully");
                        //$('warningid').style.display="none";
                        window.location="myAccount.php?rpt_mobileno="+$("#mobileid").val();
                    }
             });


}

function showUserLoginValid(req)
{
	
    $('saveid').disabled=false;
	
    n=trim(req.responseText);
	//alert(n);
	n=n*1;

    if(n==2)
    {
		
        document.frmlogin2.txtpassword.value="";	
        document.frmlogin2.txtpassword.focus();
        $('warningid1').style.display="block";
        $('warningid1').innerHTML="Invalid Password";
		
    }
    else if(n==0)
    {
		
		$('newid').style.display="block";
        $('warningid1').style.display="block";
        $('warningid1').innerHTML="Invalid Mobileno and Password";
    }
    else
    {
        //alert("Login successfully");
        //$('warningid').style.display="none";
        window.location="myAccount.php?rpt_mobileno="+$("mobileid").value;
    }
}


function checkLogin1(frmlogin1)
{
//alert(34);
    var Empty=false;
    var errNo=0;

    //frmlogin=document.frmlogin;

    if(isEmpty(frmlogin1.txtmobile1))
    {
        
        setWarning1('errmsg_txtmobile1','mobileid1','Enter ur mobile no/cafe no');
        errNo++;
    }
    else
    {

        /*mobile=($('mobileid1').value);
l=mobile.length;
if(l<10)
{
        setWarning('errmsg_txtmobile1','mobileid1','Please enter valid mobile no, The mobile no starts with 9 or 8  and it should be 10 digit.');
        errNo++;
}
else
{
        fm=(mobile.substr(0,1));
        if(fm!='9')
        {
                setWarning('errmsg_txtmobile1','mobileid1','Please enter valid mobile no, The mobile no must starts with 9 or 8 .');
        errNo++;
        }
        else
        {*/
        removeWarning1('errmsg_txtmobile1','mobileid1')
    /*	}
}*/

    }


    if( isEmpty(frmlogin1.txtpassword1))
    {

        setWarning1('errmsg_txtpassword1','passwordid1','Enter Your Password');
        errNo++;
    }
    else
    {
        removeWarning1('errmsg_txtpassword1','passwordid1')
    }

    if(errNo>0){
      //  return false;
    } else {
        checkCafeLoginValid();
    //return true;
    }
}


function checkCafeLoginValid()
{

    //$('saveid1').disabled=true;
    $('#saveid1').attr("disabled",true);
    $.post("checkCafeLogin.php",{
            mobileid: $('#mobileid1').val(),
            passwordid:$('#passwordid1').val()
            },
      function(data)
      {
       $('#saveid1').attr("disabled",false);
                n=trim(data);
                    //alert(n);
                n=n*1;

                if(n==2)
                {
                    document.frmlogin1.txtpassword1.value="";
                    document.frmlogin1.txtpassword1.focus();
                    $('#warningid2').show();
                    $('#warningid2').html("Invalid Password");
                }
                else if(n==0)
                {
                    $('#warningid2').show();
                    $('#warningid2').html("Invalid cafe no and Password");
                }
                    else if(n==3)
                {
                    window.location="cafeRegister.php";
                }
                    else if(n==5)
                {
                   //window.location="rptCafeDateReport.php";
                            window.location="cafeHomeNew.php";
                }
                else
                {
                    //alert("Login successfully");
                    //$('warningid').style.display="none";
                            //window.location="rptCafeDateReport.php";
                            window.location="cafeHomeNew.php";
                }

      
    });

}

function showCafeLoginValid(req)
{

    $('saveid1').disabled=false;
    n=trim(req.responseText);
	alert(n);
    n=n*1;

    if(n==2)
    {
        document.frmlogin1.txtpassword1.value="";
        document.frmlogin1.txtpassword1.focus();
        $('warningid2').style.display="block";
        $('warningid2').innerHTML="Invalid Password";
    }
    else if(n==0)
    {
        $('warningid2').style.display="block";
        $('warningid2').innerHTML="Invalid Mobileno and Password";
    }
	else if(n==3)
    {
        window.location="cafeRegister.php";
    }
	else if(n==5)
    {
       //window.location="rptCafeDateReport.php";
	  	window.location="cafeHomeNew.php";
    }
    else
    {
        //alert("Login successfully");
        //$('warningid').style.display="none";
		//window.location="rptCafeDateReport.php";
		window.location="cafeHomeNew.php";
    }
}


function checkAdvertiserLogin(frmlogin3)
{
//alert(12);
    var Empty=false;
    var errNo=0;

    //frmlogin=document.frmlogin;

    if(isEmpty(frmlogin3.txtuserid))
    {

        setWarning1('errmsg_txtuserid','userid1','Enter Your Email ID');
        errNo++;
    }
    else
    {
        removeWarning1('errmsg_txtuserid','userid1');
	}


    if( isEmpty(frmlogin3.txtpassword3))
    {

        setWarning1('errmsg_txtpassword3','passwordid3','Enter Your Password');
        errNo++;
    }
    else
    {
        removeWarning1('errmsg_txtpassword3','passwordid3')
    }

    if(errNo>0){
        return false;
    } else {
        checkAdvertiserLoginValid();
    //return true;
    }
}


function checkAdvertiserLoginValid()
{
//alert(2323);
    $('#saveid2').disabled=true;
    $.post("advertiser/checkAdvertiserLogin.php",{
            userid: $('#userid1').val(),
            passwordid:$('#passwordid3').val()
            },
            function(data)
            {
                $('#saveid2').disabled=false;
	
                n=trim(data);
                    //alert(n);
                n=n*1;
                    if(n==3)
                {
                    document.frmlogin1.txtpassword1.value="";
                    document.frmlogin1.txtpassword1.focus();
                    $('#warningid3').show();
                    $('#warningid3').html("You have to activate first. Please Click the activation link from your mail");
                }
               else if(n==2)
                {
                    document.frmlogin1.txtpassword1.value="";
                    document.frmlogin1.txtpassword1.focus();
                    $('#warningid3').show();
                    $('#warningid3').html("Invalid Password");
                }
                else if(n==0)
                {
                    $('#warningid3').show();
                    $('#warningid3').html("Invalid user name and password");
                }
                else if(n==1)
                {
                    window.location="advertiser/advertiserHome.php";
                }
        
    });

}

function showAdvertiserLoginValid(req)
{
	
    $('saveid2').disabled=false;
    n=trim(req.responseText);
	//alert(n);
    n=n*1;
 	if(n==3)
    {
        document.frmlogin1.txtpassword1.value="";
        document.frmlogin1.txtpassword1.focus();
        $('warningid3').style.display="block";
        $('warningid3').innerHTML="You have to activate first. Please Click the activation link from your mail";
    }
   else if(n==2)
    {
        document.frmlogin1.txtpassword1.value="";
        document.frmlogin1.txtpassword1.focus();
        $('warningid3').style.display="block";
        $('warningid3').innerHTML="Invalid Password";
    }
    else if(n==0)
    {
        $('warningid3').style.display="block";
        $('warningid3').innerHTML="Invalid user name and password";
    }
    else if(n==1)
    {
       window.location="advertiser/advertiserHome.php";
    }
}

function showAdvertiserLoginValid1(req)
{
	
    $('saveid2').disabled=false;
	
    n=trim(req.responseText);
	
    n=n*1;
 	if(n==3)
    {
        $('warningid3').style.display="block";
        $('warningid3').innerHTML="You have to activate first. Please Click the activation link from your mail";
        document.frmlogin1.txtpassword1.value="";
        document.frmlogin1.txtpassword1.focus();
        
    }
   else if(n==2)
    {
        document.frmlogin1.txtpassword1.value="";
        document.frmlogin1.txtpassword1.focus();
        $('warningid3').style.display="block";
        $('warningid3').innerHTML="Invalid Password";
    }
    else if(n==0)
    {
        $('warningid3').style.display="block";
        $('warningid3').innerHTML="Invalid user name and password";
    }
    else if(n==1)
    {
        window.location="advertiser/advertiserHome.php";
    }
}

function showForgetPassword()
{
    $('#forgetPassword').show();
    $('#cafelogin').hide();
	
}
function showForgetPassword1()
{
    //alert(23);
    $('#forgetPassword').show();
    $('#userlogin').hide();

}
function showForgetPassword2()
{
    $('#forgetPassword3').show();
    $('#adv_login').hide();
}
function getCafeLogin1()
{
    $('#forgetPassword').hide();
    $('#cafelogin').show();
	
}
function getUserLogin1()
{
    $('#forgetPassword').hide();
    $('#userlogin').show();

}
function getAdvertiserLogin1()
{
    $('#forgetPassword3').hide();
    $('#adv_login').show();
}

