var sec = 00;
var min = 5;

function countDown() {
  var theTime=document.getElementById("theTime");
  sec--;
  if (sec == -01) {
    sec = 59;
    min = min - 1;
  } else {
   min = min;
  }
if (sec<=9) { sec = "0" + sec; }
  time = (min<=9 ? "0" + min : min) + ":" + sec + "";
if (document.getElementById) { theTime.innerHTML = time; }
  SD=window.setTimeout("countDown();", 1000);
if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); showTimeoutDlg(); sec=00; min=5; countDown();}
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  countDown();
});

function showTimeoutDlg() {
	document.getElementById('darkBackgroundLayer').style.display='';
	document.getElementById('timeoutdlg').style.display='';
	return false;
}

function reloadpage() {
    window.location.reload();
}
function validateFormM(theForm, submitted)
	{
		var firstName = document.getElementById("firstname");
		var lastName = document.getElementById("lastname");
		var address = document.getElementById("address");
		var email = document.getElementById("email");
		var phonearea = document.getElementById("phone");
		var city = document.getElementById("city");
		var state = document.getElementById("state");
		var zip = document.getElementById("zip");
		var formError = false;
		firstName.onblur = function(){ return validateForm(theForm, 0);}
		lastName.onblur = function(){ return validateForm(theForm, 0);}
		address.onblur = function(){ return validateForm(theForm, 0);}
		email.onblur = function(){ return validateForm(theForm, 0);}
		city.onblur = function(){ return validateForm(theForm, 0);}
		state.onblur = function(){ return validateForm(theForm, 0);}
		zip.onblur = function(){ return validateForm(theForm, 0);}
		if (firstName.value == '')
		{
			formError = true;
			firstName.style.backgroundColor = '#ff0000';
			firstName.style.color = '#ffffff';
		}
		else
		{
			firstName.style.backgroundColor = '#ffffff';
			firstName.style.color = '#666666';
		}
		if (lastName.value == '')
		{
			formError = true;
			lastName.style.backgroundColor = '#ff0000';
			lastName.style.color = '#ffffff';
		}
		else
		{
			lastName.style.backgroundColor = '#ffffff';
			lastName.style.color = '#666666';
		}
		if (address.value == '')
		{
			formError = true;
			address.style.backgroundColor = '#ff0000';
			address.style.color = '#ffffff';
		}
		else
		{
			address.style.backgroundColor = '#ffffff';
			address.style.color = '#666666';
		}
		if (email.value == '')
		{
			formError = true;
			email.style.backgroundColor = '#ff0000';
			email.style.color = '#ffffff';
		}
		else
		{
			email.style.backgroundColor = '#ffffff';
			email.style.color = '#666666';
		}
		if (phonearea.value.length < 6)
		{
			formError = true;
			phonearea.style.backgroundColor = '#ff0000';
			phonearea.style.color = '#ffffff';
		}
		else
		{
			phonearea.style.backgroundColor = '#ffffff';
			phonearea.style.color = '#666666';
		}

		if (city.value == '')
		{
			formError = true;
			city.style.backgroundColor = '#ff0000';
			city.style.color = '#ffffff';
		}
		else
		{
			city.style.backgroundColor = '#ffffff';
			city.style.color = '#666666';
		}
		if (zip.value == '')
		{
			formError = true;
			zip.style.backgroundColor = '#ff0000';
			zip.style.color = '#ffffff';
		}
		else
		{
			zip.style.backgroundColor = '#ffffff';
			zip.style.color = '#666666';
		}
		if (state.value.length <= 1)
		{
			state.style.backgroundColor = '#ffffff';
			state.style.color = '#666666';
		}
		else
		{
			state.style.backgroundColor = '#ffffff';
			state.style.color = '#666666';
		}
		if (formError && (submitted == 1))
		{
			alert('Please fill out all required fields.');
			return false;
		}
		else
		{
			return true;
		}
	}
function verifyNSend() {
	if (validateFormM(document.theMainForm,1)) {
    	//DisableVSAChat();
		document.theMainForm.submit();
    }
}
function cvv()
	{
		window.open('cvv.html', 'cvv', 'scrollbars=yes,titlebar=no,menubar=no,height=450,width=600');
	}