//Google Map
//-----------------------------------------------------------------------------
//<![CDATA[
function loadmap(islogo,logocompanyname,g_lon,g_lat,zoom)
{
	if (GBrowserIsCompatible())
	{
		var lastmarker; // <= new 
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng(g_lon, g_lat), 15);
		if (logocompanyname != '') {
			var ballooncontent = '<div class="balloon">'
			ballooncontent += '<table border="0" cellpadding="0" cellspacing="0">'
			ballooncontent += '<tr><td height="36" width="81" align="center">'
			if (islogo==1)
			{
				ballooncontent += '<img src="/customscripts/systemfunctions/showimage.asp?img=' + logocompanyname + '&folder=listinglogos&maxw=75&maxh=33" border="0" alt="" />'
			}
			else
			{
				ballooncontent += logocompanyname;
			}
		ballooncontent += '</td></tr></table></div>';
			
		var label = new TLabel();
		label.id = '1';
		label.anchorLatLng = new GLatLng (g_lon,g_lat);
		label.anchorPoint = 'bottomLeft';
		label.content = ballooncontent;
		label.percentOpacity = 80;
		
		map.addTLabel(label);			
		}
	}
	else
	{
		alert("Sorry, our Interactive Map is not compatible with this browser");
	}
}
//]]>

//-----------------------------------------------------------------------------

//Used by pager on Profile Products Page
//-----------------------------------------------------------------------------
function ChangePager(newPage, formName, theType)
{
    var thePage = getObj('pager');
    thePage.value = newPage;
    
    var theForm = eval('document.' + formName);
    
    if (getObj('page_search_type') != null)
    {
        getObj('page_search_type').value = theType;
    }
    
    theForm.submit();
    
    return;
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// SUPORTING FUNCTIONS
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function getObj(n, d) { 
  var p,i,x;  
  if(!d) {
		d=document; 
	}
	if((p=n.indexOf("?")) > 0 && parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; 
    n=n.substring(0,p);
  }
  if(!(x=d[n]) && d.all) {
		x=d.all[n]; 
	}
	for (i=0; !x && i<d.forms.length; i++) {
		x=d.forms[i][n];
	}
  for(i=0; !x&&d.layers && i<d.layers.length; i++) {
		x=getObj(n,d.layers[i].document);
	}
  if(!x && d.getElementById) {
		x=d.getElementById(n); 
	}
	return x;
}

function Replace(argvalue, x, y)
{
    if ((x == y) || (parseInt(y.indexOf(x)) > -1))
    {
        errmessage = "replace function error: \n";
        errmessage += "Second argument and third argument could be the same ";
        errmessage += "or third argument contains second argument.\n";
        errmessage += "This will create an infinite loop as it's replaced globally.";
        alert(errmessage);
        return false;
    }

    while (argvalue.indexOf(x) != -1)
    {
        var leading = argvalue.substring(0, argvalue.indexOf(x));
        var trailing = argvalue.substring(argvalue.indexOf(x) + x.length, 
        argvalue.length);
        argvalue = leading + y + trailing;
    }

    return argvalue;
}

function emailCheck(emailStr) {
	var emailPat = /^([.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
	var matchArray = emailStr.match(emailPat);
	if (matchArray == null) {
		return false;
	}

	var IPArray = matchArray[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
	if (IPArray != null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				return false;
      }
    }
	}
	return true;
}

function InStr(Start, String1, String2, Compare) {
  if (Start < 1) {
    alert("Invalid Start argument\n\nInStr function (js2vb.js)"); return "";
  }
  if (Start > Len(String1)) return 0;
  if (Len(String2) == 0) return Start;
  if (Compare == 1) {String1 = LCase(String1); String2 = LCase(String2);}
  if (Start > 1) {
    var index = Right(String1, Len(String1) - Start + 1).indexOf(String2)
    if (index == -1) {return 0;} else {return index + Start;}
  } else {
    return String1.indexOf(String2) + 1
  }
}
//-----------------------------------------------------------------------------
function IsNumeric(thefield) 
{
	sText = getObj(thefield).value;
	var ValidChars = "0123456789.:";
	var IsNumber = true;
	var Char;
	
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}

	return IsNumber;
}

//-----------------------------------------------------------------------------
function OpenImageWindow(imgid) 
{
	openCenteredWindow('customscripts/imagePreview.asp?imgid=' + imgid, '500', '500', null, 'status=yes, resizable=yes, scrollbars=yes');
}

//-----------------------------------------------------------------------------
function openCenteredWindow(url, height, width, name, parms)
{
    var left = Math.floor( (screen.width - width) / 2);
    var top = Math.floor( (screen.height - height) / 2);
	
	var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
    if (parms)
    {
        winParms += "," + parms;
    }
    var win = window.open(url, name, winParms);
    if (parseInt(navigator.appVersion) >= 4)
    {
        win.window.focus();
    }
}

//-----------------------------------------------------------------------------
function SortByLocation()
{
	if (getObj('sort_keyword').value.length >= 2)
    {
		document.searchform.submit();
	}
    else
    {
		alert('Please enter a Postcode or Location of at least 2 characters in length');
	}
}

//-----------------------------------------------------------------------------
function ClearLocation()
{
    if (getObj('sort_keyword_hid') != null)
    {
        getObj('sort_keyword_hid').value = 'clear';
		document.searchform.submit();
	}
}

//-----------------------------------------------------------------------------
function SearchGo()
{
    var strKeyword = getObj('keyword').value;
    var strTrimmed = Trim(strKeyword);
	if (strTrimmed.length >= 3)
	{
		document.searchresults.submit();
	}
	else
	{
		alert('Please enter a Search Keyword of at least 3 characters in length');
	}
}

//-----------------------------------------------------------------------------
function Trim(theValue)
{
	var strResult;
	var objRegex = new RegExp("(^\\s+)|(\\s+$)");
	strResult = theValue.replace(objRegex, "");

	return strResult;
}

//-----------------------------------------------------------------------------
// Profile Manager specific code
//-----------------------------------------------------------------------------
function CheckRegister()
{
	var bad='';
	if (getObj('name').value == '')
	{
		bad += 'You must enter your name.\n';
	}
	if (emailCheck(getObj('email').value) == false)
	{
		bad += 'Your email address appears to be incorrect.\n';
	}
	if (getObj('secanswer').value == '')
	{
		bad += 'You must enter a security answer.\n';
	}
	if (getObj('hearus').value == '')
	{
		bad += 'Please tell us how you heard about us.\n';
	}

	if (bad != '')
	{
		msg = 'Registration details are incorrect.\n'
		msg += '---------------------------------------\n'
		alert(msg + bad);
	}
	else
	{
		document.register.submit();
	}
}

//-----------------------------------------------------------------------------
function lb_about_check(nextbackpage, bSave)
{
	var bad = '';
	
	if (bSave == true)
	{
	    var strCompany = getObj('CompanyName').value;
	    if (strCompany == '')
	    {
		    bad += 'You must enter your Company Name.\n';
	    }
	    var strBadChars = GetBadChars(strCompany);
	    if (strBadChars != '')
	    {
		    bad += 'Your company name contains these disallowed characters : \n' + strBadChars + '\n';
	    }
	    if (WebsiteCheck(strCompany) == true)
        {
            bad += 'Your company name cannot contain website information\n';
        }
        if (getObj('YearStarted').value == '')
        {
            bad += 'You must enter the year your business was started.\n';
        }
        else
        {
	        if (!IsNumeric('YearStarted'))
    	    {
        	    bad += 'The year your business started must be a valid year.\n';
        	}
		}
	    if (getObj('Tel').value == '')
	    {
		    bad += 'You must enter your Telephone Number.\n';
	    }
	    if (ContainsURL(getObj('Tel').value) == true)
        {
            bad += 'Your Telephone Number cannot contain URLs or website references.\n';
        }
        if (ContainsURL(getObj('fax').value) == true)
        {
            bad += 'Your Fax Number cannot contain URLs or website references.\n';
        }
        if (ContainsURL(getObj('mobile').value) == true)
        {
            bad += 'Your Mobile Number cannot contain URLs or website references.\n';
        }
	    if (getObj('CompanyEmail').value == '')
	    {
	        bad += 'You must enter a Contact Email address.\n';
	    }
	    if (getObj('street1').value == '')
	    {
	        bad += 'You must enter a Street Address 1\n';
	    }
	    if (WebsiteCheck(getObj('street1').value) == true)
	    {
	        bad += 'You must enter a valid Street Address 1\n';
	    }
	    if (WebsiteCheck(getObj('street2').value) == true)
	    {
	        bad += 'You must enter a valid Street Address 2\n';
	    }
	    if (WebsiteCheck(getObj('town').value) == true)
	    {
	        bad += 'You must enter a valid Town\n';
	    }
	    if (getObj('city').value == '')
	    {
		    bad += 'You must enter a City\n';
	    }
	    if (WebsiteCheck(getObj('city').value) == true)
	    {
	        bad += 'You must enter a valid City\n';
	    }
	    if ((getObj('postcode1').value == '') || (getObj('postcode2').value == ''))
	    {
		    bad += 'You must enter your Post Code.\n';
	    }
    }
    
	if (bad != '')
	{
		msg = 'Required Information is missing or is incorrect.\n'
		msg += '-------------------------------------------------------\n'
		alert(msg + bad);
	}
	else
	{
		getObj('nextbackpage').value = nextbackpage;
		document.contact.submit();
	}
}

//-----------------------------------------------------------------------------
function lb_category_check(nextbackpage, bSave) {
	var bad = '';
	if (bSave == true) 
	{
		//cat 1
		var cat1drop = getObj('CategoryID1_Cat1');
		var cat1Val = cat1drop.options[cat1drop.selectedIndex].value;
		if (cat1Val == '0') {
			bad += 'You must select a Category\n';
		}
		
		//cat 2
		var cat2drop = getObj('CategoryID1_Cat2');
		var cat2Val = cat2drop.options[cat2drop.selectedIndex].value;
		if (cat2Val == '0') {
			bad += 'You must select a Sub Category\n';
		}

		//Business Desc
		var businessDesc = getObj('businessDesc');
		if (businessDesc) {
			var radio_choice = false;
			for (counter = 0; counter < businessDesc.length; counter++) {
				if (businessDesc[counter].checked) {
					radio_choice = true; 
				}				
			}
			
			if (radio_choice == false) {
				bad += 'Please Select a Business Description\n';
			}
		}
	
	}
	
	
	
	if (bad != '')
	{
		msg = 'Required Information is missing or is incorrect.\n'
		msg += '-------------------------------------------------------\n'
		alert(msg + bad);
	}
	else
	{
		getObj('nextbackpage').value = nextbackpage;
		document.category.submit();
	}
}



//-----------------------------------------------------------------------------
function lb_expertise_check(nextbackpage, bSave)
{
	getObj('nextbackpage').value = nextbackpage;
	document.expertise.submit();
}

//-----------------------------------------------------------------------------
function lb_profile_save(nextbackpage) {
    getObj('nextbackpage').value = nextbackpage;
	getObj('saveprofile').value=1;
    document.profile.submit();
}


//-----------------------------------------------------------------------------
function lb_profile_check(nextbackpage, nMinProfileChars)
{
    var bad = '';
	var companyProfile = Trim(getObj('companyprofile').value);
	if (companyProfile == '')
	{
	    bad += 'You must enter your Company Profile\n';
    }
	
	if (companyProfile.length < nMinProfileChars)
	{
	    bad += 'Your Company Profile must be at least ' + nMinProfileChars + ' characters long\n';
    }
	if (checkInvalidChars(companyProfile))
	{
		bad += 'Your Company Profile cannot contain special characters (£, $, !, ^, ¬, #, @).\n';
	}
	if (isUppercase(companyProfile))
	{
	    bad += 'Your Company Profile (or part of it) must not be written in UPPER CASE.\n';
	}
	if (ContainsURL(companyProfile) == true)
	{
		bad += 'Your Company Profile cannot contain URLs or website references.\n';
	}
	if (check3rdPerson(companyProfile))
	{
		bad += '1';
	    //bad += 'Your Company Profile must be written in the 3rd person.\n';
        //bad += '- We, we\'re, our, us, my, I\'ve and I\'m are not allowed\n';
		//bad += '- Replace \'We\' or \'Our\' with \'The company\', \'Their\' or your company name\n';
		//bad += '- Replace \'you\' with \'the customer\' or \'the client\'\n\n';
		//bad += 'Click on the error icon below to see where the errors are.\n';
		//var error_3rdperson = getObj('error_3rdperson');
		//
    }
	if (bad !='') {	
       openCenteredWindow('customscripts/lb_profilerrors.asp', '450', '500', null, 'scrollbars=yes');
	} else {
		var newloc = 'profile-manager(' + nextbackpage + ').htm';
		alert(newloc);
	    window.location.href = newloc;
    }
}

//-----------------------------------------------------------------------------
function lb_upgrade_check(nextbackpage)
{
    getObj('nextbackpage').value = nextbackpage;
    document.upgrade.submit();
}

//-----------------------------------------------------------------------------
function uploadimage(thepath,previewImageName,HiddenFieldName)
{
   var left = Math.floor((screen.width - 400) / 2);
   var top = Math.floor((screen.height - 200) / 2);
   mywindow=window.open('upload.asp','upload','top=' + top + ',left=' + left + ',status=yes,resizable=no,width=400,height=200');
   mywindow.location.href = 'customscripts/upload.asp?thepath=' + thepath + '&previewImageName=' + previewImageName + '&HiddenFieldName=' + HiddenFieldName;
   if (mywindow.opener == null) mywindow.opener = self;
}

//-----------------------------------------------------------------------------
function lb_weblink_check()
{
	document.direct.submit();
}

//-----------------------------------------------------------------------------
function lb_recommend_check(nextbackpage,strUsername,packageType,bSave)
{
	getObj('nextbackpage').value = nextbackpage;
	document.recommend.submit();
}

//-----------------------------------------------------------------------------
function ConfirmWebLink()
{
	webaddress = getObj('website').value;
	if (webaddress != '')
	{
		var chk_webaddress = Trim(webaddress.toLowerCase());
		chk_webaddress = Replace(chk_webaddress,'http://','');
		chk_webaddress = Replace(chk_webaddress,'https://','');
		chk_webaddress = Replace(chk_webaddress,'index.html','');
		chk_webaddress = Replace(chk_webaddress,'index.htm','');
		chk_webaddress = Replace(chk_webaddress,'index.php','');
		chk_webaddress = Replace(chk_webaddress,'home.html','');
		chk_webaddress = Replace(chk_webaddress,'home.htm','');
		chk_webaddress = Replace(chk_webaddress,'home.php','');
		strLen = chk_webaddress.length;
		if ((chk_webaddress.substr(strLen-1,1)) == '/')
		{
			chk_webaddress = chk_webaddress.substr(0,strLen-1)
		}
		if (chk_webaddress.indexOf("/") > 0)
		{
			alert('Your web site Homepage address must be your domain name. \ne.g. It must end with .co.uk / .com / .net etc')
			getObj('upgrade_disabled').style.display = 'block';
		} else {
			getObj('iframe-line').style.display = 'block';
			getObj('pagescan').style.display = 'block';
			getObj('scanning').style.display = 'block';
			getObj('pagescan').src = '/customscripts/lb_pagescan.asp?url=' + webaddress;
		}
	}
	else
	{
		alert("A Web Address(URL) has not been entered.");
	}
}

//-----------------------------------------------------------------------------
function previewlisting(listingid,previewpage)
{
	var junk = openCenteredWindow("/customscripts/preview.asp?id=" + listingid + "&previewpage=" + previewpage, 600, 850, "preview", "toolbar=0,location=0,status=0,menubar=0,scrollbars=auto,resizable=1")
}

//-----------------------------------------------------------------------------
function setbuttons(thebutton)
{
	if (thebutton == 'listing')
	{
		window.parent.frames.previewbar.getObj('listbtn').src='../fx/lb_previewlist.gif';
		window.parent.frames.previewbar.getObj('pagebtn').src='../fx/lb_previewpages.gif';
	}
	else
	{
		window.parent.frames.previewbar.getObj('listbtn').src='../fx/lb_previewlist.gif';
		window.parent.frames.previewbar.getObj('pagebtn').src='../fx/lb_previewpages.gif';
	}
}

//-----------------------------------------------------------------------------
function lb_checkfinalsubmit()
{
	document.submitfinal.submit();
}

//-----------------------------------------------------------------------------
function showhelp(thediv)
{
	getObj(thediv).style.display = 'block';
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	}
    getObj(thediv).style.left = posx - 240;
	getObj(thediv).style.top = posy;
}

//-----------------------------------------------------------------------------
function hidehelp(thediv)
{
	getObj(thediv).style.display = 'none';
}

//-----------------------------------------------------------------------------
function GetBadChars(theValue)
{
	var badChars = '';
	var theChars = '/\-+?!£$%^&*()|_';
	for (var i = 1; i <= theChars. length - 1; i++)
	{
		var thisChar = (Mid(theChars, i, 1));
		var bFound = theValue.indexOf(thisChar);
		if (bFound != -1)
		{
			badChars += thisChar;
		}
	}
	
	return badChars;
}

//-----------------------------------------------------------------------------
function Mid(str, start, len) {
	if (start < 0 || len < 0) return "";
		var iEnd, iLen = String(str).length;
		if (start + len > iLen) {
			iEnd = iLen;
		} else {
			iEnd = start + len;
		}
	return String(str).substring(start,iEnd);
}

//-----------------------------------------------------------------------------
function WebsiteCheck(strWebsite)
{
	var strDotComs = /\x2E(com|uk|net|tv|cc|org|biz|info)/;
	var bFound = strWebsite.search(strDotComs);
	
	if (bFound == -1)
	{
		return false;
	}
	
	return true;
}

//-----------------------------------------------------------------------------
function ContainsURL(str)
{
	var strDotComs = /\x2E(com|uk|net|tv|cc|org|biz|info)/;
	var bFound = str.match(strDotComs);
	if (bFound != null)
	{
		return true;
	}
    
    var strInvalids = /(http:|https:|www\x2E)/;

    bFound = str.match(strInvalids);
	if (bFound != null)
	{
		return true;
	}

	return false;
}

//-----------------------------------------------------------------------------
function check3rdPerson(str) {
	var FirstPersonChk = /( we | we\'re | us | our | We | We\'re | Our | I | i |I\'ve |I\'m |We |We\'re |Our |My | you | You )/;
	var FirstPerson_FirstWord_Str = "|we|we\'re|us|our|We|We\'re|Our|I|i|I\'ve|I\'m|My|You|you|";

	//First Word
	//Get first space.
	var firstspace = str.indexOf(" ");
	var firstword = String(str).substring(0,firstspace);
	if (FirstPerson_FirstWord_Str.indexOf(firstword) > 0) {
		return true;
	}

	// Main Body
	var bFound = str.search(FirstPersonChk);
	if (bFound == -1)
	{
		return false;
	}
	return true;
}

//-----------------------------------------------------------------------------
function isUppercase(str) {
	var f_AND = str.indexOf(" AND ");
	var f_OR = str.indexOf(" OR ");
	var f_OF = str.indexOf(" OF ");
    var f_FREE = str.indexOf(" FREE ");
	
	if (f_AND > 0 || f_OR > 0 || f_OF > 0 || f_FREE > 0) {
		return true;
	}
	return false;
}

//-----------------------------------------------------------------------------
function checkInvalidChars(str)
{
    var strInvalids = /(!|£|#|\x5E)/; // 5E=^

    var bFound = str.match(strInvalids);
	if (bFound != null)
	{
		return true;
	}
	return false;
}

//-----------------------------------------------------------------------------
//Cross browser modal dialogue functions
//-----------------------------------------------------------------------------
function ModalDialogMaintainFocus()
{
    try
    {
        if (ModalDialogWindow.closed)
        {
            window.clearInterval(ModalDialogInterval);
            eval(ModalDialog.eventhandler);       
            return;
        }
        ModalDialogWindow.focus(); 
    }
    catch (everything) { }
}

//-----------------------------------------------------------------------------
function ModalDialogRemoveWatch()
{
   ModalDialog.value = '';
   ModalDialog.eventhandler = '';
}

//-----------------------------------------------------------------------------
function ModalDialogShow(strTitle, URL, args)
{
    ModalDialogRemoveWatch();
    ModalDialogWindow = window.open(URL, strTitle, args);
    ModalDialogWindow.focus();
    ModalDialogInterval = window.setInterval("ModalDialogMaintainFocus()", 5);
}

//-----------------------------------------------------------------------------
function OpenCatWindow(thecat)
{
	openCenteredWindow('/customscripts/lb_selectcategory.asp?thecat=' + thecat, '350', '450', null, 'status=yes, resizable=yes, scrollbars=yes');
}

//-----------------------------------------------------------------------------
function trackclick(clickType, id)
{
    // Affillate Click Tracker
    if (document.images)
    { 
        (new Image()).src = "/customscripts/systemfunctions/trackclick.asp?ctype=" + clickType + "&id=" + id;
    }
    
    return true;
}

//-----------------------------------------------------------------------------
function check_profilecontact()
{
	var bad='';
	if (getObj('e_name').value == '') {
		bad += 'Please enter your name.\n';
	}
	if (emailCheck(getObj('e_email').value) == false) {
		bad += 'Please enter a valid email address.\n';
	}
	if (getObj('e_enquiry').value == '') {
		bad += 'Please enter an enquiry.\n';
	}
	if (bad != '') {
		msg = 'Required Information is missing or is incorrect.\n'
		msg += '-------------------------------------------------------\n'
		alert(msg + bad);
	} else {
		document.profilecontact.submit();
	}
}

//-----------------------------------------------------------------------------
function DisplayDivForTime(thediv, showlen)
{
	getObj(thediv).style.display = 'block';
	setTimeout('getObj(\'' + thediv + '\').style.display = \'none\';', showlen);
}

//-----------------------------------------------------------------------------
function DisplayExpertise(thediv)
{
    // hide all divs who have a class of subcat1
    var arrDivs = document.all.tags('div');
    for (i = 0; i < arrDivs.length; i++)
    {
        if (arrDivs[i].className == 'subcat1')
        {
            arrDivs[i].style.display = 'none';
        }
    }
    
    // Then display the div we want
	getObj(thediv).style.display = 'block';
}

//-----------------------------------------------------------------------------
// Ajax functions
//-----------------------------------------------------------------------------
function RunScript(strScript, strDivName, strFieldName)
{
    var xmlHttpReq = false;
    var self = this;
    
    if (window.XMLHttpRequest)
    {   // Mozilla / Safari
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {   // IE
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strScript, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function()
    {
        if (self.xmlHttpReq.readyState == 4)
        {
            UpdatePage(self.xmlHttpReq.responseText, strDivName);
        }
    }
    self.xmlHttpReq.send(this.GetQueryString(strFieldName));
}

//-----------------------------------------------------------------------------
function UpdatePage(strInnerHTML, strDivName)
{
    var result = getObj(strDivName);
    if (result != null)
    {
        result.innerHTML = strInnerHTML;
        if (strInnerHTML == '')
        {
            result.style.display = 'none';
        }
        else
        {
            result.style.display = 'block';
        }
    }
}

//-----------------------------------------------------------------------------
function GetQueryString(strFieldName)
{
    var strQuery = '';
    var field = getObj(strFieldName);
    if (field != null)
    {
        var strValue = field.value;
        strValue = Replace(strValue, '+', 'PLUS_SIGN');
        strQuery = 'q=' + escape(strValue) + '';  // NOTE: no '?' before query string
    }
    return strQuery;
}

//-----------------------------------------------------------------------------
function HideDiv(strDivName)
{
    var result = getObj(strDivName);
    if (result != null)
    {
        result.style.display = 'none';
    }
}

//-----------------------------------------------------------------------------
function HideExpertise(strDivName)
{
    var result = getObj(strDivName);
    if (result != null)
    {
        result.style.display = 'none';
        var show_hide = getObj('show_hide_' + strDivName);
        var show_hide_icon = getObj('show_hide_icon_' + strDivName);
        show_hide.innerHTML = '<a href="javascript:ShowExpertise(\'' + strDivName + '\');">Show</a>';
        show_hide_icon.innerHTML = '<a href="javascript:ShowExpertise(\'' + strDivName + '\');"><img src="/fx/plus.gif" alt="Show" border="0" /></a>';
    }
}

//-----------------------------------------------------------------------------
function ShowExpertise(strDivName)
{
    // First of all, hide all divs whos class is expertise_type_items
    var arrDivs = business.all.tags('div');
    for (i = 0; i < arrDivs.length; i++)
    {
        if (arrDivs[i].className == 'expertise_type_items')
        {
            arrDivs[i].style.display = 'none';
        }
    }
    // Then change the innerHTML of the show_hide and show_hide_icon classes to hidden
    var arrTDs = business.all.tags('td');
    for (i = 0; i < arrTDs.length; i++)
    {
        switch (arrTDs[i].className)
        {
            case 'show_hide':
                var expertiseType = Replace(arrTDs[i].id, 'show_hide_', '');
                arrTDs[i].innerHTML = '<a href="javascript:ShowExpertise(\'' + expertiseType + '\');">Show</a>';
                break;
            case 'show_hide_icon':
                var expertiseType = Replace(arrTDs[i].id, 'show_hide_icon_', '');
                arrTDs[i].innerHTML = '<a href="javascript:ShowExpertise(\'' + expertiseType + '\');"><img src="/fx/plus.gif" alt="Show" border="0" /></a>';
                break;
        }
    }
    
    // Show the div that has been clicked on
    var result = getObj(strDivName);
    if (result != null)
    {
        result.style.display = 'block';
        var show_hide = getObj('show_hide_' + strDivName);
        var show_hide_icon = getObj('show_hide_icon_' + strDivName);
        show_hide.innerHTML = '<a href="javascript:HideExpertise(\'' + strDivName + '\');">Hide</a>';
        show_hide_icon.innerHTML = '<a href="javascript:HideExpertise(\'' + strDivName + '\');"><img src="/fx/minus.gif" alt="Hide" border="0" /></a>';
    }
}

//-----------------------------------------------------------------------------
function SetCat1()
{
    var cat1 = getObj('cat1').value;
    getObj('categoryid1').value = cat1;
}

//-----------------------------------------------------------------------------
function ShowRightAd()
{
    var winW = 0;

    if (parseInt(navigator.appVersion) > 3)
    {
        if (navigator.appName == "Netscape")
        {
            winW = window.innerWidth;
        }
        if (navigator.appName.indexOf("Microsoft") != -1)
        {
            winW = document.body.offsetWidth;
        }
    }

    var rightDiv = getObj('ad_right');
    if (winW > 1024)
    {
        rightDiv.style.display = 'block';
    }
    else
    {
        rightDiv.style.display = 'none';
    }
}

//-----------------------------------------------------------------------------
function ValidateFeedback()
{
    var bad = '';
	
	var bAtLeastOne = false;
	if (getObj('customer_name').value != '')
	{
	    bAtLeastOne = true;
	}
	if (getObj('customer_company').value != '')
	{
	    bAtLeastOne = true;
	}
	if (bAtLeastOne == false)
	{
	    bad += '- Please enter either your Name or your Company Name.\n';
	}

    var radio_value = false;
    var value = getObj('value');
	for (counter = 0; counter < value.length; counter++)
	{
		if (value[counter].checked)
		{
			radio_value = true; 
		}				
	}
    var radio_prof = false;
    var prof = getObj('prof');
	for (counter = 0; counter < prof.length; counter++)
	{
		if (prof[counter].checked)
		{
			radio_prof = true; 
		}				
	}
	var radio_quality = false;
    var quality = getObj('quality');
	for (counter = 0; counter < quality.length; counter++)
	{
		if (quality[counter].checked)
		{
			radio_quality = true; 
		}				
	}
	
	if (radio_value == false)
	{
		bad += '- Please select a rating for Value For Money.\n';
	}
	if (radio_prof == false)
	{
		bad += '- Please select a rating for Professionalism.\n';
	}
    if (radio_quality == false)
	{
		bad += '- Please select a rating for Quality.\n';
	}
	if (!getObj('confirmpersonal').checked) {
		bad += '- Please confirm that your review is based on your personal experience .\n';
	}
	
	if (bad != '')
	{
		msg = 'Required Information is missing or is incorrect.\n'
		msg += '-------------------------------------------------------\n'
		alert(msg + bad);
	}
	else
	{
	    getObj('action').value = 'save';
		document.feedback.submit();
	}
}

//-----------------------------------------------------------------------------
function ValidateFeedbackRequest()
{
    var bad = '';
    if (getObj('company_name').value == '')
    {
        bad += '- You must complete your business details before this option becomes available.\n';
    }
	var strEmail = Trim(getObj('client_email').value.toLowerCase());
    if (strEmail == '')
    {
	    bad += '- You must enter your client\'s Email Address.\n';
    }
    else if (emailCheck(strEmail) == false)
	{
		bad += '- Your client\'s email address appears to be incorrect.\n';
	}
	if (strEmail == getObj('username').value.toLowerCase() || strEmail == getObj('company_email').value.toLowerCase())
	{
	    bad += '- The email address provided cannot be your own.\nAbuse of the system can lead to your listing being removed from the directory.\n';
	}
    
    var arrTDs = document.getElementsByTagName('td');
    for (i = 0; i < arrTDs.length; i++)
    {
        if (arrTDs[i].className == 'client_email')
        {
            if (strEmail == arrTDs[i].innerHTML.toLowerCase())
            {
                bad += '- You have already requested a review from ' + strEmail + '.\n';
            }
        }
    }

	if (bad != '')
	{
		msg = 'Required Information is missing or is incorrect.\n'
		msg += '-------------------------------------------------------\n'
		alert(msg + bad);
	}
	else
	{
	    getObj('action').value = 'request-ratings';
		document.feedback.submit();
	}
}

//-----------------------------------------------------------------------------
function ValidateRecommendRequest()
{
    var bad = '';
	var strEmail = getObj('client_email').value;
    if (strEmail == '')
    {
	    bad += '- You must enter an Email Address.\n';
    }
    else if (emailCheck(strEmail) == false)
	{
		bad += '- The email address entered appears to be incorrect.\n';
	}
	
	if (bad != '')
	{
		msg = 'Required Information is missing or is incorrect.\n'
		msg += '-------------------------------------------------------\n'
		alert(msg + bad);
	}
	else
	{
		// Send email to recommend
		var listingId = getObj('listingid').value;
		var url = '/customscripts/recommend_email.asp?id=' + listingId + '&email=' + strEmail;
		RunScript(url, '', '');
		DisplayDivForTime('msgbox', 3000);
	}
}

//-----------------------------------------------------------------------------
function SendFeedbackRequest()
{
    getObj('action').value = 'sendtheemail';
    document.feedback_preview.submit();
}

//-----------------------------------------------------------------------------
function ReSendFeedbackRequest(id)
{
    var bConfirm = confirm('This will email your client.\nClick OK to send.');
	if (bConfirm == true)
	{
		window.location.href = '\/profile-manager(request-ratings)_' + id + '.htm';
	}
}

//-----------------------------------------------------------------------------
function HideFeedback(bHide, customerReviewId)
{
    this.RunScript('/customscripts/feedback_hide.asp?hide=' + bHide + '&id=' + customerReviewId, 'feedback_btm', '');
}

