﻿// JScript File

function ValidateSearchBook(formid)
{

	if(formid.elements["requiredFname"].value.length<3)
		{
			alert("Please Enter First Name (Minimun 3 Characters) ")
			formid.elements["requiredFname"].focus()
			return false;
		}
		if(formid.elements["requiredLname"].value.length<3)
		{
			alert("Please Enter Last Name (Minimum 3 Characters)")
			formid.elements["requiredLname"].focus()
			return false;
		}

if(formid.elements["requiredHomeTel"].value.length<1 && formid.elements["workTel"].value.length<1 && formid.elements["mobileno"].value.length<1)
		{
			alert("Please Enter Contact Number")
			formid.elements["requiredHomeTel"].focus()
			return false;
		}
		if(formid.elements["requiredEMail"].value == "" )
		{
			alert("Please Enter Email-ID ")
			formid.elements["requiredEMail"].focus()
			return false;
		}
		
if(emailCheck(formid.elements["requiredEMail"].value)!=true)
    {
         formid.elements["requiredEMail"].focus();
        return false;
	}
		
}

function emailCheck (emailStr) {
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}
if (user.match(userPat)==null) {
alert("The username doesn't seem to be valid.");
return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}
if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}
if (len<2) {
alert("This address is missing a hostname!");
return false;
}
return true;
}

// findchildren starts
function CallGetXmlHttp()
{
var XMLHttp=null;
 try
  {
  // Firefox, Opera 8.0+, Safari
  XMLHttp=new XMLHttpRequest();
  }
 catch (e)
  {
  // Internet Explorer
  try
    {
    XMLHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    XMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return XMLHttp;
}
function dest(which)
{
document.getElementById("destid").value =document.getElementById("txtdest").options[document.FltHtlSearch.txtdest.selectedIndex].text;
}
//specialevent starts 
function SpecialEvent()
{
var url;
var dest, fromdate,destination;
//if(document.getElementById("txtdest").selectedIndex != 0)
//{
  dest=document.getElementById("txtdest").options[document.FltHtlSearch.txtdest.selectedIndex].value;
  fromdate= document.getElementById("FHDptDateDDMMYY").value;
  destination= document.getElementById("txtdest").options[document.FltHtlSearch.txtdest.selectedIndex].text;
  url="sightSpecialEvent.aspx?dest=" + dest + "&fromdate=" + fromdate + "&Destination=" + destination;
  window.open(url,"SpecialEvent",'scrollbar=yes,height=340,width=700')
//}
//else
//{
// alert("Please Select Destination");
//}
   
}
//specialevent ends

//function MM_openBrWindow(theURL,winName,features) { //v2.0
//  window.open(theURL,winName,features);
//}
function Findchildren(which)
{
var i ;
if( document.FltHtlSearch.txtchild.selectedIndex != 0)
{

  var noofchild= document.getElementById("txtchild").options[document.FltHtlSearch.txtchild.selectedIndex].value;
 
  for (i=1;i<=2;i++)
      {
        var ch ="child" + i;
        document.getElementById(ch).style.display = "none";

      }
  if(noofchild != 0 || noofchild != "")
  {
      document.getElementById("childage").style.display = "block";
      var ch; 
      for (i=1;i<=noofchild;i++)
      {
        var ch ="child" + i;
        document.getElementById(ch).style.display = "block";

      }
  }
  else
  {}
   
 }
 else
 {
   document.getElementById("childage").style.display = "none";
   for (i=1;i<=2;i++)
  {
        var ch ="child" + i;
        document.getElementById(ch).style.display = "none";
        document.getElementById(ch).value = "";
       
  }
 }
}

//findchildren ends 

//function check
function check(which)
{// fun starts
     
     if (parseInt(document.getElementById("selectadult").options[document.FltHtlSearch.selectadult.selectedIndex].value)+ parseInt(document.getElementById("txtchild").options[document.FltHtlSearch.txtchild.selectedIndex].value) > 9 )
     {
       alert("Total No. of Adults and Children cannot be more than 1 - 9");
     return false;
     }
    
//     if(document.getElementById("txtdest").selectedIndex == 0)
//     {
//     alert("Select a Destination");
//     return false;
//     }
     if(document.getElementById("txtchild").value != 0)
     {  
    
     var ch; 
     ch="";
     ch = document.getElementById("txtchild").value;
    
     var i ;
        for(i=1;i<=ch;i++)
        {
           if (document.getElementById("child"+i).selectedIndex == 0  )
           {
           alert("Please Enter Child Age");
           return false;
           }
       
        }
     
     }
     else
     {
     return true;
     }
     
     
//fun ends
}
//fun check ends 

//fill current date starts 

 function findDateString()
	{
currDate=new Date();
var weekday=new Array(7);
weekday[0]="Sun";
weekday[1]="Mon";
weekday[2]="Tue";
weekday[3]="Wed";
weekday[4]="Thu";
weekday[5]="Fri";
weekday[6]="Sat";
var dd= weekday[currDate.getDay()];

	document.getElementById("FHDayMonth").value= dd;
	var DptDateString=currDate.getDate()+"/"+currDate.getMonth()+"/"+currDate.getFullYear();
	var day=currDate.getDate();
	var mon=currDate.getMonth()+1;
	var year=currDate.getFullYear();
	if(mon<=9 && day<=9)
		{
	   DptDateString ="0"+day+"/"+"0"+mon+"/"+year; //day+"-"+
		}
		else if(mon<=9 && day>9)
		{
		DptDateString =day+"/"+"0"+mon+"/"+year; //day+"-"+
		}
		else if(mon>9 && day<=9)
		{
   		DptDateString ="0"+day+"/"+mon+"/"+year; //day+"-"+
		}
		else
		{
		DptDateString =day+"/"+mon+"/"+year;
		}
	
	return DptDateString;
    }

function CheckValidCodeState() 
{ 
	if(XMLHttp.readyState == 4)
	{
		if(XMLHttp.status == 200)
		{
			CheckValidCodeWite(XMLHttp.responseText);
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}
function CheckValidCodeWite(validNode)
{
var SortField;
    var SplitNameCode,SplitNameText
    SplitNameCode = validNode.split("|")
    var newIndex, d, sorttext;
    index = 0;
         SortField=document.getElementById("city")
               while(SortField.options.length)
        {
	        d = SortField.options.length - 1;
	        SortField.remove(d);
        }

        SortField.options[0] =  new Option();
        SortField.options[0].text = "--Select Destination--";
        SortField.options[0].value = "0";
        for (var i=0;i<SplitNameCode.length-1;i++)
        {
            var code,txt;
            var temp=SplitNameCode[i].split("^");
            SortField.options[i+1] =  new Option();
            SortField.options[i+1].text = temp[1]+"("+temp[0]+")";
            SortField.options[i+1].value = temp[0];
        } 
}


//fill FindType starts

function FindType(which)
{

if( document.FltHtlSearch.txtdest.selectedIndex != 0)
{
}
else
{
alert("Select a City");
}
}
//fill FindType ends

