/*
customtools.js
Scripts to control general functionality for MI custome map tool
Sept 2009
*/

//----------------------Globals
var http;
var maxNoProducts = 9;					//Total number of map products available for purchase
//var extraOS25kPriceperKm = 0.48;		//Extra price/sq km for OS25k
var totalUKareaKm = 234411;											//Total UK area (km sq)	


//Size bands
var theSizes = new Array("21x30","30x42","42x60","70x100","88x120","88x130","88x140","88x150","88x160","88x170","88x180","88x190","88x200","88x250","88x300","88x350","88x400","88x450","88x500","100x100","100x110","100x120","100x130","100x140","100x150","100x160","100x170","100x180","100x190","100x200","100x250","100x300","100x350","100x400","100x450","100x500","110x110","110x120","110x130","110x140","110x150","110x160","110x170","110x180","110x190","110x200","110x250","110x300","110x350","110x400","110x450","110x500","120x120","120x130","120x140","120x150","120x160","120x170","120x180","120x190","120x200","120x250","120x300","120x350","120x400","120x450","120x500","130x130","130x140","130x150","130x160","130x170","130x180","130x190","130x200","130x250","130x300","130x350","130x400","130x450","130x500","140x140","140x150","140x160","140x170","140x180","140x190","140x200","140x250","140x300","140x350","140x400","140x450","140x500","150x150","150x160","150x170","150x180","150x190","150x200","150x250"
							,"150x300","150x350","150x400","150x450","150x500","160x160","160x170","160x180","160x190","160x200","160x250","160x300","160x350","160x400","160x450","160x500","170x170","170x180","170x190","170x200","170x250","170x300","170x350","170x400","170x450","170x500","180x180","180x190","180x200","180x250","180x300","180x350","180x400","180x450","180x500","190x190","190x200","190x250","190x300","190x350","190x400","190x450","190x500","200x200","200x250","200x300","200x350","200x400","200x450","200x500","250x250","250x300","250x350","250x400","250x450","250x500","300x300","300x350","300x400","300x450","300x500","350x350","350x400","350x450","350x500","400x400","400x450","400x500","450x450","450x500","500x500");

//Associated base price for the size bands by finish
var customPrices = new Array (7);
var customPricesOLD = new Array (7);
													
customPricesOLD[0] = new Array("en",65,70,70,70,70,109,122,129,139,149,159,169,189,214,239,264,289,314,339,129,136,143,150,157,164,171,178,185,192,199,224,298,328,358,388,418,139,146,153,160,167,174,181,188,195,202,227,302,332,362,392,422,149,156,163,170,177,189,194,198,205,230,306,336,366,396,426,159,166,173,180,187,194,201,208,233,309,339,369,399,453,179,189,199,209,219,229,239,264,415,314,406,446,468,238,250,262,274,286,298,328,358,388,418,460,502,262,274,286,298,310,340,370,400,450,474,518,286,298,310,322,352,382,412,462,507,552,310,322,334,364,394,446,474,521,567,334,346,376,406,457,505,554,602,358,394,430,468,518,567,617,478,526,574,622,675,732,567,652,717,782,866,725,817,889,981,916,1016,1116,1123,1211,1365);			
customPricesOLD[1] = new Array("enbm",96,111,120,129,151,168,182,202,215,232,241,257,275,325,386,493,590,643,698,181,195,193,199,209,226,239,259,265,277,283,333,475,630,756,822,564,215,213,220,226,238,244,259,266,280,286,336,477,662,786,862,937,215,221,227,243,249,277,272,283,289,348,480,696,829,906,980,237,243,249,264,278,284,297,303,351,492,728,865,946,1029,254,263,281,297,306,321,330,390,626,660,931,1018,1102,417,440,463,487,510,532,624,741,832,975,1071,1156,465,488,513,538,562,658,778,873,1020,1118,1206,512,538,565,590,686,808,903,1060,1156,1261,562,590,619,721,852,956,1111,1222,1315,616,644,751,886,992,1153,1258,1365,673,817,937,1050,1216,1336,1454,1051,1197,1347,1551,1699,1846,1176,1570,1748,1932,2116,1776,1975,1814,1984,1834,4240,2644,2665,2908,3176);			
customPricesOLD[2] = new Array("enbmf",107,123,133,143,168,187,202,224,239,258,268,286,305,361,429,547,655,715,776,201,216,215,222,232,251,265,288,295,308,315,370,528,699,840,913,986,239,237,244,251,264,271,288,295,311,318,373,530,735,873,958,1041,239,246,252,270,277,308,302,314,321,387,465,774,920,1005,1089,263,270,277,294,308,315,330,337,390,547,810,961,1051,1143,282,292,312,330,340,357,367,433,694,734,1035,1131,1225,463,489,514,541,566,592,693,817,925,1084,1190,1285,517,542,571,598,626,732,865,970,1134,1242,1340,570,598,627,656,762,898,1004,1178,1285,1401,626,656,688,801,946,1063,1234,1358,1461,685,715,835,985,1102,1281,1399,1516,747,907,1051,1166,1352,1485,1615,1167,1329,1497,1724,1887,2052,1540,1746,1942,2146,2352,1972,2194,2016,2205,2038,2688,2938,2961,3232,3529);		
customPricesOLD[3] = new Array("enhb",84,99,119,124,133,155,165,175,185,207,217,227,247,272,309,350,387,424,461,159,170,189,196,203,210,217,236,243,250,257,282,382,432,476,520,565,269,192,199,206,213,220,239,246,253,260,285,386,435,480,524,568,279,202,209,216,223,247,252,256,263,288,390,439,483,528,572,289,212,219,226,245,252,259,266,291,393,442,487,531,576,309,235,245,267,277,287,297,322,522,400,524,568,613,394,306,332,344,356,368,403,447,492,536,580,625,423,344,356,368,380,415,459,504,548,592,637,447,368,380,392,427,471,516,560,604,649,471,392,409,439,483,528,572,616,661,495,421,451,495,540,584,628,673,519,469,519,570,620,670,721,685,551,723,786,848,910,745,747,822,896,970,865,882,797,859,821,1016,1090,1105,1150,1225);		
customPricesOLD[4] = new Array("enmbmf",107,123,140,161,189,200,221,243,254,293,304,325,345,413,491,601,719,787,853,217,224,236,242,261,279,286,324,331,348,356,423,624,772,918,1004,1090,248,255,262,278,291,299,327,334,352,359,426,627,816,966,1058,1148,258,266,281,285,303,335,340,355,362,430,606,856,1014,1112,1207,296,303,311,341,361,369,392,399,459,634,900,1060,1164,1267,325,335,361,384,392,421,431,491,808,813,1142,1252,1154,511,541,568,603,626,657,768,913,1027,1201,1314,1428,570,600,632,661,690,808,960,1077,1257,1376,1496,631,662,693,724,849,1004,1129,1314,1436,1561,697,726,760,889,1048,1149,1366,1498,1630,760,793,937,1094,1245,1425,1560,1695,858,1005,1152,1300,1508,1653,1803,1348,1540,1724,1974,2156,2344,1778,2000,2227,2454,2678,2252,2506,2302,2512,2324,3072,3346,3380,3690,4023);			
customPricesOLD[5] = new Array("can",229,251,264,304,357,378,400,421,443,487,504,533,560,725,-99,-99,-99,-99,-99,370,389,407,418,444,465,489,532,544,568,662,809,-99,-99,-99,-99,-99,422,435,448,475,501,528,555,582,687,725,879,-99,-99,-99,-99,-99,450,480,509,538,567,673,713,747,781,949,-99,-99,-99,-99,-99,511,543,574,684,727,615,800,837,1026,-99,-99,-99,-99,-99,577,697,736,775,814,854,877,971,-99,-99,-99,-99,-99,790,786,870,865,907,949,1166,-99,-99,-99,-99,-99,1146,1210,1275,1340,1412,1736,-99,-99,-99,-99,-99,1279,1348,1424,1493,1845,-99,-99,-99,-99,-99,1428,1501,1574,1946,-99,-99,-99,-99,-99,1578,1655,2047,-99,-99,-99,-99,-99,1736,2149,-99,-99,-99,-99,-99,2663,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99);			
customPricesOLD[6] = new Array("acr",242,265,313,530,582,616,650,684,718,752,787,821,855,1033,1204,1374,1545,1716,1894,553,599,637,676,715,754,793,832,871,909,947,1149,1343,1544,1739,1582,2134,641,684,727,770,812,855,898,940,983,1033,1246,1460,1673,1894,2107,2328,731,777,824,871,917,964,1017,1064,1110,1343,1583,1823,2056,2289,2522,828,878,929,979,1037,1087,1138,1188,1447,1700,1960,2211,2471,2780,933,994,1048,1103,1157,1211,1250,1544,1823,2095,2374,2701,2973,1055,1115,1169,1227,1285,1343,1642,1940,2238,2529,2854,3174,1173,1235,1297,1359,1428,1739,2056,2374,2740,3051,3368,1301,1367,1440,1506,1843,2173,2510,2896,3233,3570,1443,1513,1583,1940,2296,2701,3051,3407,3764,1587,1661,2037,2412,2837,3213,3589,3965,1739,2134,2529,2973,3368,3764,4159,2626,3174,3667,4159,4651,5143,3764,4360,4949,5588,6184,5046,5789,6475,7168,6579,7370,8160,8257,9138,10136);

customPrices[0] = new Array('en',62,62,63,64,65,99,111,117,127,136,145,154,174,195,216,237,258,279,300,120,126,132,139,145,151,157,163,169,175,181,202,272,297,323,348,374,128,134,140,146,152,159,165,171,177,183,203,273,298,323,348,374,136,142,148,154,160,171,175,178,184,204,274,299,324,348,373,144,150,156,162,168,173,179,185,204,275,299,323,347,396,162,171,179,188,197,206,219,233,378,382,386,391,406,232,243,255,266,278,290,317,345,373,401,441,481,255,266,278,289,301,329,357,384,432,454,496,278,289,301,312,340,368,395,443,486,528,301,312,324,351,379,428,454,498,542,324,335,363,390,438,484,530,575,347,380,413,448,496,542,589,460,505,549,594,643,697,542,623,683,744,824,691,778,845,932,871,966,1060,1066,1148,1295);
customPrices[1] = new Array('enbm',96,109,118,123,142,158,171,190,202,219,227,242,259,305,363,465,559,609,659,172,185,183,188,197,213,225,244,249,261,266,311,449,599,721,782,520,204,202,207,212,223,228,243,248,261,267,312,448,628,747,818,889,202,207,212,227,232,259,253,262,268,322,448,659,787,858,927,222,227,232,246,258,263,275,280,322,458,688,819,894,972,237,244,261,276,283,298,310,359,589,617,882,963,1040,411,433,456,479,502,524,613,728,817,958,1052,1135,458,480,505,529,553,647,765,857,1002,1098,1184,504,529,556,580,674,794,886,1041,1135,1237,553,580,609,708,837,938,1091,1199,1290,606,633,738,870,973,1132,1234,1338,662,803,920,1030,1194,1311,1426,1033,1176,1322,1523,1667,1811,1151,1541,1714,1894,2074,1742,1936,1770,1935,1789,4190,2588,2608,2845,3106);
customPrices[2] = new Array('enbmf',107,122,131,137,159,177,192,213,226,245,254,271,290,341,406,520,624,680,737,192,206,204,210,220,238,251,273,279,291,297,348,502,668,805,873,942,228,226,231,237,250,256,272,278,293,298,349,501,701,834,914,993,226,232,238,254,260,290,283,294,300,360,433,737,878,957,1036,248,254,259,275,289,295,308,314,361,513,770,915,999,1086,265,274,293,309,317,334,347,402,657,691,986,1076,1163,457,482,507,533,558,584,682,804,910,1067,1171,1264,510,534,563,589,617,721,852,954,1116,1222,1318,562,589,618,646,750,884,987,1159,1264,1377,617,646,678,788,931,1045,1214,1335,1436,675,704,822,969,1083,1260,1375,1489,736,893,1034,1146,1330,1460,1587,1149,1308,1472,1696,1855,2017,1515,1717,1908,2108,2310,1938,2155,1972,2156,1993,2638,2882,2904,3169,3459);
customPrices[3] = new Array('enhb',83,98,117,118,124,145,154,163,173,194,203,212,232,253,286,323,356,389,422,150,160,178,185,191,197,203,221,227,233,239,260,356,401,441,480,521,258,180,186,192,198,205,223,229,235,241,261,357,401,441,480,520,266,188,194,200,206,229,233,236,242,262,358,402,441,480,519,274,196,202,208,226,231,237,243,262,359,402,441,479,519,292,217,225,246,255,264,277,291,485,357,475,513,551,388,299,325,336,348,360,392,434,477,519,561,604,416,336,348,359,371,404,446,488,530,572,615,439,359,371,382,415,457,499,541,583,625,462,382,399,426,468,510,552,593,636,485,410,438,479,521,563,604,646,508,455,502,550,598,645,693,667,530,698,758,816,875,720,718,788,858,928,831,843,753,810,776,966,1034,1048,1087,1155);
customPrices[4] = new Array('enmbmf',107,122,137,154,180,190,210,231,242,280,290,310,330,394,468,574,688,752,814,208,214,226,231,249,266,272,309,315,332,338,401,598,741,883,964,1046,237,244,250,264,277,283,310,316,333,340,402,598,782,927,1014,1100,246,252,266,269,286,317,321,335,341,403,574,819,972,1064,1154,281,287,293,323,342,348,370,376,430,600,860,1014,1112,1210,307,316,341,363,370,397,411,460,771,770,1093,1197,1092,505,534,561,595,618,649,757,900,1012,1184,1295,1407,563,592,624,652,681,797,947,1061,1239,1356,1474,623,653,684,714,837,990,1112,1295,1415,1537,688,716,750,876,1033,1131,1346,1475,1605,750,782,924,1078,1226,1404,1536,1668,847,991,1135,1280,1486,1628,1775,1330,1519,1699,1946,2124,2309,1753,1971,2193,2416,2636,2218,2467,2258,2463,2280,3022,3290,3323,3627,3953);
customPrices[5] = new Array('can',229,250,262,297,348,368,389,410,430,474,490,518,545,705,-99,-99,-99,-99,-99,361,379,397,406,432,452,475,517,528,552,644,787,-99,-99,-99,-99,-99,412,423,435,461,487,513,538,564,668,705,855,-99,-99,-99,-99,-99,438,466,494,522,550,655,694,727,760,923,-99,-99,-99,-99,-99,496,527,557,666,708,594,779,814,997,-99,-99,-99,-99,-99,560,678,716,754,792,830,857,940,-99,-99,-99,-99,-99,784,778,863,857,899,941,1156,-99,-99,-99,-99,-99,1138,1203,1267,1332,1403,1725,-99,-99,-99,-99,-99,1271,1340,1415,1484,1833,-99,-99,-99,-99,-99,1419,1492,1564,1933,-99,-99,-99,-99,-99,1568,1645,2034,-99,-99,-99,-99,-99,1725,2135,-99,-99,-99,-99,-99,2645,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99,-99);
customPrices[6] = new Array('acr',241,264,310,524,572,606,639,673,706,739,773,806,839,1013,1180,1347,1514,1681,1855,544,589,627,665,703,741,779,817,855,893,929,1127,1317,1514,1703,1542,2090,631,673,714,756,798,839,881,923,965,1013,1222,1431,1639,1855,2064,2279,718,764,809,855,900,946,998,1044,1089,1317,1552,1786,2014,2242,2469,813,862,912,961,1017,1066,1116,1165,1419,1665,1920,2166,2419,2722,915,975,1029,1082,1135,1188,1230,1514,1786,2052,2324,2646,2912,1048,1108,1161,1219,1277,1335,1631,1927,2223,2512,2835,3153,1165,1227,1289,1350,1419,1727,2043,2358,2722,3031,3346,1293,1358,1431,1496,1831,2158,2493,2877,3211,3546,1434,1504,1573,1927,2281,2684,3031,3385,3738,1577,1650,2023,2396,2819,3192,3565,3938,1727,2120,2512,2954,3346,3738,4131,2608,3153,3642,4131,4620,5108,3738,4330,4916,5550,6142,5012,5749,6431,7119,6534,7319,8104,8200,9074,10066);

//--Price structure (name,price in �/sqkm,price category no.,full name,data scale)
var pricingStructure = new Array (12);
pricingStructure[0] = new Array("ossv",0,6,"OS StreetView",10000,"no","0");
pricingStructure[1] = new Array("philips10k",0.76,5,"Philip's 10k Raster",10000,"yes","0");
pricingStructure[2] = new Array("philips18",0.76,5,"Philip's 18k Raster",18000,"yes","0"); 
pricingStructure[3] = new Array("osexplorer",0.5,4,"OS Explorer",25000,"yes","0");
pricingStructure[4] = new Array("mv25raster",0,6,"OS VectorMap District",25000,"no","0");
pricingStructure[5] = new Array("mv50raster",0,6,"MapVu 50 Raster",50000,"no","15");
//pricingStructure[4] = new Array("mv40raster",0,1,"MapVu 40 Raster",40000,"no","0");
pricingStructure[6] = new Array("oslandranger",0,4,"OS Landranger",50000,"yes","15");
pricingStructure[7] = new Array("mv100raster",0,2,"MapVu 100 Raster",100000,"no","0");
//pricingStructure[6] = new Array("mv100raster",0,2,"MapVu 100 Raster",100000,"no","15");
pricingStructure[8] = new Array("philips100",0.05,5,"Philip's 100k Raster",100000,"yes","10%"); 
pricingStructure[9] = new Array("mv200raster",0,2,"MapVu 200 Raster",200000,"no","0");
//pricingStructure[8] = new Array("mv200raster",0.04,2,"MapVu 200 Raster",200000,"no","0");
pricingStructure[10] = new Array("ostraveller",0,6,"OS Traveller",250000,"no","0");
//pricingStructure[10] = new Array("philips250",0,6,"Philip's 250k Raster",250000,"no","30%"); 
pricingStructure[11] = new Array("mv625raster",0,3,"MapVu 625 Raster",625000,"no","0");
//pricingStructure[11] = new Array("mv625raster",0,3,"MapVu 625 Raster",625000,"no","15");

var theProductionCharges = new Array(33.73,31.11,30.50,56.75,33.83,38.00,13.97,-11.40,-45.07,-98.26,46.22,51.25,31.25,69.91,-7.33,25.17,96.59,130.48,60.62,44.40,25.23,30.60,6.82,-26.85,60.81,41.09,35.39,-51.84,-139.56,102.49,104.07,120.00,118.29,130.40,31.76,73.15,22.14,-29.80,-62.96,56.22,56.25,13.75,-117.74,107.39,88.50,3.16,134.51,131.07,-58.28,41.87,83.65,120.98,-81.13,51.18,45.93,-74.34,83.03,98.06,85.74,-82.02,117.20,114.95,89.07,109.67,123.78,137.60,1.70,40.66,-96.38,78.37,93.62,-18.36,126.23,113.59,12.75,-69.58,-23.26,137.29,9.72,74.13,66.55,73.24,89.72,-39.43,121.94,101.33,-27.88,130.07,110.39,99.92,106.86,120.17,152.68,168.78,-60.95,94.84,99.81,-47.97,131.73,109.90,-54.20,1.01,-14.78,-24.19,43.45,109.15,78.84,-68.51,127.37,105.76,14.02,118.25,114.18,102.92,121.97,148.44,179.78,122.54,90.97,-5.54,131.81,82.31,19.43,39.16,12.10,10.33,132.55,-25.56,124.37,82.37,-29.73,134.51,136.18,132.70,140.07,39.96,-57.90,-52.56,132.24,87.96,74.67,42.94,98.70,81.96,108.50,55.15,138.88,159.63,158.79,122.70,64.12,135.28,75.40,69.26,29.87,138.97,26.34,93.45,9.39,99.93,208.24,289.14,63.14,325.73,260.50,419.88,336.83,367.64,485.98,488.43,491.84,457.78);

//Maximum terminal discounts allowed (range, upper range value %, decimal discount) - if area less than 8% of the country full discount is not applied
var maxUserDiscountRates = new Array (11);
maxUserDiscountRates[0] = new Array("0 to 0.1",0.001,0);
maxUserDiscountRates[1] = new Array("0.1 to 0.25",0.0025,0.23);			
maxUserDiscountRates[2] = new Array("0.25 to 0.5",0.005,0.4);
maxUserDiscountRates[3] = new Array("0.5 to 1",0.01,0.5);
maxUserDiscountRates[4] = new Array("1 to 2",0.02,0.6);
maxUserDiscountRates[5] = new Array("2 to 3",0.03,0.7);
maxUserDiscountRates[6] = new Array("3 to 4",0.04,0.76);
maxUserDiscountRates[7] = new Array("4 to 5",0.05,0.8);
maxUserDiscountRates[8] = new Array("5 to 6",0.06,0.83);
maxUserDiscountRates[9] = new Array("6 to 7",0.07,0.85);
maxUserDiscountRates[10] = new Array("7 to 8",0.08,0.865);	
		
//----------------------------------------------------------------LOCATION SEARCHING SCRIPTS	
	
//****************Create request object
function createRequestObject() {
	var ro;		
	if (window.XMLHttpRequest) { 				// Mozilla, Safari,...
		ro = new XMLHttpRequest();
		//if (ro.overrideMimeType) {
		//	ro.overrideMimeType('text/xml');
		//}
	}else if (window.ActiveXObject) { 			// IE
		try {
			ro = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			ro = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	return ro;			
}
//****************Runs database search for entered location	
function runSearch(){	
	if (document.frmLoc.txtLoc.value != ""){
		http = createRequestObject();
		http.open('get', 'searchLocation.php?search='+ document.frmLoc.txtLoc.value ); 
		document.getElementById("matches").style.display = "block"
		document.getElementById("matches").innerHTML = "<img src=\"images/5-1.gif\" />&nbsp;&nbsp;Searching for your location, please wait..."
		http.onreadystatechange = handleSearchResponse;
		http.send(null);
		//alert("hello")
		
	}else{
		alert("Please choose a centre point");
	}
}
function runSearch2011(){	
	if (document.frmLoc.txtLoc2011.value != ""){
		http = createRequestObject();
		http.open('get', 'searchLocation.php?search='+ document.frmLoc.txtLoc2011.value ); 
		document.getElementById("matches").style.display = "block"
		document.getElementById("matches").innerHTML = "<img src=\"images/5-1.gif\" />&nbsp;&nbsp;Searching for your location, please wait..."
		http.onreadystatechange = handleSearchResponse2011;
		http.send(null);
		//alert("hello")
		
	}else{
		alert("Please choose a centre point");
	}
}
function setNewLoc(){	
	if (document.getElementById("newLoc").value != ""){
		http = createRequestObject();
		http.open('get', 'updateLocation.php?search='+ document.getElementById("newLoc").value ); 
		//alert("sent")
		document.getElementById("notSet").innerHTML = "<img src=\"images/5-1.gif\" />"
		document.getElementById("changeLoc").style.display = 'none';
		http.onreadystatechange = handleUpdateResponse;
		http.send(null);
		
	}else{
		alert("Please enter a new centre point");
	}
}
function handleUpdateResponse() {
	if(http.readyState == 4){
		var uresponse = http.responseText;
		var responseArray = uresponse.split(",")
		var thex = Number(responseArray[0]);
		var they = Number(responseArray[1]);
		var zoomWidth = Number(responseArray[2]);
		var theSearch = responseArray[3];
		document.getElementById("notSet").innerHTML = theSearch + "&nbsp;&nbsp;";
		//alert(theSearch)
		if(theSearch!="Not Found"){
			if(typeof zoomToPoint == 'function') { 
				zoomToPoint(thex,they,zoomWidth)
			}
		}
		
		var loc = document.getElementById("newLoc").value
		if(document.getElementById("optHere")!=null){
			document.getElementById("optHere").style.marginTop = "-45px";
			document.getElementById("optHere").style.fontSize = "12px";
			document.getElementById("optHere").innerHTML = "<p id=\"whyLoc12011\"><a href=\"category.php?pid=28\">Buy a Wall Map centred on '"+loc+"'</a></p><p id=\"whyLoc22011\"><a href=\"category.php?pid=29\">Buy Map Data centred on '"+loc+"'</a></p>";
		}
	}
}
//****************Handles the response from running search
function handleSearchResponse() {
	if(http.readyState == 4){
		
		var response = http.responseText;

		//alert(response)
		var responseArray = response.split(",")
		var thex = Number(responseArray[0]);
		var they = Number(responseArray[1]);
		var zoomWidth = Number(responseArray[2]);
		document.getElementById("notSet").innerHTML = document.frmLoc.txtLoc.value + "&nbsp;&nbsp;";
		document.getElementById("matches").style.display = "block"
		
		var loc = document.frmLoc.txtLoc.value
		if(document.getElementById("optHere")!=null){
			document.getElementById("optHere").style.marginTop = "-45px";
			document.getElementById("optHere").style.fontSize = "12px";
			document.getElementById("optHere").innerHTML = "<p id=\"whyLoc1\"><a href=\"category.php?pid=28\">Buy a Wall Map centred on '"+loc+"'</a></p><p id=\"whyLoc2\"><a href=\"category.php?pid=29\">Buy Map Data centred on '"+loc+"'</a></p>";
		}
	
		zoomToPoint(thex,they,zoomWidth)
	}
}

function handleSearchResponse2011() {
	if(http.readyState == 4){
		
		var response = http.responseText;

		//alert(response)
		var responseArray = response.split(",")
		//alert(response)
		var thex = Number(responseArray[0]);
		var they = Number(responseArray[1]);
		var zoomWidth = Number(responseArray[2]);
		document.getElementById("notSet").innerHTML = document.frmLoc.txtLoc2011.value + "&nbsp;&nbsp;";
		document.getElementById("matches").style.display = "block"
		
		var loc = document.frmLoc.txtLoc2011.value
		if(document.getElementById("optHere")!=null){
			document.getElementById("optHere").style.marginTop = "-45px";
			document.getElementById("optHere").style.fontSize = "12px";
			document.getElementById("optHere").innerHTML = "<p id=\"whyLoc12011\"><a href=\"category.php?pid=28\">Buy a Wall Map centred on '"+loc+"'</a></p><p id=\"whyLoc22011\"><a href=\"category.php?pid=29\">Buy Map Data centred on '"+loc+"'</a></p>";
		}
	
		zoomToPoint(thex,they,zoomWidth)
	}
}

//****************Zooms to specificed location - called when choosing a match from the returned search matches
function showMap(selObj){
	var coordString = selObj.options[selObj.selectedIndex].value;
	var responseArray = coordString.split(",");
	var xLoc = Number(responseArray[0]);
	var yLoc = Number(responseArray[1]);
	var zoomWidth = Number(responseArray[2]);
	zoomToPoint(xLoc,yLoc,zoomWidth);		
}

//----------------------------------------------------------------GENERAL SCRIPTS
//------Set The visibility of Control Layers
function showLayers(theLayers){
    var tabImage = document.getElementById('tabImage');
	tabImage.src = "../images/" + theLayers + ".jpg";
	
	var allLayers = new Array("step0ON","step1ON","step2ON","step3ON"); 
	for(m=0; m < allLayers.length;m++){
		if (theLayers == allLayers[m]){
		  var layerObj = document.getElementById(allLayers[m]);
		  layerObj.className='layerOn';
		}else{
		  var layerObj = document.getElementById(allLayers[m]);
		  layerObj.className='layerOff';
		}
	}
}
//------Store the pre selected map data and scale
function storeMapData(theSelectedMapScale){

	//Check if an extent at scale is already showing - will need resizing
	if(document.frmSearch1.selectedMapScale.value != ""){
		if(vlayer.features.length > 0){
			if(document.frmSearch1.extentType.value == "scaled"){
				resizeExtent(theSelectedMapScale);
			}
		}
	}

	document.frmSearch1.selectedMapScale.value = theSelectedMapScale;
	
	//Remove all unit options
	var noCurrentOptions = eval("document.frmSearch1.txtMapUnits.options.length");
	for(var m=noCurrentOptions; m >= 0; m--){
		eval("document.frmSearch1.txtMapUnits.options[m] = null");
	}
	var noCurrentOptions = eval("document.frmSearch1.txtMapUnits2.options.length");
	for(var m=noCurrentOptions; m >= 0; m--){
		eval("document.frmSearch1.txtMapUnits2.options[m] = null");
	}
	
	//Amend the map units list to show print scales
	if(document.frmSearch1.selectedMapScale.value != ""){
		eval("document.frmSearch1.txtMapUnits.options[0]=new Option('km.','km')");
		eval("document.frmSearch1.txtMapUnits.options[1]=new Option('mi.','mi')");	
		eval("document.frmSearch1.txtMapUnits.options[2]=new Option('mm.','mm')");
		eval("document.frmSearch1.txtMapUnits.options[3]=new Option('cm.','cm')");
		eval("document.frmSearch1.txtMapUnits.options[4]=new Option('in.','in')");		
		eval("document.frmSearch1.txtMapUnits2.options[0]=new Option('km.','km')");
		eval("document.frmSearch1.txtMapUnits2.options[1]=new Option('mi.','mi')");	
		eval("document.frmSearch1.txtMapUnits2.options[2]=new Option('mm.','mm')");
		eval("document.frmSearch1.txtMapUnits2.options[3]=new Option('cm.','cm')");
		eval("document.frmSearch1.txtMapUnits2.options[4]=new Option('in.','in')");	
		//Show the extra extent options if user has chosen a data product 
		document.getElementById('CustomSizeOpts').style.display = 'block';
		document.getElementById('standardPaperOpts').style.display = 'block';
		document.getElementById('CustomSizeOptsMessage').style.display = 'none';
		document.getElementById('standardPaperOptsMessage').style.display = 'none';
			
	}else{
		eval("document.frmSearch1.txtMapUnits.options[0]=new Option('km.','km')");
		eval("document.frmSearch1.txtMapUnits.options[1]=new Option('mi.','mi')");
		eval("document.frmSearch1.txtMapUnits2.options[0]=new Option('km.','km')");
		eval("document.frmSearch1.txtMapUnits2.options[1]=new Option('mi.','mi')");		
		//Hide the extra extent options if user has chosen a data product 
		document.getElementById('CustomSizeOpts').style.display = 'none';
		document.getElementById('standardPaperOpts').style.display = 'none';
		document.getElementById('CustomSizeOptsMessage').style.display = 'block';
		document.getElementById('standardPaperOptsMessage').style.display = 'block';	
	}
	
	updateFixedExtentSizes();
	document.getElementById("gotostep2").style.display = 'block'	
}
//------Updates the list of avaialable map radius sizes to agree with the select unit
function updateFixedExtentSizes(){

	//Remove all radius options
	var noCurrentOptions = eval("document.frmSearch1.txtRadius.options.length");
	for(var m=noCurrentOptions; m >= 0; m--){
		eval("document.frmSearch1.txtRadius.options[m] = null");
	}
	
	//Recreate the list of fixed radius based on selected unit
	if(document.frmSearch1.txtMapUnits.value == "in"){
		eval("document.frmSearch1.txtRadius.options[0]=new Option('Select a Print Area','')");
		eval("document.frmSearch1.txtRadius.options[1]=new Option('30 in','30')");
		eval("document.frmSearch1.txtRadius.options[2]=new Option('50 in','50')");
		eval("document.frmSearch1.txtRadius.options[3]=new Option('100 in','100')");
		eval("document.frmSearch1.txtRadius.options[4]=new Option('150 in','150')");
		eval("document.frmSearch1.txtRadius.options[5]=new Option('200 in','200')");
	}else if(document.frmSearch1.txtMapUnits.value == "cm"){
		eval("document.frmSearch1.txtRadius.options[0]=new Option('Select a Print Area','')");
		eval("document.frmSearch1.txtRadius.options[1]=new Option('30 cm','30')");
		eval("document.frmSearch1.txtRadius.options[2]=new Option('50 cm','50')");
		eval("document.frmSearch1.txtRadius.options[3]=new Option('100 cm','100')");
		eval("document.frmSearch1.txtRadius.options[4]=new Option('150 cm','150')");
		eval("document.frmSearch1.txtRadius.options[5]=new Option('200cm','200')");
	}else if(document.frmSearch1.txtMapUnits.value == "mm"){
		eval("document.frmSearch1.txtRadius.options[0]=new Option('Select a Print Area','')");
		eval("document.frmSearch1.txtRadius.options[1]=new Option('300 mm.','300')");
		eval("document.frmSearch1.txtRadius.options[2]=new Option('500 mm.','500')");
		eval("document.frmSearch1.txtRadius.options[3]=new Option('1000 mm.','1000')");
		eval("document.frmSearch1.txtRadius.options[4]=new Option('1500 mm.','1500')");
		eval("document.frmSearch1.txtRadius.options[5]=new Option('2000 mm.','2000')");
	}else if(document.frmSearch1.txtMapUnits.value == "km"){
		eval("document.frmSearch1.txtRadius.options[0]=new Option('Select a Area','')");
		eval("document.frmSearch1.txtRadius.options[1]=new Option('5 km.','5')");
		eval("document.frmSearch1.txtRadius.options[2]=new Option('10 km.','10')");
		eval("document.frmSearch1.txtRadius.options[3]=new Option('15 km.','15')");
		eval("document.frmSearch1.txtRadius.options[4]=new Option('25 km.','25')");
		eval("document.frmSearch1.txtRadius.options[5]=new Option('50 km.','50')");
		eval("document.frmSearch1.txtRadius.options[6]=new Option('75 km.','75')");
	}else if(document.frmSearch1.txtMapUnits.value == "mi"){
		eval("document.frmSearch1.txtRadius.options[0]=new Option('Select a Area','')");
		eval("document.frmSearch1.txtRadius.options[1]=new Option('5 mi.','5')");
		eval("document.frmSearch1.txtRadius.options[2]=new Option('10 mi.','10')");
		eval("document.frmSearch1.txtRadius.options[3]=new Option('15 mi.','15')");
		eval("document.frmSearch1.txtRadius.options[4]=new Option('25 mi.','25')");
		eval("document.frmSearch1.txtRadius.options[5]=new Option('50 mi.','50')");
		eval("document.frmSearch1.txtRadius.options[6]=new Option('75 mi.','75')");
	}
}

//------Updates the list of avaialable radial sizes to agree with the select unit
function updateRadialSizes(){

	//Remove all radius options
	var noCurrentOptions = eval("document.frmSearch1.txtRadials.options.length");
	for(var m=noCurrentOptions; m >= 0; m--){
		eval("document.frmSearch1.txtRadials.options[m] = null");
	}
	
	//Recreate the list of fixed radius based on selected unit
	if(document.frmSearch1.txtRadialUnits.value == "km"){
		eval("document.frmSearch1.txtRadials.options[0]=new Option('Select a Radial','')");
		eval("document.frmSearch1.txtRadials.options[1]=new Option('Every 1 km.','1')");
		eval("document.frmSearch1.txtRadials.options[2]=new Option('Every 2 km.','2')");
		eval("document.frmSearch1.txtRadials.options[3]=new Option('Every 3 km.','3')");
		eval("document.frmSearch1.txtRadials.options[4]=new Option('Every 5 km.','5')");
		eval("document.frmSearch1.txtRadials.options[5]=new Option('Every 10 km.','10')");
		eval("document.frmSearch1.txtRadials.options[6]=new Option('Every 20 km.','20')");
	}else if(document.frmSearch1.txtRadialUnits.value == "mi"){
		eval("document.frmSearch1.txtRadials.options[0]=new Option('Select a Radial','')");
		eval("document.frmSearch1.txtRadials.options[1]=new Option('Every 1 mi.','1')");
		eval("document.frmSearch1.txtRadials.options[2]=new Option('Every 2 mi.','2')");
		eval("document.frmSearch1.txtRadials.options[3]=new Option('Every 3 mi.','3')");
		eval("document.frmSearch1.txtRadials.options[4]=new Option('Every 5 mi.','5')");
		eval("document.frmSearch1.txtRadials.options[5]=new Option('Every 10 mi.','10')");
		eval("document.frmSearch1.txtRadials.options[6]=new Option('Every 20 mi.','20')");
	}
}
//----------Opens a new window
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}
//----------Clears the map colour value
function resetColor(){
	document.getElementById('txtColor').value=''
}
//----------Checks the number of boundaries selected does not exceed the limit
function checkboxlimit(checkgroup, limit, type){
	var theType = type;
	var checkgroup=checkgroup;
	var limit=limit;
	for (var i=0; i<checkgroup.length; i++){
		checkgroup[i].onclick=function(){
		var checkedcount=0;
		for (var i=0; i<checkgroup.length; i++)
			checkedcount+=(checkgroup[i].checked)? 1 : 0
			if (checkedcount>limit){
				alert("You can only select a maximum of "+limit+" "+theType);
				this.checked=false;
			}
		}
	}
}
//----------Toggles the displayd map size on confirmation page between mm and "
function displaySize(type,width,height,id){
	
	var theType = type;
	var theID = id;
	var theWidth = width;
	var theHeight = height;
	
	if (theType=='inches'){
		document.getElementById('theWidth'+theID).innerHTML = theWidth;
		document.getElementById('theHeight'+theID).innerHTML = theHeight;
		document.getElementById('inches'+theID).style.display = 'none';
		document.getElementById('cm'+theID).style.display = 'inline';
	}else{
		document.getElementById('theWidth'+theID).innerHTML = theWidth;
		document.getElementById('theHeight'+theID).innerHTML = theHeight;
		document.getElementById('inches'+theID).style.display = 'inline';

		document.getElementById('cm'+theID).style.display = 'none';
	}	
}
//----------Passes selected map info thru to shopping basket
function buyNow(id){
	var theId = id
	if(document.getElementById('buynowlayer'+theId).style.backgroundImage == "url(images/contactUsBack.png)"){
		alert("Please contact the business team on 0845 450 3667 to discuss pricing for this map.");
	}else{
		if(document.getElementById('theFinish'+theId).value==""){
			alert('Please Select a finish before adding to your basket!');
		}else{
			document.getElementById('frmBuy'+theId).action = "http://www.mapsinternational.co.uk/addCustom.asp?id="+theId;
			var theForm = document.getElementById('frmBuy'+theId);
			theForm.submit();
		}
	}
}	
//----------Displays other map options on the confirmation page	
function showAllMaps(totalMaps){
	for(c=0;c<totalMaps;c++){
		var layerName = "container" + (c+1);
		document.getElementById(layerName).style.display = 'block';
	}
	document.getElementById("messagediv").style.display = 'none';			//Hide the message
}	
//******************Runs query to zoom to a county/region
function zoomToCounty(selObject){
	var searchString = selObject.value;			//**Get selected county	
	if(searchString != ""){				
		http = createRequestObject();
		http.open('get', '../maptools/zoomtoarea.asp?search=' + searchString ); 
		http.onreadystatechange = zoomToCountyResponse;
		http.send(null);	
	}else{
		alert("Ensure a county is selected"); 
	}				
}	
function zoomToCountyResponse(){
	if(http.readyState == 4){	
		//Get the returned values
		var response = http.responseText;		
		var tempArray = new Array();
		tempArray = response.split("|"); 	
		if(tempArray[0] == "ok"){					//Zoom to county
			addExtent(tempArray[1], "region");
		}else{										//Show message
			alert("Selected region could not be found");
		}								
	}
}
//----------Shows avaialable map type or goes to next stage
function chooseMapping(theAction){		
	if(theAction == "yes"){
		document.getElementById('alldatasets').style.display = 'block';
	}else if(theAction == "no"){
		storeMapData('','');	
		showLayers('step1ON');
	}
}	
function chooseMappingAfter(theAction){		
	if(theAction == "yes"){
		document.getElementById('alldatasets').style.display = 'block';
	}else if(theAction == "no"){	
		storeMapData('');
		showLayers('step1ON');
		
	}
}	
	
//----------------------------------------------------------------PRICING SCRIPTS

//----------Loop through each map product and work out the price
function getAllPrices(xSize,ySize,theFinish,ID,displayFinish,addOns){
	//Once the selected map item has been updated - change all the rest for comparative purposes
	for(c=1;c <= maxNoProducts; c++){
		if(document.getElementById('thePrice'+String(c))!= null){				//Check the product is showing
			xSize = document.getElementById('mapwidth'+String(c)).value;
			ySize = document.getElementById('mapheight'+String(c)).value;
			mapScale = document.getElementById('mapscale'+String(c)).value;
			dataID = document.getElementById('dataID'+String(c)).value;
			getPrice(xSize,ySize,theFinish,c,displayFinish,addOns,mapScale,dataID);
		}
	}
}

//----------Work out the map price			
function getPrice(xSize,ySize,theFinish,ID,displayFinish,addOns,mapScale,dataID){		
	var theAddOns = addOns;
	var theDisplayFinish = displayFinish;
	var theID = ID;
	var thePrice = 0;
	//var extraOS25kPrice = 0;

	if(theFinish == "floor"){									//Pricing on request for flooring
		document.getElementById('thePrice'+theID).value = "Price on request.";
		document.getElementById('theFinish'+theID).value = "";
		document.getElementById('thePrice'+theID).style.fontSize = '15px';
		document.getElementById('buynowlayer'+theID).style.backgroundImage = "url(images/contactUsBack.png)";	
	}else{
		//NEEDED
		//if(mapScale == "25,000"){										//Define the value of the xtra price added for OS25k	
		//	var xGroundSizeKm = (xSize * 25000)/1000;
		//	var yGroundSizeKm = (ySize * 25000)/1000;
		//	extraOS25kPrice =  ((xGroundSizeKm) * (yGroundSizeKm)) * extraOS25kPriceperKm;
		//}
		
		if((Number(xSize) != 0) && (Number(ySize != 0)) && (theFinish != "")){
			//Set up base price arrays and associated size array.
	
			//Set up size arrays (short side size, valid long side sizes...)
			var sizes = new Array (22);			
			sizes[0] = new Array(21,30);
			sizes[1] = new Array(30,42);
			sizes[2] = new Array(42,60);
			sizes[3] = new Array(70,100);
			sizes[4] = new Array(88,120,130,140,150,160,170,180,190,200,250,300,350,400,450,500);
			sizes[5] = new Array(100,100,110,120,130,140,150,160,170,180,190,200,250,300,350,400,450,500);
			sizes[6] = new Array(110,110,120,130,140,150,160,170,180,190,200,250,300,350,400,450,500);
			sizes[7] = new Array(120,120,130,140,150,160,170,180,190,200,250,300,350,400,450,500);
			sizes[8] = new Array(130,130,140,150,160,170,180,190,200,250,300,350,400,450,500);
			sizes[9] = new Array(140,140,150,160,170,180,190,200,250,300,350,400,450,500);
			sizes[10] = new Array(150,150,160,170,180,190,200,250,300,350,400,450,500);
			sizes[11] = new Array(160,160,170,180,190,200,250,300,350,400,450,500);
			sizes[12] = new Array(170,170,180,190,200,250,300,350,400,450,500);
			sizes[13] = new Array(180,180,190,200,250,300,350,400,450,500);
			sizes[14] = new Array(190,190,200,250,300,350,400,450,500);
			sizes[15] = new Array(200,200,250,300,350,400,450,500);
			sizes[16] = new Array(250,250,300,350,400,450,500);
			sizes[17] = new Array(300,300,350,400,450,500);
			sizes[18] = new Array(350,350,400,450,500);
			sizes[19] = new Array(400,400,450,500);
			sizes[20] = new Array(450,450,500);
			sizes[21] = new Array(500,500);
	
			if((xSize*100) > (ySize*100)){
				var longSide = (xSize*100);
				var shortSide = (ySize*100);
			}
			else{	
				var longSide = (ySize*100);
				var shortSide = (xSize*100);
			}
			//Ensure size does not exceed the max size used for pricing
			if(longSide > 500){
				longSide = 500;
			}
			if(shortSide > 500){
				shortSide = 500;
			}
	
			for(var s=0;s<sizes.length;s++){ 	
				if(sizes[s][0] >= shortSide){
					newIndex = s;
					var arrayLen = sizes[newIndex].length;
					newIndex2 = -1
					for(var s2=1;s2<arrayLen;s2++){
						if(sizes[newIndex][s2] >= longSide){
							newIndex2 = s2;					
						}
						if(newIndex2 != -1){
							break;
						}	
					}
					if(newIndex2 != -1){
						break;
					}					
				}	
			}
	
			var sizeString =  String(sizes[newIndex][0]) + "x" + String(sizes[newIndex][newIndex2]);
	
			//Define the price by matching with pre-defined sizes in the size array.
			var testIndex = -99;
			for(var p=0;p<173;p++){
				if(theSizes[p] == sizeString){
					testIndex = p + 1;
					break;
				}
			}		
			
			var philipsProductionCharge = 0;
			if(testIndex != -99){
				for(var p=0;p<7;p++){
					if(customPrices[p][0] == theFinish){
						if((dataID == "mv40raster") || (dataID == "mv100raster") || (dataID == "mv200raster") || (dataID == "mv625raster")){		//Use old pricing matrix for these soon to be defunkt products
							thePrice = customPricesOLD[p][testIndex];
						}else{
							thePrice = customPrices[p][testIndex];
						}	
						philipsProductionCharge = theProductionCharges[testIndex-1];
						break;
					}	
				}
			}
			else{
				thePrice = 0;
			}
		}
		//alert(dataID + "  base " + String(thePrice))
		
		//Price adjustmets
		if((thePrice != 0) && (thePrice != -99)){
			var addRoyalty = "";
			var addPriceperkm = 0;
			var addFixedCost = "0";
			for(p=0; p < pricingStructure.length;p++){
				if(pricingStructure[p][0] == dataID){
					addRoyalty = pricingStructure[p][5];
					addPriceperkm = pricingStructure[p][1];
					addFixedCost = pricingStructure[p][6];
					break;
				}
			}
			//Add print royaly
			printRoyalty = 0
			if(addRoyalty == "yes"){
				var xPrintSizeCm = (xSize * 100);
				var yPrintSizeCm = (ySize * 100);	
				//alert(String(xPrintSizeCm) + "," + String(yPrintSizeCm))
				var sqCm = (xPrintSizeCm * yPrintSizeCm);
				printRoyalty = ((sqCm / 1248) * 0.35);
				thePrice = thePrice + printRoyalty;				
				//Print Royalty (formula - (sqcm / 1248) * 0.35)
				//alert("sqCm"  + String(sqCm))
				//alert(dataID + "  printRoyalty " + String(printRoyalty))
			}
			//Add cost/km2
			priceperkm = 0
			if(addPriceperkm != 0){			
				var mapScaleAsNumeric = Number(mapScale.replace(",",""));
				var xGroundSizeKm = (xSize * mapScaleAsNumeric)/1000;
				var yGroundSizeKm = (ySize * mapScaleAsNumeric)/1000;
				var sqKm = (xGroundSizeKm * yGroundSizeKm);
				var priceperkm = sqKm * addPriceperkm;
				
				//Define the area ordered and % of UK
				var percentageOfUK = (sqKm / totalUKareaKm) * 100;
				//alert(percentageOfUK)
				//alert("sqKm " + String(sqKm))
				//alert(dataID + " priceperkm " + String(priceperkm))
				//alert(percentageOfUK)
				
				//Discount the price per km value
				//Apply discount for number of users (Always 1 user)
				var userDiscount = 0.875;
						
				//Check that the calculated discount is not greater than that allowd based on the % of the UK bought
				var theMaxUserDiscount = 0.875;	
				var pctCovTotest = percentageOfUK / 100;
				
				for(p=0;p<maxUserDiscountRates.length;p++){					
					if(pctCovTotest <  maxUserDiscountRates[p][1]){
						theMaxUserDiscount = maxUserDiscountRates[p][2];
						break;
					}					
				}
				if(userDiscount > theMaxUserDiscount){
					userDiscount = theMaxUserDiscount;						
				}		
				//alert(dataID + " userDiscount " + String(userDiscount))
				discountValue = (priceperkm * userDiscount);
				//alert(dataID + " discountValue " + String(discountValue))
				thePrice = (thePrice + priceperkm) - discountValue;
				//alert(dataID + " price " + String(thePrice) + "  philipsProductionCharge " + philipsProductionCharge)				
			}
			//Add a fixed cost
			extraCost = 0
			if(addFixedCost != "0"){
				if(addFixedCost.substring((addFixedCost.length-1), (addFixedCost.length)) == "%"){
					var extraCost = thePrice * (Number(addFixedCost.substring(0, (addFixedCost.length-1))) /100);
				}else{
					var extraCost = Number(addFixedCost);
				}
				//alert("extraCost  " + String(extraCost))
				thePrice = thePrice + extraCost;
			}
		
			//Add philips production charge if necessary
			if((dataID == "philips10k") || (dataID == "philips18")){
				thePrice = thePrice + philipsProductionCharge;
			}
	
			//Add the extras
			thePrice = thePrice + theAddOns;
		
		}
		
		//alert(dataID + "__" + String(printRoyalty) + "__" + String(priceperkm) + "__" + String(extraCost) + "__" + String(theAddOns) + "__" + String(thePrice))
		if((thePrice == 0) || (thePrice == -99)){
			document.getElementById('thePrice'+theID).value = "Price on request.";
			document.getElementById('theFinish'+theID).value = "";
			document.getElementById('thePrice'+theID).style.fontSize = '15px';
			document.getElementById('buynowlayer'+theID).style.backgroundImage = "url(images/contactUsBack.png)";	
		
		}else{
		
			//NEEDED
			//if(mapScale == "25,000"){										//Add the value of the xtra price added for OS25k
			//	thePrice += extraOS25kPrice; 
			//}
			
			
			thePrice = formatPrice(Math.round(thePrice));			//Format price to 0 dec places
			document.getElementById('thePrice'+theID).value = "�"+thePrice;
			document.getElementById('theFinish'+theID).value = displayFinish;
			document.getElementById('thePrice'+theID).style.fontSize = '30px';
			document.getElementById('buynowlayer'+theID).style.backgroundImage = "url(../maptools/images/buyNowBack.png)";
		}
		
	}

}
//****************Function to ensure zeros displayed at end of price	
function formatPrice(passedPrice) {   
	inPrice = String(passedPrice);
	var testLen1 = inPrice.length;
	var sep = inPrice.indexOf(".");
	//if(sep == -1){		
	//	inPrice = inPrice + ".00";
	//}else{
		var rest = inPrice.substring(0,(sep+1))  
		var testLen2 = rest.length;
		if(testLen1 == (testLen2 + 1)){
			inPrice = inPrice + "0";
		}
	//}
	return(inPrice);
}

/*Not needed??

function checkboxlimit(checkgroup, limit){
	var checkgroup=checkgroup
	var limit=limit
	for (var i=0; i<checkgroup.length; i++){
		checkgroup[i].onclick=function(){
		var checkedcount=0
		for (var i=0; i<checkgroup.length; i++)
			checkedcount+=(checkgroup[i].checked)? 1 : 0
		if (checkedcount>limit){
			alert("You can select a maximum of 2 boundaries")

			this.checked=false
			}
		}
	}
}

function checkboxlimitPC(checkgroup, limit){
	var checkgroup=checkgroup
	var limit=limit
	for (var i=0; i<checkgroup.length; i++){
		checkgroup[i].onclick=function(){
		var checkedcount=0
		for (var i=0; i<checkgroup.length; i++)
			checkedcount+=(checkgroup[i].checked)? 1 : 0
		if (checkedcount>limit){
			alert("You can select a maximum of 1 postcode")
			this.checked=false
			}
		}
	}
}

	function showLayer(theLayer, chk){		

		if(theLayer == 'vlayer'){
			var layerObj = vlayer	
		}
		else{
			var layerObj = rlayer
		}
				
		if (chk.checked){	
				layerObj.setVisibility(true)
			}
			else{
				layerObj.setVisibility(false)
			}
	}
function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
}
function handleCitySearchResponse() {
	if(http.readyState == 4){
		var theResults = http.responseText;
		document.getElementById("townPlans").innerHTML = theResults	
	}
}
function runAfricaSearch(theCity){			
	var searchTerm = theCity
	http = createRequestObject();
	http.open('get', 'searchTowns.asp?continent=' + searchTerm ); 
	http.onreadystatechange = handleCitySearchResponse;
	http.send(null);	
}
*/
//--------------------------End of Script
