﻿
///the the dialog that has both the the login and the registration panel
function PeregrineRegisterLogin(redirectUrl, target) 
{
	var url = buildLoginUrl(redirectUrl, target);
	$('[id$=ctrlLoginPopup]').CloseImage = '../img/close.gif';
	$('[id$=ctrlLoginPopup]').Show({iframeUrl:url, width: 818, height: 575});
}

///the the dialog that has the registration panel only
function PeregrineRegister(redirectUrl, target) 
{
	var url = buildLoginUrl(redirectUrl, target);	
	
	if (url.indexOf("?") == -1) {
		url += "?";
	} else {
		url += "&";
	}
	url += "Show=Register";
	
	$('[id$=ctrlLoginPopup]').CloseImage = '../img/close.gif';
	$('[id$=ctrlLoginPopup]').Show({iframeUrl:url, width: 510, height: 575});
}


///the the dialog that has the login panel only
function PeregrineLogin(redirectUrl, target) 
{		
	var url = buildLoginUrl(redirectUrl, target);		
	
	if (url.indexOf("?") == -1) {
		url += "?";
	} else {
		url += "&";
	}
	url += "Show=Login";
	
	$('[id$=ctrlLoginPopup]').CloseImage = '../img/close.gif';
	$('[id$=ctrlLoginPopup]').Show({iframeUrl:url, width: 489, height: 260});
}


// the dialog for the user to update his/her user details
function PeregrineMyProfile(redirectUrl, target) 
{
    var url = buildLoginUrl(redirectUrl, target);		
	
	if (url.indexOf("?") == -1) {
		url += "?";
	} else {
		url += "&";
	}
	url += "Show=MyProfile";
	
	$('[id$=ctrlLoginPopup]').CloseImage = '../img/close.gif';
	$('[id$=ctrlLoginPopup]').Show({iframeUrl:url, width: 510, height: 575});
}

function buildLoginUrl(redirectUrl, target) {
	var url = baseIFrameLoginUrl;

	
	if (redirectUrl != undefined && redirectUrl != null) {
		if (url.indexOf("?") == -1) {
			url += "?";
		} else {
			url += "&";
		}
		url += "ReturnUrl=" + escape(redirectUrl);
	}

	if (target != undefined && target != null) {
		if (url.indexOf("?") == -1) {
			url += "?";
		} else {
			url += "&";
		}
		url += "target=" + escape(target);
	}
	
	return url;
}




function RedirectFromLogin(url, target) 
{
	if (url.indexOf("DownloadPDF.ashx") > -1)
	{
	    var loc = location.href;
	    loc += (loc.indexOf("?") == -1) ? "?" : "&";
	    loc += "pdf=" + encodeURIComponent(url);
	    location.href = loc;
	}
	else if (target != undefined && target != null && target != "") 
	{
		window.open(url, target);
	} 
	else 
	{	
	    if (url.indexOf("#comments") >= 0)
	    {
	        url = url.replace(/#comments/, '&commenting=true');
	    }		
		location.href = url;
	}
	
	CloseLoginDialog();
}

function CloseLoginDialog() 
{
	$('[id$=ctrlLoginPopup]').Hide();
}
