function userlogin(u, p, companyname) {
    cleanErrorpanel();
    if (!validateinputPage()) return;
    else {
        //alert('a');
        document.getElementById('load').style.display = "block";
        //public string UserLogOn(string userName, string PassWord, string companyname)  
        tikAEROWebB2E.WebService.BaseService.UserLogOn(u, p, companyname, userloginresult);
    }
}

function userloginresult(result) {
    //document.getElementById('load').style.display="none";
    // document.getElementById('content').innerHTML=result;
    if (result == "")
    //window.location.reload();
        window.location.href = window.location;
    else {
        document.getElementById('load').style.display = "none";
        document.getElementById('pnError').innerHTML = "- " + result;
    }
}

function adminlogon(u, p, companyname) {
    //document.getElementById('load').style.display="block";
    cleanErrorpanel();
    if (!validateinputPage()) return;
    else {
        document.getElementById('load').style.display = "block";
        tikAEROWebB2E.WebService.BaseService.AdminLogOn(u, p, companyname, adminloginresult);
    }
}

function adminloginresult(result) {
    //document.getElementById('content').innerHTML=result;
    //loadMenu();  
    if (result == "")
    //window.location.reload();
        window.location.href = window.location;
    else {
        document.getElementById('load').style.display = "none";
        document.getElementById('pnError').innerHTML = "- " + result;
    }
}

function loadflownprofile() {
    //document.getElementById('load').style.display="block";
    tikAEROWebB2E.WebService.UtilService.LoadFlownProfile(flownprofileresult)
}

function flownprofileresult(result) {
    //document.getElementById('load').style.display="none";
    if (result == 'session_expired') {
        loadLogout();
    }
    else {
        document.getElementById('content').innerHTML = result;
    }
}

function ShowFlownDetail_Home() {
    wait();
    tikAEROWebB2E.WebService.UtilService.LoadItinerary_Home(bookid, ItineraryResult)
}

function ShowFlownDetail(bookid) {
    wait();
    tikAEROWebB2E.WebService.UtilService.LoadItinerary(bookid, ItineraryResult)
}
function ItineraryResult(result) {
    successed();
    window.scrollTo(0, 0);
    if (result == 'session_expired') {
        loadLogout();
    }
    else {
        document.getElementById('content').innerHTML = result;
    }
}

function ItinerarySendMail(bookingid, mailto, mailcc) {
    wait();
    tikAEROWebB2E.WebService.UtilService.ItinerarySendMail(bookingid, mailto, mailcc, ItinerarySendMailresult)
}

function ItinerarySendMailresult(result) {
    successed();
    if (result == "session_expired") {
        alert("Session has been expired.\n Please login again ");
        loadLogout();
    }
    else {
        alert(result);
    }
}

function wait() {
    if (document.getElementById('calendarwrapper') != null) {
        document.getElementById('calendarwrapper').style.display = 'none';
        document.getElementById('calendarwrapper').style.visibility = "hidden";
    }  
    //document.getElementById('load').style.display="block";  
    //document.getElementById('content').innerHTML="<img src='Images/loading.gif' border='0' />";
    //document.getElementById('load').style.display="none";
    document.body.style.cursor = 'wait';
    var ctrlBounds;
    //var tabWait=document.getElementById('tabWait');
    var dlgBox = document.getElementById('dlgWait');
    dlgBox.style.display = "block";

    var dvDisable = document.getElementById('dvDisable');
    //dvDisable.style.height = document.body.scrollHeight + "px";
    dvDisable.style.height = getDocHeight() + "px";
    dvDisable.style.display = "block";

    var refobj = document.getElementById('content');

    var iWidth = document.getElementById('imgLoading').width;
    var iHeight = findWindowHeight();
    if (refobj != null) {
        //dlgBox.style.left = findPosX(refobj) + 350;
        //dlgBox.style.top = findPosY(refobj) + 200;
        dlgBox.style.marginLeft = "-" + parseInt(dlgBox.offsetWidth / 2) + "px";
        dlgBox.style.marginTop = "-" + parseInt(dlgBox.offsetHeight / 2) + "px";
    }
    else {
        dlgBox.style.left = document.body.scrollWidth / 2;
        dlgBox.style.top = document.body.scrollHeight / 2;
    }
}

function findWindowHeight() {
    if (parseInt(navigator.appVersion) > 3) {
        if (navigator.appName == "Netscape") {
            //winW = window.innerWidth;
            //winH = window.innerHeight;
            return window.innerHeight;
        }
        if (navigator.appName.indexOf("Microsoft") != -1) {
            //winW = document.body.offsetWidth;
            //winH = document.body.offsetHeight;
            return document.body.offsetHeight;
        }
    }
}

function successed() {
    document.body.style.cursor = '';
    var dlgBox = document.getElementById('dlgWait');
    var dvDisable = document.getElementById('dvDisable');
    dvDisable.style.height = "0px";
    dvDisable.style.display = "none";
    dlgBox.style.display = "none";
}

function loadSalesReport() {
    //document.getElementById('load').style.display="block";
    wait();
    tikAEROWebB2E.WebService.BaseService.LoadSalesReport(loadSalesReportresult)
}

function loadSalesReportresult(result) {
    if (result == 'session_expired') {
        loadLogout();
    }
    else {
        successed();
        //document.getElementById('load').style.display="none";
        //alert(result);

        document.getElementById('content').innerHTML = result;
        //User Find For get component     
        RegisCalendar('ctl00_CalendarExtender2', 'btnFlightFrom1', 'Flightdatefrom1');
        RegisCalendar('ctl00_CalendarExtender3', 'btnFlightTo1', 'Flightdateto1');
        RegisCalendar('ctl00_CalendarExtender4', 'btnsaledatefrom', 'saledatefrom');
        RegisCalendar('ctl00_CalendarExtender5', 'btnsaledateto', 'saledateto');
    }
}

function RegisCalendar(Calendarname, btnControl, controlName) {
    var obj2 = $find(Calendarname, null);
    var objCurrentDate = document.getElementById('CurrentDate');
    var CurrentDate = '';
    if (objCurrentDate != null) CurrentDate = objCurrentDate.value;
    if (obj2 != null) {
        Sys.Application.removeComponent(obj2);
        var tmp2 = $find(Calendarname + '_popupDiv$PopupBehavior', null);
        if (tmp2 != null) Sys.Application.removeComponent(tmp2);

        Sys.Application.initialize();

        if (CurrentDate != '') {
            Sys.Application.add_init(function() {
                $create(AjaxControlToolkit.CalendarBehavior, { "firstDayOfWeek": 1, "format": "dd/MM/yyyy", "button": document.getElementById(btnControl), "id": Calendarname, "selectedDate": CurrentDate }, null, null, document.getElementById(controlName));
            });
        }
        else {
            Sys.Application.add_init(function() {
                $create(AjaxControlToolkit.CalendarBehavior, { "firstDayOfWeek": 1, "format": "dd/MM/yyyy", "button": document.getElementById(btnControl), "id": Calendarname }, null, null, document.getElementById(controlName));
            });
        }
    }
    else {
        Sys.Application.initialize();
        if (CurrentDate != '') {
            Sys.Application.add_init(function() {
                $create(AjaxControlToolkit.CalendarBehavior, { "firstDayOfWeek": 1, "format": "dd/MM/yyyy", "button": document.getElementById(btnControl), "id": Calendarname, "selectedDate": CurrentDate }, null, null, document.getElementById(controlName));
            });
        }
        else {
            Sys.Application.add_init(function() {
                $create(AjaxControlToolkit.CalendarBehavior, { "firstDayOfWeek": 1, "format": "dd/MM/yyyy", "button": document.getElementById(btnControl), "id": Calendarname }, null, null, document.getElementById(controlName));
            });
        }
    }
}

function loadLogout() {
    //document.getElementById('load').style.display="block";
    if (document.getElementById('dlgWait') != null) {
        if (document.getElementById('dlgWait').style.display != 'block') {
            wait();
        }
    }
    tikAEROWebB2E.WebService.BaseService.Logout(loadLogoutresult);
}

function loadLogoutresult(result) {
    //alert(window.location.search)
    //alert(window.location.search.split('\')[window.location.search.split('\').length-1])
    //loadMenu();
    successed();
    if (result != '') {
        if (result == 'session_expired') {
            // Start Yai edit Login Cross App Cookie
            //window.location.href = window.location;
            if (checkCookieOutside() == true) {
                if (document.getElementById("hddB2CURL") != null) {
                    window.location.replace(document.getElementById("hddB2CURL").value);
                }
                else {
                    window.location.href = window.location;
                }
            }
            else {
                window.location.href = window.location;
            }
            // End Yai edit Login Cross App Cookie  
        }
        else {
            // Start Yai edit Login Cross App Cookie
            //window.location = result;
            if (checkCookieOutside() == true) {
                if (document.getElementById("hddB2CURL") != null) {
                    window.location.replace(document.getElementById("hddB2CURL").value);
                }
                else {
                    window.location = result;
                }
            }
            else {
                window.location = result;
            }
            // End Yai edit Login Cross App Cookie
        }
    }
    else {
        window.location.href = window.location;
        //window.location.reload();
        //window.location.href=window.location.search.split('\')[window.location.search.split('\').length-1];
        //document.getElementById('load').style.display="none";
        //document.getElementById('content').innerHTML=result;
        //document.getElementById('content').innerHTML=result;
        //window.location.href="";
    }
}

function loadseatmap(flight_id, booking_segment_id) {
    //document.getElementById('load').style.display="block";
    //Save Booking //    
    var myContactXml = getContact();
    var myPassengersXml = getPassengers();

    if (myContactXml == "") return;
    if (myPassengersXml == "") return;

    var txtRe1 = getRemark1();
    var txtRe2 = getRemark2();
    var xmlMailList = getMailList();

    wait();
    tikAEROWebB2E.WebService.BaseService.LoadSeatMap(flight_id, booking_segment_id, myPassengersXml, txtRe1, txtRe2, myContactXml, xmlMailList, loadseatmapresult);
}

function loadseatmapresult(result) {
    if (result == 'session_expired') {
        successed();
        loadLogout();
    }
    else {
        document.getElementById('content').innerHTML = result;
    }
    window.scrollTo(0, 0);
    successed();
    //document.getElementById('tbHeader').focus();
    //document.getElementById('load').style.display="none";
}

function loadMenu() {
    //document.getElementById('load').style.display="block";
    tikAEROWebB2E.WebService.BaseService.LoadMenu(loadMenuresult)
}

function loadMenuresult(result) {
    //document.getElementById('load').style.display="none";
    document.getElementById('menu').innerHTML = result;
}

function oneway() {
    var tdTwoWay = document.getElementById('tdTwoWay1');
    var tdTwoWay2 = document.getElementById('calRen2');
    tdTwoWay.style.visibility = "hidden";
    tdTwoWay2.style.visibility = "hidden";
    //tdTwoWay.style.display="none";
    // Start new calendar
    runToggleDIVCalendar(false, null);
    // End new calendar
}

function twoway() {
    var tdTwoWay = document.getElementById('tdTwoWay1');
    var tdTwoWay2 = document.getElementById('calRen2');
    tdTwoWay.style.visibility = "visible";
    tdTwoWay2.style.visibility = "visible";
    //tdTwoWay.style.display="block";
    // Start new calendar
    runToggleDIVCalendar(false, null);
    // End new calendar
}

function splitDate(obj, selFrom, selMonthYearFrom) {
    //splitDate(this,'selFrom','selMonthYearFrom')
}

function loadHome() {
    wait();
    tikAEROWebB2E.WebService.BaseService.LoadHome(loadHomeresult);
}

function DDLFindByValue(sel, value, select) {
    for (var i = 0; i < sel.options.length; i++) {
        if (sel.options[i].value == value) {
            sel.options[i].selected = true;
            return;
        }
    }
}

function loadHomeresult(result) {
    successed();
    window.scrollTo(0, 0);
    if (result == 'session_expired') {
        loadLogout();
    }
    else {
        document.getElementById('content').innerHTML = result;
        //CalendarCallWs("?rt=0&id=1","CalenderBase","0");
        //CalendarCallWs("?rt=0&id=2","calRen2","0");
        checkUserType();
        window.scrollTo(0, 0);
        if (document.getElementById('hdd_MakingForOthre') != null) {
            if (document.getElementById('hdd_MakingForOthre').value == '1') {
                document.getElementById('optAdult').disabled = false;
                document.getElementById('optInfant').disabled = false;
                document.getElementById('optChild').disabled = false;
            }
            else {
                document.getElementById('optAdult').disabled = true;
                document.getElementById('optInfant').disabled = true;
                document.getElementById('optChild').disabled = true;
            }
        }
        if (document.getElementById('hdd_logontoreport') != null) {
            var bLogonToReport = false;
            switch (document.getElementById('hdd_logontoreport').value.toLowerCase()) {
                case "true": case "yes": case "1": bLogonToReport = true; break;
                case "false": case "no": case "0": bLogonToReport = false; break;
                default: bLogonToReport = Boolean(document.getElementById('hdd_logontoreport').value);
            }
            if (bLogonToReport) {
                var SearchBox = document.getElementById("SearchBox");
                var DisableBox = document.getElementById("DisableBox");

                var x = findPosX(SearchBox);
                var y = findPosY(SearchBox);

                DisableBox.style.left = x + "px";
                DisableBox.style.top = y + "px";
                DisableBox.style.display = "";
                DisableBox.style.width = SearchBox.offsetWidth + "px";
                DisableBox.style.height = SearchBox.offsetHeight + "px";
            }
        }
        // Start new calendar    
        // Call function on calendar.js
        setRefBox();
        // End new calendar
    }    
}

function checkUserType() {
    var optAdult = document.getElementById('optAdult');
    var userType = document.getElementById('userType');
    if (userType != null) {
        if (userType.value != "Admin") {
            DDLFindByValue(optAdult, "1", true);
            optAdult.disabled = true;
            //alert(optAdult)
        }
    }
}

function loadstep4() {
    //document.getElementById('load').style.display="block";
    wait();
    tikAEROWebB2E.WebService.UtilService.loadstep4(loadstep4result)
    //document.getElementById('chkReplacePersonval').checked=true
}

function loadstep4result(result) {
    //document.getElementById('load').style.display="none";
    if (result == 'session_expired') {
        loadLogout();
    }
    else {
        successed();
        document.getElementById('content').innerHTML = result;
        IsCurrentLoginpassenger();
        IsEmpStep4();
        LockControls();
        IsSelectWithContact();
        IsSendmailAll();
        markEdit();
    }
}

function IsEmpStep4() {
    document.getElementById('uxContactPerson').disabled = true;
    document.getElementById('uxBusinessPhone').disabled = true;
    document.getElementById('uxEmail').disabled = true;
    document.getElementById('uxMobilePhone').disabled = true;
    document.getElementById('uxHomePhone').disabled = true;
    //return;
    //This below for old step
    var userType = document.getElementById('userType');

    if (userType != null) {
        var isBookForOther = document.getElementById('isBookForOther').value;
        if ((userType.value != "Admin") && (isBookForOther == "false")) {
            var chk = document.getElementById('chkReplacePersonval');
            document.getElementById('uxContactPerson').disabled = true;
            document.getElementById('uxBusinessPhone').disabled = true;
            document.getElementById('uxEmail').disabled = true;
            document.getElementById('uxMobilePhone').disabled = true;
            document.getElementById('uxHomePhone').disabled = true;
            document.getElementById('selEmployee').style.visibility = "hidden";
            if (!chk.checked) {
                chk.checked = true;
                chk.disabled = true;
                replacepersonval(chk);
            }
            else {
                chk.checked = true;
                chk.disabled = true;
            }
            var tab = document.getElementById('PassengerList');
            for (var i = 1; i < tab.rows.length; i++) {
                tab.rows[i].cells[tab.rows[i].cells.length - 1].innerHTML = "";
            }
            var chksendmail = document.getElementById('chksendmail')
            var mailChkTxt = document.getElementById('mailChkTxt');
            mailChkTxt.style.visibility = "hidden";
            chksendmail.style.visibility = "hidden";
        }
        else {
            document.getElementById('uxContactPerson').disabled = true;
            document.getElementById('uxBusinessPhone').disabled = true;
            document.getElementById('uxEmail').disabled = true;
            document.getElementById('uxMobilePhone').disabled = true;
            document.getElementById('uxHomePhone').disabled = true;
        }
    }
}

function LockControls() {
    var tab = document.getElementById('PassengerList');
    var userType = document.getElementById('userType');
    for (var i = 1; i < tab.rows.length; i++) {
        var fname = document.getElementById('Fname_' + i.toString());
        var lname = document.getElementById('Lname_' + i.toString());
        var sel = document.getElementById('sel_' + i.toString());
        var ClientID = document.getElementById('hddEmp_' + i.toString());
        var Client_No = document.getElementById('Emp_no');
        //alert(ClientID.value+","+Client_No.value)
        if ((ClientID != null) && (Client_No != null)) {
            // alert(ClientID.value+","+Client_No.value+"-->"+(ClientID.value==Client_No.value))
            if (ClientID.value == Client_No.value) {
                var chkReplacePersonval = document.getElementById('chkReplacePersonval');
                chkReplacePersonval.checked = true;
            }
        }

        if (fname != null) {
            if ((fname.value != "") && (lname.value != "")) {
                fname.disabled = true;
                lname.disabled = true;
                sel.disabled = true;
                //               if(userType!=null)
                //               {
                //                    if(userType.value!="Admin")
                //                    {
                //                        tab.rows[i].cells[tab.rows[i].cells.length-1].innerHTML="";
                //                    }
                //                }
            }
        }
    }
}

function IsCurrentLoginpassenger() {
    var PassengerList = document.getElementById('PassengerList');
    var Profile_c = document.getElementById('Profile_c');
    var Emp_no = document.getElementById('Emp_no').value;
    var Client_no = document.getElementById('Client_No').value;
    var Passenger_Profile_Id = document.getElementById('hdd_Passenger_Profile_Id').value;
    var uxContactPerson = document.getElementById('uxContactPerson');
    var fname = uxContactPerson.value.split(' ')[0];
    var lname = '';
    if (uxContactPerson.value.split(' ').length >= 2) lname = uxContactPerson.value.split(' ')[1];
    // alert(findDuplicatevalue(fname,lname,Profile_c.value));
    if (findDuplicatevalue(fname, lname, Profile_c.value)) document.getElementById('chkReplacePersonval').checked = true;
}

function validateCtrols(obj, validatetype, errormessage) {
    var ret = true;
    var pnError = document.getElementById('pnError');
    switch (validatetype.toString().toLowerCase()) {
        case "required":
            if (!TextRequired(obj.value)) {
                ret = false;
                //obj.className="errorbox";
                obj.style.backgroundColor = "yellow";
                if (errormessage != "") {
                    pnError.innerHTML += "- " + errormessage + "<br />"; 
                }
                else {
                    pnError.innerHTML += "- " + "Required " + obj.name + "<br />"; 
                }
            }
            else {
                //obj.className="";
                obj.style.backgroundColor = "";
            }
            break;
        case "email":
            if (!EmailValidate(obj.value)) {
                ret = false;
                //obj.className="errorbox";
                obj.style.backgroundColor = "yellow";
                if (errormessage != "") {
                    pnError.innerHTML += "- " + errormessage + "<br/>"; 
                }
                else {
                    pnError.innerHTML += "- " + "Incorrect an email address " + obj.name + "<br/>"; 
                }
            }
            else {
                //obj.className="";
                obj.style.backgroundColor = "";
            }
            break;
        case "emptyandemailvalidate":
            if (!EmptyAndEmailValidate(obj.value)) {
                ret = false;
                obj.className = "errorbox";
                obj.style.backgroundColor = "yellow";
                if (errormessage != "") {
                    pnError.innerHTML += "- " + errormessage + "<br/>"; 
                }
                else {
                    pnError.innerHTML += "- " + "Incorrect an email address or empty " + obj.name + "<br/>"; 
                }
            }
            else {
                obj.className = "";
                obj.style.backgroundColor = "";
            }
            break;
        case "emptyandrequirefourcharacter":
            if (!EmptyAndRequireFourCharacter(obj.value)) {
                ret = false;
                obj.className = "errorbox";
                obj.style.backgroundColor = "yellow";
                if (errormessage != "") {
                    pnError.innerHTML += "- " + errormessage + "<br/>"; 
                }
                else {
                    pnError.innerHTML += "- " + "Incorrect an search condition " + obj.name + "<br/>"; 
                }
            }
            else {
                obj.className = "";
                obj.style.backgroundColor = "";
            }
            break;
        case "numbervalidate":
            if (!NumberValidate(obj.value)) {
                ret = false;
                //obj.className="errorbox";
                obj.style.backgroundColor = "yellow";
                if (errormessage != "") { pnError.innerHTML += "- " + errormessage + "<br/>"; }
                else { pnError.innerHTML += "- " + "Incorrect an email address or empty " + obj.name + "<br/>"; }
            }
            else {
                //obj.className="";
                obj.style.backgroundColor = "";
            }
            break;
        case "emptyandtextvalidate":
            if (!EmptyAndTextValidate(obj.value)) {
                ret = false;
                //obj.className="errorbox";
                obj.style.backgroundColor = "yellow";
                if (errormessage != "") { pnError.innerHTML += "- " + errormessage + "<br/>"; }
                else { pnError.innerHTML += "- " + "Incorrect an email address or empty " + obj.name + "<br/>"; }
            }
            else {
                //obj.className="";
                obj.style.backgroundColor = "";
            }
            break;
        case "customdate":
            ret = false;
            //obj.className="errorbox";
            obj.style.backgroundColor = "yellow";
            if (errormessage != "") {
                pnError.innerHTML += "- " + errormessage + "<br/>"; 
            }
            else {
                pnError.innerHTML += "- " + "Incorrect an email address or empty " + obj.name + "<br/>"; 
            }
            break;
        case "datevalidate":
            if (!DateValidate(obj.value)) {
                ret = false;
                //obj.className="errorbox";
                obj.style.backgroundColor = "yellow";
                if (errormessage != "") {
                    pnError.innerHTML += "- " + errormessage + "<br/>"; 
                }
                else {
                    pnError.innerHTML += "- " + "Incorrect an email address or empty " + obj.name + "<br/>"; 
                }
            }
            else {
                // obj.className="";
                obj.style.backgroundColor = "";
            }
            break;
        case "emptyandnumbervalidate":
            if (!EmptyAndNumberValidate(obj.value)) {
                ret = false;
                obj.className = "errorbox";
                obj.style.backgroundColor = "yellow";
                if (errormessage != "") {
                    pnError.innerHTML += "- " + errormessage + "<br/>"; 
                }
                else {
                    pnError.innerHTML += "- " + "Incorrect an email address or empty " + obj.name + "<br/>"; 
                }
            }
            else {
                obj.className = "";
                obj.style.backgroundColor = "";
            }
            break;
        case "comparevalidate":
            if (obj.getAttribute("isValid") != 'false' && document.getElementById(obj.getAttribute("comparecontrolID")).getAttribute("isValid") != 'false') {
                if (!CompareValidate(obj.value, document.getElementById(obj.getAttribute("comparecontrolID")).value)) {
                    ret = false;
                    obj.className = "errorbox";
                    obj.style.backgroundColor = "yellow";
                    document.getElementById(obj.getAttribute("comparecontrolID")).className = "errorbox";
                    document.getElementById(obj.getAttribute("comparecontrolID")).style.backgroundColor = "yellow";
                    if (errormessage != "") {
                        pnError.innerHTML += "- " + errormessage + "<br/>"; 
                    }
                    else {
                        pnError.innerHTML += "- " + "Incorrect an email address or empty " + obj.name + "<br/>"; 
                    }
                }
                else {
                    obj.className = "";
                    obj.style.backgroundColor = "";
                    document.getElementById(obj.getAttribute("comparecontrolID")).className = "";
                    document.getElementById(obj.getAttribute("comparecontrolID")).style.backgroundColor = "";
                }
            }
            break;
        case "requireandcomparevalidate":
            if (obj.getAttribute("isValid") != 'false' && document.getElementById(obj.getAttribute("comparecontrolID")).getAttribute("isValid") != 'false') {
                if (!RequireAndCompareValidate(obj.value, document.getElementById(obj.getAttribute("comparecontrolID")).value)) {
                    ret = false;
                    obj.className = "errorbox";
                    obj.style.backgroundColor = "yellow";
                    document.getElementById(obj.getAttribute("comparecontrolID")).className = "errorbox";
                    document.getElementById(obj.getAttribute("comparecontrolID")).style.backgroundColor = "yellow";
                    if (errormessage != "") {
                        pnError.innerHTML += "- " + errormessage + "<br/>"; 
                    }
                    else {
                        pnError.innerHTML += "- " + "Incorrect an email address or empty " + obj.name + "<br/>"; 
                    }
                }
                else if (!PasswordPattern(obj.value)) {
                    ret = false;
                    obj.className = "errorbox";
                    obj.style.backgroundColor = "yellow";
                    document.getElementById(obj.getAttribute("comparecontrolID")).className = "errorbox";
                    document.getElementById(obj.getAttribute("comparecontrolID")).style.backgroundColor = "yellow";
                    if (errormessage != "") {
                        pnError.innerHTML += "- " + errormessage + "<br/>"; 
                    }
                    else {
                        pnError.innerHTML += "- " + "Incorrect an email address or empty " + obj.name + "<br/>"; 
                    }
                }
                else {
                    obj.className = "";
                    obj.style.backgroundColor = "";
                    document.getElementById(obj.getAttribute("comparecontrolID")).className = "";
                    document.getElementById(obj.getAttribute("comparecontrolID")).style.backgroundColor = "";
                }
            }
            break;
        case "comparevalidatepassword":
            if (obj.getAttribute("isValid") != 'false' && document.getElementById(obj.getAttribute("comparecontrolID")).getAttribute("isValid") != 'false') {
                if (!CompareValidate(obj.value, document.getElementById(obj.getAttribute("comparecontrolID")).value)) {
                    ret = false;
                    obj.className = "errorbox";
                    obj.style.backgroundColor = "yellow";
                    document.getElementById(obj.getAttribute("comparecontrolID")).className = "errorbox";
                    document.getElementById(obj.getAttribute("comparecontrolID")).style.backgroundColor = "yellow";
                    if (errormessage != "") {
                        pnError.innerHTML += "- " + errormessage + "<br/>"; 
                    }
                    else {
                        pnError.innerHTML += "- " + "Incorrect an email address or empty " + obj.name + "<br/>"; 
                    }
                }
                else if (obj.value == "") {
                    obj.className = "";
                    obj.style.backgroundColor = "";
                    document.getElementById(obj.getAttribute("comparecontrolID")).className = "";
                    document.getElementById(obj.getAttribute("comparecontrolID")).style.backgroundColor = "";
                }
                else if (!PasswordPattern(obj.value)) {
                    ret = false;
                    obj.className = "errorbox";
                    obj.style.backgroundColor = "yellow";
                    document.getElementById(obj.getAttribute("comparecontrolID")).className = "errorbox";
                    document.getElementById(obj.getAttribute("comparecontrolID")).style.backgroundColor = "yellow";
                    if (errormessage != "") {
                        pnError.innerHTML += "- " + errormessage + "<br/>"; 
                    }
                    else {
                        pnError.innerHTML += "- " + "Incorrect an email address or empty " + obj.name + "<br/>"; 
                    }
                }
                else {
                    obj.className = "";
                    obj.style.backgroundColor = "";
                    document.getElementById(obj.getAttribute("comparecontrolID")).className = "";
                    document.getElementById(obj.getAttribute("comparecontrolID")).style.backgroundColor = "";
                }
            }
            break;
        case "compoundrequirevalidate":
            var isValid = true;
            var controlName = "";
            obj.className = "";
            obj.style.backgroundColor = "";
            controlName = obj.getAttribute("controlCompoundID").split(",");
            if (controlName != "") {
                if (obj.value != "") {
                    for (var i = 0; i < controlName.length; i++) {
                        if (document.getElementById(controlName[i]).value == "") {
                            document.getElementById(controlName[i]).className = "errorbox";
                            document.getElementById(controlName[i]).style.backgroundColor = "yellow";
                            document.getElementById(controlName[i]).setAttribute('isValid', 'false');
                            isValid = false;
                        }
                    }
                    if (!isValid) {
                        ret = false;
                        if (errormessage != "") {
                            pnError.innerHTML += "- " + errormessage + "<br/>"; 
                        }
                        else {
                            pnError.innerHTML += "- " + "Incorrect an email address or empty " + obj.name + "<br/>"; 
                        }
                    }
                    else {
                        for (var i = 0; i < controlName.length; i++) {
                            document.getElementById(controlName[i]).className = "";
                            document.getElementById(controlName[i]).style.backgroundColor = "";
                            document.getElementById(controlName[i]).setAttribute('isValid', 'true');
                        }
                    }
                }
                else if ((obj.value != "") || (document.getElementById(controlName[0]).value != "")) {
                    for (var i = 0; i < controlName.length; i++) {
                        if (document.getElementById(controlName[i]).value == "") {
                            document.getElementById(controlName[i]).className = "errorbox";
                            document.getElementById(controlName[i]).style.backgroundColor = "yellow";
                            document.getElementById(controlName[i]).setAttribute('isValid', 'false');
                            isValid = false;
                        }
                        else if (obj.value == "") {
                            obj.className = "errorbox";
                            obj.style.backgroundColor = "yellow";
                        }
                    }
                    ret = false;
                    if (errormessage != "") {
                        pnError.innerHTML += "- " + errormessage + "<br/>"; 
                    }
                    else {
                        pnError.innerHTML += "- " + "Incorrect an email address or empty " + obj.name + "<br/>"; 
                    }
                }
                else {
                    for (var i = 0; i < controlName.length; i++) {
                        if (document.getElementById(controlName[i]).value != "") {
                            obj.className = "errorbox";
                            obj.style.backgroundColor = "yellow";
                        }
                        else if (document.getElementById(controlName[i]).getAttribute("isValid") == 'false') {
                            document.getElementById(controlName[i]).className = "";
                            document.getElementById(controlName[i]).style.backgroundColor = "";
                            document.getElementById(controlName[i]).setAttribute('isValid', 'true');
                        }
                    }
                }
            }
            break;
        case "slotrequirevalidate":
            if (!(TextRequired(obj.value) || TextRequired(document.getElementById(obj.getAttribute("slotcontrolID1")).value) || TextRequired(document.getElementById(obj.getAttribute("slotcontrolID2")).value))) {
                ret = false;
                obj.className = "errorbox";
                obj.style.backgroundColor = "yellow";
                document.getElementById(obj.getAttribute("slotcontrolID1")).className = "errorbox";
                document.getElementById(obj.getAttribute("slotcontrolID1")).style.backgroundColor = "yellow";
                document.getElementById(obj.getAttribute("slotcontrolID2")).className = "errorbox";
                document.getElementById(obj.getAttribute("slotcontrolID2")).style.backgroundColor = "yellow";
                if (errormessage != "") {
                    pnError.innerHTML += "- " + errormessage + "<br/>"; 
                }
                else {
                    pnError.innerHTML += "- " + "Incorrect an email address or empty " + obj.name + "<br/>"; 
                }
            }
            /*else if(!NumberValidate(obj.value))
            {
            ret=false;
            obj.className="errorbox";
            obj.style.backgroundColor="yellow";
            
            document.getElementById(obj.getAttribute("slotcontrolID1")).className="";
            document.getElementById(obj.getAttribute("slotcontrolID1")).style.backgroundColor="";
            
            document.getElementById(obj.getAttribute("slotcontrolID2")).className="";
            document.getElementById(obj.getAttribute("slotcontrolID2")).style.backgroundColor="";
            
            pnError.innerHTML+="- "+"Please supply a valid Mobile Phone <br/>";
            }
            else if(!NumberValidate(document.getElementById(obj.getAttribute("slotcontrolID1")).value))
            {
            ret=false;
            obj.className="";
            obj.style.backgroundColor="";
            
            document.getElementById(obj.getAttribute("slotcontrolID1")).className="errorbox";
            document.getElementById(obj.getAttribute("slotcontrolID1")).style.backgroundColor="yellow";
            
            document.getElementById(obj.getAttribute("slotcontrolID2")).className="";
            document.getElementById(obj.getAttribute("slotcontrolID2")).style.backgroundColor="";
            
            pnError.innerHTML+="- "+"Please supply a valid Business Phone <br/>"; 
            }
            else if(!NumberValidate(document.getElementById(obj.getAttribute("slotcontrolID2")).value))
            {
            ret=false;
            obj.className="";
            obj.style.backgroundColor="";
            
            document.getElementById(obj.getAttribute("slotcontrolID1")).className="";
            document.getElementById(obj.getAttribute("slotcontrolID1")).style.backgroundColor="";
            
            document.getElementById(obj.getAttribute("slotcontrolID2")).className="errorbox";
            document.getElementById(obj.getAttribute("slotcontrolID2")).style.backgroundColor="yellow";
            
            pnError.innerHTML+="- "+"Please supply a valid Home Phone <br/>";   
            }*/
            else {
                obj.className = "";
                obj.style.backgroundColor = "";
                document.getElementById(obj.getAttribute("slotcontrolID1")).className = "";
                document.getElementById(obj.getAttribute("slotcontrolID1")).style.backgroundColor = "";
                document.getElementById(obj.getAttribute("slotcontrolID2")).className = "";
                document.getElementById(obj.getAttribute("slotcontrolID2")).style.backgroundColor = "";
            }
            break;
        case "dropdrowrequired":
            var defaultValue = obj.getAttribute("defaultValue");
            if (!CheckRequiredDefault(trim(obj.value), trim(defaultValue))) {
                ret = false;
                //obj.className="errorbox";
                obj.style.backgroundColor = "yellow";
                if (errormessage != "") {
                    pnError.innerHTML += "- " + errormessage + "<br />";
                }
                else {
                    pnError.innerHTML += "- " + "Required " + obj.name + "<br />";
                }
            }
            else {
                //obj.className="";
                obj.style.backgroundColor = "";
            }
            break;
        case "dropdrowrequiredandneedsepecified":
            var defaultValue = obj.getAttribute("defaultValue");
            var needValue = obj.getAttribute("needValue");
            var needValueMessage = obj.getAttribute("needvaluemessage");
            if (!CheckRequiredDefault(trim(obj.value), trim(defaultValue))) {
                ret = false;
                //obj.className="errorbox";
                obj.style.backgroundColor = "yellow";
                if (errormessage != "") {
                    pnError.innerHTML += "- " + errormessage + "<br />";
                }
                else {
                    pnError.innerHTML += "- " + "Required " + obj.name + "<br />";
                }
            }
            else {
                if (!CheckSpecifiedValue(trim(obj.value), trim(needValue))) {
                    ret = false;
                    //obj.className="errorbox";
                    obj.style.backgroundColor = "yellow";
                    if (needValueMessage != "") {
                        pnError.innerHTML += "- " + needValueMessage + "<br />";
                    }
                    else {
                        pnError.innerHTML += "- " + "Required Specified " + obj.name + "<br />";
                    }
                }
                else {
                    //obj.className="";
                    obj.style.backgroundColor = "";
                }
            }
            break;
        case "birthdatevalidate":
            var passengerType = obj.getAttribute("passengerType");
            var futureDOBMessage = obj.getAttribute("futuredobmessage");
            var invalidDOBMessage = obj.getAttribute("invalidrangedobmessage");
            // Check Valid date
            if (!DateValidate(obj.value)) {
                ret = false;
                //obj.className="errorbox";
                obj.style.backgroundColor = "yellow";
                if (errormessage != "") {
                    pnError.innerHTML += "- " + errormessage + "<br/>";
                }
                else {
                    pnError.innerHTML += "- " + "Invalid Date " + obj.name + "<br/>";
                }
            }
            else {
                // Check Past Date
                if (!ValidateDateFuturePast(trim(obj.value), "p")) {
                    ret = false;
                    //obj.className="errorbox";
                    obj.style.backgroundColor = "yellow";
                    if (futureDOBMessage != "") {
                        pnError.innerHTML += "- " + futureDOBMessage + "<br />";
                    }
                    else {
                        pnError.innerHTML += "- " + "DOB is future date " + obj.name + "<br />";
                    }
                }
                else {
                    if (!checkAge(trim(obj.value), passengerType)) {
                        ret = false;
                        //obj.className="errorbox";
                        obj.style.backgroundColor = "yellow";
                        if (invalidDOBMessage != "") {
                            pnError.innerHTML += "- " + invalidDOBMessage + "<br />";
                        }
                        else {
                            pnError.innerHTML += "- " + "Invalid DOB " + obj.name + "<br />";
                        }
                    }
                    else {
                        //obj.className="";
                        obj.style.backgroundColor = "";
                    }
                }
            }
            break;
    }
    return ret;
}
/*
function validateinputPage()
{

var inputCtrls =  document.documentElement.getElementsByTagName('input');
var ret=true;
var found =0;
var firstindex=0;
for(var i=0;i<inputCtrls.length;i++){
var attr = inputCtrls[i].getAttribute("validate");
var errormessage= inputCtrls[i].getAttribute("errormessage");
if(errormessage==null)errormessage=""; 
if(attr!=null)
{        
if(inputCtrls[i].type=="text" || inputCtrls[i].type=="password")
{          
if(!validateCtrols(inputCtrls[i],attr,errormessage))
{
if(firstindex==0)firstindex=i;                    
found++;
}            
}
}
         
if(found>=1)
{
           
if(inputCtrls[firstindex].type=="text")
{
if(!inputCtrls[firstindex].disabled){
inputCtrls[firstindex].scrollIntoView(true);
inputCtrls[firstindex].focus(); 
}
}           
}
}
if(found>0)ret=false;
if(!ret) return false;
    
return customeerror();
}
*/

function validateinputPage() {
    var isReqAddr = true;
    /*var isReqIssuNumber=true;*/
    var uxPaymentSubtype = document.getElementById('uxPaymentSubtype');
    if (uxPaymentSubtype != null) {
        var obj = uxPaymentSubtype.options[uxPaymentSubtype.selectedIndex];
        var address_required_flag = obj.getAttribute("address_required_flag");
        var issueNumber_required_flag = obj.getAttribute("address_required_flag");
        if (address_required_flag == "0") { isReqAddr = false; }
        //isReqIssuNumber=false;
        //alert(address_required_flag);
    }
    //alert(isReqAddr);
    var inputCtrls = document.documentElement.getElementsByTagName('input');
    var ret = true;
    var found = 0;
    var firstindex = 0;
    for (var i = 0; i < inputCtrls.length; i++) {
        var attr = inputCtrls[i].getAttribute("validate");
        var errormessage = inputCtrls[i].getAttribute("errormessage");
        if (errormessage == null) {
            errormessage = "";
        }
        if (attr != null) {
            if (inputCtrls[i].type == "text" || inputCtrls[i].type == "password") {
                //alert(inputCtrls[i].parentElement.parentElement.id)
                if (isReqAddr) {
                    if (!validateCtrols(inputCtrls[i], attr, errormessage)) {
                        if (inputCtrls[i].style.display != "none") {
                            if (firstindex == 0) firstindex = i;
                            found++;
                        }
                    }
                }
                else {
                    //alert(inputCtrls[i].parentElement.parentElement.id+'-->'+inputCtrls[i].parentElement.parentElement.innerHTML);
                    if (inputCtrls[i].parentElement.parentElement.id.indexOf("uxaddr") < 0) {
                        /* if(inputCtrls[i].id!="uxIssueNumber")
                        {                       
                        }  
                        else
                        {                      
                    } */
                        if (!validateCtrols(inputCtrls[i], attr, errormessage)) {
                            if (inputCtrls[i].style.display != "none") {
                                if (firstindex == 0) firstindex = i;
                                found++;
                            }
                        }
                    }
                }
            }      
        }        
        if (found >= 1) {
            if (inputCtrls[firstindex].type == "text") {
                if (!inputCtrls[firstindex].disabled) {
                    inputCtrls[firstindex].scrollIntoView(true);
                    inputCtrls[firstindex].focus();
                }
            }
        }
    }

    var selectCtrls = document.documentElement.getElementsByTagName('select');
    var selectFound = 0;
    var errorIndex = -1;
    if (selectCtrls != null) {
        for (var j = 0; j < selectCtrls.length; j++) {
            var attr = selectCtrls[j].getAttribute("validate");
            var errormessage = selectCtrls[j].getAttribute("errormessage");
            if ((attr != null) && (errormessage != null)) {
                if (selectCtrls[j].style.display != "none") {
                    if (!validateCtrols(selectCtrls[j], attr, errormessage)) {
                        if (errorIndex == -1) {
                            errorIndex = j;
                        } 
                        selectFound++;
                    }
                }
            }            
            if (found == 0 && selectFound > 0) {
                if (selectCtrls[errorIndex].type == "select-one") {                    
                    if (!selectCtrls[errorIndex].disabled) {
                        selectCtrls[errorIndex].scrollIntoView(true);
                        selectCtrls[errorIndex].focus();
                    }
                }
            }
        }
    }

    if (found > 0 || selectFound > 0) ret = false;
    if (!ret) return false;
    return customeerror();
}

function validateDateINF_CHD() {
    var isCompleted = true;
    var objTab = document.getElementById('PassengerList');
    if (objTab != null) {
        for (var i = 0; i < objTab.rows.length; i++) {
            var myType = objTab.rows[i].cells[0].innerHTML;
            if (myType.toUpperCase() != "ADULT") {
                if (objTab.rows[i].cells.length > 6) {
                    var inps = objTab.rows[i].cells[6].getElementsByTagName("INPUT");
                    if (inps != null) {
                        if (inps.length > 0) {
                            var txtINF = inps[0].value;
                            var isvalidF = CheckFormat(txtINF);

                            if (!isvalidF) {
                                isCompleted = false;
                                validateCtrols(inps[0], "datevalidate", GetMessage("Alert_Message_21")); //"Incorrect date format (dd/MM/YYYY)"
                            } else {
                                //alert(txtINF);
                                var myDates = txtINF.replace('/', '');
                                myDates = myDates.replace('/', '');
                                //alert(myDate)
                                var d = Number(myDates.substring(0, 2));
                                var m = Number(myDates.substring(2, 4));
                                var y = Number(myDates.substring(4, 8));
                                var isSdate = CheckIsDate(y, m, d);
                                if (!isSdate) {
                                    isCompleted = false;
                                    validateCtrols(inps[0], "datevalidate", GetMessage("Alert_Message_21")); //"datevalidate","Incorrect date format (dd/MM/YYYY)");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return isCompleted;
}

function check_ageINF_CHD() {
    //Child 2-11  year
    //Infant 0-23 month
    var MIN_CHD_AGE = (2 * 12);
    var MAX_CHD_AGE = (11 * 12);

    var MIN_INF_AGE = (0);
    var MAX_INF_AGE = (23);
    var isCompleted = true;
    var myType = '';
    var objTab = document.getElementById('PassengerList');
    if (objTab != null) {
        for (var i = 0; i < objTab.rows.length; i++) {
            var myTypeSP = objTab.rows[i].cells[1].getElementsByTagName("SPAN");
            myType = '';
            if (myTypeSP != null) {
                if (myTypeSP.length > 0) {
                    myType = myTypeSP[0].innerHTML;
                }
            }
            if ((myType.toUpperCase() != "ADULT") && (myType.toUpperCase() != "")) {
                if (objTab.rows[i].cells.length > 6) {
                    var inps = objTab.rows[i].cells[6].getElementsByTagName("INPUT");
                    if (inps != null) {
                        if (inps.length > 0) {
                            var myDates = inps[0].value.replace("/", "").replace("/", "");
                            var d = Number(myDates.substring(0, 2));
                            var m = Number(myDates.substring(2, 4));
                            var y = Number(myDates.substring(4, 8));
                            var isSdate = CheckIsDate(y, m, d);
                            m = m - 1;
                            var iDate = new Date(y, m, d);
                            var cDate = new Date();

                            var mmAge = dateDiff("m", iDate, cDate, 1, 1);
                            //alert(myType+"-->"+mmAge)
                            if (objTab.rows[i].cells.length > 6) {
                                var inps = objTab.rows[i].cells[6].getElementsByTagName("INPUT");

                                if (myType.toUpperCase() == "INF") {
                                    // alert(MIN_INF_AGE+","+mmAge+","+MAX_INF_AGE+(((MIN_INF_AGE<=mmAge)&&(mmAge<=MAX_INF_AGE))))
                                    if (!((MIN_INF_AGE <= mmAge) && (mmAge <= MAX_INF_AGE))) {

                                        //+MIN_INF_AGE.toString()+"-"+ MAX_INF_AGE.toString()
                                        //alert(GetMessage("Alert_Message_23"))
                                        validateCtrols(inps[0], "customdate", GetMessage("Alert_Message_23")); //"Age of infant should between "+MIN_INF_AGE.toString()+"-"+ MAX_INF_AGE.toString()+ " month(s)");
                                        isCompleted = false;
                                    }
                                }

                                if (myType.toUpperCase() == "CHD") {

                                    //alert(MIN_CHD_AGE+","+mmAge+","+MAX_CHD_AGE+(((MIN_CHD_AGE<=mmAge)&&(mmAge<=MAX_CHD_AGE))))
                                    if (!((MIN_CHD_AGE <= mmAge) && (mmAge <= MAX_CHD_AGE))) {
                                        //alert(MIN_CHD_AGE+","+mmAge+","+MAX_CHD_AGE+(((MIN_CHD_AGE<=mmAge)&&(mmAge<=MAX_CHD_AGE))))
                                        //alert('in');
                                        //+MIN_CHD_AGE.toString()+"-"+ MAX_CHD_AGE.toString()
                                        //alert(GetMessage("Alert_Message_22"))
                                        validateCtrols(inps[0], "customdate", GetMessage("Alert_Message_22")); //"customdate","Age of child should between "+(MIN_CHD_AGE/12)+"-"+ (MAX_CHD_AGE/12) + " years");
                                        //alert('out')
                                        isCompleted = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return isCompleted;
}

function CheckFormat(strDate) {
    var fdate = strDate.split('/');
    if (fdate.length < 3) return false;
    var lenStr = strDate.replace('/', '');
    lenStr = lenStr.replace('/', '');
    //alert(lenStr.toString()) 
    if (lenStr.toString().length != 8) return false;
    //alert(lenStr.toString().length);
    return true;
}

function customeerror() {
    var inputCtrls = document.documentElement.getElementsByTagName('input');
    var ret = true;
    var found = 0;
    var firstindex = 0;
    for (var i = 0; i < inputCtrls.length; i++) {
        var attr = inputCtrls[i].getAttribute("customevalidate");
        var errormessage = inputCtrls[i].getAttribute("customeerror");

        if (errormessage == null) errormessage = "";
        if (attr != null) {
            var arrAttr = attr.split(',');
            var arrError = errormessage.split(',')
            for (var j = 0; j < arrAttr.length; j++) {
                if (inputCtrls[i].type == "text" || inputCtrls[i].type == "password") {
                    // alert((!validateCtrols(inputCtrls[i],arrAttr[j],arrError[j])))
                    if (!validateCtrols(inputCtrls[i], arrAttr[j], arrError[j])) {
                        if (firstindex == 0) firstindex = i;
                        found++;
                    }
                }
            }
        }
        if (found >= 1) {

            if (inputCtrls[firstindex].type == "text") {
                inputCtrls[firstindex].scrollIntoView(true);
                inputCtrls[firstindex].focus();
            }
        }
    }
    //alert(found)
    if (found > 0) ret = false;
    return ret;
}

function cleanErrorpanel() {

    if (document.getElementById('pnError') == null) return;
    var pnError = document.getElementById('pnError');
    if (pnError.innerHTML != "") pnError.innerHTML = "";
}

//Check Max Characters
function validatelength1(obj) {
    if (obj.getAttribute('uppercase') != null) {
        if (obj.getAttribute('uppercase') == "true") {
            obj.value = obj.value.toUpperCase();
        } 
    }
    if (obj.getAttribute('charonly') != null) {
        if (obj.getAttribute('charonly') == "true") {
            if (!IfAlphaOnly(obj.value)) {
                obj.value = obj.value.substring(0, obj.value.length - 1);
            }
        }
    }
    if (parseInt(obj.value.length) < (parseInt(obj.getAttribute("maxlength")))) {
        var objDv = obj.parentNode.getElementsByTagName("span");
        if (objDv != null) {
            if (objDv[0] != null) {
                objDv[0].style.display = "none";
                objDv[0].style.visibility = "hidden";
                objDv[0].innerHTML = "";
            }
        }
        return true;
    }
    else {
        var objDv = obj.parentNode.getElementsByTagName("span");
        if (objDv[0] == null) {
            obj.parentNode.innerHTML = obj.parentNode.innerHTML + "<span id='sp_error'  style='color:#FF0000;'>*" + (parseInt(obj.getAttribute("maxlength")) - 1).toString() + "</span>";
        }
        else {
            objDv[0].style.visibility = "visibility";
            objDv[0].style.display = "block";
            objDv[0] = "<span id='sp_error' style='color:#FF0000;'>*" + (parseInt(obj.getAttribute("maxlength")) - 1).toString() + "</span>";
        }
        obj.value = obj.value.substring(0, obj.value.length - 1);
        return false;
    }
}

function validatelength(obj, DvError) {
    if (obj.getAttribute('uppercase') != null) {
        if (obj.getAttribute('uppercase') == "true") {
            obj.value = obj.value.toUpperCase();
        } 
    }
    if (obj.getAttribute('charonly') != null) {
        if (obj.getAttribute('charonly') == "true") {
            if (!IfAlphaOnly(obj.value)) {
                obj.value = obj.value.substring(0, obj.value.length - 1);
            }
        }
    }
    if (parseInt(obj.value.length) < (parseInt(obj.getAttribute("maxlength")))) {
        //document.getElementById(DvError).innerHTML="";
        document.getElementById(DvError).style.visibility = "hidden";
        // document.getElementById(DvError).style.display="none";
        return true;
    }
    else {
        var star = "";
        if (document.getElementById(DvError).innerHTML.indexOf('*') >= 0) {
            star = "<span  class='RequestStar'>  &nbsp;* </span>";
        }
        document.getElementById(DvError).style.visibility = "visible";
        document.getElementById(DvError).innerHTML = star + "max " + (parseInt(obj.getAttribute("maxlength")) - 1).toString() + " characters";
        obj.value = obj.value.substring(0, obj.value.length - 1);
        return false;
    }
}

function IfAlphaOnly(s) {
    var i;
    var b = false;
    var c = '';
    if (s.length != 0) {
        for (i = 0; i < s.length; i++) {
            c = s.charCodeAt(i);
            //			if (c == 45|| c == 39 || c == 46 || c == 32){
            //				b = true;
            //			}
            if ((c > 47 && c < 58)) {
                return false;
            }
            else if (((c > 96 && c < 123) || (c > 64 && c < 91)) == false) {
                return false;
            }
        }
        b = true;
    }
    else {
        b = false;
    }
    return b;
}

function getContact() {
    //str Contact Person
    //  cleanErrorpanel();
    //if(!validateinputPage()) return "";
    var uxDDLlang = document.getElementById('uxDDLlang');
    var lang = "";
    if (uxDDLlang != null) {
        lang = uxDDLlang.options[uxDDLlang.selectedIndex].value; 
    }
    var strContact = "<contact>";
    strContact += "<ContactPerson>" + document.getElementById('uxContactPerson').value;
    strContact += "</ContactPerson>";
    strContact += "<HomePhone>" + document.getElementById('uxHomePhone').value;
    strContact += "</HomePhone>";
    strContact += "<Email>" + document.getElementById('uxEmail').value;
    strContact += "</Email>";
    strContact += "<MobilePhone>" + document.getElementById('uxMobilePhone').value;
    strContact += "</MobilePhone>";
    strContact += "<BusinessPhone>" + document.getElementById('uxBusinessPhone').value;
    strContact += "</BusinessPhone>";
    strContact += "<CostCenter>" + document.getElementById('uxCostCenter').value;
    strContact += "</CostCenter>";
    strContact += "<PurchaseOrder>" + document.getElementById('uxPurchaseOrder').value;
    strContact += "</PurchaseOrder>";
    strContact += "<ProjectNumber>" + document.getElementById('uxProjectNumber').value;
    strContact += "</ProjectNumber>";
    strContact += "<Language>" + lang
    strContact += "</Language>";
    strContact += "</contact>";
    return strContact;
}

function getPassengers() {
    //Check Step 4 - before save//
    // cleanErrorpanel();
    //  if(!validateinputPage()) return "";
    var tblObj = document.getElementById('PassengerList');
    if (tblObj != null) {
        var id;
        var PassID;
        var ClientID;
        var Ptype;
        var Profile;
        var sel;
        var Ptype;
        var Fname;
        var Lname;
        var EmpNo;
        var strXml = '<Passengers>';
        // alert(tblObj.rows.length);
        //alert(strContact);
        var strDOB = '';
        for (var i = 1; i < tblObj.rows.length; i++) {
            id = tblObj.rows[i].id;
            PassID = document.getElementById("PassID_" + id);

            if (PassID != null) {
                ClientID = document.getElementById("ClientID_" + id);
                Ptype = document.getElementById("Ptype_" + id);
                Profile = document.getElementById("Profile_" + id);
                sel = document.getElementById("sel_" + id);
                Fname = document.getElementById("Fname_" + id);
                Lname = document.getElementById("Lname_" + id);
                EmpNo = document.getElementById("hddEmp_" + id);
                DOBs = document.getElementById('txt_date_' + id);
                strDOB = '';
                if (DOBs != null) {
                    strDOB = DOBs.value;
                }
                strXml += "<Passenger>";
                strXml += "<passenger_id>" + PassID.value + "</passenger_id>";
                strXml += "<client_number>" + ClientID.value + "</client_number>";
                strXml += "<passenger_profile_id>" + Profile.value + "</passenger_profile_id>";
                strXml += "<passenger_type_rcd>" + Ptype.value + "</passenger_type_rcd>";
                strXml += "<employee_number>" + EmpNo.value + "</employee_number>";
                strXml += "<title_rcd>" + sel.options[sel.selectedIndex].value + "</title_rcd>";
                strXml += "<lastname>" + Lname.value + "</lastname>";
                strXml += "<firstname>" + Fname.value + "</firstname>";
                strXml += "<DOB>" + strDOB + "</DOB>";
                strXml += "</Passenger>";
                //Type Title   Firstname Lastname  Client_id,PassengerID 
            }
        }
        strXml += "</Passengers>";
        //alert(strXml);
        //alert(document.getElementById('txtRemark').value);
        return strXml;
    } 
    else {
        return "";
    }
}

function getMailList() {
    var tblObj = document.getElementById('PassengerList');
    var xmlMail = "<MailList>";
    for (var i = 1; i < tblObj.rows.length; i++) {
        var mail = document.getElementById('email_' + i);
        var profile = document.getElementById('Profile_' + i);
        if ((mail != null) && (profile != null)) {
            if (mail.value != "") {
                //alert(mail.value)
                //alert(profile.value)
                xmlMail += "<Data>";
                xmlMail += "<ProfileID>" + profile.value + "</ProfileID>";
                xmlMail += "<MailAddress>" + mail.value + "</MailAddress>";
                xmlMail += "</Data>";
            }
        }
    }
    xmlMail += "</MailList>";
    //alert(xmlMail)
    return xmlMail;
}

function savestep4() {
    //Check Step 4 - before save//
    var IsCompleted = true;
    cleanErrorpanel();
    if ((document.getElementById('uxBusinessPhone').value.toString() + document.getElementById('uxMobilePhone').value.toString() + document.getElementById('uxHomePhone').value.toString()) == "") {
        document.getElementById('pnError').innerHTML += "- Please supply a valid Home phone Number or Mobile Phone or Business Phone." + "<br/>";
        IsCompleted = false;
    }
    var ctrFocus = "";
    if ((document.getElementById('uxContactPerson').value == "") && (!document.getElementById('uxContactPerson').disabled)) {
        ctrFocus = "uxContactPerson"; 
    }
    if ((document.getElementById('uxBusinessPhone').value == "") && (!document.getElementById('uxBusinessPhone').disabled)) {
        if (ctrFocus == "") $ctrFocus = "uxBusinessPhone"; 
    }
    if (validateCtrols(document.getElementById('uxEmail'), "required", "Please supply a valid Email.")) {
        if ((!validateCtrols(document.getElementById('uxEmail'), "email", "Please supply a valid Email.")) && (!document.getElementById('uxEmail').disabled)) {
            if (ctrFocus == "") ctrFocus = "uxEmail"; 
        }
    }
    else {
        if (ctrFocus == "") ctrFocus = "uxEmail"; 
    }
    if ((document.getElementById('uxMobilePhone').value == "") && (!document.getElementById('uxMobilePhone').disabled)) {
        if (ctrFocus == "") ctrFocus = 'uxMobilePhone';
    }
    if ((document.getElementById('uxHomePhone').value == "") && (!document.getElementById('uxHomePhone').disabled)) {
        if (ctrFocus == "") ctrFocus = 'uxHomePhone';
    }
    var chksendmail = document.getElementById('chksendmail');
    var sendall_passenger = '0';
    if (chksendmail.checked == true) {
        sendall_passenger = "1";
    }
    
    if (!validateinputPage()) {
        IsCompleted = false;
    }
    if (ctrFocus != "") {
        document.getElementById(ctrFocus).focus();
    }
    
    /*Only Step4*/
    if (!IsCompleted) {
        return;
    }
    //alert(IsCompleted)
    
    //Check Data of Birth INF,CHD  
//    if (IsCompleted) {
//        IsCompleted = checkPassengerTitle();
    //    }

    if (!IsCompleted) {
        return;
    }

    // Check DOB
//    if (IsCompleted) {
//        var isDateINF = validateDateINF_CHD();
//        if (!isDateINF) return;
//    }
//    
//    if (IsCompleted) {
//        var isAge = check_ageINF_CHD();
//        if (!isAge) return;
//    }

    var tblObj = document.getElementById('PassengerList');

    if (tblObj != null) {
        var id;
        var PassID;
        var ClientID;
        var Ptype;
        var Profile;
        var sel;
        var Ptype;
        var Fname;
        var Lname;
        var EmpNo;
        var DOBs;
        var strDOB = '';
        var strXml = '<Passengers>';

        var strContact = getContact();

        for (var i = 1; i < tblObj.rows.length; i++) {
            id = tblObj.rows[i].id;
            PassID = document.getElementById("PassID_" + id);

            if (PassID != null) {
                strDOB = '';
                ClientID = document.getElementById("ClientID_" + id);
                Ptype = document.getElementById("Ptype_" + id);
                Profile = document.getElementById("Profile_" + id);
                sel = document.getElementById("sel_" + id);
                Fname = document.getElementById("Fname_" + id);
                Lname = document.getElementById("Lname_" + id);
                EmpNo = document.getElementById("hddEmp_" + id);
                DOBs = document.getElementById('txt_date_' + id);
                if (DOBs != null) {
                    strDOB = DOBs.value;
                }
                strXml += "<Passenger>";
                strXml += "<passenger_id>" + PassID.value + "</passenger_id>";
                strXml += "<sendmail>" + sendall_passenger + "</sendmail>";
                strXml += "<client_number>" + ClientID.value + "</client_number>";
                strXml += "<passenger_profile_id>" + Profile.value + "</passenger_profile_id>";
                strXml += "<passenger_type_rcd>" + Ptype.value + "</passenger_type_rcd>";
                strXml += "<employee_number>" + EmpNo.value + "</employee_number>";
                strXml += "<title_rcd>" + sel.options[sel.selectedIndex].value + "</title_rcd>";
                strXml += "<lastname>" + Lname.value + "</lastname>";
                strXml += "<firstname>" + Fname.value + "</firstname>";
                strXml += "<DOB>" + strDOB + "</DOB>";
                strXml += "</Passenger>";
                //Type Title   Firstname Lastname  Client_id,PassengerID 
            }
        }
        strXml += "</Passengers>";
        var txtRe1 = getRemark1();
        var txtRe2 = getRemark2();
        var xmlMailList = getMailList();

        //alert(strXml);
        //alert(xmlMailList)
        // alert(strContact);
        //alert(document.getElementById('txtRemark').value);
        tikAEROWebB2E.WebService.UtilService.savestep4(strXml, txtRe1, txtRe2, strContact, xmlMailList, savastep4result);
    }
}

function getRemark1() {
    var txtRemark = document.getElementById('txtRemark');
    var txtRe1 = '';
    if (txtRemark != null) { txtRe1 = txtRemark.value; }
    return txtRe1;
}

function getRemark2() {
    var txtRemark2 = document.getElementById('txtAuxtOth');
    var txtRe2 = '';
    if (txtRemark2 != null) { txtRe2 = txtRemark2.value; }
    return txtRe2;
}

function savastep4result(result) {
    if (result == "session_expired") {
        alert("Session has been expired.\n Please login again ");
        loadLogout();
    }
    else {
        loadstep5();
    }
}

var popup = null;
var popupState = false
function CreateWnd(file, width, height, resize) {
    var doCenter = false;
    if ((popup == null) || popup.closed) {
        attribs = "";

        if (resize)
            size = "yes";
        else 
            size = "no";

        for (var item in window) {
            if (item == "screen") {
                doCenter = true;
                break;
            } 
        }

        if (doCenter) {
            if (screen.width <= width || screen.height <= height) 
                size = "yes";
            WndTop = (screen.height - height) / 2;
            WndLeft = (screen.width - width) / 2;
            attribs = "width=" + width + ",height=" + height + ",resizable=" + size + ",scrollbars=" + size + "," + "status=no,toolbar=no,directories=no,menubar=no,location=no,top=" + WndTop + ",left=" + WndLeft;
        }
        else {
            if (navigator.appName == "Netscape" && navigator.javaEnabled()) {
                var toolkit = java.awt.Toolkit.getDefaultToolkit();
                var screen_size = toolkit.getScreenSize();
                if (screen_size.width <= width || screen_size.height <= height) size = "yes";

                WndTop = (screen_size.height - height) / 2;
                WndLeft = (screen_size.width - width) / 2;
                attribs = "width=" + width + ",height=" + height + ",resizable=" + size + ",scrollbars=" + size + "," + "status=no,toolbar=no,directories=no,menubar=no,location=no,top=" + WndTop + ",left=" + WndLeft;
            }
            else {
                size = "yes";
                attribs = "width=" + width + ",height=" + height + ",resizable=" + size + ",scrollbars=" + size + "," +
				"status=no,toolbar=no,directories=no,menubar=no,location=no";
            }
        }

        // create the window
        //alert(file)
        //window.open(file)
        popup = window.open(file, "", attribs);
    }
    else {
        DestroyWnd();
        CreateWnd(file, width, height, resize);
    }
}

function showmanypass() {
    CreateWnd("http://www.aurigny.com/HTML/Popup/popUpPassengerRules.html", 500, 390, false);
}

function DestroyWnd() {
    if (popup != null) {
        popup.close();
        popup = null;
    }
}

function printItinerary() {
    //bookingId
    var hddBookingID = document.getElementById('hddBookingID');
    if (hddBookingID != null) window.open("PopupPrint.aspx?acc=pn&bid=" + hddBookingID.value);
}

function OpenAs(url) {
    var flag = false;
    if (url.indexOf("http://") >= 0) {
        flag = true; 
        window.open(url); 
    }
    if (url.indexOf("https://") >= 0) {
        flag = true;
        window.open(url); 
    }
    if (!flag) {
        url = "http://www.flywithstyle.com/MNA/" + url;
        window.open(url); 
    }
}

function copyword(obj) {
    var id = obj.id;
    var newid = id.replace("Fname_", "");
    if (parseInt(newid) > 1) {
        var tmp = document.getElementById("Lname_1");
        if (tmp != null) {
            if (tmp.value != "") {
                var newObj = document.getElementById("Lname_" + newid);
                if (newObj != null) {
                    if (newObj.value == "") {
                        newObj.value = tmp.value;
                    }
                }
            }
        }
    }
}

function markEdit() {
    var PassengerList = document.getElementById("PassengerList");
    var txts = PassengerList.getElementsByTagName('INPUT');
    for (var i = 0; i < txts.length; i++) {
        var myAtt = txts[i].getAttribute("DateEditmark")
        if (myAtt != null) {
            if (myAtt.toString().toUpperCase() == "TRUE") {
                InitializeMaskEdit(txts[i].id, "$d$d/$d$d/$d$d$d$d");
            }
        }
    }
}

// Start Yai add new age calculation
function checkAge(dobValue, passengerType) {
    var isDOB = true;
    
    var MIN_CHD_AGE = 2;
    var MAX_CHD_AGE = 12;

    var MIN_INF_AGE = 0;
    var MAX_INF_AGE = 2;

    if (dobValue != "__/__/____") {
        var checkDates = dobValue.replace("/", "").replace("/", "");
        var d = Number(checkDates.substring(0, 2));
        var m = Number(checkDates.substring(2, 4));
        var y = Number(checkDates.substring(4, 8));
        var arrAge = getAge(d, m, y);

        if (passengerType == "INF") {
            if (!((MIN_INF_AGE <= arrAge[0]) && (arrAge[0] < MAX_INF_AGE))) {
                isDOB = false;
            }
        }
        if (passengerType == "CHD") {
            if (arrAge[0] > MAX_CHD_AGE) {
                isDOB = false;
            }
            else if (arrAge[0] == MAX_CHD_AGE) {
                if (arrAge[1] != 0 || arrAge[2] != 0) {
                    isDOB = false;
                }
            }
            else if (arrAge[0] < MIN_CHD_AGE) {
                isDOB = false;
            }
        }
        if (passengerType == "ADULT") {
            if (arrAge[0] < MAX_CHD_AGE) {
                isDOB = false;
            }
            else if (arrAge[0] == MAX_CHD_AGE) {
                if (arrAge[1] == 0 && arrAge[2] == 0) {
                    isDOB = false;
                }
            }
        }
    }
    return isDOB;
}

function getAge(dd, mm, yyyy) {
    var month = (mm - 1);
    var date = dd;
    var year = yyyy;

    var arrAge = new Array();   // for return
    arrAge[0] = 0;              // keep count year
    arrAge[1] = 0;              // keep count month
    arrAge[2] = 0;              // keep count day

    if (month != parseInt(month)) { alert('Type Month of birth in digits only!'); return false; }
    if (date != parseInt(date)) { alert('Type Date of birth in digits only!'); return false; }
    if (year != parseInt(year)) { alert('Type Year of birth in digits only!'); return false; }
    if (year.length < 4) { alert('Type Year of birth in full!'); return false; }

    var today = new Date();
    var dateStr = today.getDate();
    var monthStr = today.getMonth();
    var yearStr = today.getFullYear();

    var theYear = yearStr - year;
    var theMonth = monthStr - month;
    var theDate = dateStr - date;

    var days = "";
    if (monthStr == 0 || monthStr == 2 || monthStr == 4 || monthStr == 6 || monthStr == 7 || monthStr == 9 || monthStr == 11) days = 31;
    if (monthStr == 3 || monthStr == 5 || monthStr == 8 || monthStr == 10) days = 30;
    if (monthStr == 1) days = 28;

    arrAge[0] = theYear;

    if (month < monthStr && date > dateStr) {
        arrAge[0] = arrAge[0] + 1;
        arrAge[1] = theMonth - 1;
    }

    if (month < monthStr && date <= dateStr) {
        arrAge[1] = theMonth;
    }
    else if (month == monthStr && (date < dateStr || date == dateStr)) {
        arrAge[1] = 0;
    }
    else if (month == monthStr && date > dateStr) {
        arrAge[1] = 11;
    }
    else if (month > monthStr && date <= dateStr) {
        arrAge[0] = arrAge[0] - 1;
        arrAge[1] = ((12 - -(theMonth)) + 1);
    }
    else if (month > monthStr && date > dateStr) {
        arrAge[1] = ((12 - -(theMonth)));
    }

    if (date < dateStr) {
        arrAge[2] = theDate;
    }
    else if (date == dateStr) {
        arrAge[2] = 0;
    }
    else {
        arrAge[0] = arrAge[0] - 1;
        arrAge[2] = days - (-(theDate));
    }
    return arrAge;
}
// End Yai add new age calculation

// Start new calendar
function findPos(obj) {
    var posX = obj.offsetLeft; var posY = obj.offsetTop;
    while (obj.offsetParent) {
        posX = posX + obj.offsetParent.offsetLeft;
        posY = posY + obj.offsetParent.offsetTop;
        if (obj == document.getElementsByTagName('body')[0]) { break }
        else { obj = obj.offsetParent; }
    }
    return [posX, posY]
}

window.onresize = doResize;
function doResize() {
    moveCalendar();
}
// End new calendar

function setCookie(strName, strValue, dExpires, strPath, strDomain, bSecure) {
    var strCookieText = escape(strName) + '=' + escape(strValue);
    strCookieText += (dExpires ? '; EXPIRES=' + dExpires.toGMTString() : '');
    strCookieText += (strPath ? '; PATH=' + strPath : '');
    strCookieText += (strDomain ? '; DOMAIN=' + strDomain : '');
    strCookieText += (bSecure ? '; SECURE' : '');

    document.cookie = strCookieText;
}
function getCookie(strName) {
    var strValue = null;
    if (document.cookie)	   //only if exists
    {
        var arr = document.cookie.split((escape(strName) + '='));
        if (2 <= arr.length) {
            var arr2 = arr[1].split(';');
            strValue = unescape(arr2[0]);
        }
    }
    return strValue;
}
function deleteCookie(strName) {
    var tmp = getCookie(strName);
    if (tmp)
    { setCookie(strName, tmp, (new Date(1))); }
}

function checkCookieOutside() {
    var username = getCookie('cOutside');
    if (username != null && username != "") {
        //alert('Welcome again '+username+'!');
        return true;
    }
    else {
        //alert('not found');
        return false;
    }
}

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}
