
// contains methods to redirect old links to the new MapMachine version

function redirectOldDynamicCall() {
	currentUrl = document.URL;
	
	// match old id with a new id
	oldId = getValue(currentUrl,"id");
	themeId = 100; // is new default
	
    //if (oldId == "362") themeId = 100;    // Political/Satellite                       
    //if (oldId == "360") themeId = 100;    // Satellite Imagery                         
    //if (oldId == "361") themeId = 100;    // Satellite Imagery (1 km)                  
	if (oldId == "620") themeId = 107;    // Flood Regions                             
    else if (oldId == "161") themeId = 108;    // Canada Political/Streets (Grayscale)      
    else if (oldId == "160") themeId = 108;    // Political/Streets                         
    else if (oldId == "100") themeId = 108;    // Political/Streets                         
    else if (oldId == "150") themeId = 108;    // Political/Streets                         
    else if (oldId == "410") themeId = 113;    // Topographic Maps                          
    else if (oldId == "165") themeId = 115;    // Political/Streets                         
    else if (oldId == "340") themeId = 117;    // Earthquakes (Recent)                      
    else if (oldId == "800") themeId = 120;    // Mars Imagery                              
    else if (oldId == "590") themeId = 121;    // Hailstorms                                
    else if (oldId == "610") themeId = 122;    // Hurricane Paths                           
    else if (oldId == "600") themeId = 123;    // Windstorms                                
    else if (oldId == "580") themeId = 124;    // Tornado Touchdowns                        
    else if (oldId == "560") themeId = 201;    // Agricultural Threats to the Environment   
    else if (oldId == "310") themeId = 202;    // Bioclimatic Soil Regions                  
    else if (oldId == "300") themeId = 203;    // Elevation                                 
    else if (oldId == "510") themeId = 204;    // Land Use                                  
    else if (oldId == "330") themeId = 205;    // Mineral Resources                         
    else if (oldId == "320") themeId = 206;    // Natural Landscapes                        
    else if (oldId == "110") themeId = 207;    // Population Density                        
    else if (oldId == "520") themeId = 208;    // Precipitation (Annual)                    
    else if (oldId == "530") themeId = 209;    // Precipitation (January)                   
    else if (oldId == "540") themeId = 210;    // Precipitation (July)                      
    else if (oldId == "550") themeId = 211;    // Snow Cover                                
    else if (oldId == "583") themeId = 212;    // Temperature (Annual)                      
    else if (oldId == "585") themeId = 213;    // Temperature (January)                     
    else if (oldId == "587") themeId = 214;    // Temperature (July)                        
    else if (oldId == "140") themeId = 215;    // Time Zones                                
    else if (oldId == "120") themeId = 216;    // Transportation Density                    
    else if (oldId == "500") themeId = 217;    // Vegetation                                
    else if (oldId == "370") themeId = 218;    // Ecoregions: Biological Distinctiveness    
    else if (oldId == "380") themeId = 219;    // Ecoregions: Degree of Threat              
    else if (oldId == "400") themeId = 220;    // Ecoregions: Habitat Type                  
    else if (oldId == "390") themeId = 221;    // Ecoregions: Projected Threat (Year 2020)  
		
	requestUrl = theWebAppPath + "/viewandcustomize.html?task=getMap&themeId=" + themeId;
	if (getValue(currentUrl,"left").length > 0)
		requestUrl += "&ext=" + getValue(currentUrl,"left")+","+getValue(currentUrl,"bottom")+","
				      + getValue(currentUrl,"right")+","+getValue(currentUrl,"top");

	document.location = requestUrl;
	
}

function redirectOldPictureCall() {
	// id=2 is default
	currentUrl = document.URL;
	themeId = getValue(currentUrl,"id");
	if (themeId.length == 0)
		themeId = 2;
		
	requestUrl = theWebAppPath + "/viewandcustomize.html?task=getMap&themeId=p" + themeId;
	if (getValue(currentUrl,"left").length > 0)
		requestUrl += "&ext=" + getValue(currentUrl,"left")+","+getValue(currentUrl,"bottom")+","
				      + getValue(currentUrl,"right")+","+getValue(currentUrl,"top");

	document.location = requestUrl;
	
}

function addParameterToUrl(str,search,use) {
	value = getValue(str,search);
	if (value != "")
		return ("&"+use+"="+value);
	return "";
}

function getValue(str,search) {
	var s = str.indexOf("&"+search+"=",0);
	if (s == -1)
		s = str.indexOf("?"+search+"=",0);
	if (s == -1) return "";
	var e = str.indexOf("&",s+2);
	if (e == -1) e = str.length;
	return str.substring(s+search.length+2,e);
}

