
var objSelRow = null;
var objSelTable = null;
var SelectedID = -1;

var colHighlight = '#e5e5ff';
var colSelected = '#c0c0ff';
var colList = "#f0f0f0";

var TempImageFolder = 'cpn';

function GetObj(id) {
        if (document.getElementById) { x = document.getElementById(id); }
        else if (document.all) { x = document.all[id]; }
        else if (document.layers) {  x = document.layers[id]; }
        return x
}

function IsMSIE() {
      var ua = window.navigator.userAgent
      var msie = ua.indexOf ( "MSIE " )

      if ( msie > 0 )      // If Internet Explorer, return version number
         return true;//parseInt (ua.substring (msie+5, ua.indexOf (".", msie )))
      else                 // If another browser, return 0
         return false;

}


function InTab( obj, dat ) {
   var s = ';'+dat.toLowerCase()+';';
	var i = s.indexOf( ';'+obj.toLowerCase()+';' );
	if (i > -1) {
	   return true;
	} else {
	   return false;
	}
}

function HasVal( obj, dat ) {
   if (dat) {
	   var s = ';'+dat.toLowerCase()+';';
	   return (s.indexOf( ';'+obj.toLowerCase()+'=' ) > -1);
	} else {
	   return false;
	}
}

function GetVal( obj, dat, def ) {
   var s = ';'+dat.toLowerCase()+';';
	var i = s.indexOf( ';'+obj.toLowerCase()+'=' );
	if (i > -1) {
	   dat = ';'+dat+';';
		s = dat.substr(i+1+obj.length+1);
		i = s.indexOf( ';' );
		if ( i > -1 ) {
			s = s.substr(0,i);
		}
	} else {
	   s = '';
	}
	if ((s == '') && (def)) { s = def; }
	return s;
}

function GetValSep( obj, dat, def, sep ) {
   var s = ""
	if ((dat) && (dat != '')) { 
	   s = sep+dat.toLowerCase()+sep;
		var i = s.indexOf( sep+obj.toLowerCase()+'=' );
		if (i > -1) {
		   dat = sep+dat+sep;
			s = dat.substr(i+1+obj.length+1);
			i = s.indexOf( sep );
			if ( i > -1 ) {
				s = s.substr(0,i);
			}
		} else {
		   s = '';
		}
		if ((s == '') && (def)) { s = def; }
	}
	return s;
}

function GetKey(ev) {
   if (ev.which) {
	   return ev.which;
   } else
	if (ev.keyCode) {
      return ev.keyCode;
   } else {
	   return 0;
	}
}

function CheckEnter(ev) {  
   return (GetKey(ev) == 13);
}

function CancelIfEnter(ev) {  
   if (GetKey(ev) == 13) {
		event.cancelBubble=true;
	}
}

function SetObjVal( obj, dat, def, sep ) {
   if (GetObj(obj)) {GetObj(obj).value = GetValSep(obj,dat,def,sep);}
}

function PrintVal( obj, dat ) {
   document.write( GetVal( obj, dat ) );
}

function DoObjColor(obj,col) {
	obj.bgColor = col;
	obj.style.backgroundColor = col;
}

function DoRowColor(obj,col) {
	DoObjColor(obj,col);
}

function DoHighlightObj(obj,val) {
	if ((obj) && (obj != objSelRow)) {
		if (val) {
			DoObjColor(obj,colHighlight);
		} else {		
			DoObjColor(obj,colList);
		}
	}
}

function DoHighlightRow(obj,val) {
	if ((obj) && (obj != objSelRow)) {
		if (val) {
			obj.className='RowHighLight';
		} else {		
			//obj.className='';		
			obj.className='RowNormal';	
		}
	}
}

function GetRowTable( obj ) {
   if ((obj) && (obj.tagName) && (obj.tagName == 'TR')) {
		obj = obj.parentNode;
		if (!obj) { return null; }
		if ((obj.tagName) && (obj.tagName == 'TABLE')) {			
			return obj;
		} else {
			obj = obj.parentNode;
			if (!obj) { return null; }
			if ((obj) && (obj.tagName) && (obj.tagName == 'TABLE')) {			
				return obj;				
			} else {
				obj = obj.parentNode;
				if (!obj) { return null; }
				if ((obj) && (obj.tagName) && (obj.tagName == 'TABLE')) {			
					return obj;				
				} else {
					obj = obj.parentNode;
					if (!obj) { return null; }
					if ((obj) && (obj.tagName) && (obj.tagName == 'TABLE')) {			
						return obj;				
					} else { return null; }				
				}
			}
		}
	} else { return null; }
}

function SelRow(e) {
	if (objSelRow) {
      objSelRow.className='RowNormal';	
   }
   objSelRow = e;	
   if (objSelRow) {
		objSelRow.className='RowSelected';	
		objSelTable = GetRowTable( e );
      SelectedID = parseInt(objSelRow.id,10);
		if (GetObj('tbSelectOrgInfo')) {			
			DisplayDataOrg( objSelRow.getAttribute('info') );
		} 
		if (GetObj('tbSelectPersonInfo')) {			
			DisplayDataPerson( objSelRow.getAttribute('info') );
		} 
		if ((parent) && (parent.GetObj('adminselorg'))) {
		   parent.SetRemoteButtons(SelectedID);
		}
   } else {
     objSelRow = null;
     SelectedID = -1;
	  objSelTable = null;
   }
	SetButtons();
}

function SelRowNone() {
	SelRow(null);
}

function SelectTableRowByID(id,tObj) {
   if (id == -1) {
      SelRow(null);
   } else {
      //var tObj = GetObj(tab);
      if ((tObj) && (tObj.rows)) {
         yr = -1;
         for (r = 0; r < tObj.rows.length; r++) {
            if ('' + tObj.rows[r].id == '' + id) {
               yr = r;
            }
         }
         if (yr == -1) {
            SelRow(null);
         } else {
            SelRow(tObj.rows[yr]);
            SetScroll(yr);
         }
      }
   }
}

function CenterRow( r ) {
	if (GetObj('ListDiv')) {
	   var objSelTable = GetRowTable( r );
	   aDiv = GetObj('ListDiv');
      var sScrTop = r.rowIndex * r.clientHeight;
      sScrTop = sScrTop - ((aDiv.clientHeight - r.clientHeight) / 2);
      aDiv.scrollTop = sScrTop ;
	}
}


function SelTableRow(tabid,rowid) {
	var tab = GetObj(tabid);
	//SelectTableRowByID(rowid,tab);
	var i = 0;
	if (tab) {
	   for (i = 0; i < tab.rows.length; i++) {
			if ( (tab.rows[i].id) && (tab.rows[i].id == rowid) ) {
				SelRow(tab.rows[i]);
				CenterRow(tab.rows[i]);				
				break;
			}
		}
	}
}

function SetButtons() {
	
	if (GetObj('btPresentationEdit')) {SetButtonEnabled( GetObj('btPresentationEdit'),((objSelRow) && (objSelTable) && (objSelTable.id == 'tbPresentations')) );}
	if (GetObj('btPresentationDelete')) {SetButtonEnabled( GetObj('btPresentationDelete'),((objSelRow) && (objSelTable) && (objSelTable.id == 'tbPresentations')) );}
	
	if ( GetObj('tbAdminPerson') ) {
		if ( parent.GetObj('btEdit') ) {SetButtonEnabled( parent.GetObj('btEdit'),((objSelRow) && (objSelTable) && (objSelTable.id == 'tbAdminPerson')) );}
		if ( parent.GetObj('btDelete') ) {SetButtonEnabled( parent.GetObj('btDelete'),((objSelRow) && (objSelTable) && (objSelTable.id == 'tbAdminPerson')) );}
		if ( parent.GetObj('btRegOK') ) {SetButtonEnabled( parent.GetObj('btRegOK'),((objSelRow) && (objSelRow.Status) && ((objSelRow.Status == '') || (objSelRow.Status == '0') || (objSelRow.Status == '3')) && (objSelTable) && (objSelTable.id == 'tbAdminPerson')) );}
		if ( parent.GetObj('btRegNo') ) {SetButtonEnabled( parent.GetObj('btRegNo'),((objSelRow) && (objSelRow.Status) && ((objSelRow.Status == '2') || (objSelRow.Status == '0') || (objSelRow.Status == '')) && (objSelTable) && (objSelTable.id == 'tbAdminPerson')) );}
		if ( parent.GetObj('Person_ID') ) { parent.GetObj('Person_ID').value = SelectedID;}
		if ( parent.GetObj('UserID') ) { parent.GetObj('UserID').value = objSelRow.UserID;}
	}
	if ( GetObj('tbAdminOrg') ) {
		if ( parent.GetObj('btEdit') ) {SetButtonEnabled( parent.GetObj('btEdit'),((objSelRow) && (objSelTable) && (objSelTable.id == 'tbAdminOrg')) );}
		if ( parent.GetObj('btDelete') ) {SetButtonEnabled( parent.GetObj('btDelete'),((objSelRow) && (objSelTable) && (objSelTable.id == 'tbAdminOrg')) );}
		if ( parent.GetObj('Org_ID') ) { parent.GetObj('Org_ID').value = SelectedID;}
	}
	if ( GetObj('tbSystemAdmin') ) {
		if ( GetObj('btEdit') ) {SetButtonEnabled( GetObj('btEdit'),((objSelRow) && (objSelTable) && (objSelTable.id == 'tbSystemAdmin')) );}
		if ( GetObj('btDelete') ) {SetButtonEnabled( GetObj('btDelete'),((objSelRow) && (objSelTable) && (objSelTable.id == 'tbSystemAdmin')) );}
	}
}

function SetButtonEnabled(e,val) {
   if (e) {
      e.disabled = (!val);
      if (e.children[0]) {
         SetImageEnabled(e.children[0],val);
      }
   }
}

function SetImageEnabled(e,val) {
	var s = '' + e.src;
   var i = s.indexOf('_disabled');
   if (val) {
		if (i != -1) {
         s = s.substr(0,i) + s.substr(i+9);
         e.src = s;
      }
   } else {
      if (i == -1) {
         i = s.lastIndexOf('.');
         s = s.substr(0,i) + '_disabled' + s.substr(i);
         e.src = s;
      }
   }
}

function LoginBar( Page, UserID, Foretag ) {
var s = "";
   s += "<table width=100% border=0 cellspacing=0 cellpadding=0 ><tr><td height=1>";
	s += "<script>BorderStart('classPrefix=Login_;Size=100')</script>";
	s += "<table width=100% border=0 cellspacing=0 cellpadding=0  >";
	s += "	<tr>";
	s += "		<td valign=top width=*>";	
	s += "			<table border=0 cellspacing=0 cellpadding=0 width=100%>";
	s += "			   <tr>";
	s += "				   <td>";
	s += "					   &nbsp;";
	s += "					</td>";
	s += "				   <td class=LoginHeader >";
	s += "					   Min sida";
	s += "					</td>";
	s += "					<td align=right>";
	s += "					   <table border=0 cellspacing=0 cellpadding=0>";
	s += "							<tr>";
	s += "								<td class=LoginInfo >";
	s += "									Inloggad:&nbsp;"+UserID+",&nbsp;Företag:&nbsp;"+Foretag+"&nbsp;&nbsp;&nbsp;";
	s += "								</td>";
	s += "								<td >";
	s += "									<a href='javascript: DoLogout()' class=LoginLink >Logga ut</a>";
	s += "								</td>";
	s += "							   <td>";
	s += "								   &nbsp;";
	s += "								</td>";
	s += "							</tr>";
	s += "						</table>";
	s += "					</td>";
	s += "				</tr>";
	s += "			</table>";
	s += "      </td>";
	s += "   </tr>";
	s += "</table>";
	s += "<script>BorderEnd()</script>";
	s += "</td></tr></table>";
	document.write( s );
}

function AdminBar( AdminUser ) {
var s = "";
   s += "<table width=100% border=0 cellspacing=0 cellpadding=0 ><tr><td height=1>";
	s += "<script>BorderStart('classPrefix=LoginAdminUser_;Size=100')</script>";
	s += "<table width=100% border=0 cellspacing=0 cellpadding=0  >";
	s += "	<tr>";
	s += "		<td valign=top width=*>";	
	s += "			<table border=0 cellspacing=0 cellpadding=0 width=100%>";
	s += "			   <tr>";
	s += "				   <td>";
	s += "					   &nbsp;";
	s += "					</td>";
	s += "				   <td class=LoginHeader >";
	s += "					   Min sida";
	s += "					</td>";
	s += "					<td align=right>";
	s += "					   <table border=0 cellspacing=0 cellpadding=0>";
	s += "							<tr>";
	s += "								<td class=LoginInfo >";
	s += "									Inloggad:&nbsp;"+UserID+",&nbsp;Företag:&nbsp;"+Foretag+"&nbsp;&nbsp;&nbsp;";
	s += "								</td>";
	s += "								<td >";
	s += "									<a href='javascript: DoLogout()' class=LoginLink >Logga ut</a>";
	s += "								</td>";
	s += "							   <td>";
	s += "								   &nbsp;";
	s += "								</td>";
	s += "							</tr>";
	s += "						</table>";
	s += "					</td>";
	s += "				</tr>";
	s += "			</table>";
	s += "      </td>";
	s += "   </tr>";
	s += "</table>";
	s += "<script>BorderEnd()</script>";
	s += "</td></tr></table>";
	//s += BorderEndVal();
	document.write( s );
}



function HideLayer(){
   GetObj('layNoClick').innerHTML="";
   GetObj('layTemp').innerHTML="";
	
	if (GetObj('ifComboBlocker')) {GetObj('ifComboBlocker').style.display = 'none';}
}

function HideMessLayer(){
   if (GetObj('messNoClick')) {
		GetObj('messNoClick').innerHTML="";
	} else {
	   GetObj('layNoClick').innerHTML="";
	}
   if (GetObj('messTemp')) {
		GetObj('messTemp').innerHTML="";
	} else {
      GetObj('layTemp').innerHTML="";
	}
	if (GetObj('ifComboBlocker')) {GetObj('ifComboBlocker').style.display = 'none';}
}

function ShowLayerCentered( what, obj, offLeft, offTop, useWidth, useHeight, mess ) {

   		
	if ((mess) && (GetObj('messTemp'))) {
	var idlayTemp = 'messTemp';	
	} else {
	var idlayTemp = 'layTemp';	
	}
	var objlayTemp = GetObj(idlayTemp);	
	objlayTemp.innerHTML=what;	
	
	var bMSIE = IsMSIE();
	
   var oX = 0;	
   var oY = 0;			
   var oNoL = 0;	
   var oNoT = 0;		
   var oNoW = 0;	
   var oNoH = 0;		
	var dims = totalElementXYOffset(objlayTemp);	
	
	
	if (!bMSIE) { 
	   var BorderTable = null;
		if (objlayTemp.getElementById) { BorderTable = objlayTemp.getElementById('tbBorderTable'); } else 
		if (objlayTemp.all) { BorderTable = objlayTemp.all['tbBorderTable']; } else
		if (objlayTemp.getElementsByTagName) { BorderTable = objlayTemp.getElementsByTagName('TABLE')[0];	}
		if (objlayTemp) {
			if (!useWidth) {useWidth = BorderTable.clientWidth;}
			if (!useHeight) {useHeight = BorderTable.clientHeight;}
		} else {
			if (!useWidth) {useWidth = dims.w;}
			if (!useHeight) {useHeight = dims.h;}
		}
	} else {	
	   if (!useWidth) {useWidth = dims.w;}
	   if (!useHeight) {useHeight = dims.h;}
	}
	if (obj) {
		var dimsc = totalElementXYOffset(obj);
		if (dimsc.h < document.body.clientHeight) {
		   oY = (dimsc.h - useHeight) / 2;
		} else {
			oY = (document.body.clientHeight - useHeight) / 2;
			oY = oY + document.body.scrollTop;			
		}
		//alert('oh: '+document.body.offsetHeight+' ch: '+document.body.clientHeight+' dech: '+document.documentElement.clientHeight+' sc: '+document.body.scrollTop+' oy: '+oY);
		if (dimsc.w < document.body.clientWidth) {
		   oX = (dimsc.w - useWidth) / 2;		   
		} else {
			oX = (document.body.clientWidth - useWidth) / 2;
			oX = oX + document.body.scrollLeft;
		}	
		//oNoT = dimsc.y;
		oNoH = dimsc.h;
		//oNoL = dimsc.x;
		oNoW = dimsc.w;
		/*oNoW = document.body.clientWidth;
		oNoH = document.body.clientHeight;*/
		//alert('pl: '+oX+'pt: '+oY+'ow: '+dimsc.w+' oh: '+dimsc.h+' lw: '+useWidth+' lh: '+useHeight+' cw: '+document.body.clientWidth+' ch: '+document.body.clientHeight);
	} else {
	   oY = (document.body.clientHeight - useHeight) / 2;
	   oX = (document.body.clientWidth - useWidth) / 2;
	   //oY = (document.body.offsetHeight - useHeight) / 2;
	   //oX = (document.body.offsetWidth - useWidth) / 2;
		oNoW = document.body.offsetWidth;
		oNoH = document.body.offsetHeight;
	}	
	
	if (bMSIE) {
		if (GetObj('dtop')) {
		   oNoW = GetObj('dtop').clientWidth;
		   oNoH = GetObj('dtop').clientHeight;
		}
	} else {	
		if (GetObj('dtop')) {
			dims = totalElementXYOffset(GetObj('dtop'));
			oNoW = dims.w;
			oNoH = dims.h;
			oNoL = dimsc.x;
		   oNoT = dimsc.y;
		}
	}
	
	if (offTop) { oY = oY + offTop; }
	if (offLeft) { oX = oX + offLeft; }	
	
	if (oX < 0) { oX = 0; }
	if (oY < 0) { oY = 0; }
   eval(idlayTemp+".style.left="+oX); 
	eval(idlayTemp+".style.top="+oY);
	
	/*var oNoClick = null;
	if ((mess) && (GetObj('messNoClick'))) {
		oNoClick = GetObj('messNoClick');
	} else
	if  (GetObj('layNoClick')) {
		oNoClick = GetObj('layNoClick');
	}
	
	if (oNoClick) {
		oNoClick.innerHTML = "<div class=DivNoClick style='left:"+oNoL+"px;top:"+oNoT+"px;width:"+oNoW+"px;height:"+oNoH+"px;' >&nbsp;</div>"; 
		oNoClick.style.left=oNoL; 
		oNoClick.style.top=oNoT;
	}*/
	
	var idNoClick = 'layNoClick';	
	
	if ((mess) && (GetObj('messNoClick'))) {
		idNoClick = 'messNoClick';
	}
	
	GetObj(idNoClick).innerHTML = "<div class=DivNoClick style='left:"+oNoL+"px;top:"+oNoT+"px;width:"+oNoW+"px;height:"+oNoH+"px;' >&nbsp;</div>"; 
   eval(idNoClick+".style.left="+oNoL); 
	eval(idNoClick+".style.top="+oNoT);
	
	if (GetObj('ifComboBlocker')) {
		var iframe = GetObj('ifComboBlocker');
		iframe.style.display = 'block';
		iframe.style.width = oNoW; //GetObj(idNoClick).style.width;
		iframe.style.height = oNoH; //GetObj(idNoClick).style.height;
		iframe.style.top = oNoT; //GetObj(idNoClick).style.top;
		iframe.style.left = oNoL;//GetObj(idNoClick).style.left;
		//alert(iframe.style.display);
		//iframe.style.zIndex = GetObj(idNoClick).style.top;
		//iframe.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		//eval("ifComboBlocker.style.left="+oNoL); 
	   //eval("ifComboBlocker.style.top="+oNoT);
	}

	/*
	if ((mess) && (GetObj('messTemp'))) {
		GetObj('messNoClick').innerHTML = "<div class=DivNoClick style='left:"+oNoL+"px;top:"+oNoT+"px;width:"+oNoW+"px;height:"+oNoH+"px;' >&nbsp;</div>"; 
      eval("messNoClick.style.left="+oNoL); 
	   eval("messNoClick.style.top="+oNoT);
	} else {
	   GetObj('layNoClick').innerHTML = "<div class=DivNoClick style='left:"+oNoL+"px;top:"+oNoT+"px;width:"+oNoW+"px;height:"+oNoH+"px;' >&nbsp;</div>"; 
      eval("layNoClick.style.left="+oNoL); 
	   eval("layNoClick.style.top="+oNoT);
	}
	*/
	
	
}

function totalElementXYOffset(obj){
    var xOffset, yOffset, iHeight, iWidth, elParent;
    yOffset = 0;
    xOffset = 0;
    iWidth = 0;
    iHeight = 0;
    if(obj){
        if(typeof obj.offsetTop == 'number'){
            yOffset = obj.offsetTop||0;
            xOffset = obj.offsetLeft||0;
            iWidth = obj.offsetWidth||0;
            iHeight = obj.offsetHeight||0;
            elParent = obj.offsetParent;
            while(elParent){
                yOffset += elParent.offsetTop||0;
                xOffset += elParent.offsetLeft||0;
                elParent = elParent.offsetParent;
            }
        }else if(typeof obj.top == 'number'){ //some Net 4 DIVs
            yOffset = obj.top;
            xOffset = obj.left;
            iWidth = obj.width;
            iHeight = obj.height;
        }else if(typeof obj.y == 'number'){  //Net 4 IMG & A
            yOffset = obj.y;
            xOffset = obj.x;
            iWidth = 0;
            iHeight = 0;
        }else{      //information is not available
            return null;
        }
        return {x:xOffset,y:yOffset,w:iWidth,h:iHeight};
    }
}

var frDataInitiated = false;
var lastCheckRegisterMail = '';
var lastCheckOrg_name = '';

function CheckRegisterMail() {
	if (!GetObj('Email')) { return false;}
	var email = GetObj('Email').value;
	if (email == '') { return false;}
	//if (email == lastCheckRegisterMail) { return false;}
	
	lastCheckRegisterMail = email;
	//if (!GetObj('Person_ID')) { return false;}
	//if (GetObj('Person_ID').value != '') { return false;}
	
	var iFr = GetObj('frData');
	var lay = 'main.asp?proc=checkregistermail&';
   lay += "Email=" + email +"&";
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	iFr.init = 1;
	iFr.proc = 'CheckRegisterMail';
	//alert(lay);
	iFr.src = lay;
	return false;
	
	/*var iFr = GetObj('frData');
	var lay = 'main.asp?proc=getsqlrecord&';
	var flds = "Person.*, org_name, Country, Department, VAT, Address1, Address2, City, State, ZIPCode";
   lay += "sql=" + "select "+flds+" from person left join Organisation ON Person.Org_ID=Organisation.Org_ID where Person.email like '"+email+"' &";
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	iFr.init = 1;
	iFr.proc = 'CheckRegisterMail';
	iFr.src = lay;
	return false;*/
}

function CheckRegisterMailResult( info ) {
	//alert(info);
	if (info == '') { return false;}
	
   if (info != '') {	
      GetObj('btSelectPerson').disabled = false;
		SelectPerson( info );		
	} else {
	   FillPersonData( info );
	}
}

function FillPersonData( info ) {
	SetObjVal( 'Person_ID', info, '', 'ū' );
	SetObjVal( 'Org_ID', info, '', 'ū' );
	
	
	SetObjVal( 'Firstname', info, '', 'ū' );
	SetObjVal( 'Surname', info, '', 'ū' );
	SetObjVal( 'Title', info, '', 'ū' );
	SetObjVal( 'Profession', info, '', 'ū' );
	
	SetObjVal( 'Mobile', info, '', 'ū' );
	SetObjVal( 'Phone', info, '', 'ū' );
	SetObjVal( 'Fax', info, '', 'ū' );
	
	SetObjVal( 'Get_together_party', info, '', 'ū' );
	SetObjVal( 'OneDay', info, '', 'ū' );
	
	
	SetObjVal( 'Org_name', info, '', 'ū' );
	SetObjVal( 'Country', info, '', 'ū' );
	SetObjVal( 'Department', info, '', 'ū' );
	SetObjVal( 'VAT', info, '', 'ū' );
	SetObjVal( 'Address1', info, '', 'ū' );
	SetObjVal( 'Address2', info, '', 'ū' );
	SetObjVal( 'City', info, '', 'ū' );
	SetObjVal( 'State', info, '', 'ū' );
	SetObjVal( 'ZIPCode', info, '', 'ū' );
	
	var pres = GetValSep( 'Presentations', info, '', 'ū' );
	if (pres != '') {
	   //alert(pres);
		var arDB = pres.split(/\?/);
		var ar = '';
		var i = 0;
		//var pid = GetValSep( 'Person_ID', info, '', 'ū' );
		for (i = 0; i < arDB.length; i++) {
			ar = arDB[i].split(/\;/);
			AddPresentation( ar[0], ar[1], ar[2], ar[3] );
		}
		//pres = pres.replace(/\?/g,'˙');
	   //pres = pres.replace(/\;/g,'ū');
	}
	
	SetObjVal( 'Stand_Size', info, '', 'ū' );
}

function AddPresentation( pid, tit, typ, ses ) {

	var tab = GetObj('tbPresentations');

	oTR = tab.insertRow(-1);
	oTR.id = pid;
	oTR.style.cursor='Hand';
	oTR.onclick = function(){SelRow(this);}; 
	oTR.onmouseover = function(){DoHighlightRow(this,true);} 
	oTR.onmouseout = function(){DoHighlightRow(this,false);}
	oTR.ondblclick = function(){EditPresentation(0);}

	oTD = oTR.insertCell(-1);
	oTD.width = 300;
	oTD.innerHTML = tit;

	oTD = oTR.insertCell(-1);
	oTD.width = 100;
	if (typ == 1) {	oTD.innerHTML = 'Poster'; } else { oTD.innerHTML = 'Paper'; }

	oTD = oTR.insertCell(-1);
	oTD.style.borderRightWidth = 1;
	oTD.innerHTML = ses;
}

function CheckOrg_name2(obj) {
	if (!obj) { obj = GetObj('Org_name'); }
	if (!obj) { return false;}
	var Org_name = obj.value;
	if (Org_name == '') { return false;}
	//if (Org_name == lastCheckOrg_name) { return false;}
	
	lastCheckOrg_name = Org_name;
	
	var iFr = GetObj('frData');
	if (!iFr) { alert('fel'); return false; }
	var lay = 'main.asp?proc=getsqlrecord&';
   lay += "sql=" + "select * from Organisation wxhxexrxe Org_name like '"+Org_name+"' &";
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	iFr.init = 1;
	iFr.proc = 'CheckOrg_name';
	alert(lay);
	iFr.src = lay;
	return false;
}



function SelectOrgID() {
	var iFr = GetObj('frData');
	if (!iFr) { alert('fel'); return false; }
	var lay = 'main.asp?proc=selectorgid&';
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	iFr.init = 1;
	iFr.proc = 'SelectOrgID';
	alert(lay);
	iFr.src = lay;
	return false;
}

function SelectOrgIDResult( info ) {
	if (info == '') { return false;}
	
	if (info.substr(0,7) == 'Error: ') {
		ShowMess( info.substr(7), 'Error' );
		return false;
	}
	var ar = info.split("˙");
   if (ar.length > 0) {	
	   GetObj('btSelectOrg').disabled = false;
		SelectOrg( info );	
	} 
}

function CheckOrg_name(obj) {
	if (!obj) { obj = GetObj('Org_name'); }
	if (!obj) { return false;}
	var Org_name = obj.value;
	if (Org_name == '') { return false;}
	//if (Org_name == lastCheckOrg_name) { return false;}
	
	lastCheckOrg_name = Org_name;
	
	var iFr = GetObj('frData');
	if (!iFr) { alert('fel'); return false; }
	var lay = 'main.asp?proc=checkorg_name&';
   lay += "Org_name=" + Org_name + "&";
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	iFr.init = 1;
	iFr.proc = 'CheckOrg_name';
	alert(lay);
	iFr.src = lay;
	return false;
}

function CheckOrg_nameResult( info ) {
	if (info == '') { return false;}
	
	if (info.substr(0,7) == 'Error: ') {
		ShowMess( info.substr(7), 'Error' );
		return false;
	}
	var ar = info.split("˙");
   if (ar.length > 0) {	
	   GetObj('btSelectOrg').disabled = false;
		SelectOrg( info );	
	} 
}

function GetSQL(sql) {
	var iFr = GetObj('frData');
	var lay = 'main.asp?proc=getsql&';
   //lay += "sql=\"" + sql + "\"&";
   lay += "sql=" + sql + "&";
   lay += "fieldnames=" + '1' + "&";
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	iFr.init = 1;
	iFr.proc = 'getsql';
	iFr.src = lay;
	return false;
}

function CheckLogin() {
	if (!GetObj('UserID')) { return false;}
	if (!GetObj('Password')) { return false;}
	
	var iFr = GetObj('frData');
	var lay = 'main.asp?proc=login&';
   lay += "UserID=" + GetObj('UserID').value + "&";
   lay += "Password=" + GetObj('Password').value + "&";
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	iFr.init = 1;
	iFr.proc = 'CheckLogin';
	iFr.src = lay;
	return false;
}

function DoLogout() {	
	var lay = 'main.asp?proc=logout&';
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	window.location.href = lay;
	return false;
}

function DoStart() {	
	var lay = 'main.asp?proc=start&';
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	//alert(lay);
	window.location.href = lay;
	return false;
}

function DoChangePassword() {
	//if (!GetObj('CurrPass')) { return false;}
	if (!GetObj('NewPass1')) { return false;}
	if (!GetObj('NewPass2')) { return false;}
	
	if (GetObj('NewPass1').value != GetObj('NewPass2').value) {
		alert( '[Nytt lösenord] och [Ange lösenord igen] är olika.' );
		return false;
	}
	
	var iFr = GetObj('frData');
	var lay = 'main.asp?proc=changepassword&';
   lay += "NewPassword=" + GetObj('NewPass1').value + "&";
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	iFr.init = 1;
	iFr.proc = 'ChangePassword';
	iFr.src = lay;
	return false;
}

function DoChangeUserID() {
	if (!GetObj('NewEmail')) { return false;}
	
	if (GetObj('NewEmail').value == GetObj('Email').value) {
		HideLayer();
		return false;
	}
	
	var iFr = GetObj('frData');
	var lay = 'main.asp?proc=changeuserid&';
   lay += "NewUserID=" + GetObj('NewEmail').value + "&";
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	iFr.init = 1;
	iFr.proc = 'ChangeUserID';
	iFr.src = lay;
	return false;
}

function DoDeletePerson() {
	HideLayer();
	if (!GetObj('Person_ID')) { return false;}
	
	if (GetObj('Person_ID').value == '') {
		HideLayer();
		return false;
	}
	
	var iFr = GetObj('frData');
	var lay = 'main.asp?proc=deleteperson&';
   lay += "Person_ID=" + GetObj('Person_ID').value + "&";
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	
	alert(lay);
	iFr.init = 1;
	iFr.proc = 'DeletePerson';
	iFr.src = lay;
	return false;
}

function DeletePersonResult( info ) {
	if (info == '') {
	   ShowMess( 'OK - Person has been deleted' );
	} else {
	   ShowMess( info );
	}
}


function ChangePasswordResult( info ) {
	//alert(info);
	if (info == '') {
	   HideLayer();
		ShowMess( 'OK - lösenordet har ändrats.' );
	} else {
	   HideLayer();
		ShowMess( info );
	}
}



function ChangeChangeUserIDResult( info ) {
	if (info == '') {
	   ShowMess( 'OK - email has been changed.' );
	} else {
	   ShowMess( info );
	}
}

function DoSendNewPassword() {
	if (!GetObj('UserID')) { return false;}
	
	if (GetObj('UserID').value == '') {
		ShowMess('Please enter your email address');
		GetObj('UserID').focus();
		return false;
	}
	
	var iFr = GetObj('frData');
	var lay = 'main.asp?proc=sendnewpassword&';
   lay += "UserID=" + GetObj('UserID').value + "&";
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	iFr.init = 1;
	iFr.proc = 'SendNewPassword';
	iFr.src = lay;
	return false;
}

function SendNewPasswordResult( info ) {
	//alert(info);
	if (info == '') {
	   HideLayer();
		ShowMess( 'OK - a new password has been sent to your email address.' );
	} else if (info.substr(0,6) == 'Mail: ') {
	   HideLayer();
		ShowMess( info.substr(6), 'Mail', 600 );
	} else {
	   ShowMess( info );
	}
}

function OrgFilter() {
	//if (!obj) { obj = GetObj('Org_name'); }
	//if (!obj) { return false;}
	//var Org_name = obj.value;
	//if (Org_name == '') { return false;}
	
	
	var iFr = GetObj('frData');
	if (!iFr) { alert('fel'); return false; }
	var lay = 'main.asp?proc=orgfilter&';
   //lay += "Org_name=" + Org_name + "&";
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	iFr.init = 1;
	iFr.proc = 'OrgFilter';
	alert(lay);
	iFr.src = lay;
	return false;
}

function OrgFilterResult( info ) {
	if (info == '') { return false;}
	
	if (info.substr(0,7) == 'Error: ') {
		ShowMess( info.substr(7), 'Error' );
		return false;
	}
	var ar = info.split("˙");
   if (ar.length > 0) {	
		SelectOrg( info );	
	} 
}

function DataLoaded(iFr) {
	var info = '';
	if (iFr) {
		var init = iFr.init;
		var proc = iFr.proc;	
		
		if (init > 0) {
			info = frames['frData'].document.body.innerHTML;
			if (proc == 'CheckRegisterMail') {
				CheckRegisterMailResult( info );
			} else 
			if (proc == 'CheckOrg_name') {
				CheckOrg_nameResult( info );
			} else 
			if (proc == 'SelectOrgID') {
				SelectOrgIDResult( info );
			} else 
			if (proc == 'CheckLogin') {
				CheckLoginResult( info );
			} else  
			if (proc == 'ChangePassword') {
				ChangePasswordResult( info );
			} else  
			if (proc == 'ChangeUserID') {
				ChangeChangeUserIDResult( info );
			} else   
			if (proc == 'DeletePerson') {
				DeletePersonResult( info );
			} else  
			if (proc == 'SendNewPassword') {
				SendNewPasswordResult( info );
			} else  
			if (proc == 'AdminEditLogin') {
				AdminEditLoginResult( info );
			} else  
			if (proc == 'AdminDeleteLogin') {
				AdminDeleteLoginResult( info );
			} else  
			if (proc == 'OrgFilter') {
				OrgFilterResult( info );
			} else 
			if (proc == 'RegOK') {
				RegOKResult( info );
			} else 
			if (proc == 'RegNo') {
				RegNoResult( info );
			} else 
			{
			
			alert('2:'+info);
			//var ar = info.split("\t");
			var ar = info.split("˙");
			alert('t:'+ar.length);
			
			}
		}
	}	
}

function ImportImageSubmit(iFr) {
	GetObj('frImportImageData').init = 1;
	return true;
}

function ImportImageExDataLoaded(iFr) {
	var info = '';
	if (iFr) {
		var init = iFr.init;
		var proc = iFr.proc;	
		if (init > 0) {
			info = frames['frImportImageData'].document.body.innerHTML;
			//alert(info);
			if (HasVal('FileSize',info)) {
			   //if (parent.GetObj('TempFilename')) {parent.GetObj('TempFilename').value = '';}
				var oPho = GetObj('imImportImage');
				if (oPho) {
				   var fil = TempImageFolder+'/'+GetVal('Filename',info);
					//alert(fil);
					oPho.src = fil;
				}	
			} else {
			   //if (parent.GetObj('TempFilename')) {parent.GetObj('TempFilename').value = '';}
				alert(info);
				window.location.reload();
			}
		}
	}	
}

function ImportImageDataLoaded(iFr) {
	var info = '';
	if (iFr) {
		var init = iFr.init;
		var proc = iFr.proc;	
		if (init > 0) {
			info = frames['frImportImageData'].document.body.innerHTML;
			//alert(info);
			if (info.substr(0,7) == 'Error: ') {
			   alert(info);
				window.location.reload();
			} else {			
			   var oPho = GetObj('imImportImage');
				if (oPho) {
		         //alert(oPho);
				   oPho.src = 'parseImageData.asp?proc=temp&cashkiller=' + Date.parse(new Date().toString());
		         //alert(oPho.src);
				}	
			}
		}
	}	
}

function imExLoaded(im) {
	parent.GetObj('TempZ').value = im.width / im.height;
	parent.GetObj('TempW').value = im.width;
	parent.GetObj('TempH').value = im.height;
	parent.GetObj('TempFilename').value = im.src;
	parent.CenterAndUpdatePhotoImages();
	window.location.href = 'ImportImageEx.asp';//  .reload();
}

function imLoaded(im) {
	parent.GetObj('TempZ').value = im.width / im.height;
	parent.GetObj('TempW').value = im.width;
	parent.GetObj('TempH').value = im.height;
	parent.GetObj('TempFilename').value = im.src;
	im.src = '';
	parent.CenterAndUpdatePhotoImages();
	window.location.href = 'ImportImage.asp';//  .reload();
}

function AfterIm() {
   var oPho = GetObj('imImportImage');
	alert('w: '+oPho.width+', h: '+oPho.height+', sw: '+oPho.style.width+', sh: '+oPho.style.height);
	oPho.width = 20;
}

function GetFirstPhotoIm() {
var i = 0;
var sKnd = '';

   if (document.all.pho.length) {      
		i = 0;
      while (document.all.pho[i]) {
         sKnd = document.all.pho[i].knd;
			if (sKnd == '') {
				return document.all.pho[i];
			}
			i++;
      }
   } else
   if (document.all.pho) {
      sKnd = document.all.pho.knd;
		if (sKnd == '') {
			return document.all.pho[i];
		}
   }
	
	return null;
}

function DoSelectOrg( DoNew ) {
	if (DoNew) {
		FillOrgData( '' );
	} else {
		if (objSelRow) {
			var info = objSelRow.getAttribute('info');	
			FillOrgData( info );
		}
	}
	HideLayer();
	return false;
}

function DoSelectPerson( DoNew ) {
	if (DoNew) {
		FillPersonData( '' );
	} else {
	   if (objSelRow) {
			var info = objSelRow.getAttribute('info');

			if ( GetObj('CurrentYear') ) {
			   if ( '' + GetValSep( 'Year', info, '', 'ū' ) == '' + GetObj('CurrentYear').value ) {
					DoLogin(GetObj('Email').value);
					return false;
				}
			}
			
			FillPersonData( info );
		}
	}
	HideLayer();
	return false;
}

function DoSelectLoginPerson(  ) {
	
	if (objSelRow) {
		var info = objSelRow.getAttribute('info');
		
		var iFr = GetObj('frData');
		var lay = 'main.asp?proc=login&';
		lay += "Person_ID=" + GetValSep( 'Person_ID', info, '', 'ū' ) + "&";
		lay += "UserID=" + GetValSep( 'Email', info, '', 'ū' ) + "&";
		lay += 'cashkiller=' + Date.parse(new Date().toString());
		//window.location.href = lay;
		
		iFr.init = 1;
		iFr.proc = 'CheckLogin';
		iFr.src = lay;
		return false;
		
	}
	HideLayer();
	return false;
}

function DoRegOK( pid, uid ) {
	if ((GetObj('Person_ID').value == -1)) {
	   ShowMess("Please select the person you want to approve.");
	   return false;
	}
   if ((GetObj('UserID').value == '')) {
	   ShowMess("Please select the person you want to.");
	   return false;
	}
	
	var iFr = GetObj('frData');
	var lay = 'main.asp?proc=regok&';
	lay += "Person_ID=" + GetObj('Person_ID').value + "&";
	lay += "UserID=" + GetObj('UserID').value + "&";
	//lay += "Person_ID=" + pid + "&";
	//lay += "UserID=" + uid + "&";
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	
	iFr.init = 1;
	iFr.proc = 'RegOK';
	iFr.src = lay;
	return false;
}

function RegOKResult( info ) {	
	if (info == '') {
	   if (GetObj('btGet')) { GetObj('btGet').click(); }
	   DoMail('mail=PersonOK');
		//ShowMess( 'OK - email has been sent.' );
	} else if (info.substr(0,8) == 'Params: ') {
	   if (GetObj('btGet')) { GetObj('btGet').click(); }
	   DoMail('mail=PersonOK;'+info.substr(8));
	} else if (info.substr(0,6) == 'Mail: ') {
	   HideLayer();
		ShowMess( info.substr(6), 'Mail', 600 );
	   if (GetObj('btGet')) { GetObj('btGet').click(); }
	} else {	
		ShowMess( info );
		//DoMail( 'mail=NewPassword;password=info' );
	}
	
	
	
}

function DoRegNo( pid, uid ) {
	if ((GetObj('Person_ID').value == -1)) {
	   ShowMess("Please select the person you want to approve.");
	   return false;
	}
   if ((GetObj('UserID').value == '')) {
	   ShowMess("Please select the person you want to.");
	   return false;
	}
	var iFr = GetObj('frData');
	var lay = 'main.asp?proc=regno&';
	lay += "Person_ID=" + GetObj('Person_ID').value + "&";
	lay += "UserID=" + GetObj('UserID').value + "&";
	//lay += "Person_ID=" + pid + "&";
	//if (uid) { lay += "UserID=" + uid + "&"; }
	lay += 'cashkiller=' + Date.parse(new Date().toString());
	
	iFr.init = 1;
	iFr.proc = 'RegNo';
	iFr.src = lay;
	return false;
}

function RegNoResult( info ) {
	if (info == '') {
	   if (GetObj('btGet')) { GetObj('btGet').click(); }
		//ShowMess( 'OK' );
	} else {	
	   ShowMess( info );
	}
}

function FillOrgData( info ) {
	SetObjVal( 'Org_ID', info, '', 'ū' );
	
	SetObjVal( 'Country', info, '', 'ū' );
	SetObjVal( 'Department', info, '', 'ū' );
	SetObjVal( 'VAT', info, '', 'ū' );
	SetObjVal( 'Address1', info, '', 'ū' );
	SetObjVal( 'Address2', info, '', 'ū' );
	SetObjVal( 'City', info, '', 'ū' );
	SetObjVal( 'State', info, '', 'ū' );
	SetObjVal( 'ZIPCode', info, '', 'ū' );
}



function DisplayDataOrg( info ) {	
	if (!GetObj('cellInfo')) { return false; }
	
	var s = '';
	s += "<table>";	
	
	s += "	<tr><td>Org_name<br><b>"+GetValSep('Org_name',info,'','ū')+"</b></td></tr>";
	s += "	<tr><td>Department<br><b>"+GetValSep('Department',info,'','ū')+"</b></td></tr>";
	s += "	<tr><td>Country<br><b>"+GetValSep('Country',info,'','ū')+"</b></td></tr>";
	s += "	<tr><td>Street address<br><b>"+GetValSep('Address1',info,'','ū')+"</b></td></tr>";
	s += "	<tr><td>Postal address<br><b>"+GetValSep('Address2',info,'','ū')+"</b></td></tr>";
	s += "	<tr><td>City<br><b>"+GetValSep('City',info,'','ū')+"</b></td></tr>";
	s += "	<tr><td>ZIP/Postal Code<br><b>"+GetValSep('ZIPCode',info,'','ū')+"</b></td></tr>";
	
	s += "</table>";
	
   GetObj('cellInfo').innerHTML = s;
}

function DisplayDataPerson( info ) {	
	if (!GetObj('cellInfo')) { return false; }
	
	var s = '';
	s += "<table>";	
	
	if (GetValSep('Title',info,'','ū') != '') { s += "	<tr><td>Title<br><b>"+GetValSep('Title',info,'','ū')+"</b></td></tr>"; }
	if (GetValSep('Firstname',info,'','ū') != '') { s += "	<tr><td>First name<br><b>"+GetValSep('Firstname',info,'','ū')+"</b></td></tr>"; }
	if (GetValSep('Surname',info,'','ū') != '') { s += "	<tr><td>Surname<br><b>"+GetValSep('Surname',info,'','ū')+"</b></td></tr>"; }
	if (GetValSep('Profession',info,'','ū') != '') { s += "	<tr><td>Profession<br><b>"+GetValSep('Profession',info,'','ū')+"</b></td></tr>"; }
	if (GetValSep('Org_name',info,'','ū') != '') { s += "	<tr><td>Org_name<br><b>"+GetValSep('Org_name',info,'','ū')+"</b></td></tr>"; }
	if (GetValSep('Department',info,'','ū') != '') { s += "	<tr><td>Department<br><b>"+GetValSep('Department',info,'','ū')+"</b></td></tr>"; }
	if (GetValSep('City',info,'','ū') != '') { s += "	<tr><td>City<br><b>"+GetValSep('City',info,'','ū')+"</b></td></tr>"; }
	if (GetValSep('Country',info,'','ū') != '') { s += "	<tr><td>Country<br><b>"+GetValSep('Country',info,'','ū')+"</b></td></tr>"; }
	
	s += "</table>";
	
   GetObj('cellInfo').innerHTML = s;
}





function EditPresentationSave() {
	var i = GetObj('EditPresentationMode').value;
	if (!GetObj('PresentationTitle')) { return false; }
	if (!GetObj('PresentationType')) { return false; }
	if (!GetObj('PresentationSession')) { return false; }
	
	if (GetObj('PresentationTitle').value == '') { 
		alert('Title can not be left blank.');
		GetObj('PresentationTitle').focus();
	   return false; 
	}
	if (GetObj('PresentationType').value == '') { 
		alert('Type has to be selected.');
		GetObj('PresentationType').focus();
	   return false; 
	}
	if (GetObj('PresentationSession').value == '') {
		alert('Session has to be selected.'); 
		GetObj('PresentationSession').focus();
	   return false; 
	}
	
	if ((objSelRow) && (i == -1)) {				
		// Delete
		if (objSelRow) {
		   var tab = GetObj('tbPresentations');
			if (tab) {
				tab.deleteRow(objSelRow.rowIndex);
				SelRow(null);
			}
		}			
	} else 
	if ((objSelRow) && (i == 0)) {				
		// Edit
		objSelRow.cells[0].innerHTML = GetObj('PresentationTitle').value;
		if (GetObj('PresentationType').value == 1) {
			objSelRow.cells[1].innerHTML = 'Poster';
		} else {
			objSelRow.cells[1].innerHTML = 'Paper';
		}
		objSelRow.cells[2].innerHTML = GetObj('PresentationSession').value;				
	} else {
		// New
		var tab = GetObj('tbPresentations');

		oTR = tab.insertRow(-1);
		//alert(oTR);
		oTR.id = -1;
		oTR.style.cursor='Hand';
		oTR.onclick = function(){SelRow(this);}; 
		oTR.onmouseover = function(){DoHighlightRow(this,true);} 
		oTR.onmouseout = function(){DoHighlightRow(this,false);}
		oTR.ondblclick = function(){EditPresentation(0);}

		oTD = oTR.insertCell(-1);
		oTD.width = 300;
		oTD.innerHTML = GetObj('PresentationTitle').value;

		oTD = oTR.insertCell(-1);
		oTD.width = 100;
		if (GetObj('PresentationType').value == 1) {	oTD.innerHTML = 'Poster'; } else { oTD.innerHTML = 'Paper'; }

		oTD = oTR.insertCell(-1);
		oTD.style.borderRightWidth = 1;
		oTD.innerHTML = GetObj('PresentationSession').value;
	
		SelRow(oTR);
	}
	HideLayer();
	return false; 	
}

function UpdateSessions() {
var sel = GetObj('PresentationSession');
var typ = GetObj('PresentationType').value;
var ar = new Array();
   /*alert(typ);
   alert(GetObj('Presentation_Paper_Sessions').value);
   alert(GetObj('Presentation_Poster_Sessions').value);*/
	sel.options.length = 0;	
	
	var oOption = document.createElement("OPTION");
	sel.options.add(oOption);
	oOption.innerHTML = '- Select session -';
	oOption.value = '';
	oOption.selected = true;	

		
	if ( typ == '' ) {
		
	}
	else if ( typ == 0 ) {
		ar = GetObj('Presentation_Paper_Sessions').value.split(';');
	}
	else if ( typ == 1 ) {
		ar = GetObj('Presentation_Poster_Sessions').value.split(';');
	}
	var i = 0;
	if (ar.length > 0) {
	   for (i = 0; i < ar.length; i++) {
		   var oOption = document.createElement("OPTION");
	      sel.options.add(oOption);
	      oOption.innerHTML = ar[i];
			oOption.value = ar[i];
		}
		GetObj('PresentationSession').disabled = false;
	} else {
		GetObj('PresentationSession').disabled = true;
	}
}

function UpdateTypes(obj) {
	
	var objTypes = GetObj('Types');
	if (obj.id == 'Types') {
	
		GetObj('tdTypeDelegate').disabled = ((objTypes.value != 'd') && (objTypes.value != 'de'));
		GetObj('DelegateCategory').disabled = GetObj('tdTypeDelegate').disabled;
		GetObj('tdTypeExhibitor').disabled = ((objTypes.value != 'e') && (objTypes.value != 'de'));
		GetObj('ExhibitorCategory').disabled = GetObj('tdTypeExhibitor').disabled;
	
	}
	
	var objDelegate = GetObj('DelegateCategory');
	var objExhibitor = GetObj('ExhibitorCategory');
	
	var visPersonOrg = ( ((objTypes.value == 'd') && (objDelegate.value != '')) || ((objTypes.value == 'e') && (objExhibitor.value != '')) || ((objTypes.value == 'de') && (objTypes.value != '') && (objExhibitor.value != '')) );
	
	var div = GetObj('divPersonOrg');		
	if (visPersonOrg) {
		div.style.visibility = '';
		div.style.position = '';
	} else {					
		div.style.visibility = 'hidden';
		div.style.position = 'absolute';
	}	
	var div = GetObj('divPresentation');
	if ((visPersonOrg) && (!objDelegate.disabled) && (objDelegate.value == '2')) {
		div.style.visibility = '';
		div.style.position = '';
	} else {	
		div.style.visibility = 'hidden';
		div.style.position = 'absolute';		
	}	
	if ((objExhibitor.value == '2') && (objTypes.value == 'e')) {
		GetObj('laEmail').innerHTML = 'Email';
		GetObj('laGet_together_party').innerHTML = 'Get together party';
	} else {					
		GetObj('laEmail').innerHTML = 'Email *';
		GetObj('laGet_together_party').innerHTML = 'Get together party *';
	}	
	var div = GetObj('divStand');
	if ( ((objTypes.value == 'e') || (objTypes.value == 'de')) && (objExhibitor.value == '1') ) {
		div.style.visibility = '';
		div.style.position = '';
	} else {	
		div.style.visibility = 'hidden';
		div.style.position = 'absolute';		
	}	
}

var FirstUnvalidId = '';

function SetRedOff( obj ) {
	if ((obj.parentNode.style.color == '#ff0000' ) || (obj.parentNode.style.color == 'rgb(255, 0, 0)' )) { 
	   obj.parentNode.style.color = ''; 
	}
}

function SetRed( obj ) {
	obj.parentNode.style.color = '#ff0000';
}

function CheckItem( obj, obj2 ) {
	var res = ((obj.disabled) || (obj.value != ''));
	if ((!res) && (obj2)) { res = ((obj2.disabled) || (obj2.value != '')); }
	if (!res) { 	   
		SetRed(obj); 
		if (FirstUnvalidId == '') { FirstUnvalidId = obj.id; }
		if (obj2) { SetRed(obj2); }
	}
	return res;
}

function SetAllRedOff() {
	SetRedOff( GetObj('Types') );
	SetRedOff( GetObj('DelegateCategory') );
	SetRedOff( GetObj('ExhibitorCategory') );
	SetRedOff( GetObj('Email') );
	SetRedOff( GetObj('Firstname') );
	SetRedOff( GetObj('Surname') );
	SetRedOff( GetObj('Get_together_party') );
	
	SetRedOff( GetObj('Org_name') );
	
	SetRedOff( GetObj('Address1') ); 
	SetRedOff( GetObj('Address2') );
	
	SetRedOff( GetObj('ZIPCode') );
	SetRedOff( GetObj('Country') );
}

function ValidateReg(obj) {
	FirstUnvalidId = '';
	SetAllRedOff();
	var res = true;
	if (!CheckItem( GetObj('Types') )) { res = false };
	if (!CheckItem( GetObj('DelegateCategory') )) { res = false };
	if (!CheckItem( GetObj('ExhibitorCategory') )) { res = false };	
	if (!CheckItem( GetObj('Firstname') )) { res = false };
	if (!CheckItem( GetObj('Surname') )) { res = false };	
	if (!CheckItem( GetObj('Org_name') )) { res = false };	
	if (!CheckItem( GetObj('Address1'), GetObj('Address2') )) { res = false };	
	if (!CheckItem( GetObj('ZIPCode') )) { res = false };
	if (!CheckItem( GetObj('Country') )) { res = false };
	
	if ((GetObj('ExhibitorCategory').value == '2') && (GetObj('Types').value == 'e')) { 
	
	} else { 
	   if (!CheckItem( GetObj('Email') )) { res = false }; 
		if (!CheckItem( GetObj('Get_together_party') )) { res = false };
	}
	
	if ( (res) && (GetObj('Stand_Size')) && (GetObj('Stand_Size').value != '') && (isNaN(GetObj('Stand_Size').value)) ) {
		ShowMess('Only numerals allowed in booth size.');
		GetObj('Stand_Size').focus();
		return false;
	}
	
	if (!res) {
	   ShowMess('There are values missing.');
		if (FirstUnvalidId != '') { GetObj(FirstUnvalidId).focus(); }
	} else {
		SetPresentations();
		res = true;
	}
	return res;
}

function SetPresentations() {
	var oTab = GetObj('tbPresentations');
	if (oTab) {
		l = '';
		for (i = 0; i < oTab.rows.length; i++) {
			id = oTab.rows[i].id;
			tit = oTab.rows[i].cells[0].innerHTML;
	      typ = oTab.rows[i].cells[1].innerHTML;
	      ses = oTab.rows[i].cells[2].innerHTML;
			if (typ == 'Poster') {
				typ = 1;
			} else {
				typ = 0;
			}
			if ( l != '' ) {
				l += '\n';
			}
			l += id + ';' + tit + ';' + typ + ';' + ses;
		}
		GetObj('Presentations').value = l;
	}
}



function CheckLoginResult( info ) {
	if (info.substr(0,7) == 'Error: ') {
		ShowMess( info.substr(7), 'Error' );
	} else 
   if (info.substr(0,10) == 'Multiple: ') {
		SelectPerson( info.substr(10), true );
	} else {
		window.location.href = info;
	}	
}

// Layers ************

function SelectOrg( info ) {
   var s = '';
	s += BorderStartVal('Size=1;Title=Select Organisation');
	s += "		<form onSubmit='return DoSelectOrg()'>\n";
	s += "<table width=600 height=300 border=0 >\n";
	s += "	<tr>\n";
	s += "		<td colspan=2 >\n";
	s += "		   Please check if your organisation is located in this list. If so select it and click [OK]. If not click [New].\n";
	s += "		</td >\n";
	s += "	</tr>\n";
	s += "	<tr>\n";
	s += "		<td height=100%>\n";
	
	s += "<table width=100% height=100% border=0 cellspacing=0 cellpadding=0 >\n";
	s += "	<tr>\n";
	s += "		<td height=1>\n";
	
   s += "	<table border='0' id='tbSelectOrgH' cellspacing=0 bgcolor='#808080' width=100% class=ListHeader >";
	s += "		<tr>";
	s += "			<td width='150' class=ListHeaderColumnSelected >Org_name</td>"; //
	s += "			<td width='150' class=ListHeaderColumn >Department</td>"; //
	s += "			<td width='*'  class=ListHeaderColumn style='border-right-width:1' >Country</td>";	//style='border-top:1 solid #808080;border-bottom:1 solid #808080;border-left:1 solid #808080;border-right:1 solid #808080;'
	s += "		</tr>";
	s += "	</table>";

	s += "		</td>\n";
	s += "	</tr>\n";
	s += "	<tr>\n";
	s += "		<td height=100% >\n";
	
	s += "	<div ID='myDiv' width=100% STYLE='width:100%;height:100%;overflow:auto;overflowY:100%;' onclick='SelRowNone()' >";// border-left:1 solid #808080;border-right:1 solid #808080
	s += "	<table border=0 id=tbSelectOrg cellspacing=0 cellpadding=1 width=100% bgcolor='#ffffff' class=List onclick='event.cancelBubble=true' >";
	
	var arDB = info.split('˙');
	var sRec = '';
	var r = 0;
	var bb = 0;
	for (r = 0; r < arDB.length; r++) {
	   sRec = arDB[r];
	   s += "<tr bgcolor=#ffffff id=" + GetValSep('Org_ID',sRec,'','ū') + " info='"+sRec+"' proc='"+sRec+"' style='CURSOR:Hand' onClick='SelRow(this)' onmouseover='DoHighlightRow(this,true)' onmouseout='DoHighlightRow(this,false)' ondblclick=DoEditVisit() >";	
		if (r == arDB.length-1) {bb = 1;}
		s += "<td width=150 id=BokdbCell  >" + GetValSep('Org_name',sRec,'','ū') +"&nbsp;</td>";	 // style='border-left:1 solid #808080;border-bottom:"+bb+" solid #808080;'      
		s += "<td width=150 id=BokdbCell  >" + GetValSep('Department',sRec,'','ū') +"&nbsp;</td>";
		s += "<td width=* id=BokdbCell style='border-right-width:1' >" + GetValSep('Country',sRec,'','ū') +"&nbsp;</td>";
		s += "</tr>";	
	}
	s += "	</table>";
	s += "	</div>";
	
	s += "		</td>\n";
	s += "	</tr>\n";
	s += "	<tr>\n";
	s += "		<td height=1 >\n";
	
	s += "	<table border=0 cellspacing=1 cellpadding=0 bgcolor=#808080 width=100% class=tblBokade onclick='SelRowNone()' >";
	s += "		<tr>";
	s += "			<td bgcolor=cfedff align='Left' id=BokcellStatus >Antal: "+arDB.length+"</td>";
	s += "		</tr>";
	s += "	</table>";
	
	s += "		</td>\n";
	s += "	</tr>\n";
	s += "</table>\n";
	
	s += "		</td>\n";	
	s += "		<td width=1 >\n";
	s += "	<table border=0 id=tbSelectOrgInfo cellspacing=0 width=200 height=100% bgColor=#D1E9F7 class=tblHeader >";
	s += "		<tr>";
	s += "			<td width=100% id=cellInfo style='border-left:1 solid #808080;border-right:1 solid #808080;border-top:1 solid #808080;border-bottom:1 solid #808080;' valign=top >&nbsp;</td>";
	s += "		</tr>";
	s += "	</table>";
	s += "		</td>\n";
	s += "	</tr>\n";
	s += "	<tr>\n";	
	s += "		<td colspan=2 ><hr></td>\n";
	s += "	</tr>\n";
	s += "	<tr>\n";	
	s += "		<td colspan=2 align=right >\n";
	s += "			<input type=button style='width:60' value='New' onClick='DoSelectOrg(true)' >&nbsp;<input type=submit style='width:60' value='OK' >&nbsp;<input type=button style='width:60' value='Avbryt' onClick='HideLayer()' >\n";
	s += "		</td>\n";
	s += "	</tr>\n";
	s += "</table>\n";
	s += "	</form>\n";
	s += BorderEndVal();	
	
	ShowLayerCentered( s, GetObj('ttop'), 0, 0, 600 );
	
	if ((GetObj('Org_ID')) && (GetObj('Org_ID').value != '')) {
		SelTableRow( 'tbSelectOrg', GetObj('Org_ID').value );
	}
}

function EditPresentation( i ) {
   var s = '';
	var what = '';
	var dis = '';
	if (!i) { i = 0; }
	if (i == 1) { what = 'New'; }
	if (i == 0) { what = 'Edit'; }
	if (i == -1) { what = 'Delete'; dis = 'disabled' }
	
	
	
	s += BorderStartVal('Size=1;Title='+what+' Presentation');
	s += "		<form onSubmit='return EditPresentationSave()'>";
	s += "<table width=300 height=1 border=0 >";
	s += "	<tr>";
	s += "		<input type=hidden name=EditPresentationMode id=EditPresentationMode value="+i+" >";
	s += "		<td height=100%>";
	
	s += "			<table width=100% border=0  >\n";
	s += "				<tr>\n";
	s += "					<td "+dis+" colspan=2>\n";
   s += "						Title<br>\n";
   s += "						<input type=text id=PresentationTitle name=PresentationTitle style='width:100%' value='' >\n";
	s += "					</td>\n";
	s += "				</tr>\n";	
	s += "				<tr>\n";
	s += "					<td "+dis+" >\n";
   s += "						Type<br>\n";
   s += "						<select id=PresentationType name=PresentationType style='width:100%' onChange='UpdateSessions()'>\n";
   s += "							<option value=''>Select type</option>\n";
   s += "							<option value=0>Paper</option>\n";
   s += "							<option value=1>Poster</option>\n";
   s += "						</select>\n";	
	s += "					</td>\n";
	s += "					<td "+dis+" >\n";
   s += "						Session<br>\n";
   s += "						<select id=PresentationSession name=PresentationSession disabled style='width:100%' >\n";
	s += "							<option value=''>- Select session -</option>\n";
   s += "						</select>\n";	
	s += "					</td>\n";
	s += "				</tr>\n";	
	s += "			</table>\n";
	
	s += "		</td>";
	s += "	</tr>";
	s += "	<tr>";	
	s += "		<td ><hr></td>";
	s += "	</tr>";
	s += "	<tr>";	
	s += "		<td align=right >";
	s += "			<input type=submit style='width:60' value='OK' >&nbsp;<input type=button style='width:60' value='Avbryt' onClick='HideLayer()' >";
	s += "		</td>";
	s += "	</tr>";
	s += "</table>";
	s += "	</form>";
	s += BorderEndVal();
	
	//alert(s);
	
	
	var id = '';
	var tit = '';
	var typ = '';
	var ses = '';
	if (i != 1) {
		id = objSelRow.id;
		tit = objSelRow.cells[0].innerHTML;
	   typ = objSelRow.cells[1].innerHTML;
		if (typ == 'Poster') {
			typ = 1;
		} else {
			typ = 0;
		}
	   ses = objSelRow.cells[2].innerHTML;
	}
	
	ShowLayerCentered( s, GetObj('ttop'), 0, 0, 300 );
	
	GetObj('PresentationTitle').value = tit;
	GetObj('PresentationType').value = typ;
	UpdateSessions();
	GetObj('PresentationSession').value = ses;
	
	GetObj('PresentationTitle').focus();
}

function DoLogin(userid) {
   if (!userid) { userid = ''; }
	
	var s = '';	
	
	s += BorderStartVal('Size=1;Title=Login');
	s += "		<form name='frmLogin' id='frmLogin' onSubmit='return CheckLogin()' >\n";
	s += "<table height=1 width=200  border=0 cellspacing=0 cellpadding=0 >"; 
	s += "	<tr>";
	s += "		<td height=100%>\n";
	
	s += "			<table width=100% height=1 border=0  >\n";
	s += "				<tr>\n";
	s += "					<td colspan=2>\n";
   s += "						Username<br>\n";
   s += "						<input type=text id=UserID name=UserID style='width:100%' value='"+userid+"' >\n";
	s += "					</td>\n";
	s += "				</tr>\n";	
	s += "				<tr>\n";
	s += "					<td colspan=2>\n";
   s += "						Password<br>\n";
   s += "						<input type=Password id=Password name=Password style='width:100%' value='' >\n";
	s += "					</td>\n";
	s += "				</tr>\n";
	s += "				<tr>";	
	s += "					<td ><hr></td>";
	s += "				</tr>";
	s += "				<tr>";	
	s += "					<td align=right >";
	s += "						<input type=submit style='width:60' value='OK' >&nbsp;<input type=button style='width:60' value='Avbryt' onClick='HideLayer()' >";
	s += "					</td>";
	s += "				</tr>";
	s += "			</table>\n";
	
	s += "		</td>";
	s += "	</tr>";
	s += "</table>";
	s += "	</form>";
	s += BorderEndVal();
	
	
	ShowLayerCentered( s, GetObj('ttop'), 0, 0, 200 );
	if (GetObj('UserID').value != '') {
		GetObj('Password').focus();
	} else {
	   GetObj('UserID').focus();
	}
}

function SelectPerson( info, login ) {
   var s = '';
	s += BorderStartVal('Size=1;Title=Select Person');
	if (login) {
	   s += "		<form onSubmit='return DoSelectLoginPerson()'>\n";
	} else {
	   s += "		<form onSubmit='return DoSelectPerson()'>\n";
	}
	s += "<table width=600 height=300 border=0 >\n";
	s += "	<tr>\n";
	s += "		<td height=100%>\n";
	
	s += "<table width=100% height=100% border=0 cellspacing=0 cellpadding=0 >\n";
	s += "	<tr>\n";
	s += "		<td height=1>\n";
	
   s += "	<table border='0' id='tbSelectPersonH' cellspacing=0 bgcolor='#808080' width=100% class=ListHeader >";
	s += "		<tr>";
	s += "			<td width='150' class=ListHeaderColumnSelected >First name</td>"; 
	s += "			<td width='150' class=ListHeaderColumn >Surname/Family name</td>"; 
	s += "			<td width='*'  class=ListHeaderColumn style='border-right-width:1' >org_name</td>";	
	s += "		</tr>";
	s += "	</table>";

	s += "		</td>\n";
	s += "	</tr>\n";
	s += "	<tr>\n";
	s += "		<td height=100% >\n";
	
	s += "	<div ID='myDiv' width=100% STYLE='width:100%;height:100%;overflow:auto;overflowY:100%;' onclick='SelRowNone()' >";
	s += "	<table border=0 id=tbSelectPerson cellspacing=0 cellpadding=1 width=100% bgcolor='#ffffff' class=List onclick='event.cancelBubble=true' >";
	
	var arDB = info.split('˙');
	var sRec = '';
	var r = 0;
	var bb = 0;
	for (r = 0; r < arDB.length; r++) {
	   sRec = arDB[r];
	   s += "<tr bgcolor=#ffffff id=" + GetValSep('Person_ID',sRec,'','ū') + " info='"+sRec+"' style='CURSOR:Hand' onClick='SelRow(this)' onmouseover='DoHighlightRow(this,true)' onmouseout='DoHighlightRow(this,false)' ondblclick=DoEditVisit() >";	
		if (r == arDB.length-1) {bb = 1;}
		s += "<td width=150 id=BokdbCell  >" + GetValSep('Firstname',sRec,'','ū') +"&nbsp;</td>";	 
		s += "<td width=150 id=BokdbCell  >" + GetValSep('Surname',sRec,'','ū') +"&nbsp;</td>";
		s += "<td width=* id=BokdbCell style='border-right-width:1' >" + GetValSep('Org_name',sRec,'','ū') +"&nbsp;</td>";
		s += "</tr>";	
	}
	s += "	</table>";
	s += "	</div>";
	
	s += "		</td>\n";
	s += "	</tr>\n";
	s += "	<tr>\n";
	s += "		<td height=1 >\n";
	
	s += "	<table border=0 cellspacing=1 cellpadding=0 bgcolor=#808080 width=100% class=tblBokade onclick='SelRowNone()' >";
	s += "		<tr>";
	s += "			<td bgcolor=cfedff align='Left' id=BokcellStatus >Antal: "+arDB.length+"</td>";
	s += "		</tr>";
	s += "	</table>";
	
	s += "		</td>\n";
	s += "	</tr>\n";
	s += "</table>\n";
	
	s += "		</td>\n";	
	s += "		<td width=1 >\n";
	s += "	<table border=0 id=tbSelectPersonInfo cellspacing=0 width=200 height=100% bgColor=#D1E9F7 class=tblHeader >";
	s += "		<tr>";
	s += "			<td width=100% id=cellInfo style='border-left:1 solid #808080;border-right:1 solid #808080;border-top:1 solid #808080;border-bottom:1 solid #808080;' valign=top >&nbsp;</td>";
	s += "		</tr>";
	s += "	</table>";
	s += "		</td>\n";
	s += "	</tr>\n";
	s += "	<tr>\n";	
	s += "		<td colspan=2 ><hr></td>\n";
	s += "	</tr>\n";
	s += "	<tr>\n";	
	s += "		<td colspan=2 align=right >\n";
	s += "			<input type=button style='width:60' value='New' onClick='DoSelectPerson(true)' >&nbsp;<input type=submit style='width:60' value='OK' >&nbsp;<input type=button style='width:60' value='Avbryt' onClick='HideLayer()' >\n";
	s += "		</td>\n";
	s += "	</tr>\n";
	s += "</table>\n";
	s += "	</form>\n";
	s += BorderEndVal();	
	
	ShowLayerCentered( s, GetObj('ttop'), 0, 0, 600 );
	
	if ((GetObj('Person_ID')) && (GetObj('Person_ID').value != '')) {
		SelTableRow( 'tbSelectPerson', GetObj('Person_ID').value );
	}
}

function ChangePassword() {	
	var s = '';	
	
	s += BorderStartVal('Size=1;Title=Ändra lösenord');
	s += "		<form name='frmLogin' id='frmLogin' onSubmit='return DoChangePassword()' >\n";
	s += "<table height=1 width=200  border=0 cellspacing=0 cellpadding=0 >"; 
	s += "	<tr>";
	s += "		<td height=100%>\n";
	
	s += "			<table width=100% height=1 border=0  >\n";
	/*s += "				<tr>\n";
	s += "					<td colspan=2>\n";
   s += "						Current password<br>\n";
   s += "						<input type=Password id=CurrPass name=CurrPass style='width:100%' value='' >\n";
	s += "					</td>\n";
	s += "				</tr>\n";	*/
	s += "				<tr>\n";
	s += "					<td colspan=2>\n";
   s += "						Nytt lösenord<br>\n";
   s += "						<input type=Password id=NewPass1 name=NewPass1 style='width:100%' value='' >\n";
	s += "					</td>\n";
	s += "				</tr>\n";	
	s += "				<tr>\n";
	s += "					<td colspan=2>\n";
   s += "						Ange lösenordet igen<br>\n";
   s += "						<input type=Password id=NewPass2 name=NewPass2 style='width:100%' value='' >\n";
	s += "					</td>\n";
	s += "				</tr>\n";
	s += "				<tr>";	
	s += "					<td ><hr></td>";
	s += "				</tr>";
	s += "				<tr>";	
	s += "					<td align=right >";
	s += "						<input type=submit style='width:60' value='OK' >&nbsp;<input type=button style='width:60' value='Avbryt' onClick='HideLayer()' >";
	s += "					</td>";
	s += "				</tr>";
	s += "			</table>\n";
	
	s += "		</td>";
	s += "	</tr>";
	s += "</table>";
	s += "	</form>";
	s += BorderEndVal();
	
	
	ShowLayerCentered( s, GetObj('ttop'), 0, 0, 200 );
	//GetObj('CurrPass').focus();
	GetObj('NewPass1').focus();
}

function ChangeUserID() {	
	var s = '';	
	
	s += BorderStartVal('Size=1;Title=Change email');
	s += "		<form name='frmLogin' id='frmLogin' onSubmit='return DoChangeUserID()' >\n";
	s += "<table height=1 width=200  border=0 cellspacing=0 cellpadding=0 >"; 
	s += "	<tr>";
	s += "		<td height=100%>\n";
	
	s += "			<table width=100% height=1 border=0  >\n";
	s += "				<tr>\n";
	s += "					<td>\n";
   s += "						New email<br>\n";
   s += "						<input type=text id=NewEmail name=NewEmail style='width:100%' value='"+GetObj('Email').value+"' >\n";
	s += "					</td>\n";
	s += "				</tr>\n";
	s += "				<tr>";	
	s += "					<td ><hr></td>";
	s += "				</tr>";
	s += "				<tr>";	
	s += "					<td align=right >";
	s += "						<input type=submit style='width:60' value='OK' >&nbsp;<input type=button style='width:60' value='Avbryt' onClick='HideLayer()' >";
	s += "					</td>";
	s += "				</tr>";
	s += "			</table>\n";
	
	s += "		</td>";
	s += "	</tr>";
	s += "</table>";
	s += "	</form>";
	s += BorderEndVal();
	
	
	ShowLayerCentered( s, GetObj('ttop'), 0, 0, 200 );
	GetObj('NewEmail').focus();
}

function SendNewPassword() {	
	var s = '';	
	
	s += BorderStartVal('Size=1;Title=Send new password');
	s += "		<form name='frmLogin' id='frmLogin' onSubmit='return DoSendNewPassword()' >\n";
	s += "<table height=1 width=200  border=0 cellspacing=0 cellpadding=0 >"; 
	s += "	<tr>";
	s += "		<td height=100%>\n";
	
	s += "			<table width=100% height=1 border=0  >\n";
	s += "				<tr>\n";
	s += "					<td>\n";
   s += "						Email<br>\n";
   s += "						<input type=text id=UserID name=UserID style='width:100%' value='' >\n";
	s += "					</td>\n";
	s += "				</tr>\n";
	s += "				<tr>";	
	s += "					<td ><hr></td>";
	s += "				</tr>";
	s += "				<tr>";	
	s += "					<td align=right >";
	s += "						<input type=submit style='width:60' value='OK' >&nbsp;<input type=button style='width:60' value='Avbryt' onClick='HideLayer()' >";
	s += "					</td>";
	s += "				</tr>";
	s += "			</table>\n";
	
	s += "		</td>";
	s += "	</tr>";
	s += "</table>";
	s += "	</form>";
	s += BorderEndVal();
	
	
	ShowLayerCentered( s, GetObj('ttop'), 0, 0 ); // 200
	GetObj('UserID').focus();
}

function DeletePerson() {	
	var s = '';	
	
	s += BorderStartVal('Size=1;Title=Delete person');
	s += "		<form name='frmLogin' id='frmLogin' onSubmit='return DoDeletePerson()' >\n";
	s += "<table height=1 width=200  border=0 cellspacing=0 cellpadding=0 >"; 
	s += "	<tr>";
	s += "		<td height=100%>\n";
	
	s += "			<table width=100% height=1 border=0  >\n";
	s += "				<tr>\n";
	s += "					<td >\n";
   s += "						Delete this person\n";
	s += "					</td>\n";
	s += "				</tr>\n";
	s += "				<tr>";	
	s += "					<td ><hr></td>";
	s += "				</tr>";
	s += "				<tr>";	
	s += "					<td align=right >";
	s += "						<input type=submit style='width:60' value='OK' >&nbsp;<input type=button style='width:60' value='Avbryt' onClick='HideLayer()' >";
	s += "					</td>";
	s += "				</tr>";
	s += "			</table>\n";
	
	s += "		</td>";
	s += "	</tr>";
	s += "</table>";
	s += "	</form>";
	s += BorderEndVal();
	
	
	ShowLayerCentered( s, GetObj('ttop'), 0, 0, 200 );
}

function ShowMess( mess, title, width ) {	
	var s = '';	
	
	if ((title) && ('' + title != '')) {
		s += BorderStartVal('Size=1;Title='+title);
	} else {
	   s += BorderStartVal('Size=1;Title=Message');
	}
	var swidth = 'width=200';
	if (width) { swidth = 'width='+width; }
	s += "		<form name='frmLogin' id='frmLogin' onSubmit='return false' >\n";
	s += "<table height=1 "+swidth+"  border=0 cellspacing=0 cellpadding=0 >"; // width=200
	s += "	<tr>";
	s += "		<td height=100%>\n";
	
	s += "			<table width=100% height=1 border=0  >\n";
	s += "				<tr>\n";
	s += "					<td align=center >\n";
   s += "						"+mess;
	s += "					</td>\n";
	s += "				</tr>\n";
	s += "				<tr>";	
	s += "					<td ><hr></td>";
	s += "				</tr>";
	s += "				<tr>";	
	s += "					<td align=right >";
	s += "						<input type=submit style='width:60' name=btMessOK id=btMessOK value='OK' onClick='HideMessLayer()' >";
	s += "					</td>";
	s += "				</tr>";
	s += "			</table>\n";
	
	s += "		</td>";
	s += "	</tr>";
	s += "</table>";
	s += "	</form>";
	s += BorderEndVal();
	
	
	ShowLayerCentered( s, GetObj('ttop'), 0, 0, null, null, true ); // 200
	GetObj('btMessOK').focus();
}

function DoSysAdmin() {
   window.location.href = 'system_admin.asp';
}

function ChangePassword_old() {
var t = 0;
var l = 0;
var f = "";
	t = screenTop ;
	l = screenLeft ;
		
		
	w = 300;
	h = 240;
		
	t = (screen.availHeight - h) / 2;
	l = (screen.availWidth - w) / 2;
		
	s =  'changepassword.asp';
	s += '?cashkiller=' + Date.parse(new Date().toString());			
		
	r = '';		
		
   f = 'dialogTop:' + t + 'px;dialogLeft:' + l + 'px;dialogwidth:' + w + 'px;dialogHeight:' + h + 'px;scroll:1;help:0;status:1';		
   r = window.showModalDialog(s,'',f);	
}

// Format card functions






var GetTempPhotoUrl = '';
var DbLogoDir = '';
var ImageImportEx = '';
var LayHasPhoto = false;

function ValidateEdit(frm) {
var res = true;
var obj = null;	
	
	if ( ( GetObj('EditFields') ) && ( GetObj('EditFields').cells ) && ( GetObj('EditFields').cells.length ) ) {
		for (i = 0; i < GetObj('EditFields').cells.length; i++) {
		   oTD = GetObj('EditFields').cells(i);
			obj = oTD.children(1);
	
			
			if (obj) {
				//if (  (obj.eg) && (obj.eg == 1) && (obj.value != '') && (GetObj('5')) && (GetObj('5').value == '  ')  ) {
				if (  (obj.eg) && (obj.eg == 1) && (GetObj('5')) && (GetObj('5').value == '  ')  ) {
					// Personnr
					res = CheckPnr( obj,true );
				} else
				if ((obj.eg) && (obj.id == 17) && (obj.value != '')) {
					// Giltigt tom
					res = CheckGiltighetsTid( obj );
				} else 
				if ((obj.eg) && (obj.eg == 3) && (obj.value != '')) {
					// Datum
					res = CheckDate( obj );
				} else 
				if ((obj.eg) && (obj.eg == 51) && (obj.value != '')) {
					// Telefon
					res = CheckTelefon( obj );
				} else 
				if ((obj.eg) && (obj.eg == 52) && (obj.value != '')) {
					// Namn
					res = CheckText( obj );
				} else 
				if ((obj.typ) && (obj.typ == 1)) {
					// Måste fyllas i
					res = TestThis( obj );
				}
				
				if (res) { res = CheckLen(obj); }
				
				if (!res) { 
					obj.focus();
					obj.select();
					return false;
				} 
				/*if (!CheckLen(obj)) { 
					obj.focus();
					obj.select();
					return false;
				}*/
			}
		}
	}	
	
	if (GetObj('TempFilename') && GetObj('TempFilename').value == '') {
		alert('Foto saknas');
		return false;
	}	
	
   return res;
}

function GetData(i) {
var res = "";
   if (document.getElementById(i)) {
      res = document.getElementById(i).value;
   }
   return res
}

function GetFixedData(nam) {
var res = "";
/*
var x = 0;
var s = "";
var ar = "";
*/
   for (x = 0; x < arFixedData.length; x++) {
		s = arFixedData[x];
		ar = s.split('=');
		if ((ar[0] == nam) || (ar[0]+'[DB]' == nam)) {
		   res = ar[1];
			return res
		}
	}
   return res
}

function GetFieldNumber(s) {
var d = 0;
   s = s.substr(s.indexOf(' ')+1,255);
   s = s.substr(0,s.indexOf('['));
   d = parseInt(s);
   s = d;
   return s
}

function FormatData( vDat, all ) {
var res = '';

var id ="";
var dat = "";
var i = 0;
var x = 0;
var s = "";
var sfrm = "";
var arfrm = "";
var d = 0;
var ar = "";
var res = "";
var grp = "";
var dbl = "";

   s = '' + vDat;

   res = s;
	

      if (s.match("!!special:")) {
         s = s.substr(s.indexOf(":")+1,255);
         ar = s.split('!');
         res = "";
	      for (x = 0; x < ar.length; x++) {
	         s = ar[x];
				if (s.substr(0,3) == 'ft"') {
	            // Fast text
					s = s.substr(s.indexOf('"')+1,255);
	            s = s.substr(0,s.indexOf('"'));
	            ar[x] = s;
	         } else {	
				   // Datafält
					if (s.substr(0,8) == 'kd"Fält ') {
						s = s.substr(s.indexOf(' ')+1,255);
						s = s.substr(0,s.indexOf('"'));
						d = parseInt(s);
						s = d;
						if ((all == false) && (s == id)) {
							ar[x] = dat;
						}
						else {
							s = GetData(s);
							ar[x] = s;
						}
					}
					else if (s.substr(0,2) == 'kd') { // Formaterad
						sfrm = s.substr(2,255);
						sfrm = sfrm.substr(0,sfrm.indexOf('"'));
						s = s.substr(s.indexOf('"')+1,255);
						s = s.substr(0,s.indexOf('"'));
						if (s.substr(0,5) == 'Fält ') {
						   // Fält data
							d = parseInt(s);
							s = d;
							s = GetData(s);
						} else {
						   // Annan data (fast)
							s = GetFixedData(s);
						}
						if (sfrm.indexOf(',') > 0) {
							//alert('h'+sfrm);
							arfrm = sfrm.split(',');
							s = s.substr( parseInt(arfrm[0])-1,parseInt(arfrm[1]) );
							sfrm = "";
						}
						ar[x] = s;
					}
				}
			}

         for (x = 0; x < ar.length; x++) {
            res = res + ar[x];
         }
      }
      //else if (s.match("[DB]")) {
      else if (s.indexOf('[DB]') > 0) {
         if (s.substr(0,5) == 'Fält ') {
            s = GetFieldNumber(s);
            if ((all == false) && (s == id)) {
               res = dat;
            }
            else {
               s = GetData(s);
               res = s;
            }
         } else {
				// Annan data (fast)
				s = s.substr(0,s.indexOf('[DB]'));
				s = GetFixedData(s);
				res = s;
			}
      }

   return res;
}

function CenterAndUpdatePhotoImages() {
var i = 0;
var sKnd = '';
var z = GetObj('TempZ').value;
var imfil = '';

	if ((GetObj('TempFilename')) && (GetObj('TempFilename').value != '')) {
		imfil = GetObj('TempFilename').value;
	} else {
		if (ImageImportEx == '1') {
			imfil = GetTempPhotoUrl;
		} else {
		   imfil = 'parseImageData.asp?proc=temp&cashkiller=' + Date.parse(new Date().toString());
		}
	}

	//alert(imfil);

	if (z != '') {
		if (document.all.pho.length) {
	      i = 0;
	      while (document.all.pho[i]) {
	         //sKnd = document.all.pho[i].knd;
				sKnd = document.all.pho[i].getAttribute('knd');
				//alert(sKnd);
				if (sKnd == '') {
				   CenterPhotoImage(document.all.pho[i],document.all.divpho[i],z);
					document.all.pho[i].src = imfil;
				}
				i++;
	      }
	   } else
	   if (document.all.pho) {
	      //sKnd = document.all.pho.knd;
			sKnd = document.all.pho.getAttribute('knd');
			if (sKnd == '') {
				CenterPhotoImage(document.all.pho,document.all.divpho,z);
				document.all.pho.src = imfil;
			}
	   }
	}
}

function CenterPhotoImage(im,pdiv,z) {
   if (z != '') {
	var pw = parseInt(pdiv.style.width);
   var ph = parseInt(pdiv.style.height);
	
	var pz = pw / ph;
	if (z > pz) {
		var ih = ph;
      var iw = ih * z;
	} else {
		var iw = pw;
      var ih = iw / z;
	}
	
   x = (pw - iw) / 2;
   y = (ph - ih) / 2;
	y = parseInt(y);
   im.style.width = iw;
   im.style.height = ih;
   im.style.left = x;
   im.style.top = y;
	}
}

function UpdatePhoto(im,pdiv) {
var imfil = '';


   if (im) {
		//s = im.dat;
		s = im.getAttribute('dat');
		//sKnd = im.knd;
		sKnd = im.getAttribute('knd');
		
		if (sKnd == '') {
			
			LayHasPhoto = true;
			if (GetObj('TempZ').value != '') {
			   if ((GetObj('TempFilename')) && (GetObj('TempFilename').value != '')) {
					imfil = GetObj('TempFilename').value;
				} else {
					if (ImageImportEx == '1') {
						imfil = GetTempPhotoUrl;
					} else {
					   imfil = 'parseImageData.asp?proc=temp&cashkiller=' + Date.parse(new Date().toString());
					}
				}
			   im.src = imfil;
			   CenterPhotoImage(im,pdiv,GetObj('TempZ').value);
			}
		} else
		if (sKnd == 'DB') {	
			s = FormatData( s );
			
			if ((s == '') || (s.substr(0,1) == '.')) {
			   s = 'blank.gif';
			}
			
			s = DbLogoDir + s;
			//im.style.display = 'none';
			im.onerror = function () {
				//im.style.display = 'none';
				im.onerror = null;
				s = 'blank.gif';
				im.src = s;
			}	
			//im.onload = function () {				
			//	im.style.display = 'block';
			//}	
			im.src = s;
			
			//im.src = '<% DbLogoDir() %>' + s;
         //document.all.pho.src = '<% DbLogoDir() %>' + s;
			//alert(im.src);
		}
	}
}

function UpdateLabel( obj, e ) {
var s = "";
var grp = "";
var dbl = "";
var fld = "";
var id ="";
var dat = "";
var ang = "";
var all = true;
if (e) {
	id = e.id;
   //alert(id);
   fld = "Fält " + id;
   dat = e.value;
   all = false;
}

   //s = obj.name;
	s = obj.getAttribute('name');
	//alert(s);
   //grp = obj.style.grp;
	if (IsMSIE()) {
	   grp = obj.style.getAttribute('grp');
		dbl = obj.style.getAttribute('dbl');
	} else {
	   grp = obj.getAttribute('grp');
		dbl = obj.getAttribute('dbl');
	}
	//alert(obj.getAttribute('dbl'));
	//alert(obj.style.getAttribute('dbl'));
	//alert(s);
   if (all || ( s.match(fld) )) {
	//alert(1);
      s = FormatData( s );
		 
		ang = obj.getAttribute('ang');
		if ((ang) && (ang != '')) {	
		   s = s.replace(/ /g,'&nbsp;');
			//alert(obj.width);
			//pObj = obj.parentNode.parentNode.parentNode;			
		}
       //obj.innerText = s;
       obj.innerHTML = s;
    }
    if ((dbl) && (grp != "")) {  // Test if grouped
	//alert('grp:'+grp+':');

    }
    if ((dbl) && (dbl != "")) {  // Test if datalabel
		 s = GetFixedData(dbl);
		 //alert(dbl+' - '+s);
		 if (s == '') {
          s = GetData(GetFieldNumber(dbl));
		 }
       if (s == "") {
          //obj.innerText = "";
          obj.innerHTML = "";
       }
    }
}

function UpdateData(e) {
var i = 0;
var s = "";
var sKnd = "";
var all = (!e);

   if ((document.all.lab) && (document.all.lab.length)) {
      i = 0;
      while (document.all.lab[i]) {
         UpdateLabel(document.all.lab[i],e);
         i++;
      }
   } else
   if (lab) {
      UpdateLabel(document.all.lab,e);
   }
   if ((document.all.pho) && (document.all.pho.length)) {
      i = 0;
      while (document.all.pho[i]) {
         UpdatePhoto(document.all.pho[i],document.all.divpho[i]);
			i++;
      }
   } else
   if (document.all.pho) {
      UpdatePhoto(document.all.pho,document.all.divpho);
   }
}

function CheckPnr(e,justmess) {
var bNotPnr = false;
var s = e.value;
var b12 = false;	
if ((GetObj('5')) && (GetObj('5').value != '  ')) { return true; }
	//if ( s!= '' ) {
		bNotPnr = ( s == '' );
		if (!bNotPnr) {
			s = s.replace(/-/,'');
			if (e.getAttribute('egval') == '0;1') {
				// 12
				if (!bNotPnr) {bNotPnr = ( s.length != 12 );}
				if (!bNotPnr) {bNotPnr = ( ( s.substr(0,2) != '19' ) && ( s.substr(0,2) != '20' ) );}
				if (!bNotPnr) { s = s.substr(2) ;}
				b12 = true;
			} 
		}
		if (!bNotPnr) {bNotPnr = ( s.length != 10 );}
		if (!bNotPnr) {bNotPnr = ( isNaN(s) );}
		if (!bNotPnr) {bNotPnr = ( ( parseInt( s.substr(2,2), 10 ) < 1 ) || ( parseInt( s.substr(2,2), 10 ) > 12 ) );}
		if (!bNotPnr) {bNotPnr = ( ( parseInt( s.substr(4,2), 10 ) < 1 ) || ( parseInt( s.substr(4,2), 10 ) > 31 ) );}
		
		if ( bNotPnr ) {
		   if (b12) {
				s = '';
				s += 'Detta är inte ett korrekt svenskt tolvsiffrigt personnr. \n';
				s += 'Kontrollera att du exempelvis har skrivit födelseåret med 4 siffror (19XX). \n';
				if (!justmess) {
				s += '\n';
				s += 'Klicka på "OK" för att rätta till felet. \n';
				s += 'Om personen inte är svensk, klicka på "Avbryt" för att fortsätta.';
				}
			} else {
				s = '';
				s += 'Detta är inte ett korrekt svenskt personnr. \n';
				if (!justmess) {
				s += '\n';
				s += 'Klicka på "OK" för att rätta till felet. \n';
				s += 'Om personen inte är svensk, klicka på "Avbryt" för att fortsätta.';	
				}
			}
			if (justmess) {
				alert(s);
				return false;			
			} else {
				r = (!confirm(s));
				if ( r != true ) {
					e.focus();
					return false;
				}
			}
	   }
		return true;
	//}

}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysInMonth(y,m) {
   y = parseInt(y);
   m = parseInt(m);
   if (m==4 || m==6 || m==9 || m==11) {
      return 30;
	} else if (m==2) {
		return daysInFebruary(y);
	} else {
		return 31;
	}
}

function CheckDate(e) {
var bDate = true;
var s = e.value;
	if ( s!= '' ) {		
		bDate = (s.length == 10);
		if (bDate) { bDate = ( ( s.substr(4,1) == '-' ) || ( s.substr(7,1) == '-' ) ); }
		
		if (bDate) { 
		   y = parseInt(s.substr(0,4),10);
		   m = parseInt(s.substr(5,2),10);
		   d = parseInt(s.substr(8,2),10);
		   bDate = ( (y >= 2007) && (m >= 1) && (m <= 12) && (d >= 1) && (d <= DaysInMonth(y,m)) );			
		}		
		if (!bDate) {
		   alert('Felaktigt datum. Datum skall anges enligt formatet "YYYY-MM-DD".');
		}
		return bDate;		
	}
}

function CheckGiltighetsTid(e) {
var bDate = CheckDate(e);
if (!bDate) { return bDate; }
var s = e.value;
	if ( s!= '' ) {		
		
		y = parseInt(s.substr(0,4),10);
		m = parseInt(s.substr(5,2),10);
		d = parseInt(s.substr(8,2),10);	
		
		var dObj = new Date();
		dObj.setFullYear(y,m-1,d);
		
		if (bDate) { 	
			var dObjMin = new Date();
		   bDate = ( dObj >= dObjMin );	
			if (!bDate) { alert('Giltighetstiden har redan passerats.'); }
		}
		if (bDate) { 	
			var dObjMax = new Date();
			dObjMax.setFullYear(dObjMax.getFullYear()+10);
		   bDate = ( dObj <= dObjMax );	
			if (!bDate) { alert('Giltighetstiden får inte överstiga 10 år.'); }
		}
		return bDate;		
	}
}

function CheckTelefon(e) {
var s = e.value;
	if ( s!= '' ) {
		s = s.replace(/[\(\)\.\-\+\ ]/g, ''); 
		if (isNaN(s)) {
			alert('Felaktigt telefonnummer. \n'+'Endast siffror och tecknen + - ( ) samt mellanslag är tillåtna i detta fält.');
			return false;
		} else {
			return true;
		}		
	}
}

function CheckText(e) {
var s = e.value;
	if ( s!= '' ) { 
	   var testName=new RegExp(/[0-9]/);
		if(testName.test(s)) { 
			alert('Endast text är tillåtet i detta fält.');
			return false; 
		} 
	}
	return true;
}

function CheckLen(e) {
   var s = e.value;
	if (e.id == 1) { return true; } // Vänta på Efternamn
	if (e.id == 2) { s = GetObj('1').value + s; }
   if (s == '')   { return true; }
	
   var c = s.length;	
	var max = 0;
	
	if (e.id == 2)  { max = 46; } // Namn
	if (e.id == 3)  { max = 14; } // Personnr
	if (e.id == 8)  { max = 32; } // Utbildningskoder
	if (e.id == 9)  { max = 16; } // Eget mobilnummer 1
	if (e.id == 10) { max = 16; } // Anhörigs Telefonnummer 2
	if (e.id == 11) { max = 28; } // Närmast anhörig
	if (e.id == 12) { max = 4;  } // Pinkod
	
	if (max == 0)   { return true; }	
	
	if (c > max) {
		if (e.id == 2) {
			alert( 'För många tecken. ('+(c)+')\n' + 'Namnfälten får inte innehålla mer än ' +max+ ' tecken tillsammans.' );
		} else {
		   alert( 'För många tecken. ('+(c)+')\n' + 'Detta fält får inte innehålla mer än ' +max+ ' tecken.' );
		}
		return false;
	}
	return true;
}

function TestThis(oObj) {
   if (oObj.value == '') {
      alert(oObj.name + ' måste fyllas i.');
      oObj.focus();
      return false;
   } else {
      return true;
   }
}




