
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//send clip registration
function send_clip_reg(email)
{
	create_XMLHttpRequest();
			
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==1)
		{
			document.getElementById("clip_reg_email_holder").innerHTML = "<img src=\"images/loading.gif\" />"; 
		}
		
		if(xmlHttp.readyState==4)
		{
			//alert(xmlHttp.responseText);
			document.getElementById("clip_reg_email_holder").innerHTML = xmlHttp.responseText;
		}	
	}
	
	//send it to the ajax script
	xmlHttp.open("POST","send_clip_reg.asp",true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	var params = "email=" + email; 
	xmlHttp.send(params);
}

//all the workings for the first panel
function update_price(currency_code, product_id, workbooks_printed, workbooks_pdf, discount_code, quantity)
{
	//switch currency image
	document.getElementById('currency_image').src='images/flag_' + currency_code + '.gif';
	
	//update hidden currency code field
	document.getElementById("currency_code").value = currency_code;
	
	//now do the price stuff
	create_XMLHttpRequest();
			
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==1)
		{
			document.getElementById("order_config_price").innerHTML = "<img src=\"images/loading.gif\" />"; 
		}
		
		if(xmlHttp.readyState==4)
		{
			//alert(xmlHttp.responseText);
			var prices = xmlHttp.responseText;
			
			prices_array = prices.split("-");
			
			document.getElementById("order_config_price").innerHTML = prices_array[0];
			document.getElementById("price").value = prices_array[1];
			document.getElementById("saving").value = prices_array[2];
			document.getElementById("workbooks_pdf_price_display").innerHTML = prices_array[3];
			document.getElementById("workbooks_printed_price_display").innerHTML = prices_array[4];
			document.getElementById("price_difference").value = prices_array[5];
		}	
	}
	
	//send it to the ajax script
	xmlHttp.open("POST","update_price.asp",true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	var params = "currency_code=" + currency_code + "&product_id=" + product_id + "&workbooks_printed=" + workbooks_printed + "&workbooks_pdf=" + workbooks_pdf + "&discount_code=" + discount_code + "&quantity=" + quantity; 
	xmlHttp.send(params);
}


function check_for_vat_number(country_id)
{
	if((country_id.length)>0)
	{	
		create_XMLHttpRequest();
				
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==1)
			{
				//document.getElementById("vat_input_box").innerHTML = "<p style=\"margin-top:10px;\"><img src=\"images/loading.gif\" /></p>";
				//document.getElementById("vat_input_box").innerHTML = '<input type="hidden" value="" name="vat_number"/>';
			}
			
			if(xmlHttp.readyState==4)
			{
				if(xmlHttp.responseText=="1")
				{
					$('vat_input_box').show();
				}
				else
				{
					$('vat_input_box').hide();
				}
			}	
		}
		
		//send it to the ajax script
		xmlHttp.open("POST","check_for_vat_number.asp",true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
		var params = "country_id=" + country_id; 
		xmlHttp.send(params);	
	}
}

function send_referrer_emails(userid, refCode, username, userEmail, Name1, Email1, Name2, Email2, Name3, Email3, Name4, Email4, Name5, Email5, Name6, Email6, Name7, Email7)
{
	if ( ((userid.length)>0) && ((refCode.length)>0) && ((username.length)>0) && ((userEmail.length)>0) )
	{	
		create_XMLHttpRequest();
				
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==1)
			{
				//disable the submit button so no more emails can be sent
				document.getElementById('email_message').innerHTML = '<img src="images/loading.gif"/>';
				$('send_referrer_emails_submit').onclick = "";
				$('send_referrer_emails_submit').href = "";
			}
			
			if(xmlHttp.readyState==4)
			{
				if(xmlHttp.responseText=="1")
				{
					//nowt
				}
				else
				{
					document.getElementById('email_message').innerHTML = '<span>Thank you</span>, your colleagues emails have been received';
				}
			}	
		}
		
		//send it to the ajax script
		xmlHttp.open("POST","send_referrer_emails.asp",true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		var params = "userid=" + userid + "&refCode=" & refCode & "&username=" & username & "&userEmail=" & userEmail & "&Name1=" & Name1 & "&Email1=" & Email1 & "&Name2=" & Name2 & "&Email2=" & Email2 & "&Name3=" & Name3 & "&Email3=" & Email3 & "&Name4=" & Name4 & "&Email4=" & Email4 & "&Name5=" & Name5 & "&Email5=" & Email5 & "&Name6=" & Name6 & "&Email6=" & Email6 & "&Name7=" & Name7 & "&Email7=" & Email7; 
		xmlHttp.send(params);	
	}
}

function save_delivery_details(country_id, vat_number, name, job_title, company, address_1, address_2, address_3, town_city, county, post_code, email, telephone)
{	
	create_XMLHttpRequest();
			
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==1)
		{
			//disable the submit button so no more emails can be sent
		}
		
		if(xmlHttp.readyState==4)
		{
			if(xmlHttp.responseText=="1")
			{
				//nowt
			}
			else
			{
				alert('ok');
			}
		}	
	}
	
	//send it to the ajax script
	xmlHttp.open("POST","save_delivery_details.asp",true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	var params = "country_id=" + country_id + "&vat_number=" & vat_number & "&name=" & name & "&job_title=" & job_title & "&company=" & company & "&address_1=" & address_1 & "&address_2=" & address_2 & "&address_3=" & address_3 & "&town_city=" & town_city & "&county=" & county & "&post_code=" & post_code & "&email=" & email & "&telephone=" & telephone; 
	xmlHttp.send(params);	
}


//checking the first panel when they hit submit
function check_step_1()
{
	//do a final updating of prices to ensure they haven't adjusted anything and then hit submit
	update_price(document.order_config.currency_selected.value, document.order_config.product_id.value, document.order_config.workbooks_printed.checked,  document.order_config.workbooks_pdf.checked, document.order_config.discount_code.value, document.order_config.quantity.value);
	
	//here we will pop up the deal nag screen
	var product_id = document.order_config.product_id.value;
	var price_difference = document.getElementById('price_difference').value;
	
	if (product_id != 'dvd_deal')
	{
		//turn off the dropdowns so ie6 can't spoil things
		$('quantity').hide();
		$('currency_selected').hide();
	
		//offer the deal
		str = '<table width="435" border="0" cellspacing="0" cellpadding="0" class="deal_offer">  <tr>    <td colspan="2"><img src="images/deal_offer_header.jpg" alt="header" width="435" height="76" /></td>  </tr>  <tr>    <td colspan="2"><table width="435" border="0" cellspacing="0" cellpadding="0">      <tr>        <td width="188" background="images/deal_offer_price.jpg" bgcolor="#264768" valign="top"><h1>';
		
		//insert the value
		str += price_difference;
		
		str += ' <span>extra</span></h1></td>        <td width="247"><img src="images/deal_offer_products.jpg" width="247" height="142" alt="products" /></td>      </tr>    </table></td>  </tr>  <tr>    <td><a href="#" onclick="messageObj.close();proceed_to_step_2()"><img src="images/deal_offer_no_button.jpg" alt="No thanks - just one product please" width="218" height="77" border="0" /></a></td>    <td><a href="#" onclick="messageObj.close();go_to_deal()"><img src="images/deal_offer_yes_button.jpg" width="217" height="77" alt="Yes please - take me to the deal" border="0" /></a></td>  </tr></table>';		
		
		messageObj.setHtmlContent(str);
		messageObj.setCssClassMessageBox(false);
		messageObj.setSource(false);	// no html source since we want to use a static message here.
		messageObj.setShadowDivVisible(true);	// Disable shadow for these boxes	
		messageObj.display();
	}
	else
	{
		proceed_to_step_2();
	}
}

function proceed_to_step_2()
{
	//change the submit button and remove its action
	$('step_1_button').src = "images/button_choose_deal_grey.jpg";
	$('step_1_button').onclick = "";
	
	//enable the dropdowns and discount code input too
	document.getElementById("currency_selected").disabled = true;
	document.getElementById("quantity").disabled = true;
	document.getElementById("discount_code").disabled = true;
	
	//disable the update price button and checkboxes
	if ($('button_update_price')) { $('button_update_price').onclick = ""; }
	document.order_config.workbooks_pdf.disabled = true;
	document.order_config.workbooks_printed.disabled = true;
	
	//show the second and third panels and hide the blank ones
	$('details_panel_blank').hide()
	$('terms_panel_blank').hide()
	
	$('details_panel_on').show()
	$('terms_panel_on').show()
	
	//show the quantity and currency dropdowns
	$('quantity').show();
	$('currency_selected').show();
}


function check_step_2(product_id, price_difference)
{
	var errors = 0;
	var str = '<h1>Please check the following:</h1><p>';
	
	if ($('name').value == '') { str += "Full name<BR>"; errors++; }
	if ($('job_title').value == '') { str += "Job title<BR>"; errors++; }
	if ($('company').value == '') { str += "Company<BR>"; errors++; }
	if ($('address_1').value == '') { str += "Address line 1<BR>"; errors++; }
	if ($('town_city').value == '') { str += "Town / City<BR>"; errors++; }
	if ($('country_id').value == '') { str += "Country<BR>"; errors++; }
	if ($('email').value == '') { str += "Email address<BR>"; errors++; }
	
	if ($('terms').checked == false) { str += "Our terms and conditions<BR>"; errors++; }
	
	if (errors > 0) 
	{ 
		//add on the buttons for this box
		str += '</p><span class="buttons"><a href="#" onclick="close_dialog_box()"><img src="images/button_ok_small.jpg" style="margin:5px 0"></a></span>';
		
		if(BrowserDetect.browser != 'Explorer') { str += '<div style="clear:both">&nbsp;</div>' };
		
		//turn off the quantity dropdown so ie6 can't spoil things
		$('quantity').hide();
		$('currency_selected').hide();
		
		//turn off the nav also
		document.getElementById('navigation').visibility = "hidden";
		
		//display modal dialog
		messageObj.setHtmlContent(str);		
		messageObj.setCssClassMessageBox(false);
		messageObj.setSource(false);	// no html source since we want to use a static message here.
		messageObj.setShadowDivVisible(true);	// Disable shadow for these boxes	
		messageObj.display();
		
		return false; 
	}
	else
	{ 
		//save the stuff in the delivery form
		//return save_delivery_details(document.order_config.country_id.value, document.order_config.vat_number.value, document.order_config.name.value, document.order_config.job_title.value, document.order_config.company.value, document.order_config.address_1.value, document.order_config.address_2.value, document.order_config.address_3.value, document.order_config.town_city.value, document.order_config.county.value, document.order_config.post_code.value, document.order_config.email.value, document.order_config.telephone.value);
		
		//submit the form
		go_to_order_confirm();
	}
}

function go_to_order_confirm()
{
	//close our box
	//messageObj.close();	
	
	//un-disable the dropdowns because they won't work otherwise...no, really
	document.getElementById("currency_selected").disabled = false;
	document.getElementById("quantity").disabled = false;
	document.getElementById("discount_code").disabled = false;
	document.getElementById("workbooks_pdf").disabled = false;
	document.getElementById("workbooks_printed").disabled = false;
	
	//submit the form
	document.order_config.submit();
}

function go_to_deal()
{
	//close our box
	messageObj.close();	
	
	//un-disable the dropdowns because they won't work otherwise...no, really
	document.getElementById("currency_selected").disabled = false;
	document.getElementById("quantity").disabled = false;
	document.getElementById("discount_code").disabled = false;
	document.getElementById("workbooks_pdf").disabled = false;
	document.getElementById("workbooks_printed").disabled = false;
	
	//submit the form
	document.location.href='order_config.asp?pid=deal';
}
	
function disable_selects()
{
	var selects = document.getElementsByTagName("select");    
	for (var i=0; i<selects.length; i++) { $(selects[i]).disable(); }
}


function close_dialog_box()
{
	//show the quantity dropdown again
	if ($('quantity')) { $('quantity').show(); }
	if ($('currency_selected')) { $('currency_selected').show(); }
	
	//close our box
	messageObj.close();	
}
	
	


//ajax enabler
function create_XMLHttpRequest()
{
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			alert("Your browser does not support AJAX!");
			return false;
			}
		}
	}
}


//broswer detection script
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();