//version 1.0 beta
//created 5/17/2006
//wrightstrategies

var ns = (navigator.appName.indexOf('Netscape')>-1);
var ie = (navigator.appName.indexOf('Microsoft Internet Explorer')>-1);
//***************************************************

function close_quick_look_entry_button()
{	
	var div_quick_view = document.getElementById("div_quick_view")
	div_quick_view.style.visibility = 'hidden';
	
	var qv_attributes = document.getElementById('qv_attributes');
	qv_attributes.style.visibility = 'hidden';
}

function populate_quick_look(event, name, description, image, price, attributes, url)
{
	var qv_name = document.getElementById('qv_name');	

	if( qv_name.value != name )
	{	
		var calling_controlID, calling_control;
		var height_of_ctrl;	

		
		//***************************************************************************************
		//build item quick look
		var qv_price = document.getElementById('qv_price');
		var qv_quantity = document.getElementById('qv_quantity');
		var qv_image = document.getElementById('qv_image');
		var qv_url = document.getElementById('qv_url');
		var qv_description = document.getElementById('qv_description');
		var qv_attributes = document.getElementById('qv_attributes');
		var ddl_attributes = document.getElementById('ddl_attributes');
		var dv_attribute_name = document.getElementById('dv_attribute_name');	
		
		qv_quantity.value = ''
		qv_name.innerHTML = name
		qv_price.innerHTML = formatCurrency(price)
		qv_image.src = image
		qv_description.innerHTML = description
		qv_url.value = url
		
		if( attributes != '' ) 
		{
			qv_attributes.style.visibility = 'visible';
			
			var attribute_values = attributes.split("$")
			dv_attribute_name.innerHTML = attribute_values[0]
							
			var x
			
			for( x = 0 ; x < ddl_attributes.length; x += 1)
			{
				ddl_attributes.options[x] = null;
			}
			
			for( x = 1; x < attribute_values.length - 1; x += 2)
			{
				ddl_attributes.options[Math.floor(x/2)] = new Option(attribute_values[x],attribute_values[x + 1])
			}				
		}
		else
		{
			qv_attributes.style.visibility = 'hidden';
		}	
	
		//***************************************************************************************
		
		if ( ns )
		{		
			calling_controlID = event.target.id;
			calling_control = document.getElementById(calling_controlID);		
			height_of_ctrl = event.target.offsetHeight;
		}
		else
		{		
			calling_controlID = event.srcElement.id;		
			calling_control = document.getElementById(calling_controlID);
			height_of_ctrl = event.srcElement.offsetHeight;
		}
		
		//***************************************************************************************

		var div_quick_view = document.getElementById("div_quick_view")

		div_quick_view.style.visibility = 'visible';
		div_quick_view.style.left = findPosX(calling_control) + 30 + 'px';
		
		if ( ns )
		{

			//div_quick_view.style.top = ( findPosY(calling_control) + ( calling_control.scrollHeight /2 )   ) - div_quick_view.offsetHeight - 20 + 'px';
			div_quick_view.style.top = findPosY(calling_control) -  div_quick_view.offsetHeight  + 'px';
		
		}
		else
		{
		
			//div_quick_view.style.top = ( findPosY(calling_control)  + ( calling_control.scrollHeight  /2 )  ) - div_quick_view.scrollHeight + 'px';
			div_quick_view.style.top = findPosY(calling_control) - div_quick_view.scrollHeight + 15;
			
		}
	
		//*************************
		//determine which close button to show
		var btn_close_left = document.getElementById('btn_close_left');
		var btn_close_right = document.getElementById('btn_close_right');
		
		if ( ns )
		{
			if ( window.innerWidth < ( parseInt(findPosX(calling_control)) + 30 + parseInt(div_quick_view.clientWidth)) )
			{
				div_quick_view.style.left = window.innerWidth - parseInt(div_quick_view.clientWidth) - 30 + 'px';
			}
		}
		else
		{		
			if ( document.body.clientWidth < ( parseInt(findPosX(calling_control)) + 30 + parseInt(div_quick_view.clientWidth)) )
			{			
				div_quick_view.style.left = document.body.clientWidth - parseInt(div_quick_view.clientWidth);
			}
		}		
		
		/*
		if ( document.body.clientWidth < ( parseInt(findPosX(calling_control)) + 30 + parseInt(div_quick_view.clientWidth)) )
		{
			btn_close_left.style.display = "inline"
			btn_close_right.style.display = "none"
		}
		else
		{
			btn_close_left.style.display = "none"
			btn_close_right.style.display = "inline"
		}				
		*/
	}
}

function add_to_cart()
{
	var qv_url = document.getElementById('qv_url');
	var qv_quantity = document.getElementById('qv_quantity');
	var dv_attribute_name = document.getElementById('dv_attribute_name');
	var ddl_attributes = document.getElementById('ddl_attributes');

	if ( qv_quantity.value == '' ) 
	{
		alert("Quantity is required.")
	}
	else
	{
		if ( dv_attribute_name.innerHTML != '' )
		{
			
			window.location.href = ddl_attributes[ddl_attributes.selectedIndex].value + qv_quantity.value
		
		}
		else
		{
			
			window.location.href = qv_url.value + qv_quantity.value
			
		}
	}
}

//found at http://www.quirksmode.org/js/ *********************
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;	
	
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			obj = obj.offsetParent;
			curtop += obj.offsetTop		
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
//**************************************************************
//Original:  Cyanide_7 (leo7278@hotmail.com)
// Web Site:  http://www7.ewebcity.com/cyanide7 

// This script and many more are available free online at 
// The JavaScript Source!! http://javascript.internet.com 
function formatCurrency(num) {
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);
}

