/* end of Main functions */
$( document ).ready( function(){
		loginRegEvent();
		checkBioPages();
		//GoogleListener();
		$(document).pngFix(); 
		enableCalendar();
		//homeRotator();
		checkFlashContent();
		logValidation();
		secretCode();
		scrollingGames();
		scrollingCatalog();
		redirect();
		homepageFlash();
		funPage();
		funFacts();
		faqPage();
		bioPage();
		gamesPage();
		catalogPage();
		PngFix_IE();
		chooseCountry();
		googleConListen();
		Translation();
		MyAccount();
		ruWhereToBuy();
		
});

function ruWhereToBuy(){
	if (page == "wheretobuy") {
		window.location="?section=";
	}
	
	if( $__( $( "#russia_store_type" ) ) ){	
		$("#ruwheretobuy-btn").css("display", "none");
	}
	$("#ru_retail").click( function(){
		$("#wheretobuy-title-ru").css("display" , "none");
		$("#russia_store_type").css("display" , "none");
		$("#ruwheretobuy-btn").css("display", "block");
		$("#russia_store_type_retail").fadeIn('slow');
	});
	
	$("#ru_market").click( function(){
		$("#wheretobuy-title-ru").css("display" , "none");
		$("#russia_store_type").css("display" , "none");
		$("#ruwheretobuy-btn").css("display", "block");
		$("#russia_store_type_market").fadeIn('slow');
	});
	
	$(".back_wheretobuy").click( function() {
		$("#wheretobuy-title-ru").css("display" , "block");
		$("#russia_store_type").css("display" , "block");
		$("#russia_store_type_retail").css("display" , "none");
		$("#russia_store_type_market").css("display" , "none");
	});
	
}

function MyAccount() {
	if(obj.id) {
		$("#login-register-box-myaccount").css("display","inline");
	}
}

function Translation() {
	if( $__( $( "#overlay-box, #overlay-login" ) ) ){
		
		$("#dialog-title").html(moxieHash.language.registration.dialogtitle);
		$("#dialog-desc").html(moxieHash.language.registration.dialogdesc);
		$("#dialog-dob").html(moxieHash.language.registration.dialogdob);
		$("#calendar").html(moxieHash.language.registration.calendar);
		$("#lang-firstname1").html(moxieHash.language.registration.firstname);
		$("#lang-firstname2").html(moxieHash.language.registration.firstname);
		$("#lang-firstname3").html(moxieHash.language.registration.firstname);
		$("#lang-lastname1").html(moxieHash.language.registration.lastname);
		$("#lang-lastname2").html(moxieHash.language.registration.lastname);
		$("#lang-lastname3").html(moxieHash.language.registration.lastname);
		$("#lang-username1").html(moxieHash.language.registration.username);
		$("#lang-username2").html(moxieHash.language.registration.username);
		$("#lang-username3").html(moxieHash.language.registration.username);
		$("#lang-password1").html(moxieHash.language.registration.password);
		$("#lang-password2").html(moxieHash.language.registration.password);
		$("#lang-password3").html(moxieHash.language.registration.password);
		$("#lang-gender").html(moxieHash.language.registration.gender);
		$("#lang-gender-boy").html(moxieHash.language.registration.boy);
		$("#lang-gender-girl").html(moxieHash.language.registration.girl);
		$("#lang-email1").html(moxieHash.language.registration.email);
		$("#lang-email2").html(moxieHash.language.registration.email);
		$("#lang-email3").html(moxieHash.language.registration.email);
		$("#lang-parent-email").html(moxieHash.language.registration.parentemail);
		$("#lang-country").html(moxieHash.language.registration.country);
		$("#lang-state").html(moxieHash.language.registration.state);
		$("#lang-select-one").html(moxieHash.language.registration.selectone);
		$("#lang-zip").html(moxieHash.language.registration.zip);
		$("#lang-newsletters").html(moxieHash.language.registration.newsletters);
		$("#lang-offer1").html(moxieHash.language.registration.offer1);
		$("#lang-offer2").html(moxieHash.language.registration.offer2);
		$("#btn-next").html(moxieHash.language.registration.btnnext);
		$("#btn-next").css("width", "100px");
		$("#p-reg-complete-header").html(moxieHash.language.registration.regcompleteheader);
		$("#p-reg-complete").html(moxieHash.language.registration.regcomplete);
		$("#enable-product-code").html(moxieHash.language.registration.enableproductcode);
		$("#complete-btn-close").html(moxieHash.language.registration.btnclose);
		$("#logon-header-left").html(moxieHash.language.registration.logonheader);
		$("#a-logon-forgot").html(moxieHash.language.registration.forgotpassword);
		$("#a-logon-register").html(moxieHash.language.registration.register);
		$("#btn-logon").html(moxieHash.language.registration.btnlogon);
		$("#forgot-header-left").html(moxieHash.language.registration.forgotpassword);
		$("#p-forgot-desc").html(moxieHash.language.registration.forgotdesc);
		$("#forgotusername").html(moxieHash.language.registration.forgotusername);
		$("#forgotemail").html(moxieHash.language.registration.forgotemail);
		$("#forgot-submit").html(moxieHash.language.registration.btnsubmit);
		
		$("#login").html(moxieHash.language.homepage.login);
		$("#register").html(moxieHash.language.homepage.register);
		$("#logged-on").html(moxieHash.language.homepage.welcome + " " + obj.username);
		$("#logout").html(moxieHash.language.homepage.logout);
		$("#a-country").html(moxieHash.language.homepage.country);
		$("#country-header-left").html(moxieHash.language.homepage.country);
		$("#en-us").html(moxieHash.language.homepage.en);
		$("#es-es").html(moxieHash.language.homepage.es);
		$("#fr-ca").html(moxieHash.language.homepage.fr);
		$("#en-ca").html(moxieHash.language.homepage.enca);
		$("#ru-ru").html(moxieHash.language.homepage.ru);
		
		
		$("#myaccount").html(moxieHash.language.homepage.myaccount);
		$("#logout").html(moxieHash.language.homepage.logout);
		$("#menu-country").html(moxieHash.language.homepage.country);
		$("#terms").html(moxieHash.language.homepage.terms);
		$("#privacy").html(moxieHash.language.homepage.privacy);
		$("#copyright").html(moxieHash.language.homepage.copyright);
		$("#faq").html(moxieHash.language.homepage.faq);
		
		
		
		
	}
}

function chooseCountry() {
	
	if( $__( $( "#overlay-country" ) ) ){
		
		$("#a-country, #a-flag").click( function(){
			$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1000 , function(){
				$("#country-wrapper").css({ "display" : "block" , "opacity" : "1" });
			});	
		
			$("#country-header-close").click( function() {
				$("#country-wrapper").css("display","none");
			});
		
			$(".choosecountry").click( function() {
				$(".close-btn").click();
				setCookie("moxiegirlzlang", this.id);
				window.location="";
				
			});
		});
		
		
	}//end if
		
	
}


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


var PngFix_IE = ( function( ){ 
		//if( $.browser.msie == true && $.browser.version == "6.0" || $.browser.version == "7.0" ){
		if( $.browser.msie == true && $.browser.version == "6.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 homepageFlash() {

			var params = { wmode : "transparent" };
 			var attributes = { id : "flash-bool" };
 			if (language != "en") {
 				var flashvars = { videoURL : "http://c1877982.cdn.cloudfiles.rackspacecloud.com/nara_video_no_narration.f4v" , loop : 1  };
 			} else {
				var flashvars = { videoURL : "http://c1877982.cdn.cloudfiles.rackspacecloud.com/NaraGameVideo.flv" , loop : 1  };
			}
			swfobject.embedSWF("smarty_files/templates/flash/build/MGAVideoPlayer.swf", "div-home-rotator", "848", "650", "9.0.0","expressInstall.swf", flashvars, params, attributes); 

}

function redirect(){
	var currentWebsite = "";
	var arr = new Array();
	    arr["a-walmart-"+country] = moxieHash.catalog.links.walmart;	//"http://www.walmart.com/";
	    arr["a-kmart-"+country] = moxieHash.catalog.links.kmart;	//"http://www.kmart.com/";
	    arr["a-toys-"+country] = moxieHash.catalog.links.tru;	//"http://www.toysrus.com/";
	    arr["a-target-"+country] = moxieHash.catalog.links.target;
		arr["a-amazon-"+country] = "http://www.amazon.com/s/?ref=ty_mga_direct&tag=mgaentertainm-20&ie=UTF8&hidden-keywords=nara&rh=n:165793011,p_6:ATVPDKIKX0DER";
	    
	    arr["menu-facebook-"+language] = "http://www.facebook.com/legendofnara";
	    arr["menu-twitter-"+language] = "http://www.twitter.com/legendofnara";
		arr["menu-youtube-"+language] = "http://www.youtube.com/legendofnara";
		
	    arr["facebook2"] = "http://www.facebook.com/legendofnara";
	    arr["twitter2"] = "http://www.twitter.com/legendofnara";
	    arr["stardoll"] = "http://www.stardoll.com/en/dolls-games/";
	   
	    
	$(".a-inter-event").click( function(){
		$("#interstitial").fadeIn("slow");
		$("#UnityObject").addClass("unityhide");
		currentWebsite = arr[this.id];
	 });

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

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

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

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

function scrollingGames(){
	$(".games-scroller").scrollable({ 
	    size: 1,
		loop: true });
		
	$("#games-area").click(function(){
		$("#games-wrapper").css("display","block");
			var params = { wmode : "transparent" };
 			var attributes = {};
			var flashvars = { };
			swfobject.embedSWF("smarty_files/templates/flash/Future_fantasy2.swf", "future-game", "600", "400", "9.0.0","expressInstall.swf", flashvars, params, attributes);  	
			
	});
	
	$("#game-close").click(function(){
			$("#games-wrapper").css("display","none");
			
	});
	
	
	
}

function scrollingCatalog(){
	
	var dude = $(".catalog-dolls-wrapper").scrollable({ 
	    size: 1,
		loop: true, 
		onSeek : function(){ 
			var cur = this.getIndex();
			$("#p-dolls-desc").html( moxieHash.productGallery.a_allprod.dolls[cur].description);
			
		}, onBeforeSeek : function(){ 
			var cur = this.getIndex();
			$("#p-dolls-desc").html( moxieHash.productGallery.a_allprod.dolls[cur].description  ); 
				
			}
	});
	$(".catalog-acc-wrapper").scrollable({ 
	    size: 1,
		loop: true, 
		onSeek : function(){ 
			var cur = this.getIndex();
			$("#p-acc-desc").html( moxieHash.productGallery.a_allprod.accessories[cur].description);
			
		}, onBeforeSeek : function(){ 
			var cur = this.getIndex();
			$("#p-acc-desc").html( moxieHash.productGallery.a_allprod.accessories[cur].description  ); 
				
			}
	});
	

}
function homeRotator(){
		var params = { wmode : "transparent"};
		var attributes = {};

		var flashvars = {};
		flashvars.image1 = "smarty_files/templates/images/cloud_animation/2_melrose_lrg.png,1,10";
		flashvars.image2 = "smarty_files/templates/images/cloud_animation/1_melrose_sm.png,2,10";
		flashvars.image3 = "smarty_files/templates/images/cloud_animation/2_bijou_lrg.png,3,10";
		flashvars.image4 = "smarty_files/templates/images/cloud_animation/1_bijou_sm.png,4,10";
		flashvars.image5 = "smarty_files/templates/images/cloud_animation/2_tristen_lrg.png,5,10";
		flashvars.image6 = "smarty_files/templates/images/cloud_animation/1_tristen_sm.png,6,10";
		flashvars.image7 = "smarty_files/templates/images/cloud_animation/2_arizona_lrg.png,7,10";
		flashvars.image8 = "smarty_files/templates/images/cloud_animation/1_arizona_sm.png,8,10";

		swfobject.embedSWF("smarty_files/templates/flash/ImageFader.swf", "div-home-rotator", "1800", "423", "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(){
		$("#dialog-reg-complete").css("display","none");			
		setCookie( "secretcode", "1" );
		window.location = "";
	});
	
	$("#home-promo-center-"+language).click( function() {
		$("#menu-secret-code-"+language).click();
	});
	
	$("#menu-secret-code-"+language).click(function(){
		if( obj.id ){

			$("#div-secret-code-"+language).fadeIn('slow');
			$("#input-secret-code").val("");
			$("#secretcode-air").css("display","none");
			$("#secretcode-earth").css("display","none");
			$("#secretcode-earth2").css("display","none");
			$("#secretcode-fire").css("display","none");
			$("#secretcode-water").css("display","none");
			$("#UnityObject").addClass("unityhide");

		
			$("#input-secret-code").keyup( function(){
				if( this.value.length >= 6 ){
					$("#secretcode-air").css("display","none");
					$("#secretcode-earth").css("display","none");
					$("#secretcode-earth2").css("display","none");
					$("#secretcode-fire").css("display","none");
					$("#secretcode-water").css("display","none");
					
					$("#secretcode-air").fadeIn('slow');
				}
				else{
				
					$("#secretcode-air").css("display","none");
					$("#secretcode-earth").css("display","none");
					$("#secretcode-earth2").css("display","none");
					$("#secretcode-fire").css("display","none");
					$("#secretcode-water").css("display","none");
				}
	
			});
					$("#secretcode-air-prev").click(function(){
						$("#secretcode-air").css("display" , "none");
						$("#secretcode-earth2").fadeIn('slow');
					});
					
					$("#secretcode-air-next").click(function(){
						$("#secretcode-air").css("display" , "none");
						$("#secretcode-earth").fadeIn('slow');
					});
					
					$("#secretcode-earth-prev").click(function(){
						$("#secretcode-earth").css("display" , "none");
						$("#secretcode-air").fadeIn('slow');
					});
					
					$("#secretcode-earth-next").click(function(){
						$("#secretcode-earth").css("display" , "none");
						$("#secretcode-fire").fadeIn('slow');
					});
					
					$("#secretcode-fire-prev").click(function(){
						$("#secretcode-fire").css("display" , "none");
						$("#secretcode-earth").fadeIn('slow');
					});
					
					$("#secretcode-fire-next").click(function(){
						$("#secretcode-fire").css("display" , "none");
						$("#secretcode-water").fadeIn('slow');
					});
					
					$("#secretcode-water-prev").click(function(){
						$("#secretcode-water").css("display" , "none");
						$("#secretcode-fire").fadeIn('slow');
					});
					
					$("#secretcode-water-next").click(function(){
						$("#secretcode-water").css("display" , "none");
						$("#secretcode-earth2").fadeIn('slow');
					});
					
					$("#secretcode-earth2-prev").click(function(){
						$("#secretcode-earth2").css("display" , "none");
						$("#secretcode-water").fadeIn('slow');
					});
					
					$("#secretcode-earth2-next").click(function(){
						$("#secretcode-earth2").css("display" , "none");
						$("#secretcode-air").fadeIn('slow');
					});
						
			$("#secretcode-close").click(function(){
				$("#div-secret-code-"+language).fadeOut('slow');
				$("#UnityObject").removeClass("unityhide");
			});
			
			setCookie("secretcode", null);
			deleteCookie("secretcode");		

		
		} else { 
			setCookie("secretcode", "1");
			$("#login").click();  
		}

	});

	if(getCookie("secretcode") != null && getCookie("secretcode") != "") {
		$("#menu-secret-code-"+language).click();
	}
	
	$("#btn-redeem").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 , website_id : website_id }, function( http ){
		         	var s_return = eval( http );
		         	if( s_return > 0 ){
		         		alert(moxieHash.language.secretcode.code0); 
						$.get("?request=download&id=" + s_return , { id : s_return } , function( url ){
							window.location = url;
						} );

					}
					else if( s_return == 0 ){
						alert(moxieHash.language.secretcode.code1);
						$.get("?request=download&id=" + s_return , { id : s_return } , function( url ){
							window.location = url;
						} );
					}
					else if( s_return < 0 ){
						alert(moxieHash.language.secretcode.code2);
					}
			
		});
	 });

}



function bioPage() {
	
	$(".bio-air-wrapper").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		visible: 5,
		scroll: 1
	    });
	
	$(".bio-earth-wrapper").jCarouselLite({
	    btnNext: ".next",
	    btnPrev: ".prev",
		visible: 5,
		scroll: 1
	});
	
	$(".bio-fire-wrapper").jCarouselLite({
	    btnNext: ".next",
	    btnPrev: ".prev",
		visible: 5,
		scroll: 1
	});
	
	$(".bio-water-wrapper").jCarouselLite({
	    btnNext: ".next",
	    btnPrev: ".prev",
		visible: 5,
		scroll: 1
	});
 
	if( $__( $( "#div-bio-box" ) ) ){
	

	if( $__( $( "#div-bio-menu" ) ) ){
		
		$(".bugtype").click ( function() {
		
			var exp = this.id.split("-");

			currentType = exp[1];
			
			$(".all").css("display" , "none");

			$("#bug-bio").html( moxieHash.bugs[currentType][0].bio );
			$("#bio-wrapper").css("background-image" , "url(smarty_files/templates/images/BIO/bugs/" + moxieHash.bugs[currentType][0].bug + ".png)");
						
			$(".bugtype").css("border","none");
			
			
			$(".bio-" + currentType + "-wrapper").css("display","block");
			
			
			
			$(this).css("background-image","url(smarty_files/templates/images/BIO/bio_Tribe_Select_over.png)");

			rebuildBugMenu(this);
	

		});
		
		
		
		$("#div-main").css("height","682px");
	
		$(".buglink").click( function(){
			
			$("#bio-wrapper").css("background-image" , "url(smarty_files/templates/images/BIO/bugs/" + this.id + ".png)");
			
			
		var currentBug = conTableFunc( this.id );
		
		$("#bug-bio").html( moxieHash.bugs[currentType][currentBug].bio );	
		
		});		
		
	}
		var firstBugInt = conTableFunc( currentBug );
	
	
	$("#bug-bio").html( moxieHash.bugs[currentType][firstBugInt].bio );	
	$("#bio-wrapper").css("background-image" , "url(smarty_files/templates/images/BIO/bugs/" + currentBug + ".png)");
	
	
		$(".all").css("display","none");
		
		$(".bio-"+currentType+"-wrapper").css("display","block");
	

}
	 	
}

function rebuildBugMenu(obj){
	/*
			$("#bio-fire").removeClass("bugtype-active");
			$("#bio-earth").removeClass("bugtype-active");
			$("#bio-water").removeClass("bugtype-active");
			$("#bio-air").removeClass("bugtype-active");
			
			
			$(this).addClass("bugtype-active");
	*/
			
	$(".bugtype").css("background-image","url(smarty_files/templates/images/BIO/bio_Tribe_Select.png)");

	$(obj).css("background-image","url(smarty_files/templates/images/BIO/bio_Tribe_Select_over.png)");

}

function conTableFunc( bugName ){
	
	var bugConvHash = {
		
		"bug_air_Lividar" : 0,
		"bug_air_Paranida" : 1,
		"bug_air_Somatus" : 2,
		"bug_air_Vespiven" : 3,
		"bug_air_Zeridec" : 4,
		"bug_air_Phorzots" : 5,
		"bug_earth_Augosus" : 0,
		"bug_earth_Elipsid" : 1,
		"bug_earth_Leprosan" : 2,
		"bug_earth_Scaratus" : 3,
		"bug_earth_Siraven" : 4,
		"bug_earth_Tralicud" : 5,
		"bug_fire_Frizakot" : 0,
		"bug_fire_Keophor" : 1,
		"bug_fire_Pacasaur" : 2,
		"bug_fire_Pelmador" : 3,
		"bug_fire_Theraton" : 4,
		"bug_fire_Venovaar" : 5,
		"bug_water_Drixot" : 0,
		"bug_water_Megaphas" : 1,
		"bug_water_Rotigast" : 2,
		"bug_water_Sidon" : 3,
		"bug_water_Tauranon" : 4,
		"bug_water_Zermotor" : 5
		
}
	
	return bugConvHash[bugName];
	
}


function gamesPage() {
	if( $__( $("#div-games" ) ) ){
		$("#div-container").css("height","710px");
		
		if(page == "games"){
			$("#div-main").css("height","540px");	
		}
		else{
		$("#div-main").css("height","600px");
		}
		
			var hasUnity = DetectUnityWebPlayer();
			var brokenUnity = false;
			var path = "http://c1877982.cdn.cloudfiles.rackspacecloud.com/Legend_of_Nara_v1.unity3d";
			//var path ="smarty_files/templates/unity/v1/Legend_of_Nara.unity3d";
			if( hasUnity ){
			$("#div-games-area").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="wmode" value="transparent"/><param name="src" value="' + path + '" /><param name="disableContextMenu" value="true" /><param name="disableFullscreen" value="true" /><embed id="UnityEmbed" src="' + path + '" disableContextMenu="true" disableFullscreen="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.

					if (navigator.appVersion.indexOf("Safari") != -1 ){
						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 ){
								if( document.getElementById("UnityEmbed").GetPluginVersion() == "2.5.0f5" ){
									brokenUnity = true;
								}

							}
						}


			}

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

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

					}
					unityDownloadWebsite();

				}

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

function catalogPage(){

	if( $__( $( "#div-catalog" ) ) ){
		$(".all-bugs").mouseover( function(){
				
			currBug = this.id;
						
				if( $( this ).hasClass("catalog-water") ){
					$("#div-catalog").css("background-image","url(smarty_files/templates/images/catalog/over_glow_waters.jpg)");
				}
				if( $( this ).hasClass("catalog-earth") ){
					$("#div-catalog").css("background-image","url(smarty_files/templates/images/catalog/over_glow_earths.jpg)");
				}
				if( $( this ).hasClass("catalog-fire") ){
					$("#div-catalog").css("background-image","url(smarty_files/templates/images/catalog/over_glow_fires.jpg)");
				}
				if( $( this ).hasClass("catalog-air") ){
					$("#div-catalog").css("background-image","url(smarty_files/templates/images/catalog/over_glow_airs.jpg)");
				}


				var strip_var_left = "375px";

				var strip_var_top = "75px";
						
				$("#div-product-info").html( moxieHash.catalogHover[currBug] ).css({ "left" : strip_var_left , "top" : strip_var_top , "display" : "block" });			
		});
		
		$(".all-bugs").mouseout( function(){
			$("#div-catalog").css("background-image","url(smarty_files/templates/images/catalog/catalog_bg_v2.jpg)");
			$("#div-product-info").html( "" ).css({ "display" : "none" });
		} );
		
		
	}

}

function findPos(obj) {
	var curleft = curtop = 0;
		if (obj.offsetParent) {
				do {
					curleft += obj.offsetLeft;
					curtop += obj.offsetTop;

				} while (obj = obj.offsetParent);

	return [curleft,curtop];
	}	

}


function faqPage() {

	if( $__( $( "#div-faq-box" ) ) ){
		var title = moxieHash.faq.intro[0].title;
		$("#faq-title").html(title);
		
		var obj = moxieHash.faq.body;
		var sOutput = "";
		
		for( x in obj ){
			sOutput += obj[x]["question"];
			sOutput += obj[x]["answer"];
		}
		
		$("#faq-body").html(sOutput);
	}
}

function funFacts() {

	if( $__( $( "#div-funfacts-box" ) ) ){
		
		var header = "<img src=\"" + moxieHash.funfacts.header[0].imgpath + "\" border=\"0\" />";
		$("#funfacts-header").html(header);
		
		var desc = moxieHash.funfacts.intro[0].description;
		$("#funfacts-intro").html(desc);
		
		var obj = moxieHash.funfacts.bug;
		var sOutput = "";
		
		for( x in obj ){
			sOutput += "<img src='" + obj[x]["imgpath"] + "' width=60 height=60 border=0 hspace=5 align=left />";
			sOutput += obj[x]["name"];
			sOutput += obj[x]["description"];
		}
		
		$("#funfacts-body").html(sOutput);
		
	}
}

function funPage() {
	if( $__( $( "#div-fun-box" ) ) ){
		$("#fun-link1-"+language).click( function(){ 		
				var url = "?section=games";
				window.location = url;
		});
		$("#fun-link2-"+language).click( function(){ 		
			var url = "?section=funfacts";
				window.location = url;	
		});
		$("#fun-link3-"+language).click( function(){ 		
				var url = "smarty_files/templates/downloads/screensavers/screensavers.zip";
				window.location = url;			
		});
		$("#fun-link4-"+language).click( function(){ 		
				var url = "smarty_files/templates/downloads/wallpapers/wallpapers.zip";
				window.location = url;			
		});
		
	}
	

}
function checkBioPages(){
	
	if( $__( $( "#girl-menu" ) ) ){
		$(".home-girl-menu").click( function(){ 
				var stringcurrent = this.id.split("-");				
				currentGirl = stringcurrent[1];
			window.location = "?section=moxieteenzbio&girl="+currentGirl;				
		});
	}
	
	if( $__( $( "#div-download-content" ) ) ){
		$("#a-download-screen").click( function(){ 
								
				var url = "smarty_files/templates/downloads/screensavers/screensaver.sfp.zip";
				window.location = url;			
		});
		
		$("#a-download-paper").click( function(){ 
				
				var url = "smarty_files/templates/downloads/wallpapers/wallpaper.jpg.zip";
				window.location = url;				
		});
	}
	
	
	
	
	if( $__( $( "#div-bio-box" ) ) ){
			
	
	}	
	
	
}

function checkFlashContent(){
	
	var params = { wmode : "transparent" };	
	 var attributes = {};

	 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 );

		
                setTimeout( function(){
                if( document.getElementById("flash-bool") ){
                }

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

                } , 2000 );

}


/* Google Analytics */

function logValidation(){
	if(obj.id){
			$("#login").click( function(){
				
				$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1500 , 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
				
		
			$("#logout").click( function(){ 
				$.post("?request=logout",function( ){
					window.location = "";
				});
			} );//end function
		
		
		
			$("#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-left,#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(moxieHash.language.homepage.myaccount);
								$(".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("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" ){
								$("#myacct-header-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{
								$("#myacct-header-left").html(moxieHash.language.homepage.myaccount);
						}

						$(".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{
		$("#login").click( function(){
			$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1500 , function(){
				$("#logon-wrapper").css({ "display" : "block" , "opacity" : "1" });
			});
		});
	}
	
}//end function

function loginRegEvent(){
	regValidateObj.checkDate();

	if( $__( $( "#header-menu-top" ) ) )
	{
		$("#register").click( function( ){ 
					$("#dialog-date").val("yyyy-mm-dd");
					$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1000 , function(){
					$("#overlay-box").css({ "display" : "block" , "opacity" : "1" });
					$("#overlay-dialog").css({ "display" : "block" , "opacity" : "1" });
					$("#UnityObject").addClass("unityhide");
				
					$("#dialog-content-2,#user-info-signup,#user-location-signup,#user-optins").css({"display" : "none" , "opacity" : "1" });

				 } );
		} );
		
		$("#logged-on").click(function(){
			$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1000 , function(){
				$("#login-dialog-wrapper").css({ "display" : "block" , "opacity" : "1" });
			});	
		});
				
		$("#login").click( function(){
			$("#overlay-wrapper").css({ "display" : "block" }).animate({ "opacity" : ".76" ,  "height" : "1135px"} , 1000 , function(){
			
			    $("#login-signin,#ul-logon-signin,#ul-login-forgot").css({ "display" : "block" });
				$("#logon-wrapper , #overlay-login").css({ "display" : "block" , "opacity" : "1" });
				$("#forgot-wrapper").css({ "display" : "none" , "opacity" : "0" } );

				$("#a-logon-forgot").click( function(){
					setTimeout( function(){
						$("#logon-wrapper").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(){
					$("#register").click(); 
					$("#logon-dialog").css("display","none");
				});
		
			
				$(".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();
				});

				
			 });

		});
		
		$("#logout").click( function(){ 
			$.post("?request=logout",function( ){
				window.location = "";
			});
		} );

		$("#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(moxieHash.language.registration.errorcode3); 
					}
					else if( stringBool == 2 ){
						alert(moxieHash.language.registration.errorcode2); 
					}
					else if( stringBool == 0 ){ 
				 		//window.location = "";
					 }
				});

		 } );
	
	}
	
	if( $__( $("#dialog-close") ) ){
		$(".close-btn, #dialog-close, #login-li-dialog-close , #logon-header-close, #forgot-header-right, #forgot-password-close, #update-cancel").click(function(){
			$("#UnityObject").removeClass("unityhide");
			$("#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(moxieHash.language.registration.dialogtitle);

			$("#dialog-content-2, #user-info-signup, #user-location-signup, #user-optins").css({ "display" : "none" , "opacity" : "0" });
			$("#dialog-content").css({ "display" : "block" });
			$("#overlay-dialog").css({ "width" : "385px" , "height" : "230px" });
			$("#reg-save").attr("id","btn-next").html(moxieHash.language.registration.btnnext);

		});
	}

		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(moxieHash.language.forgotpassword.code0);
					}
					else if( http == 1 ){
						alert(moxieHash.language.forgotpassword.code1);
					}
					else if( http == 2 ){
						alert(moxieHash.language.forgotpassword.code2);
					}

			    });

		});
	}


}

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 = moxieHash.language.myaccount.name;
			var productsregistered = moxieHash.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 = moxieHash.language.myaccount.id;
        var name = moxieHash.language.myaccount.name;
        var password = moxieHash.language.myaccount.myacct_password;
		var email = moxieHash.language.myaccount.email;
		var save = moxieHash.language.myaccount.save;
		var cancel = moxieHash.language.myaccount.cancel;
		var pmychildren = moxieHash.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 = moxieHash.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 = moxieHash.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 = moxieHash.stateList[ id ];
	var selectone = moxieHash.language.registration.selectone;
	
	var stringState = "<option id=\"0\">" + 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 = moxieHash.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 "";
	}
}

var badwords = null;

var countryReady = false;

var regValidateObj = { 
	json_send : { } ,
	checkDate : function(){
		$("#btn-next").click( function( ){ 

			$("#dialog-calendar").css({ "display" : "none", "opacity" : "0" });
			$("#user-info-signup").css({ "display" : "block", "opacity" : "1" });

				if($("#dialog-date").val() != "yyyy-mm-dd" ){
					if( badwords != null ){
					regValidateObj.getAccount_type( $("#dialog-date").val() );
					regValidateObj.hideElem();
					regValidateObj.expandBuilt();
					}
					else{
					$.post("?request=loadbadwords",{},function( http ){ badwords = eval( "(" + http + ")" ); });
					regValidateObj.getAccount_type( $("#dialog-date").val() );
					regValidateObj.hideElem();
					regValidateObj.expandBuilt();
					}
				}
				else{
					alert(moxieHash.language.registration.errordob);
				}
		});

        }
	, 

	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");
				regValidateObj.countrybuild();
				countryReady = true;
			}
			else{ 
				$("#user-optins,#user-location-signup,.li-child-email").css("display","block");
				regValidateObj.countrybuild();
				countryReady = true;
			}
	}
	,
	expandBuilt : function(){
		$("#dialog-content , #btn-next").css("display" , "none");
			$("#overlay-dialog").animate({ "width" : "705px" , "height" : "345px" } , 2000 , function(){
				$("#dialog-content-2").css({"display" : "block" , "height" : "260px" });
				$("#btn-next").css("display" , "block").attr("id","reg-save").html(moxieHash.language.registration.btnsubmit);
				$("#dialog-title").html(moxieHash.language.registration.dialogtitle2);
				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(){ 

	if( countryReady == false ){
	var obj = moxieHash.countryList;
	var selectone = moxieHash.language.registration.selectone;
        var stringCountry = "<option id=\"0\" value=\"" + selectone + "\">" + 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 = 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() != moxieHash.language.registration.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() != moxieHash.language.registration.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,4";
		json_send.option_4 = "optins_4,email_my_child,1";
                json_send.dob = "dob," + $("#dialog-date").val();  


		if( arr.length == 0 ){
			$.post("?request=register", json_send , function( http ){
				if( http != "" ){
					var returnObj = eval( "(" + http  + ")" );
					if( returnObj["error"] ){
						//alert( returnObj["error"] );						
						alert(moxieHash.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(moxieHash.language.registration.labelusername + $("#reg-signup-username").val() );
                        $("#span-reg-complete-password").html(moxieHash.language.registration.labelpassword + $("#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 = 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() != moxieHash.language.registration.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() != moxieHash.language.registration.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,4";
                json_send.dob = "dob," + $("#dialog-date").val();  


		if( arr.length == 0 ){
			if( jQuery.trim( $("#reg-signup-email").val() ) == jQuery.trim( $("#reg-signup-parent_email").val() ) ){
				alert(moxieHash.language.registration.erroremailmatch);
			 }
			else{
			$.post("?request=register", json_send , function( http ){
				if( http != "" ){
					var returnObj = eval( "(" + http  + ")" );
					if( returnObj["error"] ){
						//alert( returnObj["error"] );						
						alert(moxieHash.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(moxieHash.language.registration.labelusername + $("#reg-signup-username").val() );
                        $("#span-reg-complete-password").html(moxieHash.language.registration.labelpassword + $("#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 = 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";
                json_send.dob = "dob," + $("#dialog-date").val();  



		if( arr.length == 0 ){
			$.post("?request=register", json_send , function( http ){
				if( http != "" ){
					var returnObj = eval( "(" + http  + ")" );
					if( returnObj["error"] ){
						//alert( returnObj["error"] );						
						alert(moxieHash.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(moxieHash.language.registration.labelusername + $("#reg-signup-username").val() );
                        $("#span-reg-complete-password").html(moxieHash.language.registration.labelpassword + $("#reg-signup-password").val() );

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

					}

				}
			});
		}	
	
	}

}

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 = "******";
		}
	});
}

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").css({ "display" : "block", "opacity" : "1" });			
                        $("#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 googleEventTracker( action , label , value ){
        return pageTracker._trackEvent( "1" , action , label , value );
}

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();
}





