﻿// JScript File
<!--

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e)
{
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) 
{
    var found = false, index = 0;
	  while(!found && index < arr.length)
	  if(arr[index] == ele)
		  found = true;
	  else
		  index++;
	  return found;
}	

function getIndex(input) 
{
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input)index = i;
			else i++;
		return index;
		}
		return true;
}

function openWindow( pageName, titleName, winWidth, winHeight) {
	window.open(pageName, titleName, 'height=' + winHeight + ', width=' + winWidth + ', toolbar=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, statusbar=yes, status=yes');
}

function closeWindow()
{
  window.open('','_self','');
  window.close();
}

function applyDisplay( contID, val)
{
    var ctrl = document.getElementById(contID);
    ctrl.style.display = val;
    
    return false;
}

function applyDisplayAlarm(val, contID, rbID, contID2, rbID2)
{
    var ctrl = document.getElementById(contID);
    var rb = document.getElementById(rbID);
    
    ctrl.style.display = val;
    rb.checked = true;
    
    if (contID2 != null && rbID2 != null)
    {
        var ctrl2 = document.getElementById(contID2);
        var rb2 = document.getElementById(rbID2);
        ctrl2.style.display = val;
        rb2.checked = true;    
    }
    
    return false;
}

function redirectPage( sURL)
{
    self.location.href = sURL;
}

function getIFrameReferrer()
{
  try  {  try  {document.getElementById("txtReferrer").value  = window.top.document.referrer;}  catch(err){}  }  catch(err){}  
}

function updateRadioCover(objParking, objCoverType, objRadio, cause)
{
  try
  {
    var parking = objParking.value.replace(/^\s+|\s+$/g, '');
    var cover = objCoverType.value.replace(/^\s+|\s+$/g, '');
    
    if (( (parking == '1') || (parking == '2') || (parking == '3') || (parking == '7') ) || (cover == 'C'))
    {
      var oldIndex = objRadio.selectedIndex;
      objRadio.selectedIndex = 0;
      objRadio.disabled = "disabled";
      if (oldIndex > 0)
        if (cause == 'MP')
          alert('Sound system cover is not allowed for the selected overnight parking facility.');
        else if(cause == 'CV')
          alert('Sound system cover is not allowed for the selected cover type.');
    }
    else
    {
      objRadio.disabled = "";
    }
  }
  catch(err){}
}

function showBusinessUse()
{
      alert('Please note that this vehicle can only be insured for business use');  	  	            	            	  	           
}

function showSuburbPopup()
{
      alert('Please select the correct suburb and postal code from the confirm suburb drop down list.');  	  	            	            	  	           
}

function alertRegDriverMarital(objMarital)
{
  try
  {
    var marital = objMarital.value.replace(/^\s+|\s+$/g, '');
    if (marital == 'M')
    {
        alert('Please note that if this regular driver is not your spouse, they will need to take out their own policy.');
    }
  }
  catch(err){}
}

function LicenceCheck(objLic, objLicYY, objLicMM)
{
  try
  {
    var lic = objLic.value;
    if (lic == '3')
    {
        alert('Please note that if you are a Learner Driver, you must be accompanied by a Licensed Driver when driving a motor vehicle.\n\nPlease inform us immediately upon receipt of your Driver’s Licence.');
        objLicYY.disabled = "disabled";
        objLicMM.disabled = "disabled";
    }
    else
    {
        objLicYY.disabled = "";
        objLicMM.disabled = "";
    }
  }
  catch(err){}
}

function getQueryStringParam(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

//-->


