// Java Document
//Detect IE5.5+
var blIE = false;
var version = 0;

if (navigator.appVersion.indexOf("MSIE")!=-1) {
    var temp = navigator.appVersion.split("MSIE");
    var version = parseFloat(temp[1]);
    blIE = (version >= 5.5) //NON IE browser will return 0
}

function fnDoPrint(blPrint) {
    
    if (!blPrint) {
        // open window
        var strURL = location.href + "?doPrint=print";

        fnOpenPopup(strURL, "PRINT_PAGE", 560, 500);
    }
    else {
        this.print();
    }
}

function fnLaunchPublic() {
	location.href = "/public/home.asp";
}

function fnLaunchStudent() {
	//location.href = "/existing-students/home.asp";
	location.href = "http://moodle.harvest.edu.au";
}

function fnLaunchAlumni() {
	//location.href = "/alumni/home.asp";
	alert("Coming Soon...");
}

function fnSearch() {
	//alert("Search Facility Coming Soon...");
	document.frmSearch.action = "/common/search.asp"; // kept relative
	document.frmSearch.submit();
}

function fnSend() {
	//alert("Contact Us Form Coming Soon...\n\nIn the meantime please use the direct mail link: info@harvest.edu.au");
	//return;

    // Check Name
    var aName = document.frmEnquiry.txtName;

	if ((aName.value == null) || (aName.value == "")) {
		alert("Please provide your name.");
		aName.focus();
		return false;
	}

	// Check Email
	var emailID = document.frmEnquiry.txtEmail

	if ((emailID.value == null) || (emailID.value == "")) {
		alert("Please provide your email address.");
		emailID.focus();
		return false;
	}

	if (echeck(emailID.value) == false) {
		emailID.value="";
		emailID.focus();
		return false;
	}

	// Check Phone
	var aPhone = document.frmEnquiry.txtPhone;

	if ((aPhone.value == null) || (aPhone.value == "")) {
	    alert("Please provide your contact telephone #.");
	    aPhone.focus();
	    return false;
	}

	// Check Enquiry
	var anEnquiry = document.frmEnquiry.txtEnquiry

	if ((anEnquiry.value == null) || (anEnquiry.value == "")) {
		alert("Please make your enquiry using the space provided.");
		anEnquiry.focus();
		return false;
	}

	document.frmEnquiry.action = "/common/sendmail.aspx" // kept relative

	return true;
}

function fnSendSuggestion() {

	// Check Suggestion
	var aSuggestion = document.frmSuggestion.txtSuggestion

	if (aSuggestion.value.length==0){
		alert("Please enter your suggestion in the space provided.");
		aSuggestion.focus();
		return false;
	}
	
	document.frmSuggestion.action = "/common/sendsuggestion.aspx" // kept relative
	return true;
}

function fnProspectusEnquiry() {
    // Check First Name
    var fName = document.frmEnquiry.txtFirstName;

    if (fName.value.length == 0) {
        alert("Please provide your first name.");
        fName.focus();
        return false;
    }

    // Check Surname
    var sName = document.frmEnquiry.txtSurname;
    
	if (sName.value.length == 0) {
	    alert("Please provide your surname.");
	    sName.focus();
		return false;
	}

	// Check Email
	var emailID = document.frmEnquiry.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please provide your email address.");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}

	// Check Telephone
	var pNumber = document.frmEnquiry.txtPhone;
	
	if (pNumber.value.length == 0) {
	    alert("Please provide your mobile phone number.");
	    pNumber.focus();
		return false;
	}
	
	document.frmEnquiry.action = "/common/ProspectusEnquiry.aspx" // kept relative
	return true;
}

/*
function fnRegInterest() {
	// Check Tour
	if (!(document.frmRegInterest.chkTour[0].checked || document.frmRegInterest.chkTour[1].checked || document.frmRegInterest.chkTour[2].checked)) {
		alert("Please indicate which tour(s) you are interest in.");
		return false;
	}

	// Check Name
	if (document.frmRegInterest.txtName.value.length == 0) {
		alert("Please provide your name.");
		return false;
	}
	
	// Check Email
	var emailID = document.frmRegInterest.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please provide your email address.");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	
	// Check Country
	if (document.frmRegInterest.txtCountry.value.length == 0) {
		alert("Please provide your country.");
		return false;
	}
	
	// Check Postal Address
	if (document.frmRegInterest.txtPostalAddress.value.length == 0) {
		alert("Please provide your postal address.");
		return false;
	}
	
	document.frmRegInterest.action = "/common/sendreginterest.aspx" // kept relative
	return true;
}
*/

function fnCheckPopups() {
  var popups = false;
  testWin = window.open("http://www.harvest.edu.au/common/PopupCheck.html", "POPUP_CHECK", "height=100,width=100,top=0,left=0,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,titlebar=no");
  if (testWin != null || typeof(test_wnd)=="undefined") {
    try{
      var testValue = testWin.name;
      popups = true;
      testWin.close();
    } catch(e) {
      popups = false;
    }
  }
  
  return popups;
}

function fnCheckJava() { // returns a string not a boolean (blank if java okay)
    if (PluginDetect.isMinVersion("Java", "1,6,0,0") == 1) {
        // rollback
        var strURL = "downgrade";
        return strURL;
    }
    
    if (PluginDetect.isMinVersion("Java", "1,5,0,7") == -1) {
        // upgrade
        var strURL = "upgrade";
        return strURL;
    }
    
    return "";
}

function fnOpenPopup(varURL, varTITLE, varWIDTH, varHEIGHT) {
    var x = (window.screen.width - varWIDTH)/2;
    var y = (window.screen.height - varHEIGHT)/2;
    
    var wnd = window.open(varURL,varTITLE,"height=" + varHEIGHT + ",width=" + varWIDTH + ",top=" + y + ",left=" + x + ",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,titlebar=no");
    
    return wnd;
}

function fnOpenPopOut(varURL, varWIDTH, varHEIGHT) {
    var x = (window.screen.width - varWIDTH)/2;
    var y = (window.screen.height - varHEIGHT)/2;
    
    var wnd = window.open(varURL,"_POPOUT","height=" + varHEIGHT + ",width=" + varWIDTH + ",top=" + y + ",left=" + x + ",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,titlebar=no");
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

        var strMessage = "Please provide a valid email address.";

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert(strMessage);
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert(strMessage);
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert(strMessage);
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
  		    alert(strMessage);
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert(strMessage);
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert(strMessage);
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert(strMessage);
		    return false
		 }

 		 return true					
	}
