// 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) {
	var temp = document.getElementById(TempDiv);

	if(temp.style.visibility == 'hidden') {
		temp.style.visibility = 'visible'
	} else {
		temp.style.visibility = 'hidden'
	}
}
//end ie6 select fix

function EmailTo(url) {
	window.location = url;
}

function GotoArea(Menu) {
	if (Menu.value !== '' && Menu.value !== 'Type City or Town') {
		
		if (searchurl.length > 0) {
			document.location = searchurl;
		} else {
        	document.location = '/CommercialProperties/ComResults.aspx?HP=HomePage&Location=' + Menu.value + '&ComPage=1';
		}

	} else {

		try {
			if (searchurl != '') {
				document.location = searchurl;
			} else {
            			Menu = document.getElementById('home-txt')
				if (Menu.value !== ''  && Menu.value !== 'Type City or Town') {		
					document.location = '/CommercialProperties/ComResults.aspx?HP=HomePage&Location=' + Menu.value + '&ComPage=1';
				}
			}

		} catch(e) {

		}
	}
}

function commGotoArea(Menu) {
	if (Menu.value !== '' && Menu.value !== 'Type City or Town') {
		
		if (searchurl.length > 0) {
			document.location = searchurl;
		} else {
        	document.location = '/CommercialProperties/ComResults.aspx?HP=HomePage&Location=' + Menu.value + '&ComPage=1';
		}

	} else {

		try {
			if (searchurl != '') {
				document.location = searchurl;
			} else {
            			Menu = document.getElementById('home-txt')
				if (Menu.value !== ''  && Menu.value !== 'Type City or Town') {		
					document.location = '/CommercialProperties/ComResults.aspx?HP=HomePage&Location=' + Menu.value + '&ComPage=1';
				}
			}

		} catch(e) {

		}
	}
}

function GotoAreaDrp(Menu) {

    if (Menu.value !== 'na') {
	    
        document.location = '/' + Menu.value + '_Commercial+Office+Space+to+Rent_1.html';

    }
    
}

function commGotoAreaDrp(Menu) {

    if (Menu.value !== 'na') {
	    
        document.location = '/' + Menu.value + '_Commercial+Office+Space+to+Rent_1.html';

    }
    
}

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 = '/CommercialProperties/ComResults.aspx?HP=HomePage&Location=' + MyTextValue + '&ComPage=1';
	}		

}


function globalCheckEnter(e,MyTextValue) { //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)
		/*if (document.location != '') {
				document.location = searchurl;
		} else {
			globalSearch(MyTextValue) //submit the form
		} */
		
		globalSearch(MyTextValue)
		return false
	}
	else{
		return true
	}

}

function checkEnter(e,Menu) { //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)
		if (document.location != '') {
				document.location = searchurl;
		} else {
			GotoArea(Menu) //submit the form
		}
		return false
	}
	else{
		return true
	}

}

function CommcheckEnter(e,Menu) { //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)
		if (document.location != '') {
				//document.location = searchurl;
				document.location = '/CommercialProperties/ComResults.aspx?HP=HomePage&Location=' + Menu.value + '&ComPage=1';
		} else {
			commGotoArea(Menu) //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 = '#CCCCCC';
	} else if (searchbox.value == 'Type City or Town') {
		searchbox.value = '';
		searchbox.style.color = '#000000';
	}

}




var oldlength = 0;
var helperlink = 0;
var FoundResults = 0;
var searchurl = '';
var tempurl = '';

var searchurl = '';
var VisableHelper = 'Head';

function UpdateSearchType(MyType, MyTextBox) {

	SearchType = MyType;
	TextBoxType =  MyTextBox;

}

function HideHelper() {


}

function showhelper(searchbox) {
		
}

function changeGlobal(MyBox,Typing,SearchType) {
	var searchbox = MyBox;	
		
	if (searchbox.value == '' && Typing == false) {
		searchbox.value = 'Type UK location';
		
	} else if (Typing == true && searchbox.value == 'Type UK location') {
		searchbox.value = '';
		searchbox.style.color = '#000';
		searchbox.style.fontStyle = 'normal';
	}
}

function FocusHelp(e, forceme) {

}

function scrollnow() {

}

function changehelperlink(newlink) {


}

function findplaces(searchbox) {

	if ((searchbox.value.length > 3) && (document.getElementById(SearchType + 'SearchHelper').innerHTML != 'Loading...') && (searchbox.value.length != oldlength)) {

		LoadFeed('/includes/PredictSearch.aspx?Placename=' + searchbox.value + '&Helper=' + SearchType, SearchType + 'SearchHelper', 'Loading...', 'changehelperlink(0)');
		FoundResults = 1;
		searchurl = tempurl;
	} else if (searchbox.value.length <= 3) {
		document.getElementById(SearchType + 'SearchHelper').style.display = 'none'

		tempurl = searchurl
		searchurl = '';
	}

	oldlength = searchbox.value.length

}

function startscroll(e) {

}

function stopscroll() {

}

function hide() {

}

function setSearchHelperEvents(searchHelper) {

}