<!--
// <![CDATA[
/**
 * Class for managing template-specific scripts
 */
var Homepage =
{
	init: function () {
		this.doSIFR();
	}
	,
	doSIFR: function () {
		if (typeof sIFR == "function")
		{
			var facPanel = named({
				sFlashSrc:	"flash/Agenda.swf",
				sColor:		"#4284a6",
                sWmode:     "transparent"
			});
            
            var presentsPanel = named({
				sFlashSrc:	"flash/Agenda.swf",
				sColor:		"#4284a6",
                sWmode:     "transparent"
			});
            
             var sideBox = named({
				sFlashSrc:	"flash/Agenda.swf",
				sColor:		"#4284a6",
                sWmode:     "transparent"
			});
            
            var greenBox = named({
				sFlashSrc:	"flash/Agenda.swf",
				sColor:		"#96ad64",
                sWmode:     "transparent"
			});
            
            var strapline1 = named({
				sFlashSrc:	"flash/AgendaLt.swf",
				sColor:		"#ffffff",
				sBgColor:	"#a6851c",
				sFlashVars:	"textalign=center"
			});
            
            var strapline2 = named({
				sFlashSrc:	"flash/AgendaLt.swf",
				sColor:		"#ffffff",
				sBgColor:	"#337297",
				sFlashVars:	"textalign=center"
			});
            sIFR.replaceElement('.findCard .head h2', facPanel);
            sIFR.replaceElement('.presents .head h2', presentsPanel);
            sIFR.replaceElement('.green .head h2', greenBox);
            sIFR.replaceElement('.sideBox .head h2', sideBox);
            sIFR.replaceElement('#strapline1 h2',strapline1);
            sIFR.replaceElement('#strapline2 h2',strapline2);
		};
	}
};
var Tabs ={
  init:function(){
    if($('channel_changer')){
      var tabs = $('channel_changer').childElements();
      for(var i=0;i<tabs.length;i++){
        if(i==0){
          tabs[i].addClassName("selected");
        }
        Event.observe(tabs[i],"click",Tabs.clicked);
        Event.observe(tabs[i],"mouseout",Tabs.hoverOut);
        Event.observe(tabs[i],"blur",Tabs.hoverOut);
        Event.observe(tabs[i],"mouseover",Tabs.hoverIn);
        Event.observe(tabs[i],"focus",Tabs.hoverIn);
      }
    }
  },
  clicked:function(){
    if(this.className.indexOf("selected")<0){
      Tabs.changeFocus(this);
      Tabs.updateBigPitch(this);
    }
  },
  hoverOut:function(){
    this.removeClassName("hover");
  },
  hoverIn:function(){
    this.addClassName("hover");
  },
  changeFocus:function(offer){
    var selected = $$("li.selected");
    for(var i=0;i<selected.length;i++){
      selected[i].removeClassName("selected");
    }
    offer.addClassName("selected");
  },
  updateBigPitch:function(offer){
    var pitches = $$("div.bp");
    for(var i=0;i<pitches.length;i++){
      pitches[i].style.display = "none";
    }
    var children = offer.childElements();
    var offerToShow = $(children[0].href.split('#')[1]);
    offerToShow.style.display = "block";
  }
};
/**
 * Class to manage user ID and password input fields
 */ 
var InputManager={
  init:function(){
    $('inputTxt').setStyle({backgroundImage:"url('./img/useridBG.gif')"});
    $('password').setStyle({backgroundImage:"url('./img/passwordBG.gif')"});
    Event.observe($('inputTxt'),'focus',InputManager.hideBg);
    Event.observe($('password'),'focus',InputManager.hideBg);
    Event.observe($('inputTxt'),'blur',InputManager.showBg);
    Event.observe($('password'),'blur',InputManager.showBg);
    InputManager.initMonitor();
  },
  hideBg:function(){
    this.addClassName('clearBG');
  },
  showBg:function(){
    if(InputManager.isEmpty(this)==true){
      this.removeClassName('clearBG');
    }
  },
  isEmpty:function(input){
    var isEmpty = new Boolean(false);
    if(input.value.length==0){
      isEmpty = true;
    }
    return isEmpty;
  },
  stopInputMonitor:function(){
    clearInterval(monitor);
  },
  inputMonitor:function(){
    if(($('inputTxt').value.length > 0)&&($('password').value.length > 0)){
      InputManager.stopInputMonitor();
      $('inputTxt').addClassName('clearBG');
      $('password').addClassName('clearBG');
    }
    else if($('inputTxt').value.length > 0){
      $('inputTxt').addClassName('clearBG');
    }
    else if($('password').value.length > 0){
      $('password').addClassName('clearBG');
    }
  },
  initMonitor:function(){
    monitor = setInterval(InputManager.inputMonitor,1000);
  }
};
// Modified addEvent function to rectify display of password in Opera browser

function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}

function addStyleRule(stylesheet, selector, rule) {
	if (stylesheet.addRule) stylesheet.addRule(selector, rule);
	else {
		var index = stylesheet.cssRules.length;
		stylesheet.insertRule(selector + "{" + rule + "}", index);
	}
}

function fix_e(e) {
	if (!e && window.event) e = window.event;
	if (!e.currentTarget && e.srcElement) e.currentTarget = e.srcElement;
	if (!e.originalTarget && e.srcElement) e.originalTarget = e.srcElement;
	return e;
}

var intdays = 1000;
var now = new Date();
now.setTime(now.getTime() + intdays * 24 * 60 * 60 * 1000);

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;
}

function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
	validateform(1);
   return false;
   }
else
   return true;
}

function validateform() {
	var tempval;
	
	var uid;
	var pwd;
	uid = document.getElementById('inputTxt').value;
	pwd = document.getElementById('password').value;

	tempval = document.getElementById('manageid').options[document.getElementById('manageid').selectedIndex].value;
	
	if(tempval=="advisor") {
		loginNow(tempval);
		return false;
	}

	if (((uid =="" |  pwd=="") | (uid =="User ID" |  pwd=="Password")) & tempval !="" ) {
		alert('Please complete both the "User ID" and "Password" fields in order to Log in.');
		return false;
	}
	else if ( uid !="" & pwd !="" & tempval =="") {
		alert('Please select a service in order to log in.');
		return false;
	}
	else if ((uid =="" | pwd=="") & tempval =="") {
		alert('Please complete both the "User ID" and "Password" fields and select a service in order to Log In.');
		return false;
	}
	else if ((uid =="" | uid=="User ID") & (pwd=="" | pwd=="Password") & tempval =="") {
		alert('Please complete both the "User ID" and "Password" fields and select a service in order to Log In.');
		return false;
	}
	else if (uid.length < 4) {
		alert('The User ID or password you entered is invalid.');
		return false;
	}
	else if ((pwd.length < 5)) {
		alert('The User ID or password you entered is invalid.');
		return false;
	}
	else
	{
             manage = document.getElementById('manageid').value;
             SetCookie("Manage",manage,now,"/",".aexp.com");	
	         loginNow(tempval);
	}
}
/*Copied loginNow(tempval),Help(),SecurityHelp(),clearElements() Functions from Flash.js*/
function loginNow(tempval)
{
	var dc=window.document.ssoform;

	if(tempval== "option1"){
		dc.USERID.value = dc.UserID.value;
		dc.PWD.value = dc.Password.value;
		dc.TARGET.value = dc.DestPage.value;
		dc.submit();
  }
	if(tempval== "option2"){
		dc.USERID.value = dc.UserID.value;
		dc.PWD.value = dc.Password.value;
		dc.TARGET.value = "https://www209.americanexpress.com/oms/global/authreg_home.do?ssolang=en_IN&ssobrand=SEWOLINT&mkt=IND";
		dc.action = "https://sso.americanexpress.com/SSO/logon.fcc";
		dc.submit();
  }
	if(tempval== "option3"){
		dc.USERID.value = dc.UserID.value;
		dc.PWD.value = dc.Password.value;
		dc.TARGET.value = "https://www140.americanexpress.com/ATWORK/en_IN/atwork.do?pageAction=initialize";
		dc.action = "https://sso.americanexpress.com/SSO/logon.fcc";
		dc.submit();
  }
}
function Help() {
window.open ("/homepage/include/help.html", "help", "width=470,height=460,scrollbars=no,location=no,dependent=yes,resizable=no top=20,left=300");
}
function SecurityHelp() {
window.open ("http://www.americanexpress.com/homepage/include/security.html?referrer=ushome&section=login", "sechelp", "width=470,height=460,scrollbars=no,location=no,dependent=yes,resizable=no top=20,left=300");
}
function clearElements(){
	window.document.ssoform.UserID.focus();
	window.document.ssoform.Password.value="";	
	window.document.ssoform.UserID.value="";
		
	// retain the manage drop down value
	var mng = ReadCookie("Manage");
	if (mng!='')
	{
		var lstManage = window.document.ssoform.manage;
		for(i=0;i<lstManage.options.length;i++){
			if (lstManage.options[i].value == mng)
			{
				lstManage.options[i].selected = true;				
			}
		}
	}
}
// load handler
Event.observe(window, 'load',function () {
  Homepage.init();
  Tabs.init();
  InputManager.init();
  if(document.images){
    pic1= new Image(); 
    pic1.src="https://www99.americanexpress.com/docs/images/mycaSprites_128.gif"; 
  }
});
//]]
-->