// Read in querystring and populate variable
var qsParm = new Array();
function qs() {
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
   var pos = parms[i].indexOf('=');
   if (pos > 0) {
      var key = parms[i].substring(0,pos);
      var val = parms[i].substring(pos+1);
      qsParm[key] = val;
      }
   }
}
function regDate()
{
		var newdate=new Date();
		var year=newdate.getFullYear();
		var month=newdate.getMonth() + 1;
		if (month<10)
		{
			month="0" + month;
		}
		var day=newdate.getDate();
		if (day<10)
		{
			day="0" + day;
		}
 var Hours;
var Mins;
var Time;
Hours = newdate.getHours();
if (Hours >= 12) {
Time = " P.M.";
}
else {
Time = " A.M.";
}

if (Hours > 12) {
Hours -= 12;
}

if (Hours == 0) {
Hours = 12;
}

Mins = newdate.getMinutes();

if (Mins < 10) {
Mins = "0" + Mins;
}
var returndate=year + "/" + month + "/" + day + " " + Hours + ":" + Mins + " " + Time;
		document.questionaire.i_date_submitted.value=returndate;
//		alert (document.questionaire.i_date_submitted.value);
}
function IsEmail(emailStr) {
  if (  emailStr.match( new RegExp( '^(\\s*)(("[^"]*")|\\w+([*&+~!-\\.]\\w+)*)@\\w+([-\\.]\\w+)*\\.\\w{1,3}(\\s*)$' ) ) == null )
	return false;
  return true;
}

function IsNumber(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
      }
   }
   return IsNumber;
}

function IsAlphaNumber(sText)
{
   var ValidChars = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var IsAlphaNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsAlphaNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
         IsAlphaNumber = false;
      }
   }
   return IsAlphaNumber;
}


function ValidateAndSubmit() {
 var s_promo_code = document.questionaire.s_promo_code.options[document.questionaire.s_promo_code.selectedIndex].value;
 var i_pnmgiven = document.questionaire.i_pnmgiven.value;
 var i_pnmfamily = document.questionaire.i_pnmfamily.value;
 var i_pjobtitle = document.questionaire.i_pjobtitle.value;
 var i_orgnm = document.questionaire.i_orgnm.value;
 var i_bsaddr1 = document.questionaire.i_bsaddr1.value;
 var i_bscity = document.questionaire.i_bscity.value;
 var i_bspostcde = document.questionaire.i_bspostcde.value;
 var i_bstel1 = document.questionaire.i_bstel1.value;
 var s_bsst = document.questionaire.s_bsst.options[document.questionaire.s_bsst.selectedIndex].value;
 var i_emailgeneric = document.questionaire.i_emailgeneric.value;
 var s_INTDAY_EX_COMPSIZE = document.questionaire.s_INTDAY_EX_COMPSIZE.options[document.questionaire.s_INTDAY_EX_COMPSIZE.selectedIndex].value;
 var i_contact_email = document.questionaire.i_contact_email.value;
 var i_contact_phone = document.questionaire.i_contact_phone.value;
 var s_best_time_call = document.questionaire.s_best_time_call.options[document.questionaire.s_best_time_call.selectedIndex].value;
 var s_bp_select = document.questionaire.s_bp_select.options[document.questionaire.s_bp_select.selectedIndex].value;
 var i_bp_select_other = document.questionaire.i_bp_select_other.value;
  
 if (s_promo_code == "") {
  alert("Please select your promotion code before pressing the [Submit] button!");
  return false;
 } 
 if (i_pnmgiven == "") {
  alert("Please fill in your First Name before pressing the [Submit] button!");
  return false;
 } 
 if (i_pnmfamily == "") {
  alert("Please fill in your Last Name before pressing the [Submit] button!");
  return false;
 } 
 if (i_pjobtitle == "") {
  alert("Please fill in your Role/Title before pressing the [Submit] button!");
  return false;
 } 
 if (i_orgnm == "") {
  alert("Please fill in your Company before pressing the [Submit] button!");
  return false;
 } 
 if (i_bsaddr1 == "") {
  alert("Please fill in your Address before pressing the [Submit] button!");
  return false;
 } 
 if (i_bscity == "") {
  alert("Please fill in your City before pressing the [Submit] button!");
  return false;
 } 
 if (s_bsst == "") {
  alert("Please select your State before pressing the [Submit] button!");
  return false;
 }
 if (i_bspostcde == "") {
  alert("Please fill in your ZIP before pressing the [Submit] button!");
  return false;
 } 
 if (i_bstel1 == "") {
  alert("Please fill in your Telephone before pressing the [Submit] button!");
  return false;
 } 
 if (i_emailgeneric == "") {
  alert("Please fill in your Email before pressing the [Submit] button!");
  return false;
 } 
 if (!IsEmail(i_emailgeneric)) {
  alert("Please supply a valid Email before pressing the [Submit] button!");
  return false;
 } 
 if (s_INTDAY_EX_COMPSIZE == "") {
  alert("Please pick a company size before pressing the [Submit] button!");
  return false;
 } 
 if (i_contact_email == "") {
  alert("Please pick your Email contact option before pressing the [Submit] button!");
  return false;
 } 
 if (i_contact_phone == "") {
  alert("Please pick your Phone contact option before pressing the [Submit] button!");
  return false;
 } 
 if (s_best_time_call == "" && document.questionaire.i_contact_phone[0].checked) {
  alert("Please select the Best Time to Call before pressing the [Submit] button!");
  return false;
 } 
 if (s_bp_select == "other" && i_bp_select_other == "") {
  alert("Please indicate your preferred Authorized Avaya BusinessPartner before pressing the [Submit] button!");
  return false;
 } 
    
// document.questionaire.submit();
	regDate();
 return true;
}
