//Standard JavaScript file.  Created by Alex Fahey 0419 479898


function openWindow(URL, height, width)
{
	settings = 'height=' + height;
 	settings += ',width=' + width;
	settings += ',left=100,top=100,heading=no,topbar=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,border=no';	
	winChart=window.open(URL,'nWindow',settings);
	winChart.focus();
}

function openWindowScroll(URL, height, width)
{
	settings = 'height=' + height;
 	settings += ',width=' + width;
	settings += ',left=100,top=100,heading=no,topbar=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,border=no';	
	winChart=window.open(URL,'nWindow',settings);
	winChart.focus();
}

function openWindowPrint(URL, height, width)
{
	settings = 'height=' + height;
 	settings += ',width=' + width;
	settings += ',left=100,top=100,heading=no,topbar=no,toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,border=no';	
	winChart=window.open(URL,'nWindow',settings);
	winChart.focus();
}

function getCount(ta)
{
	var maxnum = 20000;
	var c_cnt, tmpStr;

	c_cnt = ta.value.length;
	tmpStr = ta.value + " ";

	var w_space = /^[^A-Za-z0-9]+/gi;
	var lTStr = tmpStr.replace(w_space, "");
	var non_alpha = /[^A-Za-z0-9]+/gi;
	var cStr = lTStr.replace(non_alpha, " ");
	var splitStr = cStr.split(" ");
	var w_cnt = splitStr.length-1;
	
	if (tmpStr.length <2) 
	{
		word_count = 0;
	}

	if (maxnum < c_cnt)
	{
		ta.value = ta.value.substring(0,maxnum);
		alert('Sorry, but this form can only take up to 20,000 characters (roughly 3000 words). You have now reached this limit.');
	}
}

function validateMandatoryFields(formobj,fieldRequired,fieldDescription){
var alertMsg = "The following fields must be entered before submitting this form:\n";
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
     var obj = formobj.elements[fieldRequired[i]];
     if (obj){
         switch(obj.type)
         {
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""|| obj.options[obj.selectedIndex].value == "")
{alertMsg += " - " + fieldDescription[i] + "\n";}
break;
case "select-multiple":
if (obj.selectedIndex == -1)
{alertMsg += " - " + fieldDescription[i] + "\n";}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null)
{alertMsg += " - " + fieldDescription[i] + "\n";}
break;
default:
if (obj.value == "" || obj.value == null)
{if(obj.length >0)
{
var pass=false;
for (var x = 0; x < obj.length; x++)
{
if (obj[x].checked)
{pass = true;
break;}}
if (pass == false)
{alertMsg += " - " + fieldDescription[i] + "\n";}
}}}}}
if (alertMsg.length == l_Msg){
	if(formobj.Email.value!=""){
		if (confirm ("Please confirm that this is your email address is:" + "\n" + "\n" + formobj.Email.value)){
		    return true;
		}else{
		    return false;
		}
	}else{
		return true;
	}
  } else {
    alert(alertMsg);
    return false;
  }
}


function m_over(theId, theColor)
{
  if (document.layers) 
  {
    document.layers[theId].color=theColor;
	document.layers[theId].textDecoration='underline';
  }
  else if (document.documentElement || document.all) // for NS6 & IE
  {
	// getElementById(theId) is to be used for NS6 and we can also use this for IE
    var elm = document.getElementById(theId);
	elm.style.color=theColor;
	elm.style.textDecoration='underline';
  }
}

function m_out(theId)
{
  if (document.layers) // for NN4
  {
    document.layers[theId].color='black';
	document.layers[theId].textDecoration='underline';
  }
  else if (document.documentElement || document.all) // for NS6 & IE
  {
	// getElementById(theId) is to be used for NS6 and we can also use this for IE
    var elm = document.getElementById(theId);
	elm.style.color='black';
	elm.style.textDecoration='underline';
  }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//Show hide PAS description functions
var DHTML = (document.getElementById || document.all || document.layers);

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function showSingleDescription(div_id) 
{
//Update the visibility
if (!DHTML) return;
var x = new getObj(div_id);
var y = new getObj('link'+div_id);
x.style.display = 'block';
y.style.display = 'none';
}

function showAllDescription() 
{
//Update the visibility for all div tags
if (!DHTML) return;
var div_id = 1;
var a =  new getObj('showAll');
var b =  new getObj('hideAll');
a.style.display = 'none';
b.style.display = 'block';
var x = new getObj(div_id);
var y = new getObj('link'+div_id);
	do
	{
		x.style.display = 'block';
		y.style.display = 'none';
		div_id ++;
		x = new getObj(div_id);
		y = new getObj('link'+div_id);
	}
	while (x && typeof x == 'object')
}

function showAllDescription100() 
{
//Update the visibility for all div tags
if (!DHTML) return;
var div_id = 101;
var a =  new getObj('showAllThreat');
var b =  new getObj('hideAllThreat');
a.style.display = 'none';
b.style.display = 'block';
var x = new getObj(div_id);
var y = new getObj('link'+div_id);
	do
	{
		x.style.display = 'block';
		y.style.display = 'none';
		div_id ++;
		x = new getObj(div_id);
		y = new getObj('link'+div_id);
	}
	while (x && typeof x == 'object')
}

function hideSingleDescription(div_id) 
{
//Update the visibility
if (!DHTML) return;
var x = new getObj(div_id);
var y = new getObj('link'+div_id);
x.style.display = 'none';
y.style.display = 'block';
}

function hideAllDescription() 
{
//Update the visibility for all div tags
if (!DHTML) return;
var div_id = 1;
var a =  new getObj('showAll');
var b =  new getObj('hideAll');
a.style.display = 'block';
b.style.display = 'none';
var x = new getObj(div_id);
var y = new getObj('link'+div_id);
	do
	{
		x.style.display = 'none';
		y.style.display = 'block';
		div_id ++;
		x = new getObj(div_id);
		y = new getObj('link'+div_id);
	}
	while (x && typeof x == 'object')
}

function hideAllDescription100() 
{
//Update the visibility for all div tags
if (!DHTML) return;
var div_id = 101;
var a =  new getObj('showAllThreat');
var b =  new getObj('hideAllThreat');
a.style.display = 'block';
b.style.display = 'none';
var x = new getObj(div_id);
var y = new getObj('link'+div_id);
	do
	{
		x.style.display = 'none';
		y.style.display = 'block';
		div_id ++;
		x = new getObj(div_id);
		y = new getObj('link'+div_id);
	}
	while (x && typeof x == 'object')
}


//Functions to do with the Detailed References List
//*************************************************************************************************************
function filterList(objForm)
{


	//Variables
	var strPubType
	
	//Hide all rows first
	hideAllRows()

	//Show required rows
	//Get the publication type
	for (var x = 0; x < objForm.pubtype.length; x++)
	{
		if (objForm.pubtype[x].checked)
		{
			strPubType = objForm.pubtype[x].value;
		}
	}

	//Loop through the topics and show the required ones
	
	for (var x = 0; x < objForm.type.length; x++)
	{
		if (objForm.type[x].checked)
		{
			showRow(objForm.type[x].value, strPubType)
		}
	}
	
	showAlternateColorRow();
	
	
}

function showAlternateColorRow()
{
	if(!document.getElementById) return; // Not Supported
	if(document.getElementById)
	{
		var allTrTags = new Array();
		allTrTags=document.getElementsByTagName("tr");
		var j = 0;
		for (i=0; i<allTrTags.length; i++) 
		{
			if (allTrTags[i].className=='shownData') 
			{
				j++;
				if ( j%2 == 0)
				{
					allTrTags[i].style.backgroundColor = "EFEFEF";
					
				}
				else{
					allTrTags[i].style.backgroundColor = "white";
				}
			
				
			}
			
		}
	}
}

function showRow(idType, idPubType)
{
	if(!document.getElementById) return; // Not Supported
	if(document.getElementById)
	{
		var allTrTags = new Array();
		allTrTags=document.getElementsByTagName("tr");
		for (i=0; i<allTrTags.length; i++) 
		{
			if (allTrTags[i].className=='hiddenData') 
			{
				var strType = hasType(allTrTags[i]);
				if(idPubType == 'all')
				{
					if((strType.indexOf(idType) != -1))
					{
						allTrTags[i].className = 'shownData';
					}
				} else {
					if((strType.indexOf(idType) != -1) && (strType.indexOf(idPubType) != -1))
					{
						allTrTags[i].className = 'shownData';
					}
				}
			}
		}
	}
}

function test()	
{
	//find out which cards to show in the table
	var queryString = window.location.search;

	//Only proceed if we have a query string
	if(queryString != "")
	{
		//Only proceed if there is an type parameter
		var idFound = queryString.indexOf("type=");
		if(idFound != -1 )
		{
			//Break the query string into varibles
			var vars = queryString.split("&")
			for( var i = 0; i<vars.length; i++)
			{
				var idValue = vars[i].split("=");
				if (idValue[0] == "type")
				{
					switch(idValue[1])
					{
					case "home-nodeposit":
						showRow("home-nodeposit");
						break;
					case "home-quick":
						showRow("home-quick");
						break;
					case "home-fixed":
						showRow("home-fixed");
						break;
					case "home-flexible":
						showRow("home-flexible");
						break;
					case "home-topup":
						showRow("home-topup");
						break;
					case "invest-nodeposit":
						showRow("invest-nodeposit");
						break;
					case "invest-quick":
						showRow("invest-quick");
						break;
					case "invest-fixed":
						showRow("invest-fixed");
						break;
					case "invest-flexible":
						showRow("invest-flexible");
						break;
					case "invest-topup":
						showRow("invest-topup");
						break;
					case "save-maxi":
						showRow("save-maxi");
						break;
					case "save-esaver":
						showRow("save-esaver");
						break;
					case "save-cashmx":
						showRow("save-cashmx");
						break;
					case "save-reward":
						showRow("save-reward");
						break;
					case "txn-electronic":
						showRow("txn-electronic");
						break;
					case "txn-all":
						showRow("txn-all");
						break;
					case "txn-student":
						showRow("txn-student");
						break;
					case "txn-young":
						showRow("txn-young");
						break;
					case "txn-retired":
						showRow("txn-retired");
						break;
					case "txn-pension":
						showRow("txn-pension");
						break;
					}
				}
			}
		}
	}
}

function hideAllRows()
{
	if(!document.getElementById) return; // Not Supported
	if(document.getElementById)
	{
		var allTrTags = new Array();
		allTrTags=document.getElementsByTagName("tr");
		for (i=0; i<allTrTags.length; i++) 
		{
			if (allTrTags[i].className=='shownData')
			{
				allTrTags[i].className = 'hiddenData';
			}
		}
	}
}

function hasType(obj)
{
	var strResult = "";
	if (obj.getAttributeNode("type") != null) {
		strResult = obj.getAttributeNode("type").value;
	}
	return strResult;
}


function showHidden(id)
{
	if(!document.getElementById) return; // Not Supported
	if(document.getElementById)
	{
		if(document.getElementById(id) == null )
		{
			//ID not found so do nothing
		} else {
			document.getElementById(id).className = "shownData";
		}
	}
}

function hideShown(id)
{
	if(!document.getElementById) return; // Not Supported
	if(document.getElementById)
	{
		if(document.getElementById(id) == null )
		{
			//ID not found so do nothing
		} else {
			document.getElementById(id).className = "hiddenData";
		}
	}
}