// For more information, see the article 
//    "Pre-Fill Forms From Last Use" article linked from 
//    http://willmaster.com/possibilities/archives/index2.shtml
//
// This code may be used on any legal web site so long as 
//    the copyright, "more information" statement with link, 
//    and this sentence are left intact.
//


// Three customizations:

// ONE --
// What name shall the cookie have (should be different 
//    than any other cookie names that might be set on 
//    your domain)?

CookieName = 'fillFaq';


// TWO --
// How many days shall the cookie live on your user's 
//    computer? Use 0 (zero) for session cookie, a cookie 
//    that is removed when the browser is closed. Maximum 
//    3652 days (10 years).

DaysToLive = 1;

// THREE --
// If you want certain form field names to be equal to 
//    certain other form field names (for example, one 
//    of your forms might have a name="visitorname" field, 
//    another name="yourname", and another name="name", 
//    all of which ask for the visitor's name), list them 
//    here. When one is updated in the cookie, the others 
//    are, too.
//
// To specify certain form field names are equal to 
//    certain others, list them with an equal sign 
//    character between them (no space either side 
//    of the equal sign character). Example:
//
//    visitorname=yourname=name
//
// The above is one set. If you specify more than one 
//    set, different form field names for email address, 
//    for example, then separate the sets with a comma 
//    (no space either side of the comma). Example:
//
//   visitoremail=email=Email,visitorname=yourname=name
//
// (form field names are case senstive)
//
// Specify your field names here, between the single 
//    quote characters:

CookieFormFieldNameEquality = 'spoergsmaal=spoergsmaal';

//
// Note: Cookies larger than 4k might not be accepted 
//    by the browser.
//
//
//
//
// No other customizations required.
//
///////////////////////////////////////////////////////

Separator = '%%%';
CookieArray = new Array();
if(DaysToLive > 3652) { DaysToLive = 3652; }

function RememberFormFields(form,list)
{
var listArray = list.split(',');
var equalArray = CookieFormFieldNameEquality.split(',');
var holderArray = new Array();
for (var listArrayIterator = 0; listArrayIterator < listArray.length; listArrayIterator++) {
	var value = eval('document.' + form + '.' + listArray[listArrayIterator] + '.value');
	for (var equalArrayIterator = 0; equalArrayIterator < equalArray.length; equalArrayIterator++) {
		var boolflag = false;
		var tArray = equalArray[equalArrayIterator].split('=');
		for (var tArrayIterator = 0; tArrayIterator < tArray.length; tArrayIterator++) {
			if(tArray[tArrayIterator] == listArray[listArrayIterator]) { boolflag = true; }
			}
		if(boolflag == true) {
			for (var tArrayIterator = 0; tArrayIterator < tArray.length; tArrayIterator++) {
				if(tArray[tArrayIterator] != listArray[listArrayIterator]) { holderArray[holderArray.length] = tArray[tArrayIterator] + '=' + value; }
				}
			}
		}
	listArray[listArrayIterator] += '=' + value;
	}
var holderS = listArray.join(Separator) + Separator + holderArray.join(Separator);
listArray = holderS.split(Separator);
for (var listArrayIterator = 0; listArrayIterator < listArray.length; listArrayIterator++) {
	var boolflag = false;
	var tempArray = listArray[listArrayIterator].split('=',2);
	var name = tempArray[0];
	var value = tempArray[1];
	for (var CookieArrayIterator = 0; CookieArrayIterator < CookieArray.length; CookieArrayIterator++) {
		var tttArray = CookieArray[CookieArrayIterator].split('=',2);
		if(tttArray[0] == name) {
			tttArray[1] = value;
			CookieArray[CookieArrayIterator] = tttArray.join('=');
			boolflag = true;
			}
		}
	if(boolflag == false) { CookieArray[CookieArray.length] = name + '=' + value; }
	}
var exp = '';
if(DaysToLive > 0) {
	var now = new Date();
	then = now.getTime() + (DaysToLive * 24 * 60 * 60 * 1000);
	now.setTime(then);
	exp = '; expires=' + now.toGMTString();
	}
var cookiecontent = CookieArray.join(Separator);
document.cookie = CookieName + "=" + escape(cookiecontent) + '; path=/' + exp;
return true;
} // end of function RememberFormFields()


function PopulateFormFields(form,list)
{
var cookiecontent = '';
if(document.cookie.length > 0) {
	var cookiename = CookieName + '=';
	var cookiebegin = document.cookie.indexOf(cookiename);
	var cookieend = 0;
	if(cookiebegin > -1) {
		cookiebegin += cookiename.length;
		cookieend = document.cookie.indexOf(";",cookiebegin);
		if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
		cookiecontent = document.cookie.substring(cookiebegin,cookieend);
		}
	}
if(cookiecontent.length < 3) { return true; }
cookiecontent = unescape(cookiecontent);
CookieArray = cookiecontent.split(Separator);
var listArray = list.split(',');
for (var listArrayIterator = 0; listArrayIterator < listArray.length; listArrayIterator++) {
	for (var CookieArrayIterator = 0; CookieArrayIterator < CookieArray.length; CookieArrayIterator++) {
		var tttArray = CookieArray[CookieArrayIterator].split('=',2);
		if(tttArray[0] == listArray[listArrayIterator]) { eval("document." + form + "." + listArray[listArrayIterator] + ".value='" + tttArray[1] + "'"); }
		}
	}
return true;
}