

document.onclick = TrackMouseLocation;

var thisMouseX = 0;
var thisMouseY = 0;


// 2007.08.31 KJD: 
var Currency_Items = new Array();


// 2007.08.30 KJD: Track mouse location
function TrackMouseLocation( event )
{
	// 2007.09.26 KJD: Set x,y as vars
	var xDiff = -35;
	var yDiff = -150;


	if( ( typeof event == 'undefined' ) )
	{
		// 2007.09.06 KJD: For IE
		var thisevent = window.event; 
		
		thisMouseX = thisevent.clientX + xDiff;
		thisMouseY = thisevent.clientY + yDiff;
		
	}
	else
	{
		thisMouseX = event.clientX + xDiff;
		thisMouseY = event.clientY + yDiff;
	}
}

// 2007.08.30 KJD: show change
function ShowChangeCurrency( divName )
{
	
	document.getElementById( 'Norton_CurrencySelector_Buttons' ).innerHTML = Currency_PopulateDiv( divName );

	SetLocationNorton_CurrencyDiv();
	SetVisibilityNorton_CurrencyDiv( "visible" );
}

// 2007.08.30 KJD: Hide box
function HideChangeCurrency()
{
	SetVisibilityNorton_CurrencyDiv( "hidden" );

}

// 2007.08.30 KJD: get the div
function Norton_CurrencyDiv()
{
	return document.getElementById( 'Norton_CurrencySelector' );
}

// 2007.08.30 KJD: set the visibility
function SetVisibilityNorton_CurrencyDiv( thisStyle )
{
	var thisDivBox = Norton_CurrencyDiv();
	thisDivBox.style.visibility = thisStyle;
}

// 2007.08.30 KJD: set the location
function SetLocationNorton_CurrencyDiv()
{
	var thisDivBox = Norton_CurrencyDiv();
	thisDivBox.style.left = thisMouseX + "px";
	thisDivBox.style.top = thisMouseY + "px";
}

// 2007.08.30 KJD: select a currency
function Norton_CurrencySelect( divName, thisValue )
{
	Norton_CurrencySetPrice( divName, thisValue );
	
	Currency_SetCookie( thisValue );
	
	HideChangeCurrency();
}

// 2007.08.31 KJD: Set the price
function Norton_CurrencySetPrice( divName, thisValue )
{
	// 2007.08.31 KJD: Change price for all items
	for( var i in Currency_Items )
	{
		try
		{
			if( Currency_Items[ i ][ thisValue ][ 'priceText' ] )
			{
				if( document.getElementById( i ) )
				{
					document.getElementById( i ).innerHTML = Currency_Items[ i ][ thisValue ][ 'priceText' ];
				}
				if( document.getElementById( i + 'url' ) )
				{
					document.getElementById( i + 'url' ).href = Currency_Items[ i ][ thisValue ][ 'buyURL' ];
				}
			}
		} catch (e) {}
	}
}





// 2007.08.14 KJD: Create curve
// 2007.08.31 KJD: Updated to include border
function Norton_CreateCurveTest( thisID, thisSection, thisColor, borderColor )
{
	if( !( borderColor ) )
	{
		borderColor = thisColor;
	}

	var thisString = ""
		+ "<STYLE>"
		+ ".curve_" + thisID + "_top, .curve_" + thisID + "_bottom {display:block; background:transparent;}"
		+ "	.curve_" + thisID + "_Bdygs1, .curve_" + thisID + "_Bdygs2, .curve_" + thisID + "_Bdygs3, .curve_" + thisID + "_Bdygs4 {display:block; overflow:hidden}"
		+ "	.curve_" + thisID + "_Bdygs1, .curve_" + thisID + "_Bdygs2, .curve_" + thisID + "_Bdygs3 {height:1px}"
		+ "	.curve_" + thisID + "_Bdygs2, .curve_" + thisID + "_Bdygs3, .curve_" + thisID + "_Bdygs4 {background:" + thisColor + "; border:1px solid " + borderColor + "; border-width:0 1px}"
		+ "	.curve_" + thisID + "_Bdygs1 {margin:0 5px; background:" + thisColor + ";border-bottom:solid " + borderColor + " 1px;}"
		+ "	.curve_" + thisID + "_Bdygs2 {margin:0 3px; border-width:0 2px}"
		+ "	.curve_" + thisID + "_Bdygs3 {margin:0 2px;}"
		+ "	.curve_" + thisID + "_Bdygs4 {height:2px; margin:0 1px}"
		+ "</STYLE>";
		
	if( thisSection == 'top' )
	{
		thisString += ""
			+ "	<div class='curve_" + thisID + "_" + thisSection + "'>"
			+ "		<div class='curve_" + thisID + "_Bdygs1'><b></b></div>"
			+ "		<div class='curve_" + thisID + "_Bdygs2'></div>"
			+ "		<div class='curve_" + thisID + "_Bdygs3'><b></b></div>"
			+ "		<div class='curve_" + thisID + "_Bdygs4'><b></b></div>"
			+ "	</div>";
	}
	else
	{
		thisString += ""
			+ "	<div class='curve_" + thisID + "_" + thisSection + "'>"
			+ "		<div class='curve_" + thisID + "_Bdygs4'><b></b></div>"
			+ "		<div class='curve_" + thisID + "_Bdygs3'></div>"
			+ "		<div class='curve_" + thisID + "_Bdygs2'><b></b></div>"
			+ "		<div class='curve_" + thisID + "_Bdygs1'><b></b></div>"
			+ "	</div>";
	}
		
	return thisString;
}


// 2007.08.31 KJD: Add Item
function Currency_ItemPrice( priceDiv, priceText, priceCode, priceDesc, buyURL )
{
	Currency_AddDiv( priceDiv, priceText, priceCode, priceDesc, buyURL );
	
	
}

// 2007.08.31 KJD: Add the div name to the currency array
function Currency_AddDiv( divName, priceText, priceCode, priceDesc, buyURL )
{
	if (divName == 'thisPrice3a' || divName=='thisPrice3b') {
		//alert('adding to ' + divName);
	}
	var doAdd = 1;
	
	for( var i in Currency_Items )
	{
		if( i == divName )
		{
			doAdd = 0;
			Currency_Items[ i ][ 'count' ]++;
			
			// 2007.08.31 KJD: Add the currency info
			Currency_Items[ i ][ priceCode ]				= new Array();
			Currency_Items[ i ][ priceCode ][ 'priceText' ]	= priceText;
			Currency_Items[ i ][ priceCode ][ 'priceDesc' ]	= priceDesc;
			Currency_Items[ i ][ priceCode ][ 'buyURL' ]	= buyURL;
		}
	}
	
	
	if( doAdd )
	{
		Currency_Items[ divName ]				= new Array();
		Currency_Items[ divName ]['count']		= 1;
		Currency_Items[ divName ]['default']	= priceCode;

		Currency_Items[ divName ][ priceCode ]					= new Array();
		Currency_Items[ divName ][ priceCode ][ 'priceText' ] 	= priceText;
		Currency_Items[ divName ][ priceCode ][ 'priceDesc' ] 	= priceDesc;
		Currency_Items[ divName ][ priceCode ][ 'buyURL' ] 	= buyURL;
	}
	
	if (divName == 'thisPrice3a') {
	//alert( 'added: ' + priceCode + " for " + divName + " = " + Currency_Items[ divName ][ priceCode ][ 'priceText' ] );
	}
	// alert( 'added: ' + priceCode + " for " + divName + " = " + Currency_Items[ divName ][ priceCode ][ 'priceText' ] );
}

// 2007.08.31 KJD: Check to show Change Currency link
function Currency_Link( divName )
{
	var thisString = "";
	
	// 2007.08.31 KJD: Check value
	
	// 2007.09.26 KJD: Check for value too
	try
	{
		if( Currency_Items[ divName ]['count'] > 1 )
		{
			thisString = "<a href=\"javascript:ShowChangeCurrency( '" + divName + "' )\">" + ChangeCurrencyText + "</a>";
		}
	}
	catch( e ){}
	
	document.getElementById( divName ).innerHTML = Currency_DisplayPrice( divName );
	document.getElementById( divName + 'url' ).href = Currency_DisplayBuyURL( divName );

	
	return thisString;
}

// 2007.08.31 KJD: Populate the div with the array info
function Currency_PopulateDiv( divName )
{
	// 2007.08.31 KJD: Get the default type
	var currencydefault = Currency_Default( divName );
	var thisChecked		= "";
	var thisString 		= "";
	
	for( var i in Currency_Items[ divName ] )
	{
		if( ( i !== 'count' ) && ( i !== 'default' ) && (i !== 'cxUnique' ) && (i !== 'indexOf' ) )
		{
		
			thisChecked = "";
			if( i == currencydefault )
			{
				thisChecked = " CHECKED";
			}
		
			thisString += "<br>"
				+ "<INPUT TYPE='RADIO' NAME='norton_currency' VALUE='" + i + "' ID='norton_currency" + i + "' onClick=\"Norton_CurrencySelect( '" + divName + "', this.value )\"" + thisChecked + ">"
				+ "<LABEL for='norton_currency" + i + "'>" 
				+ Currency_Items[ divName ][ i ][ 'priceDesc' ] 
				+ "</LABEL>";
		}
	}

	return thisString;
}


// 2007.08.31 KJD: Set the currency cookie
function Currency_SetCookie( thisValue )
{
	Currency_createCookie( 'NortonCurrency', thisValue, 30 );
}



// 2007.08.31 KJD: Create the cookie
function Currency_createCookie( name, value, days )
{
	if( days )
	{
		var date = new Date();
		date.setTime( date.getTime() + ( days * 24 * 60 * 60 * 1000 ) );
		var Currency_expires = "; expires=" + date.toGMTString();
	}
	else
	{
		var Currency_expires = "";
	}
	
	document.cookie = name + "=" + value + Currency_expires + "; path=/";
}

// 2007.08.31 KJD: Read the cookie
function Currency_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;
}

// 2007.08.31 KJD: Clear the cookie
function Currency_eraseCookie(name)
{
	Currency_createCookie(name,"",-1);
}


// 2007.08.31 KJD: Show default price
function Currency_DisplayPrice( divName )
{
	thisString			= "";
	

	// 2007.09.26 KJD: Check if the string exists, if not, show default
	try
	{
		var currencytype	= Currency_Default( divName );
		thisString 			= Currency_Items[ divName ][ currencytype ][ 'priceText' ];
	}
	catch( e )
	{
		try
		{
			var currencytype	= Currency_Items[ divName ]['default'];
			thisString			= Currency_Items[ divName ][ currencytype ][ 'priceText' ];
		}
		catch( e ){}
	}

	 //alert( 'divName' + divName + ": " + thisString );
	return thisString;
}

// 2010.06.15 AKD: Show default price
function Currency_DisplayBuyURL( divName )
{
	thisString			= "";
	

	// 2007.09.26 KJD: Check if the string exists, if not, show default
	try
	{
		var currencytype	= Currency_Default( divName );
		thisString 			= Currency_Items[ divName ][ currencytype ][ 'buyURL' ];
	}
	catch( e )
	{
		try
		{
			var currencytype	= Currency_Items[ divName ]['default'];
			thisString			= Currency_Items[ divName ][ currencytype ][ 'buyURL' ];
		}
		catch( e ){}
	}

	// alert( 'divName' + divName + ": " + thisString );
	return thisString;
}

// 2007.08.31 KJD: Get the Default currency
function Currency_Default( divName )
{
	var currencytype	= "";
	
	// 2007.08.31 KJD: Check for cookie
	var cookievalue = Currency_readCookie( 'NortonCurrency' );
	if( cookievalue )
	{
		currencytype = cookievalue;
	}
	else
	{
		currencytype = Currency_Items[ divName ]['default'];
	}	
	
	// 2007.09.06 KJD: Check if currency exists
	if( Currency_Exists( currencytype ) )
	{
		return currencytype;
	}
	else
	{
		return  Currency_Items[ divName ]['default'];
	}
}

// 2007.09.06 KJD: Check if that currency exists
function Currency_Exists( currencytype )
{
	for( var thisDiv in Currency_Items )
	{
		for( var thisType in Currency_Items[ thisDiv ] )
		{
			if( ( thisType != 'count' ) && ( thisType != 'default' ) && ( thisType == currencytype ) )
			{
				return true;
			}
		}
	}

	return false;
}

// 2010.07.29 ALI: Display MSRP on NLP
function Display_MSRP(div, price) {
	$('#' + div).html(price);
}



