var giMemberStyleId = -1;
var giLoggedIn = -1;
var giTaxRegion = 1; //DEFAULT AUSTRALIA
var giCurrency = 155; //DEFAULT USD
var giTaxRegionAsked = 0; //HAVE THEY BEEN ASKED ABOUT THE TAX REGION 0 = NO ==> 1 = YES 
var giCustomOrder = 0; //IS A CUSTOM PRODUCT INCLUDED IN THE ORDER? 0 = NO ---> 1= YES
var giPayType = -1; //FOR THE PAYMENT TYPE 1 = CC 2 =PAYPAL 3 = FAXMAIL 
var sDetailsMessage = '';
var giCurrencyChanged = -1;


$(function() 
{	
	var MWSUSERNAME_COOKIE = 1;
	
	//CHECK IF ON HOME PAGE
	if(msOnDemandDocumentId == 26709)
	{
		$("#butterfly").delay(2000).animate({
		left: '202px',
		top: '287px'
	}, 1000).animate({
		left: '202px',
		top: '197px'
	}, 777, 'linear').animate({
		left: '302px',
		top: '227px'
	}, 666, 'linear').animate({
		left: '377px',
		top: '197px'
	}, 777, 'linear').animate({
		left: '502px',
		top: '242px'
	}, 657, 'linear', function() 
		{
			$("#ear").fadeIn(500).css("cursor", "pointer").click(function(event){window.location.href = '/popet_home';});
		}).delay(2000).animate({
		left: '615px',
		top: '220px'
	}, 888);
	}
	
	//CHANGES HEIGHT OF BROWN to height of content
	$("#brown").height($("#content").height()+180);
	//CHANGES HEIGHT OF BROWN to height of content
	$("#stars").height($("#content").height()+180);
	if(msOnDemandDocumentId == 28609)
	{
		$("#brown").height(800);
	}
	
	if(msOnDemandDocumentId == 27441)
	{
		$("#brown").height(1000);
	}
	//CHANGES ANYTHING CALLED BUTTON INTO A JQUERY UI BUTTON
	$("button").button();

	//CHECK IF POPETLEARNING SHOP PAGE
	if(msOnDemandDocumentId == 26739)
	{
		$('.bottomscroll').mouseenter(function (event) 
		{ 
			$(this).css("cursor", "pointer");
			
		}).mouseleave(function (event) 
		{ 
			$(this).css("cursor", "auto");		
		}).click(function (event)
		{
			$.scrollTo('100%', 800, {axis:'y'});
		});
	}
	//BIND TOP MENU BUTTONS
   	BindTopMenuButtons();
	BindSideMenuButtons();
	BindPopetDifferenceButton();
	
	
	
	// or from an external source
	$.get('/site/1125/menuContent.html', function(data)
	{ 
		$('#flyout').menu(
		{ 
			content: data, flyOut: true, nextMenuLink: 'ui-icon-circle-arrow-e' 
		});
	});  
	
	if (document.location.href.indexOf('newuser=yes') > 0)
	{
		$("#loginCustomer").html('');
		AskCustomerDetails();
		AskCustomerPayment();
    }
		
	
	//GET THE SCRIPT STYLE VARIABLE FROM THE SERVER AND ASSIGN TO THE USERS CURRENT STYLE
	var sParam = 'method=SITE_GET_SESSION_VARIABLE&site=' + msOnDemandSiteId + '&variable=userstyleid';
	var sReturn;
	
	if(document.location.hash == '#myspot')
	{
		window.location.href = '/popet_myspot';
	}
	
	$.ajax({
		type: 'GET',
		url: '/directory/ondemand/site.asp?' + sParam,
		dataType: 'text',
		async: false,
		success: function(data, textStatus, XMLHttpRequest) 
		{
			sReturn = data;
			var aReturn = sReturn.split('|');
			if(aReturn[1] != '')
			{
				giMemberStyleId = aReturn[1];
			}
		}
	})
		
	sParam = 'method=SITE_IS_LOGGED_ON&site=' + msOnDemandSiteId
	sReturn = onDemandSite(sParam);
	
	//CHECK IF A USER IS LOGGED IN
	if (sReturn == 'OK|OK')
	{
		//Change Logout Button
		//Change Myspot shortcut to get to my_eworkbooks rather then login page
		if(msOnDemandDocumentId == 27441)
		{
			CheckPayPalPayment();
			WelcomeUser();
			PopulateMySpotMenu();
			BindMySpotButtons();
			CheckScriptStyle();
			ShoweWorkbooks();
		}
		
		ChangeLoginButton();
		
		giLoggedIn = 1;
		
		$('#myLoginButton').click(function(event)
		{
			//SET Logoff bind
			Logoff();
		})
	}
	else
	{
		if(msOnDemandDocumentId == 27441)
		{
		//ASK THE USER TO LOGIN
		AskCustomerLogin(1);
		}
	}
	
	//ASSIGN VARIABLES FOR ACCORDION
	var icons = 
	{
	header: "ui-icon-circle-arrow-e",
	headerSelected: "ui-icon-circle-arrow-s"
	};
	
	//SET ACCORDION ATTRIBUTES
	$("#accordion").accordion(
	{
		autoHeight: false,
		navigation: true,
		collapsible: true,
		active: false,
		icons: icons
	});

	//SET CART BAR AT THE BOTTOM OF PAGE
	$("#cart-bar").jixedbar(
	{
		hoverOpaque: true,
		roundedCorners: true
	});

	//BIND BUTTONS IN CART TO PERFORM ANIMATION
	$('.viewcart').click(function() 
			{
				if($("#cart").text() == "Show Cart")
				{
					ShowProductCart(1);
					$(".jx-bar").animate(
					{
					height: "250px"
					}, 1000, "swing", function(){
					//CALLBACK FUNCTION TO CHANGE OVERFLOW
					$(".cartInformation").css('overflow-x', 'hidden');
					$(".cartInformation").css('overflow-y', 'auto');});
					$("#cart").text("Hide Cart");
					
				}
				
				else
				{
					$(".jx-bar").animate(
					{
					height: "30px"
					}, 500 , function(){
					//CALLBACK FUNCTION TO CHANGE OVERFLOW
					$(".cartInformation").css('overflow-x', 'hidden');
					$(".cartInformation").css('overflow-y', 'auto');});
					$("#cart").text("Show Cart");
				}
	});	
	
	//BINDS SEARCH BUTTON
	$("#searchButton").click(function()
	{
		$.blockUI({ message: "<h1>Searching Products...</h1>", fadeIn: 250, timeout: 500, onBlock: function ()
			{
				SearchProducts();
			}
		});
	}).mouseenter(function()
	{
		$(this).css("cursor", "pointer");
	}).mouseleave(function()
	{
		$(this).css("cursor", "auto");
	});
			
	//BINDS CHANGE TAX REGION BUTTON CLICK TO ASKTAXTYPE FUNCTION
	$("#taxregion").click(function()
	{
		AskTaxType();
	})
	
	//BINDS CHANGE CURRENCY BUTTON CLICK TO ASKCURRENCY FUNCTION
	$("#currency").click(function()
	{
		//FUNCTION CREATES THE CURRENCY LIST AND ASKS USER TO CHANGE
		CreateCurrencyList();
	})
	
	//DELEGATE ACTIONS TO REMOVE PRODUCT DYNAMIC BUTTONS
	$("body").delegate(".removeproduct", "click", function(){
		RemoveProductFromCart($(this).attr("id"));
    });	
	$("body").delegate(".removeproduct", "mouseenter", function(){
		$(this).css("cursor", "pointer");
		$(this).css("color", "#0D3692");
    });	
	$("body").delegate(".removeproduct", "mouseleave", function(){
		$(this).css("color", "#0099FF");
    });
	$(".aboutscriptmore").click(function()
	{
		//$.unblockUI();
		$.blockUI(
		{ 
			message:  $('#scriptstylemessage'),
			onBlock: function()
			{
				$('.okscript').unbind('click');
				$('.okscript').click(function() 
				{
					//$.unblockUI();
					DisplayScriptTypeQuestion();
				});
			}
		}); 
	});
	
	UpdateCartBar();
	BindShopButtons();
	BindWhatIsPopetButton();
	BindGiftedCaseButton();
	
	//CHECK IF ON CHECKOUTPAGE
	if(msOnDemandDocumentId == 28609)
	{
		ShowProductCart(2);
		//BIND RETURNING CUSTOMER
		if (giLoggedIn == 1 )
		{
			//SHOW THE USER THEIR CURRENT DETAILS
			$("#askCustomerType").html('');
			ShowCustomerDetails();
			AskCustomerPayment();
		}	
		else
		{
			AskCustomerType();
			$("#returningCustomer").click(function(event)
			{
				$("#personalDetails").html('');
				$("#paymentDetails").html('');
				AskCustomerLogin(2);
			})
			//BIND NEW CUSTOMER
			$("#newCustomer").click(function(event)
			{
				$("#brown").height(1700);
				$("#loginCustomer").html('');
				//CUSTOMER HASNT BEEN ASKED ABOUT TAX TYPE
				if(giTaxRegionAsked == 0)
				{
					AskTaxType();
				}
				AskCustomerDetails();
				AskCustomerPayment();
			})
		}
	}
	
	
	
	if(giTaxRegion == 2)
	{
		$('.OtherPriceYes').append(" exc.");
	}
	
	//CHECKOUT BUTTON AT THE TOP
	$("#sbutton").mouseenter(function()
	{
		$(this).attr({src: "/site/1125/topcheckouton.png"});
		$(this).css("cursor", "pointer");
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/topcheckoutoff.png"});
    });
	
	//TESTIMONIALS BUTTON
	$("#tbutton").mouseenter(function()
	{
		$(this).attr({src: "/site/1125/TestimonialsOn.png"});
		$(this).css("cursor", "pointer");
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/TestimonialsOff.png"});
    });
	//EWORKBOOK INFORMATION BUTTON
	$("#ebutton").mouseenter(function()
	{
		$(this).attr({src: "/site/1125/eWorkbookInfoOn.png"});
		$(this).css("cursor", "pointer");
		$("#einfo").show();
	}).mouseleave(function()
	{
		$("#einfo").hide();
		$(this).attr({src: "/site/1125/eWorkbookInfoOff.png"});
    });
	
	//CHANGE PASSWORD BUTTONS
	$("#changepass").click(function(event)
	{	
		changePassword();
	});
	$("#cancelpass").click(function(event)
	{	
		$.unblockUI();
	});
	
	//SHOW LEFT MENU
	$('#mainmenuleft').show();	
	$("#cart-bar").slideDown();
});

function BindWhatIsPopetButton()
{
    //BINDS MOUSEENTERLEAVE 
    $('#whatispopet').mouseenter(function(event)
    {
		$(this).css("cursor", "pointer");
		$(this).attr({src: "/site/1125/WhatIsAPopetOn.png"});
    }).mouseleave(function()
    {
		$(this).attr({src: "/site/1125/WhatIsAPopetOff.png"});
    }).click(function()
    {
		window.location.href = '/what_is_a_popet';
    });
}

function BindGiftedCaseButton()
{
    //BINDS MOUSEENTERLEAVE 
    $('#giftedcase').mouseenter(function(event)
    {
    $(this).css("cursor", "pointer");
    $(this).attr({src: "/site/1125/GiftedCaseStudyOn.png"});
    }).mouseleave(function()
    {
    $(this).attr({src: "/site/1125/GiftedCaseStudyOff.png"});
    });
    $("#giftedcase").click(function()
    {
		window.location.href = '/gifted_case';
    })
}

function BindSideMenuButtons()
{
	$('#lm_home').mouseenter(function(event)
	{
		$(this).attr({src: "/site/1125/lm_homeOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/lm_homeOff.png"});
	});
	
	$('#lm_shop').mouseenter(function(event)
	{
		$(this).attr({src: "/site/1125/lm_shopOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/lm_shopOff.png"});
	});
	
	$('#lm_teacher').mouseenter(function(event)
	{
		$(this).attr({src: "/site/1125/lm_teacherOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/lm_teacherOff.png"});
	});
	
	$('#lm_pink').mouseenter(function(event)
	{
		$(this).attr({src: "/site/1125/lm_pinkOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/lm_pinkOff.png"});
	});
	
	$('#lm_green').mouseenter(function(event)
	{
		$(this).attr({src: "/site/1125/lm_greenOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/lm_greenOff.png"});
	});
	
	$('#lm_yellow').mouseenter(function(event)
	{
		$(this).attr({src: "/site/1125/lm_yellowOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/lm_yellowOff.png"});
	});
	
	$('#lm_blue').mouseenter(function(event)
	{
		$(this).attr({src: "/site/1125/lm_blueOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/lm_blueOff.png"});
	});
	
	$('#lm_purple').mouseenter(function(event)
	{
		$(this).attr({src: "/site/1125/lm_purpleOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/lm_purpleOff.png"});
	});
	
	$('#lm_discount').mouseenter(function(event)
	{
		$(this).attr({src: "/site/1125/lm_discountOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/lm_discountOff.png"});
	});
	
	$('#lm_ebooks').mouseenter(function(event)
	{
		$(this).attr({src: "/site/1125/lm_ebooksOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/lm_ebooksOff.png"});
	});
	
	$('#lm_spots').mouseenter(function(event)
	{
		$(this).attr({src: "/site/1125/lm_spotsOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/lm_spotsOff.png"});
	});
	
	$('#lm_about').mouseenter(function(event)
	{
		$(this).attr({src: "/site/1125/lm_aboutOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/lm_aboutOff.png"});
	});
}
function BindTopMenuButtons()
{
	//BINDS QUICKLINKS 
	$('#quicklinks').mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		$(this).attr({src: "/site/1125/m_quickLinksH.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/m_quickLinks.png"});
	});
	
	//BINDS BUY 
	$('#buybutton').mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		$(this).attr({src: "/site/1125/m_buyH_icon.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/m_buy_icon.png"});
	});
	
	//BINDS CONTACTUS
	$('#contactus').mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		$(this).attr({src: "/site/1125/m_contactH_icon.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/m_contact_icon.png"});
	});
	
	//BINDS LOGINBUTTON 
	$('#myLoginButton').mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		$(this).attr({src: "/site/1125/m_login_iconh.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/m_login_icon.png"});
	});
	
	//BIND the Login button to append the SID when called.
	$('.myspot').click(function(event)
	{
	
		//CHECK IF ON CHECKOUTPAGE
		if(msOnDemandDocumentId == 28609)
		{
			window.location.href = 'https://popet.myworkspace.com/popet_myspot';
		}
		else
		{
			var sParam = 'method=SITE_GET_SID&site=' + msOnDemandSiteId
			var sReturn;
			sReturn = onDemandSite(sParam);
			var aReturn = sReturn.split('|');
									
			var sSource = GetSourceVariable();
			if(sSource == '')
			{
			window.location.href = 'https://popet.myworkspace.com/?sid=' + aReturn[1] + '#myspot';
			}
			else
			{
			window.location.href = 'https://popet.myworkspace.com/?sid=' + aReturn[1] + '&source=' + sSource + '#myspot';
			}
		}
	});	
	
	$('#myspotmenubutton').mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		$(this).attr({src: "/site/1125/MySpotOn.png"});
	}).mouseleave(function(event)
	{
		$(this).css("cursor", "auto");
		$(this).attr({src: "/site/1125/MySpotOff.png"});
	});
	
	
}


function GetSourceVariable()
{
	var sParamSource = 'method=SITE_GET_SOURCE&site=' + msOnDemandSiteId
	var sReturnSource;
	sReturnSource = onDemandSite(sParamSource);
	var aReturnSource = sReturnSource.split('|');
	
	return aReturnSource[1];
}
function BindLoginButton()
{
	//BINDS MOUSEENTERLEAVE 
	$('#loginButton').mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		$(this).attr({src: "/site/1125/LoginOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/LoginOff.png"});
	});
	//BINDS LOGIN BUTTON CLICK TO LOGON FUNCTION
	$('#loginButton').click(function(event)
	{
		if ($('#txtUserName').val() != '' && $('#txtPassword').val() != '')
		{
			Logon();
		}
		else
		{
			alert("Please enter your Login details.");
		}
	})
}

function BindForgottenPasswordButton()
{
	//BINDS MOUSEENTERLEAVE 
	$('#forgotPasswordButton').mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		$(this).attr({src: "/site/1125/ForgottenPasswordOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/ForgottenPasswordOff.png"});
	});
	//BINDS FORGOTTEN YOUR PASSWORD BUTTON CLICK TO LOGON FUNCTION
	$("#forgotPasswordButton").click(function()
	{
		SendForgottenPassword();
	})
}

function BindPopetDifferenceButton()
{
	//BINDS MOUSEENTERLEAVE 
	$('#popetdiff').mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		$(this).attr({src: "/site/1125/PopetDifferenceOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/PopetDifferenceOff.png"});
	});
	//BINDS FORGOTTEN YOUR PASSWORD BUTTON CLICK TO LOGON FUNCTION
	$("#popetdiff").click(function()
	{
		//SEND TO POPET DIFFERENCE PAGE
	})
}

function BindOK()
{
	$('.ok').click(function() 
		{
			$.unblockUI();
			return false;
		});
		return false;
}

function BindShopButtons()
{
	//BIND CLICK
	$('img.addtocart').click(function(event)
	{
		
		/*		
		var sProductID = $(this).attr("id");
		var aProductID = sProductID.split("-");
		var offsetstart = $("#productImage-" + aProductID[1]).position(); 
		var ileftvalstart = offsetstart.left;
		var itopvalstart = offsetstart.top;
		//alert(ileftvalstart);
		//alert(itopvalstart);
		var offsetdestination = $("#cartNotify").offset();
		
		var ileftvaldest = offsetdestination.left;
		$("#productImage-" + aProductID[1]).css({position: 'absolute', top: itopvalstart, left : ileftvalstart});
		
		$("#productImage-" + aProductID[1]).animate({
		left: itopvalstart,
		top: ileftvalstart}, 1000).animate({
			'width' : '0' ,
			'height' : '0' ,
			'bottom' : '0px',
			'left' : ileftvaldest,
			'z-index' : '1',
			}, 2000)
		*/
		
		AddProductToCart(event.target.id);
	})
	
	$('img.downloadsample').click(function(event)
	{
		DownloadSample(event.target.id);
	})
	
	//BIND CLICKS TO IMAGES

	$('img.moreless').toggle(
	function(event){
		ShowMoreProduct(event.target.id);
		},
	function(event){
		ShowLessProduct(event.target.id);
		}
	)
	
	//BIND MOUSE OVERS TO IMAGES
	$('img.moreless').mouseenter(function()
			{
				$(this).attr({src: "/site/1125/ReadMoreLSOn.png"});
				$(this).css("cursor", "pointer");
			}).mouseleave(function()
			{
				$(this).attr({src: "/site/1125/ReadMoreLSOff.png"});
	});
	
	$('img.addtocart').mouseenter(function()
	{
		$(this).attr({src: "/site/1125/AddToCartLSOn.png"});
		$(this).css("cursor", "pointer");
		}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/AddToCartLSOff.png"});
    });

	$('img.downloadsample').mouseenter(function()
	{
		$(this).attr({src: "/site/1125/DownloadSampleLSOn.png"});
		$(this).css("cursor", "pointer");
		}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/DownloadSampleLSOff.png"});
    });
	
	//ADD THE PERSONALISED QUERY TO PRODUCT ID 11271 & 11297
	$('#tdChildName-11271').html('<div class="scriptstyle"><input id="inputChildName-11271" maxlength="13" size="14" type="text" style="align:center; position:relative;top:6px;" value="Child\'s name..."/></div>');
	$('#tdChildName-11271').show();
	$('#tdChildName-11297').html('<div class="scriptstyle"><input id="inputChildName-11297" maxlength="13" size="14" type="text" style="align:center; position:relative;top:6px;" value="Child\'s name..." /></div>');
	$('#tdChildName-11297').show();
	
	$('#inputChildName-11271, #inputChildName-11297').focus(function ()
	{
		$(this).val('');
	});
	
	//BIND CHECKOUT BUTTON IN CART TO MOUSE OVERS
	$("#checkoutButton").mouseenter(function()
	{
		$(this).attr({src: "/site/1125/checkoutcarton.png"});
		$(this).css("cursor", "pointer");
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/checkoutcartoff.png"});
	});
	
	
	//DELEGATE ACTIONS TO REMOVE PRODUCT DYNAMIC BUTTONS
	$("body").delegate(".checkoutButton", "click", function(){
		//BIND THE CHECKOUT BUTTONS (TOP PAGE, IN CART and NEXT TO PRODUCT)
		var sParam = 'method=SITE_GET_SID&site=' + msOnDemandSiteId
		var sReturn;
		sReturn = onDemandSite(sParam);
		var aReturn = sReturn.split('|');
		var sSource = GetSourceVariable();
		
		$.blockUI(
		{ 
			fadeIn: 250,
			message:  $('#terms'),
			onBlock: function()
			{
				$('#agree').click(function(event)
				{
					$.blockUI(
					{
						message:  $('#proceed'),
						fadeIn: 0,
						onBlock: function()
						{ 
							window.location.href = 'https://popet.myworkspace.com/?sid=' + aReturn[1] + '&source=' + sSource;
						}
					});
				});
				$('#disagree').click(function(event)
				{
					$.blockUI(
					{
						message:  '<h1>Cancelling...</h1>',
						fadeIn: 0,
						timeout: 500
					});
				});
			}
		});
    });	
	$("body").delegate(".checkoutButton", "mouseenter", function(){
		$(this).css("cursor", "pointer");
	});	
	$("body").delegate(".checkoutButton", "mouseleave", function(){
		$(this).css("cursor", "auto");
    });
	
	//BIND CHECKOUT BUTTON IN PRODUCT LIST TO MOUSE OVERS
	$(".checkoutButtonProd").mouseenter(function()
	{
		$(this).attr({src: "/site/1125/CheckoutLSOn.png"});
		$(this).css("cursor", "pointer");
		}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/CheckoutLSOff.png"});
	});
}


function AddToCartAnimation()
{
	if($("#cart").text() == "Show Cart")
	{
		$("#productadded").show();
		$("#productadded").animate({height: '58px', width: '216px', bottom: '30px'}, 1000).delay(2000).animate({height: '0px', width: '0px', bottom : '20px'}, 500);
		$("#productadded").hide();
	}
	else
	{
		$("#productadded").show();
		$("#productadded").animate({height: '58px', width: '216px', bottom: '250px'}, 1000).delay(2000).animate({height: '0px', width: '0px', bottom : '20px'}, 500);
		$("#productadded").hide();
	}
}
function Logon()
{
	var sReturn;
	var sParam;

	var sUserName = $('#txtUserName').val();
	var sPassword = $('#txtPassword').val();

	if($('#remember').attr('checked'))
	{
		//SET THE COOKIE
		$.cookie('MWSUSERNAME_COOKIE', $("#txtUserName").val());
	}
	
	sParam = 'logon=' + sUserName + '&password=' + sPassword;
	
	sReturn = onDemandLogon(sParam);
				
	if (sReturn.substring(0, 2) == 'OK')
	{
		var aValues = sReturn.split('|');
		if (aValues[0] == 'OK') 
		{
			if (unescape(aValues[1]) == "NO") 
			{
				if (aValues[2] == "LOGONFAILED")
				{
					$.blockUI({ message: "<h1>Logging In...</h1>", fadeIn: 1000, onBlock: function ()
					{
						$.blockUI({ message: "<h1>Login Error<br /><br />Your email address or password is incorrect, please try again.</h1>", fadeIn: 0, timeout: 2000});
					}
					});
				}
			}
			else 
			{
				$.blockUI({ message: "<h1>Logging In...</h1>", fadeIn: 1000, onBlock: function ()
				{
					$.blockUI({ message: "<h1>Login Successful...</h1>", fadeIn: 0, timeout: 1000});
				}
				});
				
				
				if (aValues[3] == "PASSWORDEXPIRED")
				{
					document.location.href = '/change-password/' + aValues[2]; 
				}
				else
				{	
					//Popet My_spot Page
					if(msOnDemandDocumentId == 27441)
					{
						document.location.href = 'https://popet.myworkspace.com/popet_myspot/';
					}
					//Checking Out Page
					if(msOnDemandDocumentId == 28609)
					{
						document.location.href = 'https://popet.myworkspace.com/'; 
					}
				}
			}
		}
	}
}

function SendForgottenPassword()
{
	var sParam;
	var sReturn;
	if($('#txtUserName').val() == '')
	{
		alert("Please enter your email address.");
	}
	else
	{
		sParam = 'method=SITE_SEND_PASSWORD&site=' + msOnDemandSiteId + '&mysiteonly=1&logon=' + $('#txtUserName').val();
		sReturn = onDemandSite(sParam);
		var aValues = sReturn.split('|');
		if(aValues[1] == 'OK')
		{
			$.blockUI(
			{
				message:  '<h1>Your password has been emailed to you.</h1>',
				timeout: 1500
			});
		}
		else
		{
			$.blockUI(
			{
				message:  '<h1>An error has occurred please check your Email Address.</h1>',
				timeout: 2000
			});
		}
	}
}

function askChangePassword()
{
	$.blockUI(
	{
		message:  $('#passchange'),
		fadeIn: 250,
		onBlock: function()
		{
			$('#txtPassword').val('');
			$('#txtNewPassword').val('');
			$('#txtNewPasswordConfirm').val('');
		}
	});
}

function changePassword()
{
	var sParam;
	var sReturn;
	var sCurrentPassword = $('#txtPassword').val();
	var sNewPassword = $('#txtNewPassword').val();
	var sNewPasswordConfirm = $('#txtNewPasswordConfirm').val();
	
	if (sNewPassword != sNewPasswordConfirm)
	{
		alert('The new passwords do not match, please check and try again.');
	}
	else
	{
		if(sNewPassword.length < 6)
		{
			alert('Please enter a password that is at least 6 characters long.');
		}
		else
		{
			sParam = 'method=SITE_USER_CHANGE_PASSWORD&site=' + msOnDemandSiteId + '&currentpassword=' + sCurrentPassword + '&newpassword=' + sNewPassword;
			sReturn = onDemandSite(sParam);
			var aValues = sReturn.split('|');
						
			if (aValues[0] == 'OK')
			{
				if(aValues[1] == 'ER')
				{
						$.blockUI(
					{
						message:  '<h1>Password Error</h1><p style="font-size: 14px; margin: 0px;">Please check your current password.</p>',
						fadeIn: 0,
						timeout: 3000
					});
				}
				else
				{
					$.blockUI(
					{
						message:  '<h1>Update Complete...</h1>',
						fadeIn: 0,
						timeout: 700
					});
				}
			}
		}
	}
}

function Logoff()
{

	var sReturn = onDemandLogoff();
	document.location.href = 'https://popet.myworkspace.com/popet_myspot';

}

function ShoweWorkbooks()
{
    // ALLOCATE REQUIRED VARIABLES
	var sParam;
	var oXML;
	var oRoot;
	var oRow;
	var aHTML = [];
	var aCustomHTML = [];
	//2=to Be Processed, 7=Processing,, 11=Invoiced in progress4=Completed 6=Requires Approval
	var aStatus =['0','View Now ','Awaiting Payment ','3','4','5','Awaiting Payment ','Awaiting Payment ','Cancelled ','On Hold ','On Back Order ','Invoiced - In Progress '];
	var h = -1;
	var c = -1;
	var cTotalPrice = 0;
	var iCustomCount = 0;
	
	aHTML[++h] = '<table id="myeWorkbooksHeading" class="eworkbookTableul" border="0" width="600">'
	aHTML[++h] = '<tbody>'
	aHTML[++h] = '<tr>'
	aHTML[++h] = '<td style="width: 100px;">eBook</td>'
	aHTML[++h] = '<td style="width: 350px;">Title</td>'
	aHTML[++h] = '<td style="width: 150px;">Status</td>'
	aHTML[++h] = '</tr>'
	aHTML[++h] = '</tbody>'
	aHTML[++h] = '</table>'
	// ADD START OF TABLE DETAILS TO THE ARRAY OF HTML
	 aHTML[++h] = '<table class="eworkbookItems" border="0" cellspacing="0" cellpadding="0" width="600">'
	aHTML[++h] = '<tbody>'
	
	// METHOD TO BE SENT THROUGH TO MYWS
	sParam = 'method=SITE_ORDER_PRODUCT_SEARCH&includeimage=1&includeproducts=1&site=' + msOnDemandSiteId + '&cart=1&historyonly=1'
	
	oXML = onDemandSiteXML(sParam);
	oRoot = oXML.getElementsByTagName("ondemand").item(0);
	
	// CHECK IF ANY PRODUCTS WERE RETURNED
	if (oRoot.childNodes.length == 0)
	{
		aHTML[++h] = '<tr><td valign="top">You have no eWorkbooks avalaible.</td></tr>'
		aHTML[++h] = '</tbody></table>'
		
		// FIND THE DIV FOR MYEWORKBOOKS AND FILL WITH THE ARRAY OF HTML
		$("#membersContent").html(aHTML.join(''));

	}
	else
	{
		// LOOP THROUGH THE RESULTS AND ADD EXTRA ROWS TO TABLE ON EACH PASS
		for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
		{
			var oRow = oRoot.childNodes.item(iRow);
			var iOrder = onDemandXMLGetData(oRow, "order");
			
			aHTML[++h] = '<tr class="myeWorkbooksDetails">'
			
			//CHECK IF CUSTOM BOOK APPEARS IN MEMBERS ORDERS ID11271 IS MYNAMEIS
			if (onDemandXMLGetData(oRow, "product") != '11271')
			{
				//CHECK IF AWAITING PAYMENT IF SO FILL OUT ARRAY
				if (onDemandXMLGetData(oRow, "orderstatus") != '1')
				{
					aHTML[++h] = '<td style="width: 100px;"><a href="#" class="paymentAlert" id="pd-' + onDemandXMLGetData(oRow, "product") + '"><img style="vertical-align: top; border: 0pt none;" src="' + onDemandXMLGetData(oRow, "imageurl") + '" width="40" height="55" /></a></td>'
					aHTML[++h] = '<td style="width: 350px;"><a href="#" class="paymentAlert" id="pd-' + onDemandXMLGetData(oRow, "product") + '">' + onDemandXMLGetData(oRow, "title") + '</a></td>'	
					aHTML[++h] = '<td style="width: 150px;"><a href="#" class="paymentAlert" id="pd-' + onDemandXMLGetData(oRow, "product") + '">' + aStatus[onDemandXMLGetData(oRow, "orderstatus")] + '</a></td>'
					aHTML[++h] = '</tr>'
				}
				//WE ASSUME IT HAS BEEN PAID FOR AND PROVIDE LINK TO THE EWORKBOOK
				else
				{
					aHTML[++h] = '<td style="width: 100px;"><a href="#" class="productDownload" id="pd-' + onDemandXMLGetData(oRow, "product") + '"><img style="vertical-align: top; border: 0pt none;" src="' + onDemandXMLGetData(oRow, "imageurl") + '" width="40" height="55" /></a></td>'
					aHTML[++h] = '<td style="width: 350px;"><a href="#" class="productDownload" id="pd-' + onDemandXMLGetData(oRow, "product") + '">' + onDemandXMLGetData(oRow, "title") + '</a></td>'		
					aHTML[++h] = '<td style="width: 150px;"><a href="#" class="productDownload" id="pd-' + onDemandXMLGetData(oRow, "product") + '">View Now <img style="position: relative; top: 3px;border: 0pt none;" title="pdf_small.png" src="https://secure.mydigitalspacelive.com/site/1125/pdf_small.png" alt="pdf_small.png" width="18" height="18" /></a></td>'
					aHTML[++h] = '</tr>'
				}
			}
			else 
			{
			//CHECKS CUSTOM ORDER IF ORDER IS NOT COMPLETED ITS WAITING FOR PAYMENT
				if (onDemandXMLGetData(oRow, "orderstatus") != '1')
				{
				aCustomHTML[++c] = '<table class="eworkbookItems" style="height: 56px;" border="0" cellspacing="0" cellpadding="0" width="600">'
				aCustomHTML[++c] = '<tbody><tr>'
				aCustomHTML[++c] = '<td style="width: 100px;"><a href="#" class="paymentAlert" id="pdCustom-' + onDemandXMLGetData(oRow, "product") + '"><img style="vertical-align: top; border: 0pt none;" src="' + onDemandXMLGetData(oRow, "imageurl") + '" width="40" height="55" /></a></td>'
				aCustomHTML[++c] = '<td style="width: 350px;"><a href="#" class="paymentAlert" id="pdCustom-' + onDemandXMLGetData(oRow, "product") + '">'+ onDemandXMLGetData(oRow, "title") + ' - ' + onDemandXMLGetData(oRow, "notes") + '</a></td>'
				aCustomHTML[++c] = '<td style="width: 150px;"><a href="#" class="paymentAlert" id="pdCustom-' + onDemandXMLGetData(oRow, "id") + '">' + aStatus[onDemandXMLGetData(oRow, "orderstatus")] + '</a></td>'
				aCustomHTML[++c] = '</tr>'
				aCustomHTML[++c] = '</tbody></table>'
				}
			
				//CHECKS IF ORDER IS COMPLETED BUT WAITING FOR PDF TO BE CREATED
				if (onDemandXMLGetData(oRow, "orderstatus") == '1' && onDemandXMLGetData(oRow, "orderprocessingstatus") == '53')
				{
				aCustomHTML[++c] = '<table class="eworkbookItems" style="height: 56px;" border="0" cellspacing="0" cellpadding="0" width="600">'
				aCustomHTML[++c] = '<tbody><tr>'
				aCustomHTML[++c] = '<td style="width: 100px;"><a href="#" class="pendingAlert" id="pdCustom-' + onDemandXMLGetData(oRow, "product") + '"><img style="vertical-align: top; border: 0pt none;" src="' + onDemandXMLGetData(oRow, "imageurl") + '" width="40" height="55" /></a></td>'
				aCustomHTML[++c] = '<td style="width: 350px;"><a href="#" class="pendingAlert" id="pdCustom-' + onDemandXMLGetData(oRow, "product") + '">'+ onDemandXMLGetData(oRow, "title") + ' - ' + onDemandXMLGetData(oRow, "notes") + '</a></td>'
				aCustomHTML[++c] = '<td style="width: 150px;"><a href="#" class="pendingAlert" id="pdCustom-' + onDemandXMLGetData(oRow, "id") + '"> Awaiting Creation </a></td>'
				aCustomHTML[++c] = '</tr>'
				aCustomHTML[++c] = '</tbody></table>'
				}
			}
		}
    	aHTML[++h] = '<tr>&nbsp;</tr></tbody></table>'
			
		$("#membersContent").html(aHTML.join(''));

	}
	
	
	//NOW ADD THE CUSTOMEWORKBOOKS
	//Sets up the variables
	aHTML = [];
	h = -1;
		aHTML[++h] = '<table id="myCustomeWorkbooksHeading" class="eworkbookTableul" border="0" width="600">'
		aHTML[++h] = '<tbody>'
		aHTML[++h] = '<tr width="600">'
		aHTML[++h] = '<td style="width: 100px;">eBook</td>'
		aHTML[++h] = '<td style="width: 350px;">Personalised eWorkbooks</td>'
		aHTML[++h] = '<td style="width: 150px;">Status</td>'
		aHTML[++h] = '</tr>'
		aHTML[++h] = '</tbody>'
		aHTML[++h] = '</table>'
	
	
	
	// METHOD TO BE SENT THROUGH TO MYWS
	sParam = 'method=SITE_GET_ATTACHMENTS&type=227&site=' + msOnDemandSiteId

	
	oXML = onDemandSiteXML(sParam);
	oRoot = oXML.getElementsByTagName("ondemand").item(0);
	
	//CHECK FOR ANY ATTACHMENTS
	if (oRoot.childNodes.length != 0)
	{
			// ADD START OF TABLE DETAILS TO THE ARRAY OF HTML
			aHTML[++h] = '<table class="eworkbookItems" style="height: 56px;" border="0" cellspacing="0" cellpadding="0" width="600">'
			aHTML[++h] = '<tbody>'
			// LOOP THROUGH THE RESULTS AND ADD EXTRA ROWS TO TABLE ON EACH PASS
			for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
			{
				var oRow = oRoot.childNodes.item(iRow);
				var sFilename = onDemandXMLGetData(oRow, "filename");
				var aValues = sFilename.split('_');
				aHTML[++h] = '<tr width="600"><td style="width: 100px;"><a href="' + onDemandXMLGetData(oRow, "link") + '" class="productDownload" id="pdCustom-' + onDemandXMLGetData(oRow, "id") + '"><img style="vertical-align: top; border: 0pt none;" src="/public/9442/product_11271_2896779_PK2004_116s.gif" width="40" height="55" /></a></td>'
				aHTML[++h] = '<td style="width: 350px;"><a href="' + onDemandXMLGetData(oRow, "link") + '" class="productDownload" id="pdCustom-' + onDemandXMLGetData(oRow, "id") + '">My Name Is . . . (Ages 3 - 4) ' + aValues[1] + '</a></td>'		
				aHTML[++h] = '<td style="width: 150px;"><a href="' + onDemandXMLGetData(oRow, "link") + '" class="productDownload" id="pdCustom-' + onDemandXMLGetData(oRow, "id") + '">View Now <img style="position: relative; top: 3px;border: 0pt none;" title="pdf_small.png" src="https://secure.mydigitalspacelive.com/site/1125/pdf_small.png" alt="pdf_small.png" width="18" height="18" /></a></td>'
				aHTML[++h] = '</tr>'
			}
				//aHTML[++h] = '<tr class="myeWorkbooksDetails">'
				aHTML[++h] = '</tbody></table>'
			
			$("#myCustomeWorkbooks").html(aHTML.join(''));
			$("#myCustomeWorkbooks").append(aCustomHTML.join(''));
		}
		else
		{
			$("#myCustomeWorkbooks").html(aHTML.join(''));
			$("#myCustomeWorkbooks").append(aCustomHTML.join(''));
		}
		
	//BIND CLICKS TO CLASSES
	$(".productDownload").click(function(event)
	{
		sProductID = $(this).attr("id");
		ShowAttachment(sProductID);
	})
	
	$(".paymentAlert").click(function(event)
	{
		$.blockUI(
			{ 
				message:  $('#payalertdialog')
			});
		$("button").button();
		BindOK();
	})
	$(".pendingAlert").click(function(event)
	{
		$.blockUI(
			{ 
				message:  $('#pendingalertdialog')
			});
		$("button").button();
		BindOK();
	})
}
function ShowAttachment(sProductID)
{
	//SPLIT THE ID AND THE PD- TEXT AND OPEN THE LINK WITH THE ATTACHMENT
	var sProductID; 
	var sParam;
	var oXML;
	var oRoot;
	var oRow;
	var iRow = 0;
	var aValues = sProductID.split('-');
	
	sParam = 'method=SITE_PRODUCT_SEARCH&select=' + aValues[1] + '&includeattachments=1&attachmenttype=' + giMemberStyleId + '&site=' + msOnDemandSiteId
	
	oXML = onDemandSiteXML(sParam);
	oRoot = oXML.getElementsByTagName("ondemand").item(0);
	
	oRow = oRoot.childNodes.item(iRow);
	
	//CHECK IF ANY ATTACHMENTS ARE RETURNED IN THEIR SCRIPT STYLE
	if (onDemandXMLGetData(oRow, "attachments") == "")
	{
		//SEARCH FOR GENERIC ATTACHMENTS
		sParam = 'method=SITE_PRODUCT_SEARCH&select=' + aValues[1] + '&includeattachments=1&attachmenttype=205&site=' + msOnDemandSiteId
	
		oXML = onDemandSiteXML(sParam);
		oRoot = oXML.getElementsByTagName("ondemand").item(0);
		oRow = oRoot.childNodes.item(iRow);
		//STILL CANT FIND ANY ATTACHMENTS FOR CUSTOMER
		if (onDemandXMLGetData(oRow, "attachments") == "")
		{
			$.blockUI(
			{ 
				message:  $('#alertnoscript')
			});
			$("button").button();
			BindOK();
		}
		else
		{
			//ISSUE DOWNLOAD LINK
			var sDownloadLink;
			sDownloadLink = onDemandXMLGetData(oRow, "attachments");
			var aSplitLink = sDownloadLink.split('#');
			document.location.href = aSplitLink[2];
		}

	}
	else
	{
		//ISSUE DOWNLOAD LINK
		var sDownloadLink;
		sDownloadLink = onDemandXMLGetData(oRow, "attachments");
		var aSplitLink = sDownloadLink.split('#');
		document.location.href = aSplitLink[2];
	}
}

function ShowOrders()
{
	var sParam;
	var oXML;
	var oRoot;
	var oRow;
	var aHTML = [];
	var aStatus =['0','Completed ','Awaiting Payment ','3','4','5','Awaiting Payment ','Awaiting Payment ','Cancelled ','On Hold ','On Back Order ','Invoiced - In Progress '];	
	var h = -1;
	var cTotalPrice = 0;
	
	sParam = 'method=SITE_ORDER_SEARCH&site=' + msOnDemandSiteId + '&includeinvoices=1&includeproductprice=1'

	oXML = onDemandSiteXML(sParam);
	oRoot = oXML.getElementsByTagName("ondemand").item(0);
	
	$("#myCustomeWorkbooks").html("<p>&nbsp;</p>");
	
	//SET UP TABLE HEADING
	aHTML[++h] = '<table id="myeWorkbooksHeading" class="eworkbookTableul" border="0" width="600">'
	aHTML[++h] = '<tbody>'
	aHTML[++h] = '<tr>'
	aHTML[++h] = '<td style="width: 125px;">Order Number<br /></td>'
	aHTML[++h] = '<td style="width: 125px;">Order Date</td>'
	aHTML[++h] = '<td style="width: 100px;">Amount</td>'
	aHTML[++h] = '<td style="width: 150px;">Status</td>'
	aHTML[++h] = '<td style="width: 100px;">Invoice</td>'
	aHTML[++h] = '</tr>'
	aHTML[++h] = '</tbody>'
	aHTML[++h] = '</table>'
	aHTML[++h] = '<table class="eworkbookItems" style="height: 56px;" border="0" cellspacing="0" cellpadding="0" width="600" align="left">'
	aHTML[++h] = '<tbody>'
	
	
	if (oRoot.childNodes.length == 0)
	{
		aHTML[++h] = '<tr><td valign="top">Sorry, you have no Orders currently avalaible</td></tr>';
		aHTML[++h] = '</tbody></table><br />';
		
		// FIND THE DIV FOR MYEWORKBOOKS AND FILL WITH THE ARRAY OF HTML
		$("#membersContent").html(aHTML.join(''));
	}
	else
	{
		// LOOP THROUGH THE RESULTS AND ADD EXTRA ROWS TO TABLE ON EACH PASS
		for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
		{
			var oRow = oRoot.childNodes.item(iRow);
			if(onDemandXMLGetData(oRow, "status") != 5)
			{
				aHTML[++h] = '<tr>';
				aHTML[++h] = '<td style="width: 125px;">' + onDemandXMLGetData(oRow, "reference") + '</td>';
				aHTML[++h] = '<td style="width: 125px;">' + onDemandXMLGetData(oRow, "orderdate") + '</td>';
				aHTML[++h] = '<td style="width: 100px;">$' + onDemandXMLGetData(oRow, "totalpriceinctax") + '</td>';
				aHTML[++h] = '<td style="width: 150px;">'  + aStatus[onDemandXMLGetData(oRow, "status")] +  '</td>';
				
				var sInvoiceString = onDemandXMLGetData(oRow, "invoices")
				if(sInvoiceString == '')
				{
				aHTML[++h] = '<td style="width: 100px;"> Not available </td>';
				}
				else
				{
				var aInvoiceId = sInvoiceString.split('#');
				aHTML[++h] = '<td style="width: 100px;"><a href="/popetinvoice/' + aInvoiceId[1] + '" target="_blank"> View Now </a></td>';
				}
				aHTML[++h] = '</tr>'
			}
		}

		aHTML[++h] = '</tbody></table><br />'


		$("#membersContent").html(aHTML.join(''));

		$('.downloadproductattachment').click(function(event)
		{
			DownloadProductAttachment(event.target.id);
		})

	}
}
	
function ShowCustomeWorkbooks()
{
   
}

// SHOWS DETAILS IN MY SPOT
function ShowUserDetails()
{
	var sParam;
	var sReturn;
	
	sParam = 'method=SITE_COUNTRY_LIST_NAME'
	sReturn = onDemandSite(sParam);
	var aCountries = sReturn.split('|');

    // ALLOCATE REQUIRED VARIABLES
	var oXML;
	var oRoot;
	var oRow;
	var aHTML = [];
	var h = -1;
	var cTotalPrice = 0;

	$("#myCustomeWorkbooks").html("<p>&nbsp;</p");
	
	aHTML[++h] = '<div class="boxTop">&nbsp;</div>'
	aHTML[++h] = '<div id="contactus_form"><table style="height: 540px; width: 750px;" border="0" cellspacing="0" cellpadding="0"><tbody>'
	aHTML[++h] = '<tr><td align="right" valign="top">First Name:</td>'
	aHTML[++h] = '<td align="left" valign="top"><input id="txtFirstName" maxlength="40" name="txtFirstName" size="40" type="TEXT" /></td></tr>'
	aHTML[++h] = '<tr><td align="right" valign="top">Last Name:</td>'
	aHTML[++h] = '<td align="left" valign="top"><input id="txtSurname" maxlength="40" name="txtSurname" size="40" type="TEXT" /></td></tr>'
	aHTML[++h] = '<tr><td align="right" valign="top">Company Name:</td>'
	aHTML[++h] = '<td align="left" valign="top"><input id="txtCompanyName" maxlength="40" name="txtCompanyName" size="40" type="TEXT" /></td></tr>'
	aHTML[++h] = '<tr><td align="right" valign="top">Email:</td>'
	aHTML[++h] = '<td align="left" valign="top"><input id="txtEmail" maxlength="40" name="txtEmail" size="40" type="TEXT" /></td></tr>'
	aHTML[++h] = '<tr><td align="right" valign="top">Contact Number:</td>'
	aHTML[++h] = '<td align="left" valign="top"><input id="txtContactNumber" maxlength="40" name="txtContactNumber" size="40" type="TEXT" /></td></tr>'
	aHTML[++h] = '<tr><td align="right" valign="top">Postcode/Zipcode:</td>'
	aHTML[++h] = '<td align="left" valign="top"><input id="txtPostcode" maxlength="40" name="txtPostcode" size="40" type="TEXT" /></td></tr>'
	aHTML[++h] = '<tr><td align="right" valign="top">Country:</td>'
	aHTML[++h] = '<td align="left" valign="top"><form><select name="country" id="myCountry">' + aCountries[1] + '</select> </form></td></tr>'
	aHTML[++h] = '<tr><td align="right" valign="top">Default Script Style:</td>'
	aHTML[++h] = '<td align="left" valign="top"><select id="currentscriptstyle"><option value="-1">Please Select...</option><option value="27548">Plain Script</option><option value="27545">NSW and ACT Script</option><option value="27546">VIC, WA and NT Script</option><option value="27547">QLD Script</option></select></td></tr>'
	aHTML[++h] = '<tr><td>&nbsp;</td><td><button class="changemypassword">Change My Password</button>&nbsp;&nbsp;&nbsp;&nbsp;<button id="saveButton">Save My Details</button></td></tr>'
	aHTML[++h] = '</tbody></table>'
	
	// METHOD TO BE SENT THROUGH TO MYWS TO FIND ALL DETAILS OF THE USER
	sParam = 'method=SITE_PERSON_SEARCH&advanced=1&site=' + msOnDemandSiteId

	
	oXML = onDemandSiteXML(sParam);
	oRoot = oXML.getElementsByTagName("ondemand").item(0);
	
	// CHECK IF ANY PRODUCTS WERE RETURNED
	if (oRoot.childNodes.length == 0)
	{
		aHTML[++h] = '<p>No Details were Found...</p>'
		$("#membersContent").html(aHTML.join(''));

	}
	else
	{
		$("#membersContent").html(aHTML.join(''));
		// LOOP THROUGH THE RESULTS AND ADD EXTRA ROWS TO TABLE ON EACH PASS
		for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
		{
			var oRow = oRoot.childNodes.item(iRow);
		
			$("#txtFirstName").val(onDemandXMLGetData(oRow, "firstname"));
			$("#txtSurname").val(onDemandXMLGetData(oRow, "surname"));
			$("#txtCompanyName").val(onDemandXMLGetData(oRow, "sq6338"));
			$("#txtEmail").val(onDemandXMLGetData(oRow, "email"));
			$("#txtContactNumber").val(onDemandXMLGetData(oRow, "phone"));
			$("#txtPostcode").val(onDemandXMLGetData(oRow, "streetpostcode"));
			$("#currentscriptstyle").val(onDemandXMLGetData(oRow, "sq5812"));
			$("#myCountry").val(onDemandXMLGetData(oRow, "streetcountry"));
		}
	}

	$("#saveButton").click(function(event)
	{
		//SET UP THE SPARAM TO REQUEST THE CHANGE
		sParam = 'method=SITE_PERSON_UPDATE&advanced=1&firstname=' + $("#txtFirstName").val() + '&surname=' + $("#txtSurname").val() + '&sq6338=' + $("#txtCompanyName").val() + '&email=' + $("#txtEmail").val() +'&phone=' + $("#txtContactNumber").val() + '&streetpostcode=' + $("#txtPostcode").val() + '&sq5812=' + $("#currentscriptstyle").val() + '&streetcountry=' + $("#myCountry").val() + '&site=' + msOnDemandSiteId;
		$.blockUI(
			{
				message:  '<h1>Updating...</h1>',
				fadeIn: 250,
				onBlock: function()
						{ 
							SaveUserDetails(sParam);
						}
			}); 
	});
	
	$(".changemypassword").click(function(event)
	{
		askChangePassword();
	})
	$("button").button();
}

function SaveUserDetails(sParam)
{
		var oRoot;
		var sReturn;
		sReturn = onDemandSite(sParam);
		$.blockUI(
			{
				fadeIn:0,
				message:  '<h1>Details Saved...</h1>',
				timeout: 500
			}
		); 
}

function CheckScriptStyle()
{
	var sParam;
	var oXML;
	var oRoot;
	var oRow;
	var iRow = 0;
	var aScript = ['205','204','206','207','208'];
	var aChoices = ['27566','27548','27545','27546','27547'];
	//Generic sq5812(27566) -> Attach 205
	//Plain sq5812(27548) -> Attach 204
	//NSW sq5812(27545) -> Attach 206
	//VICWA sq5812(27546) -> Attach 207
	//QLD sq5812(27547) -> Attach 208
	
	sParam = 'method=SITE_PERSON_SEARCH&advanced=1&site=' + msOnDemandSiteId + '&rf=XML';
	
	$.ajax({
			type: 'GET',
			url: '/directory/ondemand/site.asp?' + sParam,
			dataType: 'xml',
			success: function(data, textStatus, XMLHttpRequest) 
			{
				oXML = data;
				oRoot = oXML.getElementsByTagName("ondemand").item(0);
				oRow = oRoot.childNodes.item(iRow);
	
				var sScriptStyle = onDemandXMLGetData(oRow, "sq5812");
				//Loop through the Arrays aScript and aChoices and assign values when needed
				for (var iCount = 0; iCount < 6; iCount++)
				{
					if(sScriptStyle == aChoices[iCount])
					{
						giMemberStyleId = aScript[iCount];
					}
				}
			}
	})
}

function ChangeLoginButton()
{
	$('#myLoginButton').attr({src: "/site/1125/LogoutIcon.png"});
	$('#myLoginButton').attr({title: "Login to download purchased eWorkbooks"});
	$('#myLoginButton').mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		$(this).attr({src: "/site/1125/LogoutIconH.png"});
		$(this).attr({title: "Logout of My Spot"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/LogoutIcon.png"});
	});
}

function PopulateMySpotMenu()
{
	$("#mySpotMenu").html('<table style="height: 40px;" border="0" width="600"><tbody><tr><td style="width: 150px;"></td><td><img id="myeWorkbooksButton" class="currentLocation" src="/site/1125/myeWorkbooksActive.png"></img></td><td><img id="myDetailsButton" class="currentLocation" src="/site/1125/myDetailsOff.png"></img></td><td><img id="myOrdersButton" class="currentLocation" src="/site/1125/myOrdersOff.png"></img></td><td><img id="myLogoutButton" class="currentLocation" src="/site/1125/myLogoutOff.png"></img></td></tr></tbody></table>');
}

function BindMySpotButtons()
{
	
	$('.currentLocation').mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
	});
	//BINDS LOGOUT BUTTON TO LOGOFF FUNCTION
	$('#myLogoutButton').mouseenter(function(event)
	{
		$(this).attr({src: "/site/1125/myLogoutOn.png"});
	}).mouseleave(function(event)
	{
		$(this).attr({src: "/site/1125/myLogoutOff.png"});
	}).click(function(event)
	{
		Logoff();
	})
	//BINDS MYDETAILS BUTTON TO MYDETAILS FUNCTION
	$('#myDetailsButton').click(function(event)
	{
		$(this).attr({src: "/site/1125/myDetailsActive.png"});
		$('#myeWorkbooksButton').attr({src: "/site/1125/myeWorkbooksOff.png"});
		$('#myOrdersButton').attr({src: "/site/1125/myOrdersOff.png"});
		ShowUserDetails();
	})
	
	$('#myeWorkbooksButton').click(function(event)
	{
		$(this).attr({src: "/site/1125/myeWorkbooksActive.png"});
		$('#myDetailsButton').attr({src: "/site/1125/myDetailsOff.png"});
		$('#myOrdersButton').attr({src: "/site/1125/myOrdersOff.png"});
		CheckScriptStyle();
		ShoweWorkbooks();
	})
	
	$('#myOrdersButton').click(function(event)
	{
		$(this).attr({src: "/site/1125/myOrdersActive.png"});
		$('#myeWorkbooksButton').attr({src: "/site/1125/myeWorkbooksOff.png"});
		$('#myDetailsButton').attr({src: "/site/1125/myDetailsOff.png"});
		ShowOrders();
	})

}

function AskCustomerLogin(iLoginScreenType)
{	//1 is full 2 is minimum
	var iLoginScreenType;
	if(iLoginScreenType == 1)
	{
		$('#membersContent').html('<br><br><h6><img src="/site/1125/MySpotLoginTitle.png" /></h6><table style="border: 0pt solid #778899;" border="0" width="600" align="left"><tbody><tr><td align="left" colspan="2">Once you have purchased your Popet eBooks simply enter you email address and password to download them here as often as you need.</td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td align="right" style="width: 100px;">Email Address:&nbsp;</td><td style="width: 300px;"><input id="txtUserName" name="username" type="text" size="36"/></td></tr><tr><td align="right">Password:&nbsp;</td><td><input id="txtPassword" type="password" name="password" type="text" size="36"/></td></tr><tr><td></td><td><img id="loginButton" src="/site/1125/LoginOff.png" />&nbsp;&nbsp;<img id="forgotPasswordButton" src="/site/1125/ForgottenPasswordOff.png" /></td></tr><tr><td></td><td><input id="remember" name="remember" type="checkbox" />Remember my logon for next time.</td></tr><tr>&nbsp;</tr><tr><td><div id="divLogonMessage"></div></td></tr></tbody></table><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><table border="0" cellspacing="0" cellpadding="3" align="LEFT" width="600" style="display:block; position: relative;"><tbody><tr><td colspan="2"><p class="firstLine">6 Tips To Protect Yourself Online</p></td></tr><tr><td valign="TOP"><strong>1.</strong></td><td>Use Virus Protection Software</td></tr><tr><td valign="TOP"><strong>2.</strong></td><td>Don\'t open email attachments from unknown sources.</td></tr><tr><td valign="TOP"><strong>3.</strong></td><td>Don\'t run programs of unknown origin.</td></tr><tr><td valign="TOP"><strong>4.</strong></td><td>Keep all applications, including your operating system, up-to-date (patched).</td></tr><tr><td valign="TOP"><strong>5.</strong></td><td>Turn off your computer or disconnect from the network when not in use.</td></tr><tr><td valign="TOP"><strong>6.</strong></td><td>Never respond to an email request for your logon name and password; even if it looks legitimate.<br /><br /></td></tr></tbody></table>');
	}
	else
	{
		$('#loginCustomer').html('<div><table style="border: 0pt solid #778899;" border="0" width="600" align="left"><tbody><tr><td style="width: 100px;"></td><td style="width: 300px;"></td></tr><tr><td style="width: 100px;">&nbsp;</td><td style="width: 300px;">&nbsp;</td></tr><tr><td align="right">Email Address:&nbsp;</td><td><input id="txtUserName" name="username" type="text" size="36"/></td></tr><tr><td align="right">Password:&nbsp;</td><td><input id="txtPassword" type="password" name="password" type="text" size="36"/></td></tr><tr><td></td><td><img id="loginButton" src="/site/1125/LoginOff.png" />&nbsp;&nbsp;<img id="forgotPasswordButton" src="/site/1125/ForgottenPasswordOff.png" /></td></tr><tr><td></td><td><input id="remember" name="remember" type="checkbox" />Remember my logon for next time.</td></tr><tr></tr><tr><td><div id="divLogonMessage"></div></td></tr></tbody></table></div>');
	}
	
	
	if($.cookie('MWSUSERNAME_COOKIE') != '')
	{
		if($.cookie('MWSUSERNAME_COOKIE') != null)
		{
			//RECOVER COOKIE IF AVAILABLE
			$('#txtUserName').val($.cookie('MWSUSERNAME_COOKIE'));
		}
	}
	$('#txtUserName').focus();
	BindLoginButton();
	BindForgottenPasswordButton();
}

function WelcomeUser()
{
	var sParam = 'method=SITE_GET_USER_NAME&site=' + msOnDemandSiteId
	var sReturn;
	
	$.ajax({
		type: 'GET',
		url: '/directory/ondemand/site.asp?' + sParam,
		dataType: 'text',
		success: function(data, textStatus, XMLHttpRequest) 
		{
			sReturn = data;

			if (sReturn.substring(0, 2) == 'OK')
			{
				var aValues = sReturn.split('|');
				if (aValues[0] == 'OK')
				{
					$("#mySpotTitle").html("<br><br><br><h2><img src='/site/1125/MySpotTitle.png'/></h2><p class='firstLine'>Welcome " + unescape(aValues[1]) + "&nbsp;" + unescape(aValues[2]) + "</p>");
				}
			}
		}
	})
}

function CreateCurrencyList()
{
    // ALLOCATE REQUIRED VARIABLES
	var sParam;
	var oXML;
	var oRoot;
	var oRow;
	var aHTML = [];
	var h = -1;
	var cTotalPrice = 0;

	//SETUP HEADING OF THE HTML
	aHTML[++h] = '<div id="currencytypeHeading"><img class="dialogimg" src="/site/1125/currencyButton.png" alt="" />&nbsp;<span class="dialogfirstLine">Please select your currency:</span><br /><br /><p style="text-align: center;"><select id="currencytype"></p>'
	
	// METHOD TO BE SENT THROUGH TO MYWS TO FIND ALL CURRENCIES
	sParam = 'method=SITE_CURRENCY_SEARCH'

	oXML = onDemandSiteXML(sParam);
	oRoot = oXML.getElementsByTagName("ondemand").item(0);
	
	// CHECK IF ANY CURRENCIES WERE RETURNED
	if (oRoot.childNodes.length == 0)
	{
		aHTML[++h] = '<option value="id">No currencies were found...</option>'
	}
	else
	{
		
		// LOOP THROUGH THE RESULTS AND ADD EXTRA ROWS TO TABLE ON EACH PASS
		for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
		{
			var oRow = oRoot.childNodes.item(iRow);
			aHTML[++h] = '<option value="' + onDemandXMLGetData(oRow, "id") + '">' + onDemandXMLGetData(oRow, "description") + ' - ' + onDemandXMLGetData(oRow, "code") + '</option>';
		}
	
	}
	aHTML[++h] = '</select><br /><br /><p style="text-align: center;"><button id="currencysave">Save</button></p></div>'
	var sFormattedCurrencyList = aHTML.join('');
	AskCurrency(sFormattedCurrencyList);
	$("button").button();
}
function AskCurrency(sFormattedCurrencyList)
{
	var sParam;
	var sReturn;
	var sFormattedCurrencyList;
	var iChange = 0;
	
	$.blockUI(
	{ 
        message:  sFormattedCurrencyList
    }); 
		
	$('#currencytype').val(giCurrency);
	
	$('#currencytype').change(function()
	{
		iChange = 1;
		giCurrency = $('#currencytype option:selected').val();
	});
			
	$('#currencysave').click(function()
	{
		$.blockUI({ message: "<h1>Saving...</h1>", fadeIn:0, timeout: 500}); 
		if(iChange == 1)
		{
			//SET CURRENCY FOR THE ORDER SESSION
			sParam = 'method=SITE_CURRENCY_SET&site=' + msOnDemandSiteId + '&select=' + giCurrency;
			sReturn = onDemandSite(sParam);
			//RELOAD THE PAGE
			location.reload();
		}
	}); 
}

function AskTaxType()
{
	var sParam;
	var sReturn;
	var iChange = 0;
	
	//CHECK IF THEY HAVE SELECTED A TAX REGION YET 
	ShowTaxRegionBlock();
	giTaxRegionAsked = 1;
	$('#currenttaxregion').val(giTaxRegion);
	$('#currenttaxregion').change(function()
	{
		iChange = 1;
		if($('#currenttaxregion').val() == "2")
		{
			var sConfirm = confirm ("By selecting a region outside of Australia, you are declaring that you are not in Australia at this time and you will not be making use of this purchase in Australia.")
			if (sConfirm)
			{
				giTaxRegion=$('#currenttaxregion option:selected').val();
				$.blockUI({ message: "<h1>Saving...</h1>", timeout: 500, fadeIn:0});
				sParam = 'method=SITE_ORDER_SET_TAX_TYPE&site=' + msOnDemandSiteId + '&select=' + giTaxRegion;
				sReturn = onDemandSite(sParam);
				//AND REFRESH THE PAGE AND PRODUCT LIST
				ChangeTaxType();
			}
			else
			{
				//THEY CANCELLED, SET THEM TO AUSTRALIA
				$.blockUI({ message: "<h1>Cancelling Action...</h1>", timeout: 500, fadeIn:0});
				//AUSTRALIA
				giTaxRegion=1;
				sParam = 'method=SITE_ORDER_SET_TAX_TYPE&site=' + msOnDemandSiteId + '&select=' + giTaxRegion;
				sReturn = onDemandSite(sParam);
				ChangeTaxType();
			}				
		}
		giTaxRegion=$('#currenttaxregion').val();
	});
		
	$('#taxsave').click(function() 
	{
		$.blockUI({ message: "<h1>Saving...</h1>", timeout: 500, fadeIn:0}); 
		if(iChange == 1)
		{
			sParam = 'method=SITE_ORDER_SET_TAX_TYPE&site=' + msOnDemandSiteId + '&select=' + giTaxRegion;
			sReturn = onDemandSite(sParam);
			//AND REFRESH THE PAGE AND PRODUCT LIST
			ChangeTaxType();
		}
		else
		{
			sParam = 'method=SITE_ORDER_SET_TAX_TYPE&site=' + msOnDemandSiteId + '&select=' + giTaxRegion;
			sReturn = onDemandSite(sParam);
		}
	}); 
}	

function ChangeTaxType()
{
	//REFRESH THE PRODUCT CART TO GET THE CORRECT PRICES
	var sParam;
	var oXML;
	var oRoot;
	var oRow;
	var aHTML = [];
	
	
	sParam = 'method=SITE_ORDER_PRODUCT_SEARCH&cart=1&includeproducts=1&site=' + msOnDemandSiteId + '&shoporderonly=1'
	sReturn = onDemandSiteXML(sParam);

	oXML = onDemandSiteXML(sParam);
	oRoot = oXML.getElementsByTagName("ondemand").item(0);

	for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
		{
			var oRow = oRoot.childNodes.item(iRow);
			sParam = 'method=SITE_ORDER_ADD_PRODUCT&site=' + msOnDemandSiteId + '&quantity=1&taxtype=' + giTaxRegion + '&product=' + onDemandXMLGetData(oRow, "product") +'&orderproduct=' + onDemandXMLGetData(oRow, "id");
			
			//CUSTOM BOOK
			if(onDemandXMLGetData(oRow, "product") == '11271' || onDemandXMLGetData(oRow, "product") == '11297')
			{
				
				sParam = sParam + '&description=' + onDemandXMLGetData(oRow, "title") + ' ' + onDemandXMLGetData(oRow, "notes") + '&notes=' + onDemandXMLGetData(oRow, "notes") + '&allowmultiple=1'; 
			
			}
			
			sReturn = onDemandSite(sParam);
			//REMOVE THE PREVIOUS PRODUCT
			RemoveProductFromCart(onDemandXMLGetData(oRow, "id"));
		}
	//IF ON CHECKOUT PAGE
	if(msOnDemandDocumentId == 28609)
	{
		window.location.href = 'https://popet.myworkspace.com/' + '?newuser=yes';
	}
	else
	{
		//RELOAD THE CURRENT PAGE TO GET LATEST PRODUCT PRICING
		location.reload();
	}
}	

function ShowTaxRegionBlock()
{		
	$.blockUI(
		{ 
			message:  $('#taxtype')		 
		});
	$("button").button();
}

function AskCustomerDetails()
{
	var sParam;
	var sReturn;
	
	sParam = 'method=SITE_COUNTRY_LIST_NAME'
	sReturn = onDemandSite(sParam);
	var aCountries = sReturn.split('|');
	$("#personalDetails").html('<p class="firstLine">Personal Details</p><div class="boxTop">&nbsp;</div><div id="contactus_form"><table style=border="0" cellspacing="0" cellpadding="0"><tbody>' + 
	'<tr><td align="right" valign="top" STYLE="width: 235px">First Name:</td><td align="left" valign="top"><input id="txtFirstName" class="txtFirstNameEnquiry" style=maxlength="20" name="txtFirstName" size="35" type="TEXT" /></td></tr>' +
	'<tr id="firstNameWarn" style="display: none;"></tr>' +
	'<tr><td align="right" valign="top">Last Name:</td><td align="left" valign="top"><input id="txtSurname" class="txtSurnameEnquiry" maxlength="20" name="txtSurname" size="35" type="TEXT" /></td></tr>' + 
	'<tr id="surnameWarn" style="display: none;"></tr>' +
	'<tr><td align="right" valign="top">Email:</td><td align="left" valign="top"><input id="txtEmail" class="txtEmailEnquiry" style=maxlength="30" name="txtEmail" size="35" type="TEXT" /></td></tr>' + 
	'<tr id="emailWarn" style="display: none;"></tr>' +
	'<tr><td align="right" valign="top">Confirm Email Address:</td><td align="left" valign="top"><input id="txtConfirmEmail" class="txtConfirmEmail" style= maxlength="30" name="txtConfirmEmail" size="35" type="TEXT" /></td></tr>' + 
	'<tr id="confirmEmailWarn" style="display: none;"></tr>' +
	'<tr><td align="right" valign="top">Contact Number:</td><td align="left" valign="top"><input id="txtContactNumber" class="txtContactNumberEnquiry" style=maxlength="20" name="txtContactNumber" size="35" type="TEXT" /></td></tr>' +
	'<tr id="contactNumberWarn" style="display: none;"></tr>' +
	'<tr><td align="right" valign="top">Postcode/Zipcode:</td><td align="left" valign="top"><input id="txtPostcode" class="txtPostcodeEnquiry" style=maxlength="15" name="txtPostcode" size="35" type="TEXT" /></td></tr>' + 
	'<tr id="postcodeWarn" style="display: none;"></tr>' +
	'<tr><td align="right" valign="top">Country:</td><td align="left" valign="top"><form> <select name="country" id=\'listCountries\' STYLE="width: 235px">' + aCountries[1] + '</select> </form></td></tr>' + 
	'<tr><td align="right" valign="top">How did you hear about us?</td><td align="left" valign="top"><form> <select name="howdidyouhear" id="howdidyouhear" STYLE="width: 235px"> <option value="please">Please Select...</option><option value="700">Google</option><option value="701">Search Engine (other)</option><option value="785">Facebook</option><option value="784">Twitter</option><option value="732">Kidspot</option><option value="702">Youtube</option> <option value="703">Internet (other)</option><option value="704">School or Teacher</option><option value="705">Family or Friend</option> <option value="706">Brochure</option><option value="707">Newspaper</option><option value="708">Magazine</option><option value="709">Radio</option><option value="710">Television</option><option value="711">Yellow Pages</option><option value="712">Popet Car</option><option value="713">Other</option></select> </form></td></tr>' +
	'<tr id="howDidYouHearWarn" style="display: none;"></tr>' +
	'<tr><td align="right">Choose Email Address for login:</td><td align="left" valign="top"><input id="txtUserName" class="txtUserName" style=maxlength="20" name="txtUserName" size="35" type="TEXT" /></td></tr>' +
	'<tr id="userNameWarn" style="display: none;"></tr>' +
	'<tr><td align="right" >Create Password:</td><td align="left" valign="top"><input id="txtPassword" type="password" class="txtPassword" style=maxlength="20" name="txtPassword" size="35" type="TEXT" /></td></tr>' + 
	'<tr><td align="right">Confirm Password:</td><td align="left" valign="top"><input id="txtConfirmPassword" type="password" class="txtConfirmPasswordEnquiry" style=maxlength="20" name="txtConfirmPassword" size="35" type="TEXT"/></td></tr>' +
	'<tr id="passwordWarn" style="display: none;"></tr>' +
	'<tr><td align="right">Receive free resources and updates?</td><td>&nbsp;&nbsp;<input name="newsletter" id="newsletter" type="checkbox" value="newsletter" /></td></tr></tbody></table></div><div id="paymentDetails">&nbsp;</div>');
	
	//DEFAULT COUNTRIES TO AUSTRALIA
	$('#listCountries').val("Australia");
	$('#txtFirstName').focus();
	//AUTO POPULATE USERNAME TO EMAIL IF EMAILS MATCH
	$('#txtUserName').focus(function () {
		if($('#txtConfirmEmail').val() == $('#txtEmail').val())
		{
			$('#txtUserName').val($('#txtConfirmEmail').val());
		}
	});
	
	//CHECK FIRSTNAME NOT BLANK
	$('#txtFirstName').blur(function () 
	{
		if($('#txtFirstName').val() == '')
		{
			$('#txtFirstName').css("background-color", "#FFBFBF");
			$('#firstNameWarn').html('<td>&nbsp;</td><td class="alertFont">Please enter your first name.</td>');
			$('#firstNameWarn').show();
		}
		else
		{
			$('#txtFirstName').css("background-color", "#FFFFFF");
			$('#firstNameWarn').hide();
		}
	});
	
	//CHECK SURNAME NOT BLANK
	$('#txtSurname').blur(function () 
	{
		if($('#txtSurname').val() == '')
		{
			$('#txtSurname').css("background-color", "#FFBFBF");
			$('#surnameWarn').html('<td>&nbsp;</td><td class="alertFont">Please enter your surname.</td>');
			$('#surnameWarn').show();
		}
		else
		{
			$('#txtSurname').css("background-color", "#FFFFFF");
			$('#surnameWarn').hide();
		}
	});
	
	//CHECK EMAIL NOT BLANK
	$('#txtEmail').blur(function () 
	{
		if($('#txtEmail').val() == '')
		{
			$('#txtEmail').css("background-color", "#FFBFBF");
			$('#emailWarn').html('<td>&nbsp;</td><td class="alertFont">Please enter your email address.</td>');
			$('#emailWarn').show();
		}
		else
		{
			$('#txtEmail').css("background-color", "#FFFFFF");
			$('#emailWarn').hide();
		}
	});
	
	//CHECK CONFIRMEMAIL NOT BLANK
	$('#txtConfirmEmail').blur(function () 
	{
		if($('#txtConfirmEmail').val() == '')
		{
			$('#txtConfirmEmail').css("background-color", "#FFBFBF");
			$('#confirmEmailWarn').html('<td>&nbsp;</td><td class="alertFont">Please confirm your email address.</td>');
			$('#confirmEmailWarn').show();
		}
		else
		{
			$('#txtConfirmEmail').css("background-color", "#FFFFFF");
			$('#confirmEmailWarn').hide();
		}
	});
	
	//CHECK CONTACT NUMBER NOT BLANK
	$('#txtContactNumber').blur(function () 
	{
		if($('#txtContactNumber').val() == '')
		{
			$('#txtContactNumber').css("background-color", "#FFBFBF");
			$('#contactNumberWarn').html('<td>&nbsp;</td><td class="alertFont">Please enter your contact number.</td>');
			$('#contactNumberWarn').show();
		}
		else
		{
			$('#txtContactNumber').css("background-color", "#FFFFFF");
			$('#contactNumberWarn').hide();
		}
	});
	
	//CHECK POSTCODE NOT BLANK
	$('#txtPostcode').blur(function () 
	{
		if($('#txtPostcode').val() == '')
		{
			$('#txtPostcode').css("background-color", "#FFBFBF");
			$('#postcodeWarn').html('<td>&nbsp;</td><td class="alertFont">Please enter your post or zip code.</td>');
			$('#postcodeWarn').show();
		}
		else
		{
			$('#txtPostcode').css("background-color", "#FFFFFF");
			$('#postcodeWarn').hide();
		}
	});
	
	//CHECK HOW DID YOU HEAR NOT STUCK ON PLEASE SELECT
	$('#howdidyouhear').blur(function () 
	{
		if($('#howdidyouhear').val() == 'please')
		{
			$('#howdidyouhear').css("background-color", "#FFBFBF");
			$('#howDidYouHearWarn').html('<td>&nbsp;</td><td class="alertFont">Please make a selection.</td>');
			$('#howDidYouHearWarn').show();
		}
		else
		{
			$('#howdidyouhear').css("background-color", "#FFFFFF");
			$('#howDidYouHearWarn').hide();
		}
	});
	
	//CHECK USERNAME NOT BLANK
	$('#txtUserName').blur(function () 
	{
		if($('#txtUserName').val() == '')
		{
			$('#txtUserName').css("background-color", "#FFBFBF");
			$('#userNameWarn').html('<td>&nbsp;</td><td class="alertFont">Please enter a valid email address.</td>');
			$('#userNameWarn').show();
		}
		else
		{
			$('#txtUserName').css("background-color", "#FFFFFF");
			$('#userNameWarn').hide();
		}
	});
	
	//PASSWORD CHECKS
	$('#txtConfirmPassword').blur(function () 
	{
		//CHECK IF PASSWORDBLANK
		if($('#txtPassword').val() != '')
		{
			//CHECK PASSWORDS MATCH
			if($('#txtPassword').val() == $('#txtConfirmPassword').val())
			{
				//CHECK PASSWORD IS LONGER THEN 6 CHARS
				if($('#txtPassword').val().length < 6)
				{
					$('#txtPassword, #txtConfirmPassword').css("background-color", "#FFBFBF");
					$('#passwordWarn').html('<td>&nbsp;</td><td class="alertFont">Please enter a password at least 6 characters long.</td>');
					$('#passwordWarn').show();
				}
				else
				{
					$('#txtPassword, #txtConfirmPassword').css("background-color", "#FFFFFF");
					$('#passwordWarn').hide();
				}
			}
			else
			{
				$('#txtPassword, #txtConfirmPassword').css("background-color", "#FFBFBF");
				$('#passwordWarn').html('<td>&nbsp;</td><td class="alertFont">Your passwords do not match.</td>');
				$('#passwordWarn').show();
			}
		}
		else
		{
			$('#txtPassword, #txtConfirmPassword').css("background-color", "#FFBFBF");
			$('#passwordWarn').html('<td>&nbsp;</td><td class="alertFont">Please enter a password.</td>');
			$('#passwordWarn').show();
		}
	});
}

function AskCustomerPayment()
{
	$("#paymentDetails").html('<p class="firstLine">Payment Options</p><div class="boxTop">&nbsp;</div><div id="contactus_form"><table style=border="0" cellspacing="0" cellpadding="0" width="540px"><tbody><tr><td valign="top"><div id="ccPay"><img align="right" src="/site/1125/VisaMasterCardCO.png" /></div>&nbsp;</td><td valign="top"><div id="payPal"><img align="right" src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" /></div>&nbsp;</td><td valign="top"><div id="faxMail"><img src="/site/1125/FaxPhoneMailCO.png" align="right"/></div>&nbsp;</td></tr></tbody></table>');
	//BIND MOUSEOVERS
	$("#ccPay, #payPal, #faxMail").mouseenter(function()
	{
		$(this).css("cursor", "pointer");
	});
	
	$("#ccPay").click(function(event)
	{
		if(CartItems())
		{
			AskCustomerForCC();
		}
	})
	
	$("#payPal").click(function(event)
	{
	//CHECK FOR AT LEAST ONE PRODUCT IN CART
		if(CartItems())
		{
			AskCustomerForPayPal();
		}
	})
		
	$("#faxMail").click(function(event)
	{
		//CHECK FOR AT LEAST ONE PRODUCT IN CART
		if(CartItems())
		{
			AskCustomerForFaxMail();
		}
	})
}

function AskCustomerForCC()
{		
	if(ValidateUserDetails())
	{
		$.blockUI(
		{ 
			message:  $('#payNow'),
			css: {width:"400px"}
		}); 
		var sTotal = $("#austotal").text() + ' ' + $("#othertotal").text();
		$("#totalcharge").text(sTotal);
		$("button").button();
		BindOK();
		$("#selectCCType").focus();
	
		$("#nextStepCC").mouseenter(function()
		{
			$(this).css("cursor", "pointer");
			$(this).attr({src: "/site/1125/ProcessPaymentOn.png"});
		}).mouseleave(function()
		{
			$(this).attr({src: "/site/1125/ProcessPaymentOff.png"});
		});
		$("#nextStepCC").unbind('click');
		$("#nextStepCC").click(function(event)
		{
			if(CreateUser())
			{
				//CHECK FOR AT LEAST ONE PRODUCT IN CART
				giPayType = 1;
				ProcessOrder();
			}
			else
			{
				UsernameInUse();
			}
		}); 
	}
	else
	{
		ShowDetailsMessage();
	}
}

function UsernameInUse()
{
	$.blockUI(
	{ 
		message:  $('#usernameuse')
	}); 
	$("button").button();	
	BindOK();
}

function CreateUser()
{
	if(giLoggedIn != 1) //CHECK FOR USER NOT LOGGED IN
	{
		var sParam;
		var sReturn;
					
		//BUILD SPARAM TO REGISTER TO SITE 1214 Shadow SITE
		/*Will also add to allow news alerts also tonight via &sendnews=1 to turn on.
		If want to record at "extra tab" information (record in Surney) us &sq[questionid]=[text / or choiceid]
		eg &sq1234=3456 or &sq1235=Blue
		1. To set Currency use SITE_CURRENCY_SET&site=XXX&select=[id as per attached xls]
		sq5812= 27548 (PLAIN)
		sq5812= 27545 (NSW)
		sq5812= 27546 (VIC)
		sq5812= 27547 (QLD)
		*/

		sParam = 'method=REGISTER_SITE_ADD_USER&site=1214&passworddaystoexpire=10000&currency=' + giCurrency +  '&taxtype=' + giTaxRegion + '&dontupdate=1' + '&emaildocument=29824';
			
		//CHECK IF THE NEWSLETTER CHECKBOX HAS BEEN TICKED
		if($('#newsletter').attr('checked'))
		{
			sParam = sParam + '&sendnews=1';
		}
		else
		{
			sParam = sParam + '&sendnews=0';
		}
				
		sParam = sParam + '&firstname=' + $('#txtFirstName').val() +
				'&surname=' + $('#txtSurname').val() +
				'&email=' + $('#txtEmail').val() + '&logonname=' + $('#txtUserName').val() + 
				'&phone=' + $('#txtContactNumber').val() + '&streetpostcode=' + $('#txtPostcode').val() + 
				'&streetcountry=' + $('#listCountries').val() + '&password=' + $('#txtPassword').val() + 
				'&sourceofcontact=' + $('#howdidyouhear').val() + '&sq5812=' + giMemberStyleId;
		
		sReturn = onDemandRegister(sParam);
		var aValues = sReturn.split('|');
		
		if (aValues[3] == 'LOGON_NAME_USED')
		{
			return false;
		}
		else 
		{
			$.blockUI(
			{ 
				message:  '<h1>User created...</h1>',
				timeout: 500
			}); 
			AutoLogin();
			return true; //USER IS LOGGED IN
		}
	}
	else
	{
		return true; //USER IS LOGGED IN
	}
}

function CreateOrder()
{
	$.unblockUI();
	var sParam;
	var sReturn;
	//CHECK FOR NOT PAYPAL
	if(giPayType != 2)
	{
		//BUILD SPARAM FOR FIRST ORDER SUBMIT
		//STATUS OF 2 IS TO BE PROCESSED
		//ORDER IS CREATED, EMAILED AND LEFT AT STATUS OF TO BE PROCESSED
		var sSource = GetSourceVariable();
		sParam ='method=SITE_ORDER_SUBMIT&site=' + msOnDemandSiteId + 
			'&usesourceassalesperson=1' + // '&usesourceassalespersonreference=1' 
			'&status=2' +
			'&nosystemtemplate=1' + 
			'&orderaction=0' +
			'&salescontactpersonreference=' + sSource;
		//CCPAYMENT KEEP PRODUCTS IN CART JUST INCASE OF FAIL
		if(giPayType == 1)
		{
			sParam = sParam + '&keepproductsincart=1';
		}
		
		//FAXMAIL NEEDS TO BE INVOICED STRAIGHT UP
		if(giPayType == 3)
		{
			sParam = sParam + '&autoinvoice=1' + '&invoicedocument=28089';
		}
		
		//IF THERE ARE CUSTOM PRODUCTS
		if(giCustomOrder != 0)
		{
			sParam = sParam + '&processingstatus=53';
		}
		
		sReturn = onDemandSite(sParam);
		var aReturn = sReturn.split('|');
			
		if(aReturn[0] == 'OK')
		{
			//CHECK ITS NOT A FAXMAIL ORDER
			if(giPayType != 3)
			{
				ConfirmPayment();
			}
			//IT IS A FAXMAIL ORDER
			else
			{
				$.blockUI(
				{ 
					message:  "<h1>Completing Order...</h1>",
					fadeIn:0
				});
			}
		}
		else
		{
			alert("An error has occurred while submitting your order, please try again later.");
		}
	}
	//THIS IS PAYPAL	
	else
	{
		$.blockUI(
			{
				message:  '<h1>Transferring to PayPal...</h1>',
				fadeIn: 0,
				timeout: 1000
			});
		
		var cTotal = + GetTotal();
		sParam = 'method=SITE_COLLECT_PAYMENT&site=' + escape(msOnDemandSiteId) + '&select=' + escape('72') + '&currencycode=' +  escape('AUD') + '&totalamount=' + cTotal;
		sReturn = onDemandSite(sParam);
		var aReturn = sReturn.split('|');
		window.location.href = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + aReturn[2];
			
	}
}

function ConfirmPayment()
{
	var sParam;
	var sReturn;
	//BUILD SPARAM FOR SECOND ORDER SUBMIT - PAYMENT VERIFY 
	//STATUS OF 1 IS ORDER COMPLETED
	//ORDER IS COMPLETED BILLED AND MARKED AS COMPLETED IF SUCCESSFUL
	sParam = 'method=SITE_ORDER_SUBMIT&site=' + msOnDemandSiteId + 
			'&collectpaymentaccount=67' + 
			'&ccname=' + $('#txtCardHoldersName').val() +
			'&ccnumber=' + $('#txtCardNumber').val() +
			'&ccexpirymonth=' + $('#selectExpireMonth').val() +
			'&ccexpiryyear=' + $('#selectExpireYear').val() +
			'&autoreceipt=1' + 
			'&status=1' + 
			'&nosystemtemplate=1' + 
			'&autoinvoice=1' + 
			'&invoicedocument=28089';
	
	//IF THERE ARE CUSTOM PRODUCTS
	if(giCustomOrder != 0)
	{
		sParam = sParam + '&processingstatus=53';
	}
	
	var d = new Date();
	var curr_date = d.getDate();
	var curr_month = d.getMonth();
	curr_month++;
	var curr_year = d.getFullYear();
	sParam = sParam + '&deliverydate=' + curr_date + "/" + curr_month + "/" + curr_year;
	
	//USER HAS ALREADY LOGGED IN
	if(giLoggedIn == 1)
	{
		var sFirstName = $("#txtFirstName").text();
		var sSurname = $("#txtSurname").text();
		var sEmail = $("#txtEmail").text();
		var sPostcode = $("#txtPostcode").text();
	}
	else
	{	
		var sFirstName = $("#txtFirstName").val();
		var sSurname = $("#txtSurname").val();
		var sEmail = $("#txtEmail").val();
		var sPostcode = $("#txtPostcode").val();		
	}
	sParam = sParam	+ '&firstname=' + sFirstName +
			'&surname=' + sSurname +
			'&email=' + sEmail +
			'&postcode=' + sPostcode;
			//'&reference=' + sReference; 	
	var cTotal = GetTotal();
	sParam = sParam + '&totalamount=' + cTotal;
	sReturn = onDemandSite(sParam);
	var aReturn = sReturn.split('|');
	var sEwayReturn = aReturn[0];
	
	//PAYMENT SUCCESS
	if(sEwayReturn == 'OK')
	{
		$.blockUI(
		{ 
				message:  $('#payresponseok'),
				fadeIn:0
		});
		
		$('#ok').click(function() 
		{
			$.unblockUI();
			window.location.href = '/popet_myspot';
		});
	}
	else
	{
		$.blockUI(
			{ 
				message:  $('#payresponsefail'),
				fadeIn:0
			});
		
		$('#retry').click(function() 
		{
			//SHOW THE USER THEIR CURRENT DETAILS
			$("#askCustomerType").html('');
			ShowCustomerDetails();
			AskCustomerPayment();
			$.unblockUI();		
		});
		
		$('#callpopet').click(function() 
		{
			var sParam = 'method=SITE_ORDER_SEARCH&summary=1&site=' + msOnDemandSiteId;
		
			$.ajax({
				type: 'GET',
				url: '/directory/ondemand/site.asp?' + sParam,
				dataType: 'text',
				success: function(data, textStatus, XMLHttpRequest) 
				{
					sReturn = data;
					aReturn = sReturn.split('|');
					var iOrderID = aReturn[2];
					
					//REMOVE ITEMS FROM CART AND COMPLETE ORDER
					sParam ='method=SITE_ORDER_SUBMIT&site=' + msOnDemandSiteId + '&status=2' + '&orderaction=0' + '&autoinvoice=1' + '&invoicedocument=28089' + '&nosystemtemplate=1';
					//IF THERE ARE CUSTOM PRODUCTS
					if(giCustomOrder != 0)
					{
						sParam = sParam + '&processingstatus=53';
					}
					
					sReturn = onDemandSite(sParam);
									
					//CHECK WHICH COUNTRY THEY HAVE AS THEIR DEFAULT
					if($("#userCountry").text() == "Australia")
					{
						$.blockUI(
						{ 
							message:  $('<div id="phonepopet"><img class="dialogimg" src="/site/1125/phoneButton.png" alt="" /><span class="dialogfirstLine">&nbsp;Call Popet Education</span><br /><br /><p style="font-size:14px; margin: 0px 0px 0px 0px">Please call <strong>1300 419 148</strong> or <strong>02 8094 1890</strong> and quote Order Number <strong>' + iOrderID + '</strong> to complete your payment over the phone.</p><p style="text-align: center;"><button id="okphone">OK</button></p></div>'),
							fadeIn: 0
						});
					}
					//INTERNATIONAL
					else
					{
						$.blockUI(
						{ 
							message:  $('<div id="phonepopet"><img class="dialogimg" src="/site/1125/phoneButton.png" alt="" /><span class="dialogfirstLine">&nbsp;Call Popet Education</span><br /><br /><p style="font-size:14px; margin: 0px 0px 0px 0px">Please call <strong>+61 2 8094 1890</strong> and quote Order Number <strong>' + iOrderID + '</strong> to complete your payment over the phone.</p><p style="text-align: center;"><button id="okphone">OK</button></p></div>'),
							fadeIn: 0	
						});
					}
					$("button").button();
					$('#okphone').click(function() 
					{
						$.unblockUI();
						SendFaxMailUser(iOrderID);
					});
				}
			});
		});



		$('#requestcall').click(function() 
		{
			var sParam = 'method=SITE_ORDER_SEARCH&summary=1&site=' + msOnDemandSiteId;
			$.ajax({
				type: 'GET',
				url: '/directory/ondemand/site.asp?' + sParam,
				dataType: 'text',
				async: false,
				success: function(data, textStatus, XMLHttpRequest) 
				{
					sReturn = data;
					aReturn = sReturn.split('|');
					var iOrderID = aReturn[2];
					var sContactNumber = $("#CustContactNo").text();
					$.blockUI(
					{ 
						message:  $('<div id="callbackpopet" style="display: none;"><img class="dialogimg" src="/site/1125/phoneButton.png" alt="" /><span class="dialogfirstLine">&nbsp;Phone Details</span><br /><br /><p style="font-size: 14px; margin: 0px 0px 0px 0px;">Please confirm your phone number for a call-back from our first available operator.</p><br /><table border="0" cellspacing="0" cellpadding="2" width="100%"><tbody><tr><td align="right" valign="middle"><span style="font-size: 12px; margin: 0px 0px 0px 0px;">Phone Number:</span></td><td align="left" valign="middle"><input id="txtRequestContactNumber" type="text" /></td></tr><tr><td align="right" valign="middle"><span style="font-size: 12px; margin: 0px 0px 0px 0px;">Message:</span></td><td align="left" valign="middle"><textarea id="CustomerMessage" cols="20" rows="3" name="CustomerMessage"></textarea></td></tr><tr><td colspan=2><p style="text-align: center;"><button id="okcallpay">Request Call-back</button></p></td></tr></tbody></table></div>'),
						fadeIn: 0	
					});
					$("button").button();
					$("#txtRequestContactNumber").val(sContactNumber);
					$("#okcallpay").click(function() 
					{
						sContactNumber = $("#txtRequestContactNumber").val();
						var sCustomerMessage = $("#CustomerMessage").val();
						var d = new Date();
						var curr_date = d.getDate();
						var curr_month = d.getMonth();
						curr_month++;
						var curr_year = d.getFullYear();
						//CREATE THE ACTION
						sParam = 'method=SITE_ACTION_ADD&actionby=19004&site=1203&type=672&date=' + curr_date + "/" + curr_month + "/" + curr_year + '&description=Order Reference: ' + iOrderID + ' Contact Number: ' + sContactNumber + ' Customer Message: ' + sCustomerMessage;
						sReturn = onDemandSite(sParam);
						//CREATE THE EMAIL
						sParam = 'method=MESSENGER_SEND_EMAIL&select=1000386743&subject=New Call-back Requested&message=An Order has been placed and the customer has requested a Call-back with the following details:<br /><br/>' + 'Order Reference: <strong>' + iOrderID + '</strong><br />' + 'Contact Number: <strong>' + sContactNumber + '</strong><br />' + 'Message: <strong>' + sCustomerMessage + '</strong><br />';
						sReturn = onDemandSend(sParam);
						//REMOVE ITEMS FROM CART AND COMPLETE ORDER
						sParam ='method=SITE_ORDER_SUBMIT&site=' + msOnDemandSiteId + '&status=2' + '&orderaction=0' + '&autoinvoice=1' + '&invoicedocument=28089' + '&nosystemtemplate=1';
						//IF THERE ARE CUSTOM PRODUCTS
						if(giCustomOrder != 0)
						{
							sParam = sParam + '&processingstatus=53';
						}
						sReturn = onDemandSite(sParam);
						SendFaxMailUser(iOrderID);
					});
					
				}
			});
		});	
	}
}
			

function AskCustomerType()
{
	$("#askCustomerType").html("<table><tbody><tr style='width:600px'><td style='width:300px'><img id='newCustomer' src='/site/1125/NewCustomerOff.png'></img></td><td style='width:300px'><img id='returningCustomer' src='/site/1125/HaveAccountOff.png'></img></td></tr>");
			
	$("#returningCustomer").mouseenter(function()
	{
		$(this).css("cursor", "pointer");
		$(this).attr({src: "/site/1125/HaveAccountOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/HaveAccountOff.png"});
	});	
			
	$("#newCustomer").mouseenter(function()
	{
		$(this).css("cursor", "pointer");
		$(this).attr({src: "/site/1125/NewCustomerOn.png"});
	}).mouseleave(function()
	{
		$(this).attr({src: "/site/1125/NewCustomerOff.png"});
	});
}	

function AskCustomerForPayPal()
{
	if(ValidateUserDetails())
	{
		if(CreateUser())
		{
			giPayType = 2;
			ProcessOrder();
		}
		else
		{
			UsernameInUse();
		}
	}
	else
	{
		ShowDetailsMessage();
	}
}

function CheckPayPalPayment()
{
	var aPayReturn = msOnDemandContextId.split('=');
	if( msOnDemandContextId.indexOf("&PayerID=") != -1 )
	{
		//HAVE TO FORCE A SHOW CART IN ORDER TO CHECK FOR CUSTOM BOOKS
		CheckForCustom();
		
		var cTotal = + GetTotal();
		
		$.blockUI(
			{
				message: '<div id="paypayfinalconfirm"><img class="dialogimg" src="/site/1125/tickButton.png" alt="" /><span class="dialogfirstLine">&nbsp;Please confirm payment:</span><br /><br /><p style="font-size:14px; margin: 0px 0px 0px 0px">PayPal funds to be transferred: <strong>$' + cTotal + '</strong></p><br /><p style="text-align: center;"><button id="cancel">Cancel</button>&nbsp;&nbsp;<button id="finishpaypal">Transfer Funds</button></p></div>',
				fadeIn: 0
			});
		$("button").button();
		
		$('#finishpaypal').click(function() 
		{
			$.blockUI(
			{
				message:  '<h1>Completing Order...</h1>',
				fadeIn: 0
			});
			sParam ='method=SITE_ORDER_SUBMIT&site=' + msOnDemandSiteId + 
					'&usesourceassalesperson=1' + // '&usesourceassalespersonreference=1' 
					'&collectpaymentaccount=72' + // 71 is test 72 is live
					'&totalamount=' + cTotal +
					'&status=1' +
					'&nosystemtemplate=1' + 
					'&autoinvoice=1' + 
					'&autoreceipt=1' +
					'&invoicedocument=28089' + '&payer=' + aPayReturn[2];
					
			//IF THERE ARE CUSTOM PRODUCTS
			if(giCustomOrder != 0)
			{
				sParam = sParam + '&processingstatus=53';
			}			
					
			var d = new Date();
			var curr_date = d.getDate();
			var curr_month = d.getMonth();
			curr_month++;
			var curr_year = d.getFullYear();
					
			sParam = sParam + '&deliverydate=' + curr_date + "/" + curr_month + "/" + curr_year;
			sReturn = onDemandSite(sParam);
				
			ShoweWorkbooks();
			UpdateCartBar();
			
			$.blockUI(
			{ 
				message:  $('#payresponseokpaypal'),
				fadeIn:0
			});
		
			$('#okpay').click(function() 
			{
				$.unblockUI();
			});
		});

		$('#cancel').click(function() 
		{
			window.location.href = '/';
		});	
		
	}
	else
	{
		
	}
}

function AskCustomerForFaxMail()
{
	if(ValidateUserDetails())
	{
		AskCustomerCallBack();
	}
	else
	{
		ShowDetailsMessage();
	}
}

function AskCustomerCallBack()
{
	var iOrderRef = GetOrderRef();
	var sParam;
	var oXML;
	var oRoot;
	if(giLoggedIn != 1)
	{
		var sContactNumber = $("#txtContactNumber").val();
	}
	else
	{
		var sContactNumber = $("#CustContactNo").text();
	}
		$.blockUI(
		{ 
			message:  '<div id="faxmailquestion"><img class="dialogimg" src="/site/1125/phoneButton.png" alt="" /><span class="dialogfirstLine">&nbsp;Phone, Fax & Mail Orders</span><br/><p><span style="font-size:14px">Please confirm your contact details for a Call-back to complete your payment over the phone <strong>or</strong> click Continue to display and print your invoice for fax and mail orders.</span></p><table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td align="right"><span style="font-size: 12px; margin: 0px 0px 0px 0px;">Phone Number:</span></td><td><input id="txtRequestContactNumber" style=maxlength="20" size="20" type="TEXT" value="' + sContactNumber + '" /></td></tr><tr><td align="right"><span style="font-size: 12px; margin: 0px 0px 0px 0px;">Message:</span></td><td><TEXTAREA id="CustomerMessage" COLS=20 ROWS=3></TEXTAREA></td></tr></table><p style="text-align: center;"><button id="confirmcallback">Confirm Call-Back</button>&nbsp;&nbsp;<button id="continue">Continue</button>&nbsp;&nbsp;<button id="stop">Cancel</button></p></div>',
			fadeIn: 250	
		});
	$("button").button();
	$('#confirmcallback').click(function() 
	{
		sContactNumber = $("#txtRequestContactNumber").val();
		var sCustomerMessage = $("#CustomerMessage").val();
		
		if(CreateUser())
		{
			giPayType = 3;
			ProcessOrder();	
			//CUSTOMER REQUESTS A CALLBACK	
			//SUBMIT THE ACTIVITY ACTION/EMAIL
			$.blockUI(
			{ 
				message:  $('<h1>Sending Request...</h1>'),
				fadeIn: 0,
				timeout: 1000
			});
					
			var d = new Date();
			var curr_date = d.getDate();
			var curr_month = d.getMonth();
			curr_month++;
			var curr_year = d.getFullYear();
			
			//19004 is peterk@popet.com.au user id on myws
			sParam = 'method=SITE_ACTION_ADD&actionby=19004&site=1203&type=673&date=' + curr_date + "/" + curr_month + "/" + curr_year + '&description=Order Reference: ' + iOrderRef + ' Contact Number: ' + sContactNumber + ' Customer Message: ' + sCustomerMessage;
			sReturn = onDemandSite(sParam);
			sParam = 'method=MESSENGER_SEND_EMAIL&select=1000386743&subject=New Call-back Requested&message=An Order has been placed and the customer has requested a call-back to collect payment with the following details:<br /><br/>' +
			'Order Reference: <strong>' + iOrderRef + '</strong><br />' + 
			'Contact Number: <strong>' + sContactNumber + '</strong><br />' + 
			'Message: <strong>' + sCustomerMessage + '</strong><br />';
			sReturn = onDemandSend(sParam);
			
			SendFaxMailUser(iOrderRef);
		}
		else
		{
			UsernameInUse();
		}
	});

	$('#continue').click(function() 
	{
		if(CreateUser())
		{
			giPayType = 3;
			ProcessOrder();	
			
			//SUBMIT ACTIVITY TO PETER TO FOLLOW UP PAYMENT IF NOT RECIEVED AFTER 7 DAYS
			var d = new Date();
			d.setDate(d.getDate() + 7);// Add 7 days
			
			var new_date = d.getDate();
			var new_month = d.getMonth();
			new_month++;
			var new_year = d.getFullYear();
			//19004 is peterk@popet.com.au user id on myws
			sParam = 'method=SITE_ACTION_ADD&actionby=19004&site=1203&type=672&date=' + new_date + "/" + new_month + "/" + new_year + '&description=This is just a reminder to follow up payment for order ' + iOrderRef;
			sReturn = onDemandSite(sParam);

			SendFaxMailUser(iOrderRef);
		}
		else
		{
		UsernameInUse();
		}
	});
	
	$('#stop').click(function() 
	{
		$.unblockUI();
	});
}

function SendFaxMailUser(iOrderRef)
{
	var sParam;
	var oXML;
	var oRoot;
	var iOrderRef;
	//DO A SEARCH TO FIND THE INVOICE SO WE CAN OPEN IT
	sParam = 'method=SITE_ORDER_SEARCH&site=' + msOnDemandSiteId + '&includeinvoices=1'
	oXML = onDemandSiteXML(sParam);
	oRoot = oXML.getElementsByTagName("ondemand").item(0);
	var iInvoiceCreated;
	
	for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
	{
		var oRow = oRoot.childNodes.item(iRow);
		if(onDemandXMLGetData(oRow, "reference") == iOrderRef)
		{
			var sOrderString = onDemandXMLGetData(oRow, "reference");
			var sInvoiceString = onDemandXMLGetData(oRow, "invoices");
			var aInvoiceId = sInvoiceString.split('#');
			iInvoiceCreated = aInvoiceId[1];
		}
	}
	
	//OPEN THE INVOICE FOR THE USER
	window.open('https://popet.myworkspace.com/popetinvoice/' + iInvoiceCreated);
	//SEND THE BACKGROUND WINDOW TO MYSPOT
	window.location.href = '/popet_myspot';
}

function ShowProducts(alCategoryId, iStartRow)
{
	var sParam;
	var oXML;
	var oRoot;
	var oRow;
	var aHTML = [];
	var h = -1;
	var iRows = 50;
	var iCols = 2;
	
	//BUILD METHOD FOR ON DEMAND QUERY OF PRODUCTS
	sParam = 'method=SITE_PRODUCT_SEARCH&site=' + msOnDemandSiteId + '&includeprice=1&includeimage=1&notingroup=1&columns=' + iCols + '&rows=' + iRows + '&startrow=' + iStartRow + '&category=' + alCategoryId;
	
	oXML = onDemandSiteXML(sParam);
	oRoot = oXML.getElementsByTagName("ondemand").item(0);
	oRow = oRoot.childNodes.item(0);
		
	//CREATE TABLE HEADER
	aHTML[++h] = '<table class="pro_tab" border="0">';
	aHTML[++h] = '<tbody>'

	//CHECK FOR RETURNED RESULTS
	if (oRoot.childNodes.length > 0)
	{
		//LOOP THROUGH RETURNED RESULTS AND BUILD TABLE
		for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
		{
			var oRow = oRoot.childNodes.item(iRow);
			
			//CHECK THAT THE PRODUCT TITLE IS NOT BLANK
			if (onDemandXMLGetData(oRow, "title") != '' && onDemandXMLGetData(oRow, "shopstatus") != '2')
			{
				
				var iRowCount = parseInt(onDemandXMLGetData(oRow, "rowcount"));
				
				if (parseInt(onDemandXMLGetData(oRow, "colnumber")) == 1)
				{
					aHTML[++h] = '<tr>';
				}	

				aHTML[++h] = '<td class="pro_thumb"><img style="border: 0pt none;" id="img"' + onDemandXMLGetData(oRow, "id") + '" src="' +  onDemandXMLGetData(oRow, "imageurl") +	'" alt="' + onDemandXMLGetData(oRow, "title") + '" width="100" height="87" /></td>';
				aHTML[++h] = '<td class="pro_blurb">';
				aHTML[++h] = '<h2>' + onDemandXMLGetData(oRow, "title") + '</h2>';
				
				//CHECK IF THE TITLE DOES NOT MATCH THE DESCRIPTION
				if (onDemandXMLGetData(oRow, "title") != onDemandXMLGetData(oRow, "description"))
				{
					aHTML[++h] = '<p>' + onDemandXMLGetData(oRow, "description") + '</p>';
				}
				//CHECK IF PRODUCT TYPE IS EQUAL TO 1
				if (parseInt(onDemandXMLGetData(oRow, "type")) == 1)
				{
					aHTML[++h] = '<p><a href="#" class="moreinformation" id="' + onDemandXMLGetData(oRow, "id") + '"' +	'>More info...</a></p>';
					aHTML[++h] = '<table border="0" cellspacing="0" cellpadding="0" align="right">';
					aHTML[++h] = '<tbody>';
					aHTML[++h] = '<tr>';
					aHTML[++h] = '<td class="pro_price">$' + onDemandXMLGetData(oRow, "price") + '<br /></td>';
					
					//CHANGE THIS
					aHTML[++h] = '<td><img id="product-' + onDemandXMLGetData(oRow, "id") + '"' +
							' class="addtocart" style="border: 0pt none;" src="/site/1068/addtocart.gif" onmouseover="this.src=\'/site/1068/addtocarth.gif\';" onmouseout="this.src=\'/site/1068/addtocart.gif\';" alt="Add To Cart" title="Buy Now" width="82" height="23" /></td>';
					aHTML[++h] = '</tr>';
					aHTML[++h] = '</tbody>';
					aHTML[++h] = '</table>';
				}
				else
				{
					aHTML[++h] = '<table border="0" cellspacing="0" cellpadding="0" align="right">';
					aHTML[++h] = '<tbody>';
					aHTML[++h] = '<tr>';
					//CHANGE THIS
					aHTML[++h] = '<td><img id="expand-' + onDemandXMLGetData(oRow, "id") + '"' +
							' class="moreinformation" style="border: 0pt none;" src="expand_down.png" /></td>';
					aHTML[++h] = '</tr>';
					aHTML[++h] = '</tbody>';
					aHTML[++h] = '</table>';
				}
				aHTML[++h] = '</td>';		
					
				if (parseInt(onDemandXMLGetData(oRow, "colnumber")) == iCols)
				{
					aHTML[++h] = '</tr>';
				}
				else
				{
					aHTML[++h] = '<td class="pro_td_space">&nbsp;</td>';
				}
				
			}
		}

		if (parseInt(onDemandXMLGetData(oRow, "colnumber")) != iCols)
		{
			aHTML[++h] = '<td colspan=' + (iCols - parseInt(onDemandXMLGetData(oRow, "colnumber"))) + '></td></tr>';
		}

	}
	else
	{
		aHTML[++h] = '<tr><td valign="top">No products</td></tr>';
	}

	aHTML[++h] = '</tbody></table>';

	$("#divProducts").html(aHTML.join(''));
}

//SHOWS DETAILS IN CHECKOUT PAGE
function ShowCustomerDetails()
{
	// ALLOCATE REQUIRED VARIABLES
	var sParam;
	var oXML;
	var oRoot;
	var oRow;
		
	sParam = 'method=SITE_PERSON_SEARCH&advanced=1&site=' + msOnDemandSiteId
	
	oXML = onDemandSiteXML(sParam);
	oRoot = oXML.getElementsByTagName("ondemand").item(0);
	
	// CHECK IF ANY PRODUCTS WERE RETURNED
	if (oRoot.childNodes.length == 0)
	{
		$("#personalDetails").html('<p>No Details were Found...</p>');
	}
	else
	{
		
		// LOOP THROUGH THE RESULTS AND ADD EXTRA ROWS TO TABLE ON EACH PASS
		for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
		{
			var oRow = oRoot.childNodes.item(iRow);
						
			$("#personalDetails").html('<p class="firstLine">You are logged in, your personal details are below:</p><div class="boxTop">&nbsp;</div><div id="contactus_form"><table  style=border="0" cellspacing="0" cellpadding="5"><tbody><tr>' + 
	'<td align="right" class="font_orange" valign="top">First Name:<br /></td><td align="left" valign="top" id="txtFirstName">' + onDemandXMLGetData(oRow, "firstname") + '</td>' +
	'<td align="right" class="font_orange" valign="top">Last Name:</td><td class="tabRight" align="left" valign="top" id="txtSurname">' + onDemandXMLGetData(oRow, "surname") + '</td></tr>' + 
	'<tr><td align="right" class="font_orange" valign="top">Email:</td><td align="left" valign="top" id="txtEmail">' + onDemandXMLGetData(oRow, "email") + '</td>' + 
	'<td>&nbsp;</td><td align="left" valign="top">&nbsp;</td></tr><tr><td  align="right" valign="top" class="font_orange">Contact Number:</td><td id="CustContactNo" align="left" valign="top">' + onDemandXMLGetData(oRow, "phone") + '</td>' + 
	'<td align="right" valign="top" class="font_orange">Postcode/Zipcode:</td><td class="tabRight" align="left" valign="top" id="txtPostcode">' + onDemandXMLGetData(oRow, "streetpostcode") + '</td></tr>' + 
	'<tr><td align="right" valign="top" class="font_orange">Country:</td><td align="left" valign="top"><span id="userCountry">' + onDemandXMLGetData(oRow, "streetcountry") + '</span></td><td>&nbsp;</td>' + 
	'<td></td></tr>' + '</tbody></table></div><div id="paymentDetails">&nbsp;</div>');
		}
	}
}

function AddProductToCart(sProduct, lQuantity)
{
	var aProduct = sProduct.split('-');
	var sReturn;
	var sParam;
	var oXML;
	var oRoot;
	var oRow;
	
	var iProductID = aProduct[1]; 
	
	sParam = 'method=SITE_ORDER_ADD_PRODUCT&site=' + msOnDemandSiteId + '&quantity=1&taxtype=' + giTaxRegion + '&product=' + aProduct[1]
	
	var sTmp = $('#inputChildName-' + aProduct[1]).val()
	
	//CHECK FOR CUSTOM PRODUCT
	if (sTmp == undefined)
	{
		ShowTimer();
		AddToCartAnimation();
		$.ajax({
		type: 'GET',
		url: '/directory/ondemand/site.asp?' + sParam,
		dataType: 'text',
		//async: false,
		success: function(data, textStatus, XMLHttpRequest) 
			{
				//CHECK IF USER HAS ALREADY DEFINED THEIR STYLE ID
				if(giMemberStyleId == -1)
				{
					AskScriptType(iProductID);
				}
				UpdateCartBar();
				ShowProductCart(1);
			}
		})
	}
	else
	{
		//THE PRODUCT TO BE ADDED IS A CUSTOM PRODUCT AND THE ENTRY FIELD IS BLANK
		if(sTmp == '' || sTmp == "Child's name...")
		{
			alert("Please enter your child's name..");
		}
		//THE PRODUCT TO BE ADDED IS A CUSTOM PRODUCT AND THE ENTRY FIELD POPULATED
		else
		{
			ShowTimer();
			//CHECK IF USER HAS ALREADY DEFINED THEIR STYLE ID
			if(giMemberStyleId == -1)
			{
				AskScriptType(iProductID);
			}
			AddToCartAnimation();
			
			//CHANGE THIS IF ADD ANOTHER COMBO PACK
			if(aProduct[1] == '11271')
			{
				sParam = sParam + 
					'&description=' + 'My Name Is . . . (Ages 3 - 4) - ' + sTmp + 
					'&notes=' + sTmp + 
					'&allowmultiple=1';
			}
			
			//CHANGE THIS IF ADD ANOTHER COMBO PACK
			if(aProduct[1] == '11297')
			{
				sParam = sParam + 
					'&description=' + 'Pink Combo Pack (Ages 3 - 4) - ' + sTmp + 
					'&notes=' + sTmp;
			}
				
				
			$.ajax({
			type: 'GET',
			url: '/directory/ondemand/site.asp?' + sParam,
			dataType: 'text',
			success: function(data, textStatus, XMLHttpRequest) 
				{
					UpdateCartBar();
					ShowProductCart(1);
				}
			})
		}
	}
}

function ShowTimer()
{
	$("#cartNotify").attr({src: '/site/1125/TimerCart.gif'});
}

function AskScriptType(iProductID)
{
	var iProductID;
	var sReturn;
	var sParam;
	var oXML;
	var oRoot;
	var oRow;

	sParam = 'method=SITE_PRODUCT_SEARCH&site=' + msOnDemandSiteId + '&select=' + iProductID + '&includeattachments=1&attachmenttype=205' + '&rf=XML';
	$.ajax({
		type: 'GET',
		url: '/directory/ondemand/site.asp?' + sParam,
		dataType: 'xml',
		success: function(data, textStatus, XMLHttpRequest) 
		{
			oXML = data;
			oRoot = oXML.getElementsByTagName("ondemand").item(0);
	
			if (oRoot.childNodes.length == 0)
			{
				alert("error");
			}
			else
			{
				for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
				{
					var oRow = oRoot.childNodes.item(iRow);
											
					//CHECK FOR GENERIC ATTACHMENT IF NOT EXIST THEN ASK FOR SCRIPT 
					if(onDemandXMLGetData(oRow, "attachments") == '')
					{
						DisplayScriptTypeQuestion();
					}
				}
			}
		}
	})
}


function DisplayScriptTypeQuestion()
{
	var sReturn;
	var sParam;
	$.blockUI(
	{ 
		message:  $('#selectscriptstyle')		 
	});
	$('#currentscriptstyle').val(giMemberStyleId);
	$('#currentscriptstyle').change(function()
	{
		giMemberStyleId=$('#currentscriptstyle option:selected').val();
	});
	$('#scriptstylesave').click(function() 
	{
		if(giMemberStyleId == -1)
		{
			alert("Please select a Script Style...");
		}
		else
		{
			$.blockUI(
			{ 
				fadeIn: 0,
				message: "<h1>Saving Script Style...</h1>",
				timeout: 250
			}); 
		//SET VARIABLE ON THE SERVER
		sParam = 'method=SITE_SET_SESSION_VARIABLE&site=' + msOnDemandSiteId + '&variable=userstyleid&value=' + giMemberStyleId;
		sReturn = onDemandSite(sParam);
		}
	});
}

function RemoveProductFromCart(sProduct)
{
	ShowTimer();
	var aProduct = sProduct.split('-');
	var sReturn = '';
	var sParam = '';

	sParam = 'method=SITE_ORDER_REMOVE_PRODUCT&site=' + msOnDemandSiteId + '&product=' + aProduct[1];
	
	$.ajax({
			type: 'GET',
			url: '/directory/ondemand/site.asp?' + sParam,
			dataType: 'text',
			success: function(data, textStatus, XMLHttpRequest) 
			{
				ShowProductCart(1);
				if(msOnDemandDocumentId == 28609)
				{	//REFRESH FULL CART TOO, AS YOU ARE ON THE CHECKOUT PAGE	
					ShowProductCart(2);
				}
				UpdateCartBar();
			}
	})
		
}

function CheckForCustom()
{
	var sParam;
	var oXML;
	var oRoot;
	var oRow;
	sParam = 'method=SITE_ORDER_PRODUCT_SEARCH&cart=1&includeproducts=1&site=' + msOnDemandSiteId + '&shoporderonly=1' + '&rf=XML'
	$.ajax({
			type: 'GET',
			url: '/directory/ondemand/site.asp?' + sParam,
			dataType: 'xml',
			async: false,
			success: function(data, textStatus, XMLHttpRequest) 
			{
				oXML = data;
				oRoot = oXML.getElementsByTagName("ondemand").item(0);
				for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
					{
						var oRow = oRoot.childNodes.item(iRow);
						if (onDemandXMLGetData(oRow, "notes") != '')
						{	
							giCustomOrder = 1;
						}
						else
						{
							
						}
					}
			}
	})
}

function ShowProductCart(iProductCartType)
{
	//1 FOR PRODUCT CART IN CART BAR 2 FOR FULL PRODUCT CART IN MAIN SCREEN
	var iProductCartType;
	var sParam;
	var oXML;
	var oRoot;
	var oRow;
	var aHTML = [];
	var h = -1;
	var cTotalPrice = 0;
	var cOtherTotalPrice = 0;

	if(iProductCartType == 1)
	{
		//SHOW THE NORMAL CART AS PER CART BAR
		aHTML[++h] = '<table border="0" cellspacing="0"  width="900">';
		aHTML[++h] = '<tbody>'
		aHTML[++h] = '<tr class="pro_details_head">';
		aHTML[++h] = '<td align="left" style="width: 400px; font-size:14px;"><img class="cartstatus" style="vertical-align:middle" src="/site/1125/bigcartfull.png" /><strong>&nbsp;My Shopping Cart</strong></td>';
		aHTML[++h] = '<td style="width: 100px;">&nbsp;</td><td style="width: 130px;">&nbsp;</td><td style="width: 70px;">&nbsp;</td><td style="width: 100px;">&nbsp;</td><td style="width: 100px;">&nbsp;</td></tr>';
	
		sParam = 'method=SITE_ORDER_PRODUCT_SEARCH&cart=1&includeproducts=1&site=' + msOnDemandSiteId + '&shoporderonly=1' + '&rf=XML'

		$.ajax({
			type: 'GET',
			url: '/directory/ondemand/site.asp?' + sParam,
			dataType: 'xml',
			async: false,
			cache: false,
			success: function(data, textStatus, XMLHttpRequest) 
			{
				oXML = data;
				oRoot = oXML.getElementsByTagName("ondemand").item(0);

				if (oRoot.childNodes.length == 0)
				{
					aHTML[++h] = '<tr><td valign="top" style="padding: 4px;">There are no products in your Cart.</td></tr>';
					aHTML[++h] = '</tbody></table>';
					$('.cartInformation').html(aHTML.join(''));
					$('.cartstatus').attr({src: "/site/1125/bigcartempty.png"});
				}
				else
				{

					aHTML[++h] = '<tr class="pro_details_head">';
					aHTML[++h] = '<td class="underline" align="left" valign="top"><strong>Product</strong></td>';
					aHTML[++h] = '<td class="underline" align="left" valign="top"><strong>Product Code</strong></td>';
					aHTML[++h] = '<td class="underline" align="right" valign="top">&nbsp;</td>';
					aHTML[++h] = '<td class="underline" align="right" valign="top"><strong>Total</strong></td>';
					aHTML[++h] = '<td class="underline">&nbsp;</td>';
					aHTML[++h] = '<td class="underline">&nbsp;</td>';
					aHTML[++h] = '</tr>';

					for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
					{
						var oRow = oRoot.childNodes.item(iRow);
						
						if (onDemandXMLGetData(oRow, "totalprice") != '')
						{
							cTotalPrice = cTotalPrice + parseFloat(onDemandXMLGetData(oRow, "totalprice"));
							cOtherTotalPrice = cOtherTotalPrice + parseFloat(onDemandXMLGetData(oRow, "othertotalprice"));
						}

						aHTML[++h] = '<tr class="pro_checkout_details">';
						
						if (onDemandXMLGetData(oRow, "notes") != '')
						{
							aHTML[++h] = '<td align="left" valign="top" style="padding: 4px;">' + onDemandXMLGetData(oRow, "title") + ' - ' + onDemandXMLGetData(oRow, "notes") + ' </td>';
							giCustomOrder = 1;
						}
						else
						{
							aHTML[++h] = '<td align="left" valign="top" style="padding: 4px;">' + onDemandXMLGetData(oRow, "title") + '</td>';
						}
						
						aHTML[++h] = '<td align="left" valign="top" style="padding: 4px;">' + onDemandXMLGetData(oRow, "reference") + '</td>';
						aHTML[++h] = '<td align="left" valign="top" style="padding: 4px;">&nbsp;</td>';
						aHTML[++h] = '<td align="right" valign="top" style="padding: 4px;" id="productPrice-' + onDemandXMLGetData(oRow, "product") + '">A$' + onDemandXMLGetData(oRow, "totalprice") + '</td><td style="padding: 4px;">~' + onDemandXMLGetData(oRow, "otherpricecurrencycode") + onDemandXMLGetData(oRow, "otherprice") + '</td>';
						aHTML[++h] = '<td align="right" valign="top" style="padding: 4px;"><div id="product-' + onDemandXMLGetData(oRow, "product") + '" class="removeproduct" style="color: #0099FF; align: right;">Remove</div></td>';
						aHTML[++h] = '</tr>'
					}

					aHTML[++h] = '<tr class="pro_checkout_details">';
					aHTML[++h] = '<td align="left" class="pro_lines" valign="top">&nbsp;</td>';
					aHTML[++h] = '<td align="left" class="pro_lines" valign="top">&nbsp;</td>';
					aHTML[++h] = '<td align="right" class="topline" style="color: #000000; font-size: 14px;"><strong>Total Amount:</strong></span></td>';
					aHTML[++h] = '<td align="right" class="topline" id="orderTotalPrice" style="color: #000000; font-size: 14px;"><strong>A$' + cTotalPrice.toFixed(2) + '</strong></span></td>';
					aHTML[++h] = '<td style="color: #000000;" class="topline">~' + onDemandXMLGetData(oRow, "otherpricecurrencycode") + cOtherTotalPrice.toFixed(2) + '</td>';
					aHTML[++h] = '<td class="topline" align="left" class="pro_lines"><img class="checkoutButton" style="position:relative; left:-10px; top: 2px;" src="/site/1125/CartCheckoutButton.png"</td>';
					aHTML[++h] = '</tr>';
					aHTML[++h] = '</tbody></table>';
					$('.cartInformation').html(aHTML.join(''));
				}
			}
		})	
	}		
	else
	{
		//SHOW THE FULL CART TO SHOW ON CHECKOUT PAGE
		aHTML[++h] = '<table border="0" cellspacing="0"  width="730">';
		aHTML[++h] = '<tbody>'
		aHTML[++h] = '<tr class="pro_details_head">';
		aHTML[++h] = '<td align="left" style="width: 500px; color: #666666;"><img class="cartstatus" style="vertical-align:middle" src="/site/1125/bigcartfull.png" /><strong>&nbsp;My Shopping Cart</strong></td>';
		aHTML[++h] = '<td style="width: 30px;">&nbsp;</td><td style="width: 130px;">&nbsp;</td><td style="width: 100px;">&nbsp;</td><td style="width: 150px;">&nbsp;</td><td style="width: 100px;">&nbsp;</td></tr>';
	
		sParam = 'method=SITE_ORDER_PRODUCT_SEARCH&cart=1&includeproducts=1&site=' + msOnDemandSiteId + '&shoporderonly=1' + '&rf=XML'
		$.ajax({
			type: 'GET',
			url: '/directory/ondemand/site.asp?' + sParam,
			dataType: 'xml',
			//async: false,
			success: function(data, textStatus, XMLHttpRequest) 
			{

				oXML = data;
				oRoot = oXML.getElementsByTagName("ondemand").item(0);

				if (oRoot.childNodes.length == 0)
				{
					aHTML[++h] = '<tr><td valign="top" style="padding: 4px;">There are no products in your Cart.</td></tr>';
					aHTML[++h] = '</tbody></table><br />';
					$('.cartInformationFull').html(aHTML.join(''));
					$('.cartstatus').attr({src: "/site/1125/bigcartempty.png"});
				}
				else
				{
					aHTML[++h] = '<tr class="pro_details_head">';
					aHTML[++h] = '<td class="underline" align="left" valign="top"><strong>Product</strong></td>';
					aHTML[++h] = '<td class="underline" align="right" valign="top" colspan="2"><strong>Product Code</strong></td>';
					aHTML[++h] = '<td class="underline" align="right" valign="top"><strong>Total</strong></td>';
					aHTML[++h] = '<td class="underline">&nbsp;</td>';
					aHTML[++h] = '<td>&nbsp;</td>';
					aHTML[++h] = '</tr>';

					for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
					{
						var oRow = oRoot.childNodes.item(iRow);
						
						if (onDemandXMLGetData(oRow, "totalprice") != '')
						{
							cTotalPrice = cTotalPrice + parseFloat(onDemandXMLGetData(oRow, "totalprice"));
							cOtherTotalPrice = cOtherTotalPrice + parseFloat(onDemandXMLGetData(oRow, "othertotalprice"));
						}

						aHTML[++h] = '<tr class="pro_checkout_details">';
						
						if (onDemandXMLGetData(oRow, "notes") != '')
						{
							aHTML[++h] = '<td align="left" valign="top" style="padding: 4px; font-size:11px;">' + onDemandXMLGetData(oRow, "title").substring(0,30) + ' - ' + onDemandXMLGetData(oRow, "notes") + ' </td>';
							giCustomOrder = 1;
						}
						else
						{
							aHTML[++h] = '<td align="left" valign="top" style="padding: 4px; font-size:11px;">' + onDemandXMLGetData(oRow, "title").substring(0,40) + '</td>';
						}
						aHTML[++h] = '<td align="right" valign="top" style="padding: 4px;font-size:11px;" colspan="2">' + onDemandXMLGetData(oRow, "reference") + '</td>';
						aHTML[++h] = '<td align="right" valign="top" style="padding: 4px; font-size:11px;" id="productPrice-' + onDemandXMLGetData(oRow, "product") + '">A$' + onDemandXMLGetData(oRow, "totalprice") + '</td><td align="right" style="padding: 4px; font-size:11px;">~' + onDemandXMLGetData(oRow, "otherpricecurrencycode") + 							onDemandXMLGetData(oRow, "otherprice") + '</td>';
						aHTML[++h] = '<td align="left" valign="top" style="padding: 4px; font-size:11px;"><div id="product-' + onDemandXMLGetData(oRow, "product") + '" class="removeproduct" style="color: #0099FF;">Remove</div></td>';
						aHTML[++h] = '</tr>'
					}

					aHTML[++h] = '<tr class="pro_checkout_details">';
					aHTML[++h] = '<td align="left" class="pro_lines" valign="top">&nbsp;</td>';
					aHTML[++h] = '<td colspan="2" align="right" class="topline" style="color: #000000; font-size: 14px;"><strong>Total Amount:</strong></span></td>';
					aHTML[++h] = '<td align="right" class="topline" id="orderTotalPrice" style="color: #000000; font-size: 14px;"><strong id="austotal">A$' + cTotalPrice.toFixed(2) + '</strong></span></td>';
					aHTML[++h] = '<td align="right" style="color: #000000; font-size:11px;" class="topline"><div id="othertotal">~' + onDemandXMLGetData(oRow, "otherpricecurrencycode") + cOtherTotalPrice.toFixed(2) + '</div></td>';
					aHTML[++h] = '<td>&nbsp;</td>';
					aHTML[++h] = '</tr>';
					aHTML[++h] = '</tbody></table>';
					aHTML[++h] = '<br />';
					$('.cartInformationFull').html(aHTML.join(''));
				}
			}
		})	
	}
}

function ProcessOrder()
{
	//CHECK PAYMENT DETAILS
	if(ValidateCCDetails())
	{
		$.blockUI(
		{
			message:  '<h1>Creating Order...</h1>',
			fadeIn: 0,
			onBlock: function()
			{ 
				CreateOrder();
			}
		}); 
	}
	else
	{
		ShowCCDetailsMessage();
	}
}

//SHOW ERROR MESSAGE REGARDING USER DETAILS OR CC DETAILS
function ShowCCDetailsMessage()
{
	$.blockUI(
		{ 
			fadeIn: 0,
			message:  '<img class="dialogimg" src="/site/1125/crossButton.png" alt="" />&nbsp;<span class="dialogfirstLine">Order submit error:</span><br /><br />' + sDetailsMessage + '<br /><div style="text-align:center"><button class="return">OK</button></div>'
		}); 
	
	$("button").button();	
	$(".return").click(function()
	{
		AskCustomerForCC();
	});
}

//SHOW ERROR MESSAGE REGARDING USER DETAILS OR CC DETAILS
function ShowDetailsMessage()
{
	$.blockUI(
		{ 
			fadeIn: 0,
			message:  '<img class="dialogimg" src="/site/1125/crossButton.png" alt="" />&nbsp;<span class="dialogfirstLine">Order submit error:</span><br /><br />' + sDetailsMessage + '<br /><div style="text-align:center"><button class="ok">OK</button></div>'
		}); 
	
	$("button").button();	
	$(".ok").click(function()
	{
		$.unblockUI();
	});
}

function ValidateUserDetails() 
{
	if(giLoggedIn != 1)
	{
		sDetailsMessage = '';
		//CHECK THERE ARE NO BLANKS ON THE PAGE
		if ($('#txtFirstName').val() == '' || $('#txtSurname').val() == '' || $('#txtEmail').val() == '' || $('#txtPhone').val() == '' || $('#txtPostcode').val() == '' || $('#txtUserName').val() == '' || $('#txtPassword').val() == '' || $('#howdidyouhear').val() == 'please')
		{	
			sDetailsMessage = sDetailsMessage + '<p style="font-size: 14px; margin: 0px;">You are missing some personal details (highlighted in red).</p>';
		}

		if (!onDemandIsEmail($('#txtEmail').val()))
		{	
			sDetailsMessage = sDetailsMessage + '<p style="font-size: 14px; margin: 0px;"><br />&nbsp;Please check invalid email address.</p>';
		}

		//CHECK EMAIL MATCHES CONFIRM EMAIL
		if($('#txtConfirmEmail').val() != $('#txtEmail').val())
		{
			sDetailsMessage = sDetailsMessage + '<p style="font-size: 14px; margin: 0px;"><br />&nbsp;Your Confirm Email Address does not match.</p>';
		}
		//CHECK PASSWORD MATCHES CONFIRM PASSWORD
		if($('#txtConfirmPassword').val() != $('#txtPassword').val())
		{
			sDetailsMessage = sDetailsMessage + '<p style="font-size: 14px; margin: 0px;"><br />&nbsp;Your Confirm Password does not match.</p>';
		}
		
		if (sDetailsMessage != '')
		{
			if($('#txtFirstName').val() == '')
			{
				$('#txtFirstName').css("background-color", "#FFBFBF");
				$('#firstNameWarn').html('<td>&nbsp;</td><td class="alertFont">Please enter your first name.</td>');
				$('#firstNameWarn').show();
			}
			if($('#txtSurname').val() == '')
			{
				$('#txtSurname').css("background-color", "#FFBFBF");
				$('#surnameWarn').html('<td>&nbsp;</td><td class="alertFont">Please enter your surname.</td>');
				$('#surnameWarn').show();
			}
			if($('#txtEmail').val() == '')
			{
				$('#txtEmail').css("background-color", "#FFBFBF");
				$('#emailWarn').html('<td>&nbsp;</td><td class="alertFont">Please enter your email address.</td>');
				$('#emailWarn').show();
			}
			if($('#txtConfirmEmail').val() == '')
			{
				$('#txtConfirmEmail').css("background-color", "#FFBFBF");
				$('#confirmEmailWarn').html('<td>&nbsp;</td><td class="alertFont">Please confirm your email address.</td>');
				$('#confirmEmailWarn').show();
			}
			if($('#txtContactNumber').val() == '')
			{
				$('#txtContactNumber').css("background-color", "#FFBFBF");
				$('#contactNumberWarn').html('<td>&nbsp;</td><td class="alertFont">Please enter your contact number.</td>');
				$('#contactNumberWarn').show();
			}
			if($('#txtPostcode').val() == '')
			{
				$('#txtPostcode').css("background-color", "#FFBFBF");
				$('#postcodeWarn').html('<td>&nbsp;</td><td class="alertFont">Please enter your post or zip code.</td>');
				$('#postcodeWarn').show();
			}
			if($('#howdidyouhear').val() == 'please')
			{
				$('#howdidyouhear').css("background-color", "#FFBFBF");
				$('#howDidYouHearWarn').html('<td>&nbsp;</td><td class="alertFont">Please make a selection.</td>');
				$('#howDidYouHearWarn').show();
			}
			if($('#txtUserName').val() == '')
			{
				$('#txtUserName').css("background-color", "#FFBFBF");
				$('#userNameWarn').html('<td>&nbsp;</td><td class="alertFont">Please enter a valid email address.</td>');
				$('#userNameWarn').show();
			}
			if($('#txtPassword').val() == '')
			{
				$('#txtPassword, #txtConfirmPassword').css("background-color", "#FFBFBF");
				$('#passwordWarn').html('<td>&nbsp;</td><td class="alertFont">Please enter a password.</td>');
				$('#passwordWarn').show();
			}
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return true;
	}
}	

function ValidateCCDetails()
{
	if(giPayType == 1)
	{
		sDetailsMessage = '';
		//CREDIT CARD AREA VALIDATION
		if ($('#selectCCType').val() == 'select' || $('#txtCardHoldersName').val() == '' || $('#txtCardNumber').val() == '' || $('#selectExpireMonth').val() == 'select' || $('#selectExpireYear').val() == 'select')
		{	
			sDetailsMessage = sDetailsMessage + '<p style="font-size: 14px; margin: 0px;">You are missing some payment details.</p>';
			return false;
			
		}
		else
		{
			return true;
		}
	}
	else
	{
		return true;
	}
}

function AutoLogin()
{	
	//LOGS IN USER WITHOUT REFRESHING THE PAGE
	var sReturn;
	var sParam;

	var sUserName = $('#txtUserName').val();
	var sPassword = $('#txtPassword').val();

	sParam = 'logon=' + sUserName + '&password=' + sPassword;
	sReturn = onDemandLogon(sParam);
	giLoggedIn = 1;
}

function GetTotal()
{
	var sParam = 'method=SITE_ORDER_SEARCH&summary=1&site=' + msOnDemandSiteId;
	var sReturn = onDemandSite(sParam);
	var aValues = sReturn.split('|');
	return aValues[5];
}

function GetOrderRef()
{
	var sParam = 'method=SITE_ORDER_SEARCH&summary=1&site=' + msOnDemandSiteId;
	var sReturn = onDemandSite(sParam);
	var aValues = sReturn.split('|');
	return aValues[2];
}

function CartItems()
{
	var sParam = 'method=SITE_ORDER_SEARCH&summary=1&site=' + msOnDemandSiteId;
	var sReturn = onDemandSite(sParam);
	var aValues = sReturn.split('|');
	if(aValues[4] == 0)
	{
		alert("Your Cart is empty, please add a product before making a payment.")
		return false;
	}
	else
	{
		return true;
	}
}

function UpdateCartBar()
{
	var sParam = 'method=SITE_ORDER_SEARCH&summary=1&site=' + msOnDemandSiteId + '&includelastproduct=1'
	
	$.ajax({
		type: 'GET',
		url: '/directory/ondemand/site.asp?' + sParam,
		dataType: 'text',
		//async: false,
		cache: false,
		success: function(data, textStatus, XMLHttpRequest) 
		{
			var sReturn = data;
			if (sReturn.substring(0, 2) == 'OK') 
			{
				var aValues = sReturn.split('|');

				$('#cartQty').html("<p class=\"cartDetails\">Items in Cart: <strong>" + aValues[3] + "</strong></p>");
				if (aValues[3] == 0)
				{
					$("#cartHeader").html("<p class=\"cartHeader\">There are no products in your Cart.</p>");
					$("#cartNotify").attr({src: '/site/1125/emptycart.png'});
				}
				else
				{
					$("#cartHeader").html("<p class=\"cartHeader\">" + aValues[6].substring(0,38)  + " added.</p>");
					$("#cartNotify").attr({src: '/site/1125/fullcart.png'});
				}
				if (aValues[5] == undefined)
				{
					$('#cartTotal').html("<p class=\"cartDetails\">Total: $0.00</p>");
				}
				else
				{		
					$('#cartTotal').html("<p class=\"cartDetails\">Total: A$<strong>" + aValues[5] + "</strong></p>");
				}
				
				//CHECK CURRENCY IS NOT BLANK
				if (aValues[8] != undefined && aValues[8] != '')
				{
					giCurrency = aValues[8]; 
				}
				else
				{
					sParam = 'method=SITE_CURRENCY_SET&site=' + msOnDemandSiteId + '&select=' + giCurrency;
					sReturn = onDemandSite(sParam);
				}
				//CHECK TAXTYPE IS NOT BLANK-IF IT IS THEY HAVE NEVER SELECTED ONE
				if (aValues[9] != undefined && aValues[9] != '')
				{
					giTaxRegion = aValues[9];
					giTaxRegionAsked = 1;
				}
				else
				{
					giTaxRegionAsked = 0;
				}
			}
			//FIX FOR IE8 CART
			$(".jx-bar").css("filter", "alpha(opacity=90)");
			//$(".jx-bar").focus();
			
		}
	})
}

function ShowMoreProduct(sProduct)
{
	var sParam;
	var aProduct = sProduct.split('-');
	var aHTML = [];
	var h = -1;
	var oXML;
	var oRoot;
	var oRow;
	
	sParam = 'method=SITE_PRODUCT_SEARCH&site=' + msOnDemandSiteId + '&select=' + aProduct[1] + '&includegroupcount=1&includeattachments=1&attachmenttype=205' + '&rf=XML';
	
	
	$.ajax({
			type: 'GET',
			url: '/directory/ondemand/site.asp?' + sParam,
			dataType: 'xml',
			success: function(data, textStatus, XMLHttpRequest) 
			{
			oXML = data;
			oRoot = oXML.getElementsByTagName("ondemand").item(0);
			
			if (oRoot.childNodes.length == 0)
			{
				alert("error");
			}
			else
			{
				for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
				{
					var oRow = oRoot.childNodes.item(iRow);
					aHTML[++h] = '<table border="0"><tbody>'
					aHTML[++h] = '<tr><td><img class="viewcart" src="/site/1125/ViewCartLSOff.png" style="position:relative; left: 3px;"/>';
					aHTML[++h] = '</td></tr>';

					//CHECK FOR PRODUCTGROUP COUNT GREATER THEN ZERO IF SO SHOW THE COMBO BUTTON
					if(onDemandXMLGetData(oRow, "productgroupcount") > 0)
					{
					aHTML[++h] = '<tr><td><img class="showcombo" src="/site/1125/BuyComboLSOff.png" style="position:relative; left: 3px;"/>';
					aHTML[++h] = '</td></tr>';
					}
			
					//CHECK FOR GENERIC ATTACHMENT IF NOT EXIST THEN SHOW SCRIPT BUTTON 
					if(onDemandXMLGetData(oRow, "attachments") == '')
					{
					aHTML[++h] = '<tr><td><img class="aboutscript" src="/site/1125/ScriptStylesLSOff.png" style="position:relative; left: 3px;"/>';
					aHTML[++h] = '</td></tr>';
					}
					aHTML[++h] = '</tbody></table>';					
					$("#tdShopCartOptions-" + aProduct[1]).hide();
					$("#tdShopCartOptions-" + aProduct[1]).html(aHTML.join(''));

					$("#tdShopCartOptions-" + aProduct[1]).slideDown("slow");
					$("#moreLess-" + aProduct[1]).attr({src: "/site/1125/ReadLessLSOn.png"});
			
					$("#divFirstPara-" + aProduct[1]).hide();
					$("#divDescription-" + aProduct[1]).slideDown("slow");
			
					$('img.viewcart').mouseenter(function()
					{
						$(this).attr({src: "/site/1125/ViewCartLSOn.png"});
						$(this).attr({title: "View your Shopping Cart"});
						$(this).css("cursor", "pointer");
					}).mouseleave(function()
					{
						$(this).attr({src: "/site/1125/ViewCartLSOff.png"});
					});
			
					$('img.showcombo').mouseenter(function()
					{
						$(this).attr({src: "/site/1125/BuyComboLSOn.png"});
						$(this).attr({title: "Save by buying as part of a Combo Pack"});
						$(this).css("cursor", "pointer");
					}).mouseleave(function()
					{	
						$(this).attr({src: "/site/1125/BuyComboLSOff.png"});
					});
			
					$('img.aboutscript').mouseenter(function()
					{
						$(this).attr({src: "/site/1125/ScriptStylesLSOn.png"});
						$(this).attr({title: "View the different Script Styles available"});
						$(this).css("cursor", "pointer");
					}).mouseleave(function()
					{
						$(this).attr({src: "/site/1125/ScriptStylesLSOff.png"});
					});
					
					$("#moreLess-" + aProduct[1]).mouseenter(function()
					{
						$(this).attr({src: "/site/1125/ReadLessLSOn.png"});
						$(this).attr({title: "Shrink eBook Description"});
						$(this).css("cursor", "pointer");
					}).mouseleave(function()
					{
						$(this).attr({src: "/site/1125/ReadLessLSOff.png"});
					});
					//CANT REUSE FUNCTION AS THIS ONLY VIEWS CART NOT HIDES
					$('img.viewcart').click(function() 
					{
						ShowProductCart(1);
						$(".jx-bar").animate(
						{
							height: "250px"
						}, 1000, "swing", function(){
							//CALLBACK FUNCTION TO CHANGE OVERFLOW
							$(".cartInformation").css('overflow-x', 'hidden');
							$(".cartInformation").css('overflow-y', 'auto');});
							$("#cart").text("Hide Cart");
					});	
			
					$('img.showcombo').click(function(event)
					{
			
					window.location.href = '/white_spot/'
					})
			
					$('img.aboutscript').click(function(event)
					{
						$.blockUI(
							{ 
								message:  $('#scriptstylemessage')
							}); 
						$('.okscript').click(function() 
						{
							$.unblockUI();
							return false;
						});
			
					})
					}
			}
		}
	})
}

function ShowLessProduct(sProduct)
{
	var aProduct = sProduct.split('-');
	
	$("#tdShopCartOptions-" + aProduct[1]).slideUp("fast")
	$("#divFirstPara-" + aProduct[1]).show();
	$("#divDescription-" + aProduct[1]).slideUp("fast");
	$("#moreLess-" + aProduct[1]).attr({src: "/site/1125/ReadMoreLSOn.png"});
	
	$("#moreLess-" + aProduct[1]).mouseenter(function()
			{
				$(this).attr({src: "/site/1125/ReadMoreLSOn.png"});
				$(this).css("cursor", "pointer");
			}).mouseleave(function()
			{
				$(this).attr({src: "/site/1125/ReadMoreLSOff.png"});
			});
		
}
function DownloadSample(sProductID)
{
	//SPLIT THE ID AND THE PD- TEXT AND OPEN THE LINK WITH THE ATTACHMENT
	var sProductID; 
	var sParam;
	var oXML;
	var oRoot;
	var oRow;
	var iRow = 0;
	var aValues = sProductID.split('-');
	
	sParam = 'method=SITE_PRODUCT_SEARCH&select=' + aValues[1] + '&includeattachments=1&attachmenttype=211&site=' + msOnDemandSiteId
	
	oXML = onDemandSiteXML(sParam);
	oRoot = oXML.getElementsByTagName("ondemand").item(0);
	
	oRow = oRoot.childNodes.item(iRow);
	
	if (onDemandXMLGetData(oRow, "attachments") == "")
	{
		window.alert("Sorry there is no sample download available for this eBook.");
	}
	else
	{
		var sDownloadLink;
		sDownloadLink = onDemandXMLGetData(oRow, "attachments");
		var aSplitLink = sDownloadLink.split('#');
		document.location.href = aSplitLink[2];
	}
}

function SearchProducts()
{
	var sParam;
	var oXML;
	var oRoot;
	var oRow;
	var aHTML = [];
	var h = -1;
	var iRows = 50;
	var iCols = 2;

	sParam = 'method=SITE_PRODUCT_SEARCH&site=' + msOnDemandSiteId + '&includeprice=1&includeimage=1' + '&quicksearch=' + $("#searchTerm").val();
	oXML = onDemandSiteXML(sParam);
	oRoot = oXML.getElementsByTagName("ondemand").item(0);
	oRow = oRoot.childNodes.item(0);
		
	aHTML[++h] = '<img id="sbutton" class="checkoutButton" style="border: 0pt none; position: relative; top: 70px; left: 330px;" title="Checkout Now" src="/site/1125/topcheckoutoff.png" alt="Checkout Now" width="85" height="45" /> <a href="/testimonials"><img id="tbutton"  title="Testimonials" alt="Testimonials" style="border: 0pt none; position: relative; top: 70px; left: 330px;" src="/site/1125/TestimonialsOff.png" alt="Popet Educational e-Workbooks" width="85" height="45" /></a> <a href="#"><img id="ebutton" style="border: 0pt none; position:relative; top: 70px; left: 330px;" title="eWorkbookInfo" src="/site/1125/eWorkbookInfoOff.png" alt="eWorkbookInfo" width="85" height="45" /></a><img id="einfo" style="position: absolute; top: 230px; left: 50%; display: none; z-index: 2;"  src="/site/1125/eWorkbookInfo.png" /><h1 class="searchResults">Search Results</h1><h2 style="text-align: center;"><img style="vertical-align: middle;" title="Search Results" src="/site/1125/searchResults.png" alt="Search Results" width="289" height="124" /></h2><p class="font_11"><p style="width: 720px;"><strong>Popet</strong>&reg; <strong>eWorkbooks</strong> are in <a href="http://www.adobe.com/go/EN_US-H-GET-READER" target="_blank">Adobe&reg;Reader&reg;</a> format and require version 7.0 or later.&nbsp;Please refer to our <a href="#disclaimer">Price  and eWorkbook Copyright Notices</a> before proceeding with your  purchase.</p><p><img style="position: relative; bottom: 5px;" src="/site/1125/prodline.png" alt="" /></p></p>';
	
	if (oRoot.childNodes.length > 0)
	{
		for (var iRow = 0; iRow < oRoot.childNodes.length; iRow++) 
		{
			var oRow = oRoot.childNodes.item(iRow);
			
			//CHECK THAT THE PRODUCT TITLE IS NOT BLANK
			if (onDemandXMLGetData(oRow, "title") != '' && onDemandXMLGetData(oRow, "shopstatus") != '2')
			{
				
				var iRowCount = parseInt(onDemandXMLGetData(oRow, "rowcount"));
				
				
				//CHECK IF PRODUCT TYPE IS EQUAL TO 1 (1 Indicates Single Product 2 indicates Group Product Group products report a 0.00 value for price.
				if (parseInt(onDemandXMLGetData(oRow, "type")) == 1)
				{
				aHTML[++h] = '<table border="0" cellspacing="0" cellpadding="0" width="720">';
	aHTML[++h] = '<tbody>'
				aHTML[++h] = '<td style="width: 125px;" valign="top"><img id="productImage-' + onDemandXMLGetData(oRow, "id") + '" style="position:relative;" src="' +  onDemandXMLGetData(oRow, "imageurl") +	'" alt="' + onDemandXMLGetData(oRow, "title") + '" /></td>';
				aHTML[++h] = '<td valign="Top">';
				aHTML[++h] = '<table border="0" cellpadding="0" width="100%"><tbody><tr><td class="prodHead" valign="top">' + onDemandXMLGetData(oRow, "title") + '</td></tr><tr><td style="position: relative; top: 0px; "><strong>Product Code: ' +  onDemandXMLGetData(oRow, "reference") + '<br /></strong><strong>ISBN: ' + onDemandXMLGetData(oRow, "barcode") + '</strong></td></tr><tr><td style="width: 410px;"><div id="divDescriptionLong-' + onDemandXMLGetData(oRow, "id") + '">' + onDemandXMLGetData(oRow, "description") + '</div>';
				aHTML[++h] = '</td></tr></tbody></table></td><td style="width: 110px;" valign="top"><table style="height: 100%;" border="0" width="120"><tbody><tr><td class="prodHead" style="text-align: right;">A$' +  onDemandXMLGetData(oRow, "price") + '</td></tr><tr><td><div class="OtherPriceYes" style="font-size: 11px; text-align:right;">&nbsp;</div></td></tr><tr><td id="tdChildName-' + onDemandXMLGetData(oRow, "id") + '" style="text-align: right; display: none;">&nbsp;</td></tr><tr><td style="text-align: right;"><img id="moreLess-' + onDemandXMLGetData(oRow, "id") + '" class="moreless" style="border: 0pt none; float: right;" title="Read more about this eBook" src="/site/1125/ReadMoreLSOff.png" alt="ReadMoreLSOff.png" /></td></tr><tr><td style="text-align: right;"><img id="addtocart-' + onDemandXMLGetData(oRow, "id") + '" class="addtocart" style="border: 0pt none; float: right;" title="Add this eBook to your Cart" src="/site/1125/AddToCartLSOff.png" alt="AddToCartLSOff.png" /></td></tr><tr><td style="text-align: right;"><img id="checkoutButtonProd" class="checkoutButton checkoutButtonProd" style="float: right;" title="Proceed to Checkout & Pay" src="/site/1125/CheckoutLSOff.png" alt="CheckoutLSOff.png" /></td></tr><tr><td style="text-align: right;"><img id="downloadSample-' + onDemandXMLGetData(oRow, "id") + '" class="downloadsample" style="border: 0pt none; float: right;" title="Download a sample of this eBook" src="/site/1125/DownloadSampleLSOff.png" alt="DownloadSampleLSOff.png" /></td></tr><tr><td id="tdShopCartOptions-' + onDemandXMLGetData(oRow, "id") + '" style="float: right;">&nbsp;</td></tr></tbody></table></td></tr></tbody></table>'
				aHTML[++h] = '<p><img style="position: relative; bottom: 5px;" src="/site/1125/prodline.png" alt="" /></p>'	
				}
			}
		}
	
	aHTML[++h] = '</tbody></table>';
	aHTML[++h] = '<p class="copyright"><strong>Prices</strong><br />All charges are in Australian dollars (A$). Currency conversion rates are a guide for your convenience only. Rates are updated regularly but we do not guarantee the accuracy of this information. A number of currencies are available on this site and can be accessed by clicking "Change Currency" at the bottom of the screen. Prices shown on this page are inclusive (inc.) of the Australian Goods and Services Tax (GST).<br /><br /><strong>eWorkbook Copyright Notice</strong><br />The material in Popet&reg; eWorkbooks for Parents may only be reproduced by the original purchaser for private or domestic purposes. This material must not be used for any commercial purpose, including promotion of any supplier\'s products or services, without the prior written permission of Popet Pty Ltd. This material must not be placed on any server or website for others to access. This material must not be distributed to others. Others wanting access to this material must visit the Popet&reg; website to obtain it legally.</p><p style="color: #3c3c3c; font-size: 12px;"><a href="http://get.adobe.com/reader/" target="_blank"><img style="border: none;" title="Get Acrobat Reader" src="/site/1125/getacro.gif" alt="getacro.gif" width="88" height="31" /></a><br />Adobe&reg; Reader&reg; &mdash; free software for viewing and printing Adobe Portable Document Format (PDF) files is required to view popet eWorkbooks and eWorksheets. You can download the latest software by clicking on the Adobe&reg; Reader&reg; icon.</p>'

	$("#content").html(aHTML.join(''));
	BindShopButtons();	
	
	}
	else
	{
		$.blockUI({ message: "<h1>No Products Found...</h1>", fadeIn: 0, timeout: 1000});
	}
}

function Referral()
{
	$.blockUI(
			{
				message:  '<h1>Redirecting now...</h1>',
				fadeIn: 250,
				timeout: 1000
			});
}
