var strMessage = new Array(13);
strMessage[0] = "Please enter first name";
strMessage[1] = "Please enter last name";
strMessage[2] = "Please enter information about your organization";
strMessage[3] = "Please enter website of your organization";
strMessage[4] = "Please enter your email address";
strMessage[5] = "Please enter telephone number";

strMessage[6] = "Subject cannot be more than 40 characters";
strMessage[7] = "Are you sure, want to send this email";
strMessage[8] = "Invalid Email Address, please enter a valid Email Address";

strMessage[9] = "Please enter type of industry";
strMessage[10] = "Please enter number of users";

strMessage[11] = "Please enter non-zero, positive numeric value";
strMessage[12] = "Please enter code displayed in image.";

/*
 * VinodP : Friendly advice : Don't forget to increase the size of strMessage
 * array when you add new messages :)
 */

function fnMailSend() {
	if (isEmptyTextBox(document.hwkContactForm.firstname, strMessage[0], false)) {
		return false;
	}

	if (isEmptyTextBox(document.hwkContactForm.lastname, strMessage[1], false)) {
		return false;
	}

	if (isEmptyTextBox(document.hwkContactForm.organization, strMessage[2],
			false)) {
		return false;
	}

//	 if ( isEmptyTextBox(document.hwkContactForm.website, strMessage[3], false)) {
//		
//	 return false;
//	 }

	if (isEmptyTextBox(document.hwkContactForm.emailid, strMessage[4], false)) {
		return false;
	}

	if (validateEmailAddress(document.hwkContactForm.emailid) == false) {
		return false;
	}

	// if ( isEmptyTextBox(document.hwkContactForm.telephone, strMessage[5],
	// false))
	// {
	// return false;
	// }

	// if ( isEmptyTextBox(document.hwkContactForm.industry, strMessage[9],
	// false))
	// {
	// return false;
	// }

	// if ( isEmptyTextBox(document.hwkContactForm.noOfUsers, strMessage[10],
	// false))
	// {
	// return false;
	// }
	//	
	// if ( isNotPositiveNumeric(document.hwkContactForm.noOfUsers,
	// strMessage[11], false, 0))
	// {
	// return false;
	// }
	
	if (isEmptyTextBox(document.hwkContactForm.captcha_code, strMessage[12], false))
	{
		return false;
	}	

	return true;
}


/**
 * Convert the given string into Html encoding
 */
function myHtmlEncode(str){
	var result = '';
	for (i = 0; i < str.length; i++) {
		result = result + '&#' + str.charCodeAt(i) + ';';
	}
	return result;
}


/**
 * Convert the given string into Url encoding.
 */
function myUrlEncode(str) {
	var result = "";
	var i = 0;

	for (i=0; i < str.length; i++) {
		result = result + "%";
		result = result + "0123456789ABCDEF".charAt((str.charCodeAt(i)/16)&0x0F);
		result = result + "0123456789ABCDEF".charAt((str.charCodeAt(i)/1)&0x0F);
	}
	return result;
}

/**
 * Opens popup mail window with given details
 */
function sendMailTo(sendToId, subject, body) {
	locationstring = "mailto:" + myUrlEncode(sendToId) + "?subject=" + escape(subject)
			+ "&body=" + escape(body);
	window.location.replace(locationstring);
}

/**
 * set the content of the body
 */
function setBody() {
	var body ="------------------------------------------------\n"
			+" Welcome to the Hawkeye evaluation Program!\n"
			+"------------------------------------------------\n" 
	
			+ "\nDear Sales Team,"
			+ "\nThis is a request for free evaluation of Hawkeye.\n"
			+ "\nFollowing is the quick information for your reference"
			+ "\n------------------------------------------------"

			// First Name
			+ "\nFirst name :: "
			+ document.hwkContactForm.firstname.value

			// Last Name
			+ "\nLast name :: "
			+ document.hwkContactForm.lastname.value

			// Organisation
			+ "\nOrganization :: "
			+ document.hwkContactForm.organization.value

			// Website
			+ "\nWebsite :: "
			+ document.hwkContactForm.website.value
			
			// Email Id
			+ "\nEmail Id :: "
			+ document.hwkContactForm.emailid.value

			// Telephone Number
			+ "\nTelephone :: " + document.hwkContactForm.telephone.value

			// Industry
			+ "\nIndustry :: " + document.hwkContactForm.industry.value

			// No. of users
			+ "\nNo. of users :: " + document.hwkContactForm.noofusers.value;
	
	// Online Trial/Demo
	body += "\nOnline Trial/Demo :: ";
	if (document.hwkContactForm.Online.checked == true) {
		body += "Yes";
	}

	// SAS (Low cost shared service)
	body += "\nSAS (Low cost shared service) :: ";
	if (document.hwkContactForm.SAS.checked == true) {
		body += "Yes";
	}

	// Inhouse Server/Installation
	body += "\nInhouse Server/Installation :: ";
	if (document.hwkContactForm.inhouse.checked == true) {
		body += "Yes";
	}

	// Personal Presentation from Sales team
	body += "\nPersonal Presentation from Sales team :: ";
	if (document.hwkContactForm.presentation.checked == true) {
		body += "Yes";
	}

	// Please describe what you are looking for
	body += "\nPlease describe what you are looking for :: "
			+ document.hwkContactForm.describe.value
			+ "\n------------------------------------------------"
			+ "\n[Mail generated from email client] "
			+ "\n\nThanks and Regards.";
	
	return body;
}

/**
 * Set the details and opens Mail popup
 */
function openPopupMailWindow() {

	// Check Validation
	if (!fnMailSend()) {
		return;
	}
	// set the contents of the popup windaow
	/*
	 var sendToId = "marketing@sutrasys.com";
	var subject = "Sutra Website : Product Enquiry : Hawkeye";

	// set Body of mail
	var body = setBody();
	
	// set details for popup mail window
	sendMailTo(sendToId, subject, body);
	*/
	
	// submitted to the server
	fnSubmitForm(document.hwkContactForm, "SendMail.php", "post", "_self");
	
}
