//Copyright Mangolab Ltd. 2008. All rights reserved.
//USES:
// - j_params.js 
// - j_cookies.js
//SUMMARY:
// Simple validation of the user contact details
// in the form whose form index is sent as a param
//HISTORY:
// 07.02.06 Updated for goldmine fields
// 16.10.08 Deleted GetSearchParam function and updated for no frames
// 23.10.08 Version 1.0 - <FC> - Reviewd / FB ref: CASE:1496

//Called from Onload event
function PopulateFormFromParamsAndCookies(AFormIndex){
//Population from parameters - ie if form is resubmitted, its the  new values
//will be in the cookie not the parameters 
PopulateFromParams(AFormIndex);
//Now population from cookies:
PopulateFormFromContactDetailsCookie(AFormIndex);
//Population from mangobasket if there is a logged in user
$mb.ready(function(){
	$mb.loadUserInfo(function(data){
		var user = data.InnerData;
		var FrmInput=document.getElementById("frmGMGenerated");
		if(true == user.HasUser){
			//user.FriendlyName;
			if(IsFieldExistsAndFieldValueIsBlankOrNull("SECR",FrmInput)){FrmInput.SECR.value = user.ContactDetails.Salutation;};
			if(IsFieldExistsAndFieldValueIsBlankOrNull("DEAR",FrmInput)){FrmInput.DEAR.value = user.ContactDetails.FirstName;};
			if(IsFieldExistsAndFieldValueIsBlankOrNull("LASTNAME",FrmInput)){FrmInput.LASTNAME.value = user.ContactDetails.Surname;};
			if(IsFieldExistsAndFieldValueIsBlankOrNull("EMAIL",FrmInput)){FrmInput.EMAIL.value = user.ContactDetails.Email;};
			if(IsFieldExistsAndFieldValueIsBlankOrNull("PHONE1",FrmInput)){FrmInput.PHONE1.value = user.ContactDetails.Telephone;};
			if(IsFieldExistsAndFieldValueIsBlankOrNull("ZIP",FrmInput)){FrmInput.ZIP.value = user.Customer.DefaultDeliveryAddress.Postcode;};
			if(IsFieldExistsAndFieldValueIsBlankOrNull("COMPANY",FrmInput)){FrmInput.COMPANY.value = user.Customer.CompanyName;};
			//user.Customer.GoldMineID;
			//user.Customer.StrategixID;
			if(IsFieldExistsAndFieldValueIsBlankOrNull("ADDRESS1",FrmInput)){FrmInput.ADDRESS1.value = user.Customer.DefaultDeliveryAddress.Address1;};
			if(IsFieldExistsAndFieldValueIsBlankOrNull("ADDRESS2",FrmInput)){FrmInput.ADDRESS2.value = user.Customer.DefaultDeliveryAddress.Address2;};
			if(IsFieldExistsAndFieldValueIsBlankOrNull("CITY",FrmInput)){FrmInput.CITY.value = user.Customer.DefaultDeliveryAddress.City;};
			//user.Customer.DefaultDeliveryAddress.Country.ISOCode2;
			if(IsFieldExistsAndFieldValueIsBlankOrNull("COUNTRY",FrmInput)){FrmInput.COUNTRY.value = user.Customer.DefaultDeliveryAddress.Country.Name;};
		};            
	});
});
return true;
}

function IsFieldExistsAndFieldValueIsBlankOrNull(AControlName,AForm){
	//Check if a control name exists on the form and if it does, check if it is null or blank.
	if (IsExists(AControlName,AForm)){
	//Check if the control has a value or not, and return true or false
		return IsFieldValueBlankOrNull(AControlName);
	}
	//If there isn't a value return true.
	 return false;	
}

function IsFieldValueBlankOrNull(AControlName){
	//Check if control value is a blank  or null.
	if(AControlName.value == "" || AControlName.value == null){
		return true;
	}
	return false;
}

function GetField(AFieldName,AForm){
try {
	if (document.getElementById){
	   return document.getElementById(AFieldName);
	   }
	   else {
       return AForm.AFieldName; 
	   }
    }
    catch(err) {
        return null;
		}	
}

function IsExists(AFieldName,AForm) {
	var AField=GetField(AFieldName,AForm);
	return (AField != null && AField != undefined);
}

//called by OnClick event of checkboxes to populate hidden forms sent to Goldmine
function SendValueToHidden(ACheckbox) {
//name should be ChkSTANDARD, remove first 3 letters
var Str=ACheckbox.name;
Str=Str.substring(3,Str.length);
var Fld=GetField(Str);//ie missing form param means only safe when getElbyId is used
if (ACheckbox.checked){
   Fld.value="YES";
   }
   else {
   Fld.value="NO";
   }	
return true;
}

function SetCheckBox(ACheckBox,IsChecked) {
var Str=''+IsChecked;//ensure its converted to string
Str=Str.toLowerCase();
ACheckBox.checked=(Str=='true');
}

function SafeSetCheckAndHidden(ACheckBoxName,AForm,IsChecked,IsAHidden) {
//have to be careful with stupid js non-primitive boolean-ness, silly loose typed jokers language
if (IsExists(ACheckBoxName,AForm)){
   var Fld=GetField(ACheckBoxName,AForm);
   SetCheckBox(Fld,IsChecked);
   if (IsAHidden){
      SendValueToHidden(Fld)}
   //alert('SetCheckAndHidden: '+ACheckBoxName+' IsChecked='+IsChecked);
   }
}
function SafeSetCheckBox(AControlName,AForm,IsChecked) {
if (IsExists(AControlName,AForm)){
   var AField=GetField(AControlName,AForm);   
   SetCheckBox(Fld,IsChecked);
   }
}

//only do it if browser supports gebyId
function SetLabelState(AControlName,IsValidated,AForm) {
if (IsExists('Lbl'+AControlName,AForm)){
   var Fld=GetField('Lbl'+AControlName,AForm); //ie TD
   if (IsValidated){
      Fld.style.fontWeight='normal';
	  Fld.style.color='#000000'}
	  else{
	  Fld.style.fontWeight='bold';
	  Fld.style.color='#FF0000'}
   }	  
}

function SafeSetEditBox(AControlName,AForm,AValue,IsSetIfAValueEmpty) {
if (IsExists(AControlName,AForm)){
   var AField=GetField(AControlName,AForm);   
   if (IsSetIfAValueEmpty || (AValue!="")){
      AField.value=AValue}   
   }
}

function SafeSetEditBoxFromCookie(AControlName,ACookieName,AForm) {
var ACookieValue=GetCookieField(ACookieName,AControlName);//returns "" if  cookie or field don't exist
//only set if ACookieValue!=""
SafeSetEditBox(AControlName,AForm,ACookieValue,false);
}

function SafeSetCheckBoxFromCookie(AControlName,ACookieName,AForm) {
if (IsExists(AControlName,AForm)){
   var AField=GetField(AControlName,AForm);
   var ACookieValue=GetCookieField(ACookieName,AControlName);//returns "" if  cookie or field don't exist
   if (ACookieValue!=""){
      SetCheckBox(AControlName,ACookieValue)}
   }
}

function SafeSetCheckBoxAndHiddenFromCookie(AControlName,ACookieName,AForm) {
if (IsExists(AControlName,AForm)){
   var AField=GetField(AControlName,AForm);
   var ACookieValue=GetCookieField(ACookieName,AControlName);//returns "" if  cookie or field don't exist
   if (ACookieValue!=""){
      SafeSetCheckAndHidden(AControlName,AForm,ACookieValue,true)}
   }
}

//extra default value for dropdowns
function SafeSetDropdownFromCookie(AControlName,ACookieName,AForm,ADefaultValue) {
if (IsExists(AControlName,AForm)){
   var AField=GetField(AControlName,AForm);
   var ACookieValue=GetCookieField(ACookieName,AControlName);//returns "" if  cookie or field don't exist
   if (ACookieValue==""){
      ACookieValue=ADefaultValue}
   //alert('value='+ACookieValue);
   AField.selectedIndex=ACookieValue;
   }
}

//------------------
//Form specific:
//------------------

// - mail/alert preferences:

function SetUZHTML(ADropdown){
//have to be careful with non-primitive boolean-ness
var Fld=GetField('UZHTML',document.forms[0]); //ie TD
if (ADropdown.selectedIndex==0){
	Fld.value='HTML'}
	else {
	Fld.value='TEXT'}
return true;
}

// --------------
// Validation:
// --------------

//TODO: This function needs updating to use if (IsExists("PHONE1",FrmInput)){  etc instead of a form-type index:
//Called by Form OnSubmit 

function validate_form(IdxForm, IdxFormType){
//FormType:
// - 0 - get us to contact you, requiring: SECR, DEAR, FIRSTNAME (DEAR), LASTNAME, TEL and EMAIL)
// - 1 - Alert Preferences/mailing options, requiring: DEAR, FIRSTNAME (DEAR), LASTNAME, EMAIL 
// - 2 - Sample request, requiring DEAR, FIRSTNAME (DEAR), LASTNAME, EMAIL, ADDRESS1, POSTCODE 
// - 3 - Alert Preferences - DEAR, FIRSTNAME, LASTNAME, EMAIL 
// - 4 - Manufacturing - DEAR, FIRSTNAME, LASTNAME, EMAIL 
// - 5 - Printed carriers
// - 6 - Alert Preferences/mailing options, requiring: DEAR, FIRSTNAME (DEAR), LASTNAME, EMAIL, CompetitorCheaperProductURL, CompetitorCheaperProductPrice
var validity = true;
var StrWarning = "Sorry, the information you have entered is incomplete. Before clicking 'submit' again, please enter:";
var FrmInput=document.forms[IdxForm];
//alert(FrmInput);
//Reset any controls that were flagged as errors the last time:
SetLabelState('SECR',true,FrmInput);
SetLabelState('DEAR',true,FrmInput);
SetLabelState('LASTNAME',true,FrmInput);
SetLabelState('EMAIL',true,FrmInput);
SetLabelState('ZIP',true,FrmInput);
SetLabelState('PHONE1',true,FrmInput);
SetLabelState('CompetitorCheaperProductURL',true,FrmInput);
SetLabelState('CompetitorCheaperProductPrice',true,FrmInput);
// - occasional fields:
if (IsExists("ADDRESS1",FrmInput)){SetLabelState('ADDRESS1',true,FrmInput)}
//validation:
if (FrmInput.SECR.selectedIndex == 0){
   StrWarning=StrWarning+" your *Title*,";
   validity = false;
   SetLabelState('SECR',validity,FrmInput);
   }
if (FrmInput.DEAR.value == ""){
   StrWarning=StrWarning+" your *First Name*,";
   validity = false;
   SetLabelState('DEAR',validity,FrmInput);
   }
if (FrmInput.LASTNAME.value == ""){
   StrWarning=StrWarning+" your *Last Name*,";
   validity = false;
   SetLabelState('LASTNAME',validity,FrmInput);
   }
if (FrmInput.EMAIL.value == "") {
	StrWarning=StrWarning+" your *E-mail Address*,";   
	validity = false;
	SetLabelState('EMAIL',validity,FrmInput);
} else {
	StrEmail = FrmInput.EMAIL.value;
	//if ((StrEmail.indexOf('.') > 0) && (StrEmail.indexOf('@') > 0)){
	if (!ValidateEmail(StrEmail)){
		StrWarning=StrWarning + " a valid *E-mail Address*,";   
		validity = false;
		SetLabelState('EMAIL',validity,FrmInput);	
	}
}
//ie contact form	specific 
if (IdxFormType == 0){
   if (FrmInput.PHONE1.value == ""){
      StrWarning=StrWarning+" a *Telephone Number* we can call you on,";
      validity = false;
	  SetLabelState('PHONE1',validity,FrmInput);
      }
   }
//Sample request specific
if (IdxFormType == 2){
   if (FrmInput.ADDRESS1.value == "") {
      StrWarning=StrWarning+" your *Postal Address*,";   
      validity = false;
	  SetLabelState('ADDRESS1',validity,FrmInput);
      }
   if (FrmInput.ZIP.value == "") {
      StrWarning=StrWarning+" your *Postcode*,";   
      validity = false;
	  SetLabelState('ZIP',validity,FrmInput);
      }	  
   }  
//End bit of warning
//CompetitorCheaperProductPrice Watch Form
if (IdxFormType == 6){
   if (FrmInput.CompetitorCheaperProductURL.value == "") {
      StrWarning=StrWarning+" the *Web Address*,";   
      validity = false;
	  SetLabelState('CompetitorCheaperProductURL',validity,FrmInput);
      }
   if (FrmInput.CompetitorCheaperProductPrice.value == "") {
      StrWarning=StrWarning+" the *CompetitorCheaperProductPrice Advertised*,";   
      validity = false;
	  SetLabelState('CompetitorCheaperProductPrice',validity,FrmInput);
      }	  
   }  
//End CompetitorCheaperProductPrice Watch Specific
if (IdxFormType == 1){
   StrWarning=StrWarning+" so that we can update your preferences accordingly.";
   }
   else {
   StrWarning=StrWarning+" so that we will be able to respond to your enquiry.";
   } 
//Either proceeed or alert
if (validity){
   SetFormCONTACTFieldValue(IdxForm);
   SetContactDetailsCookie(IdxForm);
	 //Encode form input (text and textarea) 
	 SetXssSecureFormValues();
   }
   else {
   alert(StrWarning);
   }
return validity;
}

function ValidateEmail(strEmail) {
	var emailRE = new RegExp(/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/);
  var result =  emailRE.test(strEmail)
  return result
}


//ie title + last for web site reference, or 1st name if no title
function GetFriendlyName(IdxForm){
var FrmInput=document.forms[IdxForm];
var Idx=FrmInput.SECR.selectedIndex;
var StrRealName=" "+ FrmInput.LASTNAME.value;
if (Idx>0){
   StrRealName=FrmInput.SECR.options[Idx].text + StrRealName;
   }
   else {
   StrRealName=FrmInput.DEAR.value;
   }
//alert(StrRealName);
return StrRealName;
}

//1st + last for goldmine
function GetFormCONTACTValue(IdxForm){
var FrmInput=document.forms[IdxForm];
var StrCONTACT=FrmInput.DEAR.value + " " + FrmInput.LASTNAME.value;
//ie first name + surname
//alert(StrCONTACT);
return StrCONTACT;
}

function SetFormCONTACTFieldValue(IdxForm){
//set the real name value in the form
//ie from the SECR, DEAR & LASTNAME
var FrmInput=document.forms[IdxForm];
FrmInput.CONTACT.value=GetFormCONTACTValue(IdxForm);
}

// -----------
// Cookies:
// -----------

// - 0 - contact details - Title, First, Last, Contact, Friendly, Tel, Fax, Email, Company, Position, Address 1, Address2, City, County, Postcode, Country
//                                   + Product interest groups
//                                   + Sample, Catalogue, Notes
// - 1 - mailing options - Title, First, Last, Contact, Friendly, Postcode,
// - 2 - Sample request full address 
// - 3 - Alert Preferences
// - 4 - Manufacturing
// - 5 - Printed carriers
function SetContactDetailsCookie(IdxForm){
var FrmInput=document.forms[IdxForm];
var IsStore=FrmInput.rememberdetails.checked;
var StrCookie="";
if (IsStore){
   //Contact details fields - basic (all forms):  
   StrCookie = "SECR|"+FrmInput.SECR.selectedIndex
             + "|DEAR|"+FrmInput.DEAR.value
             + "|LASTNAME|"+FrmInput.LASTNAME.value
			 + "|FRIENDLY|"+GetFriendlyName(IdxForm)
			 + "|CONTACT|"+FrmInput.CONTACT.value;
   //Contact details fields - extended:  			 
   if (IsExists("PHONE1",FrmInput)){StrCookie+="|PHONE1|"+FrmInput.PHONE1.value}
   if (IsExists("FAX",FrmInput)){StrCookie+="|FAX|"+FrmInput.FAX.value}
   if (IsExists("EMAIL",FrmInput)){StrCookie+="|EMAIL|"+FrmInput.EMAIL.value}  
   if (IsExists("COMPANY",FrmInput)){StrCookie+="|COMPANY|"+FrmInput.COMPANY.value}  
   if (IsExists("TITLE",FrmInput)){StrCookie+="|TITLE|"+FrmInput.TITLE.value}  
   if (IsExists("ADDRESS1",FrmInput)){StrCookie+="|ADDRESS1|"+FrmInput.ADDRESS1.value}  
   if (IsExists("ADDRESS2",FrmInput)){StrCookie+="|ADDRESS2|"+FrmInput.ADDRESS2.value}  
   if (IsExists("CITY",FrmInput)){StrCookie+="|CITY|"+FrmInput.CITY.value}  
   if (IsExists("STATE",FrmInput)){StrCookie+="|STATE|"+FrmInput.STATE.value}  
   if (IsExists("ZIP",FrmInput)){StrCookie+="|ZIP|"+FrmInput.ZIP.value}  
   if (IsExists("COUNTRY",FrmInput)){StrCookie+="|COUNTRY|"+FrmInput.COUNTRY.value}  
   //alert(StrCookie);
   //Product Interest Group:
   if (IsExists("ChkUXSTANDARD",FrmInput)){StrCookie+="|ChkUXSTANDARD|"+FrmInput.ChkUXSTANDARD.checked}   
   if (IsExists("ChkUXCARRIER",FrmInput)){StrCookie+="|ChkUXCARRIER|"+FrmInput.ChkUXCARRIER.checked}   
   if (IsExists("ChkUXPACKING",FrmInput)){StrCookie+="|ChkUXPACKING|"+FrmInput.ChkUXPACKING.checked}   
   if (IsExists("ChkUXMAILERS",FrmInput)){StrCookie+="|ChkUXMAILERS|"+FrmInput.ChkUXMAILERS.checked}   
   if (IsExists("ChkUXCARRIERP",FrmInput)){StrCookie+="|ChkUXCARRIERP|"+FrmInput.ChkUXCARRIERP.checked}   
   if (IsExists("ChkUXENVIRO",FrmInput)){StrCookie+="|ChkUXENVIRO|"+FrmInput.ChkUXENVIRO.checked}   
   if (IsExists("ChkUXGRIPZIP",FrmInput)){StrCookie+="|ChkUXGRIPZIP|"+FrmInput.ChkUXGRIPZIP.checked}   
   if (IsExists("ChkUXBUBBLE",FrmInput)){StrCookie+="|ChkUXBUBBLE|"+FrmInput.ChkUXBUBBLE.checked}   
   if (IsExists("ChkUXSEALER",FrmInput)){StrCookie+="|ChkUXSEALER|"+FrmInput.ChkUXSEALER.checked}   
   if (IsExists("ChkUXRETAIL",FrmInput)){StrCookie+="|ChkUXRETAIL|"+FrmInput.ChkUXRETAIL.checked}   
   if (IsExists("ChkUXLAYFLAT",FrmInput)){StrCookie+="|ChkUXLAYFLAT|"+FrmInput.ChkUXLAYFLAT.checked}   
   if (IsExists("ChkUXSACKS",FrmInput)){StrCookie+="|ChkUXSACKS|"+FrmInput.ChkUXSACKS.checked}   
   if (IsExists("ChkUXCOVERS",FrmInput)){StrCookie+="|ChkUXCOVERS|"+FrmInput.ChkUXCOVERS.checked} 
   //Product interest dropdowns:
   if (IsExists("UXSPECIALS",FrmInput)){StrCookie+="|UXSPECIALS|"+FrmInput.UXSPECIALS.selectedIndex}
   if (IsExists("UXFILMS",FrmInput)){StrCookie+="|UXFILMS|"+FrmInput.UXFILMS.selectedIndex}
   //Form specific - Product sample/catalogue:
   //(no details saved for this form) 
   //Form specific - Alert preferences:
   if (IsExists("CmbUZHTML",FrmInput)){StrCookie+="|CmbUZHTML|"+FrmInput.CmbUZHTML.selectedIndex}
   if (IsExists("UZHTML",FrmInput)){StrCookie+="|UZHTML|"+FrmInput.UZHTML.value}  
   if (IsExists("UZOFFERS",FrmInput)){StrCookie+="|UZOFFERS|"+FrmInput.UZOFFERS.selectedIndex}   
   if (IsExists("ChkUZREMOVE",FrmInput)){StrCookie+="|ChkUZREMOVE|"+FrmInput.ChkUZREMOVE.checked} 
   //alert(StrCookie);
   }
//if choose not to remember, then just remember this!
StrCookie = StrCookie+"|rememberdetails|"+IsStore+"|";
//setCookie(ContactCookie, StrCookie, ExpDate);
setCookie(ContactCookie, StrCookie);
}

//IsMailOptionsForm is for when form is EMAIL alerts option form
function PopulateFormFromContactDetailsCookie(IdxForm){
var FrmInput=document.forms[IdxForm];
//Repopulate if cookie doesn't exist (use defaults) or if it does & RememberDetails is on
var IsRetrieve=(!IsCookieExists(ContactCookie)) || eval(GetCookieField(ContactCookie,"rememberdetails"));
if (IsRetrieve==true){
   //Contact details fields - basic (all forms):  
   SafeSetDropdownFromCookie("SECR",ContactCookie,FrmInput,0);
   SafeSetEditBoxFromCookie("DEAR",ContactCookie,FrmInput);
   SafeSetEditBoxFromCookie("LASTNAME",ContactCookie,FrmInput);
   SafeSetEditBoxFromCookie("CONTACT",ContactCookie,FrmInput);
   //Contact details fields - extended:  	
   SafeSetEditBoxFromCookie("PHONE1",ContactCookie,FrmInput);
   SafeSetEditBoxFromCookie("FAX",ContactCookie,FrmInput);
   SafeSetEditBoxFromCookie("EMAIL",ContactCookie,FrmInput);
   SafeSetEditBoxFromCookie("COMPANY",ContactCookie,FrmInput);
   SafeSetEditBoxFromCookie("TITLE",ContactCookie,FrmInput);
   SafeSetEditBoxFromCookie("ADDRESS1",ContactCookie,FrmInput);
   SafeSetEditBoxFromCookie("ADDRESS2",ContactCookie,FrmInput);
   SafeSetEditBoxFromCookie("CITY",ContactCookie,FrmInput);
   SafeSetEditBoxFromCookie("STATE",ContactCookie,FrmInput);
   SafeSetEditBoxFromCookie("ZIP",ContactCookie,FrmInput);
   SafeSetEditBoxFromCookie("COUNTRY",ContactCookie,FrmInput);
   //Form specific
   //Product interest checkboxes:   
   SafeSetCheckBoxAndHiddenFromCookie("ChkUXSTANDARD",ContactCookie,FrmInput);	  
   SafeSetCheckBoxAndHiddenFromCookie("ChkUXCARRIER",ContactCookie,FrmInput);	
   SafeSetCheckBoxAndHiddenFromCookie("ChkUXPACKING",ContactCookie,FrmInput);	
   SafeSetCheckBoxAndHiddenFromCookie("ChkUXMAILERS",ContactCookie,FrmInput);	
   SafeSetCheckBoxAndHiddenFromCookie("ChkUXCARRIERP",ContactCookie,FrmInput);	
   SafeSetCheckBoxAndHiddenFromCookie("ChkUXENVIRO",ContactCookie,FrmInput);	
   SafeSetCheckBoxAndHiddenFromCookie("ChkUXGRIPZIP",ContactCookie,FrmInput);	
   SafeSetCheckBoxAndHiddenFromCookie("ChkUXBUBBLE",ContactCookie,FrmInput);	
   SafeSetCheckBoxAndHiddenFromCookie("ChkUXSEALER",ContactCookie,FrmInput);	
   SafeSetCheckBoxAndHiddenFromCookie("ChkUXRETAIL",ContactCookie,FrmInput);	
   SafeSetCheckBoxAndHiddenFromCookie("ChkUXLAYFLAT",ContactCookie,FrmInput);	
   SafeSetCheckBoxAndHiddenFromCookie("ChkUXSACKS",ContactCookie,FrmInput);	
   SafeSetCheckBoxAndHiddenFromCookie("ChkUXCOVERS",ContactCookie,FrmInput);	  
   //Product interest dropdowns:
   SafeSetDropdownFromCookie("UXSPECIALS",ContactCookie,FrmInput,0);
   SafeSetDropdownFromCookie("UXFILMS",ContactCookie,FrmInput,0);
   //Form specific - Product sample/catalogue:
   //(no details saved for this form) 
   //Form specific - Alert preferences:
   SafeSetDropdownFromCookie("CmbUZHTML",ContactCookie,FrmInput,0);
   SafeSetEditBoxFromCookie("UZHTML",ContactCookie,FrmInput);
   SafeSetDropdownFromCookie("UZOFFERS",ContactCookie,FrmInput,1);//ie default to every 3 months
   SafeSetCheckBoxAndHiddenFromCookie("ChkUZREMOVE",ContactCookie,FrmInput);	
   //if not remembering, have remembered this..oh the irony!
   SafeSetCheckBoxFromCookie("rememberdetails",ContactCookie,FrmInput);	  
  }
return true;
}

//------------------------------------
//Population from parameters:
//------------------------------------

//uses jparams - see _DOCUMENTATION.htm for accepted list of params 
function PopulateFromParams(IdxForm){
//take params for active window
//First try & set any paramaters from the _Top CompetitorCheaperProductURL
SetParameters(top);
PopulateFromPreReadParams(IdxForm);
//Then try & set from the active window as well/instead
SetParameters(window);
PopulateFromPreReadParams(IdxForm);
}

function PopulateFromPreReadParams(IdxForm){
var FrmInput=document.forms[IdxForm];
// - nb SafeSetCheckAndHidden(... ,false) copes with checkboxes without a hidden joint text field too
//contact details fields - only populates if the parameters are present & not '' blank strings
SafeSetEditBox('EMAIL',FrmInput,GetParameterValue('e'),false);
SafeSetEditBox('DEAR',FrmInput,GetParameterValue('dear'),false);
SafeSetEditBox('LASTNAME',FrmInput,GetParameterValue('last'),false);
SafeSetEditBox('PHONE1',FrmInput,GetParameterValue('phn'),false);
SafeSetEditBox('COMPANY',FrmInput,GetParameterValue('comp'),false);
SafeSetEditBox('ZIP',FrmInput,GetParameterValue('zip'),false);
//sample request:
Str=GetParameterValue('sample');
if (Str!=''){
   SafeSetEditBox('UZSAMPLE',FrmInput,GetParameterValue('sample'),false);  
   SafeSetCheckAndHidden('REQUESTSAMPLE',FrmInput,true,false);//ie checked, no hidden equivalent field  
   }
//catalogue request:
SafeSetCheckAndHidden('ChkUZCATALOGU',FrmInput,GetParameterValue('cat'),true);//ie checked, no hidden equivalent field  
//safesetcheck 
}
//-->
