

function ShowMasterLoginDisabledPopup()
{
	var dialogDivId = 'loginDisabledPopup';
	var subst = {
			JsCallClose: jQuery.ark.dialog.jsCallClose(dialogDivId),
			OkButtonId: dialogDivId + 'OKButton',
			MouseOverClass: "'PopUp_Login_btn_hov';",
			MouseOutClass: "'PopUp_Login_btn';"
		};
	jQuery.ark.dialog.open('arkDialog', dialogDivId, 'Login failed!',
		tmpl('loginDisabledDialogContent', subst));
	
	document.getElementById(subst.OkButtonId).focus();
}

function ShowMasterLoginFailPopup()
{
    jQuery('#loginPopUpResult').text("Login failed! The email address or password incorrect. Please try again!");
    jQuery('#loginPopUpResult').show();
}

function ShowMasterCookiesDisabledPopup()
{
	var dialogDivId = 'loginFailPopup';
	var subst = {
			JsCallClose: jQuery.ark.dialog.jsCallClose(dialogDivId),
			OkButtonId: dialogDivId + 'OKButton',
			MouseOverClass: "'PopUp_Login_btn_hov';",
			MouseOutClass: "'PopUp_Login_btn';"
		};
	jQuery.ark.dialog.open('arkDialog', dialogDivId, 'Login failed!',
		tmpl('cookiesDisabledDialogContent', subst));
	document.getElementById(subst.OkButtonId).focus();
}

function SetDefaultColors()
{
	if(document.getElementById('popupLogin$email')) {
		document.getElementById('popupLogin$email').style.backgroundColor = '#ffffff';
	}
	if(document.getElementById('popupLogin$password')) {
		document.getElementById('popupLogin$password').style.backgroundColor = '#ffffff';
	}
	if(document.getElementById('popupForgotPass$email')) {
		document.getElementById('popupForgotPass$email').style.backgroundColor = '#ffffff';
	}
  
}
function popupLogin_loginClick()
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	emailValue = document.getElementById('popupLogin$email').value;
	passwordValue = document.getElementById('popupLogin$password').value;
	if (emailValue != '' && reg.test(emailValue) && passwordValue != '')
	{
		ProcessLoginCall(document.getElementById('popupLogin$email').value, document.getElementById('popupLogin$password').value, document.getElementById('popupLogin$remember').checked, null,
    function() { ShowMasterLoginFailPopup(); },
    function() { jQuery.ark.dialog.close('popupLogin_popupDialog'); ShowMasterLoginDisabledPopup(); },        
    function() { jQuery.ark.dialog.close('popupLogin_popupDialog'); });

	}
	else
	{
		if(passwordValue == '')
		{
            jQuery('#loginPopUpResult').text("Password should not be empty");
            jQuery('#loginPopUpResult').show();
			document.getElementById('popupLogin$password').style.backgroundColor = '#ff6d6d';
		}
		if (emailValue == '' || !reg.test(emailValue))
		{
            jQuery('#loginPopUpResult').text("Enter valid email address");
            if(passwordValue == ''){
                jQuery('#loginPopUpResult').text(jQuery('#loginPopUpResult').text() +" And "+ "password should not be empty");
            }
            jQuery('#loginPopUpResult').show();
			document.getElementById('popupLogin$email').style.backgroundColor = '#ff6d6d';
		}
	}
}
function popupLogin_cancelClick(cancelAction)
{
    
    if (cancelAction) { cancelAction(); }
	jQuery.ark.dialog.close('popupLogin_popupDialog');
    try{
        jQuery("#gHtmlLog").hide();
    }
    catch (err) { }
    if (this.isGame == true){
   
        if (this.isSlot == false){
            prerollStartTC();
        }
    }
}

function popupForgotPass_forgotClick()
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	emailValue = document.getElementById('popupForgotPass$email').value;
	if (emailValue != '' && reg.test(emailValue))
	{
		var forgotPass = new ForgotPassword(
			'popupForgotPass$email',
			'popupForgotPass_ErrorMsgDivId',
			'ForgotPassword');
		forgotPass.ProcessJSSubmitClick('http://www.greatdaygames.com/ajaxServices/ForgotPass.aspx', 
			"popupForgotPass_cancelClick('');", document.getElementById('popupForgotPass_ErrorMsgDivId'));
		//popupForgotPass_cancelClick('');
	}
	else
	{
		if (emailValue == '' || !reg.test(emailValue))
		{
			document.getElementById('popupForgotPass$email').style.backgroundColor = '#ff6d6d';
		}
	}
}
function popupForgotPass_cancelClick(cancelAction)
{
	if (cancelAction) { cancelAction(); }
	jQuery.ark.dialog.close('popupForgotPass_popupDialog');
}

function popupChest_cancelClick(cancelAction){
   
    if (cancelAction) { cancelAction(); }
	jQuery.ark.dialog.close('popupChest_popupDialog');
     if (this.isGame == true && this.isSlot == false){
        prerollStartTC();
    }
    if (isClosedBeforeEnd == true){
         googleTags('gdg/tc/cancel', "Treats|Treasure Chest Cancel");
    }
    if (isTcRegistration == true){
        googleTags('gdg/tc/no register_login', "Treats|Treasure Chest Cancel after Play");
    }
    
}

function SetHideErrorInfo(){
    jQuery('#loginPopUpResult').hide();
}

jQuery(document).ready(function(){
  // debugger;
  
});

if (jQuery) (function(jQuery) {
	//jQuery.extend(jQuery.ark, { tmpl: function() { } });

    
    jQuery.extend(jQuery.ark.tmpl, {
		popupLogin: '\
        <div class="login_popUp_width">\
        <div class="login_popUnBlocks coll" style="margin-left:20px;">\
        <div class="not_a_mem">Login to your Great Day Games Account!</div>\
            <div id="loginPopUpResult" class="loginPopUpResult_text" style="display:none" ></div>\
            <div class="login_block_fields">\
            <div class="coll">Email:</div>\
            <input class="PopUp_Login_EmailIn" type="text" id="popupLogin$email" tabindex="11"\
					onkeypress="javascript:SetDefaultColors(); {if (event.keyCode==13){popupLogin_loginClick();}}"\
					onfocus="javascript:SetDefaultColors();" value="<@= Email @>" />\
            </div>\
            <div class="login_block_fields">\
			<div class="coll">Password:</div>\
			<input class="PopUp_Login_EmailIn" type="password" id="popupLogin$password" tabindex="12"\
					onkeypress="javascript:SetDefaultColors(); {if (event.keyCode==13){popupLogin_loginClick();}}"\
					onfocus="javascript:SetDefaultColors();"  value="<@= PWD @>" />\
			</div>\
            <div class="endCol"></div>\
			<a href="" class="forgot coll" onclick="javascript:popupLogin_cancelClick();OpenPopupForgot();return false;" tabindex="16">Forgot my Password</a>\
			<div class="endCol"></div>\
            <div class="login_block_rem">\
			<input class="coll" type="checkbox" id="popupLogin$remember" tabindex="13" <@= CHK @> />\
            <span class="coll">Remember Me</span>\
            </div>\
			<div class="endCol"></div>\
            <div class="login_btn_inp">\
            <input type="button" value="Login" class="PopUp_Login_btn" tabindex="13" onclick="SetHideErrorInfo(); popupLogin_loginClick();"\
			onmouseover="javascript:this.className=<@= MouseOverClass @> return false;"\
			onmouseout="javascript:this.className=<@= MouseOutClass @> return false;" />\
            </div>\
        </div>\
        <div class="PopUp_Login_delim coll"></div>\
        <div class="login_popUnBlocks colr">\
        <div class="not_a_mem">Not a GreatDayGames member?</div>\
			<a href="javascript:popupLogin_cancelClick();OpenPopupRegister();void(0);"  class="forgot" style="font-size:15px;" tabindex="15">Join now - It\'s Free!</a>\
        <div class="login_delim_hor"></div>\
        <div class="not_a_mem">Login Now with Facebook!</div>\
        <div class="fb_pop_up_cont">\
		    <@= AdditionalText @>\
            <script type="text/javascript">                initFB();</script>\
           <a href="#" onclick="facebooklogin(function(){checkFBAuth();}); return false;" style="margin-left:90px;" class="fb_connect_button coll"></a>\
        </div>\
        </div>',
		popupForgotPass: '\
		<div class="login_popUnBlocks" style="width:420px;">\
			<div class="login_block_fields">\
            <div class="coll">Email:</div>\
			<input class="PopUp_Login_EmailIn" type="text" id="popupForgotPass$email" tabindex="11"\
					onkeypress="javascript:SetDefaultColors(); {if (event.keyCode==13){popupForgotPass_forgotClick();}}"\
					onfocus="javascript:SetDefaultColors();" />\
			</div>\
            <div class="delim_new_login"></div>\
			<div class="coll endCol home_Forgot_errorMessage" id="popupForgotPass_ErrorMsgDivId" style="display:none; width:190px;"></div>\
				<a href="javascript:popupForgotPass_cancelClick();OpenPopupRegister();void(0);" class="PopUp_Login_Urls" tabindex="15">Not a member? Register here.</a>\
				<a href="" class="PopUp_Login_Urls" onclick="javascript:popupForgotPass_cancelClick();OpenPopupLogin();return false;" tabindex="16">Return to login</a>\
			<div class="endCol" style="margin-bottom:10px;"></div>\
				<input type="button" value="OK" class="PopUp_Login_btn" tabindex="13" onclick="popupForgotPass_forgotClick();"\
					onmouseover="javascript:this.className=<@= MouseOverClass @> return false;"\
					onmouseout="javascript:this.className=<@= MouseOutClass @> return false;" />\
				<input type="button" value="Cancel" class="PopUp_Login_btn" onclick="popupForgotPass_cancelClick(<@= CancelAction @>);" tabindex="14"\
					onmouseover="javascript:this.className=<@= MouseOverClass @> return false;"\
					onmouseout="javascript:this.className=<@= MouseOutClass @> return false;" />\
        </div>',
         popupChest: '\
        <div id="dChest" style="height:500px; width:720px;background-color:#00b3ec"> \
        <script type="text/javascript">            initChest();</script>\
        </div>',
		loginPopupDummy: 0
       
	});
})(jQuery);

function initChest(){
        var dChest = jQuery('#dChest');
        var url = 'http://www.greatdaygames.com/ajaxServices/TreasureChestService/TreasureChest.aspx?' + Math.random()*99999;
        dChest.load(url);
        jQuery(".PopUp_content").attr("style", "padding: 0 0 0 0");
}


function LoadData(idDiv, urlData)
{
    var obj = jQuery('#'+ idDiv);
    if(typeof obj != 'undefined'){
        var url = urlData;
        obj.load(url);
    }
}

function ExecFunction(name){
    jQuery(document).ready(
        function(){
            if(typeof name == 'function') { name(); }
        }
    );
}

function CloseTrChaest()
{
    jQuery.ark.dialog.close('PlatformGetTreats');
    //jQuery("#gameVersionSelectorID").attr("style", "display:none;");
}

function OpenPopupNotTreats(count)
{
    jQuery.ark.dialog.open('arkDialog', 'PlatformGetTreats', '', tmpl('<div class="treasure_sorry coll"><div id="GameListFrmoTrChestPopUp"></div><script type="text/javascript">ExecFunction(function () { LoadData("GameListFrmoTrChestPopUp", "http://www.greatdaygames.com/ajaxServices/GameListFrmoTrChestPopUp.aspx"); });</script><a onclick="CloseTrChaest();" class="BTN_ClosePopup"></a><div class="TREATS_informerPopup">' + count+ '</div></div>', {}));
}

function OpenNonLogTCUnderSea(){
    jQuery.ark.dialog.open('arkDialog',
                             'TCUnderSeaNonLogPopUp',
                              '', 
                              tmpl('<div class="TC_under_nlog"><div id="TCUnderSeaNonLog"></div><div class="TC_under_but_block coll"><a id="linkLogin" class="TUS_login" onclick="LoginTcUnderSea();return false;"></a><a class="TUS_register" onclick="RegisterTcUnderSea();return false;"></a></div><a class="TC_wat coll" href="http://www.greatdaygames.com/HelpPages/General.aspx#q3">What are Treats?</a></div>', {}),
                              jQuery.ark.dialog.close('TCUnderSeaNonLogPopUp'),
                              true);
}

function StartSlotGame(){
     HideHtml();
     
     jQuery("#flashGameID").add("style", "display: inline-block;");
}

function LoginTcUnderSea(){
    this.isLoginOnSlotClicked = true;
    loginAction.LoginThenDo("update('login');", null, null, null, null, true, "", "PopUp_content_TClogin");
}

function RegisterTcUnderSea(){
    OpenPopupRegister(true, '', 'PopUp_content_TCregister');
    StartAfterRegister();
}

function StartAfterRegister(){
    jQuery(document).bind('login', function () {
       // update('login');
        jQuery(document).unbind('login'); });
}

function OpenLogTCUnderSea(){
    jQuery.ark.dialog.open('arkDialog',
                           'TCUnderSeaLogPopUp',
                           '',
                           tmpl('<div ><div id="TCUnderSeaLog"></div><script type="text/javascript">ExecFunction(function () { LoadData("TCUnderSeaLog", "http://www.greatdaygames.com/ajaxServices/SimilarGamesTCUnserSea.aspx"); });</script><a onclick="PlayTCUnderSea();">Play now</a><a  href="" onclick="SlotUnderSeaHelp();">?</a></div>', {}),
                           jQuery.ark.dialog.close('TCUnderSeaLogPopUp'),
                           true);
}

function PlayTCUnderSea(){
    StartSlotGame();
}


function SlotUnderSeaHelp(){
     jQuery.ark.dialog.open('arkDialog',
                           'TCUnderSeaHelpPopUp',
                           '',
                           tmpl('<div id="divHelp" class="SlotUnderSeaHelp_div"></div>', {}),
                           jQuery.ark.dialog.close('TCUnderSeaHelpPopUp'),
                           true);
}

function OpenPopupLogin(cancelAction, successRedirectUrl, additionalText, withOutCloseButton, isSpecPopUp, addStyle, contentStyle)
{
	if (isSpecPopUp == 'undefined'){
        isSpecPopUp = false;
    }
    if (addStyle == 'undefined'){
        addStyle = '';
    }
    if (contentStyle == 'undefined'){
        contentStyle = '';
    }
    cancelAction = typeof(cancelAction) == 'string' ? cancelAction : '';
	var dialog =  withOutCloseButton == 1 ? 'arkDialogWithoutCloseButton' : 'arkDialog' 
	jQuery.ark.dialog.open(dialog,
		'popupLogin_popupDialog',
		'Login to your Great Day Games account!',
		tmpl('popupLogin', { CancelAction: cancelAction, 
			MouseOverClass: "'PopUp_Login_btn_hov';",
			MouseOutClass: "'PopUp_Login_btn';",
			SuccessRedirectUrl: successRedirectUrl,
			AdditionalText: additionalText,
			Email: Global_GetLoginEmailFromCookie(),
			PWD: Global_GetLoginPasswordFromCookie(),
			CHK: Global_GetRememberFromCookie()
            } ),
		'popupLogin_cancelClick(' + cancelAction + ')',
        isSpecPopUp,
        addStyle,
        contentStyle
		);
	if (document.getElementById('popupLogin$email'))
	{
		document.getElementById('popupLogin$email').focus();
	}
}
function OpenPopupForgot(cancelAction)
{
	cancelAction = typeof(cancelAction) == 'string' ? cancelAction : '';
	jQuery.ark.dialog.open('arkDialog', 
		'popupForgotPass_popupDialog',
		'Restoration of your Great Day Games password!',
		tmpl('popupForgotPass', { CancelAction: cancelAction,
			MouseOverClass: "'PopUp_Login_btn_hov';",
			MouseOutClass: "'PopUp_Login_btn';"} ),
		'popupForgotPass_cancelClick(' + cancelAction + ')');
	if (document.getElementById('popupForgotPass$email')) {
		document.getElementById('popupForgotPass$email').focus();
	}
}

function OpenPopupChest(cancelAction){
 //  debugger;
   cancelAction = typeof(cancelAction) == 'string' ? cancelAction : '';
   jQuery.ark.dialog.close('popupChest_popupDialog');
   jQuery.ark.dialog.open('arkDialog', 
		'popupChest_popupDialog',
		'Treasure Chest',
		tmpl('popupChest', { 
            CancelAction: cancelAction,
			MouseOverClass: "'PopUp_Login_btn_hov';",
			MouseOutClass: "'PopUp_Login_btn';"

            } ),
        'popupChest_cancelClick(' + cancelAction + ')'
   );

   
   

   
}


