	function validateEmail($email) {
	  var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	  return emailReg.test( $email );
	}

	function callRegister(){
		
		jQuery.validity.start();
		//jQuery('#wel_reg_email').require('Please add email');
		//jQuery('#wel_reg_email').match('email','Please add proper format email');
		
		jQuery('#wel_reg_firstname').require('Please add first name');
		jQuery('#wel_reg_lastname').require('Please add last name');
		
		jQuery('#wel_reg_companyname').require('Please add company name');
		jQuery('#wel_reg_address1').require('Please add Address');
		jQuery('#wel_reg_city').require('Please add City');
		jQuery('#wel_reg_state').require('Please add State');
		jQuery('#wel_reg_postcode').require('Please add postcode / zip');
		
		jQuery('#wel_reg_phonenumber').require('Please add phone');
		jQuery('#wel_reg_phonenumber').match('integer','Please add phone numeric only');		
		
		var result = jQuery.validity.end();
		
		if(result.valid)
		{		
			
		jQuery('#createButton').val('Saving Settings..');
		jQuery('#createButton').attr('disabled','disabled');
		
		var $modal = jQuery('.js-loading-bar');
		$modal.modal('show');
		jQuery('.modal-backdrop').appendTo('#registerBlock');
		
		jQuery.post(
			ajaxurl, 			
				jQuery('#registerForm').serialize()
			, 
			function(response){
				
				if(response.error	==	0)
				{
					// jQuery('#wel_appid').val(response.appid);
					// jQuery('#wel_secret').val(response.secret);
					jQuery('.loginurl').attr('href',response.login_url);
					//jQuery('#frameSetting').attr('src',response.login_url);
					//setTimeout(function(){
						jQuery('#settingBlock').show('slow');
						jQuery('#registerBlock').hide();
						$modal.modal('hide');
						
						jQuery('.alert').show();
						setTimeout(function(){
							jQuery('.alert').fadeOut('slow');  
						},1000);
						//jQuery('#frameSetting').iFrameResize();
					//},1500);
				}else{
					alert('The server responded: ' + response.msg);
					jQuery('#createButton').removeAttr('disabled');
					$modal.modal('hide');
				}
				jQuery('body').removeClass('modal-open');
			},'json'
		);

		}else{
			alert('Please clear errors while input.');
			return false;
		}
	}
	
	function callVerify(){
		jQuery.validity.start();
		jQuery('#admin_email').require('Please add email');
		jQuery('#admin_email').match('email','Please add proper format email');
		
		var result = jQuery.validity.end();
		
		if(result.valid)
		{		
			
			jQuery('#verifyButton').val('Updating Settings..');
			jQuery('#verifyButton').attr('disabled','disabled');
			
			var $modal = jQuery('.js-loading-bar3');
			$modal.modal('show');
			jQuery('.modal-backdrop').appendTo('#loaderBlock');
			
			jQuery.post(
				ajaxurl, 			
					jQuery('#verifyForm').serialize()
				, 
				function(response){
					
					if(response.gr_reg	==	1)
					{
						alert(response.msg);
						jQuery('.error_msg').html(response.msg);
						jQuery('#verifyForm').show();
						jQuery('#verifyButton').val('Update');
						jQuery('#verifyButton').removeAttr('disabled');
						$modal.modal('hide');
						jQuery('body').removeClass('modal-open');
					}else if(response.gr_reg	==	0){
						jQuery('.loginurl').attr('href',response.login_url);
						//jQuery('#frameSetting').attr('src',response.login_url);
						setTimeout(function(){
							jQuery('#settingBlock').show('slow');
							jQuery('#loaderBlock').hide();
							$modal.modal('hide');
							jQuery('body').removeClass('modal-open');
							//jQuery('#frameSetting').iFrameResize();
						},500);
					}else{
						jQuery('#registerBlock').show('slow');
						jQuery('#loaderBlock').hide();
						$modal.modal('hide');
						jQuery('body').removeClass('modal-open');
					}
					
				},'json'
			);
		
		
		}
	}
	
	function callLoader(){
		var $modal = jQuery('.js-loading-bar3');
		$modal.modal('show');
		jQuery('.modal-backdrop').appendTo('#loaderBlock');
		
		jQuery.post(
			ajaxurl, 			
				{action:'wccheck_settings'}
			, 
			function(response){
				
				if(response.gr_reg	==	1)
				{
					alert(response.msg);
					jQuery('#loaderBlock').html(response.msg);
					$modal.modal('hide');
					jQuery('body').removeClass('modal-open');
				}else if(response.gr_reg	==	0){
					jQuery('.loginurl').attr('href',response.login_url);
					//jQuery('#frameSetting').attr('src',response.login_url);
					setTimeout(function(){
						jQuery('#settingBlock').show('slow');
						jQuery('#loaderBlock').hide();
						$modal.modal('hide');
						jQuery('body').removeClass('modal-open');
						//jQuery('#frameSetting').iFrameResize();
					},500);
				}else{
					jQuery('#registerBlock').show('slow');
					jQuery('#loaderBlock').hide();
					$modal.modal('hide');
					jQuery('body').removeClass('modal-open');
				}
				
			},'json'
		);
	}
	
	jQuery(document).ready(function(){		
			
		jQuery('.js-loading-bar').modal({
		  backdrop: 'static',
		  show: false
		});
				
		if(jQuery('#grRegisterAr').val()	== 2){
			jQuery('.js-loading-bar3').modal({
			  backdrop: 'static',
			  show: false
			});
			callLoader();
		}else{
			//jQuery('#frameSetting').iFrameResize();
		}
		jQuery('body').tooltip({selector: '[data-toggle=tooltip]'}); 
		
	});