﻿var m_ctrlId = "ctl00_ContentPlaceHolder1_";

function MoveSelected()
{
    	
    var objFrom = document.getElementById(m_ctrlId + "lstBoxCountries");
    var objTo = document.getElementById(m_ctrlId + "lstBoxSelected");
    
    
    var boolobj = false;
    
    for(var i=0; i< objFrom.length; i++)
    {            
        if (objFrom.options[i].selected) {
            boolobj = true;
            var val = objFrom.options[i].value;
            var txt = objFrom.options[i].text;
            
            // If the option does not exist, add the option
            if (IsExists(objTo, val) == false)
            {
                addOption(objTo, txt, val, 1);
                
            }
        }
    }
    
    if(!boolobj)
    {
        alert("Please select atleast one country");
        return false;
    }    
}

function IsExists(objDdl, val)
{
    for(var i=0; i<objDdl.length; i++)
    {
        var optVal = objDdl.options[i].value;
        // If the value exists return true
        if (optVal == val)
            return true;
    }
    return false;
}

//function add a new option to the list box
function addOption(obj, txt, val, txtCompare)
{
    var txtToCompare = txt.toUpperCase();
    var posToInsert = -1;
    
    // Create new option element
    var oOption = new Option(txt, val);
	
	// If text comparision needs to be done
	if (txtCompare == 1)
	{
	    // Check where to insert this
	    for(var i=0; i<obj.length; i++)
	    {
	        var txt = obj.options[i].text.toUpperCase();
	        var val = obj.options[i].value;
	        
	        if (txt > txtToCompare)
	        {
	            posToInsert = i;
	            break;
	        }
	    }
	}
		
	// Add the option
    
    //obj.add(oOption, 0);

	if (BrowserDetect.browser == "Firefox")
	{
	    if (posToInsert >= 0)
	       obj.options.add(oOption, posToInsert);
	    else
	        obj.options.add(oOption);
	}
    else
    {
        if (posToInsert >= 0)
	       obj.add(oOption, posToInsert);
	    else
	        obj.add(oOption);
    }
	    
	    
}

function removeSelected()
{
    var objFrom = document.getElementById(m_ctrlId + "lstBoxSelected");
	if (objFrom.length > 0)
	{
	    var index = objFrom.selectedIndex;
	    while (index != -1)
	    {
	        //remove the option
	        objFrom.options[index] = null;
	        index = objFrom.selectedIndex;
	    }
	}	
}
 
 function SubmitForm()
 {
 
       var checkBoxId = "rbListTravelType_";
       var chkCnt =0;     
      
     
     var travelcnt = document.getElementById(m_ctrlId + "hdnCheckboxTravel").value;
     
     for(var i=0;i<travelcnt;i++)
     {
        var objChkBox = document.getElementById(m_ctrlId+checkBoxId+i);
        if(objChkBox != null)
        {
           if(objChkBox.checked == true)
           {
               chkCnt = chkCnt + 1;
           }      
        }
     }
     if(chkCnt =="0")
     {
       alert("Please select a travel type");
       return false;
     }
     else
     {
        return true;
     }
 }

 function retainSelectedCountries()
 {
     var objTo = document.getElementById(m_ctrlId + "lstBoxSelected");
        
        if(objTo.length == "0")
        {
          alert("Please select the destination you wish to travel");
          objTo.focus();
          return false;
        }
    
    if(!dateValidation())
    {
        //alert("Travel date should be greater or equel to current date");
        return false;
    }
    
    var selectedCountries = "";
    var selectedCities = "";
    var selectedCountryNames = "";
    var selectedCityNames = "";
    
    var objTxtCountries = document.getElementById(m_ctrlId + "txtCountries");
    var objTxtCities = document.getElementById(m_ctrlId + "txtCities");
    var objTxtCountryNames = document.getElementById(m_ctrlId + "txtCountryNames");
    var objTxtCityNames = document.getElementById(m_ctrlId + "txtCityNames");
    var objCountries = document.getElementById(m_ctrlId + "lstBoxSelected");
    
    for(var i=0; i< objCountries.length; i++)
    {      
        var val = objCountries.options[i].value;
        var txt = objCountries.options[i].text;
        
        var arrVal = val.split("_");
        if (arrVal[0] == "CO")
        {
            if (selectedCountries != "") 
            {
                selectedCountries = selectedCountries + ", ";
                selectedCountryNames = selectedCountryNames + ", ";
            }
            selectedCountries = selectedCountries + arrVal[1];
            selectedCountryNames = selectedCountryNames + "Country;"+ txt;
        }
        else
        {
            if (selectedCities != "") 
            {
                selectedCities = selectedCities + ", ";
                selectedCityNames = selectedCityNames + ", ";
            }
            selectedCities = selectedCities + arrVal[1];
            selectedCityNames = selectedCityNames + "City;" + txt;
        }
    }
    objTxtCountries.value = selectedCountries;
    objTxtCities.value = selectedCities;
    
    objTxtCountryNames.value = selectedCountryNames;
    objTxtCityNames.value = selectedCityNames;
    
    return true
 }
 
 function AmtValidation()
 {
    var obj = document.getElementById("ctl00_ContentPlaceHolder1_txtAmount");
        if(obj.value != '')
        {
            if(isNaN(obj.value))
            {
                alert("Enter digits only");
                return false;
            }
            else
            {
            return true;
            }
        }
        else
        {
            alert("Please Enter Amount");
            return false;
        }
 }


//function check date is greter than current date or not

function dateValidation()
{
    var SourceDate = new Date;
    var CurrentDate =  new Date;
   
    var month;
    var day;
    var year;
    
    var objDay = document.getElementById(m_ctrlId + "ddlStDay");
    var objMonth = document.getElementById(m_ctrlId + "ddlStMonth");
    var objYear = document.getElementById(m_ctrlId + "ddlStYear");
    
    for(var i=0; i< objDay.length; i++)
    {            
        if (objDay.options[i].selected == true)
        {
            var val = objDay.options[i].value;
            day = val;
            SourceDate.setDate(val);          
        }
    }    
    
    for(var i=0; i< objMonth.length; i++)
    {            
        if (objMonth.options[i].selected == true)
        {
            var val = objMonth.options[i].value;
           
            month = val;
            
            SourceDate.setMonth(val-1);          
        }
    } 
  
    for(var i=0; i< objYear.length; i++)
    {            
        if (objYear.options[i].selected == true)
        {
            var val = objYear.options[i].value;
            year = val;
            SourceDate.setFullYear(val);          
        }
    } 
    
    
    
    if(month == 2)
    {
       
       if (((year % 400)==0) || (((year % 100)!=0) && (year % 4)==0))
       {
            if ((day == 30)|| (day == 31))
            {
                alert("This month not contain this day");
                return false;
            }
            
       }
       else
       {
            if ((day == 29) || (day == 30) || (day == 31))
            {
                alert("This month not contain this day");
                return false;
            }
            
       }
    }
    
    if((month==4)||(month==6)||(month==9)||(month==11))
    {
        if(day==31)
        {   
            alert("This month not contain this day");
            return false;
        }
    }
    
    if (SourceDate < CurrentDate)  
    {
        
        alert("Travel date should be greater or equal to current date");
        return false
    } 
    else
    {
        
        return true    
    }
     
}



// function to dispaly the currect date format.
function dispDate(dateVal)
{

DaystoAdd=dateVal
TodaysDate = new Date();
TodaysDay = new Array('Sunday', 'Monday', 'Tuesday','Wednesday', 'Thursday', 'Friday', 'Saturday');
TodaysMonth = new Array('January', 'February', 'March','April', 'May','June', 'July', 'August', 'September','October', 'November', 'December');
DaysinMonth = new Array('31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');

function LeapYearTest (Year)
{
  if (((Year % 400)==0) || (((Year % 100)!=0) && (Year % 4)==0))
   {
     return true;
   }
   else 
   {
     return false;
   }
}

CurrentYear = TodaysDate.getYear();
if (CurrentYear < 2000) 
    CurrentYear = CurrentYear + 1900;
    currentMonth = TodaysDate.getMonth();
    DayOffset = TodaysDate.getDay();
    currentDay = TodaysDate.getDate();
    month = TodaysMonth[currentMonth];
if (month == 'February') 
{
   if (((CurrentYear % 4)==0) && ((CurrentYear % 100)!=0) || ((CurrentYear % 400)==0))
   {
     DaysinMonth[1] = 29;
   }
   else
   {
    DaysinMonth[1] = 28;
   }
}
days = DaysinMonth[currentMonth];
currentDay += DaystoAdd;
if (currentDay > days)
{
 if (currentMonth == 11)
 {
    currentMonth = 0;
    month = TodaysMonth[currentMonth];
    CurrentYear = CurrentYear + 1
 }
 else
 {
   month = TodaysMonth[currentMonth+1];
 }
 
 currentDay = currentDay - days;
}
DayOffset += DaystoAdd;

function offsettheDate (offsetCurrentDay)
{
  if (offsetCurrentDay > 6)
  {
     offsetCurrentDay -= 6;
     DayOffset = TodaysDay[offsetCurrentDay-1];
     offsettheDate(offsetCurrentDay-1);
  }
  else 
  {
    DayOffset = TodaysDay[offsetCurrentDay];
    return true;
  }
}
  offsettheDate(DayOffset);TheDate = DayOffset + '<br/>';
  TheDate += currentDay + ', '; 
  TheDate += month + ' ';

if (CurrentYear<100) CurrentYear="19" + CurrentYear;
    TheDate += CurrentYear;
    document.write(' '+TheDate);
}

// Ajax Implementation

      
// to set Bookmark
function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}
//book mark for the page.

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();