	var xmlhttp;
	var merchantsXml;

	var citiesXmlHttpRequest;
	var subCategoriesXmlHttpRequest;
	var merchantsXmlHttpRequest;

	var currentPage;
	
	function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
      	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
      	var arrReturnElements = new Array();
      	var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)", "i") : null;
      	var oCurrent;
      	var oAttribute;
      	for(var i=0; i<arrElements.length; i++){
      		oCurrent = arrElements[i];
      		oAttribute = oCurrent.getAttribute(strAttributeName);
      		if(typeof oAttribute == "string" && oAttribute.length > 0){
      			if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
      				arrReturnElements.push(oCurrent);
      			}
      		}
      	}
      	return arrReturnElements;
     }
    
    function xmlRequestx(url, callbackFunction) {
        xmlhttp = null;
        var ie = true;
		if (window.XMLHttpRequest)
  		{// code for all new browsers
  			xmlhttp =new XMLHttpRequest();
  			ie = false;
  		}
		else if (window.ActiveXObject)
  		{// code for IE5 and IE6
  			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  		}
		if (xmlhttp !=null)
  		{
  			xmlhttp.onreadystatechange = callbackFunction;
  			if (ie == true) {
  			    xmlhttp.open("GET",url,false);
  			}
  			else {
  			    xmlhttp.open("GET",url,true);
  			}
  			xmlhttp.send(null);
  		}
		else
  		{
  			alert("Your browser does not support XMLHTTP.");
  		}
    }

    function xmlRequest(url, callbackFunction) {
        var req = null;
        var ie = true;
		if (window.XMLHttpRequest)
  		{// code for all new browsers
  			req =new XMLHttpRequest();
  			ie = false;
  		}
		else if (window.ActiveXObject)
  		{// code for IE5 and IE6
  			req = new ActiveXObject("Microsoft.XMLHTTP");
  		}
		if (req !=null)
  		{
  			req.onreadystatechange = callbackFunction;
  			if (ie == true) {
  			    req.open("GET",url,false);
  			}
  			else {
  			    req.open("GET",url,true);
  			}
  			req.send(null);
  		}
		else
  		{
  			alert("Your browser does not support XMLHTTP.");
  		}
  		return req;
    }
    
    function makeCitiesXmlRequest(url, callbackFunction) {
        citiesXmlHttpRequest = null;
        var ie = true;
		if (window.XMLHttpRequest)
  		{// code for all new browsers
  			citiesXmlHttpRequest =new XMLHttpRequest();
  			ie = false;
  		}
		else if (window.ActiveXObject)
  		{// code for IE5 and IE6
  			citiesXmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  		}
		if (citiesXmlHttpRequest !=null)
  		{
  			citiesXmlHttpRequest.onreadystatechange = callbackFunction;
  			if (ie == true) {
  			    citiesXmlHttpRequest.open("GET",url,false);
  			}
  			else {
  			    citiesXmlHttpRequest.open("GET",url,true);
  			}
  			citiesXmlHttpRequest.send(null);
  		}
		else
  		{
  			alert("Your browser does not support XMLHTTP.");
  		}
    }
    
    function makeSubCategoriesXmlRequest(url, callbackFunction) {
        subCategoriesXmlHttpRequest = null;
        var ie = true;
		if (window.XMLHttpRequest)
  		{// code for all new browsers
  			subCategoriesXmlHttpRequest =new XMLHttpRequest();
  			ie = false;
  		}
		else if (window.ActiveXObject)
  		{// code for IE5 and IE6
  			subCategoriesXmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  		}
		if (subCategoriesXmlHttpRequest !=null)
  		{
  			subCategoriesXmlHttpRequest.onreadystatechange = callbackFunction;
  			if (ie == true) {
  			    subCategoriesXmlHttpRequest.open("GET",url,false);
  			}
  			else {
  			    subCategoriesXmlHttpRequest.open("GET",url,true);
  			}
  			subCategoriesXmlHttpRequest.send(null);
  		}
		else
  		{
  			alert("Your browser does not support XMLHTTP.");
  		}
    }
    
    function makeMerchantsXmlRequest(url, callbackFunction) {
        merchantsXmlHttpRequest = null;
        var ie = true;
		if (window.XMLHttpRequest)
  		{// code for all new browsers
  			merchantsXmlHttpRequest =new XMLHttpRequest();
  			ie = false;
  		}
		else if (window.ActiveXObject)
  		{// code for IE5 and IE6
  			merchantsXmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  		}
		if (merchantsXmlHttpRequest !=null)
  		{
  			merchantsXmlHttpRequest.onreadystatechange = callbackFunction;
  			if (ie == true) {
  			    merchantsXmlHttpRequest.open("GET",url,false);
  			}
  			else {
  			    merchantsXmlHttpRequest.open("GET",url,true);
  			}
  			merchantsXmlHttpRequest.send(null);
  		}
		else
  		{
  			alert("Your browser does not support XMLHTTP.");
  		}
    }
    
    function onCitiesLoadedx() {
        if (xmlhttp.readyState == 4)
  		{// 4 = "loaded"
  			if (xmlhttp.status==200)
    		{	// 200 = OK
  		          responseXml = xmlhttp.responseText;
  			      xmlResponseDocument=new ActiveXObject("Microsoft.XMLDOM");
                  xmlResponseDocument.async="false";
                  xmlResponseDocument.loadXML(responseXml);
    			loadCities(xmlResponseDocument.documentElement);
    		}
  			else
    		{
    			alert("Problem retrieving XML data status " + xmlhttp.status);
    		}
    	}
    }
    
    function onSubCategoriesLoadedx() {
        if (xmlhttp.readyState == 4)
  		{// 4 = "loaded"
  			if (xmlhttp.status==200)
    		{	// 200 = OK
  		          responseXml = xmlhttp.responseText;
  			      xmlResponseDocument=new ActiveXObject("Microsoft.XMLDOM");
                  xmlResponseDocument.async="false";
                  xmlResponseDocument.loadXML(responseXml);
    			loadSubCategories(xmlResponseDocument.documentElement);
    		}
  			else
    		{
    			alert("Problem retrieving XML data status " + xmlhttp.status);
    		}
    	}
    }
    
    function onMerchantsLoadedx() {
        if (xmlhttp.readyState == 4)
  		{// 4 = "loaded"
  			if (xmlhttp.status==200)
    		{	// 200 = OK
  		          responseXml = xmlhttp.responseText;
  			      xmlResponseDocument=new ActiveXObject("Microsoft.XMLDOM");
                  xmlResponseDocument.async="false";
                  xmlResponseDocument.loadXML(responseXml);	
                  
                 
    			  loadMerchants(xmlResponseDocument.documentElement);
    		}
  			else
    		{
    			alert("Problem retrieving XML data status " + xmlhttp.status);
    		}
    	}
    }
   
    function onMerchantsLoaded()
	{
		if (merchantsXmlHttpRequest.readyState==4)
  		{// 4 = "loaded"
  			if (merchantsXmlHttpRequest.status==200)
    		{	// 200 = OK
    		    var responseXml;
    		    var xmlResponseDocument;; 
    		    if (window.XMLHttpRequest)
  		        {// code for all new browsers
  		            if (window.DOMParser) {
  		                responseXml = merchantsXmlHttpRequest.responseText;
  			            parser=new DOMParser();
                        xmlResponseDocument=parser.parseFromString(responseXml,"text/xml");
                    }//IE 7
                    else {
                        responseXml = merchantsXmlHttpRequest.responseText;
                        xmlResponseDocument=new ActiveXObject("Microsoft.XMLDOM");
                        xmlResponseDocument.async="false";
                        xmlResponseDocument.loadXML(responseXml);
                    }
  		        }
		        else if (window.ActiveXObject)
  		        {// code for IE5 and IE6
  		            responseXml = merchantsXmlHttpRequest.responseText;
  			        xmlResponseDocument=new ActiveXObject("Microsoft.XMLDOM");
                    xmlResponseDocument.async="false";
                    xmlResponseDocument.loadXML(responseXml);
  		        }
  		        merchantsXml = xmlResponseDocument.documentElement;
  		        loadMerchants(xmlResponseDocument.documentElement);
    		}
  			else
    		{
    			alert("Problem retrieving XML data status " + merchantsXmlHttpRequest.status);
    		}
    	}
 	}
 	
 	function onSubCategoriesLoaded()
	{
		if (subCategoriesXmlHttpRequest.readyState==4)
  		{// 4 = "loaded"
  			if (subCategoriesXmlHttpRequest.status==200)
    		{	// 200 = OK
    		    var responseXml;
    		    var xmlResponseDocument;; 
    		    if (window.XMLHttpRequest)
  		        {// code for all new browsers
  		            if (window.DOMParser) {
  		                responseXml = subCategoriesXmlHttpRequest.responseText;
  			            parser=new DOMParser();
                        xmlResponseDocument=parser.parseFromString(responseXml,"text/xml");
                    }//IE 7
                    else {
                        responseXml = subCategoriesXmlHttpRequest.responseText;
                        xmlResponseDocument=new ActiveXObject("Microsoft.XMLDOM");
                        xmlResponseDocument.async="false";
                        xmlResponseDocument.loadXML(responseXml);
                    }
  		        }
		        else if (window.ActiveXObject)
  		        {// code for IE5 and IE6
  		            responseXml = subCategoriesXmlHttpRequest.responseText;
  			        xmlResponseDocument=new ActiveXObject("Microsoft.XMLDOM");
                    xmlResponseDocument.async="false";
                    xmlResponseDocument.loadXML(responseXml);
  		        }
  		        loadSubCategories(xmlResponseDocument.documentElement);
    		}
  			else
    		{
    			alert("Problem retrieving XML data status " + subCategoriesXmlHttpRequest.status);
    		}
    	}
 	}

 	function onCitiesLoaded()
	{
		if (citiesXmlHttpRequest.readyState==4)
  		{// 4 = "loaded"
  			if (citiesXmlHttpRequest.status==200)
    		{	// 200 = OK
    		    var responseXml;
    		    var xmlResponseDocument;; 
    		    if (window.XMLHttpRequest)
  		        {// code for all new browsers
  		            if (window.DOMParser) {
  		                responseXml = citiesXmlHttpRequest.responseText;
  			            parser=new DOMParser();
                        xmlResponseDocument=parser.parseFromString(responseXml,"text/xml");
                    }//IE 7
                    else {
                        responseXml = citiesXmlHttpRequest.responseText;
                        xmlResponseDocument=new ActiveXObject("Microsoft.XMLDOM");
                        xmlResponseDocument.async="false";
                        xmlResponseDocument.loadXML(responseXml);
                    }
  		        }
		        else if (window.ActiveXObject)
  		        {// code for IE5 and IE6
  		            responseXml = citiesXmlHttpRequest.responseText;
  			        xmlResponseDocument=new ActiveXObject("Microsoft.XMLDOM");
                    xmlResponseDocument.async="false";
                    xmlResponseDocument.loadXML(responseXml);
  		        }
  		        loadCities(xmlResponseDocument.documentElement);
    		}
  			else
    		{
    			alert("Problem retrieving XML data status " + citiesXmlHttpRequest.status);
    		}
    	}
 	}

    function loadCitiesXmlRequest() {
        var uri = '../ajax_common/mosaic.jsp?op=cities&city_id=' + cityId;
        makeCitiesXmlRequest(uri, onCitiesLoaded);
    }
 
    function loadSubcategoriesXmlRequest(catUri) {
        makeSubCategoriesXmlRequest(catUri, onSubCategoriesLoaded);
    }

    function loadMerchantsXmlRequest() {
		displayWaitingAndClearData();
		if (window.ActiveXObject) {
			setTimeout("loadMerchantsRequest()", 1000);
        }
        else {
           loadMerchantsRequest();
        }
	}

	function loadMerchantsRequest() {
        var uri = '../ajax_common/mosaic.jsp?op=';
        if (activeCategory == 'new' || activeCategory == 'featured'){
	        uri += activeCategory;
	    }
	    else {
	        if (activeSubCategory != null){
	            uri += 'merchantsByCategory&category_id=' + activeSubCategory;
	        }
	        else {
	            uri += 'merchantsByCategory&category_id=' + activeCategory;
	        }
	    }
		uri += '&merchant_name=' + document.getElementById('merchant_name_fld').value;
	    if (activeMetroCity != null) {
	        uri += '&city_id=' + activeMetroCity + '&lang=e';
	    }
	    else {
	        uri += '&city_id=' + cityId + '&lang=e';
	    }
	    uri += '&page=' + currentPage;
		if ( postal_code != null && radius != null )
		{
			uri += '&postal_code=' + postal_code.value + '&radius=' + radius.value;
		}
	    clearMerchantDetailsOrLocations();
        makeMerchantsXmlRequest(uri, onMerchantsLoaded);
    }

	function loadXMLDoc(url)
	{
		xmlhttp=null;
		var ie = true;
		if (window.XMLHttpRequest)
  		{// code for all new browsers
  			xmlhttp=new XMLHttpRequest();
  			ie = false;
  		}
		else if (window.ActiveXObject)
  		{// code for IE5 and IE6
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
		if (xmlhttp!=null)
  		{
  			xmlhttp.onreadystatechange=onStateChange;
  			if (ie == true) {
  			    xmlhttp.open("GET",url,false);
  			}
  			else {
  			    xmlhttp.open("GET",url,true);
  			}
  			xmlhttp.send(null);
  		}
		else
  		{
  			alert("Your browser does not support XMLHTTP.");
  		}
	}

	function onError(e) {
        alert("Error " + e.target.status + " occurred while receiving the document.");
    }

	function onStateChange()
	{
		if (xmlhttp.readyState==4)
  		{// 4 = "loaded" 		 			        
  			if (xmlhttp.status=='200')
    		{	// 200 = OK
    			// ...our code here...
                //alert('status ' + xmlhttp.status);
    		    var responseXml;
    		    var xmlResponseDocument;
    		    //alert('check' + window.XMLHttpRequest); 
    		    if (window.XMLHttpRequest)
  		        {// code for all new browsers
  		            //alert ('Firefox/IE7');
  		            if (window.DOMParser) {
  		                //alert('xmlhttp.readyState = ' + xmlhttp.readyState + 'xmlhttp.status = ' + xmlhttp.status );
  		                responseXml = xmlhttp.responseText;
  			            parser=new DOMParser();
                        xmlResponseDocument=parser.parseFromString(responseXml,"text/xml");
                        //alert(xmlResponseDocument);
                        
                    }//IE 7
                    else {
                        responseXml = xmlhttp.responseText;
                        //alert('IE7 responseXML' + responseXml);
                        xmlResponseDocument=new ActiveXObject("Microsoft.XMLDOM");
                        xmlResponseDocument.async="false";
                        xmlResponseDocument.loadXML(responseXml);
                    }
  		        }
		        else if (window.ActiveXObject)
  		        {// code for IE5 and IE6
  		            responseXml = xmlhttp.responseText;
  		            //alert('IE5/6 responseXML' + responseXml);
  			        xmlResponseDocument=new ActiveXObject("Microsoft.XMLDOM");
                    xmlResponseDocument.async="false";
                    xmlResponseDocument.loadXML(responseXml);
  		        }
  		        merchantsXml = xmlResponseDocument.documentElement;
    			loadMerchants(xmlResponseDocument.documentElement);
    		}
  			else
    		{
    			alert("Problem retrieving XML data status " + xmlhttp.status);
    		}
    	}
 	}
  
    function merchantClicked(evt){
	    var id;
	    var logoImg;
	    var ie_var = "srcElement";
	    var moz_var = "target";
	    var prop_var = "id";
		// "target" for Mozilla, Netscape, Firefox et al. ; "srcElement" for IE
	    evt[moz_var] ? id = evt[moz_var][prop_var] : id = evt[ie_var][prop_var];
	    evt[moz_var] ? logoImg = evt[moz_var] : logoImg = evt[ie_var];
		document.getElementById('all_merchants_drop_down').selectedIndex = 0;
		for ( i = 0; i < document.getElementById('all_merchants_drop_down').options.length; i++ )
		{
			if ( document.getElementById('all_merchants_drop_down').options[i].value == id )
			{
				document.getElementById('all_merchants_drop_down').selectedIndex = i;
				break;
			}
		}
		displayMerchant( id, logoImg);
	}

	function displayMerchant( id, logoImg)
	{
		document.getElementById('blueborder').bgColor= '#B0D2E8';
	    var merchant = getElementsByAttribute(merchantsXml, 'merchant', 'id', id)[0];
  	    if(merchant.getElementsByTagName('locations')[0].childNodes.length > 1)
		{
	        document.getElementById('locationsButton').style.visibility='visible';
	    }
	    else
		{
	        document.getElementById('locationsButton').style.visibility='hidden';
	    }
  	    if (merchant != null)
		{
			if ( logoImg != null )
			{
  	   			logoImg.style.border = "1px solid red"; 
			}
		    if ( currentMerchantLogoImg != null )
			{
  	           	currentMerchantLogoImg.style.border = "1px solid white";
			}
			currentMerchant = merchant;
			currentMerchantLogoImg = logoImg;
  	    	document.getElementById('detailsButton').style.visibility='visible';
  	    	if (window.ActiveXObject)
			{
   		        detailsButton.fireEvent("onclick");
   		    }
   		    else
			{
   		        var evObj = document.createEvent('MouseEvents');
                evObj.initEvent( 'click', true, true );
                detailsButton.dispatchEvent(evObj);
  			}
		}
	}

  	function loadCities(citiesXmlObject) {
  	    loadSelectControl(citiesXmlObject, 'cities_drop_down', 'city', false);
	}

  	function loadSubCategories(subcategoriesXmlObject) {
  	    loadSelectControl(subcategoriesXmlObject, 'subcategories', 'SubCategory', false);
  	}
  	
  	function loadSelectControl(xmlObject, controlId, tagName, empty) {
  	    var csElement = document.getElementById(controlId);
  	    for (var q=csElement.options.length; q>=0; q--) {
  	        csElement.options[q] = null;
  	    }
  	    var number_of_elements = xmlObject.childNodes.length;
		if ( empty )
		{
  	        csElement.options[0] = document.createElement("option");
		}
  	    for (i=0; i<number_of_elements; i++) {
  			if (xmlObject.childNodes[i].tagName == tagName) {
  			    option = document.createElement("option") ;
  			    option.setAttribute("value", xmlObject.childNodes[i].getAttribute("id"));
		    var padding = 20 * xmlObject.childNodes[i].getAttribute("level");
			padding+="px";
			option.style.paddingLeft= padding;
			var level = xmlObject.childNodes[i].getAttribute("level");
			var spaces="";
			for (s=0; s<level; s++) {
			   spaces += "      ";
			} 
  			var nameElement = xmlObject.childNodes[i].getElementsByTagName('name');
                var txt = document.createTextNode(spaces + nameElement[0].firstChild.nodeValue);
                option.appendChild(txt);
                csElement.appendChild(option);
  			}
  	    }
  	}

  	function loadCitiesx(citiesXmlObject) {
  	    var csElement = document.getElementById('cities_drop_down');
  	    for (var q=csElement.options.length; q>0; q--) {
  	        csElement.options[q] = null;
  	    }
  	    var number_of_cities = citiesXmlObject.childNodes.length;
  	    for (i=0; i<number_of_cities; i++) {
  			if (citiesXmlObject.childNodes[i].tagName == 'city') {
  			    option = document.createElement("option") ;
  			    option.setAttribute("value", citiesXmlObject.childNodes[i].getAttribute("id"));
                var nameElement = citiesXmlObject.childNodes[i].getElementsByTagName('name');
                var txt = document.createTextNode(nameElement[0].firstChild.nodeValue);
                option.appendChild(txt);
                csElement.appendChild(option);
  			}
  	    }
  	}
  	
  	function displayWaitingAndClearData() {
		 document.getElementById('blueborder').bgColor= '#FFFFFF';
  		var ldiv1 = document.getElementById('merchant_logos_1');
  		var ldiv2 = document.getElementById('merchant_logos_2');
  		//clear old images
  		while(ldiv1.childNodes[0]) {
  			ldiv1.removeChild(ldiv1.childNodes[0]);
  		}
  		while(ldiv2.childNodes[0]) {
  			ldiv2.removeChild(ldiv2.childNodes[0]);
  		}
  	    ldiv1.appendChild(loadingImg);
  	}
  	
  	function loadMerchants(xmlObj)
  	{
  		var ldiv1 = document.getElementById('merchant_logos_1');
  		var ldiv2 = document.getElementById('merchant_logos_2');
  		//clear old images
  		while(ldiv1.childNodes[0]) {
  			ldiv1.removeChild(ldiv1.childNodes[0]);
  		}
  		while(ldiv2.childNodes[0]) {
  			ldiv2.removeChild(ldiv2.childNodes[0]);
  		}
  		//load new images
  		var number_of_merchants = xmlObj.firstChild.childNodes.length;
		if (number_of_merchants == 0) {
  			ldiv1.appendChild(noMerchantsFoundImg);
		}
  		var number_of_pages = xmlObj.firstChild.getAttribute("of");
  		
  		if (number_of_pages > 1) {
  		    if(currentPage != number_of_pages){
  		        document.getElementById('moreMerchants').style.visibility='visible';
  		    }
  		    else {
  		        document.getElementById('moreMerchants').style.visibility='hidden';
  		    }
  		    if(currentPage != 1){
  		        document.getElementById('previousMerchants').style.visibility='visible';
  		    }
  		    else {
  		        document.getElementById('previousMerchants').style.visibility='hidden';
  		    }
  		}
  		else {
  		    document.getElementById('moreMerchants').style.visibility='hidden';
  		    document.getElementById('previousMerchants').style.visibility='hidden';
  		    currentPage = 1;
  		}
  		
  		var counter = 0;
  		var selectedImage;
  		for (i=0; i<number_of_merchants; i++) {
  			if (xmlObj.firstChild.childNodes[i].tagName == 'merchant') {
  				var newimage = document.createElement('img');
  				var logo = xmlObj.firstChild.childNodes[i].getElementsByTagName('logo_url');
  				newimage.setAttribute('src', logo[0].firstChild.nodeValue);
  				var nameElement = xmlObj.firstChild.childNodes[i].getElementsByTagName('name');
                newimage.setAttribute('alt',nameElement[0].firstChild.nodeValue);
                newimage.setAttribute('title',nameElement[0].firstChild.nodeValue);// for Firefox
  				newimage.removeAttribute('width');
  				newimage.removeAttribute('height');
  				
  				var id = xmlObj.firstChild.childNodes[i].getAttribute("id");
  				newimage.setAttribute('id', id);
  				if(window.addEventListener){ 
  				    newimage.addEventListener("click", merchantClicked, false);
  				
  				}
  				else {
  				    newimage.attachEvent("onclick", merchantClicked);
  				}
  				
  				if (counter%2) {
  				    ldiv2.appendChild(newimage);
  				    ldiv2.appendChild(createImgElement("10", "", "images/08spacer-white.gif", "5", "0"));

  				}
  				else {
  				    ldiv1.appendChild(newimage);
  				    ldiv1.appendChild(createImgElement("10", "", "images/08spacer-white.gif", "5", "0"));
  				}
  				if (counter == 0) {
  			        selectedImage = newimage;
  			    }
  				counter++;
  			}
  		}
		loadSelectControl(xmlObj.childNodes[1], 'all_merchants_drop_down', 'merchant', true);
		if ( xmlObj.childNodes[1].childNodes.length == 0 ) 
		{
			document.getElementById('all_merchants_drop_down').style.visibility='hidden';
		}
		else
		{
			document.getElementById('all_merchants_drop_down').style.visibility='visible';
			var _cat;
			if ( activeCategory == 'new' )
			{
				_cat = "New";
			}
			else if ( activeCategory == 'featured' )
			{
				_cat = "Featured";
			}
			else
			{
				_cat = "" + document.getElementById('subcategories').options[
						 document.getElementById('subcategories').selectedIndex].text;
			}
			document.getElementById('all_merchants_drop_down').options[0].text =
				document.getElementById('cities_drop_down').options[
					document.getElementById('cities_drop_down').selectedIndex].text + "/" + _cat;
		}
  	}
  	
  	function loadXmlMerchants(name) {
  		var xmldoc=document.implementation.createDocument("","",null);
		xmldoc.async="false";

  		xmldoc.load(name);
  		alert(name + ' loaded');
  		merchantsXml = xmldoc.documentElement;
  		
  		loadMerchants(xmldoc.documentElement);
  	}
  	
  	function loadCities_local(name) {
  		var xdoc=document.implementation.createDocument("","",null);
		xdoc.async="false";

  		xdoc.load(name);
  		alert(name + ' loaded');	
  		loadCities(xdoc.documentElement);
  	}
  	
var activeCategoryImage;
var detailsHtml;
var cityId; 

var activeCategory;
var activeSubCategory;
var activeMetroCity;

var currentMerchant;
var currentMerchantLogoImg;

var detailsButton;

var loadingImg;
var noMerchantsFoundImg;

var postal_code;
var radius;

window.onload = function() { 
   		loadingImg = document.createElement('img'); 		
  	    loadingImg.setAttribute('src', 'images/preloader.gif');	
  	    loadingImg.setAttribute('width', '400');
  		loadingImg.setAttribute('height', '150'); 
  		
  		noMerchantsFoundImg = document.createElement('img'); 		
  	    noMerchantsFoundImg.setAttribute('src', 'images/no-merchant.gif');	
  	    noMerchantsFoundImg.setAttribute('width', '400');
  		noMerchantsFoundImg.setAttribute('height', '150'); 
        detailsButton = document.getElementById('detailsButton');	   
   		activeCategoryImage = document.getElementById('featured');
   		activeCategory = 'featured';
   		tdCityId = document.getElementById('cityId');
   		cityId = tdCityId.firstChild.id;
   		currentPage = 1;
   		document.getElementById('locationsButton').style.visibility='hidden';
   		loadCitiesXmlRequest();
   		activeMetroCity = null;
   		if (window.ActiveXObject){
   		    activeCategoryImage.fireEvent("onclick");
   		}
   		else {
   		    var evObj = document.createEvent('MouseEvents');
            evObj.initEvent( 'click', true, true );
            activeCategoryImage.dispatchEvent(evObj);
   		}
}

function showS(t){
	document.getElementById("saburb").innerHTML = "Ajax";
	alert(document.getElementById("city_image").width);
}

function addElement(imageName) {
  var ldiv = document.getElementById('merchant_logos');
  var newimg = document.createElement('img');
  newimg.setAttribute('src','1053_IMAGE_42.jpg');
  ldiv.appendChild(newimg);
}

function showAtt() {
	var ldiv = document.getElementById('merchant_logos');
	alert(ldiv.title);
}

function clearList() {
  var d = document.getElementById('myDiv');
  var olddiv = document.getElementById(divNum);
  d.removeChild(olddiv);
}

function categoryChanged_local(sender) {
	activeCategoryImage = sender;
	loadXmlMerchants('mosaic_v1.xml');
	return false;
}

function categoryChanged(sender) {
    currentPage =1;
	aIndexOfGif = activeCategoryImage.src.lastIndexOf('_selected');
	var aImgName = activeCategoryImage.src;
	activeCategoryImage.src = aImgName.substring(0,aIndexOfGif) + '.gif';
	var indexOfGif = sender.src.lastIndexOf('.');
	var imgName = sender.src;
	sender.src = imgName.substring(0,indexOfGif) + '_selected.gif';
	activeCategoryImage = sender;
	var getCategories = false;
	var catUri;
	activeCategory = sender.id;
	activeSubCategory = null;
	if (sender.id != 'new' && sender.id != 'featured'){
	    catUri = '../ajax_common/mosaic.jsp?op=subcategories&category_id=' + sender.id;
	    getCategories = true;
	}
	catUri += '&city_id=' + cityId + '&lang=e' + '&page=1';
    loadMerchantsXmlRequest();
	if (getCategories) {
	    loadSubcategoriesXmlRequest(catUri);
	    document.getElementById('subcategories').style.visibility='visible';
	}
	else {
	    document.getElementById('subcategories').style.visibility='hidden';
	}
	return true;
}

function merchantSelectionChanged(sender) {
	if ( document.getElementById('all_merchants_drop_down').selectedIndex == 0 )
	{
		return;
	}
	displayMerchant( sender, null);
}

function searchByPostalCode(sender, postal_code_obj, radius_obj) {
	if (postal_code_obj != null && postal_code_obj.value != null && postal_code_obj.value != '' &&
		radius_obj != null && radius_obj.value != null)
	{
	    postal_code = postal_code_obj;
		radius = radius_obj;
		activeMetroCity = null;
		document.getElementById('cities_drop_down').selectedIndex = 0;
	}
	else
	{
		postal_code = null;
		radius = null;
	}
   	loadMerchantsXmlRequest();
	return true;
}

function merchantDetailsClicked() {
	alert(detailsHtml.getElementById('details_logo'));
}

function getNextMerchants() {
    //alert('currentPage is ' + currentPage + ' xmlPage is '+ merchantsXml.getAttribute("of") + 'number of pages is ' + merchantsXml.getAttribute("of"));
    currentPage++;
    loadMerchantsXmlRequest();
}

function getPreviousMerchants() {
    currentPage--;
    loadMerchantsXmlRequest();
}

function metroCityChanged(value) {
	document.getElementById('postal_code_fld').value = '';
	postal_code = null;
	radius = null;
    currentPage =1;
    if (value != '...') {
        activeMetroCity = value;
        loadMerchantsXmlRequest();
    }
    else {
        activeMetroCity = null;
    }
}

function subCategoryChanged(value) {
    currentPage =1;
    if (value != '...') {
        activeSubCategory = value;
        loadMerchantsXmlRequest();
    }
    else {
        activeSubCategory = null;
    }
}

///THIS for the locations & details tab

function createImgElement(height, alt, src, width, border) {
    imgElement = document.createElement("img");
    imgElement.setAttribute('height', height);
    imgElement.setAttribute('width' ,width);
    imgElement.setAttribute('alt' ,alt);
    imgElement.setAttribute('border', border);
    imgElement.setAttribute('src' , src);
    
    return imgElement;
}

function createTDElement(vAlign, align, width, bgColor, colSpan, child) {
    tdElement = document.createElement("td");
    tdElement.setAttribute('vAlign', vAlign);
    tdElement.setAttribute('align' ,align);
    tdElement.setAttribute('width' ,width);
    tdElement.setAttribute('bgColor', bgColor);
    tdElement.setAttribute('colSpan' , colSpan);
    if (child != null) {
        tdElement.appendChild(child);
    }
    return tdElement;
}

function createTRElement(child) {
    trElement = document.createElement("tr");
    trElement.appendChild(child);
    return trElement;
}

function clearMerchantDetailsOrLocations() {
    var tbody = document.getElementById("merchantDetailsOrLocationsTbody");
    while(tbody.childNodes[0]) {
  			tbody.removeChild(tbody.childNodes[0]);
  		}
  	document.getElementById('locationsButton').style.visibility='hidden';
  	document.getElementById('detailsButton').style.visibility='hidden';
    
}

function createDetailsTab(merchant) {
	var table = document.getElementById("merchantDetailsOrLocationsTable");
    var tbody = document.getElementById("merchantDetailsOrLocationsTbody");
    var newtbody = document.createElement("tbody");
    newtbody.id = "merchantDetailsOrLocationsTbody";
    
    var docFragment = document.createDocumentFragment();
    
img1a = createImgElement("10", "RewardsPlus", "images/08spacer-white.gif", "5", "0");
td1a = createTDElement("top", "left", "5" , "#ffffff" ,"8", img1a);
tr1Element = createTRElement(td1a);

img2a = createImgElement("5", "RewardsPlus", "images/08spacer-white.gif", "5", "0");
td2aElement = createTDElement("top", "left", "5" , "#ffffff" ,"1", img2a);

 logo = merchant.getElementsByTagName('logo_url');
    logoImg = document.createElement('img');
    logoImg.setAttribute('src', logo[0].firstChild.nodeValue);
    td2bElement = createTDElement("top", "left", "106" , "#ffffff" ,"1", logoImg);
    
//TABLE
img2c1 = createImgElement("55", "RewardsPlus", "images/08pgs-merch-tagline2.jpg", "233", "0");
td2c1Element = createTDElement("top", "left", "233" , "#ffffff" ,"1", img2c1);
tr2c1Element = createTRElement(td2c1Element);

im2c2 = createImgElement("10", "RewardsPlus", "images/08spacer-white.gif", "5", "0");
td2c2Element = createTDElement("top", "left", "233" , "#ffffff" ,"1", im2c2);
tr2c2Element = createTRElement(td2c2Element);

var desc = merchant.getElementsByTagName('descriptions')[0].childNodes[1];
div2c3 = document.createElement("div");
//div2c3.setAttribute("class" , "vscroller");
div2c3.innerHTML = desc.firstChild.nodeValue;

td2c3Element = createTDElement("top", "left", "233" , "#ffffff" ,"1", div2c3);
tr2c3Element = createTRElement(td2c3Element);

var txt_node_2_4 = document.createTextNode('Spend limits may apply - please check with merchant for details.');
td2c4Element = createTDElement("top", "left", "233" , "#ffffff" ,"1", txt_node_2_4);
tr2c4Element = createTRElement(td2c4Element);

tbody2cElement = document.createElement("tbody");
tbody2cElement.appendChild(tr2c1Element);
tbody2cElement.appendChild(tr2c2Element);
tbody2cElement.appendChild(tr2c3Element);
tbody2cElement.appendChild(tr2c4Element);
table2cElement = document.createElement("table");
                table2cElement.cellSpacing="0";
                table2cElement.cellPadding="0";
                table2cElement.width="233";
                table2cElement.bgColor="#ffffff";
                table2cElement.border="0"
                
                table2cElement.appendChild(tbody2cElement)
td2cElement = createTDElement("top", "left", "233" , "#ffffff" ,"1", table2cElement);

im2d = createImgElement("5", "RewardsPlus", "images/08spacer-white.gif", "5", "0");                
td2dElement = createTDElement("top", "left", "5" , "#ffffff" ,"1", im2d);
               
//TABLE

var mapquestFromLink = null;
var mapquestToLink = null;
var mapquestMapLink = null;
var cinfoHtml = '';
var contactInfo = merchant.getElementsByTagName('locations')[0].childNodes[0];
if ( contactInfo != null )
{
  mapquestFromLink = 'http://www.mapquest.com/directions/main.adp?' +
  '1c=' + contactInfo.getElementsByTagName('city')[0].firstChild.nodeValue +
  '&1s=' + contactInfo.getElementsByTagName('state')[0].firstChild.nodeValue +
  '&1z=' + contactInfo.getElementsByTagName('zipcode')[0].firstChild.nodeValue +
  '&1y=CA&cid=lfddlink' +
  '&1a=' + contactInfo.getElementsByTagName('address')[0].firstChild.nodeValue;
  
  mapquestToLink = 'http://www.mapquest.com/directions/main.adp?' +
  '2c=' + contactInfo.getElementsByTagName('city')[0].firstChild.nodeValue +
  '&2s=' + contactInfo.getElementsByTagName('state')[0].firstChild.nodeValue +
  '&2z=' + contactInfo.getElementsByTagName('zipcode')[0].firstChild.nodeValue +
  '&2y=CA&cid=lfddlink' +
  '&2a=' + contactInfo.getElementsByTagName('address')[0].firstChild.nodeValue;
  
  mapquestMapLink = 'http://www.mapquest.com/maps/map.adp?formtype=address' +
  '&city=' + contactInfo.getElementsByTagName('city')[0].firstChild.nodeValue +
  '&state=' + contactInfo.getElementsByTagName('state')[0].firstChild.nodeValue +
  '&zipcode=' + contactInfo.getElementsByTagName('zipcode')[0].firstChild.nodeValue +
  '&address=' + contactInfo.getElementsByTagName('address')[0].firstChild.nodeValue;

   cinfoHtml = '<B>ADDRESS:</B><BR>' + contactInfo.getElementsByTagName('address')[0].firstChild.nodeValue + '<BR>' 
	+ contactInfo.getElementsByTagName('city')[0].firstChild.nodeValue +', ' 
	+ contactInfo.getElementsByTagName('state')[0].firstChild.nodeValue +' ' 
	+ contactInfo.getElementsByTagName('zipcode')[0].firstChild.nodeValue +'<BR>(T)' 
	+ contactInfo.getElementsByTagName('phone')[0].firstChild.nodeValue;
}
	
var companyUrl = merchant.getElementsByTagName('company-url')[0].firstChild.nodeValue
if (companyUrl != '' && companyUrl != 'Unavailable') {
	if (companyUrl.indexOf('http') == -1) {
		cinfoHtml += '<BR><A class="merchantinfo" href="http://' + companyUrl;
	} else {
		cinfoHtml += '<BR><A class="merchantinfo" href="' + companyUrl;
	}
	cinfoHtml += '" target="_blank">'+ companyUrl +'</A>';
}

if ( mapquestMapLink != null )
{
cinfoHtml += '<BR>Map:&nbsp;<A class="merchantinfo" href="' + mapquestMapLink
	+ '" target="_blank"><img src="../../images/map_ic.gif" border="0"></A>';
}

if ( mapquestToLink != null && mapquestFromLink != null )
{
cinfoHtml += '<BR>Directions:&nbsp;<A class="merchantinfo" href="' + mapquestToLink
	+ '" target="_blank">To</A>&nbsp;&nbsp;<A class ="merchantinfo" href="' 
	+ mapquestFromLink 
	+'" target="_blank">From</A>';
}

if ( contactInfo != null )
{
   if ( merchant != null && merchant.getElementsByTagName('locations')[0].childNodes.length > 1 )
   {
	   cinfoHtml += '<BR><BR><B>Click on the Locations Button to see (' +
					    (merchant.getElementsByTagName('locations')[0].childNodes.length - 1)  + ') additional location(s)</B>';
   } 
}

div2eb = document.createElement("div");
div2eb.setAttribute("class" , "merchantinfo");

div2eb.innerHTML =  cinfoHtml;

td2ebElement = createTDElement("top", "left", "160" , "#ffffff" ,"1", div2eb);
tr2eaElement = createTRElement(td2ebElement);

im2eb = createImgElement("10", "RewardsPlus", "images/08spacer-white.gif", "5", "0");
td2ebElement = createTDElement("top", "left", "160" , "#ffffff" ,"1", im2eb);
tr2ebElement = createTRElement(td2ebElement);

hours = merchant.getElementsByTagName('hours');
hdiv = document.createElement("div");
hdiv.innerHTML =  '<B>HOURS:</B><BR/>' + hours[0].firstChild.nodeValue;
td2ecElement= createTDElement("top", "left", "160" , "#ffffff" ,"1",hdiv);
tr2ecElement = createTRElement(td2ecElement);


tbody2eElement = document.createElement("tbody");
                  tbody2eElement.appendChild(tr2eaElement);
                  tbody2eElement.appendChild(tr2ebElement);
                  tbody2eElement.appendChild(tr2ecElement);
  
  
table2eElement = document.createElement("table");
                table2eElement.vAlign="top";
                table2eElement.width="160";
                table2eElement.bgColor="#ffffff";
                table2eElement.appendChild(tbody2eElement);
  
  im2ea = createImgElement("5", "RewardsPlus", "images/08spacer-white.gif", "5", "0");              
  td2eaElement = createTDElement("top", "left", "5" , "#ffffff" ,"1", im2ea);  
  
  ////
  photo = merchant.getElementsByTagName('photo_url');
    photoImg = createImgElement("128", "RewardsPlus", photo[0].firstChild.nodeValue, "168", "0");
    photoImg.removeAttribute('height');
    photoImg.removeAttribute('width');
  td2ebElement =   createTDElement("top", "left", "5" , "#ffffff" ,"1", photoImg);
  
  
  im2ec = createImgElement("5", "RewardsPlus", "images/08spacer-white.gif", "5", "0");              
  td2ecElement = createTDElement("top", "left", "5" , "#ffffff" ,"1", im2ec); 
  
  td2eElement = createTDElement("top", "left", "160" , "#ffffff" ,"1", table2eElement); 
              td2eElement.appendChild(td2eaElement);
              td2eElement.appendChild(td2ebElement);
             td2eElement.appendChild(td2ecElement);
             
             tr2Element = document.createElement("tr");
              tr2Element.appendChild(td2aElement);
              tr2Element.appendChild(td2bElement);
              tr2Element.appendChild(td2cElement);
              tr2Element.appendChild(td2dElement);
              tr2Element.appendChild(td2eElement);
              
  im3a = createImgElement("10", "RewardsPlus", "images/08spacer-white.gif", "5", "0");
  td3aElement = createTDElement("top", "left", "10" , "#ffffff" ,"5", im3a); 
  
  tr3Element = createTRElement(td3aElement);
      
           docFragment.appendChild(tr1Element);
           docFragment.appendChild(tr2Element);
           docFragment.appendChild(tr3Element);
    newtbody.appendChild(docFragment);
    table.replaceChild(newtbody, tbody);
   } 
 
function writeTextToFile(text) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("C:\\Test.txt", true);
s.WriteLine(text);
s.Close();
}

function writeTextToTextArea(text) {
	ta = document.getElementById('ta');
	ta.value = text;
}

function createEmptyLocationTableElement() { 
    tbody = document.createElement("tbody");
    table = document.createElement("table");
    table.cellSpacing="2";
    table.cellPadding="2";
    table.width="160";
    table.bgColor="#dceef8";
    table.border="0";               
    table.appendChild(tbody);
    
    return table;
}

function createLocationTableElement(contactInfo) { 
  var mapquestFromLink = 'http://www.mapquest.com/directions/main.adp?' +
  '1c=' + contactInfo.getElementsByTagName('city')[0].firstChild.nodeValue +
  '&1s=' + contactInfo.getElementsByTagName('state')[0].firstChild.nodeValue +
  '&1z=' + contactInfo.getElementsByTagName('zipcode')[0].firstChild.nodeValue +
  '&1y=CA&cid=lfddlink' +
  '&1a=' + contactInfo.getElementsByTagName('address')[0].firstChild.nodeValue;
  
  var mapquestToLink = 'http://www.mapquest.com/directions/main.adp?' +
  '2c=' + contactInfo.getElementsByTagName('city')[0].firstChild.nodeValue +
  '&2s=' + contactInfo.getElementsByTagName('state')[0].firstChild.nodeValue +
  '&2z=' + contactInfo.getElementsByTagName('zipcode')[0].firstChild.nodeValue +
  '&2y=CA&cid=lfddlink' +
  '&2a=' + contactInfo.getElementsByTagName('address')[0].firstChild.nodeValue;
  
  var mapquestMapLink = 'http://www.mapquest.com/maps/map.adp?formtype=address' +
  '&city=' + contactInfo.getElementsByTagName('city')[0].firstChild.nodeValue +
  '&state=' + contactInfo.getElementsByTagName('state')[0].firstChild.nodeValue +
  '&zipcode=' + contactInfo.getElementsByTagName('zipcode')[0].firstChild.nodeValue +
  '&address=' + contactInfo.getElementsByTagName('address')[0].firstChild.nodeValue;

  var cinfoHtml = contactInfo.getElementsByTagName('address')[0].firstChild.nodeValue + '<BR>' 
	+ contactInfo.getElementsByTagName('city')[0].firstChild.nodeValue +', ' 
	+ contactInfo.getElementsByTagName('state')[0].firstChild.nodeValue +' ' 
	+ contactInfo.getElementsByTagName('zipcode')[0].firstChild.nodeValue +'<BR>Phone: ' 
	+  contactInfo.getElementsByTagName('phone')[0].firstChild.nodeValue +'<BR>Map: ' 
	+ '<A class="merchantinfo" href="' + mapquestMapLink + '" target="_blank"><img src="../../images/map_ic.gif" border="0"></A>' + '<BR>Directions: '
	+  '<A class="merchantinfo" href="' + mapquestToLink + '" target="_blank">To</A>&nbsp;&nbsp;<A class ="merchantinfo" href="' + mapquestFromLink +'" target="_blank">From</A>';
    
   
    var cdiv = document.createElement("div");
    cdiv.setAttribute("class" , "merchantinfo");
    cdiv.innerHTML =  cinfoHtml;
   
    td = createTDElement("top", "left", "" , "#dceef8" ,"", cdiv);
    td.setAttribute("class" , "merchantinfo");
    tr = createTRElement(td);

    tbody = document.createElement("tbody");
    tbody.appendChild(tr);
                  
    table = document.createElement("table");
    table.cellSpacing="2";
    table.cellPadding="2";
    table.width="160";
    table.bgColor="#dceef8";
    table.border="0";               
    table.appendChild(tbody);
    
    return table;
}

function createLocationTab(merchant) {
    var table = document.getElementById("merchantDetailsOrLocationsTable");
    var tbody = document.getElementById("merchantDetailsOrLocationsTbody");
    var newtbody = document.createElement("tbody");
    newtbody.id = "merchantDetailsOrLocationsTbody";
    
    var docFragment = document.createDocumentFragment();
    
    img1a = createImgElement("10", "RewardsPlus", "images/08spacer-white.gif", "5", "0");
    td1a = createTDElement("top", "left", "5" , "#ffffff" ,"9", img1a);
    tr1Element = createTRElement(td1a);

    img2a = createImgElement("5", "RewardsPlus", "images/08spacer-white.gif", "5", "0");
    td2aElement = createTDElement("top", "left", "5" , "#ffffff" ,"1", img2a);

    var logo = merchant.getElementsByTagName('logo_url');
    logoImg = createImgElement("96", "RewardsPlus", logo[0].firstChild.nodeValue, "100", "0");
    td2bElement = createTDElement("top", "left", "106" , "#ffffff" ,"1", logoImg);

    img2c = createImgElement("5", "RewardsPlus", "images/08spacer-white.gif", "5", "0");
    td2cElement = createTDElement("top", "left", "5" , "#ffffff" ,"1", img2c);
    
    var locations = merchant.getElementsByTagName('locations')[0].childNodes;
    numberOfLocations = merchant.getElementsByTagName('locations')[0].childNodes.length;
    var numberOfRows;
    var mod = numberOfLocations % 3;
    if (mod == 0) {
	numberOfRows = numberOfLocations/3 
    }
    else {
	 numberOfRows = 1 + (numberOfLocations - mod)/3
    }

    var trElements = new Array(numberOfRows);

    for(var k=0; k<numberOfRows; k++) {
    	trElements[k] = document.createElement('tr');
    	trElements[k].appendChild(td2aElement);
    	trElements[k].appendChild(td2bElement);
    	trElements[k].appendChild(td2cElement);

	var ll = 3;
	if ((numberOfLocations - 3*k) < 3)
		ll = numberOfLocations - 3* k;

	for(var p =0; p < ll; p++) {
        	lTable = createLocationTableElement(locations[3*k + p]);
        td = createTDElement("top", "left", "200" , "#dceef8" ,"1", lTable);

        trElements[k].appendChild(td);
        }
        if (ll !=3) {
		for (var r=ll; r<3; r++){
        	lTable = createEmptyLocationTableElement();
        td = createTDElement("top", "left", "200" , "#dceef8" ,"1", lTable);
        		trElements[k].appendChild(td);
		}
        }
    }

    if (numberOfLocations > 3)
        numberOfLocations = 3;
    tr2Element = document.createElement('tr');
    tr2Element.appendChild(td2aElement);
    tr2Element.appendChild(td2bElement);
    tr2Element.appendChild(td2cElement);
    
    for(var i=0; i<numberOfLocations; i++){
        lTable = createLocationTableElement(locations[i]);
        td = createTDElement("top", "left", "200" , "#dceef8" ,"1", lTable);
        tr2Element.appendChild(td);
    }
    
    
    im3a = createImgElement("5", "RewardsPlus", "images/08spacer-white.gif", "5", "0");
    td3aElement = createTDElement("top", "left", "10" , "#ffffff" ,"", im3a); 
  
    tr3Element = createTRElement(td3aElement);
      
    docFragment.appendChild(tr1Element);
	divxxx = document.createElement("div");
	divxxx.setAttribute("class" , "lscroller");
    for(var t=0; t<numberOfRows; t++) {
        divxxx.appendChild(trElements[t]);
    }
    docFragment.appendChild(divxxx);
    docFragment.appendChild(tr3Element);
    newtbody.appendChild(docFragment);
    table.replaceChild(newtbody, tbody);  
}

function merchantDetailsClicked() {
    var locationsButton = document.getElementById('locationsButton');
    var detailsButton = document.getElementById('detailsButton');
    
    if (detailsButton.src.lastIndexOf('_selected') == -1) {
        var dIndex = detailsButton.src.lastIndexOf('.');
        var dImgName = detailsButton.src;
        detailsButton.src = dImgName.substring(0,dIndex) + '_selected.gif';
    }
    if (locationsButton.src.lastIndexOf('_selected') != -1) {
        var lIndex = locationsButton.src.lastIndexOf('_selected');
        var lImgName = locationsButton.src;
        locationsButton.src = lImgName.substring(0,lIndex) + '.gif';
    }
    createDetailsTab(currentMerchant);
}

function merchantLocationsClicked() {
    var locationsButton = document.getElementById('locationsButton');
    var detailsButton = document.getElementById('detailsButton');
    
    if (locationsButton.src.lastIndexOf('_selected') == -1) {
        var lIndex = locationsButton.src.lastIndexOf('.');
        var lImgName = locationsButton.src;
        locationsButton.src = lImgName.substring(0,lIndex) + '_selected.gif';
    }
    if (detailsButton.src.lastIndexOf('_selected') != -1) {
        var dIndex = detailsButton.src.lastIndexOf('_selected');
        var dImgName = detailsButton.src;
        detailsButton.src = dImgName.substring(0,dIndex) + '.gif';
    }
    createLocationTab(currentMerchant);
}

function gup( name ) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  	var regexS = "[\\?&]"+name+"=([^&#]*)";
  	var regex = new RegExp( regexS );
  	var results = regex.exec( window.location.href );
  	if( results == null )
    	return "";
  	else
    	return results[1];
}

function frameOpen(url, fr, par)
{
	newW = window.open(url, fr, par);
	newW.focus();
}

