// form validation function //
/*var numberRegex =  /^[0-9];*/
function trimSpace(x)
{
var emptySpace = / /g;
var trimAfter = x.replace(emptySpace,"");
return(trimAfter);
}
function numberValidate(incomingString, defaultValue)
{
if(trimSpace(incomingString).length == 0 || incomingString.search(/[^0-9\.]/g) != -1 || parseInt(incomingString, 10) < 0 )
{
return false;
}
else
return true;
}
function alphanumeric(incomingString, defaultValue)
{
if(trimSpace(incomingString).length == 0 || incomingString.search(/[^0-9a-zA-Z]/g) != -1 || incomingString==defaultValue)
{
return false;
}
else
return true;
}
var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
function validate(form) {
var name = trimSpace(document.demorequest.Name.value);
var email = trimSpace(document.demorequest.Email.value);
var title = trimSpace(document.demorequest.Title.value);
var company = trimSpace(document.demorequest.Company.value);
var add = trimSpace(document.demorequest.Address.value);
var city = trimSpace(document.demorequest.City.value);
var state =  trimSpace(document.demorequest.State.value);
var zip = trimSpace(document.demorequest.Zip.value);
var country =  trimSpace(document.demorequest.Country.value);
var emp = trimSpace(document.demorequest.EMP.value);
var phone = trimSpace(document.demorequest.Phone.value);
var fax = trimSpace(document.demorequest.Fax.value);
var os = trimSpace(document.demorequest.OpSystem.value);
var dtype = trimSpace(document.demorequest.DemoType.value);
if(name == "") {	
alert("Please enter your Name");
document.demorequest.Name.focus();
return false;
}
if(!name.match(nameRegex)) {
alert("Your Name should contain only Alphabets");
document.demorequest.Name.focus();
return false;
}
if(title == "") {
alert("Please enter your Title");
document.demorequest.Title.focus();
return false;
}
if(!title.match(nameRegex)) {
alert("Your Title should contain only Alphabets");
document.demorequest.Title.focus();
return false;
}
if(company == "") {
alert("Please enter your Company Name");
document.demorequest.Company.focus();
return false;
}
if(!company.match(nameRegex)) {
alert("Your Company Name should contain only Alphabets");
document.demorequest.Company.focus();
return false;
}
if(emp == "") {
alert("Please enter number of employees in your Company");
document.demorequest.EMP.focus();
return false;
}
if(!numberValidate(emp)) {
alert("Your Employees Number should contain only Numbers");
document.demorequest.EMP.focus();
return false;
}
if(add == "") {
alert("Please enter your Address");
document.demorequest.Address.focus();
return false;
}
if(city == "") {
alert("Please enter your City Name");
document.demorequest.City.focus();
return false;
}
if(!city.match(nameRegex)) {
alert("Your City Name should contain only Alphabets");
document.demorequest.City.focus();
return false;
}
if(state == "") {
alert("Please enter your State Name");
document.demorequest.State.focus();
return false;
}
if(!state.match(nameRegex)) {
alert("Your State Name should contain only Alphabets");
document.demorequest.State.focus();
return false;
}
if(zip == "") {
alert("Please enter the Zip code");
document.demorequest.Zip.focus();
return false;
}
if(!alphanumeric(zip)) {
alert("Your Zip Code should contain only Alphanumerics");
document.demorequest.Zip.focus();
return false;
}
if(country == "") {
alert("Please enter your Country Name");
document.demorequest.Country.focus();
return false;
}
if(!country.match(nameRegex)) {
alert("Your Country Name should contain only Alphabets");
document.demorequest.Country.focus();
return false;
}
if(phone == "") {
alert("Please enter your Phone Number");
document.demorequest.Phone.focus();
return false;
}
if(!numberValidate(phone)) {
alert("Your Phone Number should contain only Numbers");
document.demorequest.Phone.focus();
return false;
}  
if(fax == "") {
alert("Please enter your FAX Number");
document.demorequest.Fax.focus();
return false;
}
if(!numberValidate(fax)) {
alert("Your Fax Number should contain only Alphabets");
document.demorequest.Fax.focus();
return false;
}
if(os == "") {
alert("Please enter your OS version");
document.demorequest.OpSystem.focus();
return false;
}
if(dtype == "") {
alert("Please enter the Demo Type");
document.demorequest.DemoType.focus();
return false;
}
if(email == "") {
alert("Please enter your Email Address");
document.demorequest.Email.focus();
return false;
}
if(!email.match(emailRegex)) {
alert("Please enter valid Email Address");
document.demorequest.Email.focus();
return false;
} 
if(document.demorequest.OpSystem.options[document.demorequest.OpSystem.selectedIndex].value ==-1)
{
alert("Please Select the Windows Version");
document.demorequest.OpSystem.focus();
return false;
}
if(document.demorequest.DemoType.options[document.demorequest.DemoType.selectedIndex].value ==-1)
{
alert("Please Select the Quality System");
document.demorequest.DemoType.focus();
return false;
}  
return true;
}
function validate2(form) {	
var firstname = trimSpace(document.downloadreq.FirstName.value);
var emailId = trimSpace(document.downloadreq.emailID.value);
var companyname = trimSpace(document.downloadreq.CompanyName.value);
var companyaddress = trimSpace(document.downloadreq.CompanyAddress.value);
var companywebsite = trimSpace(document.downloadreq.CompanyWebsite.value);
var os = trimSpace(document.downloadreq.OpSystem.value);
if(firstname == "") {
alert("Please enter your name");
document.downloadreq.FirstName.focus();
return false;
}
if(!firstname.match(nameRegex)) {
alert("Your Name should contain only Alphabets");
document.downloadreq.FirstName.focus();
return false;
}
if(emailId == "") {
alert("Please enter your Email Address");
document.downloadreq.emailID.focus();
return false;
}
if(!emailId.match(emailRegex)) {
alert("Please enter Valid Email address");
document.downloadreq.emailID.focus();
return false;
}
if(companyname == "") {
alert("Please enter your Company Name");
document.downloadreq.CompanyName.focus();
return false;
}
if(!companyname.match(nameRegex)) {
alert("Your Company Name should contain only Alphabets");
document.downloadreq.CompanyName.focus();
return false;
}
if(companyaddress == "") {
alert("Please enter your Company Address");
document.downloadreq.CompanyAddress.focus();
return false;
}
if(companywebsite == "") {
alert("Please enter your Company Website Address");
document.downloadreq.CompanyWebsite.focus();
return false;
}
if(document.downloadreq.OpSystem.options[document.downloadreq.OpSystem.selectedIndex].value ==-1)
{
alert("Please Select the Windows Version");
document.downloadreq.OpSystem.focus();
return false;
}
return true;
}
function validate3(form) {	
var firstname = trimSpace(document.form1.FirstName.value);
var emailId = trimSpace(document.form1.emailID.value);
var companyname = trimSpace(document.form1.CompanyName.value);
var companyaddress = trimSpace(document.form1.CompanyAddress.value);
var companywebsite = trimSpace(document.form1.CompanyWebsite.value);
var os = trimSpace(document.form1.OpSystem.value);
var oid = trimSpace(document.form1.orderId.value);
if(firstname == "") {
alert("Please enter your Name");
document.form1.FirstName.focus();
return false;
}
if(!firstname.match(nameRegex)) {
alert("Your Name should contain only Alphabets");
document.form1.FirstName.focus();
return false;
}
if(emailId == "") {
alert("Please enter your Email Address");
document.form1.emailID.focus();
return false;
}
if(!emailId.match(emailRegex)) {
alert("Please enter Valid Email Address");
document.form1.emailID.focus();
return false;
}
if(companyname == "") {
alert("Please enter your Company Name");
document.form1.CompanyName.focus();
return false;
}
if(!companyname.match(nameRegex)) {
alert("Your Company Name should contain only Alphabets");
document.form1.CompanyName.focus();
return false;
} 
if(oid == "") {
alert("Please enter your OrderId");
document.form1.orderId.focus();
return false;
}
if(!alphanumeric(oid)) {
alert("Your OrderID should contain only Alphanumerics");
document.form1.orderId.focus();
return false;
}  
if(companyaddress == "") {
alert("Please enter your Company Address");
document.form1.CompanyAddress.focus();
return false;
}
if(companywebsite == "") {
alert("Please enter your Company Website Address");
document.form1.CompanyWebsite.focus();
return false;
}
if(document.form1.OpSystem.options[document.form1.OpSystem.selectedIndex].value ==-1)
{
alert("Please Select the Windows Version");
document.form1.OpSystem.focus();
return false;
}
return true;
}
/* pop up box script */
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
function $(x){return document.getElementById(x);}
function scrollFix(){var obol=$('ol');obol.style.top=posTop()+'px';obol.style.left=posLeft()+'px';}
function sizeFix(){var obol=$('ol');obol.style.height=pageHeight()+'px';obol.style.width=pageWidth()+'px';}
function kp(e){ky=e?e.which:event.keyCode;if(ky==88||ky==120)hm();return false}
function inf(h){tag=document.getElementsByTagName('select');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;tag=document.getElementsByTagName('iframe');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;tag=document.getElementsByTagName('object');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;}
function sm(obl, wd, ht){var h='hidden';var b='block';var p='px';var obol=$('ol'); var obbxd = $('mbd');obbxd.innerHTML = $(obl).innerHTML;obol.style.height=pageHeight()+p;obol.style.width=pageWidth()+p;obol.style.top=posTop()+p;obol.style.left=posLeft()+p;obol.style.display=b;var tp=posTop()+((pageHeight()-ht)/2)-12;var lt=posLeft()+((pageWidth()-wd)/2)-12;var obbx=$('mbox');obbx.style.top=(tp<0?0:tp)+p;obbx.style.left=(lt<0?0:lt)+p;obbx.style.width=wd+p;obbx.style.height=ht+p;inf(h);obbx.style.display=b;return false;}
function hm(){var v='visible';var n='none';$('ol').style.display=n;$('mbox').style.display=n;inf(v);document.onkeypress=''}
function initmb(){var ab='absolute';var n='none';var obody=document.getElementsByTagName('body')[0];var frag=document.createDocumentFragment();var obol=document.createElement('div');obol.setAttribute('id','ol');obol.style.display=n;obol.style.position=ab;obol.style.top=0;obol.style.left=0;obol.style.zIndex=998;obol.style.width='100%';frag.appendChild(obol);var obbx=document.createElement('div');obbx.setAttribute('id','mbox');obbx.style.display=n;obbx.style.position=ab;obbx.style.zIndex=999;var obl=document.createElement('span');obbx.appendChild(obl);var obbxd=document.createElement('div');obbxd.setAttribute('id','mbd');obl.appendChild(obbxd);frag.insertBefore(obbx,obol.nextSibling);obody.insertBefore(frag,obody.firstChild);
window.onscroll = scrollFix; 
window.onresize = sizeFix;
}
window.onload = initmb;
function test(){
sm('box',500,450);
}
function hideModal()
{
document.getElementById('box').style.display = "none";
return false;
}
/* pop up script ends */
function checkValidation(){
var email = trimSpace(document.lnviewDemo.USERNAME.value);
var password = trimSpace(document.lnviewDemo.PASSWORD.value);
if(email == ""){
alert("Please enter your email address");
document.lnviewDemo.USERNAME.focus();
return false;}
if(!email.match(emailRegex)){
alert("Please enter valid email address");
document.lnviewDemo.USERNAME.focus();
return false;}
if(password == ""){
alert("Please enter the password");
document.lnviewDemo.PASSWORD.focus();
return false;}
return true;
}
function checkValidation2(){
	
if(trimSpace(document.regForm.USER_FIRST_NAME.value)==""){
alert("Please enter your Name.");
document.regForm.USER_FIRST_NAME.focus();
return false;
}
if(!nameCheck(trimSpace(document.regForm.USER_FIRST_NAME.value))){
alert("Your name should contain only letters and spaces.")
document.regForm.USER_FIRST_NAME.focus();
return false;
}
if(trimSpace(document.regForm.USERNAME.value)==""){
alert("Please enter your Email ID.");
document.regForm.USERNAME.focus();
return false;
}
if (emailValidate(document.regForm.USERNAME.value)==false){
alert("Please enter your valid Email address.")
document.regForm.USERNAME.focus();
return false
}
if(trimSpace(document.regForm.PASSWORD.value)==""){
alert("Please enter your password.");
document.regForm.PASSWORD.focus();
return false;
}
var pass = trimSpace(document.regForm.PASSWORD.value);
if(pass.length<5){
alert("Password must be at least 5 characters long.");
document.regForm.PASSWORD.focus();
return false;
}
if(trimSpace(document.regForm.CONFIRM_PASSWORD.value)==""){
alert("Please confirm your password.");
document.regForm.CONFIRM_PASSWORD.focus();
return false;
}
if(document.regForm.PASSWORD.value != document.regForm.CONFIRM_PASSWORD.value){
alert("Please enter same password.");
document.regForm.CONFIRM_PASSWORD.focus();
return false;
}
if(trimSpace(document.regForm.CUSTOMER_WORK_CONTACT.value)=="")
{
alert("Please enter your phone number.");
document.regForm.CUSTOMER_WORK_CONTACT.focus();
return false;
}
if(isdig(document.regForm.CUSTOMER_WORK_CONTACT.value)==false)
{
alert("Your phone number is not valid.");
document.regForm.CUSTOMER_WORK_CONTACT.focus();
return false;
}
if(document.regForm.CUSTOMER_WORK_CONTACT.value.length<9)
{
alert("phone number must be atleast 9 digits long...");
document.regForm.CUSTOMER_WORK_CONTACT.focus();
return false;
}
if(document.regForm.JOB_TITLE.value =="")
{
alert("Please select the Job title");
document.regForm.JOB_TITLE.focus();
return false;
}
if(document.regForm.JOB_FUNCTION.value =="")
{
alert("Please select the Job Function");
document.regForm.JOB_FUNCTION.focus();
return false;
}
if(document.regForm.CUSTOMER_INDUSTRY.options[document.regForm.CUSTOMER_INDUSTRY.selectedIndex].value=="")
{
alert("Please select the Industry");
document.regForm.CUSTOMER_INDUSTRY.selectedIndex = [0];
document.regForm.CUSTOMER_INDUSTRY.focus();
return false;
}
if(document.regForm.CUSTOMER_COUNTRY.options[document.regForm.CUSTOMER_COUNTRY.selectedIndex].value=="")
{
alert("Please select the Country");
document.regForm.CUSTOMER_COUNTRY.selectedIndex = [0];
document.regForm.CUSTOMER_COUNTRY.focus();
return false;
}
if(document.regForm.CATAGORY_ID_PRIM.value =="")
{
alert("Please select the Primary Area of Interest");
document.regForm.CATAGORY_ID_PRIM.focus();
return false;
}
return checkValidation3();
}

function checkValidation3(){
	
if(document.regForm.interest.options[document.regForm.interest.selectedIndex].value=="")
{
alert("Please select the reason for your interest");
document.regForm.interest.selectedIndex = [0];
document.regForm.interest.focus();
return false;
}
var temp2="";
var count = 0;
for (i=0;i<7;i++){
var temp ="challenge";
temp = temp+i;
if(document.getElementById(temp).checked==true){
temp2 = temp2+document.getElementById(temp).value+", ";
count++;
}
}
if(count <1){
if(document.regForm.challenge7.checked==true){
if(document.regForm.challenge.value =="")
{
alert("Please enter quality management challenge");
document.regForm.challenge.focus();
return false;
}
temp2 = temp2+document.regForm.challenge.value+"#";
count++;
}
}
if(count<=0){
alert("Please enter quality management challenge");
document.regForm.challenge.focus();
return false;
}
//alert(temp2);
document.regForm.challenges.value=temp2;
if(document.regForm.employeesNo.options[document.regForm.employeesNo.selectedIndex].value=="")
{
alert("Please select the number of employees");
document.regForm.employeesNo.selectedIndex = [0];
document.regForm.employeesNo.focus();
return false;
}
if(document.regForm.revenue.options[document.regForm.revenue.selectedIndex].value=="")
{
alert("Please select the revenue range");
document.regForm.revenue.selectedIndex = [0];
document.regForm.revenue.focus();
return false;
}
if(document.regForm.evaluation.options[document.regForm.evaluation.selectedIndex].value=="")
{
alert("Please select the evaluation option");
document.regForm.evaluation.selectedIndex = [0];
document.regForm.evaluation.focus();
return false;
}
if(document.regForm.involvement.options[document.regForm.involvement.selectedIndex].value=="")
{
alert("Please select the level of involvement");
document.regForm.involvement.selectedIndex = [0];
document.regForm.involvement.focus();
return false;
}
if(document.regForm.timeframe.options[document.regForm.timeframe.selectedIndex].value=="")
{
alert("Please select the timeframe");
document.regForm.timeframe.selectedIndex = [0];
document.regForm.timeframe.focus();
return false;
}
if(document.getElementById('AGREEMENT_ID').checked == false)
{
alert("Please accept the terms of service");
document.getElementById('AGREEMENT_ID').focus();
return false;
}
}
function isdig(str) 
{
var strdigit="^ +-0123456789";
var count=0;
for (var i = 0; i < str.length; i++) {
if (strdigit.indexOf(str.charAt(i)) == -1){
count=1;  }} 
if(count=='0')
return true;
else
return false;		
}
function nameCheck(str)
{
var string = str.length;
var iChars = "*|,\":<>[]{}`\.';()/&$#%~!^-+=?1234567890@";
for (var i = 0; i < string; i++) {
if (iChars.indexOf(str.charAt(i)) != -1)
return false;
}
return true;
}
function emailValidate(incomingString)
{
         var iChars = "*|,\":<>[]{}`\;()&$#%/?";
         
         var emailId=incomingString;
         if(Trim(emailId).length == 0)
         {
           //alert("Not a valid e-mail address");
	   return false;
         }
         for (var i = 0; i < incomingString.length; i++) {
		 if (iChars.indexOf(emailId.charAt(i)) != -1)
		 {
			//alert("Not a valid e-mail address");
			 return false;
		 }
       	 }
	 var atpos=emailId.indexOf("@");
	 var dotpos=emailId.lastIndexOf(".");
	 if (atpos<1 || dotpos<atpos+2 || dotpos+2>=emailId.length)
	   {
	   //alert("Not a valid e-mail address");
	   return false;
  	   }
  	   
  	   /*
if(trimSpace(incomingString).length == 0 || incomingString.search(/[\_\-\d]*[A-Za-z]+[\w\_\-]*[\@][\d]*[A-Za-z]+[\w\-]*[\.][A-Za-z]+/g) == -1 )	
return false;
var iChars = "*|,\":<>[]{}`\';()&$#%/?";
for (var i = 0; i < incomingString.length; i++) {
if (iChars.indexOf(incomingString.charAt(i)) != -1)
return false;
if(incomingString.lastIndexOf('.')>-1)
{
var lastStr = incomingString.substring(incomingString.lastIndexOf('.'),incomingString.length);
if(!numCheck(lastStr))
{return false;}}}
return true;
}
function numCheck(str)
{
var string = str.length;
var iChars = "*|,\":<>[]{}`\';()/&$#%~!^-_+=?1234567890";
for (var i = 0; i < string; i++) {
if (iChars.indexOf(str.charAt(i)) != -1)
return false;
}
*/

return true;
}
