// Global Vars

// Tracks open window usage for re-use
var GsChildWin;

function PRU_showText( iID ) {

	if ( document.all && document.getElementById ) {

		var oObject = document.getElementById( iID );
		if ( oObject != null ) {
			if ( oObject.style.display == 'none' ) { oObject.style.display = ''; } else { oObject.style.display  = 'none'; }
		}

	} else if ( ( ! document.all ) && document.getElementById ) {

		var oObject = document.getElementById( iID );
		if ( oObject != null ) {
			if ( oObject && oObject.style.display == 'none' ) { oObject.style.display = 'block'; } else { oObject.style.display  = 'none'; }
		}

	} else if ( document.all ) {

		var oObject = eval( "document.all." + iID );
		if ( oObject != null ) {
			if ( oObject && oObject.style.display == 'none' ) { oObject.style.display = ''; } else { oObject.style.display  = 'none'; }
		}	
	} 

}


function PRU_hideText( iID ) {


	if ( document.all && document.getElementById ) {

		var oObject = document.getElementById( iID );
		if ( oObject != null ) {
			if ( oObject && oObject.style.display == '' ) { oObject.style.display = 'none'; } else { oObject.style.display  = ''; }
		}

	} else if ( ( ! document.all ) && document.getElementById ) {

		var oObject = document.getElementById( iID );
		if ( oObject != null ) {
			if ( oObject && oObject.style.display == 'block' ) { oObject.style.display = 'none'; } else { oObject.style.display  = 'block'; }
		}

	} else if ( document.all ) {

		var oObject = eval( "document.all." + iID );
		if ( oObject != null ) {
			if ( oObject && oObject.style.display == '' ) { oObject.style.display = 'none'; } else { oObject.style.display  = ''; }
		}
		
	} 

}


function openWindow( sUrl, sParams ) { window.open( sUrl, '', sParams ); }


function PRU_JSopenUrl( sUrl, iWidth, iHeight, sParamaters )
{
	if ( GsChildWin ) { GsChildWin.close(); }

	if ( sParamaters ) { sParamaters = sParamaters + "," };

	GsChildWin = window.open( sUrl, '', sParamaters + "width=" + iWidth + ",height=" + iHeight + ", top=" + ( ( screen.availheight - iHeight ) / 2 ) + ", left=" + ( ( screen.availwidth  - iWidth  ) / 2 ) );


}


function PRU_getCookie( sCookieID )
{

/*

Function: Returns a cookie value given a name

Input: sCookieID - cookie name

Output: String; cookie value, or false if not found

**/


	var aCookieElements = document.cookie.toString().split( /;/ ); 

	for ( var i = 0; i < aCookieElements.length; i++ )
	{
		var aNameValue = aCookieElements[i].split( /\=/ );
		aNameValue[0]  = aNameValue[0].replace( /^\s*/, "" );
		if ( aNameValue[0] == sCookieID ) { return aNameValue[1]; }
	}

	return false;

}


/* ----------------------------------------------------------- **/


function PRU_setCookie( name, value, expires, path, domain, secure )
{

/*

Function: Set a cookie

Input:  name - name of cookie
	value - cookie value
	expires - date at which cookie should be removed
	path - directories from which cookie is accessible
	domain - host name
	secure - determines whether cookie is secure

Output: N/A

**/

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

}



/* ----------------------------------------------------------- **/

function PRU_getBannerAd( )
{

/*

Function: Rotate Banners

Input:  Array from a field within the template 

Output: N/A

**/


	var iAdIndex = Math.floor( Math.random() * aGBannersAds.length );

	document.write( aGBannersAds[iAdIndex] );

}

function PRU_getApplicationForm( sPath, iMessageType )
{

	var iWidth = 720; var iHeight = 400;
	var sMessage  = "";

	if ( iMessageType == 1 )
	{
		sMessage  = "<span style='FONT-SIZE: x-small; COLOR: #003366; FONT-FAMILY: Arial, Helvetica, sans-serif'><p><img border='0' src='/content/images/pruredonwhite.gif'><p>You made a wise choice when you recommended a Prudential investment to your clients.<br><br>We believe it's still a sound choice. . .&nbsp;<br><br>. . .and here are a few reasons why:<ul><li><b>Our financial strength</b> - we're rated AA+ by Standard &amp; Poor's</li><li><b>Our fund size</b> - we have the largest <a href='/content/81442/81429/' title='This link opens in a new window' target='_blank'> With-Profits Fund </a>in the UK</li><li><b>Our experience</b> - we're one of the UK's largest financial services providers and have won awards for both products and services</li></ul></span><a href='JavaScript:window.opener.PRU_JSactionApplication( \"" + sPath + "\" )'><img src='/content/images/gobutton.gif' border='0' /></a>";
	}
	

	var sTemplage = "<html><head><title>Cash In Form</title></head><body><table cellpadding='10' cellspacing='10' align='center'><tr><td>" + sMessage + "</td></tr></table></body></html>";

	PRU_JSopenUrl( '', iWidth, iHeight, 'scrollbars=yes, resizable=yes' );

	GsChildWin.document.open();
	GsChildWin.document.write(sTemplage);
	GsChildWin.document.close();

}

/* ----------------------------------------------------------- **/

function PRU_JSactionApplication( sPath )
{
	GsChildWin.close();
	PRU_JSopenUrl( sPath, 700, 600, 'resizable=yes, scrollbars=yes, toolbar=yes' );
}

function MM_openBrWindow(theURL,winName,features) 
{
 window.open(theURL,winName,features);

}

function change_parent_url(url)    
{
	document.location=url;
}	

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

function gup( 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];}

function hideHeader(){
	if(gup( 'iEiD' )!=""){	
	document.getElementById('topBarContainer').style.display = 'none';
	document.getElementById('topBannerContainer').style.display = 'none';
	document.getElementById('topTabRedBar').style.display = 'none';
	document.getElementById('topTabContainer').style.display = 'none';
	document.getElementById('productNav').style.display = 'none';
	document.getElementById('rightNavContainer').style.display = 'none';
	document.getElementById('footer').style.display = 'none';
	}
	setupLinks()
}

var locallink=false;
var strCookValue=getCookie("mypruacookie");

function setupLinks(){
var j=0;
for (var i=0;i<document.links.length;i++){
var str=document.links[i].href.substring(0, 26);
if (document.links[i].onclick!= null){
}else{
document.links[i].onclick = function(){ locallink = true };
}
}
}

function checkExit(){
adSurvey= Math.round(Math.random() * 11);
if (!locallink){
	if(strCookValue!="b"){
 	var expireDate = new Date()
	expireDate.setDate(expireDate.getDate()+90)
	document.cookie = 'mypruacookie=b;expires='+expireDate.toGMTString() + ';path=/';	
		if(adSurvey>5){	
		//window.open("https://resp.survey01.net/servlet/survey?surveyId=ODM1OQS2");
//window.open ("https://resp.survey01.net/servlet/survey?surveyId=ODM1OQS2","mywindow","width=1350,height=1650");
//MM_openBrWindow('https://resp.survey01.net/servlet/survey?surveyId=ODYyNwS2','','scrollbars=yes,width=1200,height=800'); 
		}else{
		//window.open("http://resp.survey01.net/servlet/survey?surveyId=ODM2MAS2");	
//window.open ("https://resp.survey01.net/servlet/survey?surveyId=ODM2MAS2","mywindow","width=1350,height=1650");
//MM_openBrWindow('https://resp.survey01.net/servlet/survey?surveyId=ODYyNgS2','','scrollbars=yes,width=1200,height=800'); 
		}
	}
}
}


function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

