﻿// JScript File
var cntryDialCode = 1; // USA


/*
 * onkeyup event
 * for emails
 *
 *************************************/
function EmailHandler(textbox)
{
	var input = trim(textbox.value);
	var radio = null;
	var optInOrLabel = document.getElementById("ctl00_ContentPlaceHolder1_OptInForm1_div_OptInOutLabel"); //-- the In/Out label above the radio buttons

	if(textbox.id.lastIndexOf("_txt_Email")> -1)
        radio = radio = document.getElementsByName("ctl00$ContentPlaceHolder1$OptInForm1$_rdo_Email");
	
	if(input.length == 0)
	{
	    for(var x = 0;x<radio.length; x++)
	    {
	        if(radio[x].checked)
	            radio[x].checked = false;
	    }
	}	
}
/*
 * onkeyup event for phone 
 * number text boxes non opt
***********************************/
function PhoneNumberMask(textbox)
{
	var input = trim(textbox.value);
	var radio = null;
	
	//-- replace non-numerics
	var digitsOnly = input.replace(/\D/g, "");
	    textbox.value = digitsOnly;		

	FormatPhone(textbox);
}

/*
 * onkeyup event for phone 
 * number text boxes
***********************************/
function PhoneNumberMask2(textbox)
{
	var input = trim(textbox.value);
	var radio = null;
	var optInOrLabel = document.getElementById("ctl00_ContentPlaceHolder1_OptInForm1_div_OptInOutLabel"); //-- the In/Out label above the radio buttons
	
	//-- replace non-numerics
	var digitsOnly = input.replace(/\D/g, "");
	    textbox.value = digitsOnly;
		
	//-- series of if statements to get the appropriate div to show/hide
    if(textbox.id.lastIndexOf("_txt_MobileNmbr") > -1)
        radio = document.getElementsByName("ctl00$ContentPlaceHolder1$OptInForm1$_rdo_Mobile");
	if(textbox.id.lastIndexOf("_txt_HomeNmbr") > -1)
		radio = document.getElementsByName("ctl00$ContentPlaceHolder1$OptInForm1$_rdo_Voice");
	if(textbox.id.lastIndexOf("_txt_Email")> -1)
		radio = document.getElementsByName("ctl00$ContentPlaceHolder1$OptInForm1$_rdo_Email");

	//-- Show/Hide the radio buttons and alter style of label
	if(input.length == 0)
	{
	    for(var x = 0;x<radio.length; x++)
	    {
	        if(radio[x].checked)
	            radio[x].checked = false;
	    }
	}

	FormatPhone(textbox);

}


function ChangeSelectedCountry(){
	var countrySelector = document.getElementById("ctl00_ContentPlaceHolder1_OptInForm1__drp_Country");

	if(countrySelector != null)
	{
		var IDandDialingCode = countrySelector.options[countrySelector.selectedIndex].value.split("|");
		
		cntryDialCode = IDandDialingCode[1];
	}
}


