﻿//LTSB script contact forms validation scripts
	function ClearText(ele, type)
	{
		var val = ele.value;
		
		if(type==1)
		{
			if (val == 'Please include the international dialing code.')
			{
				ele.value='';
				ele.className = 'EnquiryText';
			}
		}
		else if(type==2)
		{
			if (val == 'Maximum 200 characters.')
			{
				ele.value='';
				ele.className = 'EnquiryText';
			}
		}
	}
	
	function ShowText(ele, type)
	{
		var val = ele.value;
		
		if(type==1)
		{
			if (val == '') 
			{ 
				ele.className = 'infoText';
				ele.value = 'Please include the international dialing code.';
			}
			else
			{
				ele.className = 'EnquiryText';
			}
		}
		else if(type==2)
		{
			if (val == '') 
			{ 
				ele.className = 'infoText';
				ele.value = 'Maximum 200 characters.';
			}
			else
			{
				ele.className = 'EnquiryText';
			}
		}
	}
	
	function ValidateForm()
	{
	    var Title = document.getElementById("ctl00_cph1_DdlTitle");
	    var Fname = document.getElementById("ctl00_cph1_TxtFirstName");
	    var Lname = document.getElementById("ctl00_cph1_TxtLastName");
	    var Country = document.getElementById("ctl00_cph1_DdlCountry");
	    var Phone = document.getElementById("ctl00_cph1_TxtPhone");
	    var Email = document.getElementById("ctl00_cph1_TxtEmail");
	    var Query = document.getElementById("ctl00_cph1_TxtEnquiry");
	    
	    ShowSuccess(Title);
	    ShowSuccess(Fname);
	    ShowSuccess(Lname);
	    ShowSuccess(Country);
	    ShowSuccess(Phone);
	    ShowSuccess(Email);
	    ShowSuccess(Query);
	    
	    var isValid = true;
	    
	    if(isValid)
	    {
	        if(Title.value == "Please select...")
	        {
	            isValid=false;
	            ShowError(Title)
	        }
	        else
	        {
	            isValid=true;
	            ShowSuccess(Title);
	        }
	    }
	    
	    if(isValid)
	    {
	        if(Fname.value == "")
	        {
	           isValid=false;
	            ShowError(Fname)
	        }
            else
	        {
	            isValid=true;
	            ShowSuccess(Fname);
	        }
	    }
	    if(isValid)
	    {
	        if(Lname.value == "")
	        {
	           isValid=false;
	            ShowError(Lname)
	        }
            else
	        {
	            isValid=true;
	            ShowSuccess(Lname);
	        }
	    }
	    if(isValid)
	    {
	        if(Country.value == "")
	        {
	           isValid=false;
	            ShowError(Country)
	        }
            else
	        {
	            isValid=true;
	            ShowSuccess(Country);
	        }
	    }
	    if(isValid)
	    {
	        if(Phone.value == "" || Phone.value == "Please include the international dialing code.")
	        {
	           isValid=false;
	            ShowError(Phone)
	        }
            else
	        {
	            isValid=true;
	            ShowSuccess(Phone);
	        }
	    }
	    if(isValid)
	    {
	        if (Email.value != "") {
	            var valid = ValidateEmail(Email.value);
	            if (!valid) {
	                isValid = false;
	                ShowError(Email)
	            }
	            else {
	                isValid = true;
	                ShowSuccess(Email);
	            }
	        }
	        else {

	            isValid = false;
	            ShowError(Email)
            }
	    }
	    if(isValid)
	    {
	        if(Query.value == "" || Query.value == "Maximum 200 characters.")
	        {
	           isValid=false;
	            ShowError(Query)
	        }
            else
	        {
	            isValid=true;
	            ShowSuccess(Query);
	        }
	    }

        if(isValid)
	    {
	        return true;
	    }
	    else
	    {
	        return false;
	    }
	}

	function showTip() {
	    alert("If you have an enquiry about your existing account or specific account transactions, please submit this using the secure e-mail facility on internet banking. Please do not enter confidential details relating to your account number or transaction details.  Please note Lloyds TSB will never ask for confidential information regarding user names, passwords or personal information regarding your account");
	}

	function ShowError(ele)
	{
	    ele.style.borderColor = '#ee3239';
	    ele.focus();
	}
	function ShowSuccess(ele)
	{
	    ele.style.borderColor = '#9a9a9a';
	}
	
	function ValidateEmail(ele) 
	{
        var email = ele;
        var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
        if (!filter.test(email)) 
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    
    function LimitChars(textid, limit, infodiv) 
    { 
        var text = document.getElementById(textid);
        var info = document.getElementById(infodiv);
        var textlength = text.value.length; 
        if(textlength > limit) 
        { 
            //info.innerHTML = 'You cannot write more then '+limit+' characters!'; 
            text.value = text.value.substring(0,limit); 
            return false; 
        } 
        else 
        { 
            info.innerHTML = 'You have '+ (limit - textlength) +' characters left.'; 
            return true; 
        } 
    } 
	
