﻿ function CarJourneyDateTime_AGT_CLT(currentDateTime, journeyDateTime, objDDlTime)
{
   var curr = Date.parse(currentDateTime);
   var DDLTime = objDDlTime.value;
    
   var jour = Date.parse(journeyDateTime + ' ' + DDLTime);    
   var time12 = jour - curr;
  
  //alert(time12);
   DDLTime = objDDlTime.value.split(':');
   var journeyTime_Day = new Array();// flag 0
   var journeyTime_Night = new Array();// flag 1
   
   journeyTime_Day = ['06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22'];
   journeyTime_Night = ['22', '23', '00', '01', '02', '03', '04', '05', '06'];
   
   //var flag = '0';
   if((DDLTime[0] == 06 && DDLTime[1] != 00) || (DDLTime[0] != 06 && DDLTime[0] < 22))//> >
   {
     flag = '0'; //journeyTime_Day loop;
   }
   if((DDLTime[0] == 22 && DDLTime[1] == 00) || (DDLTime[0] > 22 && DDLTime[0] != 06))//'> <'
   {
     flag = '1'; //journeyTime_Night    
   }
   if(DDLTime[0] == 22 && DDLTime[1] != 00)
   {
     flag = '0'; //journeyTime_Day loop;
   }
   if(DDLTime[0] == 06 && DDLTime[1] != 00)
   {
     flag = '1'; //journeyTime_Night
   }
   if((DDLTime[0] == 00 && DDLTime[1] != 00) || (DDLTime[0] == 00 && DDLTime[1] == 00))
   {
        flag = '1'; //journeyTime_Night
   }  
   
   if(flag == '0')
   {   
       for(var i = 0; i < journeyTime_Day.length; i++)   
       {       
            if(DDLTime[0] == journeyTime_Day[i])
            {           
                if(time12 < 43200000)//12 hours in milliseconds
                {                   
                    //alert('You are not allowed to book a car. There should be a time gap of 12 hrs between current datetime and journey datetime');                        
                  //  alert('Booking Accepted only after 12hrs. Kindly contact Helpline. Email : info@amsons.co.in || Phone : 022 66080909');                        
                   // return false;
                }
                else
                {
                    return true;
                }    
            }
       }
    }
    
    if(flag == '1')
    {   
       for(var j = 0; j < journeyTime_Night.length; j++)
       {
            if(DDLTime[0] == journeyTime_Night[j])
            {
                if(time12 < 18000000)//5 hours in milliseconds
                {
                    //alert('You are not allowed to book a car. There should be a time gap of 5 hrs between current datetime and journey datetime');    
                  //  alert('Booking Accepted only after 5hrs. Kindly contact Helpline. Email : info@amsons.co.in || Phone : 022 66080909');                        
                  //  return false;
                }
                else
                {
                    return true;
                }    
            }
       }
    }
}

function CarJourneyDateTime(currentDateTime, journeyDateTime, objDDlTime)
{
    var curr = Date.parse(currentDateTime);
    var DDLTime = objDDlTime.value;
    
    var jour = Date.parse(journeyDateTime + ' ' + DDLTime);    
    var time12 = jour - curr;
    
    if(time12 < 43200000)//12 hours in milliseconds
    {
        //alert('You are not allowed to book a car. There should be a time gap of 12 hrs between current datetime and journey datetime');    
        //alert('Booking Accepted only after 12hrs. Kindly contact Helpline. Email : info@amsons.co.in || Phone : 022 66080909');                        
       // return false;
    }
    else
    {
        return true;
    }    
}

function CarTerms(objChk)
{
    if(objChk.checked)
    {
        return true;
    }
    else
    {
        alert("Accept the Terms & Conditions");
        return false;
    }
}


function GetDDLValue(objtxt, objDDL)
{
    objtxt.value = objDDL.value;
}

function compareDates(objFromDate, objToDate)
{   
    var checkIn = Date.parse(objFromDate.value);
    var checkOut = Date.parse(objToDate.value);    
    
    //alert("Check In : " + checkIn);  
    //alert("Check Out : " + checkOut);  
        
    if(checkIn > checkOut)
    {
        alert("Please select a valid Checkout date");
        return false;
    }
    else
    {
    //alert("CheckOut - CheckIn" + (checkOut - checkIn));
        return true;
    }
       
}

function compareHotelDates(objCheckInDate, objCheckOutDate)
{   
    var checkIn = Date.parse(objCheckInDate.value);
    var checkOut = Date.parse(objCheckOutDate.value);    
    
    //alert("Check In : " + checkIn);  
    //alert("Check Out : " + checkOut);  
        
    if(checkIn > checkOut)
    {
        alert("Please select a valid Checkout date");
        return false;
    }
    else
    {
    //alert("CheckOut - CheckIn" + (checkOut - checkIn));
        if((checkOut - checkIn) > 2160000000)
        {
            alert("Room booking can be done only for 25 days...");
            return false
        }
        else
        {
            return true;
        }
    }
}



function ShowAreaList(CityObj, CityAreaObj, AllCityAreaObj)
{
    var selCityVal = CityObj.value;
    var j=0;
    for(i=0; i < AllCityAreaObj.length; i++)
    {
	    var tmpOptionVal = AllCityAreaObj.options[i].value.split( "#" );
    	
	    if ( selCityVal == tmpOptionVal [0] )
	    {
		    CityAreaObj.options[j] = new Option(AllCityAreaObj.options[i].text, AllCityAreaObj.options[i].value);
		    j++;
	    }				
    }		
}		

function journeyType(objTRJourneyType, objServiceType)
{
    if(objServiceType.value == 4)
    {
        objTRJourneyType.style.display = "";
    }
    else
    {
        objTRJourneyType.style.display = "none";
    }
}

//function ServiceType()
//{
//    //    alert("hi");
//    //    alert(document.getElementById('<%=ddlServiceType.ClientID %>').value);
//    //    if(document.getElementById('<%=ddlServiceType.ClientID %>').value == 4)
//    //    {
//    //        document.getElementById('<%=TRSearch.ClientID %>').style.display = "";
//    //    }
//    //    else
//    //    {
//    //        document.getElementById('<%=TRSearch.ClientID %>').style.display = "none";
//    //    }
//}

function SetDays(objTR,objTR1, objServiceType)
{
    if(objServiceType.value == 3)
    {
        objTR.style.display = "";
        objTR1.style.display = "";        
    }
    else
    {
        objTR.style.display = "none";
        objTR1.style.display = "none";
    }    

}

            function showDiv(ObjddlHrKm, ObjExtraHrCost, ObjExtraKmCost, ObjNightRCharge, ObjDriverAllo, ObjArea, ObjddlArea, ObjtxtOthers)
           {     
           
                    if(ObjddlHrKm.value == "1" || ObjddlHrKm.value == "2")
                    {
                    
                        ObjExtraHrCost.style.display = "";
                        ObjExtraKmCost.style.display = "";
                        
                        ObjNightRCharge.style.display = "none";
                        ObjDriverAllo.style.display = "none";
                        ObjArea.style.display = "none";
                        ObjtxtOthers.style.display = "none";
                    }
                    else if(ObjddlHrKm.value == "3")
                    {
                        ObjExtraHrCost.style.display = "none";
                        ObjNightRCharge.style.display = "";
                        ObjDriverAllo.style.display = "";
                        
                        ObjExtraKmCost.style.display = "";
                        ObjArea.style.display = "none";
                        ObjtxtOthers.style.display = "none";
                    }
                    else if(ObjddlHrKm.value == "4")
                    {
                        ObjExtraHrCost.style.display = "none";
                        ObjNightRCharge.style.display = "none";
                        ObjDriverAllo.style.display = "none";
                        ObjExtraKmCost.style.display = "none";
                                               
                        ObjArea.style.display = "";
                        ObjtxtOthers.style.display = "none";                        
                    }
                
           }

                    function showAreaOthers(ObjddlArea, ObjtxtOthers)
                    {
     
                        if(ObjddlArea.value == "-1")
                        {
                             ObjtxtOthers.style.display = "";
                        }
                        else
                        {
                            ObjtxtOthers.style.display = "none";
                        }
                    }        


function validateNumber()
{
	var point_pressed = event.srcElement.value.indexOf('.')?true:false;
	if((event.keyCode >=48 && event.keyCode <= 57) 
		|| (event.keyCode == 9 && !point_pressed))
	{
	}
	else if(event.keyCode == 43)
	{
	}
	else if(event.keyCode == 45)
	{
	}
	else 
	  event.keyCode = 0; //Block the key code.
}
function validateChar()
{	
	if((event.keyCode >=65 && event.keyCode <= 90) || (event.keyCode == 32 && event.keyCode == 43) || (event.keyCode >=97 && event.keyCode <= 122))
	{
	}
	else 
	{
	  event.keyCode = 0; //Block the key code.
	}
}

function checkEmail(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

 		 return true;					
	}

function ValidateEmail(ObjEmail){
	var emailID=ObjEmail;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID");
		//emailID.focus()
		return false;
	}
	if (checkEmail(emailID.value)==false){
		emailID.value="";
		//emailID.focus()
		return false;
	}
	return true;
 }
 
 
 function trim(stringToTrim) 
    {
	    return document.getElementById(stringToTrim).value.replace(/^\s+|\s+$/g,"");
    }
		
function checkData(TxtObj)
{			
	var ObjTxt = TxtObj.split("$");
	var msg = "";
	var count = 0;
	for(var i=0; i<ObjTxt.length -1; i++)
	{
		var innerArr = ObjTxt[i].split(":");
		if(count == 0)
		{
			if(trim(innerArr[0]).length == 0)
			{
				msg += innerArr[1] + ". \n";
				count = 1;
			}
		} 
	}
	
	if(msg.length > 0)
	{
		alert(msg);
		count = 0;
		return false;
	}
		
}	

function ADMDate(objIbtn)
{
    document.getElementById(objIbtn).focus();
}


