
var submitcount=0; 
function checkSubmit()
{	if (submitcount == 0)
 	{ submitcount++;
 		return true;
 	}
 	else 
	{	alert("EITHER -This data has already been sent to eNVQ" +
 		"\nOR - You may be sending a lot of data which will take some time" +
 		"\n\nAnyway, don't keep clicking the button!!\n" +
 			"\nThanks!"); 
		return false; 
	}
} 

var mailshotBoxesChecked = 0 ;

function mailshotCheckACheckbox(thisCheckBox)
{	// alert("you checked one") ;
	if (thisCheckBox.checked)
		mailshotBoxesChecked++ ;
	else
		mailshotBoxesChecked-- ;
}

function checkMailSubmit()
{	var whoTo ; 
	// Got the Mailshot gear now..
	// alert("BoxesChecked = [" + mailshotBoxesChecked + "]") ;
	if (mailshotBoxesChecked > 0) return true ;

	whoTo = window.document.MAILMSG.MailTo.value ;
	if (whoTo == 'Nobody')
	{	alert("You haven't chosen anybody to send your mail to !\n\n" +
			"(Did you mean to close the window instead ?)")	 ;
		return false ;
	}
	return (checkSubmit()) ;
}

function demoSubmit()
{		 alert("This button would store your information in the eNVQ database\n"
		 + "but is disabled during this demonstration") ;
		 return false;
}
		 
var DateText = "" ;
var MthDays = new Array(31,31,31,30,31,30,31,31,30,31,30,31);
var MthNames = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec') ;
function GetMonth(text)
{ var myText = text ;
 // remove any leading spaces
 var z = 0;
 for( z=0;z<myText.length;z++ )
 {  if( myText.charAt(z) != ' ' )
  { break;
  }
 }
 var myMonth = myText.substring(z,z+3) ;
 var mth = -1 ;
 if (myMonth == "jan") mth = 1 ;
 else if (myMonth == "feb") mth = 2 ;
 else if (myMonth == "mar") mth = 3 ;
 else if (myMonth == "apr") mth = 4 ;
 else if (myMonth == "may") mth = 5 ;
 else if (myMonth == "jun") mth = 6 ;
 else if (myMonth == "jul") mth = 7 ;
 else if (myMonth == "aug") mth = 8 ;
 else if (myMonth == "sep") mth = 9 ;
 else if (myMonth == "oct") mth = 10 ;
 else if (myMonth == "nov") mth = 11 ;
 else if (myMonth == "dec") mth = 12 ;
 if (myMonth != -1)
 { DateText = myText.substr(z+3) ;
 }
 return (mth) ;
 }

function GetDay(text)
{ 
 var c = "" ;
 var Day = 0 ;
 for (var i = 0 ; i < text.length ; i++)
 { 
  c = text.substring(i,i+1) ;
  if (c >= "0" && c <= "9")
  { Day *= 10 ;
   Day += parseInt(c,10) ;
  }
  else
  { break ;
  }
 }
 DateText = text.substr(i).toLowerCase() ;
 return (Day) ;
}

function isLeap(Year)
{ if (Year % 400 == 0) return (1) ;
 if (Year % 100 == 0) return (0) ;
 if (Year % 4 == 0) return (1) ;
 return (0) ;
}
var reformattedDate = '' ;
function IsValidDate(text)
{ OKToSubmit = 1;
 DateText = text ;
 var num_test=/\d+/;
 if(! num_test.test(text))
 { // anything without a digit in it will NOT be valid 
  return(0);
 }

 var Day = GetDay(text) ;
 if (Day < 0 || Day > 31) 
 { OKToSubmit = 0;
  return (0) ;
 }

 var Month = GetMonth(DateText) ;
 if (Month <= 0 || Month > 12)
 { OKToSubmit = 0;
  return (0) ;
 }
 //
 // need to skip any spaces that are left
 //
 var TmpYear1 = DateText;
 var x=0;
 for(x=0;x<TmpYear1.length;x++)
 { if( TmpYear1.charAt(x) != ' ')
   break;
 }
 var TmpYear2 = TmpYear1.substr(x);
 var Year = parseInt(TmpYear2,10) ;
 if (isNaN(Year) || Year < 0 || Year > 3000)
 { OKToSubmit = 0;
  return (0) ;
 }
 if (Year < 40) Year += 2000 ;
 if (Year < 1900) Year += 1900 ;
 if (isLeap(Year) == 0)
 {
  MthDays[1] = 28 ;
 }
 else
 {
  MthDays[1] = 29 ;
 }
 if (Day > MthDays[Month - 1]) 
 { OKToSubmit = 0;
  return (0) ;
 }
 reformattedDate = Day + ' ' + MthNames[Month-1] + ' ' + Year ; 
 return (1) ;
}


function validateDate(acontrol)
{ 
 if (acontrol.value == "")
 {	return(1);
 }
 if (IsValidDate(acontrol.value) == 0)
 { alert( acontrol.value + " is not a valid format date. " +
 	"\n\nPlease enter your dates like 5jan01, 30mar94" ) ;
  acontrol.value = "" ;
  acontrol.focus() ;
  OKToSubmit = 0;
  return (0) ;
 }
 acontrol.value = reformattedDate ;
 return (1) ;
}

function ValidateScore(acontrol)
{	var s ;
	var v = acontrol.value ;
	s = parseInt(v) ;
	if (v == "") return (1) ;
	if (v <= "0" || v > "9" || s <=0 || s > 9)
	{	alert("Please enter a number between 1 and 9") ;
		acontrol.value = "" ;
		acontrol.focus() ;
		return (0) ;
	}
	return (1) ;
}

function ValidateNumber(acontrol)
{	var s ;
	var v = acontrol.value ;
	s = parseInt(v) ;
	if (v == "") return (1) ;
	if (v <= "0" || v > "99" || s <=0 || s > 99)
	{	alert("Please enter a number between 1 and 99") ;
		acontrol.value = "" ;
		acontrol.focus() ;
		return (0) ;
	}
	return (1) ;
}


// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var atx = 0
var aty = 0

// Main function to retrieve mouse x-y pos.s
function MozGetMousePos(e) // For Moz Firefox
{ if (!e) 
   var e = window.event||window.Event; 
  if('undefined'!=typeof e.pageX) 
  { 
   atx = e.pageX; 
   aty = e.pageY; 
  } 
  else 
  { 
   atx = e.clientX + document.body.scrollLeft; 
   aty = e.clientY + document.body.scrollTop; 
  } 
} 
function getMouseXY(e) {
  if (IE) 
  { // grab the x-y pos.s if browser is IE
    atx = event.clientX + document.body.scrollLeft
    aty = event.clientY + document.body.scrollTop
  } 
  else 
  {  // grab the x-y pos.s if browser is NS
	MozGetMousePos(e) ;
  }  
  // catch possible negative values in NS4
  if (atx < 0){atx = 0}
  if (aty < 0){aty = 0}  
  return true
}


var myWidth = 0, myHeight = 0;

function windowWidth()
{  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
	return (myWidth) ;
}



function dereferenceObject(objName)
{	if (document.getElementById)
		return(document.getElementById(objName)) ;
	return(eval('document.all.' + objName)) ;
}

function ShowUpdateLayer(obj)
{	if (obj.style.display == "none") 
	{	obj.style.display = "";
	}
	else
	{	obj.style.display = "none";
	}
}

function MakeVisible(whatdiv)
{	var itsStyle ;
	var xoffset = 10 ;
	var midPoint = windowWidth() / 2 ;
	var theObj ;
	theObj = dereferenceObject(whatdiv) ;
//alert("MakeVis at " + atx + "," + aty) ;
	if (atx >= midPoint)
	{	xoffset = 0 - theObj.clientWidth ;
	}
	itsStyle = theObj.style ;
	//itsStyle.posTop=aty+20;
	//itsStyle.posLeft=atx+xoffset;
	itsStyle.top=aty+20;
	itsStyle.left=atx+xoffset;
	itsStyle.visibility = "visible" ;
}
function MakeVisibleIfNess(whatdiv)
{	var itsStyle ;
	var xoffset = 10 ;
	var midPoint = windowWidth() / 2 ;
	var theObj ;
	theObj = dereferenceObject(whatdiv) ;
	itsStyle = theObj.style ;
	if (itsStyle.visibility == "visible") return ;
	if (atx >= midPoint)
	{	xoffset = 0 - theObj.clientWidth ;
	}
	itsStyle.top=aty+20;
	itsStyle.left=atx+xoffset;
	itsStyle.visibility = "visible" ;
}

function MakeVisibleAtLeft(whatdiv)
{	var itsStyle ;
	itsStyle = dereferenceObject(whatdiv).style ;
	itsStyle.posTop=aty+20;
	itsStyle.posLeft=20;
	itsStyle.visibility = "visible" ;
}

function MakeInVisible(whatdiv)
{	var itsStyle ;
	itsStyle = dereferenceObject(whatdiv).style ;
	itsStyle.visibility = "hidden" ;
}

function MakeVisibleOrNot(whatdiv)
{	var itsStyle ;
	itsStyle = document.dereferenceObject(whatdiv).style ;
	itsStyle.posTop=aty+20;
	itsStyle.posLeft=atx+10;
	if (itsStyle.visibility == "visible")
		itsStyle.visibility = "hidden" ;
	else
		itsStyle.visibility = "visible" ;
}


function ImUpdateWindow()
{	window.focus() ;
	// document.body.style.overflow='hidden' ;
	// window.scroll(0,document.body.offsetHeight) ;
}

function ImDemoWindow()
{	window.focus() ;
	//initiateticker() ;
}


function loadRollerWindow(theUrl)
{	var myWidth = screen.availWidth - 10 ;
	var myHeight = screen.availHeight - 40 ;
	var optStr = 'left=0,top=0,width=' + myWidth  + ',height=' +  myHeight ;
	optStr += 'directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=yes'
	var aWindow = window.open(theUrl,'envqRoller',optStr) ;
}
 
function myFrameWidth()
{	if (parseInt(navigator.appVersion) <= 3) return(100) ;
	return(IE ? document.body.clientWidth : window.innerWidth) ;
}

function myFrameHeight()
{	if (parseInt(navigator.appVersion) <= 3) return(100) ;
	return(IE ? document.body.clientHeight : window.innerHeight) ;
}

