var bVer = parseInt(navigator.appVersion);
var sOut="";
if (!((navigator.appVersion.indexOf("MSIE") == -1)&&(navigator.appVersion.substring(0,3)-4.8<0))){
} else {
//netscape <4.8 on PC
	sOut="This site works best with modern browsers. Some features may not work properly with Netscape 4.x. ";			
}

/* Function that swaps images. */
function di20(id, newSrc) {
var theImage = FWFindImage(document, id, 0);
if (theImage) {
theImage.src = newSrc;
}
}
/* Functions that track and set toggle group button states. */
function FWFindImage(doc, name, j) {
var theImage = false;
if (doc.images) {
theImage = doc.images[name];
}
if (theImage) {
return theImage;
}
if (doc.layers) {
for (j = 0; j < doc.layers.length; j++) {
theImage = FWFindImage(doc.layers[j].document, name, 0);
if (theImage) {
return (theImage);
}
}
}
return (false);
}


function setCookie(sIn) {
    document.cookie = "welove2ski=" + sIn;
}
function readCookies() {
    return unescape(document.cookie);
}

function makeCookie(Name,Value,Expiry,Path,Domain,Secure) {
//if you want to save the cookie
if (Expiry != null && !isNaN(Expiry)) {
	var datenow = new Date();
	datenow.setTime(datenow.getTime() + Math.round(86400000*Expiry));
	Expiry = datenow.toGMTString();
}
Expiry = (Expiry) ? '; expires='+Expiry : '';
Path = (Path)?'; path='+Path:'';
Domain = (Domain) ? '; domain='+Domain : '';
Secure = (Secure) ? '; secure' : '';

document.cookie = Name + '=' + escape(Value) + Expiry + Path + Domain + Secure;

}

function readCookie(Name) {

var cookies = ' ' + document.cookie;
if (cookies.indexOf(' ' + Name + '=') == -1) return null;

var start = cookies.indexOf(' ' + Name + '=') + (Name.length + 2);
var finish = cookies.substring(start,cookies.length);
finish = (finish.indexOf(';') == -1) ? cookies.length : start + finish.indexOf(';');

return unescape(cookies.substring(start,finish));
}

function makenumeric(strIn){
	s="";
	for (i=0;i<strIn.length;i++){
		c=strIn.charAt(i);
		if ((c=="1")||(c=="2")||(c=="3")||(c=="4")||(c=="5")||(c=="6")||(c=="7")||(c=="8")||(c=="9")||(c=="0")||(c==".")) s+=c;
	}
	if (s.length==0)s="0";
	return s;
}
function checknumber(sIn,sError){
	sIn.value=makenumeric(sIn.value);
	if (sIn.value==""){
		alert("Please enter "+sError+" then click 'Next' again.");
		return false;
	}
	else if (isNaN(parseFloat(sIn.value))) {
		alert("Please enter "+sError+" as a number ONLY then click 'Next' again.");
		return false;
	}
	return true;
}

function checklimits(sIn,sError,iMin,iMax){
	if (parseFloat(sIn.value)<iMin){
		alert("The "+sError+" must be higher than "+iMin+".");
		return false;
	}
	else if (parseFloat(sIn.value)>iMax) {
		alert("The "+sError+" must be less than "+iMax+".");
		return false;
	}
	return true;
}

function isempty(sIn,sError){
	if (sIn.value==""){
		alert("Please enter "+sError+" then click 'Next' again.");
		return false;
	}
	return true;
}
function checkemail(email){
//	emailpat = /^([a-z0-9_-])+([\.a-z0-9_-])*@([a-z0-9_-])+(\.[a-z0-9_-]+)+$/i;
	emailpat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/i;
	if (!emailpat.test(email)){
		alert("Your Email address does not appear well-formed. Please check it then try again.");
		return false;
	}
	return true;
}
function replaceString(sSrc, sFrom, sTo){
	sReturn=sSrc;
    iFromLen=sFrom.length;
    iToLen=sTo.length;
    iPos=0;
    iEnd=0;
    do {
        iPos=sReturn.indexOf(sFrom,iEnd);
        if (iPos!=-1) {
            sReturn = sReturn.substring(0,iPos)+sTo+sReturn.substring(iPos+iFromLen);
            iEnd=iPos+iToLen;
        }
    } while (iPos!=-1);
	return sReturn;

}

function moveCookie(sFrom,sTo){
	var sTemp=readCookie(sFrom);
	if (sTemp==null) sTemp="";
	makeCookie(sTo,sTemp,365,'','',false);
	makeCookie(sFrom,"",365,'','',false);
}
function checkYouTube(sIn) {
	var bOk=false;
	sIn=sIn.trim();
	if (sIn!="") {
		if (sIn.indexOf("www.youtube.com")==-1 || sIn.indexOf("width")==-1 || sIn.indexOf("height")==-1)
			alert("Your embedded Video Link does not appear well-formed. Please copy and paste the contents of the \"Embed\" box from the relevant YouTube page.");
		else
			bOk=true;
	}
	else
		bOk=true;

	return bOk;
}
var gFetcher=null;
function getFetcher() {
	if (gFetcher!=null)
		return gFetcher;

	try {
		gFetcher=new XMLHttpRequest();
	}
	catch (trymicrosoft) {
		try {
			gFetcher=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (othermicrosoft) {
			try {
				gFetcher=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				gFetcher=null;
			}  
		}
	}
	return gFetcher;
}

String.prototype.ltrim=new Function("return this.replace(/^\\s+/,'')");
String.prototype.rtrim=new Function("return this.replace(/\\s+$/,'')");
String.prototype.trim=new Function("return this.replace(/^\\s+|\\s+$/g,'')");
String.prototype.nocr=new Function("return this.replace(/(\\r\\n|[\\r\\n])/g,'')");
function goLogout(){
	makeCookie('userid','',-1,'','',false);
	makeCookie('username','',-1,'','',false);
	makeCookie('password','',-1,'','',false);
	makeCookie('faves','',-1,'','',false);
	window.location.reload();	
}



var fVer = 0;	
var bFlashOK = false;
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

if(isIE && isWin){
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
	document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');	
	document.write('if (flash5Installed) then \n');	
	document.write('fVer=5 \n');	
	document.write('elseif (flash4Installed) then \n');	
	document.write('fVer=4 \n');	
	document.write('end if \n');	
	document.write('</SCR' + 'IPT\> \n');
}

function drawAdFlash(stub,w,h,alt,href) {
    if (bFlashOK) {
		document.write('<object width="'+w+'" height="'+h+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0">');
		document.write('<param name="movie" value="'+stub+'.swf"><param name="loop" value="true"><param name="menu" value="false"><param name="quality" value="high"><param name="scale" value="exactfit">');
		document.write('<embed src="'+stub+'.swf" width="'+w+'" height="'+h+'" loop="true" menu="false" quality="high" scale="exactfit" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>');
		document.write('</object>');
	}
    else {
		document.write('<a href="'+href+'" target="_blank"><img src="'+stub+'.gif" width="'+w+'" height="'+h+'" alt="'+alt+'" border="0" /></a>');
	}
}


function detectFlash(){	
	if (navigator.plugins){
		if (navigator.plugins["Shockwave Flash 2.0"]|| navigator.plugins["Shockwave Flash"]){
			var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
			fVer = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));

			fVer = parseInt(flashDescription.substring(flashDescription.indexOf(".") - 2,flashDescription.indexOf(".") ));

		}
	}
	
	if(navigator.userAgent.indexOf("WebTV") != -1) fVer = 2;	
	if (fVer >= 4) bFlashOK = true;
}

detectFlash();
//bFlashOK = false;
/**
 * SWFObject v1.4.1: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, useExpressInstall, quality, xiRedirectUrl, redirectUrl, detectKey){
	if (!document.createElement || !document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion(this.getAttribute('version'), useExpressInstall);
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', useExpressInstall);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs.push(key +"="+ variables[key]);
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "PlugIn");
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "ActiveX");
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(reqVer, xiInstall){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else{
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			for (var i=3; axo!=null; i++) {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
				PlayerVersion = new deconcept.PlayerVersion([i,0,0]);
			}
		}catch(e){}
		if (reqVer && PlayerVersion.major > reqVer.major) return PlayerVersion; // version is ok, skip minor detection
		// this only does the minor rev lookup if the user's major version 
		// is not 6 or we are checking for a specific minor or revision number
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		if (!reqVer || ((reqVer.minor != 0 || reqVer.rev != 0) && PlayerVersion.major == reqVer.major) || PlayerVersion.major != 6 || xiInstall) {
			try{
				PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
			}catch(e){}
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = parseInt(arrVersion[0]) != null ? parseInt(arrVersion[0]) : 0;
	this.minor = parseInt(arrVersion[1]) || 0;
	this.rev = parseInt(arrVersion[2]) || 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param){
		var q = document.location.search || document.location.hash;
		if(q){
			var startIndex = q.indexOf(param +"=");
			var endIndex = (q.indexOf("&", startIndex) > -1) ? q.indexOf("&", startIndex) : q.length;
			if (q.length > 1 && startIndex > -1) {
				return q.substring(q.indexOf("=", startIndex)+1, endIndex);
			}
		}
		return "";
	}
}
/* fix for video streaming bug 
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i=0; i < objects.length; i++) {
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = null;
			}
		}
	}
}
if (typeof window.onunload == 'function') {
	var oldunload = window.onunload;
		window.onunload = function() {
		deconcept.SWFObjectUtil.cleanupSWFs();
		oldunload();
	}
} else {
	window.onunload = deconcept.SWFObjectUtil.cleanupSWFs;
}*/
/* add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;


function Fetcher() {
	var me=this;
	this.fnCB=null;
	this.xmlHttp=null;
	try { this.xmlHttp=new XMLHttpRequest(); }
	catch (trymicrosoft) {
		try { this.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (othermicrosoft) {
			try { this.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (failed) {
				this.xmlHttp=null;
			}  
		}
	}
	this.now=function(sURL) {
		var sRet="";
		if (this.xmlHttp) {
			this.xmlHttp.open("GET",cacheBust(sURL),false);
			this.xmlHttp.send(null);
  			if (this.xmlHttp.readyState==4)
				sRet=this.xmlHttp.responseText.nocr().trim();
		}
		return sRet;
	}	
	this.whenever=function(sURL,fnCB) {
		if (this.xmlHttp) {
			this.fnCB=fnCB;
			this.xmlHttp.open("GET",cacheBust(sURL),true);
			this.xmlHttp.onreadystatechange=this.loader;
			this.xmlHttp.send(null);
		}
	}
	this.loader=function() {
		if (me.xmlHttp) {
			if (me.xmlHttp.readyState==4 && me.xmlHttp.status==200) {
				me.fnCB(me.xmlHttp.responseText.nocr().trim());
			}
		}
	}
}
function cacheBust(sURL) {
	return sURL+(sURL.indexOf('?')==-1 ? '?' : '&')+'cbzz='+(new Date()).getTime();
}
function isDate(DD,MM,YYYY) {
	var bValid=false;

	if (DD.length<=2 && MM.length<=2 && YYYY.length<=4) {
		if (calcAge(DD,MM,YYYY)<120) {
			MM=(1*MM)-1;
			var dateTest=new Date(YYYY,MM,DD);
			if (dateTest.getDate()==DD && dateTest.getMonth()==MM && dateTest.getFullYear()==YYYY)
				bValid=true;
		}
	}
	return bValid;
}
function calcAge(dd,mm,yyyy) {
	var bdd=parseInt(dd);
	var bmm=parseInt(mm);
	var byyyy=parseInt(yyyy);
	var now = new Date();
	var ndd=now.getDate();
	var nmm=now.getMonth()+1;
	var nyyyy=now.getFullYear();

	if (nmm>bmm || (nmm==bmm && ndd>=bdd))
		return nyyyy-byyyy;
	else
		return nyyyy-byyyy-1;
}
function validPostcode(pc) {
	var reg=/^[a-z]{1,2}[\da-z]{1,2} \d[a-z][a-z]$/i; 
	return reg.test(pc);
}
function obj(id) {
   return document.getElementById(id);
}
function showSmallAd(id,resp) {
	if (resp!='') {
		var o=obj(id);
		if (o!=null) {
			var as=resp.split('~');			
			loadStyles(as[0]);
			o.innerHTML=as[1];
			o.style.display='block';
			for (var i=2 ; i<as.length ; i++) 
				loadJS(as[i]);
		}
	}
}
function loadJS(jsfile) {
	var script=document.createElement('script');
	script.setAttribute('type','text/javascript');
	script.setAttribute('src',jsfile);

	var head=document.getElementsByTagName('head')[0];
	head.appendChild(script);
}
function loadStyles(css) {
	if (css!='') {
		var se = document.createElement('style');
		se.setAttribute("type", "text/css");
		var he = document.getElementsByTagName('head')[0];
		he.appendChild(se);
		if (se.styleSheet)
			 se.styleSheet.cssText = css;
		else
			 se.appendChild(document.createTextNode(css));
	}
}
