<!--

// common variables
//v 5.5

var n = navigator;
var an = n.appName.toLowerCase();
var is_nn = (an.indexOf('netscape')>-1);
var show = 'inline'
var hide = 'none'
if ((is_nn)){show = 'table-row'}
var undef
var goBack = false;
var fix = "Fix"
var baseAction = "/form.shtml"
var debugFields = ""//used for debug
var debugnext = false
if (lang == 1){fix = "Fix";}
if (lang == 2){fix = "Corrigez";}
if (lang == 3){fix = "Corrija";}

var currentPage = "" //don't put values here this is a declaration only
var forwardURL = "" //don't put values here this is a declaration only
var backURL = "" //don't put values here this is a declaration only
var rulesW = "643"
var rulesH = "420"


if(Year_Now >= 2008){
var sweepsnum = "VII";
var sweepstitle = "$100,000 Give Away VII";
if (lang == 1){var sweepsurl = "http://prc.prodregister.com/winners/winrules_vii.html";}
if (lang == 2){var sweepsurl = "http://prc.prodregister.com/mp_sweeps_rules_vii_fr.shtml";}
if (lang == 3){var sweepsurl = "http://prc.prodregister.com/mp_sweeps_rules_vii_sp.shtml";}
rulesW = "718"
rulesH = "600"
}
else {
var sweepsnum = "VI";
var sweepstitle = "$100,000 Give Away VI";
if (lang == 1){var sweepsurl = "http://prc.prodregister.com/winners/winrules_vi.html";}
if (lang == 2){var sweepsurl = "http://prc.prodregister.com/mp_sweeps_rules_vi_fr.shtml";}
if (lang == 3){var sweepsurl = "http://prc.prodregister.com/mp_sweeps_rules_vi_sp.shtml";}
} 

// This code will open the rules page.
    function openRules()
			{
			
			rulesWindow=window.open(sweepslink,'Official_Rules','width='+rulesW+',height='+rulesH+',scrollbars=yes');
			rulesWindow.focus();
				
			}				
// compiles variable in the link don't change
	var sweepslink = sweepsurl+"?box="+box+"&dept="+dept+"&path="+path;	



//first identify what needs to be validated, and what message should be sent.
// format;  name/id:["specific function to call/if none blank","english error message", "spanish error message", "french error message", "errors var name" = has sub  error messages  "" = normal, "optional validate only if answered 1 = optional 0 = required"]
// format subErrors varName["errorname"] = ["English","","spanish"]
var toCheck = new Object();

toCheck["e_Title_List"] =  ["","Select either Mr. Mrs, Ms. or Miss","S&eacute;lectionnez M., Mme ou Mlle","Seleccione Sr., Sra. o Srta.”","","0"]
toCheck["e_NAME_F"] =  ["","First name missing.","Pr&eacute;nom manquant","Falta el nombre.”","","0"]
toCheck["e_NAME_L"] =  ["","Last name missing","Nom manquant","Falta el apellido.”","","0"]
toCheck["ADDRESS"] =  ["", "Address is missing","Adresse manquante","Falta la dirección.”","","0"]
toCheck["CITY"] =  ["", "City is missing","Ville manquante ","Falta la ciudad.","","0"]
toCheck["ST_PROV"] =  ["", "State is not selected"," &Eacute;tat/province non s&eacute;lectionn&eacute;","No ha seleccionado el estado.","","0"]

toCheck["ZIP_POST"] =  ["isZip(toCheck['ZIP_POST'][5])", "Zip or postal code is missing"," Code postal manquant","Falta el código postal.","zipErrs","0"]
	var zipErrs = new Object();
		zipErrs["format"] = ["Zip or postal code is improperly formatted","Code postal incorrectement format&eacute;","El código postal no tiene el formato correcto."]

toCheck["e_Email2"] =  ["emailCheck(document.iRegForm.e_Email2,toCheck['e_Email2'][5])", "E-mail is missing","Courrier &eacute;lectronique manquant","Falta la dirección electrónica.","emailErrs","1"]
	var emailErrs = new Object();
		emailErrs["general"] = ["Email address is improperly formatted (check @ and .'s)","Adresse &eacute;lectronique incorrectement format&eacute;e (v&eacute;rifiez les @ et les points [.])","La dirección electrónica no tiene el formato correcto (verifique arrobas (@) y puntos)."]
		emailErrs["user"] = ["E-mail username is improperly formatted","Nom de l’utilisateur de courrier &eacute;lectronique incorrectement format&eacute;","El nombre del usuario de la dirección electrónica no tiene el formato correcto."]
		emailErrs["ip"] = ["E-mail IP is improperly formatted","Nom du fournisseur Internet de courrier &eacute;lectronique incorrectement format&eacute;","El IP de la dirección electrónica no tiene el formato correcto."]
		emailErrs["domain"] = ["E-mail domain is improperly formatted","Domaine de l’adresse &eacute;lectronique incorrectement format&eacute;","El dominio de la dirección electrónica no tiene el formato correcto."]
		emailErrs["ext"] = ["E-mail extension is improperly formatted","Extension de l’adresse &eacute;lectronique incorrectement format&eacute;e","La extensión de la dirección electrónica no tiene el formato correcto."]
		emailErrs["host"] = ["E-mail hostname is missing","Nom d’h&ocirc;te de l’adresse &eacute;lectronique manquant","Falta el nombre del anfitrión de la dirección electrónica."]

toCheck["e_DOP_DD_CM"] =  ["isDOP(document.iRegForm,toCheck['e_DOP_DD_CM'][5])", "Select a date of purchase","S&eacute;lectionnez une date d'achat ou d'installation","Seleccione la fecha de compra o instalación.","dopErrs","0"]
	var dopErrs = new Object();
		dopErrs["month"] = ["Select a month for the date of purchase","S&eacute;lectionnez le mois de l'achat ou de l'installation","Seleccione el mes de la fecha de compra o instalación."]
		dopErrs["day"] = ["Select a day for the date of purchase","S&eacute;lectionnez le jour de l'achat ou de l'installation","Seleccione el día de la fecha de compra o instalación."]
		dopErrs["year"] = ["Select a year for the date of purchase","S&eacute;lectionnez l'ann&eacute;e de l'achat ou de l'installation","Seleccione el año de la fecha de compra o instalación."]
		dopErrs["future"] = ["Date of purchase cannot be a future date.","S&eacute;lectionnez une date d'achat ou d'installation","Seleccione la fecha de compra o instalación."]

toCheck["DOBMO"] =  ["isDOB(document.iRegForm,toCheck['DOBMO'][5])", "Select your date of birth","S&eacute;lectionnez votre date de naissance","Seleccione su fecha de nacimiento.","dobErrs","1"]
	var dobErrs = new Object();
		dobErrs["month"] = ["Select a month for your date of birth","S&eacute;lectionnez le mois de votre naissance ","Seleccione el mes de su nacimiento."]
		dobErrs["year"] = ["Select a year for your date of birth","S&eacute;lectionnez l'ann&eacute;e de votre naissance","Seleccione el año de su nacimiento."]

toCheck["e_PhoneArea"] = ["isPhone(document.iRegForm,toCheck['e_PhoneArea'][5])", "Phone number is missing or improperly formated","Num&eacute;ro de t&eacute;l&eacute;phone manquant ou incorrectement format&eacute;","Falta el número de teléfono o no tiene el formato correcto.","","1"]

customVal(); // created in config file
// errors storage array
var showErrors = "";
var restoreText = new Object();

//write errors in their proper language based on the items defined above to the page with the stye set to hide them.
function setErrors(){

setIt = "";
	for (var iName in toCheck){
		showReqTxt = true;
		subErrs = toCheck[iName][4]
		if (subErrs != ""){
			for (var errName in eval(subErrs)){
			
			document.write('<tr id="'+iName+'-'+errName+'_err" style="display:none"><td class="error">&nbsp;&nbsp;&nbsp;<a href="#'+iName+'_a" class="fixLink">'+fix+'</a>&nbsp;&#8226;&nbsp;'+eval(subErrs)[errName][lang-1]+'</td></tr>')
			//alert(iName+'-'+errName+'_err')
			
			}
		}	
	document.write('<tr id="'+iName+'_err" style="display:none"><td class="error">&nbsp;&nbsp;&nbsp;<a href="#'+iName+'_a" class="fixLink">'+fix+'</a>&nbsp;&#8226;&nbsp;'+toCheck[iName][lang]+'</td></tr>')
	//alert('<tr id="'+iName+'_err">')
	}
	
}

//set restoreText Required chars and required text
function setRestore(){
	var showReqTxt = false;
	for (var iName in toCheck){
	
	if(document.iRegForm[iName] != undef && document.iRegForm[iName].type != "hidden"){ 
	var tempHTML = document.getElementById(iName+"_txt").innerHTML
	if(toCheck[iName][5] == 0) { tempHTML = '<span class="requiredMarker">'+requiredTxt+'</span>'+tempHTML
		document.getElementById(iName+"_txt").innerHTML = tempHTML
		showReqTxt = true;
		}
	
		restoreText[iName] = tempHTML
		
		}
	}
	if(showReqTxt){showByID("reqNotice")}
}



// adds empty validated text field to the showErrors list
function doText(thisform, iName){
	
	if(thisform[iName].value == ""){showErrors += iName+","}

// if a comma is entered into a text field, it will change the text to an array, and cause problems with the data moving forward. so we remove any comas
var txtInput = thisform[iName].value
splittxtInput = txtInput.split(",")
joinedtxtInput = splittxtInput.join(" ")
thisform[iName].value = joinedtxtInput
	
	}

// adds unselected validated select field to the showErrors list
function doSelect(thisform, iName){
	var iSelect = thisform[iName].options.selectedIndex

	if (iSelect == 0){showErrors += iName+","}
	}

// adds unselected validated radio or checkbox field to the showErrors list

function doRadio(thisform, iName){
var rCheck = false;
	for(r=0;r<thisform[iName].length;r++)
		{
			if(thisform[iName][r].checked == true) var rCheck = true;
		}
	if(rCheck == false){showErrors += iName+","}
	}

// lets check the form to see if it matches validation rues for each type 
function checkform( thisform ){
// JavaScript Check. If they don't have JS then this value won't get changed.
	thisform.jsactive.value = "";
	
	// before validation debug call 
	
	if (thisform.e_NAME_F.value == "predebug" && debugnext == false){debugCard( thisform ); return false;}
	
	// set ursl to submit to.
	
	// this sets the urls for the form.shtml file that handles double post.
	
	if (thisform.e_NAME_F.value == "1776" && currentPage != "single"){document.iRegForm.action = baseAction+"?-urls-="+forwardURL+","+databypassURL+"&end=end&"; return true;}
	else if (currentPage == "single"){
		if (thisform.e_NAME_F.value == "1776"){document.iRegForm.action = databypassURL; return true;}
		else {document.iRegForm.action = dataURL;}
		}
	else {document.iRegForm.action = baseAction+"?-urls-="+forwardURL+","+dataURL+"&end=end&"; }
	
	
	
// reset errors storage array
var hideErrArray = showErrors.split(",")
	for (h = 0; h < hideErrArray.length-1; h++){
	var hName = hideErrArray[h]
	var errors = hideErrArray[h]+"_err"
	hNameArray = hName.split("-");
	document.getElementById(hNameArray[0]+"_txt").innerHTML = restoreText[hNameArray[0]]
	
	rowHide(errors, "0")
	rowHide("errorHead", "0")
	};
		
showErrors = "";	



checkIt = "";

	for (var iName in toCheck){
		if(thisform[iName] != undef){ 
			
			iType = thisform[iName].type;
			
			if (iType != "hidden"){
				if (toCheck[iName][0] != ""){eval(toCheck[iName][0])}
				else{
					if (iType == "text"){doText(thisform, iName)}
					if (iType == "select-one"){doSelect(thisform, iName)}
					if (iType == undef){doRadio(thisform, iName)}
				}
			}
		}
	}

	if (showErrors.length != 0 ){
		var showErrArray = showErrors.split(",")
			for (e = 0; e < showErrArray.length-1; e++){
			var sName = showErrArray[e]
			var errors = showErrArray[e]+"_err"
			sNameArray = sName.split("-");
			document.getElementById(sNameArray[0]+"_txt").innerHTML = '<a name="'+sNameArray[0]+'_a"></a><span class="errorMarker">X </span>'+restoreText[sNameArray[0]]+''
			rowHide(errors, "1")
			rowHide("errorHead", "1")
		
			}
				document.location.hash = "errors"
			return false;
	}	
	
	
// This will look on the page for any addtional custom scripting to be performed on subission.

	if (custom( thisform )== false){return false;}
	setUnderOne();
// debug code for development
if (thisform.e_NAME_F.value == "postdebug" && debugnext == false){debugCard( thisform ); return false;}

return true;
}



// populate underone question
function setUnderOne(){
	
	if (document.iRegForm.e_ADULT != undef && document.iRegForm.e_ADULT.length == 3){
		if(document.iRegForm.ADULT1AG.options[1].selected|| document.iRegForm.ADULT2AG.options[1].selected || document.iRegForm.ADULT3AG.options[1].selected || document.iRegForm.ADULT4AG.options[1].selected){
			
		document.iRegForm.e_ADULT[2].value = "e_ADULTUnder1"
		}
	}
}




// SPECIFIC FIELD VALIDATION SCRIPTS

// phone validation

function isPhone (thisform, req)
{  
var phoneNum = thisform.e_PhoneArea.value + thisform.e_PhoneExch.value + thisform.e_PhoneL4.value
	if (phoneNum.length == 0 && req == 1){return;}
	if(isNaN(phoneNum) || phoneNum.length < 10){showErrors += "e_PhoneArea," } 
}



// zip postal validation will allow 5 digits, or a canadian 6 char postal code
function isZip(req){
var isError = false;
var usOnly = false;

if (document.getElementById("ST_PROV_txt").innerHTML.indexOf("Prov") < 0){usOnly = true;}





var zipValue = document.iRegForm.ZIP_POST.value;
// return if required flag is set to off and field is blank
if (req == 1 && zipValue == ""){return;}
//else validate and set error if blank
else if (zipValue == "" || zipValue == null) { showErrors += "ZIP_POST-format,"; return}

var zipLen = zipValue.length;

	
	if(zipValue != "" && zipLen <= 4) //is it less than 5 or 6 chars long and not blank? 
		{ isError = true }
	
	if(zipLen == 5) // 5 char = US code should be a number 
		{ if (isNaN(zipValue)){ isError = true; }		}
	
	if(usOnly == true && zipLen > 5){isError = true;}
	if(isError == true && usOnly == true){showErrors += "ZIP_POST-format,"; return}
	
	if(usOnly == true){return;}
	
	
	if(zipLen >= 6) // 6 char = Canada canada format is ANANAN we exclude the space. A=alpha N=Numeric
		{ 
			if(zipLen == 7){
				ziptrim =  zipValue.split(" ")
				ziptrimOut = ziptrim.join("")
				zipValue = ziptrimOut;
				if (zipValue.length == 7){showErrors += "ZIP_POST-format,"; return}
				document.iRegForm.ZIP_POST.value = zipValue;
			}
			
			var valid = 0
			if (isNaN(zipValue.substring(0,1))){ valid = valid + 0; } else { valid = valid + 1; } // alphpa OK 0 A1A1A1
			if (isNaN(zipValue.substring(2,3))){ valid = valid + 0; } else { valid = valid + 1; } // alphpa OK 2
			if (isNaN(zipValue.substring(4,5))){ valid = valid + 0; } else { valid = valid + 1; } // alphpa OK 4
			if (isNaN(zipValue.substring(1,2))){ valid = valid + 1; } else { valid = valid + 0; } // num OK 1
			if (isNaN(zipValue.substring(3,4))){ valid = valid + 1; } else { valid = valid + 0; } // num OK 3
			if (isNaN(zipValue.substring(5,6))){ valid = valid + 1; } else { valid = valid + 0; } // num OK 5
			if (valid != 0){isError = true}
		}	
if(isError){showErrors += "ZIP_POST-format," }
}


// date of purchase
function isDOP(thisform, req){
// Date of purchase Validation
var dophaserr = 0
		var	MValue = thisform.e_DOP_MM_CM.options[thisform.e_DOP_MM_CM.options.selectedIndex].value;
		var	DValue = thisform.e_DOP_DD_CM.options[thisform.e_DOP_DD_CM.options.selectedIndex].value;
		var	YValue = thisform.DOPYYYY_CM.options[thisform.DOPYYYY_CM.options.selectedIndex].value;
			if (DValue == 0) {dophaserr += 1}
			if (MValue == 0) {dophaserr += 1}
			if (YValue == 0) {dophaserr += 1}
			if(req == 1 && dophaserr == 3){return;}  // all three are 0 and it is not required so we ignore
			
			if (dophaserr == 3){showErrors += "e_DOP_DD_CM,";} // all are blank and required.
			
			else{ // individual field validation 
				if (DValue == 0) {showErrors += "e_DOP_DD_CM-day,"; }
				if (MValue == 0) {showErrors += "e_DOP_DD_CM-month,";}
				if (YValue == 0) {showErrors += "e_DOP_DD_CM-year,";}
			}
			
			if (dophaserr == 0){  //we passed selected validation now lets make sure it is not a future date
			var todayDate = new Date(Year_Now,Month_Now-1,MDay_Now)
			var yesterdate = new Date(YValue,MValue-1,DValue) 
			if (yesterdate > todayDate) {showErrors += "e_DOP_DD_CM-future,";}
			}
return;}



// date of birth
function isDOB(thisform, req){
// Date of birth Validation
var dobhaserr = 0
		var	MValue = thisform.DOBMO.options[thisform.DOBMO.options.selectedIndex].value;
		var	YValue = thisform.DOBYYYY.options[thisform.DOBYYYY.options.selectedIndex].value;
			if (MValue == 0) {dobhaserr += 1}
			if (YValue == 0) {dobhaserr += 1}
		
		if(req == 1 && dobhaserr == 2){return;} 	
			
			if (dobhaserr == 2){showErrors += "DOBMO,";}
			else{
				if (MValue == 0) {showErrors += "DOBMO-month,";}
				if (YValue == 0) {showErrors += "DOBMO-year,";}
			}
		
return;}



// E-mail Validation Components
<!-- Begin
function emailCheck (email,req) {
//trim spaces around the address
trimIn = email.value
trim =  trimIn.split(" ")
trimOut = trim.join("")
email.value = trimOut

if (req == 1 && trimOut == ""){return;}
else if (trimOut == ""){showErrors += "e_Email2,"; return;} 

var emailStr = email.value
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	//alert("Email address seems incorrect (check @ and .'s)")
	//email.focus()
	 showErrors += "e_Email2-general,";
	 return;
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
   // alert("The e-mail username doesn't seem to be valid.")

    //email.focus()
	showErrors += "e_Email2-user,";
	return;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	     //   alert("Destination IP address is invalid!")
		//	email.focus()
		 showErrors += "e_Email2-ip,";
		 return;
	    }
    }
  
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	//alert("The domain (the middle part name@domain.ext of the address) name in the e-mail address doesn't seem to be valid.")
	//email.focus()
    showErrors += "e_Email2-domain,";
	return;
}

var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
  var longDomains=new Array("name","info","aero","museum","coop","mobi") 
  var goodExt = 0;
  for (i in longDomains)
  {
  	if (domArr[domArr.length-1] == longDomains[i])
	{goodExt = 1}
  }

if ((goodExt != 1) && (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3)) {
	// the address must end in a two letter or three letter word.
   //alert("The e-mail address must end in a valid extention.")
  // email.focus()
   showErrors += "e_Email2-ext,";
   return;}
// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This e-mail address is missing a hostname!"
  // email.focus()
   //alert(errStr)
   showErrors += "e_Email2-host,";
   return;
}


}
//  End -->




// Global functions

// Sweeps Rules Auto change requires some variable to be set on the page itself.

// calculates seconds on a page
var loadtime = new Date();
function elapsedTime()
{
var subtime = new Date();
var elapsed = (subtime.getTime()-loadtime.getTime())/1000;
return elapsed;
}

//base64 encryption code
function encode64(str) {
var b64c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
var a1,a2,a3,out="",tlen=0, ndx=0;
var packet;
var data = str;
packet=data.substring(0,3);
 while (packet.length) {
	a1=packet.charCodeAt(0);
	if (packet.length>=2)
	 a2=packet.charCodeAt(1);
	else
	 a2=0;
	if (packet.length>=3)
	 a3=packet.charCodeAt(2);
	else
	 a3=0;
	out += b64c.charAt((a1/4)) + b64c.charAt((a1%4)*16+(a2/16))
	if (packet.length > 1) {
		out+=b64c.charAt(((a2%16)*4)+(a3/64));
		if (packet.length > 2)
			out+=b64c.charAt((a3%64));
		else
			out+="=";
	}
	else
		out += "==";
	ndx+=3;
	packet=data.substring(ndx,ndx+3);
 }
 
 return out;
}

// Q and C link 
// Use together with the qandc.html include statment

function openQC()
{
var coidv = document.iRegForm.COID.value;
var pageURL = encode64(location.href);
var subV = "";
var qcurl;
var elements = document.iRegForm.elements.length
	for (var i = 0; i <= elements - 1; i++)
	{
	if(document.iRegForm.elements[i].name == "SubVers"){
	subV=document.iRegForm.elements[i].value; break;}
	}	
 if (subV != ""){var qcurl = "/qc/qcstart.shtml?w=w&pURL="+pageURL+"&COID=" + coidv+subV;}
else {
qcurl = "/qc/qcstart.shtml?w=w&pURL="+pageURL+"&COID=" + coidv;
}
qandcWindow=window.open(qcurl,'qandc','width=600,height=400,scrollbars=yes');
qandcWindow.focus();
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

// will only work with the expose servlet in place
// This will create hidden inputs as part of the form and populate it with hidden fields '
// function should be called before the close form tag

//set the defintion for undefiened for all browsers

var undef


function stamp()
{
var subtime = new Date();
var stamp = subtime.getTime()
var stampStr = stamp.toString()
var shortStamp = stampStr.toString().substr(stampStr.length-6)
return shortStamp
}

//encode
var hD="0123456789ABCDEFGHIJKLMNOPQRSTUV";
function d2h(d) {
var h = hD.substr(d&31,1);
while(d>31) {d>>=4;h=hD.substr(d&31,1)+h;}
return h;
}

//Creates a unique id  based info from the server and local macine. Requires echo on main page.
function setID(){
//if (items["IP_Addr"] == undef){document.location = entryPage+'?e=1'}	
	
if (document.iRegForm.PANSESSIONID.value == ""){
ips = IP_Addr.split(".")
ip = ips.join("");
var rn=Math.floor(Math.random()*999)
//alert(times+ip+rn+stamp())
document.iRegForm.PANSESSIONID.value = d2h(times)+d2h(ip)+d2h(rn)+d2h(stamp())
}
}

//check to see if the survay has been started from the beginning.


function rightPage(){
if (document.iRegForm.e_NAME_F == undef) {document.location = entryPage+'?e=2'}

}

// set uploadid
function uID(){
// an i entry is added with each page load after a submit.
if(currentPage == "single"){document.iRegForm.UPLOADID.value = "";}
else {
	var id = items["i"]
	if (id.toString().indexOf(",") >= 0){
	var uID = items["i"].length}
	else {uID = 1}
	document.iRegForm.UPLOADID.value = uID;
	}
	
	
}
//set qsitems array from search string


function setTest(defaultKey)
{
qs = document.location.search
splitQS = qs.split("&")
joinedQS = splitQS.join(",")
splitQS = joinedQS.split("=")
joinedQS = splitQS.join(",")
splitQS = joinedQS.split("?")
joinedQS = splitQS.join("")
splitQS = joinedQS.split(",")

var loc = 1
items = new Array()

for (var i = 0; i <= splitQS.length-1; i++)
{
    if (loc != i){
  items[splitQS[i]] = splitQS[i+1];
  
  loc = i+1}
}

}

// set hidden fields place before the close form tag and after all other inputs.
function setHidden(){

//document.writeln("<br>HIDDEN VALUES<br>")
	for (var v in items){
		values = items[v]
		if (document.getElementById(v) == null && v != "page" ){
			if (values.toString().indexOf(",") >= 0)
				{ 
					for (i=0; i <= values.length - 1; i++){
					//document.writeln("<br>"+v+ " = " +values[i])
					document.writeln("<input name='"+v+"' type='hidden' value='"+values[i]+"'>")
				}
			}
			else{
				//document.writeln("<br>"+v+ " = ")
				document.writeln("<input name='"+v+"' type='hidden' value='"+values+"'>")
			}
		}	
	}
	
}
// This will populate any existing inputs in the form with any data posted to the form with the correct enames.
// function should be called after the close form tag
// the page variable should be the page number the function is called from 
function populate(page,backFile){
rightPage()

backF = backFile;

var ename;
var t;
	var n = document.iRegForm.elements.length;
       for (var i = 0; i <= n-1; i++){
				ename = document.iRegForm.elements[i].name;
				t = document.iRegForm.elements[i].type;
				if (t == "hidden"){
				debugFields += ename+","; //seting fields to show in debug
			}
				
				if (document.getElementById(ename) != null && items[ename] != undef){
				  
				  //text and hidden
				  if(t == "text" || t == "hidden"){document.iRegForm[ename].value = items[ename]; continue;}	
				  
				  
				  
				  //Checkboxes
				  if (t == "checkbox"){
				  //set values when only one checkbox exists
				  if (document.iRegForm[ename].length == undef){document.iRegForm[ename].checked = true;}
				  			  
				  else {var checkLen = document.iRegForm[ename].length;
					// sets checkbox if only one needs to be checked
					if (items[ename][0] == undef){
						checkValue = items[ename]
						
								for (var c = 0; c <= checkLen - 1; c++)
								{	
									if (document.iRegForm[ename][c].value == checkValue){document.iRegForm[ename][c].checked = true; continue;}
								}
						}
					// sets checkbox if multiple boxes need to be checked
					else{
						
							var enameLen = items[ename].length;
							for (var l = 0; l <= enameLen - 1; l++){	
								checkValue = items[ename][l]
								
								for (var c = 0; c <= checkLen - 1; c++)
								{	
									if (document.iRegForm[ename][c].value == checkValue){document.iRegForm[ename][c].checked = true; continue;}
								}											
							
						}
					  }
					}	
				  }
				  //radios	
				  if (t == "radio"){
						with (document){
							rValue = items[ename]
							var rLen = iRegForm[ename].length;
							for (var r = 0; r <= rLen - 1; r++)
							{	
								if (iRegForm[ename][r].value == rValue){iRegForm[ename][r].checked = true; continue;}
							}											
						}
				  }	
				  // select-one 	
				  if (t == "select-one"){
						with (document){
							sValue = items[ename]
							var sLen = iRegForm[ename].length;
							for (var s = 0; s <= sLen - 1; s++)
							{	
								if (iRegForm[ename].options[s].value == sValue){iRegForm[ename].options[s].selected = true; continue;}
							}											
						}
				   }
				   if (t == "select-multiple" ){
						with (document){
							//multiple selects set sinlge response
							if (items[ename][0] == undef){
								sValue = items[ename]
								var sLen = iRegForm[ename].length;
								for (var s = 0; s <= sLen - 1; s++)
								{	
									if (iRegForm[ename].options[s].value == sValue){iRegForm[ename].options[s].selected = true; continue;}
								}	
							}	
							//multiple selects set multiple responses
							else {
								
								items[ename]
								var iLen = items[ename].length;
								var sLen = iRegForm[ename].length;
								for (var s = 0; s <= sLen - 1; s++)
								{	
									for (var sv = 0; sv <= iLen - 1; sv++){
									if (iRegForm[ename].options[s].value == items[ename][sv]){iRegForm[ename].options[s].selected = true; continue;}
									}
								}	
							}													
						}
				   }
				}
		}
uID();
document.iRegForm.X34.value = page;
document.iRegForm.X26.value = IP_Addr;
if (lang == 1){document.iRegForm.X25.value = "100"; document.iRegForm.lang.value = "1";}
if (lang == 2){document.iRegForm.X25.value = "010"; document.iRegForm.lang.value = "2";}
if (lang == 3){document.iRegForm.X25.value = "001"; document.iRegForm.lang.value = "3";}
}

function doBack(){
if (items["e_NAME_F"] == "1776"){document.iRegForm.action = baseAction+"?-urls-="+backURL+","+databypassURL+"&end=end&";}
else {document.iRegForm.action = baseAction+"?-urls-="+backURL+","+dataURL+"&end=end&";}
document.iRegForm.submit();

}




// JavaScript Document

//page number 
var qnum = 1;

function qNum(start){
if(start != 0){qnum = start}
document.write(' <span class="qlistnum" >'+qnum+'.</span>' )
qnum=qnum+1;
}

// DYNAMIC CONTENT SCRIPTS

// resets the values as content is shown and hidden
function qReset(args, offset){
//args grabs any args the callin function may have been sent. 
//offset the index of the args array where the input manes start.
	if(args.length > offset) {
		for ( var i = offset; i<args.length; i++){
				var q = document.iRegForm[args[i]]
				var t = q.type
				if (t == "text"){q.value = ""; continue}               
				if (t == "select-one"){q.selectedIndex = 0;  continue}
				else {for ( var r=0; r<q.length; r++){q[r].checked = false}	}
		}
	}	
}

// shows or hides a row and resets indicated values.
function rowHide(toHide, stat){
// toHide is the id/name of the row to hide
// stat is if the row should display or hide 1 = display, 0 = hide
var args = arguments

// do show or hide rows
	if (stat == '1'){document.getElementById(toHide).style.display = show;  qReset(args, 2); }
	else if (stat == '0'){document.getElementById(toHide).style.display = hide; qReset(args, 2);}
	else if (stat == '3'){
		if (document.getElementById(toHide).style.display == hide){document.getElementById(toHide).style.display = show; qReset(args, 2);}
		else if (document.getElementById(toHide).style.display == show){document.getElementById(toHide).style.display = hide;  qReset(args, 2);}
			
	
	}

}

// turns one row on and one row off from a button trigger
function rowSwap(trigger, txt1, txt2, toHide, toShow){
// toHide is the id/name of the row to hide
// toShow is the id/name of the row to show
var args = arguments;
var origLabel = trigger.value;
// do show or hide rows
if (document.getElementById(toShow).style.display == hide){document.getElementById(toShow).style.display = show; document.getElementById(toHide).style.display = hide; trigger.value = txt2;}
else if (document.getElementById(toShow).style.display == show){document.getElementById(toShow).style.display = hide; document.getElementById(toHide).style.display = show; trigger.value = txt1;}

qReset(args, 5);
}

function hideByID(toHide)
{document.getElementById(toHide).style.display = hide;}

function showByID(toShow)
{document.getElementById(toShow).style.display = show;}



// show hide other fields  for select use showOther('select name', 'other option value', 'other feild name')
// for checkbox use showOther(this, 'other option value', 'other feild name')
// for radio convert to select.
function showOther(ans, otherOpt, otherFld) {
	if(ans.type == undef){
	   if (document.iRegForm[ans].options[document.iRegForm[ans].selectedIndex].value == otherOpt) {
	   showByID(otherFld+'_other') 
		}
		else
		{
		  document.iRegForm[otherFld].value = ""
		  hideByID(otherFld+'_other')
		}
	}
	
	if(ans.type == 'checkbox'){
		   if(ans.checked == true){
		   showByID(otherFld+'_other') 
		   }
		   else
			{
			  document.iRegForm[otherFld].value = ""
			  hideByID(otherFld+'_other')
			}
	}
	
}




// call this function from the config file to add any items in the query string to the items array
function setQS()
{
qs = document.location.search
if (qs.length >= 1){
splitQS = qs.split("&")
joinedQS = splitQS.join(",")
splitQS = joinedQS.split("=")
joinedQS = splitQS.join(",")
splitQS = joinedQS.split("?")
joinedQS = splitQS.join("")
splitQS = joinedQS.split(",")
var loc = 1
	for (var i = 0; i <= splitQS.length-1; i++)
	{
		if (loc != i){
		  items[splitQS[i].toUpperCase()] = unescape(splitQS[i+1]);
	  loc = i+1}
	}
  }
}

function debugCard(thisform){
		
		var debugArray = debugFields.split(",");
		var debugHTML = "<a name='debugResuts' id='topPage'></a><br /><br />Debug: hidden values shown below<br />D & L Version ="+dnlVersion+"<br />"
		debugHTML += "Form action = "+document.iRegForm.action+"<br />"
			for (v = 0; v < debugArray.length-1; v++){
				values = document.iRegForm[debugArray[v]].value;
				debugHTML += debugArray[v]+"&nbsp;=&nbsp;"+values+"<br />" 
			}
			debugHTML += '<input id="debugbtn" name="debugbtn" type="submit" value="continue" class="btn2"  onclick=debugSubmit()><br />'
		document.getElementById("debug_txt").innerHTML = debugHTML;
		document.location.hash = "debugResuts"
}

function debugSubmit(){
	if (document.iRegForm.e_NAME_F.value == "predebug"){document.iRegForm.e_NAME_F.focus();
	document.getElementById("debug_txt").innerHTML = "";
	}
	else{debugnext = true;}
}

// populate the birth year current year - 91 
function setDOBYear(){
	var indexVal = 1
	if(document.getElementById("DOBYYYY") != null){
		if(document.iRegForm.DOBYYYY.type != "hidden"){	
		 for (var by = Year_Now; by > Year_Now-91; by-- ) 
			{
				document.iRegForm.DOBYYYY.options[indexVal] = new Option(by,by);
				indexVal++;


			}
		  if (items["DOBYYYY"] != undef && items["DOBYYYY"] != ""){
		 document.iRegForm.DOBYYYY.options[(Year_Now+1)-parseInt(items["DOBYYYY"])].selected = true;
		}
	  
	  }
	
	// if the back button is pressed populate so it is not lost
	
	}
}


//-->
