﻿// popin.js - All features and functions for the Lounge popins
// 2008.01.26 KJD: Document created for popin functions


// 2008.01.28 KJD: Require Ajax function?
var popinlocation 	= "lounge/";
var helplocation 	= "lounge/help/";
var messagelocation	= "lounge/messages/";
var flashlocation 	= "/templates/lounge20080123/flash/";
var content_descriptionlocation = "/learn-templates/oomafeatures/";


// 2008.02.04 KJD: XML reader ( for replacing vars/ strings )

// var XMLreader		= "/content/FormatXML.php";
// 2008.04.28 KJD: Changed to remove PHP from content branch #3622
var XMLreader		= "/php/functions/FormatXML.php";

//Shanthi
var HTMLreader		= "/php/functions/FormatHTML.php";


// 2008.02.13 KJD: Send request to PHP controller
var postLocation	= "/lounge/loungeMVC.php";

//  2008.03.03 TLW: point at new lounge MVC controller: var postLocation	= "/templates/lounge20080123/AJAX/postback.php";


// 2008.03.10 KJD: Added since functionality not yet in MVC controller

var postBackLocation	= "/templates/lounge20080123/AJAX/postback.php";


// 2008.03.31 KJD: Add the popin locations for dragging issues
var popin_top		= 100;
var popin_left		= 100;

// 2008.04.01 KJD: Cound # of popins open for alignment
var openpopins		= 0;

// 2008.01.29 KJD: Automatically detect local version


var thisLocation 	= "" + document.location;


if( thisLocation.indexOf( 'ooma.com' ) == -1 )
{
	var popinlocation 	= "lounge/";
	var helplocation 	= "lounge/help/";
	var messagelocation = "lounge/messages/";
	var flashlocation 	= "../flash/";
	var XMLreader		= "/ThumbDrive/ooma/WebDocs/portal2/www/html-www/content/FormatXML.php";
}

// 2008.02.08 KJD: Hard-coded Ring Patterns due to time
var RingPatterns					= new Array();
RingPatterns[ RingPatterns.length ]	= {	"number": 0,	"name": "Default",			"filename":"00-default.mp3"		};
RingPatterns[ RingPatterns.length ]	= {	"number": 1,	"name": "Ring1 (s-s)",		"filename":"01-s-s.mp3"			};
RingPatterns[ RingPatterns.length ]	= {	"number": 2,	"name": "Ring2 (l-l)",		"filename":"02-l-l.mp3"			};
RingPatterns[ RingPatterns.length ]	= {	"number": 3,	"name": "Ring3 (s-s-s)",	"filename":"03-s-s-s.mp3"		};
RingPatterns[ RingPatterns.length ]	= {	"number": 4,	"name": "Ring4 (l-l-l)",	"filename":"04-l-l-l.mp3"		};
RingPatterns[ RingPatterns.length ]	= {	"number": 5,	"name": "Ring5 (s-s-s-s)",	"filename":"05-s-s-s-s.mp3"		};
RingPatterns[ RingPatterns.length ]	= {	"number": 6,	"name": "Ring6 (l-l-l-l)",	"filename":"06-l-l-l-l.mp3"		};
RingPatterns[ RingPatterns.length ]	= {	"number": 7,	"name": "Ring7 (s-s-l-l)",	"filename":"07-s-s-l-l.mp3"		};
RingPatterns[ RingPatterns.length ]	= {	"number": 8,	"name": "Ring8 (l-l-s-s)",	"filename":"08-l-l-s-s.mp3"		};



// 2008.02.20 KJD: Credit Card Types
var CreditCardTypes							= new Array();
CreditCardTypes[ CreditCardTypes.length ]	= "VISA";
CreditCardTypes[ CreditCardTypes.length ]	= "Master Card";
CreditCardTypes[ CreditCardTypes.length ]	= "American Express";
	
//06/08/2008 SHanthi: List of security questions

var SecurityQuestions						= new Array();

SecurityQuestions[ SecurityQuestions.length ]	= { "value": "Birth City"			, "text": "Which city were you born in?"};
SecurityQuestions[ SecurityQuestions.length ]  	= { "value": "Mother's Maiden Name"	, "text": "What is your mother's maiden name?"};
SecurityQuestions[ SecurityQuestions.length ]	= { "value": "Elementary School"	, "text": "What is the name of your elementary school?"};
SecurityQuestions[ SecurityQuestions.length ] 	= { "value": "Last 4 Of SSN"		, "text": "What are the last 4 digits of your SSN?"};
SecurityQuestions[ SecurityQuestions.length ]   = { "value": "Father's Middle Name"	, "text": "What is your father's middle name?"};
SecurityQuestions[ SecurityQuestions.length ]   = { "value": "Childhood Hero"		, "text": "Who was your childhood hero?"};
SecurityQuestions[ SecurityQuestions.length ]   = { "value": "Favorite Pastime"		, "text": "What is your favorite pastime?"};
SecurityQuestions[ SecurityQuestions.length ]   = { "value": "Favorite Sports Team"	, "text": "What is your all-time favorite sports team?"};
SecurityQuestions[ SecurityQuestions.length ]   = { "value": "High School Mascot"	, "text": "What was your high-school mascot?"};
SecurityQuestions[ SecurityQuestions.length ]   = { "value": "First Vehicle"		, "text": "What make was your first car or bike?"};
SecurityQuestions[ SecurityQuestions.length ]   = { "value": "Where You Met Spouse"	, "text": "Where did you first meet your spouse?"};
SecurityQuestions[ SecurityQuestions.length ]   = { "value": "Pet's Name"			, "text": "What is your pet's name?"};
SecurityQuestions[ SecurityQuestions.length ]   = { "value": "Favorite Food"		, "text": "What is your favorite food?"};
SecurityQuestions[ SecurityQuestions.length ]   = { "value": "Favorite Movie"		, "text": "What is your favorite movie?"};





// 2008.02.21 KJD: Current device


var CurrentDevice 	= "";


	


// 2008.02.29 KJD: Current Number


var CurrentNumber	= "";


	


// 2008.01.27 KJD: Get the Help vars


function GetXMLInfo( thisfile )


{


	var thisArray 		= new Array();





	var myxml 			= GetFile( thisfile, "XML", "object" );





	// 2008.01.29 KJD: Check if XML exists


	if( !( myxml ) )


	{


		return 30140;


	}


	


	var theseitems 		= myxml.getElementsByTagName( "item" );


	


	thisArray[ 'buttoncount' ] = 0;


	


	for( var i = 0; i < theseitems.length; i++ )


	{


		if( theseitems[ i ].nodeName == 'item' )


		{


			// 2008.01.29 KJD: get the main node


			var nodeID		= theseitems[ i ].getElementsByTagName( "id" );


			var thisid		= nodeID[0].firstChild.nodeValue;





			// 2008.01.31 KJD: Check for valid XML data node


			try


			{


				var thisData	= theseitems[ i ].getElementsByTagName( "data" );


				var thisdata	= thisData[0].firstChild.nodeValue;


			}


			catch( e )


			{


				return 30141;


			}


			


			// 2008.01.27 KJD: Get XML Values


			if( 


				( thisid 	== 'popintitle'	) ||


				( thisid	== 'heading1' 	) ||


				( thisid 	== 'heading2' 	) ||


				( thisid 	== 'heading3' 	) ||


				( thisid 	== 'text1' 		) ||


				( thisid 	== 'text2' 		) ||


				( thisid 	== 'text3' 		) ||


				( thisid 	== 'onload'		)	// 2008.02.08 KJD: If to execute onload 


			)


			{


				thisArray[ thisid ] = thisdata;


				


				// 2008.01.29 KJD: Check for help address


				try


				{


					var thisHelp					= theseitems[ i ].getElementsByTagName( "helpfile" );


					var thishelp					= thisHelp[0].firstChild.nodeValue;


					thisArray[ thisid + "_help" ] 	= thishelp;


				}


				catch( e )


				{


				}


			}


			else if( 


				( thisid 	== 'buttontext1' ) ||


				( thisid	== 'buttontext2' ) ||


				( thisid	== 'buttontext3' )


			)	


			{


				thisArray[ thisid ]				= thisdata;


				thisArray[ thisid + "_url" ]	= '';


				thisArray[ 'buttoncount' ]++;


				

				// 2008.01.28 KJD: Check for button URL


				try


				{


					// 2008.01.30 KJD: Get the button URL


					var thisUrl						= theseitems[ i ].getElementsByTagName( "url" );


					var thisurl						= thisUrl[0].firstChild.nodeValue;


					thisArray[ thisid + "_url" ]	= thisurl;


				}


				catch( e )


				{


				}


			}


		}


	}


	


	return thisArray;


}








// 2008.01.26 KJD: Open a popin


function popin_open( thistype, thisname, thisAction )


{


	// 2008.01.26 KJD: Check if popin already exists


	if( !( document.getElementById( 'popin_' + thisname ) ) )


	{


		var popinDiv		= document.getElementById( 'popindata' );
		var helpDiv			= document.getElementById( 'popindata_help' );
		
		// 2008.04.03 KJD: Added for messages
		var messageDiv		= document.getElementById( 'popindata_message' );
		
		// 2008.03.31 KJD: Added one for error div too
		var errorDiv		= document.getElementById( 'popindata_error' );

		var thisHTML		= '';





		// 2008.01.26 KJD: Get the popin code.
		// 2008.03.31 KJD: No need to get this, just append it
		// thisHTML 			= popinDiv.innerHTML;



	


		var thisValue 		= popin_create( thistype, thisname );


		


		// 2008.01.29 KJD: If there's an error


		if( typeof thisValue != 'string')


		{


			DisplayError( thisValue );


		}


		else


		{


			// 2008.02.08 KJD: Already have this, no need to get it again


			// thisHTML 			+= popin_create( thistype, thisname );


			thisHTML += thisValue;


		}


		// 2008.03.31 KJD: Added to solve the text disappearing from form elements when help showing
		if( thistype == 'help' )
		{
			helpDiv.innerHTML 	+= thisHTML;
		}
		else if( thistype == 'message' )
		{
			messageDiv.innerHTML += thisHTML;
		}		
		else if( thistype == 'error' )
		{
			errorDiv.innerHTML 	+= thisHTML;
		}
		else
		{
			popinDiv.innerHTML 	+= thisHTML;
		}

		// return true;


	}


	else


	{


		popin_show( "popin_" + thisname );


	}


	


	// 2008.01.31 KJD: If Action, execute it


	if( thisAction )


	{


		thisAction += "( 'popin_" + thisname + "' );";


		eval( thisAction );


	}


}





// 2008.01.26 KJD: Create a new popin window


function popin_create( thistype, thisname )


{


	// 2008.01.28 KJD: If error message


	


	var thisFile	= "";


	


	// 2008.01.29 KJD: Do full location


	if( thistype == 'help' )


	{


		// thisFile	= helplocation + thisname + ".xml";


		// 2008.02.04 KJD: Use PHP formatter


		thisFile = XMLreader + "?filename=" + escape( helplocation + thisname + ".xml" );





	}


	else if( thistype == 'popin' )


	{


		// thisFile	= popinlocation + thisname + ".xml";


		// 2008.02.04 KJD: Use PHP formatter


		thisFile = XMLreader + "?filename=" + escape( popinlocation + thisname + ".xml" );


	}


	else if( thistype == 'message' )


	{


		// thisFile	= messagelocation + thisname + ".xml";


		// 2008.02.04 KJD: Use PHP formatter


		thisFile = XMLreader + "?filename=" + escape( messagelocation + thisname + ".xml" );


	}


	else if( thistype == 'error' )


	{


		// 2008.02.14 KJD: Display an error


		thisFile = XMLreader + "?filename=" + escape( messagelocation + "Error.xml" );


	}


	else if( thistype == 'content_description' )


	{


		//Shanthi : read HTML file

		
		thisFile = HTMLreader + "?filename=" + escape(content_descriptionlocation + thisname + ".xml"  ) + "&htmlfilename=" + escape(content_descriptionlocation + thisname + ".html"  );

	}


	// 2008.01.27 KJD: Get the XML vars


	var helpVars = GetXMLInfo( thisFile );





	// 2008.01.29 KJD: Error from XML file


	if( typeof helpVars != 'object' )


	{


		return helpVars;


	}


	


	// 2008.02.14 KJD: Adjust closeX for IE


	var adjustStyle = "";


	


	var isIE = ( ( navigator.appVersion.indexOf( "MSIE" ) != -1 ) )? true : false;	


	if( isIE )


	{


		adjustStyle = "STYLE='margin:0px;'";


	}


	// 2008.04.01 KJD: Check # of popins open
	openpopins++;
	
	if( openpopins > 10 ){ openpopins = 0; }
	
	var myheight='100%';
	
	//custom popin size
	if(document.getElementById('popin_top')){
	//	popin_top=document.getElementById('popin_top').value;
	//	popin_left=document.getElementById('popin_left').value;
		popin_top=200;
		myheight='1100px'
	}
	
	popin_top += ( openpopins * 10 );
	popin_left += ( openpopins * 10 );

	
	var thisCode = "<DIV ID='popin_" + thisname + "' 		CLASS='popintype_" + thistype + "'>"
	

		+ "<DIV ID='popin_" + thisname + "_mask' 			CLASS='popin_mask' style=\"height:" + myheight + "\" OnClick=\"popin_hide('popin_" + thisname + "')\">&nbsp;</DIV>"

		
		+ "<DIV ID='popin_" + thisname + "_window' 			CLASS='popin_window' STYLE='top:" + popin_top + "px;left:" + popin_left + "px;'>"


		+ "<DIV ID='popin_" + thisname + "_windowtopbar' 	CLASS='popin_windowTopbar' onmousedown=\"dragStart( event, 'popin_" + thisname + "_window')\" >" + helpVars[ 'popintitle' ] 


		+ "<DIV ID='popin_" + thisname + "_windowX' 		CLASS='popin_windowX' OnClick=\"popin_hide('popin_" + thisname + "')\" " + adjustStyle + "></DIV>"


		+ "</DIV>";


		


	// 2008.01.28 KJD: Create the content section and title for each


	if( helpVars[ 'heading1' ] )


	{


		// 2008.01.28 KJD: Display if heading


		thisCode += "<DIV ID='popin_" + thisname + "_window_heading1' CLASS='popin_windowContentHeader'>"


		


		if( helpVars[ 'heading1_help' ] )


		{


			thisCode += popin_helpimage( helpVars[ 'heading1_help' ] );


			


		}


		


		thisCode += helpVars[ 'heading1' ] + "</DIV>";


	}


	


	// 2008.01.28 KJD: Check for Text


	if( helpVars[ 'text1' ] )


	{


		thisCode += "<DIV ID='popin_" + thisname + "_windowcontent' CLASS='popin_windowContent'>" + helpVars[ 'text1' ] + "</DIV>";


	}


	


	// 2008.02.08 KJD: Check for onload


	if( helpVars[ 'onload' ] )


	{


		// thisCode += eval( helpVars[ 'onload' ] );


		setTimeout( helpVars[ 'onload' ], 500 );


	}


	


	// 2008.01.28 KJD: Create the content section and title for each


	if( helpVars[ 'heading2' ] )


	{


		// 2008.01.28 KJD: Display if heading


		thisCode += "<DIV ID='popin_" + thisname + "_window_heading2' CLASS='popin_windowContentHeader'>"


		


		if( helpVars[ 'heading2_help' ] )


		{


			thisCode += popin_helpimage( helpVars[ 'heading2_help' ] );


		}


		


		thisCode += helpVars[ 'heading2' ] + "</DIV>";


	}


	


	// 2008.01.28 KJD: Check for Text


	if( helpVars[ 'text2' ] )


	{


		thisCode += "<DIV ID='popin_" + thisname + "_windowcontent' CLASS='popin_windowContent'>" + helpVars[ 'text2' ] + "</DIV>";


	}





	// 2008.01.28 KJD: Create the content section and title for each


	if( helpVars[ 'heading3' ] )


	{


		// 2008.01.28 KJD: Display if heading


		thisCode += "<DIV ID='popin_" + thisname + "_window_heading3' CLASS='popin_windowContentHeader'>"


		


		if( helpVars[ 'heading3_help' ] )


		{


			thisCode += popin_helpimage( helpVars[ 'heading3_help' ] );


		}


		


		thisCode += helpVars[ 'heading3' ] + "</DIV>";


	}


	


	// 2008.01.28 KJD: Check for Text


	if( helpVars[ 'text3' ] )


	{


		thisCode += "<DIV ID='popin_" + thisname + "_windowcontent' CLASS='popin_windowContent'>" + helpVars[ 'text3' ] + "</DIV>";


	}





	


	// 2008.01.28 KJD: Begin the buttons section


	thisCode += "<DIV ID='popin_" + thisname + "_windowButtons' CLASS='popin_windowButtons'>" 


		+ "<TABLE BORDER='0' CELLPADDING='0' CELLSPACING='0' WIDTH='90%'><TR>";


	


	if( helpVars[ 'buttoncount' ] > 1 )


	{


		for( var i = 0; i < helpVars[ 'buttoncount' ]; i++ )


		{


			if( i < 3 )


			{


				thisCode += "<TD ALIGN='MIDDLE'>" 


					+ popin_button( "popin_" + thisname, helpVars[ 'buttontext' + ( i + 1 ) ], helpVars[ 'buttontext' + ( i + 1 ) + "_url" ] ) 


					+ "</TD>";


			}


		}


	}


	else
	{
		// 2008.03.26 KJD: Check if the button has a URL
		if( helpVars[ 'buttontext1_url' ] )
		{
			thisCode += "<TD ALIGN='MIDDLE'>" 
				+ popin_button( "popin_" + thisname, helpVars[ 'buttontext1' ], helpVars[ 'buttontext1_url' ] ) 
				+ "</TD>";
		}
		else
		{
			thisCode += "<TD ALIGN='MIDDLE'>" 
				+ popin_button( "popin_" + thisname, helpVars[ 'buttontext1' ], "" ) 
				+ "</TD>";
		}
	}


	


	thisCode += ""


		+ "</TR></TABLE>"


		+ "</DIV>"





		+ "</DIV>"


		


		


		+ "</DIV>";


	


	return thisCode;


}





// 2008.02.08 KJD: Create Ring pattern table


function RingPatternList( itemID, itemType )


{


	var thisString = "";





	if( itemType == 'div' )


	{


		thisString += ""


			+ "	<TABLE BORDER='0' CELLPADDING='0' CELLSPACING='0' WIDTH='75%'>"


			+ "		<TR>"


			+ "			<TH>Ring Pattern</TH>"


			+ "			<TH>Sample</TH>"


			+ "		</TR>";


			


		// 2008.02.08 KJD: Loop for each ring pattern


		for( var i = 0; i < RingPatterns.length; i++ )


		{


			thisString += ""


				+ "		<TR>"


				+ "			<TD>" + RingPatterns[ i ][ 'name' ] + "</TD>"


				+ "			<TD><a href='#' OnClick=\"RingPattern( 'play', '" + RingPatterns[ i ][ 'filename' ] + "')\"><img src='/templates/lounge20080123/images/popin_speaker.gif' border='0' ALIGN='ABSMIDDLE'></a></TD>"


				+ "		</TR>";


		}





		thisString += ""


			+ "	</TABLE>"


			+ "";


			


		document.getElementById( itemID ).innerHTML = thisString;


	}


	else if( itemType == 'select' )


	{


		// 2008.02.08 KJD: Loop for each ring pattern


		for( var i = 0; i < RingPatterns.length; i++ )


		{


			try


			{


				document.getElementById( itemID ).options[ document.getElementById( itemID ).options.length ] = new Option( RingPatterns[ i ][ 'name' ], i );


				


			}catch(e){}


		}


	}





	


}





// 2008.01.29 KJD: Display Help Icon


function popin_helpimage( helpID )


{


	var thisString = ""


		+ "<DIV ID='" + helpID + "_helpIcon' onClick=\"popin_open( 'help', '" + helpID + "' )\" CLASS='popin_help'></DIV>";


	


	return thisString;


}


		


// 2008.01.27 KJD: Code for Popin Button


function popin_button( popinID, buttonText, buttoncode )


{


	// 2008.01.30 KJD: Check for button code properties


	var thisCode = "";


	


	if( buttoncode )


	{


		// 2008.01.30 KJD: Execute that function


		thisCode = buttoncode + "( '" + popinID + "' )";


	}


	else


	{


		// 2008.01.30 KJD: No buttoncode, just close popin


		thisCode = "popin_hide( '" + popinID + "' );";


	}


	


	var thisString = "<INPUT TYPE='BUTTON' VALUE='" + buttonText + "' OnClick=\"" + thisCode + "\" CLASS='popin_button' ID='button_" + popinID + "_" + buttonText + "'>";


	


	return thisString;


}





// 2008.01.26 KJD: Show the popin


function popin_show( thisname )


{


	document.getElementById( thisname ).style.display = 'block';


}





// 2008.01.26 KJD: Close the popin


function popin_hide( thisname )


{


	document.getElementById( thisname ).style.display = 'none';


}





// 2008.01.28 KJD: Display an error


function DisplayErrorPopin( errorcode, errorstringbefore, errorstringafter, thiserrorcode, thiserrormessage )


{


	// 2008.01.30 KJD: Do an error


	var thisString = "";


	


	// 2008.01.31 KJD: Error before


	if( errorstringbefore )


	{


		thisString += errorstringbefore + "\n";


	}


	


	// thisString += "Error:" + errorcode;


	


	// 2008.01.31 KJD: Check if errorcode is an array\


	if( typeof errorcode == 'object' )


	{


		for( var i = 0; i < errorcode.length; i++ )


		{


			// 2008.01.31 KJD: Add error message from Array


			thisString += ErrorArray[ errorcode[ i ] ] + "\n";


		}


	}


	else


	{


		// 2008.01.31 KJD: Add error message from Array


		thisString += ErrorArray[ errorcode ];


	}


	


	// 2008.01.31 KJD: Error after


	if( errorstringafter )


	{


		thisString += "\n" + errorstringafter;


	}


	// 2008.03.22 KJD: Let's include the error message
	if( thiserrormessage )
	{
		// 2008.04.01 KJD: Format for production
		thisString += "<p>&nbsp;</p>" + thiserrormessage;
		
		if( thiserrorcode )
		{
			thisString += "<p><font STYLE='font-size:9px'>(" + errorcode + "/" + thiserrorcode + ")</font>";
		}

	}
	



	// 2008.02.14 KJD: Show error popin


	popin_open( 'error', 'thiserror' );





	// 2008.02.14 KJD: Replace the message with the text

	// 2008.03.22 KJD: Also include the errorcode
	// 2008.03.31 KJD: Check if error open
	if(document.getElementById( "popin_thiserror_windowcontent" ) )
	{
		document.getElementById( "popin_thiserror_windowcontent" ).innerHTML = thisString;
	}
	else
	{
		alert( "Error Loading ERROR template\n\nmessage:" + thisString );
	}


	


	return false;


}








// 2008.02.01 KJD: Ring Pattern functions


function RingPattern( thisAction, thisFile, thisNumber )


{


	// 2008.02.08 KJD: if number received


	if( typeof thisNumber != 'undefined' )


	{


		for( var i = 0; i < RingPatterns.length; i++ )


		{


			if( RingPatterns[ i ][ 'number' ] == thisNumber )


			{


				thisFile = RingPatterns[ i ][ 'filename' ];


			}


		}


	}


	


	// 2008.02.08 KJD: Write the Flash player to the Ring Player Div


	var thisPlayer = flashlocation + "RingPatternPlayer.swf?thisSound=" + thisFile;


	


	var thisString = ""


		+ "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\"0\" height=\"0\" id=\"RingPatternPlayer\" align=\"middle\">"


		+ "<param name=\"allowScriptAccess\" value=\"sameDomain\" />"


		+ "<param name=\"allowFullScreen\" value=\"false\" />"


		+ "<param name=\"movie\" value=\"" + thisPlayer + "\" />"


		+ "<param name=\"quality\" value=\"high\" />"


		+ "<param name=\"bgcolor\" value=\"#ffffff\" />"


		+ "<embed src=\"" + thisPlayer + "\" "


		+ "	quality=\"high\" "


		+ "	bgcolor=\"#ffffff\" "


		+ "	width=\"0\" "


		+ "	height=\"0\" "


		+ "	name=\"RingPatternPlayer\" "


		+ "	align=\"middle\" "


		+ "	allowScriptAccess=\"sameDomain\" "


		+ "	allowFullScreen=\"false\" "


		+ "	type=\"application/x-shockwave-flash\" "


		+ "	pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />"


		+ "</object>";





	document.getElementById( "RingPatternPlayer" ).innerHTML = thisString;


	


	return false;


}








// 2008.02.06 KJD: Display the available DIDs


function DisplayNumbers( DIDArray )


{


	// 2008.02.28 KJD: Check for DID Array length


	if( DIDArray.length )


	{


		// 2008.02.07 KJD: Hide available numbers by default


		document.getElementById( 'available_numbers' ).style.display	= 'none';


		document.getElementById( 'rate_charge' ).style.display			= 'none';





		var numbersPerPage	= 10;


		var thisCount		= 0;


		var numberCount 	= 0;





		for( var i in DIDArray ){ numberCount++; }


		numberCount--;





		// 2008.02.07 KJD: Check for length


		if( numberCount )


		{


			// 2008.02.06 KJD: Display the available numbers


			document.getElementById( 'available_numbers' ).style.display	= 'block';


			document.getElementById( 'rate_charge' ).style.display			= 'block';


			


			// 2008.02.06 KJD: Get the middle of the list


			var leftcol 	= "";


			var rightcol	= "";


			


			for( var i in DIDArray )


			{


				try


				{


					var NumberInfo = DIDArray[ i ].split( "####" );


				


					if( NumberInfo[ 1 ] )


					{


						if( thisCount < ( Math.ceil( numberCount / 2 ) ) )


						{


							leftcol += "<DIV CLASS='didresult'><a href='#' onClick='AddNumberSelect( " + NumberInfo[ 0 ] + " );'>" + phone_format( NumberInfo[ 0 ] ) + " (" + NumberInfo[ 1 ] + ")</a></DIV>";


						}


						else


						{


							rightcol += "<DIV CLASS='didresult'><a href='#' onClick='AddNumberSelect( " + NumberInfo[ 0 ] + " );'>" + phone_format( NumberInfo[ 0 ] ) + " (" + NumberInfo[ 1 ] + ")</a></DIV>";


						}





						thisCount++;


					}


				}


				catch( e ){}


			}


			


			


			// 2008.02.06 KJD: Create the number list


			var thisString = ""


				+ "<DIV CLASS='didsearch_resultsleft'>" + leftcol + "</DIV>"


				+ "<DIV CLASS='didsearch_resultsright'>" + rightcol + "</DIV>";


			


				


			document.getElementById( 'number_list' ).innerHTML = thisString;


		}


	}





}





// 2008.02.07 KJD: Add new device from Add number popin


function DeviceSelected( thisString )


{


	if( thisString == '_add_' )


	{


		popin_open( 'popin', 'popin_AddDevice' );


	}





	return false;


}








// 2008.02.20 KJD: Populate the popin values


function PopinPopulate( thisarea, value1, value2 )


{


 	if( thisarea == 'serviceinfo' )


	{


		// 2008.02.20 KJD: Populate Billing Info


		SetItemValue( 'service_firstname',			CustomerInfo[ 'serviceaddress' ][ 'firstname' ] );


		SetItemValue( 'service_lastname',			CustomerInfo[ 'serviceaddress' ][ 'lastname' ] );


		SetItemValue( 'service_phone',				phone_format( CustomerInfo[ 'serviceaddress' ][ 'phone' ] ) );


		


		SetItemValue( 'service_streetnumber',		CustomerInfo[ 'serviceaddress' ][ 'streetnumber' ] );


		SetItemValue( 'service_streetdirprefix',	CustomerInfo[ 'serviceaddress' ][ 'predir' ] );


		SetItemValue( 'service_streetname', 		CustomerInfo[ 'serviceaddress' ][ 'streetname' ] );


		SetItemValue( 'service_streettype', 		CustomerInfo[ 'serviceaddress' ][ 'streettype' ] );


		SetItemValue( 'service_streetdirsuffix', 	CustomerInfo[ 'serviceaddress' ][ 'postdir' ] );


		SetItemValue( 'service_secondaryunit', 		CustomerInfo[ 'serviceaddress' ][ 'unittype' ] );


		SetItemValue( 'service_secondarynumber', 	CustomerInfo[ 'serviceaddress' ][ 'unitnumber' ] );


				


		SetItemValue( 'service_city',				CustomerInfo[ 'serviceaddress' ][ 'city' ] );


		SetItemValue( 'service_state', 				CustomerInfo[ 'serviceaddress' ][ 'state' ] );


		SetItemValue( 'service_zip', 				CustomerInfo[ 'serviceaddress' ][ 'zip' ] );


		SetItemValue( 'service_zip4', 				CustomerInfo[ 'serviceaddress' ][ 'zip4' ] );


		// 2008.04.07 KJD: Clear the errors
		FormError( 'error_service_firstname', 		'reset' );
		FormError( 'error_service_lastname', 		'reset' );
		FormError( 'error_service_phone', 			'reset' );

		FormError( 'service_streetnumber_status', 	'reset' );
		FormError( 'service_streetname_status', 	'reset' );
		FormError( 'service_streettype_status', 	'reset' );

		FormError( 'error_service_city', 			'reset' );
		FormError( 'error_service_state', 			'reset' );
		FormError( 'error_service_zip', 			'reset' );
	}


	else if( thisarea == 'billinginfo' )


	{


		// 2008.02.20 KJD: Populate Billing Info


		SetItemValue( 'billing_firstname',	CustomerInfo[ 'billingaddress' ][ 'firstname' ] );


		SetItemValue( 'billing_lastname',	CustomerInfo[ 'billingaddress' ][ 'lastname' ] );


		SetItemValue( 'billing_phone',		phone_format( CustomerInfo[ 'billingaddress' ][ 'phone' ] ) );





		// 2008.02.21 KJD: Check address type


		if( CustomerInfo[ 'billingaddress' ][ 'addresstype' ] == 'pobox' )


		{


			document.getElementById( 'bill_type_poboxYes').checked = true;


			AddressTypeSelected( 'pobox' );


			


			SetItemValue( 'billing_pobox',	CustomerInfo[ 'billingaddress' ][ 'poboxnumber' ] );


		}


		else


		{


			document.getElementById( 'bill_type_poboxNo').checked = true;


			AddressTypeSelected( 'street' );


			


			SetItemValue( 'billing_streetnumber',		CustomerInfo[ 'billingaddress' ][ 'streetnumber' ] );


			SetItemValue( 'billing_streetdirprefix',	CustomerInfo[ 'billingaddress' ][ 'predir' ] );


			SetItemValue( 'billing_streetname',			CustomerInfo[ 'billingaddress' ][ 'streetname' ] );


			SetItemValue( 'billing_streettype',			CustomerInfo[ 'billingaddress' ][ 'streettype' ] );


			SetItemValue( 'billing_streetdirsuffix',	CustomerInfo[ 'billingaddress' ][ 'postdir' ] );


			SetItemValue( 'billing_secondaryunit',		CustomerInfo[ 'billingaddress' ][ 'unittype' ] );


			SetItemValue( 'billing_secondarynumber',	CustomerInfo[ 'billingaddress' ][ 'unitnumber' ] );


		}





		SetItemValue( 'billing_city', 		CustomerInfo[ 'billingaddress' ][ 'city' ] );


		SetItemValue( 'billing_state',		CustomerInfo[ 'billingaddress' ][ 'state' ] );


		SetItemValue( 'billing_zip',		CustomerInfo[ 'billingaddress' ][ 'zip' ] );


		SetItemValue( 'billing_zip4',		CustomerInfo[ 'billingaddress' ][ 'zip4' ] );








		SetItemValue( 'billing_cctype',		CustomerInfo[ 'billinginfo' ][ 'cardtype' ] );


		SetItemValue( 'billing_ccnumber',	CustomerInfo[ 'billinginfo' ][ 'carddigits' ] );





		SetItemValue( 'billing_month',		CustomerInfo[ 'billinginfo' ][ 'cardmonth' ] );


		SetItemValue( 'billing_year',		CustomerInfo[ 'billinginfo' ][ 'cardyear' ] );





		SetItemValue( 'billing_cvv',		CustomerInfo[ 'billinginfo' ][ 'cardcvv' ] );


		// 2008.04.07 KJD: Clear errors
		FormError( 'error_billing_firstname', 		'reset' );
		FormError( 'error_billing_lastname', 		'reset' );
		FormError( 'error_billing_phone', 			'reset' );
		
		FormError( 'error_billing_addresstype', 	'reset' );
		FormError( 'error_billing_pobox',			'reset' );
		
		FormError( 'billing_streetnumber_status',	'reset' );
		FormError( 'billing_streetname_status', 	'reset' );
		FormError( 'billing_streettype_status', 	'reset' );
			
		FormError( 'error_billing_city', 			'reset' );
		FormError( 'error_billing_state', 			'reset' );
		FormError( 'error_billing_zip', 			'reset' );
		
		FormError( 'error_billing_cctype', 			'reset' );
		FormError( 'error_billing_ccnumber', 		'reset' );
		FormError( 'error_billing_date', 			'reset' );
		FormError( 'error_billing_cvv', 			'reset' );
	}


	else if( thisarea == 'logininfo' )


	{
		SetItemValue( 'login_emailaddress', CustomerInfo[ 'logininfo' ][ 'email' ] );
		SetItemHTML( 'phonenumber',CustomerInfo[ 'logininfo' ][ 'phone' ] );
		SelectBoxHelper.initSelect('security_question');
		SelectBoxHelper.addOptions(SecurityQuestions);
		SelectBoxHelper.selectOption( CustomerInfo[ 'logininfo' ][ 'SecQuestion' ]);
		SetItemValue('current_security_question', CustomerInfo[ 'logininfo' ][ 'SecQuestion' ]);
		

		// 2008.04.07 KJD: Clear Errors
		FormError( 'error_login_emailaddress', 	'reset' );	
		FormError( 'error_login_password', 		'reset' );
		FormError( 'error_login_password2', 	'reset' );

	}

	else if( thisarea == 'EmailInfo' )


	{
		
		SetItemHTML( 'phonenumber',CustomerInfo[ 'logininfo' ][ 'phone' ] );
		
		
	}

	else if( thisarea == 'viewdevice' )


	{


		// VALUE1 = device object key


		CurrentDevice = value1;


		


		// 2008.02.21 KJD: View the device before editing it.


		SetItemValue( 'viewdevice_locationname', 	deviceObject[ value1 ][ 'deviceName' ] );


		


		SetItemHTML( 'viewdevice_devicetype', 		deviceObject[ value1 ][ 'devicetype' ] );

		//Shanthi: 04/24/08 - Display Scout ID in View device popin
		// 2008.05.12 KJD: Only display this if it is a scout
		if( deviceObject[ value1 ][ 'devicetype' ] != 'Hub' )
		{
			SetItemHTML( 'viewdevice_scoutID', 	deviceObject[ value1 ][ 'scoutID' ] );
		}


		// 2008.02.28 KJD: TODO: Get this information for the device


		SetItemValue( 'viewdevice_firstname', 		deviceObject[ value1 ][ 'firstname' ] );


		SetItemValue( 'viewdevice_lastname', 		deviceObject[ value1 ][ 'lastname' ] );

		SetItemValue( 'viewdevice_emailaddress', 	deviceObject[ value1 ][ 'email' ] );  // 2008.03.12 TLW
		// SetItemValue( 'viewdevice_emailaddress', 	locationInfo[ value1 ][ 'info' ][ 'email' ] );


		


	}


	else if( thisarea == 'editdevice' )

	{

		value1 = CurrentDevice;

		

		// 2008.02.28 KJD: Updated variables to use deviceObject

		

		// 2008.02.21 KJD: View the device before editing it.

		SetItemValue( 'editdevice_devicelocation', 	deviceObject[ value1 ][ 'deviceName' ] );

		

		

		if( deviceObject[ value1 ][ 'devicetype' ] == 'Scout' )

		{

			document.getElementById( 'editdevice_scout' ).checked = true;

			editdevice_selected( 'Scout' );
			// 2008.03.13 TLW: editdevice_selected( 'scout' );

			

			SetItemValue( 'input_editdevice_scoutID', 	deviceObject[ value1 ][ 'scoutID' ] );

		}

		else

		{

			document.getElementById( 'editdevice_hub' ).checked = true;

		}



		// 2008.02.28 KJD: TODO: Get this information for the device

		SetItemValue( 'editdevice_firstname', 		deviceObject[ value1 ][ 'firstname' ] );
		// 2008.03.12 TLW: SetItemValue( 'viewdevice_firstname', 		deviceObject[ value1 ][ 'firstname' ] );

		SetItemValue( 'editdevice_lastname', 		deviceObject[ value1 ][ 'lastname' ] );
		// 2008.03.12 TLW: SetItemValue( 'viewdevice_lastname', 		deviceObject[ value1 ][ 'lastname' ] );

		SetItemValue( 'editdevice_email', 	deviceObject[ value1 ][ 'email' ] );  // 2008.03.12 TLW
		// SetItemValue( 'editdevice_email', 			locationInfo[ value1 ][ 'info' ][ 'email' ] );



	
		// 2008.02.28 KJD: TODO: Get from OSS

		// 2008.03.12 KJD: Removed
		/*
		if( deviceObject[ value1 ][ 'loungeLogin' ] )

		{

			document.getElementById( 'editdevice_sendloginyes' ).checked = true;

		}

		else

		{

			document.getElementById( 'editdevice_sendloginno' ).checked = true;

		}

		*/
	}


	else if( thisarea == 'editnumber' )


	{


		// 2008.02.21 KJD: Populate edit a number popin


		// VALUE1 = device object key


		// VALUE2 = number key

		// 2008.03.27 KJD: Clear the values shown
		SetItemHTML( 'editnumber_phonenumber', 		'' );
		SetItemHTML( 'editnumber_callerIDoverride', '' );
		SetItemHTML( 'editnumber_callerIDname', 	'' );
		
		SetItemValue( 'editnumber_device', 			'' );
		

		value1			= unescape( value1 );


		CurrentDevice	= value1;


		CurrentNumber	= value2;


		


		// 2008.02.21 KJD: Set time since there's an onload event


		setTimeout( "PopinPopulate( 'editnumberpop', '" + escape( value1 ) + "', '" + escape( value2 ) + "' )", 550 );


	}


	else if( thisarea == 'editnumberpop' )


	{


		value1	= unescape( value1 );


		value2	= unescape( value2 );





		CurrentNumber	= value2;


		// 2008.07.15 KJD: Set up the star code images
		var StarCodeString	= PhoneKeyImages( "**" + deviceObject[ value1 ][ 'DID' ][ value2 ][ 'StarCode' ] );
		


		// 2008.02.27 KJD: Updated vars to use session values


		SetItemHTML( 'editnumber_phonenumber', 		phone_format( deviceObject[ value1 ][ 'DID' ][ value2 ][ 'E164' ] ) );





		SetItemHTML( 'editnumber_callerIDoverride',	StarCodeString );


		


		SetItemValue( 'editnumber_device', 			value1 );

		//generate premier Icon
		if(CustomerInfo[ 'serviceInfo' ][ 'service_type']=='core'){
			
					thisString2="<img class=\"trigger premier_icon\" src=\"/content/en/us/learn/images/premier/crown.gif\" align='absmiddle' title='Ring patterns are available with ooma Premier - click on \"hear more\" to listen!' style='padding: 0px 0px 0px 0px'/>&nbsp;&nbsp;Ring Pattern";
				
							
			SetItemHTML('ringpattern_label', thisString2);			
		}
		else{
			thisString2="<img src=\"/content/en/us/learn/images/premier/crown.gif\" align='absmiddle' title='Ring patterns are a ooma Premier Feature' style='padding: 0px 0px 0px 0px'/>&nbsp;&nbsp;Ring Pattern";
			SetItemHTML('ringpattern_label', thisString2);
		}
			
		SetItemValue( 'editnumber_ringpattern',		deviceObject[ value1 ][ 'DID' ][ value2 ][ 'RingPattern' ] );

		//ALWAYS select default (first in list) if core customer
		if(CustomerInfo[ 'serviceInfo' ][ 'service_type']=='core')
		{
			document.getElementById("editnumber_ringpattern").disabled = true;
			var selectionBox=document.getElementById("editnumber_ringpattern");
			selectionBox[0].selected="1";
		}
	
	
		// 2008.02.27 KJD: Added CID


		SetItemHTML( 'editnumber_callerIDname',		deviceObject[ value1 ][ 'DID' ][ value2 ][ 'CName' ] );


		


		// 2008.02.27 KJD: Set up the device name and list


		var deviceCount = 0;


		for( var i in deviceObject ){	deviceCount++;	}


		


		if( deviceCount > 1 )
		{
			// 2008.02.27 KJD: Create the drop-down items
			// document.getElementById( 'editnumber_devicetext' ).style.display = 'none';	
	


			// 2008.02.28 KJD: Check if drop-down already formed
			if( !( document.getElementById( 'editnumber_device' ).options[ 1 ] ) )
			{
				for( var i in deviceObject )
				{
					document.getElementById( 'editnumber_device' ).options[ document.getElementById( 'editnumber_device' ).options.length ] = new Option( deviceObject[ i ][ 'deviceName' ], deviceObject[ i ][ 'devicePK' ] );
				}
			}
			
			// 2008.02.28 KJD: Select the device
			SetItemValue( 'editnumber_device',		deviceObject[ value1 ][ 'devicePK' ] );
		}
		else
		{
			// 2008.03.22 KJD: 
			SetItemHTML( 'editnumber_devicetext',		deviceObject[ value1 ][ 'devicePK' ] );
			document.getElementById( 'editnumber_device' ).style.display = 'none';
			
			// 2008.04.28 KJD: Only 1 device, Hide the device list row
			document.getElementById( 'devicelist_row' ).style.display = 'none';
			
		}

		// 2008.02.28 KJD: Set the hidden selected device
		SetSelectedDevice( deviceObject[ value1 ][ 'devicePK' ] );
	}
	else if( thisarea == 'addnumber' )
	{
		// 2008.03.28 KJD: Make sure the Device is selected and that the Select # is visible
		CurrentDevice = value1;
		document.getElementById( 'addnumberlink' ).style.display	= "block";
	}
	else if( thisarea == 'DIDsearch' )
	{
		// 2008.03.28 KJD: Clear the DID search results on new load
		document.getElementById( 'available_numbers' ).style.display	= 'none';
		document.getElementById( 'rate_charge' ).style.display			= 'none';
	}
	
	else if( thisarea == 'prepaidcharges' )


	{


		// 2008.02.28 KJD: Populate the prepaid charges





		var ChargeObject	= chargeList;


		var itemCount		= 0;


		var thisString		= "";

		

		

		// 2008.02.28 KJD: set up each prepaid item


		for( var i in ChargeObject )


		{

			if(i % 2 == 0){
				thisString +="<tr class='odd'>";
			}else{
				thisString +="<tr class='even'>";
			}
			
			thisString += ""

				+ "<td>" + ChargeObject[ i ][ 'callednumber' ] 	+ "</td>"

				+ "<td>" + ChargeObject[ i ][ 'destination' ] + "</td>"

				+ "<td>" + ChargeObject[ i ][ 'callstarttime' ] 	+ "</td>"

				+ "<td>" + ChargeObject[ i ][ 'length' ] 		+ "</td>"

				+ "<td>" + ChargeObject[ i ][ 'unitprice' ] 	+ "¢</td>"

				+ "<td>$" + ChargeObject[ i ][ 'totalcost' ] 	+ "</td>"

				+ "</tr>";

		


			itemCount++; 


		}


		


		


		


		


		if( itemCount )


		{

			// TODO: GET HEADERS from XML

		

			thisString = ""

				+ "<table id='csstable'>" 

				+ "<tr>"

				

				+ "<TH>Called Number</TH>"

				+ "<TH>Destination</TH>"

				+ "<TH>Call Start Time</TH>"

				+ "<TH>Duration</TH>"

				+ "<TH>Rate</TH>"

				+ "<TH>Cost</TH>"

				

				+ "</tr>"

				+ thisString 

				+ "</table>";


			SetItemHTML( 'prepaid_chargeslist',		thisString );


		}


		else


		{


			// 2008.02.28 KJD: Change prepaid text


			SetItemHTML( 'prepaid_title',		document.getElementById( 'prepaid_heading_nocharge' ).innerHTML );


		}


		


		


		


	}
	else if( thisarea == 'addfunds' )
	{
		SetItemHTML( 'cardnumbers', creditcard_number );
	}


	


}





// 2008.02.28 KJD: Set the selected device


function SetSelectedDevice( thisvalue )


{


	SetItemValue( 'editnumber_deviceselected',	thisvalue );





	return false;


}








// 2008.02.21 KJD: Set values


function SetItemValue( itemID, itemValue )


{


	try


	{


		if( document.getElementById( itemID ) )


		{


			document.getElementById( itemID ).value = itemValue;


		}


	}


	catch( e ){}


}





// 2008.02.21 KJD: Set innerHTML


function SetItemHTML( itemID, itemValue )


{


	try


	{


		if( document.getElementById( itemID ) )


		{


			document.getElementById( itemID ).innerHTML = itemValue;


		}


	}


	catch( e ){}


}

// 2008.03.28 KJD: Added for wait message
function WaitWindow( thisAction, thiscalled, thisfunction ) 
{
	if		( thisAction == 'open'	){ thisAction = "block";	}
	else if	( thisAction == 'close'	){ thisAction = "none";		}
	
	if( typeof thiscalled != 'undefined' )
	{
		
		if( !( thiscalled ) )
		{
			document.getElementById( 'WaitWindow' ).style.display = thisAction;
		
			setTimeout( "" + thisfunction, 250 );
			functioncalled = 1;
			return false;
		}
		else
		{
			WaitWindow( 'close' );
			functioncalled =0;
			return true;
		}
	}
	else
	{
		document.getElementById( 'WaitWindow' ).style.display = thisAction;
	}
	
	return false;
}

/*-Shanthi : 06/08/08 /*
created Helpper class for populating select drop-down values from static array--*/
var SelectBoxHelper = {
	
	selectBoxId : '',
	selectBox: null,
	
	/*
    initialize the select box before you can use any of the other helper functionss
    */
	initSelect: function(id) {
		this.selectBoxId = id;
		this.selectBox = document.getElementById(this.selectBoxId);
	},
	
    
    /*
    addOption is a simple helper to add option elements to a select box
    */
    addOption: function(optiontext , optionValue) {
		
		if (this.selectBox != null) {
			var tempOpt = new Option(optiontext, optionValue);
			this.selectBox.options.add(tempOpt);
		}
    },
	
	/*
    addOptions is a helper that calls addOption for each array element that is passed in
	Expects an object with two attributes { text , value}
    */
	addOptions: function(arr) {
		for (var i=0; i< arr.length; i++) {
			var arrElem = arr[i];
			if (arrElem != null && arrElem.text != 'undefined' && arrElem.value != 'undefined')	
				this.addOption(arrElem.text , arrElem.value); 
		}
	},
	
	/*
    iterates over the options and then sets the option as selected based on the option value that has been passed in
    */
	selectOption: function(optionValue) {
		
		if (this.selectBox == 'undefined' || this.selectBox == null)
			return;
			
		for (var i=0; i< this.selectBox.options.length; i++) {
			if (optionValue == this.selectBox.options[i].value) {
				this.selectBox.options[i].selected = true;
				break;
			}
		}
	}
};

/*--Shanthi: to identify which popin to open from any of the given login links --*/
var PopinEditLoginContext = {
	context : null,
	setContext : function(str) {
		context = str;
	},
	getContext : function() {
		return context;
	},
	setLoginContext:function() {
		this.setContext('logininfo');
	},
	setPasswordContext:function() {
		this.setContext('password');
	},
	setSecurityContext:function() {
		this.setContext('security');
	},
	isLoginContext:function() {
		return (this.getContext() == 'logininfo');
	},
	isPasswordContext:function() {
		return (this.getContext() == 'password');
	},
	isSecurityContext:function() {
		return (this.getContext() == 'security');
	}
	
}

function PopinSetLoginContext() 
{
	PopinEditLoginContext.setLoginContext();
}

function PopinSetPasswordContext() 
{
	PopinEditLoginContext.setPasswordContext();
}

function PopinSetSecurityContext()
{
	PopinEditLoginContext.setSecurityContext();
}

// 2008.07.15 KJD: Added to convert string to images
function PhoneKeyImages( thisString )
{
	var thisImages	= "";
	var stringArray	= thisString.split('');
	
	
	for( var i = 0; i < stringArray.length; i++ )
	{
		thisImages	+= PhoneKeyImage( stringArray[ i ] );
	}
	
	return thisImages;
}

function PhoneKeyImage( thisCharacter )
{
	var thisString	= "";
	
	if( thisCharacter )
	{
		thisCharacter	= thisCharacter.replace( "*", "asterisk" );
		thisString		= "<img src='/content/en/us/images/phonekeys/" + thisCharacter + ".gif' border='0'>";
	}
	
	return thisString;
}
