﻿//###########################################################################################################
// Description : Javascript validation
// Author :  RPO, SCS                    Date : 30 Mar 2009
// Copyright 2008 John Wiley and Sons Ltd
//-----------------------------------------------------------------------------------------------------------
// Change log:	Date		Reference		Author		Description
//-----------------------------------------------------------------------------------------------------------
// LABO-OXF264  02/04/2009  R01.P09         RPO         added client side validation
//###########################################################################################################
var _ctrlid = "ctl00_ContentPlaceHolder1_";
var dtCh = "/";
var minYear = 1900;
var maxYear = 2100;
var errHeaderText = "Please make sure you have completed all required fields. <br /><br />";

/* start: validate per page */
function initialize_ClientSide_Validation(_currentpage) {
    if (_currentpage != undefined && _currentpage != null) {  
    
        switch (_currentpage) { 
            /* start: login page header */   
            case "login":
                /* abstract title */
                //$("#ctl00_login1_txtLogin").blur(function() {
                //    isValidLoginEmail(); 
                    //setLoginPanelZIndex(0);                   
                //});   
                
                //$("#ctl00_login1_txtLogin").focus(function() {
                    //setLoginPanelZIndex(1);               
                //});
                
                //$("#ctl00_login1_txtPassword").blur(function() {                    
                    //setLoginPanelZIndex(0);                   
                //});   
                
                //$("#ctl00_login1_txtPassword").focus(function() {
                    //setLoginPanelZIndex(1);               
                //});   
                break;
            /* end: login page header */   
            
            case "createproject":                
                
                $("#txtProjectNameCreate").blur(function() {                    
                    isValidProjectName();
                });   
                
                $("#txtProjectNameCreate").click(function() {                    
                    return false;
                });   
                 break;  
                 
            case "createrssalert":                
                
                $("#txtRSSName").blur(function() {                    
                    isValidCreateRSSName();
                });   
                
                $("#txtRSSName").keypress(function() {                    
                    //return ValidateForm('createrssalert');
                });   
                 break;   
                                 
             case "createemailalert":                
                
                $("#txtAlertName").blur(function() {                                        
                    isValidCustomEmailName();
                });   
                
                $("#txtAlertName").keypress(function() {                    
                    //alert(window.event.keyCode)
                    //return ValidateForm('createemailalert');
                });   
                 break; 
                                 
                 
            /* start: pwd reminder*/   
            case "passwordreminder":
                /* abstract title */
                $("#ctl00_ContentPlaceHolder1_txtLoginPwd").blur(function() {                    
                    PwdReminder_isValidEmail();
                });   
                 break;                                                        
            /* start: pwd reminder */   
            case "admin_abstractdetails":
                /* abstract title */
                $("#" + _ctrlid + "txtAbsTitle").blur(function() {
                    isValidAbsTitle(false);                    
                });                
                
                /* abstract translated title */
                $("#" + _ctrlid + "txtTransTitle").click(function() {
                    isValidTransTitle(true);
                });   
                
                $("#" + _ctrlid + "txtTransTitle").focus(function() {
                    //isValidTransTitle(true);
                });
                                
                /* abstract authors */
                if ($("#txt_author").attr("id") != null && $("#txt_author").attr("id") != undefined) {  
                    
                    $("#txt_author").blur(function() {
                        isValidAuthors(false);
                    });     
                    
                    $("#txt_author").focus(function() {
                        isValidAuthors(true);
                    });         
                }                
               
                /* abstract journals */
                $("#" + _ctrlid + "ddlJournal").blur(function() {                         
                    isValidJournal(false);
                }); 
                
                $("#" + _ctrlid + "ddlJournal").change(function() {                         
                    isValidJournal(false);
                });
                
                /* abstract subdiscipline */
                $("#" + _ctrlid + "lbxSubdis").blur(function() {     
                    isValidSubdiscipline(false);
                }); 
                
                $("#" + _ctrlid + "lbxSubdis").change(function() {                         
                    isValidSubdiscipline(false);
                });
               
                /* publication year */
                $("#" + _ctrlid + "txtYear").blur(function() {
                    isValidYear(false);
                });
                
                /* page range from / to */
                $("#" + _ctrlid + "txtPageFrom").blur(function() {
                    isValidPageRange();
                });
                
                $("#" + _ctrlid + "txtPageTo").blur(function() {
                    isValidPageRange();
                });                
                  
                /* Cross Ref */
                $("#" + _ctrlid + "txtCrossRef").blur(function() {                    
                    isValidCrossRef(false);
                });                
                  
                /* abstract language */
                $("#" + _ctrlid + "ddlLang").blur(function() {                    
                    isValidLanguage();
                });
                
                $("#" + _ctrlid + "ddlLang").change(function() {                    
                    isValidLanguage();
                });
                
                break;
            /* end: client side valid - admin/abstract details page */                   
            
            /* start: client side validation - admin/journal details */
            case "admin_journaldetails": 
              
                $("#" + _ctrlid + "txtJourTitle").blur(function() {                    
                    isValidJourTitle();
                });
                
                //$("#" + _ctrlid + "txtTransTitle").blur(function() {                    
                //    isValidTransTitle();
                //});
                
                $("#" + _ctrlid + "txtSubTitle").blur(function() {                    
                    isValidSubTitle();
                });
                
                $("#" + _ctrlid + "txtTransSubTitle").blur(function() {                    
                    isValidTransSubTitle();
                });
                
                $("#" + _ctrlid + "txtFirstPub").blur(function() {                    
                    isValidFirstPub();
                });
                
                $("#" + _ctrlid + "txtPub").blur(function() {                    
                    isValidPublisherTitle();
                });
                
                $("#" + _ctrlid + "txtURL").blur(function() {                    
                    isValidJournalURL();
                });             
                
                break;
            /* end: client side validation - admin/journal details */
            
            /* start: client side validation - admin/journal details */
            case "admin_accountdetails": 
                $("#" + _ctrlid + "txtEclipseID").blur(function() {                    
                    isValidEclipseID();
                });
                
                $("#" + _ctrlid + "txtExpiry").blur(function() {                                        
                    isValidAccountExpiryDate();
                });
                
                $("#" + _ctrlid + "txtExpiry").change(function() {                                        
                    isValidAccountExpiryDate();
                });
                
                $("#" + _ctrlid + "txtInst").blur(function() {                    
                    isValidAccountInstitutionName();
                });
                
                $("#" + _ctrlid + "txtCity").blur(function() {                    
                    isValidAccountDetailsCity();
                });
                
                $("#" + _ctrlid + "ddlCountry").blur(function() {                    
                    isValidAccountDetailsCountry();
                });
                
                $("#" + _ctrlid + "ddlCountry").change(function() {                    
                    isValidAccountDetailsCountry();
                });
                
                $("#" + _ctrlid + "txtName").blur(function() {                    
                    isValidAccountDetailsContactName();
                });
                
                $("#" + _ctrlid + "txtEmail").blur(function() {                    
                    isValidAccountDetailsEmail();
                });             
                
                break;
            /* end: client side validation - admin/journal details */
            
            /* start: validate admin login page - LABO-OXF06, LABO-OXF201 - R01.P09 - RPO - 29/04/09 */
                case "admin_login":
                                
                $("#" + _ctrlid + "txtAdminLogin").blur(function() {                    
                    isValidAdminLogin();
                }); 
                
                $("#" + _ctrlid + "txtAdminPassword").blur(function() {                    
                    isValidAdminPassword();
                }); 
                
                break;
            /* end: validate admin login page - LABO-OXF06, LABO-OXF201 - R01.P09 - RPO - 29/04/09 */
            
            default:
                break;
        }
    }
}

/* start: funtion to call on clientside submit */
function ValidateForm(_currentpage) {
    var validform = true;
    
    switch (_currentpage) {     
        
            /* start: login page header */   
            case "login":
                /* abstract title */                
                if (!isValidLogin()) {
                    validform = false;
                }                      
                
                break;
            /* end: login page header */   
                        
            case "createproject":                
                if (!isValidProjectName()) {
                    validform = false;
                }   
                break;
                
            case "createrssalert":                                        
                if (!isValidCreateRSSName()) {
                    validform = false;
                } 
                break;
            
            case "createemailalert":                                        
                if (!isValidCustomEmailName()) {
                    validform = false;
                } 
                break;    
                
            case "passwordreminder":
                /* abstract title */                
                if (!PwdReminder_isValidEmail()) {
                    validform = false;
                }        
                break;
            /* start: client side valid - admin/abstract details page */   
            case "admin_abstractdetails":
                if (!isValidAbsTitle(false)) {
                    validform = false;
                }
                
                //if (!isValidTransTitle(false)) {
                //    validform = false;
                //}
                
                if (!isValidAuthors(false)) {
                    validform = false;
                }
                
                if (!isValidJournal(false)) {
                    validform = false;
                }
                
                if (!isValidSubdiscipline(false)) {
                    validform = false;
                }
                
                if (!isValidYear(false)) {
                    validform = false;
                }
                
                if (!isValidPageRange(false)) {
                    validform = false;
                }
                
                if (!isValidCrossRef(false)) {
                    validform = false;
                }
                
                if (!isValidLanguage()) {
                    validform = false;
                }
                
                if (validform) {
                    if (browser.indexOf('Microsoft') > -1) {
                        window.scroll(0,0);
                    }
                    
                    modalPopup_showLoading("Abstract Detail", "Saving abstract...");                    
                    $("#" + _ctrlid + "ValidationSummary1").css("display","none");                    
                    $("#" + _ctrlid + "ValidationSummary1").html("");
                }else{
                    $("#" + _ctrlid + "ValidationSummary1").css("display","inline");                    
                    $("#" + _ctrlid + "ValidationSummary1").html(errHeaderText);                    
                }
                
                break;
            /* end: client side valid - admin/abstract details page */   
            
            /* start: client side valid - admin/journal details page */             
            case "admin_journaldetails":
                
                if (!isValidJourTitle()) {
                    validform = false;
                }
                //if (!isValidTransTitle()) {
                //    validform = false;
                //}
                if (!isValidSubTitle()) {
                    validform = false;
                }
                if (!isValidTransSubTitle()) {
                    validform = false;
                }
                if (!isValidPublisherTitle()) {
                    validform = false;
                }
                
                if (!isValidFirstPub()) {
                    validform = false;
                }                
                
                if (!isValidJournalURL()) {                    
                    validform = false;
                }                
                
                break;
            /* start: client side valid - admin/journal details page */                         
            
            /* start: client side valid - admin/account details page */             
            case "admin_accountdetails":
                
                if (!isValidEclipseID()) {
                    validform = false;
                }
                if (!isValidAccountExpiryDate()) {
                    validform = false;
                }
                if (!isValidAccountInstitutionName()) {
                    validform = false;
                }
                
                if (!isValidAccountDetailsCity()) {
                    validform = false;
                }
                if (!isValidAccountDetailsCountry()) {
                    validform = false;
                }
                
                if (!isValidAccountDetailsContactName()) {
                    validform = false;
                }                
                
                if (!isValidAccountDetailsEmail()) {                    
                    validform = false;
                }                
                
                break;
            /* start: client side valid - admin/account details page */   
            
            /* start: validate admin login page - LABO-OXF06, LABO-OXF201 - R01.P09 - RPO - 29/04/09 */
                case "admin_login":
                
                if (!isValidAdminLogin()) {
                    validform = false;
                }
                
                if (!isValidAdminPassword()) {
                    validform = false;
                }
                
                if (validform) {
                    show_page_updating();
                    $("#lblValidatingAdminLogin").css("visibility","visible");
                }
                
                break;
            /* end: validate admin login page - LABO-OXF06, LABO-OXF201 - R01.P09 - RPO - 29/04/09 */
            
            default:
                break;
    }           
    
    
    
    if (!validform) window.scroll(0,0);
                
    return validform;
}

/* end: funtion to call on clientside submit */

/* start: validation fields - abstract details admin */
function isValidAbsTitle(onfocus) {
    if (onfocus) {
        if ($("#" + _ctrlid + "txtAbsTitle").val().trim() == "Required field.") {
            remove_required_field("#" + _ctrlid + "txtAbsTitle","Required field.");
            return true;
        }
    }else{
        if ($("#" + _ctrlid + "txtAbsTitle").val().trim() == "" || $("#" + _ctrlid + "txtAbsTitle").val().trim() == "Required field.") {                                                         
            set_required_field("#" + _ctrlid + "txtAbsTitle","Required field.");
            return false;
        }  
    }    
    return true;
}

function isValidTransTitle(onfocus) {
    if (onfocus) {
        if ($("#" + _ctrlid + "txtTransTitle").val().trim() == "Minimum 2 characters required.") {
            remove_required_field("#" + _ctrlid + "txtTransTitle","Minimum 2 characters required.");
            return true;
        }
    }else{
        if ($("#" + _ctrlid + "txtTransTitle").val().trim() != "") {
            if ($("#" + _ctrlid + "txtTransTitle").val().length < 2) {
                set_required_field("#" + _ctrlid + "txtTransTitle","Minimum 2 characters required."); 
                return false;  
            }            
        }
        
        //if ($("#" + _ctrlid + "txtTransTitle").val().trim() == "" || $("#" + _ctrlid + "txtTransTitle").val().trim() == "Required field.") {                                                         
        //    set_required_field("#" + _ctrlid + "txtTransTitle","Required field.");                        
        //    return false;   
        //}
    }   
    return true; 
}

function isValidAuthors(onfocus) {    
    if (onfocus) {
        if ($("#txt_author").val().trim() == "Required field.") {
            $("#txt_author").val("");            
        }
        
        if ($("#" + _ctrlid + "txtAuthorIDList").val().trim() == "") {
            remove_required_field("#txt_author","Required field.");
            return true;
        }
        
    }else{
        if ($("#" + _ctrlid + "txtAuthorIDList").val().trim() == "") { 
            //set_required_field("#txt_author","Required field.");  
            //return false;
        }
    }    
    return true;
}

function isValidJournal(onfocus) {
    if (onfocus) {
        if ($("#" + _ctrlid + "ddlJournal").val().trim() == "") {
            $("#" + _ctrlid + "cvJouranl").css("visibility","hidden");
            $("#" + _ctrlid + "cvJouranl").html("*");            
        }
    }else{
        if ($("#" + _ctrlid + "ddlJournal").val().trim() == "") {
            $("#" + _ctrlid + "cvJouranl").css("visibility","visible");
            $("#" + _ctrlid + "cvJouranl").html("Required field.");                      
            return false;   
        }else{
            $("#" + _ctrlid + "cvJouranl").css("visibility","hidden");
            $("#" + _ctrlid + "cvJouranl").html("*");            
        }
    }
    return true; 
}


function isValidSubdiscipline(onfocus) {
    if (onfocus) {
        if ($("#" + _ctrlid + "lbxSubdis").val().trim() == "") {
            $("#" + _ctrlid + "cvSubdiscipline").css("visibility","hidden");
            $("#" + _ctrlid + "cvSubdiscipline").html("*");            
        }
    }else{
        if ($("#" + _ctrlid + "lbxSubdis").val().trim() == "") {
            $("#" + _ctrlid + "cvSubdiscipline").css("visibility","visible");
            $("#" + _ctrlid + "cvSubdiscipline").html("Required field.");                      
            return false;   
        }else{
            $("#" + _ctrlid + "cvSubdiscipline").css("visibility","hidden");
            $("#" + _ctrlid + "cvSubdiscipline").html("*");            
        }
    }
    return true; 
}

function isValidYear(onfocus) {
    if (onfocus) {
        if ($("#" + _ctrlid + "txtYear").val().trim() == "") {
            $("#" + _ctrlid + "cvYear").css("visibility","hidden");
            $("#" + _ctrlid + "cvYear").html("*");            
        }
    }else{
        if ($("#" + _ctrlid + "txtYear").val().trim() == "") {
            $("#" + _ctrlid + "cvYear").css("visibility","visible");
            $("#" + _ctrlid + "cvYear").html("Required field.");                      
            return false;   
        }else{            
            if (!isNumeric($("#" + _ctrlid + "txtYear").val().trim())) {
                $("#" + _ctrlid + "cvYear").css("visibility","visible");
                $("#" + _ctrlid + "cvYear").html("Invalid Year format.");                        
                return false;
            }else{
                if ($("#" + _ctrlid + "txtYear").val().length < 4) {
                    $("#" + _ctrlid + "cvYear").css("visibility","visible");
                    $("#" + _ctrlid + "cvYear").html("Invalid Year format.");                        
                    return false;
                }else{
                    $("#" + _ctrlid + "cvYear").css("visibility","hidden");
                    $("#" + _ctrlid + "cvYear").html("Required field.");                        
                }
            }                  
        }
    }
    return true; 
}

function isValidPageRange() {     
    return validatePageRange(_ctrlid + "txtPageTo", _ctrlid + "txtPageFrom");
}

function validatePageRange(txtpageto, txtpagefrom) {
    var _pagerange_err = "";  
    var _validpagerange = true;
   
    if (document.getElementById(txtpagefrom).value != "") {
        if (!isNumeric(document.getElementById(txtpagefrom).value)) {
            _pagerange_err += "Page range from should be numeric.<br />";
            _validpagerange = false;
        }      
    }  
    
    if (document.getElementById(txtpageto).value != "") {
        if (!isNumeric(document.getElementById(txtpageto).value)) {
            _pagerange_err += "Page range to should be numeric.<br />";
            _validpagerange = false;
        }      
    }   
    
    if (document.getElementById(txtpageto).value != "" && document.getElementById(txtpagefrom).value != "") {
        
        if (isNumeric(document.getElementById(txtpageto).value) && isNumeric(document.getElementById(txtpagefrom).value)) {
            if (eval(document.getElementById(txtpageto).value) < eval(document.getElementById(txtpagefrom).value)) {
                _pagerange_err += "Page range from should be less than page range to.";
                _validpagerange = false;
            }
        }
    }   
    
    if (_pagerange_err != "") {
        $("#" + _ctrlid + "cvPageFromTo").css("visibility","visible");             
        $("#" + _ctrlid + "cvPageFromTo").html("<br />" + _pagerange_err);
    }else{
        $("#" + _ctrlid + "cvPageFromTo").css("visibility","hidden");
        $("#" + _ctrlid + "cvPageFromTo").html("*");
    }
    
    return _validpagerange;
}

function isValidCrossRef(onfocus) {
    if ($("#" + _ctrlid + "txtCrossRef").val().trim() != "" && $("#" + _ctrlid + "txtCrossRef").val().trim().indexOf("dx.doi.org") > -1) {
        $("#" + _ctrlid + "cvCrossRef").css("visibility","visible");
        $("#" + _ctrlid + "cvCrossRef").html("CrossRef URL must not have 'http://dx.doi.org/'.");                        
        return false;
    }else{
        //if ($("#" + _ctrlid + "txtCrossRef").val().trim() != "") {
        //    if (!isValidURL($("#" + _ctrlid + "txtCrossRef").val().trim())) {
        //        $("#" + _ctrlid + "cvCrossRef").css("visibility","visible");
        //        $("#" + _ctrlid + "cvCrossRef").html("CrossRef is not a valid URL format."); 
        //        return false;
        //    }else{
        //        $("#" + _ctrlid + "cvCrossRef").css("visibility","hidden");
        //        $("#" + _ctrlid + "cvCrossRef").html("*");                        
        //    }
        //}else{
            $("#" + _ctrlid + "cvCrossRef").css("visibility","hidden");
            $("#" + _ctrlid + "cvCrossRef").html("*");                        
        //}
    }        
    return true;
}                                
function isValidLanguage() {
    if ($("#" + _ctrlid + "ddlLang").val().trim() == "" || $("#" + _ctrlid + "ddlLang").val().trim() == "0") {
        $("#" + _ctrlid + "cvLanguage").css("visibility","visible");
        $("#" + _ctrlid + "cvLanguage").html("Required field.");
        return false;
    }else{
        $("#" + _ctrlid + "cvLanguage").css("visibility","hidden");
        $("#" + _ctrlid + "cvLanguage").html("*");
        return true;
    }
}
                              
/* end: validation fields - abstract details admin */

/* start: validation fields - journal details */

function isValidJourTitle() {
    if ($("#" + _ctrlid + "txtJourTitle").val().trim() == "") { 
        $("#" + _ctrlid + "cvJourTitleMinimumLength").css("visibility","visible");
        $("#" + _ctrlid + "cvJourTitleMinimumLength").html("Journal Title is a required field.");
        return false;
    }else{
        if ($("#" + _ctrlid + "txtJourTitle").val().trim().length < 2) {     
            $("#" + _ctrlid + "cvJourTitleMinimumLength").css("visibility","visible");
            $("#" + _ctrlid + "cvJourTitleMinimumLength").html("Journal Title should be at least 2 characters.");
            return false;
        }else{
            $("#" + _ctrlid + "cvJourTitleMinimumLength").css("visibility","hidden");
            $("#" + _ctrlid + "cvJourTitleMinimumLength").html("*");
        }    
    }
    return true;    
}

function isValidTransTitle() {
    if ($("#" + _ctrlid + "txtTransTitle").val().trim() == "") { 
        $("#" + _ctrlid + "cvTransTitleMinimumLength").css("visibility","visible");
        $("#" + _ctrlid + "cvTransTitleMinimumLength").html("Journal Translated Title is a required field.");
        return false;
    }else{
        if ($("#" + _ctrlid + "txtTransTitle").val().trim().length < 2) {     
            $("#" + _ctrlid + "cvTransTitleMinimumLength").css("visibility","visible");
            $("#" + _ctrlid + "cvTransTitleMinimumLength").html("Journal Translated Title should be at least 2 characters.");
            return false;
        }else{
            $("#" + _ctrlid + "cvTransTitleMinimumLength").css("visibility","hidden");
            $("#" + _ctrlid + "cvTransTitleMinimumLength").html("*");
        }    
    }
    return true;    
}

function isValidSubTitle() {
    if ($("#" + _ctrlid + "txtSubTitle").val().trim() != "" && $("#" + _ctrlid + "txtSubTitle").val().trim().length < 2) { 
        $("#" + _ctrlid + "cvSubTitleMinimumLength").css("visibility","visible");
        $("#" + _ctrlid + "cvSubTitleMinimumLength").html("Sub Title requires minimum entry of 2 characters, please edit.");
        return false;
    }else{
        $("#" + _ctrlid + "cvSubTitleMinimumLength").css("visibility","hidden");
        $("#" + _ctrlid + "cvSubTitleMinimumLength").html("*");
        return true;
    }    
}

function isValidTransSubTitle() {
    if ($("#" + _ctrlid + "txtTransSubTitle").val().trim() != "" && $("#" + _ctrlid + "txtTransSubTitle").val().trim().length < 2) { 
        $("#" + _ctrlid + "cvTransSubTitleMinimumLength").css("visibility","visible");
        $("#" + _ctrlid + "cvTransSubTitleMinimumLength").html("Translated Sub Title requires minimum entry of 2 characters, please edit.");
        return false;
    }else{
        $("#" + _ctrlid + "cvTransSubTitleMinimumLength").css("visibility","hidden");
        $("#" + _ctrlid + "cvTransSubTitleMinimumLength").html("*");
        return true;
    }    
}

function isValidFirstPub() {
    if ($("#" + _ctrlid + "txtFirstPub").val().trim() != "") {
        if (!isNumeric($("#" + _ctrlid + "txtFirstPub").val().trim())) {
            $("#" + _ctrlid + "cvFirstPubMinimumLength").css("visibility","visible");
            $("#" + _ctrlid + "cvFirstPubMinimumLength").html("Year First Published should be valid numeric format.");
            return false;
        }else{
            if ($("#" + _ctrlid + "txtFirstPub").val().trim().length < 4) {
                $("#" + _ctrlid + "cvFirstPubMinimumLength").css("visibility","visible");
                $("#" + _ctrlid + "cvFirstPubMinimumLength").html("Year First Published is not a valid year.");            
                return false;
            }else{
                $("#" + _ctrlid + "cvFirstPubMinimumLength").css("visibility","hidden");
                $("#" + _ctrlid + "cvFirstPubMinimumLength").html("*");            
            }
        }
    }    
    return true;
}

function isValidPublisherTitle() {
    if ($("#" + _ctrlid + "txtPub").val().trim() == "") {
        $("#" + _ctrlid + "cvPublisherTitleMinimumLength").css("visibility","visible");
        $("#" + _ctrlid + "cvPublisherTitleMinimumLength").html("Requried field.");  
        return false;
    }else{        
        $("#" + _ctrlid + "cvPublisherTitleMinimumLength").css("visibility","hidden");
        $("#" + _ctrlid + "cvPublisherTitleMinimumLength").html("*");  
        return true;
    }    
}

function isValidJournalURL() {
    if ($("#" + _ctrlid + "txtURL").val().trim() != "") {
        if (!isValidURL($("#" + _ctrlid + "txtURL").val().trim())) {            
            $("#" + _ctrlid + "cvURLMinimumLength").css("visibility","visible");
            $("#" + _ctrlid + "cvURLMinimumLength").html("Not a valid URL format.");   
            return false;
        }else{
            $("#" + _ctrlid + "cvURLMinimumLength").css("visibility","hidden");
            $("#" + _ctrlid + "cvURLMinimumLength").html("*");  
        }        
    }else{
        $("#" + _ctrlid + "cvURLMinimumLength").css("visibility","hidden");
        $("#" + _ctrlid + "cvURLMinimumLength").html("*");  
    }
    return true;
}

/* end: validation fields - journal details */

/* start: validation fields - account details */
function isValidEclipseID() {
    if ($("#" + _ctrlid + "txtEclipseID").val().trim() == "") {
        $("#" + _ctrlid + "cvCustomerEclipseIDAsterisk").css("visibility","visible");
        $("#" + _ctrlid + "cvCustomerEclipseIDAsterisk").html("Requried field.");  
        return false;
    }else{        
        $("#" + _ctrlid + "cvCustomerEclipseIDAsterisk").css("visibility","hidden");
        $("#" + _ctrlid + "cvCustomerEclipseIDAsterisk").html("*");  
        return true;
    }     
}

function isValidAccountExpiryDate() {    
    
    if ($("#" + _ctrlid + "txtExpiry").val().trim() == "") {
        $("#" + _ctrlid + "cvTxtExpiryDate").css("visibility","visible");
        $("#" + _ctrlid + "cvTxtExpiryDate").html("Requried field.");  
        return false;
    }else{        
        if (!isDate($("#" + _ctrlid + "txtExpiry").val().trim())) {
            $("#" + _ctrlid + "cvTxtExpiryDate").css("visibility","visible");
            $("#" + _ctrlid + "cvTxtExpiryDate").html("Not a valid date format");  
            return false;
        }else{
            $("#" + _ctrlid + "cvTxtExpiryDate").css("visibility","hidden");
            $("#" + _ctrlid + "cvTxtExpiryDate").html("*");  
        }
        
    }   
    return true;
}

function isValidAccountInstitutionName() {      
    if ($("#" + _ctrlid + "txtInst").val().trim() == "") {
        $("#" + _ctrlid + "cvInstMinimumLength").css("visibility","visible");
        $("#" + _ctrlid + "cvInstMinimumLength").html("Requried field.");  
        return false;
    }else{        
        if ($("#" + _ctrlid + "txtInst").val().trim().length < 3) {
            $("#" + _ctrlid + "cvInstMinimumLength").css("visibility","visible");
            $("#" + _ctrlid + "cvInstMinimumLength").html("Minimum 3 characters required.");  
            return false;
        }else{
            $("#" + _ctrlid + "cvInstMinimumLength").css("visibility","hidden");
            $("#" + _ctrlid + "cvInstMinimumLength").html("*");  
        }
        
    }   
    return true;
}

function isValidAccountDetailsCity() {
    if ($("#" + _ctrlid + "txtCity").val().trim() == "") {
        $("#" + _ctrlid + "cvCityAsterisk").css("visibility","visible");
        $("#" + _ctrlid + "cvCityAsterisk").html("Requried field.");  
        return false;
    }else{        
        if ($("#" + _ctrlid + "txtCity").val().trim().length < 3) {
            $("#" + _ctrlid + "cvCityAsterisk").css("visibility","visible");
            $("#" + _ctrlid + "cvCityAsterisk").html("Minimum 3 characters required.");  
            return false;
        }else{
            $("#" + _ctrlid + "cvCityAsterisk").css("visibility","hidden");
            $("#" + _ctrlid + "cvCityAsterisk").html("*");  
        }
        
    }   
    return true;
}

function isValidAccountDetailsCountry() {
    if ($("#" + _ctrlid + "ddlCountry").val().trim() == "-1") {
        $("#" + _ctrlid + "cvDdlCountry").css("visibility","visible");
        $("#" + _ctrlid + "cvDdlCountry").html("Requried field.");  
        return false;
    }else{        
        $("#" + _ctrlid + "cvDdlCountry").css("visibility","hidden");
        $("#" + _ctrlid + "cvDdlCountry").html("*");          
        return true;
    }
}

function isValidAccountDetailsContactName() {
    if ($("#" + _ctrlid + "txtName").val().trim() == "") {
        $("#" + _ctrlid + "cvNameAsterisk").css("visibility","visible");
        $("#" + _ctrlid + "cvNameAsterisk").html("Requried field.");  
        return false;
    }else{        
        if ($("#" + _ctrlid + "txtName").val().trim().length < 3) {
            $("#" + _ctrlid + "cvNameAsterisk").css("visibility","visible");
            $("#" + _ctrlid + "cvNameAsterisk").html("Minimum 3 characters required.");  
            return false;
        }else{
            $("#" + _ctrlid + "cvNameAsterisk").css("visibility","hidden");
            $("#" + _ctrlid + "cvNameAsterisk").html("*");  
        }
        
    }   
    return true;
}

function isValidAccountDetailsEmail() {
    if ($("#" + _ctrlid + "txtEmail").val().trim() == "") {
        $("#" + _ctrlid + "cvEmailInvalid").css("visibility","visible");
        $("#" + _ctrlid + "cvEmailInvalid").html("Requried field.");  
        return false;
    }else{        
        if (!isValidEmail($("#" + _ctrlid + "txtEmail").val().trim())) {
            $("#" + _ctrlid + "cvEmailInvalid").css("visibility","visible");
            $("#" + _ctrlid + "cvEmailInvalid").html("Invalid email format.");  
            return false;
        }else{
            $("#" + _ctrlid + "cvEmailInvalid").css("visibility","hidden");
            $("#" + _ctrlid + "cvEmailInvalid").html("*");  
        }
        
    }   
    return true;
}

/* end: validation fields - account details */

/* start: admin login validation - LABO-OXF06, LABO-OXF201 - R01.P09 - RPO - 29/04/09 */
function isValidAdminLogin() {
    if ($("#" + _ctrlid + "txtAdminLogin").val().trim() == "") {
        $("#lblInvalidAdminEmail").css("visibility","visible");
        $("#lblInvalidAdminEmail").html("Please enter admin email.")        
        return false;   
    }else{
         if (!isValidEmail($("#" + _ctrlid + "txtAdminLogin").val().trim())) {
            $("#lblInvalidAdminEmail").css("visibility","visible");
            $("#lblInvalidAdminEmail").html("Invalid email format.");  
            return false;
        }else{
            $("#lblInvalidAdminEmail").css("visibility","hidden");
            $("#lblInvalidAdminEmail").html("");  
        }
    }
    
    $("#lblInvalidAdminEmail").css("visibility","hidden");
    $("#lblInvalidAdminEmail").html("")        
    return true;
}
/* end: admin login validation - LABO-OXF06, LABO-OXF201 - R01.P09 - RPO - 29/04/09 */

function isValidAdminPassword() {
    if ($("#" + _ctrlid + "txtAdminPassword").val().trim() == "") {
        $("#lblInvalidAdminPassword").css("visibility","visible");
        $("#lblInvalidAdminPassword").html("Please enter admin password.")        
        return false;   
    }    
    
    $("#lblInvalidAdminPassword").css("visibility","hidden");
    $("#lblInvalidAdminPassword").html("")        
    return true;
}
/* end: admin login validation */

function isValidLogin() {
    if (!isValidLoginEmail()) {
        modalPopup_showAlert("Login Error", "Sorry, your email address or password could not be verified. Please try again.");                      
        return false;
    }    
    else
        return true;
}

function isValidLoginEmail() {
    var login = true;
    
    if ($("#ctl00_login1_txtLogin").val().trim() == "") {        
        login = false;   
    }else{
         if (!isValidEmail($("#ctl00_login1_txtLogin").val().trim())) {           
            login = false;
         }else{
            if (!isValidLoginPwd()) {
                login = false;
            }
         }
    }
    return login;
}

function isValidLoginPwd() {
    if ($("#ctl00_login1_txtPassword").val().trim() == "") {        
        return false;   
    }
    return true;
}


function PwdReminder_isValidEmail() {
    if (document.getElementById("txtLoginPwd").value == "") {
        displayErrorText("block","Please enter your email address.");        
        return false;   
    }else{
        if (!isValidEmail(document.getElementById("txtLoginPwd").value)) {
            displayErrorText("block","Incorrect email address format.");            
           return false;
        }
    }
    
    displayErrorText("none","");
    return true;
}

function isValidProjectName() {
    if (document.getElementById("txtProjectNameCreate").value.trim() == "") {
        displayErrorText("block","Please enter project name.");                    
        return false;
    }else{
        displayErrorText("none","");    
        return true;
    }
}

function isValidCustomEmailName() {    
    if (document.getElementById("txtAlertName").value.trim() == "") {
        displayErrorText("block","Please enter Custom Email Alert name.");                    
        return false;
    }else{
        displayErrorText("none","");    
        return true;
    }   
}

function isValidCreateRSSName() {    
    if (document.getElementById("txtRSSName").value.trim() == "") {
        displayErrorText("block","Please enter RSS Alert name.");                    
        return false;
    }else{
        displayErrorText("none","");    
        return true;
    }
}

function displayErrorText(display, errtext) {
    $("#clientsidevalidation").css("display", display);
    $("#clientsidevalidation").html(errtext);    
}
        
function toggleErr(div, err, display) {
    $("#" + div).css("display", display);
    $("#" + div).html(err);
}
/* start: validation functions */               
function set_required_field(obj, txt) {    
    $(obj).css("color","red");
    $(obj).val(txt);          
}

function remove_required_field(obj) {    
    $(obj).css("color","black");       
    $(obj).val("");  
}

function isNumeric(txt) {        
    var _numeric = /^[0-9]+$/;
    return _numeric.test(txt);
}

function isAlphaNumeric(str) {
	var pattern = /^([a-zA-Z0-9_\s-]+)$/; 	
	return pattern.test(str);
}

function isValidEmail(txt_email) {
    var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;    
    return emailFilter.test(txt_email.trim());
}

function isValidURL(txt_url) {
	var urlFilter = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
	return urlFilter.test(txt_url);
}


function validateNumericOnly(obj) {
    if (obj.value != "") {
        if (!isNumeric(obj).value) {
            modalPopup_showAlert('Validate Numeric','Please enter numeric value.');
            obj.focus();
        }
    }
}

function isValidVolumeIssue(value) {
    var _isvalidVolumeIssue = /^[0-9\-]+$/;
    return _isvalidVolumeIssue.test(value);
}

function stringtrim(str) {
    return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
    return true
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}


function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function resizeInputText(obj, maxWidth) {
    if ($(obj).val().length > maxWidth) {
        if ($(obj).css("overflow") == "visible") {
            $(obj).css("overflow", "hidden");                    
            document.getElementById(obj.id).size = 16;
        }
        /*else{
            if ($(obj).css("overflow") == "hidden") {
                $(obj).css("overflow", "visible");                    
                document.getElementById(obj.id).size = 6;
            }
        }
        */
    }
}        
/* end: validation functions */    
