var xmlHttp;
var addToMailingListResult = false;

function ajaxFunction() {  
	try {    
		xmlHttp = new XMLHttpRequest();    
	}
	catch (e) {    
		try {      
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");      
		}
		catch (e) {       
			try {        
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");        
			}
			catch (e) {        
				alert("Your browser does not support AJAX!");        
				return false;        
			}		      
		}    
	}  
	
	xmlHttp.onreadystatechange = function() {
  		if(xmlHttp.readyState == 4) {
    		addToMailingListResult = xmlHttp.responseText;
    	}
  	}
	
}

function updateLiveSearchList() {
	var livesearchtext = document.getElementById("livesearchtext").value;
	if(livesearchtext != "") {
		ajaxFunction();
		xmlHttp.open("GET", "modules/live_search_results.asp?searchText=" + livesearchtext, false);
		xmlHttp.send(null);
		document.getElementById("content").innerHTML = xmlHttp.responseText;
	}
	else {
		document.getElementById("content").innerHTML = "";
	}
}

function addToMailingList(facebookid) {

	var validationError = false;
	var validationErrorMsg = 'Enter valid email address!';
	
	var email = document.getElementById("subscriberemail").value;
	
	if(email.length == 0) {
		validationError = true;
		document.getElementById("subscriberemail").value = 'enter valid email...';	
	}
	
	if(email.length > 0 && !/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
		validationError = true;
		document.getElementById("subscriberemail").value = 'enter valid email...';	
	}
	
	try {
	
		var listname = document.getElementById("listname").value;
		var marketing = document.getElementById("marketing").value;
		
		document.getElementById("listname").className = 'validationSuccess';	
		document.getElementById("marketing").className = 'validationSuccess';	
		
		if(listname.length == 0) {
			validationError = true;
			document.getElementById("listname").className = 'validationError';	
		}
		
		if(marketing.length == 0) {
			validationError = true;
			document.getElementById("marketing").className = 'validationError';	
		}
		
	}
	catch(e) {
	}
	
	if(validationError == false) {
		if(isNaN(facebookid)) location.href = '/modules/add_to_mailing_list.asp?email=' + email + '&marketing=' + marketing + '&listname=' + listname;
		else location.href = '/modules/facebook_add_to_mailing_list.asp?email=' + email + "&facebookid=" + facebookid;
	}
	
}

function clearMailingListBox() {
	if(document.getElementById("subscriberemail").value == 'enter email...' || document.getElementById("subscriberemail").value == 'enter valid email...') document.getElementById("subscriberemail").value = '';
}

function mailingListEnterKey(e) {
	if(e.keyCode == 13) {
		addToMailingList();
	}
}

function displaySearchResults() {
	var searchText = document.getElementById("searchtext").value;
	if(searchText != '' && searchText != 'click to search...') {
		location.href = "display_search_results.asp?searchText=" + searchText;
	}
	else {
		document.getElementById("searchtext").value = 'click to search...';	
	}
}

function displayLiveSearchResults() {
	var searchText = document.getElementById("livesearchtext").value;
	if(searchText != '' && searchText != 'click to search...') {
		location.href = "display_search_results.asp?searchText=" + searchText;
	}
	else {
		document.getElementById("livesearchtext").value = 'click to search...';	
	}
}

function clearSearchBox() {
	if(document.getElementById("searchtext").value == 'click to search...') document.getElementById("searchtext").value = '';
}

function clearLiveSearchBox() {
	if(document.getElementById("livesearchtext").value == 'click to search...') document.getElementById("livesearchtext").value = '';
}

function liveSearchBoxEnterKey(e) {
	if(e.keyCode == 13) {
	}
}

function searchBoxEnterKey(e) {
	if(e.keyCode == 13) {
		displaySearchResults();
	}
}

function fixMargins() {
	var br = new Array(4);
	br = getBrowser();
	var browser = br[0];
	if(browser != 'msie') {
		document.getElementById("searchbutton").style.margin = '0px 0px 0px 0px';
		document.getElementById("subscribebutton").style.margin = '0px 0px 0px 0px';
	}
}

function showBlockMenu(topLevelCount) {
	try {
		if(document.getElementById("blocknavigation" + topLevelCount).style.display = 'none') document.getElementById("blocknavigation" + topLevelCount).style.display = 'block';
		else document.getElementById("blocknavigation" + topLevelCount).style.display = 'none';
		}
	catch(e) {
	}
}

function hideBlockMenus() {
	try {
		document.getElementById("blocknavigation1").style.display = 'none';
		document.getElementById("blocknavigation2").style.display = 'none';
		document.getElementById("blocknavigation3").style.display = 'none';
		document.getElementById("blocknavigation4").style.display = 'none';
		document.getElementById("blocknavigation5").style.display = 'none';
		document.getElementById("blocknavigation6").style.display = 'none';
		document.getElementById("blocknavigation7").style.display = 'none';
		document.getElementById("blocknavigation8").style.display = 'none';
		document.getElementById("blocknavigation9").style.display = 'none';
		document.getElementById("blocknavigation10").style.display = 'none';
	}
	catch(e) {
		attachBlockMenuEventHandlers();
	}
}

function attachBlockMenuEventHandlers() {
	try { document.getElementById("logo").onmouseover = hideBlockMenus; } catch(e) {}
	try { document.getElementById("banner").onmouseover = hideBlockMenus; } catch(e) {}
	try { document.getElementById("left").onmouseover = hideBlockMenus; } catch(e) {}
	try { document.getElementById("content").onmouseover = hideBlockMenus; } catch(e) {}
	try { document.getElementById("right").onmouseover = hideBlockMenus; } catch(e) {}
	try { document.getElementById("footer").onmouseover = hideBlockMenus; } catch(e) {}
}

window.onload = attachBlockMenuEventHandlers
