function fxBrowserTSY(){
  var Netscape, MSIE, Opera, AOL, Firefox, Unknown;
  var NetscapeVer, MSIEVer, OperaVer;
  
  Netscape = navigator.userAgent.indexOf("Netscape") > -1;
  Opera = navigator.userAgent.indexOf("Opera") > -1;
  Firefox = navigator.userAgent.indexOf("Firefox") > -1;
  MSIE = navigator.userAgent.indexOf("MSIE") > -1;
  AOL = navigator.userAgent.indexOf("AOL") > -1;
  Unknown = !(Netscape || MSIE || Opera || AOL || Firefox);

var strBrowser2;

if(Unknown){
	  strBrowser2 = "Unknown";
}else if(AOL){
	  strBrowser2 = "AOL ";
}else if(Opera){
	  strBrowser2 = "Opera ";
}else if(Firefox){
	  strBrowser2 = "Firefox ";
}else if(Netscape){
	  strBrowser2 = "Netscape ";
}else if(MSIE){
	  strBrowser2 = "MSIE ";
}
//alert(strBrowser2);
return strBrowser2
}
var MakeFormName = false;

function SaveYour(Mode) {
  var Val = "";
  var Val2 = "";
  var KVal = "";
  strBrowser2 = fxBrowserTSY();
  var nCtr = (strBrowser2 == "MSIE ") ? 4.1 : 1.1;
  if(Mode == 0) {
    for(var j=1; j<nCtr ; j++) {
  		var j1 = (j < nCtr) ? '0' + j : j;
		var Key = "TSY"+j1+escape(location.pathname);
    	var KVal = getTSY_Cookie(document.cookie,Key);
    	if(KVal == 0){
			if(j < 2){
				alert("No information has been saved\nYou must enter information into the fields FIRST, \nthen click the STORE button in the upper lefthand corner of the form.");
 				return false;
			}
		}else{
			Val = Val+KVal;
		}
	}
	writeOutput(false,Val);
	Val = strOutput;
	if(Val.indexOf("LoVeJesUS") != 0)alert(passwd+" is an invalid password.\nPlease try again.");
	Val = Val.substring(0,Val.length-1);
	strInput = "";
	strOutput = "";
	a = TSY_parse(Mode,Val,Val2);
  }

  if(Mode == 1) {
	var Val = TSY_parse(Mode,"","");
}

function TSY_parse(Mode,Val,Val2) {
  var Elms = TSY_Check("^(text|password|checkbox|radio|textarea|select-one)$");
//  var Elms = TSY_Check("^(text|password|checkbox|radio|textarea|select-one|hidden)$");
  var strValue = "";
  for(var n=0; n<Elms.length ; n+=2) {
    var Elm=Elms[n]; 
	var ElmN=Elms[n+1];
    switch(Mode) {
      case 0:
        var Str=getTSY_Cookie(Val,ElmN);
        if(Str != 0) {
          if(Elm.type == "checkbox" || Elm.type == "radio"){
			if (Elm.type == "radio"){
				var lcBracket = Str.substring(4,7);ElmR = Elm;ElmR.name = Elm.name+lcBracket;
				if (Str.indexOf(Elm.value,Str)!=-1)ElmR.checked = true;
			}else{
            	Elm.checked = (Str == "true");
			}
          }else{
            Elm.value = Str;
          }
        }
		break;
      case 1:
        if(Elm.type == "checkbox" || Elm.type == "radio"){
			if (Elm.type == "radio"){
				for (var xyz = 0; xyz < 10; xyz++){
					var ElmA = Elm;
				  if (Elm.checked){
				 	Val += ElmN+"=true["+xyz+"]"+Elm.value+";";
					xyz=10;
				  }
				}
			}else{
          		Val += ElmN+"="+Elm.checked+";";
			}
        }else{
		  if (Elm.value != ""){
			if (Elm.type == "textarea"){
				Val2 += ElmN+"="+escape(Elm.value)+";";
			}else{
				Val += ElmN+"="+escape(Elm.value)+";";
			}
		  }
        }
      }
	}
  if(Mode == 1){
    	strBrowser2 = fxBrowserTSY();
  		var nCtr = (strBrowser2 == "MSIE ") ? 4.1 : 1.1;
  		var Val3 = Val + Val2;
			for(var j=1; j<nCtr ; j++) {
				var j1 = (j < nCtr) ? '0' + j : j;
				var Key = "TSY"+j1+escape(location.pathname);
				setTSY_Cookie("",Key);
			}

		writeOutput(true,"LoVeJesUS"+Val3);
		Val3 = strOutput;
		if(Val3.length > 3850){ 
			Val3 = Val3.substring(0,3850);
			alert("Warning: Part of your last textbox will be truncated");
		}
		strInput = "";
		strOutput = "";
  		var Exp = new Date();
	  	var d_String = Exp.toGMTString();
	  	var Key = "TSY01"+escape(location.pathname);
	  	var nKey = Key.length+1;
	  	var nVal = Val3.length + 10 + d_String.length;
			var savedOK = 1;
			for(var j=1; j<nCtr ; j++) {
				var j1 = (j < nCtr) ? '0' + j : j;
				var Key = "TSY"+j1+escape(location.pathname);
				  if(strBrowser2 == "MSIE "){
					Val=Val3.substring((j-1)*1100,(j-1)*1100+1100);
				  }else{
					Val=Val3;
				  }
	  			if(nKey+nVal > nKey){
				    setTSY_Cookie(Val,Key);
					if(!valTSY_Cookie(Key)){
					  deleteTSY_Cookie(Key);
					  savedOK = 0;
					  break;
					}
				}else{
					if(Val != ""){
					    setTSY_Cookie(Val,Key);
						Val = "";
						if(!valTSY_Cookie(Key)){
						  savedOK = 0;
						  break;
						}
					}
				}
				nVal = nVal - 1200;
			}
			if(savedOK == 1){
				alert("The Save Your\n has STORED/SAVED your information\n       Your PASSWORD is: "+passwd+" \nPlease REMEMBER it.\n\nYour information will be saved \non this computer for upto 1 year.");
			}else{
				alert("Data NOT Saved, Error");
			}
//		window.close();
     }
  }
}

function valTSY_Cookie( Key ) {
	var start = document.cookie.indexOf( Key + "=" );
	if ( (start < 0 ) && ( Key != document.cookie.substring( 0, Key.length ) ) )
		{return false;}
	else
		{return true;}
}

function TSY_Check(Types) {
  var n=0; var Elms = new Array();
  for(var j=0; j<document.forms.length ; j++) {
    var Form = document.forms[j];
    var FormName = (Form.name.length>0) ? Form.name: (MakeFormName ? "forms["+j+"]" : "");
    for(var i=0; i<Form.elements.length; i++) {
      var Elm = Form.elements[i];
	  try{
      var ElmName = (Elm.name.length>0) ? Elm.name: "elements["+i+"]";
      if(Elm.type.toLowerCase().match(Types) != null) {
          Elms[n++]= Elm;
          Elms[n++]= FormName + "." + ElmName;
      }
	  }catch(err){}
    }
  }
  return(Elms);
}

function getTSY_Cookie(Val,Key) {
  var n1=Val.indexOf(Key+"=",0);
  if(n1<0) return(0);
  	n1 += Key.length + 1;
  	var n2 = Val.indexOf(";",n1);
  	if(n2<0) n2 = Val.length;
  		return( unescape(Val.substring(n1,n2)) );
}

function setTSY_Cookie(Val,Key) {
  var Exp = new Date();
  if( Val.length > 0 ) {
    Exp.setTime(Exp.getTime()+360*24*60*60*1000);
  }
  document.cookie = Key+ "=" + escape(Val)
    + "; expires=" + Exp.toGMTString();

  window.status = "Your data is S-A-V-E-D";
}

function deleteTSY_Cookie(Key) {
if ( getTSY_Cookie(document.cookie,Key) ) {
	setTSY_Cookie("",Key) + ";expires=Thu, 01-Jan-2000 00:00:01 GMT";
}
}




   var keyStr = "ABCDEFGHIJKLMNOP" +
      "QRSTUVWXYZabcdef" +
      "ghijklmnopqrstuv" +
      "wxyz0123456789+/" +
      "=";

   var numTestRegExp = /^[1-9][0-9]*$/;
   var passwd = "";

   function writeOutput(l_encrypt,strInput) {
      var output = "";
      var ciphertext = cipher(l_encrypt,strInput);


      // Add ciphertext
      for (var i = 0; i < ciphertext.length; i++) {
         if (i != 0 && i % 64 == 0) {
            output = output + "\n";
         }
         output = output + ciphertext.charAt(i);
      }

      if (l_encrypt) {
         strOutput = output;
      } else {
         strOutput = ciphertext;
      }
   }

   function cipher(l_encrypt,strInput) {
      strOutput = "             Performing Cipher...Please Wait";
      var input = "";
      if (l_encrypt) {
         input = strInput;
      	 passwd = prompt(txtTimeout+"Please make up and enter a Password and REMEMBER IT: ","")
      } else {
         input = decode64(strInput);
      	 passwd = prompt("Please enter the Password you CREATED when you Saved Your information: ","");
      }

      var output = "";
      var temp = "";
      var state = new Array(256);
      var key = new Array(10 + passwd.length);
      var i, j, z = 0;
      var N = 20;
      var offset = 0;

      // Prepare key
      for (i = 0; i < passwd.length; i++) {
         key[i] = passwd.charCodeAt(i);
      }
      if (l_encrypt) {
         // Create new random IV
         for (i = passwd.length; i < passwd.length + 10; i++) {
            key[i] = Math.round(Math.random() * 256);
            output = output + String.fromCharCode(key[i]);
         }
      } else {
         // Read IV from first 10 chars of input
         for (i = 0; i < 10; i++) {
            key[i + passwd.length] = input.charCodeAt(i);
         }
         input = input.substr(10, input.length - 10);
      }

      // Prepare state
      for (i = 0; i < 256; i++) {
         state[i] = i;
      }

      i = j = 0;
      for (z = 0; z < N; z++) {
         for (i = 0; i < 256; i++) {
            j = (key[i % key.length] + state[i] + j) & 255;
            temp = state[i];
            state[i] = state[j];
            state[j] = temp;
         }
      }

      i = j = 0;
      for (var index = 0; index < input.length; index++) {
         i = (i + 1) & 255;
         j = (state[i] + j) & 255;
         temp = state[i];
         state[i] = state[j];
         state[j] = temp;
         output = output + String.fromCharCode(state[(state[i] + state[j]) & 255] ^ input.charCodeAt(index));

      }

      if (l_encrypt) {
         output = encode64(output);
      }
      return output;
   }

   function encode64(input) {
      var output = "";
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;

      do {
         chr1 = input.charCodeAt(i++);
         chr2 = input.charCodeAt(i++);
         chr3 = input.charCodeAt(i++);

         enc1 = chr1 >> 2;
         enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
         enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
         enc4 = chr3 & 63;

         if (isNaN(chr2)) {
            enc3 = enc4 = 64;
         } else if (isNaN(chr3)) {
            enc4 = 64;
         }

         output = output +
            keyStr.charAt(enc1) +
            keyStr.charAt(enc2) +
            keyStr.charAt(enc3) +
            keyStr.charAt(enc4);
         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";
      } while (i < input.length);

      return output;
   }

   function decode64(input) {
      var output = "";
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;

      // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
      input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

      do {
         enc1 = keyStr.indexOf(input.charAt(i++));
         enc2 = keyStr.indexOf(input.charAt(i++));
         enc3 = keyStr.indexOf(input.charAt(i++));
         enc4 = keyStr.indexOf(input.charAt(i++));

         chr1 = (enc1 << 2) | (enc2 >> 4);
         chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
         chr3 = ((enc3 & 3) << 6) | enc4;

         output = output + String.fromCharCode(chr1);

         if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
         }
         if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
         }

         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";

      } while (i < input.length);

      return output;
   }


/*TSY Icons code - this js MUST be in the body where you want the icons to show up*/
document.write('<table width="99%" style="margin-left:0px;;" border="0"><tr>');
document.write('<td width="60"><a href="#" onclick="SaveYour(1,true);"><img src="http://www.TheSaveYour.com/images/thesaveyourS-6.gif" width="70px" height="60px" border="0" alt="Click to Save Your ... Form Info"></a>');
document.write('<td align="center">Click the "Store" button to save your information at any time (temporarily) and the "Recall" button to have your information re-populate the fields where you left off.<br />');
document.write('<a href="http://www.TheSaveYour.com" target="_blank">www.TheSaveYour.com</a></td>');
document.write('<td width="60"><a href="#" onclick="SaveYour(0);"><img src="http://www.TheSaveYour.com/images/thesaveyourF-6.gif" width="70px" height="60px" border="0" alt="Click to Fill Your ... Form Info"></a>');
document.write('</tr></table>');

window.setTimeout("fxCatchTimeout()", 890000);
var txtTimeout = "";
function fxCatchTimeout(){
	var txtTimeout = "Your form is about to time out on you.\n";
	SaveYour(1,true);
}
