// Copyright 1999 - 2007 - The website owner asserts copyright on this program and all of its components

if ((top.location != location) && (id != "628"))
   { // I'm displaying in a frame - notify me and the reader then break out.
    record("Framed in " + top.location + "destination is " + document.location.href);
    location.href = "framed.php?container=" + top.location.href + "&destination=" + document.location.href;
  };

function bookmark(url){
  if (document.all)
  window.external.AddFavorite(url,"UK Life Coaching page");
  record('Bookmarking ' + url);
};

function get_items_total()
{var LinePrice, PriceTotal = 0, items, mycookie = GetCookie("order");
 if   (mycookie == "")
      {return 0;
	  }
 else {items = mycookie.split('|');
       count = items.length;
	   for (var i=0; i<count; i++)
           {parts = items[i].split("^");
            LinePrice = parts[10];
	        PriceTotal += LinePrice/1;
           }; 
     return PriceTotal;
	 };
};

function report_error(msg, url, line)
{var info;
 info =  'msg=' + msg + ', url=' + url + ', line=' + line;
 record('WEBPAGEERROR>>>' + info);
 alert('Sorry, there is a minor problem with this page:\n\n'+
	    info + '\n\n' +
       'The fault has been logged & we will fix it soon.\n\n' +
       'Meanwhile, this page may - or may not - work correctly for you.\n\n' +
       'If you are not using Internet Explorer - then using it will probably avoid this error.\n' +
       'Alternatively, you are welcome to email or phone on 01234 306993 during UK office hours.\n\n'+
       'Once again, we apologise for any inconvenience this may have caused you.');
 return true;
};
window.onerror = report_error;

var UTILversion = 1;

function GetCookie(name)
{  var allcookies = unescape(document.cookie);
   var pos = allcookies.indexOf(name+"=", start);
   if (pos != -1)
      {var start = pos + name.length + 1
       var end   = allcookies.indexOf(";", start)
       if (end == -1) end = allcookies.length;
       return unescape(allcookies.substring(start, end))
      }
   else return "";
};

function debug(msg)
{
 if (GetCookie('DEBUG')=="ON")
    {
     alert(msg)
    };
};

function CheckForm()
{if (    (document.myform.ClearGoals.value == 5)
      || (document.myform.EasilyGiveUp.value == 5)
      || (document.myform.Optimist.value == 5)
      || (document.myform.UnderstandMyMotivation.value == 5)
      || (document.myform.GoodWorkLifeBalance.value == 5)
      || (document.myform.EnoughTime.value == 5)
      || (document.myform.StressedAndAnxious.value == 5)
      || (document.myform.LackConfidence.value == 5)
      || (document.myform.ImASpectator.value == 5)
      || (document.myform.AnythingIsPossible.value== 5)
	 )
    {alert("Please select an answer for all of the questions.");
	 return;
	};
    checkemail();	
 };

function ESubmit()
{if (document.forms.Elist.firstname.value == "")
    {alert("Please enter your firstname, so I can address you personally in your newsletters");
	 record("firstname missing");
	 return;
	};
 if (document.forms.Elist.email.value == "")
    {alert("Please enter your email address, so I can send your newsletters to you");
	 record("email missing");
	 return;
	};
 document.cookie = "firstname=" + document.Elist.firstname.value + '; expires=Tue, 31-Dec-2012 00:00:00 GMT';
 document.cookie = "email="     + document.Elist.email.value     + '; expires=Tue, 31-Dec-2012 00:00:00 GMT';
 document.cookie = "SubFrom="   + document.Elist.SubFrom.value   + '; expires=Tue, 31-Dec-2012 00:00:00 GMT';
 document.Elist.submit();
 };

function record(info)
{   var LogVersion = '1';
    var BID = GetCookie('BID');
    if (BID == '')
       {var now = new Date();
        BID = Date.parse(now.toUTCString())/1000;
        document.cookie = "BID=" + BID + '; expires=Tue, 31-Dec-2012 00:00:00 GMT';
        BID = GetCookie('BID');
       };

    var undefined;
    var NQ        = document.URL.split('?');
    if (NQ[1] == undefined) NQ[1]='';

    var pagename  = NQ[0].split(/\\|\//);
        pagename   = pagename[pagename.length-1];

//    pagename = pagename + '+' + UTILversion;

    if (info == undefined) info = '';
    if (info != '') pagename = pagename + '+' + info;
    if (NQ[1] !='') pagename = pagename + '?' + NQ[1];
    pagename = escape(pagename);

    if (pagename.length > 255)
       { pagename = pagename.slice(0,254)
       };

    NQ = document.referrer.split('?');
    if      ((NQ[0] == undefined) || (NQ[0] == ''))
           {myreferrer = ''
           }
    else  {var  temp1      = NQ[0].split('/');
                myreferrer = temp1[temp1.length-1];
                refdomain  = temp1[2]; if (refdomain == undefined) refdomain = '';

           if (refdomain != '' && refdomain != document.domain) myreferrer = document.referrer;
           if (myreferrer.length > 255)
              {myreferrer = myreferrer.slice(0,254)
              };
          };
	   
    var x = new Image();
    var logstring = 'http://www.uklifecoaching.org/cgi-bin/log.pl?' +
                     LogVersion        + '^'
                      + pagename       + '^'
                      + BID            + '^'
                      + "ONLINE"       + '^'
                      + escape(myreferrer);
    x.src = logstring;
	debug(logstring);	
//    logstring  = "http://www.uklifecoaching.org/area51/logger2.php?pagename=" + pagename+ "&BID=" + BID + "&referrer=" + escape(myreferrer);
};

record();

function MoneyFormat(amount) {
	var val = parseFloat(amount);
	if (isNaN(val)) { return "0.00"; }
	else { val = Math.round(val*100)/100; }
	val = (val == Math.floor(val)) ? val + '.00' : ((val*10 == Math.floor(val*10)) ? val + '0' : val);
	return val;
	};

var newnumber = Math.random() + "";
document.cookie = "test=" + newnumber;
if   (GetCookie("test") != newnumber)
     {alert('This web page uses cookies,\n' +
            'but your web browser is not saving them.\n\n' +
            'Please set your browser to accept cookies.\n\n' +
            'Or disengage any cookie filtering software\n' +
            'to enable it to work.');
      record("cookie warning");
      history.back();
     };
	 
function checkemail()
{var newnumber = Math.random() + "";
 document.cookie = "test=" + newnumber;
 if   (GetCookie("test") != newnumber)
      {alert('This website uses cookies,\n' +
             'but your web browser is not saving them.\n\n' +
             'Please set your browser to accept cookies,\n' +
             'Tools -> Internet Options -> Security -> Custom Level)\n' +
             'or disengage any cookie filtering software you may be using\n' +
             'to enable our website to work.\n\n' +
             'Or - to cancel, this request, click OK,\n' +
	  		     'then click the X at top-right of this wondow');
       record("cookie warning");
      }
 else {var errors = "";
	   var myvalue = myform.email.value;
       document.cookie = "emailcookie=" + myvalue + '; expires=Tue, 31-Dec-2012 00:00:00 GMT';
	   
	   if (myvalue =="")               {errors+= 'it is empty'};
 	   if (myvalue.length < 7        ) {errors+= '\nit is too short'};
       if (myvalue.indexOf('@') == -1) {errors+= '\nit does not contain an @'};
	   if (myvalue.indexOf('.') == -1) {errors+= '\nit does not contain a dot'};
       if (myvalue.indexOf('@') ==  0) {errors+= '\nthe @ cannot be at the start'};
	   if (myvalue.indexOf('.') ==  myvalue.length - 1) {errors+= '\nit cannot end with a dot'};
	   if (myvalue.indexOf(',') != -1) {errors+= '\ncommas are not allowed'};
       if (myvalue.indexOf(' ') != -1) {errors+= '\nspaces are not allowed'};
	   if (myvalue.indexOf('+') != -1) {errors+= '\nplus signs are not allowed'};
       if (myvalue.indexOf('@') == myvalue.length-1)
	      {errors+= '\nthe @ cannot be at the end'};
		  
	   var template = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
       if (template.test(myvalue) != true) {errors += '\n\nYour email address is wrong (check for spaces, odd characters and must be all lower case';};
       if   (errors != "")
	        {alert('Please correct the email address, because:\n\n' + errors);
		     record('Bad email address: ' + myvalue + 'found: ' + errors);
            }
       else {document.myform.submit();
		    };
      };
     return false;
};