function openwin(oms_url,winname){
eval(winname+"=window.open('"+oms_url+"','"+winname+"');")
eval(winname+".focus();")
}

function displaydiv(divid){
var tag=document.getElementById(divid)
tag.style.display='';
x=Math.floor((document.body.clientWidth-tag.offsetWidth)/2+document.body.scrollLeft-100);
y=Math.floor((document.body.clientHeight-tag.offsetHeight)/2+document.body.scrollTop);
	//alert('x='+x+'  y='+y+'  clientwidth='+document.body.clientWidth+'  offsetwidth='+tag.offsetWidth+'  clientHeight='+document.body.clientHeight+'  offsetHeight='+tag.offsetHeight)	

	if (x+ tag.offsetWidth >document.body.scrollLeft +document.body.clientWidth - 160){
		x=document.body.scrollLeft +document.body.clientWidth-tag.offsetWidth-1-160
		}
	if (y+ tag.offsetHeight >document.body.scrollTop +document.body.clientHeight-270){
		y=document.body.scrollTop +document.body.clientHeight-tag.offsetHeight-1-270
		}
tag.style.position='absolute';
tag.style.left=x;
tag.style.top=y;


}


function openiframe(url,style,tag){
if (!window.numopeniframe || isNaN(numopeniframe)){numopeniframe=0;}
numopeniframe++;
var htm="<span style='position:relative' ><span id='openiframe"+numopeniframe+"' style='position:absolute;left:20px;' >";
htm+="<table cellpadding=0 cellspacing=0 class='openiframe' style=''><tr><td><span align=right onclick='event.cancelBubble=true;document.getElementById(\'frameopeniframe"+numopeniframe+"\').src=\'\';document.getElementById(\'openiframe"+numopeniframe+"\').style.display=\'\';'>XXXXXXXX</span></td></tr><tr><td><iframe id='frameopeniframe"+numopeniframe+"' src='"+url+"' width='100%' height='100%' style='border:0px solid black'></iframe></td></tr></table>";
htm+="</span></span>";

document.getElementById('tagid').innerHTML+=htm;

}


function removefromtab(vtab,velt){
vlist=vtab.join(",");
vlist=removefromlist(vlist,velt);
if (vlist){return vlist.split(',');}
return new Array;
}

function removefromlist(vlist,velt){
eval("vlist=vlist.replace(/"+velt+"/g,'')");
vlist=cleanlist(vlist);
return vlist;
}

function cleanlist(vlist){
while (vlist.search(/,,/)>-1){
vlist=vlist.replace(/,,/g,',');
}
while (vlist && vlist.substr(0,1)==','){
	vlist=vlist.substr(1);
	}
while (vlist && vlist.substr(vlist.length-1,1)==','){
	vlist=vlist.substr(0,vlist.length-1);
	}
return vlist;
}

function intab(tab,elt){
var i
for (i=0;i<tab.length;i++){
	if (elt==tab[i]){return true;}
	}
return false;
}


function arrayunique(vtab){
var restab=new Array;
var i
var j
for (i=0;i<vtab.length;i++){
	var vfound=0
	for (j=0;j<restab.length;j++){
		if (vtab[i]==restab[j]){vfound=1;break;}
		}
	if (vfound==0){restab[restab.length]=vtab[i];}
	}

return restab;
}

function isinarray(velt,vtab){
vfound=0
var i
for (i=0;i<vtab.length;i++){
	if (vtab[i]==velt){return 1;}
	
	}
return 0;
}


function changesetting(vsetting,vtid){
event.cancelBubble=true;
if (confirm('Do you want to change this value?')){openwinchangesetting(vsetting,vtid);}
}


function validationpage(valtype){

if (valtype=='create'){
	eval("var inlist=listcheckname.search(/,"+document.forms.mainform.pagename.value+",/)");
	if (inlist>=0){
		alert('The name already exists. Creation impossible.')
		return false;
		}
	
	}

var error=0;
messagealert='';
if (!document.forms.mainform.pagename.value){
	messagealert+="the page name\n"
	document.forms.mainform.pagename.focus()
	error=1;
	}
	else{
	if (valtype!='create' && window.oldpagename && document.forms.mainform.pagename.value!=oldpagename){
		if (!confirm("The page's name has changed.\nYou may wish to create a new page.\nAre you sure you want to replace the page's name?")){return false;}
		}
	}


if (error==1){
	messagealert="You need to enter :\n"+messagealert;
	alert(messagealert);
	return false;
	}
	else{
	return true;
	
	}

}





tabrequiredname=new Array;
tabrequiredalert=new Array;
youneedtoenter="You need to enter :\n";
invalidemail="Invalid email address";
confirmemail="Confirm email address";

function formvalidation(formname){

var error=0;
messagealert='';
if (!window.tabrequiredname){return true;}

for (var i=0;i<tabrequiredname.length;i++){
	eval("var confirmexist=window.document."+formname+"['"+tabrequiredname[i]+"']")
	if (!confirmexist){continue;}
	eval("var reqtag=document."+formname+"['"+tabrequiredname[i]+"']")
	
	if (!reqtag.value){
		messagealert+=tabrequiredalert[i]+"\n"
		//if (!error){reqtag.focus();}
		error=1;
		}
	}
	
if (error==1){
	messagealert=youneedtoenter+messagealert;
	alert(messagealert);
	return false;
	}
	else{
	for (var i=0;i<tabrequiredalert.length;i++){
		
		if (tabrequiredalert[i].search(/email/)==-1){continue;}
		eval("var reqtag=document."+formname+"['"+tabrequiredname[i]+"']")
		
		if (!validEmail(reqtag.value))
			{
				alert(invalidemail)
				reqtag.focus()
				return false
			}
		eval("var confirmexist=window.document."+formname+"['"+tabrequiredalert[i]+"2"+"']")
		if (confirmexist){
			eval("var reqtag2=document."+formname+"['"+tabrequiredalert[i]+"2"+"']")
			if (reqtag2.value!=reqtag.value)
				{
				alert(confirmemail)
				reqtag2.focus()
				return false
				}
			}
		}
	
	return true;
	
	}

}

function validEmail(email) {

	invalidChars = " /:,;"

	if (email == "") {
		return false
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) > -1) {
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
		return false
	}
	if (periodPos+3 > email.length)	{
		return false
	}
	return true
}


function itemmenuover(menuitemid){
		
	document.getElementById(menuitemid).style.display='';
	}
	
function itemmenuout(menuitemid){

//document.getElementById("tr_"+menuitemid).className='navtopsubmenuitem';
if (window.document.getElementById('sub_'+menuitemid)){document.getElementById('sub_'+menuitemid).style.display='none';}

	//setTimeout("document.getElementById('tr_"+menuitemid+"').className='navtopsubmenuitem';document.getElementById('sub_"+menuitemid+"').style.display='none';",100);

	}
	
function createiframe(iframeid,iframesrc){
if(!window.iframecounter){iframecounter=0;}
iframecounter++;
var iframesrc = (iframesrc == null) ? null : iframesrc;
var iframeid = (iframeid == null || !iframeid) ? 'iframe'+iframecounter : iframeid;

if(window.document.getElementById(iframeid)){
	document.getElementById(iframeid).src=iframesrc;
	return iframeid;
	}
var str  = "<iframe ";
if(iframesrc != null && iframesrc){str+=" src='"+iframesrc+"'";}
str+=" name='" + iframeid + "' id='" + iframeid + "' width=0 height=0></iframe>";
var div = document.createElement("DIV");
div.innerHTML = str;

document.body.appendChild(div);
return iframeid;

}
	
