
/* General Functions
------------------------------------------------ */
function checkIfPreview(){
	var url=location.href;
      url= url.toLowerCase();
	if(url.match("preview")=="preview"){
		return true;
	}
	else {
		return false;
	}
}
function loadPage(){
    if(checkIfPreview()){  
		loadMenu('/aalaus/aalaus.nsf/resources/navpreview.xml');
	}
	else{
		loadMenu('/aalaus/aalaus.nsf/resources/navpublish.xml');
	}
}
function go(){
	window.location=document.getElementById("productmenu").value;
}
function Redirect(sRedirectPage){
// form correct URL - replace any spaces with + symbol
	var reg = /\s+/;
	sRedirectPage = sRedirectPage.replace(reg,'+') ;
	if( sRedirectPage.toLowerCase( ) == "/travel-insurance" )
	{
		window.location='https://www.allianz.com.au/travel-insurance';
	}
	else
	{
		window.location=sRedirectPage;
	}
}
function goToURL(sURL){ window.location = sURL; }
function openCalc( calcName ) {
	var width = 700;
	var height = 550;
	var x = Math.round( (screen.width - width) / 2 );
	var y = Math.round( (screen.height - height) / 4 );
	
	if( calcName == "building"  ) {
		url = "http://www.allianz.com.au/redirect/allianz-homecalc-building";
	} else {
		url = "http://www.allianz.com.au/redirect/allianz-homecalc-contents";
	}
	//var winOptions = "width=" + width + ",height=" + h + ",top=" + y + ",left=" + x+ ",scrollbars=yes,menu=no,toolbar=no,status=yes,resizable=yes";
	window.open( url, "", "menu=no,width=" + width + ",height=" + height + ",left=" + x + ",top=" + y + ",scrollbars=yes" );
}
/* Print Page
This script will change the font size of any text within a paragraph (<p> tag). 
If you wish to change text within other tags edit the getElementsByTagName('p'); part. 
------------------------------------------------------*/
function printPage(){
	window.open (location.href  +'?var=Print','Print','width=615, height=800, scrollbars=1');
}
/* Increase / Decrease Font Size
This script will change the font size of any text within a paragraph (<p> tag). 
If you wish to change text within other tags edit the getElementsByTagName('p'); part. 
------------------------------------------------------*/
var min=8;
var max=18;
function increaseFontSize() {
   var p = document.getElementsByTagName('p');
   var s = 12; // default font size
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         s = parseInt(p[i].style.fontSize.replace("px",""), 10);
      } else {
         s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px";
   }
}
function decreaseFontSize() {
   var p = document.getElementsByTagName('p');
   var s = 12; // default font size
   
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         s = parseInt(p[i].style.fontSize.replace("px",""), 10);
      } else {
         s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px";
   }   
}
function openConditions() { window.open( "/aalaus/aalaus.nsf/File?Open&v=docs&s=ConditionsApply-Common", "", "width=500,height=780,menu=no,scrollbars=yes" ); }
function openCarConditions() { window.open( "/aalaus/aalaus.nsf/File?Open&v=docs&s=ConditionsApply-Car", "", "width=500,height=780,menu=no,scrollbars=yes" ); }
function openCTPConditions() {window.open( "/aalaus/aalaus.nsf/File?Open&v=docs&s=CTP+Conditions", "", "width=490,height=460,menu=no" ); }
function openCTPQLDConditions() {window.open( "/aalaus/aalaus.nsf/File?Open&v=docs&s=CTP+QLD+Conditions", "", "width=900,height=580,menu=no" ); }
function openSBDConditions() {window.open( "/aalaus/aalaus.nsf/File?Open&v=docs&s=SBD+Conditions", "", "width=500,height=375,menu=no" ); }
function openFindOutMore() {window.open( "http://allianz.acrobat.com/newallianzwebsite/", "", "width=800,height=600," ); }
function openLifeInsuranceDisclaimer() {window.open( "/aalaus/aalaus.nsf/File?Open&v=docs&s=Life+Insurance+Disclaimer", "", "width=250,height=195,menu=no" ); }
function openAppWindow(name, shortLink)
{
	var url = "";
	var width = 1024;
	var height = 560;  // set to -1 to get maximum height on screen
	var replaceOption = false;
	if( typeof openAppWindow.winRefs == 'undefined' )  //thanks Peter Bailey and stackoverflow.com
	{
		openAppWindow.winRefs = {};
	}
	if ( typeof openAppWindow.winRefs[name] == 'undefined' || openAppWindow.winRefs[name].closed )
	{
		if( shortLink.indexOf('/') > 0 ) { url = shortLink; }
		else { url = "/redirect/" + shortLink; }
		//popapp_custwidth( name, url, 1024, true );
		if( height < 0 )
		{
			var h = Math.round( screen.height - (screen.height * 0.15) );
		}
		else
		{
			var h = height;
		}
		var x = Math.round( (screen.width - width) / 2 );
		var y = Math.round( (screen.height - h) / 4 );
		var winOptions = "width=" + width + ",height=" + h + ",top=" + y + ",left=" + x+ ",scrollbars=yes,menu=no,toolbar=no,status=yes,resizable=yes";
		if(window.location.toString().indexOf("/wb/") > 0) {
			url = "/wb" + url;
		}
		openAppWindow.winRefs[name] = window.open(url, name, winOptions, replaceOption);
	}
	else
	{
		openAppWindow.winRefs[name].focus();
	}
	return false;
}
function popapp(name, url) {
	var h = screen.height - (screen.height * 0.10);
	var x = (screen.width / 2) - 395;
	var y = 0;
	if(window.location.toString().indexOf("/wb/") > 0) {
		url = "/wb" + url;
	}
	var q = window.open(url, name, "width=790,height=" + h + ",top=" + y + ",left=" + x+ ",scrollbars=yes,menu=no,toolbar=no,status=yes");
	return false;
}
function popapp_custwidth(name, url, width) {
	var h = screen.height - (screen.height * 0.10);
	var x = (screen.width - width) / 2;
	var y = (screen.height - h) / 2;
	if(window.location.toString().indexOf("/wb/") > 0) {
		url = "/wb" + url;
	}
	var q = window.open(url, name, "width=" + width + ",height=" + h + ",top=" + y + ",left=" + x+ ",scrollbars=yes,menu=no,toolbar=no,status=yes");
	return false;
}
function popapp_maxheight(name, url, width, maxheight ) {
	var h = screen.height - (screen.height * 0.10);
                if( h > maxheight ) { h = maxheight; }
	var x = (screen.width - width) / 2;
	var y = (screen.height - h) / 2;
	if(window.location.toString().indexOf("/wb/") > 0) {
		url = "/wb" + url;
	}
	var q = window.open(url, name, "width=" + width + ",height=" + h + ",top=" + y + ",left=" + x+ ",scrollbars=yes,menu=no,toolbar=no,status=yes");
	return false;
}
function popapp_life(name, url) {
	var life_h = screen.height - (screen.height * 0.10);
	var life_x = (screen.width / 2) - 395;
	var life_y = 0;
	if(window.location.toString().indexOf("/wb/") > 0) {
		url = "/wb" + url;
	}
	var life_q = window.open(url, name, "width=860,height=" + life_h + ",top=" + life_y + ",left=" + life_x+ ",scrollbars=yes,menu=no,toolbar=no,status=yes");
	return false;
}
function popapp_home(name, url) {
	var home_h = screen.height - (screen.height * 0.10);
	var home_x = (screen.width / 2) - 395;
	var home_y = 0;
	if(window.location.toString().indexOf("/wb/") > 0) {
		url = "/wb" + url;
	}
	var life_q = window.open(url, name, "width=870,height=" + home_h + ",top=" + home_y + ",left=" + home_x+ ",scrollbars=yes,menu=no,toolbar=no,status=yes");
	return false;
}
function popapp_payment(name, url) {
	var pay_h = screen.height - (screen.height * 0.10);
	var pay_x = (screen.width / 2) - 395;
	var pay_y = 0;
	if(window.location.toString().indexOf("/wb/") > 0) {
		url = "/wb" + url;
	}
	var pay_q = window.open(url, name, "width=860,height=" + pay_h + ",top=" + pay_y + ",left=" + pay_x+ ",scrollbars=yes,menu=no,toolbar=no,status=yes");
	return false;
}
function popapp_payment2(name, url) {
	var pay_h = screen.height - (screen.height * 0.30);
	var pay_x = (screen.width / 2) - 395;
                
	var pay_y = 0;
	if(window.location.toString().indexOf("/wb/") > 0) {
		url = "/wb" + url;
	}
	var pay_q = window.open(url, name, "width=900,height=" + pay_h + ",top=" + pay_y + ",left=" + pay_x+ ",scrollbars=yes,menu=no,toolbar=no,status=yes");
	return false;
}
function openEmailFriend() {
var sPathname = escape(window.location.pathname);
window.open( "/s/email_friend?open&url="+sPathname, "", "width=440,height=490,menu=no" );
 }
function getVariableContent( sItemKey )
{
   var req = new Ajax.Request( '/aalaus/aalaus.nsf/getVariableContent?openAgent&key=' + escape(sItemKey),
   {
      method: 'get',
      asynchronous: false,
      overrideMimeType: 'text/html',
      onSuccess: function( transport )
      {
         var response = transport.responseText || "Unable to retrieve variable content.";
         document.write( response );
      },
      onFailure: function()
      {
         document.write( "Unable to retrieve variable content." );
      }
   });
}
function getQueryParam( param )
{
	var startPos = 0;
	var endPos = 0;

	var queryString = document.location.search || document.location.href.hash;

	if( queryString )
	{
		startPos = queryString.indexOf( param + "=" );
		if( queryString.indexOf("&", startPos) > -1 ) { endPos = queryString.indexOf( "&", startPos ); } else { endPos = queryString.length; }
		if( queryString.length > 1 && startPos > -1 ) { return queryString.substring( queryString.indexOf( "=", startPos ) + 1, endPos ); }
	}
	return "";
}
function setCookie( name, value, expires, path, domain, secure )
{
// use it in this format setCookie( 'mycookie', 'visited 9 times', 30, '/', '', '' );. 
// if '30' is blank, the cookie will be 
// set time, it's in milliseconds
// put in empty quotes for the unused parameters or you'll get an error when you run the code. 
// This makes the cookie named 'mycookie', with the value of 'visited 9 times', and with a life of 30 days, and the cookie is set to your root folder. 
// The Set_Cookie values for 'domain' and 'secure' are not utilized.
// Use 'domain' on the Javascript cookie if you are using it on a subdomain, like widgets.yoursite.com, where the cookie is set on the widgets subdomain, but you need it to be accessible over the whole yoursite.com domain. 
// It's good practice to not assume the path to the site root will be set the way you want it by default, so do this manually as a rule, '/'.
// If no value is set for expires, it will only last as long as the current session of the visitor, and will be automatically deleted when they close their browser. 

var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function getCookie( check_name ) {
		 // first we'll split this cookie up into name/value pairs
		 // note: document.cookie only returns name=value, not the other components
		 var a_all_cookies = document.cookie.split( ';' );
		 var a_temp_cookie = '';
		 var cookie_name = '';
		 var cookie_value = '';
		 var b_cookie_found = false; // set boolean t/f default f

		 for ( i = 0; i < a_all_cookies.length; i++ )
		 {
				// now we'll split apart each name=value pair
				a_temp_cookie = a_all_cookies[i].split( '=' );


				// and trim left/right whitespace while we're at it
				cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

				// if the extracted name matches passed check_name
				if ( cookie_name == check_name )
				{
						b_cookie_found = true;
						// we need to handle case where cookie has no value but exists (no = sign, that is):
						if ( a_temp_cookie.length > 1 )
						{
							cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
						}
						// note that in cases where cookie is initialized but no value, null is returned
						return cookie_value;
				}
				a_temp_cookie = null;
				cookie_name = '';
		}
		if ( !b_cookie_found )
		{
			return null;
		}
}
/**** Stats tracking functions ****/
function linkTracker( currentObj, linkType, ignore1, ignore2 )
{
	/* Track with Site Intelligence */
	if( typeof sitracker != 'undefined' )
	{
		switch( linkType )
		{
		case 'untagged':
			sitracker.trackLinkToUntagged( currentObj );
			break;
		case 'external':
			sitracker.trackExternalLink( currentObj );
			break;
		case 'migrate':
			sitracker.migrateCookie( currentObj );
			break;
		default:
			sitracker.trackLink( currentObj );
			break;
		}
	}
	return true;
}
/* show/hide toggle for answers in FAQ lists */
function toggle_faq(id)
{
	var e = document.getElementById(id);
	if(e.style.display == 'block')
		e.style.display = 'none';
	else
		e.style.display = 'block';
}

