function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function ValidateValues(iWhichPanel)
{
//'-------------------------------------------------------------------
//'Description: Validation registration or credit card values
//'-------------------------------------------------------------------
//'Date: 06/11/2!!5
//'Developer: David Quinn
//'Comments:   
//'*******************************************************************
	if (iWhichPanel == '1'){
		var oValueToValidate=document.getElementById("oTxtRegFirstName");				//First name
		var bValueOK = CheckValue(oValueToValidate, const_CheckAlpha, 1, 'First Name')
		if (bValueOK==false){
			return bValueOK
		}
										
		var oValueToValidate=document.getElementById("oTxtLastName");					//Surname
		var bValueOK = CheckValue(oValueToValidate, const_CheckAlpha, 1, 'Last Name')
		if (bValueOK==false){
			return bValueOK
		}
		
		/*var oValueToValidate=document.getElementById("oTxtLandNumber");					//Landline
		var bValueOK = CheckValue(oValueToValidate, const_MostlyNumeric, 0, 'Land Phone')
		if (bValueOK==false){
			return bValueOK
		}*/
		
		var oValueToValidate=document.getElementById("oTxtMobile");						//Txtmobile
		var bValueOK = CheckValue(oValueToValidate, const_MostlyNumeric, 1, 'Mobile')
		if (bValueOK==false){
			return bValueOK
		}
		
		
		var oEMail1=document.getElementById("oTxtEmail");								//Email
		var oEMail2=document.getElementById("oTxtConfirmEmail");						//Secondary Email
		
		/*if(oEMail1 == oEMail2){
			
		}else{
			alert('Email and confirm Email values must match')
			bValueOK = false
			return bValueOK
		}*/		
		
		var bValueOK = checkEmail(oEMail1)
		if (bValueOK==false){
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oDropGender");					//Gender
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose gender')
			return bValueOK
		}
		
						
		var oValueToValidate=document.getElementById("oTxtCollgeName");				//First name
		var bValueOK = CheckValue(oValueToValidate, const_CheckAlpha, 1, 'College Name')
		if (bValueOK==false){
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oTxtState");				//First name
		var bValueOK = CheckValue(oValueToValidate, const_CheckAlpha, 1, 'State')
		if (bValueOK==false){
			return bValueOK
		}
						
		var oValueToValidate=document.getElementById("oTxtPerAddress1");				//First name
		var bValueOK = CheckValue(oValueToValidate, const_BothAlphaAndNumeric, 1, 'Address 1')
		if (bValueOK==false){
			return bValueOK
		}
		
		//var oValueToValidate=document.getElementById("oTxtPerAddress2");				//First name
		//var bValueOK = CheckValue(oValueToValidate, const_BothAlphaAndNumeric, 1, 'Address 2')
		//if (bValueOK==false){
		//	return bValueOK
		//}
		
		var oValueToValidate=document.getElementById("oTxtPerTown");				//First name
		var bValueOK = CheckValue(oValueToValidate, const_CheckAlpha, 1, 'Town/City')
		if (bValueOK==false){
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oTxtPerZIP");				//First name
		var bValueOK = CheckValue(oValueToValidate, const_BothAlphaAndNumeric, 1, 'Zip Code')
		if (bValueOK==false){
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oTxtCityOfBirth");				//First name
		var bValueOK = CheckValue(oValueToValidate, const_CheckAlpha, 1, 'City of Birth')
		if (bValueOK==false){
			return bValueOK
		}
											
		
		var oValueToValidate=document.getElementById("oDropNationalityPassport")
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose a Country of Nationality')
			return bValueOK
		}													
		
		var oValueToValidate=document.getElementById("oDropCountry")
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose a Country')
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oDropDOBMonth");					//Gender
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose Date of Birth')
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oDropDOBDay");					//Gender
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose Date of Birth')
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oDropDOBYear");					//Gender
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose Date of Birth')
			return bValueOK
		}
		
						
		var bHasPassportDetails1=document.getElementById("oRadHoldPassportOpt1");		
		var bHasPassportDetails2=document.getElementById("oRadHoldPassportOpt2");		
		
		if(bHasPassportDetails1.checked==false && bHasPassportDetails2==false){
			alert('Please choose yes or no if you have passport details')
			bValueOK=false
			return bValueOK
		}
		
		if(bHasPassportDetails1.checked==true){
							
			var oValueToValidate=document.getElementById("oDropPassportExpiryMonth");					//Gender
			if(oValueToValidate.selectedIndex==0){
				bValueOK=false
				alert('Please choose Passport Expiry Date')
				return bValueOK
			}
			
			var oValueToValidate=document.getElementById("oDropPassportExpiryDay");					//Gender
			if(oValueToValidate.selectedIndex==0){
				bValueOK=false
				alert('Please choose Passport Expiry Date')
				return bValueOK
			}
			
			var oValueToValidate=document.getElementById("oDropPassportExpiryYear");					//Gender
			if(oValueToValidate.selectedIndex==0){
				bValueOK=false
				alert('Please choose Passport Expiry Date')
				return bValueOK
			}
			
			
			var oValueToValidate=document.getElementById("oDropPassportIssueMonth");					//Gender
			if(oValueToValidate.selectedIndex==0){
				bValueOK=false
				alert('Please choose Passport Expiry Date')
				return bValueOK
			}
			
			var oValueToValidate=document.getElementById("oDropPassportIssueDay");					//Gender
			if(oValueToValidate.selectedIndex==0){
				bValueOK=false
				alert('Please choose Passport issue Date')
				return bValueOK
			}
			
			var oValueToValidate=document.getElementById("oDropPassportIssueYear");					//Gender
			if(oValueToValidate.selectedIndex==0){
				bValueOK=false
				alert('Please choose Passport issue Date')
				return bValueOK
			}
		}	
		
							
	}else if (iWhichPanel=='2'){
																		
		var oValueToValidate=document.getElementById("oDropPermitStartDateMonth");					//Gender
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose permit start Date')
			return bValueOK
		}
		
		//var oValueToValidate=document.getElementById("oTxtStudentId");				//First name
		//var bValueOK = CheckValue(oValueToValidate, const_BothAlphaAndNumeric, 1, 'Student Id')
		//if (bValueOK==false){
		//	return bValueOK
		//}
		
		var oValueToValidate=document.getElementById("oDropPermitStartDateDay");					//Permit date
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose permit start Date')
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oDropPermitStartDateYear");					//Permit date
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose permit start Date')
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oDropDepartEireMonth");					//Gender
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose Depart Date from Ireland')
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oDropDepartEireDay");					//Gender
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose Depart Date from Ireland')
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oDropDepartEireYear");					//Gender
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose Depart Date from Ireland')
			return bValueOK
		}
		
							
		var oValueToValidate=document.getElementById("oTxtUSDepartureCity");						//Departure city
		var bValueOK = CheckValue(oValueToValidate, const_CheckAlpha, 1, 'Departure City')
		if (bValueOK==false){
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oEireArrivalCity");							//Arrival city
		var bValueOK = CheckValue(oValueToValidate, const_CheckAlpha, 1, 'Arrival City')
		if (bValueOK==false){
			return bValueOK
		}
							
		
		
		var oValueToValidate=document.getElementById("oDropNextOfKinRelationship");					//Gender
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose next of kin relationship')
			return bValueOK
		}
						
		var oValueToValidate=document.getElementById("oTxtNOKFirstName");								//Arrival city
		var bValueOK = CheckValue(oValueToValidate, const_CheckAlpha, 1, 'Next of kin Name')
		if (bValueOK==false){
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oTxtNOKLastName");								//Arrival city
		var bValueOK = CheckValue(oValueToValidate, const_CheckAlpha, 1, 'Next of kin Name')
		if (bValueOK==false){
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oTxtNOKAddress1");								//Arrival city
		var bValueOK = CheckValue(oValueToValidate, const_BothAlphaAndNumeric, 1, 'Nex of Kin Address')
		if (bValueOK==false){
			return bValueOK
		}
							
		//var oValueToValidate=document.getElementById("oTxtNOKAddress2");								//Arrival city
		//var bValueOK = CheckValue(oValueToValidate, const_BothAlphaAndNumeric, 1, 'Nex of Kin Address')
		//if (bValueOK==false){
		//	return bValueOK
		//}
		
		var oValueToValidate=document.getElementById("oTxtNOKState");								//Arrival city
		var bValueOK = CheckValue(oValueToValidate, const_CheckAlpha, 1, 'Nex of Kin Address')
		if (bValueOK==false){
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oTxtNOKState");								//Arrival city
		var bValueOK = CheckValue(oValueToValidate, const_BothAlphaAndNumeric, 1, 'Nex of Kin Address')
		if (bValueOK==false){
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("DropNOKCountry");					//Departure date
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose Next of kin Country')
			return bValueOK
		}
							
		var oValueToValidate=document.getElementById("oDropConvict");					//Departure date
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose legal question item')
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oDropEveryHadVisa");					//Departure date
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Choose - Have you had a previous visa?')
			return bValueOK
		}
						
		
		var oValueToValidate=document.getElementById("oTxtPlaceHearAbout");								//Arrival city
		var bValueOK = CheckValue(oValueToValidate, const_CheckAlpha, 1, 'Hear about work and travel')
		if (bValueOK==false){
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("CheckConditions");						//Drop total year course
		if(oValueToValidate.checked!=true){
			alert('You must agree to Terms outlined')
			bValueOK=false
			return bValueOK
		}
		
		
		var oValueToValidate=document.getElementById("oDropArriveEireMonth");					//Departure date
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose arrival date in Ireland')
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oDropArriveEireDay");						//Departure date
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose arrival date in Ireland')
			return bValueOK
		}
		
		var oValueToValidate=document.getElementById("oDropArriveEireYear");					//Departure date
		if(oValueToValidate.selectedIndex==0){
			bValueOK=false
			alert('Please choose arrival date in Ireland')
			return bValueOK
		}
		
		
	}	
	return bValueOK
}	


function ValidateCreditCardValues()
{
	//'-------------------------------------------------------------------
	//'Description: Validation of credit card values
	//'-------------------------------------------------------------------
	//'Date: 06/11/2!!5
	//'Developer: David Quinn
	//'Comments:   
	//'*******************************************************************
	
	var oInsSelectBOX=document.getElementById("oDropInsurance");
	if(oInsSelectBOX.selectedIndex==0){
		bValueOK=false
		alert('Please choose an Insurance option')
		return bValueOK
	}
	
	
					
	var oValueToValidate=document.getElementById("oFirstName");					//First name
	var bValueOK = CheckValue(oValueToValidate, const_CheckAlpha, 1, 'Card first Name')
	if (bValueOK==false){
		return bValueOK
	}
	
	var oValueToValidate=document.getElementById("oSurnameName");				//Surname name
	var bValueOK = CheckValue(oValueToValidate, const_CheckAlpha, 1, 'Card last name')
	if (bValueOK==false){
		return bValueOK
	}
	
					
	var oValueToValidate=document.getElementById("oCardNumber");				//Card number
	var bValueOK = CheckValue(oValueToValidate, const_AllNumeric, 1, 'Card number')
	if (bValueOK==false){
		return bValueOK
	}
	
					
	var oValueToValidate=document.getElementById("oCardType");			//Visa and MasterCard Must be a CVN
	var oCVNToValidate=document.getElementById("oCVNNumber");			//Drop total year course
	if(oValueToValidate.value=='VISA' || oValueToValidate.value=='MC'){
		if(oCVNToValidate.value==''){
			alert('Card Types Visa and Mastercard must have a Security number')
			bValueOK=false
			return bValueOK
		}else{
			//var bValueOK = CheckValue(oCVNToValidate, const_AllNumeric, 1)
			//return bValueOK
		}	
	}
	
	var oValueToValidate=document.getElementById("oCardAmount")
	var bValueOK = checkCardAmount(oValueToValidate)
	if (bValueOK==false){
		return bValueOK
	}
	
																
	var oValueToValidate=document.getElementById("oExpiry")
	if(oValueToValidate.selectedIndex==0){
		bValueOK=false
		alert('Please choose an expiry date')
		return bValueOK
	}



	alert('***NOTE: Due to new government adminstrative changes to the work and Travel Ireland Program, there will be a two to three week 	delay before we can resume processing  applications. Please be advised that this may affect your travel plans... Any queries please 	contact wii@usit.ie***')




	return bValueOK
	
}


var const_CheckAlpha = 0;
var const_MostlyNumeric = 1;
var const_AllNumeric = 2;
var const_BothAlphaAndNumeric = 3;
var const_RequiredField=1;

function Display(which)
{
	//'-------------------------------------------------------------------
	//'Description: Show hide next/previous buttons.
	//'-------------------------------------------------------------------
	//'Date: 06/11/2!!5
	//'Developer: David Quinn
	//'Comments:   
	//'*******************************************************************
	var ph=document.getElementById("PnlRegDetails");
	var dp=document.getElementById("PnlDepatureNOK");
	var em=document.getElementById("pnlCreditCardInfo");
	var cf=document.getElementById("PnlSaveResult")
	
	if(which.value=='1 - Next'){
		var bValueOK = ValidateValues('1')						//Validation registration values
		if(bValueOK==true){	
			ph.style.display="none";
			dp.style.display="block";
			em.style.display="none";
			cf.style.display="none";
		}	
	}else if (which.value=='2 - Previous'){
		dp.style.display="none";
		ph.style.display="block";
		em.style.display="none";
		cf.style.display="none";
	}else if (which.value=='2 - Next'){
		var bValueOK = ValidateValues('2')						//Validation registration values
		if(bValueOK==true){	
			ph.style.display="none";
			dp.style.display="none";
			cf.style.display="none";
			em.style.display="block";	
		}	
	}else if (which.value=='3 - Previous'){
		ph.style.display="none";
		em.style.display="none";
		cf.style.display="none";		
		dp.style.display="block";
	}else if (which.value=='Finish'){
		var bValueOK = ValidateCreditCardValues()
		
		var oValueToValidate=document.getElementById("oCardAmount")
							
		if(bValueOK==true){
			
			var answer = confirm ('The amount of $ ' + oValueToValidate.value + ' is about to be charged to your card.... ' + 'Continue? ')
			if (answer){
				ph.style.display="none";
				em.style.display="none";		
				dp.style.display="none";
				
				var pw = document.getElementById("ShowPleaseWait")
				pw.style.display="block";
				
				cf.style.display="block";
				document.Form1.sSavemode.value = 1
				document.Form1.submit()
			}	
		}	
	}	
}

function CalcProgramTotal()
{
	var oInsSelectBOX=document.getElementById("oDropInsurance");
	var dChargeAmount
	var oCheckObj = oInsSelectBOX.options[oInsSelectBOX.selectedIndex].value
	var oChargeAmount = document.getElementById("oCardAmount");
	var oISICOption = document.getElementById("CheckISIC")
	
	
	var iTotalToCalc = 399;
	var intInsuranceCOST = oCheckObj

	if (oInsSelectBOX.selectedIndex==1){
		var bTakeOwnInsurance=confirm('Choosing your own insurance must incur an administration fee of $30.00. If you choose this option then a full copy of your insurance policy must be submitted for evaluation and approval -  The policy must cover you to work in ireland for the duration of your travel')
		if (bTakeOwnInsurance){

		}else{
			oInsSelectBOX.selectedIndex=0
			intInsuranceCOST = oChargeAmount.value
		}
	}

	if (oISICOption.checked== true){
		iTotalToCalc = iTotalToCalc + parseFloat(5)
	}	


	var iCalcTotal = parseFloat(iTotalToCalc) + parseFloat(intInsuranceCOST)
	oChargeAmount.value = iCalcTotal.toFixed(2)

}

function CalcTotalPlusISIC(oCheckObj)
{
	var oChargeAmount=document.getElementById("oCardAmount");
	if (oCheckObj.checked==true){
		dChargeAmount = parseFloat(oChargeAmount.value) + 5
	}else{
		dChargeAmount = parseFloat(oChargeAmount.value) - 5
	}	
	oChargeAmount.value = dChargeAmount.toFixed(2)
}

function checkCardAmount(changed)
{

	var sCharsAllowed = '0123456789.'
	for (var i=0, len=changed.value.length, valid=sCharsAllowed ; i<len ; i++) {
		if (valid.indexOf(changed.value.substring(i,i+1)) == -1) {
			alert(changed.name + ' Entry is invalid - The field accepts only the following characters ' + sCharsAllowed);
			changed.focus()
			return false;
		}	
	}
					
	if(changed.value.length==0){
		alert('Invalid card amount input');
		bValueOK=false
		return bValueOK
	}
	
	if(changed.value==''){
		alert('Invalid card amount input');
		bValueOK=false
		return bValueOK
	}
									
	return true	

}

function ShowFirstPanel()
{
	var oValueToValidate=document.getElementById("oTxtReturnMessage");
	oValueToValidate.value=""
	document.Form1.sSavemode.value = 0
	document.Form1.submit()
}

function CheckValue(changed, iValType, iRequiredField, sProblemField)
{
//'-------------------------------------------------------------------
//'Description: Validation for alpha values
//'-------------------------------------------------------------------
//'Date: 06/11/2!!5
//'Developer: David Quinn
//'Comments:   
//'*******************************************************************
	var valid='';
	var sAllowStr = ''
	
	if (iValType==const_CheckAlpha){
		sAllowStr = 'abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ -'
	}else if(iValType==const_MostlyNumeric){
		sAllowStr = '0123456789()-.'
	}else if(iValType==const_AllNumeric){
		sAllowStr = '0123456789'
	}else if(iValType==const_BothAlphaAndNumeric){
		sAllowStr = 'abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ0123456789/ '
	} 
																				
	if(iRequiredField==const_RequiredField){				
		if(changed.value !=''){
			for (var i=0, len=changed.value.length, valid=sAllowStr ; i<len ; i++) {
				if (valid.indexOf(changed.value.substring(i,i+1)) == -1) {
					alert(sProblemField + ' Entry is invalid - The field accepts only the following characters ' + sAllowStr);
					changed.focus()
					return false;
				}	
			}
		}else{
			alert(sProblemField + ' Must contain Entry');
			changed.focus()
			return false;
		}
	}else{
		for (var i=0, len=changed.value.length, valid=sAllowStr ; i<len ; i++) {
			if (valid.indexOf(changed.value.substring(i,i+1)) == -1) {
				alert(sProblemField + ' Entry is invalid - The field accepts only the following characters ' + sAllowStr);
				changed.focus()
				return false;
			}	
		}
	}
			
	return true;
}

function checkEmail(changed)
{	
	var sCharsAllowed = 'abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ0123456789@.-'
	apos=changed.value.indexOf("@")
	dotpos=changed.value.lastIndexOf(".")
	if(apos<1||dotpos-apos<2){
		alert('Null or invalid email entered - entry must include @ and .')
		changed.focus()
		return false
	}else{
		return true
	}
}