// The following 3 functions (getCookieVal, getCookie, and setCookie work together for any page that requires a session cookie.
// get the cookies value
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}


function getCookie (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
    }
    return null;
  }
//Commented by Alpana by changing name and added new function
//function setCookieOld (name, value) {
    //document.cookie = name + "=" + escape(value);
  //}
function setCookie (name, value) {
    
    var cookie_string = name + "=" + escape ( value );
	
	  var cookie_date = new Date ( );  // current date & time
	  cookie_date.setTime ( cookie_date.getTime() - 1 );	  
	  cookie_string += ";expires=" +cookie_date.toGMTString();	  
	  cookie_string += "; secure";
	  cookie_string += "; HTTPOnly";
	
	  document.cookie = cookie_string;
}

function setcookie ( name, value, expires, path, domain, secure )
	{	
	  var cookie_string = name + "=" + escape ( value );
	
	  var cookie_date = new Date ( );  // current date & time
	  cookie_date.setTime ( cookie_date.getTime() - 1 );
      expires = (expires) ? ";expires=" + expires.toGMTString() :";expires=" +cookie_date.toGMTString();
	  
	  cookie_string += expires ;
	  
	  if ( path )
	  cookie_string += "; path=" + escape ( path );
	 	
	  if ( domain )
	        cookie_string += "; domain=" + escape ( domain );
	  
	  cookie_string += "; secure";
	  cookie_string += "; HTTPOnly";
	
	  document.cookie = cookie_string;
	}
   

//Sets the page defaults for enterable fields in any form.
function setDefault(theForm, element, value)
{
	for (i = 0; i < theForm.elements[element].length; i++)
	{
		if (theForm.elements[element][i].value == value)
		{
			theForm.elements[element].selectedIndex = i;
		}
	}
}

function encode_cookie(cookie_value) {

  // This variable holds the encoded cookie characters
  var coded_string = ""
  
  // Run through each character in the cookie value
  for (var counter = 0; counter < cookie_value.length; counter++) {
  
    // Add the characters numeric code to the string
    var encode_value = (cookie_value.charCodeAt(counter) * 1) + 88
    coded_string += ""+ encode_value
    
    // Separate each code with a plus sign (+)
    if (counter < cookie_value.length - 1) {
      coded_string += "+"
    }
  }
  return coded_string
}

function decode_cookie(coded_string) {

  // This variable holds the decoded cookie value
  var cookie_value = ""
  
  // Use + to split the coded string into an array
  var code_array = coded_string.split("+")
  
  // Loops through the array
  for (var counter = 0; counter < code_array.length; counter++) {

    // Convert the codes into a character and 
    // add it to the cookie values string
    var decode_value = (code_array[counter] * 1) - 88;
    cookie_value += String.fromCharCode(decode_value)
  }
  
  return cookie_value
}

   function setcookie(name, value, expires, path, domain, secure) {
     value = escape(value);
     expires = (expires) ? ';expires=' + expires.toGMTString() :'';
     document.cookie = name + '=' + value + expires+";path=/";
   }


function newWindow(href) {
	window.open(href);
}

function newWindowWithOptions(href, winWidth, winHeight, allowResize, allowScroll) {
	var options = 'width=' + winWidth +',height=' + winHeight + ',resizable=' + allowResize + ',scrollbars=' + allowScroll +',toolbar=no,location=no,directories=no,menubar=no,left=0,top=0,screenX=0,screenY=0'
	window.open(href,'new_window_with_option', options);
}

function loadDate() {
	var timeOfDay = "AM";
	var currentTime = new Date();
	var day = currentTime.getDate();
	if(day.toString().length <=1) {
	   day="0"+day;
	}
	var month = currentTime.getMonth()+1;
	if(month.toString().length <=1) {
	   month="0"+month;
	}
	var year = currentTime.getFullYear();
	var hours = currentTime.getHours();
	if(hours.toString().length <=1) {
	   hours="0"+hours;
	}
	var minutes = currentTime.getMinutes();
	if(minutes.toString().length<=1) {
	   minutes="0"+minutes;
	}
	var seconds = currentTime.getSeconds();
	if(seconds.toString().length <=1) {
	   seconds="0"+seconds;
	}
	if(hours >= 12) {
	   timeOfDay = "PM";
	}
	var time = month+"."+day+"."+year+" at "+hours+":"+minutes+":"+seconds+" "+timeOfDay;
	document.getElementById('showTime').innerHTML = ' '+time;
}

function getCalendarDate()
{
	var months = new Array(13);
	months[0] = "January";
	months[1] = "February";
	months[2] = "March";
	months[3] = "April";
	months[4] = "May";
	months[5] = "June";
	months[6] = "July";
	months[7] = "August";
	months[8] = "September";
	months[9] = "October";
	months[10] = "November";
	months[11] = "December";
	var day = new Array(7);
	day[0] = "Sunday";
	day[1] = "Monday";
	day[2] = "Tuesday";
	day[3] = "Wednesday";
	day[4] = "Thursday";
	day[5] = "Friday";
	day[6] = "Saturday";

	var now = new Date();
	var monthnumber = now.getMonth();
	var monthname = months[monthnumber];
	var monthday = now.getDate();
	var weekday = day[now.getDay()];
	var year = now.getYear();
	if(year < 2000) { year = year + 1900; }
	var dateString = weekday +', '+ monthname + ' ' + monthday + ', ' + year;
	document.getElementById('showTime').innerHTML = ' '+dateString;
} 
/* Added the following for transaction history enhancement - talapar*/
var reloaded = false;
var loc=""+document.location;
loc = loc.indexOf("?reloaded=")!=-1?loc.substring(loc.indexOf("?reloaded=")+10,loc.length):"";
loc = loc.indexOf("&")!=-1?loc.substring(0,loc.indexOf("&")):loc;
reloaded = loc!=""?(loc=="true"):reloaded;

function reloadOnceOnly() {
    if (!reloaded) 
        window.location.replace(window.location+"?reloaded=true");
}
/*end talapar*/

