JS_BASE = "http://www.sellstudentstuff.com/"
JS_BASE_SECURE = "https://www.sellstudentstuff.com/"
JS_UMBRELLA_BASE = "http://www.sellstudentstuff.com/"
JS_UMBRELLA_BASE_SECURE = "https://www.sellstudentstuff.com/"

// Simple Set Clipboard System
// Author: Joseph Huckaby

var ZeroClipboard = {
	
	version: "1.0.7",
	clients: {}, // registered upload clients on page, indexed by id
	moviePath: 'ZeroClipboard.swf', // URL to movie
	nextId: 1, // ID of next movie
	
	$: function(thingy) {
		// simple DOM lookup utility function
		if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
		if (!thingy.addClass) {
			// extend element with a few useful methods
			thingy.hide = function() { this.style.display = 'none'; };
			thingy.show = function() { this.style.display = ''; };
			thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
			thingy.removeClass = function(name) {
				var classes = this.className.split(/\s+/);
				var idx = -1;
				for (var k = 0; k < classes.length; k++) {
					if (classes[k] == name) { idx = k; k = classes.length; }
				}
				if (idx > -1) {
					classes.splice( idx, 1 );
					this.className = classes.join(' ');
				}
				return this;
			};
			thingy.hasClass = function(name) {
				return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
			};
		}
		return thingy;
	},
	
	setMoviePath: function(path) {
		// set path to ZeroClipboard.swf
		this.moviePath = path;
	},
	
	dispatch: function(id, eventName, args) {
		// receive event from flash movie, send to client		
		var client = this.clients[id];
		if (client) {
			client.receiveEvent(eventName, args);
		}
	},
	
	register: function(id, client) {
		// register new client to receive events
		this.clients[id] = client;
	},
	
	getDOMObjectPosition: function(obj, stopObj) {
		// get absolute coordinates for dom element
		var info = {
			left: 0, 
			top: 0, 
			width: obj.width ? obj.width : obj.offsetWidth, 
			height: obj.height ? obj.height : obj.offsetHeight
		};

		while (obj && (obj != stopObj)) {
			info.left += obj.offsetLeft;
			info.top += obj.offsetTop;
			obj = obj.offsetParent;
		}

		return info;
	},
	
	Client: function(elem) {
		// constructor for new simple upload client
		this.handlers = {};
		
		// unique ID
		this.id = ZeroClipboard.nextId++;
		this.movieId = 'ZeroClipboardMovie_' + this.id;
		
		// register client with singleton to receive flash events
		ZeroClipboard.register(this.id, this);
		
		// create movie
		if (elem) this.glue(elem);
	}
};

ZeroClipboard.Client.prototype = {
	
	id: 0, // unique ID for us
	ready: false, // whether movie is ready to receive events or not
	movie: null, // reference to movie object
	clipText: '', // text to copy to clipboard
	handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
	cssEffects: true, // enable CSS mouse effects on dom container
	handlers: null, // user event handlers
	
	glue: function(elem, appendElem, stylesToAdd) {
		// glue to DOM element
		// elem can be ID or actual DOM element object
		this.domElement = ZeroClipboard.$(elem);
		
		// float just above object, or zIndex 99 if dom element isn't set
		var zIndex = 99;
		if (this.domElement.style.zIndex) {
			zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
		}
		
		if (typeof(appendElem) == 'string') {
			appendElem = ZeroClipboard.$(appendElem);
		}
		else if (typeof(appendElem) == 'undefined') {
			appendElem = document.getElementsByTagName('body')[0];
		}
		
		// find X/Y position of domElement
		var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
		
		// create floating DIV above element
		this.div = document.createElement('div');
		var style = this.div.style;
		style.position = 'absolute';
		style.left = '' + box.left + 'px';
		style.top = '' + box.top + 'px';
		style.width = '' + box.width + 'px';
		style.height = '' + box.height + 'px';
		style.zIndex = zIndex;
		
		if (typeof(stylesToAdd) == 'object') {
			for (addedStyle in stylesToAdd) {
				style[addedStyle] = stylesToAdd[addedStyle];
			}
		}
		
		// style.backgroundColor = '#f00'; // debug
		
		appendElem.appendChild(this.div);
		
		this.div.innerHTML = this.getHTML( box.width, box.height );
	},
	
	getHTML: function(width, height) {
		// return HTML for movie
		var html = '';
		var flashvars = 'id=' + this.id + 
			'&width=' + width + 
			'&height=' + height;
			
		if (navigator.userAgent.match(/MSIE/)) {
			// IE gets an OBJECT tag
			var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
			html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+protocol+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+this.movieId+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard.moviePath+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars+'"/><param name="wmode" value="transparent"/></object>';
		}
		else {
			// all other browsers get an EMBED tag
			html += '<embed id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+this.movieId+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'" wmode="transparent" />';
		}
		return html;
	},
	
	hide: function() {
		// temporarily hide floater offscreen
		if (this.div) {
			this.div.style.left = '-2000px';
		}
	},
	
	show: function() {
		// show ourselves after a call to hide()
		this.reposition();
	},
	
	destroy: function() {
		// destroy control and floater
		if (this.domElement && this.div) {
			this.hide();
			this.div.innerHTML = '';
			
			var body = document.getElementsByTagName('body')[0];
			try { body.removeChild( this.div ); } catch(e) {;}
			
			this.domElement = null;
			this.div = null;
		}
	},
	
	reposition: function(elem) {
		// reposition our floating div, optionally to new container
		// warning: container CANNOT change size, only position
		if (elem) {
			this.domElement = ZeroClipboard.$(elem);
			if (!this.domElement) this.hide();
		}
		
		if (this.domElement && this.div) {
			var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
			var style = this.div.style;
			style.left = '' + box.left + 'px';
			style.top = '' + box.top + 'px';
		}
	},
	
	setText: function(newText) {
		// set text to be copied to clipboard
		this.clipText = newText;
		if (this.ready) this.movie.setText(newText);
	},
	
	addEventListener: function(eventName, func) {
		// add user event listener for event
		// event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
		eventName = eventName.toString().toLowerCase().replace(/^on/, '');
		if (!this.handlers[eventName]) this.handlers[eventName] = [];
		this.handlers[eventName].push(func);
	},
	
	setHandCursor: function(enabled) {
		// enable hand cursor (true), or default arrow cursor (false)
		this.handCursorEnabled = enabled;
		if (this.ready) this.movie.setHandCursor(enabled);
	},
	
	setCSSEffects: function(enabled) {
		// enable or disable CSS effects on DOM container
		this.cssEffects = !!enabled;
	},
	
	receiveEvent: function(eventName, args) {
		// receive event from flash
		eventName = eventName.toString().toLowerCase().replace(/^on/, '');
				
		// special behavior for certain events
		switch (eventName) {
			case 'load':
				// movie claims it is ready, but in IE this isn't always the case...
				// bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
				this.movie = document.getElementById(this.movieId);
				if (!this.movie) {
					var self = this;
					setTimeout( function() { self.receiveEvent('load', null); }, 1 );
					return;
				}
				
				// firefox on pc needs a "kick" in order to set these in certain cases
				if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
					var self = this;
					setTimeout( function() { self.receiveEvent('load', null); }, 100 );
					this.ready = true;
					return;
				}
				
				this.ready = true;
				this.movie.setText( this.clipText );
				this.movie.setHandCursor( this.handCursorEnabled );
				break;
			
			case 'mouseover':
				if (this.domElement && this.cssEffects) {
					this.domElement.addClass('hover');
					if (this.recoverActive) this.domElement.addClass('active');
				}
				break;
			
			case 'mouseout':
				if (this.domElement && this.cssEffects) {
					this.recoverActive = false;
					if (this.domElement.hasClass('active')) {
						this.domElement.removeClass('active');
						this.recoverActive = true;
					}
					this.domElement.removeClass('hover');
				}
				break;
			
			case 'mousedown':
				if (this.domElement && this.cssEffects) {
					this.domElement.addClass('active');
				}
				break;
			
			case 'mouseup':
				if (this.domElement && this.cssEffects) {
					this.domElement.removeClass('active');
					this.recoverActive = false;
				}
				break;
		} // switch eventName
		
		if (this.handlers[eventName]) {
			for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
				var func = this.handlers[eventName][idx];
			
				if (typeof(func) == 'function') {
					// actual function reference
					func(this, args);
				}
				else if ((typeof(func) == 'object') && (func.length == 2)) {
					// PHP style object + method, i.e. [myObject, 'myMethod']
					func[0][ func[1] ](this, args);
				}
				else if (typeof(func) == 'string') {
					// name of function
					window[func](this, args);
				}
			} // foreach event handler defined
		} // user defined handler for event
	}
	
};


function brightenOnFocus(focused, el, fcs_cls, default_text) {
	if(focused) {
		el.className = fcs_cls;
		
		if(el.value == default_text)
			el.value = "";
	} else  {
		if(el.value == "")
			el.value = default_text;
		if(el.value == default_text)
			el.className = 'unfocused';
	}
}

function forceFormSubmit(id) {
	//fix for ie6
	
	document.myAnonymousFunction = function() {

		document.getElementById(id).submit();
	
	}
	
	setTimeout("document.myAnonymousFunction();", 50);
}

function openWebSupportWindow() { 
	 window.open(JS_UMBRELLA_BASE+'support/ca_webchat.php','_blank','width=470,height=335,toolbar=no,location=no,status=no,menubar=no,scrollbars=0,resizable=0');
}

function urlRedirect(url) { 
	setTimeout("top.location.href = '" + url +"'",1);
}
function urlRedirectBAM(url) { 
	setTimeout("self.location.href = '" + url +"'",1);
}
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);
}
function delbookmark(type,id) {
	
	var pars = 'aj_action=true&action=del_bookmark';	
	pars += '&type='+type;
	pars += '&id='+id;
	
	var targ = JS_BASE+'global/account/bookmarks.php';
    var myAjax = new Ajax.Updater({success: "bookmark_"+type+"_"+id},targ,{method: 'post', parameters: pars, evalScripts: true});	
}

function showhideset(option, test){
	if(test=="hide"){
		getObject(option).style.display="none";
	} else if(test=="show"){
		getObject(option).style.display="block";
	}

}

var nmHaschanged = false;
function textOnNewMessSubmittedNotice() {
	if(nmHaschanged == false){
		nmHaschanged = true;
		getObject('textonnmnoticebutton').disabled = false;
	} else {
		nmHaschanged = false;
		getObject('textonnmnoticebutton').disabled = true;
	}
}


function proceedToCheckout(base) {
	var args = "";
	var buymeatree = $('buy_tree');
	if(buymeatree) {
		args += '?bt='+buymeatree.value;
	}
	
	urlRedirect(base+'checkout/checkout.php'+args);
}


function get_radio_value(el)
{
	var rad_val = "";
	for (var i=0; i < el.length; i++)
   {
   	  if (el[i].checked)
      {
      	rad_val = el[i].value;
      	break;
      }
   }
   
   return rad_val;
}


function quickRegisterValidateQ(theForm)
{

	
	if (theForm.title.value == "")
	{
		alert("Please select your Title");
		return false;
	}

	if (theForm.FirstName.value == "")
	{
		alert("Please enter your First Name");
		return false;
	}

	if (theForm.LastName.value == "")
	{
		alert ("Please enter your Last Name");
		return false;
	}

//	if(theForm.telephone.value != ""){
//		//alert("Telephone is wrong");
//		/* Check numeric */
//		var i;
//		for(i=0;i<theForm.telephone.value.length;i++){
//			if(!(	((theForm.telephone.value.charAt(i) <= '9') && (theForm.telephone.value.charAt(i) >= '0')) ||
//			(theForm.telephone.value.charAt(i) == ' ') || (theForm.telephone.value.charAt(i) == '.') || (theForm.telephone.value.charAt(i) == '-'))){
//				alert("Telephone should be numeric only (no spaces, letters or symbols)");
//				return(false);
//			}
//		}
//		if (theForm.telephone.value.indexOf(" ") > -1) {
//			alert("Telephone should be numeric only (no spaces, letters or symbols)");
//			return false;
//		}
//		/* Check length */
//		//check min length
//		if (theForm.telephone.value.length < 10)
//		{
//			alert("The mobile number is too short");
//			return false;
//		}
//		//check max length
//		if (theForm.telephone.value.length > 12)
//		{
//			alert("The mobile number is too long");
//			return false;
//		}
//		//check it starts with '07'
//		if ((theForm.telephone.value.charAt(0) != "0")&&(theForm.telephone.value.charAt(0) != "7"))
//		{
//			alert("Please enter a valid UK mobile number (e.g. 07123456789)");
//			return false;
//		}
//		// check spacebar
//
//	}
//
//	if(theForm.telephone.value == "")
//	{
//		alert("You must enter a valid UK mobile number");
//		return false;
//	}

	if (theForm.email.value.search("@") == -1 || theForm.email.value.search("[.*]") == -1)
	{
		alert ("Please enter a valid E-mail address");
		return false;
	}
		
	if (theForm.Password.value == "")
	{
		alert("Please enter your Password");
		return false;
	}
	if (theForm.Password.value != theForm.Cpassword.value)
	{
		alert("Your passwords did not match, please input them again");
		return false;
	}	
		
	return true;
}





function quickRegisterValidate(theForm)
{

	if (get_radio_value(theForm.Type) == "")
	{
		alert ("Are you a Landlord, Student or Other? Please choose...");
		return false;
	}
	
	if (theForm.title.value == "")
	{
		alert("Please select your Title");
		return false;
	}

	if (theForm.FirstName.value == "")
	{
		alert("Please enter your First Name");
		return false;
	}

	if (theForm.LastName.value == "")
	{
		alert ("Please enter your Last Name");
		return false;
	}


//	if (theForm.Username.value == "")
//	{
//		alert ("Please enter your Username");
//		return false;
//	}

	if (theForm.Password.value == "")
	{
		alert("Please enter your Password");
		return false;
	}
	if (theForm.Password.value != theForm.Cpassword.value)
	{
		alert("Your passwords did not match, please input them again");
		return false;
	}
		

//	if(theForm.telephone.value != ""){
//		//alert("Telephone is wrong");
//		/* Check numeric */
//		var i;
//		for(i=0;i<theForm.telephone.value.length;i++){
//			if(!(	((theForm.telephone.value.charAt(i) <= '9') && (theForm.telephone.value.charAt(i) >= '0')) ||
//			(theForm.telephone.value.charAt(i) == ' ') || (theForm.telephone.value.charAt(i) == '.') || (theForm.telephone.value.charAt(i) == '-'))){
//				alert("Telephone should be numeric only (no spaces, letters or symbols)");
//				return(false);
//			}
//		}
//		if (theForm.telephone.value.indexOf(" ") > -1) {
//			alert("Telephone should be numeric only (no spaces, letters or symbols)");
//			return false;
//		}
//		/* Check length */
//		//check min length
//		if (theForm.telephone.value.length < 10)
//		{
//			alert("The mobile number is too short");
//			return false;
//		}
//		//check max length
//		if (theForm.telephone.value.length > 12)
//		{
//			alert("The mobile number is too long");
//			return false;
//		}
//		//check it starts with '07'
//		if ((theForm.telephone.value.charAt(0) != "0")&&(theForm.telephone.value.charAt(0) != "7"))
//		{
//			alert("Please enter a valid UK mobile number (e.g. 07123456789)");
//			return false;
//		}
//		// check spacebar
//
//	}
//
//	if(theForm.telephone.value == "")
//	{
//		alert("You must enter a valid UK mobile number");
//		return false;
//	}


	if (theForm.email.value.search("@") == -1 || theForm.email.value.search("[.*]") == -1)
	{
		alert ("Please enter a valid E-mail address");
		return false;
	}
	
	
	
	
	if( theForm.captcha.value =="") {
		alert("Please confirm the word shown in the image.");
		return false;		
	}
	
	if ((theForm.tandc.checked != true))
	{
		alert("Please confirm you have read and agree to our Terms & Conditions!");
		return false;
	}
	
	return true;
}

/**
	Ensure the given field (object) is filled in by the user. If not
	a message is displayed quoting the given name (string).
**/
function ensureFilled(field, name) {
	var valid = (field && field.value);
	if(!valid) {
		alert('Please enter a '+name);
	}
	
	return valid;
}

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"), "");
}

/** Anything beyond this point is DEPRECATED - DO NOT USE **/

function getObject(name) {
	var ns4 = (document.layers) ? true : false;
	var w3c = (document.getElementById) ? true : false;
	var ie4 = (document.all) ? true : false;
	if (ns4) return eval('document.' + name);
	if (w3c) return document.getElementById(name);
	if (ie4) return eval('document.all.' + name);
	return false;

}

function bgRequest(url) {

	// Internet Explorer
	try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e) {
		try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch(oc) { req = null; }
	}

	// Mozailla/Safari
	if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

	// Call the processChange() function when the page has loaded
	if (req != null) {

		req.open("GET", url, true);
		req.send(null);
	}

}

function selectAll() {
	d = document.act_form;
	for (i = 0; i < d.elements.length; i++) {
		if (d.elements[i].type == "checkbox") {
			d.elements[i].checked = true;
		}
	}
}

function deselectAll() {
	d = document.act_form;
	for (i = 0; i < d.elements.length; i++) {
		if (d.elements[i].type == "checkbox") {
			d.elements[i].checked = false;
		}
	}
}
/*accMod.php*/
function accModValidate1(theForm)
{

	if (theForm.title.value == "")
	{
		alert("Please select your Title");
		return false;
	}

	if (theForm.FirstName.value == "")
	{
		alert("Please enter your First Name");
		return false;
	}
	if (theForm.FirstName.value.match(/\W/)) 
	{ 
		alert ("Your name should only contain letters!");
		return false;
		}
	if (theForm.LastName.value == "")
	{
		alert ("Please enter your Surname");
		return false;
	}
	if (theForm.LastName.value.match(/\W/)) 
	{ 
		alert ("Your name should only contain letters!");
		return false;
		}

	if (theForm.Password.value != theForm.Cpassword.value)
	{
		alert("Your passwords did not match, please input them again");
		return false;
	}


	return true;
}


function accModValidate2(theForm)
{
	

	if (theForm.day.value == "")
	{
		alert("Please complete your Date of Birth");
		return false;
	}
	if (theForm.month.value == "")
	{
		alert("Please complete your Date of Birth");
		return false;
	}
	if (theForm.year.value == "")
	{
		alert("Please complete your Date of Birth");
		return false;
	}

	if(theForm.mobile.value != ""){
		
		var i;
		for(i=0;i<theForm.mobile.value.length;i++){
			if(!(	((theForm.mobile.value.charAt(i) <= '9') && (theForm.mobile.value.charAt(i) >= '0')) ||
			(theForm.mobile.value.charAt(i) == ' ') || (theForm.mobile.value.charAt(i) == '.') || (theForm.mobile.value.charAt(i) == '-'))){
				alert("Mobile number should be numeric only (no spaces, letters or symbols)");
				return(false);
			}
		}
		if (theForm.mobile.value.indexOf(" ") > -1) {
			alert("Mobile number should be numeric only (no spaces, letters or symbols)");
			return false;
		}
		/* Check length */
		//check min length
		if (theForm.mobile.value.length < 10)
		{
			alert("The mobile number is too short");
			return false;
		}
		//check max length
		if (theForm.mobile.value.length > 12)
		{
			alert("The mobile number is too long");
			return false;
		}
		//check it starts with '07'
		if ((theForm.mobile.value.charAt(0) != "0")&&(theForm.telephone.value.charAt(0) != "7"))
		{
			alert("Please enter a valid UK mobile number (e.g. 07123456789)");
			return false;
		}
		// check spacebar

	}

	if(theForm.mobile.value == "")
	{
		alert("You must enter a valid UK mobile number");
		return false;
	}

	
	if(!validateAddress(theForm)){
		alert("Please enter a valid address and postcode");
		return false;
	}
	
	
	
	if(theForm.phone.value != ""){
		
		var i;
		for(i=0;i<theForm.phone.value.length;i++){
			if(!(	((theForm.phone.value.charAt(i) <= '9') && (theForm.phone.value.charAt(i) >= '0')) ||
			(theForm.phone.value.charAt(i) == ' ') || (theForm.phone.value.charAt(i) == '.') || (theForm.phone.value.charAt(i) == '-'))){
				alert("Telephone number should be numeric only (no spaces, letters or symbols)");
				return(false);
			}
		}
		if (theForm.phone.value.indexOf(" ") > -1) {
			alert("Telephone number should be numeric only (no spaces, letters or symbols)");
			return false;
		}
		/* Check length */
		//check min length
		if (theForm.phone.value.length < 10)
		{
			alert("The phone number is too short");
			return false;
		}
		//check max length
		if (theForm.phone.value.length > 12)
		{
			alert("The phone number is too long");
			return false;
		}
		
		

	}



//	if (theForm.email.value.search("@") == -1 || theForm.email.value.search("[.*]") == -1)
//	{
//		alert ("Please enter a valid E-mail address");
//		return false;
//	}
}
function validateNewProp(theForm){
	
	var form = $(theForm);
	var code1 = form['subdivided'];
	var code2 = form['propertyTypeID'];
	
	subdivided = $F(code1);
	propertyType = $F(code2);
	

	
	
	if(!validateAddress(theForm)){
		
		return false;
	}
		if(propertyType=='0'){
		alert("Please select the type of property");
		return false;
	}
	
		if(propertyType!='6'){
			if(subdivided=='0'){
			alert("Please select the number of rooms");
			return false;
		}
	}
	
	
	
	return true;
	
}
function accModValidateUniNagger(theForm) {
	
	if (theForm.occupation.value == "" || theForm.occupation.value == "Please choose...")
	{
		alert("Please select your group");
		return false;
	}
	
	if(theForm.occupation.value == "Student" || theForm.occupation.value == "Graduate") {
		if (theForm.uni.value == "" && theForm.uni_other && theForm.uni_other.value == "")
		{
			alert("Please select your University");
			return false;
		}
		
		
		if ((theForm.subj.value == "0" || theForm.subj.value == "") && theForm.subject_other && theForm.subject_other.value == "")
		{
			alert("Please select your Subject");
			return false;
		}
	}
	
	return true;
}
function accModValidatePersNagger(theForm) {
	
	if (theForm.PostCode1.value == "")
	{
		alert("Please complete your address");
		return false;
	}
	
	if (theForm.PostCode2.value == "")
	{
		alert("Please complete your address");
		return false;
	}
	if (theForm.regday.value == "")
	{
		alert("Please complete your Date of Birth");
		return false;
	}
	if (theForm.regmonth.value == "")
	{
		alert("Please complete your Date of Birth");
		return false;
	}
	if (theForm.regyear.value == "")
	{
		alert("Please complete your Date of Birth");
		return false;
	}
	
	
	
	return true;
}

function accModValidateConNagger(theForm)
{

	if(theForm.phone.value != ""){
		//alert("Telephone is wrong");
		/* Check numeric */
		var i;
		for(i=0;i<theForm.phone.value.length;i++){
			if(!(	((theForm.phone.value.charAt(i) <= '9') && (theForm.phone.value.charAt(i) >= '0')) ||
			(theForm.phone.value.charAt(i) == ' ') || (theForm.phone.value.charAt(i) == '.') || (theForm.phone.value.charAt(i) == '-'))){
				alert("Phone number should be numeric only (no spaces, letters or symbols)");
				return(false);
			}
		}
		if (theForm.phone.value.indexOf(" ") > -1) {
			alert("Phone number should be numeric only (no spaces, letters or symbols)");
			return false;
		}
		/* Check length */
		//check min length
		if (theForm.phone.value.length < 10)
		{
			alert("The phone number is too short");
			return false;
		}
		//check max length
		if (theForm.phone.value.length > 12)
		{
			alert("The phone number is too long");
			return false;
		}
		//check it starts with '07'
		if ((theForm.phone.value.charAt(0) != "0")&&(theForm.telephone.value.charAt(0) != "7"))
		{
			alert("Please enter a valid UK phone number (e.g. 07123456789)");
			return false;
		}
		// check spacebar

	}

	

	
		if(theForm.mobile.value != ""){
		//alert("Telephone is wrong");
		/* Check numeric */
		var i;
		for(i=0;i<theForm.mobile.value.length;i++){
			if(!(	((theForm.mobile.value.charAt(i) <= '9') && (theForm.mobile.value.charAt(i) >= '0')) ||
			(theForm.mobile.value.charAt(i) == ' ') || (theForm.mobile.value.charAt(i) == '.') || (theForm.mobile.value.charAt(i) == '-'))){
				alert("mobile number should be numeric only (no spaces, letters or symbols)");
				return(false);
			}
		}
		if (theForm.mobile.value.indexOf(" ") > -1) {
			alert("mobile number should be numeric only (no spaces, letters or symbols)");
			return false;
		}
		/* Check length */
		//check min length
		if (theForm.mobile.value.length < 10)
		{
			alert("The mobile number is too short");
			return false;
		}
		//check max length
		if (theForm.mobile.value.length > 12)
		{
			alert("The mobile number is too long");
			return false;
		}
		//check it starts with '07'
		if ((theForm.mobile.value.charAt(0) != "0")&&(theForm.telephone.value.charAt(0) != "7"))
		{
			alert("Please enter a valid UK mobile number (e.g. 07123456789)");
			return false;
		}
		// check spacebar

	}

	if(theForm.mobile.value == "")
	{
		alert("You must enter a valid UK mobile number");
		return false;
	}
	
	
	
	
	
	

	if (theForm.email.value.search("@") == -1 || theForm.email.value.search("[.*]") == -1)
	{
		alert ("Please enter a valid E-mail address");
		return false;
	}
	
	return true;
}


function accModValidate3(theForm) {
	if (theForm.occupation.value == "" || theForm.occupation.value == "Please choose...")
	{
		alert("Please select your group");
		return false;
	}
	
	if(theForm.occupation.value == "Student" || theForm.occupation.value == "Graduate") {
		if (theForm.uni.value == "" )
		{
			alert("Please select your University");
			return false;
		}
		
		
		if ((theForm.subj.value == "0" || theForm.subj.value == "") && theForm.subject_other && theForm.subject_other.value == "")
		{
			alert("Please select your Subject");
			return false;
		}
	}
	
	return true;
}




function validatePostCode(PostCode1, PostCode2){ //check postcode format is valid
	test1 = PostCode1.value;
	size1 = test1.length;
	test2 = PostCode2.value;
	size2 = test2.length;
	test1 = test1.toUpperCase(); //Change to uppercase
	test2 = test2.toUpperCase(); //Change to uppercase
  if(test1 != '412') {
  	if ((size1 + size2) < 5 || (size1 + size2) > 8){ //Code length rule
  		alert(test1 + " " + test2 + " is not a valid postcode - wrong length");
  		//PostCode1.focus();
  		return false;
  	}
  	if (!(isNaN(test1.charAt(0)))){ //leftmost character must be alpha character rule
  		alert(test1 + " " + test2 + " is not a valid postcode - cannot start with a number");
  		//PostCode1.focus();
  		return false;
  	}
  }

	return true;
}

/*
Checks the postcode plus the presence of a first address line - returns true or false

*/
function validateAddress(formName){
	var form = $(formName);
	var pcode1 = form['PostCode1'];
	var pcode2 = form['PostCode2'];
	var addr1 = form['addressLine1'];
	var addr2 = form['addressLine2'];
	var addrTown = form['Town'];
	var addrCounty = form['County'];
		
	postCode1 = $F(pcode1);
	postCode2 = $F(pcode2);
	addressLine1 = $F(addr1);
	addressLine2 = $F(addr2);

	
	if($F(addr1).search("@") != -1 || $F(addr2).search("@")!= -1 || $F(addrTown).search("@")!= -1 ||$F(addrCounty).search("@")!= -1){
		alert("No email addresses allowed");
		return false;
	}
	if(newValidatePostcode(postCode1,postCode2)&&(addressLine1)){
		return true;
	}
	alert("Please enter a valid address and postcode");
	return false;
	
	
	
}

function newValidatePostcode(PostCode1, PostCode2){
	
	
	size1 = PostCode1.length;
	size2 = PostCode2.length;
	test1 = PostCode1.toUpperCase(); //Change to uppercase
	test2 = PostCode2.toUpperCase(); //Change to uppercase
	if ((size1 + size2) < 5 || (size1 + size2) > 8){ //Code length rule
		
		return false;
	}
	if (!(isNaN(test1.charAt(0)))){ //leftmost character must be alpha character rule
		
		return false;
	}

	return true;
	
}

function recalcBasket() {
	
	var fields = $$(".basket_quantity_field");
	
	var pars = 'aj_action=true&action=recalcbasket';	
	var buymeatree = $('buy_tree');
	if(buymeatree) {
		pars += '&buy_tree='+buymeatree.value;
	}
	for(var i = 0; i < fields.length; i++) {
		var pid = fields[i].id;
		pid = pid.substr(pid.lastIndexOf('_')+1);
		
		pars += '&'+pid+'='+fields[i].value;
	}
	
	showSpinnerIn($('editbasketform'));
	var targ = JS_UMBRELLA_BASE+'g/classes/Basket.class.php';
    var myAjax = new Ajax.Updater({success: "editbasketform"},targ,{method: 'post', parameters: pars, evalScripts: true});	
}


function updateMiniBasket() {
	
	var pars = 'aj_action=true&action=showminibasket';
	var targ = JS_UMBRELLA_BASE+'g/classes/Basket.class.php';
    var myAjax = new Ajax.Updater({success: "basket_container"},targ,{method: 'post', parameters: pars, evalScripts: true});
	
}

function recalcWLBasket() {
	
	var fields = $$(".basket_quantity_field");
	
	var pars = 'aj_action=true&action=recalcWLbasket';	
	var buymeatree = $('buy_tree');
	if(buymeatree) {
		pars += '&buy_tree='+buymeatree.value;
	}
	for(var i = 0; i < fields.length; i++) {
		var pid = fields[i].id;
		pid = pid.substr(pid.lastIndexOf('_')+1);
		
		pars += '&'+pid+'='+fields[i].value;
	}
	
	showSpinnerIn($('editbasketform'));
	var targ = JS_UMBRELLA_BASE+'g/classes/Basket.class.php';
    var myAjax = new Ajax.Updater({success: "editbasketform"},targ,{method: 'post', parameters: pars, evalScripts: true});	
}


function updateMiniWLBasket() {
	
	var pars = 'aj_action=true&action=showminiWLbasket';
	var targ = JS_UMBRELLA_BASE+'g/classes/Basket.class.php';
    var myAjax = new Ajax.Updater({success: "basket_container"},targ,{method: 'post', parameters: pars, evalScripts: true});
	
}


function showSpinnerIn(el, nofillwidth, nofillheight) {
	var spinner = '<table cellpadding="0" cellspacing="0" border="0"';

	if(!nofillwidth) {
		spinner += 'width="100%"';
	}
	if(!nofillheight) {
		spinner += 'height="100%"';
	}
	
	spinner += ' ><tr><td valign="middle" align="center"><img src="'+JS_BASE+'images/aj_loading.gif" align="absmiddle" border="0"/></td></tr></table>';
	
	el.innerHTML = spinner;
}
function textCounter(field,cntfield,maxlimit) {
	var textlength = document.getElementById(field);
	if (textlength.value.length > maxlimit) {
		textlength.value = textlength.value.substring(0, maxlimit);
		
	}else {
		cntfield = document.getElementById(cntfield);
		cntfield.value = maxlimit - textlength.value.length;
		
	}
}
function validateLaptop(formRef){
	
	var form = $(formRef);
	var code1 = form['brand'];
	
	
	brand = $F(code1);
	
	
	if(brand=="Please Select..."){
		alert("Please select a brand");
		return false;
	}
	if(!formRef.price.value){
		alert("Please enter a price");
		return false;
	}
	if(!formRef.pAndP.value){
		alert("Please enter the cost of postage and packing");
		return false;
	}
	return true;
	
}
/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var trailimage=["test.gif", 250, 250] //image path, plus width and height
var offsetfrommouse=[15,15] //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0 //duration in seconds image should remain visible. 0 for always.
var trailid = "floating_desc";
var imageheight = 0;	
var imagewidth = 0;

function gettrailobj(){
	if($(trailid))	
		return $(trailid).style
	else 
		return null;
}

function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidetrail(){
	gettrailobj().visibility="hidden";
	document.onmousemove="";
	gettrailobj().left="-500px"
	imageheight = 0;
}

function followmouse(e) {
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]
	
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
	
	var width = imagewidth + 33;

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < width){
			xcoord = e.pageX - xcoord - width; 
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (imageheight+ 35 )){
			ycoord += e.pageY - Math.max(0,( imageheight+ 35 + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < width){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - width; 
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (imageheight + 35 )){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,( imageheight + 35 + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
		if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
	
}

function showtrail(desc, title,height, width,border) {
	if(!border )
		border = 10;
	
	document.onmousemove=followmouse;
	
	imageheight = height+border;
	imagewidth = width+border;
	//Logger.info("height: "+height);
	
	var content = !(imageheight && imagewidth) ? '' : '<iframe src="about:blank" scrolling="no" frameborder="0" style="width:'+(imagewidth+12)+'px;height:'+(imageheight+12)+'px;border:none;display:block;z-index:0;position:absolute;"></iframe>';
	content += '<div style="padding: 5px; background-color: #FFFFFF; border: 1px solid #888888;' + (imageheight && imagewidth ? 'width:'+imagewidth+'px;height:'+imageheight+'px;' : '')+'z-index:1;position:absolute;">';
	if(title)
		content += '<strong style="font-size:12px;">'+title+'</strong><br/>';
	content += '<div style="padding: 2px 2px 2px 2px;">' + $(desc).innerHTML + ' </div>';
	content += '</div>';
	
	$(trailid).innerHTML = content;
	gettrailobj().visibility="visible";
}

function showtrailimg(img, imageheight, imagewidth) {
	
	document.onmousemove=followmouse;
	
	//Logger.info("height: "+height);
	
	var content = !(imageheight && imagewidth) ? '' : '<iframe src="about:blank" scrolling="no" frameborder="0" style="width:'+(imagewidth+12)+'px;height:'+(imageheight+12)+'px;border:none;display:block;z-index:0;position:absolute;"></iframe>';
	content += '<div style="padding: 5px; background-color: #FFFFFF; border: 1px solid #888888;z-index:1;position:absolute;">';
	content += '<div style="' + (imageheight && imagewidth ? 'width:'+imagewidth+'px;height:'+imageheight+'px' : '') + '"><img '+(imageheight && imagewidth ? 'width="'+imagewidth+'" height="'+imageheight+'"' : '')+' src="' + img + '" border="0"/></div>';
	content += '</div>';
	
	$(trailid).innerHTML = content;
	gettrailobj().visibility="visible";
}




/**
 * FlashObject v1.3c: Flash detection and embed - http://blog.deconcept.com/flashobject/
 *
 * FlashObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof com == "undefined") var com = new Object();
if(typeof com.deconcept == "undefined") com.deconcept = new Object();
if(typeof com.deconcept.util == "undefined") com.deconcept.util = new Object();
if(typeof com.deconcept.FlashObjectUtil == "undefined") com.deconcept.FlashObjectUtil = new Object();
com.deconcept.FlashObject = 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 = com.deconcept.util.getRequestParameter(this.DETECT_KEY);
  this.params = new Object();
  this.variables = new Object();
  this.attributes = new Array();
  this.useExpressInstall = useExpressInstall;

  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 com.deconcept.PlayerVersion(ver.toString().split(".")));
  this.installedVer = com.deconcept.FlashObjectUtil.getPlayerVersion(this.getAttribute('version'), useExpressInstall);
  if(c) this.addParam('bgcolor', c);
  var q = quality ? quality : 'high';
  this.addParam('quality', q);
  var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
  this.setAttribute('xiRedirectUrl', xir);
  this.setAttribute('redirectUrl', '');
  if(redirectUrl) this.setAttribute('redirectUrl', redirectUrl);
}
com.deconcept.FlashObject.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;
  },
  createParamTag: function(n, v){
    var p = document.createElement('param');
    p.setAttribute('name', n);
    p.setAttribute('value', v);
    return p;
  },
  getVariablePairs: function(){
    var variablePairs = new Array();
    var key;
    var variables = this.getVariables();
    for(key in variables){
      variablePairs.push(key +"="+ variables[key]);
    }
    return variablePairs;
  },
  getFlashHTML: function() {
    var flashNode = "";
    if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
      if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "PlugIn");
      flashNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
      flashNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
      var params = this.getParams();
       for(var key in params){ flashNode += [key] +'="'+ params[key] +'" '; }
      var pairs = this.getVariablePairs().join("&");
       if (pairs.length > 0){ flashNode += 'flashvars="'+ pairs +'"'; }
      flashNode += '/>';
    } else { // PC IE
      if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "ActiveX");
      flashNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
      flashNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
      var params = this.getParams();
      for(var key in params) {
       flashNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
      }
      var pairs = this.getVariablePairs().join("&");
      if(pairs.length > 0) {flashNode += '<param name="flashvars" value="'+ pairs +'" />';}
      flashNode += "</object>";
    }
    return flashNode;
  },
  write: function(elementId){
    if(this.useExpressInstall) {
      // check to see if we need to do an express install
      var expressInstallReqVer = new com.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);
      }
    } else {
      this.setAttribute('doExpressInstall', false);
    }
    if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
      var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
      n.innerHTML = this.getFlashHTML();
    }else{
      if(this.getAttribute('redirectUrl') != "") {
        document.location.replace(this.getAttribute('redirectUrl'));
      }
    }
  }
}

/* ---- detection functions ---- */
com.deconcept.FlashObjectUtil.getPlayerVersion = function(reqVer, xiInstall){
  var PlayerVersion = new com.deconcept.PlayerVersion(0,0,0);
  if(navigator.plugins && navigator.mimeTypes.length){
    var x = navigator.plugins["Shockwave Flash"];
    if(x && x.description) {
      PlayerVersion = new com.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 com.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 com.deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
      }catch(e){}
    }
  }
  return PlayerVersion;
}
com.deconcept.PlayerVersion = function(arrVersion){
  this.major = parseInt(arrVersion[0]) || 0;
  this.minor = parseInt(arrVersion[1]) || 0;
  this.rev = parseInt(arrVersion[2]) || 0;
}
com.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 ---- */
com.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 "";
  }
}

/* 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 = com.deconcept.util.getRequestParameter;
var FlashObject = com.deconcept.FlashObject;
