﻿// JScript File


 // Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=2000;
var maxYear=9999;

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){
	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
}

    var calendar = null; 
        var oldLink = null; 
        var odialog = null;       
        function trim(strValue)
			{
			var sValue = strValue;
			var nLength      = sValue.length;
			var nFirstindex  = 0;
			var nSecondindex = nLength-1;

			while (nFirstindex < nLength && sValue.charAt(nFirstindex) == ' ')
			{
				nFirstindex++;
			}

			while (nSecondindex > nFirstindex && sValue.charAt(nSecondindex) == ' ')
			{
				nSecondindex--;
			}
			return sValue.substring(nFirstindex, nSecondindex+1);
        }

        function CheckNum(txtNum)
        {        
         //debugger   
              
         if (txtNum.value != "")
         {
        
            if (isNaN(txtNum.value)==true || txtNum.value.indexOf('.') != -1  || txtNum.value.indexOf('-') != -1 ||  parseInt(txtNum.value) > 100000)
            { 
             alert('Please Enter Valid Value') 
             txtNum.focus()
                return false
            } 
          }  
         return true
        } 
        
        function CheckCost(txtNum, name )
        {
            var total = 0;
            if(CheckNum(txtNum)){
                for(i = 1; i <=10; i++){
                     z = document.getElementById(name  + i);
                     if(z != null){
                     if((z.value.length > 0 ) ){
                          total = parseInt(total) + parseInt(z.value);
                     }
                     }
                     
                }
                var name2 = name.replace('txtCost', 'txtTripCost');
//                name2 = name2.replace('QuoteBox1_', '');
//                
                z = document.getElementById(name2);
                z.innerHTML = addCommas(total);
                return true;
            }
            else{
                return false;
            }
            
        }
        function CheckAge(txtNum)
        {        
         //debugger   
              
         if (txtNum.value != "")
         {
        
            if (isNaN(txtNum.value)==true || txtNum.value==0 || txtNum.value > 110 || txtNum.value.indexOf('.') != -1)
            { 
             
            alert('Please enter valid age in full years') 
            txtNum.focus()
            //txtNum.select()
            return false
            } 
          }  
         return true
        } 
          function addCommas(nStr)
        {
	        nStr += '';
	        x = nStr.split('.');
	        x1 = x[0];
	        x2 = x.length > 1 ? '.' + x[1] : '';
	        var rgx = /(\d+)(\d{3})/;
	        while (rgx.test(x1)) {
		        x1 = x1.replace(rgx, '$1' + ',' + '$2');
	        }
	        return x1 + x2;
        }
        
        function closedia(id){
   var iframeObj = false;
   iframeObj = document.getElementById('iframe'+id);
   var faq  = document.getElementById(id);
   faq.style.display = "none";
   iframeObj.style.display = 'none'; 
   odialog = null;
}
function opendia(id){
        var iframeObj = false;
     	iframeObj = document.getElementById('iframe'+id);
       	var faq  = document.getElementById(id);
       	if (odialog != null)
       	{
       	    var dia = document.getElementById(odialog);
       	    var diaframe = document.getElementById('iframe'+ odialog);
       	    if(dia != 'undefined'){
       	        dia.style.display = "none";
                diaframe.style.display = 'none'; 
       	    }
       	}
        if(faq.style.display == "none")
            {
            odialog = id;
            iframeObj.style.filter = 'alpha(opacity=0)';
		    iframeObj.style.position = 'absolute';
		    iframeObj.border='0px';
            iframeObj.style.border = '0px';
		    iframeObj.style.backgroundColor = '#FF0000';
		   
		
            iframeObj.style.display = 'block';
           
		   	iframeObj.style.left = faq.style.left;
		    iframeObj.style.top =  faq.style.top;
		
		
            faq.style.display = "block";
           
            iframeObj.style.height = faq.offsetHeight + 300;
		    iframeObj.style.width = faq.offsetWidth ;
			    
            }
       
            
//             	alert(faq.style.display)
//       	alert(iframeObj.style.display)
      }
  
function toggle(id){
        var iframeObj = false;
     	iframeObj = document.getElementById('iframe'+id);
       	var faq  = document.getElementById(id);
       	
        if(faq.style.display == "none")
            {
            
            iframeObj.style.filter = 'alpha(opacity=0)';
		    iframeObj.style.position = 'absolute';
		    iframeObj.border='0px';
            iframeObj.style.border = '0px';
		    iframeObj.style.backgroundColor = '#FF0000';
		   
		
            iframeObj.style.display = 'block';
           
		   	iframeObj.style.left = faq.style.left;
		    iframeObj.style.top =  faq.style.top;
		
		
            faq.style.display = "block";
           
            iframeObj.style.height = faq.offsetHeight + 300;
		    iframeObj.style.width = faq.offsetWidth ;
			    
            }
        else
            {            
            faq.style.display = "none";
            iframeObj.style.display = 'none';
            }
            
//             	alert(faq.style.display)
//       	alert(iframeObj.style.display)
      }
  
function calculateTotal(){
        var name = 'txtCost';
var total = 0;
        for(i = 1; i <=10; i++){
            z = document.getElementById(name  + i);
            if(z != null){
                  if((z.value.length > 0 ) ){
                      total = parseInt(total) + parseInt(z.value);
                   }
            }
                     
        }
        var name2 = name.replace('txtCost', 'txtTripCost');
        name2 = name2.replace('QuoteBox1_', '');
                
        z = document.getElementById(name2);
        z.innerHTML = addCommas(total);
}