﻿// JScript File
	
		function updateSelInfant()
		{
		    selInfant = eval(parseInt(document.getElementById("lstInfants").selectedIndex));
		}		
				
		function updateSelChild()
		{
		    selChild = eval(parseInt(document.getElementById("lstChilds").selectedIndex));
		    selAdult = eval(parseInt(document.getElementById("lstAdults").selectedIndex));
		    document.getElementById("lstInfants").length = 1
		    //alert(selChild + selAdult);
		    for(i=1;i<= selChild + selAdult;i++)
		    {
			    var newoption = new Option(i, i, true, true);        
			    document.getElementById("lstInfants").options[document.getElementById("lstInfants").length] = newoption;             
		    }		   	   
          
            if (selInfant <= selChild + selAdult)  
                       document.getElementById("lstInfants").selectedIndex = selInfant;
            else
            {
                       selInfant = 0;
                       document.getElementById("lstInfants").selectedIndex = 0;
            }
		}		
		function updateChildList()
		{
		    selAdult = eval(parseInt(document.getElementById("lstAdults").selectedIndex));
		    selChild = eval(parseInt(document.getElementById("lstChilds").selectedIndex));
		    document.getElementById("lstChilds").length = 1
		    document.getElementById("lstInfants").length = 1
		    // Fucntion to add the items to the dest DDL	
		    for(i=1;i< 10 - selAdult;i++)
		    {
			    var newoption = new Option(i, i, true, true);        
			    document.getElementById("lstChilds").options[document.getElementById("lstChilds").length] = newoption;             
		    }		   	   
          
            if (selChild <= 10 - selAdult)  
                       document.getElementById("lstChilds").selectedIndex = selChild;
            else
            {
                       selChild = 0;
                       document.getElementById("lstChilds").selectedIndex = 0;
            }
            //alert(selChild + selAdult);
            for(i=1;i<= selChild + selAdult;i++)
		    {
			    var newoption = new Option(i, i, true, true);        
			    document.getElementById("lstInfants").options[document.getElementById("lstInfants").length] = newoption;             
		    }		   	   
          
            if (selInfant <= selChild + selAdult)  
                       document.getElementById("lstInfants").selectedIndex = selInfant;
            else
            {
                       selInfant = 0;
                       document.getElementById("lstInfants").selectedIndex = 0;
            }

		}
			
		function AddOptionOrigin(sVals) {
		// Function to add items to the DDL 
			ArrVal = sVals.split(",") // As values are in Code,Name format
			// Text,Value format to add
			if (selOrigin == ArrVal[0]) {selOriginIdx = document.getElementById("originls").length}
			var newoption = new Option(ArrVal[1], ArrVal[0], true, true);        
			document.getElementById("originls").options[document.getElementById("originls").length] = newoption;          
			}

	
		function getDestinations(){	
		    // Function to add the valid destinations depending on the origin 
		    document.getElementById("destinationls").length = 0;	// reset the list
    		
		    AddOptionDest("Select",0) // Add the select item
    		
		    var chkOrigin = document.getElementById("originls").options[document.getElementById("originls").selectedIndex].value;
		    /* Check the origin selected and compare it with all the values in the destArr
		     if a match is found add it to the DDL
		     */		 
    		
		
		    var isFound = 0;
		    for(j=0;j<TempDestArr.length;j++){
		    chkArr = TempDestArr[j].split(",")
		        
				    if (chkOrigin == chkArr[0]){
				    // text,value
					        AddOptionDest(chkArr[2],chkArr[1])
					        if (isFound ==0 )
					        {
					            chkCode = chkArr[3];
		                        document.getElementById("txtProdcode").value = chkCode;		                        
					            isFound = 1;
					        }
				    }
			}
		    document.getElementById("destinationls").selectedIndex = 0
		
		    //alert(document.getElementById("txtProdcode").value);
		}
		
		function AddOptionDest(sVal,sText) {
		// Fucntion to add the items to the dest DDL
        var newoption = new Option(sVal, sText, true, true);
        if (selDesti == sText) {selDestiIdx = document.getElementById("destinationls").length}        
        document.getElementById("destinationls").options[document.getElementById("destinationls").length] = newoption;
         
		}	
		
		/******************** to populate the DD MM YYYY fields *****************/
		function popDDL(YearNow, DD,MM,YY){
        // get todays date and one day to it.
        //alert(YearNow);
		var theDate = new Date();
		theDate.setDate(theDate.getDate() + 1);
		var theYY = Number(YearNow) //theDate.getFullYear();
		
		for(x=1;x<32;x++){
			var newoption = new Option(x,x, true, true);        
			DD.options[DD.length] = newoption;
			}			
		
		for(y=1;y<13;y++){
			var newoption = new Option(retMMstring(y),y, true, true);			       
			MM.options[MM.length] = newoption;
			}			
		
		for(z=theYY;z<theYY+3;z++){		
		    var newoption = new Option(z,z, true, true); 		
			YY.options[YY.length] = newoption;
			}
		
		//***********************************************/
		
		
		//***********************************************/
			// Select the DD,MM,YYYY values in the DDL
			DD.selectedIndex = theDate.getDate(); //0;
			MM.selectedIndex = (theDate.getMonth()+1);//0;
			//YY.selectedIndex = theDate.getFullYear();//0;
			
			for (dd=0;dd<YY.length;dd++){
					if(YY.options[dd].value==theYY){
							YY.selectedIndex = dd;
					}			
			}
		}			
	