// JavaScript Document
function LTrim( value ) 
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) 
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
// Removes leading and ending whitespaces
function trim( value ) 
{
	return LTrim(RTrim(value));
}
//email validation
function isValidEmail(strEmail,type)
{
	if(strEmail.length<5)
	{
		return false;
	}
  validRegExp = /^[\w\.-]+@[a-z,A-Z,0-9-]+[\.]{1}[a-zA-Z]{2,}[[\.]?[a-zA-Z]{0,2}[[\.]?[a-zA-Z]{0,2}$/i;
   // search email text for regular exp matches
   strEmail = trim(strEmail);
    if (strEmail.search(validRegExp) == -1) 
	{
      return false;
    } 
	//chkExistMail(strEmail, type);
	return true; 
}
//validatating user name
function isValidUserName(val) {
	 validRegExp = /^[0-9a-zA-Z.\_\- ]+$/i;
   // search email text for regular exp matches
   val = trim(val);
    if (val.search(validRegExp) == -1) {
      return false;
    } 
    return true; 	
}
//validating address
function  isValidAddress(addr){
	//validRegExp = /^[0-9a-zA-Z\s\,./-]+$/;
	validRegExp = /^[0-9a-zA-Z \s,.\!\@\#\$\%\^\&\*\(\)\?\_\/-]+$/;
    if (addr.match(validRegExp) == null) {
      return false;
    } 
    return true;
}
//Validating Name
function isValidName(val) {
	 validRegExp = /^[a-zA-Z \.\-]+$/i;
      val = trim(val);
	  if(val.length == 1)
	  return false;
    if (val.search(validRegExp) == -1) {
      return false;
    } 
    return true; 	
}

function isValidTitle(val) {
	validRegExp = /^[0-9a-zA-Z \s,.\!\@\#\$\%\^\&\*\(\)\?\_\/-]+$/;
    if (val.match(validRegExp) == null) {
      return false;
    } 
    return true;
}

function isValidOrg(val){
	  val = trim(val);
	  if(val.length <= 1)
	  return false;
    return true; 

}

//Validating Comment
function  isValidComment(commt){
	validRegExp = /^[0-9a-zA-Z \s,.\!\@\#\$\%\^\&\*\(\)\?\_\'\"/-]+$/;
    if (commt.match(validRegExp) == null) {
      return false;
    } 
    return true;
}
//Validating Phone
function isValidPhone(val) {
	 validRegExp = /^[0-9- \(\)\+]+$/;
   // search email text for regular exp matches
   val = trim(val);
    if (val.match(validRegExp) == null) {
      return false;
    }	
	return true;
}

//Validating Zip


function isValidZip(val) {
	 validRegExp = /^[0-9a-zA-Z \-]+$/;
   // search email text for regular exp matches
   val = trim(val);
    if (val.match(validRegExp) == null) {
      return false;
    } 
	if(val.length < 5 || val.length > 10)  {
		return false; }
        return true; 	
}


function validateZIP(field) 
{
	var valid = "0123456789-";
	var hyphencount = 0;
	if (field.length < 5 || field.length > 10) 
	{
		/*document.getElementById('errormessage').innerHTML='Invalid ZIP/Postal Code';
		document.getElementById('postalcode').focus();*/
		return false;
	}	
	for (var i=0; i < field.length; i++) 
	{
		temp = "" + field.substring(i, i+1);
		if (temp == "-") hyphencount++;
			if (valid.indexOf(temp) == "-1") 
			{
				/*document.getElementById('errormessage').innerHTML='Invalid ZIP/Postal Code';
				document.getElementById('postalcode').focus();*/
				return false;
			}
			if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) 
			{
				/*document.getElementById('errormessage').innerHTML='Invalid ZIP/Postal Code';
				document.getElementById('postalcode').focus();*/
				return false;
			}
	}
	return true;
}
function checkURL(value) 
{
	var urlregex = new RegExp("^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)");
	if(urlregex.test(value))
	{
		return(true);
	}
	return(false);
}
if (window.XMLHttpRequest)
{
   // If IE7, Mozilla, Safari, etc: Use native object
	var xmlhttp = new XMLHttpRequest();

}
else
{
	if (window.ActiveXObject)
	{
		// ...otherwise, use the ActiveX control for IE5.x and IE6
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   }

}
function newsletter_subscription(){	
	document.getElementById('errormessage').innerHTML=''; 
	document.getElementById('newslettermessage').innerHTML ='';
	//var Subscribe = trim(document.getElementById('subscribe').value);
	var Subscribe = '';
	var Services = '';
	var Products = '';
	var Referencecard = '';
	var captcha = '';
	var captcha = trim(document.getElementById('txtFCaptcha').value);
	
	/*Services='';
	for (i=0;i<document.news_letter.services.length;i++)
	{
		  if (document.news_letter.services[i].checked)
		  {
				 Services = document.news_letter.services[i].value;
		  }
	} 
	Products ='';
	for (i=0;i<document.news_letter.products.length;i++)
	{
		  if (document.news_letter.products[i].checked)
		  {
				 Products = document.news_letter.products[i].value;
		  }
	}
	Referencecard = '';
	for (i=0;i<document.news_letter.referencecard.length;i++)
	{
		  if (document.news_letter.referencecard[i].checked)
		  {
				 Referencecard = document.news_letter.referencecard[i].value;
		  }
	}*/
	if(document.getElementById('services1').checked) 
		Services = document.getElementById('services1').value+',';
	if(document.getElementById('benchmark').checked) 
		Services = Services + document.getElementById('benchmark').value+','; 
	if(document.getElementById('outsource').checked) 
		Services = Services + document.getElementById('outsource').value+',';
	if(document.getElementById('measurement').checked) 
		Services = Services + document.getElementById('measurement').value+',';
	if(document.getElementById('estimating').checked) 
		Services = Services + document.getElementById('estimating').value+',';
	if(document.getElementById('CMMI').checked) 
		Services = Services + document.getElementById('CMMI').value+',';	
	if(document.getElementById('pqs').checked) 
		Services = Services + document.getElementById('pqs').value+',';
	if(document.getElementById('training').checked) 
		Services = Services + document.getElementById('training').value+',';	
	Services=Services.substr(0,Services.length-1);
	
	if(document.getElementById('products').checked)
		Products = document.getElementById('products').value+',';
	if(document.getElementById('smr').checked)
		Products = Products + document.getElementById('smr').value+',';
	if(document.getElementById('fpwork').checked)
		Products = Products +  document.getElementById('fpwork').value+',';	
	if(document.getElementById('benchmark_tool').checked)
		Products = Products +  document.getElementById('benchmark_tool').value+',';		
	Products=Products.substr(0,Products.length-1);
	
	if(document.getElementById('referencecard').checked)
		Referencecard = document.getElementById('referencecard').value+',';
	if(document.getElementById('referencecard1').checked)
		Referencecard = Referencecard +  document.getElementById('referencecard1').value+',';
	Referencecard=Referencecard.substr(0,Referencecard.length-1);
	
	
	/*var Fname = trim(document.getElementById('fname').value);
	var Lname = trim(document.getElementById('lname').value);
	var Email = trim(document.getElementById('email').value);
	var Organization = trim(document.getElementById('organization').value);
	var Address = trim(document.getElementById('address').value);
	var City = trim(document.getElementById('city').value);
	var State = trim(document.getElementById('state').value);
	var Postalcode = trim(document.getElementById('postalcode').value);
	var Country = trim(document.getElementById('country').value);
	var Phone = trim(document.getElementById('phone').value);*/
	var Fname = trim(document.getElementById('fname').value);
	var Lname = trim(document.getElementById('lname').value);
	var Title = trim(document.getElementById('title').value);
	var Organization = trim(document.getElementById('organization').value);
	var Maddress1 = trim(document.getElementById('maddress1').value);
	var Maddress2 = trim(document.getElementById('maddress2').value);
	var City = trim(document.getElementById('city').value);
	var State = trim(document.getElementById('state').value);
	var State1 = trim(document.getElementById('state1').value);
	var Postalcode = trim(document.getElementById('postalcode').value);
	var Country = trim(document.getElementById('country').value);
	var Phone = trim(document.getElementById('phone').value);
	var Email = trim(document.getElementById('email').value);
	var Fax = trim(document.getElementById('fax').value);
	var Website = trim(document.getElementById('website').value);
	
	var Subjects = trim(document.getElementById('subjects').value);
	var Comments = trim(document.getElementById('comments').value);
	var flag=true;
	
	
		if(Fname == '')
	{
		document.getElementById('errormessage').innerHTML =" First Name is mandatory";
		document.getElementById('bold_first').style.fontWeight ="bold";
		document.getElementById('fname').focus();
		return false;
		}
	if(!isValidName(Fname)){
		document.getElementById('errormessage').innerHTML =" Invalid First Name (Note: Apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_first').style.fontWeight ="bold";
		document.getElementById('fname').focus();
		return false;
	}
	if(isValidName(Fname)){
		document.getElementById('bold_first').style.fontWeight ="normal";
	}
	if(Lname == '')
	{
		document.getElementById('errormessage').innerHTML =" Last Name is mandatory";
		document.getElementById('bold_last').style.fontWeight ="bold";
		document.getElementById('lname').focus();
		return false;
		}
	if(!isValidName(Lname)){
		document.getElementById('errormessage').innerHTML =" Invalid Last Name (Note: Apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_last').style.fontWeight ="bold";
		document.getElementById('lname').focus();
		return false;
	}
	if(isValidName(Lname)){
		document.getElementById('bold_last').style.fontWeight ="normal";
	}
	
	if(Title == '')
	{
		document.getElementById('errormessage').innerHTML =" Title is mandatory";
		document.getElementById('bold_title').style.fontWeight ="bold";
		document.getElementById('title').focus();
		return false;
		}
	if(!isValidName(Title)){
		document.getElementById('errormessage').innerHTML =" Invalid Title (Note: Apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_title').style.fontWeight ="bold";
		document.getElementById('title').focus();
		return false;
	}
	
	if(isValidName(Title)){
	document.getElementById('bold_title').style.fontWeight ="normal";	
	}
	
	if(Email == '')
	{
		document.getElementById('errormessage').innerHTML =" Email is mandatory";
		document.getElementById('bold_email').style.fontWeight ="bold";	
		document.getElementById('email').focus();
		return false;
		}
	if(!isValidEmail(Email, 'validate_request_tool')){
		document.getElementById('errormessage').innerHTML ="Invalid Email (Note: Apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_email').style.fontWeight ="bold";	
		if(flag!= false) document.getElementById('email').focus();
		return false;
	}
	if(isValidEmail(Email, 'validate_request_tool')){
	document.getElementById('bold_email').style.fontWeight ="normal";		
	}
	
	if(Organization == '')
	{
		document.getElementById('errormessage').innerHTML =" Organization is mandatory";
		document.getElementById('bold_organization').style.fontWeight ="bold";	
		document.getElementById('organization').focus();
		return false;
		}
	if(!isValidAddress(Organization)){
		document.getElementById('errormessage').innerHTML ="Invalid Organization (Note: Apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_organization').style.fontWeight ="bold";	
		document.getElementById('organization').focus();
		return false;
	}
	if(isValidAddress(Organization)){
		document.getElementById('bold_organization').style.fontWeight ="normal";	
	}
	
	if(Maddress1 == '')
	{
		document.getElementById('errormessage').innerHTML =" Address is mandatory";
		document.getElementById('bold_address').style.fontWeight ="bold";	
		document.getElementById('maddress1').focus();
		return false;
		}
	if(!isValidAddress(Maddress1)){
		document.getElementById('errormessage').innerHTML ="Invalid Address (Note: Apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_address').style.fontWeight ="bold";
		document.getElementById('maddress1').focus();
		return false;
	}
	
	if(isValidAddress(Maddress1)){
		document.getElementById('bold_address').style.fontWeight ="normal";
	}
	
	if(Maddress2!='')
	{
		if(!isValidAddress(Maddress2)){
			document.getElementById('errormessage').innerHTML ="Invalid Address (Note: Apostrophes, single quotes, and double quotes are invalid!)";
			document.getElementById('maddress2').focus();
			return false;
		}
	}
	if(City == '')
	{
		document.getElementById('errormessage').innerHTML =" City is mandatory";
		document.getElementById('bold_city').style.fontWeight ="bold";
		document.getElementById('city').focus();
		return false;
		}
	if(!isValidAddress(City)){
		document.getElementById('errormessage').innerHTML ="Invalid City (Note: Apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_city').style.fontWeight ="bold";
		document.getElementById('city').focus();
		return false;
	}
	if(isValidAddress(City)){
		document.getElementById('bold_city').style.fontWeight ="normal";
	}
	
	if(State!='XX')
	{
		if(!isValidAddress(State)){
			document.getElementById('errormessage').innerHTML ="Invalid State";
			document.getElementById('bold_state').style.fontWeight ="bold";
			document.getElementById('state').focus();
			return false;
		}
	}
	else
	{
		if(!isValidAddress(State1)){
			document.getElementById('errormessage').innerHTML ="Invalid State";
			document.getElementById('state1').focus();
			return false;
		}	
	}
	if(isValidAddress(State)){
		document.getElementById('bold_state').style.fontWeight ="normal";
	}
	
	if(State =='Non-USA'  && Country=='United States')
	{
		document.getElementById('errormessage').innerHTML='Invalid Country (States and Countries must correspond)';		
		document.getElementById('country').focus();
		return false;
	}
	
	if(State !='Non-USA'  && Country !='United States')
	{
		document.getElementById('errormessage').innerHTML='Invalid Country (States and Countries must correspond)';		
		document.getElementById('country').focus();
		return false;
	}
	
	if(State =='Non-USA')
	{
		if(State1!='')
		{
			if(!isValidTitle(State1)){
				document.getElementById('errormessage').innerHTML ="Invalid State (Note: Apostrophes, single quotes, and double quotes are invalid!)";
				document.getElementById('state1').focus();
				return false;
			}	
		}
	}
	
	if(Postalcode == '')
	{
		document.getElementById('errormessage').innerHTML =" Postalcode is mandatory";
		document.getElementById('bold_zip').style.fontWeight ="bold";
		document.getElementById('postalcode').focus();
		return false;
		}
	if(!isValidZip(Postalcode)){
		document.getElementById('errormessage').innerHTML='Invalid ZIP/Postal Code';
		document.getElementById('bold_zip').style.fontWeight ="bold";
		document.getElementById('postalcode').focus();
		return false;
	}
	if(isValidZip(Postalcode)){
		document.getElementById('bold_zip').style.fontWeight ="normal";
	}
	
	if(Phone == '')
	{
		document.getElementById('errormessage').innerHTML =" Phone is mandatory";
		document.getElementById('bold_phone').style.fontWeight ="bold";
		document.getElementById('phone').focus();
		return false;
		}
	
	if(!isValidPhone(Phone)){
		document.getElementById('errormessage').innerHTML="Invalid Phone";
		document.getElementById('bold_phone').style.fontWeight ="bold";
		document.getElementById('phone').focus();
		return false;
	}
	if(isValidPhone(Phone)){
		document.getElementById('bold_phone').style.fontWeight ="normal";	
	}
	
	if(Fax!='')
	{
		if(!isValidPhone(Fax))
		{
			document.getElementById('errormessage').innerHTML="Invalid Fax";
			if(flag!= false) document.getElementById('fax').focus();
			return false;
		}
	}
	if(Website!='')
	{
		if(!checkURL(Website))
		{
			document.getElementById('errormessage').innerHTML="Invalid website";
			if(flag!= false) document.getElementById('website').focus();
			return false;
		}
	}
	
	if(Subjects!='')
	{
		if(!isValidAddress(Subjects)){
			document.getElementById('errormessage').innerHTML ="Invalid Subject (Note: Apostrophes, single quotes, and double quotes are invalid!)";
			document.getElementById('bold_organization').style.fontWeight ="bold";	
			document.getElementById('subjects').focus();
			return false;
		}
	}
	
	if(isValidAddress(Subjects)){
		document.getElementById('subjects').style.fontWeight ="normal";
	}
	
	if(Comments!='')
	{
		if(!isValidAddress(Comments)){
			document.getElementById('errormessage').innerHTML ="Invalid Comment (Note: Apostrophes, single quotes, and double quotes are invalid!)";
			document.getElementById('bold_organization').style.fontWeight ="bold";	
			document.getElementById('comments').focus();
			return false;
		}
	}
	
	if(isValidAddress(Comments)){
		document.getElementById('comments').style.fontWeight ="normal";
	}
	
	if(captcha == '')
	{
		document.getElementById('newslettermessage').innerHTML =" Captcha is mandatory";
		document.getElementById('txtFCaptcha').focus();
		return false;
		}
		
		
	querystring ="subscribe="+Subscribe+"&services="+Services+"&products="+Products+"&referencecard="+Referencecard+"&fname="+Fname+"&lname="+Lname+"&title="+Title+"&organization="+Organization+"&maddress1="+Maddress1+"&maddress2="+Maddress2+"&city="+City+"&state="+State+"&state1="+State1+"&postalcode="+Postalcode+"&country="+Country+"&phone="+Phone+"&email="+Email+"&fax="+Fax+"&website="+Website+"&subjects="+Subjects+"&comments="+Comments+"&captcha="+captcha;
	url= 'sendMail.php?option=newsletter&'+querystring;	
	if(xmlhttp){
		xmlhttp.open('POST',url,true);
		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		xmlhttp.onreadystatechange = httpnewsletter_validate;
		xmlhttp.send(null);
	}
	return false;
}
function reset_newsletter()
{
	document.getElementById('errormessage').innerHTML=''; 
	/*if(document.getElementById('option_from').value!=1)
	{
		document.getElementById('subscribe').checked = false;
		document.getElementById('email').value = '';
	}*/
	document.getElementById('txtFCaptcha').value = '';
	document.getElementById('services1').checked = false;
	document.getElementById('benchmark').checked = false;
	document.getElementById('outsource').checked = false;
	document.getElementById('measurement').checked = false;
	document.getElementById('estimating').checked = false;
	document.getElementById('CMMI').checked = false;
	document.getElementById('pqs').checked = false;
	document.getElementById('training').checked = false;
	document.getElementById('products').checked = false;
	document.getElementById('smr').checked = false;
	document.getElementById('fpwork').checked = false;
	document.getElementById('benchmark_tool').checked = false;
	document.getElementById('referencecard').checked = false;
	document.getElementById('referencecard1').checked = false;
	/*document.getElementById('fname').value = '';
	document.getElementById('lname').value = '';
	document.getElementById('organization').value = '';
	document.getElementById('address').value = '';
	document.getElementById('city').value = '';
	document.getElementById('state').value = '';
	document.getElementById('postalcode').value = '';
	document.getElementById('country').value = '';
	document.getElementById('phone').value = '';*/
	document.getElementById('fname').value = '' ;
	document.getElementById('lname').value = '' ;
	document.getElementById('title').value = '';
	document.getElementById('organization').value = '';
	document.getElementById('maddress1').value= '';
	document.getElementById('maddress2').value = '';
	document.getElementById('city').value = '';
	document.getElementById('state').value = '';
	document.getElementById('state1').value= '';
	document.getElementById('postalcode').value = '';
	document.getElementById('country').value = '';
	document.getElementById('phone').value = '';
	document.getElementById('email').value='';
	document.getElementById('fax').value='';
	document.getElementById('website').value='';
	document.getElementById('subjects').value = '';
	document.getElementById('comments').value = '';
}
function httpnewsletter_validate(){
	if (xmlhttp.readyState != 4){
		document.getElementById('spinner').innerHTML = "<img src='images/busy.gif' alt='Loading...'>";
	}
	else{
		mytext = xmlhttp.responseText;
		//alert(mytext);
		//document.getElementById('spinner').innerHTML = mytext;
		if(mytext == 'sucess'){
			window.location="thankyou.php?option=newsletter";
		}else {
			document.getElementById('spinner').innerHTML = "";
			document.getElementById("newslettermessage").innerHTML = mytext;
			//document.getElementById('fname').focus();
		}
	}
}

function register_validate(){
	if (xmlhttp.readyState != 4){
		document.getElementById('spinner').innerHTML = "<img src='../images/busy.gif' alt='Loading...'>";
	}
	else{
		mytext = xmlhttp.responseText;
		//alert(mytext);
		//document.getElementById('spinner').innerHTML = mytext;
		 if(mytext =='registered'){
			window.location="register_thankyou.php";
		}else {
			document.getElementById('spinner').innerHTML = "";
			document.getElementById("newslettermessage").innerHTML = mytext;
			//document.getElementById('fname').focus();
		}
	}
}
function tool_subscription(v_value){
	document.getElementById('errormessage').innerHTML=''; 
	var captcha = '';
	var captcha = trim(document.getElementById('txtFCaptcha').value);
	var Pqmplus = 'No';
	if(document.getElementById('pqmplus').checked)
		Pqmplus='Yes';
	var Smr = 'No';
	if(document.getElementById('smr').checked)
		Smr='Yes';
	var Charismatek = 'No';
	if(document.getElementById('charismatek').checked)
		Charismatek='Yes';
	if(Pqmplus == "No" && Smr == "No" && Charismatek == 'No' )
	{
	document.getElementById('newslettermessage').innerHTML =" You must choose atleast one tool to download";
	return false;
	}
	else
	{
		document.getElementById('newslettermessage').innerHTML = '';
		}
		
	var Fname = trim(document.getElementById('fname').value);
	var Lname = trim(document.getElementById('lname').value);
	var Title = trim(document.getElementById('title').value);
	var Organization = trim(document.getElementById('organization').value);
	var Maddress1 = trim(document.getElementById('maddress1').value);
	var Maddress2 = trim(document.getElementById('maddress2').value);
	var City = trim(document.getElementById('city').value);
	var State = trim(document.getElementById('state').value);
	var State1 = trim(document.getElementById('state1').value);
	var Postalcode = trim(document.getElementById('postalcode').value);
	var Country = trim(document.getElementById('country').value);
	var Phone = trim(document.getElementById('phone').value);
	var Email = trim(document.getElementById('email').value);
	var Fax = trim(document.getElementById('fax').value);
	var Website = trim(document.getElementById('website').value);
	var Tool = '';
	if(document.getElementById('i_search').checked)
		Tool = document.getElementById('i_search').value+',';
	if(document.getElementById('i_website').checked)
		Tool = Tool + document.getElementById('i_website').value+',';
	if(document.getElementById('conference').checked)
		Tool = Tool+ document.getElementById('conference').value+',';
	if(document.getElementById('other_request').checked)
		Tool = Tool + document.getElementById('tool1').value+',';
	Tool=Tool.substr(0,Tool.length-1);
	//var tool1=document.getElementById('tool1').value;
	var Plantool = '';
	if(document.getElementById('fp_analysis').checked)
		Plantool = document.getElementById('fp_analysis').value+',';
	if(document.getElementById('p_management').checked)
		Plantool = Plantool + document.getElementById('p_management').value+',';
	if(document.getElementById('p_estimation').checked)
		Plantool = Plantool+ document.getElementById('p_estimation').value+',';
	Plantool=Plantool.substr(0,Plantool.length-1);	
	var Pointanalysis= '';
	for (i=0;i<document.request_tool.pointanalysis.length;i++)
	{
		  if (document.request_tool.pointanalysis[i].checked)
		  {
				 Tool = document.request_tool.pointanalysis[i].value;
		  }
	}
	var Placetool= '';
	for (i=0;i<document.request_tool.placetool.length;i++)
	{
		  if (document.request_tool.placetool[i].checked)
		  {
				 Placetool = document.request_tool.placetool[i].value;
		  }
	}
	var Activities= '';
	for (i=0;i<document.request_tool.activities.length;i++)
	{
		  if (document.request_tool.activities[i].checked)
		  {
				 Activities = document.request_tool.activities[i].value;
		  }
	}
	var Comments = trim(document.getElementById('comments').value);
	var flag=true;
	if(Fname == '')
	{
		document.getElementById('errormessage').innerHTML =" First Name is mandatory";
		document.getElementById('bold_first').style.fontWeight ="bold";
		document.getElementById('fname').focus();
		return false;
		}
	if(!isValidName(Fname)){
		document.getElementById('errormessage').innerHTML =" Invalid First Name (Note: Apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_first').style.fontWeight ="bold";
		document.getElementById('fname').focus();
		return false;
	}
	
	if(isValidName(Fname)){
		document.getElementById('bold_first').style.fontWeight ="normal";
	}
	if(Lname == '')
	{
		document.getElementById('errormessage').innerHTML =" Last Name is mandatory";
		document.getElementById('bold_last').style.fontWeight ="bold";
		document.getElementById('lname').focus();
		return false;
		}
	if(!isValidName(Lname)){
		document.getElementById('errormessage').innerHTML =" Invalid Last Name (Note: Apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_last').style.fontWeight ="bold";
		document.getElementById('lname').focus();
		return false;
	}
	
	if(isValidName(Lname)){
		document.getElementById('bold_last').style.fontWeight ="normal";
	}
	
	if(Title == '')
	{
		document.getElementById('errormessage').innerHTML =" Title is mandatory";
		document.getElementById('bold_title').style.fontWeight ="bold";
		document.getElementById('title').focus();
		return false;
		}
	if(!isValidName(Title)){
		document.getElementById('errormessage').innerHTML =" Invalid Title (Note: Apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_title').style.fontWeight ="bold";
		document.getElementById('title').focus();
		return false;
	}
	if(isValidName(Title)){
	document.getElementById('bold_title').style.fontWeight ="normal";	
	}
	
	if(Email == '')
	{
		document.getElementById('errormessage').innerHTML =" Email is mandatory";
		document.getElementById('bold_email').style.fontWeight ="bold";	
		document.getElementById('email').focus();
		return false;
		}
	if(!isValidEmail(Email, 'validate_request_tool')){
		document.getElementById('errormessage').innerHTML ="Invalid Email (Note: Apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_email').style.fontWeight ="bold";	
		if(flag!= false) document.getElementById('email').focus();
		return false;
	}
	if(isValidEmail(Email, 'validate_request_tool')){
	document.getElementById('bold_email').style.fontWeight ="normal";		
	}
	
	if(Organization == '')
	{
		document.getElementById('errormessage').innerHTML =" Organization is mandatory";
		document.getElementById('bold_organization').style.fontWeight ="bold";	
		document.getElementById('organization').focus();
		return false;
		}
	if(!isValidAddress(Organization)){
		document.getElementById('errormessage').innerHTML ="Invalid Organization (Note: Apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_organization').style.fontWeight ="bold";	
		document.getElementById('organization').focus();
		return false;
	}
	if(isValidAddress(Organization)){
		document.getElementById('bold_organization').style.fontWeight ="normal";	
	}
	
	if(Maddress1 == '')
	{
		document.getElementById('errormessage').innerHTML =" Address is mandatory";
		document.getElementById('bold_address').style.fontWeight ="bold";	
		document.getElementById('maddress1').focus();
		return false;
		}
	if(!isValidAddress(Maddress1)){
		document.getElementById('errormessage').innerHTML ="Invalid Address (Note: Apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_address').style.fontWeight ="bold";
		document.getElementById('maddress1').focus();
		return false;
	}
	
	if(isValidAddress(Maddress1)){
		document.getElementById('bold_address').style.fontWeight ="normal";
	}
	
	if(Maddress2!='')
	{
		if(!isValidAddress(Maddress2)){
			document.getElementById('errormessage').innerHTML ="Invalid Address";
			document.getElementById('maddress2').focus();
			return false;
		}
	}
	if(City == '')
	{
		document.getElementById('errormessage').innerHTML =" City is mandatory";
		document.getElementById('bold_city').style.fontWeight ="bold";
		document.getElementById('city').focus();
		return false;
		}
	if(!isValidAddress(City)){
		document.getElementById('errormessage').innerHTML ="Invalid City (Note: Apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_city').style.fontWeight ="bold";
		document.getElementById('city').focus();
		return false;
	}
	if(isValidAddress(City)){
		document.getElementById('bold_city').style.fontWeight ="normal";
	}
	
	if(State!='XX')
	{
		if(!isValidAddress(State)){
			document.getElementById('errormessage').innerHTML ="Invalid State";
			document.getElementById('bold_state').style.fontWeight ="bold";
			document.getElementById('state').focus();
			return false;
		}
	}
	else
	{
		if(!isValidAddress(State1)){
			document.getElementById('errormessage').innerHTML ="Invalid State";
			document.getElementById('state').focus();
			return false;
		}	
	}
	if(isValidAddress(State)){
		document.getElementById('bold_state').style.fontWeight ="normal";
	}
	
	if(State =='Non-USA'  && Country=='United States')
	{
		document.getElementById('errormessage').innerHTML='Invalid Country (States and Countries must correspond';		
		document.getElementById('country').focus();
		return false;
	}
	
	if(State !='Non-USA'  && Country !='United States')
	{
		document.getElementById('errormessage').innerHTML='Invalid Country (States and Countries must correspond';		
		document.getElementById('country').focus();
		return false;
	}
	
	if(State =='Non-USA')
	{
		if(State1!='')
		{
			if(!isValidTitle(State1)){
				document.getElementById('errormessage').innerHTML ="Invalid State (Note: Apostrophes, single quotes, and double quotes are invalid!)";
				document.getElementById('state1').focus();
				return false;
			}	
		}
	}
	
	if(Postalcode == '')
	{
		document.getElementById('errormessage').innerHTML =" Postalcode is mandatory";
		document.getElementById('bold_zip').style.fontWeight ="bold";
		document.getElementById('postalcode').focus();
		return false;
		}
	if(!isValidZip(Postalcode)){
		document.getElementById('errormessage').innerHTML='Invalid ZIP/Postal Code';
		document.getElementById('bold_zip').style.fontWeight ="bold";
		document.getElementById('postalcode').focus();
		return false;
	}
	if(isValidZip(Postalcode)){
		document.getElementById('bold_zip').style.fontWeight ="normal";
	}
	
	if(Phone == '')
	{
		document.getElementById('errormessage').innerHTML =" Phone is mandatory";
		document.getElementById('bold_phone').style.fontWeight ="bold";
		document.getElementById('phone').focus();
		return false;
		}
	
	if(!isValidPhone(Phone)){
		document.getElementById('errormessage').innerHTML="Invalid Phone";
		document.getElementById('bold_phone').style.fontWeight ="bold";
		document.getElementById('phone').focus();
		return false;
	}
	if(isValidPhone(Phone)){
		document.getElementById('bold_phone').style.fontWeight ="normal";	
	}
	
	
	if(Fax!='')
	{
		if(!isValidPhone(Fax))
		{
			document.getElementById('errormessage').innerHTML="Invalid Fax";
			if(flag!= false) document.getElementById('fax').focus();
			return false;
		}
	}
	if(Website!='')
	{
		if(!checkURL(Website))
		{
			document.getElementById('errormessage').innerHTML="Invalid website";
			if(flag!= false) document.getElementById('website').focus();
			return false;
		}
	}
	if(Activities=='Other')
		Activities =document.getElementById('activities1').value;	
		
	if(Comments!='')
	{
		if(!isValidAddress(Comments)){
			document.getElementById('errormessage').innerHTML ="Invalid Comment (Note: Apostrophes, single quotes, and double quotes are invalid!)";
			document.getElementById('bold_organization').style.fontWeight ="bold";	
			document.getElementById('comments').focus();
			return false;
		}
	}
	
	if(isValidAddress(Comments)){
		document.getElementById('comments').style.fontWeight ="normal";
	}
	
	if(captcha == '')
	{
		document.getElementById('newslettermessage').innerHTML =" Captcha is mandatory";
		document.getElementById('txtFCaptcha').focus();
		return false;
		}
		
//------------------- New confirmation code added by QP request G.Pina 3/8/2011 -------------------
/*var answer = confirm('By clicking on the OK button you are agreeing to be contacted by a Q/P representative to receive the product installation key and a demonstration of the selected product(s).   Thank you.');
if (answer == 0){
		window.location = "main_pdts.html";
		return false;
	}
	*/
	if (v_value != 1){
		example();
	}
	
		var productElement = document.getElementById("lertWindow");
		if (productElement != null){
			// Code here when the Element Exists.
			return false;
		}
//------------------- END new confirmation code -------------------
			
	querystring ="pqmplus="+Pqmplus+"&smr="+Smr+"&charismatek="+Charismatek+"&fname="+Fname+"&lname="+Lname+"&title="+Title+"&organization="+Organization+"&maddress1="+Maddress1+"&maddress2="+Maddress2+"&city="+City+"&state="+State+"&state1="+State1+"&postalcode="+Postalcode+"&country="+Country+"&phone="+Phone+"&email="+Email+"&fax="+Fax+"&website="+Website+"&tool="+Tool+"&plantool="+Plantool+"&pointanalysis="+Pointanalysis+"&placetool="+Placetool+"&activities="+Activities+"&comments="+Comments+"&captcha="+captcha;
	url= 'sendMail.php?option=request_tool&'+querystring;
	if(xmlhttp){
		xmlhttp.open('POST',url,true);
		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		xmlhttp.onreadystatechange = httprequest_tool_validate;
		xmlhttp.send(null);
	}
	return false;
}
function httprequest_tool_validate(){
	if (xmlhttp.readyState != 4){
		document.getElementById('spinner').innerHTML = "<img src='images/busy.gif' alt='Loading...'>";
	}
	else{
		mytext = xmlhttp.responseText;
		//alert(mytext);
		//document.getElementById('spinner').innerHTML = mytext;
		 var dwn_msg = '';
		mytext=mytext.split('|');
		if(mytext[1]=='Yes' && mytext[2]=='Yes'){
			var loc = "thank_you_all_tool.html";
			//window.open('All_software.zip','a');
			 //dwn_msg = "true";
		}
		else if(mytext[1]=='Yes'){
			var loc = "thank_you_pqmplus.html";
			//window.open('PQMPlus.zip','a');
			//dwn_msg = "true";
		}
		else if(mytext[2]=='Yes'){	
			var loc = "thank_you_smr.html";
			//window.open('zipfile2.zip','b');
			//dwn_msg = "true";
		}
		else
		{
		var loc = "thankyou.php?option=request_tool&dwn_msg=true"
		}
		//popitup(mytext[1],mytext[2]);
       
/*        if(mytext[1]=='Yes' || mytext[2]=='Yes')
            dwn_msg = "true";
			*/
		if(mytext[0] == 'success'){
			/*window.location="thankyou.php?option=request_tool&dwn_msg="+dwn_msg+"&pqm="+mytext[1]+"&smr="+mytext[2];*/
			//window.location="thankyou.php?option=request_tool&dwn_msg="+dwn_msg;
			window.location= loc;
		}else {
			document.getElementById('spinner').innerHTML = "";
			document.getElementById("newslettermessage").innerHTML = mytext;
			//document.getElementById('fname').focus();
		}
	}
}

function reset_tool()
{
	document.getElementById('errormessage').innerHTML=''; 
	/*if(document.getElementById('option_from').value!=1)
	{
		document.getElementById('email').value = '';
	}*/
	document.getElementById('txtFCaptcha').value = '';
	document.getElementById('pqmplus').checked= false;
	document.getElementById('smr').checked= false;
	document.getElementById('charismatek').checked= false;
	document.getElementById('fname').value = '' ;
	document.getElementById('lname').value = '' ;
	document.getElementById('title').value = '';
	document.getElementById('organization').value = '';
	document.getElementById('maddress1').value= '';
	document.getElementById('maddress2').value = '';
	document.getElementById('city').value = '';
	document.getElementById('state').value = '';
	document.getElementById('state1').value= '';
	document.getElementById('postalcode').value = '';
	document.getElementById('country').value = '';
	document.getElementById('phone').value = '';
	document.getElementById('email').value='';
	document.getElementById('fax').value='';
	document.getElementById('website').value='';
	document.getElementById('i_search').checked= false;
	document.getElementById('i_website').checked= false;
	document.getElementById('conference').checked= false;
	document.getElementById('other_request').checked= false;
	document.getElementById('tool1').value = '';
	document.getElementById('fp_analysis').checked= false;
	document.getElementById('p_management').checked= false;
	document.getElementById('p_estimation').checked= false;
	document.getElementById('pointanalysis').checked= false;
	document.getElementById('placetool').checked= false;
	document.getElementById('activities').checked= false;
	document.getElementById('comments').value = '';
}
function showtool(str)
{
	if(str.checked)
		document.getElementById('tooltext').style.display = "";
	else
		document.getElementById('tooltext').style.display = "none";
	/*	document.getElementById('tooltext').style.display='block';
	else
		document.getElementById('tooltext').style.display='none';*/
}

function showactivities(str)
{
	if(str=='Other')
		document.getElementById('activitiestext').style.display='block';
	else
		document.getElementById('activitiestext').style.display='none';
}

function showHint(str,type)
{
	if (str.length==0)
  	{ 
		return false;
  	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		return false;
  	} 
	var url= 'sendMail.php?option='+type;
	url=url+"&email="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function chkExistMail(str,type)
{
	if (str.length==0)
  	{ 
		return false;
  	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  		return false;
  	} 
	var url= 'sendMail.php?option='+type;
	url=url+"&email="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged2;
		xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
    {
  		// Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
  	}
	catch (e)
  	{
  		// Internet Explorer
  		try
    	{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
  		catch (e)
    	{
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
  	}
	return xmlHttp;
}
function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		//document.getElementById("errormessage").innerHTML=xmlHttp.responseText;
		if(xmlHttp.responseText=='success')
		{
			alert("Mail id already Exist");
			document.getElementById('textemail').value='';	
			return false;
		}
		else
		{
			document.forms[0].action='moreinfo.html';
			document.forms[0].submit();	
		}
	}
}
function stateChanged2() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		//document.getElementById("errormessage").innerHTML=xmlHttp.responseText;
		if(xmlHttp.responseText=='success')
		{
			document.getElementById("errormessage").innerHTML="Mail id already Exist";
			document.getElementById('email').value='';	
			return false;
		}
	}
}
function newsletter() {
	txtemail = trim(document.getElementById('textemail').value);
	//Email Start--------
	validRegExpemailid = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	// search email text for regular exp matches
	if (txtemail.search(validRegExpemailid) == -1)
	{
		alert("Invalid E-mail Address! Please re-enter.");
		document.getElementById('textemail').focus();
	}
	//Email End-------
	else
		{
			document.qpmgform.action='moreinfo.html';
			document.qpmgform.submit();	
			//showHint(txtemail,'validate_newsletter')
		}	
}
function request_tool() {
	var request_tool = trim(document.getElementById('myselectbox').value);
	// search email text for regular exp matches
	if (request_tool == '')
	{
		alert("Choose Card.");
		document.getElementById('myselectbox').focus();
	}
	//Email End-------
	else
		{
			document.qpmgform.action='moreinfo.html';
			document.qpmgform.submit();	
		}	
}
function popitup(pqm,smr) {
	//newwindow=window.open(url,'Download','height=200,width=150');
	alert("hi");
	if(pqm=='Yes')
		window.open('PQMPlus.zip','a');
	if(smr=='Yes')
		window.open('zipfile2.zip','b');
	/*if (window.focus) {newwindow.focus()}*/
	return false;
}
function fcall()
{
	document.getElementById('imgFCaptcha').src = 'fcreate_image.php?id='+Math.random() * 3;
}


function email_validate()
{

var textemail = document.getElementById('textemail').value;

if(!isValidEmail(textemail, 'news_subscription')){
		//document.getElementById('error_message').innerHTML ="Invalid Email";
		alert("Enter Valid Email");
		document.getElementById('textemail').focus();
		return false;
	}
	
	document.qpmgform.action='sendMail.php?email='+textemail;
	document.qpmgform.submit();
	return true;
	
	
/*	querystring ="textemail="+textemail;
	
    var url= 'sendMail.php?option=email&'+querystring;
	return false;*/

}

function newsletter_subscribe()
{

    var txtemail   = document.getElementById('textemail').value;

    var txtCaptcha = document.getElementById('txtFCaptcha').value;
    
    if(!isValidEmail(txtemail, 'news_subscription')){
        alert("Enter Valid E-mail address");
        document.getElementById('textemail').focus();
        return false;
    }else if(txtCaptcha == "" || txtCaptcha == "Security code"){
        alert("Enter Valid Security code");
        document.getElementById('txtFCaptcha').focus();
        return false;
    }else{    
        //Modalbox.show('sendMail.php', {width: 500, params:Form.serialize('frmNewsletter') });
		Modalbox.show('Subscribe to Newsletter','../sendMail.php', {width: 500, height: 250, params:Form.serialize('frmNewsletter')});
        return false;
    }	

}

	function empty_moreinfo()
	{
	var r = confirm("Do you really want to purge");
	if(r) {
		window.location = "truncate_table.php?option=news";
	}
	
	}
	function empty_request()
	{
	var r = confirm("Do you really want to purge");
	if(r) {
		window.location = "truncate_table.php?option=request_tool";
	}
	
	}
	function empty_news()
	{
	var r = confirm("Do you really want to purge");
	if(r) {
		window.location = "truncate_table.php?option=newsletter_subscribe";
	}
	
	}
	
//*********************************************************************************


function Lert(message, buttons, options) {
	this.message_ = message;
	this.buttons_ = buttons;
	this.defaultButton_ = options.defaultButton || this.buttons_[0];
	this.icon_ = options.icon || null;
}

Lert.prototype.display = function() {
	var body = document.getElementsByTagName ('BODY')[0];
	var pageScroll = getPageScroll();
	var pageSize = getPageSize();

	//create the overlay if necessary
	var overlay = document.getElementById('lertOverlay');
	
	if(!overlay) {
		var overlay = document.createElement("div");
		overlay.setAttribute('id','lertOverlay');
		overlay.style.display = 'none';
		body.appendChild(overlay);
	}
	
	

	//position and show the overlay
	overlay.style.height=pageSize[1]+'px';
	overlay.style.display='block';

	//create the container if necessary
	var container = document.getElementById('lertContainer');
	if(!container) {
		var container = document.createElement("div");
		container.setAttribute('id','lertContainer');
		container.style.display = 'none';
		body.appendChild(container);
	}

	//position and show the container
	container.style.top = ( pageScroll[1] + (pageSize[3] / 15) ) + 'px';
	container.style.display = 'block';

	//create the window
	var win = document.createElement('div');
	win.setAttribute('id','lertWindow');

	//create the optional icon
	if(this.icon_ != null) {
		var icon = document.createElement('img');
		icon.setAttribute('src',this.icon_);
		icon.setAttribute('id','lertIcon');
		icon.setAttribute('alt','');
		win.appendChild(icon);
	}

	//create the message space
	var message = document.createElement('p');
	message.setAttribute('id','lertMessage');
	message.innerHTML = this.message_;
	win.appendChild(message);

	//create the button space
	var buttons = document.createElement('div');
	buttons.setAttribute('id','lertButtons');

	var oldKeyDown = document.onkeydown;

	//add each button
	for(i in this.buttons_) {
		var button = this.buttons_[i];
		if(button.getDom) {
			var domButton = button.getDom(function() {
				container.style.display = 'none';
				overlay.style.display = 'none';
				document.onkeydown=oldKeyDown;
				container.innerHTML = '';
				button.onclick_;
			},this.defaultButton_);
			buttons.appendChild(domButton);
		}
	}
	win.appendChild(buttons);

	document.onkeydown = this.keyboardControls;

	//append the window
	container.appendChild(win);
}

Lert.prototype.keyboardControls = function(e) {
	if (e == null) { keycode = event.keyCode; } // ie
	else { keycode = e.which; } // mozilla
	if(keycode==13) { document.getElementById('lertDefaultButton').onclick(); }
}

function LertButton(label, event, options) {
	this.label_ = label;
	this.onclick_ = event;
	this.eventClick = function() {};
}

LertButton.prototype.getDom = function(eventCleanup,defaultButton) {
	var button = document.createElement('a');
	button.setAttribute('href','javascript:void(0);');
	button.className = 'lertButton';
	if(this == defaultButton) button.setAttribute('id','lertDefaultButton');
	button.innerHTML = this.label_;

	var eventOnclick =  this.onclick_;
	button.onclick = function() {
		eventCleanup();
		eventOnclick();
	}
	this.eventClick = button.onclick;
	return button;
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}


//------------------------------------ NEW validation for library registration --------------------------------------
function library_registration(v_value){	
	document.getElementById('errormessage').innerHTML=''; 
	document.getElementById('newslettermessage').innerHTML ='';
	
	var Optin = '';
	if(document.getElementById('optin').checked){
		Optin = 'Y';
	}else{
		Optin = 'N';
	}
	
	var captcha = '';
	var captcha = trim(document.getElementById('txtFCaptcha').value);

	var Fname = trim(document.getElementById('fname').value);
	var Lname = trim(document.getElementById('lname').value);
	var Email = trim(document.getElementById('email').value);
	var Username = trim(document.getElementById('username').value);
	var Password = trim(document.getElementById('password').value);
	var Phone = trim(document.getElementById('phone').value);
	var Title = trim(document.getElementById('title').value);
	var Organization = trim(document.getElementById('organization').value);
	var Industry = trim(document.getElementById('industry').value);
	var Maddress1 = trim(document.getElementById('maddress1').value);
	var Maddress2 = trim(document.getElementById('maddress2').value);
	var City = trim(document.getElementById('city').value);
	var State = trim(document.getElementById('state').value);
	var State1 = trim(document.getElementById('state1').value);
	var Postalcode = trim(document.getElementById('postalcode').value);
	var Country = trim(document.getElementById('country').value);
	var flag=true;
	
	//----------- First Name validation -----------
	if(Fname == ''){
		document.getElementById('errormessage').innerHTML =" First Name is mandatory";
		document.getElementById('bold_first').style.fontWeight ="bold";
		document.getElementById('fname').focus();
		return false;
		}
	if(!isValidName(Fname)){
		document.getElementById('errormessage').innerHTML =" Invalid First Name (Note: Special characters, apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_first').style.fontWeight ="bold";
		document.getElementById('fname').focus();
		return false;
	}
	if(isValidName(Fname)){
		document.getElementById('bold_first').style.fontWeight ="normal";
	}
	
	//----------- Last Name validation -----------
	if(Lname == '')
	{
		document.getElementById('errormessage').innerHTML =" Last Name is mandatory";
		document.getElementById('bold_last').style.fontWeight ="bold";
		document.getElementById('lname').focus();
		return false;
		}
	if(!isValidName(Lname)){
		document.getElementById('errormessage').innerHTML =" Invalid Last Name (Note: Special characters, apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_last').style.fontWeight ="bold";
		document.getElementById('lname').focus();
		return false;
	}
	if(isValidName(Lname)){
		document.getElementById('bold_last').style.fontWeight ="normal";
	}
	
	//----------- Email Validation -----------
	if(Email == '')
	{
		document.getElementById('errormessage').innerHTML =" Email is mandatory";
		document.getElementById('bold_email').style.fontWeight ="bold";	
		document.getElementById('email').focus();
		return false;
		}
	if(!isValidEmail(Email, 'validate_request_tool')){
		document.getElementById('errormessage').innerHTML ="Invalid Email (Note: Apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_email').style.fontWeight ="bold";	
		if(flag!= false) document.getElementById('email').focus();
		return false;
	}
	
	if(isValidEmail(Email, 'validate_request_tool')){
	document.getElementById('bold_email').style.fontWeight ="normal";		
	}
	
	//----------- Phone validation -----------
	if(Phone!='')
	{
		if(!isValidPhone(Phone)){
			document.getElementById('errormessage').innerHTML="Invalid Phone";
			document.getElementById('bold_phone').style.fontWeight ="bold";
			document.getElementById('phone').focus();
			return false;
		}
	}
	
	if(isValidPhone(Phone)){
		document.getElementById('bold_phone').style.fontWeight ="normal";	
	}
	
	//---------- Title validation -----------
	if(Title!='')
	{
		if(!isValidName(Title)){
			document.getElementById('errormessage').innerHTML =" Invalid Title (Note: Apostrophes, single quotes, and double quotes are invalid!)";
			document.getElementById('bold_title').style.fontWeight ="bold";
			document.getElementById('title').focus();
			return false;
		}
	}
	if(isValidName(Title)){
	document.getElementById('bold_title').style.fontWeight ="normal";	
	}
	
	//---------- Organization validation -----------
	if(Organization!='')
	{
		if(!isValidAddress(Organization)){
			document.getElementById('errormessage').innerHTML ="Invalid Organization (Note: Apostrophes, single quotes, and double quotes are invalid!)";
			document.getElementById('bold_organization').style.fontWeight ="bold";	
			document.getElementById('organization').focus();
			return false;
		}
	}
	if(isValidAddress(Organization)){
		document.getElementById('bold_organization').style.fontWeight ="normal";	
	}
	
	//---------- Industry validation -----------
	if(Industry!='')
	{
		if(!isValidAddress(Industry)){
			document.getElementById('errormessage').innerHTML ="Invalid Industry (Note: Apostrophes, single quotes, and double quotes are invalid!)";
			document.getElementById('bold_industry').style.fontWeight ="bold";	
			document.getElementById('industry').focus();
			return false;
		}
	}
	if(isValidAddress(Organization)){
		document.getElementById('bold_organization').style.fontWeight ="normal";	
	}
	
	//---------- Mail Address 1 validation -----------
	if(Maddress1!='')
	{
		if(!isValidAddress(Maddress1)){
			document.getElementById('errormessage').innerHTML ="Invalid Address (Note: Apostrophes, single quotes, and double quotes are invalid!)";
			document.getElementById('bold_address').style.fontWeight ="bold";
			document.getElementById('maddress1').focus();
			return false;
		}
	}
	if(isValidAddress(Maddress1)){
		document.getElementById('bold_address').style.fontWeight ="normal";
	}
	
	//---------- Mail Address 2 validation -----------
	if(Maddress2!='')
	{
		if(!isValidAddress(Maddress2)){
			document.getElementById('errormessage').innerHTML ="Invalid Address";
			document.getElementById('maddress2').focus();
			return false;
		}
	}
	if(isValidAddress(Maddress2)){
		document.getElementById('bold_address2').style.fontWeight ="normal";
	}
	
	//---------- City validation -----------
	if(City!='')
	{
		if(!isValidAddress(City)){
			document.getElementById('errormessage').innerHTML ="Invalid City (Note: Apostrophes, single quotes, and double quotes are invalid!)";
			document.getElementById('bold_city').style.fontWeight ="bold";
			document.getElementById('city').focus();
			return false;
		}
	}
	if(isValidAddress(City)){
		document.getElementById('bold_city').style.fontWeight ="normal";
	}
	
	//---------- State validation -----------
	if(State1!='')
	{
		if(!isValidAddress(State1)){
			document.getElementById('errormessage').innerHTML ="Invalid State";
			document.getElementById('state1').style.fontWeight ="bold";
			document.getElementById('state1').focus();
			return false;
		}	
		if(State !='Non-USA'){
			document.getElementById('errormessage').innerHTML ="Invalid State";
			document.getElementById('state1').style.fontWeight ="bold";
			document.getElementById('state1').focus();
			return false;
		}
		if(Country=='United States'){
			document.getElementById('errormessage').innerHTML ="Invalid State";
			document.getElementById('state1').style.fontWeight ="bold";
			document.getElementById('state1').focus();
			return false;
		}
	}
	if(isValidAddress(State1)){
		document.getElementById('bold_state1').style.fontWeight ="normal";
	}
	
	//---------- Country validation -----------
	if(State =='Non-USA'  && Country=='United States')
	{
		document.getElementById('errormessage').innerHTML='Invalid Country (States and Countries must correspond';		
		document.getElementById('country').focus();
		return false;
	}
	
	if(State !='Non-USA'  && Country !='United States')
	{
		document.getElementById('errormessage').innerHTML='Invalid Country (States and Countries must correspond';		
		document.getElementById('country').focus();
		return false;
	}
	
	
	//---------- Zip Code validation -----------
	if(Postalcode!='')
	{
		if(!isValidZip(Postalcode)){
			document.getElementById('errormessage').innerHTML="Invalid ZIP/Postal Code. Must be between 5 and 10 letters and numbers.";
			document.getElementById('bold_zip').style.fontWeight ="bold";
			document.getElementById('postalcode').focus();
			return false;
		}
	}
	if(isValidZip(Postalcode)){
		document.getElementById('bold_zip').style.fontWeight ="normal";
	}
	
	
	//---------- Username validation -----------
	if(Username == '')
	{
		document.getElementById('errormessage').innerHTML =" User Name is mandatory";
		document.getElementById('bold_username').style.fontWeight ="bold";
		document.getElementById('username').focus();
		return false;
		}
		
	if(!isValidUserName(Username)){
		document.getElementById('errormessage').innerHTML =" Invalid User Name (Note: Special characters, apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_username').style.fontWeight ="bold";
		document.getElementById('username').focus();
		return false;
	}
	if(isValidName(Username)){
		document.getElementById('bold_username').style.fontWeight ="normal";
	}
	
	//---------- Password validation -----------
	if(Password == '')
	{
		document.getElementById('errormessage').innerHTML ="Password is mandatory";
		document.getElementById('bold_password').style.fontWeight ="bold";
		document.getElementById('password').focus();
		return false;
		}
		
	if(!isValidUserName(Password)){
		document.getElementById('errormessage').innerHTML ="Invalid Password (Note: Special characters, apostrophes, single quotes, and double quotes are invalid!)";
		document.getElementById('bold_password').style.fontWeight ="bold";
		document.getElementById('password').focus();
		return false;
	}
	if(isValidUserName(Password)){
		document.getElementById('bold_password').style.fontWeight ="normal";
	}
	
	//---------- Captcha validation -----------
	if(captcha == ''){
		document.getElementById('newslettermessage').innerHTML =" Captcha is mandatory";
		document.getElementById('txtFCaptcha').focus();
		return false;
	}
	
	
	/* Confirmation Code removed per QP request. Temp functionality goes to Thank you page
	//------------------- Confirmation Drop-Down -------------------
		if (v_value != 1){
			example();
		}
		else
		{
			//TEMP redirect
			window.location = "user_admin.html?&fname="+Fname+"&lname="+Lname+"&title="+Title+"&organization="+Organization+"&maddress1="+Maddress1+"&maddress2="+Maddress2+"&city="+City+"&state="+State+"&state1="+State1+"&postalcode="+Postalcode+"&country="+Country+"&phone="+Phone+"&email="+Email;
		}

		
		var productElement = document.getElementById("lertWindow");
		if (productElement != null){
			// Code here when the Element Exists.
			return false;
		}
	//------------------- END confirmation drop-down -------------------
	END confirmation change */
	
	querystring ="&fname="+Fname+"&lname="+Lname+"&title="+Title+"&organization="+Organization+"&maddress1="+Maddress1+"&maddress2="+Maddress2+"&city="+City+"&state="+State+"&state1="+State1+"&postalcode="+Postalcode+"&country="+Country+"&phone="+Phone+"&email="+Email+"&industry="+Industry+"&username="+Username+"&password="+Password+"&optin="+Optin+"&captcha="+captcha;
	url= '../sendMail.php?option=register_user&'+querystring;	
	if(xmlhttp){
		xmlhttp.open('POST',url,true);
		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		xmlhttp.onreadystatechange = register_validate;
		xmlhttp.send(null);
	}
	
	return false;
	

}

//----------------------- USER Options Edit code ------------------------------
function user_option_edit()
{

    var Username = trim(document.getElementById('username').value);
	var Password = trim(document.getElementById('password').value);
    
	if(Username == ''){
		alert("Username is mandatory");
		document.getElementById('username').focus();
		return false;
	}else if(Password == ''){
		alert("Password is mandatory");
		document.getElementById('password').focus();
		return false;
	}else if(!isValidUserName(Username)){
        alert("Enter Valid User Name!");
        document.getElementById('username').focus();
        return false;
    }else if(!isValidUserName(Password)){
        alert("Enter Valid Password! Note: Special characters, apostrophes, single quotes, and double quotes are invalid.");
        document.getElementById('password').focus();
        return false;
    }else{    
        //Modalbox.show('sendMail.php', {width: 500, params:Form.serialize('frmNewsletter') });
		Modalbox.show('Edit User Options','../sendMail.php', {width: 500, height: 250, params:Form.serialize('frmEditOptions')});
        return false;
    }	

}


//----------------------- USER Info Edit code ------------------------------
function user_info_edit()
{
	var Fname = trim(document.getElementById('fname').value);
	var Lname = trim(document.getElementById('lname').value);
	var Email = trim(document.getElementById('email').value);
	var Phone = trim(document.getElementById('phone').value);
	var Title = trim(document.getElementById('title').value);
	var Organization = trim(document.getElementById('organization').value);
	var Industry = trim(document.getElementById('industry').value);
	var Maddress1 = trim(document.getElementById('maddress1').value);
	var Maddress2 = trim(document.getElementById('maddress2').value);
	var City = trim(document.getElementById('city').value);
	var State = trim(document.getElementById('state').value);
	var State1 = trim(document.getElementById('state1').value);
	var Postalcode = trim(document.getElementById('postalcode').value);
	var Country = trim(document.getElementById('country').value);
	var flag=true;
	
	//----------- First Name validation -----------
	if(Fname == ''){
		alert("First Name is mandatory");
		document.getElementById('fname').focus();
		return false;
		}
	if(!isValidName(Fname)){
		alert("Invalid First Name! Note: Special characters, apostrophes, single quotes, and double quotes are invalid!");
		document.getElementById('fname').focus();
		return false;
	}

	//----------- Last Name validation -----------
	if(Lname == '')
	{
		alert("Last Name is mandatory");
		document.getElementById('lname').focus();
		return false;
	}
	if(!isValidName(Lname)){
		alert("Invalid Last Name (Note: Special characters, apostrophes, single quotes, and double quotes are invalid!)");
		document.getElementById('lname').focus();
		return false;
	}
	
	//----------- Email Validation -----------
	if(Email == '')
	{
		alert("Email is mandatory");
		document.getElementById('email').focus();
		return false;
		}
	if(!isValidEmail(Email, 'validate_request_tool')){
		alert("Invalid Email (Note: Apostrophes, single quotes, and double quotes are invalid!)");
		if(flag!= false) document.getElementById('email').focus();
		return false;
	}
	
	//----------- Phone validation -----------
	if(Phone!='')
	{
		if(!isValidPhone(Phone)){
			alert("Invalid Phone");
			document.getElementById('phone').focus();
			return false;
		}
	}
	
	//---------- Title validation -----------
	if(Title!='')
	{
		if(!isValidName(Title)){
			alert("Invalid Title (Note: Apostrophes, single quotes, and double quotes are invalid!)");
			document.getElementById('title').focus();
			return false;
		}
	}
	
	//---------- Organization validation -----------
	if(Organization!='')
	{
		if(!isValidAddress(Organization)){
			alert("Invalid Organization (Note: Apostrophes, single quotes, and double quotes are invalid!)");
			document.getElementById('organization').focus();
			return false;
		}
	}
	
	//---------- Industry validation -----------
	if(Industry!='')
	{
		if(!isValidAddress(Industry)){
			alert("Invalid Industry (Note: Apostrophes, single quotes, and double quotes are invalid!)");
			document.getElementById('industry').focus();
			return false;
		}
	}
	
	//---------- Mail Address 1 validation -----------
	if(Maddress1!='')
	{
		if(!isValidAddress(Maddress1)){
			alert("Invalid Address (Note: Apostrophes, single quotes, and double quotes are invalid!)");
			document.getElementById('maddress1').focus();
			return false;
		}
	}
	
	//---------- Mail Address 2 validation -----------
	if(Maddress2!='')
	{
		if(!isValidAddress(Maddress2)){
			alert("Invalid Address 2");
			document.getElementById('maddress2').focus();
			return false;
		}
	}
	
	//---------- City validation -----------
	if(City!='')
	{
		if(!isValidAddress(City)){
			alert("Invalid City (Note: Apostrophes, single quotes, and double quotes are invalid!)");
			document.getElementById('city').focus();
			return false;
		}
	}

	//---------- State validation -----------
	if(State1!='')
	{
		if(!isValidAddress(State1)){
			alert("Invalid State");
			document.getElementById('state1').focus();
			return false;
		}	
		if(State !='Non-USA'){
			alert("Invalid State. State(USA) must have Non-USA selected.");
			document.getElementById('state1').focus();
			return false;
		}
		if(Country=='United States'){
			alert("Invalid State if Country = United States.");
			document.getElementById('state1').focus();
			return false;
		}
	}
	
	//---------- Country validation -----------
	if(State =='Non-USA'  && Country=='United States')
	{
		alert("Invalid Country (States and Countries must correspond)");		
		document.getElementById('country').focus();
		return false;
	}
	
	if(State !='Non-USA'  && Country !='United States')
	{
		alert("Invalid Country (States and Countries must correspond)");		
		document.getElementById('country').focus();
		return false;
	}
	
	
	//---------- Zip Code validation -----------
	if(Postalcode!='')
	{
		if(!isValidZip(Postalcode)){
			alert("Invalid ZIP/Postal Code. Must be between 5 and 10 letters and numbers.");
			document.getElementById('postalcode').focus();
			return false;
		}
	}

	Modalbox.show('Edit User Info','../sendMail.php', {width: 500, height: 250, params:Form.serialize('frmEditInfo')});
    return false;

}


function reset_library()
{
	document.getElementById('errormessage').innerHTML=''; 
	/*if(document.getElementById('option_from').value!=1)
	{
		document.getElementById('subscribe').checked = false;
		document.getElementById('email').value = '';
	}*/
	document.getElementById('txtFCaptcha').value = '';
	document.getElementById('fname').value = '' ;
	document.getElementById('lname').value = '' ;
	document.getElementById('title').value = '';
	document.getElementById('organization').value = '';
	document.getElementById('maddress1').value= '';
	document.getElementById('maddress2').value = '';
	document.getElementById('city').value = '';
	document.getElementById('state').value = '';
	document.getElementById('state1').value= '';
	document.getElementById('postalcode').value = '';
	document.getElementById('country').value = '';
	document.getElementById('phone').value = '';
	document.getElementById('email').value='';
	document.getElementById('username').value = '';
	document.getElementById('password').value = '';
}

	


