 // <![CDATA[


function setJavaCookie() {
	//debugger;
	var expireDate = new Date();
	expireDate.setMonth(expireDate.getMonth()+6);

	var javaVal = document.getElementById("javaVal").value;
	document.cookie = "javaVal=" + javaVal + ";expires=" + expireDate.toGMTString();
	showCookies();
	return false;
}

function delCookies() {
	//debugger;
	var cookieCt = 0;

	if (document.cookie != "" && confirm("Do you want to delete the cookies?")) {
		var thisCookie = document.cookie.split("; ");
		cookieCt = thisCookie.length;

		var expireDate = new Date();
		expireDate.setDate(expireDate.getDate()-1);

		for (var i=0; i<cookieCt; i++) {
			var cookieName = thisCookie[i].split("=")[0];
			document.cookie = cookieName + "=;expires=" + expireDate.toGMTString();
		}
	}
	var outMsg = ""
	outMsg += "Number of cookies with expire date set in past: " + cookieCt + "<br />";
	var afterCookie = document.cookie.split("; ");
	var delCt = cookieCt - afterCookie.length;
	outMsg += "Number of cookies deleted: " + delCt + "<br />"; 
	document.getElementById("javaDelCount").innerHTML = outMsg;
	showCookies();
	return false;
}


function setJScookie  ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{

  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );


    cookie_string += "; expires=" + expires.toGMTString();
  } else {
	var expires= new Date();
	expires.setTime(expires.getTime()+(20*60*1000));


    cookie_string += "; expires=" + expires.toGMTString();
  }

//  if ( path )
        cookie_string += "; path=" + escape ("/");

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}


function getJScookie(cookieName) {
	var thisCookie = document.cookie.split("; ");

//	alert('1');


	for (var i=0; i<thisCookie.length; i++) {
//		alert('2');
		if (cookieName == thisCookie[i].split("=")[0]) {
//			alert('3');
			if (thisCookie[i].split("=")[1]) {
				return cleanCookieVal(thisCookie[i].split("=")[1]);
			} else {
				return '';
			}
		}
	}
	return '';
}

function showCookies() {
	var outMsg = "";
	document.getElementById("showCookies").innerHTML = "";
	if (document.cookie == "") {
		outMsg = "There are no cookies here";
	} else {
		outMsg += "Cookie file contents: " + document.cookie + "<br />";
		var thisCookie = document.cookie.split("; ");
		for (var i=0; i<thisCookie.length; i++) {
			outMsg += "Cookie " + i + ": Name ='" + thisCookie[i].split("=")[0];
			outMsg += "', Value = '" + thisCookie[i].split("=")[1] + "'<br />";
		}
	}
	document.getElementById("showCookies").innerHTML = outMsg;
}


String.prototype.replaceAll = function( 
		strTarget, // The substring you want to replace
		strSubString // The string you want to replace in.
		){

	var strText = this;
	var intIndexOfMatch = strText.indexOf( strTarget );
 

	// Keep looping while an instance of the target string
	// still exists in the string.
	while (intIndexOfMatch != -1){
		// Relace out the current instance.
		strText = strText.replace( strTarget, strSubString )
 

		// Get the index of any next matching substring.
		intIndexOfMatch = strText.indexOf( strTarget );
	}
 

	// Return the updated string with ALL the target strings
	// replaced out with the new substring.
	return( strText );
}


function cleanCookieVal(cookieVal) {


	var newString = "";

	newString = cookieVal.replaceAll("%40","@");		
	newString = newString.replaceAll("%2E",".");

	return newString;


}

// ]]>


