﻿var loc = (document.domain.match(/.+\.bigbangmedia\.net$/i))?"b":("bigbangmedia".match(/((staging|devcpd\d|dev)\.toyotacertified)\.com$|localhost/i))?"d":"t";
//var s_account = (document.domain.match(/(.+\.bigbangmedia\.net)|(((staging|devcpd\d|dev)\.toyota)\.com)$|localhost/i))?"devToyota":"TmsToyota";
var vc="1";
var region_deferred_payment_program_and = 99;
var region_deferred_payment_program_or = 99;

function getLocalSpecials(action, zipCode, seriesId, modelId, modelYear, divObj, bannerSize) {
	var url = loc=='b' ? "/data/dataCommon.asp" : "/toyotaTCUV/localspecials/specialOffers.do";

	var pars = "language=E"
        + "&action=" + action
		+ "&method=searchOffers"
		+ "&searchBy=zipcode"
		+ "&zipCode=" + escape(zipCode)
		+ "&responseType=XML";
	if (action == "zipCode"){
		pars += "&searchWith=offerType";
	}else if(action == "seriesId"){
		pars += "&searchWith=seriesId"
		    + "&seriesId=" + escape(seriesId);
	}else if(action == "modelId"){
		pars += "&searchWith=modelId"
		    + "&modelId=" + escape(modelId)
		    + "&modelYear=" + escape(modelYear);
	}else{
		//alert("no request made");
		return false;
	}
	if(bannerSize!="SHORT"  && bannerSize!="LONG" ){
               	 $(divObj).innerHTML="<br /><br /><br /><table class=\"localspecials\" align=\"center\" width=\"645\"><tr><td align=\"center\"><img alt=\"\" src=\"/img/global/img_loading_nobg.gif\" /></td></tr></table>";
	}
    var myAjax = new Ajax.Request(
        url, 
        {
            method: 'get', 
            parameters: pars, 
           // onLoading: function(){
			//	if(bannerSize!="SHORT"  && bannerSize!="LONG" ){
           //    	 $(divObj).innerHTML="<br /><br /><br /><table class=\"localspecials\" align=\"center\" width=\"645\"><tr><td align=\"center\"><img alt=\"\" src=\"/img/global/img_loading_nobg.gif\" /></td></tr></table>";
			//	}
			//}, 
            onComplete: function(req){
               // if(req.status == 404 || req.status == 500){
              //      processLocalSpecialError(zipCode, action, divObj, bannerSize);
              //  }else{
                    processLocalSpecial(req, zipCode, action, divObj, bannerSize);
              //  }
            },
			onFailure: function(req){
                    processLocalSpecialError(zipCode, action, divObj, bannerSize);
            }
        } 
    );
}

function processLocalSpecial(req, zipCode, action, divObj, bannerSize){
    //alert(req.responseText);
    var xmlDoc=parseXML(req.responseText);
    if(xmlDoc!=null){
        var htm="";
        var specials=xmlDoc.getElementsByTagName("localSpecial");
        if(action=="zipCode"){
            if(specials.length>0){
                // Tundra & Tacoma
                var cntTundra=0,bTundra=false;
                var cntTacoma=0,bTacoma=false;
                for(var i=0;i<specials.length;i++){
                    var id=parseInt(specials[i].getElementsByTagName("seriesId")[0].firstChild.nodeValue,10);
                    if(id==82 || id==83 || id==77 || id==78)cntTundra++;
                    if(id==71 || id==75)cntTacoma++;
                }
                htm+="<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"645\" align=\"center\" class=\"localspecials\">";
                for(var i=0;i<specials.length;i++){
                    var special=specials[i];
                    var series=special.getElementsByTagName("seriesId")[0].firstChild.nodeValue;
                    var id=parseInt(series);
					var idx=parseInt(series);
                    setVc(id);

                    if(!(((id==82 || id==83 || id==77 || id==78) && bTundra) || ((id==71 || id==75) && bTacoma))){
                        var aprs=special.getElementsByTagName("tcuvApr");
			            var sid=special.getElementsByTagName("tcuvId");sid=sid.length>0?sid[0].firstChild.nodeValue:"0";
                        var strDisclaimer=fixDisclaimerSeries(aprs[0].getElementsByTagName("disclaimerEn")[0].firstChild.nodeValue);
                        var strSeries=special.getElementsByTagName("seriesName")[0].firstChild.nodeValue;
						var strExclusions=special.getElementsByTagName("offerTitleEn")[0].firstChild?special.getElementsByTagName("offerTitleEn")[0].firstChild.nodeValue:"";
                        var intRegion=parseInt(special.getElementsByTagName("tcuvAssignmentCd")[0].firstChild.nodeValue,10);
                        if((id==82 || id==83 || id==77 || id==78) && cntTundra>1){
                            bTundra=true;
                            strSeries=fixSeries(strSeries);
                        }
                        
                        if((id==71 || id==75) && cntTacoma>1){
                            bTacoma=true;
                            strSeries=fixSeries(strSeries);
                        }
						
                        if(aprs[0].getElementsByTagName("rate")[0].firstChild.nodeValue=="0"
																
						   //(intRegion==22 && (idx!=25 && idx!=69 && idx!=77 && idx!=78 && idx!=82 && idx!=83 && idx!=79 && idx!=86))||
						  // (intRegion==21 && (idx!=77 && idx!=78 && idx!=82 && idx!=83 && idx!=79 && idx!=86))||
						  // (intRegion==23 && (idx!=25 && idx!=27 && idx!=69 && idx!=53 && idx!=47 && idx!=71 && idx!=75 && idx!=77 && idx!=78 && idx!=82 && idx!=83 && idx!=79 && idx!=86))
						   )
						{
							htm+="<tr>"
								+"<td align=\"center\" class=\"pic\"><img src=\"/img/localspecials/series"+series+".jpg\" alt=\""+strSeries+"\" /><br /><a href=\"/inventory/index.html?SearchModel="+escape(fixSeries(strSeries))+"&SearchZipCode="+zipCode+"&VehicleCategory="+vc+"\" onmouseover=\"msover1('searchinv"+i+"','/img/content/b_searchinventory2.gif');\" onmouseout=\"msout1('searchinv"+i+"','/img/content/b_searchinventory1.gif');\"><img name=\"searchinv"+i+"\" src=\"/img/content/b_searchinventory1.gif\" alt=\"Search Inventory\" onclick=\"goToInventory('"+escape(fixSeries(strSeries))+"');\" /></a></td>"
								+"<td class=\"content\">"
								+"<b class=\"title\">"//Get&nbsp;"+aprs[0].getElementsByTagName("rate")[0].firstChild.nodeValue+"% APR*</b><br /><b class=\"subtitle\">for up to "+aprs[0].getElementsByTagName("term")[0].firstChild.nodeValue+" months on Certified "+strSeries+" "+strExclusions
								+"90 day deferred payment program available on Certified "+strSeries+" "+strExclusions+"*"
								+"</b><br /><br />";
						}else{
							htm+="<tr>"
								+"<td align=\"center\" class=\"pic\"><img src=\"/img/localspecials/series"+series+".jpg\" alt=\""+strSeries+"\" /><br /><a href=\"/inventory/index.html?SearchModel="+escape(fixSeries(strSeries))+"&SearchZipCode="+zipCode+"&VehicleCategory="+vc+"\" onmouseover=\"msover1('searchinv"+i+"','/img/content/b_searchinventory2.gif');\" onmouseout=\"msout1('searchinv"+i+"','/img/content/b_searchinventory1.gif');\"><img name=\"searchinv"+i+"\" src=\"/img/content/b_searchinventory1.gif\" alt=\"Search Inventory\" onclick=\"goToInventory('"+escape(fixSeries(strSeries))+"');\" /></a></td>"
								+"<td class=\"content\">"
								+"<b class=\"title\">Get&nbsp;"+aprs[0].getElementsByTagName("rate")[0].firstChild.nodeValue+"% APR*</b><br /><b class=\"subtitle\">for up to "+aprs[0].getElementsByTagName("term")[0].firstChild.nodeValue+" months on Certified "+strSeries+" "+strExclusions
								+(region_deferred_payment_program_and==intRegion ? "<br />and 90 day deferred payment program available*" : "")
								+(region_deferred_payment_program_or==intRegion ? "<br />or 90 day deferred payment program available*" : "")
								+"</b><br /><br />";
								for(var j=aprs.length-1;j>=0;j--){ 
			               		 htm+="<b>"+aprs[j].getElementsByTagName("term")[0].firstChild.nodeValue+" monthly payments of $"+aprs[j].getElementsByTagName("monPayPerThouFinanced")[0].firstChild.nodeValue+" per $1,000 financed*</b><br />"
			          			  }

						}
			          // for(var j=aprs.length-1;j>=0;j--){ 
			          //  htm+="<b>"+aprs[j].getElementsByTagName("term")[0].firstChild.nodeValue+" monthly payments of $"+aprs[j].getElementsByTagName("monPayPerThouFinanced")[0].firstChild.nodeValue+" per $1,000 financed*</b><br />"
			          //  }
			            htm+="Offer ends "+special.getElementsByTagName("offerEndDate")[0].firstChild.nodeValue
			                +"<br /><br /><div class=\"disclaimer\">"+strDisclaimer+"</div><br /><br />"// tcuvId="+sid+"</div><br /><br />"
			                +"</td>"
			                +"</tr>";
			        }
                }
                htm+="</table>";
            }else{
                if(req.responseText=="" || req.responseText.toLowerCase().indexOf("error")>-1){
                    $(divObj).innerHTML="";changeZip();
					TMSSite.disclaimerHotlink("/includes/errors/serviceerror.incl");
                }else{
                    htm+="There are no current special in your area.<br />However, Toyota Certified Customers are eligible for New Car Financing Rates. <a href=\"javascript: void(null);\" onclick=\"TMSSite.disclaimerHotlink('disclaimers/financing.html');\" class=\"disclaimer\"><sup>[1]</sup></a>";
                }
            }
        }else{
            if(specials.length>0){
                var special=specials[0];
                var aprs=special.getElementsByTagName("tcuvApr");
			    var series=special.getElementsByTagName("seriesId")[0].firstChild.nodeValue;
			    var sid=special.getElementsByTagName("tcuvId");sid=sid.length>0?sid[0].firstChild.nodeValue:"0";
			    var strSeries=fixSeries(special.getElementsByTagName("seriesName")[0].firstChild.nodeValue);
			    var intRegion=parseInt(special.getElementsByTagName("tcuvAssignmentCd")[0].firstChild.nodeValue,10);
			    var maxApr=aprs[0];
			    
			    for(var i=1;i<aprs.length;i++)if(parseFloat(aprs[i].getElementsByTagName("rate")[0].firstChild.nodeValue)>parseFloat(maxApr.getElementsByTagName("rate")[0].firstChild.nodeValue))maxApr=aprs[i];
                var strDisclaimer=fixDisclaimerSeries(maxApr.getElementsByTagName("disclaimerEn")[0].firstChild.nodeValue);
                if(bannerSize=="LONG"){
					if( aprs[0].getElementsByTagName("rate")[0].firstChild.nodeValue=="0"
						  // (intRegion==22 && (idx!=25 && idx!=69 && idx!=77 && idx!=78 && idx!=82 && idx!=83 && idx!=79 && idx!=86))||
						  // (intRegion==21 && (idx!=77 && idx!=78 && idx!=82 && idx!=83 && idx!=79 && idx!=86))||
						  // (intRegion==23 && (idx!=25 && idx!=27 && idx!=69 && idx!=53 && idx!=47 && idx!=71 && idx!=75 && idx!=77 && idx!=78 && idx!=82 && idx!=83 && idx!=79 && idx!=86))
						   )
					{
                    htm+="<br/><div id=\"local_sidebar\"><div id=\"lss_close\" style=\"display:none;\"><a href=\"javascript:void(null);\" onclick=\"$('lss_content2').hide(); $('lss_close').hide();\"><img src=\"/img/content/ls_x.gif\" alt=\"Close\"/></a></div>"
                        +"<div class=\"lss_container\"><div id=\"lss_content1\" style=\"cursor:pointer;float:left;\" onclick=\"$('lss_content2').show(); $('lss_close').show();\">"
                        +"<div class=\"copy\"><b class=\"title3\">"
                        +"90 day deferred payment program available on Certified "+strSeries+"*"
						+"</b></div>"
			            //+"<div class=\"image\"><img src=\"/img/content/ls_"+strSeries+".jpg\" alt=\"\" /></div>"
			            +"</div><div id=\"lss_content2\" style=\"display:none;\"><div class=\"copy2\"><b>";
			            
					}else{
						htm+="<br/><div id=\"local_sidebar\"><div id=\"lss_close\" style=\"display:none;\"><a href=\"javascript:void(null);\" onclick=\"$('lss_content2').hide(); $('lss_close').hide();\"><img src=\"/img/content/ls_x.gif\" alt=\"Close\"/></a></div>"
                        +"<div class=\"lss_container\"><div id=\"lss_content1\" style=\"cursor:pointer;float:left;\" onclick=\"$('lss_content2').show(); $('lss_close').show();\">"
                        +"<div class=\"copy\"><b class=\"title1\">Get </b><b class=\"title2\">"+maxApr.getElementsByTagName("rate")[0].firstChild.nodeValue+"%</b> <b class=\"title3\"> APR*</b><br /><b class=\"title3\">for up to "+maxApr.getElementsByTagName("term")[0].firstChild.nodeValue+" Months</b><br /><b class=\"title4\">on "+strSeries
                        +(region_deferred_payment_program_and==intRegion ? "<br />and 90 day deferred payment program available*" : "")
                        +(region_deferred_payment_program_or==intRegion ? "<br />or 90 day deferred payment program available*" : "")
                        +"</b></div>"
			            //+"<div class=\"image\"><img src=\"/img/content/ls_"+strSeries+".jpg\" alt=\"\" /></div>"
			            +"</div><div id=\"lss_content2\" style=\"display:none;\"><div class=\"copy2\"><b>";
			            
			        for(var i=aprs.length-1;i>=0;i--)
		                htm+=aprs[i].getElementsByTagName("term")[0].firstChild.nodeValue+" monthly payments of $"+aprs[i].getElementsByTagName("monPayPerThouFinanced")[0].firstChild.nodeValue+" per $1,000 financed*<br />";
					
						
					}
			        htm+="</b><span class=\"date\">Offer ends "+special.getElementsByTagName("offerEndDate")[0].firstChild.nodeValue + "</span></div><div class=\"disclaimer\">"+strDisclaimer+"</div></div><div class=\"clear\"></div></div></div>";
				}else{
					if(aprs[0].getElementsByTagName("rate")[0].firstChild.nodeValue=="0"
						  // (intRegion==22 && (idx!=25 && idx!=69 && idx!=77 && idx!=78 && idx!=82 && idx!=83 && idx!=79 && idx!=86))||
						 //  (intRegion==21 && (idx!=77 && idx!=78 && idx!=82 && idx!=83 && idx!=79 && idx!=86))||
						 //  (intRegion==23 && (idx!=25 && idx!=27 && idx!=69 && idx!=53 && idx!=47 && idx!=71 && idx!=75 && idx!=77 && idx!=78 && idx!=82 && idx!=83 && idx!=79 && idx!=86))
						   )
					{
				    strDisclaimer=fixDisclaimer(maxApr.getElementsByTagName("disclaimerEn")[0].firstChild.nodeValue);
                    htm+="<div id=\"local_medium\"><div id=\"lsm_close\" style=\"display:none;\"><a href=\"javascript:void(null);\" onclick=\"$('lsm_content2').hide();$('lsm_close').hide();\"><img src=\"/img/content/ls_x.gif\" alt=\"Close\"/></a></div>"
                        +"<div class=\"topedge\"><img src=\"/img/content/spacer.gif\" height=\"1\" width=\"1\"/></div><div class=\"lsm_container\"><div id=\"lsm_content1\" style=\"cursor:pointer;\" onclick=\"$('lsm_content2').show(); $('lsm_close').show();\"><div class=\"clear\"></div>"
                        +"<div class=\"image\"><img src=\"/img/content/ls_"+special.getElementsByTagName("seriesId")[0].firstChild.nodeValue+".jpg\" alt=\"\" /></div>"
                        +"<div class=\"copy\"><b class=\"title3\">"
						+"90 day deferred payment program available on Certified "+strSeries+"*"
                        +"</b></div>"
			            +"<div class=\"clear\"></div>"
			            +"<div id=\"lsm_content2\" style=\"display:none;\"><div class=\"copy2\"><b>";
					}else{
						strDisclaimer=fixDisclaimer(maxApr.getElementsByTagName("disclaimerEn")[0].firstChild.nodeValue);
                   htm+="<div id=\"local_medium\"><div id=\"lsm_close\" style=\"display:none;\"><a href=\"javascript:void(null);\" onclick=\"$('lsm_content2').hide();$('lsm_close').hide();\"><img src=\"/img/content/ls_x.gif\" alt=\"Close\"/></a></div>"
                      +"<div class=\"topedge\"><img src=\"/img/content/spacer.gif\" height=\"1\" width=\"1\"/></div><div class=\"lsm_container\"><div id=\"lsm_content1\" style=\"cursor:pointer;\" onclick=\"$('lsm_content2').show(); $('lsm_close').show();\"><div class=\"clear\"></div>"
                       +"<div class=\"image\"><img src=\"/img/content/ls_"+special.getElementsByTagName("seriesId")[0].firstChild.nodeValue+".jpg\" alt=\"\" /></div>"
                        +"<div class=\"copy\"><b class=\"title1\">Get</b><br /><b class=\"title2\">"+maxApr.getElementsByTagName("rate")[0].firstChild.nodeValue+"%</b> <b class=\"title3\">APR* for up to</b><br /><b class=\"title4\">"+maxApr.getElementsByTagName("term")[0].firstChild.nodeValue+" Months on "+special.getElementsByTagName("seriesName")[0].firstChild.nodeValue
                        +(region_deferred_payment_program_and==intRegion ? "<br />and 90 day deferred payment program available*" : "")
                        +(region_deferred_payment_program_or==intRegion ? "<br />or 90 day deferred payment program available*" : "")
                        +"</b></div>"
			            +"<div class=\"clear\"></div>"
			            +"<div id=\"lsm_content2\" style=\"display:none;\"><div class=\"copy2\"><b>";
		           for(var i=aprs.length-1;i>=0;i--)
		                htm+=aprs[i].getElementsByTagName("term")[0].firstChild.nodeValue+" monthly payments of $"+aprs[i].getElementsByTagName("monPayPerThouFinanced")[0].firstChild.nodeValue+" per $1,000 financed*<br />";
					
					}
			        htm+="</b><span class=\"date\">Offer ends "+special.getElementsByTagName("offerEndDate")[0].firstChild.nodeValue + "</span><br /><br /><div class=\"disclaimer\">"+strDisclaimer+"</div></div></div></div></div><div class=\"bottomedge\"><img src=\"/img/content/spacer.gif\" height=\"1\" width=\"1\" /></div></div>";
				}
            }
        }
        $(divObj).innerHTML=htm;
    }else{
        $(divObj).innerHTML="";
        if(action="zipCode"){
            changeZip();
		    TMSSite.disclaimerHotlink("/includes/errors/serviceerror.incl");
		}
    }
}

function processLocalSpecialError(zipCode, action, divObj, bannerSize){
    $(divObj).innerHTML="";
    if(action="zipCode"){
        changeZip();
		TMSSite.disclaimerHotlink("/includes/errors/serviceerror.incl");
	}
}

function fixDisclaimer(s){
    var re=/20[0-9]{2},2/,p=s.search(re);
    while(p>=0){
        var s1=s.substr(0,p+4)+", "+s.substr(p+5),p1=s1.search(re);
        s=p1==-1?s.substr(0,p+4)+" and "+s.substr(p+5):s1;
        p=p1;
    }
    return s;
}

function fixDisclaimerSeries(s){
    var re=/20[0-9]{2},2/,p=s.search(re);
    while(p>=0){
        var s1=s.substr(0,p+4)+", "+s.substr(p+5),p1=s1.search(re);
        s=p1==-1?s.substr(0,p+4)+" and "+s.substr(p+5):s1;
        p=p1;
    }
    return s.replace(/\s*4\s*x\s*4\s*/gi,"").replace(/\s*4\s*x\s*2\s*/gi,"");
}

function fixSeries(s){
    return s.replace(/\s*4\s*x\s*4\s*/gi,"").replace(/\s*4\s*x\s*2\s*/gi,"");
}

function searchSpecials(){
    var o = $("SearchZipCode");
	if(val_zipcodeP(o.value) == 'false'){
        //alert("You must Enter a Valid 5 digit Zip Code to Search for Local Specials.");
		TMSSite.disclaimerHotlink("/includes/errors/invalidzipspecials.incl");
        o.blur();
        o.focus();
		return;
	}
	//hawaii
	else if((Math.round(o.value) >= 96701) && (Math.round(o.value) <= 96898)){
		//alert("Toyota Certified Used Vehicles are NOT Available in Hawaii.");
		TMSSite.extlink.display('http://www.toyota-hawaii.com','Toyota Certified Used Vehicles are NOT available in Hawaii.<br/><br/>To better meet your needs, Toyota is referring you to a third party site to<br/>obtain the information you requested.');
		//o.blur();
		//o.focus();
	    return;
	}
	//puerto rico 	
	else if((Math.round(o.value) >= 601) && (Math.round(o.value) <= 988)){			
		//alert("Toyota Certified Used Vehicles are NOT Available in Puerto Rico.");
		TMSSite.extlink.display('http://www.toyotapr.com','Toyota Certified Used Vehicles are NOT available in Puerto Rico.<br/><br/>To better meet your needs, Toyota is referring you to a third party site to<br/>obtain the information you requested.');
		//o.blur();
		//o.focus();
		return;
	}
	//SET states
	//else if((Math.round(o.value) >= 27000) && (Math.round(o.value) < 37000)){	
	//	TMSSite.disclaimerHotlink("/includes/errors/invalidzipset.incl");
		//alert("Toyota Certified Used Vehicles are NOT Available for Southeast Toyota.");
	//	o.blur();
	//	o.focus();
	//	return;
	//}
	//GST states
	//else if((Math.round(o.value) >= 70000) && (Math.round(o.value) < 80000) || (Math.round(o.value) >= 38600) && (Math.round(o.value) < 40000)){			
		//alert("Toyota Certified Used Vehicles are NOT Available for Gulf States Toyota.");
	//	TMSSite.disclaimerHotlink("/includes/errors/invalidzipgst.incl");
	//	o.blur();
	//	o.focus();
	//return;
	//}

    $("objZipValue").innerHTML = o.value;
    $("objZipBox").style.display = "none";
    $("objZipDetail").style.display = "block";
	getLocalSpecials("zipCode", o.value, "", "", "", "divLocalSpecials");
	
	if(o.value !=''){
		TMSSite.createCookie('zipcode', o.value, 180);
	}
	TMSSite.analytics.set({
		pageName: xSite+' : Local Specials : Search',
		channel: xSite+xSection,
		properties: {
			'7': o.value
		},
		eventVars: {},
		events: ''
	});
	TMSSite.analytics.sendPageView();
}

function val_zipcodeP(item){
   var digits = "0123456789"
   var valid = "true";
   var temp;
   var max=5;
   var maxvalid = "true";

   for (var i=0; i < item.length; i++) {
      temp = "" + item.substring(i, i+1);
      if (digits.indexOf(temp) == "-1") valid = "false";
   }

   if (item.length < max)  {
      valid = "false";
   }
   return valid;
}

function specialsStart(){
    var o = $("SearchZipCode");
	if(getQueryVariable('SearchZipCode')!='' && getQueryVariable('SearchZipCode')!=null){
		o.value = getQueryVariable('SearchZipCode');
		searchSpecials();
		return false;
	}else if(TMSSite.readCookie('zipcode')){
		o.value = TMSSite.readCookie('zipcode');
		searchSpecials();
		return false;
	}else{
		$('intro').show();
	    o.focus();
	}
}

function changeZip(){
    var o = $("SearchZipCode");
    
    $("objZipDetail").style.display = "none";
    $("objZipBox").style.display = "block";
    o.focus();
    o.select();
}

function setVc(series){
	if (series=="35" || series=="25" || series=="18" || series=="19" || series=="27" || series=="21" || series=="32"){//avalon
		vc="1";
	}
	else if (series=="44" || series=="53" || series=="61" || series=="69" || series=="86"  || series=="79" || series=="47" ){//suvs
		vc="2";
	}
	else if (series=="71" || series=="75" || series=="77" || series=="78" || series=="82" || series=="83" ){//trucks
		vc="3";
	}
	else if (series=="12"){//Hybrid
		vc="4";
	}
	else {
		vc="";
	}
}
		
function parseXML(str){
    var xmlDoc=null;
    var p=str.indexOf("<?xml");
    str = str.substr(p);
    
    try{
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async="false";
        xmlDoc.loadXML(str);
    }catch(e){
        try
        {
            parser=new DOMParser();
            xmlDoc=parser.parseFromString(str,"application/xml");
        }
        catch(e){
            try{
                xmlDoc=document.implementation.createDocument("","",null);
	            xmlDoc.loadXML(str);
            }catch(e){
                //alert(e.message);
                xmlDoc = null;
            }
        }
    }
    return xmlDoc;
}

function goToInventory(mm){
	TMSSite.analytics.set({
		pageName: xSite+' : Local Specials : Search Inventory',
		channel: xSite+xSection,
		properties: {
			'7': $('SearchZipCode').value,
			'40': mm
		},
		eventVars: {},
		events: 'event13'
	});
	TMSSite.analytics.sendPageView();	
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  return "";
}