/*
	--------------------------------------------------------------------------
	LICENSE:
		CHERISHED PIECES IS LICENSED TO USE THIS FILE ON THEIR WEBSITE
		(www.cherishedpieces.ca).
		
	DISCLAIMER:
		THE CODE IN THIS FILE IS AN INTELLECTUAL PROPERTY OF ALLIANCE 
		INTERACTIVE (http://www.allianceinteractive.ca/). YOU CANNOT USE
		THIS CODE ANYWHERE ELSE WITHOUT EXPLICIT PERMISSION FROM ALLIANCE
		INTERACTIVE. ANY UNAUTHORIZED DISTRIBUTION OR USE OF THIS CODE WILL
		BE PROSECUTED.
	--------------------------------------------------------------------------
*/



function showPic(url, width, height, name)
{
	var new_name = html_entity_decode(name);
	var new_width = width+32;
	var new_height = height+96;
	var win		= window.open('','_blank','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width='+(new_width)+', height='+(new_height));
	win.resizeTo(new_width,new_height);
	win.focus();
	win.document.write("<html><head></head><body onblur='window.close();' onload='window.focus();' style='margin: 0px; text-align: center;'><img src='"+url+"' alt='"+new_name+"' title='"+new_name+"' width='"+(width)+"' height='"+(height)+"' /></body></html>");
	win.document.close();
}

function html_entity_decode( string ) {
    // http://kevin.vanzonneveld.net
    // +   original by: john (http://www.jd-tech.net)
    // +      input by: ger
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: html_entity_decode('Kevin &amp; van Zonneveld');
    // *     returns 1: 'Kevin & van Zonneveld'
 
    var ret, tarea = document.createElement('textarea');
    tarea.innerHTML = string;
    ret = tarea.value;
    return ret;
}
function deleteItem(id)
{
	var answer	= confirm('Are you sure you want to delete this item?');
	if( answer )
	{
		var fld		= document.getElementById('id');
		fld.value	= id;
		fld.form.submit();
	}
}

function viewCart()
{
	document.getElementById('paypal').submit();
}

function showOrderForm()
{
	div	= document.getElementById('order_form_div');
	but	= document.getElementById('show_order_form');
	
	div.style.display	= 'inline';
	but.style.display	= 'none';
	return true;
}

function copyBillingAddress()
{
	var ary		= new Array('address','address2','city','province','country','pcode');
	for( i=0; i < ary.length; i++ )
	{
		id	= ary[i];
		b	= document.getElementById('order[b_'+id+']');
		s	= document.getElementById('order[s_'+id+']');
		if( b && s )
			s.value	= b.value;		
	}
}

function fillAllPrices(item_ids, prefix)
{
	var ids = new Array;
		
	ids = item_ids.split(',');
	for(var i=0; i < ids.length; i++)
	{
		if(document.getElementById(prefix+'['+ids[i]+']').value != '' && document.getElementById('all_prices').value != '')
		{
			if(document.getElementById('change_price_by').value == 'percent')
				document.getElementById(prefix+'['+ids[i]+']').value = document.getElementById(prefix+'['+ids[i]+']').value * ((document.getElementById('all_prices').value/100) + 1) ;
			if(document.getElementById('change_price_by').value == 'value')
				document.getElementById(prefix+'['+ids[i]+']').value = (document.getElementById(prefix+'['+ids[i]+']').value * 1) + (document.getElementById('all_prices').value * 1 ) ;
		
		}
	}

}