

var nocache              = ""//"?nocache=" + new Date( ).getTime( );//turn off for production. used to bust cache on local copy

var flashvars            = {};

flashvars.xmlPath        = "xml/pinsol.xml";
flashvars.host           = window.location.host;
if ( !couponUrl ) var couponUrl = null;
flashvars.coupon		 = 	escape(couponUrl);

var params               = {};

params.menu              = "false";
params.scale             = "noscale";
params.salign            = "tl";
params.wmode             = "opaque";
params.bgcolor           = "#FFFFFF";
params.allowFullScreen   = "true";
params.allowScriptAccess = "always";

var attributes           = {};

var firstVisit = "swf/preloader.swf";

var attemptingCoupon = false; //flag set if the user has clicked on get coupon, and is now in the flow for writting a review to get one.



swfobject.embedSWF(firstVisit+nocache, "myContent", "100%", "100%", "10.0.0", "swf/expressInstall.swf", flashvars, params, attributes);








$(document).ready(function() {
	closeBV();
	//showFBLike("test");
	// hide

	$('#close_contact').click(function() {
		closeBV();
		return false;
	});
	$('#close_read').click(function() {
		closeBV();
		return false;
	});

	$('#close_write').click(function() {
		closeBV();
		return false;
	});
	
	$('#close_story').click(function() {
		closeBV();
		return false;
	});	
	
	
	$('#close_survey').click(function() {
		closeSurvey();
		return false;
	});
	
	$('#surveyStartBtn').click(function() {
		//window.open = "http://survey56.datacollectionsite.com/s?I.Project=P110288";
		setSurveyCookie();
		return true;
	});
	
	$.ajaxSetup ({  
		  cache: false  
	});

	
});


	$BV.configure("global", {
		
		facebookXdChannelUrl: "/facebook_xd_receiver.htm",
		allowSamePageSubmission: true,
		submissionContainerDiv:"BVRWContainer",
		doScrollSubmission: function() {
			document.getElementById("BVRWContainer").scrollTop = 0;
			return false;
		}
	});

/**
 * 
 * launches the contact us div
 * 
 * 
 */	
	
function contactUs()
{
	$('#contact').show();
	$("#contactusHeader").html('<h1>Contact Us<br>Send your question or comments</h1><p>If you have questions or comments not answered in our <b>Products</b> section please fill out and submit the contact us form below. Thank you for your feedback!</p>');
	$("#contactus").html("<iframe class='ContactUs' frameborder='0' src='https://contactclorox.marketlocator.com/pinesol/'></iframe>");
};


	

/**
*
*@param id : int   integer passed in to write a particular BV review
*
*
*/

function writeBazaarvoiceReview( id )
{
	closeBV();	
	$('#write_headline').html("<h1>Write a Review</h1>");
	$BV.ui("rr", "submit_review", {
		productId: id
	});
	$('#bv_write').show();
}

function  writeBazaarvoiceReviewForCoupon ()
{
	
	attemptingCoupon = true;
	closeBV();
	$('#write_headline').html("<h1>Write a review. Receive a 50&cent; OFF COUPON.</h1><p>Simply add your thoughts to our Rating & Reviews page then download your coupon good towards savings on any of our products.</p>");
	
	$BV.ui("rr", "submit_review", {
		onEvent: function(json) {
			isReviewWrittenForCoupon(json);
		},
		chooseProduct: "true"
	});
	$('#bv_write').show();

}


function isReviewWrittenForCoupon(json)
{
	 
//let's keep this untill after we get through QA, and maybe after in case we need to debug in the future.
//	  var x = "";
//	  for( a in json)
//	  {
//		  x += (a + " = " + json[a]  ) + "\n\r";
//	  }
//	  console.log("============================");
//	  console.log( x );

	  
	
	
	if ( json.pageType == "Confirm" && json.eventSource == "Display" && attemptingCoupon)
	{
		//alert("review submitted for coupon");
	
	
		$('#write_headline').html("<br><br>");
		$('#BVRWContainer').html("<img src='images/loading/loading.gif' />").load( "coupon/thankyou.html" );	
	}
}




/**
*
*@param id : int   integer passed in to read a particular BV review
*
*
*/


function readBazaarvoiceReview( id )
{
	//alert("readBazaarvoiceReview");
	closeBV();
	$BV.ui("rr", "show_reviews", {
		doShowSubmission: function () {
			writeBazaarvoiceReview(id)},
			productId: id
		});
		$('#bv_read').show();
}

/**
 * 
 * 
 */
function hideFBLike() {
	
	//alert("hide like");
	
	$('#facebook_like').hide();
	$('#facebook_like').css('position', 'relative');
}

//hideFBLike();

function showFBLike(page) {
	
	page = window.location.protocol + "//" + window.location.host + page; //Christine is there a better way to do this? 
	//alert("show like");
	
	$('#facebook_like').show();
	$('#facebook_like').html("<iframe src=\"http://www.facebook.com/plugins/like.php?href="+urlencode(page)+"&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:250px; height:80px;\" allowTransparency=\"true\"></iframe> <a href=\"#\" onclick=\"hideFBLike()\">Close</a>");
	//facebookDiv.innerHTML = "<iframe src=\"http://www.facebook.com/plugins/like.php?href="+urlencode(document.location.href)+"&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:250px; height:80px;\" allowTransparency=\"true\"></iframe>";
}



function urlencode(str) {
	return escape(str).replace('+', '%2B').replace('%20', '+').replace('*', '%2A').replace('/', '%2F').replace('@', '%40');
}

function closeBV() {

	$('#bv_story').hide();

	$('#bv_write').hide();

	$('#bv_read').hide();

	$('#contact').hide();

}

function showSurvey() {	
	if(getSurveyCookie("survey") != "true") {
		$('#survey').show();
	}
}

function closeSurvey() {
	$('#survey').hide();
}

function setSurveyCookie() {
	document.cookie="survey=" +"true";	
}

function getSurveyCookie(cookieName) {
	if (document.cookie.length>0)
	  {
	  cookieStart=document.cookie.indexOf(cookieName + "=");
	  if (cookieStart!=-1)
		{
		cookieStart=cookieStart + cookieName.length+1;
		cookieEnd=document.cookie.indexOf(";",cookieStart);
		if (cookieEnd==-1) cookieEnd=document.cookie.length;
		return unescape(document.cookie.substring(cookieStart,cookieEnd));
		}
	  }
	return "";
}


$BV.configure("sy", {
    submissionContainerDiv:"BVSYContainer",
    doScrollSubmission: function() {
        document.getElementById("BVSYContainer").scrollTop = 0;
        return false;
    }
});

function showBVStories()
{
	$BV.ui("sy", "show_stories", {
			productId: "STY_1",
			subjectType: 'product'
		});
	$('#bv_story').show();
	//alert("I should show BV stories");
}

function hideBVStories()
{
	//alert("I shoudl close BV stories");
	closeBV() ;
}


//showBVStories();



