
function number_format(a,b,c,d){a=Math.round(a*Math.pow(10,b))/Math.pow(10,b);e=a+'';f=e.split('.');if(!f[0]){f[0]='0';}
if(!f[1]){f[1]='';}
if(f[1].length<b){g=f[1];for(i=f[1].length+1;i<=b;i++){g+='0';}
f[1]=g;}
if(d!=''&&f[0].length>3){h=f[0];f[0]='';for(j=3;j<h.length;j+=3){i=h.slice(h.length-j,h.length-j+3);f[0]=d+i+f[0]+'';}
j=h.substr(0,(h.length%3==0)?3:(h.length%3));f[0]=j+f[0];}
c=(b<=0)?'':c;return f[0]+c+f[1];}
$(function(){var validateErrors=0;$(".euro").blur(function(){if($(this).val()==''){$(this).val(0);}
var value=parseFloat($(this).val().replace('.','').replace(',','.'))
$(this).val(number_format(value,2,',','.'));})
$.fn.qtip.styles.hypotheekbond={width:{max:350},border:{width:5,radius:5},padding:5,textAlign:'left',tip:true,fontSize:'12px',fontFamily:'Verdana,Geneva,sans-serif',name:'green'};$('.tooltip').each(function(){$(this).qtip({position:{corner:{tooltip:'leftMiddle',target:'rightMiddle'},adjust:{x:5}},content:$(this).prev().html(),style:'hypotheekbond'});});$.fn.qtip.styles.hypotheekbond={width:{max:350},border:{width:5,radius:5},padding:5,textAlign:'left',tip:true,fontSize:'12px',fontFamily:'Verdana,Geneva,sans-serif',name:'green'};$('#pform ol li input, #pform ol li select, #pform ol li div input, #pform ol li div select').each(function(){try{if($(this).prev()[0].tagName=='DIV'){var method=($(this)[0].tagName=='SELECT')?'mouseover':'focus';var method_blur=($(this)[0].tagName=='SELECT')?'mouseout':'blur';$(this).qtip({position:{corner:{tooltip:'leftMiddle',target:'rightMiddle'},adjust:{x:5}},show:{when:{event:method},effect:'grow',solo:true},hide:{when:{event:method_blur},effect:'fade'},content:$(this).prev().html(),style:'hypotheekbond'});}}
catch(e){return;}});$('#pform ol li label').click(function(){$(this).next().focus();return false;});function show_error(elem,errorMsg)
{var elem_width=parseInt(elem.css('width').replace('px',''))-20;if(elem[0].tagName=='SELECT')
{elem_width-=28;}
elem.next().html(errorMsg);elem.css('border','1px solid #f55b5b');elem.next().css('width',elem_width+'px').fadeIn('normal',function(){elem.next().css('display','block');});}
$('#pform ol li span').click(function(){$(this).fadeOut('normal',function(){$(this).prev().focus();});})
$('#pform ol li select').focus(function(){$(this).next().fadeOut('normal',function(){});});function checkEmpty(parentId)
{var hasErrors=0;var elements=$('#'+parentId+' ol li .required');elements.each(function(){if($(this)[0].tagName=='INPUT'&&$(this).val()==''){show_error($(this),'Verplicht');hasErrors++;}
else if($(this)[0].tagName=='SELECT'&&$(this).val()=='###'){show_error($(this),'Verplicht');hasErrors++;}
else{$(this).css('border','1px solid #cccccc');$("#mainNav li.current a[rel='"+parentId+"']").css('background-image','');}})
if(hasErrors>1){$("#mainNav li.current a[rel='"+parentId+"']").css('background-image','url(/images/forms/uitroep.gif)').css('background-position','120px 3px').css('background-repeat','no-repeat');}
return hasErrors;}
function bindSteps(){$("#mainNav a[href='#']").unbind().click(function(){newStep=parseInt($(this).attr('rel').replace('step',''));thisStep=parseInt($('.step:visible').attr('id').replace('step',''));if(newStep>thisStep){hasErrors=checkEmpty($('#mainNav li.current a').attr('rel'));if(hasErrors>0||validateErrors>0)
{return false;}}
elem=$(this).parent();elem.removeClass(elem.attr('class')).addClass('current').prev().removeClass('done').addClass('lastDone');elem.prev().prevAll().addClass('done');elem.nextAll().removeClass()
elem.parent().children('li:last').addClass('mainNavNoBg');if($(this).attr('rel')!=$('.step:visible').attr('id')){var new_step=$(this).attr('rel')
$('.step:visible').fadeOut('normal',function(){$('#'+new_step).fadeIn();});}
bindSteps()
return false;});}
bindSteps()
$('.next').click(function(){var hasErrors=0;parentId=$(this).parent().attr('id');elements=$('#'+parentId+' ol li .required');elements.each(function(){if($(this)[0].tagName=='INPUT'&&$(this).val()==''){show_error($(this),'Verplicht');hasErrors++;}
else if($(this)[0].tagName=='SELECT'&&$(this).val()=='###'){show_error($(this),'Verplicht');hasErrors++;}
else{$(this).css('border','1px solid #cccccc');}})
if(hasErrors>0||validateErrors>0)
{return false;}
previousStepElem=$('#mainNav .current').prev();nextStepElem=$('#mainNav .current').next();currentElem=$('#mainNav .current');nextStepElem.addClass('current');nextStepElem.children('a').attr('href','#')
currentElem.removeClass('current').addClass('lastDone');previousStepElem.removeClass('lastDone').addClass('done');bindSteps()
hasErrors=0;validateErrors=0;var myParent=$(this).parent();$(myParent).fadeOut('normal',function(){myParent.next().slideDown();});return false;});$('.prev').click(function(){hasErrors=checkEmpty($('#mainNav li.current a').attr('rel'));if(hasErrors>0||validateErrors>0)
{return false;}
var myParent=$(this).parent();$(myParent).fadeOut('normal',function(){myParent.prev().slideDown();});previousStepElem=$('#mainNav .current').prev();nextStepElem=$('#mainNav .current').next();currentElem=$('#mainNav .current');currentElem.removeClass('current');previousStepElem.removeClass('lastDone').addClass('current');previousStepElem.prev().removeClass('done').addClass('lastDone');return false;});function ajaxValidate(elem,check)
{if(check!=undefined){var this_elem=check;}
else{var this_elem=$(this);}
if(this_elem.val()=='')
{this_elem.removeClass('form_error');this_elem.parent().next().slideUp();return;}
var field_name=this_elem.attr('name');$.post($('#pform').attr('action'),{submit:'ajax_maxhypo',field_name:this_elem.attr('name'),field_value:this_elem.val()},function(json){if(json.success==0){show_error(this_elem,json.error_message);validateErrors++;}
else
{validateErrors--;}},"json")}
$('.validate_ajax').blur(ajaxValidate);function attachSubmitHandler()
{$('#pform').submit(function(){var nodeList={submit:'ajax_maxhypo'}
$("#pform ol li input, #pform ol li select").each(function(){if($(this).val()!=''){nodeList[$(this).attr('name')]=$(this).val();}})
$.post($(this).attr('action'),nodeList,function(json){$('#form_block_content').fadeOut('slow',function(){$('#form_block_content').html(json.contents.text);$('#form_block_content').fadeIn('slow');})},"json")
return false;});}});
