﻿var ErrorFlag="";
//*****************************
function checkformat (obj,frmt)
//*****************************                         
{
if(ErrorFlag)
	{
	clearTimeout(ErrorFlag);                                                       
	}
s= new Array();                                         
s[0]=0;                                                 
s[1]=0;                                                 
len=frmt.length;                                        
f=frmt.substring(0,1);                                  
l=frmt.substring(1,len);                                
if(l.match(/\./g))                                      
	{                                                       
	s=l.split('.');                                         
	}                                                       
else                                                    
	{                                                       
	s[0]=l;                                                 
	s[1]=0;                                                                                    
	}                                                                                          
v=obj.value.split('.');                                                                    
msg="";                                                                                    
if(f=='D')                                                                                 
	{                                                                                          
	if(obj.value!="")                                                                          
		{                                                                                          
		d=new Array();                                                                             
		d[0]=obj.value.substring(0,4)*1;                                                           
		d[1]=obj.value.substring(4,6)*1-1;                                                         
		d[2]=obj.value.substring(6,8)*1;                                                           
		var D=new Date();                                                                          
		D.setFullYear(d[0],d[1],d[2]);                                                             
		if(D.getFullYear()!=d[0] || D.getMonth()!=d[1] || D.getDate()!=d[2] || obj.value.length!=8)
			{                                                                                          
			msg = 'Date must be YYYYMMDD format.';                                                     
			}                                                                                          
		}                                                                                          
	}                                                                                          
else                                                                                       
	{                                                                                          
	if(f=='A')                                          
		{                                                   
		if(obj.value.length>l)                              
			{                                                   
			msg='Data exceeds maximum of '+l+' characters.';    
			}                                                   
		}                                                   
	else                                                
		{                                                   
		if(f=='N')                                          
			{                                                   
			d=0;                                                
			try{d=obj.value*1}catch(e){};                       
			if(d!=obj.value&&obj.value!='-'&&obj.value!='.')    
				{                                                   
				msg='Input must be numeric.';                       
				}                                                   
			else                                                
				{                                                   
				if(v[0].match(/-/g))                                
					{                                                   
					if(v[0]&&v[0].length>(s[0]*1+1))                    
						{                                                            
						msg='Integer too large. Maximum '+s[0]+ ' digits allowed.';  
						}                                                            
					}                                                            
				else                                                         
					{                                                            
					if(v[0]&&v[0].length>s[0])                                   
						{                                                            
						msg='Integer too large. Maximum '+s[0]+' digits allowed.';   
						}                                                            
					else                                                         
						{                                                            
						if(s[1]==0&&obj.value.match(/\./g))                          
							{                                                            
							msg='Fraction not allowed.';                                 
							}                                                            
						else                                                         
							{                                                            
							if(v[1]&&v[1].length>s[1])                                   
								{                                                            
								msg='Fraction too large. Maximum '+ s[1]+' digits allowed.'; 
								}                                                            
							}                                                                                                                          
						}                                                                                                                          
					}                                                                                                                          
				}                                                                                                                          
			}                                                                                                                          
		}                                                                                                                          
	}  
calloutstop();                                                                                                                        
if(msg!="")                                                                                                                
	{                                                                                                                          
	if(ErrorFlag)
	{
	clearTimeout(ErrorFlag);                                                       
	}
	callout(obj,msg);
	}
cmd='calloutstop();';
ErrorFlag = setTimeout(cmd,3000);  	
}


//****************************************                                                                                                                          
function reinput(obj,msg,timer) // callout error
//****************************************                                                                                                  
{
calloutstop();
if(ErrorFlag)
	{
	clearTimeout(ErrorFlag);                                                       
	}
try{obj.focus();}catch(e){};                                                                
callout(obj,msg);
cmd='calloutstop();';
if(timer)
	{
	ErrorFlag = setTimeout(cmd,timer);
	}
else // default
	{
	ErrorFlag = setTimeout(cmd,4000);                                                                        
	}
}

//**********************************
function callout(obj,msg) // Callout
//**********************************
{
if(document.getElementById('callout'))
 {
 var p2 = document.getElementById('callout');
 p2.parentNode.removeChild(p2);
 }
if(msg!="")
{
 msg=decodeURIComponent(msg);
 var framewidth=23;
 // add temp container to determine required width & height
 var
 newFrame = document.createElement("div");
 newFrame.setAttribute("id","tempcontainer");
 newFrame.style.position='absolute';
 newFrame.style.top='-1000px';
 newFrame.style.width='auto';
 newFrame.style.height='auto';
 newFrame.style.border='1px solid red';

 newFrame.style.zIndex=1;
 newFrame.className='callout_container';
 newFrame.innerHTML=msg;
 document.getElementsByTagName('body')[0].appendChild(newFrame);
 var wh=MyElement.getElementSize(document.getElementById('tempcontainer'));
 
if(wh[0]>200)
  {
  document.getElementById("tempcontainer").style.width='200px';
  }
 wh=MyElement.getElementSize(document.getElementById('tempcontainer'));
 var w=wh[0]+(framewidth*2);
 var h=wh[1]+(framewidth*2);
 w= w<70 ? 70 : w; // minumum width of 70px
 h= h<47  ? 47 : h; // minimum height of 47px
// remove temp container
var p2 = document.getElementById('tempcontainer');
p2.parentNode.removeChild(p2);
// add callout frame
 
 var lt=MyElement.getElementPos(obj); // The targeted object's left and top
 var wh=MyElement.getElementSize(obj); // the targeted object's width and height
 var ew=w;
 var eh=h;
 var el=(lt[0]*1+parseInt(wh[0]*1)/2-35);
 var et=lt[1]*1- h*1;
 if(et<3) // is there space for the callout above the control ?
 {
 et=(lt[1]*1) + 12;
 et=((lt[1]*1)+ wh[1]*1)-5;
 newFrame = document.createElement("div");
 newFrame.setAttribute("id","callout");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.style.zIndex=39200;
 document.getElementsByTagName('body')[0].appendChild(newFrame);
 et=0;
 el=0;
 eh=framewidth;
 ew=framewidth;
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='bottom_callout_nw';
 document.getElementById('callout').appendChild(newFrame);
 et=0;
 eh=framewidth;
 el=framewidth*2;
 ew=w-(framewidth*3);
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='bottom_callout_n';
 document.getElementById('callout').appendChild(newFrame);
 et=0;
 el=w-framewidth;
 eh=framewidth;
 ew=framewidth;
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='bottom_callout_ne';
 document.getElementById('callout').appendChild(newFrame);
 et=framewidth;
 el=w-framewidth;
 eh=h-(framewidth*2);
 ew=framewidth;
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='bottom_callout_e';
 document.getElementById('callout').appendChild(newFrame);
 et=h-framewidth;
 el=w-framewidth;
 eh=framewidth;
 ew=framewidth;
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='bottom_callout_se';
 document.getElementById('callout').appendChild(newFrame);
 
 et=h-framewidth;
 el=framewidth;
 eh=framewidth;
 ew=w-(framewidth*2);
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='bottom_callout_s';
 document.getElementById('callout').appendChild(newFrame);
 
 et=0;
 el=framewidth;
 eh=framewidth;
 ew=framewidth;
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='bottom_callout_pointer';
 document.getElementById('callout').appendChild(newFrame);
 
 et=h-framewidth;
 el=0;
 eh=framewidth;
 ew=framewidth;
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='bottom_callout_sw';
 document.getElementById('callout').appendChild(newFrame);
 et=framewidth;
 el=0;
 eh=h-(framewidth*2);
 ew=framewidth;
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='bottom_callout_w';
 document.getElementById('callout').appendChild(newFrame);
 et=framewidth;
 el=framewidth;
 eh=h-(framewidth*2);
 ew=w-(framewidth*2);
 newFrame = document.createElement("div");
 newFrame.setAttribute("id","calloutcontainer");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='callout_container';
 document.getElementById('callout').appendChild(newFrame);
 document.getElementById('calloutcontainer').innerHTML=msg;
 }
 else
 {
 newFrame = document.createElement("div");
 newFrame.setAttribute("id","callout");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.style.zIndex=37200;
 document.getElementsByTagName('body')[0].appendChild(newFrame);
 et=0;
 el=0;
 eh=framewidth;
 ew=framewidth;
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='top_callout_nw';
 document.getElementById('callout').appendChild(newFrame);
 et=0;
 el=framewidth;
 eh=framewidth;
 ew=w-(framewidth*2);
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='top_callout_n';
 document.getElementById('callout').appendChild(newFrame);
 et=0;
 el=w-framewidth;
 eh=framewidth;
 ew=framewidth;
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='top_callout_ne';
 document.getElementById('callout').appendChild(newFrame);
 et=framewidth;
 el=w-framewidth;
 eh=h-(framewidth*2);
 ew=framewidth;
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='top_callout_e';
 document.getElementById('callout').appendChild(newFrame);
 et=h-framewidth;
 el=w-framewidth;
 eh=framewidth;
 ew=framewidth;
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='top_callout_se';
 document.getElementById('callout').appendChild(newFrame);
 et=h-framewidth;
 el=framewidth*2;
 eh=framewidth;
 ew=w-(framewidth*3);
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='top_callout_s';
 document.getElementById('callout').appendChild(newFrame);
 
 et=h-framewidth;
 el=framewidth;
 eh=framewidth;
 ew=framewidth;
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='top_callout_pointer';
 document.getElementById('callout').appendChild(newFrame);
 
 et=h-framewidth;
 el=0;
 eh=framewidth;
 ew=framewidth;
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='top_callout_sw';
 document.getElementById('callout').appendChild(newFrame);
 et=framewidth;
 el=0;
 eh=h-(framewidth*2);
 ew=framewidth;
 newFrame = document.createElement("div");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='top_callout_w';
 document.getElementById('callout').appendChild(newFrame);
 et=framewidth;
 el=framewidth;
 eh=h-framewidth*2;
 ew=w-framewidth*2;
 newFrame = document.createElement("div");
 newFrame.setAttribute("id","calloutcontainer");
 newFrame.style.position="absolute";
 newFrame.style.top=et+"px";
 newFrame.style.left=el+"px";
 newFrame.style.width=ew+"px";
 newFrame.style.height=eh+"px";
 newFrame.className='callout_container';
 document.getElementById('callout').appendChild(newFrame);
 document.getElementById('calloutcontainer').innerHTML=msg;
 }
 }
else
 {
 if(document.getElementById('callout'))
  {
  var p2 = document.getElementById('callout');
  p2.parentNode.removeChild(p2);
  }
 }
}
function calloutstop()
{
if(document.getElementById('callout'))
	{
	var p2 = document.getElementById('callout');
	p2.parentNode.removeChild(p2); 
	}
}

//*********************************************
function popupwindow(a,x,y,html) // info window 
//*********************************************
{
if(document.getElementById('popupwindow'))
	{
	var p2 = document.getElementById('popupwindow');
	p2.parentNode.removeChild(p2); 
	}
if(a=="destroy")
	{
	return;
	}
var framewidth=28;

if(x==0&&y==0)
	{
	// add temp container to determine required width & height
	 var newFrame = document.createElement("div");
	newFrame.setAttribute("id","tempcontainer");
	newFrame.style.position="absolute";
	newFrame.style.top="-1000px";
	newFrame.style.left="0px";
	newFrame.style.width="auto";
	newFrame.style.height="auto";
	newFrame.className='popupwindow_container';
	document.getElementsByTagName('body')[0].appendChild(newFrame);
	document.getElementById('tempcontainer').innerHTML=decodeURIComponent(html);
	
	var wh=MyElement.getElementSize(document.getElementById('tempcontainer'));
	 
	if(wh[0]>300)
	  {
	  document.getElementById("tempcontainer").style.width='300px';
	  }
	wh=MyElement.getElementSize(document.getElementById('tempcontainer'));
	var w=wh[0]+(framewidth*2);
	var h=wh[1]+(framewidth*2);
	w= w<70 ? 70 : w; // minumum width of 70px
	h= h<47  ? 47 : h; // minimum height of 47px
	// remove temp container
	var p2 = document.getElementById('tempcontainer');
	p2.parentNode.removeChild(p2);
	}
else
	{
	var w=x;
	var h=y;
	}

var el=parseInt((MyWindow.w()-w)/2);
var et=parseInt((MyWindow.h()-h-32)/2);
var eh=h;
var ew=w;
newFrame = document.createElement("div");
newFrame.setAttribute("id","popupwindow");
newFrame.style.position="absolute";
newFrame.style.top=et+"px";
newFrame.style.left=el+"px";
newFrame.style.width=ew+"px";
newFrame.style.height=eh+"px";
newFrame.style.zIndex=37200;
document.getElementsByTagName('body')[0].appendChild(newFrame);
//document.getElementById('pallet').appendChild(newFrame);
et=0;
el=0;
eh=framewidth;
ew=framewidth;
newFrame = document.createElement("div");
newFrame.setAttribute("id","northwest");
newFrame.style.position="absolute";
newFrame.style.top=et+"px";
newFrame.style.left=el+"px";
newFrame.style.width=ew+"px";
newFrame.style.height=eh+"px";
newFrame.className='popupwindow_nw';
document.getElementById('popupwindow').appendChild(newFrame);
et=0;
el=framewidth;
eh=framewidth;
ew=w-(framewidth*2);
newFrame = document.createElement("div");
newFrame.setAttribute("id","north");
newFrame.style.position="absolute";
newFrame.style.top=et+"px";
newFrame.style.left=el+"px";
newFrame.style.width=ew+"px";
newFrame.style.height=eh+"px";
newFrame.className='popupwindow_n';
document.getElementById('popupwindow').appendChild(newFrame);
et=0;
el=w-framewidth;
eh=framewidth;
ew=framewidth;
newFrame = document.createElement("div");
newFrame.setAttribute("id","northeast");
newFrame.style.position="absolute";
newFrame.style.top=et+"px";
newFrame.style.left=el+"px";
newFrame.style.width=ew+"px";
newFrame.style.height=eh+"px";
newFrame.className='popupwindow_ne';
document.getElementById('popupwindow').appendChild(newFrame);
et=framewidth;
el=w-framewidth;
eh=h-(framewidth*2);
ew=framewidth;
newFrame = document.createElement("div");
newFrame.setAttribute("id","east");
newFrame.style.position="absolute";
newFrame.style.top=et+"px";
newFrame.style.left=el+"px";
newFrame.style.width=ew+"px";
newFrame.style.height=eh+"px";
newFrame.className='popupwindow_e';
document.getElementById('popupwindow').appendChild(newFrame);
et=h-framewidth;
el=w-framewidth;
eh=framewidth;
ew=framewidth;
newFrame = document.createElement("div");
newFrame.setAttribute("id","southeast");
newFrame.style.position="absolute";
newFrame.style.top=et+"px";
newFrame.style.left=el+"px";
newFrame.style.width=ew+"px";
newFrame.style.height=eh+"px";
newFrame.className='popupwindow_se';
document.getElementById('popupwindow').appendChild(newFrame);
et=h-framewidth;
el=framewidth;
eh=framewidth;
ew=w-(framewidth*2);
newFrame = document.createElement("div");
newFrame.setAttribute("id","south");
newFrame.style.position="absolute";
newFrame.style.top=et+"px";
newFrame.style.left=el+"px";
newFrame.style.width=ew+"px";
newFrame.style.height=eh+"px";
newFrame.className='popupwindow_s';
document.getElementById('popupwindow').appendChild(newFrame);
et=h-framewidth;
el=0;
eh=framewidth;
ew=framewidth;
newFrame = document.createElement("div");
newFrame.setAttribute("id","southwest");
newFrame.style.position="absolute";
newFrame.style.top=et+"px";
newFrame.style.left=el+"px";
newFrame.style.width=ew+"px";
newFrame.style.height=eh+"px";
newFrame.className='popupwindow_sw';
document.getElementById('popupwindow').appendChild(newFrame);
et=framewidth;
el=0;
eh=h-(framewidth*2);
ew=framewidth;
newFrame = document.createElement("div");
newFrame.setAttribute("id","west");
newFrame.style.position="absolute";
newFrame.style.top=et+"px";
newFrame.style.left=el+"px";
newFrame.style.width=ew+"px";
newFrame.style.height=eh+"px";
newFrame.className='popupwindow_w';
document.getElementById('popupwindow').appendChild(newFrame);
et=framewidth;
el=framewidth;
eh=h-(framewidth*2);
ew=w-(framewidth*2);
newFrame = document.createElement("div");
newFrame.setAttribute("id","popupcontainer");
newFrame.style.position="absolute";
newFrame.style.top=et+"px";
newFrame.style.left=el+"px";
newFrame.style.width=ew+"px";
newFrame.style.height=eh+"px";
newFrame.className='popupwindow_container';
document.getElementById('popupwindow').appendChild(newFrame);
document.getElementById('popupcontainer').innerHTML=decodeURIComponent(html);
}

function dim(how,id)
{
if(document.getElementById('dimmer'))
	{
	var p2 = document.getElementById('dimmer');
	p2.parentNode.removeChild(p2); 
	}
switch (how)
	{
	case "dark":
		newFrame = document.createElement("div");
		newFrame.setAttribute("id","dimmer");
		newFrame.style.position="absolute";
		newFrame.style.top="0px";
		newFrame.style.left="0px";
		newFrame.style.width="100%";
		newFrame.style.height="100%";
		newFrame.style.zIndex=37000;
		newFrame.className='dimdark';
		if(id)
			{
			document.getElementById(id).appendChild(newFrame);
			}
		else
			{	
			document.getElementsByTagName('body')[0].appendChild(newFrame);
			}
		break;
	case "transparent":
		newFrame = document.createElement("div");
		newFrame.setAttribute("id","dimmer");
		newFrame.style.position="absolute";
		newFrame.style.top="0px";
		newFrame.style.left="0px";
		newFrame.style.width="100%";
		newFrame.style.height="100%";
		newFrame.style.zIndex=37000;
		newFrame.className='dimtransparent';
		if(id)
			{
			document.getElementById(id).appendChild(newFrame);
			}
		else
			{	
			document.getElementsByTagName('body')[0].appendChild(newFrame);
			}

		break;
	default: 
		break;
	}
}
