//***********************************
//*   Define global variables  		*
//***********************************
	var	value = new String("");
	var hdngArr = new Array();
	var paramArr = new Array();
	var returnWindow = new String();
	var check = new Boolean();
	var dataList = new String("");
	var ID = new String("");
	var	deposit = new String("");
	var	crew = new String("");
	var rDate = new String("");
	var Regatta = new String("")

//********************************************************************
// Gets the parameters from the data following the ? in the URL.
// There can 3 parameters which are separated by ':'
// They include
//   0. The Entry ID
//   1. dataList which is identical the Cookie "Entry ID" or the Cookie "EntryData" if "Entry ID is "".
//   2. The check status on the feedback form.  It is always the last item in the parameters


function getParameters() {
  var Parameters = new String("");	// Input parameters following the URL starting with ?
  if(document.URL){ 	
	Parameters = window.location.search   //Get any parameters
	if(Parameters.indexOf('?') > -1) {    //There are parameters bein passed
	  Parameters = Parameters.substring(Parameters.indexOf('?')+1,Parameters.length)
	  paramArr = Parameters.split(':')    //Split at : into an array 
      if(!paramArr[0] || paramArr[0]=="")
	    ID = "EntryData"
	  else ID = unescape(paramArr[0])
      if (paramArr[1])
	    dataList = unescape(paramArr[1])
	  else
	    dataList = getCookie(ID)  
	  if(paramArr[2] && paramArr[2]=="true")
		check = true
	  else
		check = false
	  }
	else								//Ther are no parameters being passed
	  dataList = getCookie("EntryData")
//	tempArr = dataList.split('|')
//	for(i=0; i<tempArr.length/2; i++){
//	  hdngArr[i] = tempArr[2*i]}
  }
}

//********************************************************************
// Fill in registration form data from cookies associated with entry_ID
// The cookie is a list of name,value pairs containing the data in the form.
// Since the cookie has data for more both the RegistrationForm and the 
// RegistrationFormPart2 the first part of the function creates a hdngArr which
// is an array of field names.  
 
  function fillForm(frm) {

	for(i=0;i<frm.length;i++){
	  if(frm.elements[i].type == "hidden"||frm.elements[i].type == "submit"||frm.elements[i].type == "reset"|| frm.elements[i].type == "button") {
			continue
			}
		if(frm.elements[i].name == "Entry_ID")  // Don't include the entry ID
		    continue
	  frm.elements[i].value = getDataList(frm.elements[i].name)
		}
	return
	}


	
	function returnToFix(fForm) {
		  ver = navigator.appVersion
		  ver = ver.substr(0,ver.indexOf(" "))
		  if(ver > 4.1 && ver<4.9){
		  	alert("Please Close this Alert Window!")  // Don't know why this works for NN4.7
			}
		window.location = returnWindow
		return true
	}


//********************************************************************
// Set Cookies for the data needed by the waiver/release forms.
// the Cookies are set to expire on the date expire in the form of
// mm/dd/yy.  If expire is not set or set incorrectly the cookie 
// set to expire in a week.
  function putCookie(name,value,expire) {
		var exDate = new Date()     //initialize date to today
		var oneWeek = exDate.getTime() + (7*24*60*60*1000)
		
		exDate.setTime(oneWeek)     // one week later
		expire = validDate(expire)
		if(expire.indexOf('/')!=-1) {
		  var tArr = new Array()
		  tArr = expire.split('/')
		  exDate.setMonth(tArr[0]-1) //January starts at zero
		  exDate.setDate(tArr[1])
		  exDate.setYear("20"+tArr[2])
		  }
	    document.cookie = name + "="+ escape(value)+";expires="+exDate.toGMTString()
  }

//********************************************************************
  function resetCookies(name){
	putCookie(name,"","01/01/90")
  }

//********************************************************************
	function getCookie(name) {
		var cookies = document.cookie;
		
		var start = cookies.indexOf("; "+name + "=")
		if (start == -1) {
			start = cookies.indexOf(name + "=")
			if (start == -1) {
			  return ""
			  }
			}
		start = cookies.indexOf("=",start) + 1;
		var end =  cookies.indexOf(";",start);
		if(end ==-1) {
			end = cookies.length;
			}
		return unescape(cookies.substring(start,end))
		}

// The following functions manage a "List" of which describes entries in a form.
// The entries are sets of name value pairs separated by "|".  If the name exists in the "List"
// the data for that name is updated with the passed data.  If the name is not found in the "List",
// the name|value pair are the end of the "List". 

  function putList(name,value,list) {
    addStr = "|"+name+"|" + value
	if(list.length == 0)
	  addStr=addStr.substring(1,addStr.length)  //remove the leading |
	start=list.indexOf(name)
	if(start==-1) { //the name is not in the list
	  list = list+addStr  // name and value
	  return list
	  }
	start=list.indexOf("|",start)+1      // this is the start of the data
	end= list.indexOf("|",start)         // this is the end of the data unless its the last item in the list
	if(end==-1)
	  end = list.length
	list = list.substring(0,start) + value + list.substring(end,dataList.length)  // replace data only
  return list
  }

  function putDataList(name,value) {
  	dataList = putList(name,value,dataList)   // for commonality with old process
    return
  }

// function to get data contained in the "list" under the "name". If it is found 
// the data is returned, if not a blank string is returned
  function getList(name,list) {
	start=list.indexOf(name)
	if(start==-1) { //the name is not in the list
	  return ""
	  }
	start = list.indexOf("|",start)+1     // this is the start of the data
	end = dataList.indexOf("|",start)     // this is the end of the data unless its the last item in the list
	if(end==-1)
	  end = dataList.length
	return dataList.substring(start,end)
	}

  function getDataList(name) {            // for commonality with older code
	return getList(name,dataList)
  }


// Since the number of crew etc are changing the dataList is reset to the new event data
function resetDataList(frm) {
  choice = frm.Event.selectedIndex
  dataList=""  //Clear all data
  for(i = 0; i<Regatta0.length; i++) {
    putDataList(RegattaNames[0][i],RegattaNames[choice][i])
	}
  }

//********************************************************************
// Retrieves data from the form "frm" and adds it to "dataList" as |name|value pairs.
// i.e. form element names followed by the data contained in the element.
// The hidden, submit, and reset elements are skipped.  
// Any element named "Entry_ID is skipped. 
//*******************************************************************
  function getEntryData(frm) {
	for(i = 0; i<frm.elements.length; i++) {
		if(frm.elements[i].type == "hidden"||frm.elements[i].type == "submit"||frm.elements[i].type == "reset"|| frm.elements[i].type == "button") {
			continue
			}
		if(frm.elements[i].name == "Entry_ID")  // Don't include the entry ID
		    continue
		if(frm.elements[i].type == "checkbox") {
			putDataList(frm.elements[i].name,frm.elements[i].checked)
			continue
			}
		if(frm.elements[i].type == "select-one") {
			choice = frm.elements[i].selectedIndex
			if(choice<0) {
				putDataList(frm.elements[i].name," ")
				}
			else {
				putDataList(frm.elements[i].name,frm.elements[i].options[choice].value)
				}
			continue
			}
		putDataList(frm.elements[i].name,frm.elements[i].value)
		}
  }
  
 // ***************************************************************************************************************************
 // getYear(adate as string formatted mm/dd/yy or mm/dd/yyyy), getMonth(adate as string), and getDay(adate as string)are function which parse a date string
 // and return the string portion for the year, month, or day respectively as a string.  The Year will be a 2 digit year.  
 // If there are Errors then it returns False  
 // getFullYear(adate as string) returns the 4 digit
 // *************************************************************************************************************************


	function getFullYear(strdate){
		var cdate = new Date() 							    // current date
		var yr = new Number(getYear(strdate))
		var cYear = new Number(cdate.getFullYear())
		if(yr > cYear-2000+1) {  //cover cross over year
			yr += 1900
			}
		else {
			yr += 2000
			}
		return yr
	}
	
	function getYear(strdate){
		if(strdate=="") {
			return false}
		arrDate = new Array (3)
		arrDate = strdate.split('/')
		yr = arrDate[2]
		if(!isNum(yr))
			return false
		if(yr.length==4){
	  		yr = yr.substring(2,4)
	  	}
		if(yr<0 || yr>99)
			return false
		return yr
	}

	function getMonth(strdate){
		if(strdate=="") {
			return false}
		arrDate = new Array (3)
		arrDate = strdate.split('/')
		if(!isNum(arrDate[0]))
			return false
		if(arrDate[0]<1 || arrDate[0]>12)
			return false
		return arrDate[0]
	}

	function getDay(strdate){
		if(strdate=="") {
			return false}
		arrDate = new Array (3)
		arrDate = strdate.split('/')
		if(!isNum(arrDate[1]))
			return false
		if(arrDate[1]<1 || arrDate[1]>31)
			return false
		return arrDate[1]
	}
	
/****************************************************************************************************
 * getParentURL  returns the portion of the URL that pertains to the Parent of the current page		*
 * it strips off anything (including) beyond the ? and strips of the string beyond the last 		*
 ***************************************************************************************************/
		function getParentURL(){
		var newURL=document.URL
		
		newURL = newURL.substring(0,newURL.indexOf('?'))
		newURL = newURL.substring(0,newURL.lastIndexOf("/"))
		return newURL
		}

/****************************************************************************************************
 * getThisPage  returns the portion of the URL that pertains to  the current page					*
 * it strips off anything (including) beyond the ? and returns the last piece of the URL	 		*
 ***************************************************************************************************/
		function getParentRel(){
		var newURL = getParentURL()
		
		var strtString
		if(newURL.indexOf(".com/")>0) {
			strtString = newURL.indexOf(".com/") + 5}
		else if(newURL.indexOf(".org/")>0) {
			strtString = newURL.indexOf(".org/") + 5}
		else if(newURL.indexOf(".gov/")>0) {
			strtString = newURL.indexOf(".gov/") + 5}
		else if(newURL.indexOf(".net/")>0) {
			strtString = newURL.indexOf(".net/") + 5}
		else 
			alert("Couldn't find the domain name of the site. getParentURL() in formManagement.js")
		newURL = newURL.substring(strtString,newURL.length)
		return newURL
		}
