function setProjectRating(userID, projectID, rateValue) {
	var url = "ajax/PutRatingAjax.html";
	var data="projectID=" +encodeURIComponent(projectID);
	data+="&rating="+encodeURIComponent(rateValue);
	data+="&r="+Math.random();
	var myAjax = new Ajax.Request(url,{asynchronous:true, method:'post', parameters:data, onSuccess:setProjectRatingSC, onFailure:errFunc});
}
//
function setProjectRatingSC(r) {
	var bSuccess = false;
	if (r.responseText.indexOf("success") >= 0) {
		bSuccess = true;
	}
	if (!bSuccess) {
		if (r.responseText.indexOf("NotLoggedIn") >= 0) {
			writeError("An error has occurred when attempting to save your rating.", "You must be logged in to rate a project.");
		} else {
			writeError("An error has occurred when attempting to save your rating.", "This may be due to an excessive amount of traffic to the site. Please try again.");
		}
	}
}
//
function showPrivacyPolicy() {
	popUpWindow("../../PrivacyPolicy.html", 0, 0, 740, 650);
}
//
function showTermsOfUse() {
	popUpWindow("../../PrivacyPolicy.html", 0, 0, 740, 650);
}
//
function goToMyRooms() {
	window.location = "../MyRoomsPage.html";
}
//
//
// SHADOWBOX DISPLAYS
//
function showReview(sText) {
	Shadowbox.open({
        player:     'html',
		content:    '<div id="cntReviewDetails"><img src="images/pic-header-productreview.gif" alt="Product Review" /><p>'+sText+'</p></div>',
        height:425,
        width:760
    });
}
//
function showLearnHow() {
	Shadowbox.open({
        player: 'html',
	   content: '<div class="cntLearnHow"><p>The Freshaire Choice paint contains no VOCs, harsh chemicals that make paint smell like paint and affect the air we breathe, both inside and outside your home. Some paints claim to have no VOCs, but on average, add back up to 150 grams of VOCs per gallon once the color is mixed. However, that is not the case with The Freshaire Choice paint and colorant system. By using The Freshaire Choice paint for decorating projects, this community will have avoided the emission of this many harmful VOCs into our environment to date.</p></div>',
        height:400,
        width:760
    });
}
//
function saveAsInspiration(sID) {
	var url = "ajax/PutInspirationAjax.html";
	var data="projectID="+encodeURIComponent(sID);
	data+="&r="+Math.random();
	var myAjax = new Ajax.Request(url,{asynchronous:true, method:'post',parameters:data, onSuccess:saveAsInspirationSC, onFailure:errFunc});
}
//
function saveAsInspirationSC(r) {
	if (r.responseText.indexOf("success") > 0) {
		showSaveAsInspiration();
	} else {
		if (r.responseText.indexOf("NotLoggedIn") >= 0) {
			writeError("An error has occurred when attempting to save this content.", "You must be logged in to save inspirational content.");
		} else {
			writeError("An error has occurred when attempting to save this content.", "This may be due to an excessive amount of traffic to the site. Please try again.");
		}
	}
}
//
function showSaveAsInspiration() {
	Shadowbox.open({
        player: 'html',
	   modal:false,
	   content: '<div class="shadowBoxContent"><img src="images/pic_savedAsInspiration.gif" /></div>',
        height:225,
        width:650,
	   title: '',
	   options:{enableKeys:false, displayNav:true, onClose:refreshPage} });
}
//
function showColorPicker() {
	Shadowbox.open({
        player: 'iframe',
	   modal:false,
	   content: 'ajax/SbColorPickerAjax.html',
        height:350,
        width:820,
	   title: '',
	   options:{enableKeys:false, displayNav:true} });
}
//
function deleteMyRoom(projectID) {
	if (confirm("Are you sure you want to delete this experience? This cannot be undone.")) {
		var url = "ajax/DeleteProjectAjax.html";
		var data="projectID="+encodeURIComponent(projectID);
		data+="&r="+Math.random();
		var myAjax = new Ajax.Request(url,{asynchronous:true, method:'post',parameters:data, onSuccess:deleteMyRoomSC, onFailure:errFunc});
	}
}
//
function deleteMyRoomSC(r) {
	if (r.responseText.indexOf("success") > 0) {
		showDeleteMyRoomSuccess();
	} else {
		if (r.responseText.indexOf("NotLoggedIn") >= 0) {
			writeError("An error has occurred.", "You must be logged in to delete this project.");
		} else {
			writeError("An error has occurred.", "Please try again.");
		}
	}	
}
//
function showDeleteMyRoomSuccess() {
	Shadowbox.open({
        player: 'html',
	   modal:false,
	   content: '<div class="cntError" id="cntSuccessDeleteRoom"><h1>Your project has been removed</h1></div>',
        height:150,
	   width:400,
	   title: '',
	   options:{enableKeys:false, displayNav:true, onClose:refreshPage} });
}
//
function deleteInspiration(projectID) {
	if (confirm("Are you sure you want to delete this from My Inspirations? This cannot be undone.")) {
		var url = "ajax/DeleteInspirationAjax.html";
		var data="projectID="+encodeURIComponent(projectID);
		data+="&r="+Math.random();
		var myAjax = new Ajax.Request(url,{asynchronous:true, method:'post',parameters:data, onSuccess:deleteInspirationSC, onFailure:errFunc});
	}
}
//
function deleteInspirationSC(r) {
	if (r.responseText.indexOf("success") > 0) {
		showDeleteInspirationSuccess();
	} else {
		if (r.responseText.indexOf("NotLoggedIn") >= 0) {
			writeError("An error has occurred.", "You must be logged in to delete this inspiration.");
		} else {
			writeError("An error has occurred.", "Please try again.");
		}
	}	
}
//
function showDeleteInspirationSuccess() {
	Shadowbox.open({
        player: 'html',
	   modal:false,
	   content: '<div class="cntError" id="cntSuccessDeleteRoom"><h1>The project has been removed from My Inspirations</h1></div>',
        height:150,
	   width:400,
	   title: '',
	   options:{enableKeys:false, displayNav:true, onClose:refreshPage} });
}
//
// SHADOWBOX SHARED FORMS
//
// - - - - - - - - - - - - - - - - - - 
// YOUR REVIEW
// - - - - - - - - - - - - - - - - - - 
//
function setRating(iMainRating, iCat1Rating, iCat2Rating, iCat3Rating) {
	$("fldMainRating").value = iMainRating;
	$("fldCat1Rating").value = iCat1Rating;
	$("fldCat2Rating").value = iCat2Rating;
	$("fldCat3Rating").value = iCat3Rating;
}
//
function showYourReview() {
	Shadowbox.open({
        player: 'iframe',
	   modal:false,
	   content: 'ajax/SbYourReviewAjax.html',
        height:345,
        width:750,
	   title: '',
	   options:{enableKeys:false, displayNav:true, onClose:refreshPage} });
}
//
function validateYourReview() {
	$("cntFormError").style.display = "none";
	var bValid = true;
	var bRatingValid = true;
	var bError = false;
	var sReviewTitle, sReviewDescription, sMainRating, sCat1Rating, sCat2Rating, sCat3Rating;
	try { sReviewTitle = $F("fldReviewTitle"); } catch(e) { bError = true; };
	try { sReviewDescription = $F("fldReviewDescription"); } catch(e) { bError = true; };
	try { sMainRating = $F("fldMainRating"); } catch(e) { bError = true; };
	try { sCat1Rating = $F("fldCat1Rating"); } catch(e) { bError = true; };
	try { sCat2Rating = $F("fldCat2Rating"); } catch(e) { bError = true; };
	try { sCat3Rating = $F("fldCat3Rating"); } catch(e) { bError = true; };
	if (!validate('t',true,sReviewTitle,'fldReviewTitle','lblYourReviewTitle')) { bValid = false; }
	if (!validate('t',true,sReviewDescription,'fldReviewDescription','lblYourReviewDescription')) { bValid = false; }
	if (!validate('t',true,sMainRating,'fldMainRating','lblMainRating')) { bValid = false; bRatingValid = false; }
	if (!validate('t',true,sCat1Rating,'fldCat1Rating','lblCat1Rating')) { bValid = false; bRatingValid = false; }
	if (!validate('t',true,sCat2Rating,'fldCat2Rating','lblCat2Rating')) { bValid = false; bRatingValid = false; }
	if (!validate('t',true,sCat3Rating,'fldCat3Rating','lblCat3Rating')) { bValid = false; bRatingValid = false; }
	if (bError) {
		parent.writeError("An error has occurred.", "Please try again.");
	} else if (bValid) {
		saveReview();
	} else {
		if (bRatingValid) {
			$("cntFormError").innerHTML = "<p>Unable to submit your request. Please review the fields in red.</p>";
			$("cntFormError").style.display = "block";
		} else {
			$("cntFormError").innerHTML = "<p>Unable to submit your request. Please ensure you have provided a star rating for each category.</p>";
			$("cntFormError").style.display = "block";
		}
	}
}
//
function saveReview() {
	var url = "../ajax/PutReviewAjax.html";
	var data="projectID=-1";
	data+="&overallRating="+encodeURIComponent($F("fldMainRating"));
	data+="&smellRating="+encodeURIComponent($F("fldCat1Rating"));
	data+="&coverageRating="+encodeURIComponent($F("fldCat2Rating"));
	data+="&valueRating="+encodeURIComponent($F("fldCat3Rating"));
	data+="&reviewTitle="+encodeURIComponent($F("fldReviewTitle"));
	data+="&reviewDescription="+encodeURIComponent($F("fldReviewDescription"));
	data+="&r="+Math.random();
	var myAjax = new Ajax.Request(url,{asynchronous:true, method:'post',parameters:data, onSuccess:saveReviewSC, onFailure:errFunc});
}
//
function saveReviewSC(r) {
	if (r.responseText.indexOf("success") > 0) {
		$("sbYourReview").style.display = 'none';
		$("cntSuccess").style.display = 'block';
	} else {
		parent.writeError("An error has occurred when attempting to share this content. Please try again.");
	}
}
//
// - - - - - - - - - - - - - - - - - - 
// SHARE WITH A FRIEND
// - - - - - - - - - - - - - - - - - - 
//
function showShareWithFriend(sUrl) {
	Shadowbox.open({
        player: 'iframe',
	   modal:false,
	   content: 'ajax/SbShareWithFriendAjax.html?shareURL='+escape(sUrl),
        height:415,
        width:750,
	   title: '',
	   options:{enableKeys:false, displayNav:true} });
}
//
function validateShareWithFriend() {
	var bValid = true;
	var bError = false;
	var sProjectID, sYourAddress, sFriendAddress;
	//
	try { sYourAddress = $F("fldInviteYourAddress"); } catch(e) { bError = true; };
	try { sFriendAddress = $F("fldInviteAddress"); } catch(e) { bError = true; };
	//
	if (!validate('e',true,sYourAddress,'fldInviteYourAddress','lblInviteYourAddress')) { bValid = false; }
	if (!validate('e',true,sFriendAddress,'fldInviteAddress','lblInviteAddress')) { bValid = false; }
	//
	if (bError) {
		parent.writeError("An error has occurred.", "Please try again.");
	} else if (bValid) {
		saveShareWithFriend();
	} else {
		$("cntFormError").innerHTML = "<p>Unable to submit your request. Please review the fields in red.</p>";
		$("cntFormError").style.display = "block";
	}
}
//
function saveShareWithFriend() {
	try { 
		var url = "../ajax/PutShareWithFriendAjax.html";
		var data="shareURL=" +encodeURIComponent($F("fldShareURL"));
		data+="&yourEmail="+encodeURIComponent($F("fldInviteYourAddress"));
		data+="&friendEmail="+encodeURIComponent($F("fldInviteAddress"));
		data+="&msg="+encodeURIComponent($F("fldInviteMessage"));
		data+="&r="+Math.random();
		var myAjax = new Ajax.Request(url,{asynchronous:true, method:'post', parameters:data, onSuccess:saveShareWithFriendSC, onFailure:errFunc});
	 } catch(e) {
		parent.writeError("An error has occurred.", "Please try again.");
	};
}
//
function saveShareWithFriendSC(r) {
	if (r.responseText.indexOf("success") > 0) {
		$("sbShareWithFriend").style.display = 'none';
		$("cntSuccess").style.display = 'block';
	} else {
		parent.writeError("An error has occurred when attempting to share this content. Please try again.");
	}
}
//
// - - - - - - - - - - - - - - - - - - 
// REPORT AS INAPPROPRIATE
// - - - - - - - - - - - - - - - - - - 
//
function showReportAsInappropriate(sType, sID) {
	Shadowbox.open({
		player: 'iframe',
		modal: false,
		content: 'ajax/SbReportAsInappropriateAjax.html?sType='+escape(sType)+'&sID='+escape(sID),
		height: 325,
		width: 750,
		title: '',
		options:{enableKeys:false, displayNav:true, onClose:refreshPage} });
}
//
function validateReportAsInappropriate() {
	var bValid = true;
	var bError = false;
	var sReportEmailAddress, sReportReason, sReportType, sReportID;
	//
	try { sReportEmailAddress = $F("fldReportEmailAddress"); } catch(e) { bError = true; };
	try { sReportReason = $F("fldReportReason"); } catch(e) { bError = true; };
	try { sReportType = $F("fldReportType"); } catch(e) { bError = true; };
	try { sReportID = $F("fldReportID"); } catch(e) { bError = true; };
	//
	if (!validate('e',true,sReportEmailAddress,'fldReportEmailAddress','lblReportEmailAddress')) { bValid = false; }
	if (!validate('t',true,sReportReason,'fldReportReason','lblReportReason')) { bValid = false; }
	if (!validate('t',true,sReportType,"fldReportType","")) { bValid = false; }
	if (!validate('t',true,sReportID,"fldReportID","")) { bValid = false; }
	//
	if (bError) {
		parent.writeError("An error has occurred.", "Please try again.");
	} else if (bValid) {
		saveReportAsInappropriate();
	} else {
		$("cntFormError").innerHTML = "<p>Unable to submit your request. Please review the fields in red.</p>";
		$("cntFormError").style.display = "block";
	}
}
//
function saveReportAsInappropriate() {
	try { 
		var url = "../ajax/PutInappropriateReportAjax.html";
		var data="reportID=" +encodeURIComponent($F("fldReportID"));
		data+="&reportType="+encodeURIComponent($F("fldReportType")); // can be 'project' or 'review'
		data+="&reportReason="+encodeURIComponent($F("fldReportReason"));
		data+="&reportEmail="+encodeURIComponent($F("fldReportEmailAddress"));
		data+="&r="+Math.random();
		var myAjax = new Ajax.Request(url,{asynchronous:true, method:'post', parameters:data, onSuccess:saveReportAsInappropriateSC, onFailure:errFunc});
	 } catch(e) {
		parent.writeError("An error has occurred.", "Please try again.");
	};
}
//
function saveReportAsInappropriateSC(r) {
	if (r.responseText.indexOf("success") > 0) {
		$("sbReportAsInappropriate").style.display = 'none';
		$("cntSuccess").style.display = 'block';
	} else {
		parent.writeError("An error has occurred when attempting to report this content.", "Please try again.");
	}
}
//
// - - - - - - - - - - - - - - - - - - 
// EDIT PROFILE
// - - - - - - - - - - - - - - - - - - 
//
function showEditProfileEmail() {
	Shadowbox.open({
        player: 'iframe',
	   modal:false,
	   content: 'ajax/SbEditProfileEmailAjax.html',
        height:400,
        width:750,
	   title: '',
	   options:{enableKeys:false, displayNav:true} });
}
//
function validateProfileEmail() {
	var bValid = true;
	var bError = false;
	var sOldEmail, sNewEmail, sNewEmailConfirm;
	//
	try { sOldEmail = $F("fldEditOldEmail"); } catch(e) { bError = true; };
	try { sNewEmail = $F("fldEditNewEmail"); } catch(e) { bError = true; };
	try { sNewEmailConfirm = $F("fldEditReNewEmail"); } catch(e) { bError = true; };
	//
	if (!validate('t',true,sOldEmail,'fldEditOldEmail','lblEditOldEmail')) { bValid = false; }
	if (!validate('t',true,sNewEmail,"fldEditNewEmail","lblEditNewEmail")) { bValid = false; }
	if (!validate('t',true,sNewEmailConfirm,"fldEditReNewEmail","lblEditReNewEmail")) { bValid = false; }
	if (!validateMatch('fldEditNewEmail','fldEditReNewEmail','lblEditReNewEmail')) {
		$("cntFormError").innerHTML = "<p>The emails you entered did not match. Please enter them again.</p>";
		$("cntFormError").style.display = "block";
		return false;
	}
	//
	if (bError) {
		parent.writeError("An error has occurred.", "Please try again.");
	} else if (bValid) {
		saveEditProfileEmail();
	} else {
		$("cntFormError").innerHTML = "<p>Unable to submit your request. Please review the fields in red.</p>";
		$("cntFormError").style.display = "block";
	}
}
//
function saveEditProfileEmail() {
	try { 
		var url = "../ajax/PutEditProfileEmailAjax.html";
		var data="email=" +encodeURIComponent($F("fldEditNewEmail"));
		data+="&oldemail=" +encodeURIComponent($F("fldEditOldEmail"));
		data+="&r="+Math.random();
		var myAjax = new Ajax.Request(url,{asynchronous:true, method:'post', parameters:data, onSuccess:saveEditProfileEmailSC, onFailure:errFunc});
	 } catch(e) {
		parent.writeError("An error has occurred.", "Please try again.");
	};
}
//
function saveEditProfileEmailSC(r) {
	if (r.responseText.indexOf("success") > 0) {
		$("sbEditProfile").style.display = 'none';
		$("cntSuccess").style.display = 'block';
	} else {
		if (r.responseText.indexOf("WrongEmail") >= 0) {
			$("cntFormError").innerHTML = "<p>The old email you provided was not valid. Please try again.</p>";
			$("cntFormError").style.display ="block";
		} else {
			parent.writeError("An error has occurred when attempting to edit your profile.", "Please try again.");
		}
	}
}
//
function showEditProfilePassword() {
	Shadowbox.open({
        player: 'iframe',
	   modal:false,
	   content: 'ajax/SbEditProfilePasswordAjax.html',
        height:400,
        width:750,
	   title: '',
	   options:{enableKeys:false, displayNav:true} });
}
//
function validateProfilePassword() {
	var bValid = true;
	var bError = false;
	var sOldEmail, sNewEmail, sNewEmailConfirm;
	//
	try { sOldPass = $F("fldEditOldPassword"); } catch(e) { bError = true; };
	try { sNewPass = $F("fldEditNewPassword"); } catch(e) { bError = true; };
	try { sNewPassConfirm = $F("fldEditReNewPassword"); } catch(e) { bError = true; };
	//
	if (!validate('t',true,sOldPass,'fldEditOldPassword','lblEditOldPassword')) { bValid = false; }
	if (!validate('t',true,sNewPass,"fldEditNewPassword","lblEditNewPassword")) { bValid = false; }
	if (!validate('t',true,sNewPassConfirm,"fldEditReNewPassword","lblEditReNewPassword")) { bValid = false; }
	if (!validateMatch('fldEditNewPassword','fldEditReNewPassword','lblEditReNewPassword')) {
		$("cntFormError").innerHTML = "<p>The passwords you entered did not match. Please enter them again.</p>";
		$("cntFormError").style.display = "block";
		return false;
	}
	//
	if (bError) {
		parent.writeError("An error has occurred.", "Please try again.");
	} else if (bValid) {
		saveEditProfilePassword();
	} else {
		$("cntFormError").innerHTML = "<p>Unable to submit your request. Please review the fields in red.</p>";
		$("cntFormError").style.display = "block";
	}
}
//
function saveEditProfilePassword() {
	try { 
		var url = "../ajax/PutEditProfilePasswordAjax.html";
		var data="pwd=" +encodeURIComponent($F("fldEditNewPassword"));
		data+="&oldpwd=" +encodeURIComponent($F("fldEditOldPassword"));
		data+="&r="+Math.random();
		var myAjax = new Ajax.Request(url,{asynchronous:true, method:'post', parameters:data, onSuccess:saveEditProfilePasswordSC, onFailure:errFunc});
	 } catch(e) {
		parent.writeError("An error has occurred.", "Please try again.");
	};
}
//
function saveEditProfilePasswordSC(r) {
	if (r.responseText.indexOf("success") > 0) {
		$("sbEditProfile").style.display = 'none';
		$("cntSuccess").style.display = 'block';
	} else {
		if (r.responseText.indexOf("WrongPassword") >= 0) {
			$("cntFormError").innerHTML = "<p>The old password you provided was not valid. Please try again.</p>";
			$("cntFormError").style.display ="block";
		} else {
			parent.writeError("An error has occurred when attempting to edit your profile.", "Please try again.");
		}
	}
}
//
function showEditProfilePreferences() {
	Shadowbox.open({
        player: 'iframe',
	   modal:false,
	   content: 'ajax/SbEditProfileEmailPreferencesAjax.html',
        height:400,
        width:750,
	   title: '',
	   options:{enableKeys:false, displayNav:true} });
}
//
function saveEditProfilePreferences(bOptin) {
	if (bOptin) {
		bOptin = true;
	} else {
		bOptin = false;
	}
	try { 
		var url = "../ajax/PutEditProfilePreferencesAjax.html";
		var data="optin="+bOptin;
		data+="&r="+Math.random();
		var myAjax = new Ajax.Request(url,{asynchronous:true, method:'post', parameters:data, onSuccess:saveEditProfilePreferencesSC, onFailure:errFunc});
	 } catch(e) {
		parent.writeError("An error has occurred.", "Please try again.");
	};
}
//
function saveEditProfilePreferencesSC(r) {
	if (r.responseText.indexOf("success") > 0) {
		$("sbEditProfile").style.display = 'none';
		$("cntSuccess").style.display = 'block';
	} else {
		parent.writeError("An error has occurred when attempting to edit your profile.", "Please try again.");
	}
}
//
function validatePostSuggestion() {
	if (validate('t',true,$F("fldComment"),'fldComment','lblComment')) {
		savePostSuggestion();
	} else {
		writeError("Unable to save your suggestion.", "Please ensure you have entered your comments and click submit.");
	}
}
//
function savePostSuggestion() {
	try {
		$("cntCommentsForm").style.display = 'none';
		var url = "ajax/PutSuggestionAjax.html";
		var data="suggestionText="+encodeURIComponent($F("fldComment"));
		data+="&projectID="+encodeURIComponent($F("fldProjectID"));
		data+="&r="+Math.random();
		var myAjax = new Ajax.Request(url,{asynchronous:true, method:'post', parameters:data, onSuccess:savePostSuggestionSC, onFailure:errFunc});
	 } catch(e) {
		writeError("An error has occurred.", "Please try again.");
	};
}
//
function savePostSuggestionSC(r) {
	if (r.responseText.indexOf("success") > 0) {
		showPostSuggestionSuccess();
	} else {
		writeError("An error has occurred when attempting to save your suggestion.", "Please try again.");
	}
}
//
function showPostSuggestionSuccess() {
	Shadowbox.open({
        player: 'html',
	   content: '<div class="cntError" id="cntSuccessDeleteRoom"><h1>Your suggestion has been saved.</h1><p>Thank you for your suggestions. Your posting may not appear on the site immediately.</p></div>',
        height:250,
	   width:400,
	   title: ''});
}

