<!--

// Course selector

// JavaScript Document

var intSelectorStatic = 0;

function getInfoPage(intID)  {
	
	var intDebug = 0;
	var strDataType = 'json';
	var strData = '';
	var strQuery = '';
	
	strData = 'op=getinfo&page=' + intID;
	
	
	var strURL = "/common/ajax-course-selector.asp";
	
	
	
	//$("#debug").html(strDebug);
	
	$.ajax({  
		type: 		'GET',   
		url: 		strURL,  
		data: 		strData,
		cache: 		false,  
		dataType: 	'json',
		
		beforeSend: function() { 
		
			$("#columnCenter").hide();
			$("#columnRight").hide();
			
			//alert(strURL);
		}, //show loading just when link is clicked
		
		success: function(objReturn, textStatus) {  
			
			switch (strDataType) {
				case 'json': // JSON
					
					if (objReturn.result == 'success') {
						
						switch (objReturn.op) {
							
							case 'replace': // replace table
							
								var strCourse = '' + objReturn.courseinfo;
								if (strCourse.length > 0) {
									$("#columnCenter").html(objReturn.courseinfo);
									$("#columnCenter").slideDown('slow');
									
									$("#columnRight").html('<img src="/images/courses/side-panel.gif">');
									$("#columnRight").slideDown('slow');
								}
											
							break;
							
							default:
								alert('default');
							break;
						}
					}
				break;
			}
			
			$("#waiting").hide("slow"); //hide
			//$("#questionHolder").show("slow"); //animation
			
			
			
		},
		
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert(textStatus + " " + errorThrown);
		}
		
	}); 
}

function getSelectorType(intStatic) {
	intSelectorStatic = intStatic;
	var strChoice = $('#choiceCourse').val();
	if (strChoice.length > 0) {
		doJqueryAjaxSelector('courseChoiceSecond', '', 'op=location&type=' + strChoice, 'GET', '');
	} 
	
}

//************************************************************

function getSelectorPage() {
	var strLink = '' + $('#choiceLocation').val();
	if (strLink.length > 0) {
		window.location = "/" + strLink;
	} 
}

//************************************************************


function doJqueryAjaxSelector(strShow, strHide, strQueryData, strMethod, intReplace)  {
	
	var intDebug = 0;
	var strDataType = 'json';
	var strData = '';
	var strQuery = '';
	
	strData = strQueryData;
	
	
	var strURL = "/common/ajax-course-selector.asp";
	
	var strDebug =  "<strong>doJqueryAjaxM</strong>" + 
					" <br />strShow = " + strShow + 
					" <br />strHide = " + strHide + 
					"<br /> strQueryData = " + strQueryData + 
					"<br /> strMethod = " + strMethod + 
					"<br />";
	
	
	//$("#debug").html(strDebug);
	
	$.ajax({  
		type: 		strMethod,   
		url: 		strURL,  
		data: 		strData,
		cache: 		false,  
		dataType: 	'json',
		
		beforeSend: function() { 
		
			if (strHide.length > 0) {
				$("#" + strHide).hide(); //hide
			} 
			$("#waiting").show("slow"); //hide
			$("#" + strShow).hide(); //hide
			$("#" + strShow).html("");
			if (intSelectorStatic == 0) {
				$("#columnCenter").hide();
				$("#columnRight").hide();
			}
			$("#courseChoiceSecond").hide();
			$("#courseChoiceApply").hide();
			$("#courseChoiceThird").hide();
			
			if (intDebug > 0) {
				$("#ajaxurl").html("<p>" + strURL + " (" + strQueryData + ")</p>");
			}
			//alert(strURL);
		}, //show loading just when link is clicked
		
		success: function(objReturn, textStatus) {  
			
			switch (strDataType) {
				case 'json': // JSON
					
					if (objReturn.result == 'success') {
						strDebug += "objReturn.result = success" + " - " + objReturn.op + "<br />";
						
						switch (objReturn.op) {
							
							case 'replace': // replace table
							
								var strLocations = '' + objReturn.locations;
								if (strLocations.length > 0) {
									$("#courseChoiceSecond").html(objReturn.locations);
									$("#courseChoiceSecond").fadeIn('slow');
								}
								
								var strDates = '' + objReturn.dates;
								if (strDates.length > 0) {
									$("#courseChoiceThird").html(objReturn.dates);
									$("#courseChoiceThird").fadeIn('slow');
								}
								
								var strInfo = '' + objReturn.info;
								if (strInfo.length > 0) {
									$("#courseChoiceInfo").html(objReturn.info);
									$("#courseChoiceInfo").fadeIn('slow');
								}
									
								var strApply = '' + objReturn.apply;
								if (strApply.length > 0) {
									$("#courseChoiceApply").html(objReturn.apply);
									$("#courseChoiceApply").fadeIn('slow');
								}
								
								if (intSelectorStatic == 0) {
									var strCourse = '' + objReturn.courseinfo;
									if (strCourse.length > 0) {
										$("#columnCenter").html(objReturn.courseinfo);
										$("#columnCenter").slideDown('slow');
									}
								}
								strDebug += "<strong>Action:</strong> <br />HTML = " + strShow + "<br />";
											
							break;
							
							default:
								alert('default');
							break;
						}
					}
				break;
			}
			
			$("#waiting").hide("slow"); //hide
			//$("#questionHolder").show("slow"); //animation
			
			
			if (intDebug > 0) {
				$("#ajax").html(html2entity(objReturn.html)); //animation
				$("#debug").html(strDebug);
				$("#debugSuccess").html(objReturn.debug);
			}
		},
		
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert(textStatus + " " + errorThrown);
		}
		
	}); 
}

// END course selector

function prefillClear(field) {

	if (field.defaultValue==field.value) {
		field.value = '';
		field.style.color='#000';
	}
	else if (field.value == '') {
		field.value = field.defaultValue;
		field.style.color='#bbb';
	}

}

function toggleDivImage(strShow, strImageID, strImageOn, strImageOff) { 
	 
	if ($("#" + strShow).css("display") == "none") {
		$("#" + strShow).show();
		$("#" + strImageID).attr("src", strImageOff);
	} else {
		$("#" + strShow).hide();
		$("#" + strImageID).attr("src", strImageOn);
	} 
	
}

//******************************************************

function showOnClick(strCheckbox, strTarget) {
	if ($('#' + strCheckbox).is(':checked')) {
		$("#" + strTarget).show("slow");
	}
	else {
		$("#" + strTarget).hide("slow");
	}
}

//******************************************************

function toggleDiv(strShow, strImageID) { 
	 
	if ($("#" + strShow).css("display") == "none") {
		$("#" + strShow).show();
	} else {
		$("#" + strShow).hide();
	} 
}

//******************************************************

function replaceImage(imgID, imgNew) {

	document.getElementById(imgID).src=imgNew;
	
}

//******************************************************

function doCallBack(strThis, arrCourses) {
	checkField(strThis, 'Telephone', 'showTelephoneMessage'); 
	triggerCheckboxDiv(strThis, 'showTelephoneCallTimes'); 
	
	checkCallSettings('showInterestMessage', arrCourses);	
	
}

//******************************************************

function checkSMS(strTarget) {
	var intSuccess = 0;
	var eleSMS = $('#SMS');
	
	if (eleSMS.is(':checked')) {
		$("#" + strTarget).show("slow");
	} else {
		$("#" + strTarget).hide("slow");
	}
	
	//alert("checkCallSettings " + intSuccess);
	
}

//******************************************************

function checkBrochure(arrCourses, strTarget) {
	var intSuccess = 0;
	var eleBrochure = document.getElementById('Brochure');
	var eleTarget = document.getElementById(strTarget);
	
	if (eleBrochure.checked) {
	
		intSuccess = checkTrue(arrCourses);
		
		eleTarget.style.display = intSuccess == 0 ? "block":"none";
	} else {
		eleTarget.style.display = "none";
	}
	
	//alert("checkCallSettings " + intSuccess);
	
}

//******************************************************

function checkCallSettings(strTarget, arrCourses) {
	var intSuccess = 0;
	var eleCallBack = document.getElementById('CallBack');
	var eleTarget = document.getElementById(strTarget);
	
	if (eleCallBack.checked) {
	
		intSuccess = checkTrue(arrCourses);
		
		var eleSource = document.getElementById('Enquiry');
		if (eleSource.value.length > 0) { intSuccess = 1; }
		
		
		
		eleTarget.style.display = intSuccess == 0 ? "block":"none";
	} else {
		eleTarget.style.display = "none";
	}
	
	//alert("checkCallSettings " + intSuccess);
	
}

//******************************************************

function checkTrue(arrTarget) {
	var intReturn = 0;
	for ( var i in arrTarget )
	{
		//alert("checkTrue " + arrTarget[i]);
		var eleTarget = document.getElementById(arrTarget[i]);
		 
		if (eleTarget.checked) {
			intReturn = 1;
		}
	}
	return intReturn;
}
	
//******************************************************

function hideWhenText(strSource, strTarget) {
	// alert("hideWhenText " + strSource.value.length);
	var eleTarget = document.getElementById(strTarget);
 	eleTarget.style.display = strSource.value.length == 0 ? "block":"none";
}

//******************************************************

function triggerCheckboxDiv(strSource, strTarget) {
	var eleTarget = document.getElementById(strTarget);
 	eleTarget.style.display = strSource.checked? "block":"none";
} 

//******************************************************

function checkField(strSource, strCheck, strTarget) {
	var eleTarget = document.getElementById(strTarget);
	var eleCheck = document.getElementById(strCheck);
	
	if (strSource.checked) {
		eleTarget.style.display = (eleCheck.value.length == 0)? "block":"none";
	} else {
		eleTarget.style.display = "none";
	}
}

//******************************************************

function checkSpryFormHTTP(form) {
	var theForm = typeof form != 'object' ? document.getElementById(form): form;
	var ret = Spry.Widget.Form.validate(theForm);
	if (!ret) {
		
		var objMessageID = document.getElementById("formIncomplete");
		objMessageID.innerHTML = '<p>Please check back through the form to see the fields that need to be completed</p>';
		alert("The form is not complete yet. Please check the form for the information we need.");
		return false;
	} else {
   		return true;
	}
}

//******************************************************

function processPaymentChoiceCommon(obj) {
	
	var objPay = document.getElementById('PayBalance1');
	
	$("#paymentSection").slideDown("slow");
	
	if (objPay) {
		if (document.getElementById("PayBalance1").checked == true) { // balance
			document.getElementById("PayBalanceRow").style.background = "#e8ffe8";
			document.getElementById("PayDepositRow").style.background = "#ffffff";
			if (document.getElementById('AmountToPay')) {
				document.getElementById('AmountToPay').innerHTML  = strAmountPayableBalance;
			}
		} 
		
		if (document.getElementById("PayBalance2").checked == true) { // deposit
			document.getElementById("PayDepositRow").style.background = "#e8ffe8";
			document.getElementById("PayBalanceRow").style.background = "#ffffff";
			if (document.getElementById('AmountToPay')) {
				document.getElementById('AmountToPay').innerHTML  = strAmountPayableDeposit;
			}
		}
	}
}

//******************************************************

function showCVV() {
	var eleTarget = document.getElementById('cvv');
	
	if (eleTarget.style.display == "block") {
		eleTarget.style.display = "none";
	} else {
		eleTarget.style.display = "block";
	}
}


//******************************************************

function showLanguageOption(intField, objSource) {
	var eleTarget = document.getElementById('examLanguage' + intField);
	
	
	if (objSource.value >= 30 &&  objSource.value <= 36) {
		eleTarget.innerHTML = "<div class=\"formItem\"><label>Which language?</label>" +
						"<div class=\"inputColumn\"><input type=\"text\" name=\"otherLanguage" + intField + "\" id=\"otherLanguage" + intField + "\" " + 
						"class=\"fieldWidth\" /></div></div>";
	} else {
		eleTarget.innerHTML = "";
	}
}

//*************************************************************************

function getArticle(objSelect) {
	
	var idField = document.getElementById(objSelect);
	var intArticleSectionID = idField.options[idField.selectedIndex].value;  
	//alert(intArticleSectionID + " " + strTargetID);
	
	window.location = "/ib-resources/default.asp?categoryid=25&pageid=290&article=" + intArticleSectionID;

}

//******************************************************

function getNewsletter(objSelect) {
	
	var idField = document.getElementById(objSelect);
	var intArticleSectionID = idField.options[idField.selectedIndex].value;  
	//alert(intArticleSectionID + " " + strTargetID);
	
	window.location = "/ib-resources/default.asp?categoryid=25&pageid=288&newsletter=" + intArticleSectionID;

}
 
//******************************************************

function getTool(objSelect) {
	
	var idField = document.getElementById(objSelect);
	var intArticleSectionID = idField.options[idField.selectedIndex].value;  
	//alert(intArticleSectionID + " " + strTargetID);
	
	window.location = "/ib-resources/default.asp?categoryid=25&pageid=291&tool=" + intArticleSectionID;

}
 
// sets the wait image to visible after transaction

//******************************************************

function setWaitImage() {
	
	var objWait = document.getElementById("waitImage");
	
	objWait.style.display = "block";
	
	return true;
}

//******************************************************

function select_text(objField)
{
	objField.focus();
	objField.select();
}

// AJAX calls

//****************************************************** 

function bindForm(strFormName) {

	
	// bind 'myForm' and provide a simple callback function 

	$('#' + strFormName).ajaxForm({

		 target: '#photoStudent',
		 
		 beforeSubmit: function(a,f,o) {
			  $("#waitingImage").show("slow"); //animation
		  },
 
		  success: function() {
			  $("#waitingImage").hide("slow"); //animation
			  $('#uploadOutput').fadeIn('slow');
		  }

		

	});
	
}

function getQuestionForm(intStudentID, intID, strFile) {
 
	//$("#questiondisplay" + intID).slideUp("slow"); 
	
	$(".waitingAnimation").slideDown("slow");
	
	$.ajax( {
		type: "GET",
		url: "ajax-students.asp",  
		cache: false,
		data: "op=showQuestionnaire&studentid=" + intStudentID + "&question=" + intID + "&file=" + strFile,
		dataType: "html",
		beforeSend: function() {  
			$("#questionDisplay").slideUp("slow"); //animation 
			
			//alert("Status: op=showQuestionnaire&studentid=" + intStudentID + "&question=" + intID + "&file=" + strFile);
		}, //show loading just when link is clicked
		complete: function(XMLHttpRequest, textStatus) { 
			$("#questionDisplay").hide();
			$(".waitingAnimation").slideUp("fast");
			//alert("Status: " + textStatus);
		}, //stop showing loading when the process is complete
		success: function(data, textStatus) { //so, if data is retrieved, store it in html
			//alert(data);
			
			$("#questionDisplay").html(data); //show the html inside .questiondisplay div
			$("#questionDisplay").show("slow"); //animation
			
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			alert('Error loading document ' + textStatus);
		}
	}); //close $.ajax
	
} // end function

//*************************

function copyAddressGeneral() {
	
	if ($('#Address1').val().length > 0) {
		$('#ParentAddress1').val($('#Address1').val());
	}
	if ($('#Address2').val().length > 0) {
		$('#ParentAddress2').val($('#Address2').val());
	}
	if ($('#City').val().length > 0) {
		$('#ParentCity').val($('#City').val());
	}
	if ($('#PostCode').val().length > 0) {
		$('#ParentPostcode').val($('#PostCode').val());
	}
	if ($('#CountryID').val() > 0) {
		$('#ParentCountryID').val($('#CountryID').val());
	}	
	
}

// -->