var parent_url;

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}
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;
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if ( 
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
} 



function goback()
{
	if (getURLParam("id") == GetCookie("tempvar") || getURLParam("ctrl") == GetCookie("tempvar")) {
		javascript:window.close(); }
	else {
		javascript:history.go(-1); }
}

function backOrclose()
{
	if (history.length == 0 && navigator.appName == "Microsoft Internet Explorer") 
	{
		if (getURLParam("id") != 0) {
			parent_url = getURLParam("id");
		}
		else {
			parent_url = getURLParam("ctrl"); }
		SetCookie ("tempvar", parent_url);
	}
	if (history.length == 1 && navigator.appName == "Netscape") 
	{
		if (getURLParam("id") != 0) {
			parent_url = getURLParam("id");
		}
		else {
			parent_url = getURLParam("ctrl"); }
		SetCookie ("tempvar", parent_url);
	}
	if(getURLParam("id") == GetCookie("tempvar"))
	{
		document.write("Close");
	}
	if(getURLParam("id") != GetCookie("tempvar"))
	{
		document.write("Back");
	}
}



