var separator = "|";
var separator2 = ":";
var websiteMap = null;
var websiteMapArea = 'mymap';
var websiteMapLatLong = 'maplatlong';
var websiteMapLat = 'maplat';
var websiteMapLong = 'maplong';
var websiteMapZoomLevel = 'mapzoomlevel';
var websiteMapSearchRadius = 'searchradius';
var websiteMapMarker = null;
var websitePositionMarker = null;
var websiteAttractionArea ='attractions';

function WEBSITEMapParamsObject(mapLatLong, mapLongitude, mapLatitude, mapZoomLevel, searchRadius) {
this.mapLatLong = mapLatLong;
this.mapLongitude = mapLongitude;
this.mapLatitude = mapLatitude;
this.mapZoomLevel = mapZoomLevel;
this.searchRadius = searchRadius;
}

WEBSITEMapParamsObject.prototype.destroy=function() {
  this.length=0;
  return this;
};

var websiteMapParams = new WEBSITEMapParamsObject('40:-72', 40, -72, 3, 0);

function websiteLoad(m)  {
    	// Pass one param and split because of bug in browsers using javascript
    	var i=0, p=0, x=0, latd=44, longtd=-99, zoomlvl=4, nbrmarkers=1;
    	p=m.indexOf(":");latd=m.substring(0, p);m=m.substring(p+1);
    	p=m.indexOf(":");longtd=m.substring(0, p);m=m.substring(p+1);
    	p=m.indexOf(":");zoomlvl=m.substring(0, p);m=m.substring(p+1);
    	nbrmarkers=m;
	if (GBrowserIsCompatible()) {
     	  websiteMap = new GMap2(document.getElementById(websiteMapArea));
	  var point = new GLatLng(latd, longtd);
  	  websiteMap.setCenter(point, zoomlvl);
	  // following lines are bug in google maps setting zoom level in setCenter
	  if (websiteMap.getZoom() < zoomlvl) {
		websiteMap.setZoom(2);
		for (var i=2; i<=zoomlvl; i++) {
			websiteMap.zoomIn();}
		}
     	  websiteMap.addControl(new GSmallMapControl());
   	  websiteMap.addControl(new GMapTypeControl());
	  websiteMapMarker= new Array(nbrmarkers);
   	  for (var j=0; j<=nbrmarkers; ++j) {
		websiteMapMarker[j] = null;
          }
  	}
}

function websiteAddPositionMarker() {
       websiteMap.addOverlay(websitePositionMarker);
       GEvent.addListener(websitePositionMarker, "dragend", function() {
         var location = websitePositionMarker.getPoint();
	 var zoomLevel = websiteMap.getZoom();
	 if (zoomLevel == '') {zoomLevel = 4;}
         websiteMapParams.mapLatLong = location.toString();
	 if (document.getElementById(websiteMapLatLong)) {document.getElementById(websiteMapLatLong).value = websiteMapParams.mapLatLong;}
         websiteMapParams.mapLatitude = location.lat();
	 if (document.getElementById(websiteMapLat)) {document.getElementById(websiteMapLat).value = websiteMapParams.mapLatitude;}
         websiteMapParams.mapLongitude = location.lng();
	 if (document.getElementById(websiteMapLong)) {document.getElementById(websiteMapLong).value = websiteMapParams.mapLongitude;}
	 if (websiteMapParams.searchRadius == '' && zoomLevel < 7) {zoomLevel = 7;}
	 if (websiteMapParams.searchRadius == '50' && zoomLevel < 9) {zoomLevel = 9;}
	 if (document.getElementById(websiteMapZoomLevel)) {document.getElementById(websiteMapZoomLevel).value = zoomLevel;}
	 var zoomLevelBug = zoomLevel;
         try{websiteMap.setCenter(location, zoomLevelBug);} catch(e) {}
	 if (websiteMapParams.searchRadius == '') {websiteMapParams.searchRadius = 50;}
	 if (document.getElementById(websiteMapSearchRadius)) {
		var elSel = document.getElementById(websiteMapSearchRadius);
	 	var i;
		for (i = elSel.length - 1; i>=0; i--) {
		    if (elSel.options[i].value == websiteMapParams.searchRadius) {
		      elSel.options[i].selected = true;
		    }
		}
	 }
       });
       GEvent.addListener(websiteMap, "zoomend", function() {
         websiteMapParams.mapZoomLevel = websiteMap.getZoom();
	 if (document.getElementById(websiteMapZoomLevel)) {document.getElementById(websiteMapZoomLevel).value = zoomLevel;}
       });
}

function websiteLoadAndListen(m) {
    	// Pass one param and split because of bug in browsers using javascript
    	var argm=m, i=0, p=0, x=0, latd=44, longtd=-99, zoomlvl=4, nbrmarkers=1;
    	p=m.indexOf(":");latd=m.substring(0, p);m=m.substring(p+1);
    	p=m.indexOf(":");longtd=m.substring(0, p);m=m.substring(p+1);
    	p=m.indexOf(":");zoomlvl=m.substring(0, p);m=m.substring(p+1);
    	nbrmarkers=m;
	websiteLoad(argm);
	websitePositionMarker = new GMarker(new GLatLng(latd, longtd), {draggable: true});
	websiteAddPositionMarker();
}

function websiteLoadAndDisplay(m) {
    	// Pass one param and split because of bug in browsers using javascript
    	var argm=m, i=0, p=0, x=0, latd=44, longtd=-99, zoomlvl=4, nbrmarkers=1;
    	p=m.indexOf(":");latd=m.substring(0, p);m=m.substring(p+1);
    	p=m.indexOf(":");longtd=m.substring(0, p);m=m.substring(p+1);
    	p=m.indexOf(":");zoomlvl=m.substring(0, p);m=m.substring(p+1);
    	nbrmarkers=m;
	websiteLoad(argm);
	websitePositionMarker = new GMarker(new GLatLng(latd, longtd), {draggable: false});
	websiteMap.addOverlay(websitePositionMarker);
}

function websiteCreateMarker(point, number, label, color) {
  var icon = new GIcon();
  if (color == 'yellow') {
	icon.image = "http://www.integratedvacationsystems.com/IVS/images/mm_"+color+number+".gif";
	icon.iconSize = new GSize(25, 25);
  }
  else {
	icon.image = "http://www.integratedvacationsystems.com/IVS/images/mm_20_"+color+".png";	
	icon.iconSize = new GSize(12, 20);
  }
  icon.shadow = "/IVS/images/mm_20_shadow.png";
  icon.shadowSize = new GSize(22, 20);
  icon.iconAnchor = new GPoint(6, 20);
  icon.infoWindowAnchor = new GPoint(5, 1);
  var marker = new GMarker(point, icon);
  GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(label);});
  return marker;
}

function websiteMapit(m) {
    // Pass one param and split because of bug in i.e.
    var i, p, x;
    p=m.indexOf(":");var latd=m.substring(0, p);m=m.substring(p+1);
    p=m.indexOf(":");var longtd=m.substring(0, p);m=m.substring(p+1);
    p=m.indexOf(":");var index=m.substring(0, p);m=m.substring(p+1);
    p=m.indexOf(":");var specs=m.substring(0, p);m=m.substring(p+1);
    var zoom=m;
    if (zoom == null) {zoom = 8;}
    p=specs.indexOf("|");var sqft=specs.substring(0, p);specs=specs.substring(p+1);
    p=specs.indexOf("|");var ptype=specs.substring(0, p);specs=specs.substring(p+1);
    p=specs.indexOf("|");var brs=specs.substring(0, p);specs=specs.substring(p+1);
    p=specs.indexOf("|");var bas=specs.substring(0, p);specs=specs.substring(p+1);
    var sleeps=specs;
    var label='<font size=2>Line '+index+' -> '+sqft+' Sq Ft '+ptype+'<br> '+brs+'Brs, '+bas+'Bths, Sleeps '+sleeps+'</font>';
    var point = new GLatLng(latd, longtd);
    if (websiteMap == null) {
        var n=latd+':'+longtd+':'+zoom+':'+1;
	websiteLoad(n);
    }
    else {
	if (websiteMap.getZoom() < zoom) {
	    websiteMap.setZoom(2);
	    for (var i=2; i<=zoom; i++) {
	 	websiteMap.zoomIn();
	    }
	}

    }
    if (websiteMapMarker[index] == null) {
       var marker = websiteCreateMarker(point, index, label, 'yellow');
       websiteMap.addOverlay(marker);
       websiteMapMarker[index] = marker;
       websiteMap.setCenter(point);
    }
    else {
       websiteMap.removeOverlay(websiteMapMarker[index]);
       websiteMapMarker[index] = null;
    }
}

function websiteToggle(m) {
  //  Toggle Map On and Off
  var i, p, x;
  p=m.indexOf(":");var latd=m.substring(0, p);m=m.substring(p+1);
  p=m.indexOf(":");var longtd=m.substring(0, p);m=m.substring(p+1);
  p=m.indexOf(":");var index=m.substring(0, p);m=m.substring(p+1);
  p=m.indexOf(":");var pspecs =m.substring(0, p);m=m.substring(p+1);
  var specs=m;
  if (websiteMap == null) {
      var n=latd+':'+longtd+':'+index+':'+pspecs+':10';
      websiteMapit(n);
  }
  else {
      GUnload();
      websiteMap = null;
      p=specs.indexOf("|");var type=specs.substring(0, p);specs=specs.substring(p+1);
      if (type == 'image') {
         p=specs.indexOf("|");var source=specs.substring(0, p);specs=specs.substring(p+1);
         p=specs.indexOf("|");var align=specs.substring(0, p);specs=specs.substring(p+1);
         p=specs.indexOf("|");var width=specs.substring(0, p);specs=specs.substring(p+1);
         p=specs.indexOf("|");var height=specs.substring(0, p);specs=specs.substring(p+1);
         var border=specs;
         var myhtml='<img src='+source+' align='+align+' width='+width+' height='+height+' border='+border+'>';
         document.getElementById(websiteMapArea).innerHTML = myhtml;    
      }
      else {
         document.getElementById(websiteMapArea).innerHTML = specs;    
      }
  }
}

var http_request = false;
var websiteAttractionsShown = new Array('N', 'N', 'N');
var websiteAttractionColors = new Array('yellow', 'red', 'blue');
var websiteNbrAttractionTypes = 2;
var websiteAttractionMarkers = new Array(websiteNbrAttractionTypes);
var websiteAttractionsHTML = new Array(websiteNbrAttractionTypes);

function websiteGetAttractionsBack() {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            // store markers
	    var attractions = http_request.responseText.split('::');
	    var numAttractions = attractions.length;
	    var attractionCategoryId = attractions[1].split('|')[0];
	    var htmlStart = "<td align=left><a href=#pan onclick='websitePanToAttraction(";
	    var comma1 = ',';
	    var comma2 = ',"';
	    var start1 = '("';
	    var end1 = '")';
	    var end2 = "'>";
	    var htmlend = '</a></td>';
	    websiteAttractionsShown[attractionCategoryId] = 'L';
	    websiteAttractionsHTML[attractionCategoryId] = '<table width=95% align=center><tr>';
	    websiteAttractionMarkers[attractionCategoryId] = new Array(numAttractions-1); 
	    var row = 0;
	    for (var x = 1; x<numAttractions; x++) {
		var y= x-1;
	        var attractionAttributes = attractions[x].split('|');
	    	var point = new GLatLng(attractionAttributes[7],attractionAttributes[8]);
		var label = attractionAttributes[1] + " (" + attractionAttributes[3] + ")<br>" + attractionAttributes[6];
	        var marker = websiteCreateMarker(point, x-1, label, websiteAttractionColors[attractionCategoryId]);
		row++;
	        websiteMap.addOverlay(marker);
	        websiteAttractionMarkers[attractionCategoryId][y] = marker;
	        websiteAttractionsHTML[attractionCategoryId] = websiteAttractionsHTML[attractionCategoryId] + htmlStart + attractionCategoryId + comma1 + y + comma2 + label + end1 + end2 + label + htmlend;
		if (row == 3 && x<numAttractions-1) {websiteAttractionsHTML[attractionCategoryId] = websiteAttractionsHTML[attractionCategoryId] + '</tr>\n<tr>';row=row-3;}
	    }
	    websiteAttractionsShown[attractionCategoryId] = 'Y';
	    websiteAttractionsHTML[attractionCategoryId] = websiteAttractionsHTML[attractionCategoryId] + '</tr></table>';
//	    document.getElementById(websiteAttractionArea).innerHTML = websiteAttractionsHTML[attractionCategoryId];
	    document.getElementById(websiteAttractionArea).innerHTML = '';
        }
    }
}

function websiteGetAttractions(attractionCategoryId) {
	// Get attractions
	var posturl = "/cgi-bin/IVS/common/perllet_getAttractions.pl";

	var params = "letId=" + encodeURIComponent(attractionCategoryId);

	var url = "/cgi-bin/websitepro/websitepro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);
	if (ivsType == 1) {url = "/cgi-bin/vrapro/vrapro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);}

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
          http_request = new XMLHttpRequest();
          if (http_request.overrideMimeType) {
             // set type accordingly to anticipated content type
             // http_request.overrideMimeType('text/xml');
             http_request.overrideMimeType('text/html');
          }
        } else if (window.ActiveXObject) { // IE
          try {
              http_request = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
             try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
             } catch (e) {}
          }
        }
        if (!http_request) {
           alert('Cannot create XMLHTTP instance');
           return false;
        }
	http_request.open("GET", url, true);
	http_request.onreadystatechange = websiteGetAttractionsBack;
	http_request.send(null);
}

function websiteShowAttractions(attractionCategoryId) {
	websiteAttractionsShown[attractionCategoryId] = 'Y';
	var numAttractions = websiteAttractionMarkers[attractionCategoryId].length;
	for (var x = 0; x<numAttractions; x++) {
		var attractionMarker = websiteAttractionMarkers[attractionCategoryId][x];
	        attractionMarker.show();
	}
//	document.getElementById(websiteAttractionArea).innerHTML = websiteAttractionsHTML[attractionCategoryId];
	document.getElementById(websiteAttractionArea).innerHTML = '';
}

function websiteHideAttractions() {
	// hide all attractions and uncheck other categories checkbox
	for (var y = 1; y<3; y++) {
		if (websiteAttractionsShown[y] == 'Y') {
//			if (y == 1) {document.searchform.skiareas.checked = '';} else {document.searchform.themeparcs.checked = '';}
			var numAttractions = websiteAttractionMarkers[y].length;
			for (var x = 0; x<numAttractions; x++) {
				var attractionMarker = websiteAttractionMarkers[y][x];
        			attractionMarker.hide();
			}
			websiteAttractionsShown[y] = 'L';
		}
	}
	websiteMap.closeInfoWindow();
	document.getElementById(websiteAttractionArea).innerHTML = '';
}

function websiteRemoveAttractions() {
	// Remove all attractions and uncheck other categories checkbox
	websiteMap.clearOverlays();
	websiteMap.closeInfoWindow();
	for (var y = 1; y<3; y++) {
		if (websiteAttractionsShown[y] == 'Y') {
			websiteAttractionsShown[y] = 'L';
		}
	}
	document.getElementById(websiteAttractionArea).innerHTML = '';
}

function websiteProcessAttractions(attractionCategoryId) {
  // Remove all attractions
  var attractionShown = websiteAttractionsShown[attractionCategoryId];
  websiteHideAttractions();
  if (attractionShown == 'N') {
	websiteGetAttractions(attractionCategoryId);
   }
   else {
	if (attractionShown == 'L') {
		websiteShowAttractions(attractionCategoryId);
	}
   }
}

function websitePanToAttraction(attractionCategoryId, x, label) {
	var marker = websiteAttractionMarkers[attractionCategoryId][x];
        var location = marker.getPoint();
	websiteMap.panTo(location);
	marker.openInfoWindowHtml(label);
	websitePositionMarker.setPoint(location);
        websiteMapParams.mapLatLong = location.toString();
        websiteMapParams.mapLatitude = location.lat();
        websiteMapParams.mapLongitude = location.lng();
	if (websiteMapParams.searchRadius.value == '' || websiteMapParams.searchRadius.value == 0) {websiteMapParams.searchRadius.value = 50;}
}

function websiteResetMap() {
	websiteRemoveAttractions();
	websiteAddPositionMarker();
}

function websiteUnload() {
     // destroy any property markers
     var nbrMarkers = websiteMapMarker.length;
     for (var i=0; i<nbrMarkers; i++) {
	if (websiteMapMarker[i]) {websiteMapMarker[i].length = 0;}
     }
     // destroy any attraction markers
     for (var i=0; i<2; i++) {
	   if (websiteAttractionsShown[i] != 'N') {
		var nbrAttractions = websiteAttractionMarkers[i].length;
		for (var j=0; j<nbrAttractions; j++) {
			if (websiteAttractionMarkers[i][j]) {websiteAttractionMarkers[i][j].length = 0;}
		}
	   }
     }
      GUnload();
      websiteMap = null;
}

var http_request = false;

// Return callback switch
var ivsSwitch = '';

// Country Codes
var websiteCountryCodes = '';

function WEBSITECountryCodeObject() {

this.countryId = '';
this.countryCd = '';
this.countryTxt = '';

}

WEBSITECountryCodeObject.prototype.destroy=function() {
  this.length=0;
  return this;
};

function websiteGetCountryCodes() {
	// Get Countries
	var posturl = "/cgi-bin/IVS/common/perllet_getCountryCodes.pl";

	var params = "";

	var url = "/cgi-bin/websitepro/websitepro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);
	if (ivsType == 1) {url = "/cgi-bin/vrapro/vrapro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);}

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
          http_request = new XMLHttpRequest();
          if (http_request.overrideMimeType) {
             // set type accordingly to anticipated content type
             // http_request.overrideMimeType('text/xml');
             http_request.overrideMimeType('text/html');
          }
        } else if (window.ActiveXObject) { // IE
          try {
              http_request = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
             try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
             } catch (e) {}
          }
        }
        if (!http_request) {
           alert('Cannot create XMLHTTP instance');
           return false;
        }
	if (websiteCountryCodes) {websiteCountryCodes.destroy();}
	http_request.open("GET", url, true);
	http_request.onreadystatechange = websiteGetCountryCodesBack;
	http_request.send(null);
}    

function websiteGetCountryCodesBack() {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            // extract country elements and other fields
	    var countryCodes = http_request.responseText.split('::');
	    var numElements = countryCodes.length;
	    var returnCode = countryCodes[1].split('|')[1];
	    if (!websiteCountryCodes) {websiteCountryCodes = new Array();}
	    if (returnCode == 0) {
		    for (var x = 2; x<numElements-1; x++) {
			var country = new WEBSITECountryCodeObject();
		        var countryAttributes = countryCodes[x].split('|');
			country.countryId = countryAttributes[1];
			country.countryCd = countryAttributes[2];
			country.countryTxt = countryAttributes[3];
			websiteCountryCodes.push(country);
		    }
	    }
	    if (ivsSwitch == 'Y') {
	    	try {ivsGetCountryCodesReturn(returnCode);} catch(e) {alert(e);}
	    } 
	    else {
	    	try {getCountryCodesReturn(returnCode);} catch(e) {alert(e);}
	    }
        }
    }
}

// ZipCode
var websiteZipCode = '';

function WEBSITEZipCodeObject() {

this.zipCd='';
this.city='';
this.stateCd='';

}

WEBSITEZipCodeObject.prototype.destroy=function() {
  this.length=0;
  return this;
};

function websiteValidateUSAZipCodeSend(zipCode) {
	// Validate Zip Code
	var fieldName = "ZipCode";
	var posturl = "/cgi-bin/IVS/common/perllet_validateUSAZipCode.pl";

	var params = "letId=" + encodeURIComponent(zipCode) + "&fieldName="  + encodeURIComponent(fieldName);

	var url = "/cgi-bin/websitepro/websitepro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);
	if (ivsType == 1) {url = "/cgi-bin/vrapro/vrapro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);}

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
          http_request = new XMLHttpRequest();
          if (http_request.overrideMimeType) {
             // set type accordingly to anticipated content type
             // http_request.overrideMimeType('text/xml');
             http_request.overrideMimeType('text/html');
          }
        } else if (window.ActiveXObject) { // IE
          try {
              http_request = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
             try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
             } catch (e) {}
          }
        }
        if (!http_request) {
           alert('Cannot create XMLHTTP instance');
           return false;
        }
	if (!websiteZipCode) {websiteZipCode = new WEBSITEZipCodeObject();} 
	http_request.open("GET", url, true);
	http_request.onreadystatechange = websiteValidateUSAZipCodeBack;
	http_request.send(null);
}    
 
function websiteValidateUSAZipCodeBack() {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            // extract zip code and other fields
	    var zipCodes = http_request.responseText;
	    var zipCodeElements = zipCodes.split('::');
	    var zipReturnValues = zipCodeElements[1].split('|');
	    var fieldName = zipReturnValues[1];
	    var returnCode = zipReturnValues[2];
	    var city = zipReturnValues[3];
	    var stateCd = zipReturnValues[4];
	    if (returnCode == 0) {
		// error - null out fields
		websiteZipCode.stateCd = '';
		websiteZipCode.city = '';
	    }
	    else {
		// ok - set fields
		websiteZipCode.stateCd = stateCd;
		websiteZipCode.city = city;
	    }
	    if (ivsSwitch == 'Y') {
	    	try {ivsValidateUSAZipCodeReturn(returnCode);} catch(e) {alert(e);}
	    } 
	    else {
	    	try {validateUSAZipCodeReturn(returnCode);} catch(e) {alert(e);}
	    }
        }
    }
}

function websiteValidateUSAZipCode(zipCode) {
	websiteValidateUSAZipCodeSend(zipCode);
}

// Address Elements
var websiteAddressElements = '';

function WEBSITEAddressElementObject() {

this.elementLabel = '';
this.elementName = '';
this.elementType = '';
this.elementLength = '';
this.elementEnterableLength = '';
this.elementRequiredFl = '';
this.elementValidation = '';

}

WEBSITEAddressElementObject.prototype.destroy=function() {
  this.length=0;
  return this;
};

function websiteGetSetter(type, fieldName) {
	if (fieldName == 'Address_Ln1') {return "website" + type + ".set" + type + "AddressLn1";}
	if (fieldName == 'Address_Ln2') {return "website" + type + ".set" + type + "AddressLn2";}
	if (fieldName == 'Address_City') {return "website" + type + ".set" + type + "AddressCity";}
	if (fieldName == 'Address_State_Cd') {return "website" + type + ".set" + type + "AddressStateCd";}
	if (fieldName == 'Address_Zip_Cd') {return "website" + type + ".set" + type + "AddressZipCd";}
	return 'unknown';
}

function websiteDecodeElementType(elementType) {
	if (elementType == 'TB') {return 'text';}
	return elementType;
}

function websiteGetAddressElements(countryId, fieldName) {
	// Get Address Elements For Country
	var posturl = "/cgi-bin/IVS/common/perllet_getAddressElements.pl";

	var params = "letId=" + encodeURIComponent(countryId) + "&fieldName="  + encodeURIComponent(fieldName);

	var url = "/cgi-bin/websitepro/websitepro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);
	if (ivsType == 1) {url = "/cgi-bin/vrapro/vrapro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);}

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
          http_request = new XMLHttpRequest();
          if (http_request.overrideMimeType) {
             // set type accordingly to anticipated content type
             // http_request.overrideMimeType('text/xml');
             http_request.overrideMimeType('text/html');
          }
        } else if (window.ActiveXObject) { // IE
          try {
              http_request = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
             try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
             } catch (e) {}
          }
        }
        if (!http_request) {
           alert('Cannot create XMLHTTP instance');
           return false;
        }
	if (websiteAddressElements) {websiteAddressElements.destroy();}
	http_request.open("GET", url, true);
	http_request.onreadystatechange = websiteGetAddressElementsBack;
	http_request.send(null);
}    

function websiteGetAddressElementsBack() {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            // extract address elements and other fields
	    var addressElements = http_request.responseText.split('::');
	    var numElements = addressElements.length;
	    var fieldName = addressElements[1].split('|')[0];
	    var returnCode = addressElements[1].split('|')[1];
	    var telCode = addressElements[1].split('|')[2];
	    var addressElementsHTML = '';
	    if (!websiteAddressElements) {websiteAddressElements = new Array();}
	    if (returnCode == 0) {
		// error no address found so set to default
		websiteSetAddressElementsToDefault();
	    }
	    else {
		    for (var x = 1; x<numElements-1; x++) {
			var element = new WEBSITEAddressElementObject();
		        var elementAttributes = addressElements[x].split('|');
			element.elementLabel = elementAttributes[3];
			element.elementName = elementAttributes[4];
			element.elementType = elementAttributes[5];
			element.elementLength = elementAttributes[6];
			element.elementEnterableLength = elementAttributes[7];
			element.elementRequiredFl = elementAttributes[8];
			element.elementValidation = elementAttributes[9].toString();
			websiteAddressElements.push(element);
		    }
	    }
	    if (ivsSwitch == 'Y') {
		    try {ivsGetAddressElementsReturn(returnCode, telCode);} catch(e) {alert(e);}
	    } 
	    else {
		    try {getAddressElementsReturn(returnCode, telCode);} catch(e) {alert(e);}
	    }
        }
    }
}

function websiteSetAddressElementsToDefault() {
			//
			var element = new WEBSITEAddressElementObject();
			element.elementLabel = 'Address Line 1';
			element.elementName = 'Address_Ln1';
			element.elementType = 'TB';
			element.elementLength = '55';
			element.elementEnterableLength = '50';
			element.elementRequiredFl = 'Y';
			element.elementValidation = '';
			websiteAddressElements.push(element);
			element = new WEBSITEAddressElementObject();
			element.elementLabel = 'City';
			element.elementName = 'Address_City';
			element.elementType = 'TB';
			element.elementLength = '45';
			element.elementEnterableLength = '40';
			element.elementRequiredFl = 'O';
			element.elementValidation = '';
			websiteAddressElements.push(element);
			element = new WEBSITEAddressElementObject();
			element.elementLabel = 'Locality/Province/County';
			element.elementName = 'Address_State_Cd';
			element.elementType = 'TB';
			element.elementLength = '45';
			element.elementEnterableLength = '40';
			element.elementRequiredFl = 'O';
			element.elementValidation = '';
			websiteAddressElements.push(element);
			element = new WEBSITEAddressElementObject();
			element.elementLabel = 'Post Code';
			element.elementName = 'Address_Zip_Cd';
			element.elementType = 'Tb';
			element.elementLength = '20';
			element.elementEnterableLength = '10';
			element.elementRequiredFl = 'O';
			element.elementValidation = '';
			websiteAddressElements.push(element);
}
var http_request = false;
var websitePageWidth = 750;

// Agency Signup Data
var websiteAgencySignup = '';

function WEBSITEAgencySignupObject() {

this.agencyId='';
this.agencyNm='';
this.agencyContactFirstNm='';
this.agencyContactLastNm='';
this.agencyLoginCd='';
this.agencyLoginPassword='';
this.repeatLoginPassword='';
this.agencyTelNbr='';
this.agencyTelCountryCd='';
this.agencyCountryCd='';
this.agencyAddressLn1='';
this.agencyAddressLn2='';
this.agencyAddressCity='';
this.agencyAddressStateCd='';
this.agencyAddressZipCd='';
this.inquiryTxt='';

}

WEBSITEAgencySignupObject.prototype.destroy=function() {
  this.length=0;
  return this;
};

WEBSITEAgencySignupObject.prototype.setAgencyId=function(agencyId) {this.agencyId=agencyId;};
WEBSITEAgencySignupObject.prototype.setAgencyNm=function(agencyNm) {this.agencyNm=agencyNm;};
WEBSITEAgencySignupObject.prototype.setAgencyContactFirstNm=function(agencyContactFirstNm) {this.agencyContactFirstNm=agencyContactFirstNm;};
WEBSITEAgencySignupObject.prototype.setAgencyContactLastNm=function(agencyContactLastNm) {this.agencyContactLastNm=agencyContactLastNm;};
WEBSITEAgencySignupObject.prototype.setAgencyLoginCd=function(agencyLoginCd) {this.agencyLoginCd=agencyLoginCd;};
WEBSITEAgencySignupObject.prototype.setAgencyLoginPassword=function(agencyLoginPassword) {this.agencyLoginPassword=agencyLoginPassword;};
WEBSITEAgencySignupObject.prototype.setRepeatLoginPassword=function(repeatLoginPassword) {this.repeatLoginPassword=repeatLoginPassword;};
WEBSITEAgencySignupObject.prototype.setAgencyTelNbr=function(agencyTelNbr) {this.agencyTelNbr=agencyTelNbr;};
WEBSITEAgencySignupObject.prototype.setAgencyTelCountryCd=function(agencyTelCountryCd) {this.agencyTelCountryCd=agencyTelCountryCd;};
WEBSITEAgencySignupObject.prototype.setAgencyCountryCd=function(agencyCountryCd) {this.agencyCountryCd=agencyCountryCd;};
WEBSITEAgencySignupObject.prototype.setAgencyAddressLn1=function(agencyAddressLn1) {this.agencyAddressLn1=agencyAddressLn1;};
WEBSITEAgencySignupObject.prototype.setAgencyAddressLn2=function(agencyAddressLn2) {this.agencyAddressLn2=agencyAddressLn2;};
WEBSITEAgencySignupObject.prototype.setAgencyAddressCity=function(agencyAddressCity) {this.agencyAddressCity=agencyAddressCity;};
WEBSITEAgencySignupObject.prototype.setAgencyAddressStateCd=function(agencyAddressStateCd) {this.agencyAddressStateCd=agencyAddressStateCd;};
WEBSITEAgencySignupObject.prototype.setAgencyAddressZipCd=function(agencyAddressZipCd) {this.agencyAddressZipCd=agencyAddressZipCd;};
WEBSITEAgencySignupObject.prototype.setInquiryTxt=function(inquiryTxt) {this.inquiryTxt=inquiryTxt;};

function websiteGetAgencySignupSetter(fieldName) {
	if (fieldName == 'Address_Ln1') {return "websiteAgencySignup.setAgencyAddressLn1";}
	if (fieldName == 'Address_Ln2') {return "websiteAgencySignup.setAgencyAddressLn2";}
	if (fieldName == 'Address_City') {return "websiteAgencySignup.setAgencyAddressCity";}
	if (fieldName == 'Address_State_Cd') {return "websiteAgencySignup.setAgencyAddressStateCd";}
	if (fieldName == 'Address_Zip_Cd') {return "websiteAgencySignup.setAgencyAddressZipCd";}
	return 'unknown';
}

function websiteSendAgencySignupBack() {
alert("websiteSendAgencySignupBack " + http_request.responseText);
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            // extract inquiry return code stuff
	    var resultsElements = http_request.responseText.split('::');
	    var returnCode = resultsElements[1].split('|')[1];
	    var msg = resultsElements[1].split('|')[2];
	    var errorMsgTxt = resultsElements[1].split('|')[3];
	    formatSendAgencySignupReturn(returnCode, msg, errorMsgTxt);
        }
    }
}

function websitePostAgencySignup(signupType, websiteId, securityKey) {
	// Send a signup request for an agency
	var posturl = "/cgi-bin/IVS/common/perllet_signup.pl";

	var params = "&actionTypeCd=" + encodeURIComponent('S') + "&portal=" + encodeURIComponent('Website') + "&websiteId=" + encodeURIComponent(websiteId) + "&securityKey=" + encodeURIComponent(securityKey) + "&signupType=" + encodeURIComponent(signupType) + "&entityType=" + encodeURIComponent('Agency') + "&inquiryTxt="  + encodeURIComponent(websiteAgencySignup.inquiryTxt) + "&agencyNm="  + encodeURIComponent(websiteAgencySignup.agencyNm) + "&agencyContactFirstNm="  + encodeURIComponent(websiteAgencySignup.agencyContactFirstNm) + "&agencyContactLastNm="  + encodeURIComponent(websiteAgencySignup.agencyContactLastNm)  + "&agencyLoginCd="  + encodeURIComponent(websiteAgencySignup.agencyLoginCd) + "&agencyLoginPassword="  + encodeURIComponent(websiteAgencySignup.agencyLoginPassword)  + "&repeatLoginPassword="  + encodeURIComponent(websiteAgencySignup.repeatLoginPassword) + "&agencyTelNbr="  + encodeURIComponent(websiteAgencySignup.agencyTelNbr) + "&agencyTelCountryCd="  + encodeURIComponent(websiteAgencySignup.agencyTelCountryCd) + "&agencyCountryCd="  + encodeURIComponent(websiteAgencySignup.agencyCountryCd) + "&agencyAddressLn1="  + encodeURIComponent(websiteAgencySignup.agencyAddressLn1) + "&agencyAddressLn2="  + encodeURIComponent(websiteAgencySignup.agencyAddressLn2) + "&agencyAddressCity="  + encodeURIComponent(websiteAgencySignup.agencyAddressCity) + "&agencyAddressStateCd="  + encodeURIComponent(websiteAgencySignup.agencyAddressStateCd) + "&agencyAddressZipCd="  + encodeURIComponent(websiteAgencySignup.agencyAddressZipCd);

	var url = "/cgi-bin/websitepro/websitepro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);
	if (ivsType == 1) {url = "/cgi-bin/vrapro/vrapro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);}

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
          http_request = new XMLHttpRequest();
          if (http_request.overrideMimeType) {
             // set type accordingly to anticipated content type
             // http_request.overrideMimeType('text/xml');
             http_request.overrideMimeType('text/html');
          }
        } else if (window.ActiveXObject) { // IE
          try {
              http_request = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
             try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
             } catch (e) {}
          }
        }
        if (!http_request) {
           alert('Cannot create XMLHTTP instance');
           return false;
        }
	http_request.open("GET", url, true);
	http_request.onreadystatechange = websiteSendAgencySignupBack;
	http_request.send(null);
}

function websiteValidateAgencySignup() {
	// Validate Fields
	if (websiteAgencySignup.agencyNm == '') {
		return new Array (1, 'You must enter the name of your Vacation Rental Agency in the Agency Rental Agency Name field.');
	}
	if (websiteAgencySignup.agencyLoginCd == '') {
		return new Array (2, 'You must enter your email address in the Email Address field');
	}
	if (websiteAgencySignup.agencyLoginPassword == '') {
		return new Array (3, 'You must enter a password in the Password field');
	}
	if (websiteAgencySignup.repeatPassword == '') {
		return new Array (4, 'You must repeat your password in the Repeat Password field');
	}
	if (websiteAgencySignup.agencyContactFirstNm == '') {
		return new Array (5, 'You must enter your first name in the First Name field.');
	}
	if (websiteAgencySignup.agencyContactLastNm == '') {
		return new Array (6, 'You must enter your last name in the Last Name field.');
	}
	if (websiteAgencySignup.agencyAddressLn1 == '') {
		return new Array (7, 'You must enter the first line of your agency address in the Agency Address Line 1 field.');
	}
	if (websiteAgencySignup.agencyAddressCity == '') {
		return new Array (8, 'You must enter the city of your agency address in the Agency Address City field.');
	}
	if (websiteAgencySignup.agencyAddressStateCd == '') {
		return new Array (9, 'You must enter the state/province of your agency address in the Agency Address State field.');
	}
	if (websiteAgencySignup.agencyAddressZipeCd == '') {
		return new Array (10, 'You must enter the zip/postal code of your agency address in the Agency Address Zip/Postal Code field.');
	}
	if (websiteAgencySignup.agencyTelNbr == '') {
		return new Array (11, 'You must enter the telephone number of your agency in the Phone Number field.');
	}
	if (websiteAgencySignup.agencyTelCountryCd == '') {
		return new Array (12, 'You must enter an international dialing code in the International Dialing code field.');
	}

	return new Array (0, '');
}

function websiteSendAgencySignup(type, websiteId, securityKey) {
	// Send an inquiry for a property
	var a =  websiteValidateAgencySignup();
	returnCode = a[0];
	errMsg = a[1]; 
	if (returnCode == 0) {
		websitePostAgencySignup(type, websiteId, securityKey);
		return a;
	}
	else {
		return a;
	}
}

// Agency Plans
var websiteAgencyPlans = '';

function WEBSITEAgencyPlanObject() {

this.websitePlanId = '';
this.planTypeCd = '';
this.priceTypeCd = '';
this.nbrOfListingsAmt = '';
this.currencySymbol = '';
this.listingFeeMonthlyAmt = '';
this.listingFeeSemiAmt = '';
this.listingFeeAnnualAmt = '';
this.trialPeriodDays = '';

}

WEBSITEAgencyPlanObject.prototype.destroy=function() {
  this.length=0;
  return this;
};

function websiteGetAgencyPlans(portal, type, websiteId, securityKey, planType) {
	// Get Countries
	var posturl = "/cgi-bin/IVS/common/perllet_getListingPlans.pl";

	var params = "&portal=" + encodeURIComponent(portal) + "&entityType=" + encodeURIComponent(type)  + "&entityId=" + encodeURIComponent(websiteId) + "&securityKey=" + encodeURIComponent(securityKey) + "&planType=" + encodeURIComponent(planType) + "&signupType=" + encodeURIComponent('A') ;

	var url = "/cgi-bin/websitepro/websitepro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
          http_request = new XMLHttpRequest();
          if (http_request.overrideMimeType) {
             // set type accordingly to anticipated content type
             // http_request.overrideMimeType('text/xml');
             http_request.overrideMimeType('text/html');
          }
        } else if (window.ActiveXObject) { // IE
          try {
              http_request = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
             try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
             } catch (e) {}
          }
        }
        if (!http_request) {
           alert('Cannot create XMLHTTP instance');
           return false;
        }
	if (websiteCountryCodes) {websiteCountryCodes.destroy();}
	http_request.open("GET", url, true);
	http_request.onreadystatechange = websiteGetAgencyPlansBack;
	http_request.send(null);
}    

function websiteGetAgencyPlansBack() {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            // extract country elements and other fields
	    var agencyPlans = http_request.responseText.split('::');
	    var numElements = agencyPlans.length;
	    var returnCode = agencyPlans[1].split('|')[1];
	    if (!websiteAgencyPlans) {websiteAgencyPlans = new Array();}
	    if (returnCode == 0) {
		    for (var x = 2; x<numElements-1; x++) {
			var plan = new WEBSITEAgencyPlanObject();
		        var planAttributes = agencyPlans[x].split('|');
			plan.websitePlanId = planAttributes[1];
			plan.planTypeCd = planAttributes[2];
			plan.priceTypeCd = planAttributes[3];
			plan.nbrOfListingsAmt = planAttributes[4];
			plan.currencySymbol = planAttributes[5];
			plan.listingFeeMonthlyAmt = planAttributes[6];
			plan.listingFeeSemiAmt = planAttributes[7];
			plan.listingFeeAnnualAmt = planAttributes[8];
			plan.trialPeriodDays = planAttributes[9];
			websiteAgencyPlans.push(plan);
		    }
	    }
	    if (ivsSwitch == 'Y') {
	    	try {ivsGetAgencyPlansReturn(returnCode);} catch(e) {alert(e);}
	    } 
	    else {
	    	try {getAgencyPlansReturn(returnCode);} catch(e) {alert(e);}
	    }
        }
    }
}

// Owner Plans
var websiteOwnerPlans = '';

function WEBSITEOwnerPlanObject() {

this.websitePlanId = '';
this.planTypeCd = '';
this.priceTypeCd = '';
this.nbrOfListingsAmt = '';
this.currencySymbol = '';
this.listingFeeMonthlyAmt = '';
this.listingFeeSemiAmt = '';
this.listingFeeAnnualAmt = '';
this.trialPeriodDays = '';

}

WEBSITEOwnerPlanObject.prototype.destroy=function() {
  this.length=0;
  return this;
};

function websiteGetOwnerPlans(portal, type, websiteId, securityKey, planType) {
	// Get Owner Plans
	var posturl = "/cgi-bin/IVS/common/perllet_getListingPlans.pl";

	var params = "&portal=" + encodeURIComponent(portal) + "&entityType=" + encodeURIComponent(type)  + "&entityId=" + encodeURIComponent(websiteId) + "&securityKey=" + encodeURIComponent(securityKey) + "&planType=" + encodeURIComponent(planType) + "&signupType=" + encodeURIComponent('O') ;

	var url = "/cgi-bin/websitepro/websitepro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
          http_request = new XMLHttpRequest();
          if (http_request.overrideMimeType) {
             // set type accordingly to anticipated content type
             // http_request.overrideMimeType('text/xml');
             http_request.overrideMimeType('text/html');
          }
        } else if (window.ActiveXObject) { // IE
          try {
              http_request = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
             try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
             } catch (e) {}
          }
        }
        if (!http_request) {
           alert('Cannot create XMLHTTP instance');
           return false;
        }
	if (websiteCountryCodes) {websiteCountryCodes.destroy();}
	http_request.open("GET", url, true);
	http_request.onreadystatechange = websiteGetOwnerPlansBack;
	http_request.send(null);
}    

function websiteGetOwnerPlansBack() {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            // extract country elements and other fields
	    var ownerPlans = http_request.responseText.split('::');
	    var numElements = ownerPlans.length;
	    var returnCode = ownerPlans[1].split('|')[1];
	    if (!websiteOwnerPlans) {websiteOwnerPlans = new Array();}
	    if (returnCode == 0) {
		    for (var x = 2; x<numElements-1; x++) {
			var plan = new WEBSITEOwnerPlanObject();
		        var planAttributes = ownerPlans[x].split('|');
			plan.websitePlanId = planAttributes[1];
			plan.planTypeCd = planAttributes[2];
			plan.priceTypeCd = planAttributes[3];
			plan.nbrOfListingsAmt = planAttributes[4];
			plan.currencySymbol = planAttributes[5];
			plan.listingFeeMonthlyAmt = planAttributes[6];
			plan.listingFeeSemiAmt = planAttributes[7];
			plan.listingFeeAnnualAmt = planAttributes[8];
			plan.trialPeriodDays = planAttributes[9];
			websiteOwnerPlans.push(plan);
		    }
	    }
	    if (ivsSwitch == 'Y') {
	    	try {ivsGetOwnerPlansReturn(returnCode);} catch(e) {alert(e);}
	    } 
	    else {
	    	try {getOwnerPlansReturn(returnCode);} catch(e) {alert(e);}
	    }
        }
    }
}

// Vacationer Data
var websiteVacationer = '';

function WEBSITEVacationerObject() {

this.vacationerId='';
this.vacationerFirstNm='';
this.vacationerLastNm='';
this.vacationerLoginCd='';
this.repeatLoginCd='';
this.vacationerLoginPassword='';
this.repeatLoginPassword='';
this.vacationerAltEmailAddress = '';
this.vacationerCountryCd='';
this.vacationerAddressLn1='';
this.vacationerAddressLn2='';
this.vacationerAddressCity='';
this.vacationerAddressStateCd='';
this.vacationerAddressZipCd='';
this.vacationerHomeTelCountryCd='';
this.vacationerHomeTelNbr='9999999999';
this.vacationerAgeCd='';

}

WEBSITEVacationerObject.prototype.destroy=function() {
  this.length=0;
  return this;
};

WEBSITEVacationerObject.prototype.setVacationerId=function(vacationerId) {this.vacationerId=vacationerId;};
WEBSITEVacationerObject.prototype.setVacationerFirstNm=function(vacationerFirstNm) {this.vacationerFirstNm=vacationerFirstNm;};
WEBSITEVacationerObject.prototype.setVacationerLastNm=function(vacationerLastNm) {this.vacationerLastNm=vacationerLastNm;};
WEBSITEVacationerObject.prototype.setVacationerLoginCd=function(vacationerLoginCd) {this.vacationerLoginCd=vacationerLoginCd;};
WEBSITEVacationerObject.prototype.setRepeatLoginCd=function(repeatLoginCd) {this.repeatLoginCd=repeatLoginCd;};
WEBSITEVacationerObject.prototype.setVacationerLoginPassword=function(vacationerLoginPassword) {this.vacationerLoginPassword=vacationerLoginPassword;};
WEBSITEVacationerObject.prototype.setRepeatLoginPassword=function(repeatLoginPassword) {this.repeatLoginPassword=repeatLoginPassword;};
WEBSITEVacationerObject.prototype.setVacationerAltEmailPassword=function(vacationerAltEmailPassword) {this.vacationerAltEmailAddress=vacationerAltEmailAddress;};
WEBSITEVacationerObject.prototype.setVacationerHomeTelNbr=function(vacationerHomeTelNbr) {this.vacationerHomeTelNbr=vacationerHomeTelNbr;};
WEBSITEVacationerObject.prototype.setVacationerHomeTelCountryCd=function(vacationerHomeTelCountryCd) {this.vacationerHomeTelCountryCd=vacationerHomeTelCountryCd;};
WEBSITEVacationerObject.prototype.setVacationerAgeCd=function(vacationerAgeCd) {this.vacationerAgeCd=vacationerAgeCd;};
WEBSITEVacationerObject.prototype.setVacationerCountryCd=function(vacationerCountryCd) {this.vacationerCountryCd=vacationerCountryCd;};

function websiteGetVacationerDataBack() {
   if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            // extract inquiry return code stuff
	    var resultsElements = http_request.responseText.split('::');
	    var returnCode = resultsElements[1].split('|')[1];
	    var mode = resultsElements[1].split('|')[2];
	    if (returnCode == 0) {
		// Found vacationer
		if (!websiteVacationer) {websiteVacationer = new WEBSITEVacationerObject();} 
		// Enter vacationer address elements that may have been retrieved by the db request
		// Data request with either vacationerId or login cd and password
		var i=3;
		websiteVacationer.vacationerId = resultsElements[1].split('|')[i];
		websiteVacationer.vacationerLoginCd = resultsElements[1].split('|')[i+1];
		websiteVacationer.vacationerAltEmailAddress = resultsElements[1].split('|')[i+2];
		websiteVacationer.vacationerFirstNm = resultsElements[1].split('|')[i+3];
		websiteVacationer.vacationerLastNm = resultsElements[1].split('|')[i+4];
		websiteVacationer.vacationerAgeCd = resultsElements[1].split('|')[i+5];
		websiteVacationer.vacationerCountryCd = resultsElements[1].split('|')[i+6];
		websiteVacationer.vacationerAddressLn1 = resultsElements[1].split('|')[i+7];
		websiteVacationer.vacationerAddressLn2 = resultsElements[1].split('|')[i+8];
		websiteVacationer.vacationerAddressCity = resultsElements[1].split('|')[i+9];
		websiteVacationer.vacationerAddressStateCd = resultsElements[1].split('|')[i+10];
		websiteVacationer.vacationerAddressZipCd = resultsElements[1].split('|')[i+11];
		websiteVacationer.vacationerHomeTelNbr = resultsElements[1].split('|')[i+12];
		websiteVacationer.vacationerHomeTelCountryCd = resultsElements[1].split('|')[i+13];
	    }
	    if (ivsSwitch == 'Y') {
	    	try {ivsGetVacationerDataReturn(returnCode);} catch(e) {alert(e);}
	    } 
	    else {
	    	try {getVacationerDataReturn(returnCode);} catch(e) {alert(e);}
	    }
        }
    }
}

function websiteGetVacationerData(portal, sessionId, entityType, entityId, securityKey, vacationerId, vacationerLoginCd, vacationerLoginPassword) {
	// Send an inquiry for a vacationer
	var posturl = "/cgi-bin/IVS/common/perllet_getVacationerData.pl";

	var params = "sessionId=" + encodeURIComponent(sessionId) + "&portal=" + encodeURIComponent(portal) + "&entityType=" + encodeURIComponent(entityType) + "&entityId=" + encodeURIComponent(entityId)  + "&securityKey="  + encodeURIComponent(securityKey) + "&vacationerId="  + encodeURIComponent(vacationerId)  + "&vacationerLoginCd="  + encodeURIComponent(vacationerLoginCd)  + "&vacationerLoginPassword="  + encodeURIComponent(vacationerLoginPassword);

	var url = "/cgi-bin/websitepro/websitepro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);
	if (entityType == 1) {url = "/cgi-bin/vrapro/vrapro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);}

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
          http_request = new XMLHttpRequest();
          if (http_request.overrideMimeType) {
             // set type accordingly to anticipated content type
             // http_request.overrideMimeType('text/xml');
             http_request.overrideMimeType('text/html');
          }
        } else if (window.ActiveXObject) { // IE
          try {
              http_request = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
             try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
             } catch (e) {}
          }
        }
        if (!http_request) {
           alert('Cannot create XMLHTTP instance');
           return false;
        }
	http_request.open("GET", url, true);
	http_request.onreadystatechange = websiteGetVacationerDataBack;
	http_request.send(null);
}

function websiteCheckLoginCodeBack() {
   if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            // extract inquiry return code stuff
	    var resultsElements = http_request.responseText.split('::');
	    var returnCode = resultsElements[1].split('|')[1];
	    var name = '';
	    var age = '';
	    var first = '';
	    var last = '';
	    var telNbr = '';
	    var vacationerFl = '';
	    var websiteFl = '';
	    var agencyFl = '';
	    var ownerFl = '';
	    var jointFl = '';
	    if (returnCode == 0) {
		// Found Login Code
		name = resultsElements[1].split('|')[2];
		vacationerFl = resultsElements[1].split('|')[3];
		websiteFl = resultsElements[1].split('|')[4];
		agencyFl = resultsElements[1].split('|')[5];
		ownerFl = resultsElements[1].split('|')[6];
		jointFl = resultsElements[1].split('|')[7];
		age = resultsElements[1].split('|')[8];
		first = resultsElements[1].split('|')[9];
		last = resultsElements[1].split('|')[10];
		telNbr = resultsElements[1].split('|')[11];
	    }

	    if (ivsSwitch == 'Y') {
	    	try {ivsCheckLoginCodeReturn(returnCode, name, age, first, last, telNbr, vacationerFl, websiteFl, agencyFl, ownerFl, jointFl);} catch(e) {alert(e);}
	    } 
	    else {
	    	try {checkLoginCodeReturn(returnCode, name, age, first, last, telNbr, vacationerFl, websiteFl, agencyFl, ownerFl, jointFl);} catch(e) {alert(e);}
	    }
        }
    }
}

function websiteCheckLoginCode(portal, sessionId, entityType, entityId, securityKey, loginCode, userType) {

	// Send an inquiry for a vacationer
	var posturl = "/cgi-bin/IVS/common/perllet_checkLoginCode.pl";

	var params = "sessionId=" + encodeURIComponent(sessionId) + "&portal=" + encodeURIComponent(portal) + "&entityType=" + encodeURIComponent(entityType) + "&entityId=" + encodeURIComponent(entityId)  + "&securityKey="  + encodeURIComponent(securityKey) + "&loginCode="  + encodeURIComponent(loginCode) + "&userType="  + encodeURIComponent(userType) + "&checkType="  + encodeURIComponent("C");

	var url = "/cgi-bin/websitepro/websitepro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);
	if (entityType == 1) {url = "/cgi-bin/vrapro/vrapro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);}

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
          http_request = new XMLHttpRequest();
          if (http_request.overrideMimeType) {
             // set type accordingly to anticipated content type
             // http_request.overrideMimeType('text/xml');
             http_request.overrideMimeType('text/html');
          }
        } else if (window.ActiveXObject) { // IE
          try {
              http_request = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
             try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
             } catch (e) {}
          }
        }
        if (!http_request) {
           alert('Cannot create XMLHTTP instance');
           return false;
        }
	http_request.open("GET", url, true);
	http_request.onreadystatechange = websiteCheckLoginCodeBack;
	http_request.send(null);
}

function websiteCheckLoginBack() {
   if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            // extract inquiry return code stuff
	    var resultsElements = http_request.responseText.split('::');
	    var returnCode = resultsElements[1].split('|')[1];
	    var type = '';
	    if (returnCode == 0) {
		// Found Login Code
		type = resultsElements[1].split('|')[2];
	    }
	    if (ivsSwitch == 'Y') {
		try {ivsCheckLoginReturn(returnCode, type);} catch(e) {alert(e);}
	    } 
	    else {
		try {checkLoginReturn(returnCode, type);} catch(e) {alert(e);}
	    }
        }
    }
}

function websiteCheckLogin(portal, sessionId, entityType, entityId, securityKey, loginCode, loginPassword, userType) {
	// Send an inquiry for a vacationer
	var posturl = "/cgi-bin/IVS/common/perllet_checkLoginCode.pl";

	var params = "sessionId=" + encodeURIComponent(sessionId) + "&portal=" + encodeURIComponent(portal) + "&entityType=" + encodeURIComponent(entityType) + "&entityId=" + encodeURIComponent(entityId)  + "&securityKey="  + encodeURIComponent(securityKey) + "&loginCode="  + encodeURIComponent(loginCode) + "&loginPassword="  + encodeURIComponent(loginPassword) + "&userType="  + encodeURIComponent(userType) + "&checkType="  + encodeURIComponent("L");

	var url = "/cgi-bin/websitepro/websitepro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);
	if (entityType == 1) {url = "/cgi-bin/vrapro/vrapro_client.pl?posturl=" + encodeURIComponent(posturl) + "&params=" + encodeURIComponent(params);}

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
          http_request = new XMLHttpRequest();
          if (http_request.overrideMimeType) {
             // set type accordingly to anticipated content type
             // http_request.overrideMimeType('text/xml');
             http_request.overrideMimeType('text/html');
          }
        } else if (window.ActiveXObject) { // IE
          try {
              http_request = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
             try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
             } catch (e) {}
          }
        }
        if (!http_request) {
           alert('Cannot create XMLHTTP instance');
           return false;
        }
	http_request.open("GET", url, true);
	http_request.onreadystatechange = websiteCheckLoginBack;
	http_request.send(null);
}

