/* FUNCTIONS USED IN DIARY */


isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;

function dLine (dRecId) {
  this.update = '';
  this.recid = dRecId;
}

// Set update indicator for row

function setUpdate(j) {
  dLnA[j].update = 'Y';
  changesMade=1;
} 

/* Open pop-up profile window */

function showProfile(RID,URL) {
  var winName = 'p' + RID;
  var features = 'resizable=yes,width=698,height=570,scrollbars=yes';
  URL += '?POPRID=' + RID; 
  window.open(URL,winName,features);
}

/* Check update indicator for lines that have changed. Concatenate Record Id, Comment fields and,
   status of the block/unblock indicator for lines that have changed */

function loadString() {
 var sndStrP="";
 var mQ="(^)";
 var eQ="(|)";
 var nowtime = new Date();

 for (var i=0; i<dLnT; i++){
    if (dLnA[i].update=="Y") {
       sndStrP += dLnA[i].recid + mQ;
       sndStrP += document.editForm['c'+i].value + mQ;
       if (document.editForm['h'+i]) {
          sndStrP += document.editForm['h'+i].value + eQ;
       } else {
          sndStrP += "U" + eQ;
       }
    }
  }
 document.subForm.diaryStr.value = sndStrP;
 document.subForm.UF.value = nowtime.getMinutes() +  nowtime.getSeconds();
 MainSubmit('subForm');
}

function addUFSub() {
 var nowtime = new Date();
 document.subForm.UF.value = nowtime.getMinutes() +  nowtime.getSeconds();
 MainSubmit('subForm');
}

function createCookie(name,value,days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        expires = "; expires="+date.toGMTString();
    }
    else
        expires = "";

    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}

// DSLoginForm specific code
var cookie_un = 'ds_user_name';
var cookie_pd = 'ds_pwd';

function processSaveUserCh()
{
    if ( document.loginForm.RememberMe.checked ) {
        createCookie(cookie_un, document.loginForm.MyUserID.value, 90);
        createCookie(cookie_pd, document.loginForm.MyPwd.value, 30);
    } else {
        eraseCookie(cookie_un);
        eraseCookie(cookie_pd);
    }

    return true;
}

function processRestoreUserCh()
{
    if ( readCookie(cookie_un) != undefined && readCookie(cookie_un).length > 0 ) {
        document.loginForm.MyUserID.value = readCookie(cookie_un);
        if ( readCookie(cookie_pd) != undefined && readCookie(cookie_pd).length > 0 )
            document.loginForm.MyPwd.value = readCookie(cookie_pd);
        document.loginForm.RememberMe.checked = true;
        document.loginForm.MyPwd.focus();
    } else {
        document.loginForm.RememberMe.checked = undefined;
        if(document.loginForm.MyUserID.value != "")
            document.loginForm.MyPwd.focus();
         else
            document.loginForm.MyUserID.focus();
    }
}

function isIntegerInRange (s, a, b)
{
	if (isEmpty(s))
	if (isIntegerInRange.arguments.length == 1) return false;
	else return (isIntegerInRange.arguments[1] == true);

	if (!isInteger(s, false)) return false;

	var num = parseInt (s);
	if (b == null)
		return (num >= a);
	else if (a == null)
		return (num <= b);
	else
		return ((num >= a) && (num <= b));
}

function isInteger (s)
{
	var i;

	if (isEmpty(s))
	if (isInteger.arguments.length == 1) return 0;
	else return (isInteger.arguments[1] == true);

	for (i = 0; i < s.length; i++)
	{
	var c = s.charAt(i);
	if (!isDigit(c)) return false;
	}

	return true;
}

function isEmpty(s)
{
	return ((s == null) || (s.length == 0))
}

function isDigit (c)
{
	return ((c >= "0") && (c <= "9"))
}

