//
// Platform and browser detect variables
//

//MakeLayout("document",widthMin,widthMax,widthMaxClient);

function MakeLayout(){
	
if(document.getElementById){
    var id = 'document';
    // SetWidth(id,(widthMin - 30),(widthMax - 30),widthMaxClient);
    
   
    
    // alert("test");
    // onresize=function(){ SetWidth(id,minr,maxw,maxr);}
    }
}

function SetWidth(id,a,b,c){
	
	// alert(id);
var w=getBrowserWidth();
if(w==0) return;
var el=document.getElementById(id);
el.style.margin="0 auto";
var d=el.style;
if(w<=a) d.width=a+"px";
else if(w>=c) d.width=b+"px";
else{
    var m=(b-a)/(c-a);
    d.width=parseInt(m*w+a*(1-m))+"px";
   }
}

function getBrowserWidth(){
if (window.innerWidth) return window.innerWidth;
else if (document.documentElement && document.documentElement.clientWidth!=0)
    return document.documentElement.clientWidth;
else if (document.body) return document.body.clientWidth;
return 0;
}




var domainName = "http://assetmanagement.hsbc.com"
var isUnix = false;
var isLinux = false;
var isMacintoshPPC = false;
var isMacintosh68K = false;
var isWindows95 = false;
var isWindows98 = false;
var isWindowsNT= false;
var isWindows3x = false;

var isNew = false;
var isIE = false;
var isIE4 = false;
var isIE5 = false;
var isNetscape = false;
var isNetscape4 = false;
var isNetscape6 = false;

var userAgent = navigator.userAgent.toLowerCase();
var appName = navigator.appName;
var appVersion = parseInt(navigator.appVersion);
var platform = (navigator.platform).substring (0, 5);

// Browser detection
if (appVersion > 5) isNew = true;
else if (appName == "Netscape") {
  isNetscape = true;
  if (appVersion == 4) isNetscape4 = true;
  else if (appVersion == 5) isNetscape6 = true;
}
else if (appName == "Microsoft Internet Explorer") {
  isIE = true;
  if (appVersion == 4) {
    isIE4 = true;
    if (msieversion() == 5) isIE5 = true;
  }
}

function msieversion() {
  var ua = window.navigator.userAgent
  var msie = ua.indexOf ( "MSIE " )
  if ( msie > 0 ) return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )))
  else return 0;
}

// Platform detection
if ( ( userAgent.indexOf("win95") !=-1) || ( userAgent.indexOf("windows 95") !=-1) ) isWindows95 = true;
if ( ( userAgent.indexOf("win98") !=-1) || ( userAgent.indexOf("windows 98") !=-1) ) isWIndows98 = true;
if ( ( userAgent.indexOf("winnt") !=-1) || ( userAgent.indexOf("windows nt") !=-1) ) isWindowsNT= true;
if ( ( userAgent.indexOf("win16") !=-1) || ( userAgent.indexOf("windows 3.1") !=-1) ) isWindows3x = true;
if ( navigator.appVersion.indexOf("Mac") != -1 ) {
  if ( userAgent.indexOf("pc)") !=-1 ) isMacintoshPPC = true;
  else isMacintosh68K = true;
}
if ( platform == "SunOS" ) isUnix = true;
else if ( platform == "HP-UX" ) isUnix = true;
else if ( platform == "IRIX " ) isUnix = true;
else if ( ( ( navigator.platform ).substring (0, 3) ) == "AIX" ) isUnix = true;
else if ( userAgent.indexOf("linux") != -1 ) isLinux = true;

// Added by Chris to support existing hsbc functions

if(isIE || isIE4 || isIE5) ie=true;
else ie=false;
if(isMacintoshPPC || isMacintosh68K) mac=true;
else mac=false;
if(isWindowsNT) nt=true;
else nt=false;
if(isUnix || isLinux) unix=true;
else unix=false;
if(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("5.5") != -1) ie5_5=true;
else ie5_5=false;

//
// Generic functions
//

//This preloads the images. See the body tag for the syntax to do this for an image
function imageLoad() {
        if (document.images) {
                var imgFiles = imageLoad.arguments;
                if (document.preloadArray==null) document.preloadArray = new Array();
                var i = document.preloadArray.length;
                with (document) for (var j=0; j<imgFiles.length; j++){
                        preloadArray[i] = new Image;
                        preloadArray[i++].src = imgFiles[j];
                } 
        }
}

function swapImage(layerStem,imageSpace,imageName) {
  var ns4 = (document.layers)? true:false;
  var ie4 = (document.all)? true:false;
   if(!ie){ if(layerStem == ""){imageObj = document.images[imageSpace];}
            else
         {imageObj = eval(layerStem+".document.images[imageSpace]");}
      }
   if(ie){imageObj = document.all[imageSpace]}

        imageObj.src = imageName;

}

// Used for selecting window size
function openWindow(winUrl, winName, properties) {

switch (properties) {

    case "win_a":
   newWindow = window.open(winUrl,winName,"scrollbars,menubar,location,toolbar,resizable,HEIGHT=500,WIDTH=700,TOP=10,LEFT=10");
        newWindow.focus();
   break
   
    
   case "win_external_site":
      newWindow = window.open(winUrl,winName,"scrollbars,menubar,location,toolbar,resizable,HEIGHT=600,WIDTH=800,TOP=10,LEFT=10");
           newWindow.focus();
   break

    case "win_b":
        newWindow = window.open(winUrl,winName,"HEIGHT=250,WIDTH=445,TOP=10,LEFT=10");
        newWindow.focus();
        break

    case "win_b_no_scroll":
        newWindow = window.open(winUrl,winName,"HEIGHT=470,WIDTH=525,TOP=10,LEFT=10");
        newWindow.focus();
        break

    case "win_c":
        newWindow = window.open(winUrl,winName,",HEIGHT=241,WIDTH=550,TOP=10,LEFT=10");
        newWindow.focus();
        break

    case "win_c_no_scroll":
        newWindow = window.open(winUrl,winName,"HEIGHT=555,WIDTH=570,TOP=0,LEFT=0");
        newWindow.focus();
        break


	case "win_d":
   		newWindow = window.open(winUrl,winName,"HEIGHT=180,WIDTH=700,TOP=20,LEFT=20");
        newWindow.focus();
   		break
		
	case "win_e":
        newWindow = window.open(winUrl,winName,"HEIGHT=280,WIDTH=603,TOP=10,LEFT=10");
        newWindow.focus();
        break

	case "win_e_1":
        newWindow = window.open(winUrl,winName,"HEIGHT=250,WIDTH=603,TOP=10,LEFT=10");
        newWindow.focus();
        break	
			
    case "win_e_2":
        newWindow = window.open(winUrl,winName,"HEIGHT=293,WIDTH=603,TOP=10,LEFT=10");
        newWindow.focus();
        break
	case "win_e_3":
        newWindow = window.open(winUrl,winName,"HEIGHT=308,WIDTH=603,TOP=10,LEFT=10");
        newWindow.focus();
        break
		
	case "win_e_4":
        newWindow = window.open(winUrl,winName,"HEIGHT=380,WIDTH=603,TOP=10,LEFT=10");
        newWindow.focus();
        break
		
	case "win_e_5":
        newWindow = window.open(winUrl,winName,"HEIGHT=395,WIDTH=620,scrollbars=yes,TOP=10,LEFT=10");
        newWindow.focus();
        break	
		
		case "win_f":
   		newWindow = window.open(winUrl,winName,"scrollbars, HEIGHT=600,WIDTH=800,TOP=20,LEFT=20");
        newWindow.focus();
   		break

    case "win_g":
        newWindow = window.open(winUrl,winName,"HEIGHT=100,WIDTH=300,TOP=250,LEFT=250");
        newWindow.focus();
	break
        
	case "win_h":
        newWindow = window.open(winUrl,winName,"HEIGHT=250,WIDTH=430,TOP=10,LEFT=10");
        newWindow.focus();
	break

	case "win_i":
        newWindow = window.open(winUrl,winName,"HEIGHT=700,WIDTH=700,TOP=5,LEFT=5");
        newWindow.focus();
	break

	case "win_j":
        newWindow = window.open(winUrl,winName,"HEIGHT=108,WIDTH=298,TOP=10,LEFT=10");
        newWindow.focus();
	break
	case "win_u":
	  	newWindow = window.open(winUrl,winName,"scrollbars,menubar,toolbar,resizable,HEIGHT=500,WIDTH=700,TOP=10,LEFT=10");
	       	newWindow.focus();
		showDisclaimer("../../disclaimers/disclaimer.htm");
	break
	case "win_v":
	  	newWindow = window.open(winUrl,winName,"scrollbars,menubar,toolbar,resizable,HEIGHT=500,WIDTH=700,TOP=10,LEFT=10");
	       	newWindow.focus();
		showDisclaimer("../../../disclaimers/disclaimer.htm");
	break
	case "win_x":
	  	newWindow = window.open(winUrl,winName,"scrollbars,menubar,toolbar,resizable,HEIGHT=500,WIDTH=700,TOP=10,LEFT=10");
	       	newWindow.focus();
	break
	case "win_y":
	  	newWindow = window.open(winUrl,winName,"scrollbars,menubar,toolbar,resizable,HEIGHT=500,WIDTH=700,TOP=10,LEFT=10");
	       	newWindow.focus();
		showDisclaimer("../../../disclaimers/disclaimer.htm");
	break
    default:
        newWindow = window.open(winUrl,winName,properties);
        newWindow.focus();
    }
}  

//Closes the current window
function windowClose(){
  window.close();
}

	
//This closes a window	
function closeWindow() 
{
		window.opener.focus();
		window.close();
}
// End -->


//This is for the drop down menus, within the fund selection area 
var Open = "";
var OpenSub = "";
var OpenBSub = "";
   	function mOver(theObject) {
		document[theObject].hiLite;
	}


	function toggleView(theObject) {
		parentObj = theObject.id + "Parent";

		 if (document.all) {
			if (document.all[parentObj].className == "parentUp") {
				document.all[parentObj].className = "parentDown";
				theObject.className = "shownItems";
			}else {
				document.all[parentObj].className = "parentUp";
				theObject.className = "collapsed";
			}
		}else{
			if (document.getElementById) {
				if (document.getElementById(parentObj).className == "parentUp") {
					document.getElementById(parentObj).className = "parentDown";
					theObject.className = "shownItems";
				}else {
					document.getElementById(parentObj).className = "parentUp";
					theObject.className = "collapsed";
				}
			}
		}	
	}
	function mOnClick(theObject) {
			if (Open == "") { Open = theObject; }
			 if (document.all) {
				if (Open != theObject) {
					document.all[Open].className = "collapsed";
					Open = theObject;
				}

				if (document.all[theObject].className == "shownItems") { 
					document.all[theObject].className = "collapsed"; 
				}else { 
					document.all[theObject].className = "shownItems"; 
				}
			}else {
				if (document.getElementById) {

					if (Open != theObject) {
						document.getElementById(Open).className = "collapsed";
						Open = theObject;
					}

					if (document.getElementById(theObject).className == "shownItems") { 
						document.getElementById(theObject).className = "collapsed"; 
					}else { 
						document.getElementById(theObject).className = "shownItems"; 
					}

				}
			}
	}

	function mSubOnClick(theObject) {
		if (OpenSub == "") { OpenSub = theObject; }

		if (document.all) {
	
			if (OpenSub != theObject) {
				document.all[OpenSub].className = "collapsed";
				OpenSub = theObject;
			}
			if (document.all[theObject].className == "shownItems") { 
				document.all[theObject].className = "collapsed"; 
			} else {
				document.all[theObject].className = "shownItems"; 
			}
		}else {
			if (document.getElementById) {
				if (OpenSub != theObject) {
					document.getElementById(OpenSub).className = "collapsed";
					OpenSub = theObject;
				}
				if (document.getElementById(theObject).className == "shownItems") { 
					document.getElementById(theObject).className = "collapsed"; 
				} else {
					document.getElementById(theObject).className = "shownItems"; 
				}
			}
		}
	}


	function mBSubOnClick(theObject) {
		if (OpenBSub == "") { OpenBSub = theObject; }

		if (document.all) {//a
			if (OpenBSub != theObject) {//b
					document.all[OpenBSub].className = "collapsed";
			OpenSub = theObject;
			}//end b
		
			if (document.all[theObject].className == "shownItems") { //c
				document.all[theObject].className = "collapsed"; }
			else { //c
				document.all[theObject].className = "shownItems"; 
			}//end c
		}//end a
		else{//d
			if (document.getElementById) {//e

				if (OpenBSub != theObject) {//f
						document.getElementById(OpenBSub).className = "collapsed";
				OpenSub = theObject;
				}//end f
			
				
				if (document.all(theObject).className == "shownItems") { //g
					document.getElementById(theObject).className = "collapsed"; 
				}else { 
					document.getElementById(theObject).className = "shownItems"; 
				}//end g

			}//end e
		}//end d



	}//end function



// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
     ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");

  document.cookie = curCookie;

}
// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist

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));
}
function argItems () {
if (argItems.arguments[0]==null||argItems.arguments[0]==""){
r=location.search.slice(1);
}else{
theArgName=argItems.arguments[0];
	sArgs = location.search.slice(1).split('&');
	r = '';
	for (var i = 0; i < sArgs.length; i++) {
		theVal = sArgs[i].split('=');
		if(theVal[0]== theArgName){
			r=theVal[1];
	        }
	    }
}
	return (r.length > 0 ? unescape(r) : '')
}

function expandAll(){
var allTabs=document.getElementsByTagName('TABLE');
	for (i=0;i<allTabs.length;i++){
		if (allTabs.item(i).className=="collapsed"){
			allTabs.item(i).className = "shownItems";
		}
	}
}
function collapseAll(){
var allTabs=document.getElementsByTagName('TABLE');
	for (i=0;i<allTabs.length;i++){
		if (allTabs.item(i).className=="shownItems"){
			allTabs.item(i).className = "collapsed";
		}
	}
}
function selectTable(table){
	if (table == "ALL"){
		expandAll();
	}else{
		collapseAll();		
		mOnClick(table);
	}
}


//this function is used by FAQs etc...
//For convenience, multiple arguments can be passed eg. answer('Answer1', 'Answer2',...)

var expanded="expanded";
var collapsed="collapsed";

function answer(){
//Cycle through the TD IDs and collapse ALL expanded
var allTds=document.getElementsByTagName('TD');
var idName="";
	for (i=0;i<allTds.length;i++){
		if (allTds.item(i).className==expanded){
			allTds.item(i).className = collapsed;
		}
	}
//Now expand the one(s) we asked for..

	for(i=0;i<answer.arguments.length;i++){
		idName=answer.arguments[i];
		document.getElementById(idName).className=expanded;
	}
}//End function

var disc=null;
function showDisclaimer(disclaimer){
var x = 0, y = 0; // default values

	if (document.all) {
	  x = window.screenLeft;
	  y = window.screenTop;
	}else{
		 if (document.layers) {
	 	   x = window.screenX;
		   y = window.screenY;
		}
	}
	if (disc && disc.open && !disc.closed){
		disc.focus();
	}else{
		x+=180;
		y+=150;
		disc=window.open(disclaimer,'','HEIGHT=250,WIDTH=430,status=no,resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no,top='+y+',screenY='+y+',left='+x+',screenX='+x);
		disc.focus();
	}
}

// End -->
		
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
var ur=null;
var urlvar= "";
function userReg(){
var x = 0, y = 0; // default values
if (userReg.arguments[0]==null||userReg.arguments[0]==""){
	urlvar = "../registration_form.htm";
}else{
	urlvar = userReg.arguments[0];
}
if (document.all) {
  x = window.screenLeft;
  y = window.screenTop;
}
else if (document.layers) {
  x = window.screenX;
  y = window.screenY;
}
if (ur && ur.open && !ur.closed){
	ur.focus();
}else{
	ur=window.open(urlvar,'','width=500,height=550,status=no,resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no,top='+y+',screenY='+y+',left='+x+',screenX='+x);
	ur.focus();
}
}


var ea=null;
function emailAlert(reg){
var x = 0, y = 0; // default values

if (document.all) {
  x = window.screenLeft;
  y = window.screenTop;
}else{
	 if (document.layers) {
	  x = window.screenX;
	  y = window.screenY;
	}
}
if (ea && ea.open && !ea.closed){
	ea.focus();
}else{
	ea=window.open(reg,'','width=500,height=400,status=no,resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no,top='+y+',screenY='+y+',left='+x+',screenX='+x);
	ea.focus();
}
}

// Previous link
function prev_page() {
	if (history.length > 0)
	{history.back()}
} 

// Terms and conditions
var Issued = "© 2002 Issued in the UK by HSBC Asset Management (Hong Kong) Limited. Regulated by the Financial Services Authority."



var selVisibility="visible";
var selDisplay="block";


function makeBabies(withMe){
//alert("making babies with " + withMe);
	var does_exist = true;
	var baby_val = 0;
	var my_baby = "";

	//Now we must open the immediate offspring of this selection.
	while(does_exist){
		baby_val++;
		my_baby = withMe + "." + baby_val;
		if (!document.getElementById(my_baby) || document.getElementById(my_baby)==null||document.getElementById(my_baby)=="undefined"){
			does_exist=false;
		}else{
			document.getElementById(my_baby).style.visibility=selVisibility;
			document.getElementById(my_baby).style.display=selDisplay;
		}
	}

}

function informBrothers(myBruvva){
//alert("informing brothers of " + myBruvva);
	var does_exist = true;
	var bruvva_val = 0;
	var my_bruvva = "";

	//Now we must open the brothers of this selection
	while(does_exist){
		bruvva_val++;
		my_bruvva = myBruvva + "." + bruvva_val;
		if (!document.getElementById(my_bruvva) || document.getElementById(my_bruvva)==null||document.getElementById(my_bruvva)=="undefined"){
			does_exist=false;
		}else{
			document.getElementById(my_bruvva).style.visibility=selVisibility;
			document.getElementById(my_bruvva).style.display=selDisplay;
		}
	}

}

function showLayer(myLayer,myLayers,myArea){

// alert("showLayer " + myLayer + " " + myLayers + " " + myArea);


	var myAreaRef = myArea;
	var mySwitch = 'off';
	if (myLayer == 1){
		mySwitch = 'on';
		
	}
	switchLayer(myAreaRef,mySwitch);
	
	var i = 1;
	while (i < myLayers ){
		// alert(myLayer);
		mySwitch = 'off';
		myAreaRef = myArea + i;
		if (i == (myLayer - 1)){
			mySwitch = 'on';
		
		}
		switchLayer(myAreaRef,mySwitch);
		
		i++;
	}
	
	
}

function switchLayer(myAreaRef,mySwitch){

// alert("myAreaRef: " + myAreaRef + "mySwitch " + mySwitch);

if (mySwitch == "on"){

	// alert("on");
	document.getElementById(myAreaRef).style.visibility="visible";
	document.getElementById(myAreaRef).style.display="block";

}
else
{
	// alert("off");
	document.getElementById(myAreaRef).style.visibility="hidden";
	document.getElementById(myAreaRef).style.display="none";
}
	
}

function transitionWindow(url){

	// alert(url);
	
	window.open(url,"def","Height=300,width=400");
	
}



function editWindow(url){

	// alert(url);
	
	//window.open(url,"def","Height=600,width=600");
	window.location=url;
	
}

var dm = new Array()
dm['HSBC Monthly Income Inc'] = ['HSBC Monthly Income Inc', 'MDMI']
dm['HSBC Income Inc'] = ['HSBC Income Inc','CPINC']
dm['HSBC UK Growth & Income Inc']  = ['HSBC UK Growth & Income Inc', 'CPUKII'] 
dm['HSBC Balanced Inc']  = ['HSBC Balanced Inc', 'MDBAL']
dm['HSBC Corporate Bond Inc']  = ['HSBC Corporate Bond Inc','MDCRP']
dm['HSBC Gilt & Fixed Interest Inc']  = ['HSBC Gilt & Fixed Interest Inc','MDGFI']
dm['HSBC Household Names Inc']  = ['HSBC Household Names Inc','MDHSE']
dm['HSBC British Inc']  = ['HSBC British Inc','MDBT']
dm['HSBC UK Growth Inc']  = ['HSBC UK Growth Inc','CPCAP']
dm['HSBC UK Smaller Companies Inc']  = ['HSBC UK Smaller Companies Inc','CPUKSM']
dm['HSBC American Growth Inc']  = ['HSBC American Growth Inc','CPNA']
dm['HSBC Asian Inc']  = ['HSBC Asian Inc','CPFESS']
dm['HSBC European Growth Inc']  = ['HSBC European Growth Inc','CPESS']
dm['HSBC Hong Kong Growth Inc']  = ['HSBC Hong Kong Growth Inc','WAHK']
dm['HSBC Japan Growth Inc']  = ['HSBC Japan Growth Inc','WAJG']
dm['HSBC Japanese Smaller Companies Inc']  = ['HSBC Japanese Smaller Companies Inc','WAJSC']
dm['HSBC FTSE 100 Index Fund Inc']  = ['HSBC FTSE 100 Index Fund Inc','MDFTOD']
dm['HSBC FTSE 250 Index Fund Inc']  = ['HSBC FTSE 250 Index Fund Inc','CPFTI']
dm['HSBC FTSE All Share Index Fund Inc']  = ['HSBC FTSE All Share Index Fund Inc','CPUKI']
dm['HSBC American Index Inc']  = ['HSBC American Index Inc','CPAI']
dm['HSBC European Index Inc']  = ['HSBC European Index Inc','CPEI']
dm['HSBC Japan Index Inc']  = ['HSBC Japan Index Inc','CPJI']
dm['HSBC Pacific Index Inc']  = ['HSBC Pacific Index Inc','CPPI']

function openChart(identifier){
var url = "http://webfund5.finexprestel.com/hsbc/ameuchart.wsp?";
var arg1 = "ameuref=true"
var arg2 = "&refCode=" + dm[identifier][1]
var arg3 = "&refName=" + escape(dm[identifier][0])

url = url + arg1 + arg2 + arg3
openWindow(url, 'Chart', 'win_f')
}

function showMe(fund,iType){
	var iUrl = "http://illustration.keydata.tv/servlet/uk.keydata.satellite.HSBCServlet?fund=" + fund + "&wrapper=oeic&type=" + iType;
	openWindow(iUrl,'CSI','win_i');
	}

var multif=null;
function MultiFiles(filename){
	if (multif && multif.open && !multif.closed){
		multif.close();
	}
		multif = window.open(filename,'popup','width=400,height=120,status=yes');
		multif.focus();

}
var cf = null;

function switchCommonContent(winUrl) {

	// alert(application);
	// alert(winUrl);
	var position = winUrl.indexOf("/",23);
	
	//  alert(position);
	// /imuk/generated/pages/imuk/
	// /imi/generated/pages/imi/
	var newLocation = "/" + application + "/generated/pages/" + application + "" + winUrl.substring(position,winUrl.length);
	window.location =  newLocation;
	// alert(newLocation);
	

}

function setJourney(path) {



	setCookie("path",path,null,"/");
	
	// alert("Setting " + path);
	
	
	

}

function showJourneyLHS()

{

	var path = getCookie("path");
	// alert("Now entering " + path);
}





/* this script requires the tacObjects.js script to be available
*  as it calls the array aTacs found there 
*/ 
function redirectMe(){
	tacPage = ""; //variable for the associated TAC page to the current URL
	areaNumber = null ; //declare the area value for the iteration
	var mylocation = document.location.href ; //get the current location
	
	var isQuestionmark = mylocation.indexOf("?"); //is there a questionmark
	cookieName = "TACAgree" ; //Cookie name
	
	if ( isQuestionmark != -1){ // true if the charater ? exists in the URL.Used to remove any request params
		var arrayMyLocation = mylocation.split("?") ;
		mylocation = arrayMyLocation[0] ;
	}
	

	// This if statement excludes the terms and conditions page
	// alert(termsConditionsExclusion);
	
		
	// alert(mylocation);
	if (termsConditionsExclusion.test(mylocation)){
		// alert("break");
		return;
	}	
		
	//loop through the aTacs array looking for matches for the current URL
	for ( var ii = 0 ; ii < aTacs.length ; ii++ ){
		//test if the RexExp variable matches the string mylocation
		if( aTacs[ii].tacRegEx.test( mylocation ) ) {
			tacPage = aTacs[ii].tacPath ;
			areaNumber = ii ;
			//alert("tacPage =" +tacPage) ;
			break ;
		}
	}
	
	//having got the tacPage if one exists, decide whether we need to go there by examining the cookie data
	var tacCookieVal = getCookieValue() ;
	
	//no cookie exists so we send them to the TAC page to have one generated	
	if ( tacCookieVal == "" && tacPage != ( null || "" )){
		var tacPageWithParams ;
		if ( mylocation.indexOf( "generated" )  != -1 ){ //do we need to slice
			// alert("make relative for TeamSite");
			tacPageWithParams = tacPage + "?srcpage=" + mylocation.slice( mylocation.indexOf( "generated" ) ) ;
		}else{
			tacPageWithParams = tacPage + "?srcpage=" + mylocation  ;
		}
		

		// alert("redirectMe()>1> no cookie and a tacPage has been assigned,\ngoing to tacPageWithParams: " + tacPageWithParams) ;
		document.location.href =  tacPageWithParams  ;
	}else{
		//create an array of the areas in the cookie
		var arrayCrumbs = tacCookieVal.split("::") ;
		//alert("redirectMe()>> areaNumber: " + areaNumber + "\n" + "arrayCrumbs.length: " + arrayCrumbs.length + "\n" + "tacPage:" + tacPage );
		
		//check to see whether the area has been accepted
		//sanity check
		if ( areaNumber != null && arrayCrumbs.length > 0 ){
			//if the cookie info is false go to tacPage remembering to add the srcpage parameter
			if ( arrayCrumbs[ areaNumber ] != "true" ){
				var tacPageWithParams = tacPage + "?srcpage=" + mylocation ;
				//alert( "redirectMe()>3> going to: " + tacPageWithParams ) ;
				document.location.href = tacPageWithParams ;
			}else{//if they have already seen the TAC
				//alert("redirectMe()>4> already seen the tac as  arrayCrumbs[ areaNumber ] = " +  arrayCrumbs[ areaNumber ]) ;
			}
		}
	}
	
}//end of redirectMe



/* returns the string value of a cookie and removes the session id
*   if any is present
*/
function getCookieValue() {
//alert("getCookieValue() >> pre-cookie check: " +  document.cookie ) ;
  var search = "TACAgree=" ;
  var returnString = "";
  if (document.cookie.length > 0) {
    var offset = document.cookie.indexOf(search)
    // check to see if cookie exists
    if (offset != -1) { 
      offset += search.length
      //set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value avoiding sessionId
      if (end == -1){
      	end = document.cookie.length;
      } 
      returnString=unescape(document.cookie.substring(offset, end)) ;
    }
  	//alert( "getCookieValue>> returnString is " + returnString );
  	return returnString ;
  }else{ 
  	//alert( "getCookieValue>> cookie length == 0, so returning an empty string");
      return "" ;
  }
}//end of getCookieValue


/* sets the appropriate cookie when the user
*   accepts the T and Cs
*/
function acceptTACs(){
	//set location of referrer page
	var originPage = document.referrer ;
	
	//if document.referrer is empty (MSIE6) use the parameter provided
	if ( originPage == ( null || "" ) ){
		var qString = document.location.search ;
		if ( document.location.href.indexOf( "generated" )  != -1 ){ //do we need to slice
			var firsthalf = document.location.href.split( "generated" )[0] ;
			var aQuerySplit = qString.split("=") ;
			originPage = firsthalf + aQuerySplit[1] ;
			//alert("acceptTACs()>1> originPage: " + originPage ) ;
		}else{
			originPage =  qString.split("=")[1] ;
			//alert("acceptTACs()>2> originPage: " + originPage ) ;
		}
	}//end of MSIE workaround
	
	//loop through the aTacs array looking for matching area to the origin url
	for ( var ii = 0 ; ii < aTacs.length ; ii++ ){
		if( aTacs[ii].tacRegEx.test( originPage ) ) {
			tacPage = aTacs[ii].tacPath ;
			areaNumber = ii ;
			break ;
		}
	}

	//get Cookie
	var strNewCookieVal = getCookieValue() ;
	//create an array of the areas in the cookie
	var arrayNewCrumbs = strNewCookieVal.split("::") ;
	var strUpdatedCrumbs = "" ;
	//now loop through and set this area to true leaving the others alone if they are undefined
	for ( var ii = 0 ; ii < aTacs.length ; ii++ ){
	    if ( ii != areaNumber ){
	    	//not our area so leave alone but correct undefined/null errors
	    	if ( arrayNewCrumbs[ii] == ( "true" || "false" ) ){
	    		strUpdatedCrumbs += arrayNewCrumbs[ii] ;
		}else{
			strUpdatedCrumbs += "false" ;
		}  	
	    }else{
	    	strUpdatedCrumbs += "true" ;
	    }
	    //alert("acceptTACs()>> aTacs.length " + (aTacs.length-1) + "\n" + "ii " + ii ) ;
	    //append 
	    if ( ii < ( aTacs.length-1 ) ){
	        strUpdatedCrumbs += "::" ;	
	    } 
	}
	//set cookie and return to the refering page
	var finalCookieString = "TACAgree=" +  escape( strUpdatedCrumbs ) + "; path=/;"  ;
	document.cookie = finalCookieString ;
	document.location.href = originPage ;
}//end of acceptTACs



// End -->




	