﻿function showAlert(msg, url) {
    alert(msg);
    if (url != '') {
        redirectWindow(url);
    }
}

function showAlertLogin(url) {
    alert("Sorry your login was unsuccessful.\n Either your login details are incorrect or you are only subscribed to our Newsletter.\n Please contact us (info@saferworking.com) if the problem continues.");
    if (url != '') {
        redirectWindow(url);
    }
}

function redirectWindow(url) {
    if (navigator.appName == 'Microsoft Internet Explorer') {
        location.href(url);
    }
    else if (navigator.appName == 'Netscape') {
        window.open(url, '_parent', 1);
        window.close();
    }
}


function ContactValidate() {

    var Id = 'ctl00_Mid_';
    var intSucess = '1';

    if (document.getElementById(Id + 'txtName').value == '') {
        alert("Name Cannot be blank");
        document.getElementById(Id + 'txtName').focus();
        return false;
    }

    if (document.getElementById(Id + 'txtEmail').value == '') {
        alert("E-Mail Address cannot be blank");
        document.getElementById(Id + 'txtEmail').focus();
        return false;

    }
    var msg = ''
    if (document.getElementById(Id + 'txtEmail').value != '') {
        regex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ //new RegExp(pattern);
        if (!regex.test(document.getElementById(Id + 'txtEmail').value)) {
            msg = msg + "Please enter a valid E-Mail Address,\nfor example : \n     yourname@domain.com  OR\n     yourid@yourdomain.co.in  OR\n     yourid.somname@domain.co.in OR\n     yourid@yourdomain.co.uk  OR\n     yourid.somname@domain.co.uk\n"
            alert(msg);
            document.getElementById(Id + 'txtEmail').focus();
            return false;
        }
    }

    if (document.getElementById(Id + 'txtSubject').value == '') {
        alert("Subject Cannot be blank");
        document.getElementById(Id + 'txtSubject').focus();
        return false;
    }
    if (document.getElementById(Id + 'txtComments').value == '') {
        alert("Comments Cannot be blank");
        document.getElementById(Id + 'txtComments').focus();
        return false;
    }
 
    
    return true;
}
function Validate() {
    var Id = 'ctl00_Mid_Registration1_';
    var intSucess = '1';

        if (document.getElementById(Id + 'txtEmail').value == '') {
            alert("E-Mail Address cannot be blank");
            document.getElementById(Id + 'txtEmail').focus();
           return false;
            
        }
        var msg = ''
        if (document.getElementById(Id + 'txtEmail').value != '') {
            regex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ //new RegExp(pattern);
            if (!regex.test(document.getElementById(Id + 'txtEmail').value)) {
                msg = msg + "Please enter a valid E-Mail Address,\nfor example : \n     yourname@domain.com  OR\n     yourid@yourdomain.co.in  OR\n     yourid.somname@domain.co.in OR\n     yourid@yourdomain.co.uk  OR\n     yourid.somname@domain.co.uk\n"
                alert(msg);
                document.getElementById(Id + 'txtEmail').focus();
                return false;
            }
        } 

        if (document.getElementById(Id + 'txtPwd').value == '') {
            alert("Password Cannot be blank");
            document.getElementById(Id + 'txtPwd').focus();
            return false;
        }
        var your = document.getElementById(Id + 'txtPwd').value
        if (your.length < 6) {
            alert("Password Field cannot be less than 6 Char.");
            document.getElementById(Id + 'txtPwd').focus();
            return false;
        }
        var your = document.getElementById(Id + 'txtPwd').value
        if (your.length > 25) {
            alert("Password Field cannot be more than 15 Char.");
            document.getElementById(Id + 'txtPwd').focus();
            return false;
        }
        var pass = document.getElementById(Id + 'txtPwd').value
        var Confirm = document.getElementById(Id + 'txtConfirmPwd').value
        if (Confirm != pass) {
            alert("Please enter the Confirm Password Correctly");
            document.getElementById(Id + 'txtConfirmPwd').focus();
            return false;
        }
        if (document.getElementById(Id + 'txtName').value == '') {
             alert("Name Field cannot be blank.");
              document.getElementById(Id + 'txtName').focus();
              return false;
          }
           


          if (document.getElementById(Id + 'txtContact').value == '') {
              alert("Contact Field cannot be blank.");
              document.getElementById(Id + 'txtContact').focus();
              return false;
          }
           

          if (document.getElementById(Id + 'txtCity').value == '') {
              alert("City Field cannot be blank.");
              document.getElementById(Id + 'txtCity').focus();
              return false;
          }
           

           if (document.getElementById(Id + 'txtCountry').value == '') {
               alert("Country Field cannot be blank.");
                document.getElementById(Id + 'txtCountry').focus();
                return false;
           }
           

           if (document.getElementById(Id + 'txtPostCode').value == '') {
               alert("Postcode Field cannot be blank.");
               document.getElementById(Id + 'txtPostCode').focus();
               return false;
           }
            

           if (document.getElementById(Id + 'txtFindUs').value == '') {
               alert("How did you find us? Field cannot be blank.");
               document.getElementById(Id + 'txtFindUs').focus();
               return false;
           }
           
           return true;
       }

       function SetIMage(ImageName) {

           document.getElementById("ctl00_Mid_txtFileIcon").value = 'Images\\' + ImageName + '.gif';
       }


       function LoginValidate() {

           var Id = 'ctl00_Top1_';
           var intSucess = '1';

           if (document.getElementById(Id + 'txtUsername').value == '') {
               alert("E-Mail Address cannot be blank");
               document.getElementById(Id + 'txtUsername').focus();
               return false;

           }
           var msg = ''
           if (document.getElementById(Id + 'txtUsername').value != '') {
               regex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ //new RegExp(pattern);
               if (!regex.test(document.getElementById(Id + 'txtUsername').value)) {
                   msg = msg + "Please enter a valid E-Mail Address,\nfor example : \n     yourname@domain.com  OR\n     yourid@yourdomain.co.in  OR\n     yourid.somname@domain.co.in OR\n     yourid@yourdomain.co.uk  OR\n     yourid.somname@domain.co.uk\n"
                   alert(msg);
                   document.getElementById(Id + 'txtUsername').focus();
                   return false;
               }
           }

           if (document.getElementById(Id + 'txtPassword').value == '') {
               alert("Password Cannot be blank");
               document.getElementById(Id + 'txtPassword').focus();
               return false;
           }
       }


       function ForgotValidate() {
           if (document.getElementById('ctl00_Mid_txtEmail').value == '') {
               alert("E-Mail Address cannot be blank");
               document.getElementById('ctl00_Mid_txtEmail').focus();
               return false;

           }
           var msg = ''
           if (document.getElementById('ctl00_Mid_txtEmail').value != '') {
               regex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ //new RegExp(pattern);
               if (!regex.test(document.getElementById('ctl00_Mid_txtEmail').value)) {
                   msg = msg + "Please enter a valid E-Mail Address,\nfor example : \n     yourname@domain.com  OR\n     yourid@yourdomain.co.in  OR\n     yourid.somname@domain.co.in OR\n     yourid@yourdomain.co.uk  OR\n     yourid.somname@domain.co.uk\n"
                   alert(msg);
                   document.getElementById('ctl00_Mid_txtEmail').focus();
                   return false;
               }
           }

       }


       function NewsLetterValidate() {
           if (document.getElementById('ctl00_Mid_Newsletter1_txtEmail').value == '') {
               alert("E-Mail Address cannot be blank");
               document.getElementById('ctl00_Mid_Newsletter1_txtEmail').focus();
               return false;

           }
           var msg = ''
           if (document.getElementById('ctl00_Mid_Newsletter1_txtEmail').value != '') {
               regex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ //new RegExp(pattern);
               if (!regex.test(document.getElementById('ctl00_Mid_Newsletter1_txtEmail').value)) {
                   msg = msg + "Please enter a valid E-Mail Address,\nfor example : \n     yourname@domain.com  OR\n     yourid@yourdomain.co.in  OR\n     yourid.somname@domain.co.in OR\n     yourid@yourdomain.co.uk  OR\n     yourid.somname@domain.co.uk\n"
                   alert(msg);
                   document.getElementById('ctl00_Mid_Newsletter1_txtEmail').focus();
                   return false;
               }
           }
                document.getElementById("ctl00_Mid_Newsletter1_btnNewsLetter").click();
            }
       
      function DeleteRecord(Url) 
      {
          if (confirm("Are you sure you want Delete record")) {
              document.location.href = Url;
          }
       }
