//
// home.js
//

// -------------------------------------------------------------
// cross-browser helper functions
// -------------------------------------------------------------

// Global variables
var m_search = "";
var m_localeSelector = "";
var isCSS 			= false;
var isW3C 			= false;
var isIE4 			= false;
var isNN4 			= false;
var isIE6 			= false;
var isGecko 		= false;
var isOpera 		= false;
var isDHTML 		= false;
var suppressMenus	= false;
var legacyMode		= false;
var timerID			= null;
var subtimerID		= null;

// initialize upon load to let all browsers establish content objects
function autoconfig()
{
    if(document && document.images)
    {
        isCSS		= (document.body && document.body.style) ? true : false;
        isW3C		= (isCSS && document.getElementById) ? true : false;
        isIE4		= (isCSS && document.all && readIEVer() >= 4.0) ? true : false;
        isNN4		= (document.layers) ? true : false;
        isGecko		= (isCSS && navigator && navigator.product && navigator.product == "Gecko");
        isOpera		= (isCSS && navigator.userAgent.indexOf( "Opera") != -1 );
		isIE6CSS	= (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
		isIE6		= ( isIE6CSS && readIEVer() >= 6.0 );
        isDHTML		= isCSS && ( isIE4 || isGecko || isOpera );
        
        if( suppressMenus || ( isOpera && readOperaVer() < 7 ) || ( isGecko && navigator.productSub <= 20011022 ) || ( isGecko && navigator.productSub == 20030107 ) )
        {
			isDHTML	= false;
        }
        
    }
    
    
}
function readIEVer()
{
	var agent	= navigator.userAgent;
	var offset	= agent.indexOf( "MSIE" );
	if( offset < 0 )
	{
		return 0;
	}
	return parseFloat( agent.substring( offset + 5, agent.indexOf( ";", offset ) ) );
}






function writeMH( phoneTitle, phoneMsg, phoneTariff, segmentTitle, hasLocale, logoLink, pnmsg )
{	autoconfig();}

//
// montage.js
//

var monBlock	= null;
var monImg		= null;
var monIdx		= 0;
var monContainer= null;
var monTimeout	= 7000;

function montage( href, src, caption, width, animate )
{
	// this is the case for browsers that don't support filters...
	var cycle	= Math.floor( Math.random() * href.length );

	// switch off animation if we're not on broadband
	var m_montage	= ( typeof(animate) != "undefined" ? animate : hasBroadband() );
	
	if( m_montage == false || src.length <= 1 || !( isIE4 || isW3C ) )
	{
		montagePicker( href, src, caption, cycle );
		return;
	}
	
	// go build all of the nested DIVs out
	monIdx		= cycle;

	document.writeln( "<div id=\"container\" style=\"width:" + width +"px;height:149px\">" );

	for( i = 0; i < src.length; i++ )
	{
		// set up a placeholder
		document.writeln( "\t<div id=\"montage" + i + "\" style=\"display:none\">" );
		
		montagePicker( href, src, caption, i );

		document.writeln( "\t</div>" );
	}

	document.writeln( "</div>" );

	// pull the images out
	monBlock	= new Array( src.length );
	monImg		= new Array( src.length );

	for( i = 0; i < src.length; i++ )
	{
		monBlock[i]	= document.getElementById( "montage" + i ).style;
		monImg[i]	= document.getElementById( "monimg" + i );
		
		if( monImg[i] == null )
		{
			montagePicker( href, src, caption, i );
			return;
		}
	//	alert( "foo" );
	}

	monContainer = document.getElementById("container");
	
	montageEffects();
}

function montageEffects()
{
	var nextImage	= (monIdx + 1) % monImg.length;
	
	// run the transition
	if( readIEVer() >= 4.0 )
	{
		monContainer.style.filter = "blendTrans(duration=1.5) revealTrans(duration=1.0,transition=7)";
	
		monContainer.filters(0).apply();
		monContainer.filters(1).apply();
		
 		montageSelect( nextImage );
		
		monContainer.filters(0).play();
		monContainer.filters(1).play();
	}
	else
	{
		montageSelect( nextImage );
	}

	// asked to be called again a little later
	setTimeout( "montageSwap()", monTimeout );
}

function montageSelect( nextImage )
{
	//alert( monImg[monIdx].style.visibility );
	monBlock[monIdx].display = "none";
	monIdx = nextImage;
	monBlock[monIdx].display = "block";
}		

function montageSwap()
{
	if( monImg[monIdx].complete )
	{
		// move the image index along
		montageEffects();
	}
	else
	{
		// check again 3 seconds later
		setTimeout( "montageSwap()", 3000 );
	}
}

function montagePicker( href, src, caption, cycle )
{
	if( href[cycle] != null ) 
	{
		document.writeln( "\t\t<A HREF=\"" + href[cycle] + "\"><IMG SRC=\"" + src[cycle] + "\" alt=\"" + caption[cycle] + "\" BORDER=\"0\" ID=\"monimg" + cycle + "\"></a>" );
	}
	else
	{
		document.writeln( "\t\t<IMG SRC=\"" + src[cycle] + "\" ID=\"monimg" + cycle + "\">" );
	}
}

function hasBroadband()
{
	if( readIEVer() < 5.0 )
	{
		return false;
	}
	
	try
	{
		document.body.addBehavior ("#default#clientCaps");
	
		return ( typeof(document.body.connectionType) != "undefined" && document.body.connectionType == "lan" );
	}
	catch( e )
	{
		return false;
	}
}
function btnOver(imgName)
{
	if (document.images) {
		if (document.images[imgName].src != eval(imgName + "_in.src")) {
			document.images[imgName].src = eval(imgName + "_on.src");
		}
	}
}
function btnOut(imgName, blnForce)
{
	if (document.images) {
		if ((document.images[imgName].src != eval(imgName + "_in.src")) || (blnForce)) {
			document.images[imgName].src = eval(imgName + "_off.src");
		}
	}
}
// -------------------------------------------------------------
// 
// -------------------------------------------------------------
// start customer to ship form
<!-- Begin
var ShipFirst = "";
var ShipLast = "";
var ShipCompany = "";
var ShipAddress = "";
var ShipCity = "";
var ShipState = "";
var ShipZip = "";
var Shipcountry = "";


function InitSaveVariables(form) {
ShipFirst = form.strfirstname.value;
ShipLast = form.strLastname.value;
ShipCompany = form.strCompany.value;
ShipAddress = form.strAddress.value;
ShipCity = form.strCity.value;
ShipZip = form.StrPostcode.value;
ShipState = form.strState.value;
Shipcountry = form.strCountry.value;

}

function ShipToBillPerson(form) {
if (form.copy.checked) {
InitSaveVariables(form);
form.shipname.value = form.strfirstname.value + " " + form.strLastname.value;
form.shipcompany.value = form.strCompany.value;
form.shipaddress.value = form.strAddress.value;
form.shiptown.value = form.strCity.value;
form.shipstate.value = form.strState.value;
form.shipzip.value = form.StrPostcode.value;
form.shipcountry.value = form.strCountry.value;

}
else {
form.shipname.value = "";
form.shipcompany.value = "";
form.shipaddress.value = "";
form.shiptown.value = "";
form.shipzip.value = ""; 
form.shipstate.value = "";
form.shipcountry.value = "";
}
}
// End -->

function cs(obj,cls)
{
    obj.className = (cls)?cls:"";
}
function textchoice() {
	
}
function CheckChoice(whichbox,price)
	{
with (whichbox.form)
{
	if (whichbox.checked == false)
		{ hiddentotal.value = eval(hiddentotal.value) - eval(price); }
		//
	else 	{ hiddentotal.value = eval(hiddentotal.value) + eval(price);}
	if (hiddentotal.value < 0)
	{
		document.myform.total.value='$0.00';
		document.myform.hiddentotal.value=0;

		//Set all checkboxes and radio buttons on form-1 to unchecked:
		for (xx=0; xx < document.myform.elements.length; xx++)
		{
		   if (document.myform.elements[xx].type == 'checkbox')
			{
			document.myform.elements[xx].checked = false;
			}
		}
	}
		//Now, return with formatted total:
		
		return(formatCurrency(hiddentotal.value));
		
} 
}

	//Define function to format a value as currency:
	function formatCurrency(num)
	{
	   // Courtesy of http://www7.brinkster.com/cyanide7/
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
		   num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		if(cents<10)
		    cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		    num = num.substring(0,num.length-(4*i+3))+','+
		          num.substring(num.length-(4*i+3));
  	    return (((sign)?'':'-') + '$' + num + '.' + cents);
	}

	//Define function to init the form on reload:
	function InitForm()
		{
		//Reset the displayed total on form:
		document.myform.total.value='$0.00';
		document.myform.hiddentotal.value=0;

		//Set all checkboxes and radio buttons on form-1 to unchecked:
		for (xx=0; xx < document.myform.elements.length; xx++)
		{
		   if (document.myform.elements[xx].type == 'checkbox')
			{
			document.myform.elements[xx].checked = false;
			}
		}
	}

function Total() {
        var q, i, ordertotal, tax, sh, total;
       eval("total=document.myform.hiddentotal.value * document.myform.quantity.value;");
       eval("document.myform.total.value=formatCurrency(total)");
       document.myform.hiddentotal.value= formatCurrency(total);
}

//  End -->

