﻿// JScript File
//VAlidate Dropdownlist
function checkSelected()
{
  
  var drdFranchise = document.getElementById("ucAssignFranchiseOrFranchiseCategoryToSpecial1_drdFranchisee");
  var drdFranchiseCat = document.getElementById("ucAssignFranchiseOrFranchiseCategoryToSpecial1_drdFranchiseeCat");
  if(drdFranchise.selectedIndex == 0 && drdFranchiseCat.selectedIndex == 0)
    {
      alert("Please select either franchise or franchise category");
      return false;
    } 
}
//
function validateFranchise()
{

    txtemail=document.getElementById("UcAddEditFranchise1_txtemail");
    txtfname=document.getElementById("UcAddEditFranchise1_txtfranchiseName");
    drpfcat=document.getElementById("UcAddEditFranchise1_drpfranchiseCategory");
    txtfcat=document.getElementById("UcAddEditFranchise1_txtfranchiseCategory");
    txtcname=document.getElementById("UcAddEditFranchise1_txtcontactName");
    txtaddr=document.getElementById("UcAddEditFranchise1_txtaddress");
    txtcity=document.getElementById("UcAddEditFranchise1_txtcity");
    drpstate=document.getElementById("UcAddEditFranchise1_drpstate");
    txtpostcode=document.getElementById("UcAddEditFranchise1_txtpostcode");
    txtphone=document.getElementById("UcAddEditFranchise1_txtphone");
    txtfax=document.getElementById("UcAddEditFranchise1_txtfax");
    txtmobile=document.getElementById("UcAddEditFranchise1_txtmobile");    
    txtimage=document.getElementById("UcAddEditFranchise1_txtImage");
    txtOldPsw=document.getElementById("UcAddEditFranchise1_txtOldPassword");
    txtpassword=document.getElementById("UcAddEditFranchise1_txtpassword");
    txtConfirmPassword=document.getElementById("UcAddEditFranchise1_txtConfirmPassword");
    hidpasswordexists=document.getElementById("UcAddEditFranchise1_hidpasswordexists");
    txtlogon = document.getElementById("UcAddEditFranchise1_txtLogon");    
    if(Trim(txtfname.value) == "")
    {
        alert("Please Enter Franchise Name");
        txtfname.value="";
        txtfname.focus();
        return false;
    }
    if(drpfcat.value == "")
    {
        alert("Please Select Franchise Category");
        drpfcat.focus();
        return false;
    }
    if(drpfcat.value =="Other")
    {
        if(Trim(txtfcat.value)=="")
        {
            alert("Please Enter Franchise Category");
            txtfcat.value="";
            txtfcat.focus();
            return false;
        }
    }
    if(Trim(txtcname.value)=="")
    {
        alert("Please Enter Contact Name");
        txtcname.value="";
        txtcname.focus();
        return false;
    }
    if(Trim(txtaddr.value)=="")
    {
        alert("Please Enter Address");
        txtaddr.value="";
        txtaddr.focus();
        return false;
    }
    if(Trim(txtcity.value)=="")
    {
        alert("Please Enter City");
        txtcity.value="";
        txtcity.focus();
        return false;
    }
    if(drpstate.value=="")
    {
        alert("Please Select State");
        drpstate.focus();
        return false;
    }
    if(Trim(txtpostcode.value) == "")
    {
        alert("Please Enter PostCode");
         txtpostcode.value="";
        txtpostcode.focus();
        return false;
    }
    if(Trim(txtpostcode.value) != "")
    {
        var anum=/(^\d+$)|(^\d+\.\d+$)/;
        var matchno=txtpostcode.value.match(anum);
        if (matchno==null)
        {
            alert("PostCode must be Integer only!");       
            txtpostcode.value="";
            txtpostcode.focus();
            return false;
       }
    }
       if(txtpostcode.value!="")
       {
            var pc=txtpostcode.value;
            if(pc.length > 4)
            {
                alert("Post Code Is Limited to 4 digits only");
                return false;
            }
       }
    if(Trim(txtphone.value) =="")
    {
        alert("Please Enter Phone Number");
        txtphone.value="";
        txtphone.focus();
        return false;
    }
    if(Trim(txtphone.value) != "")
       {
           if(!Ph_no(Trim(txtphone.value)))
           {
             alert("Please Enter Valid Phone Number");
             txtphone.value="";
             txtphone.focus();
             return false;
           }
       }
    if(Trim(txtfax.value)!="")
    {
        if(!Ph_no(txtfax.value))
        {
            alert("Please Enter Valid Fax Number");
            txtfax.value="";
            txtfax.focus();
            return false;
        }
    }
    if(Trim(txtmobile.value) == "")
    {
        alert("Please Enter Mobile Number");
         txtmobile.value="";
        txtmobile.focus();
        return false;
    }
    if(Trim(txtmobile.value) != "")
       {
           if(!Ph_no(Trim(txtmobile.value)))
           {
             alert("Please Enter Valid Mobile Number");
             txtmobile.value="";
             txtmobile.focus();
             return false;
           }
       }
   if(Trim(txtemail.value)=="")
   {
        alert("Please Enter Email");
        txtemail.value="";
        txtemail.focus();
        return false;     
   }   
   if(Trim(txtemail.value) != "")
   {
            var filter=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
            if (filter.test(txtemail.value))
            {
                              
            }
            else
            {
                alert("Please enter a valid email address!");
                txtemail.focus();
                return false;
            }      
//     if(!ValidateEmail(txtemail))
//     {
//       //alert("Please Enter Valid Email Address.");
//       txtemail.focus();
//       return false;
//     }
   }
   if(txtimage.value!="")
   {
        if(!checkFileExtension(txtimage))
        {
            txtimage.focus();
            return false;
        }
        var img =new Image();
        img.src = 'file:///' + txtimage.value;
        var size =img.fileSize;
        if(size=="0")
        {
            alert("Size of image is not valid")
            return false();
        }
        
   }
   if(Trim(txtlogon.value) == "")
   {
        alert("Please Enter Logon");
        txtlogon.value="";
        txtlogon.focus();
        return false;
   }
   if(hidpasswordexists.value =="No")
   {
       if(Trim(txtpassword.value) == "")
       {
            alert("Please Enter Your Password");
            txtpassword.value="";
            txtpassword.focus();
            return false;
       }
       if(Trim(txtpassword.value).length < 6 || Trim(txtpassword.value).length > 20)
       {
            alert("Password should be within 6 to 20 characters.");
            txtpassword.value="";
            txtpassword.focus();
            return false;
       }
       if(Trim(txtConfirmPassword.value) == "")
       {
            alert("Please Enter Confirm Password");
            txtConfirmPassword.value="";
            txtConfirmPassword.focus();
            return false;
       }
       if(Trim(txtpassword.value) != Trim(txtConfirmPassword.value))
       {
            alert("Password and Confirm Password are different.");
            txtpassword.value="";
            txtConfirmPassword.value="";
            txtpassword.focus();
            return false;
       }
   }
   else
   {
        if(Trim(txtpassword.value) != "")
        {   
            if(Trim(txtOldPsw.value) == "")
            {
                alert("Please Enter Old Password");
                txtOldPsw.value="";
                txtOldPsw.focus();
                return false;         
            }
            if(Trim(txtpassword.value).length < 6 || Trim(txtpassword.value).length > 20)
            {
                alert("Password should be within 6 to 20 characters.");
                txtpassword.value="";
                txtpassword.focus();
                return false;
            }
            if(Trim(txtConfirmPassword.value) == "")
            {
                alert("Please Enter Confirm Password");
                txtConfirmPassword.value="";
                txtConfirmPassword.focus();
                return false;
            }
            if(Trim(txtpassword.value) != Trim(txtConfirmPassword.value))
            {
                alert("Password and Confirm Password are different.");
                txtpassword.value="";
                txtConfirmPassword.value="";
                txtpassword.focus();
                return false;
            }
        }
   }   
}

function highlightconfirmpassword()
{
    txtpassword=document.getElementById("UcAddEditFranchise1_txtpassword");
    txtConfirmPassword=document.getElementById("UcAddEditFranchise1_txtConfirmPassword");
    lblRFV1=document.getElementById("UcAddEditFranchise1_lblRFV1");
}

function hidedrp()
{
     drpfcat=document.getElementById("UcAddEditFranchise1_drpfranchiseCategory");
     txtfcat=document.getElementById("UcAddEditFranchise1_txtfranchiseCategory");
     if(drpfcat.value=="Other")
     {
        txtfcat.disabled=false;
        txtfcat.value="";
     }
     else
     {
        txtfcat.disabled=true;
        txtfcat.value="";
     }
}

function CheckEmailExistsForFranchise(email)
{

    txtemail=document.getElementById("UcAddEditFranchise1_txtemail");
    if(email != TRIM(txtemail.value))
    {
        if(TRIM(txtemail.value)!="")
        {
            CheckEmailExists(txtemail.value,ServerSideCallBack_CheckEmailExists);
        }
    }
}

function ServerSideCallBack_CheckEmailExists(response)
{

    txtemail=document.getElementById("UcAddEditFranchise1_txtemail");
    if(response.Rows.length != 0 )
    {
        alert("Email Id is already in use.Please select another email");
        txtemail.value="";
        txtemail.focus();
        return false;
    }
    else
    {
        return true;
    }
}

function CheckLogonExistsForFranchise(logon)
{

    txtlogon=document.getElementById("UcAddEditFranchise1_txtlogon");
    if(logon != TRIM(txtlogon.value))
    {
        if(TRIM(txtlogon.value)!="")
        {
            CheckLogonExists(txtlogon.value,ServerSideCallBack_CheckLogonExists);
        }
    }
}

function ServerSideCallBack_CheckLogonExists(response)
{

    txtlogon=document.getElementById("UcAddEditFranchise1_txtlogon");
    if(response.Rows.length != 0 )
    {
        alert("logon is already in use.Please select another logon");
        txtlogon.value="";
        txtlogon.focus();
        return false;
    }
    else
    {
        return true;
    }
}


function checkFileExtension(elem) 
{
        var filePath = elem.value;

        if(filePath.indexOf('.') == -1)
            return false;
        
        var validExtensions = new Array();
        var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();
    
        validExtensions[0] = 'jpg';
        validExtensions[1] = 'jpeg';
        //validExtensions[2] = 'bmp';
        //validExtensions[3] = 'png';
        validExtensions[4] = 'gif';  
       
        for(var i = 0; i < validExtensions.length; i++) {
            if(ext == validExtensions[i])
                return true;
        }

        //alert('The file extension ' + ext.toUpperCase() + ' is not allowed!');
        alert('The file extension ' + ext + ' is not allowed!');
        filePath.value='';
        
           return false;
    }
    
    function validateSpecials()
{ 
    var title = document.getElementById("UcAddEditSpecials1_txttitle");
    var price = document.getElementById("UcAddEditSpecials1_txtprice");
    var rank = document.getElementById("UcAddEditSpecials1_txtrank");
    var desc = document.getElementById("UcAddEditSpecials1_txtdescription");
    var termsAndCond = document.getElementById("UcAddEditSpecials1_txtTermsAndCond");
    //var edate = document.getElementById("UcAddEditSpecials1_txtendDate");
    var image = document.getElementById("UcAddEditSpecials1_txtimage");
     var hidimgexists = document.getElementById("UcAddEditSpecials1_hidimgexists");
    if(TRIM(title.value)=="")
    {
        alert("Please Enter Title");
        title.value="";
        title.focus();        
        return false;
    } 
    if(TRIM(desc.value)=="")
    {
        alert("Please Enter Description");
        desc.value="";
        desc.focus();
        return false;    
    }
    if(desc.value.length > 100)
    {    
        alert("Description must be less than 100 Charector");
        desc.focus();
        return false;   
    }   
    if(TRIM(price.value)=="")
    {
        alert("Please Enter Price");
        price.focus();
        return false;
    }
    
//    if(rank.value!="")
//    {
//        if(!isNum(rank.value))
//        {
//            alert("Please Enter Valid Rank");
//            rank.value="";
//            rank.focus();
//            return false;
//        }
//    }
      Dt = new Date();
    var mon = Dt.getMonth()+1;
    
    if(mon < 10)
    {
     mon = "0"+mon;
    }
    var tdate = mon+"/"+Dt.getDate()+"/"+Dt.getFullYear();
    
//    if(Trim(sdate.value)=="")
//    {
//        alert("Please Select Start Date");
//        sdate.focus();
//        return false;
//    }
//    else
//    {
//        if(!isDate(sdate.value))
//        { 
//        sdate.value ="";
//        sdate.focus;
//        return false;
//        }
//    }
//    
//     if (Date.parse(sdate.value) < Date.parse(tdate)) 
//    {
//        alert("Date cannot be back Date!")
//        sdate.focus();
//        return false;
//    }
//    
//    
//    if(Trim(edate.value) =="")
//    {
//        alert("Please Select End Date");
//        edate.focus();
//        return false;
//    }
//    else
//    {
//        if(!isDate(edate.value))
//        { 
//        edate.value ="";
//        edate.focus;
//        return false;
//        }
//    }
//    
//    if (Date.parse(edate.value) < Date.parse(tdate)) 
//    {
//        alert("Date cannot be back Date!")
//        edate.focus();
//        return false;
//    }
//    
//    if(Date.parse(sdate.value) > Date.parse(edate.value))
//    {
//        alert("Start Date cannot be after End Date!");
//        return false;
//    }
//   
//    if(image.value!="")
//    {
//        if(!checkFileExtension(image))
//            {
//                image.focus();
//                return false;
//            }
//     }
     if(TRIM(termsAndCond.value)=="")
    {
        alert("Please Enter Terms and Condition.");
        termsAndCond.value="";
        termsAndCond.focus();
        return false;    
    }
    if(termsAndCond.value.length > 1000)
    {    
        alert("Terms and Condition must be less than 1000 Charector.");
        termsAndCond.focus();
        return false;   
    }
     return true;
}

function AssignSDate()
{
    var sdate = document.getElementById("txtstartdate");
    var edate = document.getElementById("txtendDate");
    var sdate1 =  GetRadWindow().BrowserWindow.document.getElementById("UcAssignSpecialsToFranchise1_hidsdate");
    var edate1 = GetRadWindow().BrowserWindow.document.getElementById("UcAssignSpecialsToFranchise1_hidedate");
//    if(sdate.value=="" && edate.value!="")
//    {
//        alert("Please select Start Date.")
//        return false;
//    }
//    if(edate.value=="" && sdate.value!="")
//    {
//        alert("Please select End Date.")
//        return false;
//    }
//    if(edate.value=="" && sdate.value=="")
//    {
//        alert("Please select Start Date & End Date.")
//        return false;
//    }
    Dt = new Date();
    var mon = Dt.getMonth()+1;      
    var tdate = mon+"/"+Dt.getDate()+"/"+Dt.getFullYear();    
    if (Date.parse(sdate.value) < Date.parse(tdate)) 
    {    
            alert("Start Date must not be less than Current Date.")
            sdate.focus();
            return false;    
    }
    if(sdate.value!="" && edate.value!="")
    {
        if(sdate.value > edate.value)
        {
            alert("Start Date must be less than End Date.")
            edate.focus();
            return false;
        }
        sdate1.value=sdate.value;
        edate1.value=edate.value;
        CloseOnReload();
        var button1 =  GetRadWindow().BrowserWindow.document.getElementById("UcAssignSpecialsToFranchise1_ImageButton1");
        button1.click();
        return true;
    }
}
function validateEditProfile()
{
    txtfname=document.getElementById("UcEditProfile1_lblfranchiseName");
    txtcname=document.getElementById("UcEditProfile1_txtcontactName");
    txtaddr=document.getElementById("UcEditProfile1_txtaddress");
    txtcity=document.getElementById("UcEditProfile1_txtcity");
    drpstate=document.getElementById("UcEditProfile1_drpstate");
    txtpostcode=document.getElementById("UcEditProfile1_txtpostcode");
    txtphone=document.getElementById("UcEditProfile1_txtphone");
    txtfax=document.getElementById("UcEditProfile1_txtfax");
    txtmobile=document.getElementById("UcEditProfile1_txtmobile");
    txtemail=document.getElementById("UcEditProfile1_txtemail");
    txtOldPsw=document.getElementById("UcEditProfile1_txtOldPassword");
    txtpassword=document.getElementById("UcEditProfile1_txtpassword");
    txtConfirmPassword=document.getElementById("UcEditProfile1_txtConfirmPassword");
    hidpasswordexists=document.getElementById("UcEditProfile1_hidpasswordexists");    
    if(Trim(txtcname.value)=="")
    {
        alert("Please Enter Contact Name");
        txtcname.value="";
        txtcname.focus();
        return false;
    }
    if(Trim(txtaddr.value)=="")
    {
        alert("Please Enter Address");
        txtaddr.value="";
        txtaddr.focus();
        return false;
    }
    if(Trim(txtcity.value)=="")
    {
        alert("Please Enter City");
        txtcity.value="";
        txtcity.focus();
        return false;
    }
    if(drpstate.value=="")
    {
        alert("Please Select State");
        drpstate.focus();
        return false;
    }
    if(Trim(txtpostcode.value) == "")
    {
        alert("Please Enter PostCode");
         txtpostcode.value="";
        txtpostcode.focus();
        return false;
    }
    if(Trim(txtpostcode.value) != "")
    {
        var anum=/(^\d+$)|(^\d+\.\d+$)/;
        var matchno=txtpostcode.value.match(anum);
        if (matchno==null)
        {
            alert("PostCode must be Integer only!");       
            txtpostcode.value="";
            txtpostcode.focus();
            return false;
       }
    }
       if(txtpostcode.value!="")
       {
            var pc=txtpostcode.value;
            if(pc.length > 4)
            {
                alert("Post Code Is Limited to 4 digits only");
                return false;
            }
       }
    if(Trim(txtphone.value) =="")
    {
        alert("Please Enter Phone Number");
        txtphone.value="";
        txtphone.focus();
        return false;
    }
    if(Trim(txtphone.value) != "")
       {
           if(!Ph_no(Trim(txtphone.value)))
           {
             alert("Please Enter Valid Phone Number");
             txtphone.value="";
             txtphone.focus();
             return false;
           }
       }
    if(Trim(txtfax.value)!="")
    {
        if(!Ph_no(Trim(txtfax.value)))
        {
            alert("Please Enter Valid Fax Number");
            txtfax.value="";
            txtfax.focus();
            return false;
        }
    }
    if(Trim(txtmobile.value) == "")
    {
        alert("Please Enter Mobile Number");
         txtmobile.value="";
        txtmobile.focus();
        return false;
    }
    if(Trim(txtmobile.value) != "")
       {
           if(!Ph_no(Trim(txtmobile.value)))
           {
             alert("Please Enter Valid Mobile Number");
             txtmobile.value="";
             txtmobile.focus();
             return false;
           }
       }
   if(Trim(txtemail.value)=="")
   {
        alert("Please Enter Email");
        txtemail.value="";
        txtemail.focus();
        return false;     
   }
   
   if(Trim(txtemail.value) != "")
   {
            var filter=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
            if (filter.test(txtemail.value))
            {
                              
            }
            else
            {
                alert("Please enter a valid email address!");
                txtemail.focus();
                return false;
            }      
//     if(!ValidateEmail(txtemail))
//     {
//       //alert("Please Enter Valid Email Address.");
//       txtemail.focus();
//       return false;
//     }
   }
   
   if(Trim(txtpassword.value) != "")
   {
        if(Trim(txtpassword.value).length < 6 || Trim(txtpassword.value).length > 20)
        {
            alert("Password should be within 6 to 20 characters.");
            txtpassword.value="";
            txtpassword.focus();
            return false;
        }
        if(Trim(txtOldPsw.value) == "")
        {
            alert("Please Enter Old Password");
            txtOldPsw.value="";
            txtOldPsw.focus();
            return false;
        }
        if(Trim(txtConfirmPassword.value) == "")
        {
            alert("Please Enter Confirm Password");
            txtConfirmPassword.value="";
            txtConfirmPassword.focus();
            return false;
        }
        if(Trim(txtpassword.value) != Trim(txtConfirmPassword.value))
        {
            alert("Password and Confirm Password are different.");
            txtpassword.value="";
            txtConfirmPassword.value="";
            txtpassword.focus();
            return false;
        }
    }
//   if(Trim(txtlogon.value) == "")
//   {
//        alert("Please Enter Logon");
//        txtlogon.value="";
//        txtlogon.focus();
//        return false;
//   }
   if(hidpasswordexists.value =="No")
   {
       if(Trim(txtpassword.value) == "")
       {
            alert("Please Enter Your Password");
            txtpassword.value="";
            txtpassword.focus();
            return false;
       }
   }
   return true;
}

function CheckEmailExistsForEditProfile(email)
{
    txtemail=document.getElementById("UcEditProfile1_txtemail");
    if(email != TRIM(txtemail.value))
    {
        if(TRIM(txtemail.value)!="")
        {
            CheckEmailExists_EditProfile(txtemail.value,ServerSideCallBack_CheckEmailExists_EditProfile);
        }
    }
}

function ServerSideCallBack_CheckEmailExists_EditProfile(response)
{
    txtemail=document.getElementById("UcEditProfile1_txtemail");
    if(response.Rows.length != 0 )
    {
        alert("Email Id is already in use.Please select another email");
        txtemail.value="";
        txtemail.focus();
        return false;
    }
    else
    {
        return true;
    }
}

function CheckLogonExistsForEditProfile(logon)
{
    txtLogon = document.getElementById("UcEditProfile1_txtlogon");
    if(logon != TRIM(txtLogon.value))
    {
        if(TRIM(txtLogon.value)!="")
        {
            CheckLogonExists_EditProfile(txtLogon.value,ServerSideCallBack_CheckLogonExists_EditProfile);
        }
    }
}

function ServerSideCallBack_CheckLogonExists_EditProfile(response)
{
    txtemail=document.getElementById("UcEditProfile1_txtlogon");
    if(response.Rows.length != 0 )
    {
        alert("Logon is already in use.Please select another Logon.");
        txtLogon.value="";
        txtLogon.focus();
        return false;
    }
    else
    {
        return true;
    }
}