function clearForm() {
	if(document.getElementById('search').value=='Search for Service'){
		document.getElementById('search').value='';
	}
	if(document.getElementById('where').value=='Where?'){
		document.getElementById('where').value='';
	}
}

function clearSearchForm() {
	if(search_form1.search.value=='Search for Service'){
		search_form1.search.value='';
	}
	if(search_form1.where.value=='Where?'){
		search_form1.where.value='';
	}
}

function search_form_text_click(textinput) {
	if(textinput.name=='search' && textinput.value=='Search for Service') { textinput.value=''; }
	else if(textinput.name=='area' && textinput.value=='Where?') { textinput.value=''; }
	else if(textinput.name=='where' && textinput.value=='Where?') { textinput.value=''; }
}

function ajaxLoader(url,id) {
	el = document.getElementById(id);
	if (el.innerHTML == ''){
		Element.show(id);
		el.innerHTML = '<div class="loading">Loading...</div>';
		if (document.getElementById) {
			var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		}
		if (x) {
			x.onreadystatechange = function() {
				if (x.readyState == 4 && x.status == 200) {
					el = document.getElementById(id);
					el.innerHTML = x.responseText;
				}
			}
			x.open("GET", url, true);
			x.send(null);

		}
	}else{
		Element.hide(id);
		el.innerHTML = '';

	}
}

function ajaxFormSubmit(url,formId,responseId){
	var formRef=document.getElementById(formId);
	var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	if (x) {

		var postData ="company_email="+encodeURI(formRef.company_email.value)+
			"&key="+encodeURI(formRef.key.value)+
			"&your_name="+encodeURI(formRef.your_name.value)+
			"&your_email="+encodeURI(formRef.your_email.value)+
			"&subject="+encodeURI(formRef.subject.value)+
			"&your_message="+encodeURI(formRef.your_message.value);

		x.onreadystatechange = function() {
			if (x.readyState == 4 && x.status == 200) {
				result = x.responseText;
				document.getElementById(responseId).innerHTML = result;
			}/*else {
				alert('There was a problem with the request.'+x.readyState+'  '+x.status+'  ');
			}*/
		};
		x.open('POST', url, true);
		x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		x.setRequestHeader("Content-length", postData.length);
		x.setRequestHeader("Connection", "close");
		x.send(postData);
	}

}

function ajaxPostForm(url,postData,responseId){

	var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	if (x) {

		x.onreadystatechange = function() {
			if (x.readyState == 4 && x.status == 200) {
				result = x.responseText;
				document.getElementById(responseId).innerHTML = result;
			}/*else {
				alert('There was a problem with the request.'+x.readyState+'  '+x.status+'  ');
			}*/
		};
		x.open('POST', url, true);
		x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		x.setRequestHeader("Content-length", postData.length);
		x.setRequestHeader("Connection", "close");
		x.send(postData);
	}

}

var XMLHttp=null;
var target_area;

function GetXmlHttpObject(handler) {
	var objXmlHttp = null;
	if(navigator.userAgent.indexOf("MSIE")>=0) {
		var strName="Msxml2.XMLHTTP";
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
			strName="Microsoft.XMLHTTP";
		}
		try {
			objXmlHttp=new ActiveXObject(strName);
			objXmlHttp.onreadystatechange=handler;
			return objXmlHttp;
		}catch(e){
//			alert("Error. Scripting for ActiveX might be disabled");
			return;
		}
	}else if(navigator.userAgent.indexOf("Mozilla")>=0 || navigator.userAgent.indexOf("Opera")>=0) {
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler;
		return objXmlHttp;
	}
}

function show_hide(id) {
	if(document.getElementById(id).style.display == "none"){
		document.getElementById(id).style.display = "block";
	}else{
		document.getElementById(id).style.display = "none";
	}
}
function relDropdown(container) {
	show_hide('related-cats-footer');
	show_hide('related-areas-footer');
}
function bookmarksite(){
    var urlAddress = "http://www.smilelocal.com";
    var pageName = "Smile Local Business Directory";
    if (document.all){
		window.external.AddFavorite(urlAddress,pageName);
    } else if (window.sidebar){
		window.sidebar.addPanel(pageName, urlAddress, "");
    }
}

/**
 * bt_c2c_popup
 *
 * This function displays the BT click to call popup
 *
 * @return void
 */
function bt_c2c_popup(e) {
	if (e.stopPropagation) {
		e.stopPropagation();
	}
	if (typeof(e.cancelBubble) != "undefined") {
		e.cancelBubble = true;
	}
	if (e.preventDefault) {
		e.preventDefault();
	}
	if (window.event) {
		window.event.cancelBubble = true;
	}
	if (e.target && e.target.tagName == 'A') {
		var href = e.target.href;
	} else if (e.currentTarget && e.currentTarget.tagName == 'A') {
		var href = e.currentTarget.href;
	} else if (e.rangeParent && e.rangeParent.tagName == 'A') {
		var href = e.rangeParent.href;
	} else if (e.originalTarget && e.originalTarget.tagName == 'A') {
		var href = e.originalTarget.href;
	} else if (e.srcElement) {
		var el = e.srcElement;
		while(el && el.tagName != 'A') {
			el = el.parentNode;
		}
		var href = el.href;
	}
	if (href) {
		// Chrome includes the Location bar and window title bar in the width/height, so if it's Chrome, we have to compensate for this.
		window_height = 410;
		window_width = 430;
		var popup_window = window.open(href, "bt_c2c_popup_window", "location=0, status=1, scrollbars=0, width=" + window_width + ", height=" + window_height);
		return false;
	}
	return true;
}

/**
 * get_c2c_links
 *
 * This function gets all the click to call links
 *
 * @return Array The click to call links
 */
function get_c2c_links(c2c_class, c2c_tag) {
	var links = new Array();
	if (c2c_tag) {
		var divs = document.body.getElementsByTagName(c2c_tag);
		for (var i = 0; i < divs.length; i++) {
			if (divs[i].className == c2c_class) {
				links.push(divs[i].getElementsByTagName('a')[0]);
			}
		}
	} else {
		var as = document.body.getElementsByTagName('a');
	
		for (var i = 0; i < as.length; i++) {
			if (as[i].className == c2c_class) {
				links.push(as[i]);
			}
		}
	}
	return links;
}

/**
 * set_c2c_events
 *
 * This function sets all the click to call links to have an event
 *
 * @return Array The click to call links
 */
function set_c2c_events(c2c_class, c2c_tag) {
	var links = get_c2c_links(c2c_class, c2c_tag);
	for (var i = 0; i < links.length; i++) {
		if (links[i].addEventListener) {
			links[i].addEventListener('click', bt_c2c_popup, true);
		} else if (links[i].attachEvent) {
			links[i].attachEvent('onclick', bt_c2c_popup);
		}
	}
}

