var indexLocale={loginButtonText:"Login",cancelButtonText:"Cancel",serverError:"Temporary error. could not access server. please try again later",pleaseWaitHeader:'Please wait...'}
var loginVariables={postLoginAction:null,closeLoginDialog:true,wantedRoute:'homepage',redirectAfterLogin:true,redirectAfterLoginFlash:null,isExpired:true}
function initializeLoginForm(ajaxUrl){jq.ajax({type:"get",url:ajaxUrl,data:'isExpired='+loginVariables.isExpired,timeout:15000,cache:false,success:function(result){jsonRequest=eval("("+result+")");if(jsonRequest.status=="OK"){if(loginVariables.redirectAfterLogin){redirect(jsonRequest.response);}}else{addFlashError(jsonRequest.response);}},error:function(error){if(error.status==401){initLoginDialog(error.responseText,loginVariables.postLoginAction);}
else{addFlashError(indexLocale.serverError);}}});}
function initLoginDialog(form,postLoginFunction){jq('#footer').append(form);if(jq('#dynamic_recaptcha','#login_form').length){showDynamicRecaptcha('dynamic_recaptcha');}
var contextObject=this;jq('#login_dialog').dialog({modal:true,autoOpen:true,resizable:false,width:400,open:function(){jq('#login_form').submit(function(){sendLoginRequest.call(contextObject,jq('#login_form'),jq('#login_dialog'),jq('#login_ajax_indicator'),postLoginFunction);return false;});jq('#login_dialog').keyup(function(e){if(e.keyCode==13){jq('#login_form').submit();}});},close:function(){showStaticRecaptcha('recaptcha_static_widget');jq("#login_dialog").remove();}});}
function sendLoginRequest(form,dialog,indicator,postLoginFunction){var dataToSubmit=form.serialize();if(loginVariables.wantedRoute){dataToSubmit+='&wantedRoute='+loginVariables.wantedRoute;}
var contextObject=this;jq.ajax({type:"post",url:form.attr('action'),timeout:15000,cache:false,data:dataToSubmit,beforeSend:function(){jq(".login_fields").hide();indicator.show();jq(".error_list",dialog).remove();jq(".ui-widget-content",dialog).removeClass('ui-state-error');},complete:function(){},success:function(result,data,request){jsonRequest=eval("("+result+")");if(jsonRequest.status=="OK"){if(loginVariables.closeLoginDialog){jq('#login_dialog').dialog('close');}
if(postLoginFunction){postLoginFunction.call(contextObject);}
else{if(loginVariables.redirectAfterLogin){redirect(jsonRequest.response);}}}else{indicator.hide();addFlashError(jsonRequest.response);}},error:function(error){indicator.hide();if(error.status==401){if(jq('#login_form',jq(error.responseText)).length){var newForm=jq('#login_form',jq(error.responseText));jq('#login_form').html(newForm.html());if(jq('#dynamic_recaptcha',newForm).length){showDynamicRecaptcha('dynamic_recaptcha');}}else{addFlashError(indexLocale.serverError)}}
else{addFlashError(indexLocale.serverError);}}});}
function authenticateAndAct(ajaxUrl,authenticatedAction,postAuthentication){var contextObject=this;jq.ajax({type:"get",url:ajaxUrl,data:'isExpired='+loginVariables.isExpired,timeout:15000,cache:false,async:false,success:function(result){authenticatedAction.call(contextObject);},error:function(error){if(error.status==401)
{initLoginDialog.call(contextObject,error.responseText,postAuthentication);}
else
{addFlashError(indexLocale.serverError);}}});}
function injectCSRF(getUrl,postInject)
{jq.ajaxSetup({cache:false});jq.get(getUrl,function(data){jq('input[name*="_csrf_token"]').addClass('csrfNotChecked');jq('input[name*="_csrf_token"]',data).each(function(){jq('#'+jq(this).attr('id')).val(jq(this).val());jq('#'+jq(this).attr('id')).removeClass('csrfNotChecked');});jq('input.csrfNotChecked[name*="_csrf_token"]').each(function(){var id=jq(this).attr('id');var idPrefixArray=id.split(/NEW\d/);if(idPrefixArray.length==1)
{idPrefixArray=id.split(/\d/);}
if(idPrefixArray.length>1)
{var idPrefix=idPrefixArray[0];var newCsrfWithPrefix=jq('input[id^='+idPrefix+'][name*="_csrf_token"]:first',data);if(newCsrfWithPrefix.length>0)
{jq(this).val(newCsrfWithPrefix.val());jq(this).removeClass('csrfNotChecked');}}});jq('.csrfNotChecked').removeClass('csrfNotChecked');if(postInject)
{postInject();}});}
function loadAndClickMe(getUrl)
{var id=jq(this).attr('id');jq.ajaxSetup({cache:false});jq.get(getUrl,function(data){jq('#'+id).replaceWith(jq('#'+id,data));jq('#'+id).click();});}
function showDynamicRecaptcha(element){jq('#recaptcha_static_widget').empty();Recaptcha.create("6Lfl4QoAAAAAAClHL1XCj4E_FX66oQzam-nkfPIX",element,{theme:'custom',custom_theme_widget:'recaptcha_widget',tabindex:0,callback:Recaptcha.focus_response_field});}
function showStaticRecaptcha(element){jq('#recaptcha_static_widget').html(jq('#recaptcha_widget','#dynamic_recaptcha').html());jq('#dynamic_recaptcha').empty();Recaptcha.create("6Lfl4QoAAAAAAClHL1XCj4E_FX66oQzam-nkfPIX",element,{theme:'custom',custom_theme_widget:'recaptcha_widget',tabindex:0,callback:Recaptcha.focus_response_field});}
function initClientsQuotes(){jq('#clients_list').find('li').hide();jq('#clients_list').find('li:first').show();setInterval(switchQuot,10000);}
function switchQuot(){var nextLi=jq('#clients_list').find('li:visible').next();if(nextLi.length==0){nextLi=jq('#clients_list').find('li:first');}
jq('#clients_list').find('li:visible').fadeOut(3000,function(){nextLi.fadeIn(1000);});}
function mouseOverMenu(submenuToShow){clearTimeout(timer);if(typeof submenuToShow!=='undefined'){jq('.submenu_list').addClass('hidden_menu');jq(submenuToShow).removeClass('hidden_menu');}else{jq('.submenu_list').addClass('hidden_menu');}}
function mouseOutMenu(selectedMenu){timer=setTimeout(function(){jq('.submenu_list').addClass('hidden_menu');if(typeof selectedMenu!=='undefined'){jq('#submenu_'+selectedMenu).removeClass('hidden_menu');}},3000);}
function mouseMoveSubmenu(){clearTimeout(timer);}
function mouseOverSubmenu(){clearTimeout(timer);}
function mouseOutSubmenu(outSubmenu,selectedSubmenu){timer=setTimeout(function(){jq(outSubmenu).addClass('hidden_menu');if(typeof selectedSubmenu!=='undefined'){jq('#submenu_'+selectedSubmenu).removeClass('hidden_menu');}},3000);}
