(function(win,doc,$){var SubmitUserConsentForm=(function(){var configs={url:"http://survey.jeetwin-gaming.com/times-survey/survey/opinion/insert",emailError:"Please enter a valid e-mail ID.",captchaError:"Captcha entered doesn't seem to be correct.",queryError:"Please enter your query before submitting the form.",captchaError:"Captcha entered doesn't seem to be correct."};var data={Query:"",Email:"",Consent:false,surveyid:404};var validateEmail=function($elem){var email=$elem.val();var regEmail=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,6})$/; var validEmail=regEmail.test(email);return validEmail};var validateCheckBoxConsent=function($elem){return $elem.prop("checked")};var validateQuery=function($elem){return($elem.val().trim()!="")};var getId=function(){return Math.floor(Math.random()*26)+Date.now()};var getCookie=function(name){var v=document.cookie.match("(^|;) ?"+name+"=([^;]*)(;|$)");return v?v[2]:null};var postValues=function(dataObj){data.ssoid=getCookie("ssoid");data.clientId=getId()+"";data.response=dataObj.response;if(typeof(localStorage)!=="undefined"){data.clientId=localStorage.faq?localStorage.faq:data.clientId }localStorage.faq=data.clientId;$.post(configs.url,data,function(data){$('[data-form="consent"]').addClass("hide");$('[data-form="thankyou"]').removeClass("hide")}).fail(function(){console.log("posted error")})};var printErrorMessage=function($elem,error){if($elem.parent().find("span.error_msg").length===0){$elem.parent().append(''+error+"")}$elem.parent().addClass("faqerror");return};var removeErrorMessage=function($elem){if($elem.parent().find("span.error_msg").length>0){$elem.parent().find("span.error_msg").remove() }$elem.parent().removeClass("faqerror");return};var validateCaptcha=function($elem){var _url="http://survey.jeetwin-gaming.com/times-survey/survey/captcha/validate?captchaText="+$elem.val();var _validated=false;$.ajaxSetup({type:"GET",dataType:"json",xhrFields:{withCredentials:true},crossDomain:true});$.ajax({url:_url,type:"GET",async:false}).done(function(data){_validated=eval(data[0].status)});return _validated};var submitHandler=function(element){$_query=$("#faq_query");$_email=$("#faq_email");$_consent=$("#faq_consent"); $_captcha=$("#faq_captcha");removeErrorMessage($_email);removeErrorMessage($_query);removeErrorMessage($_consent);removeErrorMessage($_captcha);var isQueryValid=validateQuery($_query);var isEmailValid=validateEmail($_email);var isValidCaptcha=validateCaptcha($_captcha);if(isQueryValid&&isEmailValid&&isValidCaptcha){data.Email=$_email.val();data.Query=$_query.val();data.Consent=$_consent.prop("checked");data.response="no";postValues(data);$(".faq_form_container").hide();$(".thankyou_msg_form").show() }else{if(!isValidCaptcha){$('[data-btn="captch-refresh"]').click();printErrorMessage($_captcha,configs.captchaError)}if(!isQueryValid){printErrorMessage($_query,configs.queryError)}if(!isEmailValid){printErrorMessage($_email,configs.emailError)}}};return{submitHandler:submitHandler,postValues:postValues}})();$(doc).ready(function(){$("#submitfaq").on("click",function(e){e.preventDefault();SubmitUserConsentForm.submitHandler()});$("#faq_query_yes").on("click",function(){$(".faq_questions").hide(); data={response:"Yes"};SubmitUserConsentForm.postValues(data);$(".thankyou_yes").show()});$("#faq_query_no").on("click",function(){$(this).closest(".faq_container").hide();$(".faq_form_container").show();$("html, body").animate({scrollTop:700},800)});$(".placeholder").click(function(){$(this).siblings("input").focus();$(this).siblings("textarea").focus()});$(".label_fix").focus(function(){$(this).siblings(".placeholder").hide()});$('[data-btn="captch-refresh"]').on("click",function(){var _capImg=$("#captchaImg"); _capImg.attr("src",_capImg.attr("src")+"?v="+(new Date().getTime()))});$(".label_fix").blur(function(){var $this=$(this);if($this.val().length==0){$(this).siblings(".placeholder").show()}});require(["jquery","tiljs/event"],function($,event){event.subscribe("user.status",function(user){if(user&&user.getEmail()){$("#faq_email").val(user.getEmail());$("#faq_email").siblings(".placeholder").hide()}})});$(".label_fix").blur()})})(window,document,jQuery);