function CloseWin(sReturnValue)
{
	window.returnValue = sReturnValue;
	window.close();
	return true;
}

// HR-anpassning - return false
function SendForm(cForm,sMode)
{
	//IE standard, should be replaced!
	var oCtrl = document.activeElement;
	//alert("oCtrl=" + oCtrl);
	if ((cForm.LastTabIndex != null) && (oCtrl != null))
	{
	cForm.LastTabIndex.value = oCtrl.tabIndex;
	//alert("oCtrl.tabIndex=" + oCtrl.tabIndex);
	}
	if (cForm["mode"] != undefined)
	    cForm.mode.value = sMode;
	//alert("cForm=" + cForm + " sMode=" + cForm.mode.value);
	   
	cForm.submit();
	
	//alert("Done");
	return false;
}

function isNumeric(x) 
{
	if (x.search) 
	 {if (x.search(/[^\d,.]/) != -1) return false;}
	return true;
}

function CheckBrowser() {
   if (navigator.appName == "Microsoft Internet Explorer")
        return 'E';
   else
        return 'N';
}

function ShowDialog(sPage,iHeight,iWidth)
{
	if (iHeight == '')
		{iHeight = 200;}
	if (iWidth == '')
		{iWidth = 300;}
		
	if(CheckBrowser()=='E')
		{
			return window.showModalDialog(sPage,"sickat",
      		"dialogHeight:"+iHeight+"px;dialogWidth:"+iWidth+"px; help:yes; scroll:yes;"+
		      "resizable:no; status:no");
		}
		else
		{
			window.location.replace(sPage);
		}
}

function MoOver(objSource,sDesc)
{
	objSource.title = sDesc;
	window.status = sDesc;
}

function MoOut(objSource,sDesc)
{
	if (sDesc == '') 
		{sDesc='Jeeves';}
	window.status = sDesc;
}

function PrintPage()
{
 window.print()
}

function ShowTextEditor(oEdit,bReadOnly,oEdit2, sCap1, sCap2)
{
 	var vReturnValue;
	var bChanged = false;
	var sEdit2;
	var iCount = 1;
	var i;
	var arrCtrls = new Array(2);
	var iReadOnly
	if (bReadOnly) 
	 {iReadOnly=1;}
	else
	 {iReadOnly=0;}
	arrCtrls[0] = oEdit;

	if (oEdit2 != null)
	{
		arrCtrls[1] = oEdit2;
		iCount = 2;
	}
	
	vReturnValue = window.showModalDialog('../include/TextEditor.asp?readonly=' + iReadOnly + '&count='+iCount+'&cap1='+StrToURL(sCap1) + '&cap2='+StrToURL(sCap2), arrCtrls );
	
 	if ( (!bReadOnly) && (vReturnValue==1) )
	 	{return true;}
	else
		{return false;};
}

function ShowCalendar(sCtrlName, sPostFunc)
{
	var window_top = (screen.height-200)/2;
	var window_left = (screen.width-300)/2;
	//window.open('../Include/Calendar.asp?Ctrl=' + escape(sCtrlName) + '&DT=' + escape(window.eval(sInputName).value), 'CalPop', 'toolbar=0,width=378,height=225');
	window.open('../Include/Calendar.asp?Ctrl=' + escape(sCtrlName) + '&Func=' + escape(sPostFunc) + '&DT=' + escape(window.eval(sCtrlName).value), 'CalPop', 'top='+window_top+' left='+window_left+' toolbar=0,width=300,height=200');
}


/* Check if an URL points to a picture
Created by: FARVIDSSON
Create date: 2008-11-12
*/
function isPicture(imgUrl)
{
    var picRegExp = /.jpg|.bmp|.gif|.jpeg/
    imgUrl = imgUrl.toLowerCase();
    
    if (imgUrl.search(picRegExp) != -1)
        return true;
    else
        return false;
}

/* Preloads an image into the browsers cache
Created by: FARVIDSSON
Create date: 2008-11-12
*/
var preLoadImgArray = new Array();
function PreLoadImage(imgUrl, name)
{
    if (isPicture(imgUrl))
    {
        var newImg = new Image();
        newImg.src = imgUrl;
        newImg.name = name;
        
        preLoadImgArray[preLoadImgArray.length] = newImg;
    }
}

/* Gets a preloaded image
Created by: FARVIDSSON
Create date: 2008-11-12
*/
function getPreLoadImg(picUrl)
{
    var i;
    
    for (i = 0; i<preLoadImgArray.length; i++)
    {
        if (preLoadImgArray[i].src == picUrl)
            return preLoadImgArray[i];
    }
    return false;
}

/* Open and fits a picture in a new window
Created by: FARVIDSSON
Create date: 2008-11-12
*/
function OpenWindowPic(iUrl, bCenter, bScroll, iTitle)
{
    var iWidth,iHeight, iObj;
	var window_top = 0;
	var window_left = 0;
	var iScroll = 0;
	if (bScroll==true) 
	  {iScroll=1;}
	
	if (iTitle == "")
	    iTitle = "JvsWin";
	
	//Need to store the URL in absolute format to be able to compare it with the URL's in the preload array
    var temp = new Image();
    temp.src = iUrl;
	
	var img;
	img = getPreLoadImg(temp.src);
	if (img == false)   //The file is not a valid image
	{
	    iObj = temp.src;
	    iWidth = 800;
	    iHeight = 600;
	    iTitle = "";
	}
	else
	{
	    iObj = img.src;
	    iWidth = img.width;
	    iHeight = img.height + 30;
	}
	
	if (bCenter == true)
	{
	    window_top = (window.screen.height-iHeight)/2;
	    window_left = (window.screen.width-iWidth)/2;
	}
	
	//myWindow = new window();
	//if (iTitle != "")
	//    myWindow.document.write('<title>' + iTitle + '</title>'); 
	myWindow = window.open(iObj, "JvsWin", "toolbar=no,status=no,menubar=no,scrollbars=" + iScroll + ",resizable=yes, location=no,width="+iWidth+",height="+iHeight);
	try
	{
	    myWindow.moveTo(window_left, window_top);
	}
	catch (err) {}
	return myWindow;
}

function OpenWindow(sUrl,iWidth,iHeight, bCenter, bScroll)
{
	var window_top = 0;
	var window_left = 0;
	var iScroll = 0;
	if (bScroll==true) 
	  {iScroll=1;}
	if (bCenter == true)
	{window_top = (window.screen.height-iHeight)/2;
	 window_left = (window.screen.width-iWidth)/2;
	}
	
	myWindow = window.open(sUrl, "JvsWin", "toolbar=0,scrollbars=" + iScroll + ",resizable=1,width="+iWidth+",height="+iHeight);
	myWindow.moveTo(window_left, window_top);
	return myWindow;
}

function HideProgress()
{
  var objProgBar = document.ProgBarImg;
  if (objProgBar != null)
  {
	objProgBar.width = 0;
    document.all('ProgBar').style.display='none'
  }
}

function ResetForm(oForm)
{
 var oElement;
 for (i = 0; i < oForm.elements.length; i++)
 {
   oElement = oForm.elements[i] 
   if (oElement.type == "text")
   {
   oElement.value = '';
   }
 }
}

function GetNextTabCtrl(iCurrTabIndex,oForm)
{
 var oElement;
 var oCtrlToReturn;

 for (i = 0; i < oForm.elements.length; i++)
 	{
   	   oElement = oForm.elements[i]
	   if ((oElement.tabIndex != '') && (oElement.tabIndex > iCurrTabIndex))
   		{
			if (oCtrlToReturn != null)
			 {
			  if (oElement.tabIndex < oCtrlToReturn.tabIndex)
			    {oCtrlToReturn = oElement}
			 } 
			else
 			 {oCtrlToReturn = oElement};
	 	}
	}
 return oCtrlToReturn;
}

function SetFocus(objElement) 
{
	if (objElement != null) 
	{objElement.focus();}
}

function StrToURL(sValue)
{
 var s=escape(sValue);
 return s.replace(/\+/g,'%2B');
}

function ReplacePage(sNewPage)
{
	window.location.href = sNewPage;
}
