
theValidator.required("form_download_sample", "first_name", "Sorry, there's a little problem...a required field appears to be missing: Please enter your First Name","REGULAR");
theValidator.required("form_download_sample", "last_name", "Sorry, there's a little problem...a required field appears to be missing: Please enter your Last Name","REGULAR");
theValidator.required("form_download_sample", "company_name", "Sorry, there's a little problem...a required field appears to be missing: Please enter your Company Name","REGULAR");
theValidator.required("form_download_sample", "contact_email", "Sorry, there's a little problem...a required field appears to be missing: Please enter a valid Email Address","EMAIL");
theValidator.required("form_download_sample", "contact_phone", "Sorry, there's a little problem...a required field appears to be missing: Please enter a valid Contact Phone #","REGULAR");
theValidator.required("form_download_sample", "job_title", "Sorry, there's a little problem...a required field appears to be missing: Please enter a valid Title","REGULAR");

function ajGetSample(theBtn )
{
	var url = "/ajax/Sample/";

	var theForm = theBtn.form;
	if ( theValidator.validate( theForm ) ) {
		if ( streamChecked( theForm ) ) {

			var arrParams = Array();

			for ( i = 0; i < theForm.elements.length; i++ ) {
				var theElem = theForm.elements[i];

				if ( theElem.type == 'checkbox' && theElem.checked == true ) {
					arrParams.push( theElem.name + "=" + theElem.value );
				}
				else if ( theElem.type != 'checkbox' && theElem.value ) {
					arrParams.push( theElem.name + "=" + theElem.value );
				}
			}

			var params = arrParams.join( "&" );

                        var retURL = document.getElementById( 'retURL' );
                        retURL.value = 'http://www.realstorygroup.com/sf_return.html';

			SendToSF( theForm );
			makeHttpRequest(url, "cb_sample", 'POST', params, false);
		}
	}
}

function cb_sample( data )
{
	var ret = eval('(' + data + ')');

	if ( ret.Status == 'OK' ) {
		var body  = document.getElementById( 'sample-request-body' );
		var email = document.getElementById( 'contact_email' ).value;

		body.innerHTML = '<p>Your request has been processed successfully.  You should receive your sample(s) at <strong>' + email + '</strong> shortly.</p><br /><br /><a href="javascript:CloseSample();">Close</a>';

	}
	else {

		var err = document.getElementById( 'sample-error-message' );
		err.innerHTML = '<p>There was an error processing your request. Please verify your information and try again.</p>';
	}
}

function GetSample(theBtn )
{
	var theForm = theBtn.form;
	if ( theValidator.validate( theForm ) ) {
		if ( streamChecked( theForm ) ) {

			var ifr = document.getElementById( 'sfFrame' );
			if (ifr.addEventListener)
				ifr.addEventListener("load", SubmitSampleForm, false)
			else if (ifr.attachEvent){
				ifr.detachEvent("onload", SubmitSampleForm) // Bug fix line
				ifr.attachEvent("onload", SubmitSampleForm)
			}

			// var pageTracker = _gat._getTracker("UA-20950341-1");
			// pageTracker._trackPageview('/Sample/ThankYou');

                        var retURL = document.getElementById( 'retURL' );
                        retURL.value = 'http://www.realstorygroup.com/sf_return.html';

			SendToSF( theForm );
		}
	}
}

function SubmitSampleForm() {
	var frm = document.getElementById( 'form_sample_download' );
	if ( frm ) {
		frm.submit();
	}
}

function streamChecked( theForm ) {

	for ( i = 0; i < theForm.elements.length; i++ ) {

		var theElem = theForm.elements[i];

		if ( theElem.name != 'selected_reports[]' ) {
			continue;
		}

		if ( theElem.type == 'checkbox' ) {
			if ( theElem.checked == true ) {
				return true;
			}
		}
		else if ( theElem.value ) {
			return true;
		}
	}

	alert( "Please select at least one Research stream" );
	return false;
}

function ClearField( theField ) {

	if ( theField.value == theField.defaultValue ) {
		theField.value = '';
	}
}

function SetDefault( theField, blah ) {

	if ( theField.value == '' ) {
		theField.value = theField.defaultValue;
	}
}

function CloseSample() {

	var lightbox = {
		wrapper : '#lb-sample-form',
		content : $( '#lb-sample-form' + ' .lightbox-content' )
	}

	closeLightbox( lightbox );
}

