// JavaScript Document

function pageLoadFunctions() {

	// add in any page initialisers here
	 submitCompetitionToTmail();
}

function submitCompetitionToTmail() {

	// enables internal processing prior to tmail form submission
	// noscript tags included in competition page for when JS disabled
	if (document.winaholidayformautosubmit != null) {
		document.winaholidayformautosubmit.submit()
	}
	
}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(month, day, year, usNotation){

    var retv = false;
    if (day && month && year)
    {
        retv = (day.value.length > 0 && month.value.length > 0 && year.value.length > 0);
        if (retv)
        {
            var strMonth = month.value;
            var strDay = day.value;
            var strYear = year.value;
            if (usNotation)
            {
                strDay = month.value;
                strMonth = day.value;
            }
            
	        var daysInMonth = DaysArray(12)
	        strYr=strYear
	        if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	        if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	        for (var i = 1; i <= 3; i++) {
		        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	        }
	        month=parseInt(strMonth)
	        day=parseInt(strDay)
	        year=parseInt(strYr)
	        if (strMonth.length<1 || month<1 || month>12){
		        retv = false;
	        }
	        if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		        retv = false;
	        }
	        if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		        retv = false;
	        }
        }
    }
    return retv;
}

function setGroupValidatorsStatus(groupID, status)
{
  for(var i = 0; i < Page_Validators.length; i++)
  {
    if(Page_Validators[i].attributes['id'].nodeValue.indexOf(groupID) != -1)
    {
      Page_Validators[i].enabled = status;
      Page_Validators[i].style.display = status ? 'inline' : 'none';
    }
  }	
}

function showFitnessFormApplicants (applicantNumber) {

	// get all applicants
	var appTwo 		= document.getElementById('applicant-two');
	var appThree 	= document.getElementById('applicant-three');
	var appFour 	= document.getElementById('applicant-four');
	var appFive 	= document.getElementById('applicant-five');
	var appSix 		= document.getElementById('applicant-six');
	var appSeven 	= document.getElementById('applicant-seven');
	var appEight 	= document.getElementById('applicant-eight');
	
	setGroupValidatorsStatus('applicantOne', true);
	setGroupValidatorsStatus('applicantTwo', false);
	setGroupValidatorsStatus('applicantThree', false);
	setGroupValidatorsStatus('applicantFour', false);
	setGroupValidatorsStatus('applicantFive', false);
	setGroupValidatorsStatus('applicantSix', false);
	setGroupValidatorsStatus('applicantSeven', false);
	setGroupValidatorsStatus('applicantEight', false);
	
	// hide all applicants
	appTwo.style.display	= "none"; 
	appThree.style.display	= "none"; 
	appFour.style.display	= "none"; 
	appFive.style.display	= "none"; 
	appSix.style.display	= "none"; 
	appSeven.style.display	= "none"; 
	appEight.style.display	= "none"; 
	
	// then turn back on the ones we want
	if (applicantNumber == '2') {
		appTwo.style.display	= "block"; 

    	setGroupValidatorsStatus('applicantTwo', true);
	} else if (applicantNumber == '3') {
		appTwo.style.display	= "block"; 
		appThree.style.display	= "block"; 

	    setGroupValidatorsStatus('applicantTwo', true);
	    setGroupValidatorsStatus('applicantThree', true);
	} else if (applicantNumber == '4') {
		appTwo.style.display	= "block"; 
		appThree.style.display	= "block"; 
		appFour.style.display	= "block"; 

	    setGroupValidatorsStatus('applicantTwo', true);
	    setGroupValidatorsStatus('applicantThree', true);
	    setGroupValidatorsStatus('applicantFour', true);
	} else if (applicantNumber == '5') {
		appTwo.style.display	= "block"; 
		appThree.style.display	= "block"; 
		appFour.style.display	= "block"; 
		appFive.style.display	= "block"; 

	    setGroupValidatorsStatus('applicantTwo', true);
	    setGroupValidatorsStatus('applicantThree', true);
	    setGroupValidatorsStatus('applicantFour', true);
	    setGroupValidatorsStatus('applicantFive', true);
	} else if (applicantNumber == '6') {
		appTwo.style.display	= "block"; 
		appThree.style.display	= "block"; 
		appFour.style.display	= "block"; 
		appFive.style.display	= "block"; 
		appSix.style.display	= "block"; 

	    setGroupValidatorsStatus('applicantTwo', true);
	    setGroupValidatorsStatus('applicantThree', true);
	    setGroupValidatorsStatus('applicantFour', true);
	    setGroupValidatorsStatus('applicantFive', true);
	    setGroupValidatorsStatus('applicantSix', true);
	} else if (applicantNumber == '7') {
		appTwo.style.display	= "block"; 
		appThree.style.display	= "block"; 
		appFour.style.display	= "block"; 
		appFive.style.display	= "block"; 
		appSix.style.display	= "block"; 
		appSeven.style.display	= "block"; 

	    setGroupValidatorsStatus('applicantTwo', true);
	    setGroupValidatorsStatus('applicantThree', true);
	    setGroupValidatorsStatus('applicantFour', true);
	    setGroupValidatorsStatus('applicantFive', true);
	    setGroupValidatorsStatus('applicantSix', true);
	    setGroupValidatorsStatus('applicantSeven', true);
	} else if (applicantNumber == '8') {
		appTwo.style.display	= "block"; 
		appThree.style.display	= "block"; 
		appFour.style.display	= "block"; 
		appFive.style.display	= "block"; 
		appSix.style.display	= "block"; 
		appSeven.style.display	= "block"; 
		appEight.style.display	= "block"; 
		
	    setGroupValidatorsStatus('applicantTwo', true);
	    setGroupValidatorsStatus('applicantThree', true);
	    setGroupValidatorsStatus('applicantFour', true);
	    setGroupValidatorsStatus('applicantFive', true);
	    setGroupValidatorsStatus('applicantSix', true);
	    setGroupValidatorsStatus('applicantSeven', true);
	    setGroupValidatorsStatus('applicantEight', true);
	} 
	
	// maybe only turn off in the if blocks....
}

function submit_form(){ 
    document.subscribe.submit(); 
} 


function submitFormById(formid) {
    document.getElementById(formid).submit();
}

function openPopup(width,height,url)
{
var csUserAgent = String(navigator.userAgent);
if(csUserAgent.indexOf("MSIE") > -1){
 height=height+50;
 width=width+50;
}else{
 height=height+20;
 width=width+20;
}
window.open(url,'','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width='+width+',height='+height+',status');
return false;
}


<!--//--><![CDATA[//><!--



dropMenu = function() {

    var sfEls = document.getElementById("mainnav-list").getElementsByTagName("LI");

    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmousedown=function() {
            hideallNavTabs();
        }
        
        sfEls[i].onmouseover=function() {
            //hideallNavTabs();
            this.className+=" dropmenu";
        }

        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" dropmenu\\b"), "");
        }
    }
}

if (window.attachEvent) window.attachEvent("onload", dropMenu);

function hideallNavTabs(){    if(navigator.userAgent.indexOf("MSIE") != -1)
    {
        //var sfEls3 = getElementsByClassName("dropmenu");
        var sfEls3 = document.getElementById("mainnav-list").getElementsByTagName("LI");
        for (var i=0; i<sfEls3.length; i++) {
            sfEls3[i].className=sfEls3[i].className.replace(new RegExp(" dropmenu\\b"), "");
        }
    }}	/*	Developed by Robert Nyman, http://www.robertnyman.com	Code/licensing: http://code.google.com/p/getelementsbyclassname/*/var getElementsByClassName = function (className, tag, elm){	if (document.getElementsByClassName) {		getElementsByClassName = function (className, tag, elm) {			elm = elm || document;			var elements = elm.getElementsByClassName(className),				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,				returnElements = [],				current;			for(var i=0, il=elements.length; i<il; i+=1){				current = elements[i];				if(!nodeName || nodeName.test(current.nodeName)) {					returnElements.push(current);				}			}			return returnElements;		};	}	else if (document.evaluate) {		getElementsByClassName = function (className, tag, elm) {			tag = tag || "*";			elm = elm || document;			var classes = className.split(" "),				classesToCheck = "",				xhtmlNamespace = "http://www.w3.org/1999/xhtml",				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,				returnElements = [],				elements,				node;			for(var j=0, jl=classes.length; j<jl; j+=1){				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";			}			try	{				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);			}			catch (e) {				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);			}			while ((node = elements.iterateNext())) {				returnElements.push(node);			}			return returnElements;		};	}	else {		getElementsByClassName = function (className, tag, elm) {			tag = tag || "*";			elm = elm || document;			var classes = className.split(" "),				classesToCheck = [],				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),				current,				returnElements = [],				match;			for(var k=0, kl=classes.length; k<kl; k+=1){				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));			}			for(var l=0, ll=elements.length; l<ll; l+=1){				current = elements[l];				match = false;				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){					match = classesToCheck[m].test(current.className);					if (!match) {						break;					}				}				if (match) {					returnElements.push(current);				}			}			return returnElements;		};	}	return getElementsByClassName(className, tag, elm);};	

//--><!]]>



