//<![CDATA[

//checks or unchecks checkboxes
//usage:
//<a href="javascript:setCheck(document.f1.testet, true)">check all</a>
//<a href="javascript:setCheck(document.f1.testet, false)">uncheck all</a>
function setCheck(oCbx, bCheck)
{
	if( typeof(oCbx) == "undefined") return; // inga rader

	if( typeof(oCbx.length) == "undefined"){  // 1 rad
		oCbx.checked = bCheck;
		return;
	}

	for(var i=0; i < oCbx.length; i++) oCbx[i].checked = bCheck;
}

function showGlasHelpTextNoFrames(sPage) 
{
  var helpWin = openWindow('/sbab/jsp/polopoly.jsp?redirectOnly=true&functionurl=' + escape('/glasServlet/jsp/help/' + sPage + '.jsp?method=setPartnerHelpText'), 'help',450,320,null,null,true,'menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0');
}

  function helptextNoFrames(textType)
  {
  	var url = '/sbab/jsp/polopoly.jsp?redirectOnly=true&functionurl=' + escape('/glasServlet/glas-sbab/hjalptext.jsp?method=getGlasText&altPage=/glasServlet/glas-sbab/hjalptext.jsp' + '&textType=' + textType);
    window.open(url,'Hjalptext','width=250,height=250,menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=yes,top=0,left=0');
  }
  

function help(sPage)
{
  var helpWin = openWindow('/jsp/help/'+ sPage +'.html', 'help',300,200,null,null,true,'menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0');
}

function Jsphelp(sPage)
{
  var helpWin = openWindow('/coopApplication/jsp/help/'+ sPage +'.jsp?method=setHelpText', 'help',300,200,null,null,true,'menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0');
}

function showGlasHelpText(sPage)
{
  var helpWin = openWindow('/openweb/glasServlet/jsp/help/'+ sPage +'.jsp?method=setPartnerHelpText', 'help',450,320,null,null,true,'menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0');
}

function showGlasHelpTextPartner(sPage)
{
  var helpWin = openWindow('/glasServlet/glas/help/'+ sPage +'.jsp?method=setPartnerHelpText', 'help',450,320,null,null,true,'menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0');
}

//sets focus on first text field in form object passed to function
// usage <body onload="focusFirstField(document.form1)">
function focusFirstField(oForm)
{
	for(var i=0; i<oForm.elements.length; i++){

		if(oForm.elements[i].type == "text"){ //koll att det är textfält
			oForm.elements[i].focus();
			break;
		}
	}

}

/*===================================================================
' Description:
' Usage:
'====================================================================
' Date:       Name:                   Comment:
' 2000-08-09  Daniel Plyhm            Created.
'==================================================================*/
function swapImg(sImg, sNewImgSrc)
{
	eval("document." + sImg + ".src = '" + sNewImgSrc + "'");
}

/*===================================================================
' Description:
' Return value:
' Parameters:
' Usage:
'====================================================================
' Date:       Name:                   Comment:
' 2000-08-09  Daniel Plyhm            Created.
'==================================================================*/
function preloadImages()
{
	for(var i=0; i < arguments.length; i++){
		temp = new Image();
		temp.src = arguments[i];
	}
}


function redirect(sURL)
{
	window.location.href = sURL;
}

function redirByValue(oSel)
{
	window.location.href = oSel[oSel.selectedIndex].value;
}

function cantSaveInfo()
{
	var cantSaveWin = openWindow('/jsp/cant_save_info.html', 'cantsave',400,130,null,null,true,null);
}

/*===================================================================
' Description:
'====================================================================
' Date:       Name:                   Comment:
' 2000-08-09  Daniel Plyhm            Created.
'==================================================================*/
function login()
{
	//var loginWin = openWindow('/jsp/login.html', 'login',400,130,200,50,false,null);
  var loginWin = openWindow('/login/jsp/login.jsp?method=getPage', 'login',380,240,200,50,false,'menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0');
}

function createMyPage()
{
  window.open('/user/privat/min_sida/registrera1.jsp?method=startUserRegistration', 'registration', 'width=480,height=460,left=200,screenX=200,top=50,screenY=50,menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0').focus();
}

/*===================================================================
' Description:
'====================================================================
' Date:       Name:                   Comment:
' 2000-08-09  Daniel Plyhm            Created.
'==================================================================*/
function no_password()
{
	var nopassWin = openWindow('/user/jsp/no_password.jsp?method=noAction', 'no_password',380,220,200,50,false,'menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0');
}

/*===================================================================
' Description:
'====================================================================
' Date:       Name:                   Comment:
' 2004-10-22  Ann Lind            		Created.
'==================================================================*/
function no_userid()
{
	var nopassWin = openWindow('/user/jsp/no_userid.jsp?method=noAction', 'no_userid',400,300,200,50,false,'menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0');
}

/*===================================================================
' Description:
' Return value:
' Parameters:
' Usage: openWindow('http://www.builder.com/', 'remote',300,300,null,null,true,null);
'	 openWindow('http://www.builder.com/', 'remote',300,300,150,230,false,'menubar=1,toolbar=1,location=0');
'   	 sPreferences default: menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0
'====================================================================
' Date:       Name:                   Comment:
' 2001-07-30  Daniel Plyhm            Created.
'==================================================================*/
function openWindow(sUrl,sName,iWidth,iHeight,iLeft,iTop,bCenter,sPreferences)
{
  	var str = "height=" + iHeight;
  	str += ",width=" + iWidth;

	if (window.screen && bCenter) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - iWidth) / 2;
		var yc = (ah - iHeight) / 2;
		str += ",left=" + xc + ",screenX=" + xc + ",top=" + yc + ",screenY=" + yc;
	}
	else{
 		str += ",left=" + iLeft + ",screenX=" + iLeft + ",top=" + iTop + ",screenY=" + iTop;
  	}

  	if( sPreferences == null ) {
 	 	str += ',menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0';
 	}
 	else{
 		str += "," + sPreferences;
 	}

  	var popupWin = window.open(sUrl,sName,str);
	if (!popupWin.opener)  popupWin.opener = self;
	popupWin.focus();
	return popupWin;
}

/*===================================================================
' Description: Removes all alfanumeric signs from a string
' Return value:
' Parameters:
' Usage: text = removeAlfanumeric(text)
'====================================================================
' Date:       Name:                   Comment:
' 2001-10-25  Andreas Terner            Created.
'==================================================================*/
function removeAlfanumeric(text)
{
  var number = new Array("0","1","2","3","4","5","6","7","8","9");
  var numberString="";
  for (var i=0;i < text.length; i++)
  {
    for (tkn in number)
    {
      if (text.charAt(i) != ' ' && text.charAt(i) == tkn)
      {
        numberString += tkn;
        break;
      }
    }
  }
  return numberString;
}

/*===================================================================
' Description: Format orgnumber by removing alfanumeric and changing to string XXXXXX-XXXX
' Return value:
' Parameters:
' Usage: onBlur="formatOrgNumber(this)"
'====================================================================
' Date:       Name:                   Comment:
' 2001-10-25  Andreas Terner            Created.
'==================================================================*/
function formatOrgNumber(field)
{
  var orgNumber = field.value;
  orgNumber = removeAlfanumeric(orgNumber);
  orgNumber = orgNumber.substring(0,6) + "-" + orgNumber.substring(6,10);
  field.value = orgNumber;
}

/*===================================================================
' Description: Format postNumber by removing alfanumeric and changing to string XXX XX
' Return value:
' Parameters:
' Usage: onBlur="formatPostNumber(this)"
'====================================================================
' Date:       Name:                   Comment:
' 2001-10-25  Andreas Terner            Created.
'==================================================================*/
function formatPostNumber(field)
{
  var postNumber = field.value;
  postNumber = removeAlfanumeric(postNumber);
  postNumber = postNumber.substring(0,3) + " " + postNumber.substring(3,5);
  field.value = postNumber;
}

/*===================================================================
' Description: Set field value after removing all alfanumeric
' Return value:
' Parameters:
' Usage: onBlur="setOnlyNumeric(this)"
'====================================================================
' Date:       Name:                   Comment:
' 2001-10-25  Andreas Terner            Created.
'==================================================================*/
function setOnlyNumeric(field)
{
  field.value = removeAlfanumeric(field.value);
}
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);	
	//var arrElements = oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	//alert(arrElements.length);
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];		
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);			
		}
	}
	return (arrReturnElements)
}

//]]>
