
//var contentPlaceHolderValue = "ctl00_PlaceHolderMain_";

function FindBrowser()
{       
    var browserName=navigator.appName; 
    
    if (browserName=="Netscape")
    { 
        document.getElementById(contentPlaceHolderValue + "valSummary").style.width = "94%";               
    }
    else 
    {             
         if (browserName=="Microsoft Internet Explorer")
         { 
            document.getElementById(contentPlaceHolderValue + "valSummary").style.width = "100%";
         }                 
    }
}

function ClearUserText()
{
    if(document.getElementById(contentPlaceHolderValue + 'txtInputId').value=='UserName')
    {
        document.getElementById(contentPlaceHolderValue + 'txtInputId').value = "";
    }
}
function ClearPasswordText()
{
    document.getElementById(contentPlaceHolderValue + 'txtPassword').value = "";
    var old = document.getElementById ('txtPassword');
    var pswdDiv = document.getElementById ("pswd");
    pswdDiv.removeChild ( old ) ;
    var newElement = document.createElement ( "INPUT" );
    newElement.setAttribute ( "name", "txtPassword");
    newElement.setAttribute ( "id", "txtPassword");
    newElement.setAttribute ( "value", "");
    newElement.setAttribute ( "type", "Password");
    newElement.style.width="90px";
    pswdDiv.appendChild (newElement);
    document.getElementById('txtPassword').focus();
}

function ShowDeptDate()
	{
        var monthYear = document.getElementById(contentPlaceHolderValue + 'cmbDeptMon').value;
        var month = monthYear.substr(0,2);
        var year = monthYear.substr(2,4);        
        var isValidDate = IsValidDate(month + "/" + document.getElementById(contentPlaceHolderValue + 'cmbDeptDay').value + "/" + year);
        
        if (isValidDate)
        {
            popup = open('../obe/FltSelectionDate.aspx?Day=' + document.getElementById(contentPlaceHolderValue + 'cmbDeptDay').value + "&month=" + month + "&year=" + year + '&txtDay=' + document.getElementById(contentPlaceHolderValue + 'cmbDeptDay').id + '&txtMonth=' + document.getElementById(contentPlaceHolderValue + 'cmbDeptMon').id + '&txtYear=txtYear&Source=Depart', 'SS', 'status=no, height=163, width=355, left = 162,top = 134 ','');
	        popup.focus();
	    }        
	}
	function ShowReturnDate()
	{   
	    var monthYear = document.getElementById(contentPlaceHolderValue + 'cmbRetMon').value;
	    var month = monthYear.substr(0,2);
	    var year = monthYear.substr(2,4);	    
        var deptMonthYear = document.getElementById(contentPlaceHolderValue + 'cmbDeptMon').value;
        var deptMonth = deptMonthYear.substr(0,2);
        var isValidDate = IsValidDate(month + "/" + document.getElementById(contentPlaceHolderValue + 'cmbRetDay').value + "/" + year);
        
        if (isValidDate)
        {
        	popup = open('../obe/FltSelectionDate.aspx?Day=' + document.getElementById(contentPlaceHolderValue + 'cmbRetDay').value + "&month=" + month + "&year=" + year+ '&txtday=' + document.getElementById(contentPlaceHolderValue + 'cmbRetDay').id + '&txtMonth=' + document.getElementById(contentPlaceHolderValue + 'cmbRetMon').id + '&txtYear=txtYear&Source=Return' + '&DeptDay=' + document.getElementById(contentPlaceHolderValue + 'cmbDeptDay').value + "&DeptMonth=" + deptMonth, 'SS', 'status=no,height=163, width=355,left = 200,top = 134','');
        	popup.focus();
        }    
	}
	
	function IsValidDate(PossibleDate)
    {
	    var PDate = new String(PossibleDate);
	    var regex = /(^\d{1,2})\/(\d{1,2})\/(\d{4,4})|(^\d{1,2})\/(\d{1,2})\/(\d{2,2})/;
	    if( regex.test(PDate) )
	    {
		    var month = new String(RegExp.$1);
		    var day = new String(RegExp.$2);
		    var year = new String(RegExp.$3);
		    if( month.length == 0 )
		    {
			    month = new String(RegExp.$4);
			    day = new String(RegExp.$5);
			    year = new String(RegExp.$6);
		    }
		    var today = new Date();
		    var thisYear = new String(today.getFullYear());
		    if( year.length == 2 )
		    {
			    if( year > 50 )
			    {
				    year = String(Number(thisYear.substring(0,2))-1) + year;
			    }
			    else
			    {
				    year = thisYear.substring(0,2) + year;
			    }
		    }
		    if( month < 1 || month > 12 ) { return false; }
		    if( day < 1 || day > 31 ) { return false; }
		    if ((month==4 || month==6 || month==9 || month==11) && day>30)
		    {
			    return false;
		    }

		    if (month == 2) // check for february 29th
		    {
			    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			    if (day>29 || (day==29 && !isleap))
			    {
				    return false;
			    }
		    }
		    if( (Number(year) < Number(thisYear) - 250) || (Number(year) > Number(thisYear) + 250) )
			    {
				    return false;
			    }
		    return true;
	    }
	    return false;
    }
    
    function ValidateDepDate(source, arguments)
    {
       var monthYear = document.getElementById(contentPlaceHolderValue + 'cmbDeptMon').value;
        var month = monthYear.substring(0,2);
	    var year = monthYear.substring(2,6);
        var day = document.getElementById(contentPlaceHolderValue + 'cmbDeptDay').value;
        if (ValidateDate(day, month, year)== false)
        {
            strErrMsg=document.getElementById(contentPlaceHolderValue + "OBE_530_INVALIDDEPARTUREDATE").value;
            document.getElementById(contentPlaceHolderValue + "custValDepDate").errormessage = strErrMsg;
            arguments.IsValid = false;                       
        }
    }
    
    function ValidateRetDate(source, arguments)
    {
        //if (tripCode == "R")
        //{
            var monthYear = document.getElementById(contentPlaceHolderValue + 'cmbRetMon').value;
            var month = monthYear.substring(0,2);
            var year = monthYear.substring(2,6);
            var day = document.getElementById(contentPlaceHolderValue + 'cmbRetDay').value;
            if(ValidateDate(day, month, year) == false)
            {
                strErrMsg=document.getElementById(contentPlaceHolderValue + "OBE_533_INVALIDRETURNDATE").value;
                    document.getElementById(contentPlaceHolderValue + "custValRetDate").errormessage = strErrMsg;
                    arguments.IsValid = false;
            }
        //}
    }
    
    function ValidateDate(day, month, year)
    {
        if((month == 4 || month == 6 || month == 9 || month == 11) && (day > 30 )){return false;}
        if((year % 4) == 0 && day > 29 && month == 2){return false;}
        if((year % 4) != 0 && day > 28 && month == 2){return false;}
        return true;
    }
    
    function CompareToSysDate(source, arguments)
    {
        var currentDate = new Date();
	    var monthYearDept = document.getElementById(contentPlaceHolderValue + 'cmbDeptMon').value;
	    var dayDept = parseInt(document.getElementById(contentPlaceHolderValue + 'cmbDeptDay').value,10);
	    var monthDept = monthYearDept.substring(0,2);
	    var yearDept =monthYearDept.substring(2,6);
	    if(parseInt(yearDept) == currentDate.getFullYear() && parseInt(monthDept,10) == (currentDate.getMonth() + 1)  )
	    {
	        if(dayDept < currentDate.getDate() )
	        {
                strErrMsg = document.getElementById(contentPlaceHolderValue + "OBE_530_INVALIDDEPARTUREDATE").value;
                document.getElementById(contentPlaceHolderValue + "custValCompSysDate").errormessage = strErrMsg;
                arguments.IsValid = false;
	        }
	    }
    }
    
    function selectDefaultPort(portDropDownName, defaultPort)
    {
        if (defaultPort != "" || defaultPort != null)
        {
            var portControl = document.getElementById(portDropDownName);
            for(i=0;i<portControl.options.length;i++)
            {
                if (portControl.options[i].value ==  defaultPort)
                {
                    portControl.options[i].selected = true;
                    break;
                }
            }
        }
    }
    
    function ValidatePassengerCount(source, arguments)
    {
        var noOfAdult = document.getElementById(contentPlaceHolderValue + 'cmbAdult').value;
	    var noOfChild = document.getElementById(contentPlaceHolderValue + 'cmbChild').value;
        if((parseInt(noOfAdult,10) + parseInt(noOfChild,10))>9)
        {
            strErrMsg=document.getElementById(contentPlaceHolderValue + "OBE_532_INVALIDPESSENGERNO").value;
            document.getElementById(contentPlaceHolderValue + "custValPassCount").errormessage = strErrMsg;
            arguments.IsValid = false;            
        }
    }
    
    function GetMonthValue(monthInString)
    {
        var monthValue;
        
        if (monthInString == "Jan")
        {
            monthValue = "01";
        }
        if (monthInString == "Feb")
        {
            monthValue = "02";
        }
        if (monthInString == "Mar")
        {
            monthValue = "03";
        }
        if (monthInString == "Apr")
        {
            monthValue = "04";
        }
        if (monthInString == "May")
        {
            monthValue = "05";
        }
        if (monthInString == "Jun")
        {
            monthValue = "06";
        }
        if (monthInString == "Jul")
        {
            monthValue = "07";
        }
        if (monthInString == "Aug")
        {
            monthValue = "08";
        }
        if (monthInString == "Sep")
        {
            monthValue = "09";
        }
        if (monthInString == "Oct")
        {
            monthValue = "10";
        }
        if (monthInString == "Nov")
        {
            monthValue = "11";
        }
        if (monthInString == "Dec")
        {
            monthValue = "12";
        }
        return monthValue;
    }
    
    //Left Trim a string
    function ltrim(strText) 
    {
	    return strText.replace(/^\s+/,'');
    }
    //Right trim a string
    function rtrim(strText) 
    {
	    return strText.replace(/\s+$/,'');
    }

    //Trim a string#f1f1f2
    function trim(strText) 
    {
    	
	    return strText.replace(/^\s+/,'').replace(/\s+$/,'');
    }

    //Validates Email. NS 4+ or IE 4+
    function checkEmail(txtElement, fieldName, allowEmpty, multipleAllowed)
    {
	    var str= txtElement.value;
	    str=trim(str);
    	
	    if((allowEmpty == false) && (str.length == 0))//empty value is not allowed
	    {
	        if (fieldName != null && fieldName.length > 0)
	        {
		        alert(fieldName);
		    }
		    txtElement.focus();
		    return false;
	    }
	    
	    
	    if(allowEmpty == true && str.length == 0) //empty value is allowed
	    {
		    return true;
	    }
	    else 
	    {
            if (multipleAllowed)
            {
                emailsList = new Array(1);
                var count = 0;
                var tmpString = str;
                var delimiter = ';';
                
                tmpString = tmpString + ";";
                
                // Validation for multiple e-mail ids
                while (tmpString.indexOf(delimiter)>0) 
                {
                    tmp = tmpString.substr(0,tmpString.indexOf(delimiter));
                    
                    tmpString = tmpString.substr(
                        tmpString.indexOf(delimiter)+1, tmpString.length-tmpString.indexOf(delimiter)+1 );
                   
                    tmp = trim(tmp);
                   
                    if (tmp != '')
                    {
                        if (tmp.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
                        {
                            testresults = true;
                        }
                        else
                        {
                            if (fieldName != null && fieldName.length > 0)
                            {
                                alert(fieldName);
                            }
                            txtElement.focus();
                            testresults=false;
                            break;
                        }
                    }
                }
            }
            else
            {
                //alert (str);
                if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
                {
                    testresults = true;
                }
                else
                {
                    if (fieldName != null && fieldName.length > 0)
                    {
                        alert(fieldName);
                    }
                    txtElement.focus();
                    testresults=false;
                }
            }
	    }
	    return (testresults);
    }
    
	function RemoveWhiteSpaceOnKeyPress(id)
	{
		document.getElementById(id).value = trim(document.getElementById(id).value);
	}
        
