function checkXMLHTTP(xmlhttp) {
    xmlhttp = false;
    try {
        return xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            return xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest !== 'undefined') {
        return xmlhttp = new XMLHttpRequest();
    }
}
function documentID(el) {
    return document.getElementById(el); //Get the element with the specified ID
}
/*
 * @Function            : check_forbidden_exist 
 * @Used IN             : front_end/sign_up.php
 * @Description         : used to check name are exist in tbl_forbidden
 * @parameter           : first_name, last_name
 * @Developed By        : Tania Akter
 * @Start DateTime      : 21-05-2016 5:21 AM
 * @Status              : available  
 * (signupforbiddenExists) --jquery   
 */
function check_forbidden_exist(first_name, last_name, account_type, url) {
    var xmlhttp;
    xmlhttp = checkXMLHTTP(xmlhttp);
    var formdata = new FormData();
    formdata.append("first_name", first_name);
    formdata.append("last_name", last_name);
    formdata.append("account_type", account_type);
    xmlhttp.addEventListener("load", function () {
        if (xmlhttp.responseText === '1') {
            documentID('sign_up_forbidden_exists').value = '1';            
        }
        else if (xmlhttp.responseText === '2') {
            documentID('sign_up_forbidden_exists').value = '';                        
        }
    }, false);
    xmlhttp.addEventListener("error", function () {
        alert("There is some problem in your browser, error");
    }, false);
    xmlhttp.addEventListener("abort", function () {
        alert("There is some problem in your browser, Aborted");
    }, false);
    xmlhttp.open("POST", url);
    xmlhttp.send(formdata);
}

/*
 * @Function            :check_email_registration
 * @Used IN             : front_end/sign_up
 * @Description         : check email address to validate
 * @parameter           : given_email, url
 * @Developed By        : Tania Akter
 * @Start DateTime      : 25-05-2016
 * @Status              : available  
 * (signupforbiddenExists) --jquery   
 */
function check_email_registration(given_email, url) {
    var xmlhttp7;
    xmlhttp7 = checkXMLHTTP(xmlhttp7);
    var formdata = new FormData();
    formdata.append("given_email", given_email);
    xmlhttp7.addEventListener("load", function () {
        if (xmlhttp7.responseText === '1') {
            document.getElementById('email_status_value').value = 2;            
        }else if (xmlhttp7.responseText === '2') {
            document.getElementById('email_status_value').value = 1;            
        }else if (xmlhttp7.responseText === '3') {
            document.getElementById('email_status_value').value = 3;            
        }
    }, false);
    xmlhttp7.addEventListener("error", function () {
        alert("There is some problem in your browser, error");
    }, false);
    xmlhttp7.addEventListener("abort", function () {
        alert("There is some problem in your browser, Aborted");
    }, false);
    xmlhttp7.open("POST", url);
    xmlhttp7.send(formdata);
}


    $(document).ready(function () {     //ready() is used to make a function available after the document is loaded
        var tz = jstz.determine();      //autometically detect timezone
        response_text = 'No timezone found';
        if (typeof (tz) === 'undefined') {
            response_text = 'No timezone found';
        }
        else {
            response_text = tz.name(); //timezone name
        }
        document.getElementById('person_time_zone').value = response_text;
    });
 
    
 /*
 * @Function            :check_exist_forgot_password_email
 * @Used IN             : front_end/forgot_password
 * @Description         : used to check user email exist in db
 * @parameter           : forgot_password_email, url
 * @Developed By        : Tania Akter
 * @Start DateTime      : 05-06-2016
 * @Status              : available  
 * (emailNotExist) --jquery   
 */   
 function check_exist_forgot_password_email(forgot_password_email, url){
     var xmlhttp8;
     xmlhttp8 = checkXMLHTTP(xmlhttp8);
     var formdata = new FormData();
     formdata.append('forgot_password_email', forgot_password_email);  
     xmlhttp8.addEventListener("load", function () {         
    if (xmlhttp8.responseText === '1') {
      documentID('forgot_password_email_hidden').value = '';     
    }else if (xmlhttp8.responseText === '2') {
      documentID('forgot_password_email_hidden').value = '1';      
        }
   }, false);
    xmlhttp8.addEventListener("error", function () {
        alert("There is some problem in your browser, error");
    }, false);
    xmlhttp8.addEventListener("abort", function () {
        alert("There is some problem in your browser, Aborted");
    }, false);
    xmlhttp8.open("POST", url);
    xmlhttp8.send(formdata);
 }  
 /*
 * @Function            : check_org_name
 * @Used IN             : front_end/sign_up
 * @Description         : check org name to validate
 * @parameter           : account_type, first_name, last_name, url
 * @Developed By        : Tania Akter
 * @Start DateTime      : 06-08-2016
 * @Status              : available  
 * (signupforbiddenExists) --jquery   
 */
//06-08-2016 
 function check_org_name(account_type, first_name, last_name, url){
    var xmlhttp8;
     xmlhttp8 = checkXMLHTTP(xmlhttp8);
     var formdata = new FormData();
     formdata.append('account_type', account_type); 
     formdata.append('first_name', first_name); 
     formdata.append('last_name', last_name); 
     xmlhttp8.addEventListener("load", function () {  
          if (xmlhttp8.responseText === '1') {
            documentID('sign_up_forbidden_exists').value = '1';
        }
        else if (xmlhttp8.responseText === '2') {
            documentID('sign_up_forbidden_exists').value = '';            
        }
   }, false);
    xmlhttp8.addEventListener("error", function () {
        alert("There is some problem in your browser, error");
    }, false);
    xmlhttp8.addEventListener("abort", function () {
        alert("There is some problem in your browser, Aborted");
    }, false);
    xmlhttp8.open("POST", url);
    xmlhttp8.send(formdata);
     
 }

 
// function check_form(){ 
// //   alert(base_url);
//    first_name_validation(base_url);
//    email_validation(base_url);
//    password_validation();
//    confirm_password_validation();
//    select_country_validation();
// }
 
// function first_name_validation(base_url){
//    var person_first_name = documentID('person_first_name').value ;
//    var filter = /^[A-z ]+$/;
//    if(person_first_name === ''){
//        documentID('person_first_name_message').innerHTML = "Person first name is required";
//        return false;          
//    }else if(!filter.test(person_first_name)){
//        documentID('person_first_name_message').innerHTML = "Person Name only contain character";
//        return false;     
//    }else if(person_first_name.length > 100){
//       documentID('person_first_name_message').innerHTML = "Person name must be less than 100 character length" ; 
//       return false;
//    }
// }
//
// function email_validation(base_url){
//    var person_email = documentID('person_email').value;
//    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
//    check_email_exist(person_email, base_url);
//    if(person_email === ''){
//        documentID('person_email_message').innerHTML = "Person email is required";
//        return false;          
//    }else if(person_email !== ''){
//        if(!filter.test(person_email.value)){
//        documentID('person_email_message').innerHTML = "Invalid email address";
//        return false;   
//        }  
//    }
//    
//     else if(!filter.test(person_email.value)){
//      documentID('person_email_message').innerHTML = "Invalid email address";
//      return false;   
//    }
////    else{
////      return true;  
////    }
// }
// 
// function check_email_exist(given_email, base_url){
//  var url = base_url +'check-user-email-registration';
//  var xmlhttp7;
//    xmlhttp7 = checkXMLHTTP(xmlhttp7);
//    var formdata = new FormData();
//    formdata.append("given_email", given_email);
//    xmlhttp7.addEventListener("load", function () {
//        if (xmlhttp7.responseText === '1') {
//            document.getElementById('person_email_message').innerHTML = 'Email already exist!';
//            return false; 
//        }else if(xmlhttp7.responseText === '2') {
//            return true;     
//        }else if(xmlhttp7.responseText === '3') {
//            document.getElementById('person_email_message').innerHTML = 'There is some problem.Please change your email';
//            return false; 
//        }
//    }, false);
//    xmlhttp7.addEventListener("error", function () {
//        alert("There is some problem in your browser, error");
//    }, false);
//    xmlhttp7.addEventListener("abort", function () {
//        alert("There is some problem in your browser, Aborted");
//    }, false);
//    xmlhttp7.open("POST", url);
//    xmlhttp7.send(formdata);   
// }
//
// function password_validation(){
//    var person_password = documentID('person_password').value;
//    if(person_password === ''){
//        documentID('person_password_message').innerHTML = "Person password is required";
//        return false;          
//    }
//    else{
//     return true;   
//    }
//    
// }
// 
// function confirm_password_validation(){
//  var confirm_password = documentID('confirm_password').value;
//  var confirm_password = documentID('person_password').value;
//    if(confirm_password === ''){
//      documentID('confirm_password_message').innerHTML = "Confirm password is required";
//      return false;          
//    }else if(confirm_password !== confirm_password){
//      documentID('confirm_password_message').innerHTML = "Password and Confirm password not mmmmatched";
//      return false;  
//    }
//    else{
//     return true;   
//    }
// }
// 
// function select_country_validation(){
//  var person_country = documentID('person_country').value;
//    if(person_country === ''){
//        documentID('person_country_message').innerHTML = "Person country is required";
//        return false;          
//    }
//    else{
//     return true;   
//    }
// }


/*
 * @Function            : SlideArea
 * @Used IN             : home page
 * @Description         : Works on tree icon mouseover
 * @parameter           : section
 * @Developed By        : Md Mashqur Ul Alam
 * @Start DateTime      : 08-04-17
 * @Status              : available   
 */
    function SlideArea(section){
        $('div[id$=SlideArea]').hide();        
        $('#'+section).show();
    }

/*
 * @Function            : SlideAreaMouseOut
 * @Used IN             : home page
 * @Description         : Works on tree icon mouseout
 * @parameter           : section
 * @Developed By        : Md Mashqur Ul Alam
 * @Start DateTime      : 08-04-17
 * @Status              : available   
 */
    function SlideAreaMouseOut() {
        $('div[id$=SlideArea]').hide();
        $('#AutoSlideArea').show();
    }
    
    /*
 * @Function            : check_form
 * @Used IN             : sign_up form
 * @Description         : for validating google captcha
 * @parameter           : 
 * @Developed By        : Kazol
 * @Start DateTime      : 14/05/2017
 * @Status              : available   
 */
    function check_form(){
    var v = grecaptcha.getResponse();
            if(v.length == 0)
        {
            //alert("please complete the captcha");
              swal({
                title: "",
                text: "please complete the captcha",
                type: "warning",
                confirmButtonColor: "#80c12c",
                confirmButtonText: "OK",
                closeOnConfirm: false

              });

            //document.getElementById('captcha').innerHTML="You can't leave Captcha Code empty";
            return false;
        }
        else{
             return true;
           }
    }
