function CheckNewTripFromTG(){
var tmpDestName = $('dest_1').value.strip();
if (tmpDestName == ''){
msgBox('information','Please enter a trip destination.');
$('dest_1').focus();
return;
}
if ($('dest_1_key').value.indexOf(",") == -1){ // destination country is unknown
SetUnknownDestination(1);
return;
}
var tmpDate1 = $('TripInfoStartDate').value;
var tmpDate2 = $('TripInfoEndDate').value;
tmpDate1 = tmpDate1.strip();
tmpDate2 = tmpDate2.strip();
if (tmpDestName==""){
alert("Please enter a destination.");
$('dest_1').focus();
return;
}
if (tmpDate1 == "") {
alert("Please enter a Start Date for the following destination: '" + tmpDestName + "'.");
$('TripInfoStartDateInput').value='';
$('TripInfoStartDateInput').focus();
return;
}
if (tmpDate2 == "") {
alert("Please enter an End Date for the following destination: '" + tmpDestName + "'.");
$('TripInfoEndDateInput').value='';
$('TripInfoEndDateInput').focus();
return;
}
document.addtrip.submit();
}
function createShortTripName(dest_name){
var TripName = '';
var destIDArray = new Array();
destIDArray = dest_name.split(",");
if (destIDArray.length > 0){
TripName = destIDArray[0];
}else{
TripName = dest_name;
}
return(TripName);
}
function CheckDestination(){
if ($('dest_1_key').value.indexOf(",") == -1){ // destination country is unknown
SetUnknownDestination(1);
}
}
function SetUnknownDestination(MyDestID){
var town =  $('dest_' + MyDestID).value;
var url = '/wayntravels.html?wci=MyTrips&wce=AddUnknownDestination&town=' + town;
var ajax1 = new Ajax.Request( url,  {
onSuccess : function(resp) {
//$('pleges_count').innerHTML = resp.responseText;
var responseXml = resp.responseXML;
for (var i = responseXml.firstChild; i != null; i = i.nextSibling) {
for (var j = i.firstChild; j != null; j = j.nextSibling) {
if(j.nodeValue != null && j.nodeValue != ''){
ShowAddUnknownDestinationBox('add_unknown_destination', j.nodeValue);
}
}
}
},
onFailure : function() {
//alert("Sorry there was an error processing your request.\nPlease try again later");
return false;
},
method : 'get'
});
}
function ShowAddUnknownDestinationBox(BoxName, Content){
var yS;
var wH;
if (window.innerHeight && window.scrollMaxY) {
yS = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){
yS = document.body.scrollHeight;
} else {yS = document.body.offsetHeight}
if (self.innerHeight) {wH = self.innerHeight;}
else if (document.documentElement && document.documentElement.clientHeight) {
wH = document.documentElement.clientHeight;
} else if (document.body) {wH = document.body.clientHeight}
if(yS < wH){pH=wH} else {pH=yS}
var BckgAndBoxDiv = $(BoxName);
BckgAndBoxDiv.innerHTML='';
BckgAndBoxDiv.style.height=pH+'px';
BckgAndBoxDiv.setAttribute('style','position:absolute;display:block;top:0px;left:0px;width:100%;height:' + pH + 'px;');
BckgAndBoxDiv.style.position = 'absolute';
BckgAndBoxDiv.style.width = document.body.clientWidth;
BckgAndBoxDiv.style.left = '0px';
BckgAndBoxDiv.style.top = '0px';
BckgAndBoxDiv.style.display='block';
var BaseDiv = document.createElement('div');
BaseDiv.style.height=pH+'px';
BaseDiv.setAttribute('style','position:absolute;display:block;opacity:0.5;background-color:#000000;top:0px;left:0px;width:100%;height:' + pH + 'px;overflow:hidden;');
BaseDiv.style.position = 'absolute';
BaseDiv.style.width = document.body.clientWidth;
BaseDiv.style.left = '0px';
BaseDiv.style.top = '0px';
BaseDiv.style.background= '#000000';
BaseDiv.style.filter='alpha(opacity=50)';
var screenW = window.innerWidth != null ? window.innerWidth : document.documentElement &&  document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null ? document.body.clientWidth : null;
var screenH = window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight:null;
var BoxDiv = document.createElement('div');
BoxDiv.setAttribute('id', 'AddUnknownDescBoxDiv');
BoxDiv.style.position = 'absolute';
BoxDiv.style.width = '410px';
BoxDiv.style.left = (screenW/2)-205;
BoxDiv.innerHTML = Content
BoxDiv.style.marginTop = document.body.scrollTop + (screenH/2)-170;
BaseDiv.style.display = 'block';
BckgAndBoxDiv.appendChild(BaseDiv);
BckgAndBoxDiv.appendChild(BoxDiv);
}
function getStates(){
alert('a');
try {
var cc = $('add_unknw_dest_country').value;
oXMLHTTP = newXMLobject();
oXMLHTTP.open("GET", "/waynfx.html?wci=GetCitiesFromCountry&countryCode=" +cc, true);
goSelect = $('add_unknw_dest_state');
oXMLHTTP.onreadystatechange = manageStateChange;
oXMLHTTP.send(null);
}
catch (err) {
alert("Sorry, server is not available at this time to process your request.");
}
}
function getCountries() {
try {
document.body.style.cursor='wait';
oXMLHTTP = newXMLobject();
oXMLHTTP.open("GET", "/waynfx.html?wci=GetCountries", true);
goSelect = $('add_unknw_dest_country');
oXMLHTTP.onreadystatechange = manageStateChange;
oXMLHTTP.send(null);
}
catch (err) {
alert("Sorry, server is not available at this time to process your request.");
}
}
function acceptDestination(){
var country_code = $('add_unknw_dest_country').value;
var city_code = $('add_unknw_dest_state').value;
$("dest_1_key").value = country_code + ',' + city_code +',0';
$('add_unknown_destination').style.display = 'none';
setNewFlagIco('1');
}
function manageStateChange() {
switch (oXMLHTTP.readyState) {
case 2, 3:     // --- RESPONSE IS IN PROGRESS ---
break;
case 4:     // --- RESPONSE FROM SERVER HAS COMPLETED ---
if (oXMLHTTP.status != 200) {
return false;
}
var xmlList = oXMLHTTP.responseXML.getElementsByTagName('setpoint');
if(xmlList.length > 0){
goSelect.options.length = 0;
if (goSelect.name=='countries')
goSelect.options[0] = new Option("Select Country","-1");
else
goSelect.options[0] = new Option("Select State","-1");
for(i=0; i<xmlList.length; i++){
goSelect.options.length++;
goSelect.options[goSelect.options.length-1] = new Option(xmlList.item(i).getAttribute('name'), xmlList.item(i).getAttribute('code'));
}
}else{
goSelect.options.length = 0;
if (goSelect.name=='countries')
goSelect.options[0] = new Option("Country Not Found",0);
else{
goSelect.options[0] = new Option("State Not Found",0);
acceptDestination();
}
}
document.body.style.cursor='auto';
oXMLHTTP = null
break;
}
}
function cancel_add_unknown_destination(){
$('add_unknown_destination').style.display='none';
}
function accept_unknown_destination(hint_element){
$("dest_1_key").value = $('box_hint_place_key_' + hint_element).value;
$("dest_1").value = $('box_hint_place_name_' + hint_element).value;
$('add_unknown_destination').style.display = 'none';
setNewFlagIco('1');
}
function selected_box_hint(hint_id){
var allhintcount = $('all_boxes_hint').value;
for (var i=1;i<=allhintcount; i++){
$('add_unknown_destination_box_hint_' + i).style.backgroundColor='#ffffff';
}
$('add_unknown_destination_box_hint_' + hint_id).style.backgroundColor='#EFEFEF';
accept_unknown_destination(hint_id);
}
function setNewFlagIco(i){
var country=$('dest_'+i+'_key').value.split(",");
if (country[0]==0 || country[0]=="" || country[0]=="ZZ"){
$('country_flag_'+i).src=appproxypath+'images/spacer.gif';
}
else	{
$('country_flag_'+i).src=appproxypath+'images/flags_small2/'+country[0]+'.gif';
$('country_flag_'+i).style.display="inline";
}
}
