
function join_now(version,tracking_names){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=true;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.submit_frame=function(frame,elm){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);}}}
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'){document.location.replace('/singles-signup.html');}else{jn_self.display_errors();jn_self.curr_frame=DOM.prevElm(jn_self.curr_frame);}}
this.next_frame=function(){if(this.first_frame){this.custom_anime();this.first_frame=false;}else{jn_self.rotate_profiles();}
if('frame_last'!=this.curr_frame.id){var next_frame_id=DOM.nextElm(this.curr_frame).id;this.custom_omniture(next_frame_id+'  '+this.tracking_names[next_frame_id]);this.curr_frame.style.display="none";DOM.nextElm(this.curr_frame).className="frame";}
if('frame_last'==this.curr_frame.id){document.getElementById('ajax_reg_form').submit();}
this.clear_errors();}
this.back_frame=function(){var next_frame_id=this.curr_frame.id;this.custom_omniture(next_frame_id+'  '+this.tracking_names[next_frame_id]);this.curr_frame.style.display="block";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.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.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){jn_self.form_errors=eval('('+response+')');}}