﻿
var userState = "";
function TestPopup() {	
	var popupCookie = getCookie("noPopup")
	if (popupCookie != 1)
	{
		jQuery.ajax({ type: "GET", url: "/location.aspx", success: function (data) {
			country = data;
			if (country == "INT") {
				showPopUp();	
			}
			else
			{
				CreatePopUpCookie()
			}
		} 
		});
	}
}
function doLogin(){	
		jQuery("#loginError").hide();
		jQuery("#obtain").hide();
		jQuery("#submitting").show();
		jQuery.post('/wp-admin/admin-ajax.php', 
					{action:'rt_login', user_login:jQuery('#user_login').val(), user_password:jQuery('#user_password').val()},
					function(str,mess){
						if(str == 'success'){
							document.location = document.location;
						}else if (str == 'loginerror')
						{
							jQuery("#loginError").show();
							jQuery("#obtain").hide();
							jQuery("#submitting").hide();
						}
					});
		return false;	
}


function showPopUp()
{		
	jQuery("body").append("<div id='popupDiv'>");	
	jQuery("#flashrotator").hide();	
		 
	jQuery("#popupDiv").load("/popup.html",function(){
		var id = "#popup";
		//Get the screen height and width
		var maskHeight = jQuery(document).height();
		var maskWidth = jQuery(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		//$('#mask').fadeIn(500);	
		jQuery('#mask').fadeIn(1000);	
	
		//Get the window height and width
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();
			  
		//Set the popup window to center
		jQuery(id).css('top',  winH/2-jQuery(id).height()/2);
		jQuery(id).css('left', winW/2-jQuery(id).width()/2);
	
		//transition effect
		jQuery(id).fadeIn(1000);
		
		
			//if close button is clicked
		jQuery('.close').click(function (e) {
			//make cookie for popup
			CreatePopUpCookie();
			//Cancel the link behavior
			e.preventDefault();
			//alert(close);
			jQuery('#mask').fadeOut(300);
			jQuery('.modal').fadeOut(300);			
		});		
					
		jQuery('.EnterLogin').keypress(function (event) {
			if (event.keyCode == '13') {
				doLogin();
			}
		});
		
		//if mask is clicked
		/*jQuery('#mask').click(function () {
			jQuery(this).fadeOut(300);
			jQuery('.modal').fadeOut(300);
		});	*/
	});
}

function CreatePopUpCookie()
{
	var d = new Date();
	setCookie ( "noPopup", 1, d.getFullYear(), d.getMonth(), d.getDate() + 7);
}

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 setCookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure ){
	var cookie_string = name + "=" + escape ( value );
	if ( exp_y ){
		var expires = new Date ( exp_y, exp_m, exp_d );
		cookie_string += "; expires=" + expires.toGMTString();
	}
	if ( path ){
		cookie_string += "; path=" + escape ( path );
	}
	if ( domain ){
		cookie_string += "; domain=" + escape ( domain );
	}
	if ( secure ){
		cookie_string += "; secure";
	}
	document.cookie = cookie_string;
}
