//
// pbar.js
//

//document.domain					= "dell.com";

//var m_pbWidth						= 140;
//var m_pbDivSize						= 2;
//var m_pbDivWidth					= "99%";
//var m_pbDivHeight					= "110px";
//var m_pbIframeHeight				= "700px";
//var m_pbIframeWidth					= "300px";

var m_pbBorderColor					= "#CCCCCC";
var m_pbExpandColor					= "#FFFFCC";
var m_pbCollapseColor				= "#FFFFFF";

//var m_imgPrefix					= "http://img.dell.com";
var m_imgPrefix						= "images/dell/";
var m_pbExpandImg;
var m_pbCollapseImg;
var	m_secondaryImg;
var m_spacerImg						= "images/spacer/clear.gif";
var m_spacerHeight					= 2; 
var m_pbPersonalizationBar;
var m_pbWelcomeSection;
var m_pbProfileSection;			
var m_pbRBISection;		
var m_pbRecommendsSection;  
var m_pbCookieInstance;
var m_CartItemCount					= 0;
var m_pbarOrder						= null;
		
var m_pbuser; 
var m_pbProdImgWidth				= 40;
var	m_protectedInit	;

var m_fnameRegex					= new RegExp( "{fname}","g" );
var m_lnameRegex					= new RegExp( "{lname}","g" );
var m_aRegex						= new RegExp( "<A[^>].*(<.*a>)","gi" );
var	m_lenCntRegex					= new RegExp( "\<[^\>]*>|nbsp;","g" );
var m_httpsRegex					= new RegExp( "http:\/\/[^\/]*", "g" );

function test()
	{
		document.writeln( "TESTING" );	
	}
	
	
function pbInIt()
{  

	window.onerror					= pbErrorHandler ;
	
	m_pbExpandImg					= "expand.gif";
	m_pbCollapseImg					= "collapse.gif";
	m_secondaryImg					= "secondary.gif";
	m_spacerImg						= "spacer.gif";

	m_pbCookieInstance				= new pbCookie ();
	m_pbWelcomeSection				= new pbWelcomeSection;
	m_pbProfileSection				= new pbProfileSection;
	m_pbRBISection					= new pbLinkListSection;
	m_pbRecommendsSection			= new pbLinkListSection;
	
	m_pbPersonalizationBar			= new pbPersonalizationBar(m_pbWelcomeSection,m_pbProfileSection,m_pbRBISection,m_pbRecommendsSection);
	//m_pbPersonalizationBar			= new pbPersonalizationBar(m_pbWelcomeSection,m_pbProfileSection,m_pbRBISection);
	//m_pbPersonalizationBar			= new pbPersonalizationBar(m_pbWelcomeSection);
}

function pbRender()
{
	if ( m_protectedInit != null )
	{
		m_protectedInit();
	}
	m_pbPersonalizationBar.Render();
	//pbExpandCookie();
	
}

function resizeParentFrame ()
{
	if ( ! isW3C )
	{
		return;
	}
	
	if ( parent == null )
	{
		return;
	}

	var iframeObj					= null;
	
	try
	{
		iframeObj						= parent.document.getElementById ( "pbarwin" );
		if ( iframeObj == null )
		{
			var	iframes					= parent.document.getElementsByTagName("iframe" );
			if ( iframes.length > 0 )
			{
				iframeObj				= iframes[0];
			}
		}
	}
	catch(e)
	{
	}
		
	if ( iframeObj != null )
	{
		var		mastTable			= document.getElementById ( "pbarMasterTable" );
		var		height				= 0; 
		var		width				= 0;
		if ( mastTable != null )
		{
			height					= mastTable.offsetHeight + 10;
			width					= mastTable.offsetWidth + 10;
		}
		
		if ( height > 20 )
		{
			iframeObj.height		= height;
		}
		if ( width > 20 )
		{
			iframeObj.width			= width;
		}
		
	}
	
}
function pbPersonalizationBar(welcome,profile,rbi,rec)
{	
	this.WelcomeSection			= welcome;
	this.ProfileSection			= profile;
	this.RBISection				= rbi;
	this.RecommendsSection		= rec;
	this.Render					= pbPersonalizationBarRender;
}

function pbPersonalizationBarRender()
{
	//document.writeln( "<table  name=\"pbarMasterTable\" id=\"pbarMasterTable\"cellpadding=\"8\" cellspacing=\"0\" border=\"0\" width=\"" + m_pbWidth + "\" style=\"background-color:#EFEFEF;border:1px solid " + m_pbBorderColor + ";\"><tr><td>" );
	
	//document.writeln( "<table  name=\"pbarMasterTable\" id=\"pbarMasterTable\"cellpadding=\"8\" cellspacing=\"0\" border=\"0\" width=\"" + m_pbWidth + "\" style=\"background-color:#EFEFEF;border-right:1px solid #ccc;border-bottom:1px solid #ccc;border-left:1px solid #ccc;\"><tr><td>" );
	
	document.writeln( "<table  name=\"pbarMasterTable\" id=\"pbarMasterTable\" cellpadding=\"7\" cellspacing=\"0\" border=\"0\" width=\"160\" style=\"background-color:#f1f1f1;\"><tr><td>" );
	
	if( m_pbarOrder == null )
	{
		this.WelcomeSection.Render();
		this.ProfileSection.Render();
		this.RBISection.Render();
		this.RecommendsSection.Render();
	}
	else
	{
		this.WelcomeSection.Render();
		var pOrder	= m_pbarOrder.split(",");
		for ( i = 0 ; i < pOrder.length; i++  )
		{
			switch( pOrder[i] )
			{
				case 'profile':
					this.ProfileSection.Render();
					break
				case 'rbi':
					this.RBISection.Render();
					break
				case 'recommends':
					this.RecommendsSection.Render();
					break
				default:
					break
			}
		}
	}
	document.writeln( "</td></tr></table>" );
	//resizeParentFrame();
	setTimeout ( "resizeParentFrame()" , 1 );
}

function pbUser ( fname, lname, email )
{
	this.FirstName		= fname;
	this.LastName		= lname;
	this.Email			= email;
	
}
// -----------------------------
// Personalization Bar Sections
// -----------------------------
function pbWelcomeSection( title, intro )
{
	this.Title			= title;
	this.Intro			= intro;
	
	this.Render			= pbWelcomeSectionRender;
}

function pbWelcomeSectionRender() 
{
	if( this.Title || this.Intro )
	{
		if ( this.Title != null )
		{
			this.Title		= this.Title.replace ( m_fnameRegex , m_pbuser.FirstName ).replace ( m_lnameRegex , m_pbuser.LastName ); 
		}
		if ( this.Intro != null )
		{
			this.Intro		= this.Intro.replace ( m_fnameRegex , m_pbuser.FirstName ).replace ( m_lnameRegex , m_pbuser.LastName ); 
		}
		if( this.Title )
		{
			document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td class=\"titlestylelight\">" + this.Title + "</td></tr></table>" );
		}
		if(this.Intro)
		{
			document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td><img scr=\"" + m_spacerImg + "\" border=\"0\" width=\"1\" height=\"5\" /></td></tr></table>" );
			document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td class=\"pbpara\" style=\"color:#666666\">" + this.Intro + "</td></tr></table>" );
		}
		
		document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td><img scr=\"" + m_spacerImg + "\" border=\"0\" width=\"1\" height=\"3\" /></td></tr></table>" );
		
		//document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr><td align=\"left\" valign=\"top\">" );
		//document.writeln( '<div class="steps"><div class="step"><div class="step_title">My Cart</div>' );
		//document.writeln( '<div class="step_body">'+ order_id + '</div>' );
		
		//document.write( '</div></div>' );
		//document.writeln("</td></tr></table><br>" );
		
		//document.writeln( "<table><tr><td valign=\"top\"><a href=\"../app.php?state=myaccount\"><img src=\"images/dell/secondary.gif\" border=\"0\"/></a></td><td><img src=\"" + m_spacerImg + "\" border=\"0\" width=\"3\" height=\"1\" alt=\"\" /></td><td class=\"pbpara\" width=\"100%\"><a href=\"../app.php?state=myaccount\">Main Page</a></td></tr></table>" );
		
		document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td><img scr=\"" + m_spacerImg + "\" border=\"0\" width=\"1\" height=\"10\" /></td></tr></table>" );
		
		
		//document.writeln( "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"1\" style=\"background: #fff;padding-top:4px;padding-bottom:4px;padding-left:10px;padding-right:10px;border-top:1px solid #ccc;border-right:1px solid #ccc;border-left:1px solid #ccc;\"><tr><td align=\"left\" valign=\"top\"><a href=\"../app.php?state=myaccount\"><img src=\"images/dell/secondary.gif\" border=\"0\"/></a></td><td><img src=\"" + m_spacerImg + "\" border=\"0\" width=\"12\" height=\"1\" alt=\"\" /></td><td width=\"100%\" align=\"left\" valign=\"middle\"><a href=\"../app.php?state=myaccount\">Main Page</a></td></tr></table>" );
		
		document.writeln( "<table width=\"100%\" cellpadding=\"4\" cellspacing=\"0\" border=\"0\" style=\"background: #fff;border-top:1px solid #ccc;border-right:1px solid #ccc;border-left:1px solid #ccc;\"><tr><td align=\"left\" valign=\"top\" style=\"padding-left:12px;\"><a href=\"../app.php?state=myaccount\"><img src=\"images/dell/secondary.gif\" border=\"0\"/></a></td><td style=\"padding-left:12px;\" align=\"left\" valign=\"middle\" width=\"100%\"><a href=\"app.php?state=myaccount\">Main Page</a></td></tr></table>" );
		
	}
}

function pbProfileSection( menus )
{
	this.MenuItems			= menus;
	this.Render				= pbProfileSectionRender;
	this.AddMenu			= pbAddMenu;
}

function pbAddMenu ( menu )
{
	if ( this.MenuItems == null )
	{
		this.MenuItems			= new Array();
	}
	this.MenuItems[this.MenuItems.length] = menu;
}
function pbProfileSectionRender()
{
	if(this.MenuItems)
	{
		//document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" style=\"padding:0px;background-color:" + m_pbCollapseColor + ";border-bottom:1px solid " + m_pbBorderColor + ";border-left:1px solid " + m_pbBorderColor + ";border-right:1px solid " + m_pbBorderColor + ";\">" );
		
		document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" style=\"padding:0px;background-color:#fff;border-bottom:1px solid "+m_pbBorderColor+";border-left:1px solid "+m_pbBorderColor+";border-right:1px solid "+m_pbBorderColor+";\">" );
		
		for(menuItemsIndex=0; menuItemsIndex<this.MenuItems.length; menuItemsIndex++)
		{
			this.MenuItems[menuItemsIndex].Render();
		}	
		document.writeln( "</table>" );
		
		document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td><img scr=\"" + m_spacerImg + "\" border=\"0\" width=\"1\" height=\"10\" /></td></tr></table>" );
		
		//document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td><img scr=\"../images/spacer/clear.gif\" border=\"0\" width=\"1\" height=\"15\" /></td></tr></table>" );
	}
}

function pbContentSection(content,overflow,divlines)
{
	this.ContentItems   = content;
	this.OverFlow		= overflow;
	this.DivLines		= divlines;
	this.AddContentItem = pbAddContentItem;
	this.Render			= pbContentSectionRender;
}

function pbAddContentItem( item )
{
	if( this.ContentItems == null )
	{
		this.ContentItems = new Array();
	}
	this.ContentItems[this.ContentItems.length] = item;
}

function pbContentSectionRender()
{
	document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td><img src=\"" + m_spacerImg + "\" width=\"1\" height=\"3\" border=\"0\" alt=\"\"/></td></tr></table>" );
	document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr><td style=\"padding-left:8px;padding-right:8px;padding-top:3px;padding-bottom:3px;\">" );
	if(this.ContentItems.length>m_pbDivSize && this.ContentItems.length>this.OverFlow)
	{
		document.writeln( "<div style=\"overflow:auto;width:" + m_pbDivWidth + ";height:" + m_pbDivHeight + ";background-color:" + m_pbCollapseColor + ";border:1px solid " + m_pbBorderColor + ";\">" );
	}
	else
	{
		document.writeln( "<div style=\"background-color:" + m_pbCollapseColor + ";border:1px solid " + m_pbBorderColor + ";\">" );
	}
	
	document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">" );
	if(this.ContentItems)
	{
		for(x=0;x<this.ContentItems.length;x++)
		{
			document.writeln( "<tr><td>" );
			this.ContentItems[x].Render();
			document.writeln( "</td></tr>" );
			if(this.DivLines == true)
			{
				if(x+1!=this.ContentItems.length)
				{
					document.writeln( "<tr><td style=\"background-color:" + m_pbBorderColor + "\"><img src=\"" + m_spacerImg + "\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"/></td></tr>" );
				}
			}
		}
	}
	document.writeln( "</table></div></td></tr></table>" );
	document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td><img src=\"" + m_spacerImg + "\" width=\"1\" height=\"3\" border=\"0\" alt=\"\"/></td></tr></table>" );
}

function pbLinkListSection(title,intro,links)
{
	this.Title				= title;
	this.Intro				= intro;
	this.LinkItems			= links;
	this.Render				= pbLinkListSectionRender;
	this.AddLink			= pbAddLinkListSectionLink;
	this.InsertAtIndex		= pbInsertLinkListSectionLink;
}
function pbAddLinkListSectionLink ( link )
{
	if ( this.LinkItems == null )
	{
		this.LinkItems		= new Array ()
	}
	this.LinkItems[this.LinkItems.length] = link;
}
function pbInsertLinkListSectionLink ( link , index )
{
	if ( this.LinkItems	 == null || index >= this.LinkItems.length )
	{
		this.AddLink ( link );
		return;
	}
	var	flg					= false;
	var	repLink				= this.LinkItems[index];
	var oldLink				= null;
	this.LinkItems[index]	= link;
	for ( pbIdx = index +1 ; pbIdx < this.LinkItems.length ; pbIdx ++ )
	{
		oldLink				= this.LinkItems[pbIdx];
		this.LinkItems[pbIdx]=repLink;
		repLink				= oldLink;
	}
	this.AddLink ( repLink );
	
}

function pbLinkListSectionRender()
{
	if(this.LinkItems)
	{
		document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">" );
		if(this.Title)
		{
			document.writeln( "<tr><td class=\"titlestylelight\">" + this.Title + "</td></tr>" );
			document.writeln( "<tr><td><img scr=\"" + m_spacerImg + "\" border=\"0\" width=\"1\" height=\"5\" /></td></tr>" );
		}
		document.writeln( "<tr><td>" );
		document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" style=\"background-color:" + m_pbCollapseColor + ";border:1px solid " + m_pbBorderColor + ";\"><tr><td>" );
		document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td><img scr=\"" + m_spacerImg + "\" border=\"0\" width=\"1\" height=\"5\" /></td></tr></table>" );
		if(this.Intro)
		{
			var	intro		= new pbMenuText( this.Intro );
			intro.Render();
		}
		for(x=0;x<this.LinkItems.length;x++)
		{
			this.LinkItems[x].Render();
		}
		document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td><img scr=\"" + m_spacerImg + "\" border=\"0\" width=\"1\" height=\"5\" /></td></tr></table>" );
		document.writeln( "</td></tr></table></td></tr></table>" );
		document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td><img src=\"" + m_spacerImg + "\" width=\"1\" height=\"5\" border=\"0\" alt=\"\"/></td></tr></table>" );
	}
}

// -----------------------------------
// Profile Menu Items Definition
// -----------------------------------
function pbMenuLink( title, href, desc, type, target, length, image )
{
	this.Target		= "_parent";
	this.Title		= title;
	this.Desc		= desc;
	this.Href		= href;
	this.Image		= image;
	this.Type		= type;
	if ( target )
	{
		this.Target	= target;
	}
	this.Length		= length;
	this.Render		= pbMenuLinkRender;
}

function pbMenuLinkRender()
{
	if ( this.Type == "storelink" )
	{
		document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td style=\"padding-left:10px;padding-right:10px;padding-top:3px;padding-bottom:3px;\">" );
		document.writeln( "<a href=\"" + this.Href + "\" TARGET=\"" + this.Target + "\"><img src=\"" + this.Image + "\" border=\"0\" alt=\"" + this.Title + "\" /></a>" );
		document.writeln( "</td></tr></table>" );
	}
	else
	{
		var titleLength = 0;
		if ( this.Title )
		{
			this.Title	=  this.Title.replace( m_aRegex, "" );
			titleLength		= this.Title.replace( m_lenCntRegex, "" ).length;
		}
		if( this.Length <= titleLength )
		{
			this.Title = this.Title.substring(0,this.Length);
			this.Title = this.Title.substring(0,this.Title.lastIndexOf(" ")) + "...";
		}
		if(!this.Type)
		{
			this.Type = "secondary";
		}
		else if ( this.Type == "secondarySelected" )
		{
			this.Type	= "secondary";
			this.Title = "<div class=\"hiernavsel\">" + this.Title + "</div>";
		}
		if ( this.Href && this.Href.length > 0 && this.Href.indexOf ( "javascript")  == -1 )
		{
			if ( this.Href.indexOf ( "?") == 0  )
			{
				this.Href	= this.Href + "?~pbar=true";
			}
			else
			{
				this.Href	= this.Href + "&~pbar=true";
			}
			//todo ~pbar=true
		}
		
		document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">" );
		if(this.Desc)
		{
			document.writeln( "<tr><td valign=\"top\" style=\"padding-left:10px;padding-right:0px;padding-top:" + m_spacerHeight + "px;padding-bottom:0px;\"><a TARGET=\"" + this.Target + "\" href=\""  + this.Href + "\"><img src=\"images/dell/secondary.gif\" border=\"0\"/></a></td><td><img src=\"" + m_spacerImg + "\" border=\"0\" width=\"5\" height=\"1\" alt=\"\" /></td><td class=\"pbpara\" width=\"100%\" style=\"padding-left:0px;padding-right:10px;padding-top:" + m_spacerHeight + "px;padding-bottom:0px;\">" );
			
			if(this.Title != 'Your Sales Representative'){ document.writeln( "<a TARGET=\"" + this.Target + "\" href=\"" + this.Href + "\">" ); }
			if(this.Title == 'Your Sales Representative'){ document.writeln( "<strong>" ); }
			document.writeln( this.Title );
			if(this.Title == 'Your Sales Representative'){ document.writeln( "</strong>" ); }
			if(this.Title != 'Your Sales Representative'){ document.writeln( "</a>" ); }
			document.writeln( "</td></tr>" );
			
			
			document.writeln( "<tr><td colspan=\"2\"><img src=\"" + m_spacerImg + "\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"/></td><td class=\"pbpara\" valign=\"top\" style=\"padding-left:0px;padding-right:10px;padding-top:0px;padding-bottom:" + m_spacerHeight + "px;\">" + this.Desc + "</td></tr>" );
		}
		else
		{
			document.writeln( "<tr><td valign=\"top\" style=\"padding-left:10px;padding-right:0px;padding-top:" + m_spacerHeight + "px;padding-bottom:" + m_spacerHeight + "px;\"><a TARGET=\"" + this.Target + "\" href=\""  + this.Href + "\"><img src=\"images/dell/secondary.gif\" border=\"0\"/></a></td><td><img src=\"" + m_spacerImg + "\" border=\"0\" width=\"5\" height=\"1\" alt=\"\" /></td><td class=\"pbpara\" width=\"100%\" style=\"padding-left:0px;padding-right:10px;padding-top:" + m_spacerHeight + "px;padding-bottom:" + m_spacerHeight + "px;\"><a TARGET=\"" + this.Target + "\" href=\"" + this.Href + "\">" + this.Title + "</a></td></tr>" );
		}
		document.writeln( "</table>" );
	}
}

function pbMenuText( text, fontclass, style )
{
	this.Text	= text;
	this.Class	= fontclass;
	this.Style	= style;
	this.Render = pbMenuTextRender;
}

function pbMenuTextRender()
{
	if(!this.Class)
	{
		this.Class = "pbpara";
	}
	document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td class=\"" + this.Class + "\" style=\"padding-left:10px;padding-right:10px;padding-top:" + m_spacerHeight + "px;padding-bottom:" + m_spacerHeight + "px;" + this.Style + "\">" );
	document.writeln( this.Text );
	document.writeln( "</td></tr></table>" );
}

function pbMyAccountLogin ( emailCaption , emailRequired, passwordCaption , passwordRequired, intro , submitCaption , postUrl , requiredField, error )
{
	this.EmailCaption		= emailCaption ;
	this.EmailRequired		= emailRequired;
	this.PasswordCaption	= passwordCaption;
	this.PasswordRequired	= passwordRequired;
	this.Intro				= intro;
	this.SubmitCaption		= submitCaption;
	this.PostUrl			= postUrl;
	this.Render				= pbMyAccountLoginRender ;
	this.RequiredField		= requiredField;
	this.Error				= error;
}

function pbMyAccountLoginRender ()
{
	signin = new pbMenuLink( this.SubmitCaption, "javascript:pbMyAccountLoginValidation();", "", "primary" ,"_self" );
	document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td><img src=\"" + m_spacerImg + "\" width=\"1\" height=\"3\" border=\"0\" alt=\"\"/></td></tr></table>" );
	document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">" );
	if(this.Intro)
	{
		var	intro		= new pbMenuText( this.Intro );
		document.writeln( "<tr><td>" )
		intro.Render();
		document.writeln( "</td></tr>" );
	}
	if ( this.Error != null && this.Error.length > 0 )
	{
		var	error		= new pbMenuText( this.Error,"","color:red;" );
		document.writeln( "<tr><td>" )
		error.Render();
		document.writeln( "</td></tr>" );
	}
	//document.writeln ( "<tr><td class=\"pbpara\" style=\"padding-left:10px;padding-right:10px;padding-top:3px;padding-bottom:3px;\"></form><form name='myaccountlogin' method='post' action='" + this.PostUrl + "'><image src=\"" + m_imgPrefix + "/images/global/brand/ui/icon_required.gif\" border=\"0\" alt=\"\" />" + this.EmailCaption + "<br /><input type='text' name='email' value='" + m_pbuser.Email + "'/><div id=\"emailDiv\" style=\"color:red;display:none\" class=\"pbpara\"><img src=\"" + m_imgPrefix + "/images/global/brand/ui/icon_notice_sm.gif\" border=\"0\" alt=\"\">" + this.EmailRequired + "</div></td></tr>");
	
	//document.writeln ( "<tr><td class=\"pbpara\" style=\"padding-left:10px;padding-right:10px;padding-top:3px;padding-bottom:3px;\"></form><form name='myaccountlogin' method='post' action='" + this.PostUrl + "'><image src=\"" + m_imgPrefix + "/images/global/brand/ui/icon_required.gif\" border=\"0\" alt=\"\" />" + this.EmailCaption + "<br /><input type='text' name='email' value='" + m_pbuser.Email + "'/><div id=\"emailDiv\" style=\"color:red;display:none\" class=\"pbpara\"><img src=\"" + m_imgPrefix + "/images/global/brand/ui/icon_notice_sm.gif\" border=\"0\" alt=\"\">" + this.EmailRequired + "</div></td></tr>");
	
	document.writeln ( "<tr><td class=\"pbpara\" style=\"padding-left:10px;padding-right:10px;padding-top:3px;padding-bottom:3px;\"><image src=\"" + m_imgPrefix + "/images/global/brand/ui/icon_required.gif\" border=\"0\" alt=\"\" />" + this.PasswordCaption + "<br /><input type='password' name='password' onkeypress='return pbEnterSubmit(event,myaccountlogin)' /><div id=\"passwordDiv\" style=\"color:red;display:none\" class=\"pbpara\"><img src=\"" + m_imgPrefix + "/images/global/brand/ui/icon_notice_sm.gif\" border=\"0\" alt=\"\">" + this.PasswordRequired + "</div><input type='hidden' name='myAccountLogin' value='true'/></td></tr>");
	document.writeln ( "</form></table>");
	signin.Render();
	if ( this.RequiredField != null && this.RequiredField.length > 0 )
	{
		document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td style=\"padding-left:10px;padding-right:10px;padding-top:3px;padding-bottom:3px;\" class=\"para_small\"><image src=\"" + m_imgPrefix + "/images/global/brand/ui/icon_required.gif\" border=\"0\" alt=\"\" />" + this.RequiredField + "</td></tr></table>" );
	}
	document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td><img src=\"" + m_spacerImg + "\" width=\"1\" height=\"3\" border=\"0\" alt=\"\"/></td></tr></table>" );
}

function pbOrderStatusItem( name, status, details )
{
	this.OrderName = name;
	this.OrderStatus = status;
	this.OrderDetailsLink = details;
	this.Render	= pbOrderStatusItemRender;
}

function pbOrderStatusItemRender()
{
	document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr><td class=\"title_emph\" style=\"padding-left:10px;padding-right:10px;padding-top:3px;padding-bottom:0px;\">" + this.OrderName + "</td></tr>" );
	document.writeln( "<tr><td class=\"para_small\" style=\"padding-left:10px;padding-right:10px;padding-top:0px;padding-bottom:0px;\">Status: " + this.OrderStatus + "</td></tr>" );
	document.writeln( "<tr><td class=\"para_small\" style=\"padding-left:10px;padding-right:10px;padding-top:0px;padding-bottom:3px;\"><a href=\"javascript:winopen('" + this.OrderDetailsLink + "','popup2','WIDTH=595,HEIGHT=400,RESIZABLE=YES,SCROLLBARS=YES,TOOLBAR=YES,LEFT=0,TOP=20');\">Details</a></td></tr>" );
	document.writeln( "</table>" );
}

function pbEnterSubmit(event,ourform)
{
	
	if (event && event.which == 13 || event.keyCode == 13)
		pbMyAccountLoginValidation();
	else
		return true;
}
   
function pbswitchProfile ( profile )
{
	for ( formIdx = 0 ; formIdx < document.parent.forms.length;formIdx ++   )
	{
		if ( "pbSwitchUserForm" == document.parent.forms[formIdx].name )
		{
			document.parent.forms[formIdx].pprofile = profile;
			document.parent.forms[formIdx].submit();
		}
	}
	
}
 
function pbClearUser()
{
	for ( formIdx = 0 ; formIdx < document.forms.length;formIdx ++   )
	{
		if ( "clearForm" == document.forms[formIdx].name )
		{
			document.forms[formIdx].submit();
		}
	}
}

function pbmyaccountlogout()
{
	for ( formIdx = 0 ; formIdx < document.forms.length;formIdx ++   )
	{
		if ( "myaccountlogout" == document.forms[formIdx].name )
		{
			document.forms[formIdx].submit();
		}
		
	}
}

function pbMyAccountLoginValidation()
{
	// Set Iframe to default size before login as autoresize won't work after that
	var iframeObj					= null;
	try
	{
		iframeObj						= parent.document.getElementById ( "pbarwin" );
		if ( iframeObj == null )
		{
			var	iframes					= parent.document.getElementsByTagName("iframe" );
			if ( iframes.length > 0 )
			{
				iframeObj				= iframes[0];
			}
		}
		iframeObj.height				= m_pbIframeHeight;
		iframeObj.width					= m_pbIframeWidth;
	}
	catch(e)
	{
	}
	var myAccntLogin ;
	for ( formIdx = 0 ; formIdx < document.forms.length;formIdx ++   )
	{
		if ( "myaccountlogin" == document.forms[formIdx].name )
		{
			myAccntLogin		= document.forms[formIdx];
			break;
		}
		
	}
	
	var email = myAccntLogin.email;
	var emailDiv = getRawObject("emailDiv");
	var password = myAccntLogin.password;
	var passwordDiv = getRawObject("passwordDiv");
	
	if( email.value.length != 0 && password.value.length != 0 )
	{
		var	actionUrl		= document.location.href;
		if ( typeof ( m_maSecure ) != "undefined" )
		{
			myAccntLogin.action = m_maSecure;
		}
		myAccntLogin.submit();
	}
	else
	{
		emailDiv.style.display = "none";
		passwordDiv.style.display = "none";
	}
	if(email.value.length == 0)
	{
		emailDiv.style.display = "block";
	}
	if(password.value.length == 0)
	{
		passwordDiv.style.display = "block";
	}
}

function pbMyAccountLogout( title )
{
	this.Title		= title;
	this.Render		= pbMyAccountLogoutRender;
}

function pbMyAccountLogoutRender()
{
	var signoff = new pbMenuLink( this.Title, "javascript:pbmyaccountlogout();", "", null , "_self");
	
	signoff.Render();
	document.writeln ( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td><form name='myaccountlogout' method='post' action=''>");
	document.writeln ( "<input type=\"hidden\" name=\"myAccountLogout\" value=\"true\"/>" );
	document.writeln( "</form></td></tr></table>" );
}

function pbSupportItem( image, title, desc, url)
{
	this.Image			= image;
	this.Title			= title;
	this.Desc			= desc;
	this.Url			= url;
	this.Render			= pbSupportItemRender;
}

function pbSupportItemRender()
{
	
	document.writeln( "<table cellpadding=\"3\" cellspacing=\"0\" border=\"0\"><tr><td valign=\"top\">&nbsp;</td><td valign=\"top\" width=\"100%\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">" );
	document.writeln( "<tr><td class=\"title_emph\">" + this.Title + "</td></tr>" );
	if( this.Desc )
	{
		document.writeln( "<tr><td class=\"pbpara\">" + this.Desc + "</td></tr>" );
	}
	document.writeln( "<tr><td class=\"para_small\"><a href=\"" + this.Url + "\" TARGET=\"_parent\">Product Support</a></td></tr>" );
	document.writeln( "</table></td></tr></table>" );
}

function pbCartItem( image,title,price,discount,discountHref,retialPrice,quantity)
{
	this.Image			= image;
	this.Title			= title;
	this.Price			= price;
	this.Discount		= discount;
	this.DiscountHref	= discountHref;
	this.RetailPrice	= retialPrice;
	this.Quantity		= quantity;
	this.Render			= pbCartItemRender;
	m_CartItemCount +=	1;
}

function pbCartItemRender()
{
	var imgWidth	= m_pbProdImgWidth;
	if(this.Image  && this.Image.length > 0 )
	{
		if ( this.Image.indexOf ("/" ) == 0  )
		{
			this.Image	= m_imgPrefix + this.Image;
		}
	}
	else
	{
		this.Image	= m_imgPrefix + "/images/global/general/spacer.gif";
	}
	
	document.writeln( "<table cellpadding=\"3\" cellspacing=\"0\" border=\"0\"><tr><td valign=\"top\"><img src=\"" + this.Image + "\" width=\"" + imgWidth + "\" border=\"\" alt=\"\" /></td><td valign=\"top\" width=\"100%\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">" );
	document.writeln( "<tr><td class=\"pbpara\">" + this.Title + "</td></tr>" );
	if(this.Discount && this.Discount.length > 0  )
	{
		document.writeln( "<tr><td><span class=\"para_marketingprice_strikethrough\">" + this.RetailPrice + "</span> <span class=\"para_marketingprice_to\">" + this.Price + "</span></td></tr>" );
		if(this.DiscountHref)
		{
			document.writeln( "<tr><td class=\"para_small\"><a href=\"javascript:winopen('" + this.DiscountHref + "','popup2','WIDTH=595,HEIGHT=400,RESIZABLE=YES,SCROLLBARS=YES,TOOLBAR=YES,LEFT=0,TOP=20');\">" + this.Discount + "</a></td></tr>" );
		}
		else
		{
			document.writeln( "<tr><td class=\"para_small\">" + this.Discount + "</td></tr>" );
		}
	}
	else
	{
		document.writeln( "<tr><td class=\"para_marketingprice_simple\">" + this.Price + "</td></tr>" );
	}
	document.writeln( "<tr><td class=\"para_small\">Quantity: " + this.Quantity + "</td></tr>" );
	document.writeln( "</table></td></tr></table>" );
}


// -----------------------------------
// Profile Menu Link Group Definition
// -----------------------------------
function pbProfileMenuLinkGroup( id, title, note, icon, intro, href, items )
{
	this.ID				= id;
	this.Title			= title;
	this.Note			= note;
	this.Icon			= icon+ ".gif";
	this.Intro			= intro;
	this.Href			= href;
	this.GroupItems		= items;
	this.Render			= pbProfileMenuLinkGroupRender;
	this.AddGroup		= pbAddMenuLinkGroup;
}
function pbAddMenuLinkGroup( group )
{
	if ( this.GroupItems == null )
	{
		this.GroupItems		= new Array();
	}
	this.GroupItems[this.GroupItems.length] = group;
}

function pbProfileMenuLinkGroupRender()
{	
	var formatedName	= this.ID;
	var	href			= this.Href ;
	var	target			= "_parent";
	var	norgie			= m_spacerImg;
	if ( href == null || href.length == 0  )
	{
		href			= "javascript:pbSectionExpand('" + formatedName + "')";
		norgie			= m_pbExpandImg;
		target			= "_self";
	}
	if ( this.Title != null )
	{
		this.Title		= this.Title.replace ( m_fnameRegex , m_pbuser.FirstName ).replace ( m_lnameRegex , m_pbuser.LastName ); 
	}
	if ( this.Intro != null )
	{
		this.Intro		= this.Intro.replace ( m_fnameRegex , m_pbuser.FirstName ).replace ( m_lnameRegex , m_pbuser.LastName ); 
	}
	
	document.writeln( "<tr><td id=\"pb" + formatedName + "ExpandCell\" valign=\"top\" style=\"padding-top:7px;padding-left:10px;padding-right:10px;background-color:" + m_pbCollapseColor + ";border-top:1px solid " + m_pbBorderColor + ";\"><a target=\"" + target + "\" href=\"" + href + "\"><img id=\"pb" + formatedName + "ExpandImg\" src=\"" + m_imgPrefix + norgie + "\" border=\"0\" /></a></td><td id=\"pb" + formatedName + "IconCell\" valign=\"top\" style=\"padding:0px;padding-top:3px;background-color:" + m_pbCollapseColor + ";border-top:1px solid " + m_pbBorderColor + ";\" align=\"center\"><a target=\"" + target + "\" href=\"" + href + "\"><img src=\"" + m_imgPrefix + this.Icon + "\" border=\"0\" /></a></td><td id=\"pb" + formatedName + "TitleCell\" style=\"padding-left:3px;padding-right:5px;padding-top:5px;padding-bottom:5px;background-color:" + m_pbCollapseColor + ";border-top:1px solid " + m_pbBorderColor + ";\" nowrap=\"true\" width=\"100%\" class=\"para\"><a target=\"" + target + "\" href=\"" + href + "\">" + this.Title + "</a>" );
	
	//document.writeln( "<tr><td id=\"pb" + formatedName + "ExpandCell\" style=\"padding-left:7px;padding-right:7px;background-color:" + m_pbCollapseColor + ";border-top:1px solid "+m_pbBorderColor+";\"><a target=\"" + target + "\" href=\"" + href + "\"><img id=\"pb" + formatedName + "ExpandImg\" src=\"" + m_imgPrefix + norgie + "\" border=\"0\" /></a></td><td id=\"pb" + formatedName + "IconCell\" style=\"padding:0px;background-color:" + m_pbCollapseColor + ";border-top:1px solid "+m_pbBorderColor+";\" align=\"center\"></td><td id=\"pb" + formatedName + "TitleCell\" style=\"padding-left:3px;padding-right:5px;padding-top:5px;padding-bottom:5px;background-color:" + m_pbCollapseColor + ";border-top:1px solid "+m_pbBorderColor+";\" nowrap=\"true\" width=\"100%\" class=\"para\"><a target=\"" + target + "\" href=\"" + href + "\">" + this.Title + "</a>" );
	
	//document.writeln( "<tr><td valign=\"top\" id=\"pb" + formatedName + "ExpandCell\" style=\"padding-top:7px;padding-left:7px;padding-right:7px;background-color:" + m_pbCollapseColor + ";border-top:1px solid "+m_pbBorderColor+";\"><a target=\"" + target + "\" href=\"" + href + "\"><img id=\"pb" + formatedName + "ExpandImg\" src=\"" + m_imgPrefix + norgie + "\" border=\"0\" /></a></td><td id=\"pb" + formatedName + "IconCell\" style=\"padding:0px;background-color:" + m_pbCollapseColor + ";border-top:1px solid "+m_pbBorderColor+";\" align=\"center\"></td><td id=\"pb" + formatedName + "TitleCell\" style=\"padding-left:3px;padding-right:5px;padding-top:5px;padding-bottom:5px;background-color:" + m_pbCollapseColor + ";border-top:1px solid "+m_pbBorderColor+";\" nowrap=\"true\" width=\"100%\" class=\"para\"><a target=\"" + target + "\" href=\"" + href + "\">" + this.Title + "</a>" );
	
	if(this.Note)
		{
			document.writeln( "</td></tr><tr><td align=\"left\" valign=\"middle\" colspan=\"3\" style=\"padding-left:10px; padding-right:3px; padding-bottom:4px; padding-top:2px; \" ><span class=\"para_small\">" + this.Note + "</span>" );
		}
	
	if(this.Intro && this.Intro != 'none')
		{
			document.writeln( "</td></tr><tr><td align=\"left\" valign=\"middle\" colspan=\"3\" style=\"padding-left:10px; padding-right:3px; padding-bottom:6px; padding-top:2px; \" ><span class=\"para_small\">" + this.Intro + "</span>" );
		}
	
	document.writeln( "</td></tr>" );
	
	if(this.Intro)
	{
		var intro = '';
		if(this.Intro != 'none'){intro == this.Intro;}
		
		document.writeln( "<tr><td id=\"pb" + formatedName + "IntroCell\" style=\"background-color:#edefd2;border-top:1px solid "+m_pbBorderColor+";\" colspan=\"3\" class=\"pbpara\"><div style=\"display:none;padding-left:10px;padding-right:10px;padding-top:5px;padding-bottom:3px;\" id=\"pb" + formatedName + "Intro\">" + intro + "</div></td></tr>" );
	}
	
	document.writeln( "<tr><td id=\"pb" + formatedName + "DivCell\"  style=\"background-color:#edefd2;\" colspan=\"3\"><div style=\"padding:0px;display:none;\" id=\"pb" + formatedName + "Div\">" );
	
	if(this.GroupItems)
	{
		for(o=0;o<this.GroupItems.length;o++)
		{
			this.GroupItems[o].Render();
		}
	}
	
	if(this.Title == 'My Cart' && this.GroupItems)
		{
			document.writeln( "<div style=\"padding: 6px 4px 0px 4px;border-top: 1px solid #ccc\"><a href=\"app.php?state=cart\"><img class=\"img2\" src=\"images/appButtons/modify.gif\" border=\"0\" alt=\"modify\"/></a> &nbsp;<a href=\"app.php?state=checkout\"><img class=\"img2\" src=\"images/appButtons/checkout.gif\" border=\"0\" alt=\"checkout\"/></a></div>" );
		}
	
	document.writeln( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td><img src=\"" + m_spacerImg + "\" width=\"1\" height=\"5\" border=\"0\" alt=\"\"/></td></tr></table></div></td></tr>" );
}

function pbSectionExpand( section )
{		
	var pbDiv = getRawObject( "pb" + section + "Div" );
	var pbExpandCell = getRawObject( "pb" + section + "ExpandCell" );
	var pbIconCell = getRawObject( "pb" + section + "IconCell" );
	var pbTitleCell = getRawObject( "pb" + section + "TitleCell" );
	var pbDivCell = getRawObject( "pb" + section + "DivCell" );
	
	if ( typeof ( pbDiv ) == "undefined"  || !pbDiv )
	{
		return;
	}
	
	m_pbCookieInstance.LastClicked = section;
	m_pbCookieInstance.CartItemCount = m_CartItemCount;
	m_pbCookieInstance.Save ();

	for( x=0;x<m_pbPersonalizationBar.ProfileSection.MenuItems.length;x++ )
	{
		if(pbRemoveSpaces(m_pbPersonalizationBar.ProfileSection.MenuItems[x].ID) == section && m_pbPersonalizationBar.ProfileSection.MenuItems[x].Intro != "")
		{
			var pbIntro = getRawObject( "pb" + section + "Intro" );
			var pbIntroCell = getRawObject( "pb" + section + "IntroCell" );
		}
	}	
	
	if( pbDiv.style.display == "block" )
	{
		pbSectionsCollapse();
		m_pbCookieInstance.LastClicked = "closeAll";
		m_pbCookieInstance.Save ();
		
	}
	else
	{
		pbSectionsCollapse();
		for( x=0;x<m_pbPersonalizationBar.ProfileSection.MenuItems.length;x++ )
		{
			if(pbRemoveSpaces(m_pbPersonalizationBar.ProfileSection.MenuItems[x].ID) == section && m_pbPersonalizationBar.ProfileSection.MenuItems[x].Intro != "")
			{
				pbIntro.style.display = "block";
				pbIntroCell.style.backgroundColor = m_pbExpandColor;
				//pbIntroCell.style.padding = 0;
				
			}
		}	
		pbDiv.style.display = "block";
		//pbExpandCell.style.backgroundColor = m_pbExpandColor;
		//pbIconCell.style.backgroundColor = m_pbExpandColor;
		//pbTitleCell.style.backgroundColor = m_pbExpandColor;
		pbDivCell.style.backgroundColor = m_pbExpandColor;
		//pbDivCell.style.padding = 0;
		pbSectionExpandImg( section );
	}
	resizeParentFrame();
}

function pbSectionExpandImg( section )
{
	pbImg = getRawObject( "pb" + section + "ExpandImg" );
	pbImg.src = m_imgPrefix + m_pbCollapseImg;
}

function pbSectionsCollapse()
{
	for( x=0;x<m_pbPersonalizationBar.ProfileSection.MenuItems.length;x++ )
	{
		var formattedName = pbRemoveSpaces(m_pbPersonalizationBar.ProfileSection.MenuItems[x].ID);
		if( m_pbPersonalizationBar.ProfileSection.MenuItems[x].Intro != "" )
		{
			var pbIntro = getRawObject("pb"+formattedName+"Intro");
			pbIntro.style.display = "none";
			var pbIntroCell = getRawObject("pb"+formattedName+"IntroCell");
			pbIntroCell.style.backgroundColor = m_pbCollapseColor;
			pbIntroCell.style.padding = 0;
		}
		var pbDiv = getRawObject("pb"+formattedName+"Div");
		pbDiv.style.display = "none";
		var pbExpandCell = getRawObject("pb"+formattedName+"ExpandCell");
		pbExpandCell.style.backgroundColor = m_pbCollapseColor;
		var pbIconCell = getRawObject("pb"+formattedName+"IconCell");
		pbIconCell.style.backgroundColor = m_pbCollapseColor;
		var pbTitleCell = getRawObject("pb"+formattedName+"TitleCell");
		pbTitleCell.style.backgroundColor = m_pbCollapseColor;
		var pbDivCell = getRawObject("pb"+formattedName+"DivCell");
		pbDivCell.style.backgroundColor = m_pbCollapseColor;
		pbDivCell.style.padding = 0;
		var pbExpandImg = getRawObject("pb"+formattedName+"ExpandImg" );
		if ( pbExpandImg.src != m_imgPrefix + m_spacerImg )
		{
			pbExpandImg.src = m_imgPrefix + m_pbExpandImg;
		}
	}
}

// -----------------------------
// Helper Functions
// -----------------------------
function pbExpandCookie()
{
	if( m_pbProfileSection.MenuItems )
	{
		
		
		var lastClicked			= m_pbCookieInstance.LastClicked;
		m_pbCookieInstance.Save();
		if ( m_pbCookieInstance.CartItemCount < m_CartItemCount )
		{
			pbSectionExpand( 'cart' );
			return;
		}
		if ( lastClicked != null && lastClicked.length > 0 && lastClicked != "closeAll") // If cookied section value exists expand that section
		{
			pbSectionExpand(lastClicked);
			return;
		}
		if( !lastClicked && m_pbProfileSection.MenuItems.length > 0 ) // Default menu expand first section
		{
			pbSectionExpand(m_pbProfileSection.MenuItems[0].ID);
			return;
		}
	}
}

function pbRemoveSpaces(string)
{
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring; 
}

function pbCookie ()
{
	this.LastClicked			= "";
	this.CartItemCount			= 0;
	
	this.Init					= pbCookieInit ;
	this.Save					= pbCookieSave;
	this.Init();
}

function pbCookieSave ()
{
	var cookieVal				= this.LastClicked + "$" + this.CartItemCount;
	InternalSetCookie ( "pbar" , cookieVal );
	
}
function pbCookieInit ()
{
	var	cookieStr				= InternalGetCookie ( "pbar" ) ;
	if ( cookieStr == null )
	{
		return;
	}
	var parts					= cookieStr.split ( "$" );
	if ( parts.length == 2 )
	{
		this.LastClicked		= parts[0];
		this.CartItemCount	= parseInt( parts[1] ) ;
	}
	
	
}
function InternalGetCookie(NameOfCookie) 
{
	if (document.cookie.length > 0) 
	{
		begin = document.cookie.indexOf(NameOfCookie+"="); 
		if (begin != -1) 
		{
			begin += NameOfCookie.length + 1; 
			end = document.cookie.indexOf(";", begin);
			if (end == -1) 
			{
				end = document.cookie.length;
			}
			return unescape( document.cookie.substring(begin, end)); 
		} 
	}

	return ""; 
}


function InternalSetCookie (NameOfCookie , value) 
{	
	document.cookie	= NameOfCookie + "=" + escape( value );
}

function pbErrorHandler(desc,page,line,chr)  
{
	if ( typeof ( m_production ) != "undefined" )
	{
		if ( !m_production  )
		{ 
			alert( 'JavaScript error occurred! \nError description: \t'+desc +'\nPage address:      \t'+page +'\nLine number:       \t'+line );
		}
	}
}
 
 // -------------------------------------------------------------
// end of pbar.js
// -------------------------------------------------------------

