
/// Function to not to allow keypress event to fire.
function pf_NoKeyPress(e)
{
	if (window.event)
	{
	 if(event.keyCode == 0)                              // 0 for TAB
	   event.returnValue = true;
	 else
	 	 event.returnValue = false;
	}
	else
	{
	 if(e.which == 0)
	 {
	  
	  
	 }
	 else
	 
	 {
	   e.preventDefault();
	 }
	 	
	}

}

// Function to enter only number.
function Filter4Characters(e)
{
	if (window.event)
	{
	  
		if (!((event.keyCode >= 48) && (event.keyCode <= 57)))//For IE
			event.returnValue = false;
		else
			event.returnValue = true;
	}
	else
	{
		
		if(e.which == 0)
		{
		}
		else if (!((e.which >= 48) && (e.which <= 57)))// For Firefox
		{
		
			e.preventDefault();
		}
		
			
	}	
}
function pf_AcceptOnlyNumericValues(e)
{
 if (window.event)
 {
    if ((!((event.keyCode >= 48) && (event.keyCode <= 57))) && !((event.keyCode == 46)))
      event.returnValue = false;
	else
	  event.returnValue = true;
   
 }
 else
 {
  if((!((e.which >= 48) && (e.which <= 57))) && !((e.which == 46)))
    e.preventDefault();
  //if (!((e.which >= 48) && (e.which <= 57)))// For Firefox
			
 }
} 
function pf_ShowScheduleDetails(scheduleID,RouteDescID)
{
 var winScheduleDetails;
 var PageName;
 var WindowFeatures;
 var intTop;
 var intLeft;
 var intHeight;
 var intWidth;
 
 intHeight = 400;
 intWidth = 750;
 intLeft = (screen.availWidth - intWidth)/2;
 intTop = (screen.availHeight - intHeight)/2;
 PageName = "SchedulesDesc.aspx?ScheduleId=" + scheduleID + "&RouteDescID=" + RouteDescID;
 WindowFeatures = 'width=' + intWidth + ',height=' + intHeight + ',scrollbars=yes,status=no,toolbar=no,resizeable=no,menubar=no,top=' + intTop + ',left=' + intLeft + ',directories=no';
 
 if (typeof(winScheduleDetails) != "undefined")
 {
  if(winScheduleDetails.closed == true)
  {
	winScheduleDetails = window.open(PageName,'frmScheduleDetails',WindowFeatures);
  }
  else
  {
	winImageCalculator.focus();
  }
	return;
 }
 else
 {
	winImageCalculator = window.open(PageName,'frmScheduleDetails',WindowFeatures);
 }
 return;
}
 
function pf_ShowStopsPopUp()
{
	var winImageCalculator;
	var PageName;
	var WindowFeatures;
	var intTop;
	var intLeft;
	var intHeight;
	var intWidth;
	
	intHeight = 300;
	intWidth = 750;
	intLeft = (screen.availWidth - intWidth)/2;
	intTop = (screen.availHeight - intHeight)/2;
	
	PageName = "../WebForm1.aspx"
	WindowFeatures = 'width=' + intWidth + ',height=' + intHeight + ',scrollbars=yes,status=no,toolbar=no,resizeable=no,menubar=no,top=' + intTop + ',left=' + intLeft + ',directories=no';

	if (typeof(winImageCalculator) != "undefined")
	{
		if(winImageCalculator.closed == true)
		{
			winImageCalculator = window.open(PageName,'frmSizeCalculator',WindowFeatures);
		}
		else
		{
			winImageCalculator.focus();
		}
		return;
	}
	else
	{
		winImageCalculator = window.open(PageName,'frmSizeCalculator',WindowFeatures);
	}
	return;
}
function pf_ShowEditStopsPopUp()
{
	var winEditStopsPopUp;
	var PageName;
	var WindowFeatures;
	var intTop;
	var intLeft;
	var intHeight;
	var intWidth;
	
	intHeight = 300;
	intWidth = 750;
	intLeft = (screen.availWidth - intWidth)/2;
	intTop = (screen.availHeight - intHeight)/2;
	
	PageName = "EditFareDetails.aspx"
	WindowFeatures = 'width=' + intWidth + ',height=' + intHeight + ',scrollbars=yes,status=no,toolbar=no,resizeable=no,menubar=no,top=' + intTop + ',left=' + intLeft + ',directories=no';

	if (typeof(winEditStopsPopUp) != "undefined")
	{
		if(winEditStopsPopUp.closed == true)
		{
			winEditStopsPopUp = window.open(PageName,'frmSizeCalculator',WindowFeatures);
		}
		else
		{
			winEditStopsPopUp.focus();
		}
		return;
	}
	else
	{
		winEditStopsPopUp = window.open(PageName,'frmSizeCalculator',WindowFeatures);
	}
	return;
}

		
		var colourNormal="black";
	    var colourError="red";
	    var errorMsg="Please enter the information for all highlighted fields"
	    
	    function pf_submit()
	    {
	      var blnSubmit=true;
	      clearErrors();
		  blnSubmit = validate();
		  
			 if(blnSubmit == true)
			 {
			  	 document.getElementById("hiphdnFlag").value = "True";
			  	
			 }
			 else
			 {
			 
			// document.getElementById("td_Email").innerHTML="";
			 document.getElementById("tdErrors").style.color=colourError;
			 document.getElementById("tdErrors").innerHTML = errorMsg;
			 }
	    }
	    function validate()
	    {
	       var blnSuccess=true;
	       if (document.getElementById("hiptxtName").value=='' ) 
	       {
	       document.getElementById("td_Name").style.color=colourError;
	       blnSuccess=false;
	       }
	       
	       if (document.getElementById("htxtareaAddress").value=='' ) 
	       {
	       document.getElementById("td_Address").style.color=colourError;
	       blnSuccess=false;
	       }
	      
	      if (document.getElementById("hiptxtCity").value=='' ) 
	       {
	        document.getElementById("td_City").style.color=colourError;
	       blnSuccess=false;
	       }
	      	    
	      	    
	       if (document.getElementById("hiptxtState").value=='' ) 
	       {
	        document.getElementById("td_StateZip").style.color=colourError;
	       blnSuccess=false;
	       }
	       
	       if (document.getElementById("hiptxtPhone").value=='' ) 
	       {
	        document.getElementById("td_Phone").style.color=colourError;
	       blnSuccess=false;
	       } 
	     	       
	       if (document.getElementById("hiptxtOrigin").value=='' ) 
	       {
	        document.getElementById("td_Origin").style.color=colourError;
	        blnSuccess=false;
	       }	    	      
	      	   
	      	 if  (document.getElementById("drdlstNoOfPassenger") == null)
	      	 {
	      		if (document.getElementById("hiptxtNoOfPassenger").value=='')
	      		{
	      			 document.getElementById("td_Passenger").style.color=colourError;
					 blnSuccess=false;
	      		}
	      	 }  
	      	 else	      	 	      
				if (document.getElementById("drdlstNoOfPassenger").value==0 ) 
				{
			         document.getElementById("td_Passenger").style.color=colourError;
					 blnSuccess=false;
				}  
	      	    	      
	       if (document.getElementById("hiptxtDestination").value=='' ) 
	       {
	        document.getElementById("td_Destination").style.color=colourError;
	       blnSuccess=false;
	       }	   
	       	     
	        if (document.getElementById("hiptxtContact").selectedIndex==0 ) 
	       {
	        document.getElementById("td_Contact").style.color=colourError;
	       blnSuccess=false;
	       }	    
	                    
	        if (document.getElementById("hiptxtTripStartDate").value=='') 
	       {
	        document.getElementById("td_StartDate").style.color=colourError;
	        blnSuccess=false;
	       }
	             
	        if (document.getElementById("hiptxtTripReturnDate").value=='') 
	       {
	        document.getElementById("td_ReturnDate").style.color=colourError;
	        blnSuccess=false;
	       }
	          
	      if (document.getElementById("hiptxtEmail").value=='' ) 
	       {
	        document.getElementById("td_Email").style.color=colourError;
	       blnSuccess=false;
	       }
	       if (blnSuccess==true)
	       {
	       if(document.getElementById("hiptxtEmail").value!='')
	       {
	        var email;
	        email = document.getElementById("hiptxtEmail").value;
		    blnSuccess =pf_IsValidEMailId(email);
		    if(blnSuccess == false)	    
			  document.getElementById("tdErrors").innerHTML="Email ID is not in correct format";
			  document.getElementById("td_Email").style.color=colourError;
		    } 	    
		    var Date1 = document.getElementById("hiptxtTripStartDate").value;
		    var Date2 = document.getElementById("hiptxtTripReturnDate").value;
		    var StartDate = new Date()
		    var EndDate = new Date()
		    StartDate = Date.parse(Date1);
		    EndDate= Date.parse(Date2);
		    
	        if (StartDate==EndDate)
	     	{
	     		if(((document.getElementById("drdlstDeptAbb").value)=="pm") && ((document.getElementById("drdlstArrAbb").value)=="am"))
					{
					document.getElementById("tdErrors").innerHTML="End time should be greater than Start time.";
					blnSuccess=false;
					}
				if((((document.getElementById("drdlstDeptAbb").value)=="pm") && ((document.getElementById("drdlstArrAbb").value)=="pm"))||(((document.getElementById("drdlstDeptAbb").value)=="am") && ((document.getElementById("drdlstArrAbb").value)=="am")))											
					{
					if (((document.getElementById("drdlstDepartureTimeHrs").selectedIndex) >= (document.getElementById("drdlstArrivalTimeHrs").selectedIndex)) && ((document.getElementById("drdlstDepartureTimeMins").selectedIndex) >= (document.getElementById("drdlstArrivalTimeMins").selectedIndex)))
						{
						document.getElementById("tdErrors").innerHTML="End time should be greater than Start time.";
						blnSuccess=false;
						}
					}
	     	}
	     	if (StartDate > EndDate)
	     	{
	     		document.getElementById("tdErrors").innerHTML="Start date should be less than end date";
	     		blnSuccess=false;
	     	}           	                   
	      }
	     
	     
	       if(document.getElementById("drdlstDepartureTimeHrs").selectedIndex == 0 ||document.getElementById("drdlstDepartureTimeMins").selectedIndex == 0 || document.getElementById("drdlstDeptAbb").selectedIndex ==0)
	       {
	        blnSuccess=false;
	        document.getElementById("td_StartTime").style.color=colourError;
	       }
	       if(document.getElementById("drdlstArrivalTimeHrs").selectedIndex == 0 ||document.getElementById("drdlstArrivalTimeMins").selectedIndex == 0 || document.getElementById("drdlstArrAbb").selectedIndex ==0)
	       {
	        blnSuccess=false;
	        document.getElementById("td_ReturnTime").style.color=colourError;
	       }
	      
	       return blnSuccess;	    
	    }
	    	    	    
	    function clearErrors()
	    {
	        document.getElementById("td_Name").style.color=colourNormal;	
	        document.getElementById("td_Address").style.color=colourNormal;	
	        document.getElementById("td_StartDate").style.color=colourNormal;	
	        document.getElementById("td_StartTime").style.color=colourNormal;
	        document.getElementById("td_ReturnDate").style.color=colourNormal;	        
	        document.getElementById("td_ReturnTime").style.color=colourNormal;
	        document.getElementById("td_Phone").style.color=colourNormal;
	        document.getElementById("td_Destination").style.color=colourNormal;
	        document.getElementById("td_Email").style.color=colourNormal;
	        document.getElementById("td_Origin").style.color=colourNormal;
	        document.getElementById("td_City").style.color=colourNormal;  
	        document.getElementById("td_StateZip").style.color=colourNormal;     
	        document.getElementById("td_Contact").style.color=colourNormal;
	        document.getElementById("td_Passenger").style.color=colourNormal;
	        document.getElementById("tdErrors").innerHTML = "";
	    }  
	    
	    
       function pf_IsValidEMailId(pstrEMailId) 
        {      

            var strEmail = new String(pstrEMailId);
            
            var blnValidEmail; 
            /* The following pattern is used to check if the entered e-mail address
               fits the user@domain format.  It also is used to separate the username
               from the domain. */
            var emailPat=/^(.+)@(.+)$/

            /* The following string represents the pattern for matching all special
               characters.  We don't want to allow special characters in the address. 
               These characters include ( ) < > @ , ; : \ " . [ ]    */
            var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

            /* The following string represents the range of characters allowed in a 
               username or domainname.  It really states which chars aren't allowed. */
            var validChars="\[^\\s" + specialChars + "\]"

            /* The following pattern applies if the "user" is a quoted string (in
               which case, there are no rules about which characters are allowed
               and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
               is a legal e-mail address. */
            var quotedUser="(\"[^\"]*\")"

            /* The following pattern applies for domains that are IP addresses,
               rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
               e-mail address. NOTE: The square brackets are required. */
            var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

            /* The following string represents an atom (basically a series of
               non-special characters.) */
            var atom=validChars + '+'

            /* The following string represents one word in the typical username.
               For example, in john.doe@somewhere.com, john and doe are words.
               Basically, a word is either an atom or quoted string. */
            var word="(" + atom + "|" + quotedUser + ")"

            // The following pattern describes the structure of the user
            var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

            /* The following pattern describes the structure of a normal symbolic
               domain, as opposed to ipDomainPat, shown above. */
            var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


            /* Finally, let's start trying to figure out if the supplied address is
               valid. */

            blnValidEmail = true;
             
            /* Begin with the coarse pattern to simply break up user@domain into
             different pieces that are easy to analyze. */
            var matchArray=strEmail.match(emailPat)
            
            if (matchArray==null) {
              /* Too many/few @'s or something; basically, this address doesn't
                 even fit the general mould of a valid e-mail address. */
                 //alert("Condition 1");        
	            blnValidEmail = false	        
	            return blnValidEmail;
    	        
            }

            var user=matchArray[1]
            var domain=matchArray[2]

            // See if "user" is valid 
            if (user.match(userPat)==null) {
                // user is not valid
                //alert("Valid User");
	            blnValidEmail = false	        
	            return blnValidEmail;
    	        
            }

            /* if the e-mail address is at an IP address (as opposed to a symbolic
               host name) make sure the IP address is valid. */
            var IPArray=domain.match(ipDomainPat)
            if (IPArray!=null) {
                // this is an IP address
	              for (var i=1;i<=4;i++) {
	                if (IPArray[i]>255) {
			            blnValidEmail = false
			            alert(blnValidEmail);
			            return blnValidEmail;
    			        
	                }
                }
                return blnValidEmail
        }

        // Domain is symbolic name
        var domainArray=domain.match(domainPat)
        if (domainArray==null) {
	        blnValidEmail = false	        
	        return blnValidEmail;
	        
        }

        /* domain name seems valid, but now make sure that it ends in a
           three-letter word (like com, edu, gov) or a two-letter word,
           representing country (uk, nl), and that there's a hostname preceding 
           the domain or country. */

        /* Now we need to break up the domain to get a count of how many atoms
           it consists of. */
        var atomPat=new RegExp(atom,"g")
        var domArr=domain.match(atomPat)
        var len=domArr.length
        if (domArr[domArr.length-1].length<2 || 
            domArr[domArr.length-1].length>3) {
           // the address must end in a two letter or three letter word.
           blnValidEmail = false	        
	        return blnValidEmail;
	        
        }

        // Make sure there's a host name preceding the domain.
        if (len<2) {
           var errStr="This address is missing a hostname!"
	        blnValidEmail = false	        
	        return blnValidEmail;
	        
        }

        // If we've gotten this far, everything's valid!
        
        return blnValidEmail;
        
        }
       
       
     /* Pop up for Maps' */
     
     function pf_ShowMapsPopUp(stopName)
	{
			var winEditStopsPopUp;
			var PageName;
			var WindowFeatures;
			var intTop;
			var intLeft;
			var intHeight;
			var intWidth;
			
			intHeight = 500;
			intWidth = 450;
			intLeft = (screen.availWidth - intWidth)/2;
			intTop = (screen.availHeight - intHeight)/2;
			
			PageName = "MapsPopUp.aspx?StopName=" + stopName 
			WindowFeatures = 'width=' + intWidth + ',height=' + intHeight + ',scrollbars=yes,status=no,toolbar=no,resizeable=no,menubar=no,top=' + intTop + ',left=' + intLeft + ',directories=no';

			if (typeof(winEditStopsPopUp) != "undefined")
			{
				if(winEditStopsPopUp.closed == true)
				{
					winEditStopsPopUp = window.open(PageName,'frmSizeCalculator',WindowFeatures);
				}
				else
				{
					winEditStopsPopUp.focus();
				}
				return;
			}
			else
			{
				winEditStopsPopUp = window.open(PageName,'frmSizeCalculator',WindowFeatures);
			}
			return;
}
