function js_email(user, domain, suffix, mlink)
	{
	if (mlink)
		document.write('<a id="js_email" href="' + 'mailto:' + user + '@' + domain + '.' + suffix + '" >' + mlink + '</a>');
	else
		{
		mlink = user + '@' + domain + '.' + suffix;
		document.write('<a id="js_email" href="' + 'mailto:' + mlink + '" >' + mlink + '</a>');
		}
	}


function ucwords(str)
	{
    // Uppercase the first character of every word in a string  
    // version: 1001.2911 , http://phpjs.org/functions/ucwords
    return (str + '').replace(/^(.)|\s(.)/g, function ($1) {
        return $1.toUpperCase();    });
	}


function clickclear(thisfield, defaulttext)
	{
	if (thisfield.value == defaulttext)
		{
		//thisfield.value = "";
		var thisID = '#'+$(thisfield).attr('id');
		$(thisID).val('');
		//$(thisID).css('color','#777');
		}
	}

function clickrecall(thisfield, defaulttext)
	{
	if (thisfield.value == "")
		{
		//thisfield.value = defaulttext;
		var thisID = '#'+$(thisfield).attr('id');
		$(thisID).val(defaulttext);
		//$(thisID).css('color','#bbb');
		}
	}

function initiate_fields(searchDefault, townDefault)
	{
	if (document.bloo_form)
		{
		if (document.bloo_form.s.value == "")
			{
			document.bloo_form.s.value = searchDefault;
			//$("#search").css('color','#777');
			}

		if (document.bloo_form.l.value == "")
			document.bloo_form.l.value = townDefault;
		}
	}


function rand ( n )
	{
	return ( Math.floor ( Math.random ( ) * n + 1 ) );
	}

/*
function toggleLayer(whichLayer,mode,linkID,browser)
	{
	var elem, vis;

	if (browser == "gecko" || browser == "opera" || browser == "safari" || browser == "chrome" || browser == "firefox")
		{
		document.poppedLayer = eval('document.getElementById(linkID)');
		elem = document.getElementById(whichLayer);
		}
	else if (browser == "msie")
		{
		document.poppedLayer = eval('document.all[linkID]');
		elem = document.all[whichLayer];
		}
	else
		{
		document.poppedLayer = eval('document.layers[linkID]');
		elem = document.layers[whichLayer];
		}

	if (mode == "show")
		document.poppedLayer.style.visibility = "hidden";
	else if (mode == "hide")
		document.poppedLayer.style.visibility = "visible";

	vis = elem.style;
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
	}
*/

function heading(type)
	{
	if (type=='login')
		{
		hide_DIV('headingRemind');
		hide_DIV('headingCreate');
		show_DIV('headingLogin');
		}
	else if (type=='remind')
		{
		hide_DIV('headingCreate');
		hide_DIV('headingLogin');
		show_DIV('headingRemind');
		}
	else
		{
		hide_DIV('headingRemind');
		hide_DIV('headingLogin');
		show_DIV('headingCreate');
		}
	}


function webcheck(id)
	{
	/*
	var site = document.getElementById(id).value;
	
	if (site.substr(0,7)=="http://")
		return site;
	else if (site)
		return ('http://' + site);
	else
		return false;
	*/
	//var url = document.getElementById(id).value;
	//return check_url(url);
	return check_url( $('#'+id).val() );
	}

function check_url(site)
	{
	if (site.substr(0,7)=="http://")
		return site;
	else if (site)
		return ('http://' + site);
	else
		return false;
	}


function toggleBtn(btnID)
	{
	if ($('#'+btnID)[0].disabled)
		{
		$('#'+btnID)[0].disabled=false;
		$('#'+btnID).css('color', '#333');
		}
	else
		$('#'+btnID)[0].disabled=true;
	}



function searchSubmit()
	{
	var hid = $('#cid').val();
	//var hid = $('#hid').val();
	var meth = $('#meth').val();
	var filters = $('#filters').val();
	var srchString = $('#search').val();
	var srchStrChk = $('#srchval').val();
	var locString = $('#location').val();
	var pml_H = $('#pml_H').val();
	var pml_L = $('#pml_L').val();
	var old = $('#pml_old').val();

	
	$('#radCat').attr('disabled','disabled');
	$('#radName').attr('disabled','disabled');
	
	if (hid=="")
		{
		$('#cid').attr('disabled','disabled');
		if (meth=="")
			$('#meth').val('cat');
		}
	else if (meth=="")
		$('#meth').val('id');
	
	if (document.forms.bloo_form.noRecs)
		{
		var noRecs = $('#noRecs').val();
		if (noRecs=="")
			$('#noRecs').attr('disabled','disabled');
		
		var pNum = $('#pNum').val();
		if (pNum=="")
			$('#pNum').attr('disabled','disabled');
		}

	if (document.forms.bloo_form.pID)
		{
		var pID = $('#pID').val();
		if (pID=="")
			$('#pID').attr('disabled','disabled');
		}
	
	if (filters=="")
		$('#filters').attr('disabled','disabled');

	if (meth=='id' && pml_H && pml_L=="") // see if we need to update the location permalink value
		{
		var town = ucwords(locString);
		town = town.split(", ");
		town = town[0].replace("'", '_');
		//pml_L = town.replace(/[^a-zA-Z_\040]/g, '');
		//pml_L = pml_L.replace(/\040/, '-');
		//town = town.replace(/\040{2,}/, '\040');
		//town = town.replace(/[^a-zA-Z_]/g, '-');
		town = town.replace(/[^a-zA-Z0-9_]/g, '-');
		//pml_L = pml_L.replace(/\040/, '-');
		pml_L = town.replace(/-{2,}/, '-');
		
		if (pml_L=='Perth-Metro')
			pml_L = 'Perth';
		}
	
	if (pml_H && pml_L && meth=='id' && filters=="")
		{
		/*
		//if ( (pml_H.toUpperCase().substr(0,4) == srchString.toUpperCase().substr(0,4)) && (pml_L.toUpperCase().substr(0,4) == locString.toUpperCase().substr(0,4)) )
		if (pml_H.toUpperCase().substr(0,4) == srchString.toUpperCase().substr(0,4))
			{
			//alert(pml_L);
			if (old=='t')
				parent.location='/'+hid+'/'+pml_H+'/'+pml_L+'/';
			else
				parent.location='/'+pml_H+'/'+pml_L+'/WA/'+hid+'/1/';
			}
		else
			{
			$('#meth').val('cat');
			$('#cid').val('');
			document.forms.bloo_form.submit();
			}
		*/
		parent.location = (old=='t')?('/'+hid+'/'+pml_H+'/'+pml_L+'/'):('/'+pml_H+'/'+pml_L+'/WA/'+hid+'/1/');
		}
	else
		{
		// check if user has changed heading string without using drop-down
		if ( meth=='id' && (srchStrChk.toUpperCase().substr(0,4) != srchString.toUpperCase().substr(0,4)) )
			{
			$('#meth').val('cat');
			$('#cid').val('');
			}
		document.forms.bloo_form.submit();
		}
	}



function urlencode(str)
	{
	str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	return str;
	}

function urldecode(str)
	{
	str = str.replace('+', ' ');
	str = unescape(str);
	return str;
	}

function popup(url) // full screen on all browsers
	{
	params  = 'width='+(screen.width-10);
	params += ', height='+(screen.height-70); // Mozilla is fine without this, but IE6 needs it.
	params += ', top=0, left=0'

	newwin=window.open(url,'full_screen', params);
	if (window.focus) {newwin.focus()}
		return false;
	}


function checkSearchForm(what,where)
	{
	if (!document.bloo_form.search.value || document.bloo_form.search.value == what)
		{
		alert('Please enter a search category or keyword');
		document.bloo_form.search.focus();
		document.bloo_form.search.value = "";
		return false;
		}

	if (!document.bloo_form.l.value || document.bloo_form.l.value == where)
		{
		alert('Please enter a town and state');
		document.bloo_form.l.focus();
		document.bloo_form.l.value = "";
		return false;
		}
	
	return true;
	}

function trim(str, chars)
	{
	return ltrim(rtrim(str, chars), chars);
	}

function ltrim(str, chars)
	{
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	}
 
function rtrim(str, chars)
	{
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	}

function checkMail(emailaddr)
	{
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;

	if (!filter.test(trim(emailaddr)))
		{
		alert('Invalid e-mail address: ' + emailaddr + ' -- please try again.');
		return false;
		}
	return true;
	}


function checkStrLen(objValue,length)
	{
	if(objValue.value.length != length) 
		{ 
		alert("Please enter the correct length (" + length + "), currently = " + objValue.value.length + " characters!"); 
		return false; 
		}
	return true;
	}


function isNumeric(objValue)
	{
	var charpos = objValue.value.search("[^0-9]");

	if(objValue.value.length > 0 && charpos >= 0)
		{ 
		alert("Please enter digits only."); 
		return false; 
		}
	return true;
	}


function isInteger(s)
	{
	var i;
    for (i = 0; i < s.length; i++)
	    {   
        var c = s.charAt(i);
        if (((c < "0") || (c > "9")))
			return false;
	    }
    return true;
	}

function stripCharsInBag(s, bag)
	{
	var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
	    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
	    }
    return returnString;
	}

function isValidPhoneAU(strPhone)
	{
	s=stripCharsInBag(strPhone,"()- +");
	return (isInteger(s) && s.length == 10);
	}


function isValidUserName(strUser)
	{
	if (strUser && (strUser.length >= 6 && strUser.length <= 15))
		return true;
	return false;
	}

function isValidPassword(strUser)
	{
	if (strUser && (strUser.length >= 6 && strUser.length <= 15))
		return true;
	return false;
	}


function CheckForm_Contact()
	{
	if (!document.bloo_form.cust_email.value)
		{
		alert('Please enter a valid e-mail address.');
		document.bloo_form.cust_email.focus();
		return false;
		}
	else
		{
		if (!checkMail(document.bloo_form.cust_email.value))
			{
			document.bloo_form.cust_email.focus();
			return false;
			}
		}
		
	if (!document.bloo_form.cust_name.value)
		{
		alert('Please enter your name.');
		document.bloo_form.cust_name.focus();
		return false;
		}
		
	if (!document.bloo_form.cust_tel.value)
		{
		alert('Please enter a contact phone number.');
		document.bloo_form.cust_tel.focus();
		return false;
		}
		
	return true;
	}


function CheckForm_Contact_r1()
	{
	if (!document.emailEnq.name.value)
		{
		alert('Please enter your name.');
		document.emailEnq.name.focus();
		return false;
		}
	
	if (!document.emailEnq.email.value)
		{
		alert('Please enter a valid e-mail address.');
		document.emailEnq.email.focus();
		return false;
		}
	else
		{
		if (!checkMail(document.emailEnq.email.value))
			{
			document.emailEnq.email.focus();
			return false;
			}
		}
		
	if (!document.emailEnq.phone.value)
		{
		alert('Please enter a contact phone number.');
		document.emailEnq.phone.focus();
		return false;
		}
	else
		{
		if (!isValidPhoneAU(document.emailEnq.phone.value))
			{
			alert('Please only enter a 10 digit phone number (includes area code).\nSpaces, hyphens, and parentheses ARE allowed.');
			document.emailEnq.phone.focus();
			return false;
			}
		}
	
	return true;
	}


function CheckForm_Seminar()
	{
	if (!document.emailEnq.name.value)
		{
		alert('Please enter your full name.');
		document.emailEnq.name.focus();
		return false;
		}
	
	if (!document.emailEnq.email.value)
		{
		alert('Please enter a valid e-mail address.');
		document.emailEnq.email.focus();
		return false;
		}
	else
		{
		if (!checkMail(document.emailEnq.email.value))
			{
			document.emailEnq.email.focus();
			return false;
			}
		}
		
	if (!document.emailEnq.phone.value)
		{
		alert('Please enter a contact phone number.');
		document.emailEnq.phone.focus();
		return false;
		}
	
	if (!document.emailEnq.biz_name.value)
		{
		alert('Please enter your place of work.');
		document.emailEnq.biz_name.focus();
		return false;
		}

	if (!document.emailEnq.biz_addr.value)
		{
		alert('Please enter your address.');
		document.emailEnq.biz_addr.focus();
		return false;
		}

	if (!document.emailEnq.biz_town.value)
		{
		alert('Please enter a suburb or city.');
		document.emailEnq.biz_town.focus();
		return false;
		}

	if (!document.emailEnq.biz_pcode.value)
		{
		alert("Please enter your town's postcode.");
		document.emailEnq.biz_pcode.focus();
		return false;
		}
	
	if (!document.emailEnq.ccnumber.value)
		{
		alert("Please enter your credit card number.");
		document.emailEnq.ccnumber.focus();
		return false;
		}
	
	if (!document.emailEnq.ccname.value)
		{
		alert("Please enter the name on your credit card.");
		document.emailEnq.ccname.focus();
		return false;
		}
	
	if (!document.emailEnq.ccexpiry_month.value)
		{
		alert("Please enter the expiry month.");
		document.emailEnq.ccexpiry_month.focus();
		return false;
		}
	
	if (!document.emailEnq.ccexpiry_year.value)
		{
		alert("Please enter the expiry year.");
		document.emailEnq.ccexpiry_year.focus();
		return false;
		}

	return true;
	}


function CheckForm_Referrals()
	{
	
	/* 
	if(!$('.formInputField.req').val())
		{
		alert("This field is required.");
		var name = $(this).attr('name');
		alert (name);
		//document.emailEnq.biz_pcode.focus();
		return false;
		}
	*/
	
	
	
	if (!document.emailEnq.name.value)
		{
		alert('Please enter your full name.');
		document.emailEnq.name.focus();
		return false;
		}
	
	if (!document.emailEnq.email.value)
		{
		alert('Please enter a valid e-mail address.');
		document.emailEnq.email.focus();
		return false;
		}
	else
		{
		if (!checkMail(document.emailEnq.email.value))
			{
			document.emailEnq.email.focus();
			return false;
			}
		}
		
	if (!document.emailEnq.phone.value)
		{
		alert('Please enter a contact phone number.');
		document.emailEnq.phone.focus();
		return false;
		}
	
	if (!document.emailEnq.biz_name.value)
		{
		alert('Please enter your place of work.');
		document.emailEnq.biz_name.focus();
		return false;
		}
	
	if (!document.emailEnq.biz_addr.value)
		{
		alert('Please enter your address.');
		document.emailEnq.biz_addr.focus();
		return false;
		}
	
	if (!document.emailEnq.biz_town.value)
		{
		alert('Please enter a suburb or city.');
		document.emailEnq.biz_town.focus();
		return false;
		}
	
	if (!document.emailEnq.biz_pcode.value)
		{
		alert("Please enter your town's postcode.");
		document.emailEnq.biz_pcode.focus();
		return false;
		}

	

	if (!document.emailEnq.name1.value)
		{
		alert("Please enter the contact's name.");
		document.emailEnq.name1.focus();
		return false;
		}

	if (!document.emailEnq.phone1.value)
		{
		alert("Please enter the contact's phone number.");
		document.emailEnq.phone1.focus();
		return false;
		}
	
	/*
	if (!document.emailEnq.name2.value)
		{
		alert("Please enter the contact's name.");
		document.emailEnq.name2.focus();
		return false;
		}
	
	if (!document.emailEnq.phone2.value)
		{
		alert("Please enter the contact's phone number.");
		document.emailEnq.phone2.focus();
		return false;
		}
	
	if (!document.emailEnq.name3.value)
		{
		alert("Please enter the contact's name.");
		document.emailEnq.name3.focus();
		return false;
		}
	
	if (!document.emailEnq.phone3.value)
		{
		alert("Please enter the contact's phone number.");
		document.emailEnq.phone3.focus();
		return false;
		}
	
	if (!document.emailEnq.name4.value)
		{
		alert("Please enter the contact's name.");
		document.emailEnq.name4.focus();
		return false;
		}
	
	if (!document.emailEnq.phone4.value)
		{
		alert("Please enter the contact's phone number.");
		document.emailEnq.phone4.focus();
		return false;
		}
	
	if (!document.emailEnq.name5.value)
		{
		alert("Please enter the contact's name.");
		document.emailEnq.name5.focus();
		return false;
		}
	
	if (!document.emailEnq.phone5.value)
		{
		alert("Please enter the contact's phone number.");
		document.emailEnq.phone5.focus();
		return false;
		}
	*/
	
	
	return true;
	}




function CheckForm_RegContact()
	{
	if (!document.bloo_form.cust_email.value)
		{
		alert('Please enter a valid e-mail address.');
		document.bloo_form.cust_email.focus();
		return false;
		}
	else
		{
		if (!checkMail(document.bloo_form.cust_email.value))
			{
			document.bloo_form.cust_email.focus();
			return false;
			}
		}
		
	if (!document.bloo_form.cust_fname.value)
		{
		alert('Please enter your first name.');
		document.bloo_form.cust_fname.focus();
		return false;
		}

	if (!document.bloo_form.cust_sname.value)
		{
		alert('Please enter your last name.');
		document.bloo_form.cust_sname.focus();
		return false;
		}

	if (!document.bloo_form.cust_mob.value)
		{
		alert('Please enter a contact phone number.');
		document.bloo_form.cust_mob.focus();
		return false;
		}
		
	return true;
	}


function CheckForm_Register()
	{
	if (CheckForm_RegContact())
		{
		if (!isValidPhoneAU(document.bloo_form.cust_mob.value))
			{
			alert('Please only enter a 10 digit phone number (includes area code).\nSpaces, hyphens, and parentheses are allowed.');
			document.bloo_form.cust_mob.focus();
			return false;
			}

		if (!isValidPassword(document.bloo_form.cust_pass.value))
			{
			alert('Please enter a unique 6-15 character password.');
			document.bloo_form.cust_pass.focus();
			return false;
			}
		}
	else
		{
		return false;
		}

	document.forms.bloo_form.submit();
	//return true;
	}


function CheckForm_userReg()
	{
	if (!document.userReg.n.value)
		{
		alert('Please enter a business name');
		document.userReg.n.focus();
		return false;
		}

	if (!document.userReg.l.value)
		{
		alert('Please enter a city or town');
		document.userReg.l.focus();
		return false;
		}

	return true;
	}


function verify_DIY(form_type)
	{
	if (!document.diyForm.Title.value)
		{
		alert('Please enter your business name.');
		document.diyForm.Title.focus();
		return false;
		}

	if (!document.diyForm.ABN.value)
		{
		alert('Please enter your Australian Business Number.');
		document.diyForm.ABN.focus();
		return false;
		}
	else
		{
		if (!isNumeric(document.diyForm.ABN))
			{
			document.diyForm.ABN.focus();
			return false;
			}
		}

	if (!document.diyForm.Street.value)
		{
		alert('Please enter a street address.');
		document.diyForm.Street.focus();
		return false;
		}

	if (!document.diyForm.Town.value)
		{
		alert('Please enter a town or city.');
		document.diyForm.Town.focus();
		return false;
		}

	if (!document.diyForm.State.value)
		{
		alert('Please select a state.');
		document.diyForm.State.focus();
		return false;
		}

	if (!document.diyForm.Postcode.value)
		{
		alert('Please enter a postcode.');
		document.diyForm.Postcode.focus();
		return false;
		}
	else
		{
		if (!isNumeric(document.diyForm.Postcode))
			{
			document.diyForm.Postcode.focus();
			return false;
			}

		if (!checkStrLen(document.diyForm.Postcode,4))
			{
			document.diyForm.Postcode.focus();
			return false;
			}
		}

	if (!document.diyForm.Telephone.value)
		{
		alert('Please enter a contact telephone number.');
		document.diyForm.Telephone.focus();
		return false;
		}

	if (!document.diyForm.Email.value)
		{
		alert('Please enter a valid e-mail address.');
		document.diyForm.Email.focus();
		return false;
		}
	else
		{
		if (!checkMail(document.diyForm.Email.value))
			{
			document.diyForm.Email.focus();
			return false;
			}
		}

	if (form_type == "checkout")
		return true;
	else
		document.forms.diyForm.submit();
	}


function verify_Billing()
	{
	if (verify_DIY("checkout"))
		{
		if (!document.diyForm.Password.value)
			{
			alert('Please enter a password for your account.');
			document.diyForm.Password.focus();
			return false;
			}

		if (!document.diyForm.bStreet.value)
			{
			alert('Please enter a street address.');
			document.diyForm.bStreet.focus();
			return false;
			}

		if (!document.diyForm.bTown.value)
			{
			alert('Please enter a town or city.');
			document.diyForm.bTown.focus();
			return false;
			}

		if (!document.diyForm.bState.value)
			{
			alert('Please select a state.');
			document.diyForm.bState.focus();
			return false;
			}

		if (!document.diyForm.bPostcode.value)
			{
			alert('Please enter a postcode.');
			document.diyForm.bPostcode.focus();
			return false;
			}
		else
			{
			if (!isNumeric(document.diyForm.bPostcode))
				{
				document.diyForm.bPostcode.focus();
				return false;
				}

			if (!checkStrLen(document.diyForm.bPostcode,4))
				{
				document.diyForm.bPostcode.focus();
				return false;
				}
			}

		if (!document.diyForm.bTelephone.value)
			{
			alert('Please enter a contact telephone number.');
			document.diyForm.bTelephone.focus();
			return false;
			}

		if (!document.diyForm.bEmail.value)
			{
			alert('Please enter a valid e-mail address.');
			document.diyForm.bEmail.focus();
			return false;
			}
		else
			{
			if (!checkMail(document.diyForm.bEmail.value))
				{
				document.diyForm.bEmail.focus();
				return false;
				}
			}

		if (document.diyForm.pmethod[0].checked) // method == online
			{
			if (!document.diyForm.CardType.value)
				{
				alert('Please select a card type.');
				document.diyForm.CardType.focus();
				return false;
				}

			if (!document.diyForm.CardName.value)
				{
				alert('Please enter the name on the card.');
				document.diyForm.CardName.focus();
				return false;
				}

			if (!document.diyForm.CardNum.value)
				{
				alert('Please enter a card number.');
				document.diyForm.CardNum.focus();
				return false;
				}
			else
				{
				if (!isNumeric(document.diyForm.CardNum))
					{
					document.diyForm.CardNum.focus();
					return false;
					}
				}

			if (!document.diyForm.CardMth.value)
				{
				alert('Please select the month of expiry.');
				document.diyForm.CardMth.focus();
				return false;
				}

			if (!document.diyForm.CardYr.value)
				{
				alert('Please select the year of expiry.');
				document.diyForm.CardYr.focus();
				return false;
				}

			if (!document.diyForm.CardCVV2.value)
				{
				alert('Please enter the verification number.');
				document.diyForm.CardCVV2.focus();
				return false;
				}
			else
				{
				if (!isNumeric(document.diyForm.CardCVV2))
					{
					document.diyForm.CardCVV2.focus();
					return false;
					}
				}
			}
		return true;
		}
	else
		{
		return false;
		}
	}


function verify_PCodes()
	{
	if (document.diyForm.pcode1.value || document.diyForm.pcode2.value || document.diyForm.pcode3.value || document.diyForm.pcode4.value || document.diyForm.pcode5.value)
		{
		if ( document.diyForm.pcode1.value && (!isNumeric(document.diyForm.pcode1) || !checkStrLen(document.diyForm.pcode1,4)) )
			{
			document.diyForm.pcode1.focus();
			return false;
			}
		if ( document.diyForm.pcode2.value && (!isNumeric(document.diyForm.pcode2) || !checkStrLen(document.diyForm.pcode2,4)) )
			{
			document.diyForm.pcode2.focus();
			return false;
			}
		if ( document.diyForm.pcode3.value && (!isNumeric(document.diyForm.pcode3) || !checkStrLen(document.diyForm.pcode3,4)) )
			{
			document.diyForm.pcode3.focus();
			return false;
			}
		if ( document.diyForm.pcode4.value && (!isNumeric(document.diyForm.pcode4) || !checkStrLen(document.diyForm.pcode4,4)) )
			{
			document.diyForm.pcode4.focus();
			return false;
			}
		if ( document.diyForm.pcode5.value && (!isNumeric(document.diyForm.pcode5) || !checkStrLen(document.diyForm.pcode5,4)) )
			{
			document.diyForm.pcode5.focus();
			return false;
			}
		}
	}


function copyToBillingFields()
	{
	document.adSelection.bStreet.value    = document.adSelection.co_street.value;
	document.adSelection.bTown.value	  = document.adSelection.co_town.value;
	document.adSelection.bState.value	  = document.adSelection.co_state.value;
	document.adSelection.bPostcode.value  = document.adSelection.co_pcode.value;
	document.adSelection.bEmail.value     = document.adSelection.co_email.value;
	document.adSelection.bMobile.value    = document.adSelection.co_mob.value;
	document.adSelection.bTelephone.value = document.adSelection.co_tel.value;
	document.adSelection.bFacsimile.value = document.adSelection.co_fax.value;
	}


function copy_Register_email()
	{
	document.bloo_form.user_id.value = document.bloo_form.cust_email.value;
	}


function blooSubOff(offset)
	{
	document.bloo_form.Offset.value = offset;
	document.bloo_form.submit();
	}

function blooSubCat(catNo)
	{
	document.bloo_form.catVal.value = catNo;
	document.bloo_form.submit();
	}

function blooSubRecs(recsCount)
	{
	document.bloo_form.noRecs.value = recsCount;
	document.bloo_form.submit();
	}

function blooSubAll(recsCount,pNum,cID,pID,cbd,filters)
	{
	document.bloo_form.noRecs.value = recsCount;
	//document.bloo_form.pTot.value = pTot;
	document.bloo_form.pNum.value = pNum;
	document.bloo_form.id.value = cID;
	document.bloo_form.pID.value = pID;
	document.bloo_form.f.value = filters;
	if (cID)
		document.bloo_form.m.value = 'id';
	
	/*
	if (cbd)
		document.bloo_form.city_only.value = cbd;
	*/
	
	//document.bloo_form.submit();
	searchSubmit();
	}


function setStyle(obj,style,value)
	{
	this.obj=getRef(obj);
	this.obj.style[style]=value;
	}

function getStyle(obj, style)
	{
	if(!document.getElementById)
		return;

	var obj = getRef(obj);
	var value = obj.style[style];

	if(!value)
		if(document.defaultView)
			value = document.defaultView.getComputedStyle(obj, "").getPropertyValue(style);
		else if(obj.currentStyle)
			value = obj.currentStyle[style];

	return value;
	}

function getRef(obj)
	{
	if(typeof obj == "string")
		obj = document.getElementById(obj);
	return obj;
	}

function setClassName(objId, className)
	{
    document.getElementById(objId).className = className;
	}


function ShowHelp(div, title, desc)
	{
	div = document.getElementById(div);
	div.style.display = 'inline';
	div.style.position = 'absolute';
	div.style.width = '400px';
	div.style.backgroundColor = '#d1d1d1';
	div.style.border = 'solid 2px #f5f5f5';
	div.style.padding = '7px';
	div.style.fontSize = '11px';
	div.style.color = 'black';
	/*
	div.ul.li.style.listStyleImage = 'none';
	div.style.listStyleType = 'none';
	*/
	div.innerHTML = '<strong>' + title + '</strong><br/><p>' + desc + '</p>';
	}

function HideHelp(div)
	{
	div = document.getElementById(div);
	div.style.display = 'none';
	}

function statesDropSelect(targ,selObj,restore)
	{ //v3.0
	eval(targ+".location='?State="+selObj.options[selObj.selectedIndex].value+"'");
	if (restore)
		selObj.selectedIndex=0;
	}

function checkRadio()
	{
	if (document.forms.diyForm.manualCats.checked)
		return true;
	return false;
	}

function checkSelect(selobj)
	{
	var selectedOption = selobj[selobj.selectedIndex];
	var label = selectedOption.firstChild.nodeValue;
	var selectedValue = selectedOption.value;

	if (selectedValue=="")
		document.getElementById('diyCatSub1').style.visibility="hidden";
	else
		{
		document.getElementById('autoCats').value = selectedValue;
		document.getElementById('category_auto').value = label;
		document.getElementById('diyCatSub1').style.visibility="visible";
		}
	}

function checkDIYcatEnter(selobj)
	{
	document.getElementById('diyCatSub1').style.visibility="visible";
	}

function checkDIYcatLeave(selobj)
	{
	if (selobj.value == "")
		{
		document.getElementById('diyCatSub1').style.visibility="hidden";
		document.forms.diyForm.reset();
		}
	}



function move_box(an, box)
	{
    var cleft = 0;
    var ctop = 0;
    var obj = an;

    while (obj.offsetParent)
	    {
        cleft += obj.offsetLeft;
        ctop += obj.offsetTop;
        obj = obj.offsetParent;
	    }

    box.style.left = cleft + 'px';

    ctop += an.offsetHeight + 8;

	if (document.body.currentStyle &&
        document.body.currentStyle['marginTop'])
	    {
        ctop += parseInt(
            document.body.currentStyle['marginTop']);
	    }

    box.style.top = ctop + 'px';
	}



function IFrame(parentElement)
	{
	// Create the iframe which will be returned
	var iframe = document.createElement("iframe");
	
	// If no parent element is specified then use body as the parent element
	if(parentElement == null)
	  parentElement = document.body;
	 
//	 parentElement.style.backgroundColor = 'transparent';
	
	// This is necessary in order to initialize the document inside the iframe
	parentElement.appendChild(iframe);
	
	// Initiate the iframe's document to null
	iframe.doc = null;
	
	// Depending on browser platform get the iframe's document, this is only
	// available if the iframe has already been appended to an element which
	// has been added to the document
	if(iframe.contentDocument)
	  // Firefox, Opera
	  iframe.doc = iframe.contentDocument;
	else if(iframe.contentWindow)
	  // Internet Explorer
	  iframe.doc = iframe.contentWindow.document;
	else if(iframe.document)
	  // Others?
	  iframe.doc = iframe.document;
	
	// If we did not succeed in finding the document then throw an exception
	if(iframe.doc == null)
	  throw "Document not found, append the parent element to the DOM before creating the IFrame";
	
	// Create the script inside the iframe's document which will call the
	iframe.doc.open();
	iframe.doc.close();
	
	// Return the iframe, now with an extra property iframe.doc containing the
	// iframe's document
	return iframe;
	}



//function show_hide_box(an, width, height, borderStyle)
//function show_hide_box_old(an, width, height, borderStyle, boxID)
function show_hide_box_old(an, titleMsgTxt, boxID) // use for IE
	{
	var browser=navigator.appName;
	var version=(navigator.appVersion).substring(22,23);
	
	width=272;
	//height=183;
	height=170;
	//borderStyle='none';
	borderStyle='1px solid #ccc';
    var href = an.href;
	var boxdiv = document.getElementById(boxID);
	
//	alert(href);
//	alert(boxID);

	if (boxdiv != null)
	    {
        if (boxdiv.style.display=='none')
    	    {
            move_box(an, boxdiv);

			boxdiv.style.display='block';
            bringToFront(boxdiv);

            if (!boxdiv.contents.contentWindow)
                boxdiv.contents.src = href;
        	}
        else
            boxdiv.style.display='none';
        return false;
	    }

    boxdiv = document.createElement('div');
    boxdiv.setAttribute('id', boxID);
    boxdiv.setAttribute('class', 'c2c_fr');
    boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
	boxdiv.style.marginTop = '-80px';
//    boxdiv.style.marginTop = '-90px';
	boxdiv.style.width = width + 'px';
    boxdiv.style.height = height + 'px';
    boxdiv.style.border = borderStyle;
    boxdiv.style.textAlign = 'right';
    boxdiv.style.padding = '4px';
    boxdiv.style.background = '#FFFFFF';
    boxdiv.style.zIndex = '100';

	document.body.appendChild(boxdiv);

    var padlock = document.createElement('img');
//	padlock.src = 'http://www.beamme.info/images/beamicon/beamlock.png';
	padlock.src = '/img/basics/beamlock.gif';
	padlock.title = 'Secured by RapidSSL 128-bit encryption';
	padlock.align = 'left';
    boxdiv.appendChild(padlock);

    var closebtn = document.createElement('img');
	closebtn.src = '/img/boxes/box_bloo_call_close-btn_r2.gif';
	closebtn.title = 'Close Window';
//	closebtn.align = 'right';
//	closebtn.style.marginRight = '0px';
	closebtn.border = '0';
//    boxdiv.appendChild(closebtn);
	
    var close_href = document.createElement('a');
	close_href.href = 'javascript:void(0);';
	close_href.onclick = function()
        {
        contents.contentWindow.document.location.replace(href); // probably need a check of current state so we don't do this unnecessarily
		//show_hide_box(an, width, height, borderStyle);
		//show_hide_box_old(an, width, height, borderStyle, boxID);
		show_hide_box_old(an, titleMsgTxt, boxID)
		}

    var offset = 0;
//	close_href.appendChild(document.createTextNode('Close'));
	//close_href.appendChild(document.createTextNode('[X]'));
	//close_href.appendChild(document.createTextNode(''));
	close_href.appendChild(closebtn);
	
//    close_href.style.backgroundColor = 'white';
//    close_href.style.border = '1px solid #bbb;';
//    close_href.style.border = '1px';
	
    boxdiv.appendChild(close_href);
    offset = close_href.offsetHeight;

    var contents = document.createElement('iframe');
    //contents.setAttribute('name', an.id);
    //contents.setAttribute('name', boxID);

	contents.scrolling = 'no'; // needed?
    contents.overflowX = 'hidden';
    contents.overflowY = 'scroll'; // needed?
    contents.overflowY = 'fixed';
    contents.frameBorder = '0';
    contents.style.width = width + 'px';
    contents.style.height = (height - offset) + 'px';

    boxdiv.contents = contents;
    boxdiv.appendChild(contents);

    move_box(an, boxdiv);

    if (contents.contentWindow)
        contents.contentWindow.document.location.replace(href);
    else
        contents.src = href;

    return false;
	}



function show_hide_box(an, titleMsgTxt, boxID) // use for everything but IE
	{
	var browser=navigator.appName;
	var version=(navigator.appVersion).substring(22,23);
	
	width=272;
	height=183;
	borderStyle='none';
	
    var href = an.href;
	var canvas = document.getElementById(boxID); // this is our canvas
	
	if (canvas != null)
	    {
        if (canvas.style.display=='none')
    	    {
            move_box(an, canvas);

			canvas.style.display='block';
            bringToFront(canvas);
			
            if (!canvas.contents.contentWindow)
                canvas.contents.src = href;
        	}
        else
            canvas.style.display='none';
        return false;
	    }
	
    var padlock = document.createElement('img');
	padlock.src = '/img/basics/beamlock.gif';
	padlock.title = 'Secured by RapidSSL 128-bit encryption';
	padlock.align = 'left';
    padlock.style.marginTop = '5px';
	
    var titleMsg = document.createElement('div');
	titleMsg.appendChild(document.createTextNode(titleMsgTxt));
    titleMsg.style.color = '#8d8d8d';
    titleMsg.style.fontFamily = 'Arial, Helvetica, sans-serif';
    titleMsg.style.fontSize = '11px';
    titleMsg.style.fontWeight = 'bold';
    titleMsg.style.position = 'absolute';
    titleMsg.style.top = '15px';
    titleMsg.style.left = '20px';

    var close_href = document.createElement('a');
	close_href.href = 'javascript:void(0);';
	close_href.title = 'Close Window';
	close_href.onclick = function()
        {
        contents.contentWindow.document.location.replace(href);
		show_hide_box(an, titleMsgTxt, boxID);
		}

    var offset = 0;
	close_href.appendChild(document.createTextNode('X'));
    offset = close_href.offsetHeight;

    close_href.style.color = '#009bc2';
    close_href.style.fontFamily = 'Arial, Helvetica, sans-serif';
    close_href.style.fontSize = '12px';
    close_href.style.fontWeight = 'bold';
    close_href.style.textDecoration = 'none';
    close_href.style.position = 'absolute';
    close_href.style.top = '5px';
    close_href.style.right = '16px';
    close_href.style.padding = '1px';

	var contents = new IFrame(canvas);
    contents.setAttribute('id', 'if' + boxID); // e.g. "ifDIV1300buzz"
    contents.setAttribute('name', 'if' + boxID); // e.g. "ifDIV1300buzz"
    contents.setAttribute('allowTransparency', 1);  // this works for IE and is not needed for FF
	contents.scrolling = 'no';  // this works for FF (and others) but not at all in IE
    contents.overflowX = 'hidden';  // this works for FF (and others) but not at all in IE
    contents.overflowY = 'fixed';  // this works for FF (and others) but not at all in IE
    contents.frameBorder = '0';  // this works for FF (and others) but not at all in IE
    contents.style.width = width + 'px';
    contents.style.height = (height - offset) + 'px';

    var boxdiv = document.createElement('div'); // METHOD 1... GOOD FOR FF
    boxdiv.setAttribute('id', boxID); // e.g. "DIV1300buzz"
    boxdiv.setAttribute('class', 'c2c_fr');
    boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
    boxdiv.style.marginTop = '-80px';
	boxdiv.style.width = width + 'px';
    boxdiv.style.height = height + 'px';
    boxdiv.style.border = borderStyle;
    boxdiv.style.textAlign = 'right';
    boxdiv.style.padding = '4px';
	boxdiv.style.zIndex = '500'; // stops text showing through the background
	
	/* if (browser=='Microsoft Internet Explorer' && version<=6)
	    boxdiv.style.background = "url('/img/boxes/box_bloo_call_us_ok_box only copy_crop2.gif') no-repeat top left";
	else */
	    boxdiv.style.background = "url('/img/boxes/box_bloo_call_us_ok_box only copy_crop.png') no-repeat top left";

    boxdiv.appendChild(padlock);
    boxdiv.appendChild(titleMsg);
    boxdiv.appendChild(close_href);

	boxdiv.contents = contents; // METHOD 1... GOOD FOR FF ... just added back in -- important as it stops window opening into new document on second click -- correct
    boxdiv.appendChild(contents); // METHOD 1... GOOD FOR FF
	document.body.appendChild(boxdiv); // METHOD 1... GOOD FOR FF
	
    if (contents.contentWindow)
        contents.contentWindow.document.location.replace(href);
    else
        contents.src = href; // works in FF
	
    move_box(an, boxdiv); // fixes up positioning of initial load -- correct

    return false;
	}



function getAbsoluteDivs()
	{
    var arr = new Array();
    var all_divs = document.body.getElementsByTagName("DIV");
    var j = 0;

    for (i = 0; i < all_divs.length; i++)
        if (all_divs.item(i).style.position=='absolute')
        {
            arr[j] = all_divs.item(i);
            j++;
        }

    return arr;
	}

function bringToFront(obj)
	{
    obj.style.zIndex = 600;
	}



function disableChkBox(chkBoxNo)
	{
	var x = document.forms.dupesChkList.cbTot.value+1;

	for (var i=1; i<x; i++)
		{
		if (i == chkBoxNo)
			{
			var cid = document.forms.dupesChkList.elements['cb' + i].value;
			document.forms.dupesChkList.elements['cb' + i].checked=false;
			document.forms.dupesChkList.elements['cb' + i].disabled=true;
			document.forms.dupesChkList.elements['cb' + i].style.display='none';
			document.forms.dupesChkList.elements['sb' + i].style.display='inline';
			}
		else if (document.forms.dupesChkList.elements['cb' + i])
			{
			document.forms.dupesChkList.elements['cb' + i].disabled=false;
			document.forms.dupesChkList.elements['cb' + i].style.display='inline';
			document.forms.dupesChkList.elements['sb' + i].style.display='none';
			}
		}

	for (var i=1; i<x; i++)
		{
		if (document.forms.dupesChkList.elements['ib' + i])
			document.forms.dupesChkList.elements['ib' + i].value = cid;
		}
	}


function handleEnter (field, event)
	{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13)
		{
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
		}
	else
		return true;
	}


function changeInputType(oldObject, oType)
	{
	var newObject = document.createElement('input');
	newObject.type = oType;

	if(oldObject.size) newObject.size = oldObject.size;
	//if(oldObject.value) newObject.value = oldObject.value;
	if(oldObject.name) newObject.name = oldObject.name;
	if(oldObject.id) newObject.id = oldObject.id;
	if(oldObject.className) newObject.className = oldObject.className;

	oldObject.parentNode.replaceChild(newObject,oldObject);

    //document.getElementById('pass').focus();
	//newObject.focus();
	return newObject;
	}




/*
// Clear prompt from username field, if required.
function clearUsernamePrompt()
	{
	var username = document.getElementById("username");
	if (username.value == "User name")
		{
		username.value = "";
		$('#errors').html('');
		}
	}

// Set the prompt for the username field, if required.
function setUsernamePrompt()
	{
	var username = document.getElementById("username");
	if (username.value == "")
		username.value = "User name";
	}

// Clear prompt from password field, if required.
function clearPasswordPrompt()
	{
	var password = document.getElementById("password");
	password.style.display = "inline";
	password.focus();
	var passwordPrompt = document.getElementById("passwordPrompt");
	if (passwordPrompt.value == "Password")
		$('#errors').html('');
	passwordPrompt.style.display = "none";
	}

// Set the prompt for the password field, if required.
function setPasswordPrompt()
	{
	var password = document.getElementById("password");
	if (password.value == "")
		{
		password.style.display = "none";
		var passwordPrompt = document.getElementById("passwordPrompt");
		passwordPrompt.style.display = "inline";
		}
	}
*/


function clearUsernamePrompt()
	{
	if ($("#username").val() == "User name")
		{
		$("#username").val('');
		$('.errors').html('');
		}
	}

function setUsernamePrompt()
	{
	if ($("#username").val() == "")
		$("#username").val('User name');
	}

function clearPasswordPrompt()
	{
	$("#password").show().focus();
	if ($("#passwordPrompt").val() == "Password")
		$('.errors').html('');
	$("#passwordPrompt").hide();
	}

function setPasswordPrompt()
	{
	if ($("#password").val() == "")
		{
		$("#password").hide();
		$("#passwordPrompt").show();
		}
	}

function clearUsernamePrompt_alt()
	{
	if ($("#alt_username").val() == "User name")
		{
		$("#alt_username").val('');
		$('.errors').html('');
		}
	}

function setUsernamePrompt_alt()
	{
	if ($("#alt_username").val() == "")
		$("#alt_username").val('User name');
	}

function clearPasswordPrompt_alt()
	{
	$("#alt_password").show().focus();
	if ($("#alt_passwordPrompt").val() == "Password")
		$('.errors').html('');
	$("#alt_passwordPrompt").hide();
	}

function setPasswordPrompt_alt()
	{
	if ($("#alt_password").val() == "")
		{
		$("#alt_password").hide();
		$("#alt_passwordPrompt").show();
		}
	}




function cacheAdImages()
	{
	image1 = new Image(129,407);
	image1.src = "/img/GMG/advertise/options-overlay-01b.png";
	image2 = new Image(129,407);
	image2.src = "/img/GMG/advertise/options-overlay-02b.png";
	image3 = new Image(129,407);
	image3.src = "/img/GMG/advertise/options-overlay-03b.png";
	image4 = new Image(129,407);
	image4.src = "/img/GMG/advertise/options-overlay-04b.png";
	}

function advertiseOption(blooProduct)
	{
	obj = blooProduct;
	if (obj == 'blooFree' )
		{
		adClear();
		adClicked();
		adSelection();
		} 
	else if (obj == 'blooBasic' )
		{
		adClear();
		adClicked();
		adSelection();
		} 
	else if (obj == 'blooBonus' )
		{
		adClear();
		adClicked();
		adSelection();
		}
	else if (obj == 'blooBusiness' )
		{
		adClear();
		adClicked();
		adSelection();
		}
	}

function adClear()
	{
	document.getElementById('blooFree').className = "blooProduct";
	document.getElementById('blooBasic').className = "blooProduct";
	document.getElementById('blooBonus').className = "blooProduct";
	document.getElementById('blooBusiness').className = "blooProduct";						
	}

function adClicked()
	{
	document.getElementById(obj).className += " selected";
	}
	
function adSelection()
	{
	document.getElementById('productChoice').value = obj;
	}

function testAdSelection()
	{
	alert(document.getElementById('productChoice').value);
	}


function updateAdvancedTxt(keyTerm)
	{
	var fieldVal = document.getElementById('advSrchText').value;

	if (fieldVal && keyTerm)
		document.getElementById('advSrchText').value += ('; ' + keyTerm);
	else if (keyTerm)
		document.getElementById('advSrchText').value = keyTerm;
	}


checked=false;
function checkAll(formID,cbID,allID)
	{
	var aa = document.getElementById(formID);

	if (checked == false)
		checked = true;
	else
		checked = false;

	for (var i=0;i<aa.elements.length;i++)
		{
		var e=aa.elements[i];

		if ((e.id == cbID || e.id == allID) && (e.type=='checkbox'))
			e.checked = checked;
		}
	}

function addEvent( element, event_type, callback ) { 

	if ( typeof( element ) == 'string' ) {
		element = document.getElementById( element );
	}
	
	if ( element.addEventListener ) { 
		element.addEventListener( event_type, callback, false ); 
		return true; 
	} else if ( element.attachEvent ) { 
		var r = element.attachEvent( "on" + event_type, callback ); 
		return r; 
	} else { 
		return false; 
	} 
}


function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}


function limitChars(textid, limit, infodiv)
	{
	var text = $('#'+textid).val();	
	var textlength = text.length;
	if(textlength > limit)
		{
		$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
		$('#'+textid).val(text.substr(0,limit));
		return false;
		}
	else
		{
		$('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
		return true;
		}
	}




