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 addToMailingList() {
	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...';	
	}
	
	if(validationError == false) {
		location.href = 'modules/add_to_mailing_list.asp?email=' + email;
	}
	
}

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 clearSearchBox() {
	if(document.getElementById("searchtext").value == 'click to search...') document.getElementById("searchtext").value = '';
}

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';
	}
}
