var imgLoaded=false;
var newWindow;
if (document.images) document.arImg=new Array();
function ai(im,i){
	with (document){
		arImg[i] = new Image();
		arImg[i].src = "images/" + im + "Off.gif";
		arImg[i+1] = new Image();
		arImg[i+1].src ="images/" + im + "On.gif";
	}
}
function changeImg(id, i) {
	if (document.images && imgLoaded) with (document) images[id].src = arImg[i].src;
}
function loadImages(){
	if (document.images) {
		ai("btHome",0);
		ai("btAgenda",2);
		ai("btLegislatie",4);
		ai("btComunity",6);
		ai("btCompany",8);
		ai("btMarket",10);
		ai("btEquip",12);
		ai("btOpportune",14);
        ai("btConsulting",16);
       	ai("btBuilder",18);
        ai("btOffer",20);
        ai("btAdmin",22);
        ai("btCompanyEn",24);
        ai("btMarketEn",26);
        ai("btOpportuneEn",28);
        ai("btOfferEn",30);
		imgLoaded = true;
	}
}
function setCombo(name, value){
	cmb=eval('document.forms.' + name);
	for(i=0;i<cmb.options.length;i++){
	if (cmb.options[i].text==value){
		cmb.selectedIndex=i;
		return;
	}
	}
}

function setComboValue(name, value){
	cmb=eval('document.forms.' + name);
	for(i=0;i<cmb.options.length;i++){
	if (cmb.options[i].value==value){
		cmb.selectedIndex=i;
		return;
	}
	}
}

function openNewWinWithMenu(url,width,height){
        if (width>window.screen.width) width=window.screen.width
	if (height>window.screen.height) height=window.screen.height
        var features="menubar=yes,left=0,top=0,scrollbars=yes,height=" + height + ",width=" + width + ",resizable=yes";
        openWindow(url, features);
}

function openNewWin(url,width,height){
        if (width>window.screen.width) width=window.screen.width
	if (height>window.screen.height) height=window.screen.height
        var features="left=0,top=0,scrollbars=yes,height=" + height + ",width=" + width + ",resizable=yes";
        openWindow(url, features);
}

function openWindow(url,features){
        var newContent;
        var width, height;
        if (width>window.screen.width) width=window.screen.width
	if (height>window.screen.height) height=window.screen.height
	if (!newWindow || newWindow.closed) {
		newWindow=window.open(url,"win",features)
		if (!newWindow.opener){
			newWindow.opener=window;
		}
	}else{
	//window already open;close and open again
	//because ns don't resize it when load a new image
	newWindow.close()
	newWindow=window.open(url,"win",features)
		if (!newWindow.opener){
			newWindow.opener=window;
		}
	newWindow.focus();
	}
}

function setMultipleList(listName, selList){
  var list,i, index, listObj;
  listObj=eval('document.forms.'+listName);
  list=selList.split(';');
  for (i=0;i<list.length;i++){
          index=getOptionIndex(listObj,list[i]);
          if (index>-1)
                  listObj.options[index].selected=true;
  }
}

function getOptionIndex(selectList,value){
  var i;
  for(i=0;i<selectList.options.length;i++)
          if (selectList.options[i].value==value)
                  return i;
  return -1;
}

function clearCombo(cmbName){
  var cmbObj,i,j;
  cmbObj=eval('document.forms.'+cmbName);
  for(i=0;i<cmbObj.options.length;i++)
    cmbObj.options[i]=null;
}

function fillCombo(cmbName, index, firstText){
  var cmbObj,i,j;
  cmbObj=eval('document.forms.'+cmbName);
  clearCombo(cmbName);
  cmbObj.options[0]=new Option(firstText,"");
  for (i=0;i<arrValues[index].length;i++){
    //cmbObj.options[i+1]=new Option(arrValues[index][i][1],arrValues[index][i][0],false,false);
    cmbObj.options[i+1]=new Option(arrValues[index][i][1]);
  }
}

function checkAllCheckBoxes(form, checkBoxName, flag){
   for (i = 0; i < form.elements.length; i++) {
        if (form.elements[i].name == checkBoxName) {
            form.elements[i].checked = flag;
        }
   }
}

function reload() {
    document.location.href="requestLevel.jsp?level=" + document.requestLevel.level.value + "&index=" + strIndex
                           + "&startday=" + startDay + "&startmonth=" + startMonth + "&startyear=" + startYear
                           + "&endday=" + endDay + "&endmonth=" + endMonth + "&endyear=" + endYear
                           + "&info=" + info;


}
function nav(pageCmb, step){
  var cmbObj;
  cmbObj=eval('document.forms.'+pageCmb);
  //for (i=0;i<cmbObj.length;i++)
  //  cmbObj[i].selectedIndex = cmbObj[i].selectedIndex + step;
  //if (cmbObj[0].selectedIndex!=undefined) {
	cmbObj[0].selectedIndex = cmbObj[0].selectedIndex + step;
  	cmbObj[1].selectedIndex = cmbObj[1].selectedIndex + step;
  //} else {
  //	cmbObj.selectedIndex = cmbObj.selectedIndex + step;
  //}
}

function setPgCmb(pageCmb, newIndex){
  var cmbObj;
  cmbObj=eval('document.forms.'+pageCmb);
  //for (i=0;i<cmbObj.length;i++)
  //  cmbObj[i].selectedIndex = newIndex;
  //if (cmbObj[0].selectedIndex!=undefined) {
	  cmbObj[0].selectedIndex = newIndex;
	  cmbObj[1].selectedIndex = newIndex;
  //} else {
  //	cmbObj.selectedIndex = newIndex;
  //}
}

function checkRadio(radioName, varValue){
  var btnRadio=eval('document.forms.' + radioName);
  for(var i=0;i<btnRadio.length;i++){
    if (btnRadio[i].value==varValue){
      btnRadio[i].checked=true;
    }
  }
  if (varValue=="") btnRadio[0].checked=true;
}

function checkSubmitForm(formName, formAction, checkboxName, actionid){
  var nr = 0;
  var form=eval('document.forms.'+formName);
  form.action=formAction;
  if (form.page!=undefined) {
	  if (form.page.selectedIndex!=undefined) {
	  		form.page.selectedIndex=0;
	  } else {
		  if (form.page[0].selectedIndex!=undefined) {
		  	form.page[0].selectedIndex=0;
		  	form.page[1].selectedIndex=0;
		  } 
	  }
  }
  if (actionid=='new'){
    form.actionid.value=actionid;
    form.submit();
  } else {
    for (i = 0; i < form.elements.length; i++) {
      if (form.elements[i].name == checkboxName) {
          if (form.elements[i].checked) nr++;
      }
    }
    if (nr==1){
      form.actionid.value=actionid;
      form.submit();
    } //else if(nr > 0 && actionid=='del'){
      //form.actionid.value=actionid;
      //form.submit();
    //}
  }
}
