/****************************************************************************************
                  Script to save or recover the values of form inputs
                   v1.0 written by Mark Wilton-Jones, 11-12/11/2003
*****************************************************************************************

Please see http://www.howtocreate.co.uk/jslibs/ for details and a demo of this script
Please see http://www.howtocreate.co.uk/jslibs/termsOfUse.html for terms of use

The script can save the values of:
text inputs
textareas
password inputs (optional)
radio buttons
checkbox inputs
select inputs

To use this, insert the following into the head of your document:

<script src="PATH TO SCRIPT/saveFormValues.js" language="javascript1.2" type="text/javascript"></script>

I suggest using my cookie script to save the form inputs into a cookie, which can be
recovered using the same script (the amount of form information that can be stored
will be limited by the maximum size of document.cookie - 4KB encoded):

<script src="PATH TO SCRIPT/saveFormValues.js" language="javascript1.2" type="text/javascript"></script>
<script src="PATH TO SCRIPT/cookie.js" language="javascript1.2" type="text/javascript"></script>
...
setCookie( 'formInputs', getFormString( document.forms.myForm, true ), 604800 );
...
recoverInputs( document.forms.myForm, retrieveCookie( 'formInputs' ), true );
...

This header file provides two functions:
var input_values_string = getFormString( reference to the form, bool: include password fields );
recoverInputs( reference to the form, input_values_string, bool: include password fields );

Opera 5 and 6 (not 7) will produce a prompt asking for permission to access password
fields. If many of your visitors use this browser, I suggest that you do not save
password values.

It is best not to use this script with forms whose inputs (or select options) are
generated with JavaScript.

Please see http://www.howtocreate.co.uk/tutorials/jsexamples/saveForm.html for
examples of how to use this script, and important notes.
_______________________________________________________________________________________*/

function getFormString( formRef, oAndPass ) {
	for( var x = 0, oStr = '', y = false; formRef.elements[x]; x++ ) {
		if( formRef.elements[x].type ) {
			var oE = formRef.elements[x]; var oT = oE.type.toLowerCase();
			if( oT == 'text' || ( oT == 'password' && oAndPass ) ) {
				oStr += ( y ? ',' : '' ) + oE.value.replace(/%/g,'%p').replace(/,/g,'%c');
				y = true;
			} else if( oT == 'radio' || oT == 'checkbox' ) {
				oStr += ( y ? ',' : '' ) + ( oE.checked ? '1' : '' );
				y = true;
			} else if( oT == 'select-one' ) {
				oStr += ( y ? ',' : '' ) + oE.selectedIndex;
				y = true;
			} else if( oT == 'select-multiple' ) {
				for( var oO = oE.options, i = 0; oO[i]; i++ ) {
					oStr += ( y ? ',' : '' ) + ( oO[i].selected ? '1' : '' );
					y = true;
				}
			}
		}
	}
	return oStr;
}

function recoverInputs( formRef, oStr, oAndPass ) {
	if( oStr ) {
		oStr = oStr.split( ',' );
		for( var x = 0, y = 0; formRef.elements[x]; x++ ) {
			if( formRef.elements[x].type ) {
				var oE = formRef.elements[x]; var oT = oE.type.toLowerCase();
				if( oT == 'text' || oT == 'textarea' || ( oT == 'password' && oAndPass ) ) {
					oE.value = oStr[y].replace(/%c/g,',').replace(/%p/g,'%');
					y++;
				} else if( oT == 'radio' || oT == 'checkbox' ) {
					oE.checked = oStr[y] ? true : false;
					y++;
				} else if( oT == 'select-one' ) {
					oE.selectedIndex = parseInt( oStr[y] );
					y++;
				} else if( oT == 'select-multiple' ) {
					for( var oO = oE.options, i = 0; oO[i]; i++ ) {
						oO[i].selected = oStr[y] ? true : false;
						y++;
					}
				}
			}
		}
	}
}

function saveIt(Remember,Values) {
  if (Remember == 1) {
    setCookie('techblogmoKo',Values,9000000,'/');
  }
  else {
    setCookie('techblogmoKo','');

  } 

// if(document.forms['komm'].elements['remember'].checked==1) {setCookie('moKo',getFormString(this.form,true));} else {setCookie('moKo',getFormString('',true));}


}
