function LoadFreeReport() { //v2.0
  //alert("In LoadFreeReport");
  var s_width = 420;
  var s_height = 350;
  var theURL = 'FreeReportPopup_Main.asp';
  var winName = 'FreeReport';
  var features = 'SCROLLBARS=NO,WIDTH=' + s_width + ',HEIGHT=' + s_height + ',status=yes';
  //alert('theURL=' + theURL + ' winName=' + winName + ' features=' + features);
  var windowHandle;
  windowHandle = window.open(theURL,winName,features);
  if (windowHandle.opener == null) 
	windowHandle.opener = self;
}

function ProcessFreeReportSuccess( strFreeReportSuccess) {
	window.focus();
	if ( strFreeReportSuccess == "Y") {
		window.close();
	}
} //ProcessFreeReportSuccess

function ValidateFreeReport () {
	//this function validates the Member's log in name and password
	//first check to be sure that entries have been made in both text boxes.
		
	var strErrors; //error message
	var arRequired; //array storing names of required fields
		
	//alert("In Validate Free Report");
	arRequired = new Array('txtFirstName', 'txtLastName', 'txtEMail');
	strErrors = CheckRequiredFields(arRequired);
	//alert(strErrors);
		
	//if there is an error message, display it and exit sub
	if (strErrors.length != 0) {
		alert(strErrors);
		return;
	}
		
	//set the flag for submition
	document.forms["frmFreeReport"].hidRefresh.value = 1
	//submit the page
	document.forms["frmFreeReport"].submit();	
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function WriteProdList( strProductID, strProductName){ //v2.0
	//this function sets the product ID to the ProdList form varible
	var tmpProdList = document.forms["frmCart"].hidProdList.value
	//alert("tmpProdList is " + tmpProdList);
	var tmpButtonName = "cmd" + strProductName;
	
	tmpProdList = tmpProdList + strProductID + "a";
	tmpProdList = replace( tmpProdList, "undefined", "");
	//alert("tmpProdList is " + tmpProdList);
	document.forms["frmCart"].hidProdList.value = tmpProdList;
	//alert("document.forms[frmCart].hidProdList.value is " + document.forms["frmCart"].hidProdList.value);
	
	//alert("tmpButtonName is " + tmpButtonName);
	tmpButtonName = replace( tmpButtonName, " ", "");
	//alert("tmpButtonName is " + tmpButtonName);
	//document.forms["frmCart"].cmdEssential7Kit.value = strProductName + " In Cart";
	eval("document.frmCart." + tmpButtonName).value = strProductName + " In Cart";
}

function GoToYLW() { //v2.0
	//this function goes to a YLW page with the ProdList and Lead Info
	//alert("In GoToYLW");
	document.forms["frmCart"].submit();
}
function CheckRequiredFields(arRequired){
	//this function checks to see if all the required fields are populated
	var strMsg = 'Please complete the following fields:\n';
	var iCount = 0;
	
	for (var i = 0; i < arRequired.length; i++) {
		var x = document.forms[0].elements[arRequired[i]].value;
		if (x == '' || x == null) {
			strMsg += ((0 < iCount) ? ', ' : '') + arRequired[i].substring(3,arRequired[i].length);
			iCount += 1;
		}
	}

	//if no errors were found, pass back an empty string
	if (iCount == 0)
		strMsg = ''
		
	//return the error message 
	return strMsg

}

function LoadPopup(theURL) { //v2.0
  var s_width = 560;
  var s_height = 600;
  var winName = 'ProductPopup'
  var features = 'RESIZE=YES,SCROLLBARS=YES,WIDTH=' + s_width + ',HEIGHT=' + s_height + ',status=yes';
  var windowHandle
  windowHandle = window.open(theURL,winName,features);
  if (windowHandle.opener == null) 
	windowHandle.opener = self;
}
function LoadLogin() { //v2.0
  var s_width = 200;
  var s_height = 150;
  var theURL = 'LoginPopup_Main.asp';
  var winName = 'Login';
  var features = 'SCROLLBARS=NO,WIDTH=' + s_width + ',HEIGHT=' + s_height + ',status=yes';
  //alert('theURL=' + theURL + ' winName=' + winName + ' features=' + features);
  var windowHandle;
  windowHandle = window.open(theURL,winName,features);
  if (windowHandle.opener == null) 
	windowHandle.opener = self;
}

function OrderProduct( strProductID){ //v2.0
	//this function sets the product ID to the ProdList form varible
	//Then sends the user to check Out on YLW
	var tmpProdList = document.forms["frmCart"].hidProdList.value
	//alert("tmpProdList is " + tmpProdList);
		
	tmpProdList = tmpProdList + strProductID + "a";
	tmpProdList = replace( tmpProdList, "undefined", "");
	//alert("tmpProdList is " + tmpProdList);
	document.forms["frmCart"].hidProdList.value = tmpProdList;
	//alert("document.forms[frmCart].hidProdList.value is " + document.forms["frmCart"].hidProdList.value);
	
	document.forms["frmCart"].submit();
}

