// $Author: michaelz $
// $Revision: 1.5 $
// $Date: 2008/08/26 04:22:19 $

function openWin(URL,target,wFeatures) {
  var openURL = URL + "#" + target;
  var openWin = window.open(openURL,"openWin",wFeatures);
  openWin.focus();
  }

function createFormId(formName) {
var formsArray = document.forms;
var noOfForms = formsArray.length;
var i;
var now = new Date();
var found = false;
var currentURL;
var newURL;

	for (i = 0; i < noOfForms; i++) {
		if (document.forms[i].name == formName) {
			found = true;
			currentURL = document.forms[i].action;
			newURL = currentURL + "?id=" + now.getTime();
			document.forms[i].action = newURL;
			break;
		}
	}
	if (found == false) {
		alert("Cannot locate form " + formName);
	}
}

function initialise() {

if (!document.getElementById) {
	  		alert("Sorry, the UAC Offers system has detected a non W3C compliant version of your browser!" + "\n" +
			"You must upgrade your browser to the latest version of Microsoft Internet Explorer OR Netscape." + "\n" +
			"Important Note:" + "\n" +
			"This page ONLY supports Microsoft Internet Explorer OR Netscape browsers." + "\n" +
			"Click OK and you will be redirected to an upgrade page.");
		window.location = "http://www.microsoft.com/ie/"
		}
        else {
        //Disable right click
        var message="";
        function clickIE() {if (document.all) {(message);return false;}}
        function clickNS(e) {if
        (document.layers||(document.getElementById&&!document.all)) {
        if (e.which==2||e.which==3) {(message);return false;}}}
        if (document.layers)
        {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
        else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
        document.oncontextmenu=new Function("return false");
    }
}

function validateLogin(f){
	if (f.uac_number.value==""){
		alert("Please enter your UAC number");
                f.uac_number.focus();
                return false;
        }
       	if (f.pin.value==""){
		alert("Please enter your PIN");
                f.pin.focus();
                return false;
	}
	return true;
}

function validateUpdate(f){
        var currCount = 0;
        var atleastone = false;
        for(i=0;i<f.length && !atleastone;i++) {
          if(f[i].checked) atleastone = true;
        }
        if(!atleastone) {
        alert("Please tick a check box before clicking on 'save'")
        return false;
        }

        return true;
}


function logIn(){
                var now = new Date();
                window.location = "/in_offers/vii_offers.tcl?" + "sid=" + now.getTime();
                }

function myOffers(){
var command = document.update.command;
command.value = "myOffers";
                          createFormId("update");
                          // submit the form
                          document.update.submit();

	}

function logOut(){
                var now = new Date();
                window.location = "/in_offers/vii_offers.tcl?command=logout" + "&sid=" + now.getTime();
                }

function validateLog(f){
    if(f.uac_number.value==""){
        alert("Please enter your UAC number");
        f.uac_number.focus();
        return false;
    }
    return true;
}

function processPinRecovery(){
    var command = document.login.command;
    command.value = "pin_recovery";
    var f=document.login;

    if(validateLog(f)){
        if(confirm("To have your UAC PIN sent to the email address" + "\n" +
                   "you included in your UAC application, click [OK]." + "\n" +
                   "Or click [CANCEL] and contact UAC on (02) 9752 0200" + "\n" +
                   "to request that your UAC PIN be re-issued."))
        {
            disableButton();
            createFormId("login");
            // submit the form
            document.login.submit();
        }
    }
}

function processLogin(){
		var f=document.login;
		if(validateLogin(f)){
			disableButton();
                        createFormId("login");
			document.login.submit();
		}
	}

function processUpdate(){
                var f = document.update.accept_check;
		if(validateUpdate(f)){
                    if(confirm("Click [OK] to continue, or [CANCEL] to quit.")){
			disableButton();
                        createFormId("update");
                        document.update.submit();
		    }
                }
	}
        var numberChecked;
        var maxAllowed = 1;
function limitChecked(obj) {
numberChecked = 0;
for (i=0; i<document.update.accept_check.length; i++){
      if (document.update.accept_check[i].checked==true) {
      numberChecked++;
      }
     }
     if (numberChecked > maxAllowed) {
      alert("You have selected to both accept and reject this offer. Please modify your selection.");
      document.update.accept_check[obj].checked = false;
      numberChecked--;
      }
}

function disableButton(){
		if(document.all){
			document.all('divButton').innerHTML="<INPUT TYPE='button' NAME='helpa' VALUE=':: Processing... please wait ::' class='vbutton'>";
		}
		else if(document.layers){
			document.layers[0].document.write("<body><INPUT TYPE='button' NAME='helpa' VALUE=':: Processing... please wait ::' class='vbutton'>");
			document.layers[0].document.close();
		}
		else if(document.getElementById('divButton')){
			// Netscape 6+  4sec delay
			var o = document.getElementById('divButton');
			o.innerHTML="<INPUT TYPE='button' NAME='helpa' VALUE=':: Processing... please wait ::' class='vbutton'>";
		}
}
