// Custom Functions

// @desc  EXTERNAL LINKS - traps all links with rel="external" or class="external" or those that link to external sources
	function linksAndEmails()
	{
		// turn rel="external" attributes into new window popups
		$j('a[rel^="external"]').click( function() {
			window.open( $j(this).attr('href') );
			return false;
		});
		// turn "external" classes into new window popups
		$j('a.external').click( function() {
			window.open( $j(this).attr('href') );
			return false;
		});
/*		// find all external links on a site and make new window popups
		$j("a[href^='http://']").not("a[href^='http://complexfamily.com/']").not("a[href^='http://www.complexfamily.com']").not('a[rel^="external"]').click(function(){
			window.open(this.href,'external');
			return false;
		});*/
		
		// Email Converter
		$j('a.email').each(function(){
			e = this.title.replace('/','@');
			this.href=" ";
			this.title="Please Contact Us Via Email";
			this.href = 'mailto:' + e; $j(this).text(e);
		});
	};//@end 

// @desc DISABLE ELEMENT Add Class "noshow" to given element if pagename exists.
	function disableContainer (element,pageName) {
		 if ( $j(element).hasClass(pageName) ) {
			$j(element).remove();
		 }
	}//@end 

// @desc CHECK EMAIL - Check if a valid email address is entered.
	function checkMail(email){
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$j/;
		if (filter.test(email)) {
			return true;
		}
		return false;
	}//@end 

// @desc GOOGLE MAP - Non Iframe Map Call up
// @Use HTML - <div id="GoogleMap"></div> [width:500px; height:400px;]
	function mapasGoogle() {
	  if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("mapaGoogle"));	
		map.setCenter(new GLatLng(42.8475, -2.6820), 15); //Define Location       	
		map.setMapType(G_HYBRID_TYPE); // Define map Type
		map.addControl(new GSmallMapControl()); // Active Map Controls
		map.addControl(new GMapTypeControl()); // Activate Type Controls
		map.openInfoWindowHtml(map.getCenter(),
		('<img src="images/logo.png" width="20" height="20" alt="" /><em>Title</em> <br /> Lorem ipsum dolor sit amet'));
	  }
	}//@end 

// @desc IMAGE PRELOADER
	function preloadImages() {
	   if (document.images) {
		  for (var i = 0; i < preloadImages.arguments.length; i++) {
			 (new Image()).src = preloadImages.arguments[i];
		  }
	   }
	}//@end 

// @desc CART FULL -  Find if cart is full
	function isCartFull() {
		 $j(".cartSummaryItem:contains('Total')").addClass("full-cart");

	}//@end 
	
// @desc CART RELOAD -  reload the shopping cart fixes
function reloadThis(actionID) {

	actionID.change(
		function()
		{
			top.location.reload();
		}
	);

}
function reloadThisClick(actionID) {

	actionID.click(
		function()
		{
			top.location.reload();
		}
	);

}


/* ==== COPY ADDRESS WHEN SELECTED ==== */
function copyAddress()
{
	if ($j("input#ShippingAddress").val() == "") {
		$j("input#ShippingAddress").val($j("input#BillingAddress").val()); 
	}
	if ($j("input#ShippingCity").val() == "") {
		$j("input#ShippingCity").val($j("input#BillingCity").val());
	}
	if ($j("input#ShippingState").val() == "") {
		$j("input#ShippingState").val($j("input#BillingState").val());
	}
	if ($j("input#ShippingZip").val() == "") {
		$j("input#ShippingZip").val($j("input#BillingZip").val());
	}
		var billIndex = $j("#BillingCountry option").index($j("#BillingCountry option:selected"))
		$j("#ShippingCountry option:eq("+billIndex+")").attr("selected", "selected")
}

/* ==== EDIT FIELDS IF CHANGED ==== */
function editifchanged() {
	$j("input#BillingAddress").change(function()
	{
		var vamount = $j(this).val();
		$j("input#ShippingAddress").val(vamount);
	});
	$j("input#BillingCity").change(function()
	{
		var vamount = $j(this).val();
		$j("input#ShippingCity").val(vamount);
	});
	$j("input#BillingState").change(function()
	{
		var vamount = $j(this).val();
		$j("input#ShippingState").val(vamount);
	});
	$j("input#BillingZip").change(function()
	{
		var vamount = $j(this).val();
		$j("input#ShippingZip").val(vamount);
	});
	$j("input#BillingCountry").change(function()
	{
		var billIndex = $j("#BillingCountry option").index($j("#BillingCountry option:selected"))
		$j("#ShippingCountry option:eq("+billIndex+")").attr("selected", "selected")
	});

}
/* ==== UPDATE WHEN TOLD ==== */
function updateWhenTold() {

		var vamount = $j("input#BillingAddress").val();
		$j("input#ShippingAddress").val(vamount);

		var vamount = $j("input#BillingCity").val();
		$j("input#ShippingCity").val(vamount);

		var vamount = $j("input#BillingState").val();
		$j("input#ShippingState").val(vamount);

		var vamount = $j("input#BillingZip").val();
		$j("input#ShippingZip").val(vamount);
		
		var billIndex = $j("#BillingCountry option").index($j("#BillingCountry option:selected"));
		$j("#ShippingCountry option:eq("+billIndex+")").attr("selected", "selected");

}
/* ==== ANOTHER UPDATE 100% CHECK  ==== */
function updateFields()
{	
	editifchanged()
	$j("input#BillingAddress").blur( function () { editifchanged(); updateWhenTold(); }); 
	$j("input#BillingCity").blur( function () { editifchanged(); updateWhenTold(); });
	$j("input#BillingState").blur( function () { editifchanged(); updateWhenTold(); });
	$j("input#BillingZip").blur( function () { editifchanged(); updateWhenTold(); });
	$j("input#BillingCountry").blur( function () { editifchanged(); updateWhenTold(); });
	$j("input#BillingCountry").click( function () { editifchanged(); updateWhenTold(); });

}
/* ==== CLEAR ADDRESS FIELDS ==== */
function removeAddress() {
	$j("input#ShippingAddress").val("");
	$j("input#ShippingCity").val("");
	$j("input#ShippingState").val("");
	$j("input#ShippingZip").val("");
}

/* ==== BILLING THE SAME AS SHIPPING ==== */
function billToShip()
{
	if ( $j("input[@name='biltoship']:checked").val() == "Yes" ) {
		copyAddress();
		$j("#entertext").addClass("hidden");	
	}
	if ( $j("input[@name='biltoship']:checked").val() == "No" ) {
		$j("#entertext").removeClass("hidden");	
		removeAddress();
	}
	
	$j("#bilship_0").change(function()
	{
		if ( $j(this).val() == "Yes" ) {
			copyAddress();
			$j("#entertext").addClass("hidden");
		}
	});
	$j("#billship_1").change(function()
	{
		if ( $j(this).val() == "No" ) {
			removeAddress();
			$j("#entertext").removeClass("hidden");	
		}
	});
}
	
// @desc CLEAR SEARCH-  Clear search field of content when click in.	
	function clearSearch() {
	
		// Clear Search Field
		$j('#search-field').mouseover (function()
		{
			if (this.value=='Press Enter to Search...') { this.value='';return true;}
		});
		$j('#search-field').mouseout (function()
		{
			if (this.value=='') { this.value='Press Enter to Search...';return true;}
		});
	}//@end 
	
	function imageBorders() {
		var elementToWrap = $j("#content img");
		var dontWrapElement = $j("#content .four_price img");
		var floatImage = $j("#content p span.border-wrap");
		if ( dontWrapElement.length ) {
			
		}
		else if ( elementToWrap ) {
			elementToWrap.wrap('<span class="border-wrap"></span>');
		}

	}//@end 
	
	

// @desc MAIN NAV - Add the main elements for the navigation to work
	
	function addDivForMenu() {
		$j("ul#nav_643799 li ul").wrap('<div class="sub"></div>');
	}
	function megaHoverOver(){
		$j(this).find(".sub").stop().fadeTo('fast', 1).show();
		$j(this).find(".sub ul").addClass('clearfix');
	}
	function megaHoverOut(){ 
	  $j(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $j(this).hide(); 
	  });
	}//@end 
	
// @desc Registration Links - Show the right form when needed so not to overload the user

	function registrationLinks() {

		$j('#free-member').click(function(e) {
			e.preventDefault();						  
			if ( $j('#register-paid').hasClass('showing') ) {
				$j('#register-paid').hide().removeClass('showing');
				$j('#paid-member').removeClass('showing-form');
				
				$j('#register-free').fadeIn('slow').addClass('showing');
				$j('#free-member').addClass('showing-form');
				return false;
			}
			else {
				$j('#register-free').fadeIn('slow').addClass('showing');
				$j('#free-member').addClass('showing-form');
				return false;
			}
			
		});
		
		$j('#paid-member').click(function(e) {
			e.preventDefault();					  
			if ( $j('#register-free').hasClass('showing') ) {
				$j('#register-free').hide().removeClass('showing');
				$j('#free-member').removeClass('showing-form');
				
				$j('#register-paid').fadeIn('slow').addClass('showing');
				$j('#paid-member').addClass('showing-form');
				return false;
			}
			else {
				$j('#register-paid').fadeIn('slow').addClass('showing');
				$j('#paid-member').addClass('showing-form');
				return false;
			}
			
		});
		
	}//@end 
	
// @desc STOCK AVAILABLE? - If an item has stock value then it is available.

	function isAvailable() {
		var productPage = $j("body.products");
		var bookingPage = $j("body.bookings");
		var str = $j(".level").text();
		var ofText = $j(".quantity");
		var inStock = $j(".instock");
		
		if ( productPage.length ) {	
			if ( str == "0" )		        { inStock.addClass("no").text("pre-order now"); }
			else if ( str == "N/A" ) 	{ $j(".level").remove().text(" "); 
							          ofText.html(ofText.html().replace(/of/ig, ""));	}
			else			                { inStock.addClass("yes").text("available"); }
		}

		else if ( bookingPage.length ) {
			if ( str == "0" ) 		   { inStock.addClass("no").text("(currently unavailable)"); }
			else if ( str == "N/A" ) { inStock.addClass("sa").text("people attending"); 
							     $j(".level").remove().text(" "); 
							     ofText.html(ofText.html().replace(/of/ig, "")); }
			else 			           { inStock.addClass("yes").text("seats available"); }
		}
		
		else {
			
			if ( str == "0" ) 		        { inStock.addClass("no").text("(currently unavailable"); }
			else if ( str == "N/A" ) 	{ $j(".level").remove().text(" "); 
							          ofText.html(ofText.html().replace(/of/ig, ""));	}
			else 				        { inStock.addClass("yes").text("available"); }
		}
	}//@end
	
// @desc HIDE ELEMENTS - If you do not want it or hidden via CSS remove the element

	function HideMe() {
		var doYouHideMe = $j(".do-you-hide-me");
		if  ( doYouHideMe.hasClass("false") ) {
			$j(".false").remove();
		}
	}
	
	function loggedInState() {
		var loggedInFalse = $j(".logged-in-0");
		var loggedOutFalse = $j(".logged-out-1"); 
		
		loggedInFalse.remove(); loggedOutFalse.remove();
	}//@end 
	

/* ==== Copy and paste details  ==== */
function copyPaste() { 
	$j("input#paypalfirstname").val($j("input#FullName").val()); 
	$j("input#paypalemail").val($j("input#EmailAddress").val());
}//@end 
function copyPasteUpgrade() { 
	$j("input#paypalfirstname").val($j("input#FirstName").val()); 
	$j("input#paypalemail").val($j("input#EmailAddress").val());
}//@end


/* ==== COPY OTHER DETAILS  ==== */
function copyDetails() {	
	$j("#register-full input#FullName").blur( function () { copyPaste(); });
	$j("#register-full input#EmailAddress").blur( function () { copyPaste(); });
	$j("#register-full button#submit").mouseover( function () { copyPaste(); });
	$j("#register-full input#submit").mouseover( function () { copyPaste(); });
	$j("#register-full input#EmailAddress").change( function () { copyPaste(); });
	$j("#register-full input#FullName").change( function () { copyPaste(); });	
}//@end

function copyDetailsUpgrade() {	
	$j(".upgrade-form input#FirstName").blur( function () { copyPasteUpgrade(); });
	$j(".upgrade-form input#FirstName").change( function () { copyPasteUpgrade(); });
	$j(".upgrade-form input#submit").mouseover( function () { copyPasteUpgrade(); });
	$j(".upgrade-form button#submit").mouseover( function () { copyPasteUpgrade(); });
	$j(".upgrade-form input#EmailAddress").change( function () { copyPasteUpgrade(); });
	$j(".upgrade-form input#EmailAddress").blur( function () { copyPasteUpgrade(); });
}//@end


/* ==== GET URL VALUES ==== */
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}//@end 

/* ==== GET PAYPAL URL DETAILS ==== */
function displayPaymentDetails() {
	getUrlVars();
	var transactionID  = getUrlVars()["tx"];
	var amount = getUrlVars()["amt"];
	var currency = getUrlVars()["cc"];
	var displayMe = '<div class="trans-id">Your Transaction ID: <strong>' + transactionID + '</strong></div>' + '<div class="amount">Amount Paid: <strong>' + amount + ' ' + currency + '</strong></div>';
	return displayMe;
}//@end 

/* ==== CREATE PAYMENT ==== */
function submitPayment() {
	if ( $j("#EmailAddress") != '') { 
		
		//$j("#paypalform").submit();
		$('#paypalform').submit(function() {
  			alert('Paypal will be launched in a new browser window or tab.');
		});
	
	}
	else {
		alert ("Please enter a valid email.");
	}
}//@end 

/* ==== CREATE UPGRADE PAYMENT ==== */
function submitPaymentUpgrade() {
		
	$('#paypalform').submit(function() {
			alert('Paypal will be launched in a new browser window or tab.');
	});
	
}//@end 


// Backups r839
/* ==== SUBMIT FORM ==== */
function submitme() {
		j(".submitme").submit();
}//@end 

/* ==== SUBMIT FORM ==== */
function submitPayment() {
		$j("#paypalform").submit();
}//@end 


/* ==== HANDLE ERROR ALERTS ==== */
// Simon Gardiner, 14/04/2010 - remove all ugly standard alert boxes and replace with inline alerts.
// Requires: <div id="errorMsgPanel"></div> to be resident on the page (ie. template above content).

window.alert=function(msg){
	// Show the errorMsgPanel on the page and display the alert contents.
	if(msg != "Shipping option selected successfully." && msg != "Shipping option removed successfully.")
		{
		var cleanMsg = msg.replace(/\n/gi, "<br />");
		var alertBox = "";
		alertBox +='<div id="errorMsgBox">';
		alertBox +='<div class="errorMsgIcon"><a name="errorMsg" href="#errorMsg" onClick="Javascript:CloseAlert()" title="Hide message?"><img src="/css/images/icons/info-circle.png" border="0" /></a></div>';
		alertBox +='<div class="errorMsg">' + cleanMsg + '</div>';
		alertBox += '</div>';
		document.getElementById("errorMsgPanel").innerHTML = alertBox;
		document.getElementById("errorMsgPanel").focus();
		var secondMsgPanel =  document.getElementById("errorMsgPanel2");
                if (secondMsgPanel != null)
                    {
                    secondMsgPanel.innerHTML =  alertBox;
		    secondMsgPanel.focus();
                    }
		else
                    {
                    window.scrollTo(0,0);
                    }
		//isAvailable(); //Hide the product "of N/A" text on the product page
		}
}

// Show the errorMsgPanel on the page from a custom call.
function ErrorMessage(msg) {
		var cleanMsg = msg.replace(/\n/gi, "<br />");
		var alertBox = "";
		alertBox +='<div id="errorMsgBox">';
		alertBox +='<div class="errorMsgIcon"><a name="errorMsg" href="#errorMsg" onClick="Javascript:CloseAlert()" title="Hide message?"><img src="/css/images/icons/info-circle.png" border="0" /></a></div>';
		alertBox +='<div class="errorMsg">' + cleanMsg + '</div>';
		alertBox += '</div>';
		document.getElementById("errorMsgPanel").innerHTML = alertBox;
		document.getElementById("errorMsgPanel").focus();
		var secondMsgPanel =  document.getElementById("errorMsgPanel2");
                if (secondMsgPanel != null)
                    {
                    secondMsgPanel.innerHTML =  alertBox;
		    secondMsgPanel.focus();
                    }
		else
                    {
                    window.scrollTo(0,0);
                    }
}

// Hide the errorMsgPanel on the page.
function CloseAlert() {
    var alertBox =  document.getElementById("errorMsgPanel");
    alertBox.innerHTML ="";
    var secondAlertBox =  document.getElementById("errorMsgPanel2");
    if (secondAlertBox != null)
       {
       secondAlertBox.innerHTML ="";
       }
}
/* ==== HANDLE ERROR ALERTS ==== */

/* ==== SHOW PAGE MESSAGES FROM URL VARIABLE ==== */
// Simon Darcey, 12 Oct 2010: Show a message on the page, based on the parsed URL value.

function ShowPageMessage(thisMsg,insertedValue) {
	switch(thisMsg.toLowerCase())
		{
		case "affiliateregistered":
			{
			setTimeout("ErrorMessage('Thank You - your application has been registered and an email should appear in your inbox shortly... :o)<br>If you are not already a Free Member, please register now so that you can track your affiliate referrals.')",3000); // 3 seconds after load
			setTimeout("CloseAlert()",24000); // Close alert after 24 secs.				
		  	break;
			}		
		case "homepagereminder":
			{
			//var fullMsg = "Reminder: To visit your personal home page, access your free material, view your previous orders, or to update<br>your personal details, you can click your [";
			//fullMsg = fullMsg + insertedValue + "&rsquo;s Menu] button above at any time.";
			var fullMsg = "Reminder: To visit your personal home page, access your free material, view your previous orders,<br>or to update your personal details, you can click the &lsquo;My Items&rsquo; link in the &lsquo;Members Area&rsquo; panel to the<br>right at any time &nbsp;&raquo;";
			setTimeout("ErrorMessage('"+fullMsg+"')", 3000); // 3 seconds after load
			setTimeout("CloseAlert()",24000); // Close alert after 24 secs.
			break;
			}
		case "specialreportsent":
			{
			setTimeout("ErrorMessage('Thank You - your Special Report should appear in your inbox shortly... :o)')",3000); // 3 seconds after load
			setTimeout("CloseAlert()",24000); // Close alert after 24 secs.				
		  	break;
			}		
		case "interestregistered":
			{
			setTimeout("ErrorMessage('Thank You - your interest has been registered and an email should appear in your inbox shortly... :o)')",3000); // 3 seconds after load
			setTimeout("CloseAlert()",24000); // Close alert after 24 secs.				
		  	break;
			}
		case "interestregisteredbook":
			{
			setTimeout("ErrorMessage('Thank You - your interest has been registered and an email should appear in your inbox shortly :o)<br><br><center>*** SPECIAL 15% DISCOUNT OFFER ***<br>Like a copy of Jill Darcey&#39;s book, Parenting with the Ex Factor?<br>Simply add it to your cart now and use your 15% Discount Code at checkout: &nbsp;<u>JDBook</u></center>')",3000); // 3 seconds after load
			//setTimeout("CloseAlert()",60000); // Close alert after 60 secs.				
		  	break;
			}
		case "bookdiscountoffer":
			{
			setTimeout("ErrorMessage('<center>*** SPECIAL 15% DISCOUNT OFFER ***<br>Like a copy of Jill Darcey&#39;s book, Parenting with the Ex Factor?<br>Simply add it to your cart now and use your 15% Discount Code at checkout: &nbsp;<u>JDBook</u></center>')",3000); // 3 seconds after load
			//setTimeout("CloseAlert()",60000); // Close alert after 60 secs.				
		  	break;
			}
		case "youtubedisc":
			{
			setTimeout("ErrorMessage('<center>*** SPECIAL 15% DISCOUNT OFFER ***<br>Like a copy of Jill Darcey&#39;s book, Parenting with the Ex Factor?<br>Simply add it to your cart now and use your 15% Discount Code at checkout: &nbsp;<u>YT611</u></center>')",3000); // 3 seconds after load
			//setTimeout("CloseAlert()",60000); // Close alert after 60 secs.				
		  	break;
			}
		case "rtrpdiscountoffer":
			{
			setTimeout("ErrorMessage('<center>*** SPECIAL 15% DISCOUNT OFFER ***<br>If you&#39;re serious about getting your co-parenting routines working for you, then here&#39;s a bonus offer!<br>Add this online video program to your cart now and use your 15% Discount Code at checkout: &nbsp;<u>RTR0511</u></center>')",3000); // 3 seconds after load
			//setTimeout("CloseAlert()",60000); // Close alert after 60 secs.				
		  	break;
			}
		case "interestregisteredrtrp":
			{
			setTimeout("ErrorMessage('Thank You - your &#39;Care &amp; Routine&#39; eBook should appear in your inbox shortly... :o)<br><br><center>*** SPECIAL 15% DISCOUNT OFFER ***<br>If you&#39;re serious about getting your co-parenting routines working for you, then here&#39;s a bonus offer!<br>Add this online video program to your cart now and use your 15% Discount Code at checkout: &nbsp;<u>RTR0511</u></center>')",3000); // 3 seconds after load
			//setTimeout("CloseAlert()",60000); // Close alert after 60 secs.				
		  	break;
			}
		case "googlediscountoffer":
			{
			setTimeout("ErrorMessage('<center>*** SPECIAL 15% DISCOUNT OFFER ***<br>Like to save a little extra $$ on our already great priced products &amp; services?<br>Add any item to your cart and use the following 15% Discount Code at checkout: &nbsp;<u>Google</u></center>')",3000); // 3 seconds after load
			//setTimeout("CloseAlert()",60000); // Close alert after 60 secs.				
		  	break;
			}
		case "rtrprogramnowavailable":
			{
			setTimeout("ErrorMessage('Great news; your interest has been registered and this program is now available below!<br>Your super discount code is RTR0111 ... and an email should also appear in your inbox shortly... :o)')",3000); // 3 seconds after load
			//setTimeout("CloseAlert()",36000); // Close alert after 36 secs.				
		  	break;
			}
		case "ppprogramnowavailable":
			{
			setTimeout("ErrorMessage('Great news; your interest has been registered and this program is now available below!<br>Your super discount code is PPP0111 ... and an email should also appear in your inbox shortly... :o)')",3000); // 3 seconds after load
			//setTimeout("CloseAlert()",36000); // Close alert after 36 secs.				
		  	break;
			}
		case "questionsent":
			{
			setTimeout("ErrorMessage('Thank You - your question has been sent and I will reply as soon as possible... :o)')",3000); // 3 seconds after load
			setTimeout("CloseAlert()",24000); // Close alert after 24 secs.				
		  	break;
			}
		case "christmascompsent":
			{
			//setTimeout("ErrorMessage('Congratulations, you have been entered into the draw for your chance to win an iPad for Christmas! :o)')",3000); // 3 seconds after load
			setTimeout("ErrorMessage('Thank you, your details have been entered for future competition notification! :o)')",3000); // 3 seconds after load
			setTimeout("CloseAlert()",24000); // Close alert after 24 secs.				
		  	break;
			}
		case "christmascompstage2":
			{
			setTimeout("ErrorMessage('Congratulations, you have been entered into the draw for your chance to win an iPad for Christmas!<br>Like to improve your chances? Simply provide the missing details below to receive a 2nd entry! :o)')",3000); // 3 seconds after load
			setTimeout("CloseAlert()",24000); // Close alert after 24 secs.				
		  	break;
			}
		case "ebooksent":
			{
			setTimeout("ErrorMessage('Thank You - your eBook should appear in your inbox shortly... :o)')",3000); // 3 seconds after load
			setTimeout("CloseAlert()",24000); // Close alert after 24 secs.				
		  	break;
			}
		case "goodmorningshow":
			{
			setTimeout("ErrorMessage('Hi there and welcome! As a Good Morning Show visitor, remember to use your special discount code<br>for a 10% discount on checkout: GoodMorning')",3000); // 3 seconds after load
			setTimeout("CloseAlert()",24000); // Close alert after 24 secs.
		  	break;
			}
		case "citylife":
			{
			setTimeout("ErrorMessage('Hi there and welcome! As a City Life Show visitor, remember to use your special discount code<br>for a 20% discount on checkout: CityLife')",3000); // 3 seconds after load
			//setTimeout("CloseAlert()",24000); // Close alert after 24 secs.
		  	break;
			}
		case "seminarbooking":
			{
			setTimeout("ErrorMessage('Thank you, your details have been entered and your seat has been saved. We will contact you by email soon with your eTicket :o)')",3000); // 3 seconds after load
			//setTimeout("CloseAlert()",24000); // Close alert after 24 secs.				
		  	break;
			}
		default:
		  	{
			break;
			}
		}
}

/* ==== SHOW PAGE MESSAGES FROM URL VARIABLE ==== */

/* ==== CONVERT TEXT TO TITLE CASE ====*/

// First letter of each word converted to upper case.  Also handles special cases like 'AT&T'
String.prototype.ChangeToTitleCase = function(){
    return this.replace(/([\w&`'‘’"“.@:\/\{\(\[<>_]+-? *)/g, function(match, p1, index, title){
        match = match.toLowerCase(); // Added by Simon, as it doesn't seem to lower case all capitals.
		match = match.replace("'","’"); // Added by Simon to replace single pip ' for a safe pip.
        if (index > 0 && title.charAt(index - 2) != ":" && 
            match.search(/^(a(nd?|s|t)?|b(ut|y)|en|for|i[fn]|o[fnr]|t(he|o)|vs?\.?|via)[ -]/i) > -1)
            return match.toLowerCase();
        if (title.substring(index - 1, index + 1).search(/['"_{([]/) > -1)
            return match.charAt(0) + match.charAt(1).toUpperCase() + match.substr(2);
        if (match.substr(1).search(/[A-Z]+|&|[\w]+[._][\w]+/) > -1 ||
            title.substring(index - 1, index + 1).search(/[\])}]/) > -1)
            return match;
        return match.charAt(0).toUpperCase() + match.substr(1);
    });
}


/* ==== CONVERT TEXT TO TITLE CASE ====*/

/* ==== CREATE, READ & DELETE COOKIES ====*/
// Simon Gardiner, 16/06/2010 - create, read and delete cookies as required.

function CreateCookie(name, value, days) {
// Requires: a name-value pair for each cookie (eg. CreateCookie('FullName', theForm.FullName.value, 7)
// will create a cookie called 'FullName' with the value of a form field and store the cookie for 7 days.)
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
  else 
      { var expires = ""; }
  // Change case for Name or email...
  if (name == "CFFullName")
      { value = value.ChangeToTitleCase(); }    
  if (name == "CFEmailAddress")
      { value = value.toLowerCase(); }

  document.cookie = name+"="+value+expires+"; path=/";
}

function ReadCookie(name) {
// Requires: a name of a cookie to read (eg. ReadCookie('FullName') will find our stored cookie called 'FullName'

  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for (var i=0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
  return null;
}

function EraseCookie(name) {
// Requires: a name of a cookie to delete (eg. EraseCookie('FullName') will delete our 'FullName' cookie.

  CreateCookie(name, "", -1);
}

/* ==== CREATE, READ & DELETE COOKIES ====*/

/* ==== MANAGE FREE/PREMIUM SHOW/HIDE MENUS FOR MEMBERS ====*/

function CheckMemberMenuSubscriptionsOld(memberFirstName,memberSubscriptions) 
// Requires: memberFirstName - either a string or empty; 
// memberSubscriptions is either a string of subs, or advising not "<!--This module requires the user to be logged into a secure zone, and should only be placed on pages inside one.-->"
{
	// Test what type of subscription we have (Free or Premium)
	if (memberSubscriptions.indexOf('Premium Member') > -1)
		{// Hack #1: Change the 'Join Today' text to 'Hi FirstName' and link to the Premium Member's home page.
		document.getElementById("join").innerHTML = '<a href="http://www.complexfamily.com/members/premium/index.htm">Hi ' + memberFirstName + '</a>';
		if (memberSubscriptions.indexOf('Free Member') > -1)
			{//Hack #2: Hide the 'Free Membership Options' menu, as this is an upgraded Premium Member.
			var htmlLiTags = new Array();
			var htmlLiTags=document.getElementsByTagName("li");
			for (i=0; i < htmlLiTags.length; i++)
				{
				if (htmlLiTags[i].className == 'zoneName' && htmlLiTags[i].innerHTML.indexOf('2648461') > -1)
				htmlLiTags[i].style.display = "none"
				}							
			}
		}
	else                    
		// Logged in, but only a Free Member.     							
		document.getElementById("join").innerHTML = '<a href="http://www.complexfamily.com/members/free/index.htm">Hi ' + memberFirstName + '</a>'
}


function CheckMemberMenuSubscriptions(memberFirstName,memberSubscriptions) 
// Requires: memberFirstName - either a string or empty; 
// memberSubscriptions is either a string of subs, or advising not "<!--This module requires the user to be logged into a secure zone, and should only be placed on pages inside one.-->"
{
	document.getElementById("membersLoginBadge").innerHTML = "<a href='http://www.complexfamily.com/members/index.htm'>" + memberFirstName + "'s Menu</a>";
	// Now there's only a single member's page - regardless of whether you're free or premium.
	// Test what type of subscription we have (Free or Premium)
	//if (memberSubscriptions.indexOf('Premium Member') > -1)
	//	{// Hack #1: Change the 'Members Login' text to "FirstName's Menu" and link to the Premium Member's home page.
	//	document.getElementById("membersLoginBadge").innerHTML = "<a href='http://www.complexfamily.com/members/premium/index.htm'>" + memberFirstName + "'s Menu</a>";
	//	if (memberSubscriptions.indexOf('Free Member') > -1)
	//		{//Hack #2: Hide the 'Free Membership Options' menu, as this is an upgraded Premium Member.
	//		var htmlLiTags = new Array();
	//		var htmlLiTags=document.getElementsByTagName("li");
	//		for (i=0; i < htmlLiTags.length; i++)
	//			{
	//			if (htmlLiTags[i].className == 'zoneName' && htmlLiTags[i].innerHTML.indexOf('2648461') > -1)
	//			htmlLiTags[i].style.display = "none"
	//			}							
	//		}
	//	}
	//else                    
		// Logged in, but only a Free Member.     							
	//	document.getElementById("membersLoginBadge").innerHTML = "<a href='http://www.complexfamily.com/members/index.htm'>" + memberFirstName + "'s Menu</a>";
}
/* ==== MANAGE FREE/PREMIUM SHOW/HIDE MENUS FOR MEMBERS ====*/

/* ==== BOOKMARK / ADD TO FAVORITES ====*/

function bookmarksite(title,url) {
    if (window.sidebar) // firefox
	  window.sidebar.addPanel(title, url, "");
    else if (window.opera && window.print)
          { // opera
	  var elem = document.createElement('a');
	  elem.setAttribute('href',url);
	  elem.setAttribute('title',title);
	  elem.setAttribute('rel','sidebar');
	  elem.click();
          } 
else if (document.all) // ie
	window.external.AddFavorite(url, title);
}

/* ==== BOOKMARK / ADD TO FAVORITES ====*/

/* ==== DYNAMICALLY CHANGE VIDEOS AND SUB-TEXT ====*/
function writeSmallVideo(videoImageURL, videoURL, videoDuration, subTitleText, changeSubTitleText){
	// Check if this is a an iPhone watching this...
	if (!navigator.userAgent.match(/iPhone/i) && !navigator.userAgent.match(/iPad/i) && !navigator.userAgent.match(/iPod/i)) {								
		var so = new SWFObject("/jwplayer/player.swf", videoURL, "240", "155", "7");
		so.addParam("allowfullscreen", "true");
		so.addParam("allowscriptaccess", "always");
		so.addParam("wmode", "opaque");
		so.addVariable("id", "video-side-multi-videos-1");									
		so.addVariable("image", videoImageURL);
		so.addVariable("controlbar","bottom");
		so.addVariable('author','Jill Darcey');
		so.addVariable('description','Jill Darcey and Complex Family; Tips for Parenting with an Ex');
		so.addVariable('duration',videoDuration);
		so.addVariable("width",240);
		so.addVariable("height",155);
		so.addVariable("playlist","none");
		so.addVariable("autostart","false");
		so.addVariable("bufferlength","10");
		so.addVariable("displayclick","play");
		so.addVariable("icons","true");
		so.addVariable('title','Jill Darcey and Complex Family; Tips for Parenting with an Ex');
		so.addVariable('backcolor','EEEEEE');
		so.addVariable('frontcolor','B10057');
		so.addVariable('lightcolor','006390');
		so.addVariable('screencolor','000000');
		so.addVariable("linktarget","_blank");
		so.addVariable("mute","false");
		so.addVariable("quality","true");
		so.addVariable("repeat","none");
		so.addVariable("resizing","true");
		so.addVariable("shuffle","false");
		so.addVariable("stretching","uniform");
		so.addVariable("volume","90");
		so.addVariable("file", videoURL);	
		so.write("videocontainer-side-multi-videos-1");
		if (changeSubTitleText)
			{ document.getElementById('videocontainer-side-multi-videos-1-subtitle').innerHTML = subTitleText; }
		}
	else {									
	// This must be an iPhone, iPad or iPod...
	jwplayer("videocontainer-side-multi-videos-1").setup({ flashplayer:"/jwplayer/player.swf", file:videoURL, height:155, width:240, image:videoImageURL });									
	}								
}	

/* ==== DYNAMICALLY CHANGE VIDEOS AND SUB-TEXT ====*/
