var p_validateOtherFields = '';
var p_formObj = '';
var p_tagsFailed = '';
var discussionId = -1;
var reloadNow=0;



$j(document).ready(function(){
	if(Ka.Info.PAGETYPE=='Group'){
		if(Ka.Info.USERID>0){
			if(Ka.Info.ISUSERMEMBER==false){
				joinClub(this);
				
				
			}
		}
	}
	
	if (Ka.Info.PAGE == "pages/customPage.jsp") {
		if (window.location.href.indexOf("&type=booklist") != -1) {
			$j('head').append('<script src="http://js.kickstatic.com/kickapps/jsc/4_5_59/StarManager.js"></script>');
			var adminTags = Ka.Util.getLocationParam('adminTags');
			var pgNum = Ka.Util.getLocationParam('pgNum');
			var totSize = Ka.Util.getLocationParam('totSize');
			var keywords = Ka.Util.getLocationParam('keywords');
			
			if (window.location.href.indexOf("&sortType=recent") != -1) {
				$j('head').append('<script src="'+customCode+'utils/viewAllBooks.php?as='+Ka.Info.AFFILIATESITEID+'&sortType=recent&divTag=ka_contentContainer&adminTags='+adminTags+'&pgNum='+pgNum+'&totSize='+totSize+'&keywords='+keywords+'"></script>');
			}
			if (window.location.href.indexOf("&sortType=rating") != -1) {
				$j('head').append('<script src="'+customCode+'utils/viewAllBooks.php?as='+Ka.Info.AFFILIATESITEID+'&sortType=rating&divTag=ka_contentContainer&adminTags='+adminTags+'&pgNum='+pgNum+'&totSize='+totSize+'&keywords='+keywords+'"></script>');
			}
			if (window.location.href.indexOf("&sortType=favorite") != -1) {
				$j('head').append('<script src="'+customCode+'utils/viewAllBooks.php?as='+Ka.Info.AFFILIATESITEID+'&sortType=favorite&divTag=ka_contentContainer&adminTags='+adminTags+'&pgNum='+pgNum+'&totSize='+totSize+'&keywords='+keywords+'"></script>');
			}
			if (window.location.href.indexOf("&sortType=popular") != -1) {
				$j('head').append('<script src="'+customCode+'utils/viewAllBooks.php?as='+Ka.Info.AFFILIATESITEID+'&sortType=popular&divTag=ka_contentContainer&adminTags='+adminTags+'&pgNum='+pgNum+'&totSize='+totSize+'&keywords='+keywords+'"></script>');
			}
			if (window.location.href.indexOf("&sortType=popular") != -1) {
				$j('head').append('<script src="'+customCode+'utils/viewAllBooks.php?as='+Ka.Info.AFFILIATESITEID+'&sortType=popular&divTag=ka_contentContainer&adminTags='+adminTags+'&pgNum='+pgNum+'&totSize='+totSize+'&keywords='+keywords+'"></script>');
			}
			if (window.location.href.indexOf("&sortType=commented") != -1) {
				$j('head').append('<script src="'+customCode+'utils/viewAllBooks.php?as='+Ka.Info.AFFILIATESITEID+'&sortType=commented&divTag=ka_contentContainer&adminTags='+adminTags+'&pgNum='+pgNum+'&totSize='+totSize+'&keywords='+keywords+'"></script>');
			}
			
		}
	}
	
	if(Ka.Info.PAGE!='pages/customPage.jsp'){
		//add twitter publish
		if(Ka.Info.PAGE=='pages/mediaPlayPage.jsp'){
        	$j('#ka_sendButton').before('<div id="ka_twitter"><img src="'+customCode+'images/twitter.jpg"/> <input id="ka_twitter_checkbox" name="ka_twitter_checkbox" type="checkbox" /> Publish this activity to Twitter</div>');
        	var newEventId = Ka.events.listen('play-page-after-add-comment', ka_twitter_publish_media);
        }
        
       
	}


	storeInDb();
	if(Ka.Info.PAGETYPE=='Group' && Ka.Info.MEDIATYPE=='Group'){
		//It is a book
		
        
		$j('#ka_groupSuccess').remove();
		//$j('#ka_playPageDetailsWrap').before('<p id="descHolder"></p>');
		//$j('#ka_playPageDetailsWrap').children().appendTo('#descHolder');
		//$j('#descHolder').appendTo('#ka_playPageDetailsWrap');
		$j('#ka_clubStatTags').appendTo('#ka_playPageDetailsWrap');
		$j('#ka_groupLogo').after('<div class="ka_bookInfo"></div>');
		$j('head').append('<script src="http://s7.addthis.com/js/200/addthis_widget.js?_=1277489681920"></script>');
		if(Ka.Info.USERID>0){
			$j('#ka_leftColumn').prepend('<div class="clearfix ka_contentBody" id="ka_playPageStats"><ul class="ka_statsList"><li id="ka_statsFriends"> <div class="ka_email"> <span id="emailArea"></span> </div><div class="ka_addFav"> <span id="favoriteArea"><a href="#" onclick="return addFav();">Add to Favorites</a> </span></div> </li> <li id="ka_statsRate"><div class="ka_share_add"><a onclick="return addthis_sendto()" onmouseout="addthis_close()" onmouseover="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" href="http://www.addthis.com/bookmark.php"><img width="125" height="16" border="0" style="border: 0pt none;" alt="" src="http://s7.addthis.com/static/btn/lg-share-en.gif"></a></div> <div class="ka_rate"></div>  <div class="ka_stats"><div class="ka_stats_comments">						Comments: </div>	<div class="ka_stats_views">Views: </div></div></li></ul></div>');
		} else {
			//not logged in
			$j('#ka_leftColumn').prepend('<div class="clearfix ka_contentBody" id="ka_playPageStats"><ul class="ka_statsList"><li id="ka_statsFriends"> <div class="ka_email"> <span id="emailArea"></span> </div> </li> <li id="ka_statsRate"><div class="ka_share_add"><a onclick="return addthis_sendto()" onmouseout="addthis_close()" onmouseover="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" href="http://www.addthis.com/bookmark.php"><img width="125" height="16" border="0" style="border: 0pt none;" alt="" src="http://s7.addthis.com/static/btn/lg-share-en.gif"></a></div> <div class="ka_rate"></div>  <div class="ka_stats"><div class="ka_stats_comments">						Comments: </div>	<div class="ka_stats_views">Views: </div></div></li></ul></div>');
		}
		url = customCode+"utils/getGroupAdminTags.php?callback=?";
		$j.ajax({
		 dataType: 'jsonp',
		 data: {as: Ka.Info.AFFILIATESITEID,groupId:Ka.Info.CLUBID },
		 jsonp: 'groupPageAdminTags',
		 url: url,
		 success: groupPageAdminTags
		});
		
	}
	
	if (Ka.Info.PAGE=='login/registerUser.jsp'){
		var favHTML = '<li id="favGenreLi"><label>Favorite Romance Genres:</label><div id="favGenreList"><div id="genreLeft"><p><input type="checkbox" name="contemporary" value="contemporary"><span id="genrecontemporary">Contemporary</span></p><p><input type="checkbox" name="urbanfantasy"  value="urbanfantasy"><span id="genreurbanfantasy">Urban Fantasy</span></p><p><input type="checkbox" name="historical" value="historical"><span id="genrehistorical">Historical</span></p></div><div id="genreRight"><p><input type="checkbox" name="romanticsuspense" value="romanticsuspense"><span id="genreromanticsuspense">Romantic Suspense</span></p><p><input type="checkbox" name="paranormal" value="paranormal"><span id="genreparanormal">Paranormal</span></p></div></li>';
		var themeHTML = '<li id="themeLi"><label>Select A Profile Theme:</label><div id="themeList"><p class="themecontemporary"><input type="radio" name="theme" value="contemporary"><span>Contemporary</span></p><p class="themeurbanfantasy"><input type="radio" name="theme" value="urbanfantasy"><span>Urban Fantasy</span></p><p class="themehistorical"><input type="radio" name="theme" value="historical"><span>Historical</span></p><p class="themeromanticsuspense"><input type="radio" name="theme" value="romanticsuspense"><span>Romantic Suspense</span></p><p class="themeparanormal"><input type="radio" name="theme" value="paranormal"><span>Paranormal</span></p></li>';
		var heardHTML = '<li id="heardLi"><label>How did you hear about this site?:</label><select name="heardAbout"><option value="none">&nbsp</option><option value="magazine">Magazine</option><option value="sswebsite">Simon & Schuster website</option><option value="backofbook">Back of my book</option><option value="friend">From a friend</option><option value="romancecommunity">From Romance Community</option><option value="email">Email</option><option value="other">Other</option></select></li>';
		var newsLetterSignup = '<li id="ss_newsletter"><input type="checkbox" name="newsletter" id="newsletter">&nbsp;&nbsp;Yes, I want to receive the Simon &amp; Schuster Newsletter with Romance preference.</li>';
		 
		
		$j('#ka_joinText').before(favHTML+themeHTML+heardHTML);
		$j('#ka_joinTOS').before(newsLetterSignup);
	}
	
	if(Ka.Info.PAGETYPE=='MKP'&&Ka.Info.PAGE=='pages/myPlace.jsp'){
		url = customCode+"utils/getUserDetails.php?callback=?";
		$j.ajax({
		 dataType: 'jsonp',
		 data: {as: Ka.Info.AFFILIATESITEID,userId:Ka.Info.USERID },
		 jsonp: 'userInfoMyHomeRender',
		 url: url,
		 success: userInfoMyHomeRender
		});
		
	}
	
	if(Ka.Info.PAGETYPE=='Kickplace'||Ka.Info.PAGETYPE=='MKP'){
		//fix for activity feed
		$j('#ka_profileActivityFeed li.externalmedia a').each(function(index){
		    var href = $j(this).attr('href');
		    if(href.length==20){
		        href = customCode+"utils/redirectBookByISBN.php?as="+Ka.Info.AFFILIATESITEID+"&isbn="+href.substring(7,20);
		        $j(this).attr('href',href);
		    }

		});
	}
	
	if(Ka.Info.PAGETYPE=='Kickplace'&&(Ka.Info.PAGE=='pages/profile.jsp'||Ka.Info.PAGE=='pages/kickPlaceServerSide.jsp')){
		if(Ka.Info.PROFILEADMINTAGS.indexOf('authorpage')<0){
			url = customCode+"utils/getUserDetails.php?callback=?";
			var profileId = (Ka.Info.PROFILEID || Ka.Info.Profile.PROFILEID)
			$j.ajax({
			 dataType: 'jsonp',
			 data: {as: Ka.Info.AFFILIATESITEID,userId:profileId },
			 jsonp: 'userInfoProfileRender',
			 url: url,
			 success: userInfoProfileRender
			});
		} else {
			//Author
			var adminTagsArr = Ka.Info.PROFILEADMINTAGS.split(",");
			var key = '';
			for(var i=0;i<adminTagsArr.length;i++){
				var tag = adminTagsArr[i];
				if(tag.indexOf("key")>=0){
					key = tag.replace("key","");
				}
			}
			if(key!=''){
				var scriptSrc = '<div id="authorAlerts" ></div><script src="'+authorAlertUrl+'?width=182&author_keys='+key+'&pp_link=http://www.simonandschuster.com/about/privacy_policy&toc_link=http://www.simonandschuster.com/about/terms_of_use&source=1919&widget_id=authorAlerts" type="text/javascript" ></script>';
				//alert("adding script:"+scriptSrc);
				$j('#ka_profileLeft').append(scriptSrc);
			}
		}
		
	}
	
	if(Ka.Info.PAGE=='pages/manageProfileQuestions.jsp'){
		
		url = customCode+"utils/getUserAdminTags.php?callback=?";
		$j.ajax({
		 dataType: 'jsonp',
		 data: {as: Ka.Info.AFFILIATESITEID,u:Ka.Info.USERID },
		 jsonp: 'userAdminTagProcessorEditProfile',
		 url: url,
		 success: userAdminTagProcessorEditProfile
		});
		
		
	}
	
	if(Ka.Info.PAGETYPE=='List' && Ka.Util.getLocationParam('includeUser')=='on' && Ka.Util.getLocationParam('adminTags')!='authorpage'){
		getAuthorsFromUserList();
	}
	if(Ka.Info.PAGETYPE=='List' && Ka.Util.getLocationParam('includePhoto')=='on' ){
		getAuthorsForBookList();
	}
	//Extra age checks for legal
	if(Ka.Info.PAGE=='pages/manageAccountSettings.jsp'&&Ka.Info.PAGETYPE=='MKP'){

	$j('#dobDay').attr('minmax-age','check');
	$j('#dobDay').removeAttr('errorkey');
	$j('#dobDay').removeAttr('not-equal-to');
	if(Ka.formValidation!=null){
		Ka.formValidation.rules["minmax-age"]={
			message:"I'm sorry, but you do not meet the eligibility requirements to register on this site.",
			test:function(val){
				// get the dates
				var bday = document.getElementById('dobDay').value;
				var bmonth = document.getElementById('dobMonth').value;
				var byear = document.getElementById('dobYear').value;

				// parse them
				bday = bday=='Select' ? 0 : parseInt(bday);
				bmonth = bmonth=='Select' ? 0 : parseInt(bmonth) - 1;
				byear = byear=='Select' ? 0 : parseInt(byear);

				// get the current date info.
				var now = new Date();
				cday = now.getDate();
				cmonth = now.getMonth();
				cyear = now.getFullYear();

				// if the current month is greater than the birthday month, or the current month is equal to the birthday month, and the current day is equal to or greater than the birthday day
				if((cmonth > bmonth) || (cmonth==bmonth && cday>=bday))	{
					// set the age to the year
					var age = byear;
					age = cyear-age;
				} else {
					// set the age to the year plus 1, since their birthday hasn't been hit yet
					var age = byear+1;
					age = cyear-age;
				}
				// return the status of an age check
				return ((age>=14 ) ? true : false);
			}
		};
	}
}

if (Ka.Info.PAGE=='login/registerUser.jsp'){
	//Add additional fields

	$j('#dobDay').attr('minmax-age','check');
	$j('#dobDay').removeAttr('errorkey');
	$j('#dobDay').removeAttr('not-equal-to');
	if(Ka.formValidation!=null){
		Ka.formValidation.rules["minmax-age"]={
			message:"I'm sorry, but you do not meet the eligibility requirements to register on this site.",
			test:function(val){
				// get the dates
				var bday = document.getElementById('dobDay').value;
				var bmonth = document.getElementById('dobMonth').value;
				var byear = document.getElementById('dobYear').value;

				// parse them
				bday = bday=='Select' ? 0 : parseInt(bday);
				bmonth = bmonth=='Select' ? 0 : parseInt(bmonth) - 1;
				byear = byear=='Select' ? 0 : parseInt(byear);

				// get the current date info.
				var now = new Date();
				cday = now.getDate();
				cmonth = now.getMonth();
				cyear = now.getFullYear();

				// if the current month is greater than the birthday month, or the current month is equal to the birthday month, and the current day is equal to or greater than the birthday day
				if((cmonth > bmonth) || (cmonth==bmonth && cday>=bday))	{
					// set the age to the year
					var age = byear;
					age = cyear-age;
				} else {
					// set the age to the year plus 1, since their birthday hasn't been hit yet
					var age = byear+1;
					age = cyear-age;
				}
				// return the status of an age check
				if (!(age>=14 )){
					createCookieSS('107649registerChk',"true",1);
				}
				if(readCookieSS('107649registerChk')==''||readCookieSS('107649registerChk')==null){
					return ((age>=14 ) ? true : false);
				} else {
					return false;
				}
			}
		};
	}
}
	
});

function showListStars(){
	$j('span.starListDiv').each(function(i){
		var rating = $j(this).html();
		$j(this).html('');
		var itemId = $j(this).attr('id');
		mediaRatingSystem    =    new kap_starSystem('view','S',{avg:Math.round(rating)});
		mediaRatingSystem.show(itemId);
	});

}

function groupPageAdminTags(json){
	if(json.success==1){
		Ka.Info.addProp('MEDIAADMINTAGS',json.admintags);
	}
	var tags = Ka.Info.MEDIAADMINTAGS.split(',');
		var isbn=-1;
		for(var i=0;i < tags.length;i++) {
			var tag = tags[i];
			if(tag.indexOf("isbn")==0){
				isbn = tag.replace('isbn','');
			}
			if(tag.indexOf("discussion")==0){
				discussionId = tag.replace('discussion','');
			}
		}
		setUserRating(isbn);
		url = customCode+"utils/getBookDetails.php?callback=?";
		$j.ajax({
		 dataType: 'jsonp',
		 data: {as: Ka.Info.AFFILIATESITEID,isbn:isbn },
		 jsonp: 'customizeBookPage',
		 url: url,
		 success: customizeBookPage
		});
}

function customizeBookPage(json){
	if(json.success==1){
		var outputStr ='';
		features = json.feature;
		var featureStr = '';
		var featureClass = '';
		if(features.length > 0){
			featureClass = features[0].featureType.toLowerCase().replace(/\s+/g,"");
			if(Ka.Info.AFFILIATESITEID==155849){
				featureStr = '<a target="_blank" class="'+featureClass+'" href="http://books.simonandschuster-biz.staging.agilesands.com/'+features[0].isbn+'/browse" class="featureButton">'+features[0].featureType+'</a>';
			} else {
				featureStr = '<a target="_blank" class="'+featureClass+'" href="http://books.simonandschuster.biz/'+features[0].isbn+'/browse" class="featureButton">'+features[0].featureType+'</a>';
			}
			//$j('#ka_playPagePlayer').append(featureStr);
			//outputStr = outputStr+featureStr;
		}
		bookTitle = $j.trim(json.book.title);
		bookSubtitle = $j.trim(json.book.subtitle);
		//$j('#ka_playPagePlayer').append('<div class="bookTitle">'+bookTitle+'</div>');
		outputStr = outputStr+'<div class="bookTitle">'+bookTitle+'</div>';
		//$j('#ka_playPagePlayer').append('<div class="bookSubTitle">'+bookSubtitle+'</div>');
		outputStr = outputStr+'<div class="bookSubTitle">'+bookSubtitle+'</div>';
		authors = json.authors;
		authorStr = '';
		authorTitleStr ='';
		authorKeys ='';
		for (index in authors) {
			author = authors[index];
			//for each one post it
			workingStr = '';
			if(author.key+''!='undefined'){
				if(authorKeys==''){
					authorKeys = authorKeys + author.key;
				} else {
					authorKeys = authorKeys+ "," + author.key;
				}
			}
			if(author.role=="Author"){
				if(authorStr.indexOf('By:')>=0){
					workingTitleStr = ', ';
				} else {
					workingTitleStr = 'By ';
				}
				workingStr = 'By: ';
				
			} else {
				if(author.role+''!='undefined'){
					workingStr = author.role+': ';
				}
			}
			if(author.role+''!='undefined'){
				authorTitleStr = authorTitleStr + workingTitleStr+' '+author.name;
				authorStr = authorStr+'<div class="author">'+workingStr+author.name+'</div>';
			}
		}
		//$j('#ka_playPagePlayer').append(authorStr);
		//document.title=document.title+' - '+authorTitleStr;
		document.title=bookTitle+' '+authorTitleStr+' on Pocket After Dark';
		
		outputStr = outputStr+authorStr;
		formats = json.formats;
		formatStr = '<div class="buyBookClass"><select id="formatSelector">';
		onlineBuyLink = '';
		for (index in formats){
			format = formats[index];
			if(format.type+''!='undefined'){
				formatWorking = "<option value='"+format.buy_link+"'>"+format.type+" $"+format.price+"</option>";
				formatStr = formatStr+formatWorking;
				if(format.isDefault==1){
					onlineBuyLink = format.online_retail_link;
				}
			}
		}
		formatStr = formatStr+"</select><a onclick='buyClick();return false;' href='javascript:void(null)' id='buyClickAnchor' class='buyClass' target='_blank'>Buy Now</a></div>";
		//$j('#ka_playPagePlayer').append(formatStr);
		outputStr = outputStr+formatStr;
		if(onlineBuyLink!=''){
			//$j('#ka_playPagePlayer').append('<a href="'+onlineBuyLink+'" id="onlineRetailLink">Buy from another online retailer</a>');
			outputStr = outputStr+'<a href="'+onlineBuyLink+'" id="onlineRetailLink" target="_blank">Buy from another online retailer</a>';
		}
		$j('#ka_groupLogo').append(featureStr);
		//right rail widgets
		var genreList = json.genre;
		var rawGenre = '';
		for(itemCount in genreList){
		//alert(genreList[itemCount].genreName);
			if(genreList[itemCount].genreName!='General'&&genreList[itemCount].genreName+''!='undefined'){
				rawGenre = genreList[itemCount].genreName;
			}
		}
		if(rawGenre==''){
			rawGenre=='General';
		}
		var genreTag = "genre"+rawGenre.toLowerCase().replace(" ","");
		//alert("genre:"+genreTag);
		var rightRail = '';
		if(discussionId>0){
			rightRail = '<div id="ka_booksRelated" class="widget"><h3>RECENT DISCUSSIONS</h3><div class="contentBody" id="recentDiscussionWidget"></div></div>';
		}
		rightRail = rightRail+'<div id="ka_booksRelated" class="widget"><h3>YOU MAY ALSO LIKE</h3><div class="contentBody" id="recentRelatedBooksWidget"></div></div>';
		$j('#ka_rightColumn').append(rightRail);
		if(discussionId>0){
			var mediaUrl = encodeURIComponent(customCode+"utils/discussionFeedByDiscussionId.php?as="+Ka.Info.AFFILIATESITEID+"&discussionId="+discussionId);
			
			var flashvars = {  
				affiliateSiteId:159176,
				widgetId:382231,
				width:320,
				height:265,
				revision:37,
				mediaURL:mediaUrl
			};
			var params = {
				allowFullScreen:true,
				allowScriptAccess:"always",
				wmode:"transparent",
				movie:"http://serve.a-widget.com/service/getWidgetSwf.kickAction"
			};
			var attributes = {  
				id: "kickWidget_159176_382231",  
				name: "kickWidget_159176_382231"
			};
			swfobject.embedSWF("http://serve.a-widget.com/service/getWidgetSwf.kickAction", "recentDiscussionWidget", "320", "265", "9.0.0","http://serve.a-widget.com/service/getWidgetSwf.kickAction", flashvars, params, attributes);
			//<object width="320" height="265" id="kickWidget_155849_364982" ><param name="movie" value="http://serve.a-widget.com/service/getWidgetSwf.kickAction"></param><param name="FlashVars" value="affiliateSiteId=155849&amp;widgetId=364982&amp;width=320&amp;height=265&amp;revision=37" ></param><param name="wmode" value="transparent" ></param><param name="allowFullScreen" value="true" ></param><param name="allowScriptAccess" value="always" ></param><embed src="http://serve.a-widget.com/service/getWidgetSwf.kickAction" name="kickWidget_155849_364982" width="320" height="265" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" allowScriptAccess="always" allowFullScreen="true" FlashVars="affiliateSiteId=155849&amp;widgetId=364982&amp;width=320&amp;height=265&amp;revision=37"></embed></object>
		}
		var mediaUrl2 = encodeURIComponent(customCode+"utils/bookFeed.php?as="+Ka.Info.AFFILIATESITEID+"&genre="+rawGenre+"&quantity=10");
		
		var widget2Id = 0;
		var widget2Width = 0;
		var widget2Height = 0;
		var widget2Revision = 0;
		if(Ka.Util.getLocationParam('param')=='FBApp'){
			widget2Id = 451395;
			widget2Width = 280;
			widget2Height = 265;
			widget2Revision = 5;

		} else {
			widget2Id = 382218;
			widget2Width = 320;
			widget2Height = 265;
			widget2Revision = 45;
		}
		
		var flashvars2 = {  
			affiliateSiteId:159176,
			widgetId:widget2Id,
			width:widget2Width,
			height:widget2Height,
			revision:widget2Revision,
			mediaURL:mediaUrl2
		};
		var params2 = {
			allowFullScreen:true,
			allowScriptAccess:"always",
			wmode:"transparent",
			movie:"http://serve.a-widget.com/service/getWidgetSwf.kickAction"
		};
		var attributes2 = {  
			id: "kickWidget_159176_"+widget2Id,  
			name: "kickWidget_159176_"+widget2Id
		};
		swfobject.embedSWF("http://serve.a-widget.com/service/getWidgetSwf.kickAction", "recentRelatedBooksWidget", widget2Width, widget2Height, "9.0.0","http://serve.a-widget.com/service/getWidgetSwf.kickAction", flashvars2, params2, attributes2);
		//<object width="320" height="265" id="kickWidget_155849_364986" ><param name="movie" value="http://serve.a-widget.com/service/getWidgetSwf.kickAction"></param><param name="FlashVars" value="affiliateSiteId=155849&amp;widgetId=364986&amp;width=320&amp;height=265&amp;revision=45" ></param><param name="wmode" value="transparent" ></param><param name="allowFullScreen" value="true" ></param><param name="allowScriptAccess" value="always" ></param><embed src="http://serve.a-widget.com/service/getWidgetSwf.kickAction" name="kickWidget_155849_364986" width="320" height="265" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" allowScriptAccess="always" allowFullScreen="true" FlashVars="affiliateSiteId=155849&amp;widgetId=364986&amp;width=320&amp;height=265&amp;revision=45"></embed></object>
	
		
		$j('div.ka_bookInfo').prepend(outputStr);
		if(authorKeys!=''){
			var scriptSrc = '<div id="authorAlerts" ></div><script src="'+authorAlertUrl+'?width=311&author_keys='+authorKeys+'&pp_link=http://www.simonandschuster.com/about/privacy_policy&toc_link=http://www.simonandschuster.com/about/terms_of_use&source=1919&widget_id=authorAlerts" type="text/javascript" ></script>';
			//alert("adding script:"+scriptSrc);
			$j('#ka_rightColumn').append(scriptSrc);
		}
		
			
		$j('#ka_rightColumn').append('<div id="twitWidget" class="twitter"></div>');
		//<object width="320" height="167" id="kickWidget_159176_382181" ><param name="movie" value="http://serve.a-widget.com/service/getWidgetSwf.kickAction"></param><param name="FlashVars" value="affiliateSiteId=159176&amp;widgetId=382181&amp;width=320&amp;height=167&amp;revision=1" ></param><param name="wmode" value="transparent" ></param><param name="allowFullScreen" value="true" ></param><param name="allowScriptAccess" value="always" ></param><embed src="http://serve.a-widget.com/service/getWidgetSwf.kickAction" name="kickWidget_159176_382181" width="320" height="167" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" allowScriptAccess="always" allowFullScreen="true" FlashVars="affiliateSiteId=159176&amp;widgetId=382181&amp;width=320&amp;height=167&amp;revision=1"></embed></object>
		//var 	mediaUrl3 = encodeURIComponent(customCode+"utils/bookFeed.php?as="+Ka.Info.AFFILIATESITEID+"&genre="+rawGenre+"&quantity=10");
		
		var widget3Id = 0;
		var widget3Width = 0;
		var widget3Height = 0;
		var widget3Revision = 0;
		if(Ka.Util.getLocationParam('param')=='FBApp'){
			widget3Id = 451136;
			widget3Width = 280;
			widget3Height = 167;
			widget3Revision = 5;

		} else {
			widget3Id = 382181;
			widget3Width = 320;
			widget3Height = 367;
			widget3Revision = 1;
		}
		
		var flashvars3 = {  
			affiliateSiteId:159176,
			widgetId:widget3Id,
			width:widget3Width,
			height:widget3Height,
			revision:widget3Revision
		};
		var params3 = {
			allowFullScreen:true,
			allowScriptAccess:"always",
			wmode:"transparent",
			movie:"http://serve.a-widget.com/service/getWidgetSwf.kickAction"
		};
		var attributes3 = {  
			id: "kickWidget_159176_"+widget3Id,  
			name: "kickWidget_159176_"+widget3Id
		};
		swfobject.embedSWF("http://serve.a-widget.com/service/getWidgetSwf.kickAction", "twitWidget", widget3Width, widget3Height, "9.0.0","http://serve.a-widget.com/service/getWidgetSwf.kickAction", flashvars3, params3, attributes3);
		
		
		//fb publish
        $j('#ka_sendButton').before('<div id="ka_facebook"><img src="http://static.ak.fbcdn.net/images/icons/favicon.gif" /> <input id="ka_facebook_checkbox" class="ka_fb_connect ka_button" type="checkbox" /> Publish this activity to Facebook</p>');
        var newEventId = Ka.events.listen('group-page-after-add-comment', ka_facebook_publish);
		//twitter publish
		$j('#ka_sendButton').before('<div id="ka_twitter"><img src="'+customCode+'images/twitter.jpg"/> <input id="ka_twitter_checkbox" name="ka_twitter_checkbox" type="checkbox" /> Publish this activity to Twitter</div>');
        var newEventId = Ka.events.listen('group-page-after-add-comment', ka_twitter_publish_media);
        
		Cufon.replace('#wrapper h3');
		
	}
}

function buyClick(){
	url = $j('#formatSelector').val();
	window.open(url);
	return false;
}

function setUserRating(isbn){
	url = customCode+"utils/getUserRating.php?callback=?";
	
	$j.ajax({
	 dataType: 'jsonp',
	 data: {as: Ka.Info.AFFILIATESITEID,u:Ka.Info.USERID,mediaId:isbn, clubId:Ka.Info.CLUBID, username:Ka.Info.USERNAME },
	 jsonp: 'setUserRatingValue',
	 url: url,
	 success: setUserRatingValue
	});
}

function setAvgRating(avgRating, votes){
	var starString = '<span class="star-rating-control">';
		
	for (var i=0;i<5;i++){
		if (Math.round(avgRating)==(i+1)){
			starString+='<input name="staravg" type="radio" class="star" disabled="disabled" checked="checked"/>';
		} else {
			starString+='<input name="staravg" type="radio" class="star" disabled="disabled" />';
		}
	}

	starString+='</span>';
	
	$j('div.ka_rate').append('<span id="ss_avglabel">Overall Rating:</span><div id="ss_avgrate"><div id="ss_avgstars">'+starString+'</div><span id="ss_avgvotecount">(<span id="ss_countrating">'+votes+'</span> Ratings)</span></div>');
	
}

function setUserRatingValue(json){
	$j('div.ka_stats_views').html('Views: '+json.views);
	$j('div.ka_stats_comments').html('Comments: <span id="ka_commentsNumArea">'+json.numComments+'</span>');
	if(json.isFav==1){
		$j('#favoriteArea').html('<a onclick="removeFav();return false;" href="#">Remove from Favorites</a>');
	}
	var starString = '<span class="star-rating-control">';
	if (json.rating<0){
		//Not  yet rated
		for (var i=0;i<5;i++){
			
		  starString+='<input name="star1" type="radio" class="auto-submit-star"  value="'+(i+1)+'" />';
			
		}
	} else {
		
		for (var i=0;i<5;i++){
			if (json.rating==(i+1)){
				starString+='<input name="star1" type="radio" class="star" disabled="disabled" checked="checked"/>';
			} else {
				starString+='<input name="star1" type="radio" class="star" disabled="disabled" />';
			}
		}
	}
	starString+='</span>';

	setAvgRating(json.avgRating, json.votes);

	$j('div.ka_rate').append('<div id="ss_userrate"><span id="ss_userrate_label">Your Rating:</span><div id="ss_userratestars">'+starString+'</div></div>');

	if(json.rating < 0){
		$j.fn.rating.options.required=true;
	}
	$j('input[type=radio].star').rating();
	
	
	$j('.auto-submit-star').rating({
	  callback: function(value, link){
	    rateMediaSS(value);
	    
	  }
	});
	 if(Ka.Info.USERID<=0){
		$j('input[name="star1"]').rating('disable');
	}
	
}

function rateMediaSS(rating){
	// DWR call to insert the rating
    url = customCode+"utils/setUserRating.php?callback=?";
	var tags = Ka.Info.MEDIAADMINTAGS.split(',');
	var isbn=-1;
	for(var i=0;i < tags.length;i++) {
		var tag = tags[i];
		if(tag.indexOf("isbn")==0){
			isbn = tag.replace('isbn','');
		}
	}
	$j.ajax({
	 dataType: 'jsonp',
	 data: {as: Ka.Info.AFFILIATESITEID,u:Ka.Info.USERNAME,mediaId:isbn, rating:rating },
	 jsonp: 'userRatingSet',
	 url: url,
	 success: userRatingSet
	});
}

function userRatingSet(json){
	// DWR call to insert the rating
    var rating = Math.round(json.avgRating);
	$j('input[name="staravg"]').rating('enable');
	$j('input[name="staravg"]').rating('select',parseInt(rating-1));
	$j('input[name="staravg"]').rating('disable');
	$j('input[name="star1"]').rating('disable');
	$j('#ss_countrating').html(json.votes);
}


function getAvgRatingSS(){
	// DWR call to get the rating details (if exists)
	KickAppsBizComponent.getAverageRatingForMedia(Ka.Info.MEDIAID,Ka.Info.MEDIATYPE,Ka.Info.AFFILIATESITEID,Ka.Info.AFFILIATESITEID,function(ratingObject){
		var rating = Math.round(ratingObject);
		$j('input[name="staravg"]').rating('enable');
		$j('input[name="staravg"]').rating('select',parseInt(rating-1));
		$j('input[name="staravg"]').rating('disable');
		$j('input[name="star1"]').rating('disable');
		$j('#ss_countrating').html(''+(parseInt(Ka.Info.VOTES)+1));
	});
}

function CoppaCheck(form,it){	 
	Ka.formValidation.actions.disableSubmit(form);

	if($j('input[name=newsletter]:checked').val()!=''){
		//newsletter
		var email = $j('#email').val();
		var day = $j('#dobDay').val();
		var month = $j('#dobMonth').val();
		var year = $j('#dobYear').val();
		signUpNewsletterJoin(email, year, day, month);
	} else {
		storeInfo();
	}
} 

function storeInfo(){
	if($j('input[name=theme]:checked').val()!=''){
		createCookieSS('afterdark_theme',$j('input[name=theme]:checked').val(),5);
	} else {
		//no theme selected
		createCookieSS('afterdark_theme','none',5);
	}
	var favs = 'none';
	
	$j('#favGenreList input:checked').each(function(key,value){
		if(favs=='none'){
			favs = $j(value).val();
		} else {
			favs = favs+','+$j(value).val();
		}
		
	});
	createCookieSS('afterdark_favs',favs,5);
	var heardAbout = $j('select[name=heardAbout]').val();
	createCookieSS('afterdark_heardabout',heardAbout,5);
	//alert("favs:"+favs+" theme:"+theme+" Heard:"+heardAbout);
	setTimeout('document.RegisterUser.submit()', 1000); 
}

function storeInDb(){
	var favs = readCookieSS('afterdark_favs');
	var theme = readCookieSS('afterdark_theme');
	var heardAbout = readCookieSS('afterdark_heardabout');
	if(Ka.Info.USERID>0&&favs+''!='undefined'&&favs+''!='null'){
		
		if(favs+''!=''&&theme+''!=''&&heardAbout+''!=''){
			if(favs=='none'){
				favs = '';
			}
			if(theme=='none'){
				theme = '';
			}
			if(heardAbout=='none'){
				heardAbout = '';
			}
			
			var url = customCode+"/utils/storeUserDetails.php?callback=?";
			$j.ajax({
			 dataType: 'jsonp',
			 data: {as: Ka.Info.AFFILIATESITEID,userId:Ka.Info.USERID, heardAbout:heardAbout, profileTheme:theme,favGenre:favs, username:Ka.Info.USERNAME },
			 jsonp: 'userInfoSaved',
			 url: url,
			 success: userInfoSaved
			});
			 
		}
	}
}

function userInfoSaved(json){
	if(json.success==1){
		eraseCookieSS('afterdark_favs');
		eraseCookieSS('afterdark_theme');
		eraseCookieSS('afterdark_heardabout');
	}
}

function userInfoMyHomeRender(json){
	var favHTML='<div id="myFavGenres"><h2>My Favorite Genres:</h2><ul id="myFavList">';
	var favCloseHTML = '</ul></div>';
	var favGenre = '';
	if(json.success==1){
		favGenre = json.userInfo.favGenre;
		if(favGenre!=''){
			favGenreArr = favGenre.split(",");
			for(var i=0;i < favGenreArr.length;i++) {
				var genre = favGenreArr[i];
				if(genre+''!=''){
					if(genre=='contemporary'){
						favHTML=favHTML+'<li class="favGenreItem"><a href="/service/openCustomPage.kickAction?as='+Ka.Info.AFFILIATESITEID+'&param=genrecontemporary&mediaType=photo&title=Contemporary Books - After Dark">Contemporary</a></li>';
					} else if (genre=='urbanfantasy'){
						favHTML=favHTML+'<li class="favGenreItem"><a href="/service/openCustomPage.kickAction?as='+Ka.Info.AFFILIATESITEID+'&param=genreurbanfantasy&mediaType=photo&title=Urban Fantasy Books - After Dark">Urban Fantasy</a></li>';
					} else if (genre=='historical'){
						favHTML=favHTML+'<li class="favGenreItem"><a href="/service/openCustomPage.kickAction?as='+Ka.Info.AFFILIATESITEID+'&param=genrehistorical&mediaType=photo&title=Historical Books - After Dark">Historical</a></li>';
					} else if (genre=='romanticsuspense'){
						favHTML=favHTML+'<li class="favGenreItem"><a href="/service/openCustomPage.kickAction?as='+Ka.Info.AFFILIATESITEID+'&param=genreromanticsuspense&mediaType=photo&title=Romantic Suspense Books - After Dark">Romantic Suspense</a></li>';
					} else if (genre=='paranormal'){
						favHTML=favHTML+'<li class="favGenreItem"><a href="/service/openCustomPage.kickAction?as='+Ka.Info.AFFILIATESITEID+'&param=genreparanormal&mediaType=photo&title=Paranormal Books - After Dark">Paranormal</a></li>';
					}
				}
			}
		}
		$j('#ka_myHomeTopRight').append(favHTML+favCloseHTML);
	}
	$j('#ka_leftColumn').append('<div id="ka_booksRelated" class="widget"><h3>YOU MAY ALSO LIKE</h3><div class="contentBody" id="recentRelatedBooksWidget"></div></div>');
	var mediaUrl2 = encodeURIComponent("http://serve.a-feed.com/service/getFeed.kickAction?as="+Ka.Info.AFFILIATESITEID+"&mediaType=photo&adminTags=bookpage&sortType=popular&quantity=10");
	if(favGenre!=''){
		mediaUrl2 = encodeURIComponent(customCode+"utils/bookFeed.php?as="+Ka.Info.AFFILIATESITEID+"&genre="+favGenre+"&quantity=10");
	} else {
		mediaUrl2 = encodeURIComponent(customCode+"utils/bookFeed.php?as="+Ka.Info.AFFILIATESITEID+"&quantity=10");
	}
	
	var flashvars2 = {  
		affiliateSiteId:159176,
		widgetId:382210,
		width:492,
		height:265,
		revision:47,
		mediaURL:mediaUrl2
	};
	var params2 = {
		allowFullScreen:true,
		allowScriptAccess:"always",
		wmode:"transparent",
		movie:"http://serve.a-widget.com/service/getWidgetSwf.kickAction"
	};
	var attributes2 = {  
		id: "kickWidget_159176_382210",  
		name: "kickWidget_159176_382210"
	};
	swfobject.embedSWF("http://serve.a-widget.com/service/getWidgetSwf.kickAction", "recentRelatedBooksWidget", "492", "265", "9.0.0","http://serve.a-widget.com/service/getWidgetSwf.kickAction", flashvars2, params2, attributes2);
	//<object width="320" height="265" id="kickWidget_155849_364986" ><param name="movie" value="http://serve.a-widget.com/service/getWidgetSwf.kickAction"></param><param name="FlashVars" value="affiliateSiteId=155849&amp;widgetId=364986&amp;width=320&amp;height=265&amp;revision=45" ></param><param name="wmode" value="transparent" ></param><param name="allowFullScreen" value="true" ></param><param name="allowScriptAccess" value="always" ></param><embed src="http://serve.a-widget.com/service/getWidgetSwf.kickAction" name="kickWidget_155849_364986" width="320" height="265" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" allowScriptAccess="always" allowFullScreen="true" FlashVars="affiliateSiteId=155849&amp;widgetId=364986&amp;width=320&amp;height=265&amp;revision=45"></embed></object>
	$j('#ka_leftColumn').append('<div id="extmyhome"><iframe src="http://dev.kickapps.com/afterdark/myhome_ad.html" height="250" width="300" frameborder="0" scrolling="no" allowtransparency="true"></iframe></div>');
	Cufon.replace('#wrapper h3')
	
	
}

function userInfoEditProfileRender(json){
	
	if(json.success==1){
		var favHTML = '<div id="favGenreDiv"><label>Favorite Romance Genres:</label><div id="favGenreList">';
		var themeHTML = '<div id="themeDiv"><label>Select A Profile Theme:</label><div id="themeList">';
		var heardHTML = '<div id="heardDiv"><label>How did you hear about this site?:</label><select name="heardAbout"><option value="none">&nbsp</option>';
		 
		var favGenre = json.userInfo.favGenre;
		if(favGenre.indexOf('contemporary')>=0){
			favHTML = favHTML+'<div id="genreLeft"><p><input type="checkbox" name="contemporary" value="contemporary" checked="checked"><span id="genrecontemporary">Contemporary</span></p>';
		} else {
			favHTML = favHTML+'<div id="genreLeft"><p><input type="checkbox" name="contemporary" value="contemporary"><span id="genrecontemporary">Contemporary</span></p>';
		}
		if(favGenre.indexOf('urbanfantasy')>=0){
			favHTML = favHTML+'<p><input type="checkbox" name="urbanfantasy"  value="urbanfantasy" checked="checked"><span id="genreurbanfantasy">Urban Fantasy</span></p>';
		} else {
			favHTML = favHTML+'<p><input type="checkbox" name="urbanfantasy"  value="urbanfantasy"><span id="genreurbanfantasy">Urban Fantasy</span></p>';
		}
		if(favGenre.indexOf('historical')>=0){
			favHTML = favHTML+'<p><input type="checkbox" name="historical" value="historical" checked="checked"><span id="genrehistorical">Historical</span></p></div>';
		} else {
			favHTML = favHTML+'<p><input type="checkbox" name="historical" value="historical"><span id="genrehistorical">Historical</span></p></div>';
		}
		if(favGenre.indexOf('romanticsuspense')>=0){
			favHTML = favHTML+'<div id="genreRight"><p><input type="checkbox" name="romanticsuspense" value="romanticsuspense" checked="checked"><span id="genreromanticsuspense" >Romantic Suspense</span></p>';
		} else {
			favHTML = favHTML+'<div id="genreRight"><p><input type="checkbox" name="romanticsuspense" value="romanticsuspense"><span id="genreromanticsuspense">Romantic Suspense</span></p>';
		}
		if(favGenre.indexOf('paranormal')>=0){
			favHTML = favHTML+'<p><input type="checkbox" name="paranormal" value="paranormal"  checked="checked"><span id="genreparanormal">Paranormal</span></p></div>';
		} else {
			favHTML = favHTML+'<p><input type="checkbox" name="paranormal" value="paranormal"><span id="genreparanormal">Paranormal</span></p></div>';
		}
		favHTML = favHTML+'</div>';
			
		var theme = json.userInfo.profileTheme;
		
		if(theme=='contemporary'){
			themeHTML=themeHTML+'<p class="themecontemporary"><input type="radio" name="theme" value="contemporary" checked="checked"><span>Contemporary</span></p>';
		} else {
			themeHTML=themeHTML+'<p class="themecontemporary"><input type="radio" name="theme" value="contemporary"><span>Contemporary</span></p>';
		}
		if(theme=='urbanfantasy'){
			themeHTML=themeHTML+'<p class="themeurbanfantasy"><input type="radio" name="theme" value="urbanfantasy" checked="checked"><span>Urban Fantasy</span></p>';
		} else {
			themeHTML=themeHTML+'<p class="themeurbanfantasy"><input type="radio" name="theme" value="urbanfantasy"><span>Urban Fantasy</span></p>';
		}
		if(theme=='historical'){
			themeHTML=themeHTML+'<p class="themehistorical"><input type="radio" name="theme" value="historical" checked="checked"><span>Historical</span></p>';
		} else {
			themeHTML=themeHTML+'<p class="themehistorical"><input type="radio" name="theme" value="historical"><span>Historical</span></p>';
		}
		if(theme=='romanticsuspense'){
			themeHTML=themeHTML+'<p class="themeromanticsuspense"><input type="radio" name="theme" value="romanticsuspense" checked="checked"><span>Romantic Suspense</span></p>';
		} else {
			themeHTML=themeHTML+'<p class="themeromanticsuspense"><input type="radio" name="theme" value="romanticsuspense"><span>Romantic Suspense</span></p>';
		}
		if(theme=='paranormal'){
			themeHTML=themeHTML+'<p class="themeparanormal"><input type="radio" name="theme" value="paranormal" checked="checked"><span>Paranormal</span></p>';
		} else {
			themeHTML=themeHTML+'<p class="themeparanormal"><input type="radio" name="theme" value="paranormal"><span>Paranormal</span></p>';
		}
		themeHTML=themeHTML+'</div>';
		
		var heard = json.userInfo.heardAbout;
		if(heard=='magazine'){
			heardHTML = heardHTML+'<option value="magazine" selected="selected">Magazine</option>';
		} else {
			heardHTML = heardHTML+'<option value="magazine">Magazine</option>';
		}
		if(heard=='sswebsite'){
			heardHTML = heardHTML+'<option value="sswebsite" selected="selected">Simon & Schuster website</option>';
		} else {
			heardHTML = heardHTML+'<option value="sswebsite">Simon & Schuster website</option>';
		}
		if(heard=='backofbook'){
			heardHTML = heardHTML+'<option value="backofbook" selected="selected">Back of my book</option>';
		} else {
			heardHTML = heardHTML+'<option value="backofbook">Back of my book</option>';
		}
		if(heard=='friend'){
			heardHTML = heardHTML+'<option value="friend" selected="selected">From a friend</option>';
		} else {
			heardHTML = heardHTML+'<option value="friend">From a friend</option>';
		}
		if(heard=='romancecommunity'){
			heardHTML = heardHTML+'<option value="romancecommunity" selected="selected">From Romance Community</option>';
		} else {
			heardHTML = heardHTML+'<option value="romancecommunity">From Romance Community</option>';
		}
		if(heard=='email'){
			heardHTML = heardHTML+'<option value="email" selected="selected">Email</option>';
		} else {
			heardHTML = heardHTML+'<option value="email">Email</option>';
		}
		if(heard=='other'){
			heardHTML = heardHTML+'<option value="email">Email</option><option value="other" selected="selected">Other</option>';
		} else {
			heardHTML = heardHTML+'<option value="email">Email</option><option value="other">Other</option>';
		}
		heardHTML = heardHTML+'</select></div>';
		
		$j('#ka_editProfileSubmit').before(favHTML+themeHTML+heardHTML);
	} else {
		var favHTML = '<li id="favGenreLi"><label>Favorite Romance Genres:</label><div id="favGenreList"><p><input type="checkbox" name="contemporary" value="contemporary"><span id="genrecontemporary">Contemporary</span></p><p><input type="checkbox" name="urbanfantasy"  value="urbanfantasy"><span id="genreurbanfantasy">Urban Fantasy</span></p><p><input type="checkbox" name="historical" value="historical"><span id="genrehistorical">Historical</span></p><p><input type="checkbox" name="romanticsuspense" value="romanticsuspense"><span id="genreromanticsuspense">Romantic Suspense</span></p><p><input type="checkbox" name="paranormal" value="paranormal"><span id="genreparanormal">Paranormal</span></p></li>';
		var themeHTML = '<li id="themeLi"><label>Select A Profile Theme:</label><div id="themeList"><p class="themecontemporary"><input type="radio" name="theme" value="contemporary"><span>Contemporary</span></p><p class="themeurbanfantasy"><input type="radio" name="theme" value="urbanfantasy"><span>Urban Fantasy</span></p><p class="themehistorical"><input type="radio" name="theme" value="historical"><span>Historical</span></p><p class="themeromanticsuspense"><input type="radio" name="theme" value="romanticsuspense"><span>Romantic Suspense</span></p><p class="themeparanormal"><input type="radio" name="theme" value="paranormal"><span>Paranormal</span></p></li>';
		var heardHTML = '<li id="heardLi"><label>How did you hear about this site?:</label><select name="heardAbout"><option value="none">&nbsp</option><option value="magazine">Magazine</option><option value="sswebsite">Simon & Schuster website</option><option value="backofbook">Back of my book</option><option value="friend">From a friend</option><option value="romancecommunity">From Romance Community</option><option value="email">Email</option><option value="other">Other</option></select></li>';
		$j('#ka_editProfileSubmit').before(favHTML+themeHTML+heardHTML);
		
	}
	
}

function userInfoProfileRender(json){
	var favHTML='<div id="profileFavGenres" class="ka_profileSeg"><div class="ka_profileSegHeader ka_contentTitle">   </div><div class="ka_profileSegCont ka_contentBody"><strong>My Genres:</strong><ul id="myFavList">';
	var favCloseHTML = '</ul></div><div class="ka_profileSegFooter">&nbsp;</div></div>';
	if(json.success==1){
		var favGenre = json.userInfo.favGenre;
		if(favGenre!=''){
			favGenreArr = favGenre.split(",");
			for(var i=0;i < favGenreArr.length;i++) {
				var genre = favGenreArr[i];
				if(genre+''!=''){
					if(genre=='contemporary'){
						favHTML=favHTML+'<li class="favGenreItem"><a href="/service/openCustomPage.kickAction?as='+Ka.Info.AFFILIATESITEID+'&param=genrecontemporary&mediaType=photo&title=Contemporary Books - After Dark">Contemporary</a></li>';
					} else if (genre=='urbanfantasy'){
						favHTML=favHTML+'<li class="favGenreItem"><a href="/service/openCustomPage.kickAction?as='+Ka.Info.AFFILIATESITEID+'&param=genreurbanfantasy&mediaType=photo&title=Urban Fantasy Books - After Dark">Urban Fantasy</a></li>';
					} else if (genre=='historical'){
						favHTML=favHTML+'<li class="favGenreItem"><a href="/service/openCustomPage.kickAction?as='+Ka.Info.AFFILIATESITEID+'&param=genrehistorical&mediaType=photo&title=Historical Books - After Dark">Historical</a></li>';
					} else if (genre=='romanticsuspense'){
						favHTML=favHTML+'<li class="favGenreItem"><a href="/service/openCustomPage.kickAction?as='+Ka.Info.AFFILIATESITEID+'&param=genreromanticsuspense&mediaType=photo&title=Romantic Suspense Books - After Dark">Romantic Suspense</a></li>';
					} else if (genre=='paranormal'){
						favHTML=favHTML+'<li class="favGenreItem"><a href="/service/openCustomPage.kickAction?as='+Ka.Info.AFFILIATESITEID+'&param=genreparanormal&mediaType=photo&title=Paranormal Books - After Dark">Paranormal</a></li>';
					}
				}
			}
			//Set user theme
			var theme = json.userInfo.profileTheme;
			$j('body').addClass('genre'+theme);
			
			
		}
		$j('#ka_profileUser').after(favHTML+favCloseHTML);
		
		
		
	}
	//Render cufon
	Cufon.replace('#wrapper h3').replace('#ka_profileContainer #ka_profileUser h5').replace('#ka_profileContainer #ka_profileRight h5').replace('.play_addMedia a').replace('.ka_bumperTop span').replace('#ka_playPage h2');
		
	
}

function userInfoUpdated(json){
	return p_validateOtherFields(p_formObj, p_tagsFailed);
}

function userAdminTagProcessorEditProfile(json){
	if(json.success==1){
		if(json.admintags!=''&&json.admintags.indexOf('authorpage')!=0){
			//Authors
		} else {
			//Non Author
			$j('.ka_supplementalQuestions').hide();
			url = customCode+"utils/getUserDetails.php?callback=?";
			$j.ajax({
			 dataType: 'jsonp',
			 data: {as: Ka.Info.AFFILIATESITEID,userId:Ka.Info.USERID },
			 jsonp: 'userInfoEditProfileRender',
			 url: url,
			 success: userInfoEditProfileRender
			});
			//override existing validations
			if (typeof window.validateOtherFields != 'undefined') {
				p_validateOtherFields = validateOtherFields;
				
				validateOtherFields = function(formObj, tagsFailed){
					p_formObj = formObj;
					p_tagsFailed = tagsFailed;
					var primaryValidationOk = Ka.formValidation.actions.validateForm(formObj);
					if(primaryValidationOk&&!tagsFailed){ 
						//validate fields and update db
						var theme = $j('input[name=theme]:checked').val();
						
						var favs = 'none';
						
						$j('#favGenreList input:checked').each(function(key,value){
							if(favs=='none'){
								favs = $j(value).val();
							} else {
								favs = favs+','+$j(value).val();
							}
							
						});
						
						var heardAbout = $j('select[name=heardAbout]').val();
						
						//alert("favs:"+favs+" theme:"+theme+" Heard:"+heardAbout);
						var url = customCode+"utils/updateUserDetails.php?callback=?";
						$j.ajax({
						 dataType: 'jsonp',
						 data: {as: Ka.Info.AFFILIATESITEID,userId:Ka.Info.USERID, heardAbout:heardAbout, profileTheme:theme,favGenre:favs, username:Ka.Info.USERNAME },
						 jsonp: 'userInfoUpdated',
						 url: url,
						 success: userInfoUpdated
						});
						//now call original
						return false;
					} else {
						//other issues exist
						//now call original
						return p_validateOtherFields(formObj, tagsFailed);
					}
	
				};
			}
		}
	}
}

function signUpNewsletterJoin(email, year, day, month){
	var dob = year+"-"+month+"-"+day;
	if(isEmail(email)&&!isNaN(new Date(year,month,day).getYear())) {
		
		url = customCode+"utils/newsletterSignup.php?callback=?";
		$j.ajax({
		 dataType: 'jsonp',
		 data: {as: Ka.Info.AFFILIATESITEID,email:email, dob: dob},
		 jsonp: 'completedSignupNewsletterJoin',
		 url: url,
		 success: completedSignupNewsletterJoin
		});
	} 
	return false;
	
}

function ka_ss_isOver13(bmonth, bday,byear){
		var propVal = 13;
                bday = bday == "Select" ? 0 : parseInt(bday);
                bmonth = bmonth == "Select" ? 0 : parseInt(bmonth) - 1;
                byear = byear == "Select" ? 0 : parseInt(byear);
                var now = new Date();
                cday = now.getDate();
                cmonth = now.getMonth();
                cyear = now.getFullYear();
                if ((cmonth > bmonth) || (cmonth == bmonth && cday >= bday)) {
                    var age = byear;
                    age = cyear - age;
                } else {
                    var age = byear + 1;
                    age = cyear - age;
                }
                return (age >= propVal ? true: false);

}

function signUpNewsletter(){
	var email = $j('#ka_email').val();
	var year = $j('#selYear').val();
	var day = $j('#selDay').val();
	var month = $j('#selMonth').get(0).selectedIndex
	var dob = year+"-"+month+"-"+day;
	if(isEmail(email)&&!isNaN(new Date(year,month,day).getYear())) {
	
		if(ka_ss_isOver13(month, day,year)){
			
			url = customCode+"utils/newsletterSignup.php?callback=?";
			$j.ajax({
			 dataType: 'jsonp',
			 data: {as: Ka.Info.AFFILIATESITEID,email:email, dob: dob},
			 jsonp: 'completedSignupNewsletter',
			 url: url,
			 success: completedSignupNewsletter
			});
		} else {
			alert("Sorry, you are not eligible to subscribe.");
		}
	} else {
		alert("Please check the date of birth and email values entered and re-submit.");
	}
	return false;
	
	
	
}

function completedSignupNewsletter(json){
	if(json.success==1){
		alert("Signup for newsletter completed successfully");
	} else {
		alert("Signup for newsletter failed");
	}
}

function completedSignupNewsletterJoin(json){
	//Don't really care about results
	storeInfo();
}

function isEmail(argvalue) {

  if (argvalue.indexOf(" ") != -1)
    return false;
  else if (argvalue.indexOf("@") == -1)
    return false;
  else if (argvalue.indexOf("@") == 0)
    return false;
  else if (argvalue.indexOf("@") == (argvalue.length-1))
    return false;

  arrayString = argvalue.split("@");
  

  if (arrayString[1].indexOf(".") == -1){
    return false;
  }else if (arrayString[1].indexOf(".") == 0){
    return false;
  }else if (arrayString[1].charAt(arrayString[1].length-1) == ".") {
    return false;
  }

  return true;

}

function ka_facebook_publish(data){
	var commentText = $j('#ka_commentList ').find('.ka_bubbleComment:first').html().trim();
	
	if(document.getElementById('ka_facebook_checkbox').checked){
		var noQuoteText = commentText;
		var commentText = '"'+commentText+'"';
		FB.ensureInit(function() {
	            FB.Connect.requireSession(function() {
	                FB.Facebook.get_sessionState().waitUntilReady(function() {
	                    var attachment = {'name':Ka.Info.CLUBNAME,'href':escape(window.location.href),'description':commentText,'caption':'{*actor*} commented on this book.'};
	                    FB.Connect.streamPublish(noQuoteText, attachment, null, null,'',null);
	                });
	            });
	        });    
	}
}

function ka_twitter_publish_media(data){
    if(document.getElementById('ka_twitter_checkbox').checked){
		//alert('ka_twitter_publish:'+data);
		url = "http://api.bit.ly/v3/shorten?callback=?";
		$j.ajax({
		 dataType: 'jsonp',
		 data: {login: bitlyLogin, apiKey:bitlyKey, uri: window.location.href, format:'json'},
		 jsonp: 'ka_twitter_publish_callback',
		 url: url,
		 success: ka_twitter_publish_callback
		});
	}	
}

function ka_twitter_publish_callback(json){
	//alert('ka_twitter_publish_callback'+json.status_code);
	var pageUrl = '<?php echo $id; ?>';
	if(json.status_code=='200'){
		pageUrl = unescape(json.data.url);
	}
	
	var currentDateObject = new Date();
	var currentHours = currentDateObject.getHours();
	var currentMinutes = currentDateObject.getMinutes();
	var currentSeconds = currentDateObject.getSeconds();
	var currentTimeString = ''+currentHours+':'+currentMinutes;
	
	var twitterPublishText = Ka.Info.USERNAME + ' left a comment on "'+Ka.Info.CLUBNAME+'" '+pageUrl+' #'+twitterTag+' at '+currentTimeString+'';	
	var twitterIframeUrl='';
	twitterIframeUrl = 'http://dev.kickapps.com/shared/ajax/twitterPublish.php?message='+escape(twitterPublishText)+'&email=';
	
	
	$j.fn.colorbox.init();	
	$j.fn.colorbox({iframe:true, title:"", href:twitterIframeUrl, transition:"elastic", speed:1000, scrollbars:false, initialWidth:"100", initialHeight:"50", width:"280", height:"365", open:true, overlayClose:false, opacity:0.3});
}

function getAuthorsFromUserList(){
	var uids='';
	$j("li.ka_member").each(function(i){
		var hrefStringPhoto = $j(this).children("a:first").attr('href');
	    if(uids==''){
	    	uids = uids+hrefStringPhoto.substring(hrefStringPhoto.indexOf("u=")+2,hrefStringPhoto.indexOf("&",hrefStringPhoto.indexOf("u=")));
	    } else {
	        uids = uids+','+hrefStringPhoto.substring(hrefStringPhoto.indexOf("u=")+2,hrefStringPhoto.indexOf("&",hrefStringPhoto.indexOf("u=")));
	    }
 	});
 	url = customCode+"utils/getAuthors.php?callback=?";
	$j.ajax({
	 dataType: 'jsonp',
	 data: {as: Ka.Info.AFFILIATESITEID,uids:uids},
	 jsonp: 'gotAuthorsFromUserList',
	 url: url,
	 success: gotAuthorsFromUserList
	});
	
}

function removeFav(){
	var tags = Ka.Info.MEDIAADMINTAGS.split(',');
	var isbn=-1;
	for(var i=0;i < tags.length;i++) {
		var tag = tags[i];
		if(tag.indexOf("isbn")==0){
			isbn = tag.replace('isbn','');
		}
	}
	
 	url = customCode+"utils/removeFavorite.php?callback=?";
	$j.ajax({
	 dataType: 'jsonp',
	 data: {as: Ka.Info.AFFILIATESITEID,username:Ka.Info.USERNAME, mediaId:isbn},
	 jsonp: 'removedFav',
	 url: url,
	 success: removedFav
	});
	return false;
}

function removedFav(json){
	if(json.fav){
		$j('#favoriteArea').html('<a onclick="return addFav();" href="#">Add to Favorites</a>');
	} else {
		alert("Unable to add as favorite at this time.");
	}
}

function addFav(){
	var tags = Ka.Info.MEDIAADMINTAGS.split(',');
	var isbn=-1;
	for(var i=0;i < tags.length;i++) {
		var tag = tags[i];
		if(tag.indexOf("isbn")==0){
			isbn = tag.replace('isbn','');
		}
	}
	
 	url = customCode+"utils/addFavorite.php?callback=?";
	$j.ajax({
	 dataType: 'jsonp',
	 data: {as: Ka.Info.AFFILIATESITEID,username:Ka.Info.USERNAME, mediaId:isbn},
	 jsonp: 'addedFav',
	 url: url,
	 success: addedFav
	});
	return false;
}

function addedFav(json){
	if(json.fav){
		$j('#favoriteArea').html('<a onclick="removeFav();return false;" href="#">Remove from Favorites</a>');
	} else {
		alert("Unable to add as favorite at this time.");
	}
}

function gotAuthorsFromUserList(json){
	if(json.success==1){
		uidArr = json.authorIds;
		$j("li.ka_member").each(function(i){
			var hrefStringPhoto = $j(this).children("a:first").attr('href');
		   	uid = hrefStringPhoto.substring(hrefStringPhoto.indexOf("u=")+2,hrefStringPhoto.indexOf("&",hrefStringPhoto.indexOf("u=")));
		   	for(i=0;i<uidArr.length;i++){
		   		authId = uidArr[i];
		   		if(authId==uid){
		   			$j(this).find('.ka_listDetails').append('<li class="ka_authorTag">Author</li>');
		   		}
		   	}
		    
	 	});
	}
}

function getAuthorsForBookList(){
	var uids='';
	$j("li.ka_photo").each(function(i){
		var hrefStringPhoto = $j(this).children("a:first").attr('href');
	    if(uids==''){
	    	uids = uids+hrefStringPhoto.substring(hrefStringPhoto.indexOf("photo/")+6,hrefStringPhoto.indexOf("/",hrefStringPhoto.indexOf("photo/")+6));
	    } else {
	        uids = uids+','+hrefStringPhoto.substring(hrefStringPhoto.indexOf("photo/")+6,hrefStringPhoto.indexOf("/",hrefStringPhoto.indexOf("photo/")+6));
	    }
	    //$j(this).find('.ka_listFrom').remove();
 	});
 	url = customCode+"utils/getAuthorsByBookMediaId.php?callback=?";
	$j.ajax({
	 dataType: 'jsonp',
	 data: {as: Ka.Info.AFFILIATESITEID,uids:uids},
	 jsonp: 'gotAuthorsForBookList',
	 url: url,
	 success: gotAuthorsForBookList
	});
	
}

function gotAuthorsForBookList(json){
	if(json.success==1){
		uidArr = json.authors;
		$j("li.ka_photo").each(function(i){
			var hrefStringPhoto = $j(this).children("a:first").attr('href');
		   	uid = hrefStringPhoto.substring(hrefStringPhoto.indexOf("photo/")+6,hrefStringPhoto.indexOf("/",hrefStringPhoto.indexOf("photo/")+6));
		   	for(i=0;i<uidArr.length;i++){
		   		authId = uidArr[i];
		   		if(authId.mediaId==uid){
		   			
		   			$j(this).find('.ka_listDate').before('<li class="bookAuthor"><strong>From</strong> '+authId.authorName+'</li>');
		   		}
		   	}
		    
	 	});
	}
}





