/* end of Main functions */
$( document ).ready( function(){
		setTimeout( function(){ $("#getflash").css("display","block");  } , 90 );
		homeRotator(); 
		logValidation();
		loginRegEvent();
		checkBioPages();
		//GoogleListener();
		enableCalendar();
		checkFlashContent();
		activeMenu();
		secretCode();
		scrollingGames();
		scrollingCatalog();
		redirect();
		homePromos();
		interstitial();
		musicPlayer();
		//$( document ).pngFix();
		//loginTabs();
		googleConListen();

});


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

var davePngFix = ( function( ){ 
		if( $.browser.msie == true && $.browser.version == "6.0" || $.browser.version == "7.0" ){
			$('.imgfix').css("visibility","hidden");
			var stringElem = "";
			$('.imgfix').each( function( i , val ){ 
				var img_url =  $( this ).attr("src");
				var img_width = $( this ).attr("width"); 
				var img_height = $( this ).attr("height");

				$( this ).parent().get( 0 ).innerHTML = "<span style=\"width:"+ img_width +";height:"+ img_height +";filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enable=true,src='"+ img_url +"' ,sizingMethod='scale')\"></span>";   
			} );

			$(".png").each( function( i , val ){
				var img_url =  $( this ).css("background-image").replace(/url\("|"|\)$/ig, "");
				$( this ).addClass("force").attr("style", "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img_url + "' ,sizingMethod='scale');");
			 });
		}
	} );
	
function pngFader(){
	
	jQuery.fn.fadeTo = function(speed,to,callback) {
	    return this.animate({opacity: to}, speed, function() {
	        if (to == 1 && jQuery.browser.msie)
	            this.style.removeAttribute('filter');
	        if (jQuery.isFunction(callback))
	            callback();
	    });
	};
	
	$(".png").fadeTo("slow", 0.3); // This sets the opacity of the thumbs to fade down to 30% when the page loads
	         $(".png").hover(function(){
	         $(this).fadeTo("slow", 1.0); // This should set the opacity to 100% on hover
	         },function(){
	         $(this).fadeTo("slow", 1.0); // This should set the opacity back to 30% on mouseout
	         });
	   
}



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

function musicPlayer(){

	if( $__( $( "#music-player" ) ) ){
		/* see if off exists */
		var params = { wmode : "transparent" };
		var attributes={wmode : "transparent" };
		
		if(getCookie("volOff")){
				
			var flashvars={"playState":1, "songURL":"http://wwww.bratz.com/smarty_files/templates/sounds/Bratz_Are_Back_loop_v4.mp3"}
				swfobject.embedSWF( "smarty_files/templates/flash/build/MGAMusicPlayer.swf" , "music-player" , "55" , "20" , "9.0.0" , "", flashvars , params , attributes );

		} else { 
			var flashvars={"playState":0, "songURL":"http://www.bratz.com/smarty_files/templates/sounds/Bratz_Are_Back_loop_v4.mp3"}
				swfobject.embedSWF( "smarty_files/templates/flash/build/MGAMusicPlayer.swf" , "music-player" , "55" , "20" , "9.0.0" , "", flashvars , params , attributes );
		}
				
    }
}


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

function interstitial(){
	
	if(  $__( $( "#interstitial" ) ) ){
		
		var interstit = bratzHash.interstitial.image;
		
		$("#interstitial").css( {"background-image" : "url("+ interstit  +")" } );
		
		
	}
}


function redirect(){

	var currentWebsite = "";
	var arr = new Array();
	    arr["walmart"] = "http://www.walmart.com/search/search-ng.do?search_constraint=0&ic=48_0&search_query=Bratz";
	    arr["kmart"] = "http://www.kmart.com/shc/s/search_10151_10104?keyword=bratz";
	    arr["tru"] = "http://www.toysrus.com/shop/index.jsp?categoryId=2274244";
	    arr["target"] = "http://www.target.com/b/ref=gp_se_search-results-box/189-5397131-8887211?ie=UTF8&node=1038692";
	    arr["facebook"] = "http://www.facebook.com/bratz";
	 	arr["promo-middle"] = "http://www.facebook.com/bratz";
	    arr["myspace"] = "http://www.myspace.com/bratz.girlz";
		arr["redirect-facebook"] = "http://www.facebook.com/bratz";
		arr["redirect-myspace"] = "http://www.myspace.com/bratz.girlz";
		arr["promo-twitter"] = "http://www.twitter.com/bratz";
		arr["promo-yt"] = "http://www.youtube.com/bratz";


	    arr["social-media-img1"] = "http://www.facebook.com/bratz";
	    arr["social-media-img2"] = "http://www.myspace.com/bratz.girlz";

	$(".where-to-buy").click( function(){
		$("#interstitial").fadeIn("slow");
		currentWebsite = arr[this.id];
	 });

	$("#interstitial-yes").click( function(){ 
			gotoLink( currentWebsite );
		$("#interstitial").fadeOut("slow");
	});

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

function scrollingGames(){
	
	if(  $__( $( ".games-scroller" ) ) ){
	
	$(".game-items").cycle({ 
			cleartype:  !$.support.opacity, 
			cleartypeNoBg: true,
	   		fx: 'fade', 
		    speed:  'slow', 
		    timeout: 0, 
		    next:   '.next', 
		    prev:   '.prev' });
		
	$("#games-glam").click(function(){
		$("#glam-game-wrapper").css("display","block");
			
			var params = { wmode : "transparent" };
 			var attributes = {};
			var flashvars = { };
			swfobject.embedSWF("smarty_files/templates/flash/Glam_bratz_2010/Bratz_Glam2.swf", "glam-game", "600", "400", "9.0.0","smarty_files/templates/flash/expressInstall.swf", flashvars, params, attributes);  	
	});
	
	$("#glam-game-close").click(function(){
			$("#glam-game-wrapper").css("display","none");
	});
	
	$("#games-lovemeter").click(function(){
	
			
		$("#lovemeter-game-wrapper").css("display","block")
			
			var params = { wmode : "transparent" };
 			var attributes = {};
			var flashvars = { };
			swfobject.embedSWF("smarty_files/templates/flash/love_meter_bratz_2010/lovemeter.swf", "lovemeter-game", "600", "400", "9.0.0","smarty_files/templates/flash/expressInstall.swf", flashvars, params, attributes);  	
	});
	
	
	$("#lovemeter-game-close").click(function(){
			$("#lovemeter-game-wrapper").css("display","none");
	});
	
	$("#games-fishtank").click(function(){
	
			
		$("#fishtank-game-wrapper").css("display","block")
			
			var params = { wmode : "transparent" };
 			var attributes = {};
			var flashvars = { };
			swfobject.embedSWF("smarty_files/templates/flash/FishTank.swf", "fishtank-game", "600", "400", "9.0.0","expressInstall.swf", flashvars, params, attributes);  	
	});
	
	
	$('#fishtank-game-close').click(function(){
			$("#fishtank-game-wrapper").css("display","none");
	});
	
	
	
	$("#games-mall").click(function(){
		
		if( obj.id ){
		$("#mall-game-wrapper").css("display","block")
			var params = { wmode : "transparent" , base : "http://www.bratz.com/smarty_files/templates/flash/bratzmall/build/" };
 			var attributes = {};
			var flashvars = {};
			swfobject.embedSWF("smarty_files/templates/flash/bratzmall/build/BoutiqueLoader.swf", "mall-game", "800", "600", "9.0.0","expressInstall.swf", flashvars, params, attributes); 
				}else { 
					//setCookie("secretcode", "1");
					$("#login").click();  
				} 	
	});
	
	
	
	$('#mall-game-close').click(function(){
			$("#mall-game-wrapper").css("display","none");
	});
		
	
}
	if(  $__( $( ".game-items" ) ) ){
			var google_conversion_label = "RZSeCMrr4AEQgIyC7wM";
			$("#google_conversion").html("<img src='http://www.googleadservices.com/pagead/conversion/1038124544/?label=RZSeCMrr4AEQgIyC7wM&amp;guid=ON&amp;script=0' border='0' />");
	}
	
}


function scrollingCatalog(){
	
	if( $__( $("#div-catalog-container") ) ){
		
		var catalog_arr = bratzHash.productGallery.a_allprod.dolls;
		
		var toString = "";
		
		for( x in catalog_arr ){
			
			toString += "<div class=\"div-dolls\">";
			toString += "<img src=\""+ catalog_arr[x]["imgpath"] +"\" class=\""+ catalog_arr[x]["cssClass"]+"\"/>";	
			toString += "<p class=\"dolls-desc\">" + catalog_arr[x]["description"]  + "</p>";
			toString += "</div>";
			
		}
		
		$("#dolls-wrapper").html( toString );
		
		var catalog_acc = bratzHash.productGallery.a_allprod.accessories;

		var accString = "";

		for( x in catalog_acc ){

				accString += "<div class=\"acc-list\">";
				accString += "<img src=\""+ catalog_acc[x]["imgpath"] +"\" class=\""+ catalog_acc[x]["cssClass"]+"\"/>";	
				accString += "<p class=\"acc-desc\">" + catalog_acc[x]["description"]  + "</p>";
				accString += "</div>";

			}

	$("#acc-wrapper").html( accString );

	$("#acc-wrapper, #dolls-wrapper").cycle({ 
			cleartype:  !$.support.opacity, 
			cleartypeNoBg: true,
	   		fx: 'fade', 
		    speed:  'slow', 
		    timeout: 0, 
		    next:   '.next', 
		    prev:   '.prev' });
	
	}

}

function getFlashVersion(){
// ie
try {
try {
// avoid fp6 minor version lookup issues
// see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
try { axo.AllowScriptAccess = 'always'; }
catch(e) { return '6,0,0'; }
} catch(e) {}
return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
// other browsers
} catch(e) {
try {
if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
}
} catch(e) {}
}
return '0,0,0';
}

function homeRotator(){
	
	
	if(  $__( $( "#rotator-wrapper" ) ) ){
			var google_conversion_label = "_s_kCNLq4AEQgIyC7wM";
			$("#google_conversion").html("<img src='http://www.googleadservices.com/pagead/conversion/1038124544/?label=_s_kCNLq4AEQgIyC7wM&amp;guid=ON&amp;script=0' border='0' />");
	}
	
	var flashVersion = getFlashVersion().split(',').shift();
	if (jQuery.browser.mozilla && flashVersion >= 10) {
		
		var htmlString = "<img src='smarty_files/templates/images/home_cloe.png' />";
		htmlString += "<img src='smarty_files/templates/images/home_jade.png' />";
		htmlString += "<img src='smarty_files/templates/images/home_sasha.png' />";
		htmlString += "<img src='smarty_files/templates/images/home_yasmin.png' />";

		$("#div-home-rotator").html(htmlString);
		$("#div-home-rotator").cycle({
				fx: 'fade',
				speed: 'slow',
				timeout: 5000 });

				//drop the code for the fading thing here.
			} else {
				var params = { wmode : "transparent"};
				var attributes = {};
				var flashvars = {};
				flashvars.image1 = "smarty_files/templates/images/home_cloe.png,1,10";
				flashvars.image2 = "smarty_files/templates/images/home_jade.png,2,10";
				flashvars.image3 = "smarty_files/templates/images/home_sasha.png,3,10";
				flashvars.image4 = "smarty_files/templates/images/home_yasmin.png,4,10";
				
				
				$("#rotator-wrapper").css({"left" : "-370px"});
				
swfobject.embedSWF("smarty_files/templates/flash/ImageFader.swf", "div-home-rotator", "455", "876", "9.0.0","smarty_files/templates/flash/expressInstall.swf", flashvars, params, attributes);

$("#a-flash-desc,#p-flash-desc").css({"display":"block"});

		
	}

	
}



function secretCode(){
	$("#enable-product-code").click( function(){
			setCookie( "secretcode", "1" );
			window.location = "";
	});

	$("#toplink-secret-code").click(function(){
		if( obj.id ){
			$("#input-secret-code").val("");
			$("#secretcode-basic").css("display","none");

			$("#secret-code").fadeIn('slow');
			$("#input-secret-code").keyup( function(){
				if( this.value.length >= 6 ){
					$("#secretcode-basic").fadeIn('slow');
					$("#secretcode-next").click(function(){
						$("#secretcode-basic").css("display" , "none");
						$("#secretcode-party").fadeIn('slow');
					});
					
					$("#secretcode-party-next").click(function(){
						$("#secretcode-party").css("display" , "none");
						$("#secretcode-basic").fadeIn('slow');
					});
				}
				else{
					$("#secretcode-basic, #secretcode-party").fadeOut('slow');
				}
			});

			$("#secretcode-close").click(function(){
				$("#secret-code").fadeOut('slow');
			});
	
		} else { 
			setCookie("secretcode", "1");
			$("#login").click();  
		}

	});

	$("#promo-left").click( function(){
		window.location =  "?section=bratzgames";

	 });
	
	if(getCookie("secretcode") != null && getCookie("secretcode") != "") {	
	 	$("#toplink-secret-code").click();
			setCookie("secretcode", null);
			deleteCookie("secretcode");
	 }


	$(".radio-secretcode").click( function(){
		var girl = 0;
		var secret_code = $("#input-secret-code").val();
		$(".radio-secretcode").each( function( i , val ){ 
			if( $( this ).attr("checked") ){
				girl =  this.value;
			}
	});

		 $.post("?request=secretcode", { secret_code : secret_code , girl : girl , user_id : obj.id }, function( http ){
                                var s_return = eval( http );
                                if( s_return == 0 ){
                                        alert("Your item has been added."); 
					$.get("?request=download&id=" + girl , { id : girl } , function( url ){
						window.location = url;
					 } );

                                }
                                else if( s_return == 1 ){
                                        alert("You have already registered this product.");
					$.get("?request=download&id=" + girl , { id : girl } , function( url ){
						window.location = url;
					 } );
                                }

                                else if( s_return == 2 ){
                                        alert("Please check your secret code and try again.");
                                }
                });

	 });
	
}

function checkBioPages(){
	if( $__( $( "#div-bio-box" ) ) ){
		
		$(".div-bios-menu-common").click( function(){ 
			
				var stringcurrent = this.id.split("-");				
				currentGirl = stringcurrent[3];

				$(".div-bios-menu-common").each( function( val , i ) {
						$("#" + this.id ).removeClass( this.id + "-current");
						$( this ).addClass( this.id );
						
				 });
				
				$( this ).removeClass("div-bios-menu-yasmin").addClass( this.id + "-current");
				
				$(".all, .chat").css("display","none");
				
				$("#div-chat-" + currentGirl).css("display" , "block");
				
				$("#div-img-" + currentGirl ).css("display","block");
				
				$("#div-circle-" + currentGirl ).css("display"	,"block");
				
				
				$("#div-bio-copy").html( bratzHash.girls[currentGirl].bio ); 
				$("#bio-header").html( bratzHash.girls[currentGirl].header ); 
				$("#blog-header").html(bratzHash.girls[currentGirl].blogheader);
				$("#div-blog-copy").html(bratzHash.girls[currentGirl].blog);			
		});
			$("#div-bio-copy").html( bratzHash.girls[currentGirl].bio ); 
			$("#bio-header").html( bratzHash.girls[currentGirl].header ); 
			$("#blog-header").html( bratzHash.girls[currentGirl].blogheader);
			$("#div-blog-copy").html( bratzHash.girls[currentGirl].blog);
		
		$("#a-blog-header").click( function(){
			$("#div-bio-copy").css("display","none");
			$("#div-blog-copy").css("display","block");
		});
		
		$("#a-bio-header").click( function(){
			$("#div-blog-copy").css("display","none");
			$("#div-bio-copy").css("display","block");
		});
	}	
	
	$('#div-chat-copy').cycle({ 
	    fx:    'scrollUp',
	 	speed:  1000,
	    timeout: 15000
	});

}

function homePromos(){
	if(  $__( $( "#div-btm-promo" ) ) ){
		
		var promoleft = bratzHash.homepromos.promoleft;
		var promomiddle = bratzHash.homepromos.promomiddle;
		var promoright = bratzHash.homepromos.promoright;
		var promotwitter = bratzHash.homepromos.promotwitter;
		var promoyt = bratzHash.homepromos.promoyt;

		$("#promo-left").html("<img src='" + promoleft + "'/>");
		$("#promo-middle").html("<img src='" + promomiddle + "'/>");
		$("#promo-right").html("<img src='" + promoright + "'/>");
		$("#promo-twitter").html("<img src='" + promotwitter + "'/>");
		$("#promo-yt").html("<img src='" + promoyt + "'/>");

	}
}

function checkFlashContent(){
	
	if(  $__( $( "#home-overlay-wrapper" ) ) ){
		
		var params = { wmode : "transparent" };
		var attributes = { id : "flash-bool" };
		var flashvars = { videoURL : "http://c1886602.cdn.cloudfiles.rackspacecloud.com/BRPAD0013H_Party_v2.f4v" , loop : 1  };
		swfobject.embedSWF("smarty_files/templates/flash/build/MGAVideoPlayer.swf", "home-overlay-video", "850", "580", "9.0.0","expressInstall.swf", flashvars, params, attributes);
		
		
	$("#home_video_close").click( function(){
		$("#home-overlay-wrapper").fadeOut('slow');
		
		$("#video-wrapper, #home-overlay-wrapper, #flash-bool").html("");
	});
		
	}
	
	var params = { wmode : "transparent" };
	 var attributes = { wmode : "transparent" };

	 var flashvars = { };

	 swfobject.embedSWF("smarty_files/templates/flash/home_promo.swf", "div-home-promo", "630", "520", "9.0.0","expressInstall.swf", flashvars, params, attributes);  	

		setTimeout( function(){
			$("#div-btm-promo").fadeIn('slow');
		} , 2000 );

}

function activeMenu(){
	if(page == "moxiehomepage")
	{
		$("#div-menu-home").css({"background-position" : "439px 125px", "top" : "39px"});
		
		$("#div-menu-bios, #div-menu-games, #div-menu-catalog").mouseover(function() {
		$("#div-menu-home").css({"background-position" : "439px 250px", "top" : "29px"});
		});
		
		$("#div-menu-bios, #div-menu-games, #div-menu-catalog").mouseout(function() {
		$("#div-menu-home").css({"background-position" : "439px 125px", "top" : "39px"});
		});
		
	}
	
	else if(page == "bratzgirlz")
	{
		$("#div-menu-bios").css({"background-position" : "359px 125px", "top" : "39px"});

		$("#div-menu-home, #div-menu-games, #div-menu-catalog").mouseover(function() {
		$("#div-menu-bios").css({"background-position" : "359px 250px", "top" : "29px"});
		});

		$("#div-menu-home, #div-menu-games, #div-menu-catalog").mouseout(function() {
		$("#div-menu-bios").css({"background-position" : "359px 125px", "top" : "39px"});
		});
	}
	
	else if(page == "bratzgames")
	{
		$("#div-menu-games").css({"background-position" : "234px 125px", "top" : "39px"});

		$("#div-menu-home, #div-menu-bios, #div-menu-catalog").mouseover(function() {
		$("#div-menu-games").css({"background-position" : "234px 250px", "top" : "29px"});
		});

		$("#div-menu-home, #div-menu-bios, #div-menu-catalog").mouseout(function() {
		$("#div-menu-games").css({"background-position" : "234px 125px", "top" : "39px"});
		});
	}
	
	else if(page == "bratzcatalog")
	{

		$("#div-menu-home, #div-menu-bios, #div-menu-games").mouseover(function() {
		$("#div-menu-catalog").css({"background-position" : "144px 250px", "top" : "29px"});
		});

		$("#div-menu-home, #div-menu-bios, #div-menu-games").mouseout(function() {
		$("#div-menu-catalog").css({"background-position" : "144px 125px", "top" : "39px"});
		});
	}
}
/* Google Analytics */

function loginRegEvent(){
	
	if(  $__( $( "#register" ) ) ){
		var google_conversion_label = "tA8bCMLs4AEQgIyC7wM";
			$("#google_conversion").html("<img src='http://www.googleadservices.com/pagead/conversion/1038124544/?label=tA8bCMLs4AEQgIyC7wM&amp;guid=ON&amp;script=0' border='0' />");
	}

	
	if( $__( $( "#login-register-box" ) ) )
	{
		$("#register").click( function( ){ 
				$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1500 , function(){
					$("#dialog-date").val("yyyy-mm-dd");
					$("#overlay-box").css({ "display" : "block" , "opacity" : "1" });
					$("#overlay-dialog").css({ "display" : "block" , "opacity" : "1" });
					regValidateObj.checkDate();
				 } );
		} );

			$("#a-logon-register").click( function(){
						$("#register").click();
						$("#logon-dialog").css("display","none");
			});
		
		$("#login").click( function(){	
			$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1500 , function(){
				
				$("#logon-wrapper,#overlay-login").css({ "display" : "block" , "opacity" : "1" });
				$("#forgot-wrapper").css("display","none");
				$("#logon-dialog").css("display","block");
				
				$("#a-logon-forgot").click( function(){
					$("#logon-wrapper").css("display","none");
						$("#forgot-wrapper").fadeIn('slow');
						$("#div-forgot").css("height","252px");

				});
		
			 });

		});
		
		$("#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("Please check your username and password and try again."); 
					}
					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 = ""; }
				});
		 } );


		$("#logout").click( function(){ 
				$.post("?request=logout",function( ){
					window.location = "";
				});
		} );
	
	}
	
	if( $__( $("#dialog-close") ) ){
		$("#dialog-close, #login-li-dialog-close , #logon-header-close , #forgot-password-close, #update-cancel").click(function(){
			$("#overlay-box,#overlay-login").css({ "display" : "none" , "opacity" : "0" });
			$("#overlay-wrapper").animate({ "opacity" : "0" , "height" : "0px" } , 1500 , function(){ $( this ).css("display" , "none"); } );

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

	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 Bratz.com.");
					}
					else if( http == 2 ){
						alert("Your account information has been emailed to the address you used to register on Bratz.com");
					}

			    });

		});
	}
}

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 + ")");
			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>Products Registered:</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 = "";

        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\">Please check/uncheck website access for you're child:</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"] , "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 = bratzHash.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 = bratzHash.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 = bratzHash.stateList[ id ];
	var stringState = "<option id=\"0\">Select One</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 = bratzHash.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 loginTabs() {

	if(obj.id){
			var toplinks = parseInt( (obj.username.length * 19) + 3 ) + "px";
			$("#div-top-links").css("width", toplinks);
	}
	
}

function logValidation(){
	if(obj.id){
			
			$("#myaccount").click( function(){
					$("#password").val("******");
					$("#password-confirm").val("");
				$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1500 , function(){
						$("#logon-wrapper").css({"display" : "none"});
						$("#overlay-login,#login-dialog-wrapper,#div-myacct,#div-profile-wrapper,#login-ul-dialog-header,#myacct-header-text,#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-text").html("Parent Account");
								$(".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");
								$("#login-li-dialog-left").html("MyAccount");
								$(".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" ){
									$("#login-li-dialog-left").html("Parent Account");
									$(".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{
								$("#login-li-dialog-left").html("My Account");
							}

				$(".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;

                                        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("readonly", false);
                                        $("#username,#email-account,#parent-email-account").attr("readonly", true);
					$(".li-password-confirm").css("display","block");
					passwordListener();
                                 });

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




							
						});

					});	
				} );
	
}

	else{
			$("#login").click( function(){
				$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1500 , function(){
					$("#logon-wrapper").css({ "display" : "block" , "opacity" : "1" });
					});
		
				} );

	}
	
}

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

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

var countryReady = false;

var regValidateObj = { 
	json_send : { } ,
	badwords : null ,

	checkDate : function(){
		$("#btn-next").click( function(){ 
				if($("#dialog-date").val() != "yyyy-mm-dd" ){
					if( regValidateObj.badwords != null ){
					regValidateObj.getAccount_type( $("#dialog-date").val() );
					regValidateObj.hideElem();
					regValidateObj.expandBuilt();
					}
					else{
					$.post("?request=loadbadwords",{},function( http ){ regValidateObj.badwords = eval( "(" + http + ")" ); });
					regValidateObj.getAccount_type( $("#dialog-date").val() );
					regValidateObj.hideElem();
					regValidateObj.expandBuilt();
					}
				}
				else{
					alert("Please choose a birthday.");
				}
		});

        }
	, 

	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" ){
				$("#user-optins,#user-location-signup,.li-child-email").css("display","none");
				$(".li-parent-email").css("display","block");
			}
			else if( regValidateObj.json_send.acct_type == "parent" ){
				$("#user-optins,#user-location-signup,.li-child-email").css("display","block");
                                $(".li-parent-email").css("display","none");
				if( countryReady == false ){
					regValidateObj.countrybuild();
				}
				countryReady = true;
			}
			else{ 
			        $("#user-optins,#user-location-signup,.li-child-email").css("display","block");
				if( countryReady == false ){
                                	regValidateObj.countrybuild();
				}
                                countryReady = true;
			}
	}
	,
	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("Submit");
				$("#dialog-title").html("Registration - Step 2 of 2");
				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 = bratzHash.countryList;
        var stringCountry = "<option id=\"0\">Select One</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 alpha = /^([a-zA-Z])+$/;
		var arr = new Array();
		var json_send = {};

		if( $("#reg-signup-first_name").val() == "" || alpha.test( $("#reg-signup-first_name").val() ) == false ){
			$("#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") ){
			var arr_bad = regValidateObj.badwords;
			if( $("#reg-signup-username").val() == "" ){
					$("#reg-signup-username").css("border","1px solid red");	
					arr[1] = false;
			}
			else {

			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() != "Select One"){
			$("#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() != "Select One"){
			$("#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() == "" || alpha.test( $("#reg-signup-last_name").val() ) == false ){
			$("#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.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,3";
		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"] );
					}
					else{ 
						setTimeout( function(){
						$("#overlay-dialog").css({ "background" : "none" , "border" : "none" });
						$("#dialog-header,#dialog-content-2,#dialog-bottom").css("display", "none");
						$("#dialog-content-2").css("display","none");
						$("#dialog-reg-complete").css({ "display" : "block","background-color" : "#CFCFCF" });
						
						$("#span-reg-complete-username").html("Username is: " + $("#reg-signup-username").val() );
                                                $("#span-reg-complete-password").html("Password is:" + $("#reg-signup-password").val() );

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

				}
			});
		}	

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

		if( $("#reg-signup-first_name").val() == "" || alpha.test( $("#reg-signup-first_name").val() ) == false ){
			$("#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") ){
			var arr_bad = regValidateObj.badwords;
			if( $("#reg-signup-username").val() == "" ){
					$("#reg-signup-username").css("border","1px solid red");	
					arr[1] = false;
			}
			else {

			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() != "Select One"){
			$("#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() != "Select One"){
			$("#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() == "" || alpha.test( $("#reg-signup-last_name").val() ) == false ){
			$("#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.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,3";

		if( arr.length == 0 ){
			if( jQuery.trim( $("#reg-signup-email").val() ) == jQuery.trim( $("#reg-signup-parent_email").val() ) ){
				alert("Your email cann't be the same as your parents email ");
			 }
			else{
			$.post("?request=register", json_send , function( http ){
				if( http != "" ){
					var returnObj = eval( "(" + http  + ")" );
					if( returnObj["error"] ){
						alert( returnObj["error"] );
					}
					 else{     
						setTimeout( function(){
                                                $("#overlay-dialog").css({ "background" : "none" , "border" : "none" });
                                                $("#dialog-header,#dialog-content-2,#dialog-bottom").css("display", "none");
						$("#dialog-content-2").css("display", "none");
						$("#dialog-reg-complete").css("display","block","background-color","#CFCFCF");

						$("#span-reg-complete-username").html("Username is: " + $("#reg-signup-username").val() );
                                                $("#span-reg-complete-password").html("Password is:" + $("#reg-signup-password").val() );

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


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

		if( $("#reg-signup-first_name").val() == "" || alpha.test( $("#reg-signup-first_name").val() ) == false ){
			$("#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") ){
			var arr_bad = regValidateObj.badwords;
			if( $("#reg-signup-username").val() == "" ){
					$("#reg-signup-username").css("border","1px solid red");	
					arr[1] = false;
			}
			else {


			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() == "" || alpha.test( $("#reg-signup-last_name").val() ) == false ){
			$("#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";

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



						$("#span-reg-complete-username").html("Username is: " + $("#reg-signup-username").val() );
                                                $("#span-reg-complete-password").html("Password is:" + $("#reg-signup-password").val() );

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

				}
			});
		}	
	
	}

}

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

}


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

function enableCalendar(){

	if( $__( $( "#calendar" ) ) ){
                $("#calendar").click( function(){
                        $("#dialog-calendar").datepicker( {
                                                 onSelect: function(dateText, inst) { $("#dialog-date").val(dateText); $( "#dialog-calendar" ).datepicker( "destroy" ); },
                                                 changeMonth: true ,
                                                 changeYear: true ,
                                                 yearRange: "1900:2010" ,
                                                 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 == "bittymeet" ){
			objCallEventTracker( new Object() , 4 );	
		}

	},

	blogs : function(){ 

	},

	catalog : function(){ 

	},

	wishlist : function(){ 

	}

}

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

function setMuteCookie(){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+50);
	document.cookie="volOff=1;expires="+exdate.toGMTString() + ";";
}

function setCookie( name , value ){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+50);
	document.cookie="" + name + "=" + value + ";expires="+exdate.toGMTString() + ";";
}

function removeMuteCookie(){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()-50);
	document.cookie="volOff=1;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();
}
