// JavaScript Document

var XMLObject;

function LoadFeed(URL, ElementID, LoadingHTML, LoadCode) {
		
	var XMLObject;

	XMLObject = false;

	if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	
		try {
			XMLObject = new XMLHttpRequest();
		} catch(e) {
			XMLObject = false;
		}

	} else if(window.ActiveXObject) {
		
		try {
			XMLObject = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				XMLObject = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				XMLObject = false;
	       		}
		}

	}

	if(XMLObject) {
		if (ElementID != '') {
			document.getElementById(ElementID).innerHTML = LoadingHTML;
		}
			
		if (URL.indexOf('?') == -1) {
			XMLObject.open("GET", URL + '?Rndd=' + Math.floor(Math.random()*99999999999999999), true);
		} else {
			XMLObject.open("GET", URL + '&Rndd=' + Math.floor(Math.random()*99999999999999999), true);
		}
			
		XMLObject.onreadystatechange = function() {
												
											if (XMLObject.readyState == 4 && XMLObject.status == 200) {
												if (ElementID != '') {
													document.getElementById(ElementID).innerHTML = XMLObject.responseText
												}
												XMLObject = null;
												eval(LoadCode);
											}
											
										}
		XMLObject.send("");

	} else {
		
		document.getElementById(ElementID).innerHTML = '<div class="errordiv">No LDAP detected</div>'
			
	}
		
}

//use if select box is showing through an element thats above it in ie6
function selectDisplay(TempDiv) {
	try {
		var temp = document.getElementById(TempDiv);

		if(temp.style.visibility == 'hidden') {
			temp.style.visibility = 'visible'
		} else {
			temp.style.visibility = 'hidden'
		}
	} catch(e) {

	}
}
//end ie6 select fix

function EmailTo(url) {
	window.location = url;
}

function GotoArea(Menu, USState) {
	
    if (Menu.value !== '' && Menu.value !== 'Type City or Town' && USState.value !== 'NA') {
	    
        document.location = '/SearchOffices.aspx?HP=TopBar&City=' + Menu.value + '&State='+ USState.value +'&ComPage=0';
	
	} else if (USState.value !== 'NA') {
	    
        document.location = '/SearchOffices.aspx?HP=TopBar&State='+ USState.value +'&ComPage=0';
		
	} else {

		try {

                	Menu = document.getElementById('home-txt')
	
			if (Menu.value !== ''  && Menu.value !== 'Type City or Town' && USState.value !== 'NA') {		

				document.location = '/SearchOffices.aspx?HP=TopBar&City=' + Menu.value + '&State='+ USState.value +'&ComPage=0';
	
			} else if (USState.value !== 'NA') {
				
				document.location = '/SearchOffices.aspx?HP=TopBar&State='+ USState.value +'&ComPage=0';
				
			} else {
				alert('Please type city name then choose a State');
			}
		       

            	} catch(e) {
					alert('Please type city name then choose a State');

		}		

		
	}
    
}

function GotoAreaDrp(Menu) {

    if (Menu.value !== 'na') {
	    
        document.location = '/' + Menu.value + '_Office+Space+to+Rent_1.html';

    }
    
}

function GotoStateAreaDrp(Menu) {

    if (Menu.value !== 'na') {
	    
        document.location = Menu.value;

    }
    
}
    

function checkFormError(element) {

	var splitElements = element.split(":");

	for(i = 0; i < splitElements.length; i++){
		var temp = document.getElementById(splitElements[i]).value
		temp = temp.replace(/</g, "&lt;");
		document.getElementById(splitElements[i]).value = temp
		
	}
	return true;
}

function globalSearch(MyTextValue) {
		
	if (MyTextValue != ''  && MyTextValue !== 'Type UK location') {		
		document.location = '/SearchOffices.aspx?ST=FreeText&Location=' + MyTextValue + '&ComPage=0';
	}		

}


function checkEnter(e,Menu, USState) { //e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		GotoArea(Menu, USState) //submit the form
		return false
	}
	else{
		return true
	}

}

function clearsearch(MyBox) {

	var searchbox = MyBox;

	if (searchbox.value == '') {
		searchbox.value = 'Type City or Town';
		searchbox.style.color = '#000000';
	} else if (searchbox.value == 'Type City or Town') {
		searchbox.value = '';
		searchbox.style.color = '#000000';
	}

}