// 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('');
									$("#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);
		}
		
	}); 
}