/*  ------------------------------------------------------------------------
NiFTy FORM Javascript
------------------------------------------------------------------------  */

// VALIDATE EMAIL
function echeck(str) 
{ 
	var at="@"
		var dot="."
        var semi=";"
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
        if (str.indexOf(semi)!=-1)
        {
            return false;
        }
		if (str.indexOf(at)==-1)
			return false

			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
				return false

				if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
					return false

					if (str.indexOf(at,(lat+1))!=-1)
						return false

						if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
							return false

							if (str.indexOf(dot,(lat+2))==-1)
								return false

								if (str.indexOf(" ")!=-1)
									return false

									return true					
}

function pcheck(str) 
{ 
    var phoneRe = "0123456789()-";
    for(var i = 0; i < str.length;i++)
    {
        if(phoneRe.indexOf(str.charAt(i))==-1)
        {
            return false;
        }
    }
    return true;
}


function trim(stringToTrim) 
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function emailCheck2 (emailStr) {
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */

	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */

	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";http://javascript.internet.com/link-us.html

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */

		//alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			//alert("Ths username contains invalid characters.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			//alert("Ths domain name contains invalid characters.");
			return false;
		}
	}

	// See if "user" is valid 

	if (user.match(userPat)==null) {

		// user is not valid

		//alert("The username doesn't seem to be valid.");
		return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

		// this is an IP address

		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				//alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}

	// Domain is symbolic name.  Check if it's valid.

	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			//alert("The domain name does not seem to be valid.");
			return false;
		}
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
			//alert("The address must end in a well-known domain or two letter " + "country.");
			return false;
	}

	// Make sure there's a host name preceding the domain.

	if (len<2) {
		//alert("This address is missing a hostname!");
		return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
}


//Display screenshot instructions
function display_instructions()
{
	(document.getElementById('screenshots').style || document.getElementById('screenshots')).visibility = "visible";
	(document.getElementById('screenshots').style || document.getElementById('screenshots')).position = "static";
	document.getElementById('screenshots').style.display='block';
	document.getElementById('screenshots').scrollIntoView(true);
}

function hide_instructions()
{
	document.getElementById('screenshots').style.display='none';
}


function display_time(displayTime,postTime)
{
	if(displayTime && postTime)
	{
		document.getElementById('timeSlot').innerHTML='<b>Next Event: '+displayTime+' Central</b><br/>';	
		document.getElementById('selected_event_time').value = postTime;
	}
	else
	{
		document.getElementById('timeSlot').innerHTML=''; 
	}
} 

function show_event_submit()
{
	if(document.getElementById("repeat_reminders").checked == false)
	{
		document.getElementById("selected_event").selectedIndex = 0;
		document.getElementById("timeSlot").style.display = "";
		document.getElementById("interval_li").style.display = "";
		document.getElementById("userSubmit").style.display = "none";
		document.getElementById("selected_event_li").style.display = "";
	}
	else
	{
		document.getElementById("timeSlot").style.display = "none";
		document.getElementById("interval_li").style.display = "";
		document.getElementById("userSubmit").style.display = "";
		document.getElementById("selected_event_li").style.display = "none";		
	}
}

function gethicolor(colorstr)
{

	red = eval("0x" + colorstr.slice(1,3));
	green = eval("0x" + colorstr.slice(3,5));
	blue = eval("0x" + colorstr.slice(5,7));

	if(red > 255)red = 255;
	if(green > 255)green = 255;
	if(blue > 255)blue = 255;

	red = 255 - red;
	green = 255 - green;
	blue = 255 - blue;


	var DecVal= ((red * 65536) + (green * 256) + blue);

	var StringVal = DecVal.toString(16).toUpperCase();
	var StrLen = 6 - ("" + StringVal).length;

	for(var i = 0; i < StrLen; i++)
	{
		StringVal = '0' + StringVal;
	}

	return StringVal;
}

function pageScroll(xx,yy)
{
	window.scrollBy(xx,yy); // horizontal and vertical scroll increments
}

function captcha_error()
{
	var errors = new Array(); 
	var error_print = ''; 
	var html_out = ''; 

	frm=document.forms[0];

	errors[0] = 'The entry for the confirmation image was incorrect. Please try again.';




	// Loop through errors to build error list 
	for( var i=errors.length-1; i>=0; --i )  
	{ 
		if(errors[i]) 
		{
			error_print = error_print+'<li> &nbsp; '+errors[i]+'</li>';
		}
	} 

	// Print error list or submit form 
	if(error_print.length > 0)  
	{ 
		pageScroll(0,1200);
		document.getElementById('errors').style.display='block'; 
		document.getElementById('errors').style.border='1px solid #'+gethicolor(document.bgColor)+''; 
		document.getElementById('errors').style.color='#'+gethicolor(document.bgColor)+''; 

		document.getElementById('errors').innerHTML='<b><font color="#'+gethicolor(document.bgColor)+'">Please correct the following errors:</b><ul>'+error_print+'</font></ul>'; 
	}     
}


function confirm_friends_send() 
{ 
	var errors = new Array(); 
	var error_print = ''; 
	var html_out = ''; 
	var noEmailsTo = new Boolean(true);
	frm=document.forms[0];



	// Define requirements 
	if(document.getElementById('userName').value == '') 
	{
		errors[0] = 'Your name is a required.'; 
	}

	if(document.getElementById('userEmail').value == '')  
	{ 
		errors[1] = 'Your Email address is required.'; 
	} 
	else 
	{ 
		if(echeck(document.getElementById('userEmail').value)==false) 
			errors[2] = 'Your email address is not valid.'; 
	}

	if(document.getElementById('userToEmail1').value != '')
	{
		noEmailsTo=false;
		if(echeck(document.getElementById('userToEmail1').value)==false)
		{
			errors[3] = 'One of the email addresses you want to send to is invalid.';
		}
	}
	else if(document.getElementById('userToEmail2').value != '')
	{
		noEmailsTo=false;
		if(echeck(document.getElementById('userToEmail2').value)==false)
		{
			errors[3] = 'One of the email addresses you want to send to is invalid.';
		}
	}
	else if(document.getElementById('userToEmail3').value != '')
	{
		noEmailsTo=false;
		if(echeck(document.getElementById('userToEmail3').value)==false)
		{
			errors[3] = 'One of the email addresses you want to send to is invalid.';
		}
	}
	else if(document.getElementById('userToEmail4').value != '')
	{
		noEmailsTo=false;
		if(echeck(document.getElementById('userToEmail4').value)==false)
		{
			errors[3] = 'One of the email addresses you want to send to is invalid.';
		}
	}
	else if(document.getElementById('userToEmail5').value != '')
	{
		noEmailsTo=false;
		if(echeck(document.getElementById('userToEmail5').value)==false)
		{
			errors[3] = 'One of the email addresses you want to send to is invalid.';
		}
	}
	else if(noEmailsTo)
	{
		errors[3] = 'Please enter a valid email address to send to.';
	}





	// Loop through errors to build error list 
	for( var i=errors.length-1; i>=0; --i )  
	{ 
		if(errors[i]) 
		{
			error_print = error_print+'<li> &nbsp; '+errors[i]+'</li>';
		}
	} 

	// Print error list or submit form 
	if(error_print.length > 0)  
	{ 
		pageScroll(0,1200);
		if(document.getElementById('success')) 
			document.getElementById('success').style.display='none'; 
		document.getElementById('errors').style.display='block'; 

		document.getElementById('errors').style.border='1px solid #'+gethicolor(document.bgColor)+''; 
		document.getElementById('errors').style.color='#'+gethicolor(document.bgColor)+'';
		document.getElementById('errors').innerHTML='<b><font color="#'+gethicolor(document.bgColor)+'">Please correct the following errors:</b><ul>'+error_print+'</font></ul>'; 

	} 
	else 
	{ 
		frm.userSubmit.value="Please Wait...";
		frm.userSubmit.disabled=true;

		document.getElementById('errors').style.display='none'; 
		document.getElementById('errors').innerHTML=''; 
		document.getElementById('email2friends').submit(); 
	}           
}

function confirm_survey_v2_send()
{
	var errors = new Array();
	var error_print = '';
	var error_length = 0;
     	
 	// Define requirements
	if(trim(document.getElementById('first_name').value) == '')
	{
		errors[error_length] = 'First Name is a required field.';
		error_length++;
	}
	if(trim(document.getElementById('last_name').value) == '')
	{
		errors[error_length] = 'Last Name is a required field.';
		error_length++;
	}
		
	if(trim(document.getElementById('email').value) == '') 
	{
		errors[error_length] = 'Email Address is a required field.';
		error_length++;
	}
	else if(echeck(document.getElementById('email').value)==false)
	{
		errors[error_length] = 'Your Email Address is not valid.';
		error_length++;
	}
	
/*	if(trim(document.getElementById('city').value) == '') 
	{
		errors[error_length] = 'City is a required field.';
		error_length++;
	}
	
	if(trim(document.getElementById('state').value) == '') 
	{
		errors[error_length] = 'State is a required field.';
		error_length++;
	}
	
	if(trim(document.getElementById('watchonline_withyou').value) != '') 
	{
		if(!isInt(document.getElementById('watchonline_withyou').value))
		{
			errors[error_length] = 'Invalid value for number of people watching with you.';
			error_length++;
		}
	}
	
*/
	// Loop through errors to build error list
	for(var i=0; i<error_length; i++) 
	{
	 	if(errors[i])
	 		error_print = error_print+'<li>&bull; &nbsp; '+errors[i]+'</li>';
	}
	
	// Print error list or submit form
	if(error_print) 
	{
	 	if(document.getElementById('success'))
			document.getElementById('success').style.display='none';
		document.getElementById('errors').style.display='block';
		document.getElementById('errors').innerHTML='<b>Please fix the following errors:</b><ul>'+error_print+'</ul>';
	}
	else
	{
		document.getElementById('errors').style.display='none';
		document.getElementById('errors').innerHTML='';
	 	document.getElementById('survey_form').submit();
	}
}

function confirm_send()
{
	var errors = new Array();
	var error_print = '';

	// Define requirements
	if(document.getElementById('name').value == '')
		errors[0] = 'Full name is a required field.';

	if(document.getElementById('email').value == '') 
	{
		errors[1] = 'Email address is a required field.';
	}
	else
	{
		if(echeck(document.getElementById('email').value)==false)
			errors[2] = 'Your email address is not valid.';
	}


	// Loop through errors to build error list
	for( var i=errors.length-1; i>=0; --i ) 
	{
		if(errors[i])
			error_print = error_print+'<li>&bull; &nbsp; '+errors[i]+'</li>';
	}

	// Print error list or submit form
	if(error_print) 
	{
		if(document.getElementById('success'))
			document.getElementById('success').style.display='none';
		document.getElementById('errors').style.display='block';
		document.getElementById('errors').innerHTML='<b>Please correct the following errors:</b><ul>'+error_print+'</ul>';
	}
	else
	{
		document.getElementById('errors').style.display='none';
		document.getElementById('errors').innerHTML='';
		document.getElementById('contact_form').submit();
	}

}

function trim (str) 
{
	return str.replace(/^\s+|\s+$/g, '');
}

function confirm_survey_send()
{
	var errors = new Array();
	var error_print = '';

	// Define requirements
	if(trim(document.getElementById('name').value) == '')
		errors[12] = 'First Name is a required field.';

	if(trim(document.getElementById('last_name').value) == '')
		errors[11] = 'Last Name is a required field.';

	if(trim(document.getElementById('email').value) == '') 
	{
		errors[10] = 'Email Address is a required field.';
	}
	else
	{
		if(echeck(document.getElementById('email').value)==false)
			errors[9] = 'Your Email Address is not valid.';
	}

	if(trim(document.getElementById('mail').value) == '')
		errors[8] = 'Mailing Address is a required field.';

	if(trim(document.getElementById('city').value) == '')
		errors[7] = 'City is a required field.';

	if(trim(document.getElementById('state').options[document.getElementById('state').selectedIndex].innerHTML) == '')
		errors[6] = 'State is a required field.';

	if(trim(document.getElementById('zip').value) == '')
		errors[5] = 'Zip Code is a required field.';

	if(trim(document.getElementById('age').options[document.getElementById('age').selectedIndex].innerHTML) == '')
		errors[4] = 'Age is a required field.';

	if(trim(document.getElementById('gender').options[document.getElementById('gender').selectedIndex].innerHTML) == '')
		errors[3] = 'Gender is a required field.';

	if(trim(document.getElementById('hsize').options[document.getElementById('hsize').selectedIndex].innerHTML) == '')
		errors[2] = 'Size of Household is a required field.';

	if(trim(document.getElementById('vsize').options[document.getElementById('vsize').selectedIndex].innerHTML) == '')
		errors[1] = 'Number of Viewers is a required field.';

	if(trim(document.getElementById('favorite').options[document.getElementById('favorite').selectedIndex].innerHTML) == '')
		errors[0] = 'Promotional Team is a required field.';


	// Loop through errors to build error list
	for( var i=errors.length-1; i>=0; --i ) 
	{
		if(errors[i])
			error_print = error_print+'<li>&bull; &nbsp; '+errors[i]+'</li>';
	}

	// Print error list or submit form
	if(error_print) 
	{
		if(document.getElementById('success'))
			document.getElementById('success').style.display='none';
		document.getElementById('errors').style.display='block';
		document.getElementById('errors').innerHTML='<b>Please correct the following errors:</b><ul>'+error_print+'</ul>';
	}
	else
	{
		document.getElementById('errors').style.display='none';
		document.getElementById('errors').innerHTML='';
		document.getElementById('survey_form').submit();
	}
}

function confirm_reminder_v2_send() 
{ 
	var errors = new Array(); 
	var error_print = ''; 
	var html_out = ''; 
	var noEmailsTo = new Boolean(true);
	var error_count = 0;
	frm=document.forms[0];

	if(document.getElementById('email').value != '') 
	{
		if(emailCheck2(document.getElementById('email').value)==false)
		{
			errors[error_count] = 'Your email address is not valid.';
			error_count++;
		}
		if(document.getElementById('phone').value != '') 
		{
			if(document.getElementById('phone').value.length < 10) 
			{
				errors[error_count] = 'The phone number entered is too short.';
				error_count++;
			}
            if(document.getElementById('phone').value.length > 18) 
			{
				errors[error_count] = 'The phone number entered is too long.';
				error_count++;
			}
			if(document.getElementById('provider').value == '') 
			{
				errors[error_count] = 'A phone number was entered without selecting a provider';
				error_count++;
			}
            
            if(!pcheck(document.getElementById('phone').value))
            {
                errors[error_count] = 'Your phone number is not valid';
				error_count++;
            }
		}

	}
	else if(document.getElementById('phone').value != '') 
	{
		if(document.getElementById('phone').value.length < 10) 
		{
			errors[error_count] = 'The phone number entered is too short.';
			error_count++;
		}
        if(document.getElementById('phone').value.length > 18) 
        {
            errors[error_count] = 'The phone number entered is too long.';
            error_count++;
        }

		if(document.getElementById('provider').value == '') 
		{
			errors[error_count] = 'A phone number was entered without selecting a provider';
			error_count++;
		}
	//Fails on IE
        if(!pcheck(document.getElementById('phone').value))
        {
            errors[error_count] = 'Your phone number is not valid';
            error_count++;
        }
		if(document.getElementById('email').value != '') 
		{
			if(echeck(document.getElementById('email').value)==false)
			{
				errors[error_count] = 'Your email address is not valid.';
				error_count++;
			}
		}
	}
	else
	{
		errors[error_count] = 'You must enter an Email address or phone number for us to contact you.';
		error_count++;
	}



	if(document.getElementById('increment').value=='')
	{
		errors[error_count] = 'Please select a preset time to be alerted.';
		error_count++;
	}
	if(document.getElementById('selected_channel').value=='')
	{
		errors[error_count] = 'Please select a Channel.';
		error_count++;
	}
	


	for( var i=errors.length-1; i>=0; --i ) 
	{
		if(errors[i])
			error_print = error_print+'<li>&bull; &nbsp; '+errors[i]+'</li>';
	}

	// Print error list or submit form
	if(error_print) 
	{
		if(document.getElementById('success'))
			document.getElementById('success').style.display='none';
		document.getElementById('errors').style.display='block';
		document.getElementById('errors').innerHTML='<b>Please correct the following errors:</b><ul>'+error_print+'</ul>';
		pageScroll(0,1200);
	}
	else
	{
		frm.userSubmit.value="Please Wait";
		frm.userSubmit.disabled=true;

		document.getElementById('errors').style.display='none';
		document.getElementById('errors').innerHTML='';
		document.getElementById('reminder_form').submit();
	}

}

function confirm_reminder_send()
{
	var errors = new Array(); 
	var error_print = ''; 
	var html_out = ''; 
	var noEmailsTo = new Boolean(true);
	var error_string = new String();
	frm=document.forms[0];

	// Define requirements


	if(document.getElementById('email').value != '') 
	{
		if(echeck(document.getElementById('email').value)==false)
		{
			errors[2] = 'Your email address is not valid.';
		}
		if(document.getElementById('phone').value != '') 
		{
			/*if(document.getElementById('phone').value.indexOf('-') != -1||document.getElementById('phone').value.indexOf('(') != -1||document.getElementById('phone').value.indexOf(')') != -1) 
			{
			errors[6] = 'Please format your phone number like the example provided.';
			}*/
			if(document.getElementById('phone').value.length < 10) 
			{
				errors[6] = 'The phone number entered is too short.';
			}

			if(document.getElementById('provider').value == '') 
			{
				errors[3] = 'A phone number was entered without selecting a provider';
			}
		}

	}
	else if(document.getElementById('phone').value != '') 
	{
		/*if(document.getElementById('phone').value.indexOf('-') != -1||document.getElementById('phone').value.indexOf('(') != -1||document.getElementById('phone').value.indexOf(')') != -1) 
		{
		errors[6] = 'Please format your phone number like the example provided.';
		}*/
		if(document.getElementById('phone').value.length < 10) 
		{
			errors[6] = 'The phone number entered is too short.';
		}

		if(document.getElementById('provider').value == '') 
		{
			errors[3] = 'A phone number was entered without selecting a provider';
		}
		if(document.getElementById('email').value != '') 
		{
			if(echeck(document.getElementById('email').value)==false)
			{
				errors[2] = 'Your email address is not valid.';
			}
		}
	}
	else
	{
		errors[1] = 'You must enter an Email address or phone number for us to contact you.';
	}

	if(document.getElementById('increment').value=='')
	{
		errors[4] = 'Please select a preset time to be alerted.';
	}



	/*
	if(document.reminder_form.c_time_layout[0].checked)
	{
	if(document.getElementById('increment').value=='')
	{
	errors[4] = 'Please select a preset time to be alerted at.';
	}
	}
	if(document.getElementById('recaptcha_response_field').value == '')
	{
	errors[5] = 'Please enter the text for the confirmation image.';
	}*/


	// Loop through errors to build error list
	for( var i=errors.length-1; i>=0; --i ) 
	{
		if(errors[i])
			error_print = error_print+'<li>&bull; &nbsp; '+errors[i]+'</li>';
	}

	// Print error list or submit form
	if(error_print) 
	{
		if(document.getElementById('success'))
			document.getElementById('success').style.display='none';
		document.getElementById('errors').style.display='block';
		document.getElementById('errors').innerHTML='<b>Please correct the following errors:</b><ul>'+error_print+'</ul>';
		pageScroll(0,1200);
	}
	else
	{
		frm.userSubmit.value="Please Wait";
		frm.userSubmit.disabled=true;

		document.getElementById('errors').style.display='none';
		document.getElementById('errors').innerHTML='';
		document.getElementById('reminder_form').submit();
	}
}

function confirm_unregister_send()
{
	var errors = new Array(); 
	var error_print = ''; 
	var html_out = ''; 
	var noEmailsTo = new Boolean(true);
	var error_string = new String();
	var error_count = 0;
	frm=document.forms[0];

	// Define requirements


	if(document.getElementById('email').value != '') 
	{
		if(emailCheck2(document.getElementById('email').value)==false)
		{
			errors[error_count] = 'Your email address is not valid.';
			error_count++;
		}
		if(document.getElementById('phone').value != '') 
		{
			if(document.getElementById('phone').value.length < 10) 
			{
				errors[error_count] = 'The phone number entered is too short.';
				error_count++;
			}

			if(document.getElementById('provider').value == '') 
			{
				errors[error_count] = 'A phone number was entered without selecting a provider';
				error_count++;
			}
		}

	}
	else if(document.getElementById('phone').value != '') 
	{
		if(document.getElementById('phone').value.length < 10) 
		{
			errors[error_count] = 'The phone number entered is too short.';
			error_count++;
		}

		if(document.getElementById('provider').value == '') 
		{
			errors[error_count] = 'A phone number was entered without selecting a provider';
			error_count++;
		}
		if(document.getElementById('email').value != '') 
		{
			if(echeck(document.getElementById('email').value)==false)
			{
				errors[error_count] = 'Your email address is not valid.';
				error_count++;
			}
		}
	}
	else
	{
		errors[error_count] = 'You must enter an Email address or phone number for us to contact you.';
		error_count++;
	}	




	// Loop through errors to build error list
	for( var i=errors.length-1; i>=0; --i ) 
	{
		if(errors[i])
			error_print = error_print+'<li>&bull; &nbsp; '+errors[i]+'</li>';
	}

	// Print error list or submit form
	if(error_print) 
	{
		if(document.getElementById('success'))
			document.getElementById('success').style.display='none';
		document.getElementById('errors').style.display='block';
		document.getElementById('errors').innerHTML='<b>Please correct the following errors:</b><ul>'+error_print+'</ul>';
		pageScroll(0,1200);
	}
	else
	{
		frm.userSubmit.value="Please Wait";
		frm.userSubmit.disabled=true;

		document.getElementById('errors').style.display='none';
		document.getElementById('errors').innerHTML='';
		document.getElementById('reminder_form').submit();
	}
}

function confirm_selected_unregister_submit()
{
	frm=document.forms[0];
	frm.userSubmit.value="Please Wait";
	frm.userSubmit.disabled=true;
	document.getElementById('reminder_form').submit();
}

function form_custom_time_enable()
{

	document.getElementById('preset_time_div').style.display="none";
	document.getElementById('custom_time_div').style.display="block";
	//document.getElementById('c_time_layout').options[1].checked="true";
	document.reminder_form.c_time_layout[1].checked="true";

}

function form_preset_time_enable()
{

	document.getElementById('custom_time_div').style.display="none";
	document.getElementById('preset_time_div').style.display="block";
	document.reminder_form.c_time_layout[0].checked="true";
}

function form_incomplete_error()
{
	document.getElementById('errors').style.display='block';
	document.getElementById('errors').innerHTML='<b>Please fill out all required fields.</b>';
}

function form_captcha_error()
{
	document.getElementById('errors').style.display='block';
	document.getElementById('errors').innerHTML='<b>The text you entered did not match the confirmation image, please try again.</b>';
}

function form_invalidphone_error()
{
	document.getElementById('errors').style.display='block';
	document.getElementById('errors').innerHTML='<b>The phone number you entered is invalid.</b>';
}

function ReminderLinkedSelect(primary) 
{
	/*Array listing all upcoming events for brand*/     
	var list = new Array();
	var i = 1;
	var nextEvent = "event-" + i;
	var curr = document.getElementById(nextEvent);

	while (curr)
	{
		list[i-1] = curr.attributes.value.nodeValue;
		i++;
		nextEvent = "event-" + i;
		curr = document.getElementById(nextEvent);
	}

	/* When the channel selection changes... */	
	primary.onchange = function() 
	{
		/*If selection is not the default value*/
		if(primary.selectedIndex != 0)
		{
			/* The code for the selected channel */       
			var primaryCode = primary.options[primary.selectedIndex].value;
			var found = false;

			for (var i = 0; i < list.length; i++) 
			{
				/* If the option starts with the selected channel code */         
				if (list[i].indexOf(primaryCode) == 0)
				{
					var listSplit = list[i].split("|");
					display_time(listSplit[2],listSplit[1]);
					found = true;
					break;
				}
			} 
			if(!found)
			{
				display_time(null,null);
			}

			document.getElementById("interval_li").style.display = "";							//Display the Time Interval Dropdown
			document.getElementById("repeat_reminders_li").style.display = "";					//Display the Repeat Reminder Radio Buttons			
			event_reminder_mode_change();											//Show Correct Selection Boxes based on Mode
			document.getElementById("userSubmit").style.display = "";							//Display Submit Button
		}
		else
		{
			//Hide all Boxes
			document.getElementById("no_events_li").style.display = "none";
			document.getElementById("timeSlot").style.display = "none";
			document.getElementById("interval_li").style.display = "none";			
			document.getElementById("repeat_reminders_li").style.display = "none";
			document.getElementById("userSubmit").style.display = "none";	
			display_time(null,null);
		}        
	}
	
	/* Update the channel select now */     
	primary.onchange();
}

function event_reminder_mode_change()
{
	var radioObj = document.forms["reminder_form"].elements['repeat_reminders'];			//Get Repeat Reminders Radio Object
	if(radioObj[1].checked == false)											//If Not Repeat Reminders
	{
		if(document.getElementById('timeSlot').innerHTML != '')
		{
			document.getElementById("timeSlot").style.display = "";					//Show the Next Event Time		
		}
		else
		{
			var radioObj = document.forms["reminder_form"].elements['repeat_reminders'];	//Get Repeat Reminders Radio Object
			document.getElementById("no_events_li").style.display = "";				//Show the No Events Message
			document.getElementById("timeSlot").style.display = "none";				//Hide the Next Event Time
			document.getElementById("single_reminder_wrapper").style.display = "none";		//Hide the Single Reminder button
			radioObj[1].checked = true;										//Set Repeat Reminders Checked				
		}
	}
	else
	{
		if(document.getElementById('timeSlot').innerHTML != '')
		{
			document.getElementById("single_reminder_wrapper").style.display = "";		//Show Single Reminder Button
			document.getElementById("no_events_li").style.display = "none";				//Hide No Events Message
			document.getElementById("timeSlot").style.display = "";					//Show the Next Event Time
		}
		else
		{
			document.getElementById("single_reminder_wrapper").style.display = "none";		//Hide Single Reminder Button
			document.getElementById("no_events_li").style.display = "";				//Show No Events Message
			document.getElementById("timeSlot").style.display = "none";				//Hide the Next Event Time
		}
	}
	update_increment_select();
}

function update_increment_select()
{
	//var incrementObj = document.getElementById("increment");
    
    var incrementObj = document.reminder_form.increment;
    var incrementObjBase = document.reminder_form.increment_base;
	var dateArr = document.getElementById("selected_event_time").value.split(" ");
    var timeDiff = 0;
	var selected_event = false;
    if(document.getElementById("selected_event_time").value.length>0)
    {
        var timeArr = dateArr[3].split(":");
        var selectedEventTime = new Date();
        selectedEventTime.setTime(Date.parse(dateArr[1]+" "+dateArr[2].substring(0,(dateArr[2].length-2)) + ", " +selectedEventTime.getFullYear()));
        selectedEventTime.setMinutes(timeArr[1]);
        if(dateArr[4] == "PM" && timeArr[0] != 12)
        {
            selectedEventTime.setHours((parseInt(timeArr[0])+12) + "");
        }
        else
        {
            selectedEventTime.setHours(timeArr[0]);
        }
        var now = new Date();
        var serverTime = document.getElementById("server_time").value;
        serverTime = ("" + serverTime);
        serverTime.replace(/,/,"");
        serverTime.replace(/ /,", ");
        now.setTime(Date.parse(serverTime));
        timeDiff = (((selectedEventTime - now))/(1000*60));
		selected_event = true;
    }
	
	
	var radioObj = document.forms["reminder_form"].elements['repeat_reminders'];
    var length = incrementObj.options.length;
    for (var i = 0; i < length; i++)
    {
        incrementObj.remove(0);
    }
    var length2 = incrementObjBase.options.length;
    //int placementCounter=0;
	for (var i = 0; i < length2; i++)
	{
    	
        if(timeDiff > (parseInt(incrementObjBase.options[i].value)-1) || !selected_event)
		{
            var elOptNew = document.createElement('option');
            elOptNew.text = incrementObjBase.options[i].text;
            elOptNew.value = incrementObjBase.options[i].value;

            try 
            {
                incrementObj.add(elOptNew,null);
            }
            catch(ex) 
            {
                incrementObj.add(elOptNew);
            }
		}
	}
}

function strikeToggle(hash)
{
    //var tempText = document.forms["reminder_form"].elements[hash];
    
    if(document.getElementById(hash+ "_t_1").style.textDecoration == "")
    {
    
        var t_string = hash;
        var str1 = hash + "_t_1";
        var str2 = hash + "_t_2";
        var str3 = hash + "_t_3";
        var str4 = hash + "_t_4";
        
        var tempText = document.getElementById(str1);
        tempText.style.textDecoration ="line-through";
        
        tempText = document.getElementById(str2);
        tempText.style.textDecoration ="line-through";
        
        tempText = document.getElementById(str3);
        tempText.style.textDecoration ="line-through";
        
        tempText = document.getElementById(str4);
        tempText.style.textDecoration ="line-through";
        
    }
    else
    {
        var t_string = hash;
        var str1 = hash + "_t_1";
        var str2 = hash + "_t_2";
        var str3 = hash + "_t_3";
        var str4 = hash + "_t_4";
        
        var tempText = document.getElementById(str1);
        tempText.style.textDecoration ="";
        
        tempText = document.getElementById(str2);
        tempText.style.textDecoration ="";
        
        tempText = document.getElementById(str3);
        tempText.style.textDecoration ="";
        
        tempText = document.getElementById(str4);
        tempText.style.textDecoration ="";
    }
}

function ReminderIntervalLink(primary,secondary) 
{
	/*Array for ssecondaryring option text/value pairs*/     
	var temp_options = new Array();

	for (var i=0; i < secondary.options.length; i++) 
	{
		/* Save text and value of original options */       
		temp_options[i] = new Array(secondary.options[i].text,secondary.options[i].value);     
	}

	/* When the brand selection changes... */
	primary.onchange = function() 
	{
		/*If selection is not the default value*/

		/* The code for the selected brand */       
		var primaryCode = primary.options[primary.selectedIndex].value;

		/* Remove current options */       
		secondary.options.length = 0;

		/* Run throught all options... */       

		for (i = 0; i < temp_options.length; i++) 
		{
			/* If the option starts with the selected brand code */         
			if (temp_options[i][1].indexOf(primaryCode) == 0)
			{
				/* Add the option secondary the channel select */
				secondary.options[secondary.options.length] = new Option(temp_options[i][0],temp_options[i][1]);
			}
		} 

		/* Select the first of the new options */       
		if(secondary.options[0])
		{
			secondary.options[0].selected = true;
		}
		UpdateTime(primary,secondary);
	}


	/* Update the channel select now */     
	primary.onchange();
}

function UpdateTime(hours,minutes)
{
	var Hours = hours.options[hours.selectedIndex].value;
	var Minutes = minutes.options[minutes.selectedIndex].value;
	Minutes = Minutes.split("-");
	Minutes = Minutes[1];
	Hours = Hours*60;
	document.getElementById("increment").value = (parseInt(Hours)+parseInt(Minutes));
}

function reset_submit_button()
{
	frm=document.forms[0];
	frm.userSubmit.value="Submit";
	frm.userSubmit.disabled=false;
}
