﻿
var n;
var p;
var p1;
function ValidatePhone()
{
    p=p1.value
    if(p.length==3)
    {
	    pp=p;
	    d4=p.indexOf('(')
	    d5=p.indexOf(')')
	    if(d4==-1)
	    {
		    pp="("+pp;
	    }
	    if(d5==-1)
	    {
		    pp=pp+")";
	    }
	    document.getElementById("ctl00_MainContentArea_txtPhoneNumber2").value="";
	    document.getElementById("ctl00_MainContentArea_txtPhoneNumber2").value=pp;
    }
    if(p.length>3)
    {
	    d1=p.indexOf('(')
	    d2=p.indexOf(')')
	    if (d2==-1)
	    {
		    l30=p.length;
		    p30=p.substring(0,4);
		    p30=p30+")"
		    p31=p.substring(4,l30);
		    pp=p30+p31;
		    document.getElementById("ctl00_MainContentArea_txtPhoneNumber2").value="";
		    document.getElementById("ctl00_MainContentArea_txtPhoneNumber2").value=pp;
	    }
    }
    if(p.length>5)
    {
	    p11=p.substring(d1+1,d2);
	    if(p11.length>3)
	    {
	        p12=p11;
	        l12=p12.length;
	        l15=p.length
	        p13=p11.substring(0,3);
	        p14=p11.substring(3,l12);
	        p15=p.substring(d2+1,l15);
	        document.getElementById("ctl00_MainContentArea_txtPhoneNumber2").value="";
	        pp="("+p13+")"+p14+p15;
	        document.getElementById("ctl00_MainContentArea_txtPhoneNumber2").value=pp;
	    }
	    l16=p.length;
	    p16=p.substring(d2+1,l16);
	    l17=p16.length;
	    if(l17>3&&p16.indexOf('-')==-1)
	    {
		    p17=p.substring(d2+1,d2+4);
		    p18=p.substring(d2+4,l16);
		    p19=p.substring(0,d2+1);
	        pp=p19+p17+"-"+p18;
	        document.getElementById("ctl00_MainContentArea_txtPhoneNumber2").value="";
	        document.getElementById("ctl00_MainContentArea_txtPhoneNumber2").value=pp;
	    }
    }
    
    
    if(document.getElementById("ctl00_MainContentArea_ddCountry").options[document.getElementById("ctl00_MainContentArea_ddCountry").selectedIndex].text == "United States")
    {
        setTimeout(ValidatePhone,100)
    }
}

function GetPhoneValue(m)
{
    if(document.getElementById("ctl00_MainContentArea_ddCountry").options[document.getElementById("ctl00_MainContentArea_ddCountry").selectedIndex].text == "United States")
    {
        n=m.name;
        p1=m
        ValidatePhone()
    }
}


function ValidateTxtUPI(source, args)
{
        args.IsValid = true;
}

function ValidateTxtFirstName(source, args)
{
    if (trim(document.getElementById("ctl00_MainContentArea_txtFirstName").value) != "")
    {
        document.getElementById("ctl00_MainContentArea_txtFirstName").style.border = '1px solid #c1b8b2';
        args.IsValid = true; 
    }
    else
    {
        document.getElementById("ctl00_MainContentArea_txtFirstName").style.border = '1px solid Red';
        args.IsValid = false;
    }
}

function ValidateTxtLastName(source, args)
{
    if (trim(document.getElementById("ctl00_MainContentArea_txtLastName").value) != "")
    {
        document.getElementById("ctl00_MainContentArea_txtLastName").style.border = '1px solid #c1b8b2';
        args.IsValid = true; 
    }
    else
    {
        document.getElementById("ctl00_MainContentArea_txtLastName").style.border = '1px solid Red';
        args.IsValid = false;
    }
}

function ValidateTxtEmail(source, args)
{
    if (trim(document.getElementById("ctl00_MainContentArea_txtEmail").value) != "")
    {
        document.getElementById("ctl00_MainContentArea_txtEmail").style.border = '1px solid #c1b8b2';
        args.IsValid = true; 
    }
    else
    {
        document.getElementById("ctl00_MainContentArea_txtEmail").style.border = '1px solid Red';
        args.IsValid = false;
    }
}

function ValidateTxtConfirmEmail(source, args)
{
    if (trim(document.getElementById("ctl00_MainContentArea_txtConfirmEmail").value) != "")
    {
        document.getElementById("ctl00_MainContentArea_txtConfirmEmail").style.border = '1px solid #c1b8b2';
        args.IsValid = true; 
    }
    else
    {
        document.getElementById("ctl00_MainContentArea_txtConfirmEmail").style.border = '1px solid Red';
        args.IsValid = false;
    }
}

function ValidateTxtPassword(source, args)
{
    if (trim(document.getElementById("ctl00_MainContentArea_txtPassword").value) != "")
    {
        document.getElementById("ctl00_MainContentArea_txtPassword").style.border = '1px solid #c1b8b2';
        args.IsValid = true; 
    }
    else
    {
        document.getElementById("ctl00_MainContentArea_txtPassword").style.border = '1px solid Red';
        args.IsValid = false;
    }
}

function ValidateTxtConfirmPassword(source, args)
{
    if (trim(document.getElementById("ctl00_MainContentArea_txtConfirmPassword").value) != "")
    {
        document.getElementById("ctl00_MainContentArea_txtConfirmPassword").style.border = '1px solid #c1b8b2';
        args.IsValid = true; 
    }
    else
    {
        document.getElementById("ctl00_MainContentArea_txtConfirmPassword").style.border = '1px solid Red';
        args.IsValid = false;
    }
}

function ValidateTxtCity(source, args)
{
    if (trim(document.getElementById("ctl00_MainContentArea_txtCity").value) != "")
    {
        document.getElementById("ctl00_MainContentArea_txtCity").style.border = '1px solid #c1b8b2';
        args.IsValid = true; 
    }
    else
    {
        document.getElementById("ctl00_MainContentArea_txtCity").style.border = '1px solid Red';
        args.IsValid = false;
    }
}

function ValidateDdState(source, args)
{
    if(document.getElementById("ctl00_MainContentArea_ddCountry").options[document.getElementById("ctl00_MainContentArea_ddCountry").selectedIndex].text == "United States")
    {
        if (trim(document.getElementById("ctl00_MainContentArea_ddState").value) != "")
        {
            document.getElementById("ctl00_MainContentArea_ddState").style.background = '#FFFFFF';
            args.IsValid = true; 
        }
        else
        {
            document.getElementById("ctl00_MainContentArea_ddState").style.background = 'Red';
            args.IsValid = false;
        }
    }
    else
    {
        document.getElementById("ctl00_MainContentArea_ddState").style.background = '#FFFFFF';
        args.IsValid = true; 
    }
}


function ValidateTxtInternationalState(source, args)
{
    if(document.getElementById("ctl00_MainContentArea_ddCountry").options[document.getElementById("ctl00_MainContentArea_ddCountry").selectedIndex].text != "United States")
    {
        if (trim(document.getElementById("ctl00_MainContentArea_txtInternationalState").value) != "")
        {
            document.getElementById("ctl00_MainContentArea_txtInternationalState").style.border = '1px solid #c1b8b2';
            args.IsValid = true; 
        }
        else
        {
            document.getElementById("ctl00_MainContentArea_txtInternationalState").style.border = '1px solid Red';
            args.IsValid = false;
        }
    }
    else
    {
        document.getElementById("ctl00_MainContentArea_ddState").style.border = '1px solid #c1b8b2';
        args.IsValid = true; 
    }
}

function ValidateTxtZip(source, args)
{
    if(document.getElementById("ctl00_MainContentArea_ddCountry").options[document.getElementById("ctl00_MainContentArea_ddCountry").selectedIndex].text == "United States")
    {
        if (trim(document.getElementById("ctl00_MainContentArea_txtZip").value) != "")
        {
            document.getElementById("ctl00_MainContentArea_txtZip").style.border = '1px solid #c1b8b2';
            args.IsValid = true; 
        }
        else
        {
            document.getElementById("ctl00_MainContentArea_txtZip").style.border = '1px solid Red';
            args.IsValid = false;
        }
    }
    else
    {
        document.getElementById("ctl00_MainContentArea_txtZip").style.border = '1px solid #c1b8b2';
        args.IsValid = true; 
    }
}

function ValidatePrimaryOther(source, args)
{
    if (trim(document.getElementById("ctl00_MainContentArea_ddPrimary").value) == "-1")
    {
        document.getElementById("ctl00_MainContentArea_ddPrimary").style.background = 'Red';
        args.IsValid = false;
    }
    else
    {
        document.getElementById("ctl00_MainContentArea_ddPrimary").style.background= '#FFFFFF';
        args.IsValid = true; 
    }
}

function ValidateTxtPrimaryOther(source, args)
{    
    if (trim(document.getElementById("ctl00_MainContentArea_ddPrimary").value) == "0")
    {
        if(trim(document.getElementById("ctl00_MainContentArea_txtPrimaryOther").value) != "")
        {
            document.getElementById("ctl00_MainContentArea_txtPrimaryOther").style.border = '1px solid #c1b8b2';
            args.IsValid = true; 
        }
        else
        {
            document.getElementById("ctl00_MainContentArea_txtPrimaryOther").style.border = '1px solid Red';
            args.IsValid = false;
        }
    }
}

function ValidateTxtCountryOther(source, args)
{
    if (trim(document.getElementById("ctl00_MainContentArea_ddCountry").value) == "000")
    {
        if (trim(document.getElementById("ctl00_MainContentArea_txtCountryOther").value) == "")
        {
            document.getElementById("ctl00_MainContentArea_txtCountryOther").style.border = '1px solid Red';
            args.IsValid = false;
        }
        else
        {
            document.getElementById("ctl00_MainContentArea_txtCountryOther").style.border = '1px solid #c1b8b2';
            args.IsValid = true;  
        }
    }
    else
    {
        args.IsValid = true; 
    }
}


function trim(str) 
{
	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

// Text Mask: Only allows letters, space, apostrophe, hyphen, period.
// ASCII Values:
//  65-90 = A-Z
//  97-122 = a-z
//  32 = space
//  39 = apostrophe
//  45 = hyphen
//  46 = period
//  8 = Backspace
//  0 = Null
//  9 = Tab
//  127 = Delete
$(document).ready(function() {
    $(".mask-text").each(function() {
        $(this).keypress(function(e) {
        if (e.which == 0 || e.which == 8 || e.which == 9 || e.which == 127 || e.which == 32 || e.which == 39 || e.which == 45 || 
            e.which == 46 || (e.which > 64 && e.which < 91) || (e.which > 96 && e.which < 123)) {
                return true;
            }
            else {
                return false;
            }
        });
    });
});


// Number-Mask: Allows only numbers to be entered into a text field.
// ASCII Values:
//  8 = Backspace
//  0 = Null
//  9 = Tab
//  127 = Delete
//  48-57 = 0-9
$(document).ready(function() {
    $(".mask-numbers").each(function() {
        $(this).keypress(function(e) {
            if (e.which == 0 || e.which == 8 || e.which == 9 || e.which == 127 || (e.which > 47 && e.which < 58)) {
                return true;
            }
            else {
                return false;
            }
        });
    });
});


// Phone-Mask: Allows only numbers, "(", ")", and "-" to be entered into a text field.
// ASCII Values:
//  8 = Backspace
//  0 = Null
//  9 = Tab
//  127 = Delete
//  40 = (
//  41 = ) 
//  45 = -
//  48-57 = 0-9
$(document).ready(function() {
    $(".mask-phone").each(function() {
        $(this).keypress(function(e) {
            if (e.which == 0 || e.which == 8 || e.which == 9 || e.which == 127 || (e.which > 47 && e.which < 58) || e.which == 40|| e.which == 41 || e.which == 45) {
                return true;
            }
            else {
                return false;
            }
        });
    });
});

// Zip-Mask: Allows only numbers and hyphens to be entered into a text field.
// ASCII Values:
//  8 = Backspace
//  0 = Null
//  9 = Tab
//  127 = Delete
//  48-57 = 0-9
//  45 = "-"
$(document).ready(function() {
    $(".mask-zip").each(function() {
        $(this).keypress(function(e) {
            if (e.which == 0 || e.which == 8 || e.which == 9 || e.which == 127 || e.which == 45 || (e.which > 47 && e.which < 58)) {
                return true;
            }
            else {
                return false;
            }
        });
    });
});

// Password-Mask: Does not allow "<" or ">" or "/" or "\" to be entered in the password field.
// ASCII Values:
//  8 = Backspace
//  0 = Null
//  9 = Tab
//  127 = Delete
//  48-57 = 0-9
//  45 = "-"
$(document).ready(function() 
{
    $(".mask-password").each(function() 
    {
        $(this).keypress(function(e) 
        {
            if ((e.which != 47) && (e.which != 60) && (e.which != 61) && (e.which != 62) && (e.which != 92))
            {
                return true;
            }
            else 
            {
                return false;
            }
        });
    });
});


// Email-Mask: Does not allow "<" or ">" or "/" or "\" to be entered in the password field.
// ASCII Values:
//  8 = Backspace
//  0 = Null
//  9 = Tab
//  127 = Delete
//  48-57 = 0-9
//  45 = "-"
$(document).ready(function() 
{
    $(".mask-email").each(function() 
    {
        $(this).keypress(function(e) 
        {
            if ((e.which != 47) && (e.which != 60) && (e.which != 61) && (e.which != 62) && (e.which != 92))
            {
                return true;
            }
            else 
            {
                return false;
            }
        });
    });
});


// Script-Mask: General use mask for text fields to not allow "<" or ">" or "/" or "\" to be entered in the password field.
// ASCII Values:
//  8 = Backspace
//  0 = Null
//  9 = Tab
//  127 = Delete
//  48-57 = 0-9
//  45 = "-"
$(document).ready(function() 
{
    $(".mask-script").each(function() 
    {
        $(this).keypress(function(e) 
        {
            if ((e.which != 47) && (e.which != 60) && (e.which != 61) && (e.which != 62) && (e.which != 92))
            {
                return true;
            }
            else 
            {
                return false;
            }
        });
    });
});

// Numeric-Mask: General use mask for numbers only.
// ASCII Values:
//  48-57 = 0-9
//  8 = Backspace
//  0 = Null
//  9 = Tab
//  127 = Delete
$(document).ready(function() 
{
    $(".mask-numeric").each(function() 
    {
        $(this).keypress(function(e) 
        {
            if (((e.which >= 48) && (e.which <= 57)) || (e.which == 8) || (e.which == 0) || (e.which == 9) ||(e.which == 127))
            {
                return true;
            }
            else 
            {
                return false;
            }
        });
    });
});