
function checkLoginCookie (){
 
    var log = readCookie('iPlanetDirectoryPro2')

	clear_layer_login();

//	log = "blocked"
 
	switch(log){
		case null:
		case undefined:
			document.cookie = "testcookie=test; max-age=10000";
			var cookies = document.cookie;
			if(cookies.indexOf("testcookie=test") == -1) {
		 		reveal_layer_article('dndlogin3');  
				alert("Your browser's cookie functionality \n is turned off. Please turn it on. \n\n If you do not have Cookies enabled \n you will not be able to fully experience \n the D&D website and D&D Insider");
			} else {
				reveal_layer_article('dndlogin1');  
			}
			/*
			if (readCookie('CookieCheck') != 'yes') {
		 		reveal_layer_article('dndlogin3');  
				alert("Your browser's cookie functionality \n is turned off. Please turn it on. \n\n If you do not have Cookies enabled \n you will not be able to fully experience \n the D&D website and D&D Insider");
			} else {
				reveal_layer_article('dndlogin1');  
			}
			*/
			break;
		case 'false':
			reveal_layer_article('dndlogin1');  
			break;
		case 'invalid':
			reveal_layer_article('dndlogin1');  
			break;
		case 'cancelled':
			reveal_layer_article('dndlogin1');  
			break;
		case 'terminated':
			reveal_layer_article('dndlogin1');  
			break;
		case 'retired':
			reveal_layer_article('dndlogin1');  
			break;
		case 'suspended':
			reveal_layer_article('dndlogin1');  
			break;
		case 'blocked':
			reveal_layer_article('dndlogin1');  
			break;			
		case 'error':
			reveal_layer_article('dndlogin1');  
			break;
		default:
			reveal_layer_article('dndlogin2');  
			break;
	} 
}

function popInvalidCheck (){

// popinvalid = "invalid" 
// popinvalid = "error" 
// popinvalid = "cancelled" 
// popinvalid = "terminated" 
// popinvalid = "retired" 
// popinvalid = "suspended" 
// popinvalid = "blocked" 
 
 if (popinvalid == null) {
	 popinvalid = "";
 }
 

	switch(popinvalid){
		case null:
		case undefined:
			break;
		case 'invalid':
		//	alert(' We are sorry that we could not \n find your account. \n\n If you have a D&D Insider account \n please try again. \n\n If you have not yet migrated your \n boards account to D&D Insider\n please do so now. ')
	//		window.open('https://accounts.gleemax.com/AmLogin.aspx','','');	
//			window.open('http://ssowebappdvinf1.gleemax.com/AmLogin.aspx','','');	

			var popheadline = "<b>D&D Insider Login Alert!</b>"
			var popmessage = "<p align='center'><br/>You have entered an invalid login or password; if you have a D&D Insider account please try again.</p>"
			openloginalert(popheadline,popmessage)

			break;
		case 'error':
//			alert(' Wizards login service \n is temporarily unavailable. \n\n Please try again soon. ')

			var popheadline = "<b>D&D Insider Login Alert!</b>"
			var popmessage = "<p align='center'><br/>Wizards login service is temporarily unavailable.<br/><br/>Please try again soon.</p>"
			openloginalert(popheadline,popmessage)

			break;
		case 'cancelled':
	//		alert(' This account has been cancelled. ')
	//		window.open('https://accounts.gleemax.com/Help/HelpSystem.aspx','','');
//			window.open('http://ssowebappdvinf1.gleemax.com/Help/HelpSystem.aspx','','');

			var popheadline = "<b>D&D Insider Login Alert!</b>"
			var popmessage = "<p align='center'><br/>This account appears to be cancelled.<br/><br/>If this account status seems incorrect, please visit our <a href='https://accounts.gleemax.com/Help/HelpSystem.aspx' target='_blank'>help system</a> to request more information.</a>.</p>"
			openloginalert(popheadline,popmessage)

			break;
		case 'terminated':
	//		alert(' This account has been terminated due \n to violations of our Terms of Service. ')
//			window.open('https://accounts.gleemax.com/Help/HelpSystem.aspx','','');
//			window.open('http://ssowebappdvinf1.gleemax.com/Help/HelpSystem.aspx','','');


			var popheadline = "<b>D&D Insider Login Alert!</b>"
			var popmessage = "<p align='center'><br/>This account has been terminated due to violations of our Terms of Service.<br/><br/>Please visit our <a href='https://accounts.gleemax.com/Help/HelpSystem.aspx' target='_blank'>help system</a> to find out more</a>.</p>"
			openloginalert(popheadline,popmessage)


			break;
		case 'retired':
	//		alert(' This account has been retired due \n to 2 years of inactivity. ')
	//		window.open('http://wizards.custhelp.com/','','');		
 		
			var popheadline = "<b>D&D Insider Login Alert!</b>"
			var popmessage = "<p align='center'><br/>This account has been retired due to 2 years of inactivity.<br/><br/>Please contact <a href='http://wizards.custhelp.com/' target='_blank'>Customer Service</a> for help</a>.</p>"
			openloginalert(popheadline,popmessage)			
			
			
			break;
		case 'suspended':
//			alert(' This account has been suspended due \n to violations of the Terms of Service. \n Your account will be reinstated \n at the end of the suspension. ')
	//		window.open('http://wizards.custhelp.com/','','');	
			
			
			var popheadline = "<b>D&D Insider Login Alert!</b>"
			var popmessage = "<p align='center'><br/>This account has been suspended due to violations of the Terms of Service. Your account will be reinstated at the end of the suspension.<br/><br/>Please contact <a href='http://wizards.custhelp.com/' target='_blank'>Customer Service</a> for help</a>.</p>"
			openloginalert(popheadline,popmessage)			
			
			
			
			
			
			break;
		case 'blocked':
		//	alert(' Unable to Authorize access from given location. ')
			
			
			var popheadline = "<b>D&D Insider Login Alert!</b>"
			var popmessage = "<p align='center'><br/>Unable to Authorize access from given location.</p>"
			openloginalert(popheadline,popmessage)					
			
			
			break;			
		default:
			break;
	} 



}

function popDownloadCheck (){

	popdownload = "";

	if ((parent.location.href.split("&down=e").length-1) >= 1) {
		popdownload = "e"
	}

	if ((parent.location.href.split("&down=a").length-1) >= 1) {
		popdownload = "a"
	}

	if ((parent.location.href.split("&down=x").length-1) >= 1) {
		popdownload = "x"
	}
	
	if ((parent.location.href.split("&down=s").length-1) >= 1) {
		popdownload = "s"
	}	
 
	switch(popdownload){
		case null:
			break;
		case 'e':
//			parent.location.href = parent.location.href.replace( "&down=e", "" );
//			alert('Error Finding File.')
			
			var popheadline = "<b>D&D Insider Download Alert!</b>"
			var popmessage = "<p align='center'><br/><br/>Error Finding File.</p>"
			openloginalert(popheadline,popmessage)				
			
			break;
		case 'a':
//			parent.location.href = parent.location.href.replace( "&down=a", "" );
//			alert('This download requires that you sign-in \n to D&D Insider to access the content.')
			
			var popheadline = "<b>D&D Insider Download Alert!</b>"
			var popmessage = "<p align='center'><br/><br/>This download requires that you sign-in to D&D Insider to access the content.</p>"
			openloginalert(popheadline,popmessage)				
			
			break;
		case 'x':
//			parent.location.href = parent.location.href.replace( "&down=x", "" );
//			alert('This download is no longer available.')

			var popheadline = "<b>D&D Insider Download Alert!</b>"			
			var popmessage = "<p align='center'><br/><br/>This download is no longer available.</p>"
			openloginalert(popheadline,popmessage)					
			
			break;
		case 's':
//			parent.location.href = parent.location.href.replace( "&down=s", "" );
//			alert('This download requires you to be a \n current D&D Insider subscriber. ')
			
			var popheadline = "<b>D&D Insider Download Alert!</b>"
			var popmessage = "<p align='center'><br/><br/>This download requires you to be a current D&D Insider subscriber. <br/><br/> <a href='/default.asp?x=dnd/insider/subscription' target='_blank'>Subscribe Now</a></p>"
			openloginalert(popheadline,popmessage)				
			
			break;
		default:
			break;
	} 
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}


// =========== login alert box ================== 

function openloginalert(headline,message)
{



  if (document.getElementById) {
    document.getElementById("dndloginpopup").style.visibility = 'visible';
    document.getElementById("dndloginheadline").innerHTML = headline;
    document.getElementById("dndloginmessage").innerHTML = message;
  }
  else if (document.layers && document.layers["dndloginpopup"]) {
    document.layers["dndloginpopup"].visibility = 'visible';
    document.layers["dndloginheadline"].innerHTML = headline;
    document.layers["dndloginmessage"].innerHTML = message;
  }
  else if (document.all) {
    document.all["dndloginpopup"].style.visibility = 'visible';
    document.all["dndloginheadline"].innerHTML = headline;
    document.all["dndloginmessage"].innerHTML = message;
  }


}
 
function closeloginalert()
{
 
  if (document.getElementById) {
    document.getElementById("dndloginpopup").style.visibility = 'hidden';
  }
  else if (document.layers && document.layers["dndloginpopup"]) {
    document.layers["dndloginpopup"].visibility = 'hidden';
  }
  else if (document.all) {
    document.all["dndloginpopup"].style.visibility = 'hidden';
  }



	
}


  