/* -- BUSINESSLINX SCRIPTS -- */
/* ©2003 Access2.co.uk - JMM  */
/* THESE FUNCTIONS HAVE NOT BEEN TESTED IN NUTSCRAPE! */

/* This file has become increasingly complicated and could propably be dramatically reduced in size
   if some of the functions are combined. JMM 5/9/03 */

function newLocation(LocID) {
  if(LocID != "") {
    if(document.getElementById('locTitle')) document.getElementById('locTitle').innerText = " Searching..."
    if(window.location.search == "") window.location.search = "?LocationID=" + LocID;
    else if(window.location.search.indexOf("LocationID") > 0) {
      // Cut the Location ID out of the SearchString
      sIndex = window.location.search.indexOf("LocationID=") + 11;
      fIndex = window.location.search.indexOf("&", sIndex);
      
      newSearchString  = window.location.search.substring(1, sIndex);
      newSearchString += LocID;
      if(fIndex >= sIndex) newSearchString += window.location.search.substring(fIndex);
      
      newSearchString = removeListingCount(newSearchString) // Cut out the Listing Count, if it exists
      
      window.location.search = newSearchString
      }
    else window.location.search = window.location.search + "&LocationID=" + LocID;
  }
}


function newTrade(TradeID, Depth, LocationID)
{ 
  if (LocationID == 0) LocationID = undefined;
  var querystring = window.location.search;

  	if(TradeID == "1") //when the tradeid is that of 'home'
	{
		if(LocationID == undefined) window.location = "Default.aspx";
		else window.location = "Default.aspx?LocationID=" + LocationID;
		return TradeID //use return to quit the function & go to Default.aspx
	}
	if (Depth == "3"){
		if(LocationID == undefined) LocationID = ""
		window.location = "Listing.aspx?TradeID=" + TradeID + "&LocationID=" + LocationID
	}else{
		if(LocationID == undefined) LocationID = ""
		if(document.getElementById('traTitle')) document.getElementById('traTitle').innerText = " Searching..."
		if(TradeID != "") 
		{  
			if(querystring == "") window.location.search = "?TradeID=" + TradeID; //there is nothing in querystring so add a tradeId
		    
			else if(querystring.indexOf("TradeID") > 0)
			{ 
			//there is a tradeId in querystring so alter its value
		      
			//no need to check for/remove tradeletter from querystring as it won't be present if there is a tradeId 
			//(it gets dropped when you click a letter, and it is then removed when a trade is then selected - see else clause) 
		                      
			sIndex = querystring.indexOf("TradeID=") + 8; //get index of the tradeId value
			fIndex = querystring.indexOf("&", sIndex); //get index of '&' after tradeID=X - if not one after, will return 0
		      
			newSearchString  = querystring.substring(1, sIndex); //get querystring up to and including '=' in tradeID=
			newSearchString += TradeID; //add the new id
			if(fIndex >= sIndex) newSearchString += querystring.substring(fIndex); //get rest of querystring after and including the '&'
				window.location.search = newSearchString
			}
			else
			{
			//there is something in querystring, but not tradeID
		      
			querystring = removeTradeLetter(querystring); //check for/remove tradeletter from querystring
			querystring = removeListingCount(querystring); //check for/remove ListingCount from querystring
		             
			if (querystring == "")
			{
				window.location.search = "?TradeID=" + TradeID; //after removing tradeletter the querystring is empty
			} 
			else
			{ 
				window.location.search = querystring + "&TradeID=" + TradeID; //the returned querystring is not empty
			}
		}
	}
  }
}


function removeTradeLetter(querystring)
//function used by newTrade()
//removes the tradeletter from the querystring - in order to allow drill-down of trades after choosing a trade via abc bar
{
  if (querystring.indexOf("TradeLetter") > 0) 
  {
    //there is a tradeletter in querystring
    
    sIndex = querystring.indexOf("TradeLetter="); //get index of start of tradeletter=X
    fIndex = querystring.indexOf("&", sIndex); //get index of '&' after tradeletter=X - if not one after, will return 0
    newQuerystring = querystring.substring(1, sIndex); //returns querystring before tradeletter=X
    
    if(fIndex >= sIndex) //if there are vars after tradeletter=X
    {    
      if (newQuerystring == "") 
      {
        //wanna cut off '&' since there are now no vars before the rest of querystring 
        newfIndex = querystring.indexOf("&", sIndex) + 1; //lose the '&'
        newQuerystring = querystring.substring(newfIndex); //get rest of querystring after and not including the '&'.        
      }
      else 
      {
        //############## NOT TESTED!!! AT PRESENT TRADELETTER IS ALWAYS THE FIRST VARIABLE IN THE QUERYSTRING ############
        
        //wanna keep '&' since there are some vars before the now missing tradeletter=X
        newQuerystring += querystring.substring(fIndex); //combine rest of querystring after and including the '&'.         
      }
    }
  }
  else
  {
  newQuerystring = querystring; //tradeletter not in querystring so stays the same
  }  
  return newQuerystring;
}

// This function is a copy of removeTradeLetter above, but modified to remove the listingCount
function removeListingCount(querystring)
{
  if (querystring.indexOf("ListingCount") > 0) 
  {
    //there is a ListingCount in querystring
    sIndex = querystring.indexOf("ListingCount=");
    fIndex = querystring.indexOf("&", sIndex);
    newQuerystring = querystring.substring(1, sIndex);
    
    if(fIndex >= sIndex) //if there are vars after tradeletter=X
    {    
      if (newQuerystring == "") 
      {
        newfIndex = querystring.indexOf("&", sIndex) + 1;
        newQuerystring = querystring.substring(newfIndex);
      }
      else 
      {
        newQuerystring += querystring.substring(fIndex); //combine rest of querystring after and including the '&'.         
      }
    }
  }
  else
  {
  newQuerystring = querystring; //tradeletter not in querystring so stays the same
  }  
  return newQuerystring;
}


function moreListings(Count) {
  if(Count != "") {
    if(window.location.search == "") window.location.search = "?ListingCount=" + Count;
    else if(window.location.search.indexOf("ListingCount") > 0) {
      // Cut the Location ID out of the SearchString
      sIndex = window.location.search.indexOf("ListingCount=") + 13;
      fIndex = window.location.search.indexOf("&", sIndex);
      
      newSearchString  = window.location.search.substring(1, sIndex);
      newSearchString += Count;
      if(fIndex >= sIndex) newSearchString += window.location.search.substring(fIndex);
      
      window.location.search = newSearchString
      }
    else window.location.search = window.location.search + "&ListingCount=" + Count;
  }
}


var TITimeOut

function showTouristInfoPic() {
  clearTimeout(TITimeOut);
  TLI = document.getElementById("TouristLrgImage");
  TSI = document.getElementById("TouristSmlImage");
  
  if(document.all) TLI.style.top = TSI.offsetHeight - TLI.offsetHeight;
  
  if(document.all) TLI.style.visibility = "visible"; // Code for IE
  else TLI.visibility = "show"; // Code for NN
}

function hideTouristInfoPic() {
  TLI = document.getElementById("TouristLrgImage")
  TITimeOut = setTimeout("if(document.all) TLI.style.visibility='hidden'; else TLI.visibility='hide';", 1500)
}


// These functions control the ABC buttons
function ABCin(evt, StatusText) {
  if (document.all) {
	//IE
	if(event.srcElement.className == "az") 
	{
	    event.srcElement.className = "azOver";
	    if(event.srcElement.innerText == "All") window.status = "Show all businesses (for any selections you may have made)";
	    else window.status = StatusText + event.srcElement.innerText;
	    return false;
	} 
  } else {
	//MOZ
	if(evt.target.className == "az") 
	{
	    evt.target.className = "azOver";
	    if(evt.target.innerText == "All") window.status = "Show all businesses (for any selections you may have made)";
	    else window.status = StatusText + evt.target.innerText;
	    return false;
	} 
  }
}

function ABCout(evt) {
  if (document.all) {
	if(event.srcElement.className == "azOver") {
	    event.srcElement.className = "az";
	    window.status = "";
	    return false;
	}
  } else {
	if(evt.target.className == "azOver") {
	    evt.target.className = "az";
	    window.status = "";
	    return false;
	}
  }
}

// A over
function AOver(evt) {
  if (document.all) {
 	if(event.srcElement.tagName == "A")
 		event.srcElement.className = event.srcElement.className + " over";
  }else{
 	if(evt.target.tagName == "A")
 		evt.target.className = evt.target.className + " over";
  }
}

// A out
function AOut(evt) {
if (document.all) {
 	if(event.srcElement.tagName == "A")
 		event.srcElement.className = event.srcElement.className.substring(0,event.srcElement.className.length - 5);
  }else{
 	if(evt.target.tagName == "A")
 		evt.target.className = evt.target.className.substring(0,evt.target.className.length - 5);
  }
}

function Mail(url)
{window.open(url,"EMailWindow","width=530,height=400")}

function OpenEmailIframe(ListingID){
  //parent.showcontent('customercontactus', ListingID)
  parent.location.href = "customercontactus.aspx?ListingID=" + ListingID;
}

//A2 menu function below...
function selected(layer, evt){
  if(document.all){
	if (layer != 'blank') {
	    event.srcElement.className = "menu-Over";
	}else{
		event.srcElement.className = "menu";
	}//EI
  }else{
	if (layer != 'blank') {
	    evt.target.className = "menu-Over";
	}else{
		evt.target.className = "menu";
	}//EI  
  }//EI
}//EF

//360 menu function
function selected360(layer, layernum, evt){
  if(document.all){
	if (layer != 'blank') {
	    event.srcElement.className = "menu" + layer + "-Over";
			document.getElementById('TitleTd').className = "menu" + layer + "-Over";
			document.getElementById('TitleTd').style.textAlign = "left";
			document.getElementById('TitleTd').style.fontWeight = "bold";
			document.getElementById('TitleTd').style.fontSize = "12px";
			document.getElementById('TitleTd').style.paddingTop = "2";
			document.getElementById('TitleTd').style.letterSpacing = "2px";
	}else{
		event.srcElement.className = "menu";
		document.getElementById('TitleTd').className = "menu" + layernum + "-Over";
	}//EI
  }else{
	if (layer != 'blank') {
	    evt.target.className = "menu" + layer + "-Over";
	    document.getElementById('TitleTd').className = "menu" + layer + "-Over";
			document.getElementById('TitleTd').style.textAlign = "left";
			document.getElementById('TitleTd').style.fontWeight = "bold";
			document.getElementById('TitleTd').style.fontSize = "12px";
			document.getElementById('TitleTd').style.paddingTop = "2";
			document.getElementById('TitleTd').style.letterSpacing = "2px";
	}else{
		evt.target.className = "menu";
		document.getElementById('TitleTd').className = "menu" + layernum + "-Over";
	}//EI  
  }//EI
}//EF

//What and Where into and out of their textboxes
function Emptywhatwhere(evt, text){
	if(document.getElementById(text).value == "What" || document.getElementById(text).value == "Where" || document.getElementById(text).value == "What ?" || document.getElementById(text).value == "Where ?"){
		document.getElementById(text).value = ""
	}
}//EF

function whatwhere(evt, text){
	var textbox = text
	var trimmedtext = document.getElementById(textbox).value
	var textlength = trimmedtext.length
	for (i = 1; i <= textlength; i++){
		trimmedtext = trimmedtext.replace(" ", "")
	}//EL
	if(trimmedtext.length == 0){
		document.getElementById(textbox).value = textbox
	}//EI		
}//EF