
	
	$j(function(){
		// get the referral cookie
		$j("#referral").val(Ka.Cookie.read("affiliateReferral"));
	});
		
	// set the validation boolean
	var ka_ks_valid     =    true;
	// set the error field
	var ka_ks_errorF    =    '';

	// hits link tracking
    var Ka_hitsTracking                    =    {
  											        form:    			{},
        										    url:    			'https://counter.hitslink.com/confirmation.asp?acct=kickapps&type=56216&s=1&uniqueId=',
        										    track: 			    function(email,form)
        										  					    {
        										  					    	// set the form
        										  					    	Ka_hitsTracking.form								 =    form;
                														    var tImage   										 = 	  new Image();
                														    tImage.src 										     =    Ka_hitsTracking.url+(email);
                													        setTimeout(function(){
                													    		Ka_hitsTracking.form.submit();
                													    	}, 3000);
                													    }
                							    };

	// array to store the possible error messages
	var ka_ks_errorM   				  =    new Array();
	ka_ks_errorM['firstName']		  =    'Your name is required.';
	ka_ks_errorM['username']		  =    'Your username must be between 4 and 24 characters long.';
	ka_ks_errorM['usernameF']		  =    'Your username can only have numbers, letters or underscores.';
	ka_ks_errorM['usernameE']		  =    'This username is already in use.';
	ka_ks_errorM['email']       	  =    'Please enter a valid email address.';
	ka_ks_errorM['emailE']       	  =    'This email address is already in use.';
	ka_ks_errorM['password']		  =    'Password must be 4 to 24 characters long.';
	ka_ks_errorM['siteName']          =    'Community name must be 4 to 40 characters long.';
	ka_ks_errorM['siteNameA']         =    'Name can only have letters, numbers, spaces and apostrophes.';
	ka_ks_errorM['siteNameE']         =    'Your community name is already in use.';
	ka_ks_errorM['tos']     		  =    'You forgot to agree to KickApps\' TOS.';
	ka_ks_errorM['captcha'] 		  =    'CAPTCHA test failed. Please try again.';
	ka_ks_errorM['urlIssue'] 		  =    'Please enter a valid URL.';

	// array to store the error message associated fields
	var ka_ks_errorA				  =    new Array();
	ka_ks_errorA['firstName']		  =    'firstNameEr';
	ka_ks_errorA['username']		  =    'usernameEr';
	ka_ks_errorA['usernameF']		  =    'usernameEr';
	ka_ks_errorA['usernameE']		  =    'usernameEr';
	ka_ks_errorA['email']       	  =    'emailEr';
	ka_ks_errorA['emailE']       	  =    'emailEr';
	ka_ks_errorA['password']		  =    'passwordEr';
	ka_ks_errorA['siteName']          =    'siteNameEr';
	ka_ks_errorA['siteNameA']         =    'siteNameEr';
	ka_ks_errorA['siteNameE']         =    'siteNameEr';
	ka_ks_errorA['tos']     		  =    'termsOfUseEr';
	ka_ks_errorA['captcha'] 		  =    'securityImageTextEr';
	ka_ks_errorA['urlIssue'] 		  =    'homePageURLEr';

    // array to store the bubble text
    var ka_ks_bubbles                 =    new Array();
    ka_ks_bubbles['videos']           =    'Lets members contribute videos to your community. You can review, approve, and reject videos before they go live on your site.';
    ka_ks_bubbles['audio']            =    'Lets members contribute audio tracks to your community. You can review, approve, and reject audio tracks before they go live on your site.';
    ka_ks_bubbles['photos']           =    'Lets members contribute photos to your community. You can review, approve, and reject photos before they go live on your site.';
    ka_ks_bubbles['blogs']            =    'Lets members contribute blogs to your community. You can review, approve, and reject blogs before they go live on your site.';
    ka_ks_bubbles['groups']           =    'Lets members request and join groups. Groups have their own homepages and widgets. They offer members a way to interact with each other around common interests.';
    ka_ks_bubbles['messageBoards']    =    'Lets members have discussions in public forums. You can edit members\' message board posts.';
    ka_ks_bubbles['pnls']     		  =    'Lets members earn points for contributing to your community.  You can define status levels (e.g., "Silver Member", "Gold Member") that your members can attain by earning enough points.';
    ka_ks_bubbles['chat']    		  =    'Lets members have live chat room and instant message conversations.';
    ka_ks_bubbles['ws']     		  =    'Build completely custom video players, audio players, slideshows, interactive widgets with chat and maps, and rich media ads, all within an easy-to-use WYSIWYG interface. Easily add your widgets to your own site, your KickApps-powered pages, or syndicate to Facebook, MySpace, or any other destination across the web. Monetize your widgets with in-stream video and Flash-in-Flash display advertising (built-in support for all the major ad networks)';

    // add the events for apply buttons
    Ka.addDOMLoadEvent
    (
        // 
        function()
        {
			if(Ka.Cookie.read('domainAffiliate')==='buydomains.com')
			{
			    var hiddenSKU = document.createElement('input');
			    hiddenSKU.type = 'hidden';
			    hiddenSKU.value = '1_1';
			    hiddenSKU.name = 'SKU';
			    hiddenSKU.id = 'SKU';
			    document.getElementById('affiliateForm').appendChild(hiddenSKU);
			}

        	// load themes for IE 6
        	if(navigator.userAgent.toLowerCase().indexOf('msie')!=-1 && navigator.userAgent.toLowerCase().indexOf('6.0')!=-1)
        	{
        		// 
        		for(var q=0;q< 14;q++)
        		{
	        		// 
	        		var preview     =    new Image();
	        		preview.src     =    Ka.Info.STATICSERVERIMAGES+'/themes/themeThumbs/themePreview'+(q+1)+'L.jpg';
        		}
        	}
            // set up the default themes
            ka_ks_setup_themes();
            // loop through the tab check boxes
            for(var x=0;x<Ka.$('.ka_ks_tabChecks').length;x++)
            {
            	// if it's not the userplane chat checkbox
            	if(Ka.$('.ka_ks_tabChecks')[x].id!='chatFeature')
            	{
	                // make sure they are checked (as caching sometimes occurs)
	                Ka.$('.ka_ks_tabChecks')[x].checked    =    'checked';
	            }
            }
            // make sure the hompage checkbox is not checked
            Ka.$('#useHomePage').checked    =    'checked';
           

            // add the events for the preview links
            for(var x=1;x<Ka.$('.ka_ks_preview_link').length;x++)
            {
                // add the click event to the link
                Ka.addEvent
                (
                    // the object
                    Ka.$('.ka_ks_preview_link')[x],
                    // the event
                    'click',
                    // the action/function
                    function()
                    {
                        // if it's the current theme container
                        if(this.parentNode.parentNode.parentNode.tagName.toLowerCase()=='div')
                        {
                            // preview theme function
                            ka_ks_previewTheme(this.parentNode.parentNode.className.split('ka_ks_theme ka_ks_current_theme')[1]);
                        }
                        // otherwise it's a normal list item (in the list of themes)
                        else
                        {
                            // preview theme function
                            ka_ks_previewTheme(this.parentNode.parentNode.className.split('ka_ks_theme ka_ks_theme')[1]);
                        }
                    }
                );
                // add the click event to the image
                Ka.addEvent
                (
                    // the object
                    Ka.$('.ka_ks_preview_link')[x].parentNode.parentNode.getElementsByTagName('img')[0],
                    // the event
                    'click',
                    // the action/function
                    function()
                    {
                        // if it's the current theme container
                        if(this.parentNode.parentNode.parentNode.tagName.toLowerCase()=='div')
                        {
                            // preview theme function
                            ka_ks_previewTheme(this.parentNode.parentNode.className.split('ka_ks_theme ka_ks_current_theme')[1]);
                        }
                        // otherwise it's a normal list item (in the list of themes)
                        else
                        {
                            // preview theme function
                            ka_ks_previewTheme(this.parentNode.parentNode.className.split('ka_ks_theme ka_ks_theme')[1]);
                        }
                    }
                );
            }
            // loop through the page input fields
            for(var x=0;x<document.getElementsByTagName('input').length;x++)
            {
            	// set the field
            	var field    =    document.getElementsByTagName('input')[x];
            	// if it's a text or password field
            	if(field.type=='text' || field.type=='password')
            	{
	                // add the keydown event to the input field
	                Ka.addEvent
	                (
	                    // the object
	                    field,
	                    // the event
	                    'keydown',
	                    // the action/function
	                    function(e)
	                    {
	                    	// 
							var code;
							if (!e) var e = window.event;
							if (e.keyCode) code = e.keyCode;
							else if (e.which) code = e.which;
							// if it's the entire key
							if(code==13)
							{
	                            // stop the default action
								e.cancelBubble    =    true;
    							e.returnValue     =    false;
								
								// if it's a firefox (method check)
								if(e.stopPropagation)
								{
								    // stop the default action
								    e.stopPropagation();
								    e.preventDefault();
								}
								// if it's not for the homepage input field
								if(this.id!='homePageURL')
								{
									// advance to step 2
									ka_ks_step('2');
								}
								// otherwise if it is
								else
								{
									// call function to finish
									ka_ks_step('finish');
								}
							}
	                    }
	                );
	            }
            }
            // add the events for the apply links
            for(var x=0;x<Ka.$('.ka_ks_apply_link').length;x++)
            {
                // add the click event
                Ka.addEvent
                (
                    // the object
                    Ka.$('.ka_ks_apply_link')[x],
                    // the event
                    'click',
                    // the action/function
                    function()
                    {
                        // kickstart apply theme function
                        ka_ks_applyTheme(this);
                    }
                );
            }
            // apply the first theme to be 'applied'
            ka_ks_applyTheme(Ka.$('.ka_ks_theme1')[0].getElementsByTagName('a')[2]);
            // focus on the name
            Ka.$('#firstName').focus();
        }
    );

    // function to advanced submit
    function ka_ks_advSub()
    {
    	// if the form hasn't been submitted
    	if(!ka_ks_submitted)
    	{
    	    // set the advanced hidden variable for the post handling
    	    Ka.$('#step_value').value    =    '2';
    		// set it to not be submittable
    		ka_ks_submitted    			 =    true;
    		// timeout for IE6
    		setTimeout
    		(
    			function()
    			{
    				// analytics code
    				pageTracker._trackPageview('/KS2-ADVFINISH');
    				// launch tracking and submit action
    				Ka_hitsTracking.track(Ka.$('#email').value,Ka.$('#affiliateForm'));
	            	// hide the step buttons
	            	Ka.$('.ka_ks_step_footer')[1].style.visibility    =    'hidden';
    			},
    			100
    		);
    	}
    }

	// function to update a timestamp
	function ka_ks_update_tmsp(themeObj,attribute)
	{
		// local date object
		var lo_date                       =    new Date();
		// set the last editted timestamp
		themeObj.attributes[attribute]    =    lo_date.getFullYear()+'-'+
		                                       ((lo_date.getMonth()+1)<10 ? ('0'+(lo_date.getMonth()+1)) : (lo_date.getMonth()+1))+'-'+
		                                       (lo_date.getDate()<10 ? ('0'+lo_date.getDate()) : lo_date.getDate())+' '+
		                                       (lo_date.getHours()<10 ? ('0'+lo_date.getHours()) : lo_date.getHours())+':'+
		                                       (lo_date.getMinutes()<10 ? ('0'+lo_date.getMinutes()) : lo_date.getMinutes())+':'+
		                                       (lo_date.getSeconds()<10 ? ('0'+lo_date.getSeconds()) : lo_date.getSeconds())+':'+
		                                       (lo_date.getMilliseconds()<10 ? ('0'+lo_date.getMilliseconds()) : lo_date.getMilliseconds());
	}

    // function to apply a theme
    function ka_ks_applyTheme(link)
    {
		// store the object
		var newTheme			      											 =    ga_defaultThemes[parseInt(link.parentNode.parentNode.className.split('ka_ks_theme ka_ks_theme')[1])-1];
		// set the created date of the theme
		ka_ks_update_tmsp(newTheme,'created');
		// set the updated date of the theme
		ka_ks_update_tmsp(newTheme,'edited');
		// set it to be selected
		newTheme.attributes.active    											 =    true;
        // store the theme JSON object
        Ka.$('#themeJSON').value      											 =    ka_toJSONString(newTheme);
        // store the theme CSS
        Ka.$('#themeCSS').value       											 =    ga_defaultThemesCSS[parseInt(link.parentNode.parentNode.className.split('ka_ks_theme ka_ks_theme')[1])-1];

        // apply the theme
//        Ka.LE.theme.apply(newTheme);
        // remove whichever one is currently selected (in the list of themes)
        Ka.$('.ka_ks_preview_theme')[1].className                                =    '';
        // remove the previous previewed link class for it being applied (so it no longer looks clickable)
        Ka.$('.ka_ks_apply_s_link')[0].className                                 =    'ka_ks_apply_link';
        // add the new applied theme link to be selected
        link.className                                                           =    'ka_ks_apply_s_link ka_ks_apply_link';
        // add the new theme's container to be selected
        link.parentNode.parentNode.parentNode.className                          =    'ka_ks_preview_theme';
        // switch the image of the current theme container
//        Ka.$('#ka_ks_current_theme').getElementsByTagName('img')[0].src          =    link.parentNode.parentNode.getElementsByTagName('img')[0].src;
        // change the text node for the theme title
        Ka.$('.ka_ks_theme_title')[0].innerHTML                                  =    link.parentNode.parentNode.getElementsByTagName('div')[0].innerHTML;
        // change the link action
        Ka.$('#ka_ks_current_theme').getElementsByTagName('div')[0].className    =    'ka_ks_theme ka_ks_current_theme'+link.parentNode.parentNode.className.split('ka_ks_theme ka_ks_theme')[1];
    }

    // function to preview a theme
    function ka_ks_previewTheme(themeCount)
    {
    	// if it's for the 0'th or the last plus 1 (safari issue - KA-5520 #2)
    	if(themeCount==0 || themeCount==Ka.$('.ka_ks_theme').length)
    	{
    		// do nothing
    		return;
    	}
    	// otherwise it's within range 
    	else
    	{
    	//http://192.168.1.100:8080/kickapps/user/displayAffiliateRegisterPage.kickAction?STATUS=MAIN
	        // set the image
	    	var image = new Image();
	    	image.src = Ka.Info.STATICSERVERIMAGES+'/themes/themeThumbs/themePreview'+parseInt(themeCount)+'L.jpg';
    	
	        setTimeout(function(){Ka.$('#ka_ks_preview_content').getElementsByTagName('img')[0].src    =    image.src;},100);
	        // set the title
	        Ka.$('#ka_ks_preview_title').innerHTML                               =    Ka.$('.ka_ks_theme_title')[themeCount].innerHTML;
	        // set the theme count
	        Ka.$('#ka_ks_preview_count').innerHTML                               =    '('+themeCount+'/'+(Ka.$('.ka_ks_theme').length-1)+')';
	        // if it's already the currently set theme
	        if(Ka.$('#ka_ks_current_theme').getElementsByTagName('div')[1].innerHTML==Ka.$('.ka_ks_theme'+themeCount)[0].getElementsByTagName('div')[0].innerHTML)
	        {
	            // set the button to be the 'current theme' button
	            Ka.$('#ka_ks_preview_button').getElementsByTagName('img')[0].src           =    Ka.Info.STATICSERVERIMAGES+'/KS/currentTheme.gif';
	            // set the cursor
	            Ka.$('#ka_ks_preview_button').getElementsByTagName('a')[0].style.cursor    =    'default';
	        }
	        // otherwise it's not the currently set theme
	        else
	        {
	            // set the button to be the 'apply this theme' button
	            setTimeout(function(){Ka.$('#ka_ks_preview_button').getElementsByTagName('img')[0].src           =    Ka.Info.STATICSERVERIMAGES+'/KS/applyThemeButton.gif';},100);
	            // set the cursor
	            Ka.$('#ka_ks_preview_button').getElementsByTagName('a')[0].style.cursor    =    'pointer';
	        }
	        // set the visibility of the next/previous links
	        Ka.$('#ka_ks_preview_next').style.visibility                         =    'visible';
	        Ka.$('#ka_ks_preview_prev').style.visibility                         =    'visible';

            // set the cursor types (KA-5520 #2)
            Ka.$('#ka_ks_preview_prev').style.cursor                             =    'pointer';
            Ka.$('#ka_ks_preview_next').style.cursor                             =    'pointer';

	        // if it's the first theme
	        if(themeCount==1)
	        {
	            // hide the previous link
	            Ka.$('#ka_ks_preview_prev').style.visibility                               =    'hidden';
	            // set the cursor type (KA-5520 #2)
	            Ka.$('#ka_ks_preview_prev').style.cursor                                   =    'default';
	        }
	        // otherwise if it's the last theme
	        else if(themeCount==(Ka.$('.ka_ks_theme').length-1))
	        {
	            // hide the next link, but show the first one
	            Ka.$('#ka_ks_preview_next').style.visibility                               =    'hidden';
	            // set the cursor type (KA-5520 #2)
	            Ka.$('#ka_ks_preview_next').style.cursor                                   =    'default';
	        }
	        // set the onclick for the previous theme preview button
	        Ka.$('#ka_ks_preview_prev').getElementsByTagName('a')[0].onclick     =    function() { ka_ks_previewTheme(parseInt(themeCount)-1); };
	        // set the onclick for the next theme next button
	        Ka.$('#ka_ks_preview_next').getElementsByTagName('a')[0].onclick     =    function() { ka_ks_previewTheme(parseInt(themeCount)+1); };
	        // show the theme preview
	        Ka.popup('#ka_ks_preview_hidden');
	    }
    }

    // function to toggle the tabs
    function ka_ks_tab_toggle(tab)
    {
        // set the visibility in the sample nav bar
        Ka.$('#ka_ks_'+tab+'Tab').style.display    =    Ka.$('#ka_ks_'+tab+'Tab').style.display!='none' ? 'none' : 'block';
        // if it's the homepage
        if(tab=='home')
        {
            // if the home tab is visible
            if(Ka.$('#ka_ks_'+tab+'Tab').style.display=='block')
            {
                // focus on it
                Ka.$('#homePageURL').focus();
            }
            // empty out the address string
            Ka.$('#homePageURL').value    =    '';
        }
        
        //If it's points and levels
        //if(tab=='pointsNlevel')
       // {
            // if the home tab is visible
         //   if(Ka.$('#ka_ks_'+tab+'Tab').style.display=='none')
           // {
                // Prompt user
			//	$j('#pointswarning').show('slow');
           // } else {
           // 	$j('#pointswarning').hide('slow');
           // }
            
       // }
    }

    // function to create a theme list item
    function ka_ks_setup_themes()
    {
        // loop through the themes
        for(var x=0;x<ga_defaultThemes.length;x++)
        {
            // create the list item
            var lo_listItem           =    Ka.UI.element.create('li',{'className':(x==0 ? 'ka_ks_preview_theme' : '')});
            // create the container
            var lo_themeCont          =    Ka.UI.element.create('div',{'className':'ka_ks_theme ka_ks_theme'+(x+1)});
            // create the preview image link
            var lo_imgLink            =    Ka.UI.element.create('a',{'title':ga_defaultThemes[x].attributes.name,'href':'javascript: ;'});
            // create the preview image
	            var lo_prevImg            =    Ka.UI.element.create('img',{'class':'ka_ks_preview_img','alt':ga_defaultThemes[x].attributes.name,'src':ga_defaultThemes[x].attributes.thumbnail});
            // create the theme title
            var lo_title              =    Ka.UI.element.create('div',{'class':'ka_ks_theme_title'});
            lo_title.innerHTML        =    ga_defaultThemes[x].attributes.name;
            // create the links container
            var lo_links              =    Ka.UI.element.create('div',{'class':'ka_ks_theme_links'});
            // create the preview text link
            var lo_prevLink           =    Ka.UI.element.create('a',{'class':'ka_ks_preview_link','title':'','href':'javascript: ;'});
            lo_prevLink.innerHTML     =    'Preview';
            // create the spacer
            var lo_spacer             =    Ka.UI.element.create('span');
            lo_spacer.innerHTML       =    '&nbsp;&nbsp;';
            // create the apply text link
            var lo_applyLink          =    Ka.UI.element.create('a',{'class':(x==0 ? 'ka_ks_apply_s_link ' : '')+'ka_ks_apply_link','title':'','href':'javascript: ;'});
            lo_applyLink.innerHTML    =    'Apply';
            // add them to the proper DOM tree
            lo_links.appendChild(lo_prevLink);
            lo_links.appendChild(lo_spacer);
            lo_links.appendChild(lo_applyLink);
            lo_imgLink.appendChild(lo_prevImg);
            lo_themeCont.appendChild(lo_imgLink);
            lo_themeCont.appendChild(lo_title);
            lo_themeCont.appendChild(lo_links);
            lo_listItem.appendChild(lo_themeCont);
            Ka.$('#ka_ks_themes').appendChild(lo_listItem);
        }
    }

    // function to show the tab bubble
    function ka_ks_show_bubble(source,tab)
    {
        // if its ie
        if(navigator.userAgent.toLowerCase().indexOf('msie')!=-1)
        {
            // if it's the video tab
            if(tab=='videos')
            {
                // hide proper image
                Ka.$('.ka_ks_tab_info')[3].style.visibility = 'hidden';
            }
            // otherwise if it's the audio tab
            else if(tab=='audio')
            {
                // hide proper images
                Ka.$('.ka_ks_tab_info')[3].style.visibility = 'hidden';
                Ka.$('.ka_ks_tab_info')[4].style.visibility = 'hidden';
            }
            // otherwise if its the photos tab
            else if(tab=='photos')
            {
                // hide proper images
                Ka.$('.ka_ks_tab_info')[3].style.visibility = 'hidden';
                Ka.$('.ka_ks_tab_info')[4].style.visibility = 'hidden';
                Ka.$('.ka_ks_tab_info')[5].style.visibility = 'hidden';
            }
        }
        // set the content
        Ka.$('.ka_ks_bubbleMain')[0].getElementsByTagName('div')[0].innerHTML    =    ka_ks_bubbles[tab];
        // add the bubble to the tab icon's DOM
        source.parentNode.appendChild(Ka.$('.ka_ks_bubbleWrap')[0]);
        // show the bubble
        Ka.$('.ka_ks_bubbleWrap')[0].style.display    =    'block';
    }

    // function to hide the tab bubble
    function ka_ks_hide_bubble(evt,tab)
    {
        // show the proper images
        Ka.$('.ka_ks_tab_info')[3].style.visibility = 'visible';
        Ka.$('.ka_ks_tab_info')[4].style.visibility = 'visible';
        Ka.$('.ka_ks_tab_info')[5].style.visibility = 'visible';
        // hide the bubble
        Ka.$('.ka_ks_bubbleWrap')[0].style.display    =    'none';
    }

	// 
	var ka_ks_submitted    =    false;

    // function to add go to a new step
    function ka_ks_step(step,direction)
    {
        // if the direction is backward
        if(direction=='back')
        {
            // hide all
            Ka.hide('.ka_ks_step');
            // show the step
            Ka.show('#ka_ks_step'+step);
        }
        // otherwise it's forward
        else
        {
            // if it's for step 2 (from step 1)
            if(step=='2')
            {
            	// validate it
            	ka_ks_validate();
            }
            // otherwise if it's for step 3 (from step 2)
            else if(step=='3')
            {
	            // hide all
	            Ka.hide('.ka_ks_step');
                // show step 3
                Ka.show('#ka_ks_step3');
                // analytics code
				pageTracker._trackPageview('/KS2-KS3');
            }
            // otherwise if it's to finish (from step 3)
            else if(step=='finish')
            {
            	// hide the steps and show the "please wait" message
            	$j(".ka_ks_step").hide();
            	$j("#ka_ks_step4")
            	    .css({height: $j("#ka_ks_step3").height()})
            	    .fadeIn();
            	
				// strip out any error html
				for(var x=0;x<Ka.$('.ka_ks_error').length;x++)
				{
					// strip out any html
					Ka.$('.ka_ks_error')[x].innerHTML    =    '';
				}
            	// set a variable to track whether the homepage url is valid
            	var ka_ks_hp_valid    =    true;
				// if the homepage url is to be included and is not valid (is not empty and is not formatted properly)
				if(Ka.$('#useHomePage').checked==true && Ka.$('#homePageURL').value!='' && !Ka.formValidation.rulesArray[2].test(Ka.$('#homePageURL').value))
				{
					// mark that the url is not valid
					ka_ks_errorF    =	 'urlIssue';
					// mark that validation has failed
//					ka_ks_valid     =    false;
					// mark that it's not valid for the suubmission
					ka_ks_hp_valid  =    false;
				}
            	// if the form hasn't been submitted, and the homepage url is valid
            	if(!ka_ks_submitted && ka_ks_hp_valid)
            	{
            		// set it to not be submittable
            		ka_ks_submitted    =    true;
            		// timeout for IE6
            		setTimeout
            		(
            			function()
            			{
            				// analytics code
		    				pageTracker._trackPageview('/KS3-FINISH');
		    				// launch tracking and submit action
		    				Ka_hitsTracking.track(Ka.$('#email').value,Ka.$('#affiliateForm'));
			            	// hide the step buttons
			            	Ka.$('.ka_ks_step_footer')[2].style.visibility    =    'hidden';
            			},
            			100
            		);
            	}
            	// otherwise if an error was encountered
            	else
            	{
		        	// show the error message
		        	Ka.$('#'+ka_ks_errorA[ka_ks_errorF]).innerHTML    =    ka_ks_errorM[ka_ks_errorF];
		        	// focus on the field
		        	Ka.$('#'+ka_ks_errorA[ka_ks_errorF].substring(0,ka_ks_errorA[ka_ks_errorF].length-2)).focus();
		        	// reset the validation info
//		        	ka_ks_valid     =    true;	
		        	ka_ks_errorF    =    '';
            	}
            }
        }
    }

	// function to handle validation
	function ka_ks_validate()
	{
		
		// strip out any error html
		for(var x=0;x<Ka.$('.ka_ks_error').length;x++)
		{
			// strip out any html
			Ka.$('.ka_ks_error')[x].innerHTML    =    '';
		}

		// if the name is not filled
		if(Ka.$('#firstName').value=='')
		{
			// mark that the name was not met
			ka_ks_errorF    =	 'firstName';
			// mark that validation has failed
			ka_ks_valid     =    false;
		}
		// otherwise if the email is not valid
		else if(!Ka.formValidation.rulesArray[10].test(Ka.$('#email').value))
		{
			// mark that the email was not met
			ka_ks_errorF    =	 'email';
			// mark that validation has failed
			ka_ks_valid     =    false;
		}
		// otherwise if the username is not between 4 and 24 characters long
		else if(Ka.$('#username').value.length<4 || Ka.$('#username').value.length>24)
		{
			// mark that the username was not met
			ka_ks_errorF    =	 'username';
			// mark that validation has failed
			ka_ks_valid     =    false;
		}
		// otherwise if the username is not alphanumeric
		else if(!Ka.formValidation.rulesArray[11].test(Ka.$('#username').value))
		{
			// mark that the username was not met
			ka_ks_errorF    =	 'usernameF';
			// mark that validation has failed
			ka_ks_valid     =    false;
		}
		// otherwise if the password is not between 4 and 24 characters long
		else if(Ka.$('#password').value.length<4 || Ka.$('#password').value.length>24)
		{
			// mark that the username was not met
			ka_ks_errorF    =	 'password';
			// mark that validation has failed
			ka_ks_valid     =    false;
		}
		// otherwise if the password is not equal to the confirm password field
//		else if(!Ka.formValidation.rulesArray[13].test(Ka.$('#password').value,'confirmPassword'))
//		{
//			// mark that the username was not met
//			ka_ks_errorF    =	 'passwordMatch';
//			// mark that validation has failed
//			ka_ks_valid     =    false;
//		}
		// otherwise if the name is not between 4 and 24 characters long
		else if(Ka.$('#siteName').value.length<4 || Ka.$('#siteName').value.length>40)
		{
			// mark that the username was not met
			ka_ks_errorF    =	 'siteName';
			// mark that validation has failed
			ka_ks_valid     =    false;
		}
		// otherwise if the site name contains an invalid character
		else if(new RegExp(/[^a-zA-Z0-9 \']/).test(Ka.$('#siteName').value)===true)
		{
			// mark that the siteName was not met
			ka_ks_errorF    =	 'siteNameA';
			// mark that validation has failed
			ka_ks_valid     =    false;
		}
		// otherwise if the TOS is not checked
		else if(!Ka.$('#termsOfUse').checked)
		{
			// mark that the username was not met
			ka_ks_errorF    =	 'tos';
			// mark that validation has failed
			ka_ks_valid     =    false;
		}

		// if the validation has passed thus far
		if(ka_ks_valid)
		{
	        // validate calls
			KickAppsBizComponent.kickStartValidation
			(
		  		1,
		  		Ka.$('#username').value,
		  		Ka.$('#email').value,
		  		Ka.$('#password').value,
		  		Ka.$('#firstName').value,
		  		Ka.$('#siteName').value,
		  		Ka.$('#termsOfUse').value,
		  		Ka.$('#securityImageText').value,
	  			function(map)
	  			{
	  				// if the username is already taken
	  				if(typeof map.usernameTaken!='undefined' && map.usernameTaken=='E_SORRY_AN_AFFILIATE_ACCOUNT_ALREADY_EXISTS_WITH_THAT_USERNAME')
	  				{
	  					// mark that the captcha did not match
	  					ka_ks_errorF    =	 'usernameE';
	  					// mark that validation has failed
	  					ka_ks_valid     =    false;
	  				}
	  				// otherwise if the email address is already taken
	  				else if(typeof map.emailTaken!='undefined' && map.emailTaken=='E_SORRY_AN_AFFILIATE_ACCOUNT_ALREADY_EXISTS_WITH_THAT_EMAIL')
	  				{
	  					// mark that the captcha did not match
	  					ka_ks_errorF    =	 'emailE';
	  					// mark that validation has failed
	  					ka_ks_valid     =    false;
	  				}
	  				// otherwise if the name of the community is already taken
	  				else if(typeof map.siteNameExists!='undefined' && map.siteNameExists=='Site name already exists. Please select another.')
	  				{
	  					// mark that the captcha did not match
	  					ka_ks_errorF    =	 'siteNameE';
	  					// mark that validation has failed
	  					ka_ks_valid     =    false;
	  				}
	  				// otherwise if the captch does not match
	  				else if(typeof map.securityImageText!='undefined' && map.securityImageText=='E_SECURITY_STRING_MISMATCH')
	  				{
	  					// mark that the captcha did not match
	  					ka_ks_errorF    =	 'captcha';
	  					// mark that validation has failed
	  					ka_ks_valid     =    false;
	  				}
			        // if it's been validated
			        if(ka_ks_valid)
			        {
		            	// analytics code
	    				pageTracker._trackPageview('/KS1-KS2');
			            // hide all
			            Ka.hide('#ka_ks_step1');
			            // show the step
			            Ka.show('#ka_ks_step2');
			        }
			        // otherwise if it hasn't
			        else
			        {
			        	// show the error message
			        	Ka.$('#'+ka_ks_errorA[ka_ks_errorF]).innerHTML    =    ka_ks_errorM[ka_ks_errorF];
			        	// focus on the field
			        	Ka.$('#'+ka_ks_errorA[ka_ks_errorF].substring(0,ka_ks_errorA[ka_ks_errorF].length-2)).focus();
			            // show the previous step
			            Ka.show('#ka_ks_step1');
			        	// reset the validation info
			        	ka_ks_valid     								  =    true;
			        	ka_ks_errorF    								  =    '';
			        }
	  			}
		  	);
		}
		// otherwise the validation has not passed
		else
		{
        	// show the error message
        	Ka.$('#'+ka_ks_errorA[ka_ks_errorF]).innerHTML    =    ka_ks_errorM[ka_ks_errorF];
        	// focus on the field
        	Ka.$('#'+ka_ks_errorA[ka_ks_errorF].substring(0,ka_ks_errorA[ka_ks_errorF].length-2)).focus();
        	// reset the validation info
        	ka_ks_valid     =    true;
        	ka_ks_errorF    =    '';
		}
	}

    // function to preview a theme's homepage
//    function ka_ks_homepage_preview()
//    {
//    	//http://192.168.1.100:8080/kickapps/user/displayAffiliateRegisterPage.kickAction?STATUS=MAIN
//    	new Image().src = Ka.Info.STATICSERVERIMAGES+'/themes/homeThumbs/theme'+Ka.$('.ka_ks_preview_theme')[1].getElementsByTagName('div')[0].className.split('ka_ks_theme ka_ks_theme')[1]+'Home.gif';
//        // set the image
//        Ka.$('#ka_ks_preview_content').getElementsByTagName('img')[0].src    =    Ka.Info.STATICSERVERIMAGES+'/themes/homeThumbs/theme'+Ka.$('.ka_ks_preview_theme')[1].getElementsByTagName('div')[0].className.split('ka_ks_theme ka_ks_theme')[1]+'Home.gif';
//        // hide the title, count, and footer
//        Ka.hide('#ka_ks_preview_title','#ka_ks_preview_count','#ka_ks_preview_footer');
//        // re-adjust the bottom padding
//        Ka.$('#ka_ks_preview_main').style.paddingBottom                      =    '15px';
//        // alter the close button's onclick function
//        Ka.$('#ka_ks_preview_close').getElementsByTagName('a')[0].onclick    =    function()
//                                                                                  {
//                                                                                      // set it to close
//                                                                                      Ka.popup();
//                                                                                      // set it to show the title, count and footer
//                                                                                      Ka.show('#ka_ks_preview_title','#ka_ks_preview_count','#ka_ks_preview_footer');
//                                                                                      // set the padding
//                                                                                      Ka.$('#ka_ks_preview_main').style.paddingBottom                      =    '5px';
//                                                                                      // reset the close button as well
//                                                                                      Ka.$('#ka_ks_preview_close').getElementsByTagName('a')[0].onclick    =    function() { Ka.popup(); };
//                                                                                  };
//        // show the hompage preview
//        Ka.popup('#ka_ks_preview_hidden');
//    }
    
    function reloadCaptcha() {
		var now = new Date();
    	if (document.images) {
			document.images.captcha.src = '/service/getSecureImage.kickAction?tms='+ now.getTime();
		}
	}