﻿
var SeachOptionSelected="HotelOnly";
var CtlChkInDate="UscSearch_txtHCCheckIndate";
var CtlChkOutDate="UscSearch_txtHCCheckOutdate";
var CtlChkInBtn="imgHCCheckIndate";
var CtlChkOutBtn="imgHCCheckOutdate";

function ShowHideAdditionalOptions(str)
{
    //Adition Option Button.
    var sender =document.getElementById('UscSearch_'+str);
    var hdnIsAddOptionExpand =document.getElementById('UscSearch_hdnIsAddOptionExpand');
    
    //Display or Hide Additional Option Panel.
    if(sender.style.display=='none')
        sender.style.display="block";
    else
        sender.style.display="none";
     
     //Preserving Additional Option Status.  
     hdnIsAddOptionExpand.value=sender.style.display;
     
     AdjustHeight();
     
}

//Displays the Calendar.
function ShowCalendar()
{
    var sender="";
    var CtlOption =frmSearch.UscSearch$rblSearcType;
    for(var i = 0; i < CtlOption.length; i++) 
    if(CtlOption[i].checked) 
	    sender= CtlOption[i].value;

    if(sender=="HotelCar" || sender=="HotelOnly")
    {
        CtlChkInDate="UscSearch_txtHCCheckIndate";
        CtlChkOutDate="UscSearch_txtHCCheckOutdate";
        CtlChkInBtn="imgHCCheckIndate";
        CtlChkOutBtn="imgHCCheckOutdate";
    }
    else if(sender=="AirHotel" || sender=="AirHotelCar")
    {
        CtlChkInDate="UscSearch_txtFHDepart";
        CtlChkOutDate="UscSearch_txtFHReturn";
        CtlChkInBtn="imgFHDepart";
        CtlChkOutBtn="imgFHReturn";
    }

   
    startDate=new Date (document.getElementById(CtlChkInDate).value);
    endDate=new Date (document.getElementById(CtlChkOutDate).value);
	callbacks = 0;
	
	InitializeCalendar(); 
}



function ShowCalendar1()
{
        //CtlChkInDate="txtOrderFrom";
        //CtlChkOutDate="txtOrderTo";
        //CtlChkInBtn="imgHCCheckIndate";
        //CtlChkOutBtn="imgHCCheckOutdate";
    startDate=new Date (document.getElementById(CtlChkInDate).value);
   	endDate=new Date (document.getElementById(CtlChkOutDate).value);
	callbacks = 0;
	
	InitializeCalendar1(); 
}

function ShowBookingCalendar()
{
    startDate = new Date(document.getElementById(CtlChkInDate).value);

    callbacks = 0;

    InitializeBookingCalendar();
}
<!--  to hide script contents from old browsers
var startDate;
var endDate;
var callbacks = 0;

function resetDates() {
	startDate = endDate = null;
}


/*
* Given two dates (in seconds) find out if date1 is bigger, date2 is bigger or
 * they're the same, taking only the dates, not the time into account.
 * In other words, different times on the same date returns equal.
 * returns -1 for date1 bigger, 1 for date2 is bigger 0 for equal
 */

function compareDatesOnly(date1, date2) {
	var year1 = date1.getYear();
	var year2 = date2.getYear();
	var month1 = date1.getMonth();
	var month2 = date2.getMonth();
	var day1 = date1.getDate();
	var day2 = date2.getDate();

	if (year1 > year2) {
		return -1;
	}
	if (year2 > year1) {
		return 1;
	}

	//years are equal
	if (month1 > month2) {
		return -1;
	}
	if (month2 > month1) {
		return 1;
	}

	//years and months are equal
	if (day1 > day2) {
		return -1;
	}
	if (day2 > day1) {
		return 1;
	}

	//days are equal
	return 0;


	/* Can't do this because of timezone issues
	var days1 = Math.floor(date1.getTime()/Date.DAY);
	var days2 = Math.floor(date2.getTime()/Date.DAY);
	return (days1 - days2);
	*/
}

function filterDates1(cal) {
	startDate = cal.date;
	/* If they haven't chosen an 
	end date before we'll set it to the same date as the start date This
	way if the user scrolls in the start date 5 months forward, they don't
	need to do it again for the end date.
	*/
    SetDaysInterval();
	if (endDate == null) { 
		Calendar.setup({
			inputField     :    CtlChkOutDate,
			//button       :    imgHCheckOutDate,  // What will trigger the popup of the calendar
			ifFormat       :    "%m/%d/%Y",//"%Y-%m-%d ",
			timeFormat     :    "24",
			date           :     startDate,
			electric       :     false,
			showsTime      :     false,          //no time
			disableFunc    :    dateInRange2, //the function to call
			onUpdate       :    filterDates2
		});
	}
}

function filterDates2(cal) {
	endDate = cal.date;
}

/*
* Both functions disable and hilight dates.
*/

/* 
* Can't choose days after the
* end date if it is choosen, hilights start and end dates with one style and dates between them with another
*/
function dateInRange1(date) {

	if (endDate != null) {

		// Disable dates after end date
		var compareEnd = compareDatesOnly(date, endDate);
		if  (compareEnd < 0) {
			return (false);
		}

		// Hilight end date with "edges" style
		if  (compareEnd == 0) {
			{return "edges";}
		}


		// Hilight inner dates with "between" style
		if (startDate != null){
			var compareStart = compareDatesOnly(date, startDate);
			if  (compareStart < 0) {
				return "between";
			} 
		} 
	}

	//disable days prior to today
	var today = new Date();
	var compareToday = compareDatesOnly(date, today);
	if (compareToday > 0) {
		return(true);
	}


	//all other days are enabled
	return false;
	//alert(ret + " " + today + ":" + date + ":" + compareToday + ":" + days1 + ":" + days2);
	return(ret);
}

/* 
* Can't choose days before the
* start date if it is choosen, hilights start and end dates with one style and dates between them with another
*/

function dateInRange2(date) {
	if (startDate != null) {
		// Disable dates before start date
		var compareDays = compareDatesOnly(startDate, date);
		if  (compareDays < 0) {
			return (true);
		}

		// Hilight end date with "edges" style
		if  (compareDays == 0) {
			{return "edges";}
		}

		// Hilight inner dates with "between" style
		if ((endDate != null) && (date > startDate) && (date < endDate)) {
			return "between";
		} 
	} 

	var now = new Date();
	if (compareDatesOnly(now, date) < 0) {
		return (true);
	}

	//all other days are enabled
	return false;
}
// end hiding contents from old browsers  -->
function InitializeCalendar()
{
    var cal = new Calendar.setup({
	
	        inputField     :    CtlChkInDate,   // id of the input field
	        button         :    CtlChkInBtn,  // What will trigger the popup of the calendar
	        ifFormat       :    "%m/%d/%Y",       // format of the input field
	        timeFormat     :    "24",
	        showsTime      :     false,          //no time
	        electric       :     false,
	        dateStatusFunc :    dateInRange1, //the function to call
	        onUpdate       :    filterDates1
		
    });
	
        Calendar.setup({
	        inputField     :    CtlChkOutDate,
	        button         :    CtlChkOutBtn,  // What will trigger the popup of the calendar
	        ifFormat       :    "%m/%d/%Y",
	        timeFormat     :    "24",
	        showsTime      :     false,          //no time
	        electric       :     false,
	        dateStatusFunc :    dateInRange2, //the function to call
	        onUpdate       :    filterDates2
        });
}
function InitializeCalendar1()
{
    var cal = new Calendar.setup({
	
	        inputField     :    CtlChkInDate,   // id of the input field
	        button         :    CtlChkInBtn,  // What will trigger the popup of the calendar
	        ifFormat       :    "%m/%d/%Y",       // format of the input field
	        timeFormat     :    "24",
	        showsTime      :     false,          //no time
	        electric       :     false
	       
		
    });
	
        Calendar.setup({
	        inputField     :    CtlChkOutDate,
	        button         :    CtlChkOutBtn,  // What will trigger the popup of the calendar
	        ifFormat       :    "%m/%d/%Y",
	        timeFormat     :    "24",
	        showsTime      :     false,          //no time
	        electric       :     false
	   
        });
}

function InitializeBookingCalendar()
{
    var cal = new Calendar.setup({
	
	        inputField     :    CtlChkInDate,   // id of the input field
	        button         :    CtlChkInBtn,  // What will trigger the popup of the calendar
	        ifFormat       :    "%m/%d/%Y",       // format of the input field
	        timeFormat     :    "24",
	        showsTime      :     false,          //no time
	        electric       :     false
	        //onUpdate       :    startDate
            //dateStatusFunc :    dateInRange1, //the function to call
		
    });
 }

//Validating the Form.
function ValidateForm()
{
    var sender="";
    var CtlOption =frmSearch.UscSearch$rblSearcType;
    for(var i = 0; i < CtlOption.length; i++) 
    if(CtlOption[i].checked) 
	    SeachOptionSelected= CtlOption[i].value;
	    
    var IsTrue=false;
     if(SeachOptionSelected=='HotelCar' || SeachOptionSelected=='HotelOnly')
    {
       if(ValidateLocations(null,document.getElementById('UscSearch_ddlHCDestination')) && ValidateRating() && ValidateDateRange(document.getElementById('UscSearch_txtHCCheckIndate'),document.getElementById('UscSearch_txtHCCheckOutdate')))
            IsTrue =true; 
    }
    else if(SeachOptionSelected=='AirHotel' || SeachOptionSelected=='AirHotelCar')
    {
       if(ValidateLocations(document.getElementById('UscSearch_txtFHLeavingFrom'),document.getElementById('UscSearch_ddlFHGoingTo')) && ValidateRating() && ValidateDateRange(document.getElementById('UscSearch_txtFHDepart'),document.getElementById('UscSearch_txtFHReturn')))
            IsTrue =true; 
    }
    
    if(IsTrue)
    {
      // $("#Container").addClass("Progress");
      if (top.location.href.search("/farefinder/")>0)
      {
        parent.parent.BlockingPage(AgencyLogoPath);
      }
      else
      {
        BlockPage();
      }
        return true;
    }
    else
    {
        return false;
        }
}

function BlockPage() {
    var div = document.createElement("div");
    div.cellSpacing = '1px';
    div.cellPadding = '2px';
    div.style.border = '0px';
    div.style.position = 'absolute';
    var top = 0;
    var left = 0;
    div.style.top = "0px";
    div.style.left = "0px";
    div.id = 'blockdiv';
    document.body.appendChild(div);
    if ($.browser.msie) {
        div.style.height = $(document).height();
        div.style.width = $(document).width();
    }
    else {
        div.style.height ="100%";// document.height+50+"px";
        div.style.width = "100%";
    }
    $('#blockdiv').block({ message: null });
    if (AgencyLogoPath.length > 0)
    {
        document.getElementById("imgAgencyLogo").src = AgencyLogoPath;
        document.getElementById("imgAgencyLogo").style.visibility = "visible"; 
    }
    else
        document.getElementById("imgAgencyLogo").style.visibility = "hidden";


}

//Validating Check-in and Check-out Date.
function ValidateDateRange(CtlCheckinDate, CtlCheckOutDate)
{
    if(CtlCheckinDate.value=="")
    {
        CtlCheckinDate.focus();
        alert("Check-in/Depart date required")
        return false;
    }
    
     if(CtlCheckOutDate.value=="")
    {
        CtlCheckOutDate.focus();
        alert("Check-out/Return date required")
        return false;
    }
 
//Validating date Format. 
       if(validateDateFormat(CtlCheckinDate.value,'U','F') ==false)
       {
            CtlCheckinDate.focus();
            CtlCheckinDate.select();
            return false; 
       }
       if(validateDateFormat(CtlCheckOutDate.value,'U','F') ==false)
       {
            CtlCheckOutDate.focus();
            CtlCheckOutDate.select();
            return false; 
       }
   
    var date1 = new Date(CtlCheckinDate.value);
    var date2 = new Date(CtlCheckOutDate.value);

    var date1Comp = date1.getTime(); // milliseconds
    var date2Comp = date2.getTime();

    if (date1Comp > date2Comp)
    {
        alert('Check-in/Depart date should be less than Check-out/Return date.');
        CtlCheckOutDate.focus();
        CtlCheckOutDate.select();
        return false;
    }
    return true;
}

//Validating Destination.
function ValidateLocations(CtlLeavingFrom, CtlGoingTo)
{

    if(CtlLeavingFrom!=null)
        if(trim(CtlLeavingFrom.value)=="")
        {
             alert('Enter Leaving From');
             CtlLeavingFrom.focus();
             return false; 
        }
    if(CtlGoingTo!=null)
        if(trim(CtlGoingTo.value)=="")
        {
            alert('Select Destination/Going To');
            CtlGoingTo.focus();
            return false;  
        }
   return true;
}

//Validating Check-in Date and Checkout Date.
function ValidateDate(CtlToValidate1,CtlToValidate2)
{
    if(CtlToValidate1!=null && CtlToValidate2!=null)
        if(CtlToValidate1.value=="" || CtlToValidate2.value=="")
            return false;
            
}

//Validating MinRate and MaxRate.
function ValidateRating()
{
    var DiffValue;
    
    DiffValue=parseInt(document.getElementById('UscSearch_UscHotelAdditionalOption_ddlMaxRating').value)-parseInt(document.getElementById('UscSearch_UscHotelAdditionalOption_ddlMinRating').value);
    
    if(DiffValue<0)
    {
        alert('MinRating should be less than MaxRating')
        return false;
    }
    
    var MaxRatingDiff=parseInt(document.getElementById('UscSearch_hdnMaxRatingDiff').value)
    if(DiffValue>MaxRatingDiff)
    {
        alert('Difference between MaxRating and MinRating should not be greater than ' + MaxRatingDiff)
        return false;
    }
        
    return true;    
}

//Allows number only.
function isNumberKey(evt)
{
     var charCode = (evt.which) ? evt.which : event.keyCode
     if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

     return true;
}

//Adding Intervals when Changing Checkin Date.
function SetDaysInterval()
{

    var DaysAdvance=document.getElementById('UscSearch_hdnDaysAdvance').value;
    var ChkinDate=new Date(document.getElementById(CtlChkInDate).value);
    var newCheckOutDate=new Date(ChkinDate.getTime()+ parseInt(DaysAdvance)*24*60*60*1000);
    var day,month;
    day=newCheckOutDate.getDate();
    month=newCheckOutDate.getMonth() +1;
    
    if(day.toString().length<2)
       day='0'+day.toString();
    if(month.toString().length<2) 
       month='0'+month.toString(); 
    document.getElementById(CtlChkOutDate).value=month+'/'+day+'/'+ newCheckOutDate.getFullYear();
    startDate=new Date (document.getElementById(CtlChkInDate).value);
	endDate=new Date (document.getElementById(CtlChkOutDate).value);
	frmSearch.UscSearch$hdnCheckoutDate.value=document.getElementById(CtlChkOutDate).value;
	callbacks = 0;
}

///Show or hide the Tab Content.
///This function Used in 'uscRoomView.ascx' Control.
function ShowTabContent(SelectedTab)
{
    var div
    var tdLeft;
    var tdRight;
    var tdBg;
    var a;
    document.getElementById("divRoomDetails").style.display ="none";
    document.getElementById("tdRoomDetailslft").className="inactivetablft";
    document.getElementById("tdRoomDetailsbg").className="inactivetabbg";
    document.getElementById("aRoomDetails").className="inactivetab";
    document.getElementById("tdRoomDetailsrht").className="inactivetabrht";
    
    document.getElementById("divHotelDetails").style.display ="none";
    document.getElementById("tdHotelDetailslft").className="inactivetablft";
    document.getElementById("tdHotelDetailsbg").className="inactivetabbg";
    document.getElementById("aHotelDetails").className="inactivetab";
    document.getElementById("tdHotelDetailsrht").className="inactivetabrht";

    document.getElementById("divPictures").style.display ="none";
    document.getElementById("tdPictureslft").className="inactivetablft";
    document.getElementById("tdPicturesbg").className="inactivetabbg";
    document.getElementById("aPictures").className="inactivetab";
    document.getElementById("tdPicturesrht").className="inactivetabrht";
    
    
    document.getElementById("div"+SelectedTab).style.display ="block";
    document.getElementById("td"+SelectedTab+"lft").className="activetablft";
    document.getElementById("td"+SelectedTab+"bg").className="activetabbg";
    document.getElementById("a"+SelectedTab).className="activetab";
    document.getElementById("td"+SelectedTab+"rht").className="activetabrht";
   
   try
   { 
        top.frm_onload();
   }
   catch(err) 
   {}
}

function ValidateCreditCardDetails()
{
    var txtCCHolderName=document.getElementById('txtCCHolderName');
    var txtCCNumber=document.getElementById('txtCCNumber');
    var txtCVVNumber=document.getElementById('txtCVVNumber');
    var ddlMonth=document.getElementById('ddlMonth');
    var ddlYear=document.getElementById('ddlYear');
    
    if(txtCCHolderName!=null)
        if(trim(txtCCHolderName.value)=="")
        {
            alert('Name on Card  required')
            txtCCHolderName.focus();
            return false;
        }
    
    if(txtCCNumber!=null)
   { 
        if(trim(txtCCNumber.value)=="")
        {
            alert('Credit Card Number  required')
            txtCCNumber.focus();
            return false;
        }
        
       if( ValidateCCNumber(txtCCNumber.value)==false)
      { 
        txtCCNumber.focus();
        txtCCNumber.select();
        return false; 
      }
  }
    
    if(txtCVVNumber!=null)
        if(trim(txtCVVNumber.value)=="")
        {
            alert('Card Verification Number  required')
            txtCVVNumber.focus();
            return false;
        }
        
    if(ddlMonth!=null)
        if(ddlMonth.value=="")
        {
            alert('Select Month')
            ddlMonth.focus();
            return false;
        }
        
    if(ddlYear!=null)
        if(ddlYear.value=="")
        {
            alert('Select Year')
            ddlYear.focus();
            return false;
        }
       
    var CurDate = new Date()
    var cYear=CurDate.getFullYear()
    var cMonth=parseInt(CurDate.getMonth()) + 1;
    
    if(parseInt(ddlMonth.value)<= cMonth && parseInt(ddlYear.value)<=cYear)
    {
        alert("Invalid Card Expiry Date")
        return false;
    }

    return ValidateBillingDetails();
}

function ValidateBillingDetails()
{
    var txtAddress1=document.getElementById('UscBillingDetails_txtAddress1');
    var txtCity=document.getElementById('UscBillingDetails_txtCity');
    var ddlState=document.getElementById('UscBillingDetails_ddlState');
    var txtPostalCode=document.getElementById('UscBillingDetails_txtPostalCode');
    var ddlCountry=document.getElementById('UscBillingDetails_ddlCountry');
    var txtEmail=document.getElementById('UscBillingDetails_txtEmail');
    var txtPhone=document.getElementById('UscBillingDetails_txtPhone');
    
    if(txtAddress1!=null)
        if(trim(txtAddress1.value)=="")
        {
            alert('Address line 1 required')
            txtAddress1.focus();
            return false;
        }
    
    if(txtCity!=null)
        if(trim(txtCity.value)=="")
        {
            alert('City required')
            txtCity.focus();
            return false;
        }
    
    if(ddlState!=null)
        if(ddlState.value=="")
        {
            alert('Select State')
            ddlState.focus();
            return false;
        }
        
    if(txtPostalCode!=null)
        if(trim(txtPostalCode.value)=="")
        {
            alert('Postal Code required')
            txtPostalCode.focus();
            return false;
        }
    
    if(ddlCountry!=null)
        if(ddlCountry.value=="")
        {
            alert('Select Country')
            ddlCountry.focus();
            return false;
        }
        
    if(txtEmail!=null)
        if(trim(txtEmail.value)=="")
        {
            alert('Email required')
            txtEmail.focus();
            return false;
        }
        else if(IsValidEmail(txtEmail.value)==false)
            return false;
    
    if(txtPhone!=null)
        if(trim(txtPhone.value)=="")
        {
            alert('Phone number required')
            txtEmail.focus();
            return false;
        }
        
    if(ValidateTermsAndConditions()==false)
        return false;
        
    return true;
}

function ValidateBankingDetails()
{
    var txtAccountNumber=document.getElementById('txtAccountNumber');
    var txtBankRoutingNumber=document.getElementById('txtBankRoutingNumber');
    var txtAccountHolderName=document.getElementById('txtAccountHolderName');
    
    if(txtAccountNumber!=null)
        if(trim(txtAccountNumber.value)=="")
        {
           alert("Account Number required")
           txtAccountNumber.focus();
           return false;
        }
    
    if(txtBankRoutingNumber!=null)
        if(trim(txtBankRoutingNumber.value)=="")
        {
           alert("Routing Number required")
           txtBankRoutingNumber.focus();
           return false;
        }
    
    if(txtAccountHolderName!=null)
        if(trim(txtAccountHolderName.value)=="")
        {
           alert("Account Holder Name required")
           txtAccountHolderName.focus();
           return false;
        }
        
    return ValidateBillingDetails();
}

function ValidatePaymnetDetails()
{
    var rblPaymentType=frmPaymentDetails.rblPaymentType;
    var PaymentType="CreditCard";
    var IsValid=false;
    
    for(var i = 0; i < rblPaymentType.length; i++) 
    if(rblPaymentType[i].checked) 
	    PaymentType= rblPaymentType[i].value;
	    
	    if(PaymentType=="CreditCard")
	        IsValid= ValidateCreditCardDetails();
	    else
	        IsValid= ValidateBankingDetails();
	       
	    if(IsValid) 
            ProcessingImage();
        else
            return false;
}

function ValidateTermsAndConditions()
{
    if(document.getElementById("UscBillingDetails_chkAccept")!=null)
        if(document.getElementById("UscBillingDetails_chkAccept").checked == false)
        {
            alert('Accept terms and conditions');
            return false;
        }
        
    return true;
}

function ProcessingImage()
{
    if (document.getElementById('Processing'))
    {
        var df=document.getElementById('Processing');
        df.style.position='absolute';
        df.style.left = 220
        df.style.top = 220
        df.style.zIndex = 999999; 
        //Used for current and previous tabs to avoid certain block of code in the control code behind. (Behaviour of !isPostBack).
    
        document.getElementById('Processing').style.display ="block";
    }
    
    return true;
}

function IsValidEmail(strEmail)
{
        var validRegExp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
        if(strEmail.length>0)
        {
            if (strEmail.search(validRegExp) == -1) 
            {
                alert("Please enter valid Email Id.");
                return false;
            }
            return true;
        }        
}

function OpenTermsAndConWidow()
{
    window.open('TermsAndCon.aspx',null,'scrollbars =1;height=500,width=730,status=yes,toolbar=no,menubar=no,location=no');
}

function roll(Source)
{
    document.getElementById('imgPictures').src=Source.name;
}


var letters='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var numbers='1234567890';
var signs='!?,.:;@-';
var mathsigns='+-=()*/^';
var custom='<>#$%&amp;?¿';
var splchars='- *,.';
var emailchars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890.-_@';
var regZipCanada = /[a-zA-Z0-9]/
var regZipUs = /^\d{5}$/
function AllowKeys(e,allow) 
{ 

        //var k;
        // this gets the key that was pressed on the keyboard!
        //k=document.all?parseInt(e.keyCode): parseInt(e.which);

        if(allow == "ZipCode")

        {

//                        if(window.document.getElementById("csPassenger_Shipping_Country").value == 'Canada')

//                                        allow = numbers + letters;

//                        else

                            allow = numbers;

        }                                                

        var chCode = (e.which)?e.which:e.keyCode;

        if (typeof document.getElementById!="undefined" && typeof document.all=="undefined")

        {

                        if ((34 < e.charCode && e.charCode < 41) || e.charCode == 46) return false;

                        if ((34 < chCode && chCode < 41) || chCode == 46) return true;

        }

        if (!(allow.indexOf(String.fromCharCode(parseInt(chCode))) != -1 || parseInt(chCode) == 8 || parseInt(chCode) == 13 || parseInt(chCode) <= 31)) return false;

        //if((chCode<48 || 57<chCode) && chCode>31) return false;

        return true;

}

function CheckUploadFiles(sender, args)
{
    if(args.Value.toLowerCase().indexOf(".xls")>0)
    {
        args.IsValid = true;
        return;
    }
    args.IsValid = false;
}

function CheckImageType(sender, args)
{
    if(args.Value.toLowerCase().indexOf(".jpg")>0 || args.Value.toLowerCase().indexOf(".gif")>0 || args.Value.toLowerCase().indexOf(".jpeg")>0)
    {
        args.IsValid = true;
        return;
    }
    args.IsValid = false;
}

function closeWindow()
{
    window.open('','_parent',''); 
    window.close();
    return false;
}





// Date Validation Javascript
// copyright 30th October 2004, by Stephen Chapman
// http://javascript.about.com

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.
function stripBlanks(fld) 
{
    var result = "";
   var c=0; 
    for (i=0; i<fld.length; i++)
    {
        if (fld.charAt(i) != " " || c > 0)
        {
            result += fld.charAt(i);
            
            if (fld.charAt(i) != " ") 
                c = result.length;
        }
    }
    
    return result.substr(0,c);
}

var numb = '0123456789';
function isValid(parm,val) 
{
    if (parm == "")
    return true;
    for (i=0; i<parm.length; i++) 
    {
         if (val.indexOf(parm.charAt(i),0) == -1)
         return false;
    }
    return true;
 }
 
function isNum(parm) 
{
    return isValid(parm,numb);
}

function validateDateFormat(fld,fmt,rng) 
{
var mth = new Array(' ','january','february','march','april','may','june','july','august','september','october','november','december');
var day = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

    var dd=0, mm=0, yy=0;var today = new Date;var t = new Date;fld = stripBlanks(fld);
    if (fld == '') return false;var d1 = fld.split('\/');
    if (d1.length != 3) d1 = fld.split(' ');
    if (d1.length != 3) return false;

    if(stripBlanks(d1[1])=='' || stripBlanks(d1[0])=='' || stripBlanks(d1[2])=='')
   { 
        alert('Invalid Date format. Date Format should be mm/dd/yyyy');
        return false;
    }
    
    if(stripBlanks(d1[0]).length >2 || stripBlanks(d1[1]).length >2  || stripBlanks(d1[2]).length >4)
   { 
         alert('Invalid Date format. Date Format should be mm/dd/yyyy');
        return false;
   }
        
    if (fmt == 'u' || fmt == 'U') {
      dd = d1[1]; mm = d1[0]; yy = d1[2];}
    else if (fmt == 'j' || fmt == 'J') {
      dd = d1[2]; mm = d1[1]; yy = d1[0];}
    else if (fmt == 'w' || fmt == 'W'){
      dd = d1[0]; mm = d1[1]; yy = d1[2];}
    else return false;
    
    var n = dd.lastIndexOf('st');
    if (n > -1) dd = dd.substr(0,n);
    n = dd.lastIndexOf('nd');
    if (n > -1) dd = dd.substr(0,n);
    n = dd.lastIndexOf('rd');
    if (n > -1) dd = dd.substr(0,n);
    n = dd.lastIndexOf('th');
    if (n > -1) dd = dd.substr(0,n);
    n = dd.lastIndexOf(',');
    if (n > -1) dd = dd.substr(0,n);
    n = mm.lastIndexOf(',');
    if (n > -1) mm = mm.substr(0,n);
    if (!isNum(dd)) return false;
    if (!isNum(yy)) return false;
    
    if (!isNum(mm)) 
    {
          var nn = mm.toLowerCase();
          for (var i=1; i < 13; i++) 
          {
                if (nn == mth[i] || nn == mth[i].substr(0,3)) 
                {
                     mm = i; i = 13;
                }
          }
    }
    
    if (!isNum(mm)) 
        return false;

    dd = parseFloat(dd); mm = parseFloat(mm); yy = parseFloat(yy);
    
    if (yy < 100) yy += 2000;
    if (yy < 1582 || yy > 4881) 
   {
       alert('Invalid Year. Year should be  [1582 - 4881]');
        return false;
   }
    
    if (mm == 2 && (yy%400 == 0 || (yy%4 == 0 && yy%100 != 0))) day[mm-1]++;
    if (mm < 1 || mm > 12) 
   {
   alert('Invalid Month. Month should be [1 - 12] ') 
   return false;
   }
   if (dd < 1 || dd > day[mm-1]) 
   {
        alert('Invalid Day. Date should be [1 - '+ day[mm-1] +']');
        return false;
   }
    
    t.setDate(dd); 
    t.setMonth(mm-1); 
    t.setFullYear(yy);
    
    if (rng == 'p' || rng == 'P') 
    {
        if (t > today) return false;
    }
    else if (rng == 'f' || rng == 'F') 
    {
        if (t < today) 
        {
            alert('Invalid Date. Date should be greater than current Date');
            return false;
        }
    }
    else if (rng != 'a' && rng != 'A') return false;
    
    return true;
}




/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: David Leppek :: https://www.azcode.com/Mod10

Basically, the alorithum takes each digit, from right to left and muliplies each second
digit by two. If the multiple is two-digits long (i.e.: 6 * 2 = 12) the two digits of
the multiple are then added together for a new number (1 + 2 = 3). You then add up the 
string of numbers, both unaltered and new values and get a total sum. This sum is then
divided by 10 and the remainder should be zero if it is a valid credit card. Hense the
name Mod 10 or Modulus 10. */
function ValidateCCNumber(ccNumb) {  // v2.0
var valid = "0123456789"  // Valid digits in a credit card number
var len = ccNumb.length;  // The length of the submitted cc number
var iCCN = parseInt(ccNumb);  // integer of ccNumb
var sCCN = ccNumb.toString();  // string of ccNumb
sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
var iTotal = 0;  // integer total set at zero
var bNum = true;  // by default assume it is a number
var bResult = false;  // by default assume it is NOT a valid cc
var temp;  // temp variable for parsing string
var calc;  // used for calculation of each digit

// Determine if the ccNumb is in fact all numbers
for (var j=0; j<len; j++) {
  temp = "" + sCCN.substring(j, j+1);
  if (valid.indexOf(temp) == "-1"){bNum = false;}
}

// if it is NOT a number, you can either alert to the fact, or just pass a failure
if(!bNum){
  /*alert("Not a Number");*/bResult = false;
}

// Determine if it is the proper length 
if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
  bResult = false;
} else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
  if(len >= 15){  // 15 or 16 for Amex or V/MC
    for(var i=len;i>0;i--){  // LOOP throught the digits of the card
      calc = parseInt(iCCN) % 10;  // right most digit
      calc = parseInt(calc);  // assure it is an integer
      iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
      i--;  // decrement the count - move to the next digit in the card
      iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
      calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
      calc = calc *2;                                 // multiply the digit by two
      // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
      // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
      switch(calc){
        case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
        case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
        case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
        case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
        case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
        default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
      }                                               
    iCCN = iCCN / 10;  // subtracts right most digit from ccNum
    iTotal += calc;  // running total of the card number as we loop
  }  // END OF LOOP
  if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
    bResult = true;  // This IS (or could be) a valid credit card number.
  } else {
    bResult = false;  // This could NOT be a valid credit card number
    }
  }
}

if(!bResult){
  alert("Enter valid Credit Card Number");
}
  return bResult; // Return the results
}

function AutoComplete()
{
    if(document.getElementById('UscSearch_txtFHLeavingFrom')!=null)
            var obj = actb(document.getElementById('UscSearch_txtFHLeavingFrom'),customarray);
    if(document.getElementById('UscSearch_txtFCHLeavingFrom')!=null)
            var obj = actb(document.getElementById('UscSearch_txtFCHLeavingFrom'),customarray);
    //setTimeout(function(){obj.actb_keywords = custom2;},10000);
}

function SetZIndex(str)
{
    var HideCtls=false;
    var browser=navigator.appName;
    var version=navigator.appVersion;
    
    if (browser.indexOf("Microsoft") >= 0)
        if (version.indexOf("MSIE 3.") >= 0 || version.indexOf("MSIE 4.") >= 0 || version.indexOf("MSIE 5.") >= 0 || version.indexOf("MSIE 6.") >= 0 )
            HideCtls=true;
   
    if(HideCtls)
    {
        var layer = document.getElementById('tat_table');
        var iframe = document.getElementById('iframetop');
        var tat_table_height=0;
        
        if(layer!=null)
            tat_table_height=document.getElementById('tat_table').offsetHeight;
        
        if(tat_table_height>0)
        {
            layer.style.display = 'block';
            iframe.style.display = 'block';
            iframe.style.width = layer.offsetWidth;
            iframe.style.position="absolute";
            iframe.style.height = layer.offsetHeight;
            iframe.style.left = layer.offsetLeft;
            iframe.style.top = layer.offsetTop;
        }
        else
            iframe.style.display = 'none';
    } 
}

//Trim function.
function trim(str)
{
    if(!str || typeof str != 'string')
        return "";

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}



function ShowProgress(msg) {
    var div = document.createElement("div");
    div.cellSpacing = '1px';
    div.cellPadding = '2px';
    div.style.border = '0px';
    div.style.position = 'absolute';
    var top = 0;
    var left = 0;
    div.style.top = "0px";
    div.style.left = "0px";
    div.id = 'blockdiv';
    document.body.appendChild(div);
    if ($.browser.msie) {
        div.style.height = $(document).height();
        div.style.width = $(document).width();
    }
    else {
        div.style.height = document.height+50+"px";
        div.style.width = "100%";
    }
    $('#blockdiv').block({ message: msg });
    if (AgencyLogoPath.length > 0)
    {
        document.getElementById("imgAgencyLogo").src = AgencyLogoPath;
        document.getElementById("imgAgencyLogo").style.visibility = "visible"; 
    }
    else
        document.getElementById("imgAgencyLogo").style.visibility = "hidden";


}
