function changeCase(frmObj) {
var index;
var tmpStr;
var tmpChar;
var preString;
var postString;
var strlen;
tmpStr = frmObj.value.toLowerCase();
strLen = tmpStr.length;
if (strLen > 0)  {
for (index = 0; index < strLen; index++)  {
if (index == 0)  {
tmpChar = tmpStr.substring(0,1).toUpperCase();
postString = tmpStr.substring(1,strLen);
tmpStr = tmpChar + postString;
}
else {
tmpChar = tmpStr.substring(index, index+1);
if (tmpChar == " " && index < (strLen-1))  {
tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
preString = tmpStr.substring(0, index+1);
postString = tmpStr.substring(index+2,strLen);
tmpStr = preString + tmpChar + postString;
         }
      }
   }
}
frmObj.value = tmpStr;
}
	function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please Enter a Valid Email Address. Your appointment confirmation and followup details will be sent to this address.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please Enter a Valid Email Address. Your appointment confirmation and followup details will be sent to this address.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please Enter a Valid Email Address. Your appointment confirmation and followup details will be sent to this address.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please Enter a Valid Email Address. Your appointment confirmation and followup details will be sent to this address.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please Enter a Valid Email Address. Your appointment confirmation and followup details will be sent to this address.")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please Enter a Valid Email Address. Your appointment confirmation and followup details will be sent to this address.")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please Enter a Valid Email Address. Your appointment confirmation and followup details will be sent to this address.")
		    return false
		 }
 		 return true					
	}

function check_required(){
	var emailID=document.theForm.email;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter a Valid Email Address. Your appointment confirmation and followup details will be sent to this address.");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	
if ( document.theForm.fname.value == "" ) {
alert("You did not enter an answer for the field \'First Name\'! \n\nPlease complete this field and then press the Button to continue.");
document.theForm.fname.focus();
return false;
}
if ( document.theForm.lname.value == "" ) {
alert("You did not enter an answer for the field \'Last Name\'! \n\nPlease complete this field and then press the Button to continue.");
document.theForm.lname.focus();
return false;
}
if ( document.theForm.user2.value == "" ) {
alert("You did not enter an answer for the field \'Phone\'! \n\nPlease complete this field and then press the Button to continue.");
document.theForm.user2.focus();
return false;
}
if ( document.theForm.time_of_day.value == "" ) {
alert("You did not enter an answer for the field \'Best time of day for your phone consultation [SELECT ONE]\'! \n\nPlease complete this field and then press the Button to continue.");
document.theForm.time_of_day.focus();
return false;
}
if ( document.theForm.time_zone.value == "" ) {
alert("You did not enter an answer for the field \'Best time of day for your phone consultation [TIME ZONE]\'! \n\nPlease complete this field and then press the Button to continue.");
document.theForm.time_zone.focus();
return false;
}

changeCase(document.theForm.fname);
changeCase(document.theForm.lname);
document.theForm.user8.value = document.theForm.time_of_day.value + " " + document.theForm.time_zone.value;
if (document.theForm.user4.value == "")
{
document.theForm.user4.value = document.theForm.fname.value;
}
if (document.theForm.user5.value == "")
{
document.theForm.user5.value = document.theForm.lname.value;
}

// Code for the 1 day autoresponder, return to website
// Note, we are not using day 1 for health program support at this time
// var link1 = '';
// link1 = 'http://www.hairanalysiskit.com/customerservice/hpscontinue.htm?' + document.theForm.fname.value + '?' + document.theForm.email.value;
// document.theForm.user6.value = link1.replace(/ /g, "%20");

// Code for the 5 day autoresponder, discount link
// Note, we are not using a day 5 link at this time, just going directly to www.hairanalysiskit.com/41. The reason being, is we want to make this a time limited offer, and a direct link to paypal wouldn't allow that.
// The solution would be to create a modified page like in the 41 directory, that bounces people to paypal if the promotion isn't over.
// var link2 = '';
// discValue = (document.theForm.user3.value - 20);
// link2 = 'https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=web%40hairanalysiskit%2ecom&shipping=0%2e00&no_shipping=1&cancel_return=http%3a%2f%2fwww%2ehairanalysiskit%2ecom%2fconfirmations%2forder-cannot-be-confirmed%2ehtm&no_note=1&currency_code=USD&lc=CA&bn=PP-BuyNowBF&charset=UTF%2d8';
// link2 = link2 + '&return=http%3a%2f%2fwww%2ehairanalysiskit%2ecom%2fAR%2fsignup%2ephp?list=1&overwritedupes=1&email=' + document.theForm.email.value + '&fname=' + document.theForm.fname.value + '&user1=' + document.theForm.user1.value + '&user2=' + document.theForm.user2.value + '&user3=' + discValue + '&user4=' + document.theForm.user4.value + '&user5=' + document.theForm.user5.value;
// link2 = link2 + '&item_name=' + document.theForm.user1.value;
// link2 = link2 + '&item_number=' + document.theForm.user2.value;
// link2 = link2 + '&amount=' + discValue;
// document.theForm.user7.value = link2.replace(/ /g, "%20");

return true;
}
