$j(document).ready(function() {
	
	try {
		initMouseEvents();
	} catch(e) 
	{};
	try 
	{showSidebar();} catch(e) {};
	
	$j('#notmarsearch').submit(function() {
  		return checkTextSubmit('e');
	});
	
	$j("#eprofilelogin_btn").click(function() {
		$j("#userid2").val($j("#userid").val());
		$j("#pass2").val($j("#pass").val());
		$j("#lang2").val($j("#lang").val());

		if ($j('#profilelogin_frm').length > 0) {
		$j("#profilelogin_frm").validate({
		     rules: {
		       userid: { required: true,email: true },
		       pass : { required: true }
		     },
				submitHandler: function() { 	
			   	
				$j.ajax({
					type: "POST",
					url: "/search/userCategoryHelper.php",
					data: $j("#profilelogin_frm").serializeArray(),
					success: function(data) {
						
						if (data == "1") {
							// write error to error div
							$j("#loginerror_txt").html("Error: There was an error with your E-Mail/Password combination. Please try again.");
						} else if (data == "2") {

							$j("#profilelogin_success").submit();
						
					} else  {
						//provide user_category interstitial if valid
						$j("#userCategoryRequest").html(data);
						}
				  } 
				 });	     
		    	 }
		  }); 
		  }	
	});
						
	$j("#createprofile_frm").validate({
					rules: {
					pass: { required: true},
					pass2 : { required: true },
					notmar_user_category: { required: true }
		     },
			 messages: {
				 userid:" Required",
				 pass:" Required",
				 notmar_user_category:" Required"
			 }
		});							

	$j("#usercategory_interstitial_frm").live('submit',function() {
		if ($j("#notmar_user_category").val() == undefined) {  	
			$j("#user_category_label").addClass("ntmerror");
			return false;
		}
		   
		$j.ajax({
					type: "POST",
					url: "/search/userCategoryHelper.php",
					data: $j("#usercategory_interstitial_frm").serializeArray(),
					success: function(data) {
						//alert(data);
					}
		});
		
	});
	$j("#usercategory_chart_interstitial_frm").live('submit',function() {
		if ($j("#notmar_user_category").val() == "") {  	
			$j("#user_category_label").addClass("ntmerror");
			return false;
		}
		$j.ajax({
					
					type: "POST",
					url: "/search/userCategoryHelper.php",
					data: $j("#usercategory_chart_interstitial_frm").serializeArray(),
					success: function(data) {
						$j(".user_category_frm").hide();
						$j("#ntm_data").show();
						return false;
				
					}
					
			});
		return false;
	});
	
	//bind events for search controls
	$j('#search_chart').focus(function() {
		clearDefault(this);
		selectChartReset();
	});
	
	$j('#search_product').focus(function() {
		enterChartReset();
	});
	
	$j('#startMonth').change(function() {
		changeList($j('#startMonth'),$j('#startDay').val(),'e');
	});
	
	$j("#privacy_accept").live('change',function() {
		
		if ($j('#privacyform #privacy_accept').is(':checked'))
		{
			getDivSel('accept','e','3','privacy');
		}
	});
	
	$j("#privacy_decline").live('change',function() {
	
	if ($j('#privacyform #privacy_decline').is(':checked'))
	{
		getDivSel('decline','e','3','privacy');
	}
	});
	
	$j("#privacy_agreelink").live('click',function() {
		$j('#privacyform').submit();
	});
	
	//user profile
	
	$j("#noticesSelect").live('change',function() {
		
		var NoticeChoice = $j('#noticesSelect').val(); 
		if (NoticeChoice != "") {
			window.location.replace(NoticeChoice);
		}
	});
	
});

function disclaimer(lang) {
          if (lang == "English") {
             alert("This page contains notices which have been released by the Canadian Coast Guard prior to the year 2000.  They are not necessarily active and are not to be relied upon.  DFO accepts no liability whatsoever for consequences resulting from any reliance upon them.");
        } else {
             alert("Cette page contient des avis qui ont �t� �mis par la Garde c�ti�re canadienne entre janvier 1997 et d�cembre 1999. Il ne sont pas n�cessairement actifs et on ne doit pas s�y fier. Le MPO d�cline toute responsabilit� pour les cons�quences r�sultant de l�utilisation de ces donn�es.");
        }
}

function setfocus() { 
	document.profile.userid.focus(); 
}



function checkemail(form1) {

    Ctrl = $j('#notmarsearch').userid;

    if(Ctrl.value == "" || Ctrl.value.indexOf("@") < 0 || Ctrl.value.indexOf(".") < 0) {

        validatePrompt (Ctrl, "Please enter a valid e-mail address.\nThis will be your Notmar profile identifier")

        return(false);

    }

            if ($j('#notmarsearch').pass1.value == ""){

             alert(" Please enter a password ");

             return false;

        }

        if ($j('#notmarsearch').pass1.value != $j('#notmarsearch').pass2.value){

             alert(" Passwords do not match ");

             return false;

        }   else {

        return(true);

    }

}

function validAnswers(form1) {

return false;
if ($j('#user_category').val() == "default") {
	alert(" Please provide a NOTMAR user category ");
	$j('#user_category').focus();

    return false;
}
	
 if ($j('#notmarsearch').pass.value == ""){

      alert(" Please enter a password ");

      return false;

 }

 if ($j('#notmarsearch').pass.value != $j('#notmarsearch').pass2.value){

      alert(" Passwords do not match ");

      return false;

 }

 else{

      return true;

 }

}



function helpWindow(file) {

        window.open(file,'email','toolbar=no,width=400,height=300,directories=no,scrollbars=no,resizable=no,menubar=no,status=no')

}



function gotocharts(form) {	

	var product = document.forms['f'].product.options[document.forms['f'].product.selectedIndex].value;

	

}



function testEmail(form1) {

    Ctrl = $j('#notmarsearch').userid;

    if(Ctrl.value == "" || Ctrl.value.indexOf("@") < 0 || Ctrl.value.indexOf(".") < 0) {

        validatePrompt (Ctrl, "Please enter a valid e-mail address.\nThis will be your Notmar profile identifier")

        return(false);

    } else {

        return(true);

    }

}


function validPassword(form1) {

 if ($j('#notmarsearch').pass1.value == ""){

      alert(" Please enter a password ");

      return false;

 }

 if ($j('#notmarsearch').pass1.value != $j('#notmarsearch').pass2.value){

      alert(" Passwords do not match ");

      return false;

 }

 else{

      return true;

 }

}



function validPasswoprdLogin(form1) {

 if ($j('#notmarsearch').pass.value == ""){

      alert(" Please enter a password ");

      return false;

 }

 else{

      return true;

 }

}

function runSubmitLogin (form1) {

	
    var dataString = 'userid=' + $j("#userid").val() + '&pass=' + $j("#pass").val();
	$j.ajax({
		type: "POST",
		url: "/search/userCategoryHelper.php",
		data: dataString,
		success: function(data) {
		$j("#userCategoryRequest").html(data);
	  } 
	 });
	
	
	return false;
	
	
        if(!testEmail($j('#notmarsearch'))){

         return(false);

        }
		
        if(! validPasswoprdLogin($j('#notmarsearch'))){

         return(false);

        }

        else {

            return(true);

        }

}

function runSubmit (form1) {

        if(!testEmail($j('#notmarsearch'))){

         return(false);

        }
		
        if(! validPassword($j('#notmarsearch'))){

         return(false);

        }


        else {

            return(true);

        }

}

function runSubmitDelete (form1) {

		Ctrl = $j('#notmarsearch').user;
		
		if(Ctrl.value == "" || Ctrl.value.indexOf("@") < 0 || Ctrl.value.indexOf(".") < 0) {
		
			validatePrompt (Ctrl, "Please enter a valid e-mail address.\n")
		
			return(false);
		
		}
		
		if ($j('#notmarsearch').pass1.value == ""){
		
			alert(" Please enter a password ");
				
			return false;
		
		}


        else {

			var agree=confirm("Are you sure you want to delete your Notmar Profile?");
			if (agree)
				return true ;
			else
				return false ;

        }

}

function validatePrompt (Ctrl, PromptStr) {

        alert (PromptStr)

        Ctrl.focus();

        return(true);

}



function MM_openBrWindow(theURL,winName,features) { //v2.0

     window.open(theURL,winName,features);

}


function SelectAll(fieldName){

var checker = true;

var len = document.forms['f'].elements.length;

    for (var i=0; i<len; i++){

         var e = document.forms['f'].elements[i];

         e.checked = checker;

    }

}


function deSelectAll(fieldName){

var checker = false;

var len = document.forms['f'].elements.length;

    for (var i=0; i<len; i++){

         var e = document.forms['f'].elements[i];

         e.checked = checker;

    }

}

function atleastone_chart(form1) { 

	atleastonechart = 0;
	
	for (var i=0; i < document.forms['notmarsearch'].product.length; i++) {
						
		thisbox = "c"+document.forms['notmarsearch'].product.options[i].value;	

		if(document.getElementById(i)) {
			atleastonechart = 1;
			i = document.forms['notmarsearch'].product.length;
		}   
		
	}
	
	if(atleastonechart == 0) {
		alert("You must add at least one chart to create a profile");
	 	return(false);

	} else {
		
		return(true);

	}
}



	
	 var printthelist=new Array();
	
// function to check the checkboxes and make them appear based on the selectbox   
 	function showCheckbox() {	
	
	theselectedoptions = document.forms['notmarsearch'].product.selectedIndex;
	printthis="<table border='0' width='400'><tr>";

			printthelist[0] = "";
			cellcounter = 0;
			for (var i=0; i < document.forms['notmarsearch'].product.length; i++) {
			
				if(document.forms['notmarsearch'].product.options[i].selected == true) {
							
					thisboxlabel = document.forms['notmarsearch'].product.options[i].text;
					thisbox = "c"+document.forms['notmarsearch'].product.options[i].value;	
					
					if(document.getElementById(thisbox)) {

					} else {
						printthelist[i] = "<td align='center'>"+thisboxlabel+"<br><input id=\""+i+"\" type=\"checkbox\" name=\""+thisbox+"\" value=\""+thisbox+"\" checked></td>";
						
					}					
				
				}
				if( printthelist[i]) {
					printthis += printthelist[i];
						cellcounter++;
						if(cellcounter > 6){
							printthis += "</tr><tr>";
							cellcounter = 0;
						}				
						
				}
			//}
			
						 
		} 
		printthis+="</tr></table>";
		
		  if (document.all){
               document.all.chartListing.innerHTML = printthis;
          }
          if(!document.all && document.getElementById){
               document.getElementById("chartListing").innerHTML = printthis;
          }
		  /*
          if(document.layers){
                    chartListing = document.layers["chartListing"];
                    chartListing.document.open();
                    chartListing.document.write(printthis);
                    chartListing.document.close();
          }
		 */
	}  		
	
// function to check the checkboxes and make them appear based on the selectbox   
 	function showCheckbox2(form1) {	
	
	//theselectedoptions = document.form1.product.options[document.form1.product.selectedIndex].value;
	//alert("Selected Charts: "+theselectedoptions);
	theselectedoptions = document.forms['notmarsearch'].product.selectedIndex;
		printthis="";
		
		if(document.forms['notmarsearch'].product.options[0].selected == true) {			
			thisboxlabel = document.forms['notmarsearch'].product.options[0].text;
			thisbox = "c"+document.forms['notmarsearch'].product.options[0].value;	
			startloop = "0";
				
			//printthelist[0] = thisboxlabel+"<input id=\"0\" type=\"checkbox\" name=\""+thisbox+"\" value=\"all\" onClick=\"uncheckCharts(form1,'"+thisbox+"',"+startloop+")\" checked>";
			printthelist[0] = thisboxlabel+"<input id=\"0\" type=\"checkbox\" name=\""+thisbox+"\" value=\"all\" checked>";	
	
			printthis += printthelist[0]; 
			for (var i=1; i< document.forms['notmarsearch'].product.length; i++) {											
					if(printthelist[i]){
						printthelist[i] = ""; 
					}
			}	
					
		} else {
			printthelist[0] = "";
			for (var i=1; i < document.forms['notmarsearch'].product.length; i++) {
			
				if(document.forms['notmarsearch'].product.options[i].selected == true) {
							
					thisboxlabel = document.forms['notmarsearch'].product.options[i].text;
					thisbox = "c"+document.forms['notmarsearch'].product.options[i].value;	
					
					if(document.getElementById(thisbox)) {

					} else {
						//printthelist[i] = thisboxlabel+"<input id=\""+i+"\" type=\"checkbox\" name=\""+thisbox+"\" value=\""+thisbox+"\" onClick=\"uncheckCharts(form1,'"+thisboxlabel+"',"+i+")\" checked>";
						printthelist[i] = thisboxlabel+"<input id=\""+i+"\" type=\"checkbox\" name=\""+thisbox+"\" value=\""+thisbox+"\" checked>";
						//alert(printthelist[i]);
					}

				
				}
				if( printthelist[i]) {
					printthis += printthelist[i]; 
				}
			}

						 
		} 
		
		
		  if (document.all){
               document.all.chartListing.innerHTML = printthis;
          }
          if(!document.all && document.getElementById){
               document.getElementById("chartListing").innerHTML = printthis;
          }
		  /*
          if(document.layers){
                    chartListing = document.layers["chartListing"];
                    chartListing.document.open();
                    chartListing.document.write(printthis);
                    chartListing.document.close();
          }
		 */
	}  		
		
// function to uncheck the chart checkboxes and make them disappear
	function uncheckCharts2(form1,deleteChartLabel,labelNum) {
	
	
	//alert(deleteChartLabel);
		deleteChart = "c" + deleteChartLabel;
		
		if(labelNum == "0"){
			deleteChart = "call";		
			printthelistDel = "Select All Charts<input id=\"0\" type=\"checkbox\" name=\"call\" value=\"all\" checked>";		
		
		} else {										
			printthelistDel = deleteChartLabel+"<input id=\""+labelNum+"\" type=\"checkbox\" name=\""+deleteChart+"\" value=\""+deleteChart+"\" checked>";										
			
			//alert(printthelistDel);
		}
		printthis = (printthis.replace(printthelistDel, ""));
		printthelist[labelNum] = "";
		
		document.forms['notmarsearch'].product.options[labelNum].selected = false;
		
		  if (document.all){
               document.all.chartListing.innerHTML = printthis;
          }
          if(!document.all && document.getElementById){
               document.getElementById("chartListing").innerHTML = printthis;
          }

	}				
	

	
// function to uncheck the chart checkboxes and make them disappear
	function uncheckCharts(form1,deleteChartLabel,labelNum) {
	
		deleteChart = "c" + deleteChartLabel;
		printthelist[labelNum] = "";
		
		document.getElementById(labelNum).checked = false;		
		document.forms['notmarsearch'].product.options[labelNum].selected = false;
		
		thisboxlabel = document.forms['notmarsearch'].product.options[labelNum].text;
		thisbox = "c"+document.forms['notmarsearch'].product.options[labelNum].value;
					
		printthelistcheck = "<td align='center'>"+thisboxlabel+"<br><input id=\""+labelNum+"\" type=\"checkbox\" name=\""+thisbox+"\" value=\""+thisbox+"\" onClick=\"uncheckCharts(form1,'"+thisboxlabel+"',"+labelNum+")\" checked></td>";

		var printthis2 = printthis.split(printthelistcheck);
		checkCount = printthis2[0].split("br");
	    printthis=printthis2[0];
		
			cellcountrows = (checkCount.length % 7); 
			
			if(cellcountrows > 0) {
				cellcounter = cellcountrows;
			} else {
			
				cellcounter = 7;
			}
			//alert(labelNum+"  "+document.form1.product.length);
			for (var i=labelNum; i < document.forms['notmarsearch'].product.length; i++) {
					thisboxlabel = document.forms['notmarsearch'].product.options[i].text;
					thisbox = "c"+document.forms['notmarsearch'].product.options[i].value;
										
					if(document.getElementById(i)) {
						if(document.getElementById(i).checked == true) {
							//printthelist[i] = "<td align='center'>"+thisboxlabel+"<br><input id=\""+i+"\" type=\"checkbox\" name=\""+thisbox+"\" value=\""+thisbox+"\" onClick=\"uncheckCharts(form1,'"+thisboxlabel+"',"+i+")\" checked></td>";
							//alert(printthelist[i]);
						}
					} 	
				
				
				if( printthelist[i]) {
					printthis += printthelist[i];
						
					if(cellcounter > 6){
						printthis += "</tr><tr>";
						cellcounter = 0;
					}				
					cellcounter++;
				}
			}
					
		   //alert(printthis);
		
		  printthis+="</tr></table>";

		
		  if (document.all){
               document.all.chartListing.innerHTML = printthis;
          }
          if(!document.all && document.getElementById){
               document.getElementById("chartListing").innerHTML = printthis;
          }
		
	}
		
// function to setup the checkboxes when the page first loads
	function setupCheckboxes() {
			
		for (var i=0; i<document.forms['notmarsearch'].product.length; i++) {	
				printthelist[i] = "";		
		}		
		
	}   
	
	
// function to setup the checkboxes when the page first loads
	function PresetupCheckboxes() {
	//showalljsstuff="";
		
		for (var i=0; i<document.forms['notmarsearch'].product.length; i++) {		
		
		
			printthelist[i] = "";		
			//showalljsstuff += "printthelist["+i+"] = '';<br>";
		}		
		
		
		  if (document.all){
               document.all.chartListing.innerHTML = printthis;
          }
          if(!document.all && document.getElementById){
               document.getElementById("chartListing").innerHTML = printthis;
          }
		  
	}  	


// function to uncheck the chart checkboxes and make them disappear
	function uncheckChartstest(form1) {

			printthis="<table border='0' width='400'><tr>";
			cellcountrows =1;
			
			if(cellcountrows > 0) {
				cellcounter = cellcountrows;
			} else {
			
				cellcounter = 7;
			}
			//alert(labelNum+"  "+document.form1.product.length);
			for (var i=1; i < document.forms['notmarsearch'].product.length; i++) {
					thisboxlabel = document.forms['notmarsearch'].product.options[i].text;
					thisbox = "c"+document.forms['notmarsearch'].product.options[i].value;
										
					if(document.getElementById(i)) {
						if(document.getElementById(i).checked == true) {
							printthelist[i] = "<td align='center'>"+thisboxlabel+"<br><input id=\""+i+"\" type=\"checkbox\" name=\""+thisbox+"\" value=\""+thisbox+"\" checked></td>";
							//alert(printthelist[i]);
						} else {
							//alert(thisbox);
							printthelist[i] = "";
						}
					} 	
				
				
				if( printthelist[i]) {
					printthis += printthelist[i];
						
					if(cellcounter > 6){
						printthis += "</tr><tr>";
						cellcounter = 0;
					}				
					cellcounter++;
				}
			}
					
		   //alert(printthis);
		
		  printthis+="</tr></table>";

		
		  if (document.all){
               document.all.chartListing.innerHTML = printthis;
          }
          if(!document.all && document.getElementById){
               document.getElementById("chartListing").innerHTML = printthis;
          }
		
	}
	// below moved from date_listboxes.js
	//I think this is trying to reset the date 
	function emptyList(master) {

		 while (master.options.length) master.options[0] = null;

	}


	function fillList(master, arr, selectedOption) {

		 for ( i = 0; i < arr[0].length; i++ ) {

			   option = new Option( arr[0][i], arr[1][i] );

			   master.options[master.length] = option;

			   if( arr[1][i] == selectedOption)

			   {
				   master.selectedIndex=i;
			   }

		 }

	}

	
	function changeList2(master,slave,txtlang,selectedOption) {

		if(txtlang == "e"){
			var dateslists2 = new Array();
			dateslists2['months'] = new Array();
			dateslists2['months'][0] = new Array('Jan','Feb','March','April','May','June','July','August','Sept','Oct','Nov','Dec');
			dateslists2['months'][1] = new Array('01','02','03','04','05','06','07','08','09','10','11','12');
		} else {
			var dateslists2 = new Array();
			dateslists2['months'] = new Array();
			dateslists2['months'][0] = new Array('Jan','Fev','Mar','Avr','Mai','Juin','Juil','Août','Sep','Oct','Nov','Dec');
			dateslists2['months'][1] = new Array('01','02','03','04','05','06','07','08','09','10','11','12');	
		}
		
		now = new Date;
		currentMonth = now.getMonth();
		currentMonth = currentMonth +1;
	
		 list = dateslists2[master];

		 emptyList( slave );

		 fillList( slave, list, currentMonth );

	}
	
	
	function changeList(master,slave,txtlang,selectedOption) {

		 if(txtlang == "e") 
		 {
				var dateslists = new Array(); 
				
				dateslists['years'] = new Array();
				dateslists['years'][0] = new Array('2000','2001','2002','2003','2004','2005');
				dateslists['years'][1] = new Array('2000','2001','2002','2003','2004','2005');
				
				dateslists['months'] = new Array();
				dateslists['months'][0] = new Array('Jan','Feb','March','April','May','June','July','August','Sept','Oct','Nov','Dec');
				dateslists['months'][1] = new Array('01','02','03','04','05','06','07','08','09','10','11','12');
				
				dateslists['01'] = new Array();
				dateslists['01'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				dateslists['01'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				
				dateslists['02'] = new Array();
				dateslists['02'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28');
				dateslists['02'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28');
				
				dateslists['03'] = new Array();
				dateslists['03'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				dateslists['03'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				
				dateslists['04'] = new Array();
				dateslists['04'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30');
				dateslists['04'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30');
				
				dateslists['05'] = new Array();
				dateslists['05'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				dateslists['05'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				
				dateslists['06'] = new Array();
				dateslists['06'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30');
				dateslists['06'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30');
				
				dateslists['07'] = new Array();
				dateslists['07'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				dateslists['07'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				
				dateslists['08'] = new Array();
				dateslists['08'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				dateslists['08'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				
				dateslists['09'] = new Array();
				dateslists['09'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30');
				dateslists['09'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30');
				
				dateslists['10'] = new Array();
				dateslists['10'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				dateslists['10'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				
				dateslists['11'] = new Array();
				dateslists['11'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30');
				dateslists['11'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30');
				
				dateslists['12'] = new Array();
				dateslists['12'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				dateslists['12'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
							
		 } 
		 else 
		 {
			 
				var dateslists = new Array(); 
				
				dateslists['months'] = new Array();
				dateslists['months'][0] = new Array('Jan','Fev','Mar','Avr','Mai','Juin','Juil','Août','Sep','Oct','Nov','Dec');
				dateslists['months'][1] = new Array('01','02','03','04','05','06','07','08','09','10','11','12');
				
				dateslists['01'] = new Array();
				dateslists['01'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				dateslists['01'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				
				dateslists['02'] = new Array();
				dateslists['02'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28');
				dateslists['02'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28');
				
				dateslists['03'] = new Array();
				dateslists['03'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				dateslists['03'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				
				dateslists['04'] = new Array();
				dateslists['04'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30');
				dateslists['04'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30');
				
				dateslists['05'] = new Array();
				dateslists['05'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				dateslists['05'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				
				dateslists['06'] = new Array();
				dateslists['06'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30');
				dateslists['06'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30');
				
				dateslists['07'] = new Array();
				dateslists['07'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				dateslists['07'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				
				dateslists['08'] = new Array();
				dateslists['08'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				dateslists['08'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				
				dateslists['09'] = new Array();
				dateslists['09'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','30');
				dateslists['09'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','30');
				
				dateslists['10'] = new Array();
				dateslists['10'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				dateslists['10'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				
				dateslists['11'] = new Array();
				dateslists['11'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30');
				dateslists['11'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30');
				
				dateslists['12'] = new Array();
				dateslists['12'][0] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
				dateslists['12'][1] = new Array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
							
		 }
		 
		// list = dateslists[master.options[master.selectedIndex].value];
		 list = dateslists[$j('#startMonth').val()];

		 emptyList( slave );
		
		 fillList( slave, list, selectedOption );

	}

function lastDay(form1) { 
	var TheOptions = document.forms['notmarsearch'].endDay.options.length - 1;
	document.forms['notmarsearch'].endDay.selectedIndex = TheOptions;
}

function curMonthSel(form1) { 
	now = new Date;
	var currentMonth = now.getMonth();
		
	document.forms['notmarsearch'].endMonth.selectedIndex = currentMonth;
}

function checkTextSubmit(txtlang) {
	
	var msgString = "";

	var emsgString = "The chart number entered may no longer be valid or may not exist, please verify the chart number and enter it again. To identify replaced or withdrawn charts please consult Section 1 of the Monthly Notices to Mariners current edition and archives.\n\nPlease feel free to visit the Canadian Hydrographic Services (CHS) site which also provides the list of replaced and withdrawn charts by clicking on the link found on the \"Search Notmar\" Page.";
	
	var fmsgString = "Le numéro de la carte que vous avez entré pourrait ne plus être valide ou pourrait ne pas exister. Veuillez vérifier le numéro de la carte et l’entrer de nouveau.  Pour repérerles cartes qui ont été retirées ou remplacées, consultez la partie 1 de l’édition mensuelle récente des Avis aux navigateurs ou les archives.\n\nVous pouvez visiter le site Web du Service hydrographique du Canada (SHC) qui fournit aussi la liste des cartes retirées ou remplacées en cliquant sur le lien \"Recherche dans Notmar\".";
	
	if (txtlang == "e")
	{
		msgString = emsgString;
	} else {
		msgString = fmsgString;	
	}
	
	var pattern=new RegExp("[0-9]{4}");

	//check for 4 digit product code from select control if entry is not default of nil from select control
	var productcheck = document.forms['notmarsearch'].product.options[document.forms['notmarsearch'].product.selectedIndex].value;
	if (productcheck != "nil")
	{
		var producttst = pattern.exec(productcheck);
	
		if (producttst == null)
		{
			alert (msgString);
				 return false;	
		} else {
			return true;
		}
	}
	
	//check for 4 digit product code
	var charttst = pattern.exec(document.forms['notmarsearch'].chart.value);
	
	if (charttst == null)
	{
		alert (msgString);
			 return false;	
	}

	//check that 4 digit product code entered is valid product
	var nochart=0;
	
	for (var i=0; i < document.forms['notmarsearch'].product.length; i++)
	{						
		productlisttst = document.forms['notmarsearch'].product.options[i].value;	
			
		if (productlisttst == charttst) 
		{
			 nochart = 1; 
		}
	}

	if (nochart == 0) {			
		 alert (msgString);
		 return false;	
	} else {
		return true ;
	}
}
