var currentMenuId=0;
var currentChildMenuId;
var mail_address="contact@example.com";
var isLoggedIn=false;
var userinfo="";
var currentId;
var pto_loginState=-1;
var country="";

//$(function(){
//	createPopup("popup.html")
//})

// redirect non-secure requests to secure port for registration, account management and purchase (before page loads).
try {
	var protoc = window.location.protocol.toLowerCase();
	var pathNameU = window.location.pathname;
	var pathName = pathNameU.toLowerCase();
	if (protoc == 'http:' && (pathName == '/registration.html' || pathName == '/manageaccount.html' || pathName == '/purchase.html')) {
		// use location.replace, otherwise you cause an infinite redirection loop hitting back button
		window.location.replace(location.href.replace(/http/i,"https"));
	}
} catch(e) {}

function showCountry(country) {
	if (country === undefined || typeof country == 'undefined' || country == '') return;
	//if (country != 'united states') {
	//	window.location = 'http://home.disney.go.com/guestservices/international';
	//}
}

function ctoTrackPageView(strPageName) {
   try{
     cto.pageName=strPageName;
     cto.track();
   }catch(e){}
}

function ctoTrackPageViewWithLeadType(strPageName, strLeadType) {
   try{
     cto.pageName=strPageName;
	 cto.leadType=strLeadType;
     cto.track();
   }catch(e){alert(e.toString())}
}

function ctoTrackPageViewWithRegistrationFlag(strPageName, strRegFlag) {
   try{
     cto.pageName=strPageName;
	 cto.registration=strRegFlag;
     cto.track();
   }catch(e){alert(e.toString())}
}

function onDataReady(){
	$('.pto_sharePanel_bg').corner("cc:#6ab9da");
	$('.pto_logoutPanel_bg').corner("cc:#6ab9da");
	$('.pto_loginPanel_bg').corner("cc:#6ab9da");
	$('.pto_menuList_container_cell').corner();
	$('.pto_subNavi_container_cell').corner();
}

function onPageLoaded(){
	if($.browser.msie && $.browser.version<7){
		try{
			DD_belatedPNG.fix('.pto_mainContainer a,.pto_mainContainer div');
			//DD_belatedPNG.fix('*');
		}catch(e){
			//DD_belatedPNG.fix('*');
		}
		$('.pto_pageContainer').css('display','')
	}
	//alert('loginPanel>>>:'+$('.pto_loginPanel_bg').css('display')+"/"+$('.pto_logoutPanel_bg').css('display'))

	//var loggedIn = getLoginStatus();
	//alert('loggedIn: '+loggedIn);

	//pto_setLoginState()
}

// provide a getter
function pto_getLoginState(){
return pto_loginState
}

//login function start
function pto_setLoginState(loggedIn){
	pto_loginState = loggedIn;
	//if (getCookie('SWID')!=null){
	if (loggedIn==2){
		$('.pto_loginPanel_bg').css('display','block')
		$('.pto_logoutPanel_bg').css('display','none')

		if($('.pto_menuList li').eq(0).find('a').hasClass('pto_currentNavi')==true){
			$('.pto_menuList li').eq(0).replaceWith('<li><a href="http://preschooltime.go.com/member.html" class="pto_menuList_container_cell pto_currentNavi">Home</a></li>')
		}else{
			$('.pto_menuList li').eq(0).replaceWith('<li><a href="http://preschooltime.go.com/member.html" class="pto_menuList_container_cell ">Home</a></li>')
		}

		if($('.pto_menuList li').eq(2).find('a').hasClass('pto_currentNavi')==true){
			$('.pto_menuList li').eq(2).replaceWith('<li><a href="https://preschooltime.go.com/manageaccount.html" class="pto_menuList_container_cell pto_currentNavi">My Account</a></li>')
		}else{
			$('.pto_menuList li').eq(2).replaceWith('<li><a href="https://preschooltime.go.com/manageaccount.html" class="pto_menuList_container_cell">My Account</a></li>')
		}

		$('.pto_menuList_container_cell').corner();
	} else if (loggedIn==1){
		$('.pto_loginPanel_bg').css('display','block')
		$('.pto_logoutPanel_bg').css('display','none')

		if($('.pto_menuList li').eq(0).find('a').hasClass('pto_currentNavi')==true){
			$('.pto_menuList li').eq(0).replaceWith('<li><a href="http://preschooltime.go.com/member.html" class="pto_menuList_container_cell pto_currentNavi">Home</a></li>')
		}else{
			$('.pto_menuList li').eq(0).replaceWith('<li><a href="http://preschooltime.go.com/member.html" class="pto_menuList_container_cell ">Home</a></li>')
		}

		if($('.pto_menuList li').eq(2).find('a').hasClass('pto_currentNavi')==true){
			$('.pto_menuList li').eq(2).replaceWith('<li><a href="http://preschooltime.go.com/membership.html" class="pto_menuList_container_cell pto_currentNavi">Membership</a></li>')
		}else{
			$('.pto_menuList li').eq(2).replaceWith('<li><a href="http://preschooltime.go.com/membership.html" class="pto_menuList_container_cell">Membership</a></li>')
		}

		$('.pto_menuList_container_cell').corner();
	} else {
		if (loggedIn==0){
			if (window.location.pathname == "/member.html"){window.location = "http://preschooltime.go.com/"}
		}
		$('.pto_loginPanel_bg').css('display','block')
		$('.pto_logoutPanel_bg').css('display','none')

		if($('.pto_menuList li').eq(0).find('a').hasClass('pto_currentNavi')==true){
			$('.pto_menuList li').eq(0).replaceWith('<li><a href="http://preschooltime.go.com/" class="pto_menuList_container_cell pto_currentNavi">Home</a></li>')
		}else{
			$('.pto_menuList li').eq(0).replaceWith('<li><a href="http://preschooltime.go.com/" class="pto_menuList_container_cell ">Home</a></li>')
		}

		if($('.pto_menuList li').eq(2).find('a').hasClass('pto_currentNavi')==true){
			$('.pto_menuList li').eq(2).replaceWith('<li><a href="http://preschooltime.go.com/membership.html" class="pto_menuList_container_cell pto_currentNavi">Membership</a></li>')
		}else{
			$('.pto_menuList li').eq(2).replaceWith('<li><a href="http://preschooltime.go.com/membership.html" class="pto_menuList_container_cell">Membership</a></li>')
		}

		$('.pto_menuList_container_cell').corner();

	}
	startWidgets();
}

function startWidgets() {
	var pathNameU = window.location.pathname;
	var pathName = pathNameU.toLowerCase();
	// Check path name to see which SWFs should be loaded
	// Play Arrow
	if (pathName == '/' || pathName == '/index.html' || pathName == '/about-faqs.html' || pathName == '/contacts.html' || pathName == '/feedback.html' || pathName =='/getting-started-faqs.html' || pathName =='/install.html' || pathName == '/livechat.html' || pathName == '/manageaccount.html' || pathName == '/member.html' || pathName == '/membership.html' || pathName =='/membershipcongrats.html' || pathName == '/membership-faqs.html' || pathName == '/news.html' || pathName =='/overview.html' || pathName == '/pagenotfound.html' || pathName == '/paypalerror.html' || pathName == '/purchase.html' || pathName == '/registration.html' || pathName == '/report_bug.html' || pathName == '/returning-members-faqs.html' || pathName == '/technical-help-faqs.html' || pathName == '/thanks.html' || pathName == '/usagereport.html' || pathName == '/what-is-it.html') {
		attributes = {};
		if (pathName == '/purchase.html' || pathName == '/registration.html' || pathName == '/manageaccount.html' || pathName =='/membershipcongrats.html' || pathName == '/paypalerror.html') {
			flashvars = {uiswf:"https://s.dolimg.com/preschooltime/global/en/swf/pto_play_arrow.swf",regconfig:"https://s.dolimg.com/preschooltime/global/en/swf/registration.xml",w:"202",h:"137"};
			params = {menu:"false",wmode:"transparent",allowScriptAccess:"always"};
			swfobject.embedSWF("https://s.dolimg.com/preschooltime/global/en/swf/pto_play_button.swf", "pto_ArrowPlayBtn", "202", "137", "9.0.0", "https://s.dolimg.com/preschooltime/global/en/swf/expressInstall.swf", flashvars, params, attributes);
		} else {
			flashvars = {uiswf:"http://cdn.dol.dolimg.com/preschooltime/global/en/swf/pto_play_arrow.swf",regconfig:"http://cdn.dol.dolimg.com/preschooltime/global/en/swf/registration.xml",w:"202",h:"137"};
			params = {menu:"false",wmode:"transparent",allowScriptAccess:"always"};
			swfobject.embedSWF("http://cdn.dol.dolimg.com/preschooltime/global/en/swf/pto_play_button.swf", "pto_ArrowPlayBtn", "202", "137", "9.0.0", "http://cdn.dol.dolimg.com/preschooltime/global/en/swf/expressInstall.swf", flashvars, params, attributes);
		}
	}
	// Play Ad
	if (pathName == '/about-faqs.html' || pathName == '/feedback.html' || pathName =='/getting-started-faqs.html' || pathName =='/livechat.html' || pathName =='/membership.html' || pathName =='/membership-faqs.html' || pathName =='/news.html' || pathName =='/overview.html' || pathName =='/report_bug.html' || pathName =='/returning-members-faqs.html' || pathName =='/technical-help-faqs.html' || pathName =='/what-is-it.html') {
		attributes = {};
		flashvars = {uiswf:"http://cdn.dol.dolimg.com/preschooltime/global/en/swf/pto_play_ad.swf",regconfig:"http://cdn.dol.dolimg.com/preschooltime/global/en/swf/registration.xml",w:"208",h:"214"};
		params = {menu:"false",wmode:"transparent",allowScriptAccess:"always"};
		swfobject.embedSWF("http://cdn.dol.dolimg.com/preschooltime/global/en/swf/pto_play_button.swf", "ad_play_btn", "208", "214", "9.0.0", "http://cdn.dol.dolimg.com/preschooltime/global/en/swf/expressInstall.swf", flashvars, params, attributes);
	}
	// Play Flag
	if (pathName == '/' || pathName == '/index.html') {
		attributes = {};
		flashvars = {uiswf:"http://cdn.dol.dolimg.com/preschooltime/global/en/swf/pto_play_flag.swf",regconfig:"http://cdn.dol.dolimg.com/preschooltime/global/en/swf/registration.xml",w:"259",h:"122"};
		params = {menu:"false",wmode:"transparent",allowScriptAccess:"always"};
		swfobject.embedSWF("http://cdn.dol.dolimg.com/preschooltime/global/en/swf/pto_play_button.swf", "pto_playFlag", "259", "122", "9.0.0", "http://cdn.dol.dolimg.com/preschooltime/global/en/swf/expressInstall.swf", flashvars, params, attributes);
	}
	// Play Lozenge/Pill
	if (pathName == '/member.html' || pathName =='/news.html') {
		//attributes = {};
		flashvars = {uiswf:"http://cdn.dol.dolimg.com/preschooltime/global/en/swf/pto_play_lozenge.swf",regconfig:"http://cdn.dol.dolimg.com/preschooltime/global/en/swf/registration.xml",w:"205",h:"100"};
		params = {menu:"false",wmode:"transparent",allowScriptAccess:"always"};
		if (pathName == '/member.html') {
			swfobject.embedSWF("http://cdn.dol.dolimg.com/preschooltime/global/en/swf/pto_play_button.swf", "pto_member_play_btn", "205", "100", "9.0.0", "http://cdn.dol.dolimg.com/preschooltime/global/en/swf/expressInstall.swf", flashvars, params, attributes);
		}
		if (pathName == '/news.html') {
			swfobject.embedSWF("http://cdn.dol.dolimg.com/preschooltime/global/en/swf/pto_play_button.swf", "pto_news_play_btn", "205", "100", "9.0.0", "http://cdn.dol.dolimg.com/preschooltime/global/en/swf/expressInstall.swf", flashvars, params, attributes);
		}
	}
	// Install Module
	if (pathName == '/install.html') {
		attributes = {base:"."};
		flashvars = {regconfig:"http://cdn.dol.dolimg.com/preschooltime/global/en/swf/registration.xml",uiswf:"http://cdn.dol.dolimg.com/preschooltime/global/en/swf/pto_install_gui.swf",airURL:"http://cdn.dol.dolimg.com/preschooltime/air/DisneyPreschoolTime1.4.6.air",airswfURL:"http://airdownload.adobe.com/air/browserapi/air.swf",runver:"1.4"};
		params = {menu:"false",wmode:"transparent",allowScriptAccess:"always"};
		swfobject.embedSWF("http://cdn.dol.dolimg.com/preschooltime/global/en/swf/pto_install.swf", "pto_installContainer", "693", "593", "9.0.0", "http://cdn.dol.dolimg.com/preschooltime/global/en/swf/expressInstall.swf", flashvars, params, attributes);
	}
	// Manage Account Module
	if (pathName == '/manageaccount.html') {
		attributes = {base:"."};
		flashvars = {flow:"accountmanagement",regconfig:"https://s.dolimg.com/preschooltime/global/en/swf/registration.xml",swfurl:"https://s.dolimg.com/preschooltime/global/en/swf/pto_registration_browser_gui.swf",w:"693",h:"593"};
		params = {menu:"false",wmode:"transparent",allowScriptAccess:"always"};
		swfobject.embedSWF("https://s.dolimg.com/preschooltime/global/en/swf/pto_accountmanagement.swf", "pto_purchaseContainer", "693", "593", "9.0.0", "https://s.dolimg.com/preschooltime/global/en/swf/expressInstall.swf", flashvars, params, attributes);
	}
	// Purchase/Registration Module
	if (pathName == '/purchase.html' || pathName == '/registration.html') {
		attributes = {base:"."};
		params = {menu:"false",wmode:"transparent",allowScriptAccess:"always"};
		if (pathName == '/purchase.html') {
			flashvars = {regconfig:"https://s.dolimg.com/preschooltime/global/en/swf/registration.xml",uiswf:"https://s.dolimg.com/preschooltime/global/en/swf/pto_registration_browser_gui.swf",flow:"purchase"};
			swfobject.embedSWF("https://s.dolimg.com/preschooltime/global/en/swf/pto_registration.swf", "pto_purchaseContainer", "693", "593", "9.0.0", "https://s.dolimg.com/preschooltime/global/en/swf/expressInstall.swf", flashvars, params, attributes);
		}
		if (pathName == '/registration.html') {
			flashvars = {regconfig:"https://s.dolimg.com/preschooltime/global/en/swf/registration.xml",uiswf:"https://s.dolimg.com/preschooltime/global/en/swf/pto_registration_browser_gui.swf"};
			swfobject.embedSWF("https://s.dolimg.com/preschooltime/global/en/swf/pto_registration.swf", "pto_registrationContainer", "693", "593", "9.0.0", "https://s.dolimg.com/preschooltime/global/en/swf/expressInstall.swf", flashvars, params, attributes);
		}
	}
	// Usage Report Module
	if (pathName == '/usagereport.html') {
		attributes = {base:"."};
		flashvars = {uiswf:"http://cdn.dol.dolimg.com/preschooltime/global/en/swf/pto_usagereport_gui.swf"};
		params = {menu:"false",wmode:"transparent",allowScriptAccess:"always"};
		swfobject.embedSWF("http://cdn.dol.dolimg.com/preschooltime/global/en/swf/pto_usagereport.swf", "pto_useagereportContainer", "693", "593", "9.0.0", "http://cdn.dol.dolimg.com/preschooltime/global/en/swf/expressInstall.swf", flashvars, params, attributes);
	}
	// Video Player (Home)
	if (pathName == '/' || pathName =='/index.html') {
		attributes = {};
		params = {menu:"false",wmode:"transparent",scale:"noScale",salign:"TOP_Left"};
		swfobject.embedSWF("http://cdn.dol.dolimg.com/preschooltime/global/en/swf/videoPlayer.swf?videoLoop=false&server=rtmp://wdigplayhs.fcod.llnwd.net/a3558/d1&vname=preschool_time/phd/marketingsizzle", "pto_flash_content", "320", "240", "10.0.0", "http://cdn.dol.dolimg.com/preschooltime/global/en/swf/expressInstall.swf", flashvars, params, attributes);
	}
	// Video Player (What Is It?)
	if (pathName == '/what-is-it.html') {;
		attributes = {};
		flashvars = {};
		//params = {menu:"false",wmode:"transparent",allowScriptAccess:"always"}
		params = {menu:"false",wmode:"transparent",scale:"noScale",salign:"TOP_Left",allowScriptAccess:"always"};
		swfobject.embedSWF("http://cdn.dol.dolimg.com/preschooltime/global/en/swf/videoPlayer.swf?videoLoop=false&server=rtmp://wdigplayhs.fcod.llnwd.net/a3558/d1&vname=preschool_time/phd/parentssizzle", "pto_flash_content", "490", "368", "10.0.0", "http://cdn.dol.dolimg.com/preschooltime/global/en/swf/expressInstall.swf", flashvars, params, attributes);
	}

	// Load DC Logo on all pages
	/*
	if (pathName == '/purchase.html' || pathName == '/registration.html' || pathName == '/manageaccount.html' || pathName =='/membershipcongrats.html' || pathName == '/paypalerror.html') {
		attributes = {};
		flashvars = {uiswf:"https://s.dolimg.com/preschooltime/global/en/img/dclogo.png",regconfig:"https://s.dolimg.com/preschooltime/global/en/swf/registration.xml",w:"208",h:"89"};
		params = {menu:"false",wmode:"transparent",allowScriptAccess:"always"};
		swfobject.embedSWF("https://s.dolimg.com/preschooltime/global/en/swf/dclogo.swf", "pto_disneyConnection", "208", "89", "9.0.0", "https://s.dolimg.com/preschooltime/global/en/swf/expressInstall.swf", flashvars, params, attributes);
	} else {
		attributes = {};
		flashvars = {uiswf:"http://cdn.dol.dolimg.com/preschooltime/global/en/img/dclogo.png",regconfig:"http://cdn.dol.dolimg.com/preschooltime/global/en/swf/registration.xml",w:"208",h:"89"};
		params = {menu:"false",wmode:"transparent",allowScriptAccess:"always"};
		swfobject.embedSWF("http://cdn.dol.dolimg.com/preschooltime/global/en/swf/dclogo.swf", "pto_disneyConnection", "208", "89", "9.0.0", "http://cdn.dol.dolimg.com/preschooltime/global/en/swf/expressInstall.swf", flashvars, params, attributes);
	}
	*/

}
function pto_logout(){}

function pto_login(){}
//login function end

function showDetail(id){
	if(currentId!=null){
		if(currentId!=id){
			$('#node'+currentId).find('.pto_list_detail').css('display','none');
			$('#node'+currentId).find('.pto_spacing3').css('backgroundPosition','0px -3px');
			autoExtendBackground()
		}
	}
	if(currentId==id){
		$('#node'+currentId).find('.pto_list_detail').css('display','none');
		$('#node'+currentId).find('.pto_spacing3').css('backgroundPosition','0px -3px');
		currentId=null
		autoExtendBackground()
	}else{
		$('#node'+id).find('.pto_list_detail').css('display','block');
		$('#node'+id).find('.pto_spacing3').css('backgroundPosition','0px -43px');
		currentId=id
		autoExtendBackground()
	}
}

function showDetailautoExtendBackground(id){
	if(currentId!=null){
		if(currentId!=id){
			$('#node'+currentId).find('.pto_list_detail').css('display','none');
			$('#node'+currentId).find('.pto_spacing3').css('backgroundPosition','0px -3px');
			//$('#node'+currentId).find('.pto_list_title a').css('fontWeight','normal');
			autoExtendBackground()
		}
	}
	if(currentId==id){
		$('#node'+currentId).find('.pto_list_detail').css('display','none');
		$('#node'+currentId).find('.pto_spacing3').css('backgroundPosition','0px -3px');
		//$('#node'+currentId).find('.pto_list_title a').css('fontWeight','normal');
		autoExtendBackground()
		currentId=null
	}else{
		$('#node'+id).find('.pto_list_detail').css('display','block');
		$('#node'+id).find('.pto_spacing3').css('backgroundPosition','0px -43px');
		//$('#node'+id).find('.list_title a').css('fontWeight','bold');
		currentId=id
		autoExtendBackground()
	}
}

function autoExtendBackground(){
	var num=Number($('.pto_left_mid_container').height())
	var str1=String(num+660+'px')
	var str2=String(num+600+'px')
	var str3=String(num+600+'px')

	$('.pto_pageFooterBar').css('top',str1)
	$('.pto_pageContainer_mid_mid').css('height',str3)
	$('.pto_pageContainer_side_left').css('height',str3)
	$('.pto_pageContainer_side_right').css('height',str3)
    // alert($('.pto_pageContainer').css('height'))
}

//run*******************************************
//cookie functions=======================
function SetCookie(name,value){
	var Days = 30;
	var exp  = new Date();    //new Date("December 31, 9998");
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+"path=/;domain=go.com";
}

function getCookie(name){
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null) return unescape(arr[2]); return null;
}

function delCookie(name){
	var exp = new Date();
	exp.setTime(exp.getTime() - 100000);
	var cval=getCookie(name);
	if(cval!=null) document.cookie= name + "="+cval+";expires=Thu, 01-Jan-1970 00:00:01 GMT;path=/;domain=go.com";
}

//popup element init
function createPopup(cLink){
	var popupBox=document.createElement("div")
	$(popupBox).attr('id',"popupBox")
	$('body').append(popupBox)
	//load
	$.ajax({
		type: "get",
		url: cLink,
		data:"",
		cache: true,
		success: function(html){
			$('#popupBox').html(html);
			initPopup()
		}
	});
	//end load
}
//email popup function

function openEmailPopup(){
	$("#dialog-form").dialog( "enable" )
	$('#dialog-form').dialog('open');
}
function openGiftPopup(){
	$("#gift_popup").dialog("open");
}


function ptoGuestModule(){

	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window["pto_loginPanel"] : document["pto_loginPanel"];
}

function getProductContext(){
	return ptoGuestModule().getProductContext();
}

function getUserStatus(){
	return ptoGuestModule().getUserStatus();
}

function initPopup(){
	// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
	$("#dialog-form").dialog("destroy");

	var name = $("#merge-first_name"),
		fname = $("#merge-friend_name"),
		friend_email = $("#toAddress"),
		allFields = $([]).add(name).add(fname).add(friend_email),
		tips = $(".validateTips");

	function updateTips(t) {
		tips
			.text(t)
			.addClass('ui-state-highlight');
		setTimeout(function() {
			tips.removeClass('ui-state-highlight', 1500);
		}, 500);
	}

	function checkLength(o,n,min,max) {
		if ( o.val().length > max || o.val().length < min ) {
			o.addClass('ui-state-error');
			updateTips("Length of " + n + " must be between "+min+" and "+max+".");
			return false;
		} else {
			return true;
		}
	}

	function checkRegexp(o,regexp,n) {
		if ( !( regexp.test( o.val() ) ) ) {
			o.addClass('ui-state-error');
			updateTips(n);
			return false;
		} else {
			return true;
		}
	}


	$("#dialog-form").dialog({
		autoOpen: false,
		height: 480,
		width: 620,
		modal: true,
		zIndex:99999999,
		buttons: {
			'Send Email': function() {
				var bValid = true;
				allFields.removeClass('ui-state-error');

				bValid = bValid && checkLength(name,"Your Name",3,16);
				bValid = bValid && checkLength(fname,"Your Friend's Name",3,16);
				bValid = bValid && checkLength(friend_email,"Your Friend's E-mail Address",6,80);

				bValid = bValid && checkRegexp(name,/^[a-z]([a-z_])+$/i,"Name may consist of a-z, A-Z, with no spaces.");
				bValid = bValid && checkRegexp(fname,/^[a-z]([a-z_])+$/i,"Friend's name may consist of a-z, A-Z, with no spaces.");
				bValid = bValid && checkRegexp(friend_email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"eg. name@example.com");

				if (bValid) {
					$('#users tbody').append('<tr>' +
						'<td>' + name.val() + '</td>' +
						'<td>' + fname.val() + '</td>' +
						'<td>' + friend_email.val() + '</td>' +
						'</tr>');
					$('#shareForm').submit();
					$(this).dialog('close');

					//**replace the code to POST DATA TO Y0UR SERVER. start
					$("#email-success").dialog('open');
					//**replace the code to POST DATA TO Y0UR SERVER. end
				}
			},
			Cancel: function() {
				$(this).dialog('close');
			}
		},
		close: function() {
			$("#dialog-form").dialog( "disable" )
			allFields.val('').removeClass('ui-state-error');
		}
	});

	//******************************************************************
	// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
	$("#email-success").dialog("destroy");
	$("#email-success").dialog({
		autoOpen: false,
		modal: true,
		height:200,
		width:520,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			}
		}
	});
	$("#gift_popup").dialog("destroy");
	$("#gift_popup").dialog({
		autoOpen: false,
		modal: false,
		height:"auto",
		width:"auto",
		resizable: false,
		zIndex:99999999
	});

	$("#dialog-form").dialog( "disable" )

//******************************************************************
}

function openWindow(path,_width,_height){

	 var _window=window.open (path,'',"height="+_height+" , width="+_width+", top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");
	 if(_window=="[object]") {
		_window.focus();
	}

}

function processState(st) {
	alert(st)
	}

function openPopup() {
	var path = 'http://preschooltime.go.com/share.html';
	var _width = 630;
	var _height = 480;
	var _left = (screen.width) ? (screen.width-_width)/2 : 0;
	var _top = (screen.height) ? (screen.height-_height)/2 : 0;

	var _window=window.open (path,'',"height="+_height+" , width="+_width+", top="+_top+", left="+_left+", toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");
	 if(_window=="[object]") {
		_window.focus();
	}
}

function openPopupFB() {
	var path = 'http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.preschooltime.com&t=Disney%20Preschool%20Time%20Online&src=sp';
	var _width = 630;
	var _height = 480;
	var _left = (screen.width) ? (screen.width-_width)/2 : 0;
	var _top = (screen.height) ? (screen.height-_height)/2 : 0;

	var _window=window.open (path,'',"height="+_height+" , width="+_width+", top="+_top+", left="+_left+", toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");
	 if(_window=="[object]") {
		_window.focus();
	}
}

function cssButtonSwap(clazz, overCbFn, outCbFn) {
	$(clazz).mouseover(function() {
		var url = $(this).css('background-image');
		$(this).css('background-image', url.replace("_off","_on"));
		if (overCbFn) { try { overCbFn.call($(this)); } catch(e) {} }
	}).mouseout(function() {
		var url = $(this).css('background-image');
		$(this).css('background-image', url.replace("_on","_off"));
		if (outCbFn) { try { outCbFn.call($(this)); } catch(e) {} }
	});
}

// requires master_flash_light.js
function tryDetectFlash(version, intervalMs, secure, maxAttempts) {
	var max = (maxAttempts > 0) ? maxAttempts : 1;
	var tries = 0;
	var handle = null;
	var protocol = (secure) ? 'https' : 'http';
	function detectFlash() {
		try {
			DetectFlash(version,protocol+"://preschooltime.go.com/flashdetect.html");
			if ( (handle != null) || (tries > max)) { window.clearInterval(handle); }
		} catch(e) { 
			if (handle == null) {
				handle = window.setInterval("detectFlash()", intervalMs); 
			} else {
				max++;
			}
		}
	}
}

