//Pre services T&C's
//var termsConditionsExclusion= new RegExp(/Terms_Conditions|pages\/home|\/disclaimer|site\/microsites\/t_and_c/);
//var intermediariesTac = "/site/microsites/t_and_c/tac_" ;
//aTacs = [ 	new tac( new RegExp(/fund_centre/) , intermediariesTac )  ] ;


//services T&C's (used in function redirectMe()
var termsConditionsExclusion= new RegExp(/Terms_Conditions|pages\/home|\/disclaimer|site\/microsites\/t_and_c/);
var destTacHost;
var bounceURL;
var fundcentreTac;
 // the RegExp variable "tacTegEx" is a string-ish type but with certain differences,
 // the variable is not quoted(' or ") and is surrounded by a forward 
 // slash (e.g./matcher/). Forward slashes (/) and other special characters used
 // by regular expressions should be escaped by adding a back slash (so / is \/)
 // in the variable, as shown below
 
// select siteTac based on hostname
switch (location.hostname) {
	case "services.assetmanagement.hsbc.co.in":
		bounceURL = "http://www.assetmanagement.hsbc.com/in/mutual-funds/fund-centre/tnc.html?tnc=";
		destTacHost = "?returnurl=" + location.protocol + "//" + location.host;			
		fundcentreTac = bounceURL + "inCommonFC" + destTacHost + "/site/microsites/t_and_c/tac_services-en.html";
		break;
		
	case "assetmanagement-uatin.hibm.hsbc":
		bounceURL = "http://qa.assetmanagement.hsbc.btctest.com/in/mutual-funds/fund-centre/tnc.html?tnc=";
		destTacHost = "?returnurl=" + location.protocol + "//" + location.host;			
		fundcentreTac = bounceURL + "inCommonFCQA" + destTacHost + "/site/microsites/t_and_c/tac_services-en.html";
		break;
		
	default:
		bounceURL = "http://amiplt01d.uk.hibm.hsbc:7161/bounceback.htm?returnurl=";
		destTacHost = location.protocol + "//" + location.host;		
		fundcentreTac = bounceURL + destTacHost + "/site/microsites/t_and_c/tac_services-en.html";
		break;
}
aTacs = [ 	new tac( new RegExp(/mutual_fund_centre/) , fundcentreTac )  ] ;
//end services vars


//end Services t&cs

function ValiDate(obj, min, max, format){
	
	if (typeof(obj) == "object")
	  dateBits = DateComponents(obj.value, format);
	else
	  dateBits = DateComponents(obj, format);
	  
	if (dateBits == null) return false;

	//Check it is a valid date first
	day = dateBits[0];
	month = dateBits[1];
	year = dateBits[2];

	if ((month < 1 || month > 12) || (day < 1 || day > 31)) { // check month range 
		return false;
	} 
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		return false;
	}
	if (month == 2) {
	// check for february 29th 
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); 
		if (day>29 || (day==29 && !isleap)) {
			return false;
		}
	} 

	//Now check whether a range is specified and if in bounds
	//Modified by AJH 27/5/2002. Change all parseInt's to parseFloat as it was treating
	// numbers with leading zeroes as octal numbers!!!
	var theDate = new Date(dateBits[2], parseFloat(dateBits[1]) - 1, dateBits[0]);

	if ( min ) {
		minBits = DateComponents (min, format);
		var minDate = new Date(minBits[2], parseFloat(minBits[1]) - 1, minBits[0]);
		if ( minDate.getTime() > theDate.getTime() ) return false;
	} 
	if ( max) {
		maxBits = DateComponents (max, format);
		var maxDate = new Date(maxBits[2], parseFloat(maxBits[1]) - 1, maxBits[0]);
		if ( theDate.getTime() > maxDate.getTime() ) return false;
	}
	return true;
}
function DateComponents(dateStr, format) {
	var results = new Array();
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var matchArray = dateStr.match(datePat);
	
	if (matchArray == null) { 
		return null; 
	}
	// parse date into variables
	if (format.charAt(0)=="d"){ //what format does the server use for dates? 
		results[0] = matchArray[1];
		results[1] = matchArray[3];
	} else { 
		results[1] = matchArray[1];
		results[0] = matchArray[3]; }
	results[2] = matchArray[4];
	return results;
}
function getUKDateComp(sComp, sDate)
{
  var nFirstSlash = sDate.indexOf("/");
  var nSecondSlash = sDate.indexOf("/", nFirstSlash+1);
  var days = sDate.slice(0, nFirstSlash);
  var month = sDate.slice(nFirstSlash + 1, nSecondSlash);
  var year = sDate.slice(nSecondSlash + 1);
  var ret;
  switch(sComp)
  {
    case "d":
      ret = days;
      break;
    
    case "m":
      ret = month;
      break;
    
    case "y":
      ret = year;
      break;
  }
  return ret;
}
function LTrim(strIn) //added to this script library by MW (12/03/2003)
{
//Adrian Holdsworth 06/02/2002
//recursively call self until all leading whitespace is removed
	if (strIn == "" || strIn == null || strIn == "undefined")
		return strIn;
	if (strIn.charCodeAt(0) == 32 || strIn.charCodeAt(0) == 10 || strIn.charCodeAt(0) == 13)
		return LTrim(strIn.slice(1));
	else
		return strIn;
}

function getCookieValue(sIn)
{ 
  var s = document.cookie;
  asCookie = s.split(";");
  for (var i = 0; i<asCookie.length;i++)
  {
	  if (LTrim(asCookie[i].split("=")[0].toLowerCase()) == LTrim(sIn))
	  {
		  return (asCookie[i].split("=")[1]);
	  }
	}
  return "";
}
function onFundNameSelect(obIn)
{
	return true;
}
function onFundGroupSelect(obIn)
{
	return true;
}
function gotoAnchor(obVar)
{
    var sDiv = sCurrentImgId.slice((sCurrentImgId.indexOf("_")+1));
    location.href= "#" + sDiv + obVar.value;
    
}


function Window(winUrl, winName, properties) {
switch (properties) {
    case "win_b":
	newwindow = window.open();
        newwindow.moveTo(0,0);
        newwindow.resizeTo(screen.availWidth,screen.availHeight);
     	newwindow.location = winUrl;
        newwindow.focus();
 	break

    default:
        newWindow = window.open(winUrl,winName,properties);
        newWindow.focus();
    }
}

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_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_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.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];}
}
function openWindowHandle(sURL,sWinName,sFeatures)
{
	//adrian holdsworth 18/03/2003
	//open window and keep global handle to this
	//declare variable without var keyword so it has global scope. Not nice, but keeps variable in function
	//declaration
	hwnd = window.open(sURL,sWinName,sFeatures);
}
function openWindowHandle_callback()
{
	//adrian holdsworth 18/03/2003
	//allow another window to callback to the opener and make it shut the childe (the caller)
	hwnd.close();
}
function redirectTo(sIn)
{
	//adrian holdsworth 18/03/2003
	self.location.href = sIn;
}
function hideLayer(sIn) 
{
  //do the iframes price/perf charts
    var ob = top.document.getElementById("chart");
    if (ob!= null)
    {
      var inob = ob.Document.getElementById(sIn);
      if (inob != null)
      {
        inob.style.visibility= "hidden"
        inob.style.display= "none"
      }
    }
    var bDoneOne = false;
    if (sIn != "ch" && sIn != "en")
    {    
	if(document.getElementById(sIn))
	    {
	    	if (document.getElementById(sIn).style)
	        {
	        	document.getElementById(sIn).style.visibility = "hidden";
		        document.getElementById(sIn).style.display = "none";
	        	bDone = true;
	       	}
	    }
    }
    else
    //the following line is a stop gap until Jas gets around to changing all the id's and class names
    //all the hide/when could then be done by one call to showLayer("ch") and one call to hideLayer("en")
    {
        var coll = document.getElementsByTagName("*");
        if (coll.length == 0)       //we are probably detecting an ie client
          coll = document.all;
        for (var i =0;i<coll.length-1;i++)
        {
          var item = coll.item(i);
          
    	    if (item.className.toLowerCase() == sIn.toLowerCase() || item.id.toLowerCase() == sIn.toLowerCase())
            {
            	item.style.visibility = "hidden";
              item.style.display = "none";
	            bDoneOne = true;
            }
        }
        
    }
    return bDoneOne;

}

function showLayer(sIn)
{
    //do the iframes price/perf charts
    var ob = top.document.getElementById("chart");
    if (ob!= null)
    {
      var inob = ob.Document.getElementById(sIn);
      if (inob != null)
      {
        inob.style.visibility= ""
        inob.style.display= ""
      }
    }
    var bDoneOne = false;
    if (sIn != "ch" && sIn != "en")
    {
	    if(document.getElementById(sIn))
    	{
    		if (document.getElementById(sIn).style)
    		{
       	    	 	document.getElementById(sIn).style.visibility = "";
        		document.getElementById(sIn).style.display = "";
        		bDone = true;
       		}
    	}
    }
    else
    //the following line is a stop gap until Jas gets around to changing all the id's and class names
    //all the hide/when could then be done by one call to showLayer("ch") and one call to hideLayer("en")
    {
    	   var coll = document.getElementsByTagName("*");
    	    if (coll.length == 0)       //we are probably detecting an ie client
            coll = document.all;
         for (var i =0;i<coll.length-1;i++)
         {
            var item = coll.item(i);
    	      if (item.className == sIn ||item.id == sIn)
            {
    	          item.style.visibility = "";
                item.style.display = "";
                bDoneOne =  true;
            }
        }
       
       var sOldToken = "";
        if (sIn == "en")
          sOldToken = "_ch";
        else
          sOldToken = "_en";
        var sReplaceToken = "_" + sIn
        //document.getElementById("img_prc").src = document.getElementById("img_prc").src.replace(sOldToken, sReplaceToken);
        //document.getElementById("img_per").src = document.getElementById("img_per").src.replace(sOldToken, sReplaceToken);
        //document.getElementById("img_aids").src = document.getElementById("img_aids").src.replace(sOldToken, sReplaceToken);
        //document.getElementById("img_fct").src = document.getElementById("img_fct").src.replace(sOldToken, sReplaceToken);
        
        //document.getElementById("img_prc_ch").src = document.getElementById("img_prc_ch").src.replace(sOldToken, sReplaceToken);
        //document.getElementById("img_per_ch").src = document.getElementById("img_per_ch").src.replace(sOldToken, sReplaceToken);
        //document.getElementById("img_aids_ch").src = document.getElementById("img_aids_ch").src.replace(sOldToken, sReplaceToken);
        //document.getElementById("img_fct_ch").src = document.getElementById("img_fct_ch").src.replace(sOldToken, sReplaceToken);
        
    }
    return bDoneOne;
}
function UKDateToXML(sIn)
{
    //adrian holdsworth 23/5/2003
    //convert uk date (dd/mm/yyyy) to xml date yyyy-mm-ddThh:mm:ss.
        
    //test if the date has the day omitted and if so default to the first
    var iFirstSlash = sIn.indexOf("/");
    var iSecondSlash = sIn.indexOf("/", iFirstSlash + 1);
    
    if (iSecondSlash == -1)
      sIn = "1/" + sIn;
    
    var asDate = sIn.split("/");

    var sDay = asDate[0];
    var sMonth = asDate[1];
    var sYear = asDate[2];
    
    if (sDay != null)
    	if (sDay.length == 1)
    	    sDay = "0" + sDay;
        
    if (sMonth != null)
    	if (sMonth.length == 1)
    	    sMonth = "0" + sMonth;
    
    if (sYear != null)
    {
    	if (sYear.length == 2 && parseFloat(sYear) < 70)
	        sYear = "20" + sYear;
    	if (sYear.length == 2 && parseFloat(sYear) > 70)
        	sYear = "19" + sYear;
    }
    return sYear + "-" + sMonth + "-" + sDay + "T00:00:00";
}
function UKDateToXMLEnd(sIn)
{
    //adrian holdsworth 23/5/2003
    //convert uk date (dd/mm/yyyy) to xml date yyyy-mm-ddThh:mm:ss.
        
    //test if the date has the day omitted and if so default to the first
    var iFirstSlash = sIn.indexOf("/");
    var iSecondSlash = sIn.indexOf("/", iFirstSlash + 1);
    
    if (iSecondSlash == -1)
      sIn = "days/" + sIn;
    
    var asDate = sIn.split("/");

    var sDay = asDate[0];
    var sMonth = asDate[1];
    var sYear = asDate[2];
    
    var sReplaceWithThis = "";
  
    switch (sMonth)
    {
      case "9":
      case "09":
      case "4":
      case "04":
      case "6":
      case "06":
      case "11":
        sReplaceWithThis = "30"; 
        break;
      case "1":
      case "01":
      case "3":
      case "03":
      case "5":
      case "05":
      case "7":
      case "07":
      case "8":
      case "08":
      case "10":
      case "12":
        sReplaceWithThis = "31"; 
        break;
      case "2":
      case "02":
        if(sYear % 4 == 0) 
          sReplaceWithThis = "29"; 
        else
          sReplaceWithThis = "28"; 
        break;
    }    
    sDay = sDay.replace(/days/g, sReplaceWithThis);
    
    
    if (sDay != null)
    	if (sDay.length == 1)
    	    sDay = "0" + sDay;
        
    if (sMonth != null)
    	if (sMonth.length == 1)
    	    sMonth = "0" + sMonth;
    
    if (sYear != null)
    {
    	if (sYear.length == 2 && parseFloat(sYear) < 70)
	        sYear = "20" + sYear;
    	if (sYear.length == 2 && parseFloat(sYear) > 70)
        	sYear = "19" + sYear;
    }
    return sYear + "-" + sMonth + "-" + sDay + "T00:00:00";
}

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]+"'");
}

function getArgs() {
	var args = new Object();
	var query = location.search.substring(1);
	var pairs = query.split("&");
	for (var i=0; i<pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		args[argname] = unescape(value);		
	}
	return args;
}


function jumpTo(obVar)
{
    location.href= "#" + obVar.value;    
}

// Rotating Banner Functions
function getItem (asIn, iIndex)
{
  var sRet ="";
  for (foo=0;foo<asIn.length;foo++)
  {
    if (asIn[foo]!="") //incase of trailing ";"
    {
      asLine = asIn[foo].split("|");
      sRet = sRet +  asLine[iIndex] + "^"  
    }
  }
  if (sRet.slice(sRet.length-1)=="^")
    sRet = sRet.slice(0, sRet.length-1);
  return sRet;
}
function getImages (asIn, iIndex)
{
  var asRet = new Array();
  for (foo=0;foo<asIn.length;foo++)
  {
    if (asIn[foo]!="") //incase of trailing ";"
    {
      asLine = asIn[foo].split("|");
      asRet[foo] = new Image();
      asRet[foo].src = asLine[iIndex];
    }
  }
  return asRet;
} 

function cycleAdsEn_1(bID)
{  
  if (eval("++gAdCtrEn"+bID) == eval("adImagesEn"+bID+".length"))
  {
    eval("gAdCtrEn"+bID+"=0");
  }
  if (eval("adImagesEn"+bID+"[gAdCtrEn"+bID+"]")!=null)
  {
  	
    eval('document.getElementById("adBannerEn'+bID+'").src = adImagesEn'+bID+'[gAdCtrEn'+bID+'].src');
    eval('document.getElementById("adBannerEn'+bID+'").alt = adAltEn'+bID+'[gAdCtrEn'+bID+']');  
    var iTime = parseInt(eval("adDelayEn"+bID+"[gAdCtrEn"+bID+"]"))*1000;
         
    if (isNaN(iTime)) {
      //no calling timeout please
      //hideAll();
    } else {
      setTimeout("cycleAdsEn_2('"+bID+"')", iTime);
    }
  }
  else
  {
    eval('document.getElementById("hrefEn'+bID+'").style.visibility = "hidden"');
    eval('document.getElementById("hrefEn'+bID+'").style.display = "none"');
  }
}

function cycleAdsEn_2(bID)
{  
  if (eval("++gAdCtrEn"+bID) == eval("adImagesEn"+bID+".length"))
  {
    eval("gAdCtrEn"+bID+"=0");
  }
  if (eval("adImagesEn"+bID+"[gAdCtrEn"+bID+"]")!=null)
  {
  	
    eval('document.getElementById("adBannerEn'+bID+'").src = adImagesEn'+bID+'[gAdCtrEn'+bID+'].src');
    eval('document.getElementById("adBannerEn'+bID+'").alt = adAltEn'+bID+'[gAdCtrEn'+bID+']');  
    var iTime = parseInt(eval("adDelayEn"+bID+"[gAdCtrEn"+bID+"]"))*1000;
         
    if (isNaN(iTime))
      //no calling timeout please
      hideAll();
    else {
      setTimeout("cycleAdsEn_2('"+bID+"')", iTime);
    }
  }
  else
  {
    eval('document.getElementById("hrefEn'+bID+'").style.visibility = "hidden"');
    eval('document.getElementById("hrefEn'+bID+'").style.display = "none"');
  }
}

function gotoAdEn(bID)
{
	if (eval("adTargetEn"+bID+"[gAdCtrEn"+bID+"]") == "aic") {
    		openWindow(eval("adURLEn"+bID+"[gAdCtrEn"+bID+"]"), eval("adTargetEn"+bID+"[gAdCtrEn"+bID+"]"), 'width=780,height=630,directories=no,location=no,menubar=no,scrollbars=yes,status=no,resizable=yes,toolbar=no') ;		    	
    	} else {
    		openWindow(eval("adURLEn"+bID+"[gAdCtrEn"+bID+"]"), eval("adTargetEn"+bID+"[gAdCtrEn"+bID+"]"), "win_a") ;
	}
}


function initBanner(bID)
{
	eval("count"+bID+"=document.frm_banner"+bID+".alt.length");
	eval('banner_config'+bID+' = "";');
	eval('gAdCtrEn'+bID+'=-1');
}

function setBanner(bID)
{
	
	if (eval("count"+bID+">1")) {
		for (var i=0; i<eval("count"+bID); i++) {
			var alt_val = eval("document.frm_banner"+bID+".alt["+i+"].value");
			var url_val = eval("document.frm_banner"+bID+".url["+i+"].value");
			var gif_val = eval("document.frm_banner"+bID+".gif["+i+"].value");
			var delay_val = eval("document.frm_banner"+bID+".delay["+i+"].value");
			var target_val = eval("document.frm_banner"+bID+".target["+i+"].value");	
			eval('banner_config'+bID+' += alt_val+"|"+url_val+"|"+gif_val+"|"+delay_val+"|"+target_val+";"');
		} 
	} else {
		var alt_val = eval("document.frm_banner"+bID+".alt.value");
		var url_val = eval("document.frm_banner"+bID+".url.value");
		var gif_val = eval("document.frm_banner"+bID+".gif.value");
		var delay_val = eval("document.frm_banner"+bID+".delay.value");
		var target_val = eval("document.frm_banner"+bID+".target.value");		
		eval('banner_config'+bID+' += alt_val+"|"+url_val+"|"+gif_val+"|"+delay_val+"|"+target_val+";"');
	}	
		
	eval('var rotatingBanner'+bID+' = banner_config'+bID+'.split(";")');
	eval('adAltEn'+bID+' = getItem(rotatingBanner'+bID+', 0).split("^")');
	eval('adURLEn'+bID+' = getItem(rotatingBanner'+bID+', 1).split("^")');			 
	eval('adImagesEn'+bID+' = getImages(rotatingBanner'+bID+', 2)');
	eval('adDelayEn'+bID+' = getItem(rotatingBanner'+bID+', 3).split("^")');				 
	eval('adTargetEn'+bID+' = getItem(rotatingBanner'+bID+', 4).split("^")');				 	
}	

function writeBanner(bID)
{
	document.write('<div class="component_36_link_banner">');
	document.write('<a id="hrefEn'+bID+'" href="javascript:gotoAdEn(\''+bID+'\')">');
	document.write('<img id="adBannerEn'+bID+'" name="adBannerEn'+bID+'" src="/amhk/media/images/banners/space.gif" width="152" height="100" border="0" alt="">');
	document.write('</a>');
	document.write('</div>');	
}

function startBanner(mode, bID)
{
	if (mode.toLowerCase() == "on") {
		writeBanner(bID)
		initBanner(bID);
		setBanner(bID);
		cycleAdsEn_1(bID);
	}	
}	

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) : '')
}

// Used for selecting window size
function openWindow1(winUrl, winName, properties) {

switch (properties) {

    case "win_a":
   newWindow = window.open(winUrl,winName,"HEIGHT=200,WIDTH=420,TOP=10,LEFT=10");
        newWindow.focus();
   break

    default:
        newWindow = window.open(winUrl,winName,properties);
        newWindow.focus();
    }
}  


//Closes the current window
function  closeWindow1(){
  window.close();
}

function addToFav(who){
	var ver = navigator.appName
	var num = parseInt(navigator.appVersion)
	var url = "http://www.hsbcinvestments.co.uk";
	var who = "HSBC Investments (India) Private Limited";
	
	if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) {
		window.external.AddFavorite(url,who);
	}else{
		alert("To bookmark this site press CTRL+D");
	}
}

function forwardToFriend() {
	var selfURL = window.location;
	var selfTitle = "HSBC Investments (India) Private Limited";

	// SET MESSAGE VALUES
	var to = "";
	var cc = " ";
	var bcc = "";
	var body = "I think you'll be interested in the following website of HSBC Investments:\n" + selfURL;

	// BUILD MAIL MESSAGE COMPONENTS
	var doc = "mailto:" + to +
		"?&cc=" + cc +
		"&bcc=" + bcc +
		"&subject=" + escape(selfTitle) +
		"&body=" + escape(body);

	// POP UP EMAIL MESSAGE WINDOW
	window.location = doc;
}

//Pre services redirectMe() function
///* this script requires the tacObjects.js script to be available
//*  as it calls the array aTacs found there 
//*/ 
//function redirectMe(){
//	var bodyTag = document.getElementsByTagName("body")[0]
//	var html_lang = document.getElementsByTagName("html").item(0).getAttribute("lang") ;
//	//alert("site/content/javascript/redirectMe: html_lang - " + html_lang ) ;
//	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
//	var isDirected = mylocation.indexOf("?srcpage=");
//	cookieName = "TACAgree" ; //Cookie name
//	if ( isQuestionmark != -1 && isDirected == -1){ // true if the charater ? exists in the URL.Used to remove any request params
//		var arrayMyLocation = mylocation.split("?") ;
//		mylocation = arrayMyLocation[0] ;
//		if (mylocation.length > 1) {
//			mylocation = mylocation + "&" +  arrayMyLocation[1];
//		}
//	}
//	
//
//	// This if statement excludes the terms and conditions page
//	// alert(termsConditionsExclusion);
//	
//		
//	// alert(mylocation);
//	if (termsConditionsExclusion.test(mylocation)){
//		// alert("break");
//		bodyTag.style.visibility = 'visible' ;
//		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 + html_lang +".html?srcpage=" + mylocation.slice( mylocation.indexOf( "generated" ) ) ;
//		}else{
//			tacPageWithParams = tacPage + html_lang +".html?srcpage=" + mylocation  ;
//		}
//		// alert("redirectMe()>1> no cookie and a tacPage has been assigned,\ngoing to tacPageWithParams: " + tacPageWithParams) ;
//		//bodyTag.style.visibility = 'hidden' ;
//		document.location.href =  tacPageWithParams  ;
//	}else{
//		//create an array of the areas in the cookie
//		var arrayCrumbs = tacCookieVal.split("::") ;
//		//check to see whether the area has been accepted
//		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 + html_lang +".html?srcpage=" + mylocation ;
//				//alert( "redirectMe()>3> going to: " + tacPageWithParams ) ;
//				//bodyTag.style.visibility = 'hidden' ;
//				document.location.href = tacPageWithParams ;
//			}else{//if they have already seen the TAC
//				bodyTag.style.visibility = 'visible' ;
//				//alert("alright") ;
//				return ;
//				//alert("redirectMe()>4> already seen the tac as  arrayCrumbs[ areaNumber ] = " +  arrayCrumbs[ areaNumber ]) ;
//			}
//		}else{
//			bodyTag.style.visibility = 'visible' ;
//		}
//	}
//}//end of redirectMe
//Services redirectMe()
/* this script requires the array aTacs.services version
*/ 
function redirectMe(){
	
	var bodyTag = document.getElementsByTagName("body")[0] ;
	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
	cookieName = "TACAgree" ; //Cookie name

	// This if statement excludes the terms and conditions page
	if (termsConditionsExclusion.test(mylocation)){
		//alert("break due to exclusions list");
		bodyTag.style.visibility = 'visible' ;
		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 ;
			break ;
		}
	}
	
	//having got the tacPage if one exists, decide whether we need to go there by examining the cookie data
	var tacCookieVal = getCookieValue() ;
	var strTeamSiteSplit = "iw-mount" ;
	
	//no cookie exists so we send them to the TAC page to have one generated	
	if ( tacCookieVal == "" && tacPage != ( null || "" )){
		
		var tacPageWithParams ;
		if ( mylocation.indexOf( strTeamSiteSplit )  != -1 ){ //do we need to allow for Teamsite
			// alert("make relative for TeamSite");
			tacPageWithParams = tacPage + "?srcpage=" + escape( mylocation.slice( mylocation.indexOf( strTeamSiteSplit ) ) ) ;
		}else{
			tacPageWithParams = tacPage + "?srcpage=" + escape( mylocation ) ;
		}
		document.location.href =  tacPageWithParams  ;
		return
	}else{
		//create an array of the areas in the cookie
		var arrayCrumbs = tacCookieVal.split("::") ;
		//check to see whether the area has been accepted
		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=" + escape( mylocation ) ;
				document.location.href = tacPageWithParams ;
				return ;
			}else{//if they have already seen the TAC
				bodyTag.style.visibility = 'visible' ;
				return ;
			}
		}else{
			bodyTag.style.visibility = 'visible' ;
		}
	}
}//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 query = "";
//		var args = getArgs();
//		var srcpage = args.srcpage;
//		for (sValue in args) {
//			if (sValue != "srcpage") {
//				if (query == "") {
//					query = "?" + sValue + "=" + args[sValue];
//				} else {
//					query = query + "&" + sValue + "=" + args[sValue];					
//				}			
//			}			
//		}
//		originPage = srcpage + query;
//	//}//end of MSIE workaround

	var splitString = "site" ; 
	var currentLoc = document.location.href ;
	var splitIndex = currentLoc.indexOf("/", 9 ) ;
	var currentWebApp = currentLoc.substring(0, splitIndex) ;
	var paramLoc = document.location.search.substring(document.location.search.indexOf('='));
	var startIndex = 15 ;
	var splitIndexParam = paramLoc.indexOf("/", startIndex ) ;
	var paramPage = unescape( paramLoc.substring(splitIndexParam) ) ;	
	var originPage = currentWebApp + paramPage ;

	
	//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" ;
	    }
	    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

function tac ( tacRegEx , tacPath ){
	this.tacRegEx =  tacRegEx  ;
	this.tacPath = tacPath ;
}


/* private method to get the href of of the a tag in the div*/
function getMyHref( pDivToHref ){
	var as = pDivToHref.getElementsByTagName('a') ;
	var ahref = as.item(0).getAttribute("href") ;
	
	// old code replaced by code to remove params from the url
	//return  ahref.split("site")[1]; 
	var fullurl = "";
	var returnurl = "";
	if (ahref.indexOf("site") >= 0){
	   fullurl =  ahref.split("site")[1];	
	   returnurl = fullurl.split("?")[0] ;
	}
	return returnurl;
}
