var PHH_WATCH_THIS_USER_SIGNUP_URL="";
var PHH_USER_REGISTRATION_SUCCESS_URL="";
var PHH_WATCH_THIS_USER_PROF_DELETE_CONFIRM="";
var PHH_WATCH_THIS_USER_PROF_DELETE_SUCCESS="";
var PHH_WATCH_THIS_LOGGED_IN_USER_ID="";
var PHH_WATCH_THIS_LOGGED_IN_GREETINGS_BAR_ID="top";
var PHH_WATCH_THIS_NOT_LOGGED_IN_GREETINGS_BAR_ID="signup";
var PHH_WATCH_THIS_GREETINGS_BAR_WELCOME_TEXT_ID="spanPHHWatchThisUserGreeting";
var PHH_WATCH_THIS_LIST_URL=null;
var PHH_WATCH_THIS_NOT_WATCHING_DIV_TAG_PREFIX = "divPhhNotWatching";
var PHH_WATCH_THIS_WATCHING_DIV_TAG_PREFIX = "divPhhWatching";
var PHH_WATCH_THIS_AJAX_IMAGE_DIV_TAG_PREFIX = "divPhhWTIAjaxImage";
var PHH_WATCH_THIS_NOT_WATCHING_USERCOUNT_SPAN_TAG_PREFIX = "spanPhhNotWatchingUserCount";
var PHH_WATCH_THIS_WATCHING_USERCOUNT_SPAN_TAG_PREFIX = "spanPhhWatchingUserCount";
var PHH_WATCH_THIS_HIDDEN_LINK_TAG_PREFIX = "aLinkPhhWTIHidden";
var PHH_WATCH_THIS_FRIENDLY_REMINDER_HIDDEN_LINK_TAG_PREFIX = "aLinkPhhWTIFRHidden";
var PHH_WATCH_THIS_CONSTANT_USER_COUNT = "";
var PHH_WATCH_THIS_CONSTANT_WATCHING="";
var PHH_WATCH_THIS_REDIRECT_TO_WATCH_THIS_ICON="";
var PHH_WATCH_THIS_WATCH_CATEGORY_CODE_MC="";
var PHH_CONVERSION_IFRAME_ID="";
var PHH_CONVERSION_PAGE_NAME=null;

var g_Phh_WTI_EmailAddress="";
var g_Phh_WTI_FR_Response=false;

var g_Phh_WTI_Param_1=null;
var g_Phh_WTI_Param_2=null;
var g_Phh_WTI_Param_3=null;
var g_Phh_WTI_Param_4=null;
var g_Phh_WTI_Param_5=null;

//the actual values for these variables are set in watchthis_icon.jsp
var PHH_WATCH_THIS_MC_HEADER_ICON_NUM=0;
var PHH_WATCH_THIS_TOTAL_ICONS=0;

function phhUserRegistration(formName, formErrors, submitButtonName, divPassword, divConfirmPassword, forwardURL) {
	
	try{
		var url = eval("document." + formName).action;
		var sbuttonObj = eval("document." + formName + "." + submitButtonName);
		
		if(divConfirmPassword != null && divConfirmPassword.length > 0){
			//User Registration
			document.getElementById(divConfirmPassword).innerHTML=document.forms[formName].confirmPassword.value;
			if(document.forms[formName].confirmPassword.value.length > 0){
				document.forms[formName].confirmPassword.value = binl2b64(str2binl(document.forms[formName].confirmPassword.value));
			}
			document.getElementById(divPassword).innerHTML=document.forms[formName].password.value;
			if(document.forms[formName].password.value.length > 0){
				document.forms[formName].password.value = binl2b64(str2binl(document.forms[formName].password.value));
			}
			document.forms[formName].homePhone.value = document.forms[formName].homePhone_firstPart.value + document.forms[formName].homePhone_secondPart.value + document.forms[formName].homePhone_thirdPart.value;
			populateTrafficSourceHiddenFields(formName);//load the traffic source data
		}else{
			//Login Screen
			document.getElementById(divPassword).innerHTML=document.forms[formName].password.value;
			if(document.forms[formName].password.value.length > 0){
				document.forms[formName].password.value = b64_md5(document.forms[formName].password.value);
			} 
		}
		document.getElementById(formErrors).innerHTML="";
		document.getElementById(formErrors).style.display = "none";		
		jQuery.ajax({
					'type' : 'POST',
					'url' : url,
					'data' : $(formName).serialize(true),
					'beforeSend' : function(xhr) {
						if (sbuttonObj) {
							sbuttonObj.disabled=true;
						}

					},
					'success' : function(data) {
						if (sbuttonObj) {
							sbuttonObj.disabled=false;
						}
						var respTxt=data.strip();
						var respObj = null;
						try{
							respObj=respTxt.evalJSON(true);
						}catch(e){
							respObj = null;
						}
						if(respObj != null && respObj.result == PHH_SUCCESS){
							//success
							if(divConfirmPassword != null && divConfirmPassword.length > 0){
								//User Registration
								phhWatchThisgoogleYahooConversion();
								pageTracker._trackPageview(PHH_USER_REGISTRATION_SUCCESS_URL);
							}
							if(g_Phh_WTI_Param_5 != null && g_Phh_WTI_Param_5.length > 0 && g_Phh_WTI_Param_5 != PHH_WATCH_THIS_WATCH_CATEGORY_CODE_MC && "1" == eval("respObj." + PHH_WATCH_THIS_REDIRECT_TO_WATCH_THIS_ICON)){
								//do not hide the modal box. Need to show "A friendly reminder..."
							}else{
								Modalbox.hide();	
							}
							PHH_WATCH_THIS_LOGGED_IN_USER_ID = "" + respObj.uid;
							if(PHH_WATCH_THIS_LIST_URL == forwardURL){
								document.location.href=PHH_WATCH_THIS_LIST_URL + "/" + respObj.uid;
							}else{
								phhWatchThisSetGreetings(respObj.greetings);
								$j("body").addClass("loggedin");
								if(eval("respObj." + PHH_WATCH_THIS_REDIRECT_TO_WATCH_THIS_ICON) == "1"){
									phhWatchThisResource(g_Phh_WTI_Param_1, g_Phh_WTI_Param_2, g_Phh_WTI_Param_3, g_Phh_WTI_Param_4, g_Phh_WTI_Param_5);
								}else{
									phhResetWatchThisIconsOnLoginOrRegister(null);
								}
							}
						}
						else{
							//error message
							document.getElementById(formErrors).innerHTML = respTxt;
							document.getElementById(formErrors).style.display = "block";
							Modalbox.resizeToContent();
						}
					},
					'error' : function(xhr, err, e) {
						if (sbuttonObj) {
							sbuttonObj.disabled=false;
						}
						document.getElementById(formErrors).innerHTML = xhr.status + ": " + xhr.statusText + "; " + err + ": "+ e;
						document.getElementById(formErrors).style.display = "block";
						Modalbox.resizeToContent();
					}
				});
			
			if(divPassword != null && divPassword.length > 0){					
				document.forms[formName].password.value = document.getElementById(divPassword).innerHTML;
				document.getElementById(divPassword).innerHTML = "";
			}
			if(divConfirmPassword != null && divConfirmPassword.length > 0){					
				document.forms[formName].confirmPassword.value = document.getElementById(divConfirmPassword).innerHTML;
				document.getElementById(divConfirmPassword).innerHTML = "";
			}
	}catch(e){
		alert("Javascript Error in phhUserRegistration => " + e.description);		
	}
}

function phhForgotPassword(formName, formErrors, submitButtonName, successPage) {
	
	try{
		
		var url = eval("document." + formName).action;
		var sbuttonObj = eval("document." + formName + "." + submitButtonName);
		document.getElementById(formErrors).innerHTML="";
		document.getElementById(formErrors).style.display = "none";		
		
		jQuery.ajax({
					'type' : 'POST',
					'url' : url,
					'data' : $(formName).serialize(true),
					'beforeSend' : function(xhr) {
						if (sbuttonObj) {
							sbuttonObj.disabled=true;
						}

					},
					'success' : function(data) {
						if (sbuttonObj) {
							sbuttonObj.disabled=false;
						}
						var respTxt=data.strip();
						var respObj = null;
						try{
							respObj=respTxt.evalJSON(true);
						}catch(e){
							respObj = null;
						}
						if(respObj != null && respObj.result == PHH_SUCCESS){
							//Modalbox.show("<div class='mb'><h2>Thank you!</h2><p>Your pasword has been sent. <a href='" + successPage + "' title='Create New Account' onclick='Modalbox.show(this.href, {title: this.title, width: 780}); return false;\'>Close this dialog</a>.</p></div>", {title: 'Password sent', width: 500});
							Modalbox.show("<div class='mb'><h2>Thank you!</h2><p>Your pasword has been sent. <a href='javascript:void(0);' title='Close this Dialog' onclick='Modalbox.hide(); return false;\'>Close this dialog</a>.</p></div>", {title: 'Password sent', width: 500});
							Modalbox.resizeToContent();
						}
						else{
							//error message
							document.getElementById(formErrors).innerHTML = respTxt;
							document.getElementById(formErrors).style.display = "block";
							Modalbox.resizeToContent();
						}
					},
					'error' : function(xhr, err, e) {
						if (sbuttonObj) {
							sbuttonObj.disabled=false;
						}
						document.getElementById(formErrors).innerHTML = xhr.status + ": " + xhr.statusText + "; " + err + ": "+ e;
						document.getElementById(formErrors).style.display = "block";
						Modalbox.resizeToContent();
					}
				});
			
	}catch(e){
		alert("Javascript Error in phhForgotPassword => " + e.description);		
	}
}

function phhUserLogout(logoutUrl) {
	
	try{
		jQuery.ajax({
					'type' : 'POST',
					'url' : logoutUrl,
					'data' : "ajax=1",
					'success' : function(data) {
						var respTxt=data.strip();
						var respObj = null;
						try{
							respObj=respTxt.evalJSON(true);
						}catch(e){
							respObj = null;
						}
						if(respObj != null && respObj.result == PHH_SUCCESS){
							PHH_WATCH_THIS_LOGGED_IN_USER_ID = "";
							phhWatchThisSetGreetings(null);
							$j("body").removeClass("loggedin");
							phhResetWatchThisIconsOnLogout();
						}
						else{
							//error message
							Modalbox.show("<div class='mb'><p>" + respTxt + "</p></div>", {title: 'Logout', width: 500, autoFocusing: false});
							Modalbox.resizeToContent();
						}
					},
					'error' : function(xhr, err, e) {
						Modalbox.show("<div class='mb'><p>" + xhr.status + ": " + xhr.statusText + "; " + err + ": "+ e + "</p></div>", {title: 'Logout', width: 500, autoFocusing: false});
						Modalbox.resizeToContent();
					}
				});
	}catch(e){
		alert("Javascript Error in phhUserLogout => " + e.description);		
	}
}

function phhWatchThisResource(watchThisClicked, url, counter, forwardUrl, watchCategoryCode) {
	
	try{

		var userId = phhReadCookie(USER_REGISTRATION_COOKIE_USER_UID);
		if(userId == null || userId.length == 0){
			//Store the method parameters in global variables.
			//These global variables will be used, when this function is invoked 
			//from "phhUserRegistration" function, once the user registers/login successfully.
			g_Phh_WTI_Param_1 = watchThisClicked;
			g_Phh_WTI_Param_2 = url;
			g_Phh_WTI_Param_3 = counter;
			g_Phh_WTI_Param_4 = forwardUrl;
			g_Phh_WTI_Param_5 = watchCategoryCode;
			Modalbox.show(PHH_WATCH_THIS_USER_SIGNUP_URL + "?" + PHH_WATCH_THIS_REDIRECT_TO_WATCH_THIS_ICON + "=1", {title: "Sign Up For A Free Account", width: 780});
			//exit the method
			return;
		}
		
		//check the user is watching the location or not. Only when "Watch This" is clicked.
		//Not needed for "Unwatch This"
		var objFRLink = $j('#' + PHH_WATCH_THIS_FRIENDLY_REMINDER_HIDDEN_LINK_TAG_PREFIX + counter);
		if(watchCategoryCode != PHH_WATCH_THIS_WATCH_CATEGORY_CODE_MC && watchThisClicked && userId != null && userId.length > 0 && objFRLink && g_Phh_WTI_FR_Response == false){
			//Store the method parameters in global variables.
			//These global variables will be used, when this function is invoked 
			//from the "A friendly Reminder..." Modalbox, if a user explicitly wants to watch an inventory
			//in addition to the location.
			g_Phh_WTI_Param_1 = watchThisClicked;
			g_Phh_WTI_Param_2 = url;
			g_Phh_WTI_Param_3 = counter;
			g_Phh_WTI_Param_4 = forwardUrl;
			g_Phh_WTI_Param_5 = watchCategoryCode;						
			objFRLink.click();
			return;
		}
		
		//reset the value of global variables.
		phhResetParamGlobalVariables();
		g_Phh_WTI_FR_Response = false;
		
		var objNotWatching = null;
		var objWatching = null;
		var objCountNotWatching = null;
		var objCountWatching = null;
		var objAjaxImage = null;
		if(watchThisClicked){
			objNotWatching = $j('#' + PHH_WATCH_THIS_NOT_WATCHING_DIV_TAG_PREFIX + counter);
			objWatching = $j('#' + PHH_WATCH_THIS_WATCHING_DIV_TAG_PREFIX + counter);
			objCountNotWatching = $j('#' + PHH_WATCH_THIS_NOT_WATCHING_USERCOUNT_SPAN_TAG_PREFIX + counter);
			objCountWatching = $j('#' + PHH_WATCH_THIS_WATCHING_USERCOUNT_SPAN_TAG_PREFIX + counter);
		}else{
			objWatching = $j('#' + PHH_WATCH_THIS_NOT_WATCHING_DIV_TAG_PREFIX + counter);
			objNotWatching = $j('#' + PHH_WATCH_THIS_WATCHING_DIV_TAG_PREFIX + counter);
			objCountWatching = $j('#' + PHH_WATCH_THIS_NOT_WATCHING_USERCOUNT_SPAN_TAG_PREFIX + counter);
			objCountNotWatching = $j('#' + PHH_WATCH_THIS_WATCHING_USERCOUNT_SPAN_TAG_PREFIX + counter);
		}
		objAjaxImage = $j('#' + PHH_WATCH_THIS_AJAX_IMAGE_DIV_TAG_PREFIX + counter);
		if(!objNotWatching || !objWatching || !objCountNotWatching || !objCountWatching || !objAjaxImage){
			return;
		}

		objNotWatching.attr('style', 'display:none');
		objAjaxImage.attr('style', 'display:block');
		if(forwardUrl != null && forwardUrl.length > 0){
			forwardUrl = "forwardUrl=" + escape(forwardUrl);
		}else{
			forwardUrl = "";
		}
		
		jQuery.ajax({
					'type' : 'POST',
					'url' : url,
					'data' : forwardUrl,
					'beforeSend' : function(xhr) {
						objAjaxImage.html('<img src="/images/cms/ajax-loader_1.gif">Processing...');
					},
					'success' : function(data) {
						objNotWatching.attr('style', 'display:block');
						objAjaxImage.attr('style', 'display:none');
						var respTxt=data.strip();
						var respObj = null;
						try{
							respObj=respTxt.evalJSON(true);
						}catch(e){
							respObj = null;
						}
						if(respObj != null && respObj.result == PHH_SUCCESS){
							if(watchThisClicked){
								if(eval("respObj." + PHH_WATCH_THIS_CONSTANT_WATCHING)){
									objNotWatching.attr('style', 'display:none');
									objWatching.attr('style', 'display:block');
								}else{
									objNotWatching.attr('style', 'display:block');
									objWatching.attr('style', 'display:none');
								}
							}else{
								objNotWatching.attr('style', 'display:none');
								objWatching.attr('style', 'display:block');
							}
							var usercount=eval("respObj." + PHH_WATCH_THIS_CONSTANT_USER_COUNT);
							objCountWatching.html(usercount);
							objCountNotWatching.html(usercount);
							phhResetWatchThisIconsOnLoginOrRegister(counter);
						}
						else{
							//error message
							Modalbox.show("<div class='mb'><p>" + respTxt + "</p></div>", {title: 'Watch This', width: 500, autoFocusing: false});
							Modalbox.resizeToContent();
						}
					},
					'error' : function(xhr, err, e) {
						objNotWatching.attr('style', 'display:block');
						objAjaxImage.attr('style', 'display:none');
						Modalbox.show("<div class='mb'><p>" + xhr.status + ": " + xhr.statusText + "; " + err + ": "+ e + "</p></div>", {title: 'Watch This', width: 500, autoFocusing: false});
						Modalbox.resizeToContent();
					}
				});
			
	}catch(e){
		objNotWatching.attr('style', 'display:block');
		objAjaxImage.attr('style', 'display:none');
		alert("Javascript Error in phhWatchThisResource => " + e.description);		
	}
}

function phhWatchThisGetUserCount(url, counter) {
	
	try{
		var objNotWatching = $j('#' + PHH_WATCH_THIS_NOT_WATCHING_DIV_TAG_PREFIX + counter);
		var objWatching = $j('#' + PHH_WATCH_THIS_WATCHING_DIV_TAG_PREFIX + counter);
		var objCountNotWatching = $j('#' + PHH_WATCH_THIS_NOT_WATCHING_USERCOUNT_SPAN_TAG_PREFIX + counter);
		var objCountWatching = $j('#' + PHH_WATCH_THIS_WATCHING_USERCOUNT_SPAN_TAG_PREFIX + counter);
		var objAjaxImage = $j('#' + PHH_WATCH_THIS_AJAX_IMAGE_DIV_TAG_PREFIX + counter);
		if(!objNotWatching || !objWatching || !objCountNotWatching || !objCountWatching || !objAjaxImage){
			return;
		}

		objNotWatching.attr('style', 'display:block');
		objWatching.attr('style', 'display:none');
								
		objNotWatching.attr('style', 'display:none');
		objAjaxImage.attr('style', 'display:block');
		
		jQuery.ajax({
					'type' : 'POST',
					'url' : url,
					'beforeSend' : function(xhr) {
						objAjaxImage.html('<img src="/images/cms/ajax-loader_1.gif">Processing...');
					},
					'success' : function(data) {
						objNotWatching.attr('style', 'display:block');
						objAjaxImage.attr('style', 'display:none');
						var respTxt=data.strip();
						var respObj = null;
						try{
							respObj=respTxt.evalJSON(true);
						}catch(e){
							respObj = null;
						}
						if(respObj != null && respObj.result == PHH_SUCCESS){
							if(eval("respObj." + PHH_WATCH_THIS_CONSTANT_WATCHING)){
								objNotWatching.attr('style', 'display:none');
								objWatching.attr('style', 'display:block');
							}else{
								objNotWatching.attr('style', 'display:block');
								objWatching.attr('style', 'display:none');
							}
							objCountNotWatching.text(eval("respObj." + PHH_WATCH_THIS_CONSTANT_USER_COUNT));
							objCountWatching.text(eval("respObj." + PHH_WATCH_THIS_CONSTANT_USER_COUNT));
						}
						else{
							//error message
							Modalbox.show("<div class='mb'><p>" + respTxt + "</p></div>", {title: 'Watch This', width: 500, autoFocusing: false});
							Modalbox.resizeToContent();
						}
					},
					'error' : function(xhr, err, e) {
						objNotWatching.attr('style', 'display:block');
						objAjaxImage.attr('style', 'display:none');
						Modalbox.show("<div class='mb'><p>" + xhr.status + ": " + xhr.statusText + "; " + err + ": "+ e + "</p></div>", {title: 'Watch This', width: 500, autoFocusing: false});
						Modalbox.resizeToContent();
					}
				});
			
	}catch(e){
		objNotWatching.attr('style', 'display:block');
		objAjaxImage.attr('style', 'display:none');
		alert("Javascript Error in phhWatchThisGetUserCount => " + e.description);		
	}
}

function phhWatchThisgoogleYahooConversion() {
	try{
		if(PHH_CONVERSION_PAGE_NAME != null && PHH_CONVERSION_PAGE_NAME.length > 0){
			var ifrm = document.getElementById(PHH_CONVERSION_IFRAME_ID);
			ifrm.setAttribute("src", PHH_CONVERSION_PAGE_NAME);
		}else{
			alert("PHH_CONVERSION_PAGE_NAME=" + PHH_CONVERSION_PAGE_NAME); 
		}
	}catch(e){
		alert(e.description);
	}
	return "";
}

function phhShowFriendlyReminder(reminderUrl, userWatchLocUrl, locationUID, counter){
	
	try{
		var objNotWatching = $j('#' + PHH_WATCH_THIS_NOT_WATCHING_DIV_TAG_PREFIX + counter);
		var objAjaxImage = $j('#' + PHH_WATCH_THIS_AJAX_IMAGE_DIV_TAG_PREFIX + counter);
		if(!objNotWatching || !objAjaxImage){
			return;
		}

		//userWatchLocUrl,
		objNotWatching.attr('style', 'display:none');
		objAjaxImage.attr('style', 'display:block');
		
		jQuery.ajax({
					'type' : 'POST',
					'url' : userWatchLocUrl,
					'data' : 'locationUID=' + locationUID,
					'beforeSend' : function(xhr) {
						objAjaxImage.html('<img src="/images/cms/ajax-loader_1.gif">Processing...');
					},
					'success' : function(data) {
						objNotWatching.attr('style', 'display:block');
						objAjaxImage.attr('style', 'display:none');
						var respTxt=data.strip();
						var respObj = null;
						try{
							respObj=respTxt.evalJSON(true);
						}catch(e){
							respObj = null;
						}
						if(respObj != null && respObj.result == PHH_SUCCESS){
							if(eval("respObj." + PHH_WATCH_THIS_CONSTANT_WATCHING)){
								Modalbox.show((reminderUrl + "/" + respObj.locationUID), {title: 'A friendly reminder...', width: 600, autoFocusing: false, closeValue: "", inactiveFade: false});
								Modalbox.deactivate();
							}else{
								phhWatchThisFriendlyReminderSubmit(true);
							}
						}
						else{
							//error message
							Modalbox.show("<div class='mb'><p>" + respTxt + "</p></div>", {title: 'A friendly reminder...', width: 500, autoFocusing: false});
							Modalbox.resizeToContent();
						}
					},
					'error' : function(xhr, err, e) {
						objNotWatching.attr('style', 'display:block');
						objAjaxImage.attr('style', 'display:none');
						Modalbox.show("<div class='mb'><p>" + xhr.status + ": " + xhr.statusText + "; " + err + ": "+ e + "</p></div>", {title: 'A friendly reminder...', width: 500, autoFocusing: false});
						Modalbox.resizeToContent();
					}
				});
			
	}catch(e){
		objNotWatching.attr('style', 'display:block');
		objAjaxImage.attr('style', 'display:none');
		alert("Javascript Error in phhShowFriendlyReminder => " + e.description);		
	}
}

function phhWatchThisValidateEmailAddress(outputSourceName, validateUrl, value, objTarget, objFocus) {

	var emailPattern=/[a-z0-9!#$%&*+/=?^_{|}~-]+(?:\.[a-z0-9!#$%&*+/=?^_{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
	var output=$j("#" + outputSourceName);

	if(value.length == 0 && value != g_Phh_WTI_EmailAddress && output){
		output.html("");
		output.attr('style', 'display:none;');
		return;
	}
	
	if(value.length == 0 || value == g_Phh_WTI_EmailAddress || !emailPattern.test(value) || !output){
		return;
	}
	
	output.attr('style', 'display:block;');
	
	try{
		jQuery.ajax({
					'type' : 'POST',
					'url' : validateUrl,
					'data' : "emailAddress=" + escape(value),
					'beforeSend' : function(xhr) {
						output.html('<img src="/images/cms/ajax-loader_1.gif">Checking the email adress already exists or not...');
						Modalbox.resizeToContent();
					},
					'success' : function(data) {
						var respTxt=data.strip();
						if(respTxt == PHH_SUCCESS){
							output.html("");
							output.attr('style', 'display:none;');
							if(objTarget){
								objTarget.value = "";
							}
						}else{
							//error message
							output.html(respTxt);
							if(objTarget){
								objTarget.value = value;
							}
							if(objFocus){
								objFocus.focus();
							}
						}
					},
					'error' : function(xhr, err, e) {
						output.html(xhr.status + ": " + xhr.statusText + "; " + err + ": "+ e);
					}
				});
	}catch(e){
		alert("Javascript Error in phhUserLogout => " + e.description);
		output.html("");
		output.attr('style', 'display:none;');		
	}
}

function phhOpenGreetingsLink(url, userId){
	if(PHH_WATCH_THIS_LOGGED_IN_USER_ID != null && PHH_WATCH_THIS_LOGGED_IN_USER_ID.length > 0){
		url = url + "/" + PHH_WATCH_THIS_LOGGED_IN_USER_ID;
	}else{
		url = url + "/" + userId;		
	}
	newwindow=window.open(url,"phhWatchThis");
	if (window.focus) {newwindow.focus()}
}

function phhResetWatchThisIconsOnLoginOrRegister(excludeCounter) {
	try{
		for(var i=1; i<=PHH_WATCH_THIS_TOTAL_ICONS; i++){
			if(excludeCounter == null || (excludeCounter != null && i != excludeCounter)){
				var objLink = $j('#' + PHH_WATCH_THIS_HIDDEN_LINK_TAG_PREFIX + i);
				if(objLink){
					objLink.click();
				}
			}
		}
	}catch(e){
		alert("Javascript error in phhResetWatchThisIconsOnLoginOrRegister =>" + e.description);
	}
}

function phhResetWatchThisIconsOnLogout() {
	try{
		for(var i=1; i<=PHH_WATCH_THIS_TOTAL_ICONS; i++){
			var objNotWatching = $j('#' + PHH_WATCH_THIS_NOT_WATCHING_DIV_TAG_PREFIX + i);
			var objWatching = $j('#' + PHH_WATCH_THIS_WATCHING_DIV_TAG_PREFIX + i);
			if(objNotWatching && objWatching){
				if(PHH_WATCH_THIS_MC_HEADER_ICON_NUM == i){
					//Special condition to hide the "Watch This" icon on the Model Center header
					objNotWatching.attr('style', 'display:none');
					objWatching.attr('style', 'display:none');
				}else{
					objNotWatching.attr('style', 'display:block');
					objWatching.attr('style', 'display:none');
				}
			}
		}
	}catch(e){
		alert("Javascript error in phhResetWatchThisIconsOnLogout =>" + e.description);
	}
}

function phhWatchThisSetGreetings(welcomeText) {
	var objLoggedIn=document.getElementById(PHH_WATCH_THIS_LOGGED_IN_GREETINGS_BAR_ID);
	var objNotLoggedIn=document.getElementById(PHH_WATCH_THIS_NOT_LOGGED_IN_GREETINGS_BAR_ID);
	var objWelcomeText=document.getElementById(PHH_WATCH_THIS_GREETINGS_BAR_WELCOME_TEXT_ID);
	if(welcomeText == null || welcomeText.length == 0){
		//Logout
		if(objLoggedIn){
			objLoggedIn.style.display="none";
		}
		if(objNotLoggedIn){
			objNotLoggedIn.style.display="block";
		}
		if(objWelcomeText){
			objWelcomeText.innerHTML="";
		}
	}else{
		//Login
		if(objLoggedIn){
			objLoggedIn.style.display="block";
		}
		if(objNotLoggedIn){
			objNotLoggedIn.style.display="none";
		}
		if(objWelcomeText){
			objWelcomeText.innerHTML=welcomeText;
		}
	}
}

function phhWatchThisFriendlyReminderSubmit(flag){
	try{
		Modalbox.hide();		
	}catch(e){
		//ignore the error
	}

	try{
		if(flag == true){
			g_Phh_WTI_FR_Response = true;
			phhWatchThisResource(g_Phh_WTI_Param_1, g_Phh_WTI_Param_2, g_Phh_WTI_Param_3, g_Phh_WTI_Param_4, g_Phh_WTI_Param_5);
		}else{
			phhResetParamGlobalVariables();
			phhResetWatchThisIconsOnLoginOrRegister(null);
		}
	}catch(e){
		alert("Javascript error in phhWatchThisFriendlyReminderSubmit =>" + e.description);
	}
}

function phhResetParamGlobalVariables(){
	g_Phh_WTI_Param_1 = null;
	g_Phh_WTI_Param_2 = null;
	g_Phh_WTI_Param_3 = null;
	g_Phh_WTI_Param_4 = null;
	g_Phh_WTI_Param_5 = null;
}

