

	/*  promoMedia.js */
	// *************** 

	/* 
	   
	  Version    : 7.0

	  Changelog	 : 	1.0 : Initial release	
				1.1 : Flash Movie changed | writemovie() created | View all phones is skipped
				2.0 : Copy of promoMedia.js from production (deployed with PhoneAdvisor) launch
				3.0 : Updated embedPromoMedia() with new Omniture/Cookie tagging requirements
				3.1 : Fixed bugs - Javascript error displayed on UHP
				3.2 : Fixed bugs - Alerts being displayed, A, B users being displayed Phone Advisor
				4.0 : Updated embedPromoMedia () code with new Omniture tags for A, B users - "A/B Default UHP 2"
				5.0 : Changed randomization in embedPromoMedia () from 5% to 10%
				6.0 : Stopped showing Phone Advisor
				7.0 : Fix ?debug issue
				   

	   Purpose:    Embeds Phone Advisor (PA) and Features or Atlas Banner.

	   Features : Random embedding the Phone Advisor. 
	   Set a cookie to serve the phone advisor again to a user who saw it the first time
	   Swap the Atlas default banner with the PhoneAdvisor embed
	   Animate the phone advisor swf when a link is clicked - section -> "Flash Interaction functions "
	   Pass the right category to  Flash
	   If you were not shown the Phone Adviosr , direct links to individual pages

	   Dependencies : Tools.js, FlashObject.js  <Embedded Already>
	   All files together as organized, XML to be at the same level.
	   ".primeList" to be the classname of the links on the left, if changing it please change "listClassName" attribute on the Dependencies Section.

	   Debug Code: Uncommenting Line 221 gives you the a non-random embedding.

	*/



/* Flash File path */


var swfPath = "assets/phoneadvisor/phoneAdvisor.swf";
var cssLocation="assets/phoneadvisor/styles/PA.css";
var s_eVar4="";

var s_prop29;
var omniDebug = location.search.indexOf('omniture');

/* Browser Check */

var ie;
var ieversion;

if(navigator.appName == "Microsoft Internet Explorer")  ie = true;
if(ie){
	versionDetect=navigator.appVersion.split("MSIE")
	ieversion=parseFloat(versionDetect[1])
}



/* Check Dependencies */

var clickedLink = 0;


// Class Name of UL list on the left
var listClassName = ".primeList"

//Global check on JS dependencies and Flash Version
var sFail;

// Container for default Atlas Banner
var defaultContent=""; 
// If you closed the movie once using the close link
var Pclosed = false;

// Indicates that the movie has been written, dont re-write it, just pass the variable to Playmovie();
var wrotemovie=false;


var divTohideHeight=""; 

var FlashEmsg = "Phone Advisor  The FlashObject library could not be detected, the PromoMedia.js functions will fail";
var AdlibMsg = "Phone Advisor  The Adlib library could not be detected, the PromoMedia.js functions will fail";
if(typeof adlib =="undefined") {  window.status = AdlibMsg; sFail =true;  }
if(typeof com =="undefined")  { window.status =FlashEmsg ; sFail =true;  }






						var isStageSet = 'true';


						function setisStageSet(arg){
							isStageSet = arg;

						};





//Movie positioning
var leftOffset = 0;
				if(!sFail)
				{

				// Debug: Signin Box  wrap in Internet Explorer
				//if(ie == true) window.setTimeout("setDebugwidth('ie')", 15);
						/* Top Level functions: These are placed here as some user agents want definitions first  see -> embedProMedia() for the main function */
						/* Swaps Classes based on whats selected, send string: 'reset', to reset everything and not set any classes. */ 

						//Applies the highlight class to the links
						function applyClass(theLink){
						
						oList=$css('.PAlinkNode');
						if(oList.length>0){
							oList.each(
							function(classobj,classvalue){
								replaceClass(classobj,'PAlinkNode','');
								replaceClass(classobj.parentNode,'PAlinkBgNode','');
								replaceClass(classobj.parentNode,'PAlinkBgNodeFirst','');
								oList.next();
							}
							)
							}
							if(typeof theLink=="object")
							{
							theLink.className='PAlinkNode';
					
							//Determine if this is the first link, if yes then assign no borders on top.
							var isFirstLink;

							if(ie){	if(theLink.parentNode.previousSibling==null) isFirstLink=true }	else { if(theLink.parentNode==theLink.parentNode.parentNode.getElementsByTagName("LI")[0]) isFirstLink = true;}
						
							
							
							if(isFirstLink!=true){
							theLink.parentNode.className='PAlinkBgNode';
							}
								else{
								theLink.parentNode.className='PAlinkBgNodeFirst';
								}
							}
						};

						//CSS Embed File.
						function embedCSS(){
							var headID = document.getElementsByTagName("head")[0];
							var cssNode = document.createElement('link');
							cssNode.type = 'text/css';
							cssNode.rel = 'stylesheet';
							cssNode.href = cssLocation;
							cssNode.media = 'screen';
							headID.appendChild(cssNode);
						}
						
						/* Firefox likes the Close functions to sit on top  here */
						function closeAdvisor() {

							//IE Bug, wants a delay before restoring the DOM Content.
							window.setTimeout("fncRestore()" , 0.5); 
							//toggleSelectDisplay('block');
							applyClass('reset');
							Pclosed = true;
						};
				
						var oOffset = 0
						function fncRestore(){
							 
							bannerLeft = getLeft( 'atlasBanner' ) - leftOffset;
							moveObjTo('atlasBanner', bannerLeft - oOffset);
							oOffset =0;
							setHeight('atlasBanner',divTohideHeight);




						setHTML('atlasBanner' ,defaultContent);
						}
							
						/* Toggles the display of Select Boxes , when the Flash layer is loaded. */

						function toggleSelectDisplay(display){
						var selectBoxes = $t("select");
							selectBoxes.each (
												
												function (SelectObject, SelectValue)
													{

														SelectObject.style.display = display;
													}
													

											);
											selectBoxes.next()
						};

				// End Top Level Functions 


						
						// Start Main function.
			function embedPromoMedia() {

							// Debug: Signin Box  wrap in Internet Explorer
							//if(ie == true) window.setTimeout("setDebugwidth('ie')", 1000);



							// Begin : Randomization 

								// Store if the PA was embedded
								var PAembed;
								
								// If cookied already embed PA else Random 
								
								var debugString = location.search.indexOf('debug');								
								if(debugString!=-1)
								{
									//setCookie('debug');
									embedPA();
									PAembed = true;
								}
								else if(readCookie('PA') == "served")
								{
									//embedPA();
									//PAembed = true;

								 	// Omniture Tracking, Send Confirmation of Phone advisor being embedded.
									// s_eVar4="C Phone Advisor UHP";

								}
								else if(readCookie('PA') == "debug")
								{
									//embedPA();
									//PAembed = true;

								 	// Omniture Tracking, Send Confirmation of Phone advisor being embedded.
									//s_eVar4="C Phone Advisor UHP";

								}
								else if(readCookie('PA') == "valA")
								{
								 	// Omniture Tracking, Send Confirmation of Phone advisor being embedded.
									// s_eVar4="A Default UHP 2";

								}
								else if(readCookie('PA') == "valB")
								{
								 	// Omniture Tracking, Send Confirmation of Phone advisor being embedded.
									//s_eVar4="B Default UHP 2";

								}
								else if(readCookie('PA') == "random")
								{
									//embedPA();
									//PAembed = true;

								 	// Omniture Tracking, Send Confirmation of Phone advisor being embedded.
										// s_eVar4="C Phone Advisor UHP 2";

								}
								else
								{
									var randomnumber=Math.floor(Math.random()* 20);
									

									if(randomnumber ==  1 || randomnumber == 2)
									{
										//setCookie('random');
										//embedPA();
										//PAembed = true;
										
										// Omniture Tracking, Send Confirmation of Phone advisor being embedded.
										  //s_eVar4="C Phone Advisor UHP 2";
																		
									}
									else if (randomnumber == 5 || randomnumber == 6){
										//setCookie('valA');
										// Omniture Tracking, sample group
										//s_eVar4="A Default UHP 2";
									}
									else if (randomnumber == 18 || randomnumber == 19) {
										//setCookie('valB');
										// Omniture Tracking, another sample group
										//s_eVar4="B Default UHP 2";
									}
									else
									{
										// Omniture Tracking : Phone Advisor was not embedded.
										// var s_eVar4 = "A – Phone Advisor UHP";

									}
								}
							// End: Randomization Functions.


						// Begin : Phone Advisor Embed Functions 
							function embedPA()  {


							//Flash Check 
							 var embedPA;

							// Check for the Flash version > 7 to start the embed process
							try{ if (com.deconcept.FlashObjectUtil.getPlayerVersion().major < 7) embedPA = false} catch(e){ window.status=FlashEmsg; embedPA = false };

						// Check for the links on the left and assign a onclick to them.
						if(embedPA!=false)	{


							// Assign the CSS File
							embedCSS();
							
							 var lists = $css(listClassName);
							
							 //Debug: Fixing signin
							 //if(ie) setHeight(lists, 203)
							 var o = 0;
							lists.each(
										
										function(key,value)	
										{
										 var listAnchors = key.$t("a");

										
											listAnchors.each (
												
												function (anchorKey, anchorValue)
													{
													
														// The View All Phones ( last link )  is a direct link to the Sprint Store.
													
														if(anchorValue <=  listAnchors.length - 3) {
														
														Events.add("PAEvents","click", { f:passMovie, o:anchorKey, P:[anchorValue] } );
														
														Events.attach(anchorKey, 'PAEvents');
														anchorKey.p =anchorValue;
														anchorKey.k = anchorKey;
																												
														
															anchorKey.href="javascript:void(0)";
															
														}
												
														else
														{
																if(ie) {
																	//	anchorKey.parentNode.style.height="26px"
																}
																else{
																	//	anchorKey.parentNode.style.height="16px"
																	}

																if (anchorValue == listAnchors.length-2)
																{

																	anchorKey.parentNode.style.borderTop="1px dotted #4B4B4B";
																	anchorKey.parentNode.style.borderBottom="0";
																	anchorKey.parentNode.style.marginTop="-1px";
																	anchorKey.parentNode.style.paddingTop="9px";




																}
																																	anchorKey.parentNode.parentNode.marginTop="12px";
																if(anchorValue==listAnchors.length-1){
																anchorKey.parentNode.parentNode.style.borderBottom="0";
																

																}
																anchorKey.parentNode.style.borderBottom="0";
																anchorKey.parentNode.style.backgroundPosition="4px 13px";
																
																//anchorKey.parentNode.style.borderBottom="0";
																anchorKey.parentNode.className="aquaLinks";

																	


																//anchoreKey.parentNode
														}
														 //alert (anchorKey.Events);
														 listAnchors.next();
																					
													}
												
												)
											// Only using the first List, the list classname is re-used for "Upgrade Phone link", not required to be attached. 
											//lists.next();
										}
									
								  );


							};

						};



							

						var clickedAlready =false;

			
					function resetClicked(){
							clickedAlready=false;
						};


						function setUnclickable(){
							if(isStageSet =='true') {
								//alert("value was set, we will play");
								clickedAlready = false;
								isStageSet = 'false';
							}
							else{
								//alert("value was not set, no action");
								clickedAlready = true;
							}
							//window.setTimeout(resetClicked,2000 );
						};

				

						/* This is the new Onlick Function for the left links  */
							function passMovie(obj) {
							
						setUnclickable();
								if(clickedAlready!=true){
							window.scrollTo(0,240);


							s_linkTrackVars='prop29';
							s_linkType='o';
						
									
							/* Evaluate the Hyperlink and Frame Number to Play */
								var oLink = (obj.srcElement) ? obj.srcElement : obj.target;
								var num = (obj.srcElement) ? obj.srcElement.p : obj.target.p;
								var eLink = (obj.srcElement) ? obj.srcElement.k : obj.target.k;
								if(num=='0') s_prop29='PhoneAdvisor:Open:WalkieTalkiePhones';
								if(num=='1') s_prop29='PhoneAdvisor:Open:CameraPhones';
								if(num=='2') s_prop29='PhoneAdvisor:Open:TVMusicPhones';
								if(num=='3') s_prop29='PhoneAdvisor:Open:PDASmartPhones';
								if(num=='4') s_prop29='PhoneAdvisor:Open:MobileBroadbandCards';

							s_lnk=s_co(oLink);
							s_gs('sprintglobal');
							
								if(omniDebug>-1) alert(s_prop29);

						/*
						createCSS(".PAlinkNode", "font-weight:normal;color:#FFE100 !important; text-decoration:none; font-style:normal;");
						createCSS(".PAlinkBgNode", "background-color:#070A11 !important; border-top: 1px solid #070A11 !important; border-bottom: 1px solid #fff !important;border-right:1px solid #070A11 !important");
						createCSS(".PAlinkBgNodeFirst", "background-color:#070A11 !important ;border-top:0px !important;  border-bottom: 1px solid #666 !important;border-right:1px solid #070A11 !important  ");
						*/
						//

						applyClass(oLink);


   						 oLink.blur();


							if(wrotemovie==false || Pclosed==true) writemovie();

							/* Take Decision on whether to create the movie layer or just to play it */
								clickedLink =num;
								checkInit(eLink,num);

								}
							};


						function writemovie()
						{
							wrotemovie=true;
							defaultContent ="";
							
							var tmpMovieHolder = document.createElement("div");
							tmpMovieHolder.id = "tmpHolder"
							tmpMovieHolder.style.display = "none";
							document.body.appendChild(tmpMovieHolder);


							var phoneEmbed = new FlashObject(swfPath, "phoneAdvisor", "590", "430", "8", "transparent");
							
							phoneEmbed.addParam("wmode", "transparent");
							phoneEmbed.addParam("autoPlay", "false");
							phoneEmbed.addParam("swLiveConnect", "true");
							phoneEmbed.addParam("name", "phoneAdvisor");
							phoneEmbed.addParam("allowScriptAccess", "sameDomain");
							phoneEmbed.addParam("myjsvar", "0");
							phoneEmbed.write('tmpHolder');



						}


							
						
							function checkInit(theLink,linkNum)  {

								
								// Swap the Static banner with the phoneAdvisor
								var divTohide = $('atlasBanner');
								// Set Height only the first time - DML bug fix
								 if(divTohideHeight=="") divTohideHeight = getHeight(divTohide);
								 //alert(divTohideHeight);
								//Hide the Select Boxes on the page;
								//toggleSelectDisplay('none');



								if( defaultContent  == "" )  defaultContent  = getHTML(divTohide);
									
								/* Effects code, Work in Progress */
								
						/*
									effectObj = new Object();
									effectObj.items = ["display" ,  , 'none' , '*'];
								
							//		fx.Effect.init( effectObj);

								   doinit = function(effectObj){};
								   fx.Effect( "init" : (function (effectObj){} )) ;

									//fx.Effect.run = function(divTohide){};
									//fx.Effect.run ( {divTohide} );


									( 	
									function(effectObj){
										fx.Effect.run(function(divTohide){});
									}
								);
						*/


						/* When swapping, make the position absolute so that the layer can flow on top of the page */





						// Only swap the layer, if the content is the default banner.
						if($('atlasBanner').innerHTML == defaultContent){

							// Get the left and top values of the current Banner
						

							if( Pclosed!=true) leftOffset = 0;
							leftOffset = (ie) ?  1 : 1	;

							var locy = getTop (divTohide) + "px";	
							var locx = getLeft (divTohide) + leftOffset +  "px";


							//Position and size the Phone Advisor layer
							
							divTohide.style.position="absolute";
							divTohide.style.width="595px";
							divTohide.style.left=locx  ;
							divTohide.style.height="420px";

							var oStyle ="position:absolute; top:" + locy + "left:" + locx +  ";  z-index:1000 ;" +"height:700px";
						//Use the FlashObject to embed our movie, with the parameters.


							

						// Place a timeout, to pass the JS command to the SWF to play the right frame, Firefox wants it


						//playit = true;
						//window.setTimeout("playmovie(" + linkNum +")", 1000);

						movietoWrite = getHTML($('tmpHolder'));

						setHTML($('atlasBanner'), movietoWrite);

						removetmpNode('tmpHolder');
						Pclosed= false;

							playit = true;
							wTimer= window.setTimeout("playmovie(" + linkNum +", false)", 1000);
							
							
						



						}
						else
							
						{

							//  The movie is present, just play it.

									playit = true;
									wTimer = window.setTimeout("playmovie(" + linkNum + ", true)", 300);

								//window.setTimeout("playmovie(" + linkNum +")", 1000);
						}


							};



							/* Setting and Reading Cookies */

							function readCookie(name) {
								var nameEQ = name + "=";
								var ca = document.cookie.split(';');
								for(var i=0;i < ca.length;i++) {
									var c = ca[i];
									while (c.charAt(0)==' ') c = c.substring(1,c.length);
									if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
								}
								return null;
							}

							function setCookie(name) {
								//Set a cookie that never expires
								document.cookie =  'PA=' + name + '; expires=Thu, 2 Aug 2099 20:47:11 UTC; path=/';
							};


						 //Default Atlas Implementation 
//							var squareBannerView ="http://view.atdmt.com/SPT/view/ntrnvspr0060000007spt/direct/01/";
//							var squareBannerClick ="http://clk.atdmt.com/SPT/go/ntrnvspr0060000007spt/direct/01/";
//							if (location.href.getParam("brand") == 'Nextel'){
//									squareBannerView ="http://view.atdmt.com/SPT/view/ntrnvspr0060000009spt/direct/01/";
//									squareBannerClick = "http://clk.atdmt.com/SPT/go/ntrnvspr0060000009spt/direct/01/";				
//									}
//							dwl('<div id="atlasBanner"><a href="'+squareBannerClick+'"><img src="'+squareBannerView+'" /></a></div>');
//							};

						var iframeBannerView = "http://view.atdmt.com/SPT/iview/ntrnvspr0060000016spt/direct/01?click=";
						var iframeBannerClick = "http://clk.atdmt.com/SPT/go/ntrnvspr0060000016spt/direct/01/";
						var iframeImgView = "http://view.atdmt.com/SPT/view/ntrnvspr0060000016spt/direct/01/";
						if (location.href.getParam("brand") == 'Nextel'){	
							iframeBannerView = "http://view.atdmt.com/SPT/iview/ntrnvspr0060000015spt/direct/01?click=";
							iframeBannerClick = "http://clk.atdmt.com/SPT/go/ntrnvspr0060000015spt/direct/01/";
							iframeImgView = "http://view.atdmt.com/SPT/view/ntrnvspr0060000015spt/direct/01/";
						}
						dwl('<div id="atlasBanner"><iframe src="'+iframeBannerView+'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" allowtransparency="true" width="591" height="199"><a href="'+iframeBannerClick+'" target="_blank"><img src="'+iframeImgView+'"/></a></iframe></div>');
				};


						// Flash Interaction Functions


							var movieName = "phoneAdvisor";

							function thisMovie(movieName) {
							  // IE and Netscape refer to the movie object differently.
							  // This function returns the appropriate syntax depending on the browser.
							  if (navigator.appName.indexOf ("Microsoft") !=-1) {
								return window[movieName]
							  }	else {
								return document[movieName]
							  }
							}




							// Checks if movie is completely loaded.
							// Returns true if yes, false if no.
							function movieIsLoaded (theMovie) {
							  if (typeof(theMovie) != "undefined") {
								return theMovie.PercentLoaded() == 100;
							  } else {
								return false;
							  }
							}

						var playit = true;

							function playmovie(arg, sendPlay) {
							
									//thisMovie(movieName).SetVariable("myjsvar",""); 
								if(playit==true)  {
							
								thisMovie(movieName).SetVariable("myjsvar",arg); 

								 
								//alert(typeof arg);
								if(sendPlay==true){
									golabel();
									//alert('playing movie');
									thisMovie(movieName).Play();
								}
								playit=false;
								}
							  
							}

							function stopmovie() {
							  if (movieIsLoaded(thisMovie(movieName))) {
									thisMovie(movieName).StopPlay();
							  }
							}


							function go(theFrame) {
							  if (movieIsLoaded(thisMovie(movieName))) {
								thisMovie(movieName).GotoFrame(theFrame);
							  }
							}




				//mylabel
							function golabel() {
							  if (movieIsLoaded(thisMovie(movieName))) {
								thisMovie(movieName).TGotoLabel("_level0/","myloop");
							  }
							}






							
						}


						//Utility Functions

						function createCSS(selector, declaration) {
								// test for IE
								var ua = navigator.userAgent.toLowerCase();
								var isIE = (/msie/.test(ua)) && !(/opera/.test(ua)) && (/win/.test(ua));

								// create the style node for all browsers
								var style_node = document.createElement("style");
								style_node.setAttribute("type", "text/css");
								style_node.setAttribute("media", "screen"); 

								// append a rule for good browsers
								if (!isIE) style_node.appendChild(document.createTextNode(selector + " {" + declaration + "}"));

								// append the style node
								document.getElementsByTagName("head")[0].appendChild(style_node);

								// use alternative methods for IE
								if (isIE && document.styleSheets && document.styleSheets.length > 0) {
										var last_style_node = document.styleSheets[document.styleSheets.length - 1];
										if (typeof(last_style_node.addRule) == "object") last_style_node.addRule(selector, declaration);
								}
						};
						 
						function removetmpNode(oNodeId){

					
						var oNode = $(oNodeId);
						var oChildren = $(oNodeId).childNodes;
									
								for(i=0;i<oChildren.length;i++)
								{
									oNode.removeChild(oChildren[i]);
								}


				}
					
				if(ie == true){

					
					document.execCommand("BackgroundImageCache",false,true);
				
					

		}
		else{
					 //window.setTimeout("setDebugwidth('firefox')",1);			
		}

		function setDebugwidth(oBrowser){
		
			if(oBrowser=="firefox")	{

		

			}
			else {

				var off10 = $css('.off10');
				//if(ieversion>6) setStyle(off10,  'padding-left', '13px');
				

				var oSign = $css('.SignIn');
				//setWidth(oSign , 210);




			}
					
					


		}
