//****************************** EdInfo Javascript ********************************
//***																			***
//***	Important: !!!! Required Changes for moving from UAT to PROD !!!!		***
//***																			***
//***	There are different "Google Analytics" tracking codes UAT and PROD		***
//***	See the SubmitGATracker() function in this file							***
//***																			***
//*********************************************************************************
 
 function selectMajor() {
	//document.frmProgramSearch.aspAction.value = "ProgramSearchPage";
	//document.frmProgramSearch.action = "RequestAction.asp";
	//document.frmProgramSearch.submit();
		var loc = "RequestAction.asp?aspAction=ProgramSearchPage&SelectedMajor=";
		loc = loc + document.frmProgramSearch.SelectedMajor[document.frmProgramSearch.SelectedMajor.selectedIndex].value + "&Page=EduProg";
		loc = loc + "&Distance=" + document.frmProgramSearch.Distance.value;
		document.location.href = loc	
}
		
function KeywordSearch() {
	if (document.frmProgramSearch.Keyword.value.length < 3) {
		alert("You must enter at least 3 characters in the Keyword field.");
	}
	else if (document.frmProgramSearch.Keyword.value.indexOf('%') > -1) {
		alert("You can not use the character '%' in the Keyword field.");
	}
	else if (document.frmProgramSearch.Keyword.value.indexOf('_') > -1) {
		alert("You can not use the character '_' in the Keyword field.");
	}
	else if (document.frmProgramSearch.Keyword.value.indexOf('/') > -1) {
		alert("You can not use the character '/' in the Keyword field.");
	}
	else	{
		var loc = "RequestAction.asp?aspAction=KeywordSearch&Keyword=";
		loc = loc + escape(document.frmProgramSearch.Keyword.value) + "&Page=EduProg&Results=TRUE";
		loc = loc + "&Distance=" + document.frmProgramSearch.Distance.value;
		document.location.href = loc
	}
}

function NOCSearch() {
	if (document.frmProgramSearch.NOC.value.length < 3 ||
		document.frmProgramSearch.NOC.value.Length > 6) {
		alert("You must enter 3-5 digits in the NOC field.");
	}
	else {
		var loc = "RequestAction.asp?aspAction=NOCSearch&NOC=";
		loc = loc + document.frmProgramSearch.NOC.value + "&Page=EduProg&Results=TRUE";
		loc = loc + "&Distance=" + document.frmProgramSearch.Distance.value;
		document.location.href = loc		
	}
}

function MinorSearch() {
	if (document.frmProgramSearch.SelectedMinor.selectedIndex < 0) {
		alert("Please select a Sub-category.");
	}
	else {
		var loc = "RequestAction.asp?aspAction=MinorSearch";
		for (var i = 0; i < document.frmProgramSearch.SelectedMinor.options.length; i++){
			if (document.frmProgramSearch.SelectedMinor.options[i].selected == true) 
				loc = loc + "&SelectedMinor=" + document.frmProgramSearch.SelectedMinor.options[i].value;
		}		
		loc = loc + "&Page=EduProg&Results=TRUE&Distance=" + document.frmProgramSearch.Distance.value;
		document.location.href = loc;	
	}
}

function FreshForm() {
	document.location = "RequestAction.asp?aspAction=ProgramSearchPage&Page=EduProg&Distance=" + document.frmProgramSearch.Distance.value;
}

function clearSchoolCriteria() {
	var items = document.frmSchoolCriteria.elements;
	for (var i = 0; i < items.length; i++){
		if (items[i].type == 'checkbox') {
			items[i].checked = false;
		}
	}
}

function ProgDetails(parm){
	var items = document.frmSearchResults.elements;
	var count = 0;
	
	for (var i = 0; i < items.length; i++){
		if (items[i].type == "checkbox")
			items[i].checked = false;
		if (items[i].type == "checkbox" && items[i].value == parm){
			items[i].checked = true;
			SubmitGATracker(items[i].value);		
			count++;
		}
	}
	
	if (count > 0)
		document.frmSearchResults.submit();		
}

function SubmitGATracker(pid){
	// Google Analytics Tracking Code for PROD: UA-8810012-1
	// Google Analytics Tracking Code for UAT:  UA-8810012-2
	try {
		//Check if Google Analytics is enabled for page
		if (gaJsHost=="https://ssl." || gaJsHost=="http://www."){
			var gtCode = "UA-8810012-1";
			var tUrl = "/edinfo/Content/RequestAction.asp?aspAction=ProgramDetails&chkProg="+pid;
			//var pr=prompt("URL",tUrl);  //Comment out this line before deployment
			var pageTracker = _gat._getTracker(gtCode);
			pageTracker._trackPageview(tUrl);
		}
	} catch(err) {}
}

function ProgramDetails(all) {
	var items = document.frmSearchResults.elements;
	var count = 0;
	for (var i = 0; i < items.length; i++){
		if (all){
			if (items[i].type == "checkbox"){
				 items[i].checked = true;
				 SubmitGATracker(items[i].value);
				 count++;
			}
		}
		else{
			if (items[i].type == "checkbox" && items[i].checked == true){
				SubmitGATracker(items[i].value);
				count++;
			}
		}
	}
	if (count > 0) {
		document.frmSearchResults.submit();
	}
	else
		alert ('Please select at least one program.');
}

function openHelpWindow(url)
{
//	Open the specifed in URL in a new window.  The new window appears
//	centered in the screen, with properties specified as follows:
//
//			popUpStyle
//					If true, the window appears with no menu bar (suitable for
//					a pop-up dialog page).  If false, a standard browser window
//					is opened.
//			width
//					Width of the new window.
//			height
//					Height of the new window.
// 
	openWindow(url,true, 500, 400);
}

function openStatement(url) {
	openWindow(url, true, 500, 400);
}

function openWindow(url, popUpStyle, width, height) {

	var options;
	var left = (window.screen.availWidth - width)/2;
	var top = (window.screen.availHeight - height)/2;

	if (left < 0)
		left = 0;
		
	if (top < 0)
		top = 0;
	
	if (popUpStyle) {
		options = "resizable=yes,scrollbars=yes";
	}
	else {
		options = "resizable=yes,scrollbars=yes,menubar=yes,status=yes,toolbar=yes,location=yes";
		//Adjust for JS weirdness in window size
		height = height - 100;
	}
		
	options = options	+ ",width=" + width + ",height=" + height + ",left=" + left + ",top=" + top;
    return window.open(url,"",options);
}

function showTextPopup(text) {
	
	var newWin = openWindow("", true, 600, 300);
	newWin.document.write(text);
	newWin.document.close();
}

function showStandardAdmission(school, text) {
	var page = "";
	
	page = page + "<html>";
	page = page + "  <head>";
	page = page + "    <title>Standard Admission</title>";
	page = page + "  </head>";
	page = page + "  <link rel='stylesheet' href='Basic.css' type='text/css'/>";
	page = page + "  <body>";
	page = page + "   <form name='frmStdAdm'>";
	page = page + "    <table width='95%' border='0' cellspacing='0' cellpadding='0'>";
	page = page + "      <tr>";
	page = page + "        <td align='left'>";
	page = page + "	         <b>" + school + "</b>";
	page = page + "        </td>";
	page = page + "        <td align='right' valign='top' rowspan='2' nowrap='nowrap'>";
	page = page + "          <input type='button' name='cmdPrint' value='Print' onclick='javascript:window.print();'/>";
	page = page + "          <input type='button' name='cmdClose' value='Close' onclick='javascript:window.close();'/>";
	page = page + "        </td>";
	page = page + "      </tr>";
	page = page + "      <tr>";
	page = page + "        <td align='left'>";
	page = page + "	         <h3>Standard Admission</h3>";
	page = page + "        </td>";
	page = page + "      </tr>";
	page = page + "      <tr>";
	page = page + "        <td colspan='2' width='100%' align='left'>";
	page = page + "          <p>" + text + "</p>";
	page = page + "        </td>";
	page = page + "      </tr>";
	page = page + "    </table>";
	page = page + "   </form>";
	page = page + "  </body>";
	page = page + "</html>";
	showTextPopup(page);
}


function showRegionMap() {
	var page = "";
	
	page = page + "<html>";
	page = page + "  <head>";
	page = page + "    <title>Regions of Alberta</title>";
	page = page + "  </head>";
	page = page + "  <link rel='stylesheet' href='Basic.css' type='text/css'/>";
	page = page + "  <body>";
	page = page + "   <form name='frmMap'>";
	page = page + "    <table width='95%' border='0' cellspacing='0' cellpadding='0'>";
	page = page + "      <tr>";
	page = page + "        <td align='left'>";
	page = page + "	         <h3>Regions of Alberta</h3>";
	page = page + "        </td>";
	page = page + "        <td align='right' valign='top' nowrap='nowrap'>";
	page = page + "          <input type='button' name='cmdPrint' value='Print' onclick='javascript:window.print();'/>";
	page = page + "          <input type='button' name='cmdClose' value='Close' onclick='javascript:window.close();'/>";
	page = page + "        </td>";
	page = page + "      </tr>";
	page = page + "      <tr>";
	page = page + "        <td colspan='2' width='100%' align='center'>";
	page = page + "          <img src='../images/altamap.gif' alt='Map of Alberta'>";
	page = page + "        </td>";
	page = page + "      </tr>";
	page = page + "    </table>";
	page = page + "   </form>";
	page = page + "  </body>";
	page = page + "</html>";

	var newWin = openWindow("", true, 350, 480);
	newWin.document.write(page);
	newWin.document.close();
}

//=========================================================================
//
//IE 4.0 Print Compatibility Functions
//====================================

//	This following javascript functions provide javascript
//	print compatibility for IE 4.0

// The flow of the printing process is: 
//		PrintThis() -> vbPrintPage()

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printThis() {
if (pr) { 					// NS4, IE5
	window.print();
  } else if (da && !mac) { 	// IE4 (Windows)
    vbPrintPage();
  } else { 					// other browsers
    alert("Sorry, your browser doesn't support this feature.");
  }
}

//If the browser detected is IE 4.0, then insert a Web Browser
//ActiveX object to provide print functionality

function insertWBforIE4() {
	if (da && !pr && !mac) {
	  document.writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
	  document.writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
	  document.writeln('Sub window_onunload');
	  document.writeln('  On Error Resume Next');
	  document.writeln('  Set WB = nothing');
	  document.writeln('End Sub');
	  document.writeln('Sub vbPrintPage');
	  document.writeln('  OLECMDID_PRINT = 6');
	  document.writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
	  document.writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
	  document.writeln('  On Error Resume Next');
	  document.writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER');
	  document.writeln('End Sub');
	  document.writeln('<' + '/SCRIPT>');
	}
}
