function page_init() {
//temporary method do not remove this else it will give JS error since it is included in default html
}
function popUp(url) {
sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
self.name = "mainWin";
}

 // close pop-up window 
 function clean() 
 {
     if (popwin != null)
        popwin.close();
 }
 

function launchdisclosure(url)
{
  window.open(url, "reader", "width=490,height=480,menubar=yes,scrollbars=yes");
}

function closeIt()
{
  self.close()
}



// Javascript functions for OB portfolio.
function display(text)
{
    alert(text)
}

// Java Script functions for PL	  
function getDigestNumber() {
   
       digestNumberLink = "https://digitalid.verisign.com/as2/f9d9f773a3ea4900bfae6bc696fc8e5f";
       sealWin=window.open(digestNumberLink,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
       self.name = "mainWin";
                
}

function showAlert(url)
{	
	alert(" Your session has expired.\n ");
	parent.location.href= url;
}


//This part of the code is for State double letter pick

//The last time that a key was pressed.  The intitial value of 0 guarantees 
//that the test in keyPressed() fails.
var lastKeyTime = 0;
//Maximum delay between keystrokes in milliseconds.
var maxDelay = 1000;
//The characters entered
var input = " ";
//The selected index in the options
var matchIndex = 0;
//A flag to set up the options
var setUpOptions = true;
//The select flag is only used in Netscape
var selectFlag = true;
//The next variables are used to detect the type of browser
var internetExplorer = (navigator.appName == "Microsoft Internet Explorer") ? true : false;
var netscape = (navigator.appName == "Netscape") ? true : false;

function select(){
  if (internetExplorer) {
    window.document.Form1.ApplicantState.selectedIndex = matchIndex;
  } else if (netscape){
    if (!selectFlag )
	  return;
    selectFlag = false;
    window.document.Form1.ApplicantState.selectedIndex = matchIndex;
    window.document.Form1.ApplicantState.blur();
    window.document.Form1.ApplicantState.focus();
    selectFlag = true;
  }
}

function setUpTheOptions(){
  for (i =1; i < window.document.Form1.ApplicantState.options.length; i++){
    window.document.Form1.ApplicantState.options[i].text = " " + window.document.Form1.ApplicantState.options[i].text;
  }
}

var out = "";

function keyPressed(event){
  if (internetExplorer) {
    //If this is the first time set up the options
    if (setUpOptions){
      setUpTheOptions();
      setUpOptions = false;
    }
    var currentTime = new Date().getTime();
    //If the time after the last key stroke is less than maxDelay, append the key 
    //to input.  Otherwise, initialize input with the key
    if (currentTime - lastKeyTime < maxDelay)
      input = input + String.fromCharCode(window.event.keyCode).toLowerCase();
    else
      input = " " + String.fromCharCode(window.event.keyCode);
    lastKeyTime = currentTime; //this is the time of last key stroke
    //Match the input with the entries in the combobox.
    //matchIndex = -1; //index of the best match
matchIndex = 0;
    var maxCount = 0; //max number of characters matched
    //For each entry in the options list
    for (i =0; i < window.document.Form1.ApplicantState.options.length; i++){
      nextEntry = window.document.Form1.ApplicantState.options[i].text.toLowerCase();
      if (nextEntry.length < input.length)
      continue; //Entry is too short
      //Count how many characters in the entry match the input.
      var count = 0;
      for (j = 0; j < input.length; j++){
        if (nextEntry.charCodeAt(j) == input.charCodeAt(j))
          count = count + 1;
        else
          break;
      }
      //If the entry is a better match, select it.
      if (count > maxCount){
        matchIndex = i;
        maxCount = count;
      }
    }
    //Directly executing window.this.ApplicantState.selectedIndex = matchIndex; fails.  Must use a delay
    setTimeout("select()", 500);
  } else if (netscape){
  	if (event.which < 32 || event.which > 126)
		return;
    var currentTime = new Date().getTime();
    var delay = currentTime - lastKeyTime;
    if (delay < maxDelay)
      input = input + String.fromCharCode(event.which).toLowerCase();
    else
      input = String.fromCharCode(event.which);
    lastKeyTime = currentTime; //this is the time of last key stroke
    //Match the input with the entries in the combobox.
    matchIndex = -1; //index of the best match
    var maxCount = 0; //max number of characters matched
    //For each entry in the options list
    for (i =0; i < window.document.Form1.ApplicantState.options.length; i++){
      nextEntry = window.document.Form1.ApplicantState.options[i].text.toLowerCase();
      if (nextEntry.length < input.length)
        continue; //Entry is too short
      //Count how many characters in the entry match the input.
      var count = 0;
      for (j = 0; j < input.length; j++){
        if (nextEntry.charAt(j) == input.charAt(j))
          count = count + 1;
        else
          break;
      }
      //If the entry is a better match, select it.
      if (count > maxCount){
        matchIndex = i;
        maxCount = count;
      }
  }
  //Directly executing window.document.Form1.ApplicantState.selectedIndex = matchIndex; fails.  Must use a delay
  setTimeout("select()", 500);
  }
}


// Feb'05 release : Plastic Choice functionality Code : START
// This function added to display popup window when click on thumbnail image in
// plastic choice pages.
var cardPopWin = null;
function displayPCLargeImg(cardNameUrl, cardDesign, pcImage) {
            if (cardPopWin != null && !cardPopWin.closed) { 
             cardPopWin.document.close();
             cardPopWin.focus();
            }
 
            // variable to display popup window in center on screen
            var centerwidth=(screen.width/2)-(179/2);
            var centerheight=(screen.height/2)-(118/2);
            
            // Open a new jsp and pass cardname and image name in url because we are displaying card name from content servlet html file
            cardPopWin=window.open('PlasticChoicePopUpWindow.jsp?cardNameUrl='+cardNameUrl + '&cardDesign=' + cardDesign + '&pcImage=' + pcImage, "newwin", 'height=113, width=179,location=no,toolbar=no,scrollbars=no,menubar=no,top=' + centerheight + ',left=' + centerwidth);
}
 
 
// Close plastic choice card pop-up window on page onUnload
function cardPopWinClose() 
{
     if (cardPopWin != null && !cardPopWin.closed) {
        cardPopWin.close();
             }
}
// Feb'05 release : Plastic Choice functionality Code : END


//this is being called for getcard from right nav
function launchgetcard(filename)
{
  var sPath = window.location.host;
  var filePath = "https://"+sPath+"/hcs/cms?collection=common&id=/"+filename;

  window.open(filePath, "reader", "width=490,height=480,menubar=yes,scrollbars=yes");
}
 var linkWin = false
function openIWPopUp(url,windowWidth,windowHeight)
{
	if (linkWin && !linkWin.closed)
	{
		linkWin.close();
	}
	var windowParameters = 'width='+windowWidth+',height='+windowHeight+',toolbar=no, directories=no, location=no, left=250, top=150, status=no, menubar=no, resizable=no, scrollbars=yes';
	
	linkWin = window.open(url,'',windowParameters);
	if (!linkWin.opener) linkWin.opener = self;
}
function simpleWinUp(targetAddress)
{
	var indexoflocale = targetAddress.indexOf("&locale");
    if (indexoflocale != -1)
    {
        targetAddress =  targetAddress.substring(0,indexoflocale);
    }

	var index = targetAddress.indexOf("=");
	targetAddress1 = targetAddress.substring(index+1,targetAddress.length);
	targetAddress =  targetAddress.substring(0,index+1) + escape(targetAddress1);
	window.open(targetAddress,'new',"height=230,width=550,status=no,toolbar=no,menubar=no,location=no,top=250");
}

//Added for enabling the enter key in all the forms.

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) {
		   submitForm();
		   return false;
	}
	else {
	   return true;
	}
}

function billPayOpenNewWindow(valBillPay)
	{
		paymentwindow = window.open(valBillPay,'','screenX=0,screenY=0,left=0,top=0,width=800,height=550,resizable=yes,scrollbars=yes,toolbar=no,locationbar=no,personalbar=no,menubar=no');
		paymentwindow.focus();
	}

function openDocument(filename, titleName)

{
	var linkWin = false
	if (linkWin && !linkWin.closed)
	{
		linkWin.close();
	}

    linkWin = window.open(filename,'','width=580,height=230,scrollbars=yes,resizable=yes,toolbar=no');

     if (!linkWin.opener) linkWin.opener = self;

}

function winUp(targetAddress)

{
	var indexoflocale = targetAddress.indexOf("&locale");

    if (indexoflocale != -1)
	 {
        targetAddress =  targetAddress.substring(0,indexoflocale);
    }

	var index = targetAddress.indexOf("=");
	targetAddress1 = targetAddress.substring(index+1,targetAddress.length);

	targetAddress =  targetAddress.substring(0,index+1) + escape(targetAddress1);

	window.open(targetAddress,'new',"height=230,width=550,status=no,toolbar=no,scrollbars=yes,menubar=no,resizable=yes,location=no,top=250");

}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);	
function autoTab(input,len, e) 
{
    var keyCode = (isNN) ? e.which : e.keyCode; 
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
    if(input.value.length >= len && !containsElement(filter,keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input)+1) % input.form.length].focus();
    }
    function containsElement(arr, ele) 
    {
        var found = false, index = 0;
        while(!found && index < arr.length)
            if(arr[index] == ele)
                found = true;
            else
                index++;
        return found;
    }
    function getIndex(input) 
    {
        var index = -1, i = 0, found = false;
        while (i < input.form.length && index == -1)
            if (input.form[i] == input)index = i;
            else i++;
        return index;
    }
    return true;
}

function validateInputs(chkBox, divName, ErrMsg)
{
	var result = true;
	// for agree Term
	if(chkBox != null)
	{
		if( chkBox.checked )
		{
			writeContent(divName, "");
		} 
		 else
		 {
			 result = false;
			 writeContent(divName, "<table><tr class=\"err_bx\"><td><div class=\"err_msg\">" + ErrMsg + "</div></td></tr></table>");
	     }
	     	return result;
     }
}

function writeContent(divName, content)
{
	var divHandle;
	if(document.all)
	{
		divHandle = document.all[divName];
		divHandle.innerHTML = content;
	}
	else if(document.getElementById)
	{
		divHandle = document.getElementById(divName);
		divHandle.innerHTML = content;
	}
}
function submitFunction()
{
	
var radioVal="";
    for(var i=0; i < document.StatementPrefernceInfo.StmtPrfrradioSelect.length; i++){
	if(document.StatementPrefernceInfo.StmtPrfrradioSelect[i].checked)
		{radioVal=document.StatementPrefernceInfo.StmtPrfrradioSelect[i].value;
		 break;
		}
	}
	
	//Changed for prod fix july'08
	var radioEmail="";
    	for(var i=0; i < document.StatementPrefernceInfo.StmtPrfrverifyEmail.length; i++)
    	{
    	if(document.StatementPrefernceInfo.StmtPrfrverifyEmail[i].checked)
			{
				radioEmail=document.StatementPrefernceInfo.StmtPrfrverifyEmail[i].value;
			 	break;
			}
		}
		
	if(radioVal=="selPaperless" && radioEmail=="verifyEmailN") 
	{
	  document.StatementPrefernceInfo.action='/ecare/choosePaperlessEmailChange?'+'&locale='+locale+'&brand='+brand+'&StmtOption=selPaperless';
	  //document.forcedStatementInterstitial.action="/ecare/choosePaperlessFormForcedStatement";
     	
      document.StatementPrefernceInfo.submit();
      formSubmitted=true;
      return true;
	}
	else if (radioVal=="selPaperless" && radioEmail=="verifyEmailY")
	{
	  document.StatementPrefernceInfo.action='/ecare/choosePaperlessStatement?'+'&locale='+locale+'&brand='+brand+'&StmtOption=selPaperless';
	  //document.forcedStatementInterstitial.action="/ecare/choosePaperlessFormForcedStatement";
      
      document.StatementPrefernceInfo.submit();
      formSubmitted=true;
      return true;
	}
	else if (radioVal=="selPostal")
	{
	  document.StatementPrefernceInfo.action='/ecare/choosePaperStatement?'+'&locale='+locale+'&brand='+brand+'&StmtOption=selPostal';
      document.StatementPrefernceInfo.submit();
      formSubmitted=true;
      return true;
	}	
	else
	{
		document.StatementPrefernceInfo.action='/ecare/choosePaperlessStatement?'+'&locale='+locale+'&brand='+brand+'&StmtOption=selPaperless';
		document.StatementPrefernceInfo.submit();
	    formSubmitted=true;
    	return true;
	}
 	
}


