
// Javascript file for Rep Locator functionality
// used in various file under /sales/

function gupFrames(name, frame)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( frames[frame].location );
  if( results == null )
    return "";
  else
    return results[1];
}

function gupDocument(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( document.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function getTitle(channel)
{
   switch(channel) 
    {
        case "Retail": title = "RETAIL"; break;
        case "Hearth": title = "HEARTH"; break;
        case "Wholesale": title = "WHOLESALE"; break;
        case "Commercial": title = "COMMERCIAL & INDUSTRIAL"; break;        
    }
    return title;
}

function setActive(channel)
{
    parent.window.document.getElementById('Retail').className = "";
    parent.window.document.getElementById('Hearth').className = "";
    parent.window.document.getElementById('Wholesale').className = "";
    parent.window.document.getElementById('Commercial').className = "";
    parent.window.document.getElementById(channel).className = "active";
}

function initSrc(channel)
{   
    document.location.href = channel + '.aspx';    
    setActive(channel);    
    parent.window.document.getElementById('channelTitle').innerHTML = getTitle(channel);    
}


function changeSrc(channel)
{    
    document.getElementById('map').src = 'maps/' + channel + '.aspx';
    setActive(channel);
    document.getElementById('channelTitle').innerHTML = getTitle(channel);
    
    var location = gupFrames('location', 1);
    if(location != "")
    {
        //alert("New URL: " + 'rep-list/' + channel + '.aspx?location=' + location);        
        document.getElementById('reps').src = 'rep-list/' + channel + '.aspx?location=' + location;        
    }
}

function updateChannel(channelTitle)
{
    var location = gupDocument("location");
    parent.window.document.getElementById('channelTitle').innerHTML = channelTitle + " >> " + location;    
}

function loadMap(xmlFile)
{
    document.write(''
      + '  <object style="margin-left: -100px; margin-top: -20px;" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="610" height="550" align="middle" id="usa_canada_locator">'
      + '    <param name="allowScriptAccess" value="sameDomain" />'
      + '    <param name="movie" value="usa_canada_locator.swf" />'
      + '	 <param name="FlashVars" value="xmlfile1=' + xmlFile + '.xml" />'
      + '    <param name="quality" value="high" />'
      + '    <param name="bgcolor" value="#ffffff" />'
      + '    <embed style="margin-top: -20px;" src="usa_canada_locator.swf?xmlfile1=' + xmlFile + '.xml" quality="high" bgcolor="#ffffff" width="610" height="550" name="usa_canada_locator" align="right" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
      + '  </object>'); 
}