// JavaScript Document
function request_cv(ref,title,id)
{
	var in_shortlist = "FALSE";
	
	var shortlist = new Cookie(document, "shortlist", null, "/");
	shortlist.load();
	
	if(shortlist.counter)
	{
		var refs = unescape(shortlist.refs);
		var ref_array = refs.split(":");
		
		for(i=0;i<ref_array.length;i++)
		{
			if(ref_array[i] == ref)
				in_shortlist = "TRUE";
		}
	}
	
	if(in_shortlist == "FALSE")
	{
		if(!shortlist.counter)
			var counter = 0;
		else		
			var counter = shortlist.counter;
		if(!shortlist.refs)
			var refs = "";
		else
			var refs = unescape(shortlist.refs);
		if(!shortlist.titles)
			var titles = "";
		else
			var titles = unescape(shortlist.titles);
		if(!shortlist.ids)
			var ids = "";
		else
			var ids = unescape(shortlist.ids);
	
		if(counter < 10)
		{
			refs += ref += ':';
			titles += title += ':';
			ids += id += ':';
			counter++;
			shortlist.refs = escape(refs);
			shortlist.titles = escape(titles);
			shortlist.ids = escape(ids);
			shortlist.counter = counter;
			shortlist.store();
			window.document.cvs.cv_ids.value = ',' + replace(ids,':',',');
			window.document.cvs.current_cv.value = parseInt(id);
			window.document.cvs.submit();
		}
		else
			alert(error_cv_shortlist_max);
	}
	else
	{
		window.document.cvs.current_cv.value = parseInt(id);
		window.document.cvs.submit();
	}
}

function add_to_shortlist(title,id,quantity) 
{
	var shortlist = new Cookie(document, "shortlist", null, "/");
	shortlist.load();
	if(!shortlist.counter)
		var counter = 0;
	else		
		var counter = shortlist.counter;
	if(!shortlist.titles)
		var titles = "";
	else
		var titles = unescape(shortlist.titles);
	if(!shortlist.ids)
		var ids = "";
	else
		var ids = unescape(shortlist.ids);
	if(!shortlist.quantities)
		var quantities = "";
	else
		var quantities = unescape(shortlist.quantities);

	var a_ids = ids.split(":");
	
	var already_present = false;
	
	for(i=0;i<a_ids.length;i++)
	{
		if(a_ids[i] == id)
		{
			already_present = true;
		}
	}
	
	if(already_present == false)
	{
		titles += title += ':';
		ids += id += ':';
		quantities += quantity += ':';
		counter++;
		shortlist.titles = escape(titles);
		shortlist.ids = escape(ids);
		shortlist.quantities = escape(quantities);
		shortlist.counter = counter;
		shortlist.store();
		show_shortlist();
	}
}

function request_shortlist()
{
	if(window.document.cvs.cv_ids.value == ",")
		alert(error_no_cvs_in_shortlist);
	else
		window.document.profiles.submit();
}

function show_shortlist()
{
//	var temp_ids = "";
	var shortlist = new Cookie(document, "shortlist", null, "/");
	shortlist.load();
	
	if(shortlist.counter > 0)
	{
//		window.document.write('<table width="100%">');
		
		var titles = unescape(shortlist.titles);
		var ids = unescape(shortlist.ids);
		var quantities = unescape(shortlist.quantities);
		
		var title_array = titles.split(":");
		var id_array = ids.split(":");
		var quantity_array = quantities.split(":");
		
		var html = '<table width="100%" cellspacing="0" cellpadding="0">';
		
		for(i=0;i<shortlist.counter;i++)
		{
			html += '<tr bgcolor="#E8E0D9" height="25"><td class="listmenu"><a href="product_page.cfm?pc=' + id_array[i] + '" >' +  unescape(title_array[i]) + '</a></td><td width="11" class="listmenu" valign="middle"><a href="javascript:remove_from_shortlist(' + id_array[i] + ',0)"><img src="images/icon_delete2.gif" height="14" width="11" border="0" alt="Remove from list"></a></td></tr>';

/*			var title = "";
			if(title_array[i].length > 24)
			{
				title = title_array[i].substring(0,20) + '...';
			}
			else
			{
				title = title_array[i];
			}*/
//			window.document.write('<tr valign="top"><td width="10" valign="middle"><img src="images/bullet.gif" width="5" height="5"></td><td class="content-10px"><a href="product_detail.asp?id=' + id_array[i] + '">' + title_array[i] + '</a></td></tr>');
//			window.document.write('<td width="20" class="content-10px" align="right">- +</td></tr>');
		}
		//html += '<tr><td colspan="2" class="content-9px" height="5">&nbsp;</td></tr>';
		
		html += '<tr bgcolor="#E8E0D9" height="25"><td colspan="2"  align="right"><a href="wish_list1.cfm?nsl=1"><img src="images/but_small_view_wishlist.gif" height="15" width="113" border="0" alt="View Order List"></a>&nbsp;</td></tr>';
		html += '</table>';
//		window.document.write('<tr><td colspan="2" class="content-9px">&nbsp;</td></tr>');
//		window.document.write('<tr><td colspan="2" class="content-10px-bold" align="right"><a href="check_out.asp">Go to the checkout &gt;&gt;</a></td></tr>');
//		window.document.write('</table>');
//		window.document.write('<tr align="right" valign="bottom"><td colspan="2" align="right" height="25"><a href="javascript:window.document.cvs.submit()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'requestcvsbutton\',\'\',\'../images/button_request_cvs_hover.gif\',1)"><img name="requestcvsbutton" border="0" src="../images/button_request_cvs_off.gif" hspace="10"></a></td></tr>');
		shortlist_display.innerHTML = html;
	}
	else
	{
//		window.document.write('You have no items in your basket.');
		shortlist_display.innerHTML = '<table width="100%" cellpadding="0" cellspacing="0"><tr bgcolor="#E8E0D9" ><td><span class="listmenu"><FONT color="#CC0000">Your order list is empty.</font></span></td></tr></table>';
	}
/*	window.document.write('<form name="cvs" action="cv_request.cfm" method="post">');
	window.document.write('<input type="hidden" name="cv_ids" value=",');
	window.document.write(temp_ids);
	window.document.write('"><input type="hidden" name="current_cv" value="0"></form>');*/
}

/*function final_shortlist()
{
	var shortlist = new Cookie(document, "shortlist", null, "/");
	shortlist.load();

	var refs = unescape(shortlist.refs);
	var titles = unescape(shortlist.titles);
	var ids = unescape(shortlist.ids);
		
	var ref_array = refs.split(":");
	var title_array = titles.split(":");
	var id_array = ids.split(":");
	
	window.document.data.profiles.value="";
	
	window.document.write('<table>');
	
	for(i=0;i<shortlist.counter;i++)
	{
		window.document.write('<tr valign="middle"><td class="contentbody" width="80">');
		window.document.write(ref_array[i]);
		window.document.write('</td><td class="contentbody" width="*">');
		window.document.write(title_array[i]);
		window.document.write('</td><td class="contentbody" width="30" align="center"><input type="checkbox" name="profile_check" value="' + id_array[i] + '" checked></td></tr>')
		window.document.data.profiles.value += id_array[i] += ',';
	}
	
	window.document.write('</table>');
}*/

function remove_from_shortlist(id,list_type,form)
{
	if(confirm("Are you sure?"))
	{
		var n;
	
		var shortlist = new Cookie(document, "shortlist", null, "/");
		shortlist.load();
	
		var titles = unescape(shortlist.titles);
		var ids = unescape(shortlist.ids);
		var quantities = unescape(shortlist.quantities);

			
		var title_array = titles.split(":");
		var id_array = ids.split(":");
		var quantity_array = quantities.split(":");
		
		for(i=0;i<id_array.length;i++)
		{
			if(id_array[i] == id)
				n = i;
		}
		
		var size = id_array.length;
		
		for (j=n; j<size-1; j++)
		{
			if (j != size)
			{
				id_array[j] = id_array[j+1];
				title_array[j] = title_array[j+1];
				quantity_array[j] = quantity_array[j+1];
			}
		}
		id_array.length = size-1;
		title_array.length = size-1;
		quantity_array.length = size-1;
		
		size = id_array.length;
		
		ids = "";
		titles = "";
		quantities = "";
		
		for(i=0;i<size-1;i++)
		{
			ids += id_array[i] += ":";
			titles += title_array[i] += ":";
			quantities += quantity_array[i] += ":";
		}
		
//		prices = prices.replace((price_array[n] + ":"),"");
//		titles = titles.replace((title_array[n] + ":"),"");
//		ids = ids.replace((id_array[n] + ":"),"");
//		quantities = quantities.replace((quantity_array[n] + ":"),"");
//		weights = weights.replace((weight_array[n] + ":"),"");
		
		shortlist.titles = escape(titles);
		shortlist.ids = escape(ids);
		shortlist.quantities = escape(quantities);
		shortlist.counter--;
		shortlist.store();
	//	window.location = 'cv_search_results.cfm';
		
	//	show_shortlist();
		
		if(list_type == 1)
		{
			shortlist.titles = escape(titles);
			shortlist.ids = escape(ids);
			shortlist.quantities = escape(quantities);
			show_checkout_list(0,form);
		}
		else
			show_shortlist();
	}
}

function adjust_shortlist_quantity(id,count,type,form)
{
	var shortlist = new Cookie(document, "shortlist", null, "/");
	shortlist.load();

	var ids = unescape(shortlist.ids);
	var quantities = unescape(shortlist.quantities);
		
	var id_array = ids.split(":");
	var quantity_array = quantities.split(":");
	
	for(i=0;i<id_array.length;i++)
	{
		if(id_array[i] == id)
		{
			if(type == "+")
				quantity_array[i] = parseInt(quantity_array[i]) + count;
			else if(type == "-" && quantity_array[i] > 1)
				quantity_array[i] = quantity_array[i] - count;
		}
	}
	
	quantities = "";
	
	for(i=0;i<id_array.length;i++)
	{
		quantities += quantity_array[i] + ":";
	}
	
	shortlist.quantities = escape(quantities);
	shortlist.store();
	//document.wish_page.prod_quantities.value = escape(quantities);
	
//	show_shortlist();
	show_checkout_list(0,form);
}
//global variable add_array





function add_to_add_array(title,code,quantity)
{
	code = code + '';
	var j = add_array.length;
	add_array[j] = new Array(3);
	add_array[j][0] = title;
	add_array[j][1] = code;
	add_array[j][2] = quantity;
	//add_array[1][0] = code;
	//add_array[1][1] = quantity;
	//add_array[1][2] = title;
	//alert(add_array[j][0]);
	j = add_array.length;
	alert("added " + code + " " + j);
	
}

function delete_from_add_array(code,quantity,title)
{
		alert("delete "+code)
	for (var i = 1; i < add_array.length; i++){
		if (add_array[i][1] == code){
			alert("deleted "+code)
			delete add_array[i];
			var j = add_array.length;
			alert(j);
		}
	}
}

function add_array_to_shortist()
{
	for (var i = 0; i < add_array.length; i++){
		add_to_shortlist(add_array[i][2],add_array[i][0],add_array[i][1]);
		delete add_array[i];
	}
}

var counter = -1;
var add_array = new Array();

function create_add_array(value,divname,code,title,des)
{
	counter++;
	code = code + '';
	add_array[counter] = new Array(6);
	add_array[counter][0] = '<b>' + code + '</b> ' + title + ' ' + des;
	add_array[counter][1] = code;
	add_array[counter][2] = value;
	add_array[counter][3] = divname;
	add_array[counter][4] = des;
	add_array[counter][5] = counter;
	
	show_product(add_array[counter][2],add_array[counter][3],add_array[counter][1],add_array[counter][0],add_array[counter][4],counter);
}
function show_product(value,divname,code,title,des,counter)
{
	//counter++;
	var co;
	var div = divname.id;
	co = code + '';
	var quantity = value;
	var t = title;
	
	//add_array[counter] = new Array(6);
	//add_array[counter][0] = t;
	//add_array[counter][1] = co;
	//add_array[counter][2] = quantity;
	//add_array[counter][3] = div;
	//add_array[counter][4] = des;
	//add_array[counter][5] = counter;
	
	
	divname.innerHTML ='<table width="550" cellpadding="0" cellspacing="0"><tr><td width="20">&nbsp;</td><td width="260" valign="top"><span class="product-code-red"><b>' + co + '</b></span>&nbsp;&nbsp;<span class="product-info">' + des + '&nbsp;&nbsp;</span></td><td><span class="product-info">' +quantity + '&nbsp;&nbsp;&nbsp; <a href="javascript:decrease_product(\'' + co + '\',' + quantity + ',1,' + div + ',\'' + t +'\'' + ',\'' + des +'\',' + counter +')" onMouseOver="window.status=\'Decrease quantity\';return true" onMouseOut="window.status=\'\';return true"><img align="middle" src="images/icon_decrease.gif" height="10" width="11" border="0" alt="Decrease quantity"></a>&nbsp;&nbsp;&nbsp;<a href="javascript:increase_product(\'' + co + '\',' + quantity + ',1,' + div + ',\'' + t +'\'' + ',\'' + des +'\','+ counter +')" onMouseOver="window.status=\'Increase quantity\';return true" onMouseOut="window.status=\'\';return true"><img align="middle" src="images/icon_increase.gif" height="10" width="11" border="0" alt="Increase quantity"></a>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="c" </span></td></tr></table>';
}

function increase_product(code,quantity,amount,divname,title,des,count)
{
	
	var co = code + '';
	var div = divname;
	var quant = quantity + amount;
	add_array[count][2]=quantity + amount;
	//alert(count + ' ' + add_array[count][2]);
	show_product(quant,div,co,title,des,count);
}

function decrease_product(code,quantity,amount,divname,title,des,count)
{
	if (quantity != 1){
		code = code + '';
		var div = divname;
		var quant = quantity - amount;
		add_array[count][2]=quantity - amount;
		show_product(quant,div,code,title,des,count);
	}
}

function check_addbutton()
{
		var iproduct_code,jproduct_code;
		var aElements=document.forms[1].elements;
		for (var i = 0; i < aElements.length; i++){
			if (aElements[i].checked) {
				add_to_shortlist(add_array[i][0],add_array[i][1],add_array[i][2]);
			}
		}
}

function check_add(code,quantity,title,form)
{
		var c = code + '';
		var q = quantity;
		//var boxno = window.forms[1].c.length;
		var aElements=document.forms[1].elements;
		//alert(aElements.length);
		for (var i = 0; i < aElements.length; i++){
			if (aElements[i].checked) {
				add_to_add_array(title,c,quantity);	
			}
			else{
				delete_from_add_array(c,quantity,title);
			}
		}
}



function show_checkout_list(final,form)
{
	
	var final_list;
	
	if(final == 1)
	{
		final_list = true;
	}
	else
	{
		final_list = false;
	}

	if(final_list == true)
	{

		var titles = unescape(form.prod_titles.value);
		var ids = unescape(form.prod_ids.value);
		//var quantities = unescape(document.wish_page.prod_quantities.value);

	}
	else
	{
		var shortlist = new Cookie(document, "shortlist", null, "/");
		shortlist.load();

		var titles = unescape(shortlist.titles);
		var ids = unescape(shortlist.ids);

	}
	
//	var temp_ids = "";

	if(ids != "undefined" && ids.length > 0)
	{
//		window.document.write('<table width="100%">');
		
/*		var prices = unescape(shortlist.prices);
		var titles = unescape(shortlist.titles);
		var ids = unescape(shortlist.ids);
		
		var weights = unescape(shortlist.weights);*/
		var quantities = unescape(shortlist.quantities);
		var title_array = titles.split(":");
		var id_array = ids.split(":");
		var quantity_array = quantities.split(":");

		
		var html = '<table width="100%" border="0" cellpadding="2" cellspacing="0">';
		if(final_list == true)
		{
			html += '<tr><td colspan="3" class="content-9px"><hr></td></tr>';
		}

		html += '<tr>';
		html += '<td class="contentbody" width="70%"><b>Product Name</b></td>';
		html += '<td class="contentbody" align="center"><b>Quantity</b></td>';
		html += '<td class="contentbody" align="center" width="30"><b>&nbsp;</b></td>';
		html += '</tr>';
		html += '<tr><td colspan="3" class="content-10px" align="center">&nbsp;</td></tr>';
		var bg_colour = '#E8E0D9';
		
//		var packaging = 7.5;
		
		for(i=0;i<(id_array.length - 1);i++)
		{
			
			
			html += '<tr valign="top" bgcolor="' + bg_colour + '">';
			html += '<td class="contentbody" align="left">&nbsp;<a href="product_page.cfm?pc=' + id_array[i] + '" >' +  unescape(title_array[i]) + '</a></td>';
			html += '<td class="contentbody" align="center">' + quantity_array[i] + '</td>';
			

			if(final_list == true)
			{
				html += '<td class="contentbody" align="center">&nbsp;</td>';
				html += '<td class="contentbody" align="center">&nbsp;</td></tr>';				
			}
			else
			{

				html += '<td class="contentbody" align="center">&nbsp;</td><td valign="middle" align="right"><a href="javascript:adjust_shortlist_quantity(' + id_array[i] + ',1,\'-\',window.document.data)" onMouseOver="window.status=\'Decrease quantity\';return true" onMouseOut="window.status=\'\';return true"><img align="middle" src="images/icon_decrease.gif" height="10" width="11" border="0" alt="Decrease quantity"></a>&nbsp;&nbsp;<a href="javascript:adjust_shortlist_quantity(' + id_array[i] + ',1,\'+\',window.document.data)" onMouseOver="window.status=\'Increase quantity\';return true" onMouseOut="window.status=\'\';return true"><img align="middle" src="images/icon_increase.gif" height="10" width="11" border="0" alt="Increase quantity"></a>&nbsp;&nbsp;<a href="javascript:remove_from_shortlist(' + id_array[i] + ',1,window.document.data)" onMouseOver="window.status=\'Remove item from list\';return true" onMouseOut="window.status=\'\';return true"><img align="middle" src="images/icon_delete.gif" height="10" width="11" border="0" alt="Remove from list"></a></td></tr>';
			}
			
			if(bg_colour == '#E8E0D9')
			{
				bg_colour = '#FFFFFF';
			}
			else
			{
				bg_colour = '#E8E0D9';
			}
/*			var title = "";
			if(title_array[i].length > 24)
			{
				title = title_array[i].substring(0,20) + '...';
			}
			else
			{
				title = title_array[i];
			}*/
//			window.document.write('<tr valign="top"><td width="10" valign="middle"><img src="images/bullet.gif" width="5" height="5"></td><td class="content-10px"><a href="product_detail.asp?id=' + id_array[i] + '">' + title_array[i] + '</a></td></tr>');
//			window.document.write('<td width="20" class="content-10px" align="right">- +</td></tr>');
		}
		
		
		if(final_list == false)
		{
			//form.prod_quantities.value = shortlist.quantities;
			document.wish_page.prod_quantities.value = quantities;
			document.wish_page.wish_ids.value = shortlist.ids;
		}
		html += '</table><table width="100%" border="0" cellpadding="2" cellspacing="0"><tr><td class="content-10px" align="center">&nbsp;</td></tr>';
		html += '<tr><td class="content-10px" align="center">&nbsp;</td></tr>';		
		if(final_list == false)
		{
			html += '<tr><td colspan="7" class="content-10px-bold" align="right"><a href="javascript:window.history.back()" onMouseOver="window.status=\'Go back\';return true" onMouseOut="window.status=\'\';return true"><img src="images/button_back.gif" width="49" height="23" border="0" alt="Go Back"></a>&nbsp;';
			html += '<a href="javascript:cancel_order()" onmouseover="window.status=\'Clear Order List\'; return true" onmouseout="window.status=\'\'; return true"><img src="images/button_clear_wishlist.gif" width="136" height="23" border="0" alt="Clear Order List"></a>&nbsp;';
			html += '<input name="submit1" VALUE="Send Order List" type="image" src="images/button_send_wishlist.gif" width="128" height="23" border="0" alt="Send your Order list" onMouseOver="window.status=\'Send your Order list\';return true" onMouseOut="window.status=\'\';return true"></td></tr>';
		}
		html += '</table>';
//		window.document.write('<tr><td colspan="2" class="content-9px">&nbsp;</td></tr>');
//		window.document.write('<tr><td colspan="2" class="content-10px-bold" align="right"><a href="check_out.asp">Go to the checkout &gt;&gt;</a></td></tr>');
//		window.document.write('</table>');
//		window.document.write('<tr align="right" valign="bottom"><td colspan="2" align="right" height="25"><a href="javascript:window.document.cvs.submit()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'requestcvsbutton\',\'\',\'../images/button_request_cvs_hover.gif\',1)"><img name="requestcvsbutton" border="0" src="../images/button_request_cvs_off.gif" hspace="10"></a></td></tr>');
		checkout_list.innerHTML = html;
		
	}
	else
	{
//		window.document.write('You have no items in your basket.');
		checkout_list.innerHTML = '<p>&nbsp;</p><p><span class="contentbody">You have no items on your list.</span></p>';
	}
/*	window.document.write('<form name="cvs" action="cv_request.cfm" method="post">');
	window.document.write('<input type="hidden" name="cv_ids" value=",');
	window.document.write(temp_ids);
	window.document.write('"><input type="hidden" name="current_cv" value="0"></form>');*/
}

function check_shortlist_button(price,title,id,quantity)
{
	var in_shortlist = false;

	var shortlist = new Cookie(document, "shortlist", null, "/");
	shortlist.load();
	
	if(shortlist.counter)
	{
		var ids = unescape(shortlist.ids);
		var id_array = ids.split(":");
		
		for(i=0;i<id_array.length;i++)
		{
			if(id_array[i] == id)
				in_shortlist = true;
		}
	}
	if(in_shortlist == true)
		window.document.write('<p><a href="javascript:add_to_shortlist(\'' & price & '\',\'' & title & '\',' & id & ',' & quantity & ')"><img src="images/button_add_to_basket.gif" width="130" height="26" border="0"></a></p>');
	else
		window.document.write('<p>Already in shortlist</p>');
}

function pick_shortlist_button(ref,title,id)
{
	var in_shortlist = "FALSE";
	
	var shortlist = new Cookie(document, "shortlist", null, "/");
	shortlist.load();
	
	if(shortlist.counter)
	{
		var refs = unescape(shortlist.refs);
		var ref_array = refs.split(":");
		
		for(i=0;i<ref_array.length;i++)
		{
			if(ref_array[i] == ref)
				in_shortlist = "TRUE";
		}
	}
	
	if(in_shortlist == "FALSE")
		window.document.write('<a href="javascript:add_to_shortlist(\'' + ref + '\',\'' + title + '\',\'' + id + '\')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'addshortlistbutton\',\'\',\'../images/button_add_shortlist_hover.gif\',1)"><img name="addshortlistbutton" border="0" src="../images/button_add_shortlist_off.gif"></a>');
		//window.document.write('<td align="right" width="113"><a href="javascript:add_to_shortlist(\'' + ref + '\',\'' + title + '\',\'' + id + '\')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'addshortlistbutton\',\'\',\'../images/button_add_shortlist_hover.gif\',1)"><img name="addshortlistbutton" border="0" src="../images/button_add_shortlist_off.gif" width="108" height="15"></a></td>');
	else
		window.document.write('<a href="javascript:remove_from_shortlist(\'' + ref + '\',\'' + title + '\',\'' + id + '\')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'removeshortlistbutton\',\'\',\'../images/button_remove_shortlist_hov.gif\',1)"><img name="removeshortlistbutton" border="0" src="../images/button_remove_shortlist_off.gif"></a>');
		//window.document.write('<td align="right" width="151"><a href="javascript:remove_from_shortlist(\'' + ref + '\',\'' + title + '\',\'' + id + '\')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'removeshortlistbutton\',\'\',\'../images/button_remove_shortlist_hov.gif\',1)"><img name="removeshortlistbutton" border="0" src="../images/button_remove_shortlist_off.gif" width="146" height="15"></a></td>');
}

function process_cv_shortlist(form)
{
	var return_value = false;

	form.cv_ids.value = ",";
	
	var cv_credits = form.cv_credits.value;
	var cvs_checked = 0;
	
	if(form.cv_check.length > 1)
	{
		for(i=0;i<form.cv_check.length;i++)
		{
			if(form.cv_check[i].checked == true)
			{
				form.cv_ids.value += (form.cv_check[i].value + ',');
				cvs_checked ++;
			}
		}
	}
	else
	{
		if(form.cv_check.checked == true)
		{
			form.cv_ids.value += (form.cv_check.value + ',');
			cvs_checked ++;
		}
	}
	
	if(cvs_checked > cv_credits)
	{
		var deselect = cvs_checked - cv_credits;
		alert(text_requested + cvs_checked + text_cvs_but_only + cv_credits + text_cv_credits_please_select + deselect + text_cvs);
	}
	else if(cvs_checked == 0)
	{
		alert(error_no_cvs_selected);
	}
	else if(is_email(form.email.value) == false)
	{
		alert(error_email);
		form.email.focus();
	}
	else
	{
		form.credits_used.value = cvs_checked;
		return_value = true;
	}
	
	return return_value;
}

function complete_cv_request(form)
{
	if(process_cv_shortlist(form) == true)
	{
		//alert(form.cv_ids.value);
		form.submit();
	}
}

function create_list_for_email()
{
	var shortlist = new Cookie(document, "shortlist", null, "/");
	shortlist.load();

	var refs = unescape(shortlist.refs);
	var titles = unescape(shortlist.titles);
	var ids = unescape(shortlist.ids);
	var counter = shortlist.counter;
	
	var ref_array = refs.split(":");
	var title_array = titles.split(":");
	var id_array = ids.split(":");
	
	for(i=0;i<counter;i++)
		window.document.write(ref_array[i] + '&nbsp;' + title_array[i] + '<br>');
}

function clear_shortlist()
{
	var shortlist = new Cookie(document, "shortlist", null, "/");
	shortlist.remove();
	window.location.reload();
}

function cancel_order(url)
{
	if(!url)
		var return_url = "/";
	else
		var return_url = url;
		
	if(confirm("Do you want to clear your order list?") == true)
	{
		var shortlist = new Cookie(document, "shortlist", null, "/");
		shortlist.remove();
		//window.location = return_url + "?ACTION=CLEARSB";
		window.history.back();
	}
	else
	{
		//window.history.back();
	}
}

function cancel_order2(url)
{
	if(!url)
		var return_url = "/";
	else
		var return_url = url;
		
	if(confirm("Do you want to clear your order list?") == true)
	{
		var shortlist = new Cookie(document, "shortlist", null, "/");
		shortlist.remove();
		//window.location = return_url + "?ACTION=CLEARSB";
		window.location = "default.html";
	}
	else
	{
		//window.history.back();
	}
}

function FormatNumber(expr, decplaces) {

var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));

while (str.length <= decplaces) {
str = "0" + str;
}

var decpoint = str.length - decplaces;

return str.substring(0,decpoint) + "." + str.substring(decpoint, str.length);

}

function validate_order(form)
{
	var return_value = false;
	
	if(form.bill_name.value == "")
	{
		alert("Please enter your name");
		form.bill_name.focus();
	}
	else if(form.bill_addr1.value == "")
	{
		alert("Please enter your address");
		form.bill_addr1.focus();
	}
	else if(form.bill_town.value == "")
	{
		alert("Please enter the town");
		form.bill_town.focus();
	}
	else if(form.bill_county.value == "")
	{
		alert("Please enter the county");
		form.bill_county.focus();
	}
	else if(form.bill_postcode.value == "")
	{
		alert("Please enter the postcode");
		form.bill_postcode.focus();
	}
	else if(form.bill_phone.value == "")
	{
		alert("Please enter your phone number");
		form.bill_phone.focus();
	}
	else if(form.bill_email.value == "")
	{
		alert("Please enter your email address");
		form.bill_email.focus();
	}
	else if(form.del_addr1.value == "" && form.same_addr.value == "N")
	{
		alert("Please enter your address");
		form.del_addr1.focus();
	}
	else if(form.del_town.value == "" && form.same_addr.value == "N")
	{
		alert("Please enter the town");
		form.del_town.focus();
	}
	else if(form.del_county.value == "" && form.same_addr.value == "N")
	{
		alert("Please enter the county");
		form.del_county.focus();
	}
	else if(form.del_postcode.value == "" && form.same_addr.value == "N")
	{
		alert("Please enter the postcode");
		form.del_postcode.focus();
	}
	else if(form.card_number.value == "" && form.card_type.value != "None")
	{
		alert("Please enter your card number");
		form.card_number.focus();
	}
	else if(form.card_expiry_date.value == "" && form.card_type.value != "None")
	{
		alert("Please enter your card expiry date");
		form.card_expiry_date.focus();
	}
	else if(form.card_name.value == "" && form.card_type.value != "None")
	{
		alert("Please enter the cardholders name, as shown on the card");
		form.card_name.focus();
	}
	else
	{
		return_value = true;
	}
	
	return return_value;
}

function submit_order(form)
{
	if(validate_order(form) == true)
	{
		form.submit();
	}
}

function check_del_addr(form)
{
	if(form.same_addr_check.checked)
	{
		form.same_addr.value = "Y";
		form.del_addr1.disabled = true;
		form.del_addr2.disabled = true;
		form.del_addr3.disabled = true;
		form.del_town.disabled = true;
		form.del_county.disabled = true;
		form.del_postcode.disabled = true;
	}
	else
	{
		form.same_addr.value = "N";
		form.del_addr1.disabled = false;
		form.del_addr2.disabled = false;
		form.del_addr3.disabled = false;
		form.del_town.disabled = false;
		form.del_county.disabled = false;
		form.del_postcode.disabled = false;
	}
}

function check_card_type(form)
{
	if(form.card_type.value == "None")
	{
		form.card_number.disabled = true;
		form.card_issue_date.disabled = true;
		form.card_expiry_date.disabled = true;
		form.card_issue_number.disabled = true;
		form.card_name.disabled = true;
	}
	else
	{
		form.card_number.disabled = false;
		form.card_issue_date.disabled = false;
		form.card_expiry_date.disabled = false;
		form.card_issue_number.disabled = false;
		form.card_name.disabled = false;
	}
}

function validate_catalogue_request(form)
{
	var return_value = false;
	
	if(form.name.value == "")
	{
		alert("Please enter your name");
		form.name.focus();
	}
	else if(form.address.value == "")
	{
		alert("Please enter your address");
		form.address.focus();
	}
	else if(form.postcode.value == "")
	{
		alert("Please enter the postcode");
		form.postcode.focus();
	}
	else
	{
		return value = true;
	}

	return return_value;
}

function submit_catalogue_request(form)
{
	if(validate_catalogue_request(form) == true)
	{
		form.submit();
	}
}

function addElement(array) {
size = array.length;
addindex = parseInt(prompt("Please enter the element index where you would like to add an item.",""));
validNo = (addindex != "NaN");
inRange = ( (addindex >= 0) && (addindex <= array.length+1) );
if (validNo && inRange) {
addvalue = prompt("Please enter the value to be added as element index " + addindex + ".","");
for (var i=array.length+1; i>addindex; i--) array[i] = array[i-1];
array[addindex] = addvalue;
array.length = array.length-1;
showArray(array);
}
else alert("You only add element indexes between 0 and " + (size) + ".");
}

function deleteElement(array)
{
	size = array.length;
	delindex = parseInt(prompt("Please enter the element index of the item to remove.",""));
	validNo = (delindex != "NaN");
	inRange = ( (delindex >= 0) && (delindex <= array.length) );

	if (validNo && inRange)
	{
		for (var i=0; i<=size; i++)
		{
			array[i] = ((i == delindex) ? "delete" : array[i]);
		}
		for (var j=delindex; j<size-1; j++)
		{
			if (j != size)
			{
				array[j] = array[j+1];
			}
			array.length = size-1;
		}
		alert("Element index " + delindex + " has been removed.  The other elements have moved to fill the spot.");
		showArray(array);
	}
	else
		alert("You only delete from element index 0 to " + (size-1) + ".");
}

function showArray(array) {
arraytext = "";
for (var i=0; i<array.length; i++) {
arraytext += "Element Index " + i + ":  " + array[i] + "\n";
}
document.form.text.value = arraytext;
}
