/***********************************************
 *  Feedback page functions
 * 
 *
 * * * * * * * * * * * * * * * * * * * * * * * */

//common variables
var firstOptionValue = "Please select:";


var devicelist;
var versionList;
if (mapsVersionNumber == 2) { //mapsVersionNumber must be set for this to work
  deviceList = new Array("5320 XpressMusic","5630 XpressMusic","5730 XpressMusic","5800 XpressMusic","6110 Navigator","6120 Classic","6121 Classic","6124 Classic","6210 Navigator","6220 Classic","6290","66650 Fold","6710 Classic","6720 Classic","6730 Classic","E51","E52","E55","E63","E66","E71","E75","E90","N76","N78","N79","N81","N81 8GB","N82","N85","N86 8MP","N95","N95 8GB","N96","N97");
  versionList = new Array("v2.0_wk05_b11","v2.0_wk16_b02","v2.0_wk18_b03",
                          "v2.0_wk19_b04","v2.0_wk21_b,2","v2.0_wk22_b04","v2.0_wk24_b02","v2.0_wk26_b02","v2.0_wk30_b04","v2.0_wk32_b04","v2.0_wk42_b01 (T)","v2.0_wk45_b03","v2.0_wk39_b04","v3.00_wk18_b01","v3.00_wk24_b01","v3.00_wk26_b01","v3.00_wk26_b02","v3.01_wk25_b04","v3.01_wk26_b01","v3.01_wk26_b02","v3.01_wk34_b02","v3.01_wk36_b01","v3.01_wk38_b02","v3.01_wk44_b01","v.3.03_wk03_b04","v.3.03_wk10_b02","v.3.04_wk17_b07");
} else if (mapsVersionNumber == 1) {
  deviceList = new Array("5700 XpressMusic","E50","E60","E61","E61i","E62","E65","E70","N73","N75","N77","N80","N93i");
  versionList = new Array("v3.x_generic", "v1.2_wk37_b05", "v1.2_wk38_b02", "v1.2_wk41_b01", "v1.2_wk43_b01",
                          "v1.2_wk45_b02", "v1.2_wk47_b05", "v1.2_wk48_b01", "v1.2_wk07_b02");
}



var countryList = new Array("AUSTRIA", "AUSTRALIA", "BAHRAIN", "BELGIUM", "BRAZIL", "CANADA",
                            "CHINA / HONG KONG / MACAU", "CROATIA", "CZECH REPUBLIC", "DENMARK",
                            "EGYPT", "ESTONIA", "FINLAND", "FRANCE (MONACO, ANDORRA)", "GERMANY", 
                            "GREAT BRITAIN", "GREECE", "HUNGARY", "INDIA", "INDONESIA", "IRELAND",
                            "ITALY (VATICAN, SAN MARINO)", "KUWAIT", "LATVIA", "LIECHTENSTEIN",
                            "LITHUANIA", "LUXEMBOURG", "MALAYSIA", "MEXICO", "NETHERLANDS", "NORWAY",
                            "OMAN", "POLAND", "PORTUGAL", "PUERTO RICO", "QATAR", "RUSSIA", 
                            "SAUDI ARABIA", "SINGAPORE", "SLOVAKIA", "SLOVENIA", "SOUTH AFRICA", 
                            "SPAIN (GIBRALTAR)", "SWEDEN", "SWITZERLAND", "TAIWAN", "THAILAND", 
                            "TURKEY", "UNITED ARAB EMIRATES", "USA");

var voiceCommands = new Array("turn sharply right", "turn sharply left", "keep straight", 
                              "turn right", "turn left", "no command", "turn slightly right", 
                              "turn slightly left", "other", "keep right", "keep left");

var emailerTool = "/lv1web/public_pageflows/EmailerToolProcessor/EmailerToolProcessorController.jpf";
var emailerToolId = 852;

//page flow data structure
//fields:
//  0 -> title, string
//  1 -> previous page, integer
//  2 -> current page, integer
//  3 -> next page, integer
//  4 -> buttons, 0 = neither, 1 = "back", 2 = "back" and "submit" (note: "continue" is always present)

//rout setting variable
var transportModeWalk = 0;

//routing feedback

var fbLayout; 
if (mapsVersionNumber == 2) {
  fbLayout = [ 
               [ 
                 ["Please select feedback type!", -1, 0, 1, 0], 
                 ["Platform info - Step 1 of 10", 0, 1, 2, 1], 
                 ["Start location - Step 2 of 10", 1, 2, 3, 1],
                 ["Destination - Step 3 of 10", 2, 3, 4, 1], 
                 ["Error point - Step 4 of 10", 3, 4, 5, 1], 
                 ["Preferred route - Step 5 of 10", 4, 5, 6, 1],
                 ["Transport mode - Step 6 of 10", 5, 6, 7, 1], 
                 ["Route settings - Step 7 of 10", 6, 7, 8, 1], 
            ["Recalculated route - Step 8 of 10", 7, 8, 9, 1],
				  ["Your opinion - Step 9 of 10", 8, 12, 10, 1],
        ["Your routing feedback - Step 10 of 10", 9, 9, 4, 2]
               ],[ 
                 ["Please select feedback type!", -1, 0, 1, 0], 
                 ["Platform info - Step 1 of 9", 0, 1, 2, 1], 
                 ["Start location - Step 2 of 9", 1, 2, 3, 1],
                 ["Destination - Step 3 of 9", 2, 3, 4, 1], 
                 ["Error point - Step 4 of 9", 3, 4, 5, 1], 
                 ["Commands given - Step 5 of 9", 4, 10, 6, 1],
                 ["Transport mode - Step 6 of 9", 5, 6, 7, 1], 
                // ["Route settings - Step 7 of 9", 6, 7, 8, 1], 
          ["Recalculated route - Step 7 of 9", 6, 8, 8, 1],
			    ["Your opinion - Step 8 of 9", 7, 12, 9, 1],
     ["Your guidance feedback - Step 9 of 9", 8, 11, 4, 2] 
               ]
             ];
} else if (mapsVersionNumber == 1) {
  fbLayout = [ 
               [ 
                 ["Please select feedback type!", -1, 0, 1, 0], 
                 ["Platform info - Step 1 of 8", 0, 1, 2, 1], 
                 ["Start location - Step 2 of 8", 1, 2, 3, 1],
                 ["Destination - Step 3 of 8", 2, 3, 4, 1], 
                 ["Error point - Step 4 of 8", 3, 4, 5, 1], 
                 ["Preferred route - Step 5 of 8", 4, 5, 6, 1],
                 ["Route settings - Step 6 of 8", 5, 7, 7, 1], 
                 ["Recalculated route - Step 7 of 8", 6, 8, 8, 1],
                 ["Your routing feedback - Step 8 of 8", 7, 9, 4, 2] 
               ],[ 
                 ["Please select feedback type!", -1, 0, 1, 0], 
                 ["Platform info - Step 1 of 8", 0, 1, 2, 1], 
                 ["Start location - Step 2 of 8", 1, 2, 3, 1],
                 ["Destination - Step 3 of 8", 2, 3, 4, 1], 
                 ["Error point - Step 4 of 8", 3, 4, 5, 1], 
                 ["Commands given - Step 5 of 8", 4, 10, 6, 1],
                 ["Route settings - Step 6 of 8", 5, 7, 7, 1], 
                 ["Recalculated route - Step 7 of 8", 6, 8, 8, 1],
                 ["Your guidance feedback - Step 8 of 8", 7, 11, 4, 2] 
               ]
             ];
}

var firstPage = true;

/*
 * Code below executes stuff after the DOM is loaded
 */
var alreadyrunflag=0 //flag to indicate whether target function has already been run

/*if (document.addEventListener)
  document.addEventListener("DOMContentLoaded", function(){alreadyrunflag=1; handleParams()}, false)
else if (document.all && !window.opera){
  document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
  var contentloadtag=document.getElementById("contentloadtag")
  contentloadtag.onreadystatechange=function(){
    if (this.readyState=="complete"){
      alreadyrunflag=1
     handleParams()
    }
  }
}

window.onload=function(){
  setTimeout("if (!alreadyrunflag) handleParams()", 0)
}*/
/*
 * End DOM-loaded check code
 */

function handleParams() {
  var params = document.location.href;
  var paramArray = params.split('?');
  if (paramArray[1] != undefined) {
    /*goToPage(paramArray[1]);*/
  }
}

var fbType; //0 = routing, 1 = guidance*/
var fbIndex = 0; //index of the current page in fbLayout

var fbDivs; //an array holding all feedback pages

//error message:
var errroBox;

//buttons:
var backButtonBox;
var submitButtonBox;
var continueButtonBox;

//
// Form fields
//

//device and maps
var device;
var mapsVer;

//start address
var startStreet;
var startCity;
var startZip;
var startHouse;
var startCountry;
var startCountryIndex;

//destinationa address
var destStreet;
var destCity;
var destZip;
var destHouse;
var destCountry;

//error route
var errorStreet;
var errorOptional;
var errorCity;
var errorCountry;

//preferred route
var preferredStreet;
var preferredOptional;
var preferredCity;
var preferredCountry;

//transport mode, route selection and reroute check
var transportMode;
var routeSelection;
var rerouteCheck;

//voice commands
var receivedCommand;
var expectedCommand;

//opinion
var yourOpinion;


//waypoint arrays
var arrErrorPoints; 
var arrPreferredRoutes;
var arrVoiceCommands;

//make sure that the 0th option is not selected
function validateSelect(sel) {
  if (sel.selectedIndex == 0) {
    sel.style.backgroundColor = "#FFBFBF";
    return 0;
  } else {
    sel.style.backgroundColor = "white";
    return 1;
  }
}

function validateInput(type, element) {
  var validInput = 0;
  switch(type) {
  case "opt":
    if (element.value.length == 0) {
      validInput = 1;
      break;
    }
  case "street":
  case "city":
    if (element.value.length > 0 && element.value.length <= 40) {
      validInput = 1;
    } else {
      validInput = 0;
    }
    break;
  case "house":
  if (element.value.length == 0) {
      validInput = 1;
      break;
    }
    if (element.value.length > 0 && element.value.length <= 5) {
      validInput = 1;
    } else {
      validInput = 0;
    }
    break;
  case "zip":
    if (element.value.length == 0) {
      validInput = 1;
      break;
    }

    if (element.value.length > 0 && element.value.length <= 8) {
      validInput = 1;
    } else {
      validInput = 0;
    }
    break;
	//opinion check
	case "opinion":
    if (element.value.length <= 500) {
      validInput = 1;
      break;
    }

 //   if (element.value.length > 0 && element.value.length <= 5) {
   //   validInput = 1;
   // } else {
     // validInput = 0;
    // }
    break;
	
  }
  if (validInput == 0) {
    element.style.backgroundColor = "#FFBFBF";
    return 0;
  } else {
    element.style.backgroundColor = "white";
    return 1;
  }
}


function highlightRadioButtonBox(box, validVal) {
  if (validVal == 1) {
    box.style.borderWidth = "0px";
  } else {
    box.style.borderWidth = "1px;";
  }
}

function displayInfoPopup(id) {
  var element = document.getElementById(id);
  element.style.display = "block";
  document.onclick = function() {
    element.style.display = "none";
  }
}

function closeInfoPopup(id) {
  var element = document.getElementById(id);
  element.style.display = "none";
  document.onclick = '';
}





function validatePage(page) {
  var validVal = 0;
  errorBox = document.getElementById('formErrorContainer');
  switch(page) {
    case 0:
      var chBox1 = document.getElementById("radioRouting");
      if(chBox1.checked) {
        fbType = 0;
        validVal = 1;
      }
      
      var chBox2 = document.getElementById("radioGuidance");
      if(chBox2.checked) {
        fbType = 1;
        validVal = 1;
      }
      
      //init the waypoint arrays
      arrErrorPoints = new Array();
      arrPreferredRoutes = new Array();
      arrVoiceCommands = new Array();
      
      var radioBBox = document.getElementById('fbTypeRadio');
      highlightRadioButtonBox(radioBBox, validVal);
      break;
    case 1:
      //device and maps
      var sel = document.getElementById("selectDevices");
      if (validateSelect(sel) == 0) { 
        validVal *= 0;
      } else { 
        device = sel[sel.selectedIndex];
        validVal = 1;
      }

      sel = document.getElementById("selectMapsVersion");
      if (validateSelect(sel) == 0) {
        validVal *= 0;
      } else { 
        mapsVer = sel[sel.selectedIndex];
        validVal *= 1;
      }

      break;
    case 2:
      //start address
      validVal = validateInput("street", startStreet = document.getElementById('txtStartStreet'));
      validVal *= validateInput("city", startCity = document.getElementById('txtStartCity'));
      validVal *= validateInput("house", startHouse = document.getElementById('txtStartHouse'));
      validVal *= validateInput("zip", startZip = document.getElementById('txtStartZip'));

      sel = document.getElementById("selectStartCountry");
      if (validateSelect(sel) == 0) {
        validVal *= 0;
      } else { 
        startCountry = sel[sel.selectedIndex];
        startCountryIndex = sel.selectedIndex;
        validVal *= 1;
      }

      if (validVal == 1) {
        //preset the next values for country and city
        var sel = document.getElementById("selectDestCountry");
        sel.selectedIndex = startCountryIndex;
        sel = document.getElementById("selectErrorCountry");
        sel.selectedIndex = startCountryIndex;
        sel = document.getElementById("selectPreferredCountry");
        sel.selectedIndex = startCountryIndex;
        
        destCity = document.getElementById('txtDestCity');
        errorCity = document.getElementById('txtErrorCity');
        preferredCity = document.getElementById('txtPreferredCity');
        preferredCity.value = errorCity.value = destCity.value = startCity.value;
      }
      break;
    case 3:
      //destination address
      validVal = validateInput("street", destStreet = document.getElementById('txtDestStreet'));
      validVal *= validateInput("city", destCity = document.getElementById('txtDestCity'));
      validVal *= validateInput("house", destHouse = document.getElementById('txtDestHouse'));
      validVal *= validateInput("zip", destZip = document.getElementById('txtDestZip'));

      sel = document.getElementById("selectDestCountry");
      if (validateSelect(sel) == 0) {
        validVal *= 0;
      } else { 
        destCountry = sel[sel.selectedIndex];
        validVal *= 1;
      }
      break;
    //error point - put stuff into array
    case 4:
      //error route
      validVal = validateInput("street", errorStreet = document.getElementById('txtErrorStreet'));
      validVal *= validateInput("opt", errorOptional = document.getElementById('txtErrorOptional'));
      validVal *= validateInput("city", errorCity = document.getElementById('txtErrorCity'));

      var sel = document.getElementById("selectErrorCountry");
      if (validateSelect(sel) == 0) {
        validVal *= 0;
      } else { 
        errorCountry = sel[sel.selectedIndex];
      }
      break;
    case 5:
      //preferred route
      validVal = validateInput("street", preferredStreet = document.getElementById('txtPreferredStreet'));
      validVal *= validateInput("opt", preferredOptional = document.getElementById('txtPreferredOptional'));
      validVal *= validateInput("city", preferredCity = document.getElementById('txtPreferredCity'));

      var sel = document.getElementById("selectPreferredCountry");
      if (validateSelect(sel) == 0) {
        validVal *= 0;
      } else { 
        preferredCountry = sel[sel.selectedIndex];
        validVal *= 1;
      }
      break;
    case 6:
      //transport mode
     
      var radioBBox = document.getElementById('radioTransportMode');
      for (i = 0; i < document.feedbackForm.radioTransportMode.length; i++) {
        if (document.feedbackForm.radioTransportMode[i].checked == true) {
          transportMode = document.feedbackForm.radioTransportMode[i];
         if(fbType == 0 && i==1){
         transportModeWalk = 1 ; 
         
         }
          validVal = 1;
        }
      }
      highlightRadioButtonBox(radioBBox, validVal);
      break;
    case 7:
      //route selection
      var radioBBox = document.getElementById('radioRouteSelection');
      for (i = 0; i < document.feedbackForm.radioRouteSelection.length; i++) {
        if (document.feedbackForm.radioRouteSelection[i].checked == true) {
          routeSelection = document.feedbackForm.radioRouteSelection[i];
           
          validVal = 1;
        }
      }
      highlightRadioButtonBox(radioBBox, validVal);
      break;
    case 8:
      //re-route check and final checkups before the summary page

      //re-route check
      var radioBBox = document.getElementById('radioReroute');
      for (i = 0; i < document.feedbackForm.radioReroute.length; i++) {
        if (document.feedbackForm.radioReroute[i].checked == true) {
          rerouteCheck = document.feedbackForm.radioReroute[i];
          validVal = 1;
        }
      }
      highlightRadioButtonBox(radioBBox, validVal);
      
      //stop processing if the page is not validated
      if (validVal == 0) {
        break;
      }

	 break;
      
    case 9:
    validVal = 1;
     break;
    case 11:
     //report pages have nothing to validate
     // if(pageStructOld[4]==2 && pageStructOld[3]==4 ){transportModeWalk = 0;}
     validVal = 1;
     break;
	 
	 case 12:
      
     validVal = validateInput("opinion", yourOpinion = document.getElementById('Opinion'));
     
	  //validVal = 1;
	     
      
      //stop processing if the page is not validated
      if (validVal == 0) {
        break;
      }
	     //populate the waypoints array (if done before bad behaviour may occur)
	 arrErrorPoints.push([errorStreet.value, errorOptional.value, errorCity.value, errorCountry.value]);
	      
      if (fbType == 0) {
        arrPreferredRoutes.push([preferredStreet.value, preferredOptional.value, preferredCity.value, preferredCountry.value]);
       
      } 
      
      else if (fbType == 1) {
        arrVoiceCommands.push([receivedCommand.value, expectedCommand.value]);
    
      }
      
      if (fbType == 0) {
      
        displayReport('routeReport');
       
      } else if (fbType == 1) {
      
        displayReport('guidanceReport');
      } 
  
       
        break;
	 
    case 10:
      //voice commands check
      var sel = document.getElementById("selectGivenCommand");
      if (validateSelect(sel) == 0) {
        validVal *= 0;
      } else { 
        receivedCommand = sel[sel.selectedIndex];
        validVal = 1;
      }
      
      sel = document.getElementById("selectExpectedCommand");
      if (validateSelect(sel) == 0) {
        validVal *= 0;
      } else { 
        expectedCommand = sel[sel.selectedIndex];
        validVal *= 1;
      }
      break;
  }
  if (validVal == 1) {
    errorBox.style.display = "none";
    return 1;
  } else {
    errorBox.style.display = "block";
    return -1;
  }
}

function goToPage(page){
  //get all the DIVs of the class feedbackPage
  var formDivs = document.getElementById('feedbackForm').getElementsByTagName('div');
  fbDivs = new Array();
  
  for(var i = 0; i < formDivs.length; i++) {
	

    if(formDivs[i].className == "feedbackPage") {
      fbDivs.push(formDivs[i]);
    }
  }

  backButtonBox = document.getElementById('backButtonBox');
  submitButtonBox = document.getElementById('submitButtonBox');
  continueButtonBox = document.getElementById('continueButtonBox');
  
  //set the fbType
  if (fbType == undefined) {
    if(validatePage(0) == -1) {
      return false;
    }
  }

  //get the current page array
  var pageStructOld = fbLayout[fbType][fbIndex];
  var nextPage;
  
  //check whether "back" or "continue" button has been pressed
  if (page == "next") {
    if (validatePage(pageStructOld[2]) != -1 ) 
    { 

    if(transportModeWalk == 1 && fbIndex == 6 ){ fbIndex = pageStructOld[3]+ 1;}
 
      else { fbIndex = pageStructOld[3];}
     
    } 
    
    
    else {
      return -1;
    }
    
  } else if (page == "prev") {
    //hide error message
    errorBox.style.display = "none";
    //check for Walk selection under rout setting
    
    if(transportModeWalk == 1 && fbIndex == 8){ fbIndex = pageStructOld[1]- 1;}
 
    
   else { fbIndex = pageStructOld[1];}
  //sets the first page as the destination page
  } else if (page == "first") {
    fbIndex = 0;
  }
  
  //fbIndex has changed
  var pageStructNew = fbLayout[fbType][fbIndex];
  
  //change titles
  fbDivs[pageStructNew[2]].getElementsByTagName('h3')[0].innerHTML = pageStructNew[0];

  //handle navi buttons
  switch(pageStructNew[4]) {
  case 0:
    backButtonBox.style.visibility = "hidden";
    submitButtonBox.style.visibility = "hidden";
    break;
  case 1:
    backButtonBox.style.visibility = "visible";
    submitButtonBox.style.visibility = "hidden";
    break;
  case 2:
    backButtonBox.style.visibility = "visible";
    submitButtonBox.style.visibility = "visible";
  }  
  
  //hide other divs
  for (i=0;i<fbDivs.length;i++){ 
    fbDivs[i].style.display="none"; 
  }

  fbDivs[pageStructNew[2]].style.display="block";

  return false;
}

// Generate select box based on the array of option values
function addOptions(selectId, optionList) {
  var selectBox = document.getElementById(selectId);
  
  //Set the default first option first
  var optn = document.createElement("option");
  optn.text = optn.value = optn.name = firstOptionValue;
  selectBox.options.add(optn);

  //add the rest of the select options
  for (var i = 0; i < optionList.length; i++) {
    var optn = document.createElement("option");
    optn.text = optn.value = optn.name = optionList[i];
    selectBox.options.add(optn);
  }
}


// check text in opinion box
function chopText(elem, limit)
{
if(elem.value.length>limit)
elem.value=elem.value.substring(0,limit);

document.getElementById("cLeft").value =limit-elem.value.length ;
}

setInterval("chopText(document.feedbackForm.txtOpinion,500)",0);



function displayReport(reportContainerId) {
  //display report to the user
  
  var reportContainer = document.getElementById(reportContainerId);
  var report = generateReport('web');
  
  reportContainer.innerHTML = report;
 
  
}  

function generateReport(format) {
  //<p>, </p>, <b>, </b>, <br />, <hr />
  var pO;
  var pC;
  var bO;
  var bC;
  var nL;
  var hR;
  
  if (format == 'email') {
    pO = '---------------------------\n';
    pC = '\n---------------------------\n';
    bO = '';
    bC = '';
    nL = '\n';
    hR = '';
  } else if (format == 'web') {
    pO = '<p>';
    pC = '</p>';
    bO = '<b>';
    bC = '</b>';
    nL = '<br />';
  }

  var routeReport = pO + bO + "Platform info" + bC + nL +
                    "Device selected: " + device.value + nL +
                    "Maps version: " + mapsVer.value + pC +
                    
                    pO + bO + "Start location" + bC + nL +
                    "Street: " + startStreet.value + nL +
                    "City: " + startCity.value + nL +
                    "House Number: " + startHouse.value + nL +
                    "ZIP code: " + startZip.value + nL +
                    "Country: " + startCountry.value + pC +
                    
                    pO + bO + "Destination location" + bC + nL +
                    "Street: " + destStreet.value + nL +
                    "City: " + destCity.value + nL +
                    "House Number: " + destHouse.value + nL +
                    "ZIP code: " + destZip.value + nL +
                    "Country: " + destCountry.value + pC;
                     //Iterate through all possible waypoints
 for (i = 0; i < arrErrorPoints.length; i++) {
     routeReport += pO + bO + "Waypoint "+ (i+1) + bC + pC +
                    pO + bO + "Point of Error" + bC + nL +
                    "Street: " + arrErrorPoints[i][0] + nL +
                    "Optional information: " + arrErrorPoints[i][1] + nL +
                    "City: " + arrErrorPoints[i][2] + nL +
                    "Country: " + arrErrorPoints[i][3] + pC;
    //routing-specific fields
    if (fbType == 0) {
     routeReport += pO + bO + "Preferred route" + bC + nL +
                    "Street: " + arrPreferredRoutes[i][0] + nL +
                    "Optional information: " + arrPreferredRoutes[i][1] + nL +
                    "City: " + arrPreferredRoutes[i][2] + nL +
                    "Country: " + arrPreferredRoutes[i][3] + pC;
    //guidance-specific fields
    } else if (fbType == 1) {
     routeReport += pO + bO + "Given command: " + bC + arrVoiceCommands[i][0] + pC +
                    pO + bO + "Expected command: " + bC + arrVoiceCommands[i][1] + pC;
    }
  }
  //common fields
  //transport mode is only present in Maps v1.x
  if (mapsVersionNumber == 2)
   {
    routeReport += pO + bO + "Transport mode: " + bC + transportMode.value + pC;
  }
  
  if (fbType == 0 ) {
  if(transportModeWalk ==0 ){
  routeReport += pO + bO + "Route selection: " + bC + routeSelection.value + pC ;
  }
  routeReport += pO + bO + "Re-route check: " + bC + rerouteCheck.value + pC +                  
   pO + bO + "Your opinion: " + bC + yourOpinion.value + pC + nL
  

        } 
        
        else if (fbType == 1) {
        
        routeReport += pO + bO + "Re-route check: " + bC + rerouteCheck.value + pC +                  
   pO + bO + "Your opinion: " + bC + yourOpinion.value + pC + nL
        
        }
                 
              
                 
  

  return routeReport;
  
}

if ( typeof XMLHttpRequest == "undefined" && window.ActiveXObject ) {
	XMLHttpRequest = function() {

		var arrSignatures = [
								"MSXML2.XMLHTTP.7.0", "MSXML2.XMLHTTP.6.0",
								"MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP.4.0",
								"MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];

		for (var i=0; i < arrSignatures.length; i++) {
			try {
				var oRequest = new ActiveXObject(arrSignatures[i]);
				return oRequest;
			} catch (oError) {
				//pass
			}
		}
		alert("No support for MSXML on your system");
	};
}

function submitFeedback() {
  //send feedback
  emailReport();

  //clear the form
  var inputElements = document.getElementsByTagName('input');
  for (i = 0; i < inputElements.length; i++) {
    if (inputElements[i].className != "radio") {
      inputElements[i].value = '';
    }
    if (inputElements[i].checked == true) {
      inputElements[i].checked = false;
    }
  }

  //after the form is submitted go to first page
  goToPage('first');
}

function emailReport() {
  var fbName;
  if (fbType == 0) {
    fbName = "Routing";
  } else if (fbType == 1) {
    fbName = "Guidance";
  }
  var message = generateReport('email');
  var postParams = "email_message="+ message
                   + "&email_subject=Maps " + mapsVersionNumber +".0 " + fbName + " feedback"
                   + "&id=" + emailerToolId;
  var xhr = new XMLHttpRequest();
  xhr.open("POST", emailerTool, true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.onreadystatechange = function() { //Call a function when the state changes
    if(xhr.readyState == 4 && xhr.status == 200) {
      //alert(xhr.responseText);
    }
  }
  //alert(postParams);
  try {
  	xhr.send(postParams);
  } catch(e) {
    alert("Sending form data failed. Please retry later!\nThank you.");
  }
}

