//-------------------------------------------------------------------------
// <> FUNCTION synlighet |  Uppdated By: FD (2001-01-02)
//-------------------------------------------------------------------------
function synlighet(div){
	if (document.all) {
		obj = document.all[div].style
		if(obj.visibility=='visible' || obj.visibility=='show') {obj.visibility='hidden'}
		else {obj.visibility='visible'}
	}
	else {
		obj = document.layers[div]
		if(obj.visibility=='visible' || obj.visibility=='show') {obj.visibility='hidden'}
		else {obj.visibility='show'}
	}
}
//-------------------------------------------------------------------------
// <> FUNCTION OpenWin  |  Uppdated By: FD (2000-08-15)
//-------------------------------------------------------------------------
function OpenWin(url,width,height,x,y,scrollbars,resizable,toolbar,location,directories,status,menubar,name) {
	if(width==null){width=600}; if(height==null){height=400}
	if(scrollbars==null){scrollbars='yes'};
	if(resizable==null){resizable='yes'};
	if(x==null){x=(screen.width/2)-(width/2);if(x<0){x=0}}
	if(y==null){y=(screen.height/2)-(height/2)-80;if(y<0){y=0}}
	Win = window.open("",name,"width="+width+",height="+height+",screenX="+x+",screenY="+y+",resizable="+resizable+",scrollbars="+scrollbars+",toolbar="+toolbar+",location="+location+",directories="+directories+",status="+status+",menubar="+menubar+",left="+x+",top="+y);
	if(url!=null && url!=''){Win.location = url};
	Win.focus();
}
//-------------------------------------------------------------------------
// <> FUNCTION HelpWindow |  Uppdated By: FD (2001-08-08)
//-------------------------------------------------------------------------
function HelpWindow(Lev) {
	Win=window.open('/apps/help/index.asp?Lev='+Lev,'HelpWindow','scrollbars=yes,width=380,height=420,resizable=yes');
	Win.moveTo(246,121)
	Win.focus();
}
//-------------------------------------------------------------------------
// <> FUNCTION notnumber  |  Uppdated By: FD (2000-08-15)
//-------------------------------------------------------------------------
function notnumber(str) {
	if (str==null) {return null;}
	for(i=0;i<str.length;i++) {
		if (str.charAt(i)<'0' || str.charAt(i)>'9') {return true;}
	}
	return false;
}
//-------------------------------------------------------------------------
// <> FUNCTION FileArchive |  Uppdated By: FD (2001-08-28)
//-------------------------------------------------------------------------
function FileArchive() {
	Win=window.open('/apps/_shared/FileArchive/FileArchive.asp?reurl=close','FileArchive','scrollbars=yes,width=540,height=580,resizable=yes');
	Win.moveTo(170,150)
	Win.focus();
}
//-------------------------------------------------------------------------
// <> FUNCTION CheckBrackets  |  Uppdated By: FD (2000-08-15)
//-------------------------------------------------------------------------
function CheckBrackets(str) {
	if (str==null) {return null;}
	for(i=0;i<str.length;i++) {
		if (str.charAt(i)=='<' || str.charAt(i)=='>') {return true;}
	}
	return false;
}
//-------------------------------------------------------------------------
// <> FUNCTION CorrectEmail |  Uppdated By: FD (2002-08-29)
//-------------------------------------------------------------------------
function CorrectEmail(email) {
	if(email.length>0){
		var email_len = email.length;
		var snabel = email.indexOf('@');
		var punkt =  email.lastIndexOf('.');

		if(
			email.indexOf('å')>-1 || email.indexOf('Å')>-1 ||
			email.indexOf('ä')>-1 || email.indexOf('Ä')>-1 ||
			email.indexOf('ö')>-1 || email.indexOf('Ö')>-1
			) {return false;}
				
		if ( (snabel < 1) || (snabel > (email_len - 5)) ) {return false;}
		if ( ((punkt + 3) > email_len) || ((punkt + 5) < email_len) ) {return false;}
	}
	return true;
}
//-------------------------------------------------------------------------
// <> FUNCTION FlipBlock |  Uppdated By: FD (2000-09-10)
//-------------------------------------------------------------------------
Blocktemp=new Array;
BlockStatus=new Array;
function FlipBlock(HiddenField,BlockID,NewStatus) {
	var ReplaceTxt='';
	if(HiddenField!='') {ReplaceTxt="<INPUT TYPE='hidden' NAME='"+HiddenField+"'>"}
	if(HiddenField==''){ReplaceTxt="<IMG SRC='/imgs/dutt.gif'><BR>"}
	if (BlockStatus[BlockID]==null){BlockStatus[BlockID]=0}
	// Fixar rätt status
	if(NewStatus=='show' && BlockStatus[BlockID]==0){return}
	else if(NewStatus=='hide' && BlockStatus[BlockID]==1){return};
  else if(BlockStatus[BlockID]==1){NewStatus='show'}
	else {NewStatus='hide'}
	// Gömmer block
	if(NewStatus=='hide') { 
		Blocktemp[BlockID] = document.all(BlockID).innerHTML;
		document.all(BlockID).innerHTML=ReplaceTxt;
		BlockStatus[BlockID]=1;
	}
	// Visar block
	else if(NewStatus=='show') {
		document.all(BlockID).innerHTML=Blocktemp[BlockID];
		Blocktemp[BlockID] = ReplaceTxt;
		BlockStatus[BlockID]=0;
	}
}

//-------------------------------------------------------------------------
// <> FUNCTION MinMaxBlock |  Uppdated By: FD (2001-09-08)
//-------------------------------------------------------------------------
function MinMaxBlock(BlockID,FixedStatus) {
	var CurrDisplay=""
	var ActionID="AreaButton_" + BlockID
	BlockID='Area_' + BlockID
	CurrDisplay = document.all(BlockID).style.display

	if( (FixedStatus!=false && CurrDisplay=='none') || FixedStatus==true) {
		document.all(BlockID).style.display='block'
		document.all(ActionID).src='/apps/bilder/ikoner/arr_up.gif'
	}
	else {
		document.all(BlockID).style.display='none'
		document.all(ActionID).src='/apps/bilder/ikoner/arr_dw.gif'
	}
}

//-------------------------------------------------------------------------
// <> FUNCTION OpenUserBrowser |  Uppdated By: FD (2001-09-08)
//-------------------------------------------------------------------------
function OpenUserBrowser(ReturnField) {
	url='/apps/_shared/UserBrowser/UserBrowser.asp?ReturnField=' + ReturnField
	OpenWin(url,310,405,null,null,false,false,null,null,null,null,null,'UserBrowser') 
}


function mClk(src) 
{if(event.srcElement.tagName=='TD'){src.children.tags('A')[0].click();}}
function mOvr(src,bgc)
{if (!src.contains(event.fromElement)) {src.style.cursor = 'hand';if(bgc!=null){src.style.background=bgc;}}}
function mOut(src,bgc)
{if (!src.contains(event.toElement)) {src.style.cursor = 'default';if(bgc!=null){src.style.background=bgc;}}}

//-------------------------------------------------------------------------
// <> FUNCTION correctDate  |  Uppdated By: FD (2000-08-15)
//-------------------------------------------------------------------------
function correctDate(date) {
	if (date=="") {return false;}
	strarray=date.split('-');
	if (strarray.length!=3) {
		alert('Enter a correct Date (YYYY-MM-DD)');
		return false;
	}
	if (strarray[0].length!=4 || strarray[1].length!=2 || strarray[2].length!=2) {
		alert('Enter a correct Date (YYYY-MM-DD)');
		return false;
	}
	if (notnumber(strarray[0]) || notnumber(strarray[1]) || notnumber(strarray[2])) {
		alert('Enter a correct Date (YYYY-MM-DD)');
		return false;
	}
	if (strarray[1]>'12' || strarray[2]>'31') {
		alert('Enter a correct Date (YYYY-MM-DD)');
		return false;
	}
	if (strarray[1]=='02' && strarray[2]>'29' ) {
		alert('Enter a correct Date (YYYY-MM-DD)');
		return false;
}
	if (strarray[1]=='04' || strarray[1]=='06' || strarray[1]=='09' || strarray[1]=='11') {
		if (strarray[2]>'30') {
			alert('Enter a correct Date (YYYY-MM-DD)');
			return false;
		}
	}
	return true;
}

//-------------------------------------------------------------------------
// <> FUNCTION correctTime  |  Uppdated By: FD (2000-08-15)
//-------------------------------------------------------------------------
function correctTime(time) {
	if (time==""){return false;}
	strarray=time.split(':');
	if (strarray.length!=2) {
		alert('Enter a correct Time (HH:MM)');
		return false;
	}
	if (strarray[0].length!=2 || strarray[1].length!=2) {
		alert('Enter a correct Time (HH:MM)');
		return false;
	}
	if (notnumber(strarray[0]) || notnumber(strarray[1]) || notnumber(strarray[2])) {
		alert('Enter a correct Time (HH:MM)');
		return false;
	}
	if (strarray[0]>23 || strarray[1]>'59') {
		alert('Enter a correct Time (HH:MM)');
		return false;
	}
	return true;
}