/* header navigation */
var scrollerwidth="450px"
var scrollerheight="100px"
var scrollerspeed=1
var pauseit=1
scrollerspeed=(document.all)? scrollerspeed : Math.max(1, scrollerspeed-1) //slow speed down by 1 for NS
var copyspeed=scrollerspeed
var iedom=document.all||document.getElementById
var actualheight=''
var cross_scroller, ns_scroller
var pausespeed=(pauseit==0)? copyspeed: 0
var lefttime;

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.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 cookieExists(ck){
	var cookies = document.cookie;
	var	re = new RegExp(ck+"=\\w+");
	return re.test(cookies);
}

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function SetOVTabMonthlyCookie(cookieDomain)
{
    SetCookie("selected_ov_tab",0+'',"/",cookieDomain);
    return true;
}

function readCookie(nam) {
var tC = document.cookie.split('; ');
for (var i = tC.length - 1; i >= 0; i--) {
var x = tC[i].split('=');
if (nam == x[0]) return unescape(x[1]);}
return null;}


function SetCookie (cookie_name, cookie_value,  cookie_path, cookie_domain, secure) {
	var expires = new Date();
	expires.setTime(expires.getTime() + (24 * 60 * 60 * 1000) * 180 ); // 6 months from now
    var cookieVal = escape (cookie_value);
	document.cookie =  cookie_name + "=" + cookieVal +
    	((expires) ? "; expires=" + expires.toGMTString() : "") +
    	((cookie_path) ? "; path=" + cookie_path : "") +
    	((cookie_domain) ? "; domain=" + cookie_domain : "") +
    	((secure) ? "; secure" : "");
}

/* site menu */
function showLowerTab(topTabId){
	hideAllLowerTabs();
	if(topTabId == gTopTabs[0])
		return;

	var tab = document.getElementById("lower_" + topTabId);
	tab.style.display = "block";

}

function hideAllLowerTabs(){
	for(var i=1; i<gTopTabs.length; i++){
		document.getElementById("lower_" + gTopTabs[i]).style.display = "none";
	}
}

function menuClick(tabId, url){
	if(isTopTab(tabId)){
		if(tabId == gTopTabs[0]){
			window.location = url;
			return;
		}

		var currentClass = document.getElementById(tabId).className;
		if(currentClass == "topTabSelected")
			return;

		var newUrl = gTopTabUrls[tabId];
		window.location = newUrl;
	}else{
		if(tabId == gSelectedLowerTab)
			return;

		window.location = url;
	}
}


function isTopTab(id){
	var re = /^top\d+$/;
	return re.test(id);
}


/* quick logon */
// Handle the enter key for a section of a form, binding it to the provided submit buton
function HandleEnterKey(event) {
	var nav = window.Event ? true : false;
	if (nav) {
		return NetscapeEventHandler_KeyDown(event);
	} else {
		return MicrosoftEventHandler_KeyDown();
	}
}

function NetscapeEventHandler_KeyDown(e) {
    var obj = e.target;
    if ((obj.id == "username" || obj.id == "password" || obj.Id == "imgBtnGo") && e.which == 13) {
		e.returnValue = false;
		e.cancel = true;
		e.preventDefault();
		return OnLoginClicked();
    }
    return true;
}

function MicrosoftEventHandler_KeyDown() {
    var obj = event.srcElement;
    if ((obj.id == "username" || obj.id == "password" || obj.Id == "imgBtnGo") && event.keyCode == 13) {
		event.returnValue = false;
		event.cancel = true;
		return OnLoginClicked();
	}
	return true;
}

if(document.addEventListener) {
	document.addEventListener("keypress", HandleEnterKey, true);
}
else {
	document.attachEvent("onkeypress", HandleEnterKey);
}

function ClearLogin() {
	var qlogin = document.getElementById("QLogin");
	var uname = document.getElementById("username");
	var pwd = document.getElementById("password");
	qlogin.value = "";
	uname.value = "";
	pwd.value = "";
}

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 PrintUserName() {
var dc = document.cookie;
	var user = getCookie("user");
	if (user == null || user.length == 0) return;
	var  namearray = new Array();
	namearray = user.split("|");
	document.write("Welcome " + namearray[0] +"!");
}

// put the functions into sitescript.js
function openMenuPicker(event, lobj) {

  var el, x, y, lef, id;
  //lobj = this.id;
  x = getPageOffsetLeft(lobj);
  y = getPageOffsetTop(lobj) + 13;
  z = getPageOffsetBottom(lobj);
  
  el = document.getElementById('curMenuPicker');
  
  el.style.left = x + "px";
  el.style.top  = y + "px";
  el.style.visibility = "visible";
}

function closeMenuPicker(event) {
  var current, related;
  if (window.event) {
    current = this;
    related = window.event.toElement.value;
  }
  else {
    current = event.currentTarget;
    related = event.relatedTarget;
  }

  if ((window.event.toElement.id != 'curMenuPicker') && (window.event.toElement.parentNode != null) && (window.event.toElement.parentNode.id != 'curMenuPicker'))
  	 curMenuPicker.style.visibility = 'hidden';
  else
  if (current != related && !contains(current, related))
    current.style.visibility = "hidden";
}


function contains(a, b) {

  // Return true if node a contains node b.
  if (b == undefined)
     return true;
     
  while ((b.parentNode != null) )  //&& (b.parentNode)
  {
    if ((b.parentNode != null) && (b = b.parentNode) == a)
      return true;
   }
  return false;
}

function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.
  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.
  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}

function getPageOffsetBottom(el) {

  var z;

  // Return the x coordinate of an element relative to the page.
  z = el.offsetBottom;
  return z;
}
function ToggleTabVisibility(firstLink,  numberToBeVisible,  delimiTabNames)
{
    //firstLink.className = "perfDetLink";
	var TabNames = delimiTabNames.split(";");
	var i;
	for(i=0;i<TabNames.length;i++)
	{
	    var obj1 = document.getElementById(TabNames[i]);
	    var obj2 = document.getElementById(PerfDet_LinkArray[i]);
	    if(i==numberToBeVisible)
	    {
    	    obj1.style.display ="block";
    	    obj2.removeAttribute("href");
    	    //obj2.removeAttribute("className");
    	    obj2.className= "SecondSubMenu_2";
    	    obj2.disabled = true;
    	}
    	else
    	{
    	    obj1.style.display="none";
   	        obj2.setAttribute("href","javascript:void(0);");
   	        obj2.className="SecondSubMenu_1";
    	    obj2.disabled = false;
    	}
	}
	return false  ;
}


function ToggleContactUsTabVisibility(numberToBeVisible)
{
    HideErrorDiv();
    var DivNames = delimitedDivNames.split(";");
	var i;
	
	// for custom validation and email attachment functionality
	if(numberToBeVisible == 4)
	{ 
	    var ct = DivNames[numberToBeVisible];
	    ShowDivInclusion(ct);
	    DisableotherDivforBroadIndex(numberToBeVisible);
    }
    else
    {
      EnableAllDivs();
    }
	
	
	for(i=0;i<DivNames.length;i++)
	{
	    var obj1 = document.getElementById(DivNames[i]);
	    var delimitedValNames = ContactUs_ValidatorsArray[i];
	    var ValNames = null;
	    if(delimitedValNames != null)
	        ValNames  = delimitedValNames.split(";");

	    if(i==numberToBeVisible)
	    {
    	    obj1.style.display ="block";
    	    if(ValNames != null)
    	    {
    	        for(i1=0;i1<(ValNames.length-1);i1++)
	            {
	                var obj1 = document.getElementById(ValNames[i1]);
	                ValidatorEnable(obj1,true);
	                obj1.style.visibility = "hidden";
	            }
	            var summaryControl = document.getElementById(ValNames[ValNames.length-1]);
	            if(summaryControl != null)
	                summaryControl.style.display = "none";
	        }
    	}
    	else
    	{
    	    obj1.style.display="none";
    	    if(ValNames != null)
    	    {
    	        for(i2=0;i2<(ValNames.length-1);i2++)
	            {
	                var obj1 = document.getElementById(ValNames[i2]);
	                ValidatorEnable(obj1,false);
	                obj1.style.visibility = "hidden";
	            }
	            var summaryControl1 = document.getElementById(ValNames[ValNames.length-1]);
	            if(summaryControl != null)
	                summaryControl1.style.display = "none";
	        }

    	}
	}
	
    var lblMsg ; // if at all the old contact us message is present - clear it.
    lblMsg =  document.getElementById(OutputLabel);
    lblMsg.innerHTML = "";

	return false  ;
}

function DisableotherDivforBroadIndex(numberToBeVisible)
  {
    var DivNames = delimitedDivNames.split(";");
	var i;
	
	// for custom validation and email attachment functionality
	   for(i=0;i<DivNames.length;i++)
	    {
	     var objDiv  = document.getElementById(DivNames[i]);
	        if(i != numberToBeVisible)
	        {
	            objDiv.disabled = true;
	        }
	    }
}

function EnableAllDivs()
{
  var DivNames = delimitedDivNames.split(";");
  var i;
  
  // for custom validation and email attachment functionality
    for(i=0;i<DivNames.length;i++)
    { 
        var objDiv  = document.getElementById(DivNames[i]);
        objDiv.disabled = false;
    }
}


function ToggleOverviewTabVisibility( firstLinkText, firstLink, numberToBeVisible,  delimiTabNames,cookieDomain)
{
    SetCookie("selected_ov_tab",numberToBeVisible+'',"/",cookieDomain);
    

	var TabNames = delimiTabNames.split(";");
	var i;
	for(i=0;i<TabNames.length;i++)
	{
	    var obj1 = document.getElementById(TabNames[i]);
	    var obj2 = document.getElementById(PerfOverview_LinkArray[i]);
	    if(i==numberToBeVisible)
	    {
    	    obj1.style.display ="block";
    	    obj2.removeAttribute("href");
    	}
    	else
    	{
    	    obj1.style.display="none";
    	    obj2.setAttribute("href","javascript:void(0);");
    	}
	}
	return false  ;
}

function OpennewUrl(url)
{
    window.location = url;

}

function DisplayUserLogin(loginHyperLink,divUserLogin)
{
    //set the position where the login pop-up should be dislpayed
    divUserLogin.style.display="block";
   return 3;
}

function HideMe(controlToHide)
{
    controlToHide.style.display="none";
}



function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    //alert(aCrumb[0]);
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

/*
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
alert(document.cookie);
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
alert(document.cookie.substring(i, j));
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
*/

/* start :scripts for contact us page */
function ContactUsIC()
{
    /*
    Order of arguments to the function-
     txtName, txtUserName , txtEmailAddr,txtSubject, txtRequest
     */
     
    if(Page_ClientValidate())
    {
    PageMethods.ContactRequestIC(
    arguments[0].value,
    arguments[1].value,
    arguments[2].value,
    arguments[3].value,
    arguments[4].value,
    OnSucceeded,
    OnFailed
    );
    }

}

function ContactUsIC1()
{
    /*
    Order of arguments to the function-
     txtName, txtUserName , txtEmailAddr,txtSubject, txtRequest
     */
     
    if(Page_ClientValidate())
    {
    PageMethods.ContactRequestIC1(
    arguments[0].value,
    arguments[1].value,
    arguments[2].value,
    arguments[3].value,
    arguments[4].value,
    OnSucceeded,
    OnFailed
    );
    }

}


/* start :scripts for contact us page */



function ContactUsOE()
{
    /*
    Order of arguments to the function-
     txtName, txtUserName , txtEmailAddr,txtSubject, txtRequest
     */
     
    if(Page_ClientValidate())
    {
    PageMethods.ContactRequestOE(
    arguments[0].value,
    arguments[1].value,
    arguments[2].value,
    arguments[3].value,
    arguments[4].value,
    OnSucceeded,
    OnFailed
    );
    }

}



function ContactUsII()
{
    /*
    Order of arguments to the function-
     txtName, txtUserName , txtEmailAddr,txtSubject, txtRequest
     */
     
   /* if(Page_ClientValidate())
    {
        PageMethods.ContactRequestII(
        arguments[0].value,
        arguments[1].value,
        arguments[2].value,
        arguments[3].value,
        arguments[4].value,
        OnSucceeded,
        OnFailed
        );
    }
  */
  
   // customized javascript validation.
   
}


function ContactUsIP()
{
/*
order of arguments to the function-
 txtName, txtUserName , txtEmailAddr, txtTelephone, ddlRole, ddlInvestor, ddlCountry, ddlRegion,
rblistQ1[0], rbListQ2[0], rbListQ3[0], txtMessage, ContactUsDiv, ContactUsMsgDiv, MsgLabel
*/
    if(Page_ClientValidate())
    {
    PageMethods.ContactRequestIP(
    arguments[0].value,
    arguments[1].value,
    arguments[2].value,
    arguments[3].value,
    arguments[4].options[arguments[4].selectedIndex].value,
    arguments[5].options[arguments[5].selectedIndex].value,
    arguments[6].options[arguments[6].selectedIndex].value,
    arguments[7].options[arguments[7].selectedIndex].value,
    getYesNo(arguments[8]),
    getYesNo(arguments[9]),
    getYesNo(arguments[10]),
    arguments[11].value,
    OnSucceeded,
    OnFailed
    );
    }
    
}

function ShowContactUsResponse( msg)
{
    var DivNames = delimitedDivNames.split(";");
	var i;


	for(i=0;i<DivNames.length;i++)
	{
		var div1;
        div1 = document.getElementById(DivNames[i]);
	
	    if(i==6)
	    {
	        div1.style.display = "block";
	    }
	    else
	    {
	        div1.style.display = "none";
	    }
	}

    var lblMsg ;
    lblMsg =  document.getElementById(OutputLabel);
    lblMsg.innerHTML = msg;
    lblMsg.focus();
    return;
}

function OnSucceeded(sucData)
{
    ShowContactUsResponse(sucData);
}

function OnFailed(failData)
{
    ShowContactUsResponse(failData);  
}

function WriteUserName(userWelcomeLink) { 
var dc = document.cookie;   
var uwlink = document.getElementById(userWelcomeLink); 
var user = getCookie("user"); 
if (user == null || user.length == 0) return; 
var  namearray = new Array(); 
namearray = user.split("|"); 
var text = uwlink.innerHTML; 
 if (text.indexOf("%name%")>0){ 
 text = text.replace("%name%", namearray[0]); }else{
text =  "Welcome " + namearray[0];} 
uwlink.innerHTML = text; 
} 

function getYesNo(buttonGroupNoButton) {
    if(buttonGroupNoButton.checked)
    {
        return "false"; // no selected
    }
    else
    {
        return "true"; // yes selected
    }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

/* end :scripts for contact us page */

/* Mail attachment related functionlity  */

function addArea() 
	{
		var newArea = addElement();
		var area = "<input type='file' name='attachment[]' onkeydown='this.blur();'/>";
		var link= "&nbsp;<a onclick='removeElement(" + '"' +  newArea + '"' + ")' href='#'>Remove</a>";
		document.getElementById(newArea).innerHTML = area + link;
	}
	function addElement() 
	{
		  var ni = document.getElementById('area');
		  var numi = document.getElementById('intVal');
		  var num = (document.getElementById('intVal').value -1)+ 2;
		  numi.value = num;
		  var newdiv = document.createElement('div');
		  var divIdName = 'my'+num+'Div';
		  newdiv.setAttribute('id',divIdName);
		  ni.appendChild(newdiv);
		  return divIdName;
	}
	
	function removeElement(divid)
	{
	 
	 var div = document.getElementById(divid);
	 document.getElementById("area").removeChild(div); 
	}
	
	function validateFiles()
	{
	    var node_list = document.getElementsByTagName('input');
        for (var i = 0; i < node_list.length; i++)
        {
            var node = node_list[i];
            if (node.getAttribute('type') == 'file') 
            {
                if (node.value == '') 
                {  
                    return false;
                }
            }
       }
	}

	

function validateContactUs_II(jsname,jsemail)
{
 
  var name = document.getElementById(jsname);
  var email = document.getElementById(jsemail); 
  var emailRegex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  var emailvalid=true;
  var isvalid=true;
  
 HideDiv();
 
 if(name.value == "") 
 {
    validateName_ContactUsII(name);
    isvalid=false;
 }
 
 if(email.value == "")
 {
    validateEmail_ContactUsII(email,"Email is required"); // blank email
    emailvalid = false;
    isvalid = false;
 }
 
 if(!emailRegex.test(email.value))
 {
    if(emailvalid)
    {
        validateEmail_ContactUsII(email,"Please provide a valid email address"); // valid email
        isvalid = false;
    }
    
 }
  
 if(!verifyFiles())
 {
    isvalid=false;
 }
 
    if(isvalid)
    {
       DisableotherDivforBroadIndex(4);
       var fm = document.forms[0];
       fm.submit();
    } 
    else
    {
        return isvalid;
    }
}



function HideDiv()
{
    var divname = document.getElementById("validatename_II");
    var divemail = document.getElementById("validateemail_II");
    var filediv = document.getElementById("filediv");
    
    divname.style.visibility = "hidden"; 
    divemail.style.visibility = "hidden"; 
    filediv.style.visibility = "hidden"; 
    
}

function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}


function validateName_ContactUsII(name)
{   
    var div = document.getElementById("validatename_II");
    var targetwidth = div.offsetWidth;
    var leftp = leftPosition(name);
    div.style.left= leftp + targetwidth + 80;
    div.style.top = topPosition(name) + 2;
    div.style.visibility = "visible";   
}

function validateEmail_ContactUsII(email,text)
{   
    var div = document.getElementById("validateemail_II");
    var targetwidth = div.offsetWidth;
    var leftp = leftPosition(email);
    div.style.left= leftp + targetwidth + 80;
    div.style.top = topPosition(email) + 2;
    div.style.visibility = "visible";   
    div.innerHTML = text;
}

function ShowDivInclusion(div)
{
    var divinclusion = document.getElementById(div);
    divinclusion.style.visibility ="visible";
    divinclusion.disabled = false;
}

function verifyFiles() 
{
    var nodes = document.getElementsByTagName('input');
    for (var i = 0; i < nodes.length; i++)
      {
         var node = nodes[i];
         if (node.getAttribute('type') == 'file') 
          {
            if (node.value == '') 
             {  
                var filediv = document.getElementById("filediv");
                filediv.style.visibility = "visible";   
                return false;
             }
           }
       }
       
       return true;
  }

function scrollscroller()
{
    if (parseInt(cross_scroller.style.top)>(actualheight*(-1)+8))
    {
    cross_scroller.style.top=parseInt(cross_scroller.style.top)-copyspeed+"px"
    }
    else
    {
        cross_scroller.style.top=parseInt(scrollerheight)+8+"px"
    }
}    

function togglePannelStatus(content)
{
    var expand = (content.style.display=="none");
    content.style.display = (expand ? "block" : "none");
    toggleChevronIcon(content);
}

var currentContent = null;

function togglePannelAnimatedStatus(content, interval, step)
{
    if (currentContent==null)
    {
        currentContent = content;
        var expand = (content.style.display=="none");
        if (expand)
            content.style.display = "block";
        var max_height = content.offsetHeight;

        var step_height = step + (expand ? 0 : -max_height);
        toggleChevronIcon(content);
                
        content.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePannelAnimatingStatus(" + interval + "," + step
            + "," + max_height + "," + step_height + ")", interval);
    }
}

function togglePannelAnimatingStatus(interval, step, max_height, step_height)
{
    var step_height_abs = Math.abs(step_height);


    if (step_height_abs>=step && step_height_abs<=(max_height-step))
    {
        step_height += step;
        currentContent.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePannelAnimatingStatus(" + interval + "," + step
            + "," + max_height + "," + step_height + ")", interval);
    }
    else
    {
        if (step_height_abs<step)
            currentContent.style.display = "none";
        currentContent.style.height = "";
        currentContent = null;
    }
}

function toggleChevronIcon(content)
{
    var chevron = content.parentNode.firstChild.childNodes[1].childNodes[0];
    var expand = (chevron.src.indexOf("expand.gif")>0);
    chevron.src = chevron.src
        .split(expand ? "expand.gif" : "collapse.gif")
        .join(expand ? "collapse.gif" : "expand.gif");
}


function TriggerBannerCount()
{
  window.open("counter.aspx?indexname=NONE"); 
    
}

