//
// Framework
//

//alert("loading frmwrk.js ...");

// set to generate messages
var fDebugMsg=0;
var fErrorMsg=1;

// variables for Session
var stSessionID="";

function DebugMsg(Msg) {
  if (fDebugMsg)
    alert("DEBUG :" + Msg);
}

function ErrorMsg(Msg) {
  if (fErrorMsg)
    alert("ERROR : " + Msg);
}


// Write to document function
function w(m) {
  m = "" + m + ""; //  Make sure that the m variable is a string.
  if ("undefined" != m) { // Test for empty write or other undefined item.
    document.write(m);
  }
}


// set the style of a document-object
function SetStyle(stID,stStyle) {
  for ( var i=0 ; i <= document.all.length-1 ; ++i ) {
    stringrep = document.all[i];
    if (stringrep.id == stID) {
      stringrep.className=stStyle;
    }
  }
}

// change an image
function SetImage(hDoc,stID,stImagePath) {
  for ( var i=0 ; i <= hDoc.all.length-1 ; ++i ) {
    stringrep = hDoc.all[i];
    if (stringrep.id == stID) {
      stringrep.src=stImagePath;
    }
  }
}


// get an object-handle
function GetObjectHandle(hDoc,stID) {
  for ( var i=0 ; i <= hDoc.all.length-1 ; ++i ) {
    stringrep = hDoc.all[i];
    if (stringrep.id == stID) {
      return stringrep;
    }
  }
}

function GetObj(ObjName) {
  var hObj;
  eval("hObj=self."+ObjName);
  return hObj;
}

  //
  // URL-History Framework
  //
  var History=new Array();
  var aktHist=0;

  function PushURL(stURL) {
    History[aktHist]=new String(stURL);
    aktHist++;
  }

  function PopURL() {
    if (aktHist==0) return "";
    aktHist--;
    return History[aktHist];
  }

  function ClearURL() {
    aktHist=0;
  }


//
// Date conversion
//

function GetDateFromISO(DateField) {
  var isoDte= DateField.value;
  var aDte=isoDte.split("-");
  DateField.value=aDte[2]+"."+aDte[1]+"."+aDte[0];
}

function SetDateToISO(DateField) {
  var Dte= DateField.value;
  var aDte=Dte.split(".");
  DateField.value=aDte[2]+"-"+aDte[1]+"-"+aDte[0];
}

function DateFromISO(stDate) {
  if (stDate=="")
    return "";
  var aDte=stDate.split("-");
  if ((aDte[2]=="01") && (aDte[1]=="01") && (aDte[0]=="0001"))
    return "";
  return aDte[2]+"."+aDte[1]+"."+aDte[0];
}

function GetToday8() {
  var d,m;
  d = new Date();
	var s=""+d.getYear();
	s=s.substring(2,s.length);
	m=d.getMonth()+1;
	if (m<10)
	  s+="0"+m;
	else
	  s+=m;
	m=d.getDate();
	if (m<10)
	  s+="0"+m;
	else
	  s+=m;
	return s;	
}

//
// Field validation
//

function CheckBlank(ObjName) {
  var hObj=GetObj(ObjName);
  if (hObj.value=="") {
    return true;
  }
  return false;
}

function CheckDate(ObjName) {
  var hObj=GetObj(ObjName);

  return false;
}

// Page generation
function OpenPage(hDoc) {

  hDoc.open();
  hDoc.write("<html><head>");
  hDoc.write("<link rel='stylesheet' href='styles/hstyles.css' type='text/css' >");
  hDoc.write("</head>");
  hDoc.write("<body bgcolor='white' leftmargin='5' topmargin='5' marginwidth='0' marginheight='0'>\n");
}

function ClosePage(hDoc) {
  hDoc.write("\n</body>\n</html>\n");
  hDoc.close();
}


