/*
	NOTES
		<storeComments> Place comments in hidden text field as cookie loop does not store textAreas and is therefore not passed
	DEBUG	
		document.write('<a href=\"' + dataToSend + '\">Test submission directly</a>');
		document.getElementById('ajax1').innerHTML = dataToSend;
		document.getElementById('ajax2').innerHTML = dataToSend;
	FILES
		Xsl_FSEcho/RequestForm.xslt
		o2Fsecho/www/JavascriptShell/Requestform.js	
		o2Fsecho/www/include/writeLeadToFS.asp
		fedsig/www/infoReqFromIntegratedSystems.asp
*/
var debugDisplay = false;	//Show debug display data: transaction still occurs
var testSubmissionDirectly = false;

function storeComments(){
	document.RequestForm.commentsTextBox.value = document.RequestForm.comments.value;
}
function submitDataToDatabase(){
	var dataToSend = document.RequestForm.AJAX_VAL.value;
	document.RequestForm.style.display = 'none';
	window.scrollTo(0,0);
	xmlhttpPost('/include/writeLeadToFS.asp','ajax1',dataToSend,'dataSubmittedReturnResults');
}
function dataSubmittedReturnResults(httpResults){
	var dataToSend = document.RequestForm.AJAX_VAL.value
	
	httpResults = unescape(httpResults);
	
	if(debugDisplay == true){
		document.getElementById('ajax1').innerHTML = httpResults; 
	}
	if((httpResults.indexOf('SENDING ERROR') != -1)){
		document.getElementById('errors').style.display = 'block';
	}else if(httpResults.indexOf('Insert Complete') != -1){
		var searchString = 'CONTACT_ID_FOR_EMAIL';
		var FedSigAWProfileIDStart = httpResults.indexOf(searchString);
		var FedSigAWProfileIDEnd = httpResults.indexOf('/' + searchString);
		var FedSigAWProfileID = httpResults.substring((FedSigAWProfileIDStart + (searchString.length + 1)),FedSigAWProfileIDEnd-1);
		var AWLink = '';

		if(siteUrl().indexOf('orbisdesign.net') != -1){
			AWLink = 'http://fedsigaw.orbisdesign.net/AWWeb/admin/AdminStart.asp?Page=4&View=5&ContactID=' + FedSigAWProfileID;
		}else{
			//AWLink = 'http://www.federalsignal-indust.com/AWWeb/admin/AdminStart.asp?Page=4&View=5&ContactID=' + FedSigAWProfileID;
			AWLink = 'http://aw.federalsignal-indust.com/AWWeb/admin/default_admin.asp?Page=4&View=5&ContactID=' + FedSigAWProfileID;
		}
		
		dataToSend = dataToSend.replace(/ReplaceWithDynamicLink/,escape(AWLink));
		
		if(testSubmissionDirectly){
			document.write('<a href=\"' + dataToSend + '\">Test submission directly</a>');
		}else{	
			document['ProcessForm'].src = dataToSend;
		}	
		document.getElementById('formThanks').style.display = 'block';
	}else{
		document.getElementById('errors').style.display = 'block';
	}
}
function setProductInterest(){
	if(getQueryVariable('productRfi') != '999'){
		document.RequestForm.product.value = unescape(getQueryVariable('productRfi'));
	}
}
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
  	}
	return "999";
}

