// JavaScript Document

function categoryChoose(location, mc)
{
	var catID = document.getElementById('categoryChoose').options[document.getElementById('categoryChoose').selectedIndex].value;
	document.location = location + "?mc=" + mc + "&subCat=" + catID;
}
function confirmLogin(redir)
{
	if(confirm("You must log in to add businesses to your address book\nYou will be navigated back to the current page upon login."))
	{
		window.location = "login.php?redir=" + redir;
	}
}
function printPaidListing(name,add1,add2,add3,add4,town,county,postcode,tel,fax,email,web)
{
	var toRead="<html><head><style type=\"text/css\"><!-- body { font-family:Trebuchet MS, Arial; } --></style><\/head><body onload='print()'>";
	
	toRead+="<img src=\"http:\/\/www.findtraders.com\/images\/header-MasterU.png\" \/><br \/>";
	
	toRead+="<h3>" + name + "<\/h3><br \/><br \/>";
	
	toRead+="<strong>Address:<\/strong><br \/><br \/>";
	if (add1 != "") {
		toRead+="<em>" + add1 + "<\/em><br \/>";
	}
	if (add2 != "") {
		toRead+="<em>" + add2 + "<\/em><br \/>";
	}
	if (add3 != "") {
		toRead+="<em>" + add3 + "<\/em><br \/>";
	}
	if (add4 != "") {
		toRead+="<em>" + add4 + "<\/em><br \/>";
	}
	if (town != "") {
		toRead+="<em>" + town + "<\/em><br \/>";
	}
	if (county != "") {
		toRead+="<em>" + county + "<\/em><br \/>";
	}
	if (postcode != "") {
		toRead+="<em>" + postcode + "<\/em><br \/><br \/>";
	}
	
	toRead+="<strong>Contact Details:<\/strong><br \/><br \/>";
	
	if (tel != "") {
		toRead+="<u>Tel:<\/u> <em>" + tel + "<\/em><br \/>";
	}
	if (fax != "") {
		toRead+="<u>Fax:<\/u> <em>" + fax + "<\/em><br \/><br \/>";
	}
	if (email != "") {
		toRead+="<u>Email:<\/u> <em>" + email + "<\/em><br \/>";
	}
	if (web != "") {
		toRead+="<u>Website:<\/u> <em>" + web + "<\/em><br \/><br \/>";
	}
	toRead+="<\/body><\/html>";
	
	
	var popup = window.open('','popup','toolbar=no,menubar=no,width=800,height=600');
	popup.document.open();	
	popup.document.write(toRead);
	popup.document.close();
}
function printFreeListing(name,add1,add2,add3,add4,town,county,postcode,tel)
{
	var toRead="<html><head><style type=\"text/css\"><!-- body { font-family:Trebuchet MS, Arial; } --></style><\/head><body onload='print()'>";
	
	toRead+="<img src=\"http:\/\/www.findtraders.com\/images\/header-MasterU.png\" \/><br \/>";
	
	toRead+="<strong>" + name + "<\/strong><br \/><br \/>";
	
	toRead+="<strong>Address:<\/strong><br \/><br \/>";
	if (add1 != "") {
		toRead+="<em>" + add1 + "<\/em><br \/>";
	}
	if (add2 != "") {
		toRead+="<em>" + add2 + "<\/em><br \/>";
	}
	if (add3 != "") {
		toRead+="<em>" + add3 + "<\/em><br \/>";
	}
	if (add4 != "") {
		toRead+="<em>" + add4 + "<\/em><br \/>";
	}
	if (town != "") {
		toRead+="<em>" + town + "<\/em><br \/>";
	}
	if (county != "") {
		toRead+="<em>" + county + "<\/em><br \/>";
	}
	if (postcode != "") {
		toRead+="<em>" + postcode + "<\/em><br \/><br \/>";
	}
	
	toRead+="<strong>Contact Details:<\/strong><br \/><br \/>";
	
	if (tel != "") {
		toRead+="<u>Tel:<\/u> <em>" + tel + "<\/em><br \/>";
	}
	toRead+="<\/body><\/html>";
	
	
	var popup = window.open('','popup','toolbar=no,menubar=no,width=800,height=600');
	popup.document.open();	
	popup.document.write(toRead);
	popup.document.close();
}
function searchPending()
{
	document.getElementById('searchPending').className = "hidden";
}

function toggleBenefits(thisElement, way)
{
	if (way == "fwd")
	{
		if (thisElement == "paidListingInList")
		{
			var nextElement = "paidListingMoreDetails";
		}
		else if (thisElement == "paidListingMoreDetails")
		{
			var nextElement = "paidListingEditMoreDetails";
		}
		
		//check if last in list - if so; can't go back
		if (nextElement == "paidListingEditMoreDetails")
		{
			document.getElementById('infoToggle').innerHTML = "<a href=\"#less\" onclick=\"toggleBenefits('" + nextElement + "','bck')\">Previous</a>";
		}
		//if not last (can't be first), display previous and next link
		else if(nextElement == "paidListingMoreDetails")
		{
			document.getElementById('infoToggle').innerHTML = "<a href=\"#less\" onclick=\"toggleBenefits('" + nextElement + "','bck')\">Previous</a> <a href=\"#next\" onclick=\"toggleBenefits('" + nextElement + "','fwd')\">Next</a>";
		}
		
		document.getElementById(thisElement).className = "hidden";
		document.getElementById(nextElement).className = "visible";
	}
	else //must be 'bck'
	{
		if (thisElement == "paidListingEditMoreDetails")
		{
			var nextElement = "paidListingMoreDetails";
		}
		else if (thisElement == "paidListingMoreDetails")
		{
			var nextElement = "paidListingInList";
		}
		
		//check if first in list - if so; can't go back
		if (nextElement == "paidListingInList")
		{
			document.getElementById('infoToggle').innerHTML = "<a href=\"#next\" onclick=\"toggleBenefits('" + nextElement + "','fwd')\">Next</a>";
		}
		//if not first (can't be last), display previous and next link
		else if (nextElement == "paidListingMoreDetails")
		{
			document.getElementById('infoToggle').innerHTML = "<a href=\"#less\" onclick=\"toggleBenefits('" + nextElement + "','bck')\">Previous</a> <a href=\"#next\" onclick=\"toggleBenefits('" + nextElement + "','fwd')\">Next</a>";
		}
		
		document.getElementById(thisElement).className = "hidden";
		document.getElementById(nextElement).className = "visible";
	}
}




function showPreview(type) {
	document.getElementById('supremePreview').className = "hidden";
	document.getElementById('advancedPreview').className = "hidden";
	document.getElementById('borderPreview').className = "hidden";
	document.getElementById('freePreview').className = "hidden";
	
	document.getElementById(type + 'Preview').className = "visible";
}

function addImagesShow()
{
	document.getElementById("transBG").className = "visible";
}

function getHTTPObject()
{
	var xmlhttp;
	/*@cc_on 
	@if (@_jscript_version >= 5) 
		try { 
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
		catch (e) { 
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (E) { xmlhttp = false; }
		} 
	@else xmlhttp = false; 
	@end @*/  
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try {
			xmlhttp = new XMLHttpRequest();
			xmlhttp.overrideMimeType("text/xml");
		} catch (e) {xmlhttp = false;}
	}
	return xmlhttp;
}

var http3 = getHTTPObject();

// Upload images
	var imgUrl = "includes/addimgck.php";
	
	function uploadImagesMoreD(idNo)
	{
		imgUrl = "includes/addimgck.php";
					
		if (!isWorking && http3)
		{
			if (idNo!="")
			{
				imgUrl = imgUrl + "?id=" + idNo;
			}
			http3.open("GET", imgUrl, true);
			http3.onreadystatechange = handleHttpResponseuploadImagesMoreD;
			isWorking = true;
			http3.send(null);
		}
	}
	
	function handleHttpResponseuploadImagesMoreD()
	{
		if (http3.readyState == 4)
		{
			var xmlDocument = http3.responseXML;
			
			/*var result_img = xmlDocument.getElementsByTagName('result_img').item(0).firstChild.data;
	
			if(result_img == "True")
			{
			}
			else
			{
				alert("Error 101: Upload failed.");
			}*/
		}
		isWorking = false;
	
	}

function highlightImage(imgName)
{
	if (document.getElementById(imgName).className == "noBorderUploadPhotos")
	{
		document.getElementById(imgName).className = "borderUploadPhotos";
	}
	else
	{
		document.getElementById(imgName).className = "noBorderUploadPhotos";
	}
}
function highlightImageHover(id) {
	if (document.getElementById(id).className == "noBorderShow") {
		document.getElementById(id).className = "borderShow";
		document.getElementById("scrollingImages").scrollAmount = 0;
	}
	else {
		document.getElementById(id).className = "noBorderShow";
		document.getElementById("scrollingImages").scrollAmount = 4;
	}
}
function showImage(id,an,wd,ht) {
	document.getElementById("showLargeImage").innerHTML = "<img src=\"Company_Images/Account-" + an + "/" + id + "\" style=\"width:" + wd + "px;height:" + ht + "px;\" />";
}
function showLoader() {
	document.getElementById("loading").className = "visible";
}
function changeDir(dir) {
	document.getElementById("scrollingImages").direction = dir;
}
function toggleElem(elem, display, win) {
	if (win == "parent") {
		window.parent.document.getElementById(elem).className = display;
	}
	else {
		document.getElementById(elem).className = display;
	}
}
function submitIE(event,dir)
{
	if(event.keyCode==13)
	{
		document.getElementById('form1234').action = dir;
		return false;
	}
}
