http_request = new XMLHttpRequest();

function disablebackspace() {
	if (window.focus) window.focus();
		document.onkeydown=catchbackspace;
		document.onkeyup=catchbackspace;
}

function catchbackspace() {
	if (!e) e=window.event;
	if (e.keyCode == 8){
		alert("Backspace key was pressed.");
		return false;
	}
}

function showMenu(menu, obj) {
	hideMenu();
	menu = document.getElementById(menu);
	menu.style['display'] = 'block';
	menu.style['top'] = '100px';
	menu.style['left'] = obj.offsetLeft + 'px';
	if (BrowserDetect.browser == 'Explorer') {
		navbarOffset = document.getElementById('nav').offsetParent.offsetLeft;
		menu.style['left'] = obj.offsetLeft + navbarOffset + 'px';
	}
}

function hideMenu() {
	menu1 = document.getElementById('leads');
	menu1.style['display'] = 'none';
	if (document.getElementById('vendors')) {
		menu2 = document.getElementById('vendors');
		menu2.style['display'] = 'none';
	}
	if (document.getElementById('manufacturers')) {
		menu2 = document.getElementById('manufacturers');
		menu2.style['display'] = 'none';
	}
	if (document.getElementById('orders')) {
		menu6 = document.getElementById('orders');
		menu6.style['display'] = 'none';
	}
	if (document.getElementById('users')) {
		menu3 = document.getElementById('users');
		menu3.style['display'] = 'none';
	}
	if (document.getElementById('reports')) {
		menu4 = document.getElementById('reports');
		menu4.style['display'] = 'none';
	}
	if (document.getElementById('files')) {   	
		menu5 = document.getElementById('files');	
		menu5.style['display'] = 'none';           	
	}                                           	
}

function toggleCheckboxes() {
	boxes = document.getElementsByTagName('input');
	for (i in boxes) {
		if (/idcheck/.test(boxes[i].className)) {
			if (boxes[i].checked) {
				// Do Nothing
				} else {
				boxes[i].checked = 'checked';
			}
		}
	}
}

function updateCounties(selectObj, counter) {
	var http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	
	myState = selectObj.options[selectObj.selectedIndex].value;
	real    = 'realvalue_' + counter;
	myValue = document.getElementById(real);
	myValue.value = myState;
	
	http_request.onreadystatechange = function() { handleChangeDropdown(http_request, counter); };
	http_request.open('POST', '../admin/admin_county_list.php', true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send('q=' + myState);
}
			
function handleChangeDropdown(http_request, counter) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var dropdowner = 'counties_' + counter;
			document.getElementById(dropdowner).innerHTML = '&nbsp;' + http_request.responseText;
			// document.getElementById(dropdowner).style['display'] = 'none';
		}
	}
}

function updateCriteriaType(selectObj, counter) {
	value   = selectObj.options[selectObj.selectedIndex].value;
	div     = 'criteria_' + counter;
	real    = 'realvalue_' + counter;
	myDiv   = document.getElementById(div);
	myValue = document.getElementById(real);
	stateCriteria      = 'State';
	countyCriteria     = 'County';
	excludeCriteria    = 'County_Exclude';
	minBudgetCriteria  = 'Budget_Min';
	maxBudgetCriteria  = 'Budget_Max';
	houseStyleCriteria = 'House_Style';
	if ((value == stateCriteria) || (value == countyCriteria) || (value == excludeCriteria)) {
		myDiv.style['display'] = 'block';
	} else if ((value == minBudgetCriteria) || (value == maxBudgetCriteria)) {
		myDiv.innerHTML = 'Amount: <select name="realvalue_' + counter + '"><option>100000</option><option>150000</option><option>200000</option><option>250000</option><option>300000</option><option>400000</option><option>500000</option><option>600000</option><option>700000</option><option>800000</option><option>900000</option><option>1000000</option><option>1500000</option><option>2000000</option><option>3000000</option></select>';
		myDiv.style['display'] = 'block';
	} else if (value == houseStyleCriteria) {
		myDiv.innerHTML = 'Amount: <select name="realvalue_' + counter + '"><option>Bungalow</option><option>Colonial</option><option>Cottage</option><option>Country</option><option>Georgian</option><option>Log Type</option><option>Luxury</option><option>Mediterranean</option><option>Modern</option><option>Ranch</option><option>Southwestern</option><option>Tudor</option><option>Victorian</option></select>';
		myDiv.style['display'] = 'block';
	} else {
		myDiv.style['display'] = 'none';
		myValue.value = 'True';
	}
}

function updateCountyValue(selectObj, counter) {
	myCounty  = selectObj.options[selectObj.selectedIndex].value;
	real      = 'realvalue_' + counter;
	myValue   = document.getElementById(real);
	myValue.value = myCounty;
}

function showLeadNotes(row, div_id) {
	divName = 'notes_' + div_id;
	obj = document.getElementById(divName);
	navbarOffset = document.getElementById('nav').offsetLeft;
	obj.style['display'] = 'block';
	obj.style['top'] = row.offsetTop + row.offsetHeight + 855 - obj.offsetHeight + 'px';
}

function hideLeadNotes(div_id) {
	divName = 'notes_' + div_id;
	obj = document.getElementById(divName);
	obj.style['display'] = 'none';
}

function showVendorNotes(row, div_id) {
	divName = 'notes_' + div_id;
	obj = document.getElementById(divName);
	navbarOffset = document.getElementById('nav').offsetLeft;
	obj.style['display'] = 'block';
	obj.style['top'] = row.offsetTop + row.offsetHeight + 230 - obj.offsetHeight + 'px';
}

function hideVendorNotes(div_id) {
	divName = 'notes_' + div_id;
	obj = document.getElementById(divName);
	obj.style['display'] = 'none';
}

function showAdditionalNotes(row, div_id) {
	divName = 'additional_' + div_id;
	obj = document.getElementById(divName);
	navbarOffset = document.getElementById('nav').offsetLeft;
	obj.style['display'] = 'block';
	obj.style['top'] = row.offsetTop + row.offsetHeight + 755 - obj.offsetHeight + 'px';
}

function hideAdditionalNotes(div_id) {
	divName = 'additional_' + div_id;
	obj = document.getElementById(divName);
	obj.style['display'] = 'none';
}

function writeSuccessMessage(message) {
	obj = document.getElementById('successmessage');
	obj.innerHTML = '<img src="../images/success.png" alt="Modulars.com Administration" />&nbsp;' + message;
}

function writeErrorMessage(message) {
	obj = document.getElementById('errormessage');
	obj.innerHTML = '<img src="../images/error.png" alt="Modulars.com Administration" />&nbsp;' + message;
}

function showVendorProfile(vendor_id) {
	divName = 'profile_' + vendor_id;
	obj = document.getElementById(divName);
	obj.style['display'] = 'block';
}

function hideVendorProfile(vendor_id) {
	divName = 'profile_' + vendor_id;
	obj = document.getElementById(divName);
	obj.style['display'] = 'none';
}

function followContextMenuLink() {
	mylink = document.getElementById('contextmenu').options[document.getElementById('contextmenu').selectedIndex].value;
	
	location.href = mylink;
}
 // HAXORED
