﻿// doExternalPost:for form post to aweber, infusion
function doExternalPost(targetUrl, theForm) {
    theForm.__VIEWSTATE.value = "";
    theForm.encoding = "application/x-www-form-urlencoded";
    theForm.action = targetUrl;
    theForm.target = '_new';
    theForm.submit();
}
//end external post function

//doExternalPostWithTarget:for form post to aweber, infusion
function doExternalPostWithTarget(targetUrl, theForm, target) {
    theForm.__VIEWSTATE.value = "";
    theForm.encoding = "application/x-www-form-urlencoded";
    theForm.action = targetUrl;
    theForm.target = target;
    theForm.submit();
}
//end external post function

// doExternalPostWithTargetVS:for form post to aweber, infusion
function doExternalPostWithTargetVS(targetUrl, theForm, target) {
    theForm.encoding = "application/x-www-form-urlencoded";
    theForm.action = targetUrl;
    theForm.target = target;
    theForm.submit();
}
//end external post function

// doExternalPostWithTargetPurl:for form post to aweber, infusion
function doExternalPostWithTargetPurl(targetUrl, theForm, target,  arNameField, arEmailField, extDomain, arRedirectId) {
    theForm.__VIEWSTATE.value = "";
    theForm.encoding = "application/x-www-form-urlencoded";
    theForm.action = targetUrl;
    theForm.target = target;

    if (extDomain == true) {
        //external domain cant use cookies so...
        //external domain so set the querystring of the
        //redirect hidden field and we use that to get the
        //name and email purl data
        document.getElementById(arRedirectId).value = document.getElementById(arRedirectId).value + '&fname=' + document.getElementById(arNameField).value + '&email=' + document.getElementById(arEmailField).value;
    }
    else {
        //siteBOSS domain so use cookies
        document.cookie = "arName=" + document.getElementById(arNameField).value;
        document.cookie = "arEmail=" + document.getElementById(arEmailField).value;
    }
    theForm.submit();
}
//end external post function

// for form post to 1shoppingCart with getSurveyAnswers()
function doExternalPostSurvey(targetUrl, theForm) {
    if (validateSurvey() == true) {
        theForm.__VIEWSTATE.value = "";
        theForm.encoding = "application/x-www-form-urlencoded";
        theForm.action = targetUrl;
        theForm.target = '_new';
        document.getElementById('field10').value = document.getElementById('field10').value + "\r\n\r\n" + document.getElementById('WHY').value + "\r\n\r\n" + document.getElementById('DELIGHT').value;
        theForm.submit();
        document.getElementById('field10').value = "";
        document.getElementById('WHY').value = "";
        document.getElementById('DELIGHT').value = "";
        return true;
    }
    return false;
}

// for form post to AWEBER with validateSurveyAWBR()
function doExternalPostSurveyAWBR(targetUrl, theForm) {
    if (validateSurveyAWBR('custom Student interest in the film was') == false) {
	alert("Please answer: Student interest in the film was...");
	return false;
    }

    if (validateSurveyAWBR('custom Student comprehension of the film was') == false) {
	alert("Please answer: Student comprehension of the film was...");
	return false;
    }
	
    if (validateSurveyAWBR('custom Interest in participating in future START virtual interactive opportunities with my students') == false) {
	alert("Please answer: Interest in participating in future START virtual interactive opportunities with my students...");
	return false;
    }


    if (validateSurveyAWBR('custom Interest in participating in future START marine environmental projects with my students') == false) {
	alert("Please answer: Interest in participating in future START marine environmental projects with my students...");
	return false;
    }


    if (document.getElementById('awf_field-939689').value.length == 0) {
	alert("Please enter your first and last name...");
	return false;
    }


    if (document.getElementById('awf_field-939690').value.length == 0) {
	alert("Please enter your school name...");
	return false;
    }


    if (document.getElementById('awf_field-939691').value.length == 0) {
	alert("Please enter email address...");
	return false;
    }

    theForm.__VIEWSTATE.value = "";
    theForm.encoding = "application/x-www-form-urlencoded";
    theForm.action = targetUrl;
    theForm.target = '_new';
    theForm.submit();
    return true;

}

function validateSurveyAWBR(rbname) {

var rb = document.getElementsByName(rbname);

chosen = "";
len = rb.length;

	for (i = 0; i <len; i++) {
		if (rb[i].checked) {
		chosen = rb[i].value;
		}
 	}

	if (chosen == "") {
		return false;
	}
	else {
		
		return true;
	}
}

function validateSurvey() {
    if (document.getElementById('field10').value.length == 0) {
        alert("Please enter all required data...");
        return false;
    }

    if (document.getElementById('WHY').value.length == 0) {
        alert("Please enter all required data...");
        return false;
    }

    if (document.getElementById('DELIGHT').value.length == 0) {
        alert("Please enter all required data...");
        return false;
    }
    return true;
}
//end survey function