function AuthenticationBridge(){

}

/* Basic configuration */
var YPSSO_IFRAME_ID = "rpxIframe";
var YPSSO_LOGO_URL = "http://www.google.com/nottherefornow.jpg";
var YPSSO_BASE_SERVER = "http://profiles.yellowpages.ca/";
var YPSSO_RPX_POPUP_URL = 'https://sso.yellowpages.ca/blank.txt';

AuthenticationBridge.prototype.fbWindowHandle = undefined;
AuthenticationBridge.prototype.forgotPasswordUrl = "";

AuthenticationBridge.prototype.startAuthentication = function(endpoint, language, apikey, isReviewLogin) {

	isReviewLogin = (isReviewLogin == true ? "1" : "0");

	var iframeUrl = YPSSO_BASE_SERVER + "showsignin.action?lang=" + language +"&returnUrl=" + encodeURIComponent(endpoint) + "&logoUrl=" + YPSSO_LOGO_URL + "&apikey=" + apikey  + "&isReviewLogin=" + isReviewLogin;
	document.getElementById(YPSSO_IFRAME_ID).src = iframeUrl;
}

AuthenticationBridge.prototype.startFacebookAuthentication = function(endpoint, language, apikey) {

	var popupUrl = YPSSO_BASE_SERVER + "showfacebookconnect.action?lang=" + language +"&returnUrl=" + encodeURIComponent(endpoint) + "&logoUrl=" + YPSSO_LOGO_URL + "&apikey=" + apikey;
	var options = "height=500,width=475,status=no,toolbar=no,menubar=no,location=yes";

	 this.fbWindowHandle = window.open(YPSSO_RPX_POPUP_URL, 'rpx_yp_popup', options);
	 document.getElementById(YPSSO_IFRAME_ID).src = popupUrl;
	 //setTimeout("YP_SSO.checkFBWindow()", 4000);
}

AuthenticationBridge.prototype.checkFBWindow = function() {
	try {
		alert("isClosed?: " + this.fbWindowHandle.closed + " popup url = " + this.fbWindowHandle.window);
	} catch (e){
		alert("Error : " + e);
	}

	
	if (this.fbWindowHandle != undefined && this.fbWindowHandle.closed){
		window.location.reload();
	} else {
		setTimeout("YP_SSO.checkFBWindow()", 4000);
	}
}

AuthenticationBridge.prototype.startRegistration = function(endpoint, language, apikey) {

	var iframeUrl = YPSSO_BASE_SERVER + "showsignup.action?lang=" + language +"&returnUrl=" + encodeURIComponent(endpoint) + "&logoUrl=" + YPSSO_LOGO_URL + "&apikey=" + apikey;
	document.getElementById(YPSSO_IFRAME_ID).src = iframeUrl;
}

AuthenticationBridge.prototype.forgotPassword = function(language, apikey) {

	var iframeUrl = this.forgotPasswordUrl + "showforgotpassword.action?lang=" + language +"&returnUrl=" + encodeURIComponent(endpoint) + "&logoUrl=" + YPSSO_LOGO_URL + "&apikey=" + apikey;
	document.getElementById(YPSSO_IFRAME_ID).src = iframeUrl;
}

var YP_SSO = new AuthenticationBridge();
