//	VARS
var strRequestTypeError = "Please select at least one request type.\n";

function fAJAXRequest(strTarget,strURL,ajaxData) {
	//alert(ajaxData);
strURL = strURL+ajaxData
//alert(strURL);
	if(window.XMLHttpRequest) {
		oRequest = new XMLHttpRequest();
		oTarget = strTarget;
		oRequest.onreadystatechange = fAJAXChangeWhenReady;
		oRequest.open("GET", strURL, true);
		oRequest.send(null);
	} else if(window.ActiveXObject) {
		oRequest = new ActiveXObject("Microsoft.XMLHTTP");
		if(oRequest) {
			oTarget = strTarget;
			oRequest.onreadystatechange = fAJAXChangeWhenReady;
			oRequest.open("GET", strURL, true);
			oRequest.send(null);
		}

	}
}
function fAJAXChangeWhenReady()
{
    if(oRequest.readyState == 4 || oRequest.readyState=="complete")
    {
    	if(document.getElementById(oTarget))
    	{
    		document.getElementById(oTarget).innerHTML = oRequest.responseText;
    	}
    }

}

function fVerifyInput(strID, strText) {
//alert("fVerifyInput(" + strID + ", " + strText + ") called.");
	var oInput = document.getElementById(strID);
	if(oInput.value == "") {
		oInput.style.background = "#ffcccc";
		return strText;
	} else {
		oInput.style.background = "";
		return "";
	}
}

function fVerifyInputLength(strID, intLength, strText) {
	//alert("VERIFY");
	var oInput = document.getElementById(strID);
	//alert(oInput.value.length);
	if(oInput.value.length < intLength) {
		oInput.style.background = "#ffcccc";
		return strText;
	} else {
		oInput.style.background = "";
		return "";
	}
}

function fVerifyMaxInputLength(strID, intLength, strText) {
	//alert("VERIFY");
	var oInput = document.getElementById(strID);
	//alert(oInput.value.length);
	if(oInput.value.length > intLength) {
		oInput.style.background = "#ffcccc";
		return strText;
	} else {
		oInput.style.background = "";
		return "";
	}
}

function fRequest() {	
	var strError = "";
	var strPage = escape(document.getElementById("hdnPage").value);
	var strURL = "txtName="+escape(document.getElementById("txtName").value);
	strURL += "&txtEmail="+escape(document.getElementById("txtEmail").value);
	strURL += "&txtComp="+escape(document.getElementById("txtComp").value);
	strURL += "&txtComments="+escape(document.getElementById("txtComments").value);
	strURL += "&hdnPage="+strPage;
	
//alert(strURL);
	if(strPage=="lyophilization")
	{
		var chkL = document.getElementById("chkLyo").checked;
		if(chkL==true)
		{
			strURL += "&chkLyo=" + chkL;
		}
		var chkD = document.getElementById("chkDCOOL").checked;
		if(chkD ==true)
		{
			strURL += "&chkDCOOL=" + chkD;
		}
		if((!chkL) && (!chkD))
		{
			strError += strRequestTypeError;
		}
	}else if(strPage=="improved"){
		//alert("here");
		//var chkLS = document.getElementById("chkLyoSpec").checked;
			var oneChecked =false;
		$('.checkboxes').each(function(){
			//alert("here");
			if($(this).attr('checked')){
				strID = $(this).attr('id');
				//alert(strID);
				strURL += "&"+strID+"="+$(this).attr('checked');
				oneChecked =true;
			}

		});
if(!oneChecked){
				strError += strRequestTypeError;
			}
		}
	//alert(strURL);
	strError += fVerifyInput("txtName","Please enter your Name.\n");
	strError += fVerifyInput("txtEmail","Please enter your Email Address.\n");
	strError += fVerifyInput("txtComp","Please enter your Company Name.\n");
	strError += fVerifyMaxInputLength("txtComments", "500", "Please do not enter more than 500 characters.\n");
	if(strError != "") {
		alert(strError);
		return false;
	}
	else{
		//alert("good til here");
		//fAJAXRequest("","dbRequest.php","?"+strURL);
		//window.location = "reqThankYou.php";
		return true;
	}
}


function fValidate() {

	var strError = "";
	if(fIsValideCheck('checkboxes') == false){
		strError += strRequestTypeError;
		$('.checkboxes').css("background-color","#ffcccc");
	}
	var txtName = $('#txtName').val();
	//alert(fIsText(txtName));
	if(fIsText(txtName)==false){
		strError += "Please enter your Name.\n";
		$('#txtName').css("background-color","#ffcccc");
	}
	var txtEmail = $('#txtEmail').val();
	if(fVerifyEmail(txtEmail) == false){
		strError += "Please enter your Email Address.\n";
		$('#txtEmail').css("background-color","#ffcccc");
	}	
	var txtComp = $('#txtComp').val();
	if(fIsText(txtComp)==false){
		strError += "Please enter your Company Name.\n";
		$('#txtComp').css("background-color","#ffcccc");
	}
	var txtCom = $('#txtComments').val();
	if(fVerifyMaxLength(txtCom, "500")==false){
		strError += "Please do not enter more than 500 characters.\n";
		$('#txtComments').css("background-color","#ffcccc");
		
	}

	if(strError != "") {
		alert(strError);
		return false;
	}
	return true;
}

//	Open a modal window and output the code for the video.  JQuery required.
function fShowControlLyoVideo() {
	var strSelector = "#controlLyoModal";
	var intWidth = 580;
	var intHeight = 320;
	var requiredMajorVersion = 7;
	var requiredMinorVersion = 0;
	var requiredRevision = 0;
	var strHtml = "";
	
	strHtml += "<div class=\"cssPaddingBottom3\">\n";
	var boolValidFlashInstall = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	if(boolValidFlashInstall) {
		strHtml += fGetFlash("../flash/player.swf", "controLyoVideo", intWidth, intHeight, "file=Controlyo_Tech_3.flv&autostart=true");
	} else {
		strHtml += fGetNoFlash("../img/img_getFlash.jpg", intWidth, intHeight, "Please install the latest Adobe Flash plugin in order to view this video.  Our apologies for any inconvenience.");
	}
	strHtml += "</div>\n";
	strHtml += "<div style=\"float: right;\"><a href=\"#\" onclick=\"return fCloseModalWindow();\"><img src=\"../img/btn_close.jpg\" height=\"22\" width=\"75\" alt=\"CLOSE\" border=\"0\" /></a></div>\n";
	strHtml += "<span class=\"cssBlue\" style=\"font-size: 11px;\"><b>ControLyo&trade; Technology Demo Video</b></span>";
	
//alert("strHtml = " + strHtml + "\n");
	$(strSelector).html(strHtml);
	fOpenModalWindow(strSelector);
	fCenterVerticallyOnScreen(strSelector);
	return false;
}