/*	DS CONTROLLED FILE.

				*************************************
						EDIT AT YOUR OWN RISK.
				*************************************

  	Avoid using any of these function names in your own javascript (apart from the empty ones -
  	they are only there to prevent errors being displayed).

  	Reusing these function names WILL lead to unexpected issues which the helpdesk will be
  	unable to resolve.

*/

/////////////////////////////////////////////////////////////////////////////////////////////////

/*	Redefine these functions to perform the tasks you wish. They are only present to prevent
	"Object expected" errors being generated by the browser.
	There is no function actually required for DServe ro function in any of the empty scripts.
*/


function StartUpScript() {
	// EMPTY STARTUP script,  redefine in UserDefined.js or <scriptname>.js
	// Used as OnLoad() function most pages.
}
function LoginFailed() {
	// EMPTY LoginFailed script,  redefine in UserDefined.js or loginchk.js
	// Runs when login attempt fails.
}

function LoginOK() {
	// EMPTY LoginOK script,  redefine in UserDefined.js or loginchk.js
	// Runs when login attempt succeeds.
}

function CheckForm() {
	// EMPTY CheckForm script,  redefine in UserDefined.js or <scriptname>.js
	// Runs on submission of form generated by DS script ONLY. If the form is not standard, it could be anything.
}


/////////////////////////////////////////////////////////////////////////////////////////////////
// AVOID USING FUNCTION NAMES BELOW HERE.

function Focus() { document.forms[0].elements[0].focus() }

function OpenPopup(x, y ,href, i, scr) {
	if(scr == "No") {
		var newwin = window.open(href, "PopUp", "left=0,top=0,width="+x+",height="+y+",scrollbars=No");
	} else {
		var newwin = window.open(href, "PopUp", "left=0,top=0,width="+x+",height="+y+",scrollbars");
	}
	newwin.opener = self;
}

function CloseAuthority(txt,fld) {
	var x = "window.opener.document.SearchForm."+fld+".value = '"+txt+"'"
	eval(x);
	self.close();

}

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function CheckCookies() {
	if(document.cookie == '') {
		document.cookie = 'KILL_acook=yes';
		if(document.cookie == '') {
			alert("Your browser doesn't accept cookies!  Returning to menu");
			self.location.href=document.referrer;
			return 0 ; // set cookie failed - return to calling page
		}
	}
	// kill test cookie
	document.cookie = "KILL_acook=''; expires=Fri, 13-Apr-1970 00:00:00 GMT"
	return 1; // cookie already exists
}

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;
}
function KillCookie(x) {
	document.write("Killing: "+x+"=''; expires=Fri, 13-Apr-1970 00:00:00 GMT");
}

function Page(x,m) {
 	var c = document.PageNum.PageCt.value;
	c = eval(c + x)
	if (c<1) { var c = 1}
	if (c>m) { var c = m }
	document.PageNum.PageCt.value=c;
}

function ChangePage(app,srvr,ini,db,srch,max,cnt) {
	var c = document.PageNum.PageCt.value;
	if (c < 2) { c = 2 }
	if (eval(max - c) < 0) { c = max }
	var c = ((c-1) * cnt) + 1
	var h = window.opener
	var r = h.location.href
	var pos = r.split("?")
	hr = pos[0]+'?dsqServer='+srvr+'&dsqApp='+app+'&dsqDb='+db+'&dsqCmd=Overview.tcl'+'&dsqPos='+c
	h.location.href = hr
	self.close()
}

function ChangeRecord(app,srvr,ini,db,srch,max,cnt) {
	var c = document.PageNum.PageCt.value;
	if (c < 2) { c = 2 }
	if (eval(max - c) < 0) { c = max }

	var h = window.opener
	var r = h.location.href
	var pos = r.split("?")
	hr = pos[0]+'?dsqServer='+srvr+'&dsqApp='+app+'&dsqDb='+db+'&dsqCmd=Show.tcl'+'&dsqPos='+c+'&dsqSearch='+srch
	h.location.href = hr
	self.close()
}

function popnamed(href,tgt) {
	if (tgt=="_top") {
		// ignore click.  treat as plain link
		self.location=tgt
	} else {
		// open new window called 'tgt'
		window.open(href,tgt)
		return true
	}
}



