function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless,focus) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;  
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth; 
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0; 						
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  
 // This is for only photos display 
 if(winName == 'photo')
  {
      popupWindow[wp] = window.open('',winName,features);
	  popupWindow[wp].document.write('<body bgcolor=#dbdcdc onLoad="if (window.focus) window.focus()"><center>');
	  popupWindow[wp].document.write('<img src="' + theURL + '">');
	  popupWindow[wp].document.write('</center></body>');
	  popupWindow[wp].document.close();  
  }
  else
  {
  	  popupWindow[wp] = window.open(theURL,winName,features);
  }

  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;  
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}  
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }   
    if (focus && focus != "") {popupWindow[wp].focus();}
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function selectFullField( fld ) {
	fld.select();
}

function showPhoto( url ) {
  GP_AdvOpenWindow(url,'photo','fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes',400,300,'center','ignoreLink','',0,'');
}


function validate_required(field,alerttxt)	{
		with (field)
		{
			if (value==null||value=="")
  			{
  			//alert(alerttxt);
  			return false
  			}
			else {return true}
		}
}
     	
function validate_email(field,alerttxt){
		with (field)
		{
			apos=value.indexOf("@")
			dotpos=value.lastIndexOf(".")
			if (apos<1||dotpos-apos<2) 
  				{
  				//alert(alerttxt);
  				return false
  				}
			else {return true}
		}
}



function validate_email(field,alerttxt){
		
		
		with (field)
		{
		
		/*	apos=value.indexOf("@")
			dotpos=value.lastIndexOf(".")
			if (apos<1||dotpos-apos<2) 
  				{
  				//alert(alerttxt);
  				return false
  				}
			else {return true}
		*/
		
		return 	emailCheck (value);
		
		}
}



function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@&,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	//alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    //alert("The part of your email address before the '@' doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        //alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	//alert("Part of your email address after the '@' doesn't seem to be valid")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>6) {
   // the address must end in a two letter or other TLD including museum
   //alert("The address must end in a top level domain (e.g. .com), or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   //alert(errStr)
   return false
}

// If we've got this far, everything's valid!
return true;
}


function invokeURL(url) 
{
  var req;
  // branch for native XMLHttpRequest object
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
    req.onreadystatechange = processReqChange;
    req.open("GET", url, true);
    req.send(null);
    // branch for IE/Windows ActiveX version
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    if (req) {
      req.onreadystatechange = processReqChange;
      req.open("GET", url, true);
      req.send();
    }
  }
}

function processReqChange(){
}



	// Declaring required variables
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 7;

	function isInteger(s)
	{   
		var i;
		
    		for (i = 0; i < s.length; i++)
    		{   
        		// Check that current character is number.
        		var c = s.charAt(i);
        		if (((c < "0") || (c > "9"))) return false;
    		}
    		// All characters are numbers.
    		return true;
	}

	
	function stripCharsInBag(s, bag)
	{   
		var i;
    		var returnString = "";
    		// Search through string's characters one by one.
    		// If character is not in bag, append to returnString.
    		for (i = 0; i < s.length; i++)
    		{   
        		// Check that current character isn't whitespace.
        		var c = s.charAt(i);
        		if (bag.indexOf(c) == -1) returnString += c;
    		}
    	return returnString;
	}

	function checkInternationalPhone(strPhone){
		s=stripCharsInBag(strPhone,validWorldPhoneChars);
		return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
	}

	function isValidDate(day,month,year){
	/*
	Purpose: return true if the date is valid, false otherwise

	Arguments: day integer representing day of month
	month integer representing month of year
	year integer representing year

	Variables: dteDate - date object

	*/
	var dteDate;

	//set up a Date object based on the day, month and year arguments
	//javascript months start at 0 (0-11 instead of 1-12)
	dteDate=new Date(year,month,day);

	/*
	Javascript Dates are a little too forgiving and will change the date to a reasonable guess if it's invalid. We'll 		use this to our advantage by creating the date object and then comparing it to the details we put it. If the Date 		object is different, then it must have been an invalid date to start with...
	*/

	return ((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear()));
	}
	


// ----------------------


	function fasttrack_form_process(thisform)
      	{	
      		if(validate_fasttrack_form (thisform))
      		{      			
      		
      			thisform.submit();		      		      			
      			 
      		}  
      	} 

	function validate_fasttrack_form(thisform)
	{
	
	
		with (thisform)
		{			
			
  			Obj = null;
  			MSG="";
  			
  			
  			if (validate_required(ContactCompany,"")==false)
  			{
  				Obj = (Obj == null)?ContactCompany:Obj;  				
  				MSG = MSG + "Please enter your company name\n";
  			}  			
  			
			if (validate_required(ContactName,"")==false)
  			{  				
  				Obj = (Obj == null)?ContactName:Obj;  				
  				MSG = MSG + "Please enter your contact name\n";
  			}  			
  			
  			if (validate_required(ContactTel,"")==false)
  			{
  				Obj = (Obj == null)?ContactTel:Obj;
  				MSG = MSG + "Please enter your telephone number\n";
  			}
  			
  			if (validate_required(ContactTel,"") && checkInternationalPhone(ContactTel.value)==false)
  			{  			
  				Obj = (Obj == null)?ContactTel:Obj;
  				MSG = MSG + "Please make sure telephone number is valid\n";
  			}			
			
			if (validate_required(ContactEmail,"")==false)
  			{
  				
  				Obj = (Obj == null)?ContactEmail:Obj;	
  				MSG = MSG + "Please enter your email\n";
  			}
  			
  			if ((MSG=="") && validate_email(ContactEmail,"")==false)
  			{  			
  				Obj = ContactEmail;
  				MSG = "Please make sure e-mail address is valid\n";
  			}
  			
			
			if(MSG == "")
			{
				return true;
			}
			else
			{
				alert(MSG);
				Obj.focus();
				return false;
			}
		}
	}


	
// This is code for fast track form validation and confirmation
    function form_process(thisform)
    {	
	
    		if(validate_form (thisform))
      		{      			
      			if(checkSelected())
      			{
      				thisform.submit();		      		      			
      			} 
      		}  
    } 

	
	function validate_form(thisform)
	{
	
	
		with (thisform)
		{			
			
  			Obj = null;
  			MSG="";
  			
  			if (validate_required(email,"")==false)
  			{
  				
  				Obj = (Obj == null)?email:Obj;	
  				MSG = MSG + "Please enter your email\n";
  			}
  			
  			if ((MSG=="") && validate_email(email,"")==false)
  			{  			
  				Obj = email;
  				MSG = "Please make sure e-mail address is valid\n";
  			}
  			
  			if (validate_required(companyName,"")==false)
  			{
  				Obj = (Obj == null)?companyName:Obj;  				
  				MSG = MSG + "Please enter your company name\n";
  			}  			
  			
			if (validate_required(firstName,"")==false)
  			{  				
  				Obj = (Obj == null)?firstName:Obj;  				
  				MSG = MSG + "Please enter your first name\n";
  			}
  			
  			if (validate_required(tel,"")==false)
  			{
  				Obj = (Obj == null)?tel:Obj;
  				MSG = MSG + "Please enter your telephone number\n";
  			}
  			
  			if (validate_required(tel,"") && checkInternationalPhone(tel.value)==false)
  			{  			
  				Obj = (Obj == null)?tel:Obj;
  				MSG = MSG + "Please make sure telephone number is valid\n";
  			}
			
			if (validate_required(numPeople,"")==false)
  			{
  				Obj = (Obj == null)?numPeople:Obj;
  				MSG = MSG + "Please enter your space requirements (number of people)\n";
  			}
			
			if(MSG == "")
			{
				return true;
			}
			else
			{
				alert(MSG);
				Obj.focus();
				return false;
			}
		}
	}

function checkSelected() 
	{	
		if(saved_bcids.length < 1)
		{
    			alert( "Please ensure you have selected at least one business centre for your report" );
    			return false;  
		}
		return true;
	}
	

function reqPriceView( id, req ) {
		re = /XXX/gi;		
		durl = priceview_url.replace( re, "" + id );				
		location.href=durl+ "&req=" + req;		
	}
		
function showDescription( id, area, point ) {
		re = /XXX/gi;
		resPoint=point;
		durl = description_url.replace( re, "" + id );
		location.href=durl;		
	}

  	
function checkSelected() 
	{	
		if(saved_bcids.length < 1)
		{
    			alert( "Please ensure you have selected at least one business centre for your report" );
    			return false;  
		}
		return true;
	}

function setFormTheme()
	{	
		if(saved_bcids.length > 0)
		{
			fblock=document.getElementById("basket");
			//fblock.style.background="#73be1e";
			fblock.style.display="block";
	
		}
		else
		{	
			fblock=document.getElementById("basket");
			//fblock.style.background="#4d6aab";
			fblock.style.display="none";
	
		}
	}
		
function Re_Submit(qry)
	{
		//window.location.href=document.URL;
		document.forms['ReSubmit'].qryType.value = qry; 		
		document.forms['ReSubmit'].submit();
	}


function leasing_form_process(thisform)
	{

		if(validate_leasing_form (thisform))
      		{      			
      		
      			thisform.submit();		      		      			
      			 
      		}  

	}


function validate_leasing_form (thisform)
	{
	
	
		with (thisform)
		{			
			
  			Obj = null;
  			MSG="";

			if (validate_required(applicantName,"")==false)
  			{  				
  				Obj = (Obj == null)?applicantName:Obj;  				
  				MSG = MSG + "Please enter your name\n";
  			}  			  			
  			
			if (validate_required(applicantCompany,"")==false)
  			{
  				Obj = (Obj == null)?applicantCompany:Obj;  				
  				MSG = MSG + "Please enter your company name\n";
  			}

			if (validate_required(businessType,"")==false)
  			{
  				Obj = (Obj == null)?businessType:Obj;  				
  				MSG = MSG + "Please select your business type\n";
  			}

			if (validate_required(applicantAddress1,"")==false)
  			{
  				Obj = (Obj == null)?applicantAddress1:Obj;  				
  				MSG = MSG + "Please enter your address\n";
  			}
			
			if (validate_required(applicantTown,"")==false)
  			{
  				Obj = (Obj == null)?applicantTown:Obj;  				
  				MSG = MSG + "Please enter your town\n";
  			}

			if (validate_required(applicantCountry,"")==false)
  			{
  				Obj = (Obj == null)?applicantCountry:Obj;  				
  				MSG = MSG + "Please enter your country\n";
  			}
			
			if (validate_required(applicantCounty,"")==false)
  			{
  				Obj = (Obj == null)?applicantCounty:Obj;  				
  				MSG = MSG + "Please enter your region (county/state)\n";
  			}
			
			if (validate_required(applicantPostcode,"")==false)
  			{
  				Obj = (Obj == null)?applicantPostcode:Obj;  				
  				MSG = MSG + "Please enter your postcode\n";
  			}
			
			if (validate_required(applicantTel,"")==false)
  			{
  				Obj = (Obj == null)?applicantTel:Obj;
  				MSG = MSG + "Please enter your telephone number\n";
  			}
  			
  			if (validate_required(applicantTel,"") && checkInternationalPhone(applicantTel.value)==false)
  			{  			
  				Obj = (Obj == null)?applicantTel:Obj;
  				MSG = MSG + "Please make sure telephone number is valid\n";
  			}

  			if (validate_required(applicantEmail,"")==false)
  			{
  				
  				Obj = (Obj == null)?applicantEmail:Obj;	
  				MSG = MSG + "Please enter your email\n";
  			}
  			
  			if ((MSG=="") && validate_email(applicantEmail,"")==false)
  			{  			
  				Obj = applicantEmail;
  				MSG = "Please make sure e-mail address is valid\n";
  			}
  			
			if (validate_required(location,"")==false)
  			{
  				Obj = (Obj == null)?location:Obj;
  				MSG = MSG + "Please enter location you required in\n";
  			}

			if (validate_required(workstations,"")==false)
  			{
  				Obj = (Obj == null)?workstations:Obj;
  				MSG = MSG + "Please enter your space requirements (number of people)\n";
  			}
			
			if(MSG == "")
			{
				return true;
			}
			else
			{
				alert(MSG);
				Obj.focus();
				return false;
			}
		}
	}


// -->

// This is to move the registration form in results page 
		
var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }

function AssignPosition(d) {
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}

//d.style.left = (cX-770) + "px";
//d.style.top = (cY-500) + "px";

d.style.left = (2) + "px";
d.style.top = (cY-300) + "px";

}


function AssignPosition(d, area) {

if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}


//d.style.left = (cX-770) + "px";
//d.style.top = (cY-500) + "px";

var basket = document.getElementById('basket').clientHeight;
var info = document.getElementById('textblue').clientHeight;
var reg = document.getElementById('register').clientHeight;

if (area == "middle"){
	d.style.left = (0) + "px";
	//d.style.top = (cY-300) + "px";
	d.style.top = (rY-basket-100) + "px";
	//alert("mid =>" + d.style.top);
	}
else if(area == "bottom"){
	d.style.left = (0) + "px";				
	// d.style.top = (cY-(840+basket+info)) + "px";
	
	if((rY-reg) < 0)	
	 d.style.top = (0)  + "px";
	else
	 d.style.top = (rY-reg)+100  + "px";

	//alert("bot =>" + d.style.top);
	}
else{
	// For Top, now do nothing
	
	d.style.left = (0) + "px";	
	d.style.top = (0) + "px";
	//alert("top =>" + d.style.top);
	
	}


}

function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
dd.style.display = "block";
}

function ShowContent(d, area) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd, area);
dd.style.display = "block";
}

function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
if(dd.style.display == "none") { dd.style.display = "block"; }
else { dd.style.display = "none"; }
}
//-->	
