$( document ).ready( function(){
	
		googleConListen();
		GoogleListener();
		resizeListener();
		//googleEventTracker();
		checkFlashContent();
		logValidation();
		loginRegEvent();		
		checkBioPages();
		chooseCountry();
		launchGame();
		$(document).pngFix(); 
		enableCalendar();
		redirect();
		hashLanguage();
		//bittyPoll();
		wtbRandomizer();
		lalamap();
		secretCode();
		saharaCode();
		//saharaPage();
		//goldenButton();
		goldenButtonSweepstakes();
		
		setTimeout( "productScroller()" , 1000 ) ;

		var assigned = "";
		var arrProducts = new Array();
		//$(".a-inter-event-home").click();
	 
	if("#div-town"){

			$("#bitty-world-close").click(function(){
				$("#bitty-game-wrapper").css("display" , "none");
			});

			var google_conversion_label = "u76CCJrx4AEQgIyC7wM";
			$("#google_conversion").html("<img src='http://www.googleadservices.com/pagead/conversion/1038124544/?label=u76CCJrx4AEQgIyC7wM&amp;guid=ON&amp;script=0' border='0' />");
	
			var hasUnity = DetectUnityWebPlayer();
			var brokenUnity = false;
			$("#div-game-overlay").css("display","block");
			
			if( hasUnity ){
			
			//Current Version on Dev from Pub file	
			var landVersion = bittyHash.flashvars.landVersion;
			//Current Dev Version
			//var landVersion = "http://c1877312.r12.cf0.rackcdn.com/lalaloopsy04282011.unity3d";	
			
			$("#div-bitty-game").html('<object id="UnityObject" classid="clsid:444785F1-DE89-4295-863A-D46C3A781394" width="640" height="480" codebase="http://webplayer.unity3d.com/download_webplayer-2.x/UnityWebPlayer.cab#version=2,0,0,0"><param name="src" value="'+ landVersion + '" /><param name="disableContextMenu" value="true" /><embed id="UnityEmbed" src="' + landVersion + '" disableContextMenu="true" width="640" height="480" type="application/vnd.unity" pluginspage="http://www.unity3d.com/unity-web-player-2.x" /></object>');
					// if Unity does not define to GetPluginVersion on Safari on 10.6, we presume the plugin
					// failed to load because it is not compatible with 64-bit Safari.
					//version thats on product - http://c1877312.cdn.cloudfiles.rackspacecloud.com/lalaloopsy_v5.unity3d
					//Dev version - http://c1877312.r12.cf0.rackcdn.com/lalaloopsy_dev.unity3d
					//US Previous Version - http://c1877312.r12.cf0.rackcdn.com/lalaloopsy04282011.unity3d
					//US Current Version - smarty_files/templates/unity/games/land/winter/lalaloopsy.unity3d
					if (navigator.appVersion.indexOf("Safari") != -1 ){
						if( document.getElementById("UnityEmbed") ){
						if( navigator.appVersion.indexOf("Mac OS X 10_6") != -1
							&& document.getElementById("UnityEmbed").GetPluginVersion == undefined){
							brokenUnity = true;
						}		
						}
					}

					// 2.5.0 cannot auto update on ppc. Treat as broken.
					else if ( navigator.platform == "MacPPC") {
							if (navigator.appVersion.indexOf("Safari") != -1 ){
								alert( document.getElementById("UnityEmbed") );
								if( document.getElementById("UnityEmbed") ){
								if( document.getElementById("UnityEmbed").GetPluginVersion() == "2.5.0f5" ){
									brokenUnity = true;
								}
								}

							}
					}
			}

			if( !hasUnity || brokenUnity ){
				var installerPath = GetInstallerPath();
				if (installerPath != "") {
					if( brokenUnity ){
						$("#div-bitty-game").html('<a href= ' + installerPath + '><img src="http://webplayer.unity3d.com/installation/getunityrestart.png" border="0"/></a>');
					 }
					else{
						$("#div-bitty-game").html('<a href= ' + installerPath + '><img src="http://webplayer.unity3d.com/installation/getunity.png" border="0"/></a>')
					}

					// By default disable ActiveX cab installation, because we can't make a nice Install Now button
						if (navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.toLowerCase().indexOf("win") != -1)
						if (0){	
							var innerHtmlDoc =
								'<object id="UnityInstallerObject" classid="clsid:444785F1-DE89-4295-863A-D46C3A781394" width="320" height="50" codebase="http://webplayer.unity3d.com/download_webplayer-2.x/UnityWebPlayer.cab#version=2,0,0,0">\n' + 
							    '</object>';
						$("#div-bitty-game").html( innerHtmlDoc );
						}

					//include the msie crap
				}
				else{
					if( brokenUnity ){
						$("#div-bitty-game").html('<a class="openWindow" href="javascript://"><img src=\"http://webplayer.unity3d.com/installation/getunityrestart.png\" border=\"0\"/></a>');
					}
					else{
						$("#div-bitty-game").html('<a class="openWindow" href="javascript://"><img src=\"http://webplayer.unity3d.com/installation/getunity.png\" border=\"0\"/></a>');

					}
					unityDownloadWebsite();

				}

				if( !brokenUnity ){
					AutomaticReload();
				}
			}
		}
	
});





function productFilter( json_arr, year, season, series, most, avail ){
	var strHtml = "";
	
	if ( year != null && year != "" ) {
		json_arr = jQuery.grep(json_arr, function(e){ return (e.year == year); });
    }
	
	if ( season != null && season != "" ) {
		var month = season.split(",");	
		json_arr = jQuery.grep(json_arr, function(e){ return (e.month >= month[0] && e.month <= month[1]); });
    }

	strHtml = productArray( json_arr );
	$("#product-list").html( strHtml );
}

function productArray(json_arr){
	var strHtml="";
	for( x in json_arr ){
		strHtml += "<li class='product-item'>";
		strHtml += "<div class='div-product-thumbnail'>";
		strHtml += "<a href='?section=productinfo&sku="+json_arr[x]["sku"]+"'><img src='smarty_files/templates/images/catalog/thumb/" + json_arr[x]["sku"] + ".jpg' class='product-image' /></a><br/>";
		strHtml += "</div>";
		strHtml += "<div class='div-product-name'><a href='?section=productinfo&sku="+json_arr[x]["sku"]+"'>" + json_arr[x]["name"] + "</a></div>";
		strHtml += "</li>" + "\n";
	}
	return (strHtml);

}

function productScroller(){
	if( $__( $( "#product-wrapper" ) ) ){
		
		$("#product-wrapper").jScrollPane({		
			verticalDragMinHeight: 40,
			verticalDragMaxHeight: 40,
			showArrows: true,
			verticalArrowPositions: 'split',
			horizontalArrowPositions: 'split',
			autoReinitialise: true
		});
	}
}

function unityDownloadWebsite(){
		$(".openWindow").click( function(){
			gotoLink2("http://www.unity3d.com/unity-web-player-2.x");
		 });
}

function googleConListen(){
	if( google_return_con == "reg" ){
			$("#register").click();
	}
}

function chooseCountry(){
	
		$(".choosecountry").click( function() {
			var currCountry = this.id;
			setCookie("lalaloopsylang", this.id);
			if (page == "productinfo"){
			window.location=base+"?section=productinfo"+"&sku="+currentSku+ "&uriLang=" + this.id;
			}else{
				window.location=base+"?section="+ page + "&uriLang=" + this.id;
			}
			
			pageTracker._trackEvent('Country:', currCountry);
		});
		
	
		$(".choosecountry").hover(function() {
			var countryid = this.id + "-mouseover";
			$("#"+countryid).css("display","block");
			},
			function() {
			var countryid = this.id + "-mouseover";
			$("#"+countryid).css("display","none");
			}	
		);
		
		$("#ja-ja").hover(function() {
			$("#ja-ja-mouseover").css("display","block");
			},
			function() {
				$("#ja-ja-mouseover").css("display","none");
		});
		
		$("#ja-ja").click(function(){
			window.location = "http://www.lalaloopsy.jp"; 
		});

	if (jQuery.browser.msie && (jQuery.browser.version > 6.0000) && (jQuery.browser.version < 9)){
			$("#allpage-choosecountry, #a-flag").click( function(){
				$("#overlay-country").css("display", "block");
			});
			$("#home-chooosecountry, #home-img-flag").click( function(){
				$("#overlay-country").css("display", "block");
			});
			$("#reset-overlay-country").click( function(){
				$("#overlay-country").css("display", "none");
			});
	}
	else {
		if( $__( $( "#allpages-register-wrapper" ) ) ){
			     /*	$(".choosecountry").click( function() {
					var currCountry = this.id;
					setCookie("lalaloopsylang", this.id);
					if (page == "productinfo"){
					window.location=base+"?section=productinfo"+"&doll="+currentDoll+"&sku="+currentSku+ "&uriLang=" + this.id;
					}else{
						window.location=base+"?section="+ page + "&uriLang=" + this.id;
					}

					pageTracker._trackEvent('Country:', currCountry);
				});


				$(".choosecountry").hover(function() {
					var countryid = this.id + "-mouseover";
					$("#"+countryid).css("display","block");
				},
					function() {
					var countryid = this.id + "-mouseover";
					$("#"+countryid).css("display","none");
				}
			);*/
			
				$("#allpage-choosecountry, #a-flag").click( function(){
						$("#overlay-country").css("display","block");
   						$("#country-overlay-wrapper").animate({
    						marginLeft: "40px"
    						}, 1200 );
    						//#country-overlay-cloud
	    					$("#country-overlay-cloud-wrapper").delay(1000).animate({
	    						marginTop: "-1055px"
	    						}, 700 );
    					$(".overlay-columns").delay(1200).animate({
    						opacity: "1.0"
    						}, 700 );
				});

				$("#reset-overlay-country").click( function(){
						
   						$("#country-overlay-wrapper").animate({
    						opacity: "0.0"
    						}, 700 );
    					$("#country-overlay-cloud-wrapper").animate({
    						opacity: "0.0",
							filter: "alpha(opacity=0)"
    						}, 700 );
    					$(".overlay-columns").animate({
    						opacity: "0.0"
    						}, 700 );
						
    					$("#country-overlay-wrapper").delay(700).animate({
    						marginLeft: "-3050px",
    						opacity: "1.0"
    						}, 0 );
    					$("#country-overlay-cloud-wrapper").delay(700).animate({
    						marginTop: "-2055px",
    						opacity: "1.0",
							filter: "alpha(opacity=100)"
    						}, 0 , function() {
    					$("#overlay-country").delay(700).css("display","none"); });
				});



				$("#country-header-close").click( function() {
					$("#country-wrapper").css("display","none");
					
					setTimeout( function(){
						centerPage();
						} , 2000 );
				});
		}
		
		else if( $__( $( "#homepage-login-wrapper" ) ) ){
			
			/*	$(".choosecountry").click( function() {
					var currCountry = this.id;
					setCookie("lalaloopsylang", this.id);
					if (page == "productinfo"){
					window.location=base+"?section=productinfo"+"&doll="+currentDoll+"&sku="+currentSku+ "&uriLang=" + this.id;
					}else{
						window.location=base+"?section="+ page + "&uriLang=" + this.id;
					}

					pageTracker._trackEvent('Country:', currCountry);
				});


				$(".choosecountry").hover(function() {
					var countryid = this.id + "-mouseover";
					$("#"+countryid).css("display","block");
				},
					function() {
					var countryid = this.id + "-mouseover";
					$("#"+countryid).css("display","none");
				}
			);*/
			
				$("#home-chooosecountry, #home-img-flag").click( function(){
					$("#country-wrapper").css({ "display" : "block" , "width" : "2300px" });
						$("#overlay-country").css({"display" : "block" , "width" : "2300px" });
   						$("#country-overlay-wrapper").animate({
    						marginLeft: "40px"
    						}, 1200 );
						//#country-overlay-cloud
    					$("#country-overlay-cloud-wrapper").delay(1000).animate({
    						marginTop: "-1055px",
							filter: "alpha(opacity=100)"
    						}, 700 );
    					$(".overlay-columns").delay(1200).animate({
    						opacity: "1.0"
    						}, 700 );
						
						setTimeout( function(){ $(".overlay-columns").css("display" , "block")}
						, 1000 ) ;
						
				});

				$("#reset-overlay-country").click( function(){
						
   						$("#country-overlay-wrapper").animate({
    						opacity: "0.0"
    						}, 700 );
    					$("#country-overlay-cloud-wrapper").animate({
    						opacity: "0.0"
    						}, 700 );
    					$(".overlay-columns").animate({
    						opacity: "0.0"
    						}, 700 );
						$(".overlay-columns").css("display" , "none");
    					$("#country-overlay-wrapper").delay(700).animate({
    						marginLeft: "-3050px",
    						opacity: "1.0"
    						}, 0 );
    					$("#country-overlay-cloud-wrapper").delay(700).animate({
    						marginTop: "-2055px",
    						opacity: "1.0"
    						}, 0 , function() {
    					$("#overlay-country").delay(700).css("display","none"); });
				});
				$("#country-header-close").click( function() {
					$("#country-wrapper").css("display","none");
				});

		}//end if
	}
	if (jQuery.browser.msie && (jQuery.browser.version > 6.0000) && (jQuery.browser.version < 9) && page =="homepage"){
		$("#country-dialog").css({ "margin" : "0 auto" , "position" : "relative" });
		$("#country-overlay-wrapper").css({ "marginTop" : "285px" , "marginLeft" : "550px" , "width" : "900px" });
		$("#overlay-columns").css({ "opacity" : "1.0" });
		$("#country-overlay-cloud-wrapper").css({ "marginTop" : "-1055px" });
		//$("#country-overlay-cloud").css({ "marginTop" : "-767px" });
	}
	else if (jQuery.browser.msie && (jQuery.browser.version > 6.0000) && (jQuery.browser.version < 9) && page !="homepage"){
		$("#country-dialog").css({ "margin" : "0 auto" , "position" : "relative" , "width" : "900px" });
		$("#country-overlay-wrapper").css({ "marginTop" : "285px" , "marginLeft" : "40px" , "width" : "900px" });
		$("#overlay-columns").css({ "opacity" : "1.0" });
		$("#country-overlay-cloud-wrapper").css({ "marginTop" : "-1055px" });
		//$("#country-overlay-cloud").css({ "marginTop" : "-767px" });
	}
	else if (page =="homepage" && (jQuery.browser.msie && (jQuery.browser.version >= 9)) || page =="homepage" && !jQuery.browser.msie  ){
		$("#country-dialog").css({ "margin" : "0 auto" , "position" : "relative"});
		$("#country-overlay-wrapper").css({ "marginTop" : "285px" , "marginLeft" : "-3050px" , "width" : "900px" });
	}
	else if (page !="homepage" && (jQuery.browser.msie && (jQuery.browser.version >= 9)) || page !="homepage" && !jQuery.browser.msie ){
		$("#country-dialog").css({ "margin" : "0 auto" , "position" : "relative" , "width" : "900px" });
		$("#country-overlay-wrapper").css({ "marginTop" : "285px" , "marginLeft" : "-3050px" , "width" : "900px" });
	}
}
function setCookie( name , value ){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+50);
	document.cookie="" + name + "=" + value + ";expires="+exdate.toGMTString() + ";";
}
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}


function deleteCookie( name ){
	var expdate = new Date();
	expdate.setTime(expdate.getTime() - 1);
	return	document.cookie = name += "=; expires=" + expdate.toGMTString();
}

function hashLanguage(){

	/* Top links copy */
	$("#homepage-reg, #allpage-reg").html(bittyHash.language.toplinks.register);
	$("#allpage-login, #homepage-login").html(bittyHash.language.toplinks.login);
	
	if(obj.id){
		$("#homepage-name, #allpage-name").html(bittyHash.language.toplinks.welcome + obj.first_name);
	}
	
	$("#allpage-logout, #homepage-logout").html(bittyHash.language.toplinks.logout);
	$("#home-chooosecountry, #allpage-choosecountry").html(bittyHash.language.toplinks.country);
	$("#country-header-left").html(bittyHash.language.allpage.choosecountry_desc);
	$("#game-header-p").html(bittyHash.language.allpage.hidden_game);
	
	/* Country copy */
	$("#en-us").html(bittyHash.language.countryLang.usa);
	$("#en-uk").html(bittyHash.language.countryLang.uk);
	$("#en-au").html(bittyHash.language.countryLang.australia);
	$("#it-it").html(bittyHash.language.countryLang.italy);
	$("#en-ca").html(bittyHash.language.countryLang.canadaEn);
	$("#fr-ca").html(bittyHash.language.countryLang.canadaFr);
	$("#nl-nl").html(bittyHash.language.countryLang.nederland);
	$("#es-es").html(bittyHash.language.countryLang.spain);
	$("#fr-fr").html(bittyHash.language.countryLang.france);
	$("#de-de").html(bittyHash.language.countryLang.germany);
	
	/* Footer copy */
	$("#copyright").html(bittyHash.language.footer.copyright); 
	$("#terms").html(bittyHash.language.footer.termsofuse);
	$("#privacy").html(bittyHash.language.footer.policy);
	$("#footer-faq").html(bittyHash.language.footer.faq);
	$("#wheretobuy").html(bittyHash.language.footer.wheretobuy);
	$("#best-viewed").html(bittyHash.language.footer.best_view);
	
	/* Town copy */
	
	$("#game-dialog-header").html(bittyHash.language.town.welcometo);
	
	/* New Fun Page Translation */
	$("#fun-tab-land").html(bittyHash.language.funpage.label_land);
	$("#fun-tab-games").html(bittyHash.language.funpage.label_games);
	$("#fun-tab-downloads").html(bittyHash.language.funpage.label_downloads);
	
	/*Registration*/
	$("#dialog-title").html(bittyHash.language.registration.reg_step1);
	$("#dialog-desc").html(bittyHash.language.registration.introduction);
	$("#dialog-dob").html(bittyHash.language.registration.reg_dob);
	$("#calendar").html(bittyHash.language.registration.reg_calendar);
	$("#span-reg-firstname").html(bittyHash.language.registration.reg_firstname);
	$("#span-reg-lastname").html(bittyHash.language.registration.reg_lastname);
	$("#span-reg-username").html(bittyHash.language.registration.reg_username);
	$("#span-reg-password").html(bittyHash.language.registration.reg_password);
	$("#reg_submit").html(bittyHash.language.registration.reg_submit);
	$("#span-reg-gender").html(bittyHash.language.registration.reg_gender);
	$("#span-reg-girl").html(bittyHash.language.registration.reg_girl);
	$("#span-reg-boy").html(bittyHash.language.registration.reg_boy);
	$("#span-reg-email").html(bittyHash.language.registration.reg_email);
	$("#span-reg-parentemail").html(bittyHash.language.registration.reg_parent_email);
	$("#span-reg-country").html(bittyHash.language.registration.reg_country);
	$("#span-reg-state").html(bittyHash.language.registration.reg_state);
	$("#span-reg-zip").html(bittyHash.language.registration.reg_zip);
	$("#span-reg-newsletters").html(bittyHash.language.registration.reg_newsletters);
	$("#optin_1").html(bittyHash.language.registration.reg_optin1);
	$("#optin_2").html(bittyHash.language.registration.reg_optin2);
	$("#btn-next").html(bittyHash.language.registration.reg_next);
	$("#p-reg-complete, #p-reg-complete1").html(bittyHash.language.registration.reg_complete);
	$("#span-reg-complete-username").html(bittyHash.language.registration.reg_complete_user);
	$("#span-reg-complete-password").html(bittyHash.language.registration.reg_complete_password);
	$("#complete-btn-close").html(bittyHash.language.registration.reg_close);
	
	
	$("#logon-header-left").html(bittyHash.language.login.login_desc);
	$("#span-login-username").html(bittyHash.language.login.login_username);
	$("#span-login-password").html(bittyHash.language.login.login_password);
	$("#a-logon-forgot").html(bittyHash.language.login.login_forgot);
	$("#a-logon-register").html(bittyHash.language.login.login_register);
	
	$("#btn-logon").html(bittyHash.language.login.login_button);
	$("#forgot-header-left").html(bittyHash.language.login.login_forgot);
	
	$("#p-forgot-desc").html(bittyHash.language.login.login_forgot_emailed);
	$("#span-forgot-firstname").html(bittyHash.language.login.forgot_firstname);
	
	
	$("#span-forgot-email").html(bittyHash.language.login.forgot_email);
	
	$("#forgot_username").html(bittyHash.language.login.forgot_username);
	$("#forgot_email").html(bittyHash.language.login.forgot_parent_email);
	$("#forgot-submit").html(bittyHash.language.login.forgot_submit);
	
	/*FAQ*/
	$("#faq-wrapper").html(bittyHash.language.faq.questions);
	
	/*Catalog*/
	$("#label-back").html(bittyHash.language.catalog.label_back);
	
	/*Video*/
	$("#webisodes").html(bittyHash.language.video.webisodes);
	$("#products").html(bittyHash.language.video.products);
	$("#games").html(bittyHash.language.video.games);
	$("#birthdays").html(bittyHash.language.video.birthdays);


}

	var currentWebsite = "";	

function openInterstitial(id) {
	flashInt(id);
}
function redirect(id,url){
	var arr = new Array();
	    arr["wtb-walmart"] = "http://www.walmart.com/search/search-ng.do?search_query=lalaloopsy&ic=16_0&Find=Find&search_constraint=0";
	    arr["wtb-kmart_2"] = "http://www.kmart.com/shc/s/search_10151_10104?keyword=lalaloopsy&vName=&part=&url=";
	    arr["wtb-toyrus"] = "http://www.toysrus.com/search/index.jsp?kwCatId=&kw=lalaloopsy&origkw=lalaloopsy&f=Taxonomy/TRUS/2254197&sr=1";
	    arr["wtb-target_2"] = "http://www.target.com/s?searchTerm=lalaloopsy&category=0%7CAll%7Cmatchallany%7Call+categories";
		arr["wtb-tikes"] = "http://www.littletikes.com/lalaloopsy-dolls";
		arr["wtb-amazon"] = "http://www.amazon.com/s/?ref=ty_mga_direct&tag=mgaentertainm-20&url=search-alias%3Dtoys-and-games&field-keywords=lalaloopsy";
	    arr["facebook"] = "http://www.facebook.com/lalaloopsy";
   	    arr["facebook-uk"] = "http://www.facebook.com/lalaloopsyuk";
		arr["twitter"] = "http://www.twitter.com/lalaloopsy";
		arr["youtube"] = "http://www.twitter.com/lalaloopsy";
	    arr["home-myspace"] = "http://www.twitter.com/";
	    arr["stardoll"] = "http://www.stardoll.com/en/dolls-games/";
		arr["voteforus"] = "http://www.timetoplaymag.com/peoplesplayawards/2010/";
		arr["cloud-facebook"] = "http://www.facebook.com/lalaloopsy";
		arr["cloud-twitter"] = "http://www.twitter.com/lalaloopsy";
		arr["cloud-youtube"] = "http://www.youtube.com/lalaloopsy";
		arr["cloud-facebook-es"] = "http://www.facebook.com/lalaloopsy.es";
		arr["cloud-facebook-uk"] = "http://www.facebook.com/lalaloopsyuk";
		arr["cloud-twitter-es"] = "http://www.twitter.com/lalaloopsy";
		arr["cloud-youtube-es"] = "http://www.youtube.com/lalaloopsy";
		arr["hyves"] = "http://lalaloopsy1.hyves.nl/",
		arr["bestviewed_chrome"] = "http://www.google.com/chrome";
		arr["bestviewed_firefox"] = "http://www.mozilla.com";
		arr["bestviewed_safari"] = "http://www.apple.com/safari/";
		arr["footer-firefox"] = "http://www.mozilla.com";
		arr["footer-chrome"] = "http://www.google.com/chrome";
		arr["footer-safari"] = "http://www.apple.com/safari/";
		arr["time-to-play"] = "http://www.timetoplaymag.com/peoplesplayawards/2010/";
		arr["adobe-reader-nl"] = "http://get.adobe.com/reader/";
		arr["adobe-reader-en"] = "http://get.adobe.com/reader/";
		arr["adobe-reader-fr"] = "http://get.adobe.com/reader/";
		arr["adobe-reader-it"] = "http://get.adobe.com/reader/";
		arr["uk-amazon"] = "http://www.amazon.co.uk/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=lalaloopsy&x=0&y=0";
		arr["uk-entertainer"] = "http://www.thetoyshop.com/SoftToysAndDolls/FashionDolls/Lalaloopsy";
		arr["uk-toysrus"] = "http://www.toysrus.co.uk/index.jsf?fh_eds=%ef%bf%bd&fh_view_size=10&omitxmldecl=yes&fh_maxdisplaynrvalues_brand=-1&fh_refview=lister&fh_refpath=facet_6&fh_reffacet=brand&fh_location=%2f%2ftrus%2fen_GB%2fcategories%3c%7btrus_trus%7d%2fitemtype%3dproduct%2fcategories%3c%7btrus_trus_toysrus_trutoys%7d%2fbrand%3e%7bbrands_brandlalaloopsy%7d";
		arr["uk-toymaster"] = "http://www.toymastershop.co.uk/search.aspx?SearchTerm=lalaloopsy";
		arr["uk-argos"] = "http://www.argos.co.uk/webapp/wcs/stores/servlet/Search?storeId=10001&catalogId=1500002701&langId=-1&searchTerms=LALALOOPSY";
		arr["uk-johnlewis"] = "http://www.johnlewis.com/Search/Search.aspx?SearchTerm=lalaloopsy#1";
		arr["uk-smyths"] = "http://www.smythstoys.com/Shop_Product_List.aspx?Profile=Sterling&query=lalaloopsy";
		arr["uk-littlewoods"] = "http://www.littlewoods.com/e/q/lalaloopsy.end?cmtag=o&_requestid=16654";
		arr["uk-woolworths"] = "http://www.woolworths.co.uk/e/q/lalaloopsy.end?cmtag=o&_requestid=37052";
		arr["uk-tesco"] = "http://direct.tesco.com/search/default.aspx?search=lalaloopsy&confirm.x=0&confirm.y=0";
		arr["it-giocheria"] = "http://www.giocheria.it";
		arr["it-toyscenter"] = "http://www.toyscenter.it";
		arr["de-de-amazon-de"] = "http://www.amazon.de/s/ref=nb_sb_noss?__mk_de_DE=%C5M%C5Z%D5%D1&url=search-alias%3Daps&field-keywords=lalaloopsy&x=0&y=0";
		arr["de-de-mytoys"] = "http://www.mytoys.de/catalog/search?query=lalaloopsy&productsPerPage=20";
		arr["de-de-spielemax"] = "http://www.spielemax.de";
		arr["de-de-toysrus-de"] = "http://www.toysrus.de";
		arr["lalaloopsythegame"] = "http://www.lalaloopsythegame.com";
	

	$(".a-inter-event").click( function(){
		$("#allpage-interstitial-"+language).fadeIn("slow");
		currentWebsite = arr[this.id];
	 });
	
	$(".a-inter-home").click( function(){
		$("#home-interstitial-"+language).fadeIn("slow");
		currentWebsite = arr[this.id];
	 });

	$("#interstitial-yes-"+language).click( function(){ 
			gotoLink( currentWebsite );
			pageTracker._trackEvent('retailers', currentWebsite);
		$("#allpage-interstitial-"+language).fadeOut("slow");
		$("#home-interstitial-"+language).fadeOut("slow");
	});

	$("#interstitial-no-"+language).click( function(){ 
		$("#allpage-interstitial-"+language).fadeOut("slow");
		$("#home-interstitial-"+language).fadeOut("slow");
	});
}

function flashInt( id ){
	
	var arr = new Array();
	    arr["wtb-walmart"] = "http://www.walmart.com/";
	    arr["wtb-kmart"] = "http://www.kmart.com/";
	    arr["wtb-toyrus"] = "http://www.toysrus.com/";
	    arr["wtb-target"] = "http://www.target.com/";
		if(country == "es-es"){
			arr["facebook"] = "http://www.facebook.com/lalaloopsy.es";
		}
		else if(country == "en-uk"){
			arr["facebook"] = "http://www.facebook.com/lalaloopsyuk";
		}
	    else{
			arr["facebook"] = "http://www.facebook.com/lalaloopsy";
		}
		arr["twitter"] = "http://www.twitter.com/lalaloopsy";
		arr["youtube"] = "http://www.youtube.com/lalaloopsy";
	    arr["home-myspace"] = "http://www.twitter.com/";
	    arr["stardoll"] = "http://www.stardoll.com/en/dolls-games/";
		arr["voteforus"] = "http://www.timetoplaymag.com/peoplesplayawards/2010/";
		arr["direct-buy"] = "http://www.littletikes.com/toys/lalaloopsy-dolls-zapf.aspx";
		arr["cloud-facebook"] = "http://www.facebook.com/lalaloopsy";
		arr["cloud-twitter"] = "http://www.twitter.com/lalaloopsy";
		arr["cloud-youtube"] = "http://www.youtube.com/lalaloopsy";
		arr["hyves"] = "http://lalaloopsy1.hyves.nl/",
		arr["time-to-play"] = "http://www.timetoplaymag.com/peoplesplayawards/2010/";
		arr["adobe-reader"] = "http://get.adobe.com/reader/";
		arr["footer-firefox"] = "http://www.mozilla.com";
		arr["footer-chrome"] = "http://www.google.com/chrome";
		arr["footer-safari"] = "http://www.apple.com/safari/";
		arr["mittensiphone"] = "http://itunes.apple.com/us/app/mittens-speedy-ski/id420058566?mt=8";
		arr["lalaloopsythegame"] = "http://www.lalaloopsythegame.com";

	
	
		currentWebsite = arr[ id ];	
	
	
		$("#home-interstitial-"+language).fadeIn("slow");

}

function gotoLink( website ){
			window.open( website ,"","menubar=1,resizable=1,location=1,status=1,scrollbars=1" );
}

function gotoLink2( website ){
			window.open( website ,"","menubar=no,toolbar=no,resizable=no,location=0,status=no,scrollbars=no,width=600,height=500" );
}

function $__( objId ) {
        return $( objId ).get(0);
}

function launchGame(){
	$("#div-town-hangtag-"+language).click(function(){
		$("#bitty-game-wrapper").fadeIn('slow');
	});
}

function showModalOverlay(){

	$("#overlay-wrapper").css({ "display" : "block" , "width" : "2300px"}).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 500 );
}

function bittyPoll(){

	
	if (page == "homepage" && language == "en"){	
	$("#overlay-poll").css("display" , "block");

	var params = { wmode : "transparent" , allowscriptaccess : "always" };
	var attributes = {};

	var flashvars = {};
	flashvars.gamepipe = base + "gamepipe/index.php";

	swfobject.embedSWF("smarty_files/templates/flash/build/lalaloopsypoll.swf", "poll-dialog", "425", "250", "9.0.0","expressInstall.swf", flashvars, params, attributes);
	}
}

function hideModalOverlay(){
	$("#overlay-wrapper").css( "display" , "none" );
	$("#overlay-poll").css("display" , "none");
	$("#bittypoll-wrapper").html("<div id='poll-dialog'></div>");
}


function centerPage(){
	
	if( page == "homepage" && typeof window.innerWidth!='undefined' )
	{
		var width = window.innerWidth/2;	
		var cwidth = ((width-(1150))*-1);
		window.scrollTo( cwidth ,0);
	}
		
	if ( page == "homepage" && document.documentElement &&                 
	typeof document.documentElement.clientWidth!='undefined' &&
	document.documentElement.clientWidth!=0 ) 
	{
		var width  = document.documentElement.clientWidth/2;
		var cwidth = ((width-(1150))*-1);
		window.scrollTo( cwidth ,0);
	} 
	

	if ( page == "homepage" && document.body && typeof document.body.clientWidth!='undefined' ) 
	{
		var width = document.body.clientWidth/2;
		var cwidth = ((width-(1150))*-1);
		window.scrollTo( cwidth ,0);
	}  			

}


function lalamap(){
	
	var params = { wmode : "opaque" , allowscriptaccess : "always" };
	 var attributes = {};

	 var flashvars = {};
	 flashvars.downloadurl = "http://www.lalaloopsy.com/smarty_files/templates/documents/";

	 swfobject.embedSWF("smarty_files/templates/flash/build/lalaloopsymap.swf", "lala-map-game", "645", "480", "9.0.0","expressInstall.swf", flashvars, params, attributes);
	
}

function wtbRandomizer(){
	
	if(country == "en-us"){

	  var arr = new Array();
	
		arr[0]=bittyHash.wtbLogos.wtb_toyrus;
		arr[1]=bittyHash.wtbLogos.wtb_amazon;
		arr[2]=bittyHash.wtbLogos.wtb_target;
		arr[3]=bittyHash.wtbLogos.wtb_walmart;
		arr[4]=bittyHash.wtbLogos.wtb_kmart;
		arr[5]=bittyHash.wtbLogos.wtb_tikes;
		
		$('#array').text(arr.join(', '));
			arr = $.shuffle(arr);

		$(".retail-1").html("<img src='smarty_files/templates/images/wtb_logos/" +arr[0] + ".png'/>").attr("id" , arr[0]);
		$(".retail-2").html("<img src='smarty_files/templates/images/wtb_logos/" +arr[1] + ".png'/>").attr("id" , arr[1]);
		$(".retail-3").html("<img src='smarty_files/templates/images/wtb_logos/" +arr[2] + ".png'/>").attr("id" , arr[2]);
		$(".retail-4").html("<img src='smarty_files/templates/images/wtb_logos/" +arr[3] + ".png'/>").attr("id" , arr[3]);
		$(".retail-5").html("<img src='smarty_files/templates/images/wtb_logos/" +arr[4] + ".png'/>").attr("id" , arr[4]);
		$(".retail-6").html("<img src='smarty_files/templates/images/wtb_logos/" +arr[5] + ".png'/>").attr("id" , arr[5]);
		
	}
}

/*function saharaPage(){
	$("#enter-sahara").click( function(){ 
		iFrameWindow();
	} );
	$("#x-close-iframe").click( function(){ 
		$("#div-x-close-wrapper").css("display" , "none");
			closeIframe();
	});

	if( data.length > 0  ){
		iFrameWindow();
	}
}
*/

var sweepstakes_strict = null;

function goldenButtonSweepstakes(){
        $("#gb-enter-sweeps-img, #a-weekly-enternow").click( function(){
                sweepstakes_strict = "strict";
                iFrameWindow();
        } );

        $("#a-footer-gb").click( function(){
                sweepstakes_strict = "non";
                iFrameWindow();
        } );


        $("#x-close-iframe").click( function(){
                $("#div-x-close-wrapper").css("display" , "none");
                        closeIframe();
        });

        if( data.length > 0  ){
                iFrameWindow();
        }
}



function iFrameWindow(){
                $("#div-sahara-iframe-wrapper,#iframe-sahara, #div-iframe-close-wrapper").fadeIn("slow");

                if( data != "" ){
                        $("#iframe-sahara").attr("src","sweepstakes/index.php?data=" + data );
                }
                else{
                        $("#iframe-sahara").attr("src","sweepstakes/index.php?type=" + sweepstakes_strict );
                }
}

function goHome(){
	window.location = "http://www.lalaloopsy.com/?section=homepage";
}

function closeIframe(){ 
	//goHome();
	$("#iframe-sahara,#div-sahara-iframe-wrapper, #div-iframe-close-wrapper").css("display","none");
}

function gotoGame( id ) {
	window.location="?section=fun&game="+id;
}

function getFlashMovie(movieName) 
{ 
	var isIE = navigator.appName.indexOf("Microsoft") != -1; return (isIE) ? window[movieName] : document[movieName]; 
}

function birthdays(){
	var homeVideos;
	var birthdayweek;
	var birthdays = {
		"dot" : {
			"name" : "dot",
			"date" : "1307316617"
		},
		"patch" : {
			"name" : "patch",
			"date" : "1308267617"
			}
		};
	
	for( x in birthdays ){
		birthdayweek = birthdays[x].date + 604800;
		
		if(	birthdays[x].date >= time && birthdays[x].date <= birthdayweek ){
			alert(birthdays[x].name + " birthday");
			currbday = birthdays[x].date + 604800;
			homeVideos = birthdays[x].name +"_birthday.f4v," + bittyHash.flashvars.homevideos;
		}
		else{
			homeVideos = bittyHash.flashvars.homevideos;
		}
	}
}

function checkFlashContent(){
	
	var menubar = bittyHash.flashvars.menubar;
	
	setTimeout( function(){
	centerPage();
	} , 1500 );
	
	var startMini = $.url.param("start");
	
	if( page == "homepage" ){
		
		var homeVideos;
		var birthdayweek;
		var nobirthdays;
		var birthdays = {
			"dot" : {
				"name" : "dot",
				"date" : "1308333900"
			},
			"patch" : {
				"name" : "patch",
				"date" : "1309370700"
				}
			};
	
			for(x in birthdays){
				birthdayweek = parseInt(birthdays[x].date) + 604800;
				if( birthdays[x].date <= time && birthdays[x].date <= birthdayweek){
					
					//alert(birthdays[x].name);
					//homeVideos = bittyHash.flashvars.homevideos;
					break;
					
				}
				else{
					nobirthdays = 1;
				}
			}
			
			if(nobirthdays == 1){
				alert("there are no birthdays");
			}

			var google_conversion_label = "ergtCKLw4AEQgIyC7wM";
			$("#google_conversion").html("<img src='http://www.googleadservices.com/pagead/conversion/1038124544/?label=ergtCKLw4AEQgIyC7wM&amp;guid=ON&amp;script=0' border='0' />");

		
		$("body").addClass("mainhomepage");
		
		/* Set variable from Hash */
		var homeurl = bittyHash.flashvars.homeurl;
		var homepromo1 = bittyHash.flashvars.promo1;
		var homepromo2 = bittyHash.flashvars.promo2;
		var homepromo3 = bittyHash.flashvars.promo3;
		var homepromo1_link = bittyHash.flashvars.promo1_link;
		var homepromo2_link = bittyHash.flashvars.promo2_link;
		var homepromo3_link = bittyHash.flashvars.promo3_link;
		var homeVideos = bittyHash.flashvars.homevideos;	
		var allVideos = homeVideos;
		
		var flashvars = { };
		
		
		flashvars.imageFader = bittyHash.flashvars.imageFader;
			
		

		flashvars.swf_url = homeurl;
		
		flashvars.homeVideoURL = allVideos;
		
		flashvars.promo1 =  homepromo1 + homepromo1_link;
		flashvars.promo2 =  homepromo2 + homepromo2_link;
		flashvars.promo3 =  homepromo3 + homepromo3_link;
		
		var params = { wmode : "transparent" , allowscriptaccess : "always" };
		var attributes = { id : "flash-bool" };
		if(country != "it-it"){
			swfobject.embedSWF("smarty_files/templates/flash/build/BittyButtonsLoader.swf", "main", "2300", "1135", "9.0.0","expressInstall.swf", flashvars, params, attributes); 
		}
		else{
			swfobject.embedSWF("smarty_files/templates/flash/build/it-IT/BittyButtonsLoader.swf", "main", "2300", "1135", "9.0.0","expressInstall.swf", flashvars, params, attributes);  
		}
		
		

		$("#main").css({ "display" : "block"}); 
	
		setTimeout( function(){ $("#login_register-wrapper, .homepage-login, .homepage-p, .homepage-reg, #div-socialmedia").fadeIn("slow") } , 15000 );


		setTimeout( function(){

		if( document.getElementById("flash-bool") ){
		}
		else{
			$("#div-flash-detection").css({  "display" : "block" });
			$("#homepage-login-wrapper").css({  "display" : "none" });
			$("#img-facebook").css({  "display" : "none" });
		}

		} , 2000 );
	
	}


	else{

		$("#main").css({ "display" : "none" });
		 $("body").addClass("allpages");
		 var params = { wmode : "transparent" , allowscriptaccess : "always" };
		 var attributes = {};

		 var flashvars = { };
		 swfobject.embedSWF(menubar, "menu_bar", "1100", "300", "9.0.0","expressInstall.swf", flashvars, params, attributes);
		
		
		setTimeout( function(){	
		$("#allpages-register-wrapper").fadeIn("slow");} , 2000);
		
		$("#div-legal").fadeIn("slow");
		
		$("#allpage-interstitial").css("top" , "-86px");
		
	}

}

function openSecretCode(){
	if(obj.id){
	 		$("#home-secretcode-wrapper").css("display" , "block");
	}
	else{
		setCookie( "secretcode", "1" );
		$("#homepage-login").click();
	}
	
}

function saharaCode(){
	$("#sahara-code, #sahara-nick").click(function(){
		if(obj.id){
			$("#allpage-secretcode-wrapper").css("display" , "block");
		}else{
			setCookie( "secretcode", "1" );
			$("#allpage-login").click();
		}
	});
}

function secretCode(){
	
	if(getCookie("secretcode") != null && getCookie("secretcode") != "") {
		if(obj.id){
			setTimeout( function(){ $("#home-secretcode-wrapper,#allpage-secretcode-wrapper").fadeIn("slow"); } , 8000 );
			deleteCookie("secretcode");	
		}
	}
	$("#codeSubmit").click( function(){
		var girl = 0;
		var secret_code = $("#input-secret-code").val();

		$.post("?request=secretcode", { secret_code : secret_code , user_id : obj.id , girl:girl, website_id : website_id }, function( http ){
		       var s_return = eval( http );
		        if( s_return > 0 ){
			
					alert(bittyHash.language.registration.addSecretCode); 
					
					if(s_return > 87 && s_return < 25288){
						window.location = bittyHash.downloads.sahara.path;
					}else{
						$.get("?request=download&id=" + s_return , { id : s_return } , function( url ){							
							window.location = url;
						});
					}
				}
				else if( s_return == 0 ){
					alert("You have already registered this product.");
					if(s_return > 87 && s_return < 25288){
						window.location = bittyHash.downloads.sahara.path;
					}else{
						$.get("?request=download&id=" + s_return , { id : s_return } , function( url ){
							window.location = url;
						});
					}
				}
				else if( s_return < 0 ){
					alert(bittyHash.language.registration.check_secretcode);
				}
		});
		
	 $("#home-secretcode-wrapper").css("display" , "none");
	
	 });
	
	$("#code_close_btn").click(function(){
		$("#home-secretcode-wrapper, #allpage-secretcode-wrapper").css("display" , "none");
	});

}

/* Google Analytics */

function logValidation(){
	if(obj.id){
			$("#allpage-login").click( function(){
				
				$("#overlay-wrapper").css({ "display" : "block" , "width" : "2300px"}).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 500 , function(){
						//$("#logon-wrapper").css({"display" : "none"});
						$("#login-dialog-wrapper").css({"display" : "none"}).animate({ "opacity" : "1" , "height" : "408px" , "width" : "628px"} , 500 , function(){
							
							if( obj.acct_type == "parent" ){
								$("#myacct-header-left").html("Parent Console");
								$(".li-parent-email").css("display","none");
								$("#first_name").val(obj.first_name);
								$("#username").val(obj.username);
								$("#input-" + obj.gender ).attr("checked","checked");
								$("#email").val( obj.email );
								buildCountry();
								buildState();
								$("#myacct-postal_code").val( obj.postal_code );
							}
							
							else if( obj.acct_type == "child" ){
								$("#div-myacct-location,.li-child-email").css("display","none");
								$("#myacct-header-left").html("MyAccount");
								$(".li-parent-email").css("display","block");
								$("#first_name").val(obj.first_name);
								$("#username").val(obj.username);
								$("#parent-email-account").val(obj.parent_email);

								$("#input-" + obj.gender ).attr("checked","checked");
								$("#menu-mychildren, #menu-myactivities").css("display","none");

							}
							else if( obj.acct_type == "teen" ){
									$("#myacct-header-left").html("Parent Console");
									$(".li-parent-email").css("display","block");
									$("#first_name").val(obj.first_name);
									$("#username").val(obj.username);
									$("#input-" + obj.gender ).attr("checked","checked");
									$("#email").val( obj.email );
									buildCountry();
									buildState();
									$("#myacct-postal_code").val( obj.postal_code );
							}
							else{
								$("#myacct-header-left").html("My Account");
							}
						});//end function
				});//end function	
			} );//end function
				
		
			$("#homepage-logout").click( function(){ 
				$.post("?request=logout",function( ){
					window.location = "";
				});
			} );//end function
		
		
		
			$("#homepage-myacct").click( function(){
				$("#password").val("******");
				$("#password-confirm").val("");
				$("#overlay-wrapper").css({ "display" : "block" , "width" : "2300px"}).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 500 , function(){

					$("#logon-wrapper").css({"display" : "none"});
					$("#overlay-login,#login-dialog-wrapper,#div-myacct,#div-profile-wrapper,#login-ul-dialog-header,#div-all-info").css({"display" : "block","opacity" : "1"});

					$("#login-dialog-wrapper").css({"display" : "none"}).animate({ "opacity" : "1" , "height" : "408px" , "width" : "628px"} , 500 , function(){
						if( obj.acct_type == "parent" ){
								$("#myacct-header-left").html(bittyHash.language.myaccount.myacctheadertext);
								$(".li-parent-email").css("display","none");
								$("#first_name").val(obj.first_name);
								$("#last_name").val(obj.last_name);
								$("#username").val(obj.username);
								$("#input-" + obj.gender ).attr("checked","checked");
								$("#email-account").val( obj.email );
								buildCountry();
								buildState();
								$("#myacct-postal_code").val( obj.postal_code );
						}
						else if( obj.acct_type == "child" ){
								$("#div-myacct-location,.li-child-email").css("display","none");
								$("#myacct-header-left").html(bittyHash.language.myaccount.myacctheadertext);
								$(".li-parent-email").css("display","block");
								$("#first_name").val(obj.first_name);
								$("#last_name").val(obj.last_name);
								$("#username").val(obj.username);
								$("#parent-email-account").val(obj.parent_email);

								$("#input-" + obj.gender ).attr("checked","checked");
								$("#menu-mychildren, #menu-myactivities").css("display","none");

						}
						else if( obj.acct_type == "teen" ){
								$("#myacct-header-left").html(bittyHash.language.myaccount.myacctheadertext);
								$(".li-parent-email").css("display","block");
								$("#first_name").val(obj.first_name);
								$("#last_name").val(obj.last_name);
								$("#username").val(obj.username);
								$("#input-" + obj.gender ).attr("checked","checked");
								$("#email").val( obj.email );
								buildCountry();
								buildState();
								$("#myacct-postal_code").val( obj.postal_code );
						}
						else{
								$("#myacct-header-left").html(bittyHash.language.myaccount.myacctheadertext);
						}

						$(".disabled").attr("readonly",true);

                    	$(".menu-events").click(function(){
                                        $(".wrapper,.li-password-confirm").css("display" , "none");
                                        $("#div-"+this.id+"-wrapper,#div-myacct-menu").css({"display":"block","opacity":"1"});
										$(".disabled").attr("readonly",false);
										
                                        ( this.id == "profile") ? buildProfileSection() : $("#menu-edit,#div-all-info").css("display","none");
                                        ( this.id == "products") ? buildAllProducts() : null;
                                        ( this.id == "children") ? buildAllChildAccess() : null;
                                        ( this.id == "activities") ? buildAllActivities() : null;

                                        $("#menu-myprofile").removeClass('menu-active');
                                        $("#menu-myproducts").removeClass('menu-active');
                                        $("#menu-myscores").removeClass('menu-active');
                                        $("#menu-mychildren").removeClass('menu-active');
                                        $("#menu-myactivities").removeClass('menu-active');
                                        
                                        if(!$("#menu-my"+this.id).hasClass('menu-active')){
                                                $("#menu-my"+this.id).removeClass('menu-active');
                                                $("#menu-my"+this.id).addClass('menu-active');
                                        }
                                        
                                        if (this.id != "profile") {
											if(!$("#div-"+this.id+"-wrapper").hasClass('show wrapper')){
                                                $("#div-"+this.id+"-wrapper").removeClass('show wrapper');
                                                $("#div-"+this.id+"-wrapper").addClass('show wrapper');
                                       		}
										}                                        
                     	});//end function

                    	 $("#menu-enable-edit").click(function(){
                    	                if ( $(".disabled").attr("readonly") ) {
                                        	$(".disabled").attr("readonly", false);
                                        	$("#username,#email-account,#parent-email-account").attr("readonly", true);
											$(".li-password-confirm").css("display","block");
											passwordListener();
										} else {
											$(".disabled").attr("readonly", true);
                                        	$(".li-password-confirm").css("display","none");
										}
						});//end function

                		$("#update-save").click( function(){
                			getAllupdateElems();
						});

					});//end function

				});	//end function
			} );//end click function()
		}

	else{
		$("#allpage-login").click( function(){
			$("#overlay-wrapper").css({ "display" : "block" , "width" : "2300px"}).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 500 , function(){
				//$("#logon-wrapper").css({ "display" : "block" , "opacity" : "1"});
				$("#all-overlay-login").css({ "display" : "block" , "opacity" : "1"});
			});
		});
	}
	
}//end function


function loginRegEvent(){
	
	if(  $__( $( "#homepage-reg" ) ) ){
		var google_conversion_label = "toFGCJLy4AEQgIyC7wM";
			$("#google_conversion").html("<img src='http://www.googleadservices.com/pagead/conversion/1038124544/?label=toFGCJLy4AEQgIyC7wM&amp;guid=ON&amp;script=0' border='0' />");
	}
	
	if(  $__( $( "#allpage-reg" ) ) ){
		var google_conversion_label = "toFGCJLy4AEQgIyC7wM";
			$("#google_conversion").html("<img src='http://www.googleadservices.com/pagead/conversion/1038124544/?label=toFGCJLy4AEQgIyC7wM&amp;guid=ON&amp;script=0' border='0' />");
	}
	
	if (obj.id){
		$("#homepage-welcome").html("Welcome " + obj.first_name);
		$("#homepage-welcome").css("display","block");
		$("#homepage-logout, #allpage-logout").css("display","block");
		
		
		//$("#homepage-login").css("display","none");
		$("#homepage-reg, #allpage-reg").css("display","none");
		
		$("#homepage-logout , #allpage-logout").click( function(){ 
				$.post("?request=logout",function( ){
					window.location = base+"?section="+page+"&uriLang="+country;
				});
		} );
	}
	
	$("#homepage-myacct").click(function(){
		$("#overlay-wrapper").css({ "display" : "block", "width" : "2300px" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 500 , function(){
			$("#login-dialog-wrapper").css({ "display" : "block" , "opacity" : "1" });
		});	
	});

		$("#homepage-reg").click( function( ){ 
				$("#overlay-wrapper").css({ "display" : "block" , "width" : "2300px"}).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 500 , function(){
					$("#overlay-login").css("display" , "none");
					$("#dialog-date").val(bittyHash.language.registration.reg_yyyymmdd);
					$("#overlay-box").css({ "display" : "block" , "opacity" : "1" , "width" : "2300px" });
					$("#overlay-dialog").css({ "display" : "block" , "opacity" : "1" });
					regValidateObj.checkDate();
				 } );
		} );

		$("#homepage-login").click(function(){
			$("#overlay-wrapper").css({ "display" : "block", "width" : "2300px" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 500 , function(){
				$("#logon-wrapper").css({ "display" : "block" , "opacity" : "1" , "width" : "2300px" });
				$("#overlay-login").css({ "display" : "block" , "opacity" : "1" });
				$("#forgot-wrapper").css({ "display" : "none"  , "opacity" : "0" });
			});	
		});
		
		$("#allpage-login").click(function(){
			$("#overlay-wrapper").css({ "display" : "block", "width" : "2300px" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 500 , function(){
				//$("#logon-wrapper").css({ "display" : "block" , "opacity" : "1"});
				$("#all-overlay-login").css({ "display" : "block" , "opacity" : "1" , "width" : "100%"});
				$("#forgot-wrapper").css({ "display" : "none"  , "opacity" : "0" });
			});	
		});

		$("#a-logon-register").click( function(){
			$("#all-overlay-login").css("display","none");
			$("#homepage-reg").click();
			//$("#allpage-reg").click();
		});


		$("#btn-logon").click( function() {
			$.post("?request=login" , { username: jQuery.trim( $("#myacct-userid").val() ) , website_id : website_id , password: jQuery.trim( $("#myacct-password").val() ) } , function(http){
				var stringBool = eval( "(" + http + ")" );
				if( stringBool == "3" ){
            		alert(bittyHash.language.login.error1);
				}
            	else if( stringBool == "2" ){
            		alert("You do not have access to this account. Please check with your parent for approval.");
				}
            	else if( stringBool == "0" ){
            		window.location = base+"?section="+page+"&uriLang="+country;
				}
			});
		} );

		if( $__( $("#dialog-header") ) ){
                $(".btn-close, #update-cancel, #dialog-close, #login-a-dialog-close , #logon-header-close, #forgot-header-right, #forgot-password-close").click(function(){
                        $("#overlay-box,#overlay-login,#all-overlay-login").css({ "display" : "none" , "opacity" : "0" });
                        $("#overlay-wrapper").animate({ "opacity" : "0" , "height" : "0px" } , 500 , function(){ $( this ).css("display" , "none"); } );
                        $("#dialog-title").html(bittyHash.language.registration.reg_step1);

                        $("#dialog-content-2").css({ "display" : "none" });
                        $("#dialog-content").css({ "display" : "block" });
                        $("#overlay-dialog").css({ "width" : "385px" , "height" : "230px" });
                        $("#reg-save").attr("id","btn-next").html("Next");

                });
        	}

		$("#a-logon-forgot").click( function(){
			$("#forgot-wrapper").css({ "opacity" : "1" , "display" : "block" });
			$("#div-forgot").css({ "display" : "block" , "opacity" : "1" });
			$("#all-overlay-login").css({ "display" : "none" ,  "opacity" : "0"  });
		});
	
	
		$("#allpage-reg").click( function( ){ 
				$("#overlay-wrapper").css({ "display" : "block" , "width" : "2300px"}).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 500 , function(){
					$("#all-overlay-login").css("display" , "none");
					$("#dialog-date").val(bittyHash.language.registration.reg_yyyymmdd);
					$("#overlay-box").css({ "display" : "block" , "opacity" : "1" , "width" : "100%" });
					$("#overlay-dialog").css({ "display" : "block" , "opacity" : "1" });
					regValidateObj.checkDate();
				 } );
		} );//end click

		
		$("#allpage-login").click(function(){
			$("#overlay-wrapper").css({ "display" : "block", "width" : "2300px" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 500 , function(){
				$("#all-overlay-login").css({ "display" : "block" , "opacity" : "1"  });
				$("#overlay-login").css({ "display" : "block" , "opacity" : "1" , "width" : "100%"});
				$("#forgot-wrapper").css({ "display" : "none"  , "opacity" : "0" });
			
			
				$("#a-logon-forgot").click( function(){
					setTimeout( function(){
						$("#all-overlay-login").css({ "display" : "none" ,  "opacity" : "0"  });
						$("#forgot-wrapper").css({ "opacity" : "1" , "display" : "block" });
						$("#div-forgot").css({ "display" : "block" , "opacity" : "1" });						
					} , 500 );	
				});
			
				$("#a-logon-register").click( function(){
					$("#all-overlay-login").css("display","none");
					$("#allpage-reg").click();
				});


				/* My Account Codes */
				$(".disabled").attr("disabled",true);
		
				$(".menu-events").click(function(){
					$(".wrapper").css("display" , "none");
					$("#div-"+this.id+"-wrapper").css("display" , "block");
					$(".disabled").attr("disabled",true);
					( this.id == "profile")? $("#menu-edit").css("display","block") : $("#menu-edit").css("display","none"); 
					( this.id == "products")? buildAllProducts() : null;
					( this.id == "children")? buildAllChildAccess() : null;
		
					if(!$("#menu-my"+this.id).hasClass('menu-active')){
						$("#menu-my"+this.id).removeClass('menu-active');
						$("#menu-my"+this.id).addClass('menu-active');
					}
				});

				$("#menu-enable-edit").click(function(){
					$(".disabled").attr("disabled", false);
					$("#username").attr("disabled", true);
				 });

				$("#update-save").click( function(){
					getAllupdateElems();
				});
			});	
		});

		$("#myacct-userid, #myacct-password").keypress( function(event) {
				if (event.keyCode == '13') {$("#btn-logon").click();}
		});

		$("#btn-logon").click( function() {
			$.post("?request=login" , { username: jQuery.trim( $("#myacct-userid").val() ) , website_id : website_id , password: jQuery.trim( $("#myacct-password").val() ) } , function(http){
				var stringBool = eval( "(" + http + ")" );
				if( stringBool == "3" ){
					alert(bittyHash.language.login.error1);
				}
				else if( stringBool == "2" ){
					alert("You do not have access to this account. Please check with your parent for approval.");
				}
				else if( stringBool == "0" ){
					window.location = base+"?section="+page+"&uriLang="+country;
				}
			});
		} );//end click

		if( $__( $("#dialog-header") ) ){
			$("#dialog-close, #login-li-dialog-close , #logon-header-close, #forgot-header-right").click(function(){
                        $("#overlay-box,#overlay-login").css({ "display" : "none" , "opacity" : "0" });
                        $("#overlay-wrapper").animate({ "opacity" : "0" , "height" : "0px" } , 500 , function(){ $( this ).css("display" , "none"); } );
                        //$("#dialog-title").html(bittyHash.language.registration.reg_step1);

                        $("#dialog-content-2").css({ "display" : "none" });
                        $("#dialog-content").css({ "display" : "block" });
                        $("#overlay-dialog").css({ "width" : "385px" , "height" : "230px" });
                        $("#reg-save").attr("id","btn-next").html("Next");
			});
		
	}
	else if( $__( $( "#allpage-reg" ) ) ){
		$("#allpage-reg").click( function( ){ 
			var width = window.innerWidth/2;
			var cwidth = (width)-(385/2)
				$("#overlay-wrapper").css({ "display" : "block", "width" : "2300px" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 500 , function(){
					$("#all-overlay-login").cs("display" , "none");
					$("#overlay-box").css({ "display" : "block" , "opacity" : "1"});
					$("#overlay-dialog").css({ "display" : "block" , "opacity" : "1", "left" : cwidth+"px"});
				 } );
		} );
	
	}

	if( $__( $("#logon-header-close") ) ){
		$("#logon-header-close,#dialog-close").click(function(){
			
			$("#overlay-wrapper,#overlay-login,#overlay-dialog,#overlay-box").animate({ "opacity" : "0" }
			 , function(){ 
				setTimeout( function(){ $("#overlay-wrapper,#overlay-login,#all-overlay-login,#overlay-dialog,#overlay-box").css({ "display" : "none" }); 
				} , 1 );
				centerPage();
			});
		});
	}


	  if( $__( $("#forgot-submit") ) ){
                $("#forgot-submit").click(function(){
                        var first_name = $("#input-forgot-firstname").val();
                        var input_value = $("#input-forgot-email").val();
                        var radio_type = null;
                            $(".radio-forgot-password").each( function( i , val ){ if( $( this ).attr("checked") ){ radio_type = this.value; } });
                            $.post("?request=forgotpasswordbyusername", { first_name : first_name , input_value : input_value , radio_type : radio_type } , function( http ){
                                        if( http == 0 ){
                                                alert("We couldn't locate this account.");
                                        }
                                        else if( http == 1 ){
                                                alert("Your account information has been emailed to the address your parent used to register on Moxieteenz.com.");
                                        }
                                        else if( http == 2 ){
                                                alert("Your account information has been emailed to the address you used to register on Moxieteenz.com");
                                        }

                            });

                });
        }


}


var regValidateObj = { 
	json_send : { } ,
	badwords : null ,
	checkDate : function(){
		$("#btn-next").click( function(){ 
				if($("#dialog-date").val() != bittyHash.language.registration.reg_yyyymmdd ){
					if( regValidateObj.badwords != null ){
					regValidateObj.getAccount_type( $("#dialog-date").val() );
					//regValidateObj.hideElem();
					regValidateObj.expandBuilt();
					$("#dialog-calendar").css("display","none");
					}
					else{
					$.post("?request=loadbadwords",{},function( http ){ regValidateObj.badwords = eval( "(" + http + ")" ); });
					regValidateObj.getAccount_type( $("#dialog-date").val() );
					regValidateObj.hideElem();
					regValidateObj.expandBuilt();
					$("#dialog-calendar").css("display","none");
					}
				}
				else{
					alert(bittyHash.language.registration.error_choose_bday);
				}
		});

        }
	, 

	getAccount_type: function( dob ){
		var expl =  dob.split("-");	
		var d = new Date();
		var age = ( d.getFullYear() - expl[0] );

		if( age > 17 ){
			regValidateObj.json_send.acct_type = "parent";
		}
		else if( age <= 17 && age > 12 ){
			regValidateObj.json_send.acct_type = "teen";
		 }
		else{
			regValidateObj.json_send.acct_type = "child";
		}

	}
	,
	hideElem : function(){ 
			if( regValidateObj.json_send.acct_type == "child" ){
				$("#newsletter-optins,#user-location,.li-child-email").css("display","none");
				$("#newsletter-optins").css("top" , "-65px");
			}
			else if( regValidateObj.json_send.acct_type == "parent" ){
				$(".li-parent-email").css("display","none");
				$("#newsletter-optins").css("top" , "-65px");
				regValidateObj.countrybuild();
			}
			else{ 
				
				regValidateObj.countrybuild();
			}
	}
	,
	expandBuilt : function(){
		$("#dialog-content , #btn-next").css("display" , "none");
			$("#overlay-dialog").animate({ "width" : "705px" , "height" : "335px" } , 2000 , function(){
				$("#dialog-content-2").css({"display" : "block" , "height" : "250px" });
				$("#btn-next").css("display" , "block").attr("id","reg-save").html(bittyHash.language.registration.reg_submit);
				$("#dialog-title").html(bittyHash.language.registration.reg_step2);
				regValidateObj.allElems();
		} );
        }
	,
	allElems : function(){
		$("#reg-save").click( function( evt ){
				evt.stopImmediatePropagation();

				if( regValidateObj.json_send.acct_type == "parent" ){
					regValidateObj.parentAcct();
				}
				else if( regValidateObj.json_send.acct_type == "teen" ){
					regValidateObj.teenAcct();
				}
				else{
					regValidateObj.childAcct();
				}

		})
	}
	,
	countrybuild : function(){ 
	var obj = bittyHash.countryList;
        var stringCountry = "<option id=\"0\" value=\"Select One\">" + bittyHash.language.registration.reg_selectone + "</option>";
        for( x in obj ){
                stringCountry += "<option id=\""+ obj[x]["country_id"] +"\" value=\""+ obj[x]["country_id"] +"\" >"+ obj[x]["local_name"] + "</option>";
        }

        $("#reg-signup-country").html( stringCountry ).change( function(){
                        getBuildState2( this.options[ this.selectedIndex ].id );
         });

	}
	,
	elem : function( obj ){

	} 
	,
	parentAcct : function(){
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		var arr = new Array();
		var json_send = {};

		if( $("#reg-signup-first_name").val() == "" ){
			$("#reg-signup-first_name").css("border","1px solid red");	
			arr[0] = false;
		}
		else{
			$("#reg-signup-first_name").css("border","1px solid #CFCFCF");	
			json_send.first_name = "first_name," +  $("#reg-signup-first_name").val(); 
		}

		if( $("#reg-signup-username") ){
			if( $("#reg-signup-username").val() == "" ){
					$("#reg-signup-username").css("border","1px solid red");	
					arr[1] = false;
			}
			else {
				var arr_bad = regValidateObj.badwords;
			for( x in arr_bad ){
				if( arr_bad[x]  == $("#reg-signup-username").val() ){ 
					$("#reg-signup-username").css("border","1px solid red");	
					arr[1] = false;
					break;
				}		
				else{
					$("#reg-signup-username").css("border","1px solid #CFCFCF");	
				}
			} 

			( arr[1] == false ) ? null : json_send.username = "username," + $("#reg-signup-username").val();

			}
		}

		if( $("#reg-signup-password").val() == "" ){
			$("#reg-signup-password").css("border","1px solid red");	
			arr[2] = false;
		}
		else{
			$("#reg-signup-password").css("border","1px solid #CFCFCF");	
			json_send.password = "password," +  $("#reg-signup-password").val(); 
		}

		if( filter.test( $("#reg-signup-email").val() ) ){
			$("#reg-signup-email").css("border","1px solid #CFCFCF");	
			json_send.email = "email," +  $("#reg-signup-email").val(); 
		}
		else{
			$("#reg-signup-email").css("border","1px solid red");	
			arr[3] = false;
		}

		if( $("#reg-signup-country").val() != bittyHash.language.registration.reg_selectone){
			$("#reg-signup-country").css("border","1px solid #CFCFCF");	
			json_send.country = "country_id," +  $("#reg-signup-country").val(); 
		}
		else{
			$("#reg-signup-country").css("border","1px solid red");	
			arr[4] = false;
		}

		if( $("#reg-signup-state").val() != bittyHash.language.registration.reg_selectone){
			$("#reg-signup-state").css("border","1px solid #CFCFCF");	
			json_send.state = "state_id," +  $("#reg-signup-state").val(); 
		}
		else{
			$("#reg-signup-state").css("border","1px solid red");	
			arr[5] = false;
		}

		if( $("#reg-signup-zip").val() != "" ){
			$("#reg-signup-zip").css("border","1px solid #CFCFCF");	
			json_send.zip = "postal_code," +  $("#reg-signup-zip").val(); 
		 }
		else{
			$("#reg-signup-zip").css("border","1px solid red");	
			arr[6] = false;
		 }

		if( $("#reg-signup-last_name").val() == "" ){
			$("#reg-signup-last_name").css("border","1px solid red");	
			arr[7] = false;
		}

		else{
			$("#reg-signup-last_name").css("border","1px solid #CFCFCF");	
			json_send.last_name = "last_name," +  $("#reg-signup-last_name").val(); 
		}
		
		json_send.parent_email = "parent_email," + $("#reg-signup-email").val(); 
		json_send.gender = ( $("#reg-signup-f").attr("checked") )? "gender,f" : "gender,m";
		json_send.acct_type = "acct_type,parent";
		json_send.option_1 = ( $("#option_1").attr("checked") == true )? "optins_1,brands,1" : "optins_1,brands,0";
		json_send.option_2 = ( $("#option_2").attr("checked") == true )? "optins_2,other_brands,1" : "optins_2,other_brands,0";
		json_send.option_3 = "optins_3,website_id,2";
		json_send.option_4 = "optins_4,email_my_child,1";

		if( arr.length == 0 ){
			$.post("?request=register", json_send , function( http ){
				if( http != "" ){
					var returnObj = eval( "(" + http  + ")" );
					if( returnObj["error"] ){
						//alert( returnObj["error"] );						
						alert(bittyHash.language.registration[ "errorcode" + returnObj["error"] ]);
					}
					else{ 
						$("#dialog-content-2,#dialog-parent-wrapper").css({ "display" : "none", "opacity" : "0" });
                                                $("#overlay-dialog,dialog-reg-complete").css({ "display" : "block" , "opacity" : "1" });
						$("#overlay-dialog").css({ "background" : "none" , "border" : "none" });
						$("#dialog-header,#dialog-content-2,#dialog-bottom").css("display", "none");
						$("#dialog-reg-complete").css("display","block","background-color","#CFCFCF");
						
						$("#span-reg-complete-username").html(bittyHash.language.registration.reg_complete_user + $("#reg-signup-username").val() );
                        $("#span-reg-complete-password").html(bittyHash.language.registration.reg_complete_password + $("#reg-signup-password").val() );

						$("#complete-btn-close,#reg-complete-close").click( function(){
							window.location = "";
						 });
					}

				}
			});
		}	

	}
	,
	teenAcct : function(){
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		var arr = new Array();
		var json_send = {};

		if( $("#reg-signup-first_name").val() == "" ){
			$("#reg-signup-first_name").css("border","1px solid red");	
			arr[0] = false;
		}
		else{
			$("#reg-signup-first_name").css("border","1px solid #CFCFCF");	
			json_send.first_name = "first_name," +  $("#reg-signup-first_name").val(); 
		}

		if( $("#reg-signup-username") ){
			if( $("#reg-signup-username").val() == "" ){
					$("#reg-signup-username").css("border","1px solid red");	
					arr[1] = false;
			}
			else {
				var arr_bad = regValidateObj.badwords;
			for( x in arr_bad ){
				if( arr_bad[x]  == $("#reg-signup-username").val() ){ 
					$("#reg-signup-username").css("border","1px solid red");	
					arr[1] = false;
					break;
				}		
				else{
					$("#reg-signup-username").css("border","1px solid #CFCFCF");	
				}
			} 

			( arr[1] == false ) ? null : json_send.username = "username," + $("#reg-signup-username").val();

			}
		}

		if( $("#reg-signup-password").val() == "" ){
			$("#reg-signup-password").css("border","1px solid red");	
			arr[2] = false;
		}
		else{
			$("#reg-signup-password").css("border","1px solid #CFCFCF");	
			json_send.password = "password," +  $("#reg-signup-password").val(); 
		}

		if( filter.test( $("#reg-signup-parent_email").val() ) ){
			$("#reg-signup-parent_email").css("border","1px solid #CFCFCF");	
			json_send.parent_email = "parent_email," +  $("#reg-signup-parent_email").val(); 
		}
		else{
			$("#reg-signup-parent_email").css("border","1px solid red");	
			arr[3] = false;
		}

		if( filter.test( $("#reg-signup-email").val() ) ){
			$("#reg-signup-email").css("border","1px solid #CFCFCF");	
			json_send.email = "email," +  $("#reg-signup-email").val(); 
		}
		else{
			$("#reg-signup-email").css("border","1px solid red");	
			arr[4] = false;
		}

		if( $("#reg-signup-country").val() != bittyHash.language.registration.reg_selectone){
			$("#reg-signup-country").css("border","1px solid #CFCFCF");	
			json_send.country = "country_id," +  $("#reg-signup-country").val(); 
		}
		else{
			$("#reg-signup-country").css("border","1px solid red");	
			arr[5] = false;
		}

		if( $("#reg-signup-state").val() != bittyHash.language.registration.reg_selectone){
			$("#reg-signup-state").css("border","1px solid #CFCFCF");	
			json_send.state = "state_id," +  $("#reg-signup-state").val(); 
		}
		else{
			$("#reg-signup-state").css("border","1px solid red");	
			arr[6] = false;
		}

		if( $("#reg-signup-zip").val() != "" ){
			$("#reg-signup-zip").css("border","1px solid #CFCFCF");	
			json_send.zip = "postal_code," +  $("#reg-signup-zip").val(); 
		 }
		else{
			$("#reg-signup-zip").css("border","1px solid red");	
			arr[7] = false;
		 }
		
		if( $("#reg-signup-last_name").val() == "" ){
			$("#reg-signup-last_name").css("border","1px solid red");	
			arr[8] = false;
		}
		else{
			$("#reg-signup-last_name").css("border","1px solid #CFCFCF");	
			json_send.last_name = "last_name," +  $("#reg-signup-last_name").val(); 
		}

		json_send.gender = ( $("#reg-signup-f").attr("checked") )? "gender,f" : "gender,m";
		json_send.acct_type = "acct_type,teen";
		json_send.option_1 = ( $("#option_1").attr("checked") == true )? "optins_1,brands,1" : "optins_1,brands,0";
		json_send.option_2 = ( $("#option_2").attr("checked") == true )? "optins_2,other_brands,1" : "optins_2,other_brands,0";
		json_send.option_3 = "optins_1,website_id,2";

		if( arr.length == 0 ){
			if( jQuery.trim( $("#reg-signup-email").val() ) == jQuery.trim( $("#reg-signup-parent_email").val() ) ){
				alert(bittyHash.language.registration.sameemail);
			 }
			else{
			$.post("?request=register", json_send , function( http ){
				if( http != "" ){
					var returnObj = eval( "(" + http  + ")" );
					if( returnObj["error"] ){
						//alert( returnObj["error"] );						
						alert(bittyHash.language.registration[ "errorcode" + returnObj["error"] ]);
					}
					 else{     
						$("#dialog-content-2,#dialog-parent-wrapper").css({ "display" : "none", "opacity" : "0" });
                                                $("#overlay-dialog,dialog-reg-complete").css({ "display" : "block" , "opacity" : "1" });
                                                $("#dialog-header,#dialog-content-2,#dialog-bottom").css("display", "none");
						$("#overlay-dialog").css({ "background" : "none" , "border" : "none" });
						$("#dialog-reg-complete").css("display","block","background-color","#CFCFCF");

						$("#span-reg-complete-username").html(bittyHash.language.registration.reg_complete_user + $("#reg-signup-username").val() );
                                                $("#span-reg-complete-password").html(bittyHash.language.registration.reg_complete_password + $("#reg-signup-password").val() );

                                                $("#complete-btn-close,#reg-complete-close").click( function(){ 
                                                        window.location = "";
                                                 });


                                        }


				}
			});
			}
		}	
	 }
	,
	childAcct : function(){
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		var arr = new Array();
		var json_send = {};

		if( $("#reg-signup-first_name").val() == "" ){
			$("#reg-signup-first_name").css("border","1px solid red");	
			arr[0] = false;
		}
		else{
			$("#reg-signup-first_name").css("border","1px solid #CFCFCF");	
			json_send.first_name = "first_name," +  $("#reg-signup-first_name").val(); 
		}

		if( $("#reg-signup-username") ){
			if( $("#reg-signup-username").val() == "" ){
					$("#reg-signup-username").css("border","1px solid red");	
					arr[1] = false;
			}
			else {
			var arr_bad = regValidateObj.badwords;
			for( x in arr_bad ){
				if( arr_bad[x]  == $("#reg-signup-username").val() ){ 
					$("#reg-signup-username").css("border","1px solid red");	
					arr[1] = false;
					break;
				}		
				else{
					$("#reg-signup-username").css("border","1px solid #CFCFCF");	
				}
			} 

			( arr[1] == false ) ? null : json_send.username = "username," + $("#reg-signup-username").val();

			}
		}

		if( $("#reg-signup-password").val() == "" ){
			$("#reg-signup-password").css("border","1px solid red");	
			arr[2] = false;
		}
		else{
			$("#reg-signup-password").css("border","1px solid #CFCFCF");	
			json_send.password = "password," +  $("#reg-signup-password").val(); 
		}

		if( filter.test( $("#reg-signup-parent_email").val() ) ){
			$("#reg-signup-parent_email").css("border","1px solid #CFCFCF");	
			json_send.parent_email = "parent_email," +  $("#reg-signup-parent_email").val(); 
		}
		else{
			$("#reg-signup-parent_email").css("border","1px solid red");	
			arr[3] = false;
		}

		if( $("#reg-signup-last_name").val() == "" ){
			$("#reg-signup-last_name").css("border","1px solid red");	
			arr[4] = false;
		}

		else{
			$("#reg-signup-last_name").css("border","1px solid #CFCFCF");	
			json_send.last_name = "last_name," +  $("#reg-signup-last_name").val(); 
		}

		json_send.acct_type = "acct_type,child";
		json_send.gender = ( $("#reg-signup-f").attr("checked") )? "gender,f" : "gender,m";


		if( arr.length == 0 ){
			$.post("?request=register", json_send , function( http ){
				if( http != "" ){
					var returnObj = eval( "(" + http  + ")" );
					if( returnObj["error"] ){
						//alert( returnObj["error"] );						
						alert(bittyHash.language.registration[ "errorcode" + returnObj["error"] ]);
					}
					 else{     
						$("#dialog-content-2,#dialog-parent-wrapper").css({ "display" : "none", "opacity" : "0" });
                                                $("#overlay-dialog,dialog-reg-complete").css({ "display" : "block" , "opacity" : "1" });
                                                $("#dialog-header,#dialog-content-2,#dialog-bottom").css("display", "none");
						$("#overlay-dialog").css({ "background" : "none" , "border" : "none" });
						$("#dialog-reg-complete").css("display","block","background-color","#CFCFCF");



						$("#span-reg-complete-username").html(bittyHash.language.registration.reg_complete_user + $("#reg-signup-username").val() );
                                                $("#span-reg-complete-password").html(bittyHash.language.registration.reg_complete_password + $("#reg-signup-password").val() );

                                                $("#complete-btn-close,#reg-complete-close").click( function(){ 
                                                        window.location = "";
                                                 });

                                        }

				}
			});
		}	
	
	}

}

function showDiv(pass){
		 if (document.getElementById(pass)) { 
		 var obj = document.getElementById(pass); 
		 obj.style.display = (obj.style.display=='block')?'none':'block'; 
		 } 
		 return false; 

}

function checkBioPages(){
	if( $__( $( "#div-bio-copy" ) ) ){
		currentGirl = currentGirl.toLowerCase();
			$("#div-bio-copy").html( bittyHash.girls[currentGirl].bio );
	}
}

function resizeListener(){
	window.onresize = function(){
		setTimeout( function(){ centerPage(); }, 500);
	}
}

function  GoogleListener(){
	//	objGoogleAEventAttach[ page ]();			
}

function enableCalendar(){


                $("#calendar").click( function(){
	
						$("#dialog-calendar").css("display" , "block");
                        $("#dialog-calendar").datepicker( {
                                                 onSelect: function(dateText, inst) { $("#dialog-date").val(dateText); $( "#dialog-calendar" ).datepicker( "destroy" ); },
                                                 changeMonth: true ,
                                                 changeYear: true ,
                                                 yearRange: "1900:2011" ,
                                                 dateFormat : "yy-mm-dd"
	                  } );
	
					
		} );
		
	

}

var objGoogleAEventAttach = {

	promos : function(){
	},

	downloads : function(){

			$(".google-a-icon").click( function(){ } );
			$(".google-a-wallpaper").click( function(){ } );
			$(".google-a-screensaver").click( function(){ } );
	},

	bittymeet : function(){ 

		if( page == "meet" ){
			objCallEventTracker( new Object() , 4 );	
		}

	},

	blogs : function(){ 

	},

	catalog : function(){ 

	},

	wishlist : function(){ 

	}

}

function objCallEventTracker( obj , id ){
	alert( obj );
	alert( id );
}

function googleEventTracker( action , label ){
	return pageTracker._trackEvent( "1" , action , label );	
}

/* My Account Codes */
function buildProfileSection(){
	$("#menu-edit,#div-all-info").css("display","block");
	$(".disabled").attr("readonly",true);
}

function buildAllChildAccess(){
	$("#div-mychildren").html("");
	$.post("?request=mychildaccess" , { parent_email_id : obj.parent_email_id } , function( http ){ 
			if( http != "false" ){
			var json_arr = eval("(" + http + ")");
			for( x in json_arr ){
				childLoop( json_arr[x] );
			}
			}
			else{
				$("#div-mychildren").html("You don't have any kids registered.");
			}

	});
} 

function buildAllActivities(){
	var stringHtml = "";
	$.post("?request=mykidactivities" , { parent_email_id : obj.parent_email_id } , function( http ){
			var json_arr = eval("(" + http + ")");
			var name = bittyHash.language.myaccount.name;
			var productsregistered = bittyHash.language.myaccount.productsregistered;
			
			for( x in json_arr ){
				if( json_arr[x]["userInfo"] ){
					stringHtml += "<ul id=\"ul-activities-name\">"
					stringHtml += "<li class=\"li-activities\" ><span>" + name + "</span><input type=\"text\" id=\"activities-name\" value=\""+ json_arr[x]["userInfo"]["first_name"]  +"\"></li>";
					stringHtml += "<li class=\"li-activities\"><span>" + productsregistered + "</span><input class=\"input-activities\" value=\"" + kidsLoop( json_arr[x] , x ) + "\"></li>";
					stringHtml +="</ul>";
				}
			}
		$("#div-activities").html( stringHtml );
	 });
}

function kidsLoop( obj_arr , i  ){
	var stringProducts = "";
	for( x in obj_arr ){
		if( obj_arr[x]["product_name"] ){
			stringProducts += obj_arr[x]["product_name"];
			if( obj_arr.length - 1 != x  ){
				stringProducts += ", ";
			} 
		}
	}
	return stringProducts = stringProducts.substr( 0 , stringProducts.length - 2 );
}

function childLoop( obj_arr ){
        var ulInfoString = "";
        var finalString = "";
        var id = bittyHash.language.myaccount.id;
        var name = bittyHash.language.myaccount.name;
        var password = bittyHash.language.myaccount.myacct_password;
		var email = bittyHash.language.myaccount.email;
		var save = bittyHash.language.myaccount.save;
		var cancel = bittyHash.language.myaccount.cancel;
		var pmychildren = bittyHash.language.myaccount.pmychildren;
		
        for( x in obj_arr ){
                if( !obj_arr[x]["user_access_id"] ){
                        /*upper part*/
                        ulInfoString += "<ul id=\"ul-mychildren-info\"><li class=\"li-children\"><div><span>" + name + "</span><input type=\"text\" class=\"input user_id"+obj_arr[x]["user_id"] +"\" id=\"mychildren-id\" value=\""+ obj_arr[x]["first_name"] +"\" name=\"first_name\"></div></li>";
                        ulInfoString += "<li class=\"li-children\"><div><span>" + id + "</span><input type=\"text\" class=\"input\" id=\"mychildren-id\" value=\""+ obj_arr[x]["user_id"] +"\" disabled></div></li>";
                        ulInfoString += "<li class=\"li-children\"><div><span>" + password + "</span><input type=\"text\" class=\"input user_id"+ obj_arr[x]["user_id"] +"\" id=\"mychildren-password\" name=\"password\" /></div></li>";
                        if( obj_arr[x]["email"] ){
                        ulInfoString += "<li class=\"li-children\"><div><span>" + email + "</span><input type=\"text\" class=\"input user_id"+ obj_arr[x]["user_id"] +"\" id=\"mychildren-email\" value=\"" + obj_arr[x]["email"] + "\" name=\"email\" /></div></li></ul>";
                        }
                }

        }
        var global_id = null;
        var string1 = "<ul id=\"ul-mychildren-info\" class=\"clear\">";
        string1 += "<p id=\"p-mychildren\" class=\"clear\">" + pmychildren + "</p>";
        for( x in obj_arr ){
                if( obj_arr[x]["user_access_id"] ){
                        global_id = obj_arr[x]["user_id"];
                        string1 += continueLoop( obj_arr[x] );
                }
        }
        string1 += "<li class=\"li-button-save\"><button id=\""+ global_id +"\" onclick=\"mychildsave( this )\">" + save + "</button><button>" + cancel + "</button></li>";
        string1 += "</ul>";
        finalString += ulInfoString;
        finalString += string1;
        $("#div-mychildren").html( $("#div-mychildren").html() + finalString );

}

function continueLoop( arr ){
                var strInfoString = "";
                return strInfoString += "<li class=\"li-children\"><span>"+ arr["website_domain"]  +":</span><input type=\"checkbox\" "+ checkedState( arr )+" class=\"user_id"+ arr["user_id"] +"\" name=\""+ arr["user_access_id"]+"\" /></li>";
}

function checkedState(arr){
        if( arr["access_bool"] == "1" ){
                return "checked=\"checked\"";
        }
}


function mychildsave( obj ){
      var json_send = {};
      $(".user_id" + obj.id ).each(function( i , val ){
                 if( $(this).is('input:checkbox') ){
                                json_send[ "website_" + $( this ).attr("name") ] = $( this ).attr("name") + "," + checkboxstatus( $( this ).attr("checked") );
                }
                 else{
                        if( $( this ).val()  != "" ){
                                 json_send[ $( this ).attr("name") ] = $( this ).attr("name") + "," + $( this ).val();
                       }
                 }
         });
 
        json_send.user_id = "user_id," + obj.id;

         $.post("?request=childrenupdate" , json_send , function(){

          } );
 }


function checkboxstatus( val ){
         if( val == "true" || val == true ){
                 return "1";
         }
         else{
                 return "0";
         }
}

function buildAllProducts(){
	var json_arr;

	var website_obj = { "1" : ["nara_icon_logo_v2.png", "160px"] , "2" : ["bitty_icon_logo_v2.png", "160px"] , "3" : ["bratz_icon_logo_v2.png","110px"] , "4" : ["moxieteenz_icon_logo_v2.png", "110px"] }

	$.post("?request=myproducts" , { id : obj.id } , function( http ){ 
		
		if( http ){
			json_arr = eval("(" + http + ")");	
			var sku = "";
			for( x in json_arr ){
				if( json_arr[x]["website_id"] == website_id ){
			
					if( json_arr[x]["sku"] != "undefined" || json_arr[x]["sku"] != undefined ){
						sku += "<li class=\"li-products\" >";
						sku += "<img class=\"div-product-image\" src=\"http://c2154692.cdn.cloudfiles.rackspacecloud.com/" + json_arr[x]["product_key"] + ".png\" />";
						sku += "<span>" + json_arr[x]["product_name"]  + "</span>";
						sku += "</li>";
					}
				}
			}
			
			$("#ul-products").html( sku );
			$("#product-website").css( { "width" : website_obj[website_id][1] , "background-image" : "url(http://c2154692.cdn.cloudfiles.rackspacecloud.com/"+ website_obj[ website_id ][0]  +")" } );
		
		}
		else{
			$("#ul-products").html( "You currently don't any items registered." );
		}
	});

	$("#sort-by-website").change( function(){
		var sku = "";
		for( x in json_arr ){
                                if( json_arr[x]["website_id"] == this.value ){
                                        if( json_arr[x]["sku"] != "undefined" || json_arr[x]["sku"] != undefined ){
						sku += "<li class=\"li-products\" >";
                                                sku += "<img class=\"div-product-image\" src=\"http://c2154692.cdn.cloudfiles.rackspacecloud.com/" + json_arr[x]["product_key"] + ".png\" />";
                                                sku += "<span>" + json_arr[x]["product_name"]  + "</span>";
                                                sku += "</li>";

                                        }

                                }
               }
		$("#ul-products").html( sku );
		$("#product-website").css( { "width" : website_obj[this.value][1] , "background-image" : "url(http://c2154692.cdn.cloudfiles.rackspacecloud.com/"+ website_obj[this.value][0]  +")" } );
	});
}

function getAllupdateElems(){
	var obj_ = { };
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;

	if( $("#first_name").val().length >= 2 ){
		obj_.first_name = "first_name," + $("#first_name").val();
		$("#first_name").css("border","1px solid #AFAFAF");	
	}
	else{
		$("#first_name").css("border","1px solid red");	
	}

	if( $("#last_name").val().length >= 2 ){
		obj_.last_name = "last_name," + $("#last_name").val();
		$("#last_name").css("border","1px solid #AFAFAF");	
	}
	else{
		$("#last_name").css("border","1px solid red");	
	}

	if( $("#password").val() != "" || $("#password").val() != "******" ){
		if( $("#password-confirm").val() != $("#password").val() ){
			$("#password-match").html("Your password doesn't match.");
		}
		else{
			$("#password-match").html("");
			obj_.password = "password," + $("#password").val();
		}
	}

	if( filter.test( $("#email").val() ) ){
		obj_.email = "email," + $("#email").val();
	 }

	if( $("#myacct-postal_code").val().length > 4 ){
		obj_.postal_code = "postal_code," + $("#myacct-postal_code").val();
		$("#myacct-postal_code").css("border","1px solid #AFAFAF");	
	}
	else{
		$("#myacct-postal_code").css("border","1px solid red");	
	}


	obj_.country_id = "country_id," + $("#choose-country option:selected").attr("id");
	obj_.state_id = "state_id," + $("#choose-state option:selected").attr("id");
	obj_.gender = ( $("#input-f").attr("checked") )? "gender,f" : "gender,m";
	obj_.user_id = "user_id," + obj.id ;

	$.post("?request=regupdate" , obj_ , function( http ){ });


}

function buildCountry(){
	var obj = bittyHash.countryList;
	var stringCountry = "";
	for( x in obj ){
		stringCountry += "<option id=\""+ obj[x]["country_id"] +"\" " + selectCountry( obj[x]["country_id"] ) + ">"+ obj[x]["local_name"] + "</option>";
	}
	$("#choose-country").html( stringCountry ).change( function(){
			getBuildState( this.options[ this.selectedIndex ].id );
	 });	
}

function selectCountry( current_id ){
	if( current_id == obj.country_id ){
		return "selected=\"selected\"";
	}
}

function getBuildState( id ){
	var state = bittyHash.stateList[ id ];
	var stringState = "";
	for( x in state ){
		stringState += "<option id=\""+ state[x]["state_id"] +"\">" + state[x]["local_name"] + "</option>";
	}
	$("#choose-state").html( stringState );	
}

function getBuildState2( id ){
	var state = bittyHash.stateList[ id ];
	
	var stringState = "<option id=\"0\">"+bittyHash.language.registration.reg_selectone+"</option>";
	for( x in state ){
		stringState += "<option value=\""+ state[x]["state_id"] +"\">" + state[x]["local_name"] + "</option>";
	}
	$("#reg-signup-state").html( stringState );	
}

function buildState(){
	var state = bittyHash.stateList[ obj.country_id ];
	var stringState = "";
	for( x in state ){
		stringState += "<option id=\""+ state[x]["state_id"] +"\" "+ selectState( state[x]["state_id"] ) +" >" + state[x]["local_name"] + "</option>";
	}
	$("#choose-state").html( stringState );	
}

function selectState( current_id ){
	if( current_id == obj.state_id ){
		return "selected=\"selected\"";
	}
	else{
		return "";
	}
}

function passwordListener(){
	$("#password").click( function(){ 
		if( this.value == "******" ){
			this.value = "";
		}
	}).blur( function(){ 
		if( this.value == "" ){
			this.value = "******";
		}
	});
}






