//--------------------------------------------------------------------------
// Name:	ContentSelection.js
//
// Description:	functions used by various content selection pages
//		
//
// Revisions:	06/06	Mathias
//			Created (Mostly copied from Validate_Form.js)
//--------------------------------------------------------------------------


	// Set Sniffer Vars -
	var isIE = false;
	var isNN = false;
   
	// If document.all exists, then we're in some flavor of IE
	if (document.all) {
	isIE = true;

	// Otherwise, it's not IE	  
	} else {
		isNN = true;
	}





//--------------------------------------------------------------------------
// Name:	preSelectProduct
//
// Description:	PreSelects a product if a match is found
//
// Arguments:	None
//
// Revisions:	06/06	Mathias
//			Created
//
//--------------------------------------------------------------------------
function preSelectProduct() {

	
	
	var frmMain = document.forms["frmMain"];
	if (!frmMain) {
		alert ("Can't Find frmMain!");
		return false;
	}

	var frmReset = document.forms["frmReset"];
	if (!frmReset) {
		alert ("Can't Find frmReset!");
		return false;
	}


	// get the hidden form field that contains the preselected value
	var PreSelectedProductValue = frmReset.elements["PreSelectedProduct"].value;
	

	// loop through each of the products to see
	// if any of them should be pre selected
	var rdoProductList = frmMain.elements["ProductList"];
	if (rdoProductList) {
		for (var i=0; i<rdoProductList.length; i++) {
			if (rdoProductList[i].value == PreSelectedProductValue) {
				rdoProductList[i].checked = true;
			} // alert (rdoProductList[i].value);
               	}
	}

}


//--------------------------------------------------------------------------
// Name:	checkCompanyCode
//
// Description:	Checks to see what the company code should be
//		Hard coded exceptions
//
// Arguments:	None
//
// Revisions:	06/06	Mathias
//			Created
//--------------------------------------------------------------------------
function checkCompanyCode () {


	// Get ref to main form -
	var frmMain = document.forms["frmMain"];
	if (!frmMain) {
		alert ("Can't Find Main Form!");
		return false;
	}

	// set the default value
	frmMain.elements["COMPANY"].value = "LNL";

	 
}



//--------------------------------------------------------------------------
// Name:	getAudience
//
// Description:	Gets the audience cookie
//
// Arguments:	None
//
// Revisions:	06/06	Mathias
//			Created
//
//--------------------------------------------------------------------------
function getAudience() {


	// for debugging
	// alert (readCookie("VIEW_AS"));

	var viewAsCookie = readCookie("VIEW_AS");

	var frmMain = document.forms["frmMain"];
	if (!frmMain) {
		alert ("Can't Find Main Form!");
		return false;
	}
	frmMain.elements["Audience"].value = viewAsCookie;
}





//--------------------------------------------------------------------------
// Name:	getCheckBoxValue
//
// Description:	Returns true (at least one checked) or false (none checked)
//              for input checkbox object
//
// Arguments:	checkBox    - Check Box Object
//
// Revisions:	06/06	Mathias
//			Created
//
//--------------------------------------------------------------------------
function getCheckBoxValue (checkBox){

	var blnChecked = false;
				
	// Is there more than one checkbox, it's length 
	// is true so then it's an array
	if (checkBox.length) {
		// an array, see if one of them is checked
		for (var i = 0; i < checkBox.length; i++){ 
			if (checkBox[i].checked) {
				blnChecked = true; 
				break; 
      			}
   		}
	}
	else {
		// Only one checkbox (not an array)
		blnChecked = checkBox.checked; 
	}
	
	return blnChecked;
}


 
  
//--------------------------------------------------------------------------
// Name:	getOptionValue
//
// Description:	Returns true (at least one item selected) or false (none
//              selected) for input dropdown list object 
//
// Arguments:	option      - The dropdown list object
//
// Revisions:	06/06	Mathias
//			Created
//
//--------------------------------------------------------------------------
function getOptionValue (option){   

	var blnOption = false;

	for (var i = 0; i < option.length; i++){
		if (option[i].selected) {
			blnOption = true; 
			break; 
		}
   }

   return blnOption;

}
   
         
//--------------------------------------------------------------------------
// Name:	getRadioValue
//
// Description:	Returns the value of a radio button form element
//
// Arguments:	objRDO      = the radio button object
//
// Returns:	The value of the radio button
//
// Revisions:	06/06	Mathias
//			Created
//
//--------------------------------------------------------------------------
function getRadioValue (objRDO) {

	// Set default return value of nothing
	var strValue = "";

	// Is there more than one radio box, it's length 
	// is true so then it's an array
	if (objRDO.length) {
		// Find the value of the one selected item in the array
		for (var i = 0; i < objRDO.length; i++) {
			if (objRDO[i].checked) {
         			strValue = objRDO[i].value;
         			break;
      			}
   		}

	}
	else {

		// Only one checkbox (no array)
		strValue = objRDO.value;
	}		

	// Return value
	return strValue;

}


//--------------------------------------------------------------------------
// Name:	resetPage
//
// Description:	Sets the hidden Company form field back to LNL
//
// Revisions:	11/05	Mathias
//			Created
//  
//--------------------------------------------------------------------------
function resetPage() {

	// just in case this user uses the back button after the company was changed
	// behind the scenes, reset the form to LNL
	//var frmMain = document.forms["frmMain"];
	//if (!frmMain) {
		//alert ("Can't Find Main Form!");
	//	return false;
	//}
	
	//frmMain.elements["COMPANY"].value = "LNL"
	
}



//--------------------------------------------------------------------------
// Name:	validateFormRequest
//
// Description:	Validates form search post
//
// Arguments:	theForm     - Form object
//
// Revisions:	11/05	Mathias
//			Created
//
//--------------------------------------------------------------------------
function validateFormRequest(theForm) {

	// Set default return of all data valid (bad data is false)
	var blnBadData = false;

	// Make sure at least one product is checked
	if (theForm.ProductList) {

		if (!getRadioValue(theForm.elements["ProductList"])) {
			blnBadData = true;
			alert("Please Choose A Product.");
		}
	}

	// Make sure at least one state is checked
	if (theForm.ddState) {
		if (!getOptionValue(theForm.elements["ddState"])) {
			blnBadData = true;
			alert("Please Choose A State.");
		}
	}

	// No purpose list for fillable forms, 
	// So make sure it is there before the check
	if (theForm.PurposeList) {
	
		// Make sure at least one purpose selected
		if (!getCheckBoxValue(theForm.elements["PurposeList"])) {
			blnBadData = true;
			alert("Please Choose At Least One Purpose.");
		}

	}

  
	// If data is bad, then just exit
	if (blnBadData) return;

	// Validate availability on last time -
	var txtCompany = theForm.elements["COMPANY"];
	if (txtCompany) {
		strCompany = txtCompany.value;
	} else {
		strCompany = "NA";
	}
   
	// Add state list back to form
	//can only select one state now

	var strStatesPicked = "";
   	var strSep = "";
	var objStateList = theForm.elements["ddState"];
	for (var i=0; i<objStateList.length; i++) {
		if (objStateList[i].selected) {
			strStatesPicked = strStatesPicked + strSep + "'" + objStateList[i].value + "'";
         		strSep = ","
      		}
   	}
	theForm.elements["StateList"].value = strStatesPicked;


	// Submit the form
	theForm.submit();

}







//--------------------------------------------------------------------------
// Name:	validateFormRequest_AdvancedSearch
//
// Description:	Validates form search post
//
// Arguments:	theForm     - Form object
//
// Revisions:	06/06	Mathias
//			Created
//
//--------------------------------------------------------------------------
function validateFormRequest_AdvancedSearch(theForm) {

	// Submit the form
	// we don't need no stinkin validation here
	theForm.submit();
}






//--------------------------------------------------------------------------
// Name:          validateFormRequest_MoneyGuard
//
// Description:   Validates form search post FOR MONEYGUARD.COM
//
// Arguments:	theForm     - Form object
//
// Revisions:	06/06	Mathias
//			Created
//--------------------------------------------------------------------------
function validateFormRequest_MoneyGuard(theForm) {

   // Set default return of all data valid (bad data is false)
   var blnBadData = false;

   // Make sure at least one product is checked
   if (theForm.ProductList) {
      if (!getCheckBoxValue(theForm.elements["ProductList"])) {
      blnBadData = true;
      alert("Please Choose A Product.");
     }
    }

   // Make sure at least one state is checked
   if (theForm.ddState) {
      if (!getOptionValue(theForm.elements["ddState"])) {
      blnBadData = true;
      alert("Please Choose A State.");
   }
 }

   // No purpose list for fillable forms, 
   // So make sure it is there before the check
   if (theForm.PurposeList) {
	
      // Make sure at least one purpose selected
      if (!getCheckBoxValue(theForm.elements["PurposeList"])) {
         blnBadData = true;
         alert("Please Choose At Least One Purpose.");
      }

   }

  
   // If data is bad, then just exit
   if (blnBadData) return;
  
   // Add state list back to form
   var strStatesPicked = "";
   var strSep = "";
   var objStateList = theForm.elements["ddState"];
   if (theForm.ddState) {
   for (var i=0; i<objStateList.length; i++) {
      if (objStateList[i].selected) {
         strStatesPicked = strStatesPicked + strSep + "'" + objStateList[i].value + "'";
         strSep = ","
      }
   }
 
   theForm.elements["StateList"].value = strStatesPicked;
   }

	
   // Submit the form
   theForm.submit();

}






//--------------------------------------------------------------------------
// Name:          validateFormRequest_POS
//
// Description:   Validates form search post
//
// Arguments:	theForm     - Form object
//
// Revisions:	06/06	Mathias
//			Created
//--------------------------------------------------------------------------
function validateFormRequest_POS(theForm) {

	// Create a return code -
	var blnBadData = false;

	// Make sure at least one product is checked
	if (theForm.ProductList) {
		if (!getRadioValue(theForm.elements["ProductList"])) {
			blnBadData = true;
			alert("Please Choose A Product.");
		}
	}

	//Check to see if a state is selected
	var objStateList = theForm.elements["ddState"];
	blnChecked = false;
	for (var i = 0; i < objStateList.length; i++) {
		if (objStateList[i].selected) {
			blnChecked = true;
			break;
		}
	
	}

	if (!blnChecked) {
		blnBadData = true;
		alert("Please Choose A State.");
	}

	// If bad data, then exit
	if (blnBadData) return;

	// Add state list back to form
	//can only select one state now

	var strStatesPicked = "";
	var strSep = "";
	var objStateList = theForm.elements["ddState"];
	for (var i=0; i<objStateList.length; i++) {
		if (objStateList[i].selected) {
			strStatesPicked = strStatesPicked + strSep + "'" + objStateList[i].value + "'";
			strSep = ","
		}
	}

	theForm.elements["StateList"].value = strStatesPicked;
   
	// Submit the form
	theForm.submit();

}




//--------------------------------------------------------------------------
// Name:	validateFormRequest_Public
//
// Description:	Validates form search post
//
// Arguments:	theForm     - Form object
//
// Revisions:	11/05	Mathias
//			Created
//
//--------------------------------------------------------------------------
function validateFormRequest_Public(theForm) {

	// Set default return of all data valid (bad data is false)
	var blnBadData = false;

	// Make sure at least one product is checked
	if (theForm.ProductList) {

		if (!getRadioValue(theForm.elements["ProductList"])) {
			blnBadData = true;
			alert("Please Choose A Product.");
		}
	}

	// Make sure at least one state is checked
	if (theForm.ddState) {
		if (!getOptionValue(theForm.elements["ddState"])) {
			blnBadData = true;
			alert("Please Choose A State.");
		}
	}

	
  
	// If data is bad, then just exit
	if (blnBadData) return;

	// Validate availability on last time -
	var txtCompany = theForm.elements["COMPANY"];
	if (txtCompany) {
		strCompany = txtCompany.value;
	} else {
		strCompany = "NA";
	}
   
	// Add state list back to form
	//can only select one state now

	var strStatesPicked = "";
   	var strSep = "";
	var objStateList = theForm.elements["ddState"];
	for (var i=0; i<objStateList.length; i++) {
		if (objStateList[i].selected) {
			strStatesPicked = strStatesPicked + strSep + "'" + objStateList[i].value + "'";
         		strSep = ","
      		}
   	}
	theForm.elements["StateList"].value = strStatesPicked;


	// Submit the form
	theForm.submit();

}




//--------------------------------------------------------------------------
// Name:	changeDisplayState
//
// Description:	shows/hides a select section (DIV, TD, etc)
//		
// Arguments:	id - the id of the section to manipulate
//
// Revisions:	06/06	Mathias
//			
//--------------------------------------------------------------------------
function changeDisplayState (id) {

	var objElement=document.getElementById(id);

	if (objElement != null) {

		// Visibility value varies by browser -
		if (isIE) {
			strTestValue = "inline";
		} else {
			strTestValue = "block";
		}     

		if (objElement.style.display == 'none' || objElement.style.display =="") {
			objElement.style.display = strTestValue;		
		} else {
			objElement.style.display = 'none';		
		}
	}
}


//--------------------------------------------------------------------------
// Name:	changeShowHideLink
//
// Description:	Changes the show hide verbiage to be the oposite of whatever it is 
//		
// Arguments:	id - the id of the section to change
//
// Revisions:	06/06	Mathias
//			
//--------------------------------------------------------------------------
function changeShowHideLink (id) {

	var textToShow;	
	
	var objElement=document.getElementById(id);
	
	if (objElement != null) {

		if (objElement.innerHTML == 'Show') {
			textToShow = 'Hide';
		} else {
			textToShow = 'Show';
		}

		objElement.innerHTML = textToShow;
		setCookie( id, textToShow, 30)
	}
	
	
}


//--------------------------------------------------------------------------
// Name:	showHideSection
//
// Description:	One function to call the two seperate functions from the web page
//		
// Arguments:	sectionId - the id of the section to change
//		linkID - the id of the link to change
//
// Revisions:	06/06	Mathias
//			
//--------------------------------------------------------------------------
function showHideSection(sectionId, linkID) {

	changeDisplayState (sectionId);
	changeShowHideLink (linkID);

}



//--------------------------------------------------------------------------
// Name:	checkShowHides
//
// Description:	Check the user's cookies to see if any sections should be shown
//		When the enter this page
//		
// Arguments:	none
//		
//
// Revisions:	06/06	Mathias
//			
//--------------------------------------------------------------------------
function checkShowHides() {

	var americanLegacyLink
	var lifeCurrentLink
	var lifeElementsLink
	var lifeGuaranteeLink
	var lifeReserveLink
	var cPGLink
	var clearPointLink
	var newDirectionsLink
	var optiChoiceLink
	var optiPointLink
	var classicLink
	var landscapeLink
	var choicePlusFALink
	var cPFALink
	var choicePlusLink
	var choicePlusIILink
	var multiFundLink
	var otherLink
	var fixedLink
	var groupLink
	var ensembleLink

	americanLegacyLink = getCookie('americanLegacyLink');
	if (americanLegacyLink == 'Hide') {
		showHideSection('americanLegacyProducts', 'americanLegacyLink')
	}

	lifeCurrentLink = getCookie('lifeCurrentLink');
	if (lifeCurrentLink == 'Hide') {
		showHideSection('lifeCurrentProducts', 'lifeCurrentLink')
	}

	lifeElementsLink = getCookie('lifeElementsLink');
	if (lifeElementsLink == 'Hide') {
		showHideSection('lifeElementsProducts', 'lifeElementsLink')
	}

	lifeGuaranteeLink = getCookie('lifeGuaranteeLink');
	if (lifeGuaranteeLink == 'Hide') {
		showHideSection('lifeGuaranteeProducts', 'lifeGuaranteeLink')
	}
	
	lifeReserveLink = getCookie('lifeReserveLink');
	if (lifeReserveLink == 'Hide') {
		showHideSection('lifeReserveProducts', 'lifeReserveLink')
	}

	cPGLink = getCookie('cPGLink');
	if (cPGLink == 'Hide') {
		showHideSection('cPGProducts', 'cPGLink')
	}
	
	clearPointLink = getCookie('clearPointLink');
	if (clearPointLink == 'Hide') {
		showHideSection('clearPointProducts', 'clearPointLink')
	}

	newDirectionsLink = getCookie('newDirectionsLink');
	if (newDirectionsLink == 'Hide') {
		showHideSection('newDirectionsProducts', 'newDirectionsLink')
	}

	optiChoiceLink = getCookie('optiChoiceLink');
	if (optiChoiceLink == 'Hide') {
		showHideSection('optiChoiceProducts', 'optiChoiceLink')
	}

	optiPointLink = getCookie('optiPointLink');
	if (optiPointLink == 'Hide') {
		showHideSection('optiPointProducts', 'optiPointLink')
	}

	classicLink = getCookie('classicLink');
	if (classicLink == 'Hide') {
		showHideSection('classicProducts', 'classicLink')
	}
	
	landscapeLink = getCookie('landscapeLink');
	if (landscapeLink == 'Hide') {
		showHideSection('landscapeProducts', 'landscapeLink')
	}

	choicePlusFALink = getCookie('choicePlusFALink');
	if (choicePlusFALink == 'Hide') {
		showHideSection('choicePlusFAProducts', 'choicePlusFALink')
	}
	
	cPFALink = getCookie('cPFALink');
	if (cPFALink == 'Hide') {
		showHideSection('cPFAProducts', 'cPFALink')
	}

	choicePlusLink = getCookie('choicePlusLink');
	if (choicePlusLink == 'Hide') {
		showHideSection('choicePlusProducts', 'choicePlusLink')
	}

	choicePlusIILink = getCookie('choicePlusIILink');
	if (choicePlusIILink == 'Hide') {
		showHideSection('choicePlusIIProducts', 'choicePlusIILink')
	}

	multiFundLink = getCookie('multiFundLink');
	if (multiFundLink == 'Hide') {
		showHideSection('multiFundProducts', 'multiFundLink')
	}

	otherLink = getCookie('otherLink');
	if (otherLink == 'Hide') {
		showHideSection('otherProducts', 'otherLink')
	}

	fixedLink = getCookie('fixedLink');
	if (fixedLink == 'Hide') {
		showHideSection('fixedAnnuities', 'fixedLink')
	}
	
	groupLink = getCookie('groupLink');
	if (groupLink == 'Hide') {
		showHideSection('groupAnnuities', 'groupLink')
	}
	ensembleLink = getCookie('ensembleLink');
	if (ensembleLink == 'Hide') {
		showHideSection('ensembleProducts', 'ensembleLink')
	}
	
}




/*
Script Name: Javascript Cookie Script
Author: Public Domain, with some modifications
Script Source URI: http://techpatterns.com/downloads/javascript_cookies.php
Version 1.0.0
Last Update: 30 May 2004

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
*/



//--------------------------------------------------------------------------
// Name:	getCookie
//
// Description:	get the value of a select cookie if it exists
//
// Arguments:	name - The name of the cookie
//
// Revisions:	08/06	Mathias
//			Created
//
//--------------------------------------------------------------------------
function getCookie( name ) {
	
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}



//--------------------------------------------------------------------------
// Name:	setCookie
//
// Description:	Set a cookie
//
// Arguments:	name - The name of the cookie
//		value - The value of the cookie
//		expires - The number of days this cookie should expire in
//		path - Not needed
//		domain - Not needed
//		secure - Not needed
//
//	only the first 2 parameters are required, the cookie name, the cookie
//	value. Cookie time is in milliseconds, so the below expires will make the 
//	number you pass in the setCookie function call the number of days the cookie
//	lasts, if you want it to be hours or minutes, just get rid of 24 and 60.
//
//	Generally you don't need to worry about domain, path or secure for most applications
//	so unless you need that, leave those parameters blank in the function call.
//
// Revisions:	08/06	Mathias
//			Created
//
//--------------------------------------------------------------------------
function setCookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}


//--------------------------------------------------------------------------
// Name:	deleteCookie
//
// Description:	deletes the cookie when called
//
// Arguments:	name - The name of the cookie
//
// Revisions:	08/06	Mathias
//			Created
//
//--------------------------------------------------------------------------
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}



