var g_CurrentFlyout = "";
var g_CurrentBubble = "";

var g_CurrentSpecialFocus = "";		
var g_DebugSpecialBubbles = false;	

var g_Stalled = false;
var g_MenuMustClose = false;
var g_MenuDebugIsOn = false;

var g_MastheadOffsetHeight = 0;

var g_CancelConsoleHide = false;

var g_BoxFloat_LastY = 0;
var g_BoxFloat_Count = 0;

var b_LogonInProgress = false;
var b_ForgotPasswordInProgress = false;

var b_BusyReporting = false;

var b_TermAndConditionsAccepted = false;

var g_CurrentPersonalisationUpsellId = "UpsellItem0";


/* SPECIALS PAGE FUNCTIONS */
function SpecialGetFocus(event, oDiv){
	document.getElementById(g_CurrentSpecialFocus)&&g_CurrentSpecialFocus!=oDiv.id+"_Blurb"?SpecialDelayLoseFocus(document.getElementById(g_CurrentSpecialFocus.replace("_Blurb",""))):null;

	var oBlurb = document.getElementById(oDiv.id+"_Blurb");
	var s_Debug = "";
	var b_SPParentParentIsNotBody = false;
	var i_PositionFromLeft = oDiv.offsetLeft;
	var i_PositionFromTop = oDiv.offsetTop;
	
	if(oBlurb){
		oBlurb.style.display = "block";
		
		oDebug = document.getElementById("SPDebugRectangle");

		if(g_DebugSpecialBubbles&&oDebug){
			oDebug.style.display = "block";
		}
		
		if(oDiv.offsetParent.offsetParent.id!=null&&oDiv.offsetParent.offsetParent.id=="Content"){
			b_SPParentParentIsNotBody = true;
		}
		
		if(BrowserDetect.browser=="Explorer"&&BrowserDetect.version>5){
			i_PositionFromTop = oDiv.offsetParent.offsetTop+oDiv.offsetTop;
			i_PositionFromLeft = oDiv.offsetParent.offsetLeft+oDiv.offsetLeft;
		}
		
		if(g_DebugSpecialBubbles){
			s_Debug += "oDiv.offsetLeft = " + oDiv.offsetLeft + " | ";
			s_Debug += "b_SPParentParentIsNotBody = " + b_SPParentParentIsNotBody + " | ";
			s_Debug += "oBlurb.REQUIREDWIDTH = " + (oBlurb.offsetWidth-(oBlurb.offsetWidth-oDiv.offsetWidth)) + " | ";
			s_Debug += "oDiv.offsetHeight = " + oDiv.offsetHeight + " | ";
			s_Debug += "i_PositionFromTop = " + i_PositionFromTop + " | ";
			s_Debug += "i_PositionFromLeft = " + i_PositionFromLeft + " | ";
			i_PositionFromLeft
		}
		
		if(g_DebugSpecialBubbles&&oDebug){
			oDebug.style.top = i_PositionFromTop;
			oDebug.style.left = i_PositionFromLeft+(b_SPParentParentIsNotBody?1:0);
			oDebug.style.width = oDiv.offsetWidth-2;
			oDebug.style.height = oDiv.offsetHeight-2;										
			oDebug.innerText = s_Debug;
		}
		
		if(g_DebugSpecialBubbles){
			window.status = s_Debug;
		}
		
		oBlurb.style.left = i_PositionFromLeft+(b_SPParentParentIsNotBody?1:0);
		oBlurb.style.width = oDiv.offsetWidth-12;
		oBlurb.style.top =  i_PositionFromTop+oDiv.offsetHeight-oBlurb.offsetHeight-1;
		g_CurrentSpecialFocus = oBlurb.id;
	}	
	event.cancelBubble = true;
	return false;
}
function SpecialDelayLoseFocus(oDiv){
	var oBlurb = document.getElementById(oDiv.id + "_Blurb");									
	if(oBlurb){
		window.setTimeout("SpecialLoseFocus(\"" + oBlurb.id + "\");", 1000);
	}
	return false;
}
function SpecialLoseFocus(sDivId){
	var oBlurb = document.getElementById(sDivId);
	if(oBlurb){
		oBlurb.style.display = "none";
	}
}		


/* ADMIN CONSOLE FUNCTIONS */
function highlightConsole(curObj){
  dontDampenConsole();
  curObj.className = curObj.className.replace("adminConsoleInactive", "adminConsoleActive"); 
}
function dampenConsole(sCurrentId){
  if(g_CancelConsoleHide){
    document.getElementById(sCurrentId).className = document.getElementById(sCurrentId).className.replace("adminConsoleActive", "adminConsoleInactive");
    g_CancelConsoleHide = false;
  }
}
function waitDampenConsole(curObj){
	self.setTimeout("dampenConsole(\""+curObj.id+"\");", 4000);
}
function dontDampenConsole(){
  g_CancelConsoleHide = true;
}

function NetFloristZoomOpen(){
  var oZoomed = document.getElementById("ImageZoomed");
  var oTT = document.getElementById("Title");
  if(oZoomed){
	oTT?oZoomed.style.top=oTT.offsetHeight:null;
    oZoomed.className = oZoomed.className.replace("hideMe","showMe");
  }
}
function NetFloristZoomClose(){
  var oZoomed = document.getElementById("ImageZoomed");
  if(oZoomed!=null){
    oZoomed.className = oZoomed.className.replace("showMe","hideMe");
  }
}
function delayZoomOut(){
  self.setTimeout("NetFloristZoomClose();", 500)
}

function RefreshTemplate(){
	g_MastheadOffsetHeight = 0;
	_fn_FTA();
}

/****************************************************/
/*  Executes final sizing adjustments to the page   */
/*  -  Adjusts IE rightbar to compensate for footer */
/****************************************************/
function _fn_FTA()
{
	var bDebug = false;
	var vVersion = 1;
	
	if(vVersion==1){
		if(BrowserDetect.browser!="Weird"){
			var o_RB = document.getElementById("Rightbar");
			var o_RBE = document.getElementById("RightbarBarEnd");
			var o_FT = document.getElementById("Footer");
			var o_CT = document.getElementById("Content");
			var o_TT = document.getElementById("Title");
			
			var o_M = document.getElementById("Main");
			bDebug?window.status="o_M.oH " + (o_M.offsetHeight) + " | "+window.status.substring(0,100):null;
			
			if(o_RB&&o_FT&&o_RBE&&o_CT&&o_TT){
				bDebug?window.status="o_RB.oP.oH " + (o_RB.offsetParent.offsetHeight) + " | "+window.status.substring(0,100):null;
				bDebug?window.status="o_RB.oH " + (o_RB.offsetHeight) + " | "+window.status.substring(0,100):null;
				bDebug?window.status="o_FT.oH " + (o_FT.offsetHeight) + " | "+window.status.substring(0,100):null;
				bDebug?window.status="o_CT.oH " + (o_CT.offsetHeight) + " | "+window.status.substring(0,100):null;
				bDebug?window.status="o_TT.oH " + (o_TT.offsetHeight) + " | "+window.status.substring(0,100):null;
				
				if((o_TT.offsetHeight+o_CT.offsetHeight)<o_RB.offsetHeight){
					
					//rightbar taller
					bDebug?window.status="o_RB taller | "+window.status.substring(0,100):null;
					
					//make content same height as rightbar (minus title box)
					o_CT.style.height = o_RB.offsetHeight - o_TT.offsetHeight;
					
					bDebug?window.status="o_CT.oH " + (o_CT.offsetHeight) + " | "+window.status.substring(0,100):null;
	
					
					//wtf? why do I need to do this, what am I missing?
					o_FT.style.position = "relative";
					o_FT.style.top = -30;
					
					bDebug?window.status="o_FT.oH " + (o_FT.offsetHeight) + " | "+window.status.substring(0,100):null;
					
				}
				else				
				{
					//content taller
					bDebug?window.status="o_CT taller | "+window.status.substring(0,100):null;	
					
					if(location.href.indexOf("Search.")==-1){
						//make rightbar same height as content plus title box
						o_RB.style.height = o_CT.offsetHeight + o_TT.offsetHeight;
					}
					else
					{
						o_RB.style.height = o_M.offsetHeight -  o_FT.offsetHeight + 58;
					}
				}

				if((BrowserDetect.browser=="GoogleChrome"||BrowserDetect.browser=="Firefox")&&bDebug&&window.status.length>0)
				{
					alert(window.status);
				}
			}
		}	
	}
	if(vVersion==0){
		if(BrowserDetect.browser!="Weird"){
			var o_RB = document.getElementById("Rightbar");
			var o_RBE = document.getElementById("RightbarBarEnd");
			var o_FT = document.getElementById("Footer");
			var o_CT = document.getElementById("Content");
			var o_TT = document.getElementById("Title");
			
			var o_M = document.getElementById("Main");
			bDebug?window.status="o_M.oH " + (o_M.offsetHeight) + " | "+window.status.substring(0,100):null;
			
			if(o_RB&&o_FT&&o_RBE&&o_CT&&o_TT){
				bDebug?window.status="o_RB.oP.oH " + (o_RB.offsetParent.offsetHeight) + " | "+window.status.substring(0,100):null;
				bDebug?window.status="o_RB.oH " + (o_RB.offsetHeight) + " | "+window.status.substring(0,100):null;
				bDebug?window.status="o_FT.oH " + (o_FT.offsetHeight) + " | "+window.status.substring(0,100):null;
				if((o_RB.offsetHeight-o_FT.offsetHeight)>=o_RB.offsetParent.offsetHeight){
					bDebug?window.status="o_CT to " + (o_RB.offsetHeight-(o_TT.offsetHeight)-o_RBE.offsetHeight+3) + " | "+window.status.substring(0,100):null;
					o_CT.style.height = o_RB.offsetHeight-(o_TT.offsetHeight)-o_RBE.offsetHeight+3;
				}
				else
				{
					bDebug?window.status="o_RB to " + (o_TT.offsetHeight+o_CT.offsetHeight) + " | "+window.status.substring(0,100):null;
					o_RB.style.height = o_TT.offsetHeight+o_CT.offsetHeight;
				}
			}
		}	
	}
}

/*************************************************/
/*  Draws the site menu based on the hidden UL   */
/*************************************************/
function findMenus(curObj,curLevel, curParent){

    var cTag = curObj.childNodes;
    var sMenuItemTitle = "";
    var sMenuItemLink = "";
    var bIsLevel0 = false;
        
	for(var i=0; i<cTag.length; i++){
	
		if(cTag[i].nodeName=="LI"){
		  
		  iCurrentNFMenu += 1;
		  
		  sMenuItemTitle = cTag[i].getElementsByTagName("A")[0].textContent==null?cTag[i].getElementsByTagName("A")[0].innerText:cTag[i].getElementsByTagName("A")[0].textContent;
		  sMenuItemLink = cTag[i].getElementsByTagName("A")[0].href;
		  sMenuName = "nfMenu" + iCurrentNFMenu;

		  bIsLevel0 = curLevel==0?true:false;
		  
		  if(bIsLevel0){ //if toplevel, add a seperator
		    if(iCurrentNFMenu>1){ //but not for the very first caption
				oCMenu.makeMenu("","","","","",3,23,sCurrentNFRoot+"layout/images/netflorist_menubar_caption_seperator7_g.gif");
		    }
		    else if(iCurrentNFMenu==1)
		    {
				oCMenu.makeMenu("","","","","",3,23,sCurrentNFRoot+"layout/images/spacer.gif");		    
		    }
		  }
		  
		  oCMenu.makeMenu(sMenuName,curParent,sMenuItemTitle,sMenuItemLink,'_self',(curLevel==0?findMenuSize(sMenuItemTitle):168));
		  
		  if(cTag[i].getElementsByTagName("UL")[0]!=null){
		    findMenus(cTag[i].getElementsByTagName("UL")[0], curLevel+1, sMenuName);
		  }
		}		
	}
	
}

/*************************************************/
/*  Repositions the menu                         */
/*************************************************/
function AdjustMenuPosition(){
  g_MenuAnchorStopX = pgHeader?pgHeader.offsetLeft+76:0;
  oCMenu.fromLeft = g_MenuAnchorStopX;
}

/*************************************************/
/*  Caching support: Restructure basket link     */
/*************************************************/
function AdjustBasketLink(cwProd,cwState,cwCountry,cwPrice,cwUpsellList,cwPersonalisationText){
  var s_NewUrl = "";
  if(location.hostname!="www.netflorist.co.za"&&location.hostname!="ww1.netflorist.co.za"){
    s_NewUrl += "http://www.netflorist.co.za";
  }
  s_NewUrl += "/_activecom/prd/addtobasket.asp?cwpg=43&cwprod="+cwProd+"&cwstate="+cwState+"&UseThisCountry="+cwCountry+"&cwprice="+cwPrice+"&ups="+URLEncode(cwUpsellList);
  if(String(cwPersonalisationText)!="undefined"){
	s_NewUrl += "&prn="+URLEncode(cwPersonalisationText);
  }
  
  document.NetFloristForm.action = s_NewUrl;
  document.NetFloristForm.submit();
  
  return true;
}

/*************************************************/
/*  Caching support: Terms and Conditions alert  */
/*************************************************/
function TermsAndConditionsChallenge(){
	var b_TACCResult = true;
	var o_TACCWindow = document.getElementById("TermsConditionsAction");
	
	var b_RequiresTermsAndConditions_Acceptance = document.getElementById("TermsConditionsAction")?true:false;

	if(o_TACCWindow&&b_TermAndConditionsAccepted==false){
		o_TACCWindow.style.display = "block";

		//reposition if necessary
	
		

	}
	
	o_TACCWindow = null;
	
	return ;//b_TACCResult;
}

/*************************************************/
/*  Caching support: Terms and Conditions accept */
/*************************************************/
function TermsAndConditionsAccept(){
	var o_TACCWindow = document.getElementById("TermsConditionsAction");
	
	b_TermAndConditionsAccepted = true;
	
	//change text
	
	//hide	
	o_TACCWindow.style.display = "none";
	
	o_TACCWindow = null;
	
	AddToBasket();
}

/*************************************************/
/*  Caching support: Terms and Conditions cancel */
/*************************************************/
function TermsAndConditionsCancel(){
	var o_TACCWindow = document.getElementById("TermsConditionsAction");
	
	b_TermAndConditionsAccepted = false;
	
	//hide	
	o_TACCWindow.style.display = "none";
	
	o_TACCWindow = null;
}

/*************************************************/
/*  Caching support: Add to basket event         */
/*************************************************/
function AddToBasket(){

  var i_Variant = 0;
  var i_Selected = 1;
  var i_Upsell = 0;
  var s_Upsell = "";
  var i_UpsellCount = 0;
  var s_PersonalisationText = "";
  var b_PersonalisationEnabled = (document.NetFloristForm.prnText?true:false);
  for(i_Variant=0;i_Variant<document.getElementsByName("frmVariantOption").length;i_Variant++){
    if(document.getElementsByName("frmVariantOption")[i_Variant].checked){
      i_Selected = i_Variant + 1;
      break;
    }
  }
  for(i_Variant=0;i_Variant<document.getElementsByName("optUpsellFromInfo").length;i_Variant++){
    if(document.getElementsByName("optUpsellFromInfo")[i_Variant].checked){
      i_UpsellCount += 1;
      if(i_UpsellCount>1){
        s_Upsell += ",";
      }
      s_Upsell += document.getElementsByName("optUpsellFromInfo")[i_Variant].value;
    }
  }
  if(i_UpsellCount==0){
    s_Upsell = "0-0"; //no upsell
  }
  if(b_PersonalisationEnabled){ /* THEN ENFORCE PERSONALISATION */
	if(document.NetFloristForm.prnOption&&document.NetFloristForm.prnOption.value.length>0&&document.NetFloristForm.prnOption.value!="UpsellItem0"){
		if(document.NetFloristForm.prnOption!=g_CurrentPersonalisationUpsellId){ //it's not the default option
			//so set the value from the active text box
			if(document.getElementById(document.NetFloristForm.prnOption.value)){
				var s_TMPPRNName = document.getElementById(document.NetFloristForm.prnOption.value).id.replace("UpsellItem","UpsellItemText");
				var s_TMPPRNLabel = document.getElementById(document.NetFloristForm.prnOption.value).id.replace("UpsellItem","UpsellItemLabel");
				if(document.getElementById(s_TMPPRNName).value.length==0){
					alert("To add this personalisation item to your basket, you need to enter the text that you would like to appear on this product.");
					return;	
				}
				var s_PRNChallenge = "";
				
				if(document.getElementById(s_TMPPRNName)){
					s_PersonalisationText = document.getElementById(s_TMPPRNName).value;
				}
				else
				{
					s_TMPPRNName = document.getElementById(document.NetFloristForm.prnOption.value).id.replace("UpsellItem","UpsellItemLabel");
					if(document.getElementById(s_TMPPRNName)){
						s_PersonalisationText = document.getElementById(s_TMPPRNName).innerText;
					}				
				}	
				
				if(document.getElementById(s_TMPPRNLabel)){
					s_PRNChallenge += "You have chosen the ";
					if(document.getElementById(s_TMPPRNLabel).innerText!=null){
						s_PRNChallenge += document.getElementById(s_TMPPRNLabel).innerText.toUpperCase();				
					}
					else //Firefox fix (yes, I said Firefox fix... not IE fix. IE is the majority. Freetards).
					{
						s_PRNChallenge += document.getElementById(s_TMPPRNLabel).textContent.toUpperCase();
					}
					s_PRNChallenge += " personalisation option.\n\n";
				}
				s_PRNChallenge += "Are you happy with the following text to appear on this gift?\n\n";
				s_PRNChallenge += "     " + s_PersonalisationText + "     \n\n";
				s_PRNChallenge += "Click OK for yes, or click CANCEL to alter the text.";
				
				if(confirm(s_PRNChallenge)!=true){
					return;
				}
			}		
		}  
		else
		{
			alert("Please choose which type of personalistion you would like.");
			return;
		}
	}
	else
	{
		alert("Please choose which type of personalistion you would like.");
		return;
	}
  }  
  
  AdjustBasketLink(s_CurrentProductId,2,s_CurrentCountryId,i_Selected, s_Upsell, s_PersonalisationText);
  return;
}

/*************************************************/
/*  FloatBox repositions floating boxes to an    */
/*  anchor target.                               */
/*************************************************/
function FloatBox(sFloat,sAnchor,iWidth,iSpacingTop,bAddComfortZone){
  var oAnchor = document.getElementById(sAnchor);
  var oFloat = document.getElementById(sFloat);
  var oSpirit = document.getElementById("SpiritLevel");
  var iSpirit = 0;
  var bDebug = false;
  
  var iVersion = 1;
  
  if(iVersion==1){ 
	/* 
		FINAL, RESTRUCTURED HTML, BROWSER WILL NOW AUTOMATICALLY
		TAKE CARE OF WHERE EACH BOX STARTS, BUT, WE STILL ENFORCE
		OUR FLOAT CALCULATION, WHICH DISPLAYS MORE NEATLY THAN 
		WHEN A BROWSER CALCULATES. (i.e. appears shrinkwrapped).
	*/
	if(oAnchor!=null&&oFloat!=null){
	
		//so we can see that the block has been adjusted (debugging)
		bDebug?oFloat.style.backgroundColor = (g_BoxFloat_Count%2==0?"#FF00FF":"#0FFFF0"):null;
		bDebug?oAnchor.style.backgroundColor = (g_BoxFloat_Count%2==0?"#FF00FF":"#0FFFF0"):null;
		
		bDebug?window.status = "ANC oH " + oAnchor.offsetHeight + "| " + window.status.substring(0,100):null;
		bDebug?window.status = "ANC oT " + oAnchor.offsetTop + "| " + window.status.substring(0,100):null;
		
		if(g_BoxFloat_Count==0){
			if( //Firefox 2, GoogleChrome
				(BrowserDetect.browser=="Firefox"&&BrowserDetect.version=="2")
				||
				(BrowserDetect.browser=="GoogleChrome")			
			){
				i_Spirit = oFloat.offsetTop;			
			}
			else //rest
			{
				i_Spirit = oFloat.offsetTop+oAnchor.offsetTop;
			}
		}
		
		if((oFloat.offsetTop-i_Spirit)<oAnchor.offsetHeight){
			bDebug?window.status = "A FT " + oFloat.offsetTop + "| " + window.status.substring(0,100):null;
		}
		else
		{
			bDebug?window.status = "B FT " + oFloat.offsetTop + "| " + window.status.substring(0,100):null;
			oFloat.style.width = iWidth + oAnchor.offsetWidth;
		}
		
		g_BoxFloat_Count++;
	}  
  }
  
  if(iVersion==0){
	/* 
		OLD VERSION, MESSY (to be removed)
	*/
	if(oAnchor!=null&&oFloat!=null){
		//so we can see that the block has been adjusted (debugging)
		bDebug?oFloat.style.backgroundColor = (g_BoxFloat_Count%2==0?"#FF00FF":"#0FFFF0"):null;
	  
		var i_PIFromTop = oAnchor.offsetTop;
	  
		oFloat.style.position = "absolute";
		oFloat.style.top = i_PIFromTop + (g_BoxFloat_LastY*1) + iSpacingTop;
		
		if(oFloat.offsetTop>(oAnchor.offsetHeight+oAnchor.offsetTop)){
			oFloat.style.width = "" + (oAnchor.offsetWidth+iWidth) + "px";
		}
		else //"next to" width
		{
			oFloat.style.left = oAnchor.offsetWidth+(bAddComfortZone?20:0);
			oFloat.style.width = "" + (iWidth) + "px";	
		}
		
		g_BoxFloat_LastY += (oFloat.offsetHeight);
		
		g_BoxFloat_Count++;
	}
  }
}

function nf_LogonStatusString(LogonStatusData){

	var c_LogonStatus_Num  = 0;
	var c_LogonStatus_Description  = 1;
	var c_LogonStatus_FirstName  = 2;
	var c_LogonStatus_LastName  = 3;
	var c_LogonStatus_UserId  = 4;
	
	var s_Data_Num = 0;
	var s_Data_Description = "";
	var s_Data_FirstName = "";
	var s_Data_LastName = "";
	var s_Data_UserId = 0;

	var s_EndKey = "EOL";
	
	var a_Object = LogonStatusData.split("|");
    
	if(a_Object[0]=="OK"){

		var i_Item = 0; 

		for (i_Item=1; i_Item<a_Object.length; i_Item++) 
		{ 
			var a_StatusData = a_Object[i_Item].split(",");
			
			var i_Data = 0;
			
			for (i_Data=0; i_Data<a_StatusData.length; i_Data++) 
			{
				if(i_Data==c_LogonStatus_Num){
					s_Data_Num = URLDecode(a_StatusData[i_Data])*1;
				}
				else if(i_Data==c_LogonStatus_Description){
					s_Data_Description = URLDecode(a_StatusData[i_Data]);
				}
				else if(i_Data==c_LogonStatus_FirstName){
					s_Data_FirstName = URLDecode(a_StatusData[i_Data]);
				}
				else if(i_Data==c_LogonStatus_LastName){
					s_Data_LastName = URLDecode(a_StatusData[i_Data]);
				}
				else if(i_Data==c_LogonStatus_UserId){
					s_Data_UserId = URLDecode(a_StatusData[i_Data])*1;
				}

			}
			
			if(s_Data_Num==200) //logon authenticated
			{
				document.getElementById("NFPanelLoggedNeutral")?document.getElementById("NFPanelLoggedNeutral").style.display="none":null;
				document.getElementById("NFPanelLoggedOff")?document.getElementById("NFPanelLoggedOff").style.display="none":null;
				document.getElementById("NFPanelLoggedOn")?document.getElementById("NFPanelLoggedOn").style.display="block":null;
				
				if(document.all){
					document.getElementById("NFPanelLoggedOnName")?document.getElementById("NFPanelLoggedOnName").innerText = s_Data_FirstName + " " + s_Data_LastName:null;
				} else{
					document.getElementById("NFPanelLoggedOnName")?document.getElementById("NFPanelLoggedOnName").textContent = s_Data_FirstName + " " + s_Data_LastName:null;
				}		
				
			}
			else //not currently logged on
			{
				document.getElementById("NFPanelLoggedNeutral")?document.getElementById("NFPanelLoggedNeutral").style.display="none":null;
				document.getElementById("NFPanelLoggedOn")?document.getElementById("NFPanelLoggedOn").style.display="none":null;
				document.getElementById("NFPanelLoggedOff")?document.getElementById("NFPanelLoggedOff").style.display="block":null;
			}
		}
	}
	return "";
}

function nf_PetalStatusString(PetalStatusData){

	var c_Petals_PetalCountActual  = 0;
	var c_Petals_BouquetsAvailable  = 1;
	var c_Petals_PetalCount  = 2;
	var c_Petals_PetalsToNextLevel  = 3;
	
	var s_Data_PetalCountActual = 0;
	var s_Data_BouquetsAvailable = 0;
	var s_Data_PetalCount = 0;
	var s_Data_PetalsToNextLevel = 0;
	
	var a_Object = PetalStatusData.split("|");
    
	if(a_Object[0]=="OK"&&URLDecode(a_Object[1])!="No results."){
		var i_Item = 0; 

		for (i_Item=1; i_Item<a_Object.length; i_Item++) 
		{ 
			var a_StatusData = a_Object[i_Item].split(",");
			
			var i_Data = 0;
			
			for (i_Data=0; i_Data<a_StatusData.length; i_Data++) 
			{
				if(i_Data==c_Petals_PetalCountActual){
					s_Data_PetalCountActual = a_StatusData[i_Data]*1;
				}
				else if(i_Data==c_Petals_BouquetsAvailable){
					s_Data_BouquetsAvailable = a_StatusData[i_Data]*1;
				}
				else if(i_Data==c_Petals_PetalCount){
					s_Data_PetalCount = a_StatusData[i_Data]*1;
				}
				else if(i_Data==c_Petals_PetalsToNextLevel){
					s_Data_PetalsToNextLevel = a_StatusData[i_Data]*1;
				}
			}
		}
		
		var s_Dialog = "";
		
		s_Dialog += "<img src=\"" + s_ProjectPath + "/layout/images/fp_petals_";
		if(s_Data_PetalCount=="0"&&s_Data_BouquetsAvailable>0){
			s_Dialog += s_Data_PetalCount<0?"0":""+s_Data_PetalCount;
			s_Dialog += s_Data_PetalCount;		
		}
		else
		{
			s_Dialog += s_Data_PetalCount<10?"0":""+s_Data_PetalCount;
			s_Dialog += s_Data_PetalCount;
		}
		s_Dialog += ".gif\" border=\"0\" />";

		
		s_Dialog += "You currently have " + (s_Data_PetalCount>0?"<b>"+GetWordForNumber(s_Data_PetalCount)+" petals</b>":"no petals");
		if(s_Data_BouquetsAvailable>0){
			s_Dialog += ", and <b>" + (s_Data_BouquetsAvailable==1?"one bouquet":GetWordForNumber(s_Data_BouquetsAvailable)+" bouquets") + "</b> available.";
		}
		else
		{
			s_Dialog += ".";
		}
		s_Dialog += "&nbsp; You need " + GetWordForNumber((s_Data_PetalsToNextLevel==0&&s_Data_PetalCount==0?10:s_Data_PetalsToNextLevel)) + " more " + (s_Data_PetalsToNextLevel==1?"petal":"petals") + " to get your next free bouquet.";
		
		document.getElementById("NFPanelPetalsOn")?document.getElementById("NFPanelPetalsOn").innerHTML=s_Dialog:null;
		document.getElementById("NFPanelPetalsOn")?document.getElementById("NFPanelPetalsOn").style.display="block":null;
		
		document.getElementById("NFPanelPetalsOn")?document.getElementById("NFPanelPetalsOn").parentElement.style.display="block":null;		
		document.getElementById("PanelPetalAdvert")?document.getElementById("PanelPetalAdvert").style.display="none":null;
		
		 
	}
	if(a_Object[0]=="OK"&&URLDecode(a_Object[1])=="No results.")
	{
		document.getElementById("PanelPetalAdvert")?document.getElementById("PanelPetalAdvert").style.display="block":null;
		document.getElementById("NFPanelPetalsOn")?document.getElementById("NFPanelPetalsOn").parentElement.style.display="none":null;
	}
	if(a_Object[0]!="OK")
	{
		//alert("Error");
	}
	return "";
}

function nf_LogonNow(){
    b_LogonInProgress = true;
	document.forms[0].action = s_ProjectPath+"/_activecom/prd/logon.asp";
	document.forms[0].ErrorUrl.value = s_ProjectPath+"/Logon.htm";
	if(location.href.toLowerCase().indexOf(s_ProjectPath.toLowerCase()+"/logon.htm")==-1){
		document.forms[0].ReturnUrl.value = location.href;
	}
	else
	{
		if(document.forms[0].ReturnUrl.value.length==0){
			document.forms[0].ReturnUrl.value = s_ProjectPath+"/MyAccount/";
		}
		else
		{
			document.forms[0].ReturnUrl.value = document.forms[0].ReturnUrl.value;
		}
	}
	document.forms[0].submit();
}

function nf_ForgotPasswordNow(){
    b_ForgotPasswordInProgress = true;
	document.forms[0].action = s_ProjectPath+"/_activecom/prd/forgotpassword.asp";
	document.forms[0].ErrorUrl.value = s_ProjectPath+"/ForgotPassword.htm";
	if(location.href.toLowerCase().indexOf(s_ProjectPath.toLowerCase()+"/ForgotPassword.htm")==-1){
		document.forms[0].ReturnUrl.value = location.href;
	}
	else
	{
		if(document.forms[0].ReturnUrl.value.length==0){
			document.forms[0].ReturnUrl.value = s_ProjectPath+"/ForgotPassword.htm";
		}
		else
		{
			document.forms[0].ReturnUrl.value = document.forms[0].ReturnUrl.value;
		}
	}
	document.forms[0].submit();
}

function nf_SelectRelevantVariant(nfFormItemName){
	var sQueryString = "";

	var aQS;
	var sTmp;
	
	sQueryString = location.search.substr(1,location.search.length-1);
	
	var s_PD_Key_CurrentOption = "varopt";
	var s_PD_Value_CurrentOption = "0";
	var i_PD_Value_CurrentOption = 0;
	
	aQS = sQueryString.split("&");
	
	for (i = 0; i < aQS.length; i++) {
		if (aQS[i].substr(0,s_PD_Key_CurrentOption.length+1)==s_PD_Key_CurrentOption+"=") {
			s_PD_Value_CurrentOption = aQS[i].substring(s_PD_Key_CurrentOption.length + 1);
		}
	}
	
	switch(s_PD_Value_CurrentOption){
		case "2":
			i_PD_Value_CurrentOption = 1;
			break;
		case "3":
			i_PD_Value_CurrentOption = 2;
			break;
		case "4":
			i_PD_Value_CurrentOption = 3;
			break;
		case "5":
			i_PD_Value_CurrentOption = 4;
			break;
		default:
			i_PD_Value_CurrentOption = 0;				
	}
	
	selectFormItemRadioOption(nfFormItemName, "NFProductVariant_Name_", i_PD_Value_CurrentOption);
}

function nf_SelectRelevantVariantForce(VariantOption){
	selectFormItemRadioOption("frmVariantOption", "NFProductVariant_Name_", VariantOption-1);
}

function selectFormItemRadioOption(nfFormItemName, nfFormItemLabelNamePrfx, CurrentOption){

	for (i = 0; i < document.getElementsByName(nfFormItemName).length; i++) {
		document.getElementById(nfFormItemLabelNamePrfx+(i+1))?document.getElementById(nfFormItemLabelNamePrfx+(i+1)).className = "unBoldMe":null;
	}

	//bold
	document.getElementById(nfFormItemLabelNamePrfx+(CurrentOption+1))?document.getElementById(nfFormItemLabelNamePrfx+(CurrentOption+1)).className = "boldMe":null;

	if(document.getElementsByName(nfFormItemName).length>0){
	
		//select
		document.getElementsByName(nfFormItemName)?document.getElementsByName(nfFormItemName)[CurrentOption].checked = true:null;		
	
	}
}

function SearchNow(){
	if(!b_LogonInProgress&&!b_ForgotPasswordInProgress){
		var s_SearchText = document.getElementById("PanelSearchText").value;
		var s_SearchCountry = document.NetFloristForm.lstCountry?document.NetFloristForm.lstCountry.options[document.NetFloristForm.lstCountry.selectedIndex].text:"South Africa";
		var b_ResubmitSearch = false;//!self.nf_Search;
		if(b_ResubmitSearch){ //we're on the search page, so just call Ajax search
			s_Active_Search_Value_Text = s_SearchText;
			s_Active_Search_Value_Country = s_SearchCountry;
			s_Active_Search_Value_PageNumber = 1;
			nf_Search(
					s_Active_Search_Value_Text,
					s_Active_Search_Value_Country,
					s_Active_Search_Value_PageNumber,
					-1,
					-1
					);
			return false;
		}
		else //we're not on the search page, so go hit the Search page with clear text search
		{
			location.href = s_ProjectPath+"/Search.htm?Search="+URLEncode(s_SearchText)+"&Country=" + URLEncode(s_SearchCountry) +"&PageNumber=1&PriceStart=-1&PriceStop=-1";
			return false;
		}
	}
	else
	{
		return false;
	}
}

function reportToggle(){
	var o_ERTPanel = document.getElementById("ERTPanel");
	var o_ERTMessage = document.getElementById("ERTMessage");
	var o_ERTStatus = document.getElementById("ERTStatus");
	if(o_ERTPanel){
		if(b_BusyReporting){ //hide it, toggle off
			o_ERTPanel.style.display = "none";			
			o_ERTMessage.blur();
			b_BusyReporting = false;
		}
		else //show it, and toggle on
		{
			o_ERTPanel.style.display = "block";
			o_ERTMessage.focus();
			b_BusyReporting = true;
			o_ERTStatus?o_ERTStatus.innerHTML="&nbsp;":null;
		}
	}
}

function showDateRestrictions(){
	document.getElementById("RestrictionArea")?document.getElementById("RestrictionArea").style.display="block":null;
	document.getElementById("RestrictionAreaLink")?document.getElementById("RestrictionAreaLink").style.display="none":null;
}
function hideDateRestrictions(){
	document.getElementById("RestrictionArea")?document.getElementById("RestrictionArea").style.display="none":null;
	document.getElementById("RestrictionAreaLink")?document.getElementById("RestrictionAreaLink").style.display="block":null;
}

function TogglePersonalisationUpsell(PRNUpsellToggleId){
	var o_PRNOld = document.getElementById(g_CurrentPersonalisationUpsellId);
	var o_PRNNew = document.getElementById(PRNUpsellToggleId);
	var o_PRNDefault = document.getElementById("UpsellItem0");
	
	if(PRNUpsellToggleId!=g_CurrentPersonalisationUpsellId){
		if(o_PRNOld){o_PRNOld.checked = false; }
		if(o_PRNNew){o_PRNNew.checked = true; g_CurrentPersonalisationUpsellId = PRNUpsellToggleId;}
		document.NetFloristForm.prnOption.value = o_PRNNew.id;
	}
	else
	{
		if(o_PRNNew){o_PRNNew.checked = false; }
		if(o_PRNDefault){o_PRNDefault.checked = true; g_CurrentPersonalisationUpsellId = o_PRNDefault.id;}
		document.NetFloristForm.prnOption.value = o_PRNDefault.id;
	}
}

function NetFloristGenericPopup(NFUrlPopup,NFWindowNamePopup) {
  NFUrlPopup = NFUrlPopup.replace(".aspx",".htm");
  msgWindow=window.open(NFUrlPopup,NFWindowNamePopup,'toolbar= 0,location= 0,directories= 0,status= 0,menubar= 0,scrollbars= 0,resizable= 1,copyhistory= 0,width=250,height=250');
  msgWindow.focus();
}
function RA191() {
  msgWindow=window.open('http://ww1.netflorist.co.za/nf_info_product_ra191.asp' ,'ProductInfoWindow','toolbar= 0,location= 0,directories= 0,status= 0,menubar= 0,scrollbars= 0,resizable=0,copyhistory= 0,width=460,height=391');
  msgWindow.focus();
}
function RA192() {
  msgWindow=window.open('http://ww1.netflorist.co.za/nf_info_product_ra192.asp' ,'ProductInfoWindow','toolbar= 0,location= 0,directories= 0,status= 0,menubar= 0,scrollbars= 1,resizable= 0,copyhistory= 0,width=460,height=391');
  msgWindow.focus();
}
function RA194() {
  msgWindow=window.open('http://ww1.netflorist.co.za/nf_info_product_ra194.asp' ,'ProductInfoWindow','toolbar= 0,location= 0,directories= 0,status= 0,menubar= 0,scrollbars= 1,resizable= 0,copyhistory= 0,width=460,height=391');
  msgWindow.focus();
}
function RA195() {
  msgWindow=window.open('http://ww1.netflorist.co.za/nf_info_product_ra195.asp' ,'ProductInfoWindow','toolbar= 0,location= 0,directories= 0,status= 0,menubar= 0,scrollbars= 1,resizable= 0,copyhistory= 0,width=460,height=391');
  msgWindow.focus();
}
function RA196() {
  msgWindow=window.open('http://ww1.netflorist.co.za/nf_info_product_ra196.asp' ,'ProductInfoWindow','toolbar= 0,location= 0,directories= 0,status= 0,menubar= 0,scrollbars= 1,resizable= 0,copyhistory= 0,width=460,height=391');
  msgWindow.focus();
}