// Function to allow one JavaScript file to be included within another
function Fetch_pepScript(jsFile)
{
  document.write('<script type="text/javascript" src="'
    + jsFile + '"> </script>'); 
}

Fetch_pepScript('pg_scripts/chk_email_address.js');

function alertValueM()
{
var x=document.getElementById("sequence");
// alert("You are looking for a store or stores secured by the password " + "'"+ x.value+"'");

if (x.value.length< 4) 
 {
 alert("Not a valid password. Less than 4 characters in length. Please re-enter.");
	document.getelementbyid("sequence").focus(); 
//	document.getElementById("sequence").select();
// document.getElementById("chg4").innerHTML = '5678'; 
  return false;
} 
return true;
} // end of function

function Capital(my_string)
{
// Capitalize Words Using JavaScript
// This script takes the input from the first text field and outputs it to the second.
// conversion by pep 21Jun08

var tmpStr, tmpChar, preString, postString, strlen;
tmpStr = my_string.toLowerCase();
stringLen = tmpStr.length;

//alert ( " my string = " + tmpStr);
if (stringLen > 0)
{
  for (i = 0; i < stringLen; i++)
  {
    if (i == 0)
	{
      tmpChar = tmpStr.substring(0,1).toUpperCase();
      postString = tmpStr.substring(1,stringLen);
      tmpStr = tmpChar + postString;
    }
    else
	{
      tmpChar = tmpStr.substring(i,i+1);
      if (tmpChar == " " && i < (stringLen-1))
	  {
      tmpChar = tmpStr.substring(i+1,i+2).toUpperCase();
      preString = tmpStr.substring(0,i+1);
      postString = tmpStr.substring(i+2,stringLen);
      tmpStr = preString + tmpChar + postString;
      }
    }
  }
}
 //   outputString.value = tmpStr;
// alert ( " 991 my string = " + tmpStr);
return tmpStr;
}
// end of function caps
  // *************************************************************
  // CHECK POSTCODE NUMERIC
  // *************************************************************
  		function doNumberTest(postcode) 
  
  		{ //alert (" inside validpcode" + postcode);
  
  			if (isNaN(postcode) || postcode < 1000 || postcode > 9000) 
  			return false;
  			else
  			{return true;} 
  		}
  
// *************************************************************
// COUNT NUMBER OF CHARACTERS. Note a two (2) is hard coded as min length
// *************************************************************

		function countchar(passedVal) {

		var jj = 0
		for (i=0; i< passedVal.length; i++) {
		if (passedVal.charAt(i) == "\s*") jj++;
	}

// alert(+ passedVal.length + " value of passed length is")
		if (passedVal.length >=2 )
		return true
		else
{
		return false
}
		}
// *************************************************************
// SUBMIT FORM
// *************************************************************

		function submitMagpie_email(MagForm)

		{
		re = /^\(?(\d{4})\)?[\.\-\/ ]?(\d{4})[\.\-\/ ]?(\d{4})[\.\-\/ ]?(\d{4})$/;

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
//document.write(month + "/" + day + "/" + year)

//alert ( " sequence = " + MagForm.sequence.value + " " + MagForm.hcheck.value );
// Check valid checknumbers
		if (MagForm.sequence.value != MagForm.hcheck1.value)
		{alert("Sorry, numbers do not match. The numbers are \n "+ MagForm.sequence.value +"\n vs \n " + MagForm.hcheck1.value);
		MagForm.hcheck1.focus();
		MagForm.hcheck1.select();
		return false;}
		
// Check a valid email
			if (!emailCheck(MagForm.email.value))
			{
//	alert("Please enter a valid email address. Please re enter ")
			MagForm.email.focus();
			MagForm.email.select();
			return false;
		}

// Check persons first name
			if(!countchar(MagForm.first_n.value))
			{
			alert("You must enter your name. Please re enter ")
			MagForm.first_n.focus();
			MagForm.first_n.select();
			return false;
			}
//toUpper() ;
			
// check for valid postcode
//		alert (" postcode is " + MagForm.pcode.value );
			
			if (!doNumberTest(MagForm.pcode.value))
			{
			alert("You must enter a valid Postcode. Please re enter ")
			MagForm.pcode.focus();
			MagForm.pcode.select();
			return false;
			}

	var abc = "<input type='hidden' id='chg1' name='_mailto' value='" + MagForm.email.value + "'>";
	document.getElementById("chg1").innerHTML = abc;
//alert ( " html is " + abc);

	var def = "<input type='hidden' id='chg2' name='_name' value='" + MagForm.first_n.value + "'>";
// alert (" first_n = " + def);
	document.getElementById("chg2").innerHTML = def; 

 var mysubject = "<input type='hidden' id='chg3' name='_mailsubject' value='Pamms e-zine registration on "+day+'/'+month+'/'+year+ "'>";
//alert (" html = " +	mysubject);
document.getElementById("chg3").innerHTML = mysubject;


// if we made it to here, everythings valid, disable button, then return true
		document.MagForm.gogo.disabled;
		return true ;
		} // End hiding script
