
function CheckFirstName(){
  var formString = document.VideoView.FirstName.value;
  if((formString.search(/<|>/)!=-1) || ((formString == "") || (formString == null))) {  
  document.VideoView.FirstName.value = "";
  var ErrorFound = 'Please enter a valid First Name';
  } else {
  var ErrorFound = 0;
  }
  return ErrorFound ;
} 
function CheckLastName(){
  var formString = document.VideoView.LastName.value;
  if((formString.search(/<|>/)!=-1) || ((formString == "") || (formString == null))) {  
  document.VideoView.LastName.value = "";
  var ErrorFound = 'Please enter a valid Last Name';
  } else {
  var ErrorFound = 0;
  }
  return ErrorFound ;
} 


function CheckCompanyName(){
  var formString = document.VideoView.CompanyName.value;
  if((formString.search(/<|>/)!=-1) || ((formString == "") || (formString == null))) {  
 var ErrorFound = 'Please enter a valid Company Name';  
  document.VideoView.CompanyName.value = "";
  } else {
  var ErrorFound = 0;
  }
  return ErrorFound ;
} 

function CheckAddress(){
  var formString = document.VideoView.Address.value;
  if((formString.search(/<|>/)!=-1) || ((formString == "") || (formString == null))) {  
  document.VideoView.Address.value = "";
  var ErrorFound = 'Please enter a valid Address';
  } else {
  var ErrorFound = 0;
  }
  return ErrorFound ;
} 


function CheckState(){
  var formString = document.VideoView.State.value;
  if((formString.search(/<|>|[0-9]/)!=-1) || ((formString == "") || (formString == null))) {  
  document.VideoView.State.value = "";
  var ErrorFound = 'Please enter a valid State';
  } else {
  var ErrorFound = 0;
  }
  return ErrorFound ;
} 

function CheckEmail(){
  var reString = "^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$";
  var re = new RegExp(reString);
  var m = re.exec(document.VideoView.Email.value);
  
 
	  if (m == null) {
	  document.VideoView.Email.value = "";
	  var ErrorFound = 'Please enter the correct E-mail Address';
 	  } else {
 	  var ErrorFound = 0;
 	  }
  return ErrorFound ;
} 

function CheckZip(){
  var reString = "[0-9]{5}";
  var re = new RegExp(reString);
  var m = re.exec(document.VideoView.ZipCode.value);
  
  if(document.VideoView.ZipCode.value.length == 5){
	   
	  if (m == null) {
	  var ErrorFound = 'Please enter the correct 5 digit Zip Code';  
	  document.VideoView.ZipCode.value = "";
	  } else {
	  var ErrorFound = 0;
 	  }
  } 
  else if (document.VideoView.ZipCode.value.length != 5)
  {
	  var ErrorFound = 'Please enter the correct 5 digit Zip Code';  
	  document.VideoView.ZipCode.value = "";
  }
  
   return ErrorFound ;
}



function CheckPhone1(){
  var reString = "[0-9]{3}";
  var re = new RegExp(reString);
  var m = re.exec(document.VideoView.Phone1.value);
  
  if(document.VideoView.Phone1.value.length == 3){
	   
	  if (m == null) {
	  alert('Please enter the correct area code');  
	  document.VideoView.Phone1.value = "";
	  } else {
	  document.VideoView.Phone2.focus();
	  }
  } 
  else if (document.VideoView.Phone1.value.length > 3)
  {
	  document.VideoView.Phone1.value = "";
  }
}

function CheckPhone2(){
  var reString = "[0-9]{3}";
  var re = new RegExp(reString);
  var m = re.exec(document.VideoView.Phone2.value);
  
  if(document.VideoView.Phone2.value.length == 3){
	   
	  if (m == null) {
	  alert('Please enter the correct phone number');  
	  document.VideoView.Phone2.value = "";
	  } else {
	  document.VideoView.Phone3.focus();
	  }
  } 
  else if (document.VideoView.Phone2.value.length > 3)
  {
	  document.VideoView.Phone2.value = "";
  }
}


function CheckPhone3(){
  var reString = "[0-9]{4}";
  var re = new RegExp(reString);
  var m = re.exec(document.VideoView.Phone3.value);
  
  if(document.VideoView.Phone3.value.length == 4){
	   
	  if (m == null) {
	  alert('Please enter the correct phone number');  
	  document.VideoView.Phone3.value = "";
	  } 
  } 
  else if (document.VideoView.Phone3.value.length > 4)
  {
	  document.VideoView.Phone3.value = "";
  }
}

function TermsOfUse(){
  if(document.VideoView.AgreeToTerms.checked) {  
   var ErrorFound = 0;
    } else {
  var ErrorFound = 'Please read and agree with our Terms of Use';
 

  }
  return ErrorFound ;
} 


function ValidateForm(){
	var AllErrorsFound = "";
	var ErrorCounter = 0;
	var result = CheckFirstName(); if(CheckFirstName() != 0){ AllErrorsFound+="\n"+result; ErrorCounter++;}
	var result = CheckLastName(); if(CheckLastName() != 0){ AllErrorsFound+="\n"+result; ErrorCounter++;}
//	var result = CheckCompanyName(); if(CheckCompanyName() != 0){ AllErrorsFound+="\n"+result; ErrorCounter++;}  //not required
//	var result = CheckAddress(); if(CheckAddress() != 0){ AllErrorsFound+="\n"+result; ErrorCounter++;} //removed
//	var result = CheckState(); if(CheckState() != 0){ AllErrorsFound+="\n"+result; ErrorCounter++;} //removed
//	var result = CheckZip(); if(CheckZip() != 0){ AllErrorsFound+="\n"+result; ErrorCounter++;} //removed
//	var result = CheckEmail(); if(CheckEmail() != 0){ AllErrorsFound+="\n"+result; ErrorCounter++;}
	var result = TermsOfUse(); if(TermsOfUse() != 0){ AllErrorsFound+="\n"+result; ErrorCounter++;}

	if(ErrorCounter == 0){
	ShowVideo();
	WriteUser();	
	} else {
	alert(AllErrorsFound);
	}
		
	
}

function ShowVideo(){
  
  var str = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='500' height='305' id='video' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='allowFullScreen' value='true' /><param name='movie' value='swf/preview4.swf' /><param name='quality' value='high' /><param name='scale' value='noscale' /><param name='wmode' value='transparent' /><param name='bgcolor' value='#000000' />	<embed src='swf/preview4.swf' quality='high' scale='noscale' wmode='transparent' bgcolor='#000000' width='500' height='305' name='movie' align='middle' allowScriptAccess='sameDomain' allowFullScreen='true' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object><p style='font-size:12px; color:red; font-family:arial; display:block; margin:30px 0px 0px 0px;'><em>If you experience any problems, please pause the video and allow a few minutes for it to load</em></p>"
  document.getElementById('video').innerHTML = str;	
   document.getElementById('video').style.display = "block";
   document.getElementById('video').style.height = "400px";
	
}

function WriteUser(){
	var newsrc = "/scripts/add.cfm?FirstName="+document.VideoView.FirstName.value+"&LastName="+document.VideoView.LastName.value+"&CompanyName="+document.VideoView.CompanyName.value+"&AgreedToTerms=yes";
	document.getElementById("AddVideoUser").src = newsrc;
	window.location = "#ShowVideo";
}

