
function join_now(version,tracking_names,auto_submit){jn_self=this;this.aj=new AJAX();this.region_city_aj=new AJAX();this.profiles_aj=new AJAX();this.version=version;this.form_inputs;this.curr_frame;this.first_frame=1;this.count_frame=1;this.form_errors=false;this.country_overide=false;this.profiles;this.display_profiles=3;this.curr_profile_set=0;this.tracking_names=tracking_names;this.next_frame_id=1;this.auto_submit=auto_submit;this.last_frame_shown=null;this.submit_form_version=1;this.sf=new AJAX();this.submit_uri=null;this.gender=-1;this.finish_mobile_reg=0;this.submit_frame=function(frame,elm){if('frame_last'==frame){getioBB(0);}
this.curr_frame=document.getElementById(frame);this.form_inputs=this.get_all_child_inputs(this.curr_frame);this.validate();}
this.get_all_child_inputs=function(frame){var all_inputs=new Array();all_inputs['selects']=frame.getElementsByTagName('select');all_inputs['inputs']=frame.getElementsByTagName('input');all_inputs['textarea']=frame.getElementsByTagName('textarea');return all_inputs;}
this.validate=function(){var uri="/xmlhttp/ajax_joinnow.html?version="+this.version;this.frame_first_question_name=undefined
for(var i in this.form_inputs){for(var z=0;z<this.form_inputs[i].length;z++){var tmp=this.form_inputs[i];if((('radio'==tmp[z].type||'checkbox'==tmp[z].type)&&true==tmp[z].checked)||('radio'!=tmp[z].type&&'checkbox'!=tmp[z].type)){uri+='&'+tmp[z].name+"="+TOOLS.urlencode(tmp[z].value);}
if('has_gender'==tmp[z].name&&-1!=tmp[z].value){this.display_profiles=DOM.getElementsByClassName('reg_profile','img');this.profiles_aj.fetch('/xmlhttp/reg_profiles.html?g='+tmp[z].value+'&cnt='+this.display_profiles.length);}else if(this.finish_mobile_reg==1){this.display_profiles=DOM.getElementsByClassName('reg_profile','img');this.profiles_aj.fetch('/xmlhttp/reg_profiles.html?g='+this.gender+'&cnt='+this.display_profiles.length);}}}
this.aj.fetch(uri);}
this.aj.onRequestComplete=function(){if(jn_self.form_errors.status=='ok'){jn_self.next_frame();}else if(jn_self.form_errors.status=='rejected'){document.location.replace('/joinnow_non_qualified.html');}else if(jn_self.form_errors.status=='fatal_error'){if(jn_self.finish_mobile_reg==1){document.location.replace('/promo/finish_mobile_registration.html');}else{document.location.replace('/singles-signup.html');}}else{jn_self.display_errors();if(jn_self.last_frame_shown!=null){jn_self.last_frame_shown.className="frame displaynone";jn_self.last_frame_shown=null;jn_self.curr_frame.className="frame";}else{jn_self.curr_frame=DOM.prevElm(jn_self.curr_frame);}}}
this.next_frame=function(){if(this.first_frame==this.count_frame){this.custom_anime();this.count_frame++;}else{if(this.count_frame>this.first_frame){jn_self.rotate_profiles();}
this.count_frame++;}
if('frame_last'!=this.curr_frame.id){var next_frame_id=jn_self.next_frame_id;if(this.auto_submit[next_frame_id]==1){if(this.first_frame==this.count_frame){this.first_frame++;}
if(this.last_frame_shown==null){this.last_frame_shown=this.curr_frame;}
this.submit_frame(next_frame_id);}else{this.custom_omniture(next_frame_id+'  '+this.tracking_names[next_frame_id]);if(this.last_frame_shown!=null){this.last_frame_shown.className="frame displaynone";this.last_frame_shown=null;}
this.curr_frame.className="frame displaynone";document.getElementById(next_frame_id).className="frame";}}
if('frame_last'==this.curr_frame.id){if(this.submit_form_version==2){document.getElementById('reg-form').innerHTML='<div id="success"><h1 id="pagetitle">Please Wait...</h1><div class="full minheight" id="body_column"><div class="bodyblock nobottom pad"><p>We are creating your profile.  Please wait a moment.</p></div></div></div>';this.sf.fetch(this.submit_uri);setTimeout('join_now.sf.fetch(join_now.submit_uri + "&resubmit=1");',30000);setTimeout('document.location="/central/index.html?popup=congratulations"',60000);}else{document.getElementById('ajax_reg_form').submit();}}
this.clear_errors();}
this.sf.processResponse=function(response){setTimeout('document.location="'+response+'"',1000);}
this.check_first_frame=function(){this.first_frame++;this.submit_frame('frame_1');}
this.back_frame=function(){var next_frame_id=this.curr_frame.id;this.auto_submit=new Array();this.custom_omniture(next_frame_id+'  '+this.tracking_names[next_frame_id]);this.curr_frame.className="frame";DOM.nextElm(this.curr_frame).className="frame displaynone";this.curr_frame=DOM.prevElm(this.curr_frame);}
this.rotate_profiles=function(){if(0!=jn_self.profiles.length){for(var i in this.display_profiles){this.display_profiles[i].src=jn_self.profiles[this.curr_profile_set%this.display_profiles.length][i].thumb;}
this.curr_profile_set++;}}
this.display_errors=function(){this.clear_errors();for(var i in this.form_errors.errors){if(i=='captcha'){var now=new Date();document.getElementById('captcha_img').src='captcha.html?'+now.getTime();}
document.getElementById('error_msg_'+i).innerHTML=this.form_errors.errors[i].error_msg;if('location_country'==i&&''!=document.getElementById('extra_postal_code').value){this.country_overide=true;if(document.getElementById('region_dropdown')==undefined){this.region_city(document.getElementById('has_location_country_dropdown'),'region')}
document.getElementById('extra_postal_code').value='';}}
this.custom_error_anime();}
this.clear_errors=function(){var display_error_elms=DOM.getElementsByClassName('form_elm_error_msg');for(var i in display_error_elms){display_error_elms[i].innerHTML='';display_error_elms[i].style.color='';}}
this.check_country=function(){var country_dd=document.getElementById('has_location_country_dropdown');if(undefined!=country_dd){if(country_dd.value!=1&&country_dd.value!=42){join_now.region_city(country_dd,'region')}}}
this.country_change=function(elm,mode){this.country_overide=false;document.getElementById('extra_postal_code').value='';this.region_city(elm,mode);}
this.region_city=function(elm,mode){var country=document.getElementById('has_location_country_dropdown').value;if((1!=country&&42!=country)||true==this.country_overide){this.clear_errors();if('region'==mode){document.getElementById('city_holder').innerHTML='';document.getElementById('region_holder').innerHTML='';var uri="/xmlhttp/region_city.html?country="+elm.value;this.region_city_aj.innerHTML('region_holder',uri);}else if('city'==mode){document.getElementById('city_holder').innerHTML=''
if(elm.value!=-1){var uri="/xmlhttp/region_city.html?country="+country+"&region="+elm.value;this.region_city_aj.innerHTML('city_holder',uri);}}
document.getElementById('postal_code').style.display='none';}else{document.getElementById('postal_code').style.display='block';document.getElementById('city_holder').innerHTML=''
document.getElementById('region_holder').innerHTML=''}}
this.ministry_keyup=function(elm,e){var search_str=$('#extra_ministry_other').val();jQuery.get('/xmlhttp/ajax_ministry_lookup.html',{search:search_str},function(data){if(null==data||''==data){$('#search_container').hide();$('#search_container').html('');}else{var items='';for(x in data){items+='<li>'+data[x]+'</li>';}
$('#search_container').html(items);$('#search_container').show();}},'json');}
this.custom_anime=function(){var anime=new Animator({durration:500});var tmp=document.getElementById('pagetitle');anime.addSubject(new NumericalStyleSubject(tmp,'opacity',1,0));anime.play();}
this.custom_error_anime=function(){var error_anime=new Animator({durration:500});var tmp=DOM.getElementsByClassName('form_elm_error_msg','span');error_anime.addSubject(new ColorStyleSubject(tmp,'color','#FFFFFF','#FF0000'));error_anime.play();}
this.custom_omniture=function(frame){}
this.profiles_aj.processResponse=function(response){jn_self.profiles=eval('('+response+')');jn_self.rotate_profiles();}
this.aj.processResponse=function(response){var tmp=eval('('+response+')');jn_self.form_errors=new Array();jn_self.form_errors['status']=tmp.status;if(tmp.errors){jn_self.form_errors['errors']=tmp.errors;}
if(tmp.next_frame){jn_self.next_frame_id=tmp.next_frame;}}}
