function getData(obj) {
	// finds all TDs inside obj
	var arrTD = obj.getElementsByTagName('TD');
	// assigns TD value to form field
//	document.getElementById('ddlCity').value = trim(arrTD[0].innerHTML,' ');
  //     document.getElementById('CityID').value = trim(arrTD[1].innerHTML,' ');

	document.getElementById('ddlCity').value = trim(arrTD[0].innerHTML,' ');
	document.getElementById('HiddenCityName').value = trim(arrTD[0].innerHTML,' ');
	
	document.getElementById('LatID').value = arrTD[1].innerHTML;
	document.getElementById('LotID').value = arrTD[2].innerHTML;

	// hides the DIV
	document.getElementById('countrySuggestItems').style.display = 'none';
	document.getElementById("ddlSuiteType").style.display ="inline";
	counter=0;
	while(document.getElementById('citytable').hasChildNodes())
	    document.getElementById('citytable').removeChild(document.getElementById('citytable').firstChild);
}

function htmlFormat(arr,lat,lot) {
	// formats arr as an HTML table
	document.getElementById("ddlSuiteType").style.display ="none";
	var output = '<table class="suggestList" id="citytable" style="font-size: 11px;font-family: Arial, Helvetica, sans-serif;">';
	for (var i=0;i<arr.length;i++) {
		output = output + '<tr onmouseover="this.style.backgroundColor=0xeeeeee;" onmouseout="this.style.backgroundColor=0xffffff;" onclick="getData(this) ">'+'<td>' + arr[i] + '</td><td style="display:none">'+lat[i]+'</td><td style="display:none">'+lot[i]+ '</td></tr>';
		//output = output + '<tr onmouseover="this.style.backgroundColor=0xeeeeee;" onmouseout="this.style.backgroundColor=0xffffff;" onclick="getData(this)">'+'<td>' + arr[i] + '</td><td  style="display:none">' + arr1[i] + '</td>' + '</tr>';
		//output = output + '<tr onmouseover="this.style.backgroundColor=0xeeeeee;" onmouseout="this.style.backgroundColor=0xffffff;" onclick="getData(this) ">' + '<td>'+ <img src="airplane.gif" height=10 width=10 /> + '</td> <td>' + arr[i] + '</td>' + '</tr>';
		//output = output + '<tr onmouseover="this.style.backgroundColor=0xeeeeee;" onmouseout="this.style.backgroundColor=0xffffff;" onclick="getData(this) ">' + '<td>'+ '<img src="airplane.gif" height=10 width=10 />' + '</td> <td>' + arr[i] + '</td>' + '</tr>';
	}
	output = output + '</table>';
//alert(output);
	return output;
}



function AirData(obj) {
	// finds all TDs inside obj
	var arrTD = obj.getElementsByTagName('TD');
	// assigns TD value to form field
//alert(trim(arrTD[1].innerHTML,' '));
	document.getElementById('airporttext').value = trim(arrTD[1].innerHTML,' ');
	document.getElementById('HiddenCityName').value = trim(arrTD[1].innerHTML,' ');
	document.getElementById('LatID').value = arrTD[2].innerHTML;
	document.getElementById('LotID').value = arrTD[3].innerHTML;
	
	// hides the DIV
	document.getElementById('vipin').style.display = 'none';
	document.getElementById("ddlSuiteType").style.display ="inline";
	counter=0;
	while(document.getElementById('citytable').hasChildNodes())
	                		document.getElementById('citytable').removeChild(document.getElementById('citytable').firstChild);
}

function airhtmlFormat(arr,lat,lot) {
	// formats arr as an HTML table
	document.getElementById("ddlSuiteType").style.display ="none";
	var output = '<table class="suggestList" id="citytable">';
	for (var i=0;i<arr.length;i++) {
		output = output + '<tr onmouseover="this.style.backgroundColor=0xeeeeee;" onmouseout="this.style.backgroundColor=0xffffff;" onclick="AirData(this) ">' + '<td>'+ '<img src="airplane.gif" height=10 width=10 />' + '</td> <td>' + arr[i] + '</td><td style="display:none">'+lat[i]+'</td><td style="display:none">'+lot[i]+ '</td></tr>';
		//output = output + '<tr onmouseover="this.style.backgroundColor=0xeeeeee;" onmouseout="this.style.backgroundColor=0xffffff;" onclick="AirData(this) ">' + '<td>' + arr[i] + '</td></tr>';
	}
	output = output + '</table>';
//alert(output);
	return output;
}



var xmlhttp;
function loadXMLDoc(url,Zip)
{
 if (document.getElementById('ddlCity').value =='' ||document.getElementById('ddlCity').value.length < 3   )
{
document.getElementById('countrySuggestItems').style.display = 'none';
document.getElementById("ddlSuiteType").style.display ="inline";
counter=0;
//document.getElementById('countrySuggestItems').removeChild(document.getElementById('countrySuggestItems').firstChild);
}
else

 {
   var str=document.getElementById('ddlCity').value;
     
     if (str.slice(str.length-1)=='.')
     {
        url=url+str.substring(0,str.length-1)+' '+"&Zip="+Zip;    
     }
     else
     {
         
       if (str.slice(str.length-2)=='  ' && str.substring(str.length-2,str.length-1)==' ')
       {
       document.getElementById('ddlCity').value=str.substring(0,str.length-1);
        url=url+str.substring(0,str.length-1)+"&Zip="+Zip;
        return;
        //alert("3");
       }
       else if ((str.slice(str.length-1)=='.' && str.substring(str.length-2,str.length-1)==' ')||(str.slice(str.length-1)==' ' && str.substring(str.length-2,str.length-1)=='.'))
       {
       document.getElementById('ddlCity').value=str.substring(0,str.length-1);
        url=url+str.substring(0,str.length-2)+' '+"&Zip="+Zip;
        return;
        //alert("1");
       }
       else
       {
    // alert(str.slice(str.length-1));
     //alert(str.substring(str.length-2,str.length-1));
     
        url=url+str+"&Zip="+Zip;
       }
       
       
     }
 
//alert(url);
//alert(document.getElementById('country').value);
xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for Firefox, Opera, IE7, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=state_Change;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

function state_Change()
{
if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"

//alert(xmlhttp.responseText);
				var temp=xmlhttp.responseText.split('$');
     				var arr = temp[0].split('@');
     				//alert(arr[0]);
                                arr[0]=trim(arr[0].substring(arr[0].indexOf('>')+1,arr[0].length));
                      //          alert(arr[0]);
                      //          alert(arr);
				var dff=temp[1].split("@");
				var temp2=temp[2].split('@');

                    document.getElementById('countrySuggestItems').innerHTML =htmlFormat(arr,dff,temp2);
					document.getElementById('countrySuggestItems').style.display = 'block';
					if (trim(temp2[0],'')==0)
										{
										document.getElementById('countrySuggestItems').style.display = 'none';
				                        document.getElementById("ddlSuiteType").style.display ="inline";
										}
					
      
    }
  else
    {
   // alert("Problem retrieving data:" + xmlhttp.statusText);
    }
  }
}
}
 




function loadXMLAir(url)
	{
	
		 if (document.getElementById('airporttext').value ==''||document.getElementById('airporttext').value.length < 3)
			{
				document.getElementById('vipin').style.display = 'none';
				document.getElementById("ddlSuiteType").style.display ="inline";
				counter=0;
//			        while(document.getElementById('citytable').hasChildNodes())
//	                		document.getElementById('citytable').removeChild(document.getElementById('citytable').firstChild);

			}
		else

			{
				 url=url+document.getElementById('airporttext').value;
				//alert(url);
				xmlhttp=null;
				if (window.XMLHttpRequest)
					  {// code for Firefox, Opera, IE7, etc.
  						xmlhttp=new XMLHttpRequest();
					  }
				else if (window.ActiveXObject)
					  {// code for IE6, IE5
  						xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
					  }
				if (xmlhttp!=null)
					  {
						  xmlhttp.onreadystatechange=state_Change;
						  xmlhttp.open("GET",url,true);
						  xmlhttp.send(null);
					  }
				else
					  {
						  alert("Your browser does not support XMLHTTP.");
					  }
			}

				function state_Change()
					  {
						if (xmlhttp.readyState==4)
							  {// 4 = "loaded"
								  if (xmlhttp.status==200)
									    {// 200 = "OK"
//alert(xmlhttp.responseText);
										var temp=xmlhttp.responseText;
										//alert(temp);
										var arr = temp.split('@');
										var Name=arr[0].split('$');
										var lat=arr[1].split('$');
										var lot=arr[2].split('$');
										
										//alert (lat);
										//alert(lot);
                                        Name[0]=Name[0].substring(Name[0].indexOf('>')+1,Name[0].length);
                                        Name[0]=trim(Name[0]);
                                        //alert(Name[0]);
										document.getElementById('vipin').innerHTML =airhtmlFormat(Name,lat,lot);
										document.getElementById('vipin').style.display = 'block';
										 
										if (trim(Name[0],'')==0)
										{
										document.getElementById('vipin').style.display = 'none';
				                        document.getElementById("ddlSuiteType").style.display ="inline";
										}
										
      
    										}
								  else
										{
    								//		alert("Problem retrieving data:" + xmlhttp.statusText);
   										 }
  							  }
					 }
		}






//function trim(str, chars) {
//    return ltrim(rtrim(str, chars), chars);
//}

//function ltrim(str, chars) {
//    chars = chars || "\\s";
//    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
//}

//function rtrim(str, chars) {
//    chars = chars || "\\s";
//    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
//}



 function trim(str)
{
   
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}


function DeleteSession()
	{
		
	var url="./DeleteSession.aspx";
				alert(url);
				xmlhttp=null;
				if (window.XMLHttpRequest)
					  {// code for Firefox, Opera, IE7, etc.
  						xmlhttp=new XMLHttpRequest();
					  }
				else if (window.ActiveXObject)
					  {// code for IE6, IE5
  						xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
					  }
				if (xmlhttp!=null)
					  {
						  xmlhttp.onreadystatechange=state_Change;
						  xmlhttp.open("GET",url,true);
						  xmlhttp.send(null);
					  }
				else
					  {
						  alert("Your browser does not support XMLHTTP.");
					  }
					  
					  
			function state_Change()
					  {
						if (xmlhttp.readyState==4)
							  {// 4 = "loaded"
								  if (xmlhttp.status==200)
    							    {
									var temp=xmlhttp.responseText;
									
										
  							         }
  							         else
										{
    							        	alert("Problem retrieving data:" + xmlhttp.statusText);
   										 }
					           }
					     }      		  
					  
		 

				
		}








var counter=-1;	
    function KeyPress(evt)
    {
     
    	evt = (evt) ? evt : ((event) ? event : null);
          if (evt) {
        var text = "";
        
        //alert(evt.keyCode);
        //alert(document.getElementById('zip').value);
           switch(evt.keyCode)
	        {
		        case 38: //up arrow
		        
		        		        	
		        		        	       
		                            --counter;
		                            for(var i=0;i<document.getElementById('citytable').childNodes[0].childNodes.length;i++)
		                            {
			                            if(i==counter)
			                            {
                            			  document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[0].className="over";
				                          document.getElementById('ddlCity').value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[0].innerHTML;
				                          document.getElementById('HiddenCityName').value =document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[0].innerHTML;
				                          document.getElementById("LatID").value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[1].innerHTML;
				                         document.getElementById("LotID").value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[2].innerHTML;
                            						
			                            }
			                            else
			                            {
			                            document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[0].className="";
			                            }
			                             
		                            }
		                            if (counter<0)
		                            {
		                            counter=0
		                            }	 
		                            
	//		        this.autoComplete.moveUp();
	//alert(document.getElementById('citytable').childNodes[1].innerHTML  )
	                //alert("38");
			        break;
		        case 40: //down arrow
		                        //alert(counter);
		                           
		                         //alert(counter);
		                            if (counter>document.getElementById('citytable').childNodes[0].childNodes.length)
		                            {
		                            counter=document.getElementById('citytable').childNodes[0].childNodes.length;
		                            }
		                            
		                            for(var i=0;i<document.getElementById('citytable').childNodes[0].childNodes.length;i++)
		                            {
			                            if(i==counter)
			                            {
                            			document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[0].className="over";
				                           // document.getElementById('citytable').childNodes[0].childNodes[2].className="over";
				                            document.getElementById('ddlCity').value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[0].innerHTML;
				                            document.getElementById('HiddenCityName').value =document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[0].innerHTML;
				                            document.getElementById("LatID").value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[1].innerHTML;
				                            document.getElementById("LotID").value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[2].innerHTML;
                            							
			                            }
			                            else
			                            {
			                            document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[0].className="";
			                            }
			                             
		                            }
		                           
		   
		            // alert(document.getElementById('citytable').childNodes[0].childNodes[2].innerHTML);
			    //    this.autoComplete.moveDown();
			   // alert("40");
			    ++counter;
			        break;
			        
		        case 13: //return key
			       // window.focus();
			       document.getElementById('countrySuggestItems').style.display = 'none';
			       document.getElementById("ddlSuiteType").style.display ="inline";
			       document.getElementById('ddlCity').focus();
			       counter=0;
			       while(document.getElementById('citytable').hasChildNodes())
	                		document.getElementById('citytable').removeChild(document.getElementById('citytable').firstChild);
			       return false;
			       
			        break;
			    case 39://Back Kay
			        break;
			    case 37: // Forword Key
			        break;
			        
			   default :
			         
			        dosearchdemo();
			        break;
	        }
 
 
    }
         
 


       }
       
       
       function KeyPressAir(evt)
    {
    	
    	
    	evt = (evt) ? evt : ((event) ? event : null);
          if (evt) {
        var text = "";
        
        //alert(evt.keyCode);
           switch(evt.keyCode)
	        {
		        case 38: //up arrow
		        
		        		        		        
		                            --counter;
		                            for(var i=0;i<document.getElementById('citytable').childNodes[0].childNodes.length;i++)
		                            {
			                            if(i==counter)
			                            {
			                            //alert(document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[1].innerHTML);
                            			  document.getElementById('citytable').childNodes[0].childNodes[i].className="over";
                            			  if (navigator.appName =='Netscape')
                            			  {
				                          document.getElementById('airporttext').value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[2].innerHTML;
				                          document.getElementById('HiddenCityName').value =document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[2].innerHTML;
				                          document.getElementById("LatID").value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[3].innerHTML;
				                         document.getElementById("LotID").value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[4].innerHTML;
				                         }
				                         else
				                         {
				                          document.getElementById('airporttext').value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[1].innerHTML;
				                          document.getElementById('HiddenCityName').value =document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[1].innerHTML;
				                          document.getElementById("LatID").value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[2].innerHTML;
				                         document.getElementById("LotID").value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[3].innerHTML;
				                         
				                         }
                            						
			                            }
			                            else
			                            {
			                            document.getElementById('citytable').childNodes[0].childNodes[i].className="";
			                            }
			                             
		                            }
		                            
		                            
	//		        this.autoComplete.moveUp();
	//alert(document.getElementById('citytable').childNodes[1].innerHTML  )
	                //alert("38");
			        break;
		        case 40: //down arrow
		                            
		                            for(var i=0;i<document.getElementById('citytable').childNodes[0].childNodes.length;i++)
		                            {
			                            if(i==counter)
			                            {
			                            //alert(document.getElementById('citytable').childNodes[0].childNodes[i].innerHTML);
			                            document.getElementById('citytable').childNodes[0].childNodes[i].className="over";
			                            if (navigator.appName =='Netscape')
                            			  {
				                          document.getElementById('airporttext').value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[2].innerHTML;
				                          document.getElementById('HiddenCityName').value =document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[2].innerHTML;
				                         document.getElementById("LatID").value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[3].innerHTML;
				                         document.getElementById("LotID").value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[4].innerHTML;
				                          
				                          //document.getElementById("LatID").value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[4].innerHTML;
				                         //document.getElementById("LotID").value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[3].innerHTML;
				                         }
				                         else
				                         {
				                          document.getElementById('airporttext').value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[1].innerHTML;
				                          document.getElementById('HiddenCityName').value =document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[1].innerHTML;
				                          document.getElementById("LatID").value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[2].innerHTML;
				                         document.getElementById("LotID").value=document.getElementById('citytable').childNodes[0].childNodes[i].childNodes[3].innerHTML;
				                         
				                         }
                            							
			                            }
			                            else
			                            {
			                            document.getElementById('citytable').childNodes[0].childNodes[i].className="";
			                            }
			                             
		                            }
		                           
		   ++counter;
		            // alert(document.getElementById('citytable').childNodes[0].childNodes[2].innerHTML);
			    //    this.autoComplete.moveDown();
			   // alert("40");
			        break;
		        case 13: //return key
			        document.getElementById('vipin').style.display = 'none';
			       document.getElementById("ddlSuiteType").style.display ="inline";
			       document.getElementById('airporttext').focus();
			       counter=0;
			       while(document.getElementById('citytable').hasChildNodes())
	                		document.getElementById('citytable').removeChild(document.getElementById('citytable').firstChild);
 
	
			       return false;
			        break;
			    case 39://Back Kay
			        break;
			    case 37: // Forword Key
			        break;
			        
			   default :
			        DoSearchAir();
			        break;
	        }
 
 
    }
         
 


       }
       
       
       function DoSearchAir()
       {
       var cbo;
      
	    cbo= document.getElementById("ddlCountry");
	    //alert("dd");
		if (cbo.options[cbo.selectedIndex].text=="USA")
		loadXMLAir('./Airport.cfm?pal=1&search=');
                      
      		else
      		loadXMLAir('./Airport.cfm?pal=2&search=');
                      
       
        
       }

	function dosearchdemo()
	{
	counter=0;
		var cbo;
	    cbo= document.getElementById("ddlCountry");
		if (cbo.options[cbo.selectedIndex].text=="USA")
		              if (isNaN(document.getElementById("ddlCity").value)==true && document.getElementById('Radio1').checked==true )
		              {
		                     
		                         loadXMLDoc('./CityName.cfm?par=1&search=',1);
		              }
		              else
		              {
		                 if (document.getElementById('Radio1').checked==false)
		                 {    
		              		     loadXMLDoc('./CityName.cfm?par=1&search=',0);
		                 }
		              }
		                                    
      		else
      		        if (isNaN(document.getElementById("ddlCity").value)==true && document.getElementById('Radio1').checked==true)
		              {
		                            loadXMLDoc('./CityName.cfm?par=2&search=',1);
		              }
		              else
		              {
		                   if (document.getElementById('Radio1').checked==false)
		                   {
		              
		                            loadXMLDoc('./CityName.cfm?par=2&search=',0);
		                            }
		              }
      		
                      

}



 function HideRemove()
    {
                   cbo= document.getElementById("ddlCountry");
                   
                   if (cbo.options[cbo.selectedIndex].text=="Canada")
                   {
                   document.getElementById("label2").style.display ="inline";
                   document.getElementById("label1").style.display ="none";
                   }
                   else
                   {
                   document.getElementById("label2").style.display ="none";
                   document.getElementById("label1").style.display ="inline";
                   }
       
        document.getElementById('countrySuggestItems').style.display = 'none';
        document.getElementById("ddlSuiteType").style.display ="inline";
        document.getElementById('vipin').style.display = 'none';
	    document.getElementById('airporttext').value="";
       document.getElementById("LatID").value="";
       document.getElementById("LotID").value="";
       document.getElementById("ddlCity").value="";
       counter=0;
        if (document.getElementById("Postal"))
                {
                    document.getElementById("Postal").style.display ="none";
                }
       
       if (document.getElementById('citytable'))
                {	
	                while(document.getElementById('citytable').hasChildNodes())
			            document.getElementById('citytable').removeChild(document.getElementById('citytable').firstChild);
    			}
    }





      function AirportRadio()
	{
	//document.getElementById("ddlCity").style.width=100;
	document.getElementById("ddlCity").style.display ="inline";
	document.getElementById("cou").style.display ="inline";
	//document.getElementById("airporttext").style.width=0;
	document.getElementById("airporttext").style.display ="none";
	document.getElementById("air").style.display ="none";
	document.getElementById("Zip").style.display ="none";
	
	 document.getElementById('Radio1').checked=true;
	  document.getElementById('Radio2').checked=false;
	  document.getElementById('Radio3').checked=false
	  
	 HideRemove();
		
	}
	
	
	
	  function ZipCode()
	{
	//document.getElementById("ddlCity").style.width=100;
	document.getElementById("Zip").style.display ="inline";
	document.getElementById("ddlCity").style.display ="inline";
	document.getElementById("cou").style.display ="none";
	//document.getElementById("airporttext").style.width=0;
	document.getElementById("airporttext").style.display ="none";
	document.getElementById("air").style.display ="none";
	 document.getElementById('Radio3').checked=true;
	  document.getElementById('Radio2').checked=false;
	  document.getElementById('Radio1').checked=false
	 HideRemove();
	 ddlCountry_onchange();
		
	}
	
	
	function CountryRadio()
	{
	//document.getElementById("ddlCity").style.width=0;
	document.getElementById("ddlCity").style.display ="none";
	document.getElementById("cou").style.display ="none";
	//document.getElementById("airporttext").style.width=100;
	document.getElementById("airporttext").style.display ="inline";
	document.getElementById("air").style.display ="inline";
	document.getElementById('Radio1').checked=false;
	document.getElementById('Radio3').checked=false;
	document.getElementById('Radio2').checked=true;
	document.getElementById("Zip").style.display ="none";
	
	
	 HideRemove();
			
	}
	
	
	
	
	function popup(url, name, width, height)
						{
							settings=
								"toolbar=no,location=no,directories=no,"+
								"status=no,menubar=no,scrollbars=no,"+
								"resizable=no,width="+width+",height="+height+",screenX=500,screenY=500,left=500, top=300";
								MyNewWindow=window.open(url,name,settings);
		
				}


function NextDate()
                {
                                var nextdate=new Date();
                                if (document.getElementById('daysOfMonthPos').value !='')
                                {
                                var cf=document.getElementById('daysOfMonthPos').value.split("/");
                                 if (cf.length<=1)
                                 {
                                 
                                 return false;
                                 }
                                nextdate.setFullYear(cf[2],cf[0]-1,cf[1]);
                                nextdate.setDate(nextdate.getDate()+1) ;
                                document.getElementById('daysOfMonth2Pos').value=nextdate.getMonth()+1+"/"+nextdate.getDate()+"/"+nextdate.getFullYear();
                                }
                               
                }






 
/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
 //alert("dd");
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

//function ValidateForm(){
//	var dt=document.frmSample.txtDate
//	if (isDate(dt.value)==false){
//		dt.focus()
//		return false
//	}
//    return true
// }

 