var viewportwidth;
var viewportheight;

//BROWSER HEIGHT (available height allowing for browser toolbars etc.)

function getBrowserSizes(){
	 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
		  viewportwidth = window.innerWidth,
		  viewportheight = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
		   viewportwidth = document.documentElement.clientWidth,
		   viewportheight = document.documentElement.clientHeight
	 }
	 
	 // older versions of IE
	 
	 else
	 {
		   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	
	//-->
	
}

// COMPLETES DELIVERY ADDRESS THE SAME AS STANDARD ADDRESS
function same_delivery() {
	
	if (document.getElementById('use_billing'))
	{
		
		// SPAN TO SHOW BUTTON WHICH AUTO-COMPLETES DELIVERY ADDRESS
		document.getElementById('use_billing').innerHTML	=	'<input type="checkbox" class="checkbox" name="same_address" id="same_address" value="Y" />';
		document.getElementById('use_billing').innerHTML	+=	'<label for="same_address">Please deliver to the billing address above</label>';
		
		var from_fields	=	new Array();
		var to_fields	=	new Array();
		
		from_fields[0]='first_name';
		from_fields[1]='surname';
		from_fields[2]='telephone_number';
		from_fields[3]='address_1';
		from_fields[4]='address_2';
		from_fields[5]='town';
		from_fields[6]='county';
		from_fields[7]='postcode';
		from_fields[8]='country';
		
		to_fields[0]='delivery_first_name';
		to_fields[1]='delivery_surname';
		to_fields[2]='delivery_telephone_number';
		to_fields[3]='delivery_address_1';
		to_fields[4]='delivery_address_2';
		to_fields[5]='delivery_town';
		to_fields[6]='delivery_county';
		to_fields[7]='delivery_postcode';
		to_fields[8]='delivery_country';
		
		var default_values=new Array();
		
		for (i=0;i<to_fields.length; i++)
		{
			field_id=to_fields[i];
			default_values[i]=document.getElementById(to_fields[i]).value;
		}
		
		// ACTION WHEN USER CLICKS BUTTON
		document.getElementById('same_address').onclick=function()
		{
			if (document.getElementById('same_address').checked==true) {
				for (i=0;i<from_fields.length;i++) {
					document.getElementById(to_fields[i]).value=document.getElementById(from_fields[i]).value;
				}
			}
			else {
				for (i=0;i<default_values.length;i++) {
					document.getElementById(to_fields[i]).value=default_values[i];
				}
			}
		}
	}
}


function changeDeliveryOption(val)
{
	window.location	=	"index.php?page=pages&url=basket&delivery_option_id="+val;	
}


// Image thumbnail select function
function select_thumb_image(title, large_path, xlarge_path) {
	
	element = document.getElementById('feature_product_image');
	if (!element || !large_path) { return; }
	
	img_str = '';
	
	img_str	+=	xlarge_path?'<a href="'+xlarge_path+'" class="thickbox">':'';
	
	img_str += '<img src="'+large_path+'" alt="'+title+'" />';
	
	img_str += xlarge_path?'</a>':'';
	
	element.innerHTML = img_str;
	
	// refresh thickbox as the dom has changed
	if (xlarge_path) { tb_init('a.thickbox'); }
}


/*	--------------------------------------------------------------------------  */
/*	--------------	JQUERY DOCUMENT READY RUNTIME PROCESSES  -----------------  */
/*	--------------------------------------------------------------------------  */


$(document).ready(function(){
	
	//COPY DELIVERY/BILLING DETAILS
	same_delivery();
	
});
