var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;
 
var headline_rotate;
var headline2_rotate;
 var headline2_count;
var headline2_interval;
var old_headline2 = 0;
var current_headline2 = 0;
 
$(document).ready(function(){
	
	 headline_count = $("div.headline").size();
   $("div.headline:eq("+current_headline+")").css('top','5px');
 
   headline_interval = setInterval(headline_rotate,5000); //time in milliseconds
	
	
   headline_count2= $("div.headline2").size();
//   $("div.headline2:eq("+current_headline+")").css('left','0px');
   $("div.headline2:eq("+current_headline2+")").fadeIn("slow");
//   headline2_interval = setInterval(headline2_rotate,5000); //time in milliseconds
   
 });
 
 function headline_rotate() {
	 
	 current_headline = (old_headline + 1) % headline_count; 
   $("div.headline:eq(" + old_headline + ")").animate({top: -205},"slow", function() {
     $(this).css('top','210px');
   });
   $("div.headline:eq(" + current_headline + ")").show().animate({top: 5},"slow");  
   old_headline = current_headline;
	 
	 
   current_headline2 = (old_headline2 + 1) % headline_count2; 
/*   $("div.headline2:eq(" + old_headline + ")").animate({left: -560},"slow", function() {
/*     $(this).css('left','-560px');
		$(this).css('visible: none; left:0');
   });*/
   
     $("div.headline2:eq(" + old_headline2 + ")").fadeOut("slow", function() {
   
		   $("div.headline2:eq(" + current_headline2 + ")").fadeIn("slow");
	 });
//   .show().animate({left: 0},"slow");  
   
   //$("div.headline2:eq(" + current_headline + ")").show().animate({left: 0},"slow");  
   
   old_headline = current_headline
   old_headline2 = current_headline2;
   
 }


function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateFreeEmail(theForm.user_email);
  
  if (reason != "") {
    alert("There is a problem with your email address:\n\n" + reason );
    return false;
  }
  
  t = "";
  t = validateEmpty(theForm.theanswer);
  if (t !="")
  {
    alert("Please enter the skill testing question");
    return false;
  }
  return true;
}

function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#c2efcb'; 
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateFName(fld) {
    var error = "";
 
    if (fld.value == "" || fld.value == "Your First Name") {
        fld.style.background = '#c2efcb'; 
        error = "Please enter your first name.\n\n";
	} else if (fld.value.length < 2) {
        fld.style.background = '#c2efcb';
        error = "Please enter your first name.\n\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateLName(fld) {
    var error = "";
 
    if (fld.value == "" || fld.value == "Your Last Name") {
        fld.style.background = '#c2efcb'; 
        error = "Please enter your last name.\n\n";
	} else if (fld.value.length < 2) {
        fld.style.background = '#c2efcb';
        error = "Please enter your last name.\n\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateFreeEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	var telusEmail = /@telus\.com/i;
	var hotmailEmail = /@hotmail\.com/i;
	var liveEmail = /@live\.com/i;
	var gmailEmail = /@gmail\.com/i;
	var yahooEmail = /@yahoo\.com/i;
	var yahoocaEmail = /@yahoo\.ca/i;
	var sympaticoEmail = /@sympatico\.ca/i;
	var rogersEmail = /@rogers\.com/i;
   
    if (fld.value == "" || fld.value == "Your Email") {
        fld.style.background = '#ffc9bb';
        error = "Please enter your email address.\n\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#ffc9bb';
        error = "The email address you entered is not valid.\n\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#ffc9bb';
        error = "Your email address contains illegal characters.\n\n";
	} else if (fld.value.match(telusEmail)) {
		fld.style.background = '#ffc9bb';
        error = "You have entered a Telus email address:\n" + fld.value + "\n\nTelus' Corporate Policy disallows the use of your work email address\nfor signing up. Sorry. Please use a different email address.\n\n";
	} else if (fld.value.match(hotmailEmail)) {
		fld.style.background = '#ffc9bb';
        error = "You have entered a Hotmail email address:\n" + fld.value + "\n\nTo protect our intellectual  property we require that you use your Business / Office / Work email address for signing up. \n\nSorry. Please use your Business / Office / Work  email address.\n\n";
	} else if (fld.value.match(liveEmail)) {
		fld.style.background = '#ffc9bb';
        error = "You have entered a Windows Live email address:\n" + fld.value + "\n\nTo protect our intellectual  property we require that you use your Business / Office / Work email address for signing up. \n\nSorry. Please use your Business / Office / Work  email address.\n\n";
	} else if (fld.value.match(gmailEmail)) {
		fld.style.background = '#ffc9bb';
        error = "You have entered a gMail email address:\n" + fld.value + "\n\nTo protect our intellectual  property we require that you use your Business / Office / Work email address for signing up. \n\nSorry. Please use your Business / Office / Work  email address.\n\n";
	} else if (fld.value.match(yahooEmail)) {
		fld.style.background = '#ffc9bb';
        error = "You have entered a Yahoo email address:\n" + fld.value + "\n\nTo protect our intellectual  property we require that you use your Business / Office / Work email address for signing up. \n\nSorry. Please use your Business / Office / Work email address.\n\n";
	} else if (fld.value.match(yahoocaEmail)) {
		fld.style.background = '#ffc9bb';
        error = "You have entered a Yahoo email address:\n" + fld.value + "\n\nTo protect our intellectual  property we require that you use your Business / Office / Work email address for signing up. \n\nSorry. Please use your Business / Office / Work email address.\n\n";
	} else if (fld.value.match(sympaticoEmail)) {
		fld.style.background = '#ffc9bb';
        error = "You have entered a Sympatico email address:\n" + fld.value + "\n\nTo protect our intellectual  property we require that you use your Business / Office / Work email address for signing up. \n\nSorry. Please use your Business / Office / Work email address.\n\n";
	} else if (fld.value.match(rogersEmail)) {
		fld.style.background = '#ffc9bb';
        error = "You have entered a Rogers email address:\n" + fld.value + "\n\nTo protect our intellectual  property we require that you use your Business / Office / Work email address for signing up. \n\nSorry. Please use your Business / Office / Work email address.\n\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}